Skip to content

Commit

Permalink
Merge pull request #469 from rabbitholegg/mmackz/pods/amount-zero
Browse files Browse the repository at this point in the history
fix(pods): amount zero fix
  • Loading branch information
mmackz authored Jul 10, 2024
2 parents 2f0d70d + 95fad79 commit 1b8d7c0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-shirts-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-pods": minor
---

fix for quantity zero mints
17 changes: 11 additions & 6 deletions packages/pods/src/Pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
FIXED_PRICE_SALE_STRATS,
ZORA_DEPLOYER_ADDRESS,
} from './contract-addresses'
import { getLatestTokenId } from './utils'
import { type AndArrayItem, getLatestTokenId } from './utils'
import {
type MintActionParams,
type TransactionFilter,
Expand All @@ -15,6 +15,8 @@ import {
type MintIntentParams,
chainIdToViemChain,
getExitAddresses,
formatAmount,
getMintAmount,
} from '@rabbitholegg/questdk-plugin-utils'
import {
http,
Expand All @@ -33,24 +35,27 @@ export const mint = async (
): Promise<TransactionFilter> => {
const { chainId, contractAddress, tokenId, amount, recipient } = mint

const andArray1155 = []
const andArray1155: AndArrayItem[] = [
{
quantity: formatAmount(amount),
},
]
if (recipient) {
andArray1155.push({
minterArguments: {
$regex: `.*${recipient.toLowerCase().replace(/^0x/, '')}.*`,
},
})
}
if (tokenId || amount) {
if (tokenId) {
andArray1155.push({
quantity: amount,
tokenId,
})
}

const ERC1155_FILTER = {
$abiAbstract: ZORA_MINTER_ABI_1155,
$and: andArray1155.length !== 0 ? andArray1155 : undefined,
$and: andArray1155,
}

return compressJson({
Expand Down Expand Up @@ -140,7 +145,7 @@ export const getFees = async (
mint: MintActionParams,
): Promise<{ actionFee: bigint; projectFee: bigint }> => {
const { chainId, contractAddress, tokenId, amount } = mint
const quantityToMint = typeof amount === 'number' ? BigInt(amount) : BigInt(1)
const quantityToMint = getMintAmount(amount)
try {
const client = createPublicClient({
chain: chainIdToViemChain(chainId),
Expand Down
3 changes: 2 additions & 1 deletion packages/pods/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { POD_MINT } from './test-transactions'
import { POD_MINT, ZERO_QUANTITY } from './test-transactions'
import { createTestCase } from '@rabbitholegg/questdk-plugin-utils'
import { getAddress } from 'viem'

Expand Down Expand Up @@ -29,4 +29,5 @@ export const failingTestCases = [
createTestCase(POD_MINT, 'when amount is incorrect', {
amount: '72',
}),
createTestCase(ZERO_QUANTITY, 'when quantity minted is 0'),
]
18 changes: 18 additions & 0 deletions packages/pods/src/test-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ export const POD_MINT: TestParams<MintActionParams> = {
},
}

export const ZERO_QUANTITY: TestParams<MintActionParams> = {
transaction: {
chainId: 8453, // BASE
from: '0xc5c2Be8852D38D862A22A80902ABd9935b2ABdc3',
hash: '0xc1b6bb785ed9e1ed3d958c3063168e54e9e7f4376fce0c23b5d311d96d2c079a',
input:
'0x9dbb844d00000000000000000000000004e2516a2c207e84a1839755675dfd8ef6302f0a0000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000061919af4b9c1a0fd94c65f0e67fd0651b080da640000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c5c2be8852d38d862a22a80902abd9935b2abdc300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000',
to: '0x7e0b40af1d6f26f2141b90170c513e57b5edd74e',
value: '0',
},
params: {
chainId: Chains.BASE,
contractAddress: '0x7E0b40AF1D6f26F2141b90170C513e57b5EdD74e',
tokenId: 21,
recipient: '0xc5c2Be8852D38D862A22A80902ABd9935b2ABdc3',
},
}

export const EXPECTED_ENCODED_DATA_721 =
'0xefef39a1000000000000000000000000000000000000000000000000000000000000000a'
export const EXPECTED_ENCODED_DATA_1155 =
Expand Down
10 changes: 9 additions & 1 deletion packages/pods/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { ZORA_MINTER_ABI_1155 } from './abi'
import { type Address, type PublicClient, createPublicClient, http } from 'viem'
import { chainIdToViemChain } from '@rabbitholegg/questdk-plugin-utils'
import {
FilterOperator,
chainIdToViemChain,
} from '@rabbitholegg/questdk-plugin-utils'

export type AndArrayItem =
| { quantity: string | number | bigint | FilterOperator }
| { minterArguments: { $regex: string } }
| { tokenId: number | string }

export async function getLatestTokenId(
contractAddress: Address,
Expand Down

0 comments on commit 1b8d7c0

Please sign in to comment.