Skip to content

Commit

Permalink
contract creation event optionally creates a drop as well
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Jun 1, 2024
1 parent ab0047a commit 60bd589
Show file tree
Hide file tree
Showing 10 changed files with 701 additions and 17 deletions.
450 changes: 449 additions & 1 deletion args/create_open_edition_contract.json

Large diffs are not rendered by default.

192 changes: 192 additions & 0 deletions args/encode_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
[
{
"type": "Dictionary",
"value": [
{
"key": {
"type": "String",
"value": "dropDetails"
},
"value": {
"type": "Struct",
"value": {
"id": "A.f8d6e0586b0a20c7.FlowtyDrops.DropDetails",
"fields": [
{
"name": "display",
"value": {
"type": "Struct",
"value": {
"id": "A.f8d6e0586b0a20c7.MetadataViews.Display",
"fields": [
{
"name": "name",
"value": {
"type": "String",
"value": "My First Drop"
}
},
{
"name": "description",
"value": {
"type": "String",
"value": "This is a description for my first drop"
}
},
{
"name": "thumbnail",
"value": {
"type": "Struct",
"value": {
"id": "A.f8d6e0586b0a20c7.MetadataViews.IPFSFile",
"fields": [
{
"name": "cid",
"value": {
"type": "String",
"value": "QmWWLhnkPR3ejavNtzeJcdG9fwcBHKwBVEP4pZ9rGbdHEM"
}
},
{
"name": "path",
"value": {
"type": "Optional",
"value": null
}
}
]
}
}
}
]
}
}
},
{
"name": "medias",
"value": {
"type": "Optional",
"value": null
}
},
{
"name": "totalMinted",
"value": {
"type": "Int",
"value": "0"
}
},
{
"name": "minters",
"value": {
"type": "Dictionary",
"value": []
}
},
{
"name": "commissionRate",
"value": {
"type": "UFix64",
"value": "0.05"
}
},
{
"name": "nftType",
"value": {
"type": "String",
"value": "A.f8d6e0586b0a20c7.MyCollection.NFT"
}
}
]
}
}
},
{
"key": {
"type": "String",
"value": "phaseDetails"
},
"value": {
"type": "Array",
"value": [
{
"type": "Struct",
"value": {
"id": "A.f8d6e0586b0a20c7.FlowtyDrops.PhaseDetails",
"fields": [
{
"name": "switcher",
"value": {
"type": "Struct",
"value": {
"id": "A.f8d6e0586b0a20c7.FlowtySwitchers.AlwaysOn",
"fields": []
}
}
},
{
"name": "display",
"value": {
"type": "Optional",
"value": null
}
},
{
"name": "pricer",
"value": {
"type": "Struct",
"value": {
"id": "A.f8d6e0586b0a20c7.FlowtyPricers.FlatPrice",
"fields": [
{
"name": "price",
"value": {
"type": "UFix64",
"value": "1.0"
}
},
{
"name": "paymentTokenType",
"value": {
"type": "String",
"value": "A.0ae53cb6e3f42a79.FlowToken.Vault"
}
}
]
}
}
},
{
"name": "addressVerifier",
"value": {
"type": "Struct",
"value": {
"id": "A.f8d6e0586b0a20c7.FlowtyAddressVerifiers.AllowAll",
"fields": [
{
"name": "maxPerMint",
"value": {
"type": "Int",
"value": "100"
}
}
]
}
}
},
{
"name": "data",
"value": {
"type": "Dictionary",
"value": []
}
}
]
}
}
]
}
}
]
}
]
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: nftType)
let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05, nftType: nftTypeIdentifier)
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: nftType)
let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05, nftType: nftTypeIdentifier)
let drop <- FlowtyDrops.createDrop(details: dropDetails, minterCap: minterCap, phases: <- [<-phase])

return <- drop
Expand Down
4 changes: 2 additions & 2 deletions contracts/DropTypes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ access(all) contract DropTypes {
minterCount: dropDetails.minters.keys.length,
mintedByAddress: minter != nil ? dropDetails.minters[minter!] : nil,
commissionRate: dropDetails.commissionRate,
nftType: dropDetails.nftType,
nftType: CompositeType(dropDetails.nftType)!,
address: minter,
phases: phaseSummaries
)
Expand Down Expand Up @@ -267,7 +267,7 @@ access(all) contract DropTypes {
minterCount: dropDetails.minters.keys.length,
mintedByAddress: minter != nil ? dropDetails.minters[minter!] : nil,
commissionRate: dropDetails.commissionRate,
nftType: dropDetails.nftType,
nftType: CompositeType(dropDetails.nftType)!,
address: minter,
phases: phaseSummaries
))
Expand Down
7 changes: 4 additions & 3 deletions contracts/FlowtyDrops.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ access(all) contract FlowtyDrops {
access(all) event ResourceDestroyed(
uuid: UInt64 = self.uuid,
minterAddress: Address = self.minterCap.address,
nftType: String = self.details.nftType.identifier,
nftType: String = self.details.nftType,
totalMinted: Int = self.details.totalMinted
)

Expand All @@ -58,6 +58,7 @@ access(all) contract FlowtyDrops {
): @{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"
}
Expand Down Expand Up @@ -190,7 +191,7 @@ access(all) contract FlowtyDrops {
access(all) var totalMinted: Int
access(all) var minters: {Address: Int}
access(all) let commissionRate: UFix64
access(all) let nftType: Type
access(all) let nftType: String

access(contract) fun addMinted(num: Int, addr: Address) {
self.totalMinted = self.totalMinted + num
Expand All @@ -201,7 +202,7 @@ access(all) contract FlowtyDrops {
self.minters[addr] = self.minters[addr]! + num
}

init(display: MetadataViews.Display, medias: MetadataViews.Medias?, commissionRate: UFix64, nftType: Type) {
init(display: MetadataViews.Display, medias: MetadataViews.Medias?, commissionRate: UFix64, nftType: String) {
self.display = display
self.medias = medias
self.totalMinted = 0
Expand Down
6 changes: 3 additions & 3 deletions contracts/FlowtyPricers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ access(all) contract FlowtyPricers {
*/
access(all) struct FlatPrice: FlowtyDrops.Pricer {
access(all) var price: UFix64
access(all) let paymentTokenType: Type
access(all) let paymentTokenType: String

access(all) view fun getPrice(num: Int, paymentTokenType: Type, minter: Address?): UFix64 {
return self.price * UFix64(num)
}

access(all) view fun getPaymentTypes(): [Type] {
return [self.paymentTokenType]
return [CompositeType(self.paymentTokenType)!]
}

access(Mutate) fun setPrice(price: UFix64) {
Expand All @@ -29,7 +29,7 @@ access(all) contract FlowtyPricers {

init(price: UFix64, paymentTokenType: Type) {
self.price = price
self.paymentTokenType = paymentTokenType
self.paymentTokenType = paymentTokenType.identifier
}
}

Expand Down
38 changes: 38 additions & 0 deletions contracts/initializers/OpenEditionInitializer.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "ContractInitializer"
import "NFTMetadata"
import "FlowtyDrops"

access(all) contract OpenEditionInitializer: ContractInitializer {
access(all) fun initialize(contractAcct: auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account, params: {String: AnyStruct}): NFTMetadata.InitializedCaps {
Expand All @@ -21,6 +22,43 @@ access(all) contract OpenEditionInitializer: ContractInitializer {

self.account.storage.save(cap, to: StoragePath(identifier: "metadataAuthAccount_".concat(contractName))!)

// do we have information to setup a drop as well?
log(params.keys)
if params.containsKey("dropDetails") && params.containsKey("phaseDetails") && params.containsKey("minterController") {
// extract expected keys
let minterCap = params["minterController"]! as! Capability<&{FlowtyDrops.Minter}>
let dropDetails = params["dropDetails"]! as! FlowtyDrops.DropDetails
let phaseDetails = params["phaseDetails"]! as! [FlowtyDrops.PhaseDetails]

log(dropDetails)
log(phaseDetails)

assert(minterCap.check(), message: "invalid minter capability")


let phases: @[FlowtyDrops.Phase] <- []
for p in phaseDetails {
phases.append(<- FlowtyDrops.createPhase(details: p))
}

let drop <- FlowtyDrops.createDrop(details: dropDetails, minterCap: minterCap, phases: <- phases)
if acct.storage.borrow<&AnyResource>(from: FlowtyDrops.ContainerStoragePath) == nil {
acct.storage.save(<- FlowtyDrops.createContainer(), to: FlowtyDrops.ContainerStoragePath)

acct.capabilities.unpublish(FlowtyDrops.ContainerPublicPath)
acct.capabilities.publish(
acct.capabilities.storage.issue<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerStoragePath),
at: FlowtyDrops.ContainerPublicPath
)
}

let container = acct.storage.borrow<auth(FlowtyDrops.Owner) &FlowtyDrops.Container>(from: FlowtyDrops.ContainerStoragePath)
?? panic("drops container not found")
container.addDrop(<- drop)
} else {
log("missing keys to setup drop")
}

return NFTMetadata.initialize(acct: acct, collectionInfo: collectionInfo, collectionType: self.getType())
}
}
7 changes: 4 additions & 3 deletions contracts/nft/OpenEditionNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ access(all) contract OpenEditionNFT: BaseCollection {

init(params: {String: AnyStruct}, initializeIdentifier: String) {
self.totalSupply = 0
self.MetadataCap = ContractBorrower.borrowInitializer(typeIdentifier: initializeIdentifier).initialize(contractAcct: self.account, params: params).pubCap

let minter <- create NFTMinter()
self.account.storage.save(<-minter, to: FlowtyDrops.getMinterStoragePath(type: self.getType()))
self.account.capabilities.storage.issue<&{FlowtyDrops.Minter}>(FlowtyDrops.getMinterStoragePath(type: self.getType()))
params["minterController"] = self.account.capabilities.storage.issue<&{FlowtyDrops.Minter}>(FlowtyDrops.getMinterStoragePath(type: self.getType()))

self.MetadataCap = ContractBorrower.borrowInitializer(typeIdentifier: initializeIdentifier).initialize(contractAcct: self.account, params: params).pubCap

}
}
6 changes: 3 additions & 3 deletions contracts/nft/OpenEditionTemplate.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ access(all) contract OpenEditionTemplate: ContractFactoryTemplate {
.concat("\n")
.concat(" init(params: {String: AnyStruct}, initializeIdentifier: String) {\n")
.concat(" self.totalSupply = 0\n")
.concat(" self.MetadataCap = ContractBorrower.borrowInitializer(typeIdentifier: initializeIdentifier).initialize(contractAcct: self.account, params: params).pubCap\n")
.concat("\n\n")
.concat(" let minter <- create NFTMinter()\n")
.concat(" self.account.storage.save(<-minter, to: FlowtyDrops.getMinterStoragePath(type: self.getType()))\n")
.concat(" self.account.capabilities.storage.issue<&{FlowtyDrops.Minter}>(FlowtyDrops.getMinterStoragePath(type: self.getType()))\n")
.concat(" params[\"minterController\"] = self.account.capabilities.storage.issue<&{FlowtyDrops.Minter}>(FlowtyDrops.getMinterStoragePath(type: self.getType()))\n")
.concat("\n\n")
.concat(" self.MetadataCap = ContractBorrower.borrowInitializer(typeIdentifier: initializeIdentifier).initialize(contractAcct: self.account, params: params).pubCap\n")
.concat(" }\n")
.concat("}\n")

Expand Down
4 changes: 4 additions & 0 deletions scripts/util/encode_data.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
access(all) fun main(data: {String: AnyStruct}): Bool {
log(data)
return true
}

0 comments on commit 60bd589

Please sign in to comment.