diff --git a/.changeset/rude-days-hide.md b/.changeset/rude-days-hide.md new file mode 100644 index 000000000..0803bf386 --- /dev/null +++ b/.changeset/rude-days-hide.md @@ -0,0 +1,5 @@ +--- +"@rabbitholegg/questdk-plugin-moshicam": patch +--- + +fix amount zero issue diff --git a/packages/moshicam/src/Moshicam.test.ts b/packages/moshicam/src/Moshicam.test.ts index 8db12ff31..a4b87cb65 100644 --- a/packages/moshicam/src/Moshicam.test.ts +++ b/packages/moshicam/src/Moshicam.test.ts @@ -5,11 +5,11 @@ import { mint, simulateMint, } from './Moshicam' -import { IMOSHI_PIC1155_ABI } from './abi.ts' -import { DEFAULT_MINT_PRICE, MOSHIMINTER_ADMIN } from './constants.ts' +import { IMOSHI_PIC1155_ABI } from './abi' +import { DEFAULT_MINT_PRICE, MOSHIMINTER_ADMIN } from './constants' import { failingTestCases, passingTestCases } from './test-transactions' import { COLLECT_FROM_USER_MOSHICAM } from './test-transactions' -import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk' +import { apply } from '@rabbitholegg/questdk' import { Chains, MintIntentParams } from '@rabbitholegg/questdk-plugin-utils' import { encodeFunctionData, parseEther } from 'viem' import { describe, expect, test } from 'vitest' @@ -62,6 +62,7 @@ describe('Given the getMintIntent function', () => { chainId: Chains.BASE, contractAddress: COLLECT_FROM_USER_MOSHICAM.params.contractAddress, recipient: COLLECT_FROM_USER_MOSHICAM.transaction.from, + amount: 1n, tokenId: 1, } const data = encodeFunctionData({ @@ -113,7 +114,7 @@ describe('Given the getFee function', () => { }) test('it should return the expected fee if amount is not provided', async () => { - const mint: MintIntentParams = { + const mint = { chainId: Chains.BASE, contractAddress: COLLECT_FROM_USER_MOSHICAM.params.contractAddress, recipient: COLLECT_FROM_USER_MOSHICAM.transaction.from, @@ -127,7 +128,7 @@ describe('Given the getFee function', () => { }) test('it should return the expected fee if failed to fetch', async () => { - const mint: MintIntentParams = { + const mint = { chainId: Chains.BLAST, // unsupported chain contractAddress: COLLECT_FROM_USER_MOSHICAM.params.contractAddress, recipient: COLLECT_FROM_USER_MOSHICAM.transaction.from, @@ -146,7 +147,7 @@ describe('Given the simulateMint function', () => { const mint: MintIntentParams = { chainId: Chains.BASE, contractAddress: COLLECT_FROM_USER_MOSHICAM.params.contractAddress, - amount: 1, + amount: 1n, recipient: COLLECT_FROM_USER_MOSHICAM.transaction.from, tokenId: 0, } @@ -173,12 +174,8 @@ describe('Given the simulateMint function', () => { expect( async () => - await simulateMint( - mint, - DEFAULT_MINT_PRICE, - MOSHIMINTER_ADMIN, - ).toThrowError(), - ) + await simulateMint(mint, DEFAULT_MINT_PRICE, MOSHIMINTER_ADMIN), + ).rejects.toThrowError() }) test('it should throw error if chain is not supported', async () => { @@ -191,11 +188,7 @@ describe('Given the simulateMint function', () => { expect( async () => - await simulateMint( - mint, - DEFAULT_MINT_PRICE, - MOSHIMINTER_ADMIN, - ).toThrowError(), - ) + await simulateMint(mint, DEFAULT_MINT_PRICE, MOSHIMINTER_ADMIN), + ).rejects.toThrowError() }) }) diff --git a/packages/moshicam/src/Moshicam.ts b/packages/moshicam/src/Moshicam.ts index 9180768a2..2fbc0b50d 100644 --- a/packages/moshicam/src/Moshicam.ts +++ b/packages/moshicam/src/Moshicam.ts @@ -10,6 +10,8 @@ import { DEFAULT_ACCOUNT, type MintIntentParams, chainIdToViemChain, + formatAmount, + getMintAmount, } from '@rabbitholegg/questdk-plugin-utils' import { type Address, @@ -33,7 +35,7 @@ export const mint = async ( $abi: IMOSHI_PIC1155_ABI, to: recipient, id: tokenId, - quantity: amount, + quantity: formatAmount(amount), }, }) } @@ -45,7 +47,7 @@ export const getMintIntent = async ( const tokenIdToMint = tokenId ? tokenId : 0 - const quantityToMint = typeof amount === 'number' ? BigInt(amount) : BigInt(1) + const quantityToMint = getMintAmount(amount) const data = encodeFunctionData({ abi: IMOSHI_PIC1155_ABI, @@ -75,7 +77,7 @@ export const getFees = async ( chain: chainIdToViemChain(chainId), transport: http(), }) - const quantityToMint = typeof amount === 'number' ? BigInt(amount) : BigInt(1) + const quantityToMint = getMintAmount(amount) try { const data = (await client.readContract({ address: contractAddress, @@ -107,7 +109,7 @@ export const simulateMint = async ( throw new Error(`${chainId} is not supported`) } - const amountToMint = amount ? amount : 1n + const amountToMint = getMintAmount(amount) const _client = (client ?? createPublicClient({ diff --git a/packages/moshicam/src/test-transactions.ts b/packages/moshicam/src/test-transactions.ts index a82b2b389..2e34d9089 100644 --- a/packages/moshicam/src/test-transactions.ts +++ b/packages/moshicam/src/test-transactions.ts @@ -34,8 +34,8 @@ export const failingTestCases = [ createTestCase(COLLECT_FROM_USER_MOSHICAM, 'when chainId is not correct', { chainId: 99, }), - createTestCase(COLLECT_FROM_USER_MOSHICAM, 'when amount is less than one', { - amount: 0, + createTestCase(COLLECT_FROM_USER_MOSHICAM, 'when amount is not sufficient', { + amount: GreaterThanOrEqual(11), }), createTestCase( COLLECT_FROM_USER_MOSHICAM,