From c4fbc1f5ee712da3b6eb856abae45f6d892f1491 Mon Sep 17 00:00:00 2001 From: Vignesh Hirudayakanth Date: Fri, 13 Oct 2023 18:04:26 -0700 Subject: [PATCH] Add per token fee to value calculation for old minters (#275) --- .changeset/calm-radios-speak.md | 5 + packages/sdk/src/client/edition/mint.ts | 14 +- packages/sdk/src/client/edition/schedules.ts | 127 +++++++++++++++++-- packages/sdk/src/types.ts | 3 +- 4 files changed, 136 insertions(+), 13 deletions(-) create mode 100644 .changeset/calm-radios-speak.md diff --git a/.changeset/calm-radios-speak.md b/.changeset/calm-radios-speak.md new file mode 100644 index 00000000..cd327ab7 --- /dev/null +++ b/.changeset/calm-radios-speak.md @@ -0,0 +1,5 @@ +--- +'@soundxyz/sdk': major +--- + +Add per token fee to value calculation for old minters diff --git a/packages/sdk/src/client/edition/mint.ts b/packages/sdk/src/client/edition/mint.ts index 2ec16843..9408e420 100644 --- a/packages/sdk/src/client/edition/mint.ts +++ b/packages/sdk/src/client/edition/mint.ts @@ -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, @@ -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, diff --git a/packages/sdk/src/client/edition/schedules.ts b/packages/sdk/src/client/edition/schedules.ts index 2d365aa4..b6f0fa98 100644 --- a/packages/sdk/src/client/edition/schedules.ts +++ b/packages/sdk/src/client/edition/schedules.ts @@ -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' @@ -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) @@ -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) @@ -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: { diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 714f35fc..e1567e67 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -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 = [