From 8ebade893da07ab97c0da4eb1210cfc7b194224c Mon Sep 17 00:00:00 2001 From: aureliusbtc <82057759+aureliusbtc@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:09:45 +0200 Subject: [PATCH 1/5] Init lifi approval revoke page --- .../synapse-interface/pages/lifi/index.tsx | 176 ++++++++++++++++++ 1 file changed, 176 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..149efa4c2a --- /dev/null +++ b/packages/synapse-interface/pages/lifi/index.tsx @@ -0,0 +1,176 @@ +import Grid from '@tw/Grid' +import { useEffect, useState } from 'react' +import { useAccount } from 'wagmi' + +import { DEFAULT_FROM_CHAIN } from '@/constants/swap' +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 LifiPage = () => { + const { address: currentAddress, chain, isConnected } = useAccount() + const [connectedChainId, setConnectedChainId] = useState(0) + const [address, setAddress] = useState(undefined) + const { openConnectModal } = useConnectModal() + + useEffect(() => { + setConnectedChainId(chain?.id ?? DEFAULT_FROM_CHAIN) + }, [chain]) + + useEffect(() => { + setAddress(currentAddress) + }, [currentAddress]) + + const usdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' + const usdtAddress = '0xdac17f958d2ee523a2206206994597c13d831ec7' + const wethAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' + + const [usdcAllowance, setUsdcAllowance] = useState(0n) + const [usdtAllowance, setUsdtAllowance] = useState(0n) + const [wethAllowance, setWethAllowance] = useState(0n) + + useEffect(() => { + const fetchAllowances = async () => { + if (address) { + const usdcAllowance = await getErc20TokenAllowance({ + address: "0xbc6f5a4ed57f16af3db54da801aba8d1dc4ed675", + chainId: connectedChainId, + tokenAddress: usdcAddress, + spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", + }) + setUsdcAllowance(usdcAllowance) + + const usdtAllowance = await getErc20TokenAllowance({ + address: "0xbc6f5a4ed57f16af3db54da801aba8d1dc4ed675", + chainId: connectedChainId, + tokenAddress: usdtAddress, + spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", + }) + setUsdtAllowance(usdtAllowance) + + const wethAllowance = await getErc20TokenAllowance({ + address: "0xbc6f5a4ed57f16af3db54da801aba8d1dc4ed675", + chainId: connectedChainId, + tokenAddress: wethAddress, + spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", + }) + setWethAllowance(wethAllowance) + } + } + + fetchAllowances() + }, [address, connectedChainId]) + + + + return ( + + +
+
+
+ Revoke Li.fi Approvals +
+
+
+
+ +
+
+
USDC Allowance At Risk: {usdcAllowance.toString()}
+
USDT Allowance At Risk: {usdtAllowance.toString()}
+
WETH Allowance at Risk: {wethAllowance.toString()}
+
+
+ {!isConnected && ( +
+ + new Promise((resolve, reject) => { + try { + openConnectModal() + resolve(true) + } catch (e) { + reject(e) + } + }) + } + /> +
+ )} + {usdcAllowance > 0n && ( + { + await approveToken( + "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", + connectedChainId, + usdcAddress, + 0n, + ) + setUsdcAllowance(0n) + }} + /> + )} + + {usdtAllowance > 0n && ( + { + await approveToken( + "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", + connectedChainId, + usdtAddress, + 0n, + ) + setUsdtAllowance(0n) + }} + /> + )} + + {wethAllowance > 0n && ( + { + await approveToken( + "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", + connectedChainId, + wethAddress, + 0n, + ) + setWethAllowance(0n) + }} + /> + )} +
+
+
+
+ ) +} + +export default LifiPage From 1244bde41d079ae84115b6bcfdbfd6977f0c4407 Mon Sep 17 00:00:00 2001 From: aureliusbtc <82057759+aureliusbtc@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:18:34 +0200 Subject: [PATCH 2/5] get rid of victim address and use connected address --- packages/synapse-interface/pages/lifi/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/synapse-interface/pages/lifi/index.tsx b/packages/synapse-interface/pages/lifi/index.tsx index 149efa4c2a..7287eaa14c 100644 --- a/packages/synapse-interface/pages/lifi/index.tsx +++ b/packages/synapse-interface/pages/lifi/index.tsx @@ -36,7 +36,7 @@ const LifiPage = () => { const fetchAllowances = async () => { if (address) { const usdcAllowance = await getErc20TokenAllowance({ - address: "0xbc6f5a4ed57f16af3db54da801aba8d1dc4ed675", + address: currentAddress, chainId: connectedChainId, tokenAddress: usdcAddress, spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", @@ -44,7 +44,7 @@ const LifiPage = () => { setUsdcAllowance(usdcAllowance) const usdtAllowance = await getErc20TokenAllowance({ - address: "0xbc6f5a4ed57f16af3db54da801aba8d1dc4ed675", + address: currentAddress, chainId: connectedChainId, tokenAddress: usdtAddress, spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", @@ -52,7 +52,7 @@ const LifiPage = () => { setUsdtAllowance(usdtAllowance) const wethAllowance = await getErc20TokenAllowance({ - address: "0xbc6f5a4ed57f16af3db54da801aba8d1dc4ed675", + address: currentAddress, chainId: connectedChainId, tokenAddress: wethAddress, spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", From 5382c4e2b007400b60d77087f645f5d374d54722 Mon Sep 17 00:00:00 2001 From: aureliusbtc <82057759+aureliusbtc@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:22:49 +0200 Subject: [PATCH 3/5] Add some text --- packages/synapse-interface/pages/lifi/index.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/synapse-interface/pages/lifi/index.tsx b/packages/synapse-interface/pages/lifi/index.tsx index 7287eaa14c..e1d14bf70d 100644 --- a/packages/synapse-interface/pages/lifi/index.tsx +++ b/packages/synapse-interface/pages/lifi/index.tsx @@ -87,6 +87,10 @@ const LifiPage = () => { >
+

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:

+
USDC Allowance At Risk: {usdcAllowance.toString()}
USDT Allowance At Risk: {usdtAllowance.toString()}
WETH Allowance at Risk: {wethAllowance.toString()}
From 84788c67ff456b628f69279c323e550126a0489f Mon Sep 17 00:00:00 2001 From: aureliusbtc <82057759+aureliusbtc@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:24:43 +0200 Subject: [PATCH 4/5] Only show approval data once connected --- packages/synapse-interface/pages/lifi/index.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/synapse-interface/pages/lifi/index.tsx b/packages/synapse-interface/pages/lifi/index.tsx index e1d14bf70d..7bf909f4a5 100644 --- a/packages/synapse-interface/pages/lifi/index.tsx +++ b/packages/synapse-interface/pages/lifi/index.tsx @@ -91,9 +91,13 @@ const LifiPage = () => {

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


-
USDC Allowance At Risk: {usdcAllowance.toString()}
-
USDT Allowance At Risk: {usdtAllowance.toString()}
-
WETH Allowance at Risk: {wethAllowance.toString()}
+ {isConnected && ( + <> +
USDC Allowance At Risk: {usdcAllowance.toString()}
+
USDT Allowance At Risk: {usdtAllowance.toString()}
+
WETH Allowance at Risk: {wethAllowance.toString()}
+ + )}
{!isConnected && ( @@ -105,7 +109,7 @@ const LifiPage = () => { border: '1px solid #9B6DD7', borderRadius: '4px', }} - label="Connect wallet" + label="Connect wallet to check for approvals" pendingLabel="Connecting" onClick={() => new Promise((resolve, reject) => { From 8c6a56c252d01097ad1a035f7e9d420ace46965a Mon Sep 17 00:00:00 2001 From: aureliusbtc <82057759+aureliusbtc@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:32:55 +0200 Subject: [PATCH 5/5] Multi-chain checker --- .../synapse-interface/pages/lifi/index.tsx | 241 ++++++++---------- 1 file changed, 102 insertions(+), 139 deletions(-) diff --git a/packages/synapse-interface/pages/lifi/index.tsx b/packages/synapse-interface/pages/lifi/index.tsx index 7bf909f4a5..954f130751 100644 --- a/packages/synapse-interface/pages/lifi/index.tsx +++ b/packages/synapse-interface/pages/lifi/index.tsx @@ -1,8 +1,8 @@ import Grid from '@tw/Grid' import { useEffect, useState } from 'react' -import { useAccount } from 'wagmi' +import { useAccount, useAccountEffect, useSwitchChain } from 'wagmi' + -import { DEFAULT_FROM_CHAIN } from '@/constants/swap' import { LandingPageWrapper } from '@layouts/LandingPageWrapper' import StandardPageContainer from '@layouts/StandardPageContainer' import { getErc20TokenAllowance } from '@/actions/getErc20TokenAllowance' @@ -10,72 +10,80 @@ import { approveToken } from '@/utils/approveToken' import { TransactionButton } from '@/components/buttons/TransactionButton' import { useConnectModal } from '@rainbow-me/rainbowkit' -const LifiPage = () => { - const { address: currentAddress, chain, isConnected } = useAccount() - const [connectedChainId, setConnectedChainId] = useState(0) - const [address, setAddress] = useState(undefined) - const { openConnectModal } = useConnectModal() - - useEffect(() => { - setConnectedChainId(chain?.id ?? DEFAULT_FROM_CHAIN) - }, [chain]) +const CHAIN_IDS = [1, 42161, 10] +const LIFI_SPENDER = "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae" - useEffect(() => { - setAddress(currentAddress) - }, [currentAddress]) +const TOKENS = { + USDC: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', + USDT: '0xdac17f958d2ee523a2206206994597c13d831ec7', + WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' +} as const; - const usdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' - const usdtAddress = '0xdac17f958d2ee523a2206206994597c13d831ec7' - const wethAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' - - const [usdcAllowance, setUsdcAllowance] = useState(0n) - const [usdtAllowance, setUsdtAllowance] = useState(0n) - const [wethAllowance, setWethAllowance] = useState(0n) - - useEffect(() => { - const fetchAllowances = async () => { - if (address) { - const usdcAllowance = await getErc20TokenAllowance({ - address: currentAddress, - chainId: connectedChainId, - tokenAddress: usdcAddress, - spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", - }) - setUsdcAllowance(usdcAllowance) - - const usdtAllowance = await getErc20TokenAllowance({ - address: currentAddress, - chainId: connectedChainId, - tokenAddress: usdtAddress, - spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", - }) - setUsdtAllowance(usdtAllowance) - - const wethAllowance = await getErc20TokenAllowance({ - address: currentAddress, - chainId: connectedChainId, - tokenAddress: wethAddress, - spender: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", - }) - setWethAllowance(wethAllowance) - } - } +interface TokenAllowances { + [chainId: number]: { + [token: string]: bigint + } +} - fetchAllowances() - }, [address, connectedChainId]) +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 + Revoke Li.fi Approvals (Multi-chain)
@@ -86,94 +94,49 @@ const LifiPage = () => { className="justify-center px-2 py-16 sm:px-6 md:px-8" >
-
-

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 && ( - <> -
USDC Allowance At Risk: {usdcAllowance.toString()}
-
USDT Allowance At Risk: {usdtAllowance.toString()}
-
WETH Allowance at Risk: {wethAllowance.toString()}
- - )} -
-
- {!isConnected && ( -
- - new Promise((resolve, reject) => { - try { +
+

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) - } catch (e) { - reject(e) - } - }) - } - /> + })} + /> +
+ )}
- )} - {usdcAllowance > 0n && ( - { - await approveToken( - "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", - connectedChainId, - usdcAddress, - 0n, - ) - setUsdcAllowance(0n) - }} - /> - )} - - {usdtAllowance > 0n && ( - { - await approveToken( - "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", - connectedChainId, - usdtAddress, - 0n, - ) - setUsdtAllowance(0n) - }} - /> - )} - - {wethAllowance > 0n && ( - { - await approveToken( - "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae", - connectedChainId, - wethAddress, - 0n, - ) - setWethAllowance(0n) - }} - /> - )} +