Skip to content

Commit

Permalink
Merge pull request #266 from XY-Finance/feature/xy_finance_native_tok…
Browse files Browse the repository at this point in the history
…ens_map

XY Finance: add NativeTokens maps
  • Loading branch information
vrtnd authored Aug 11, 2024
2 parents efa4baf + 9ef9296 commit 48d2c2d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/adapters/xy-finance/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,32 @@ export enum VAULTS_TOKEN {
ETH
}

type ContractAddress = string
type Address = string
type YBridgeVaultsTokenAddress = Record<VAULTS_TOKEN, {
contractAddress: ContractAddress
tokenAddress: ContractAddress
contractAddress: Address
tokenAddress: Address
}>

export const ETH_ADDRESS: Address = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'

export const NativeTokens: Partial<Record<Chain, string>> = {
[Chain.Ethereum]: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
[Chain.Arbitrum]: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
[Chain.Optimism]: "0x4200000000000000000000000000000000000006",
[Chain.Base]: "0x4200000000000000000000000000000000000006",
[Chain.Linea]: "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",
[Chain.Blast]: "0x4300000000000000000000000000000000000004",
[Chain.Polygon]: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
[Chain.Scroll]: "0x5300000000000000000000000000000000000004",
[Chain.PolygonZkevm]: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
[Chain.ZkSync]: "0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91",
[Chain.XLayer]: "0x5a77f1443d16ee5761d310e38b62f77f726bc71c",
[Chain.Bsc]: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
[Chain.Mantle]: "0xdeaddeaddeaddeaddeaddeaddeaddeaddead1111",
[Chain.Taiko]: "0xA51894664A773981C6C112C43ce576f315d5b1B6",
[Chain.Avalanche]: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
};

export const YBridgeVaultsTokenContractAddress: Record<Exclude<Chain, Chain.Numbers>, YBridgeVaultsTokenAddress> = {
[Chain.Ethereum]: {
[VAULTS_TOKEN.USDT]: {
Expand Down Expand Up @@ -361,7 +382,7 @@ export const YBridgeVaultsTokenContractAddress: Record<Exclude<Chain, Chain.Numb
}
}

export const YBridgeContractAddress: Record<Exclude<Chain, Chain.Numbers>, ContractAddress> = {
export const YBridgeContractAddress: Record<Exclude<Chain, Chain.Numbers>, Address> = {
[Chain.Ethereum]: '0x4315f344a905dC21a08189A117eFd6E1fcA37D57',
[Chain.Scroll]: "0x778C974568e376146dbC64fF12aD55B2d1c4133f",
[Chain.Mantle]: "0x73Ce60416035B8D7019f6399778c14ccf5C9c7A1",
Expand All @@ -387,7 +408,7 @@ export const YBridgeContractAddress: Record<Exclude<Chain, Chain.Numbers>, Contr
[Chain.Taiko]: "0x73Ce60416035B8D7019f6399778c14ccf5C9c7A1"
}

export const XYRouterContractAddress: Record<Chain, ContractAddress> = {
export const XYRouterContractAddress: Record<Chain, Address> = {
[Chain.Ethereum]: "0xFfB9faf89165585Ad4b25F81332Ead96986a2681",
[Chain.Scroll]: "0x22bf2A9fcAab9dc96526097318f459eF74277042",
[Chain.Mantle]: "0x52075Fd1fF67f03beABCb5AcdA9679b02d98cA37",
Expand Down
18 changes: 18 additions & 0 deletions src/adapters/xy-finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { BridgeAdapter, ContractEventParams, PartialContractEventParams } from "
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import {
Chain,
ETH_ADDRESS,
NativeTokens,
XYRouterContractAddress,
YBridgeContractAddress,
YBridgeVaultsTokenContractAddress
Expand All @@ -28,6 +30,13 @@ const getYBridgeSwapRequestedEventParams = (chain: Exclude<Chain, Chain.Numbers>
to: "_referrer",
},
argGetters: {
token: (log: any) => {
const token = log?._vaultToken
if (token?.toLowerCase() === ETH_ADDRESS.toLowerCase()) {
return NativeTokens[chain] || token
}
return token
},
to: (log: any) => {
const vaultToken = log?._vaultToken
const toVaultContract = find(YBridgeVaultsTokenContractAddress[chain], { tokenAddress: vaultToken })?.contractAddress
Expand Down Expand Up @@ -56,6 +65,15 @@ const getYBridgeSwappedForUserEventParams = (chain: Exclude<Chain, Chain.Numbers
from: "_srcToken",
to: "_receiver",
},
argGetters: {
token: (log: any) => {
const token = log?._dstToken
if (token?.toLowerCase() === ETH_ADDRESS.toLowerCase()) {
return NativeTokens[chain] || token
}
return token
},
},
isDeposit: false,
}
}
Expand Down

0 comments on commit 48d2c2d

Please sign in to comment.