fix denormolized wallet balance error

This commit is contained in:
lomonoshka
2023-11-03 13:16:16 +04:00
parent 8e018aa1b0
commit 47e68cc7fa
4 changed files with 27 additions and 7 deletions

View File

@@ -41,3 +41,22 @@ export default async function getBalance(
wallet: denormalizedAssetInWalletBalance,
};
}
export async function getWalletBalance(
assetAddress: string,
walletAddress: string,
provider: ethers.Provider,
) {
const assetIsNativeCryptocurrency = assetAddress === ethers.ZeroAddress;
let assetWalletBalance: bigint | undefined;
if (!assetIsNativeCryptocurrency) {
const assetContract = ERC20__factory.connect(assetAddress, provider);
assetWalletBalance = await assetContract.balanceOf(walletAddress);
} else {
assetWalletBalance = await provider.getBalance(walletAddress);
}
return assetWalletBalance
}