diff --git a/README.md b/README.md index 56537f9..995ffea 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ FlowtyDrops is made up of a few core resources and structs: 3. @Container - Holds Drop resources in it. 4. @{Minter} - A resource interface that creators can implement to be compatible with FlowtyDrops. When constructing a drop, you must supply a `Capability<&{Minter}>` to it. -5. {Switch} - A struct interface that is responsible for whether a phase is active or not. For example, one implementation could be configured +5. {Switcher} - A struct interface that is responsible for whether a phase is active or not. For example, one implementation could be configured to start a phase at a time in the future, while another could turn start based on block height. 6. {AddressVerifier} - A struct interface that is responsible for determining if an account is permitted to mint or not. For example, one implementation might permit any account to mint as many as it wants, while another might check an allow-list. @@ -38,7 +38,7 @@ FlowtyDrops is made up of a few core resources and structs: are responsible for handling how much an attempted mint should cost. For example, you might make a drop free, or might configure a drop to be a flat fee regardless of how many are being minted at once. -5. FlowtySwitches - Implementations of the Switch struct interface. - Switch are responsible for flagging if a drop is live or not. For +5. FlowtySwitchers - Implementations of the Switcher struct interface. + Switchers are responsible for flagging if a drop is live or not. For example, a drop might go live a certain unix timestamp and end at a future date, or it might be on perpetually until manually turned off. \ No newline at end of file diff --git a/contracts/DropFactory.cdc b/contracts/DropFactory.cdc index afdff2a..c9b154d 100644 --- a/contracts/DropFactory.cdc +++ b/contracts/DropFactory.cdc @@ -2,7 +2,7 @@ import "FungibleToken" import "MetadataViews" import "FlowtyDrops" -import "FlowtySwitches" +import "FlowtySwitchers" import "FlowtyAddressVerifiers" import "FlowtyPricers" @@ -21,7 +21,7 @@ pub contract DropFactory { } // This drop is always on and never ends. - let switch = FlowtySwitches.AlwaysOn() + let switcher = FlowtySwitchers.AlwaysOn() // All addresses are allowed to participate let addressVerifier = FlowtyAddressVerifiers.AllowAll(maxPerMint: 10) @@ -29,7 +29,7 @@ pub contract DropFactory { // 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(switch: switch, display: nil, pricer: pricer, addressVerifier: addressVerifier) + let phaseDetails = FlowtyDrops.PhaseDetails(switcher: switcher, display: nil, pricer: pricer, addressVerifier: addressVerifier) let phase <- FlowtyDrops.createPhase(details: phaseDetails) let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05) @@ -50,8 +50,8 @@ pub contract DropFactory { paymentTokenType.isSubtype(of: Type<@FungibleToken.Vault>()): "paymentTokenType must be a FungibleToken" } - // This switch turns on at a set unix timestamp (or is on by default if nil), and ends at the specified end date if provided - let switch = FlowtySwitches.TimestampSwitch(start: startUnix, end: endUnix) + // 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) // All addresses are allowed to participate let addressVerifier = FlowtyAddressVerifiers.AllowAll(maxPerMint: 10) @@ -59,7 +59,7 @@ pub contract DropFactory { // 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(switch: switch, display: nil, pricer: pricer, addressVerifier: addressVerifier) + let phaseDetails = FlowtyDrops.PhaseDetails(switcher: switcher, display: nil, pricer: pricer, addressVerifier: addressVerifier) let phase <- FlowtyDrops.createPhase(details: phaseDetails) let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05) diff --git a/contracts/FlowtyDrops.cdc b/contracts/FlowtyDrops.cdc index c12b513..8967e67 100644 --- a/contracts/FlowtyDrops.cdc +++ b/contracts/FlowtyDrops.cdc @@ -112,8 +112,8 @@ pub contract FlowtyDrops { var count = 0 while count < self.phases.length { let ref = self.borrowPhasePublic(index: count) - let switch = ref.getDetails().switch - if switch.hasStarted() && !switch.hasEnded() { + let switcher = ref.getDetails().switcher + if switcher.hasStarted() && !switcher.hasEnded() { arr.append(ref) } @@ -141,7 +141,7 @@ pub contract FlowtyDrops { dropAddress: self.owner!.address, id: phase.uuid, index: self.phases.length, - switcherType: phase.details.switch.getType().identifier, + switcherType: phase.details.switcher.getType().identifier, pricerType: phase.details.pricer.getType().identifier, addressVerifierType: phase.details.addressVerifier.getType().identifier ) @@ -203,13 +203,13 @@ pub contract FlowtyDrops { } } - // A switch represents a phase being on or off, and holds information + // A switcher represents a phase being on or off, and holds information // about whether a phase has started or not. - pub struct interface Switch { - // Signal that a phase has started. If the phase has not ended, it means that this switch's phase + pub struct interface Switcher { + // Signal that a phase has started. If the phase has not ended, it means that this switcher's phase // is active pub fun hasStarted(): Bool - // Signal that a phase has ended. If a switch has ended, minting will not work. That could mean + // Signal that a phase has ended. If a switcher has ended, minting will not work. That could mean // the drop is over, or it could mean another phase has begun. pub fun hasEnded(): Bool @@ -225,15 +225,15 @@ pub contract FlowtyDrops { // returns whether this phase of a drop has started. pub fun isActive(): Bool { - return self.details.switch.hasStarted() && !self.details.switch.hasEnded() + return self.details.switcher.hasStarted() && !self.details.switcher.hasEnded() } pub fun getDetails(): PhaseDetails { return self.details } - pub fun borrowSwitchAuth(): auth &{Switch} { - return &self.details.switch as! auth &{Switch} + pub fun borrowSwitchAuth(): auth &{Switcher} { + return &self.details.switcher as! auth &{Switcher} } pub fun borrowPricerAuth(): auth &{Pricer} { @@ -261,7 +261,7 @@ pub contract FlowtyDrops { pub struct PhaseDetails { // handles whether a phase is on or not - pub let switch: {Switch} + pub let switcher: {Switcher} // display information about a phase pub let display: MetadataViews.Display? @@ -275,8 +275,8 @@ pub contract FlowtyDrops { // placecholder data dictionary to allow new fields to be accessed pub let data: {String: AnyStruct} - init(switch: {Switch}, display: MetadataViews.Display?, pricer: {Pricer}, addressVerifier: {AddressVerifier}) { - self.switch = switch + init(switcher: {Switcher}, display: MetadataViews.Display?, pricer: {Pricer}, addressVerifier: {AddressVerifier}) { + self.switcher = switcher self.display = display self.pricer = pricer self.addressVerifier = addressVerifier @@ -303,7 +303,7 @@ pub contract FlowtyDrops { pub resource interface Minter { pub fun mint(payment: @FungibleToken.Vault, amount: Int, phase: &Phase, data: {String: AnyStruct}): @[NonFungibleToken.NFT] { post { - phase.details.switch.hasStarted() && !phase.details.switch.hasEnded(): "phase is not active" + phase.details.switcher.hasStarted() && !phase.details.switcher.hasEnded(): "phase is not active" result.length == amount: "incorrect number of items returned" } } @@ -348,8 +348,8 @@ pub contract FlowtyDrops { name: details.display.name, description: details.display.description, imageUrl: details.display.thumbnail.uri(), - start: firstPhaseDetails.switch.getStart(), - end: firstPhaseDetails.switch.getEnd() + start: firstPhaseDetails.switcher.getStart(), + end: firstPhaseDetails.switcher.getEnd() ) destroy self.drops.insert(key: drop.uuid, <-drop) } diff --git a/contracts/FlowtySwitches.cdc b/contracts/FlowtySwitchers.cdc similarity index 82% rename from contracts/FlowtySwitches.cdc rename to contracts/FlowtySwitchers.cdc index 2749ab5..fc0178b 100644 --- a/contracts/FlowtySwitches.cdc +++ b/contracts/FlowtySwitchers.cdc @@ -1,14 +1,14 @@ import "FlowtyDrops" /* -This contract contains implementations for the FlowtyDrops.Switch struct interface. +This contract contains implementations for the FlowtyDrops.Switcher struct interface. You can use these implementations, or your own, for switches when configuring a drop */ -pub contract FlowtySwitches { +pub contract FlowtySwitchers { /* - The AlwaysOn Switch is always on and never ends. + The AlwaysOn Switcher is always on and never ends. */ - pub struct AlwaysOn: FlowtyDrops.Switch { + pub struct AlwaysOn: FlowtyDrops.Switcher { pub fun hasStarted(): Bool { return true } @@ -27,10 +27,10 @@ pub contract FlowtySwitches { } /* - The manual switch is used to explicitly toggle a drop. - This version of switch allows a creator to turn on or off a drop at will + 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 */ - pub struct ManualSwitch: FlowtyDrops.Switch { + pub struct ManualSwitch: FlowtyDrops.Switcher { access(self) var started: Bool access(self) var ended: Bool @@ -66,9 +66,9 @@ pub contract FlowtySwitches { /* TimestampSwitch uses block timestamps to determine if a phase or drop is live or not. - A timestamp switch has a start and an end time. + A timestamp switcher has a start and an end time. */ - pub struct TimestampSwitch: FlowtyDrops.Switch { + pub struct TimestampSwitch: FlowtyDrops.Switcher { pub var start: UInt64? pub var end: UInt64? diff --git a/contracts/nft/OpenEditionNFT.cdc b/contracts/nft/OpenEditionNFT.cdc index 0fa4953..4829f63 100644 --- a/contracts/nft/OpenEditionNFT.cdc +++ b/contracts/nft/OpenEditionNFT.cdc @@ -17,7 +17,7 @@ import "FlowToken" import "ExampleToken" import "FlowtyDrops" -import "FlowtySwitches" +import "FlowtySwitchers" import "FlowtyAddressVerifiers" import "FlowtyPricers" import "DropFactory" diff --git a/flow.json b/flow.json index 7e4e308..a3b21b9 100644 --- a/flow.json +++ b/flow.json @@ -61,8 +61,8 @@ "testing": "0x0000000000000006" } }, - "FlowtySwitches": { - "source": "./contracts/FlowtySwitches.cdc", + "FlowtySwitchers": { + "source": "./contracts/FlowtySwitchers.cdc", "aliases": { "testing": "0x0000000000000006" } @@ -144,7 +144,7 @@ "emulator": { "emulator-account": [ "FlowtyDrops", - "FlowtySwitches", + "FlowtySwitchers", "FlowtyAddressVerifiers", "FlowtyPricers", "DropFactory", @@ -165,7 +165,7 @@ "testnet": { "flowty-drops-testnet": [ "FlowtyDrops", - "FlowtySwitches", + "FlowtySwitchers", "FlowtyAddressVerifiers", "FlowtyPricers", "DropFactory" diff --git a/scripts/has_phase_ended.cdc b/scripts/has_phase_ended.cdc index 24ea213..20a81c3 100644 --- a/scripts/has_phase_ended.cdc +++ b/scripts/has_phase_ended.cdc @@ -15,5 +15,5 @@ pub fun main(contractAddress: Address, contractName: String, dropID: UInt64, pha let phase = drop.borrowPhasePublic(index: phaseIndex) - return phase.getDetails().switch.hasEnded() + return phase.getDetails().switcher.hasEnded() } \ No newline at end of file diff --git a/scripts/has_phase_started.cdc b/scripts/has_phase_started.cdc index f30f637..74506b8 100644 --- a/scripts/has_phase_started.cdc +++ b/scripts/has_phase_started.cdc @@ -15,5 +15,5 @@ pub fun main(contractAddress: Address, contractName: String, dropID: UInt64, pha let phase = drop.borrowPhasePublic(index: phaseIndex) - return phase.getDetails().switch.hasStarted() + return phase.getDetails().switcher.hasStarted() } \ No newline at end of file diff --git a/scripts/import_all.cdc b/scripts/import_all.cdc index 00bdadf..e0e5b11 100644 --- a/scripts/import_all.cdc +++ b/scripts/import_all.cdc @@ -1,6 +1,6 @@ import "FlowtyDrops" import "FlowtyAddressVerifiers" -import "FlowtySwitches" +import "FlowtySwitchers" import "FlowtyPricers" import "OpenEditionNFT" diff --git a/tests/FlowtySwitches_tests.cdc b/tests/FlowtySwitches_tests.cdc index 46cf47c..ca19c52 100644 --- a/tests/FlowtySwitches_tests.cdc +++ b/tests/FlowtySwitches_tests.cdc @@ -1,29 +1,29 @@ import Test import "test_helpers.cdc" -import "FlowtySwitches" +import "FlowtySwitchers" pub fun setup() { deployAll() } -pub fun test_FlowtySwitches_AlwaysOn() { - let s = FlowtySwitches.AlwaysOn() - Test.assert(s.hasStarted(), message: "AlwaysOn switch should always be started") - Test.assert(!s.hasEnded(), message: "AlwaysOn switch never ends") +pub fun test_FlowtySwitchers_AlwaysOn() { + let s = FlowtySwitchers.AlwaysOn() + Test.assert(s.hasStarted(), message: "AlwaysOn switcher should always be started") + Test.assert(!s.hasEnded(), message: "AlwaysOn switcher never ends") Test.assertEqual(nil, s.getStart()) Test.assertEqual(nil, s.getEnd()) } -pub fun test_FlowtySwitches_ManualSwitch() { - let s = FlowtySwitches.ManualSwitch() +pub fun test_FlowtySwitchers_ManualSwitch() { + let s = FlowtySwitchers.ManualSwitch() Test.assertEqual(false, s.hasStarted()) Test.assertEqual(false, s.hasEnded()) Test.assertEqual(nil, s.getStart()) Test.assertEqual(nil, s.getEnd()) - // now turn the switch on + // now turn the switcher on s.setStarted(true) Test.assertEqual(true, s.hasStarted()) Test.assertEqual(false, s.hasEnded()) @@ -33,9 +33,9 @@ pub fun test_FlowtySwitches_ManualSwitch() { Test.assertEqual(true, s.hasEnded()) } -pub fun test_FlowtySwitches_TimestampSwitch_StartIsNil() { +pub fun test_FlowtySwitchers_TimestampSwitch_StartIsNil() { let end = UInt64(getCurrentBlock().timestamp) + 10 - let s = FlowtySwitches.TimestampSwitch(start: nil, end: end) + let s = FlowtySwitchers.TimestampSwitch(start: nil, end: end) Test.assertEqual(true, s.hasStarted()) Test.assertEqual(nil, s.getStart()) @@ -44,10 +44,10 @@ pub fun test_FlowtySwitches_TimestampSwitch_StartIsNil() { Test.assertEqual(end, s.getEnd()!) } -pub fun test_FlowtySwitches_TimestampSwitch_StartAfterNow() { +pub fun test_FlowtySwitchers_TimestampSwitch_StartAfterNow() { let start = UInt64(getCurrentBlock().timestamp) + 1 let end = UInt64(getCurrentBlock().timestamp) + 10 - let s = FlowtySwitches.TimestampSwitch(start: start, end: end) + let s = FlowtySwitchers.TimestampSwitch(start: start, end: end) Test.assertEqual(false, s.hasStarted()) Test.assertEqual(start, s.getStart()!) @@ -56,10 +56,10 @@ pub fun test_FlowtySwitches_TimestampSwitch_StartAfterNow() { Test.assertEqual(end, s.getEnd()!) } -pub fun test_FlowtySwitches_TimestampSwitch_StartBeforeNow() { +pub fun test_FlowtySwitchers_TimestampSwitch_StartBeforeNow() { let start = UInt64(getCurrentBlock().timestamp) - 1 let end = UInt64(getCurrentBlock().timestamp) + 10 - let s = FlowtySwitches.TimestampSwitch(start: start, end: end) + let s = FlowtySwitchers.TimestampSwitch(start: start, end: end) Test.assertEqual(true, s.hasStarted()) Test.assertEqual(start, s.getStart()!) @@ -68,20 +68,20 @@ pub fun test_FlowtySwitches_TimestampSwitch_StartBeforeNow() { Test.assertEqual(end, s.getEnd()!) } -pub fun test_FlowtySwitches_TimestampSwitch_Ended() { +pub fun test_FlowtySwitchers_TimestampSwitch_Ended() { let start = UInt64(getCurrentBlock().timestamp) - 10 let end = UInt64(getCurrentBlock().timestamp) - 1 - let s = FlowtySwitches.TimestampSwitch(start: start, end: end) + let s = FlowtySwitchers.TimestampSwitch(start: start, end: end) Test.assertEqual(true, s.hasStarted()) Test.assertEqual(true, s.hasEnded()) } -pub fun test_FlowtySwitches_TimestampSwitch_InvalidStartEnd() { +pub fun test_FlowtySwitchers_TimestampSwitch_InvalidStartEnd() { let start: UInt64 = 10 let end: UInt64 = 9 Test.expectFailure(fun() { - FlowtySwitches.TimestampSwitch(start: start, end: end) + FlowtySwitchers.TimestampSwitch(start: start, end: end) }, errorMessageSubstring: "start must be less than end") } \ No newline at end of file diff --git a/tests/test_helpers.cdc b/tests/test_helpers.cdc index ed0c02d..4ec24ff 100644 --- a/tests/test_helpers.cdc +++ b/tests/test_helpers.cdc @@ -165,7 +165,7 @@ pub fun deployAll() { deploy("ExampleToken", "../contracts/standard/ExampleToken.cdc", []) deploy("FlowtyDrops", "../contracts/FlowtyDrops.cdc", []) - deploy("FlowtySwitches", "../contracts/FlowtySwitches.cdc", []) + deploy("FlowtySwitchers", "../contracts/FlowtySwitchers.cdc", []) deploy("FlowtyPricers", "../contracts/FlowtyPricers.cdc", []) deploy("FlowtyAddressVerifiers", "../contracts/FlowtyAddressVerifiers.cdc", []) deploy("DropFactory", "../contracts/DropFactory.cdc", []) diff --git a/transactions/drops/add_free_phase.cdc b/transactions/drops/add_free_phase.cdc index fc72f60..8e6502b 100644 --- a/transactions/drops/add_free_phase.cdc +++ b/transactions/drops/add_free_phase.cdc @@ -8,7 +8,7 @@ transaction(dropID: UInt64, start: UInt64?, end: UInt64?) { let drop = container.borrowDrop(id: dropID) ?? panic("drop not found") let firstPhase = drop.borrowPhase(index: 0) - let details = FlowtyDrops.PhaseDetails(switch: firstPhase.details.switch, display: firstPhase.details.display, pricer: FlowtyPricers.Free(), addressVerifier: firstPhase.details.addressVerifier) + let details = FlowtyDrops.PhaseDetails(switcher: firstPhase.details.switcher, display: firstPhase.details.display, pricer: FlowtyPricers.Free(), addressVerifier: firstPhase.details.addressVerifier) let phase <- FlowtyDrops.createPhase(details: details) drop.addPhase(<- phase) diff --git a/transactions/drops/edit_timebased_phase_start_and_end.cdc b/transactions/drops/edit_timebased_phase_start_and_end.cdc index 90e9157..66ff1c4 100644 --- a/transactions/drops/edit_timebased_phase_start_and_end.cdc +++ b/transactions/drops/edit_timebased_phase_start_and_end.cdc @@ -1,5 +1,5 @@ import "FlowtyDrops" -import "FlowtySwitches" +import "FlowtySwitchers" transaction(dropID: UInt64, phaseIndex: Int, start: UInt64?, end: UInt64?) { prepare(acct: AuthAccount) { @@ -7,7 +7,7 @@ transaction(dropID: UInt64, phaseIndex: Int, start: UInt64?, end: UInt64?) { ?? panic("container not found") let drop = container.borrowDrop(id: dropID) ?? panic("drop not found") let phase = drop.borrowPhase(index: phaseIndex) - let s = phase.borrowSwitchAuth() as! auth &FlowtySwitches.TimestampSwitch + let s = phase.borrowSwitchAuth() as! auth &FlowtySwitchers.TimestampSwitch s.setStart(start: start) s.setEnd(end: end) diff --git a/transactions/drops/remove_last_phase.cdc b/transactions/drops/remove_last_phase.cdc index 2da0a29..13d194d 100644 --- a/transactions/drops/remove_last_phase.cdc +++ b/transactions/drops/remove_last_phase.cdc @@ -8,7 +8,7 @@ transaction(dropID: UInt64, start: UInt64?, end: UInt64?) { let drop = container.borrowDrop(id: dropID) ?? panic("drop not found") let firstPhase = drop.borrowPhase(index: 0) - let details = FlowtyDrops.PhaseDetails(switch: firstPhase.details.switch, display: firstPhase.details.display, pricer: FlowtyPricers.Free(), addressVerifier: firstPhase.details.addressVerifier) + let details = FlowtyDrops.PhaseDetails(switcher: firstPhase.details.switcher, display: firstPhase.details.display, pricer: FlowtyPricers.Free(), addressVerifier: firstPhase.details.addressVerifier) let phases = drop.borrowAllPhases() destroy drop.removePhase(index: phases.length - 1)