From 4163b668ba5a4c6c6463b99819ee3ab77b4352d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B4=CF=85=CF=82?= Date: Mon, 15 Jul 2024 16:22:53 -0400 Subject: [PATCH] =?UTF-8?q?fixing=20ERC-20=20contract=20read=20using=20WAG?= =?UTF-8?q?MI=20=F0=9F=91=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/quests/createQuest/permissions.ts | 11 ++++++----- packages/backend/src/lib/abis/ERC20.json | 2 +- packages/backend/src/lib/ethereum.ts | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/handlers/actions/quests/createQuest/permissions.ts b/packages/backend/src/handlers/actions/quests/createQuest/permissions.ts index 5ac465213..3149a3c21 100644 --- a/packages/backend/src/handlers/actions/quests/createQuest/permissions.ts +++ b/packages/backend/src/handlers/actions/quests/createQuest/permissions.ts @@ -6,7 +6,8 @@ import { polygon } from 'viem/chains'; const { amountToDecimal } = numbers; /** - * As a first iteration, we only allow people to create quests if they hold more that 100 pSEED tokens + * As a first iteration, we only allow people to + * create quests if they hold more that 100 pSEED tokens */ export async function isAllowedToCreateQuest( @@ -20,12 +21,12 @@ export async function isAllowedToCreateQuest( Constants.PSEED_ADDRESS, polygonClient, ); - const pSEEDBalance = await pSEEDContract.balanceOf(playerAddress); - const pSEEDDecimals = await pSEEDContract.decimals(); + const pSEEDBalance = await pSEEDContract.read.balanceOf([playerAddress]); + const pSEEDDecimals = await pSEEDContract.read.decimals(); const minimumPooledSeedBalance = BigInt(Constants.PSEED_FOR_QUEST); const pSEEDBalanceInDecimal = amountToDecimal( - pSEEDBalance.toString(), - pSEEDDecimals, + pSEEDBalance as string, + pSEEDDecimals as number, ); const allowed = BigInt(pSEEDBalanceInDecimal) >= minimumPooledSeedBalance; diff --git a/packages/backend/src/lib/abis/ERC20.json b/packages/backend/src/lib/abis/ERC20.json index 405d6b364..3b0ab2f1a 100644 --- a/packages/backend/src/lib/abis/ERC20.json +++ b/packages/backend/src/lib/abis/ERC20.json @@ -219,4 +219,4 @@ "name": "Transfer", "type": "event" } -] +] \ No newline at end of file diff --git a/packages/backend/src/lib/ethereum.ts b/packages/backend/src/lib/ethereum.ts index de0ceb5f4..3a94153e2 100644 --- a/packages/backend/src/lib/ethereum.ts +++ b/packages/backend/src/lib/ethereum.ts @@ -1,7 +1,7 @@ import ERC20_ABI from './abis/ERC20.json' assert { type: 'json' }; import { getContract, PublicClient } from 'viem'; -export const getERC20Contract = async ( +export const getERC20Contract = ( contractAddress: `0x${string}`, client: PublicClient ) => (