Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call decimals() on generating test permits #249

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions scripts/typescript/generate-erc20-permit-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")}`),
Expand Down Expand Up @@ -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)];
Expand Down
Loading