From c8bc79a1c029f1dc53a072a2dee25439bf59ff71 Mon Sep 17 00:00:00 2001 From: Volodymyr Derunov Date: Wed, 9 Oct 2024 03:04:57 +0300 Subject: [PATCH] Revert tokenAddress (#12) --- src/fetchTokenAllowance.ts | 10 +++------- src/fetchTokenBalance.ts | 6 +++--- src/useClaimReward.ts | 2 +- src/useDeposit.ts | 6 +++--- src/usePerpsModifyCollateral.ts | 6 +++--- src/useSpotSell.ts | 8 ++++---- src/useSpotWrap.ts | 10 +++++----- src/useTokenAllowance.ts | 14 +++++++------- src/useTokenBalance.ts | 14 +++++++------- src/useWethDeposit.ts | 2 +- src/useWithdraw.ts | 2 +- 11 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/fetchTokenAllowance.ts b/src/fetchTokenAllowance.ts index 9a03a66..0fa5907 100644 --- a/src/fetchTokenAllowance.ts +++ b/src/fetchTokenAllowance.ts @@ -2,20 +2,16 @@ import { ethers } from 'ethers'; export async function fetchTokenAllowance({ provider, - collateralTypeTokenAddress, + tokenAddress, ownerAddress, spenderAddress, }: { provider: ethers.providers.BaseProvider; - collateralTypeTokenAddress: string; + tokenAddress: string; ownerAddress: string; spenderAddress: string; }) { - const Token = new ethers.Contract( - collateralTypeTokenAddress, - ['function allowance(address owner, address spender) view returns (uint256)'], - provider - ); + const Token = new ethers.Contract(tokenAddress, ['function allowance(address owner, address spender) view returns (uint256)'], provider); const allowance = Token.allowance(ownerAddress, spenderAddress); return allowance; } diff --git a/src/fetchTokenBalance.ts b/src/fetchTokenBalance.ts index 7875ba5..dda7677 100644 --- a/src/fetchTokenBalance.ts +++ b/src/fetchTokenBalance.ts @@ -2,14 +2,14 @@ import { ethers } from 'ethers'; export async function fetchTokenBalance({ provider, - collateralTypeTokenAddress, + tokenAddress, ownerAddress, }: { provider: ethers.providers.BaseProvider; - collateralTypeTokenAddress: string; + tokenAddress: string; ownerAddress: string; }) { - const Token = new ethers.Contract(collateralTypeTokenAddress, ['function balanceOf(address account) view returns (uint256)'], provider); + const Token = new ethers.Contract(tokenAddress, ['function balanceOf(address account) view returns (uint256)'], provider); const balance = Token.balanceOf(ownerAddress); return balance; } diff --git a/src/useClaimReward.ts b/src/useClaimReward.ts index ff35de3..3eb4b0d 100644 --- a/src/useClaimReward.ts +++ b/src/useClaimReward.ts @@ -162,7 +162,7 @@ export function useClaimReward({ preset, 'Balance', { - collateralTypeTokenAddress, + tokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress, }, ], diff --git a/src/useDeposit.ts b/src/useDeposit.ts index 733bd3f..0762aa9 100644 --- a/src/useDeposit.ts +++ b/src/useDeposit.ts @@ -46,7 +46,7 @@ export function useDeposit({ const freshBalance = await fetchTokenBalance({ provider, ownerAddress: walletAddress, - collateralTypeTokenAddress, + tokenAddress: collateralTypeTokenAddress, }); log('freshBalance: %O', freshBalance); @@ -57,7 +57,7 @@ export function useDeposit({ const freshAllowance = await fetchTokenAllowance({ provider, ownerAddress: walletAddress, - collateralTypeTokenAddress, + tokenAddress: collateralTypeTokenAddress, spenderAddress: CoreProxyContract?.address, }); log('freshAllowance: %O', freshAllowance); @@ -118,7 +118,7 @@ export function useDeposit({ ], }); queryClient.invalidateQueries({ - queryKey: [chainId, preset, 'Balance', { collateralTypeTokenAddress, ownerAddress: walletAddress }], + queryKey: [chainId, preset, 'Balance', { tokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress }], }); onSuccess(); diff --git a/src/usePerpsModifyCollateral.ts b/src/usePerpsModifyCollateral.ts index a9a63f9..af80a65 100644 --- a/src/usePerpsModifyCollateral.ts +++ b/src/usePerpsModifyCollateral.ts @@ -38,7 +38,7 @@ export function usePerpsModifyCollateral({ const freshBalance = await fetchTokenBalance({ provider, ownerAddress: walletAddress, - collateralTypeTokenAddress: systemToken?.address, + tokenAddress: systemToken?.address, }); log('freshBalance: %O', freshBalance); @@ -49,7 +49,7 @@ export function usePerpsModifyCollateral({ const freshAllowance = await fetchTokenAllowance({ provider, ownerAddress: walletAddress, - collateralTypeTokenAddress: systemToken.address, + tokenAddress: systemToken.address, spenderAddress: PerpsMarketProxyContract.address, }); log('freshAllowance: %O', freshAllowance); @@ -95,7 +95,7 @@ export function usePerpsModifyCollateral({ }); queryClient.invalidateQueries({ - queryKey: [chainId, preset, 'Balance', { collateralTypeTokenAddress: systemToken?.address, ownerAddress: walletAddress }], + queryKey: [chainId, preset, 'Balance', { tokenAddress: systemToken?.address, ownerAddress: walletAddress }], }); queryClient.invalidateQueries({ queryKey: [chainId, preset, 'Perps GetAvailableMargin', { PerpsMarketProxy: PerpsMarketProxyContract?.address }, perpsAccountId], diff --git a/src/useSpotSell.ts b/src/useSpotSell.ts index 84b6e5a..ecb2635 100644 --- a/src/useSpotSell.ts +++ b/src/useSpotSell.ts @@ -90,7 +90,7 @@ export function useSpotSell({ const freshBalance = await fetchTokenBalance({ provider, ownerAddress: walletAddress, - collateralTypeTokenAddress: synthTokenAddress, + tokenAddress: synthTokenAddress, }); log('freshBalance: %O', freshBalance); @@ -101,7 +101,7 @@ export function useSpotSell({ const freshAllowance = await fetchTokenAllowance({ provider, ownerAddress: walletAddress, - collateralTypeTokenAddress: synthTokenAddress, + tokenAddress: synthTokenAddress, spenderAddress: SpotMarketProxyContract.address, }); log('freshAllowance: %O', freshAllowance); @@ -163,10 +163,10 @@ export function useSpotSell({ }); } queryClient.invalidateQueries({ - queryKey: [chainId, preset, 'Balance', { collateralTypeTokenAddress: systemToken?.address, ownerAddress: walletAddress }], + queryKey: [chainId, preset, 'Balance', { tokenAddress: systemToken?.address, ownerAddress: walletAddress }], }); queryClient.invalidateQueries({ - queryKey: [chainId, preset, 'Balance', { collateralTypeTokenAddress: synthTokenAddress, ownerAddress: walletAddress }], + queryKey: [chainId, preset, 'Balance', { tokenAddress: synthTokenAddress, ownerAddress: walletAddress }], }); onSuccess(); }, diff --git a/src/useSpotWrap.ts b/src/useSpotWrap.ts index 6a802ed..4826b2c 100644 --- a/src/useSpotWrap.ts +++ b/src/useSpotWrap.ts @@ -85,7 +85,7 @@ export function useSpotWrap({ const freshBalance = await fetchTokenBalance({ provider, - collateralTypeTokenAddress, + tokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress, }); log('freshBalance: %O', freshBalance); @@ -96,7 +96,7 @@ export function useSpotWrap({ const freshAllowance = await fetchTokenAllowance({ provider, - collateralTypeTokenAddress, + tokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress, spenderAddress: SpotMarketProxyContract.address, }); @@ -163,14 +163,14 @@ export function useSpotWrap({ chainId, preset, 'Allowance', - { collateralTypeTokenAddress, ownerAddress: walletAddress, spenderAddress: SpotMarketProxyContract?.address }, + { tokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress, spenderAddress: SpotMarketProxyContract?.address }, ], }); queryClient.invalidateQueries({ - queryKey: [chainId, preset, 'Balance', { collateralTypeTokenAddress: synthTokenAddress, ownerAddress: walletAddress }], + queryKey: [chainId, preset, 'Balance', { tokenAddress: synthTokenAddress, ownerAddress: walletAddress }], }); queryClient.invalidateQueries({ - queryKey: [chainId, preset, 'Balance', { collateralTypeTokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress }], + queryKey: [chainId, preset, 'Balance', { tokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress }], }); onSuccess(); diff --git a/src/useTokenAllowance.ts b/src/useTokenAllowance.ts index 992a00d..c34517a 100644 --- a/src/useTokenAllowance.ts +++ b/src/useTokenAllowance.ts @@ -9,12 +9,12 @@ const log = debug('snx:useTokenAllowance'); export function useTokenAllowance({ provider, - collateralTypeTokenAddress, + tokenAddress, ownerAddress, spenderAddress, }: { provider?: ethers.providers.BaseProvider; - collateralTypeTokenAddress?: string; + tokenAddress?: string; ownerAddress?: string; spenderAddress?: string; }) { @@ -22,18 +22,18 @@ export function useTokenAllowance({ const errorParser = useErrorParser(); return useQuery({ - enabled: Boolean(chainId && preset && provider && collateralTypeTokenAddress && ownerAddress && spenderAddress), - queryKey: [chainId, preset, 'Allowance', { collateralTypeTokenAddress, ownerAddress, spenderAddress }], + enabled: Boolean(chainId && preset && provider && tokenAddress && ownerAddress && spenderAddress), + queryKey: [chainId, preset, 'Allowance', { tokenAddress, ownerAddress, spenderAddress }], queryFn: async () => { - if (!(chainId && preset && provider && collateralTypeTokenAddress && ownerAddress && spenderAddress)) { + if (!(chainId && preset && provider && tokenAddress && ownerAddress && spenderAddress)) { throw 'OMFG'; } - log({ chainId, preset, collateralTypeTokenAddress, ownerAddress, spenderAddress }); + log({ chainId, preset, tokenAddress, ownerAddress, spenderAddress }); const allowance = await fetchTokenAllowance({ provider, - collateralTypeTokenAddress, + tokenAddress, ownerAddress, spenderAddress, }); diff --git a/src/useTokenBalance.ts b/src/useTokenBalance.ts index 4ef0112..fb98650 100644 --- a/src/useTokenBalance.ts +++ b/src/useTokenBalance.ts @@ -9,27 +9,27 @@ const log = debug('snx:useTokenBalance'); export function useTokenBalance({ provider, - collateralTypeTokenAddress, + tokenAddress, ownerAddress, }: { provider?: ethers.providers.BaseProvider; - collateralTypeTokenAddress?: string; + tokenAddress?: string; ownerAddress?: string; }) { const { chainId, preset } = useSynthetix(); const errorParser = useErrorParser(); return useQuery({ - enabled: Boolean(chainId && preset && provider && collateralTypeTokenAddress && ownerAddress), - queryKey: [chainId, preset, 'Balance', { collateralTypeTokenAddress, ownerAddress }], + enabled: Boolean(chainId && preset && provider && tokenAddress && ownerAddress), + queryKey: [chainId, preset, 'Balance', { tokenAddress, ownerAddress }], queryFn: async () => { - if (!(chainId && preset && provider && collateralTypeTokenAddress && ownerAddress)) { + if (!(chainId && preset && provider && tokenAddress && ownerAddress)) { throw 'OMFG'; } - log({ chainId, preset, collateralTypeTokenAddress, ownerAddress }); + log({ chainId, preset, tokenAddress, ownerAddress }); - const balance = await fetchTokenBalance({ provider, collateralTypeTokenAddress, ownerAddress }); + const balance = await fetchTokenBalance({ provider, tokenAddress, ownerAddress }); log('balance: %O', balance); return balance; }, diff --git a/src/useWethDeposit.ts b/src/useWethDeposit.ts index cdb1e29..a997d81 100644 --- a/src/useWethDeposit.ts +++ b/src/useWethDeposit.ts @@ -53,7 +53,7 @@ export function useWethDeposit({ if (!queryClient) return; queryClient.invalidateQueries({ - queryKey: [chainId, preset, 'Balance', { collateralTypeTokenAddress, ownerAddress: walletAddress }], + queryKey: [chainId, preset, 'Balance', { tokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress }], }); queryClient.invalidateQueries({ queryKey: [chainId, preset, 'EthBalance', { ownerAddress: walletAddress }], diff --git a/src/useWithdraw.ts b/src/useWithdraw.ts index 48c02d7..d19b7f7 100644 --- a/src/useWithdraw.ts +++ b/src/useWithdraw.ts @@ -162,7 +162,7 @@ export function useWithdraw({ preset, 'Balance', { - collateralTypeTokenAddress, + tokenAddress: collateralTypeTokenAddress, ownerAddress: walletAddress, }, ],