Skip to content

Commit

Permalink
Add eth token whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbqds committed Oct 27, 2023
1 parent 2ce3d4c commit dcd1df3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bridge_ui/src/hooks/useHandleAttest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
parseSequenceFromLogSolana,
parseSequenceFromLogTerra,
uint8ArrayToHex,
parseTargetChainFromLogEth
parseTargetChainFromLogEth,
CHAIN_ID_ETH
} from "@alephium/wormhole-sdk";
import { CHAIN_ID_UNSET } from "@alephium/wormhole-sdk/lib/esm";
import { Alert } from "@material-ui/lab";
Expand Down Expand Up @@ -71,7 +72,7 @@ import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry";
import parseError from "../utils/parseError";
import { signSendAndConfirm } from "../utils/solana";
import { postWithFees, waitForTerraExecution } from "../utils/terra";
import { attestFromEthWithoutWait } from "../utils/ethereum";
import { attestFromEthWithoutWait, checkETHTokenInfo } from "../utils/ethereum";
import { useWallet, Wallet as AlephiumWallet } from "@alephium/web3-react";

async function algo(
Expand Down Expand Up @@ -139,6 +140,10 @@ async function evm(
) {
dispatch(setIsSending(true));
try {
if (chainId === CHAIN_ID_ETH) {
await checkETHTokenInfo(sourceAsset)
}

// Klaytn requires specifying gasPrice
const overrides =
chainId === CHAIN_ID_KLAYTN
Expand Down
27 changes: 27 additions & 0 deletions bridge_ui/src/utils/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,36 @@ import {
} from "../hooks/useGetSourceParsedTokenAccounts";
import { BSC_RPC_HOST, CLUSTER, ETH_RPC_HOST, getTokenBridgeAddressForChain } from "./consts";
import { Multicall, ContractCallContext } from 'ethereum-multicall';
import axios from "axios"

export const DefaultEVMChainConfirmations = 15

interface TokenInfo {
address: string
name: string
symbol: string
decimals: number
logoURI: string
}

let _whitelist: TokenInfo[] | undefined = undefined

async function loadETHTokenWhitelist(): Promise<TokenInfo[]> {
if (_whitelist !== undefined) return _whitelist
const { data: { tokens } } = await axios.get('https://tokens.1inch.eth.link/')
_whitelist = tokens
return tokens
}

export async function checkETHTokenInfo(tokenAddress: string) {
if (CLUSTER !== 'mainnet') return

const tokenWhitelist = await loadETHTokenWhitelist()
if (tokenWhitelist.find((token) => token.address === tokenAddress) === undefined) {
throw new Error(`Token ${tokenAddress} does not exists in the token list`)
}
}

//This is a valuable intermediate step to the parsed token account, as the token has metadata information on it.
export async function getEthereumToken(
tokenAddress: string,
Expand Down

0 comments on commit dcd1df3

Please sign in to comment.