From 25791ddc917d6f293c3977c1f21c823726a85fcb Mon Sep 17 00:00:00 2001 From: Austin Kline Date: Mon, 9 Sep 2024 11:43:20 -0500 Subject: [PATCH] add royalty rate to drop types (#36) * add royalty rate to drop types * deploy to new DropTypes address --- contracts/DropTypes.cdc | 27 ++++++++++++++++++++++++--- contracts/nft/BaseCollection.cdc | 16 ---------------- flow.json | 2 +- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/contracts/DropTypes.cdc b/contracts/DropTypes.cdc index ba37248..bb15bde 100644 --- a/contracts/DropTypes.cdc +++ b/contracts/DropTypes.cdc @@ -42,6 +42,7 @@ access(all) contract DropTypes { access(all) let blockTimestamp: UInt64 access(all) let blockHeight: UInt64 + access(all) let royaltyRate: UFix64 init( id: UInt64, @@ -53,7 +54,8 @@ access(all) contract DropTypes { commissionRate: UFix64, nftType: Type, address: Address?, - phases: [PhaseSummary] + phases: [PhaseSummary], + royaltyRate: UFix64 ) { self.id = id self.display = Display(display) @@ -75,6 +77,7 @@ access(all) contract DropTypes { let b = getCurrentBlock() self.blockHeight = b.height self.blockTimestamp = UInt64(b.timestamp) + self.royaltyRate = royaltyRate } } @@ -199,6 +202,14 @@ access(all) contract DropTypes { phaseSummaries.append(summary) } + var royaltyRate = 0.0 + if let tmpRoyalties = resolver!.resolveContractView(resourceType: nftType, viewType: Type()) { + let royalties = tmpRoyalties as! MetadataViews.Royalties + for r in royalties.getRoyalties() { + royaltyRate = royaltyRate + r.cut + } + } + let dropSummary = DropSummary( id: drop!.uuid, display: dropDetails.display, @@ -209,7 +220,8 @@ access(all) contract DropTypes { commissionRate: dropDetails.commissionRate, nftType: CompositeType(dropDetails.nftType)!, address: minter, - phases: phaseSummaries + phases: phaseSummaries, + royaltyRate: royaltyRate ) return dropSummary @@ -263,6 +275,14 @@ access(all) contract DropTypes { continue } + var royaltyRate = 0.0 + if let tmpRoyalties = resolver!.resolveContractView(resourceType: nftType, viewType: Type()) { + let royalties = tmpRoyalties as! MetadataViews.Royalties + for r in royalties.getRoyalties() { + royaltyRate = royaltyRate + r.cut + } + } + summaries.append(DropSummary( id: drop!.uuid, display: dropDetails.display, @@ -273,7 +293,8 @@ access(all) contract DropTypes { commissionRate: dropDetails.commissionRate, nftType: CompositeType(dropDetails.nftType)!, address: minter, - phases: phaseSummaries + phases: phaseSummaries, + royaltyRate: royaltyRate )) } diff --git a/contracts/nft/BaseCollection.cdc b/contracts/nft/BaseCollection.cdc index a14624a..aada599 100644 --- a/contracts/nft/BaseCollection.cdc +++ b/contracts/nft/BaseCollection.cdc @@ -82,22 +82,6 @@ access(all) contract interface BaseCollection: ViewResolver { ) case Type(): return FlowtyDrops.DropResolver(cap: acct.capabilities.get<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerPublicPath)) - case Type(): - let c = getAccount(addr).contracts.borrow<&{BaseCollection}>(name: segments[2])! - let tmp = c.MetadataCap.borrow() - if tmp == nil { - return nil - } - - return tmp!.collectionInfo.getDisplay() - case Type(): - let c = getAccount(addr).contracts.borrow<&{BaseCollection}>(name: segments[2])! - let tmp = c.MetadataCap.borrow() - if tmp == nil { - return nil - } - - return tmp!.collectionInfo.getDisplay() } // These views require the {BaseCollection} interface diff --git a/flow.json b/flow.json index a9540dd..106caef 100644 --- a/flow.json +++ b/flow.json @@ -42,7 +42,7 @@ } }, "droptypes-testnet": { - "address": "0x934da91a977f1ac4", + "address": "0xa061e5b10252955d", "key": { "type": "google-kms", "index": 0,