Skip to content

Commit

Permalink
Add per token fee to value calculation for old minters (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshka authored Oct 14, 2023
1 parent 612cf6b commit c4fbc1f
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-radios-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@soundxyz/sdk': major
---

Add per token fee to value calculation for old minters
14 changes: 12 additions & 2 deletions packages/sdk/src/client/edition/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ async function mintHelper(
}
}

const value = mintSchedule.price
.add(mintSchedule.platformPerTokenFee)
.mul(quantity)
.add(mintSchedule.platformPerTransactionFee)

const txnOverrides: PayableOverrides = {
value: mintSchedule.price.mul(quantity).add(mintSchedule.platformTransactionFee),
value,
gasLimit,
maxFeePerGas,
maxPriorityFeePerGas,
Expand Down Expand Up @@ -250,8 +255,13 @@ async function mintToHelper(
}
}

const value = mintSchedule.price
.add(mintSchedule.platformPerTokenFee)
.mul(quantity)
.add(mintSchedule.platformPerTransactionFee)

const txnOverrides: PayableOverrides = {
value: mintSchedule.price.mul(quantity).add(mintSchedule.platformTransactionFee),
value,
gasLimit,
maxFeePerGas,
maxPriorityFeePerGas,
Expand Down
127 changes: 117 additions & 10 deletions packages/sdk/src/client/edition/schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import {
HANDLED_MINTER_INTERFACE_IDS,
type MinterInterfaceId,
type MintSchedule,
type RangeEditionV1Schedule,
type RangeEditionV2Schedule,
type RangeEditionV2_1Schedule,
type MerkleDropV1Schedule,
type MerkleDropV2Schedule,
type MerkleDropV2_1Schedule,
} from '../../types'
import { minterFactoryMap } from '../../utils/constants'
import { LazyPromise } from '../../utils/promise'
Expand Down Expand Up @@ -208,8 +214,64 @@ export async function mintInfosFromMinter(
}

switch (interfaceId) {
case interfaceIds.IRangeEditionMinter:
case interfaceIds.IRangeEditionMinterV2:
case interfaceIds.IRangeEditionMinter: {
const minterContract = minterFactoryMap[interfaceId].connect(minterAddress, await signerOrProvider)
const mintSchedule = await minterContract.mintInfo(editionAddress, mintId)
return {
mintType: 'RangeEdition',
interfaceId,
mintId,
editionAddress,
minterAddress,
startTime: mintSchedule.startTime,
endTime: mintSchedule.endTime,
mintPaused: mintSchedule.mintPaused,
price: mintSchedule.price,
maxMintableLower: mintSchedule.maxMintableLower,
maxMintableUpper: mintSchedule.maxMintableUpper,
cutoffTime: mintSchedule.cutoffTime,
maxMintable: (unixTimestamp?: number) =>
(unixTimestamp || Math.floor(Date.now() / 1000)) < mintSchedule.cutoffTime
? mintSchedule.maxMintableUpper
: mintSchedule.maxMintableLower,
maxMintablePerAccount: mintSchedule.maxMintablePerAccount,
totalMinted: mintSchedule.totalMinted,
affiliateFeeBPS: mintSchedule.affiliateFeeBPS,
platformPerTokenFee: BigNumber.from(0),
platformPerTransactionFee: BigNumber.from(0),
} satisfies RangeEditionV1Schedule
}
case interfaceIds.IRangeEditionMinterV2: {
const minterContract = minterFactoryMap[interfaceId].connect(minterAddress, await signerOrProvider)
const [mintSchedule, platformPerTokenFee] = await Promise.all([
minterContract.mintInfo(editionAddress, mintId),
minterContract.platformFlatFee(),
])
return {
mintType: 'RangeEdition',
interfaceId,
mintId,
editionAddress,
minterAddress,
startTime: mintSchedule.startTime,
endTime: mintSchedule.endTime,
mintPaused: mintSchedule.mintPaused,
price: mintSchedule.price,
maxMintableLower: mintSchedule.maxMintableLower,
maxMintableUpper: mintSchedule.maxMintableUpper,
cutoffTime: mintSchedule.cutoffTime,
maxMintable: (unixTimestamp?: number) =>
(unixTimestamp || Math.floor(Date.now() / 1000)) < mintSchedule.cutoffTime
? mintSchedule.maxMintableUpper
: mintSchedule.maxMintableLower,
maxMintablePerAccount: mintSchedule.maxMintablePerAccount,
totalMinted: mintSchedule.totalMinted,
affiliateFeeBPS: mintSchedule.affiliateFeeBPS,
platformPerTokenFee,
platformPerTransactionFee: BigNumber.from(0),
} satisfies RangeEditionV2Schedule
}

case interfaceIds.IRangeEditionMinterV2_1: {
const minterContract = minterFactoryMap[interfaceId].connect(minterAddress, await signerOrProvider)
const mintSchedule = await minterContract.mintInfo(editionAddress, mintId)
Expand All @@ -233,13 +295,58 @@ export async function mintInfosFromMinter(
maxMintablePerAccount: mintSchedule.maxMintablePerAccount,
totalMinted: mintSchedule.totalMinted,
affiliateFeeBPS: mintSchedule.affiliateFeeBPS,
platformTransactionFee:
'platformPerTxFlatFee' in mintSchedule ? mintSchedule.platformPerTxFlatFee : BigNumber.from(0),
}
platformPerTokenFee: mintSchedule.platformFlatFee,
platformPerTransactionFee: mintSchedule.platformPerTxFlatFee,
} satisfies RangeEditionV2_1Schedule
}

case interfaceIds.IMerkleDropMinter:
case interfaceIds.IMerkleDropMinterV2:
case interfaceIds.IMerkleDropMinter: {
const minterContract = minterFactoryMap[interfaceId].connect(minterAddress, await signerOrProvider)
const mintSchedule = await minterContract.mintInfo(editionAddress, mintId)
return {
mintType: 'MerkleDrop',
interfaceId,
mintId,
merkleRoot: mintSchedule.merkleRootHash,
editionAddress,
minterAddress,
startTime: mintSchedule.startTime,
endTime: mintSchedule.endTime,
mintPaused: mintSchedule.mintPaused,
price: mintSchedule.price,
maxMintable: mintSchedule.maxMintable,
maxMintablePerAccount: mintSchedule.maxMintablePerAccount,
totalMinted: mintSchedule.totalMinted,
affiliateFeeBPS: mintSchedule.affiliateFeeBPS,
platformPerTokenFee: BigNumber.from(0),
platformPerTransactionFee: BigNumber.from(0),
} satisfies MerkleDropV1Schedule
}
case interfaceIds.IMerkleDropMinterV2: {
const minterContract = minterFactoryMap[interfaceId].connect(minterAddress, await signerOrProvider)
const [mintSchedule, platformPerTokenFee] = await Promise.all([
minterContract.mintInfo(editionAddress, mintId),
minterContract.platformFlatFee(),
])
return {
mintType: 'MerkleDrop',
interfaceId,
mintId,
merkleRoot: mintSchedule.merkleRootHash,
editionAddress,
minterAddress,
startTime: mintSchedule.startTime,
endTime: mintSchedule.endTime,
mintPaused: mintSchedule.mintPaused,
price: mintSchedule.price,
maxMintable: mintSchedule.maxMintable,
maxMintablePerAccount: mintSchedule.maxMintablePerAccount,
totalMinted: mintSchedule.totalMinted,
affiliateFeeBPS: mintSchedule.affiliateFeeBPS,
platformPerTokenFee,
platformPerTransactionFee: BigNumber.from(0),
} satisfies MerkleDropV2Schedule
}
case interfaceIds.IMerkleDropMinterV2_1: {
const minterContract = minterFactoryMap[interfaceId].connect(minterAddress, await signerOrProvider)
const mintSchedule = await minterContract.mintInfo(editionAddress, mintId)
Expand All @@ -258,9 +365,9 @@ export async function mintInfosFromMinter(
maxMintablePerAccount: mintSchedule.maxMintablePerAccount,
totalMinted: mintSchedule.totalMinted,
affiliateFeeBPS: mintSchedule.affiliateFeeBPS,
platformTransactionFee:
'platformPerTxFlatFee' in mintSchedule ? mintSchedule.platformPerTxFlatFee : BigNumber.from(0),
}
platformPerTokenFee: mintSchedule.platformFlatFee,
platformPerTransactionFee: mintSchedule.platformPerTxFlatFee,
} satisfies MerkleDropV2_1Schedule
}

default: {
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export interface MintScheduleBase {
maxMintablePerAccount: number
totalMinted: number
affiliateFeeBPS: number
platformTransactionFee: BigNumber
platformPerTransactionFee: BigNumber
platformPerTokenFee: BigNumber
}

export const HANDLED_MINTER_INTERFACE_IDS = [
Expand Down

0 comments on commit c4fbc1f

Please sign in to comment.