Skip to content

Commit

Permalink
improve handling of non eth chains (#1254)
Browse files Browse the repository at this point in the history
* improve handling of non eth chains

* fix

* fix: route generation script

---------

Co-authored-by: Dong-Ha Kim <[email protected]>
  • Loading branch information
gsteenkamp89 and dohaki authored Nov 14, 2024
1 parent 4fe3f0e commit 3f2169e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions scripts/generate-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
import { utils as sdkUtils } from "@across-protocol/sdk";

import { utils } from "ethers";
import { writeFileSync } from "fs";
import * as prettier from "prettier";
Expand Down Expand Up @@ -270,12 +271,11 @@ function transformChainConfigs(
];
}

// Handle WETH Polygon
// Handle WETH Polygon & other non-eth chains
if (
tokenSymbol === "WETH" &&
[CHAIN_IDs.POLYGON, CHAIN_IDs.POLYGON_AMOY].includes(
toChainConfig.chainId
)
!toChainConfig.tokens.includes("ETH") &&
chainConfig.tokens.includes("ETH")
) {
return ["WETH", "ETH"];
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ export function getChainInfo(chainId: number): ChainInfo {
return chainInfo;
}

// For destination chains with no native ETH support, we will send WETH even if the receiver is an EOA
// TODO: add Aleph Zero here
export const nonEthChains = [ChainId.POLYGON, ChainId.POLYGON_AMOY];

export const tokenTable = Object.fromEntries(
tokenList.map((token) => {
return [token.symbol.toUpperCase(), token];
Expand Down
8 changes: 4 additions & 4 deletions src/views/Bridge/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BigNumber } from "ethers";

import {
ChainId,
Route,
SwapRoute,
fixedPointAdjustment,
Expand All @@ -11,6 +10,7 @@ import {
hubPoolChainId,
isProductionBuild,
interchangeableTokensMap,
nonEthChains,
} from "utils";
import { SwapQuoteApiResponse } from "utils/serverless-api/prod/swap-quote";

Expand Down Expand Up @@ -69,18 +69,18 @@ export function getReceiveTokenSymbol(
outputTokenSymbol: string,
isReceiverContract: boolean
) {
const isDestinationChainPolygon = destinationChainId === ChainId.POLYGON;
const isDestinationChainWethOnly = nonEthChains.includes(destinationChainId);

if (
inputTokenSymbol === "ETH" &&
(isDestinationChainPolygon || isReceiverContract)
(isDestinationChainWethOnly || isReceiverContract)
) {
return "WETH";
}

if (
inputTokenSymbol === "WETH" &&
!isDestinationChainPolygon &&
!isDestinationChainWethOnly &&
!isReceiverContract
) {
return "ETH";
Expand Down

0 comments on commit 3f2169e

Please sign in to comment.