Skip to content

Commit

Permalink
Merge pull request #491 from rabbitholegg/mmackz/rename-amount-utils
Browse files Browse the repository at this point in the history
refactor(utils): rename amount utils to be more descriptive
  • Loading branch information
mmackz authored Jul 23, 2024
2 parents 5cf2b27 + 7b93d2c commit ee5441e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 32 deletions.
10 changes: 10 additions & 0 deletions .changeset/rare-cats-change.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions packages/foundation/src/Foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
import {
Chains,
DEFAULT_ACCOUNT,
formatAmount,
getMintAmount,
formatAmountToFilterOperator,
formatAmountToInteger,
type MintIntentParams,
chainIdToViemChain,
} from '@rabbitholegg/questdk-plugin-utils'
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/pods/src/Pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
type MintIntentParams,
chainIdToViemChain,
getExitAddresses,
formatAmount,
getMintAmount,
formatAmountToFilterOperator,
formatAmountToInteger,
} from '@rabbitholegg/questdk-plugin-utils'
import {
http,
Expand All @@ -38,7 +38,7 @@ export const mint = async (

const andArray1155: AndArrayItem[] = [
{
quantity: formatAmount(amount),
quantity: formatAmountToFilterOperator(amount),
},
]
if (referral) {
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 6 additions & 6 deletions packages/soundxyz/src/Soundxyz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
type MintIntentParams,
chainIdToViemChain,
getExitAddresses,
formatAmount,
getMintAmount,
formatAmountToFilterOperator,
formatAmountToInteger,
} from '@rabbitholegg/questdk-plugin-utils'
import {
type Address,
Expand All @@ -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,
Expand All @@ -67,7 +67,7 @@ export const getMintIntent = async (
): Promise<TransactionRequest> => {
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,
Expand Down Expand Up @@ -119,7 +119,7 @@ export const simulateMint = async (
tokenId,
_client,
)
const quantity = getMintAmount(amount)
const quantity = formatAmountToInteger(amount)

const mintTo = {
edition: contractAddress,
Expand Down Expand Up @@ -186,7 +186,7 @@ export const getFees = async (
tokenId,
client,
)
const quantity = getMintAmount(amount)
const quantity = formatAmountToInteger(amount)

try {
const totalPriceAndFees = (await client.readContract({
Expand Down
14 changes: 7 additions & 7 deletions packages/thirdweb/src/ThirdWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
DEFAULT_ACCOUNT,
type MintActionParams,
type MintIntentParams,
formatAmount,
getMintAmount,
formatAmountToFilterOperator,
formatAmountToInteger,
} from '@rabbitholegg/questdk-plugin-utils'
import {
type Address,
Expand All @@ -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,
}

Expand All @@ -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 {
Expand Down Expand Up @@ -138,7 +138,7 @@ export const simulateMint = async (
const mintArgs = [
recipient,
tokenId ?? 0n,
getMintAmount(amount),
formatAmountToInteger(amount),
claimCondition.currency,
value,
[
Expand Down Expand Up @@ -174,7 +174,7 @@ export const simulateMint = async (

const mintArgs = [
recipient,
getMintAmount(amount),
formatAmountToInteger(amount),
claimCondition.currency,
value,
[
Expand Down
5 changes: 4 additions & 1 deletion packages/utils/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 3 additions & 3 deletions packages/utils/src/helpers/mint-amount.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FilterOperator } from '../types'

export function formatAmount(
export function formatAmountToFilterOperator(
amount: FilterOperator | undefined,
): FilterOperator {
if (!amount || (typeof amount === 'string' && isNaN(Number(amount)))) {
Expand All @@ -17,8 +17,8 @@ export function formatAmount(
return amount
}

export function getMintAmount(amount: FilterOperator | undefined) {
if (!amount) {
export function formatAmountToInteger(amount: FilterOperator | undefined) {
if (!amount || amount === '0') {
return 1n
}
// If the amount is a primitive, pass that value through
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export {
chainIdToViemChain,
createTestCase,
getExitAddresses,
formatAmount,
getMintAmount,
formatAmountToFilterOperator,
formatAmountToInteger,
} from './helpers'
export type {
IntentParams,
Expand Down
4 changes: 2 additions & 2 deletions packages/zora/src/Zora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Chains,
Expand Down Expand Up @@ -110,7 +110,7 @@ export const mint = async (
: contractAddress

const quantityCheck = {
quantity: formatAmount(amount),
quantity: formatAmountToFilterOperator(amount),
}
const andArray721: AndArrayItem[] = [quantityCheck]
const andArray1155: AndArrayItem[] = [quantityCheck]
Expand Down

0 comments on commit ee5441e

Please sign in to comment.