Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add royalty rate to drop types #36

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading