Skip to content

Commit

Permalink
add paymentTokenTypes to DropDetails struct
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Sep 23, 2024
1 parent 32eafee commit 4efcd8e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 46 deletions.
4 changes: 2 additions & 2 deletions contracts/DropFactory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ access(all) contract DropFactory {


let nftType = CompositeType(nftTypeIdentifier) ?? panic("invalid nft type identifier")
let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05, nftType: nftTypeIdentifier)
let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05, nftType: nftTypeIdentifier, paymentTokenTypes: {paymentTokenType.identifier: true})
let drop <- FlowtyDrops.createDrop(details: dropDetails, minterCap: minterCap, phases: <- [<-phase])

return <- drop
Expand Down Expand Up @@ -67,7 +67,7 @@ access(all) contract DropFactory {
let phase <- FlowtyDrops.createPhase(details: phaseDetails)

let nftType = CompositeType(nftTypeIdentifier) ?? panic("invalid nft type identifier")
let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05, nftType: nftTypeIdentifier)
let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05, nftType: nftTypeIdentifier, paymentTokenTypes: {paymentTokenType.identifier: true})
let drop <- FlowtyDrops.createDrop(details: dropDetails, minterCap: minterCap, phases: <- [<-phase])

return <- drop
Expand Down
35 changes: 19 additions & 16 deletions contracts/DropTypes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ access(all) contract DropTypes {
access(all) let commissionRate: UFix64
access(all) let nftType: String
access(all) let creator: Address?
access(all) let paymentTokenTypes: {String: Bool}

access(all) let address: Address?
access(all) let mintedByAddress: Int?
Expand All @@ -58,7 +59,8 @@ access(all) contract DropTypes {
address: Address?,
phases: [PhaseSummary],
royaltyRate: UFix64,
creator: Address?
creator: Address?,
paymentTokenTypes: {String: Bool}
) {
self.id = id
self.display = Display(display)
Expand All @@ -82,6 +84,7 @@ access(all) contract DropTypes {
self.blockHeight = b.height
self.blockTimestamp = UInt64(b.timestamp)
self.royaltyRate = royaltyRate
self.paymentTokenTypes = paymentTokenTypes
}
}

Expand Down Expand Up @@ -118,7 +121,7 @@ access(all) contract DropTypes {
access(all) let remainingForAddress: Int?
access(all) let maxPerMint: Int?

access(all) let quote: Quote?
access(all) let quotes: {String: Quote}

init(
index: Int,
Expand All @@ -127,7 +130,7 @@ access(all) contract DropTypes {
totalMinted: Int?,
minter: Address?,
quantity: Int?,
paymentIdentifier: String?
paymentIdentifiers: [String]
) {
self.index = index
self.id = phase.uuid
Expand Down Expand Up @@ -155,19 +158,17 @@ access(all) contract DropTypes {
self.remainingForAddress = nil
}

self.maxPerMint = d.addressVerifier.getMaxPerMint(addr: self.address, totalMinted: totalMinted ?? 0, data: {} as {String: AnyStruct})
self.maxPerMint = d.addressVerifier.getMaxPerMint(addr: self.address, totalMinted: totalMinted ?? 0, data: {})
self.quotes = {}

if paymentIdentifier != nil && quantity != nil {
let price = d.pricer.getPrice(num: quantity!, paymentTokenType: CompositeType(paymentIdentifier!)!, minter: minter)

self.quote = Quote(price: price, quantity: quantity!, paymentIdentifier: paymentIdentifier!, minter: minter)
} else {
self.quote = nil
for paymentIdentifier in paymentIdentifiers {
let price = d.pricer.getPrice(num: quantity!, paymentTokenType: CompositeType(paymentIdentifier)!, minter: minter)
self.quotes[paymentIdentifier] = Quote(price: price, quantity: quantity!, paymentIdentifier: paymentIdentifier, minter: minter)
}
}
}

access(all) fun getDropSummary(nftTypeIdentifier: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifier: String?): DropSummary? {
access(all) fun getDropSummary(nftTypeIdentifier: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifiers: [String]): DropSummary? {
let nftType = CompositeType(nftTypeIdentifier) ?? panic("invalid nft type identifier")
let segments = nftTypeIdentifier.split(separator: ".")
let contractAddress = AddressUtils.parseAddress(nftType)!
Expand Down Expand Up @@ -206,7 +207,7 @@ access(all) contract DropTypes {
totalMinted: minter != nil ? dropDetails.minters[minter!] : nil,
minter: minter,
quantity: quantity,
paymentIdentifier: paymentIdentifier
paymentIdentifiers: paymentIdentifiers
)
phaseSummaries.append(summary)
}
Expand All @@ -231,13 +232,14 @@ access(all) contract DropTypes {
address: minter,
phases: phaseSummaries,
royaltyRate: royaltyRate,
creator: creator
creator: creator,
paymentTokenTypes: dropDetails.paymentTokenTypes
)

return dropSummary
}

access(all) fun getAllDropSummaries(nftTypeIdentifier: String, minter: Address?, quantity: Int?, paymentIdentifier: String?): [DropSummary] {
access(all) fun getAllDropSummaries(nftTypeIdentifier: String, minter: Address?, quantity: Int?, paymentIdentifiers: [String]): [DropSummary] {
let nftType = CompositeType(nftTypeIdentifier) ?? panic("invalid nft type identifier")
let segments = nftTypeIdentifier.split(separator: ".")
let contractAddress = AddressUtils.parseAddress(nftType)!
Expand Down Expand Up @@ -278,7 +280,7 @@ access(all) contract DropTypes {
totalMinted: minter != nil ? dropDetails.minters[minter!] : nil,
minter: minter,
quantity: quantity,
paymentIdentifier: paymentIdentifier
paymentIdentifiers: paymentIdentifiers.length > 0 ? paymentIdentifiers : dropDetails.paymentTokenTypes.keys
)
phaseSummaries.append(summary)
}
Expand Down Expand Up @@ -307,7 +309,8 @@ access(all) contract DropTypes {
address: minter,
phases: phaseSummaries,
royaltyRate: royaltyRate,
creator: creator
creator: creator,
paymentTokenTypes: dropDetails.paymentTokenTypes
))
}

Expand Down
60 changes: 35 additions & 25 deletions contracts/FlowtyDrops.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ access(all) contract FlowtyDrops {
// Interface to expose all the components necessary to participate in a drop
// and to ask questions about a drop.
access(all) resource interface DropPublic {
access(all) fun borrowPhasePublic(index: Int): &{PhasePublic}
access(all) fun borrowActivePhases(): [&{PhasePublic}]
access(all) fun borrowAllPhases(): [&{PhasePublic}]
access(all) view fun borrowPhasePublic(index: Int): &{PhasePublic}
access(all) view fun borrowActivePhases(): [&{PhasePublic}]
access(all) view fun borrowAllPhases(): [&{PhasePublic}]
access(all) fun mint(
payment: @{FungibleToken.Vault},
amount: Int,
Expand All @@ -35,8 +35,18 @@ access(all) contract FlowtyDrops {
receiverCap: Capability<&{NonFungibleToken.CollectionPublic}>,
commissionReceiver: Capability<&{FungibleToken.Receiver}>?,
data: {String: AnyStruct}
): @{FungibleToken.Vault}
access(all) fun getDetails(): DropDetails
): @{FungibleToken.Vault} {
pre {
self.getDetails().paymentTokenTypes[payment.getType().identifier] == true: "unsupported payment token type"
receiverCap.check(): "unvalid nft receiver capability"
commissionReceiver == nil || commissionReceiver!.check(): "commission receiver must be nil or a valid capability"
self.getType() == Type<@Drop>(): "unsupported type implementing DropPublic"
expectedType.isSubtype(of: Type<@{NonFungibleToken.NFT}>()): "expected type must be an NFT"
expectedType.identifier == self.getDetails().nftType: "expected type does not match drop details type"
receiverCap.check(): "receiver capability is not valid"
}
}
access(all) view fun getDetails(): DropDetails
}

// A phase represents a stage of a drop. Some drops will only have one
Expand All @@ -51,23 +61,23 @@ access(all) contract FlowtyDrops {
access(all) let resources: @{String: AnyResource}

// returns whether this phase of a drop has started.
access(all) fun isActive(): Bool {
access(all) view fun isActive(): Bool {
return self.details.activeChecker.hasStarted() && !self.details.activeChecker.hasEnded()
}

access(all) fun getDetails(): PhaseDetails {
access(all) view fun getDetails(): PhaseDetails {
return self.details
}

access(EditPhase) fun borrowActiveCheckerAuth(): auth(Mutate) &{ActiveChecker} {
access(EditPhase) view fun borrowActiveCheckerAuth(): auth(Mutate) &{ActiveChecker} {
return &self.details.activeChecker
}

access(EditPhase) fun borrowPricerAuth(): auth(Mutate) &{Pricer} {
access(EditPhase) view fun borrowPricerAuth(): auth(Mutate) &{Pricer} {
return &self.details.pricer
}

access(EditPhase) fun borrowAddressVerifierAuth(): auth(Mutate) &{AddressVerifier} {
access(EditPhase) view fun borrowAddressVerifierAuth(): auth(Mutate) &{AddressVerifier} {
return &self.details.addressVerifier
}

Expand Down Expand Up @@ -111,10 +121,7 @@ access(all) contract FlowtyDrops {
data: {String: AnyStruct}
): @{FungibleToken.Vault} {
pre {
expectedType.isSubtype(of: Type<@{NonFungibleToken.NFT}>()): "expected type must be an NFT"
expectedType.identifier == self.details.nftType: "expected type does not match drop details type"
self.phases.length > phaseIndex: "phase index is too high"
receiverCap.check(): "receiver capability is not valid"
}

// validate the payment vault amount and type
Expand Down Expand Up @@ -167,23 +174,23 @@ access(all) contract FlowtyDrops {
return <- payment
}

access(Owner) fun borrowPhase(index: Int): auth(EditPhase) &Phase {
access(Owner) view fun borrowPhase(index: Int): auth(EditPhase) &Phase {
return &self.phases[index]
}


access(all) fun borrowPhasePublic(index: Int): &{PhasePublic} {
access(all) view fun borrowPhasePublic(index: Int): &{PhasePublic} {
return &self.phases[index]
}

access(all) fun borrowActivePhases(): [&{PhasePublic}] {
let arr: [&{PhasePublic}] = []
access(all) view fun borrowActivePhases(): [&{PhasePublic}] {
var arr: [&{PhasePublic}] = []
var count = 0
while count < self.phases.length {
let ref = self.borrowPhasePublic(index: count)
let activeChecker = ref.getDetails().activeChecker
if activeChecker.hasStarted() && !activeChecker.hasEnded() {
arr.append(ref)
arr = arr.concat([ref])
}

count = count + 1
Expand All @@ -192,12 +199,12 @@ access(all) contract FlowtyDrops {
return arr
}

access(all) fun borrowAllPhases(): [&{PhasePublic}] {
let arr: [&{PhasePublic}] = []
access(all) view fun borrowAllPhases(): [&{PhasePublic}] {
var arr: [&{PhasePublic}] = []
var index = 0
while index < self.phases.length {
let ref = self.borrowPhasePublic(index: index)
arr.append(ref)
arr = arr.concat([ref])
index = index + 1
}

Expand Down Expand Up @@ -228,7 +235,7 @@ access(all) contract FlowtyDrops {
return <- phase
}

access(all) fun getDetails(): DropDetails {
access(all) view fun getDetails(): DropDetails {
return self.details
}

Expand All @@ -253,6 +260,7 @@ access(all) contract FlowtyDrops {
access(all) var minters: {Address: Int}
access(all) let commissionRate: UFix64
access(all) let nftType: String
access(all) let paymentTokenTypes: {String: Bool}

access(all) let data: {String: AnyStruct}

Expand All @@ -265,7 +273,7 @@ access(all) contract FlowtyDrops {
self.minters[addr] = self.minters[addr]! + num
}

init(display: MetadataViews.Display, medias: MetadataViews.Medias?, commissionRate: UFix64, nftType: String) {
init(display: MetadataViews.Display, medias: MetadataViews.Medias?, commissionRate: UFix64, nftType: String, paymentTokenTypes: {String: Bool}) {
pre {
nftType != "": "nftType should be a composite type identifier"
}
Expand All @@ -276,6 +284,8 @@ access(all) contract FlowtyDrops {
self.commissionRate = commissionRate
self.minters = {}
self.nftType = nftType
self.paymentTokenTypes = paymentTokenTypes

self.data = {}
}
}
Expand All @@ -300,8 +310,8 @@ access(all) contract FlowtyDrops {
// - How many items are left in the current phase?
// - Can Address x mint on a phase?
// - What is the cost to mint for the phase I am interested in (for address x)?
access(all) fun getDetails(): PhaseDetails
access(all) fun isActive(): Bool
access(all) view fun getDetails(): PhaseDetails
access(all) view fun isActive(): Bool
}

access(all) struct PhaseDetails {
Expand Down
7 changes: 6 additions & 1 deletion scripts/get_drop_summaries.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import "DropTypes"

access(all) fun main(nftTypeIdentifier: String, minter: Address?, quantity: Int?, paymentIdentifier: String?): [DropTypes.DropSummary] {
return DropTypes.getAllDropSummaries(nftTypeIdentifier: nftTypeIdentifier, minter: minter, quantity: quantity, paymentIdentifier: paymentIdentifier)
return DropTypes.getAllDropSummaries(
nftTypeIdentifier: nftTypeIdentifier,
minter: minter,
quantity: quantity,
paymentIdentifiers: paymentIdentifier != nil ? [paymentIdentifier!] : []
)
}
8 changes: 7 additions & 1 deletion scripts/get_drop_summary.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import "DropTypes"

access(all) fun main(nftTypeIdentifier: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifier: String?): DropTypes.DropSummary? {
return DropTypes.getDropSummary(nftTypeIdentifier: nftTypeIdentifier, dropID: dropID, minter: minter, quantity: quantity, paymentIdentifier: paymentIdentifier)
return DropTypes.getDropSummary(
nftTypeIdentifier: nftTypeIdentifier,
dropID: dropID,
minter: minter,
quantity: quantity,
paymentIdentifiers: paymentIdentifier != nil ? [paymentIdentifier!]: []
)
}
3 changes: 2 additions & 1 deletion transactions/factory/create_open_edition_drop.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ transaction(contractName: String, managerInitialTokenBalance: UFix64, start: UIn
),
medias: nil,
commissionRate: 0.05,
nftType: nftType
nftType: nftType,
paymentTokenTypes: {paymentTokenType: true}
)

let phaseDetails = FlowtyDrops.PhaseDetails(
Expand Down

0 comments on commit 4efcd8e

Please sign in to comment.