Skip to content

Commit

Permalink
add royalty rate to drop types (#36)
Browse files Browse the repository at this point in the history
* add royalty rate to drop types

* deploy to new DropTypes address
  • Loading branch information
austinkline authored Sep 9, 2024
1 parent ece5ad2 commit 25791dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
27 changes: 24 additions & 3 deletions contracts/DropTypes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -75,6 +77,7 @@ access(all) contract DropTypes {
let b = getCurrentBlock()
self.blockHeight = b.height
self.blockTimestamp = UInt64(b.timestamp)
self.royaltyRate = royaltyRate
}
}

Expand Down Expand Up @@ -199,6 +202,14 @@ access(all) contract DropTypes {
phaseSummaries.append(summary)
}

var royaltyRate = 0.0
if let tmpRoyalties = resolver!.resolveContractView(resourceType: nftType, viewType: Type<MetadataViews.Royalties>()) {
let royalties = tmpRoyalties as! MetadataViews.Royalties
for r in royalties.getRoyalties() {
royaltyRate = royaltyRate + r.cut
}
}

let dropSummary = DropSummary(
id: drop!.uuid,
display: dropDetails.display,
Expand All @@ -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
Expand Down Expand Up @@ -263,6 +275,14 @@ access(all) contract DropTypes {
continue
}

var royaltyRate = 0.0
if let tmpRoyalties = resolver!.resolveContractView(resourceType: nftType, viewType: Type<MetadataViews.Royalties>()) {
let royalties = tmpRoyalties as! MetadataViews.Royalties
for r in royalties.getRoyalties() {
royaltyRate = royaltyRate + r.cut
}
}

summaries.append(DropSummary(
id: drop!.uuid,
display: dropDetails.display,
Expand All @@ -273,7 +293,8 @@ access(all) contract DropTypes {
commissionRate: dropDetails.commissionRate,
nftType: CompositeType(dropDetails.nftType)!,
address: minter,
phases: phaseSummaries
phases: phaseSummaries,
royaltyRate: royaltyRate
))
}

Expand Down
16 changes: 0 additions & 16 deletions contracts/nft/BaseCollection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,6 @@ access(all) contract interface BaseCollection: ViewResolver {
)
case Type<FlowtyDrops.DropResolver>():
return FlowtyDrops.DropResolver(cap: acct.capabilities.get<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerPublicPath))
case Type<MetadataViews.NFTCollectionDisplay>():
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<MetadataViews.Royalties>():
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
Expand Down
2 changes: 1 addition & 1 deletion flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
},
"droptypes-testnet": {
"address": "0x934da91a977f1ac4",
"address": "0xa061e5b10252955d",
"key": {
"type": "google-kms",
"index": 0,
Expand Down

0 comments on commit 25791dd

Please sign in to comment.