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 1/2] 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 From f6cf5df8cf9e6e1d508d48ae892e4a8bbf5a6976 Mon Sep 17 00:00:00 2001 From: trajan0x Date: Tue, 16 Jul 2024 13:37:36 +0000 Subject: [PATCH 2/2] Publish - @synapsecns/synapse-interface@0.28.2 --- packages/synapse-interface/CHANGELOG.md | 8 ++++++++ packages/synapse-interface/package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/synapse-interface/CHANGELOG.md b/packages/synapse-interface/CHANGELOG.md index 7047547652..4d6f2e8bc6 100644 --- a/packages/synapse-interface/CHANGELOG.md +++ b/packages/synapse-interface/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.28.2](https://github.com/synapsecns/sanguine/compare/@synapsecns/synapse-interface@0.28.1...@synapsecns/synapse-interface@0.28.2) (2024-07-16) + +**Note:** Version bump only for package @synapsecns/synapse-interface + + + + + ## [0.28.1](https://github.com/synapsecns/sanguine/compare/@synapsecns/synapse-interface@0.28.0...@synapsecns/synapse-interface@0.28.1) (2024-07-15) **Note:** Version bump only for package @synapsecns/synapse-interface diff --git a/packages/synapse-interface/package.json b/packages/synapse-interface/package.json index 58e6f3ab0c..4ea6327c2f 100644 --- a/packages/synapse-interface/package.json +++ b/packages/synapse-interface/package.json @@ -1,6 +1,6 @@ { "name": "@synapsecns/synapse-interface", - "version": "0.28.1", + "version": "0.28.2", "private": true, "engines": { "node": ">=18.18.0"