Skip to content

Commit

Permalink
Fix Axl Network Selection (#977)
Browse files Browse the repository at this point in the history
* Fix Network Display Name

* Minor change

* Fix testnet Metamask network detection

* Fix transfer fees

* minor fix to testnet fees

Co-authored-by: jonator <[email protected]>
  • Loading branch information
JeremyParish69 and jonator authored Nov 15, 2022
1 parent 3eec2f6 commit 11c9ab3
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 79 deletions.
1 change: 1 addition & 0 deletions packages/web/config/ibc-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const IBCAssetInfos: (IBCAsset & {
method: "deposit-address" as const,
sourceChains: [
AxelarSourceChainConfigs.usdc.ethereum,
AxelarSourceChainConfigs.usdc.binance,
AxelarSourceChainConfigs.usdc.moonbeam,
],
},
Expand Down
58 changes: 35 additions & 23 deletions packages/web/integrations/axelar/source-chain-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export const SourceChainConfigs: {
} = {
usdc: {
ethereum: {
id: IS_TESTNET ? ("ethereum-2" as const) : ("Ethereum" as const),
id: IS_TESTNET
? ("Goerli Testnet" as const)
: ("Ethereum" as const),
erc20ContractAddress: IS_TESTNET
? "0x254d06f33bDc5b8ee05b2ea472107E300226659A"
: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // test: 'aUSDC' on metamask/etherscan
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: IS_TESTNET ? "150000" : "10500000", // From https://docs.axelar.dev/resources/mainnet#cross-chain-relayer-gas-fee
transferFeeMinAmount: IS_TESTNET ? "150000" : "20500000", // From https://docs.axelar.dev/resources/mainnet#cross-chain-relayer-gas-fee
},
avalanche: {
id: "Avalanche" as const,
Expand All @@ -26,7 +28,9 @@ export const SourceChainConfigs: {
transferFeeMinAmount: IS_TESTNET ? "150000" : "1500000",
},
binance: {
id: "binance" as const,
id: IS_TESTNET
? ("BSC Testnet" as const)
: ("Binance Smart Chain" as const),
erc20ContractAddress: IS_TESTNET
? "0xc2fA98faB811B785b81c64Ac875b31CC9E40F9D2"
: "0x4268B8F0B87b6Eae5d897996E6b845ddbD99Adf3",
Expand All @@ -42,7 +46,9 @@ export const SourceChainConfigs: {
transferFeeMinAmount: IS_TESTNET ? "150000" : "1500000",
},
moonbeam: {
id: "Moonbeam" as const,
id: IS_TESTNET
? ("Moonbase Alpha" as const)
: ("Moonbeam" as const),
erc20ContractAddress: IS_TESTNET
? "0xD1633F7Fb3d716643125d6415d4177bC36b7186b"
: "0xCa01a1D0993565291051daFF390892518ACfAD3A",
Expand All @@ -60,24 +66,28 @@ export const SourceChainConfigs: {
},
weth: {
ethereum: {
id: IS_TESTNET ? ("ethereum-2" as const) : ("Ethereum" as const),
id: IS_TESTNET
? ("Goerli Testnet" as const)
: ("Ethereum" as const),
erc20ContractAddress: IS_TESTNET
? "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6"
: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: IS_TESTNET ? "100000000000000" : "6300000000000000",
transferFeeMinAmount: IS_TESTNET ? "100000000000000" : "20400000000000000",
},
},
wglmr: {
moonbeam: {
id: "Moonbeam" as const,
id: IS_TESTNET
? ("Moonbase Alpha" as const)
: ("Moonbeam" as const),
erc20ContractAddress: IS_TESTNET
? "0x1436aE0dF0A8663F18c0Ec51d7e2E46591730715"
: "0xAcc15dC74880C9944775448304B263D191c6077F",
logoUrl: "/networks/moonbeam.svg",
transferFeeMinAmount: IS_TESTNET
? "40000000000000000"
: "2000000000000000000",
? "60000000000000000"
: "2900000000000000000",
},
},
wbtc: {
Expand All @@ -93,108 +103,110 @@ export const SourceChainConfigs: {
id: "Ethereum" as const,
erc20ContractAddress: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "10000000000000000000",
transferFeeMinAmount: "20500000000000000000",
},
},
dot: {
moonbeam: {
id: "Moonbeam" as const,
erc20ContractAddress: "0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080",
logoUrl: "/networks/moonbeam.svg",
transferFeeMinAmount: "1000000000",
transferFeeMinAmount: "1700000000",
},
},
usdt: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "10000000",
transferFeeMinAmount: "20500000000000000000",
},
},
frax: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0x853d955aCEf822Db058eb8505911ED77F175b99e",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "10000000000000000000",
transferFeeMinAmount: "20500000000000000000",
},
},
link: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0x514910771AF9Ca656af840dff83E8264EcF986CA",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "2000000000000000000",
transferFeeMinAmount: "3080000000000000000",
},
},
aave: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "200000000000000000",
transferFeeMinAmount: "308000000000000000",
},
},
ape: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0x4d224452801ACEd8B2F0aebE155379bb5D594381",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "2000000000000000000",
transferFeeMinAmount: "4100000000000000000",
},
},
axs: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0xBB0E17EF65F82Ab018d8EDd776e8DD940327B28b",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "700000000000000000",
transferFeeMinAmount: "1030000000000000000",
},
},
mkr: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "10000000000000000",
transferFeeMinAmount: "20600000000000000",
},
},
rai: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0x03ab458634910AaD20eF5f1C8ee96F1D6ac54919",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "3000000000000000000",
transferFeeMinAmount: "7200000000000000000",
},
},
shib: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "1000000000000000000000000",
transferFeeMinAmount: "2050000000000000000000000",
},
},
uni: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "2000000000000000000",
transferFeeMinAmount: "4100000000000000000",
},
},
xcn: {
ethereum: {
id: "Ethereum" as const,
erc20ContractAddress: "0xA2cd3D43c775978A96BdBf12d733D5A1ED94fb18",
logoUrl: "/networks/ethereum.svg",
transferFeeMinAmount: "100000000000000000000",
transferFeeMinAmount: "206000000000000000000",
},
},
wbnb: {
binance: {
id: "binance" as const,
id: IS_TESTNET
? ("BSC Testnet" as const)
: ("Binance Smart Chain" as const),
erc20ContractAddress: IS_TESTNET
? "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd"
: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
Expand Down
37 changes: 22 additions & 15 deletions packages/web/integrations/axelar/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ import { useGeneralAmountConfig } from "../use-general-amount-config";
import { useDepositAddress } from "./hooks";
import {
AxelarBridgeConfig,
SourceChain,
EthClientChainIds_AxelarChainIdsMap,
AxelarChainIds_SourceChainMap,
waitBySourceChain,
} from ".";
import {
SourceChain,
EthClientChainIds_SourceChainMap
} from "../bridge-info";
import { useAmplitudeAnalytics } from "../../hooks/use-amplitude-analytics";
import { EventName } from "../../config/user-analytics-v2";
import { useTranslation } from "react-multi-lang";
Expand Down Expand Up @@ -77,28 +80,30 @@ const AxelarTransfer: FunctionComponent<

// notify eth wallet of prev selected preferred chain
useEffect(() => {

let ethClientChainName: string | undefined = getKeyByValue(
EthClientChainIds_SourceChainMap,
selectedSourceChainKey
) ?? selectedSourceChainKey

let hexChainId: string | undefined = getKeyByValue(
ChainNames,
selectedSourceChainKey
ethClientChainName
)
? selectedSourceChainKey
? ethClientChainName
: undefined;

if (!hexChainId) {
hexChainId = getKeyByValue(
EthClientChainIds_AxelarChainIdsMap,
selectedSourceChainKey
);
}
if (!hexChainId) return;

ethWalletClient.setPreferredSourceChain(hexChainId);
}, [selectedSourceChainKey, ethWalletClient]);

/** Chain key that Axelar accepts in APIs. */
const selectedSourceChainAxelarKey =
EthClientChainIds_AxelarChainIdsMap[selectedSourceChainKey] ??
selectedSourceChainKey;
const selectedSourceChainAxelarKey = getKeyByValue(
AxelarChainIds_SourceChainMap,
selectedSourceChainKey
)
?? selectedSourceChainKey;

const sourceChainConfig = sourceChains.find(
({ id }) => id === selectedSourceChainKey
Expand Down Expand Up @@ -220,8 +225,10 @@ const AxelarTransfer: FunctionComponent<
}, [ethWalletClient.isConnected, userDisconnectedEthWallet]);

const correctChainSelected =
(EthClientChainIds_AxelarChainIdsMap[ethWalletClient.chainId as string] ??
ethWalletClient.chainId) === selectedSourceChainAxelarKey;
(EthClientChainIds_SourceChainMap[ethWalletClient.chainId as string] ??
ethWalletClient.chainId) ===
(AxelarChainIds_SourceChainMap[selectedSourceChainAxelarKey] ??
selectedSourceChainAxelarKey);

const { depositAddress, isLoading: isDepositAddressLoading } =
useDepositAddress(
Expand Down
66 changes: 29 additions & 37 deletions packages/web/integrations/axelar/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SourceChain } from "../bridge-info";

const IS_TESTNET = process.env.NEXT_PUBLIC_IS_TESTNET === "true";

export interface AxelarBridgeConfig {
Expand All @@ -24,53 +26,43 @@ export interface AxelarBridgeConfig {
};
}

/** See: https://docs.axelar.dev/dev/build/chain-names/mainnet
* See: https://docs.axelar.dev/dev/build/chain-names/testnet
* Testnet: https://axelartest-lcd.quickapi.com/axelar/nexus/v1beta1/chains?status=1
*/
export type SourceChain =
| "aurora"
| "Avalanche"
| "binance"
| "Ethereum"
| "ethereum-2"
| "Fantom"
| "Moonbeam"
| "Polygon";

/** Maps eth client chainIDs => axelar chain ids.
*
* ethClientChainIDs must be specified in ../ethereuem/types.ts::ChainNames{} to map the name to a chainID, which is in turn used to add the network to EVM-compatible wallets, like Metamask.
*
* AxelarChainIds must be specified in SourceChain{} and are used in ./source-chain-configs.ts::SourceChainConfigs{} as <asset>::<network>::id values.
*
* Values not included as keys are assumed to be the same across chainlist and Axelar.
/** Maps Axelar chain id agruments => source chain ids.
* SourceChain (IDs) are used in ./source-chain-configs.ts::SourceChainConfigs{} as <asset>::<network>::id values.
* Axelar Chain IDs are accepted as arguments in Axelar's APIs.
* Mainnet Docs: https://docs.axelar.dev/dev/build/chain-names/mainnet
* Testnet Docs: https://docs.axelar.dev/dev/build/chain-names/testnet
* Testnet API: https://axelartest-lcd.quickapi.com/axelar/nexus/v1beta1/chains?status=1
*/
export const EthClientChainIds_AxelarChainIdsMap: {
[ethClientChainIds: string]: SourceChain;
export const AxelarChainIds_SourceChainMap: {
[axelarChainIds: string]: SourceChain;
} = IS_TESTNET
? {
"Aurora Testnet": "aurora",
"Avalanche Fuji Testnet": "Avalanche",
"Binance Smart Chain Testnet": "binance",
"Goerli Test Network": "ethereum-2",
"Fantom Testnet": "Fantom",
"Moonbase Alpha": "Moonbeam",
Mumbai: "Polygon",
"aurora": "Aurora Testnet",
"Avalanche": "Avalanche Fuji Testnet",
"binance": "BSC Testnet",
"ethereum-2": "Goerli Testnet",
"Fantom": "Fantom Testnet",
"Moonbeam": "Moonbase Alpha",
"Polygon": "Mumbai"
}
: {
"Avalanche C-Chain": "Avalanche",
"Binance Smart Chain Mainnet": "binance",
"Ethereum Main Network": "Ethereum",
"Fantom Opera": "Fantom",
"Moonbeam Mainnet": "Moonbeam",
"Polygon Mainnet": "Polygon",
"Avalanche": "Avalanche",
"binance": "Binance Smart Chain",
"Ethereum": "Ethereum",
"Fantom": "Fantom",
"Moonbeam": "Moonbeam",
"Polygon": "Polygon"
};


export type SourceChainConfig = {
/** Axelar-defined identifier. */

/** Source Chain identifier. */
id: SourceChain;
/** Address of origin ERC20 token for that origin chain. Leave blank to prefer native ETH currency if `id` is not a Cosmos chain in `ChainInfo`.

/** Address of origin ERC20 token for that origin chain. Leave blank to
* prefer native ETH currency if `id` is not a Cosmos chain in `ChainInfo`.
*/
erc20ContractAddress?: string;

Expand Down
2 changes: 1 addition & 1 deletion packages/web/integrations/axelar/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SourceChain } from "./types";
import { SourceChain } from "../bridge-info";
import { t } from "react-multi-lang";

export function waitBySourceChain(sourceChain: SourceChain) {
Expand Down
Loading

1 comment on commit 11c9ab3

@vercel
Copy link

@vercel vercel bot commented on 11c9ab3 Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.