Skip to content

Commit

Permalink
BaseNFT interfaces and helper contracts (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline authored Jul 31, 2024
1 parent cc2c3c0 commit 54a12b2
Show file tree
Hide file tree
Showing 36 changed files with 1,648 additions and 396 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
coverage.lcov
coverage.lcov
.DS_Store
453 changes: 453 additions & 0 deletions 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": []
}
}
]
}
}
]
}
}
]
}
]
47 changes: 47 additions & 0 deletions contracts/ContractManager.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import "FlowToken"
import "FungibleToken"

access(all) contract ContractManager {
access(all) let StoragePath: StoragePath
access(all) let PublicPath: PublicPath

access(all) entitlement Manage

access(all) resource Manager {
access(self) let acct: Capability<auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account>

access(Manage) fun borrowContractAccount(): auth(Contracts) &Account {
return self.acct.borrow()!
}

access(all) fun addFlowTokensToAccount(_ tokens: @FlowToken.Vault) {
self.acct.borrow()!.storage.borrow<&{FungibleToken.Receiver}>(from: /storage/flowTokenVault)!.deposit(from: <-tokens)
}

access(all) fun getAccount(): &Account {
return getAccount(self.acct.address)
}

init(tokens: @FlowToken.Vault) {
pre {
tokens.balance >= 0.001: "minimum balance of 0.001 required for initialization"
}

let acct = Account(payer: ContractManager.account)
self.acct = acct.capabilities.account.issue<auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account>()
assert(self.acct.check(), message: "failed to setup account capability")

acct.storage.borrow<&{FungibleToken.Receiver}>(from: /storage/flowTokenVault)!.deposit(from: <-tokens)
}
}

access(all) fun createManager(tokens: @FlowToken.Vault): @Manager {
return <- create Manager(tokens: <- tokens)
}

init() {
let identifier = "ContractManager_".concat(self.account.address.toString())
self.StoragePath = StoragePath(identifier: identifier)!
self.PublicPath = PublicPath(identifier: identifier)!
}
}
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
23 changes: 17 additions & 6 deletions contracts/DropTypes.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "FlowtyDrops"
import "MetadataViews"
import "ViewResolver"
import "AddressUtils"

access(all) contract DropTypes {
access(all) struct Display {
Expand Down Expand Up @@ -156,13 +157,18 @@ access(all) contract DropTypes {
}
}

access(all) fun getDropSummary(contractAddress: Address, contractName: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifier: String?): DropSummary? {
access(all) fun getDropSummary(nftTypeIdentifier: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifier: String?): DropSummary? {
let nftType = CompositeType(nftTypeIdentifier) ?? panic("invalid nft type identifier")
let segments = nftTypeIdentifier.split(separator: ".")
let contractAddress = AddressUtils.parseAddress(nftType)!
let contractName = segments[2]

let resolver = getAccount(contractAddress).contracts.borrow<&{ViewResolver}>(name: contractName)
if resolver == nil {
return nil
}

let dropResolver = resolver!.resolveContractView(resourceType: nil, viewType: Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
let dropResolver = resolver!.resolveContractView(resourceType: nftType, viewType: Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
if dropResolver == nil {
return nil
}
Expand Down Expand Up @@ -201,21 +207,26 @@ 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
)

return dropSummary
}

access(all) fun getAllDropSummaries(contractAddress: Address, contractName: String, minter: Address?, quantity: Int?, paymentIdentifier: String?): [DropSummary] {
access(all) fun getAllDropSummaries(nftTypeIdentifier: String, minter: Address?, quantity: Int?, paymentIdentifier: String?): [DropSummary] {
let nftType = CompositeType(nftTypeIdentifier) ?? panic("invalid nft type identifier")
let segments = nftTypeIdentifier.split(separator: ".")
let contractAddress = AddressUtils.parseAddress(nftType)!
let contractName = segments[2]

let resolver = getAccount(contractAddress).contracts.borrow<&{ViewResolver}>(name: contractName)
if resolver == nil {
return []
}

let dropResolver = resolver!.resolveContractView(resourceType: nil, viewType: Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
let dropResolver = resolver!.resolveContractView(resourceType: nftType, viewType: Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
if dropResolver == nil {
return []
}
Expand Down Expand Up @@ -256,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
Loading

0 comments on commit 54a12b2

Please sign in to comment.