From ac98c88e21ef8d0525e60656917ad76562f244de Mon Sep 17 00:00:00 2001 From: rndquu Date: Wed, 12 Jun 2024 14:20:20 +0300 Subject: [PATCH] fix: call decimals() on generation test permits --- scripts/typescript/generate-erc20-permit-url.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/typescript/generate-erc20-permit-url.ts b/scripts/typescript/generate-erc20-permit-url.ts index fb23fec0..d7824a88 100644 --- a/scripts/typescript/generate-erc20-permit-url.ts +++ b/scripts/typescript/generate-erc20-permit-url.ts @@ -13,11 +13,17 @@ function createProviderAndWallet() { return { provider, myWallet }; } -function createPermitTransferFromData(amount: string) { +async function createPermitTransferFromData(amount: string) { + // get payment token decimals + const { provider } = createProviderAndWallet(); + const erc20Abi = ["function decimals() public view returns (uint8)"]; + const tokenContract = new ethers.Contract(process.env.PAYMENT_TOKEN_ADDRESS, erc20Abi, provider); + const tokenDecimals = await tokenContract.decimals(); + return { permitted: { token: process.env.PAYMENT_TOKEN_ADDRESS || "", - amount: ethers.utils.parseUnits(amount || "", 18), + amount: ethers.utils.parseUnits(amount || "", tokenDecimals), }, spender: process.env.BENEFICIARY_ADDRESS, nonce: BigNumber.from(`0x${randomBytes(32).toString("hex")}`), @@ -58,10 +64,10 @@ function createTxData(myWallet: ethers.Wallet, permitTransferFromData: PermitTra export async function generateERC20Permit() { const { myWallet } = createProviderAndWallet(); - const permitTransferFromData = createPermitTransferFromData(process.env.AMOUNT_IN_ETH); + const permitTransferFromData = await createPermitTransferFromData(process.env.AMOUNT_IN_ETH); const signature = await signTypedData(myWallet, permitTransferFromData); - const permitTransferFromData2 = createPermitTransferFromData("9"); + const permitTransferFromData2 = await createPermitTransferFromData("9"); const sig = await signTypedData(myWallet, permitTransferFromData); const txData = [createTxData(myWallet, permitTransferFromData, signature), createTxData(myWallet, permitTransferFromData2, sig)];