Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eth token whitelist #90

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, checkETHToken } 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 checkETHToken(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 checkETHToken(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`)
Lbqds marked this conversation as resolved.
Show resolved Hide resolved
}
}

//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