From 31b8aa776f31ffe7dd2d05cef3cf388e858522e0 Mon Sep 17 00:00:00 2001 From: mmackz Date: Thu, 18 Jul 2024 20:04:05 -0700 Subject: [PATCH 1/5] refactor(utils): change name of amount functions --- packages/utils/src/helpers/mint-amount.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/utils/src/helpers/mint-amount.ts b/packages/utils/src/helpers/mint-amount.ts index 81901231d..5abb88d75 100644 --- a/packages/utils/src/helpers/mint-amount.ts +++ b/packages/utils/src/helpers/mint-amount.ts @@ -1,7 +1,7 @@ import { FilterOperator } from '../types' -export function formatAmount( - amount: FilterOperator | undefined, +export function amountToFilterOperator( + amount: number | bigint | undefined, ): FilterOperator { if (!amount || (typeof amount === 'string' && isNaN(Number(amount)))) { return { $gte: 1n } @@ -17,7 +17,7 @@ export function formatAmount( return amount } -export function getMintAmount(amount: FilterOperator | undefined) { +export function amountToInteger(amount: FilterOperator | undefined) { if (!amount) { return 1n } From 907b2e2ebbc52fba14ed745939d3060bcebe8709 Mon Sep 17 00:00:00 2001 From: mmackz Date: Thu, 18 Jul 2024 20:04:45 -0700 Subject: [PATCH 2/5] fix(utils): improve handling of zero amount in amountToInteger function --- packages/utils/src/helpers/mint-amount.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/helpers/mint-amount.ts b/packages/utils/src/helpers/mint-amount.ts index 5abb88d75..608f4ad28 100644 --- a/packages/utils/src/helpers/mint-amount.ts +++ b/packages/utils/src/helpers/mint-amount.ts @@ -18,7 +18,7 @@ export function amountToFilterOperator( } export function amountToInteger(amount: FilterOperator | undefined) { - if (!amount) { + if (!amount || amount === '0') { return 1n } // If the amount is a primitive, pass that value through From 31825669727decafa98fc62977a55814b4320a6a Mon Sep 17 00:00:00 2001 From: mmackz Date: Thu, 18 Jul 2024 20:15:10 -0700 Subject: [PATCH 3/5] refactor(utils): rename amount utils --- packages/utils/src/helpers/mint-amount.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/utils/src/helpers/mint-amount.ts b/packages/utils/src/helpers/mint-amount.ts index 608f4ad28..1996bd4e1 100644 --- a/packages/utils/src/helpers/mint-amount.ts +++ b/packages/utils/src/helpers/mint-amount.ts @@ -1,7 +1,7 @@ import { FilterOperator } from '../types' -export function amountToFilterOperator( - amount: number | bigint | undefined, +export function formatAmountToFilterOperator( + amount: FilterOperator | undefined, ): FilterOperator { if (!amount || (typeof amount === 'string' && isNaN(Number(amount)))) { return { $gte: 1n } @@ -17,7 +17,7 @@ export function amountToFilterOperator( return amount } -export function amountToInteger(amount: FilterOperator | undefined) { +export function formatAmountToInteger(amount: FilterOperator | undefined) { if (!amount || amount === '0') { return 1n } From 0f68df5b8f81adad76728bfa62833ea31c912f44 Mon Sep 17 00:00:00 2001 From: mmackz Date: Thu, 18 Jul 2024 20:26:39 -0700 Subject: [PATCH 4/5] refactor(utils): replace instances of util amount functions with more descriptive names --- packages/foundation/src/Foundation.ts | 14 +++++++------- packages/pods/src/Pods.ts | 8 ++++---- packages/soundxyz/src/Soundxyz.ts | 12 ++++++------ packages/thirdweb/src/ThirdWeb.ts | 14 +++++++------- packages/utils/src/helpers/index.ts | 5 ++++- packages/utils/src/index.ts | 4 ++-- packages/zora/src/Zora.ts | 4 ++-- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/packages/foundation/src/Foundation.ts b/packages/foundation/src/Foundation.ts index 43f1515eb..94c22ebf7 100644 --- a/packages/foundation/src/Foundation.ts +++ b/packages/foundation/src/Foundation.ts @@ -24,8 +24,8 @@ import { import { Chains, DEFAULT_ACCOUNT, - formatAmount, - getMintAmount, + formatAmountToFilterOperator, + formatAmountToInteger, type MintIntentParams, chainIdToViemChain, } from '@rabbitholegg/questdk-plugin-utils' @@ -70,7 +70,7 @@ export const mint = async ( { // 721 $abi: [...FIXED_PRICE_FRAGMENTS, DUTCH_AUCTION_FRAGMENT], - count: formatAmount(amount), + count: formatAmountToFilterOperator(amount), nftContract: contractAddress, nftRecipient: recipient, buyReferrer: referral, @@ -81,7 +81,7 @@ export const mint = async ( multiTokenCollection: contractAddress, tokenRecipient: recipient, tokenQuantities: { - $some: { tokenId, quantity: formatAmount(amount) }, + $some: { tokenId, quantity: formatAmountToFilterOperator(amount) }, }, referrer: referral, }, @@ -108,7 +108,7 @@ export const getFees = async ( }) as PublicClient const contractType = await getContractType(client, contractAddress) - const quantityToMint = getMintAmount(amount) + const quantityToMint = formatAmountToInteger(amount) if (contractType === '721') { const dropFactoryAddress = CHAIN_TO_CONTRACT_ADDRESS[chainId] @@ -178,7 +178,7 @@ export const getMintIntent = async ( }) as PublicClient const contractType = await getContractType(client, contractAddress) - const mintAmount = getMintAmount(amount) + const mintAmount = formatAmountToInteger(amount) if (contractType === '721') { const dropFactoryAddress = CHAIN_TO_CONTRACT_ADDRESS[chainId] @@ -286,7 +286,7 @@ export const simulateMint = async ( const contractType = await getContractType(_client, contractAddress) - const mintAmount = getMintAmount(amount) + const mintAmount = formatAmountToInteger(amount) if (contractType === '721') { if (tokenId) { diff --git a/packages/pods/src/Pods.ts b/packages/pods/src/Pods.ts index 5073cf963..ae1ff9471 100644 --- a/packages/pods/src/Pods.ts +++ b/packages/pods/src/Pods.ts @@ -14,8 +14,8 @@ import { type MintIntentParams, chainIdToViemChain, getExitAddresses, - formatAmount, - getMintAmount, + formatAmountToFilterOperator, + formatAmountToInteger, } from '@rabbitholegg/questdk-plugin-utils' import { http, @@ -38,7 +38,7 @@ export const mint = async ( const andArray1155: AndArrayItem[] = [ { - quantity: formatAmount(amount), + quantity: formatAmountToFilterOperator(amount), }, ] if (referral) { @@ -161,7 +161,7 @@ export const getFees = async ( mint: MintActionParams, ): Promise<{ actionFee: bigint; projectFee: bigint }> => { const { chainId, contractAddress, tokenId, amount } = mint - const quantityToMint = getMintAmount(amount) + const quantityToMint = formatAmountToInteger(amount) try { const client = createPublicClient({ chain: chainIdToViemChain(chainId), diff --git a/packages/soundxyz/src/Soundxyz.ts b/packages/soundxyz/src/Soundxyz.ts index 303027412..42509f019 100644 --- a/packages/soundxyz/src/Soundxyz.ts +++ b/packages/soundxyz/src/Soundxyz.ts @@ -25,8 +25,8 @@ import { type MintIntentParams, chainIdToViemChain, getExitAddresses, - formatAmount, - getMintAmount, + formatAmountToFilterOperator, + formatAmountToInteger, } from '@rabbitholegg/questdk-plugin-utils' import { type Address, @@ -53,7 +53,7 @@ export const mint = async ( $abiAbstract: SUPERMINTER_V2_ABI, p: { edition: contractAddress, - quantity: formatAmount(amount), + quantity: formatAmountToFilterOperator(amount), tier: tokenId, to: recipient, // Can be given as gift, so recipient will not always match sender affiliate: referral, @@ -67,7 +67,7 @@ export const getMintIntent = async ( ): Promise => { const { contractAddress, recipient, tokenId, amount } = mint const tier = await getDefaultMintTier(mint.chainId, contractAddress, tokenId) - const quantity = getMintAmount(amount) + const quantity = formatAmountToInteger(amount) const mintTo = { edition: contractAddress, @@ -119,7 +119,7 @@ export const simulateMint = async ( tokenId, _client, ) - const quantity = getMintAmount(amount) + const quantity = formatAmountToInteger(amount) const mintTo = { edition: contractAddress, @@ -186,7 +186,7 @@ export const getFees = async ( tokenId, client, ) - const quantity = getMintAmount(amount) + const quantity = formatAmountToInteger(amount) try { const totalPriceAndFees = (await client.readContract({ diff --git a/packages/thirdweb/src/ThirdWeb.ts b/packages/thirdweb/src/ThirdWeb.ts index 9101f2403..d218e46f0 100644 --- a/packages/thirdweb/src/ThirdWeb.ts +++ b/packages/thirdweb/src/ThirdWeb.ts @@ -18,8 +18,8 @@ import { DEFAULT_ACCOUNT, type MintActionParams, type MintIntentParams, - formatAmount, - getMintAmount, + formatAmountToFilterOperator, + formatAmountToInteger, } from '@rabbitholegg/questdk-plugin-utils' import { type Address, @@ -38,13 +38,13 @@ export const mint = async ( const Erc721Filter = { $abi: [CLAIM_721_FRAGMENT], _receiver: recipient, - _quantity: formatAmount(amount), + _quantity: formatAmountToFilterOperator(amount), } const Erc1155Filter = { $abi: [CLAIM_1155_FRAGMENT], _receiver: recipient, - _quantity: formatAmount(amount), + _quantity: formatAmountToFilterOperator(amount), _tokenId: tokenId, } @@ -66,7 +66,7 @@ export const getFees = async ( mint: MintActionParams, ): Promise<{ actionFee: bigint; projectFee: bigint }> => { const { chainId, contractAddress, amount, tokenId } = mint - const quantityToMint = getMintAmount(amount) + const quantityToMint = formatAmountToInteger(amount) const client = getClient(chainId) try { @@ -138,7 +138,7 @@ export const simulateMint = async ( const mintArgs = [ recipient, tokenId ?? 0n, - getMintAmount(amount), + formatAmountToInteger(amount), claimCondition.currency, value, [ @@ -174,7 +174,7 @@ export const simulateMint = async ( const mintArgs = [ recipient, - getMintAmount(amount), + formatAmountToInteger(amount), claimCondition.currency, value, [ diff --git a/packages/utils/src/helpers/index.ts b/packages/utils/src/helpers/index.ts index 683509400..e9a35069a 100644 --- a/packages/utils/src/helpers/index.ts +++ b/packages/utils/src/helpers/index.ts @@ -2,4 +2,7 @@ export { createTestCase } from './test-helpers' export type { TestCase, TestParams } from './test-helpers' export { chainIdToViemChain } from './chain-id-to-viem-chain' export { getExitAddresses } from './get-exit-addresses' -export { formatAmount, getMintAmount } from './mint-amount' +export { + formatAmountToFilterOperator, + formatAmountToInteger, +} from './mint-amount' diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 9d85f4f5d..ff9c6ca80 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -12,8 +12,8 @@ export { chainIdToViemChain, createTestCase, getExitAddresses, - formatAmount, - getMintAmount, + formatAmountToFilterOperator, + formatAmountToInteger, } from './helpers' export type { IntentParams, diff --git a/packages/zora/src/Zora.ts b/packages/zora/src/Zora.ts index 51cd22bf0..d8608f0ad 100644 --- a/packages/zora/src/Zora.ts +++ b/packages/zora/src/Zora.ts @@ -19,7 +19,7 @@ import { type TransactionFilter, compressJson, } from '@rabbitholegg/questdk' -import { formatAmount } from '@rabbitholegg/questdk-plugin-utils' +import { formatAmountToFilterOperator } from '@rabbitholegg/questdk-plugin-utils' import { ActionType, DEFAULT_ACCOUNT, @@ -109,7 +109,7 @@ export const mint = async ( : contractAddress const quantityCheck = { - quantity: formatAmount(amount), + quantity: formatAmountToFilterOperator(amount), } const andArray721: AndArrayItem[] = [quantityCheck] const andArray1155: AndArrayItem[] = [quantityCheck] From 7b93d2c297c897d72669ea9346e4a851c940da69 Mon Sep 17 00:00:00 2001 From: mmackz Date: Thu, 18 Jul 2024 20:27:48 -0700 Subject: [PATCH 5/5] chore: generate changeset --- .changeset/rare-cats-change.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/rare-cats-change.md diff --git a/.changeset/rare-cats-change.md b/.changeset/rare-cats-change.md new file mode 100644 index 000000000..6ef4c243c --- /dev/null +++ b/.changeset/rare-cats-change.md @@ -0,0 +1,10 @@ +--- +"@rabbitholegg/questdk-plugin-foundation": patch +"@rabbitholegg/questdk-plugin-soundxyz": patch +"@rabbitholegg/questdk-plugin-thirdweb": patch +"@rabbitholegg/questdk-plugin-utils": patch +"@rabbitholegg/questdk-plugin-pods": patch +"@rabbitholegg/questdk-plugin-zora": patch +--- + +change name of amount utils to be more descriptive