Skip to content

Commit

Permalink
sync drops contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Aug 28, 2024
1 parent 90ba66f commit b459a38
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 127 deletions.
32 changes: 29 additions & 3 deletions contracts/flowty-drops/ContractManager.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "FlowToken"
import "FungibleToken"
import "FungibleTokenRouter"

access(all) contract ContractManager {
access(all) let StoragePath: StoragePath
Expand All @@ -9,11 +10,24 @@ access(all) contract ContractManager {

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

access(all) let data: {String: AnyStruct}
access(all) let resources: @{String: AnyResource}

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

access(Manage) fun addOverride(type: Type, addr: Address) {
let router = self.routerCap.borrow() ?? panic("fungible token router is not valid")
router.addOverride(type: type, addr: addr)
}

access(Manage) fun getSwitchboard(): auth(FungibleTokenRouter.Owner) &FungibleTokenRouter.Router {
return self.routerCap.borrow()!
}

access(all) fun addFlowTokensToAccount(_ tokens: @FlowToken.Vault) {
self.acct.borrow()!.storage.borrow<&{FungibleToken.Receiver}>(from: /storage/flowTokenVault)!.deposit(from: <-tokens)
}
Expand All @@ -22,7 +36,7 @@ access(all) contract ContractManager {
return getAccount(self.acct.address)
}

init(tokens: @FlowToken.Vault) {
init(tokens: @FlowToken.Vault, defaultRouterAddress: Address) {
pre {
tokens.balance >= 0.001: "minimum balance of 0.001 required for initialization"
}
Expand All @@ -32,11 +46,23 @@ access(all) contract ContractManager {
assert(self.acct.check(), message: "failed to setup account capability")

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

let router <- FungibleTokenRouter.createRouter(defaultAddress: defaultRouterAddress)
acct.storage.save(<-router, to: FungibleTokenRouter.StoragePath)

let receiver = acct.capabilities.storage.issue<&{FungibleToken.Receiver}>(FungibleTokenRouter.StoragePath)
assert(receiver.check(), message: "invalid switchboard receiver capability")
acct.capabilities.publish(receiver, at: FungibleTokenRouter.PublicPath)

self.routerCap = acct.capabilities.storage.issue<auth(FungibleTokenRouter.Owner) &FungibleTokenRouter.Router>(FungibleTokenRouter.StoragePath)

self.data = {}
self.resources <- {}
}
}

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

init() {
Expand Down
12 changes: 6 additions & 6 deletions contracts/flowty-drops/DropFactory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "FungibleToken"
import "MetadataViews"

import "FlowtyDrops"
import "FlowtySwitchers"
import "FlowtyActiveCheckers"
import "FlowtyAddressVerifiers"
import "FlowtyPricers"

Expand All @@ -22,15 +22,15 @@ access(all) contract DropFactory {
}

// This drop is always on and never ends.
let switcher = FlowtySwitchers.AlwaysOn()
let activeChecker = FlowtyActiveCheckers.AlwaysOn()

// All addresses are allowed to participate
let addressVerifier = FlowtyAddressVerifiers.AllowAll(maxPerMint: 10)

// The cost of each mint is the same, and only permits one token type as payment
let pricer = FlowtyPricers.FlatPrice(price: price, paymentTokenType: paymentTokenType)

let phaseDetails = FlowtyDrops.PhaseDetails(switcher: switcher, display: nil, pricer: pricer, addressVerifier: addressVerifier)
let phaseDetails = FlowtyDrops.PhaseDetails(activeChecker: activeChecker, display: nil, pricer: pricer, addressVerifier: addressVerifier)
let phase <- FlowtyDrops.createPhase(details: phaseDetails)


Expand All @@ -54,16 +54,16 @@ access(all) contract DropFactory {
paymentTokenType.isSubtype(of: Type<@{FungibleToken.Vault}>()): "paymentTokenType must be a FungibleToken"
}

// This switcher turns on at a set unix timestamp (or is on by default if nil), and ends at the specified end date if provided
let switcher = FlowtySwitchers.TimestampSwitch(start: startUnix, end: endUnix)
// This ActiveChecker turns on at a set unix timestamp (or is on by default if nil), and ends at the specified end date if provided
let activeChecker = FlowtyActiveCheckers.TimestampChecker(start: startUnix, end: endUnix)

// All addresses are allowed to participate
let addressVerifier = FlowtyAddressVerifiers.AllowAll(maxPerMint: 10)

// The cost of each mint is the same, and only permits one token type as payment
let pricer = FlowtyPricers.FlatPrice(price: price, paymentTokenType: paymentTokenType)

let phaseDetails = FlowtyDrops.PhaseDetails(switcher: switcher, display: nil, pricer: pricer, addressVerifier: addressVerifier)
let phaseDetails = FlowtyDrops.PhaseDetails(activeChecker: activeChecker, display: nil, pricer: pricer, addressVerifier: addressVerifier)
let phase <- FlowtyDrops.createPhase(details: phaseDetails)

let nftType = CompositeType(nftTypeIdentifier) ?? panic("invalid nft type identifier")
Expand Down
18 changes: 11 additions & 7 deletions contracts/flowty-drops/DropTypes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ access(all) contract DropTypes {
access(all) let id: UInt64
access(all) let index: Int

access(all) let switcherType: String
access(all) let activeCheckerType: String
access(all) let pricerType: String
access(all) let addressVerifierType: String

Expand Down Expand Up @@ -124,15 +124,15 @@ access(all) contract DropTypes {
self.index = index
self.id = phase.uuid

let d = phase.getDetails()
self.switcherType = d.switcher.getType().identifier
let d: FlowtyDrops.PhaseDetails = phase.getDetails()
self.activeCheckerType = d.activeChecker.getType().identifier
self.pricerType = d.pricer.getType().identifier
self.addressVerifierType = d.addressVerifier.getType().identifier

self.hasStarted = d.switcher.hasStarted()
self.hasEnded = d.switcher.hasEnded()
self.start = d.switcher.getStart()
self.end = d.switcher.getEnd()
self.hasStarted = d.activeChecker.hasStarted()
self.hasEnded = d.activeChecker.hasEnded()
self.start = d.activeChecker.getStart()
self.end = d.activeChecker.getEnd()

self.paymentTypes = []
for pt in d.pricer.getPaymentTypes() {
Expand Down Expand Up @@ -259,6 +259,10 @@ access(all) contract DropTypes {
phaseSummaries.append(summary)
}

if CompositeType(dropDetails.nftType) == nil {
continue
}

summaries.append(DropSummary(
id: drop!.uuid,
display: dropDetails.display,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import "FlowtyDrops"

/*
This contract contains implementations for the FlowtyDrops.Switcher struct interface.
You can use these implementations, or your own, for switches when configuring a drop
This contract contains implementations for the FlowtyDrops.ActiveChecker struct interface.
You can use these implementations, or your own, to configure when a phase in a drop is active
*/
access(all) contract FlowtySwitchers {
access(all) contract FlowtyActiveCheckers {
/*
The AlwaysOn Switcher is always on and never ends.
The AlwaysOn ActiveChecker is always on and never ends.
*/
access(all) struct AlwaysOn: FlowtyDrops.Switcher {
access(all) struct AlwaysOn: FlowtyDrops.ActiveChecker {
access(all) view fun hasStarted(): Bool {
return true
}
Expand All @@ -27,10 +27,10 @@ access(all) contract FlowtySwitchers {
}

/*
The manual switcher is used to explicitly toggle a drop.
This version of switcher allows a creator to turn on or off a drop at will
The manual checker is used to explicitly toggle a drop.
This version of checker allows a creator to turn on or off a drop at will
*/
access(all) struct ManualSwitch: FlowtyDrops.Switcher {
access(all) struct ManualChecker: FlowtyDrops.ActiveChecker {
access(self) var started: Bool
access(self) var ended: Bool

Expand Down Expand Up @@ -65,10 +65,10 @@ access(all) contract FlowtySwitchers {
}

/*
TimestampSwitch uses block timestamps to determine if a phase or drop is live or not.
A timestamp switcher has a start and an end time.
TimestampChecker uses block timestamps to determine if a phase or drop is live or not.
A timestamp checker has a start and an end time.
*/
access(all) struct TimestampSwitch: FlowtyDrops.Switcher {
access(all) struct TimestampChecker: FlowtyDrops.ActiveChecker {
access(all) var start: UInt64?
access(all) var end: UInt64?

Expand Down
Loading

0 comments on commit b459a38

Please sign in to comment.