From 9a84556c5328dc4d094e5c869eb59f1f2324260b Mon Sep 17 00:00:00 2001 From: aureliusbtc <82057759+aureliusbtc@users.noreply.github.com> Date: Tue, 16 Jul 2024 09:33:23 -0400 Subject: [PATCH] FE LiFi: Revoke approvals (#2874) * Init lifi approval revoke page * get rid of victim address and use connected address * Add some text * Only show approval data once connected * Multi-chain checker --- .../synapse-interface/pages/lifi/index.tsx | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 packages/synapse-interface/pages/lifi/index.tsx diff --git a/packages/synapse-interface/pages/lifi/index.tsx b/packages/synapse-interface/pages/lifi/index.tsx new file mode 100644 index 0000000000..954f130751 --- /dev/null +++ b/packages/synapse-interface/pages/lifi/index.tsx @@ -0,0 +1,147 @@ +import Grid from '@tw/Grid' +import { useEffect, useState } from 'react' +import { useAccount, useAccountEffect, useSwitchChain } from 'wagmi' + + +import { LandingPageWrapper } from '@layouts/LandingPageWrapper' +import StandardPageContainer from '@layouts/StandardPageContainer' +import { getErc20TokenAllowance } from '@/actions/getErc20TokenAllowance' +import { approveToken } from '@/utils/approveToken' +import { TransactionButton } from '@/components/buttons/TransactionButton' +import { useConnectModal } from '@rainbow-me/rainbowkit' + +const CHAIN_IDS = [1, 42161, 10] +const LIFI_SPENDER = "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae" + +const TOKENS = { + USDC: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', + USDT: '0xdac17f958d2ee523a2206206994597c13d831ec7', + WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' +} as const; + +interface TokenAllowances { + [chainId: number]: { + [token: string]: bigint + } +} + +const LifiPage = () => { + const { address, isConnected, chain } = useAccount() + const { chains, switchChain: switchNetwork } = useSwitchChain() + const { openConnectModal } = useConnectModal() + + const [allowances, setAllowances] = useState({}) + + useEffect(() => { + const fetchAllowances = async () => { + if (address) { + const newAllowances: TokenAllowances = {} + + for (const chainId of CHAIN_IDS) { + newAllowances[chainId] = {} + + for (const [tokenName, tokenAddress] of Object.entries(TOKENS)) { + const allowance = await getErc20TokenAllowance({ + address, + chainId, + tokenAddress, + spender: LIFI_SPENDER, + }) + newAllowances[chainId][tokenName] = allowance + } + } + + setAllowances(newAllowances) + } + } + + if (isConnected) { + fetchAllowances() + } + }, [address, isConnected]) + + const handleRevoke = async (chainId: number, tokenName: string, tokenAddress: string) => { + if (chain?.id !== chainId) { + await switchNetwork({chainId: chainId}) + } + await approveToken(LIFI_SPENDER, chainId, tokenAddress, 0n) + setAllowances(prev => ({ + ...prev, + [chainId]: { + ...prev[chainId], + [tokenName]: 0n + } + })) + } + + return ( + + +
+
+
+ Revoke Li.fi Approvals (Multi-chain) +
+
+
+
+ +
+
+

Li.fi / Jumper is investigating an ongoing exploit, and users should revoke approvals - Li.fi Tweet

+
+

Check to see if you have any approvals at risk below:

+
+ {isConnected ? ( + CHAIN_IDS.map(chainId => ( +
+

Chain ID: {chainId}

+ {Object.entries(allowances[chainId] || {}).map(([tokenName, allowance]) => ( +
+ {tokenName} Allowance: {allowance.toString()} + {allowance > 0n && ( + handleRevoke(chainId, tokenName, TOKENS[tokenName])} + /> + )} +
+ ))} +
+ )) + ) : ( +
+ new Promise((resolve) => { + openConnectModal() + resolve(true) + })} + /> +
+ )} +
+
+
+
+
+
+ ) +} + +export default LifiPage