Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crescendo upgrade #18

Merged
merged 10 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install Flow dependencies
run: npm i
- name: Install Flow CLI
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.17.0
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/feature/stable-cadence/install.sh)"
- name: Run tests
run: sh ./run-tests.sh
- name: Upload coverage reports to Codecov
Expand Down
10 changes: 5 additions & 5 deletions contracts/DropFactory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import "FlowtyPricers"
/*
The DropFactory is a contract that helps create common types of drops
*/
pub contract DropFactory {
pub fun createEndlessOpenEditionDrop(
access(all) contract DropFactory {
access(all) fun createEndlessOpenEditionDrop(
price: UFix64,
paymentTokenType: Type,
dropDisplay: MetadataViews.Display,
minterCap: Capability<&{FlowtyDrops.Minter}>,
nftTypeIdentifier: String
): @FlowtyDrops.Drop {
pre {
paymentTokenType.isSubtype(of: Type<@FungibleToken.Vault>()): "paymentTokenType must be a FungibleToken"
paymentTokenType.isSubtype(of: Type<@{FungibleToken.Vault}>()): "paymentTokenType must be a FungibleToken"
}

// This drop is always on and never ends.
Expand All @@ -41,7 +41,7 @@ pub contract DropFactory {
return <- drop
}

pub fun createTimeBasedOpenEditionDrop(
access(all) fun createTimeBasedOpenEditionDrop(
price: UFix64,
paymentTokenType: Type,
dropDisplay: MetadataViews.Display,
Expand All @@ -51,7 +51,7 @@ pub contract DropFactory {
nftTypeIdentifier: String
): @FlowtyDrops.Drop {
pre {
paymentTokenType.isSubtype(of: Type<@FungibleToken.Vault>()): "paymentTokenType must be a FungibleToken"
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
Expand Down
92 changes: 46 additions & 46 deletions contracts/DropTypes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import "FlowtyDrops"
import "MetadataViews"
import "ViewResolver"

pub contract DropTypes {
pub struct Display {
pub let name: String
pub let description: String
pub let url: String
access(all) contract DropTypes {
access(all) struct Display {
access(all) let name: String
access(all) let description: String
access(all) let url: String

init(_ display: MetadataViews.Display) {
self.name = display.name
Expand All @@ -15,32 +15,32 @@ pub contract DropTypes {
}
}

pub struct Media {
pub let url: String
pub let mediaType: String
access(all) struct Media {
access(all) let url: String
access(all) let mediaType: String

init(_ media: MetadataViews.Media) {
self.url = media.file.uri()
self.mediaType = media.mediaType
}
}

pub struct DropSummary {
pub let id: UInt64
pub let display: Display
pub let medias: [Media]
pub let totalMinted: Int
pub let minterCount: Int
pub let commissionRate: UFix64
pub let nftType: String
access(all) struct DropSummary {
access(all) let id: UInt64
access(all) let display: Display
access(all) let medias: [Media]
access(all) let totalMinted: Int
access(all) let minterCount: Int
access(all) let commissionRate: UFix64
access(all) let nftType: String

pub let address: Address?
pub let mintedByAddress: Int?
access(all) let address: Address?
access(all) let mintedByAddress: Int?

pub let phases: [PhaseSummary]
access(all) let phases: [PhaseSummary]

pub let blockTimestamp: UInt64
pub let blockHeight: UInt64
access(all) let blockTimestamp: UInt64
access(all) let blockHeight: UInt64

init(
id: UInt64,
Expand Down Expand Up @@ -77,11 +77,11 @@ pub contract DropTypes {
}
}

pub struct Quote {
pub let price: UFix64
pub let quantity: Int
pub let paymentIdentifier: String
pub let minter: Address?
access(all) struct Quote {
access(all) let price: UFix64
access(all) let quantity: Int
access(all) let paymentIdentifier: String
access(all) let minter: Address?

init(price: UFix64, quantity: Int, paymentIdentifier: String, minter: Address?) {
self.price = price
Expand All @@ -91,25 +91,25 @@ pub contract DropTypes {
}
}

pub struct PhaseSummary {
pub let id: UInt64
pub let index: Int
access(all) struct PhaseSummary {
access(all) let id: UInt64
access(all) let index: Int

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

pub let hasStarted: Bool
pub let hasEnded: Bool
pub let start: UInt64?
pub let end: UInt64?
access(all) let hasStarted: Bool
access(all) let hasEnded: Bool
access(all) let start: UInt64?
access(all) let end: UInt64?

pub let paymentTypes: [String]
access(all) let paymentTypes: [String]

pub let address: Address?
pub let remainingForAddress: Int?
access(all) let address: Address?
access(all) let remainingForAddress: Int?

pub let quote: Quote?
access(all) let quote: Quote?

init(
index: Int,
Expand Down Expand Up @@ -156,13 +156,13 @@ pub contract DropTypes {
}
}

pub fun getDropSummary(contractAddress: Address, contractName: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifier: String?): DropSummary? {
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName)
access(all) fun getDropSummary(contractAddress: Address, contractName: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifier: String?): DropSummary? {
let resolver = getAccount(contractAddress).contracts.borrow<&{ViewResolver}>(name: contractName)
if resolver == nil {
return nil
}

let dropResolver = resolver!.resolveView(Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
let dropResolver = resolver!.resolveContractView(resourceType: nil, viewType: Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
if dropResolver == nil {
return nil
}
Expand Down Expand Up @@ -209,13 +209,13 @@ pub contract DropTypes {
return dropSummary
}

pub fun getAllDropSummaries(contractAddress: Address, contractName: String, minter: Address?, quantity: Int?, paymentIdentifier: String?): [DropSummary] {
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName)
access(all) fun getAllDropSummaries(contractAddress: Address, contractName: String, minter: Address?, quantity: Int?, paymentIdentifier: String?): [DropSummary] {
let resolver = getAccount(contractAddress).contracts.borrow<&{ViewResolver}>(name: contractName)
if resolver == nil {
return []
}

let dropResolver = resolver!.resolveView(Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
let dropResolver = resolver!.resolveContractView(resourceType: nil, viewType: Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
if dropResolver == nil {
return []
}
Expand Down
20 changes: 10 additions & 10 deletions contracts/FlowtyAddressVerifiers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import "FlowtyDrops"
/*
This contract contains implementations of the FlowtyDrops.AddressVerifier struct interface
*/
pub contract FlowtyAddressVerifiers {
access(all) contract FlowtyAddressVerifiers {
/*
The AllowAll AddressVerifier allows any address to mint without any verification
*/
pub struct AllowAll: FlowtyDrops.AddressVerifier {
pub var maxPerMint: Int
access(all) struct AllowAll: FlowtyDrops.AddressVerifier {
access(all) var maxPerMint: Int

pub fun canMint(addr: Address, num: Int, totalMinted: Int, data: {String: AnyStruct}): Bool {
access(all) view fun canMint(addr: Address, num: Int, totalMinted: Int, data: {String: AnyStruct}): Bool {
return num <= self.maxPerMint
}

pub fun setMaxPerMint(_ value: Int) {
access(Mutate) fun setMaxPerMint(_ value: Int) {
self.maxPerMint = value
}

Expand All @@ -31,29 +31,29 @@ pub contract FlowtyAddressVerifiers {
The AllowList Verifier only lets a configured set of addresses participate in a drop phase. The number
of mints per address is specified to allow more granular control of what each address is permitted to do.
*/
pub struct AllowList: FlowtyDrops.AddressVerifier {
access(all) struct AllowList: FlowtyDrops.AddressVerifier {
access(self) let allowedAddresses: {Address: Int}

pub fun canMint(addr: Address, num: Int, totalMinted: Int, data: {String: AnyStruct}): Bool {
access(all) view fun canMint(addr: Address, num: Int, totalMinted: Int, data: {String: AnyStruct}): Bool {
if let allowedMints = self.allowedAddresses[addr] {
return allowedMints >= num + totalMinted
}

return false
}

pub fun remainingForAddress(addr: Address, totalMinted: Int): Int? {
access(all) view fun remainingForAddress(addr: Address, totalMinted: Int): Int? {
if let allowedMints = self.allowedAddresses[addr] {
return allowedMints - totalMinted
}
return nil
}

pub fun setAddress(addr: Address, value: Int) {
access(Mutate) fun setAddress(addr: Address, value: Int) {
self.allowedAddresses[addr] = value
}

pub fun removeAddress(addr: Address) {
access(Mutate) fun removeAddress(addr: Address) {
self.allowedAddresses.remove(key: addr)
}

Expand Down
Loading
Loading