From b1322f0db0e2dc50a3a3c2a9ee73f0806dd86dcc Mon Sep 17 00:00:00 2001 From: Akash SM Date: Mon, 14 Aug 2023 18:32:10 +0530 Subject: [PATCH 1/6] squid router adapter hacky implementation --- package-lock.json | 2 +- src/adapters/index.ts | 2 ++ src/data/bridgeNetworkData.ts | 36 +++++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index dfdfa44d..ea7fc271 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "bridges_server", + "name": "bridges-server", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 0cf72e47..9f73b2b2 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -32,6 +32,7 @@ import meson from "./meson"; import base from "./base"; import mantle from "./mantle"; import neuron from "./neuron"; +import squidrouter from "./squidrouter" export default { polygon, @@ -66,6 +67,7 @@ export default { base, mantle, neuron, + squidrouter, } as { [bridge: string]: BridgeAdapter; }; diff --git a/src/data/bridgeNetworkData.ts b/src/data/bridgeNetworkData.ts index 5ec95199..87cefeff 100644 --- a/src/data/bridgeNetworkData.ts +++ b/src/data/bridgeNetworkData.ts @@ -265,18 +265,18 @@ export default [ gnosis: "xdai", // this is needed temporarily, need to fix and remove }, }, - // { - // id: 17, - // displayName: "Axelar", - // bridgeDbName: "axelar", - // iconLink: "icons:axelar", - // largeTxThreshold: 10000, - // url: "", - // chains: ["Ethereum", "Polygon", "Avalanche", "BSC", "Fantom", "Arbitrum"], - // chainMapping: { - // avalanche: "avax", // this is needed temporarily, need to fix and remove - // }, - // }, + { + id: 17, + displayName: "Axelar", + bridgeDbName: "axelar", + iconLink: "icons:axelar", + largeTxThreshold: 10000, + url: "", + chains: ["Ethereum", "Polygon", "Avalanche", "BSC", "Fantom", "Arbitrum"], + chainMapping: { + avalanche: "avax", // this is needed temporarily, need to fix and remove + }, + }, { id: 18, displayName: "Rainbow Bridge", @@ -471,4 +471,16 @@ export default [ // url: "", // chains: ["Arbitrum", "Linea", "Optimism", "Base"], // }, + { + id: 32, + displayName: "SquidRouter", + bridgeDbName: "squidrouter", + iconLink: "icons:axelar", + largeTxThreshold: 10000, + url: "", + chains: ["Ethereum", "Polygon", "Avalanche", "BSC", "Fantom", "Arbitrum"], + chainMapping: { + avalanche: "avax", // this is needed temporarily, need to fix and remove + }, + }, ] as BridgeNetwork[]; From d8e62b13c94f833445035c267c3fee1fe30774ab Mon Sep 17 00:00:00 2001 From: Akash SM Date: Wed, 16 Aug 2023 16:06:32 +0530 Subject: [PATCH 2/6] add squidrouter adapter --- src/helpers/processTransactions.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/helpers/processTransactions.ts b/src/helpers/processTransactions.ts index 51b322ed..aa1c41ce 100644 --- a/src/helpers/processTransactions.ts +++ b/src/helpers/processTransactions.ts @@ -190,6 +190,8 @@ export const getTxDataFromEVMEventLogs = async ( Object.entries(argKeys).map(([eventKey, argKey]) => { // @ts-ignore const value = argGetters?.[eventKey](args) || get(args, argKey); + //// DEBUG + // console.log(argGetters?.[eventKey]); if (typeof value !== EventKeyTypes[eventKey] && !Array.isArray(value)) { throw new Error( `Type of ${eventKey} retrieved using ${argKey} is ${typeof value} when it must be ${ From 73c8594eba584c5c228f077e1f0a0bf649c400a7 Mon Sep 17 00:00:00 2001 From: Akash SM Date: Wed, 16 Aug 2023 23:31:07 +0530 Subject: [PATCH 3/6] add the squid adapter --- src/adapters/squidrouter/index.ts | 125 ++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/adapters/squidrouter/index.ts diff --git a/src/adapters/squidrouter/index.ts b/src/adapters/squidrouter/index.ts new file mode 100644 index 00000000..9722e898 --- /dev/null +++ b/src/adapters/squidrouter/index.ts @@ -0,0 +1,125 @@ +import { Chain } from "@defillama/sdk/build/general"; +import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type"; +import { constructTransferParams } from "../../helpers/eventParams"; +import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions"; +import { ethers } from "ethers"; + +const squidRouterAddress = "0xce16F69375520ab01377ce7B88f5BA8C48F8D666"; + +const routerAddresses = { + ethereum: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", + bsc: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", + polygon: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", + avax: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", + fantom: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", + arbitrum: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", +} as { + [chain: string]: string; +}; + +const axelarGatewayAddresses = { + ethereum: "0x4F4495243837681061C4743b74B3eEdf548D56A5", + bsc: "0x304acf330bbE08d1e512eefaa92F6a57871fD895", + polygon: "0x6f015F16De9fC8791b234eF68D486d2bF203FBA8", + avax: "0x5029C0EFf6C34351a0CEc334542cDb22c7928f78", + fantom: "0x304acf330bbE08d1e512eefaa92F6a57871fD895", + arbitrum: "0xe432150cce91c13a887f7D836923d5597adD8E31", + } as { + [chain: string]: string; + }; + +const axelarGasService = { + ethereum: "0x2d5d7d31F671F86C782533cc367F14109a082712", + bsc: "0x2d5d7d31F671F86C782533cc367F14109a082712", + polygon: "0x2d5d7d31F671F86C782533cc367F14109a082712", + avax: "0x2d5d7d31F671F86C782533cc367F14109a082712", + fantom: "0x2d5d7d31F671F86C782533cc367F14109a082712", + arbitrum: "0x2d5d7d31F671F86C782533cc367F14109a082712", + optimism: "0x2d5d7d31F671F86C782533cc367F14109a082712" +} as { + [chain: string]: string +}; + +const nullAddress = "0x0000000000000000000000000000000000000000"; + +const TokenWithdrawalParams: PartialContractEventParams = { + target: "", + topic: "NativeGasPaidForContractCallWithToken(address,string,string,bytes32,string,uint256,uint256,address)", + topics: [ethers.utils.id("NativeGasPaidForContractCallWithToken(address,string,string,bytes32,string,uint256,uint256,address)"), ethers.utils.hexZeroPad(squidRouterAddress,32)], + abi: ["event NativeGasPaidForContractCallWithToken(address indexed sourceAddress, string destinationChain, string destinationAddress, bytes32 indexed payloadHash, string symbol, uint256 amount, uint256 gasFeeAmount, address refundAddress)"], + logKeys: { + blockNumber: "blockNumber", + txHash: "transactionHash", + // token: "token" + }, + argKeys: { + from: "refundAddress", + amount: "amount", + to: "destinationAddress", + token: "symbol" + }, + isDeposit: false, + + }; + + const GatewayWithdrawalParams: PartialContractEventParams = { + target: "", + topic: "ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)", + // topics: [ethers.utils.id("NativeGasPaidForContractCallWithToken(address,string,string,bytes32,string,uint256,uint256,address)"), ethers.utils.hexZeroPad(squidRouterAddress,32)], + abi: ["event ContractCallWithToken(address indexed sender, string destinationChain, string destinationContractAddress, bytes32 indexed payloadHash, bytes payload, string symbol, uint256 amount)"], + logKeys: { + blockNumber: "blockNumber", + txHash: "transactionHash", + // token: "token" + }, + argKeys: { + from: "payload", + amount: "amount", + to: "destinationContractAddress", + token: "symbol" + }, + argGetters: { + from: (log: any) => log.payload.slice(0,32).toHexString(), // note: this is not the real sender address + amount: (log: any) => log.amount, + to: (log: any) => log.payload.slice(10,42).toHexString(), + token: (log: any) => log.symbol, + }, + isDeposit: false, + + }; + +const constructParams = (chain: string) => { + let eventParams = [] as PartialContractEventParams[]; + const addy = axelarGasService[chain]; + +// const depositTransfer = constructTransferParams(addy, true, { +// excludeFrom: [addy, nullAddress], +// excludeTo: [nullAddress], +// includeTo: [addy], +// }); + +// const withdraw = constructTransferParams(addy, false, { +// excludeFrom: [nullAddress], +// excludeTo: [nullAddress, addy], +// includeFrom: [addy], +// }); +// const deposit = {...TokenWithdrawalParams, target: axelarGasService[chain], }; + const deposit = {...GatewayWithdrawalParams, target: axelarGatewayAddresses[chain], }; + + + eventParams.push(deposit); + + return async (fromBlock: number, toBlock: number) => + await getTxDataFromEVMEventLogs("squidrouter", chain as Chain, fromBlock, toBlock, eventParams); +}; + +const adapter: BridgeAdapter = { + polygon: constructParams("polygon"), + fantom: constructParams("fantom"), + avalanche: constructParams("avax"), + bsc: constructParams("bsc"), + ethereum: constructParams("ethereum"), + arbitrum: constructParams("arbitrum"), +}; + +export default adapter; From c1ee1f6b214c6dc47faddf5a06ff88b19d86e0cd Mon Sep 17 00:00:00 2001 From: Akash SM Date: Mon, 21 Aug 2023 22:58:28 +0530 Subject: [PATCH 4/6] squidrouter adapter working! --- src/adapters/squidrouter/index.ts | 81 +++++++++---------------------- 1 file changed, 23 insertions(+), 58 deletions(-) diff --git a/src/adapters/squidrouter/index.ts b/src/adapters/squidrouter/index.ts index 9722e898..d72d2be0 100644 --- a/src/adapters/squidrouter/index.ts +++ b/src/adapters/squidrouter/index.ts @@ -6,17 +6,6 @@ import { ethers } from "ethers"; const squidRouterAddress = "0xce16F69375520ab01377ce7B88f5BA8C48F8D666"; -const routerAddresses = { - ethereum: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", - bsc: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", - polygon: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", - avax: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", - fantom: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", - arbitrum: "0xce16F69375520ab01377ce7B88f5BA8C48F8D666", -} as { - [chain: string]: string; -}; - const axelarGatewayAddresses = { ethereum: "0x4F4495243837681061C4743b74B3eEdf548D56A5", bsc: "0x304acf330bbE08d1e512eefaa92F6a57871fD895", @@ -28,86 +17,62 @@ const axelarGatewayAddresses = { [chain: string]: string; }; -const axelarGasService = { - ethereum: "0x2d5d7d31F671F86C782533cc367F14109a082712", - bsc: "0x2d5d7d31F671F86C782533cc367F14109a082712", - polygon: "0x2d5d7d31F671F86C782533cc367F14109a082712", - avax: "0x2d5d7d31F671F86C782533cc367F14109a082712", - fantom: "0x2d5d7d31F671F86C782533cc367F14109a082712", - arbitrum: "0x2d5d7d31F671F86C782533cc367F14109a082712", - optimism: "0x2d5d7d31F671F86C782533cc367F14109a082712" -} as { - [chain: string]: string -}; - -const nullAddress = "0x0000000000000000000000000000000000000000"; -const TokenWithdrawalParams: PartialContractEventParams = { + const GatewayWithdrawalParams: PartialContractEventParams = { target: "", - topic: "NativeGasPaidForContractCallWithToken(address,string,string,bytes32,string,uint256,uint256,address)", - topics: [ethers.utils.id("NativeGasPaidForContractCallWithToken(address,string,string,bytes32,string,uint256,uint256,address)"), ethers.utils.hexZeroPad(squidRouterAddress,32)], - abi: ["event NativeGasPaidForContractCallWithToken(address indexed sourceAddress, string destinationChain, string destinationAddress, bytes32 indexed payloadHash, string symbol, uint256 amount, uint256 gasFeeAmount, address refundAddress)"], + topic: "ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)", + topics: [ethers.utils.id("ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)"), ethers.utils.hexZeroPad(squidRouterAddress,32)], + abi: ["event ContractCallWithToken(address indexed sender, string destinationChain, string destinationContractAddress, bytes32 indexed payloadHash, bytes payload, string symbol, uint256 amount)"], logKeys: { blockNumber: "blockNumber", txHash: "transactionHash", // token: "token" }, argKeys: { - from: "refundAddress", + from: "payload", amount: "amount", - to: "destinationAddress", + to: "destinationContractAddress", token: "symbol" }, + argGetters: { + from: (log: any) => "0x".concat(log.payload.substr(90,40)), // note: this is not the real sender address + amount: (log: any) => log.amount, + to: (log: any) => "0x".concat(log.payload.substr(log.payload.lastIndexOf(log.payload.substr(90,40)),40)), + token: (log: any) => log.symbol, + }, isDeposit: false, }; - const GatewayWithdrawalParams: PartialContractEventParams = { + const GatewayDepositParams: PartialContractEventParams = { target: "", - topic: "ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)", - // topics: [ethers.utils.id("NativeGasPaidForContractCallWithToken(address,string,string,bytes32,string,uint256,uint256,address)"), ethers.utils.hexZeroPad(squidRouterAddress,32)], - abi: ["event ContractCallWithToken(address indexed sender, string destinationChain, string destinationContractAddress, bytes32 indexed payloadHash, bytes payload, string symbol, uint256 amount)"], + topic: "ContractCallApprovedWithMint(bytes32,string,string,address,bytes32,string,uint256,bytes32,uint256)", + topics: [ethers.utils.id("ContractCallApprovedWithMint(bytes32,string,string,address,bytes32,string,uint256,bytes32,uint256)"), null, ethers.utils.hexZeroPad(squidRouterAddress,32)], + abi: ["event ContractCallApprovedWithMint(bytes32 indexed commandId, string sourceChain, string sourceAddress, address indexed contractAddress, bytes32 indexed payloadHash, string symbol, uint256 amount, bytes32 sourceTxHash, uint256 sourceEventIndex)"], logKeys: { blockNumber: "blockNumber", txHash: "transactionHash", // token: "token" }, argKeys: { - from: "payload", + from: "sourceAddress", amount: "amount", - to: "destinationContractAddress", + to: "contractAddress", token: "symbol" }, - argGetters: { - from: (log: any) => log.payload.slice(0,32).toHexString(), // note: this is not the real sender address - amount: (log: any) => log.amount, - to: (log: any) => log.payload.slice(10,42).toHexString(), - token: (log: any) => log.symbol, - }, - isDeposit: false, - + isDeposit: true, }; + const constructParams = (chain: string) => { let eventParams = [] as PartialContractEventParams[]; - const addy = axelarGasService[chain]; -// const depositTransfer = constructTransferParams(addy, true, { -// excludeFrom: [addy, nullAddress], -// excludeTo: [nullAddress], -// includeTo: [addy], -// }); -// const withdraw = constructTransferParams(addy, false, { -// excludeFrom: [nullAddress], -// excludeTo: [nullAddress, addy], -// includeFrom: [addy], -// }); -// const deposit = {...TokenWithdrawalParams, target: axelarGasService[chain], }; - const deposit = {...GatewayWithdrawalParams, target: axelarGatewayAddresses[chain], }; + const deposit = {...GatewayDepositParams, target: axelarGatewayAddresses[chain], }; + const withdraw = {...GatewayWithdrawalParams, target: axelarGatewayAddresses[chain], }; - eventParams.push(deposit); + eventParams.push(deposit, withdraw); return async (fromBlock: number, toBlock: number) => await getTxDataFromEVMEventLogs("squidrouter", chain as Chain, fromBlock, toBlock, eventParams); From af4f4a812af911fe6bf3c4c8bac64cea9143bc5a Mon Sep 17 00:00:00 2001 From: Akash SM Date: Mon, 21 Aug 2023 23:34:41 +0530 Subject: [PATCH 5/6] added base, linea, celo, moonbeam, kava, filecoin adapters --- src/adapters/squidrouter/index.ts | 12 ++++++++++++ src/data/bridgeNetworkData.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/adapters/squidrouter/index.ts b/src/adapters/squidrouter/index.ts index d72d2be0..11ab2e15 100644 --- a/src/adapters/squidrouter/index.ts +++ b/src/adapters/squidrouter/index.ts @@ -13,6 +13,12 @@ const axelarGatewayAddresses = { avax: "0x5029C0EFf6C34351a0CEc334542cDb22c7928f78", fantom: "0x304acf330bbE08d1e512eefaa92F6a57871fD895", arbitrum: "0xe432150cce91c13a887f7D836923d5597adD8E31", + base: "0xe432150cce91c13a887f7d836923d5597add8e31", + linea: "0xe432150cce91c13a887f7d836923d5597add8e31", + celo: "0xe432150cce91c13a887f7d836923d5597add8e31", + moonbeam: "0x4F4495243837681061C4743b74B3eEdf548D56A5", + kava: "0xe432150cce91c13a887f7D836923d5597adD8E31", + filecoin: "0xe432150cce91c13a887f7D836923d5597adD8E31" } as { [chain: string]: string; }; @@ -85,6 +91,12 @@ const adapter: BridgeAdapter = { bsc: constructParams("bsc"), ethereum: constructParams("ethereum"), arbitrum: constructParams("arbitrum"), + base: constructParams("base"), + linea: constructParams("linea"), + celo: constructParams("celo"), + moonbeam: constructParams("moonbeam"), + kava: constructParams("kava"), + filecoin: constructParams("filecoin") }; export default adapter; diff --git a/src/data/bridgeNetworkData.ts b/src/data/bridgeNetworkData.ts index 87cefeff..298799ac 100644 --- a/src/data/bridgeNetworkData.ts +++ b/src/data/bridgeNetworkData.ts @@ -478,7 +478,7 @@ export default [ iconLink: "icons:axelar", largeTxThreshold: 10000, url: "", - chains: ["Ethereum", "Polygon", "Avalanche", "BSC", "Fantom", "Arbitrum"], + chains: ["Ethereum", "Polygon", "Avalanche", "BSC", "Fantom", "Arbitrum", "Base", "Linea", "Celo", "Moonbeam", "Kava", "Filecoin"], chainMapping: { avalanche: "avax", // this is needed temporarily, need to fix and remove }, From d434a267bba1baf17f6f78d3449280b497fb9600 Mon Sep 17 00:00:00 2001 From: vrtnd Date: Tue, 22 Aug 2023 15:50:20 +0300 Subject: [PATCH 6/6] rmv old axelar --- src/data/bridgeNetworkData.ts | 41 +++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/data/bridgeNetworkData.ts b/src/data/bridgeNetworkData.ts index 298799ac..9aa2b0ba 100644 --- a/src/data/bridgeNetworkData.ts +++ b/src/data/bridgeNetworkData.ts @@ -265,18 +265,18 @@ export default [ gnosis: "xdai", // this is needed temporarily, need to fix and remove }, }, - { - id: 17, - displayName: "Axelar", - bridgeDbName: "axelar", - iconLink: "icons:axelar", - largeTxThreshold: 10000, - url: "", - chains: ["Ethereum", "Polygon", "Avalanche", "BSC", "Fantom", "Arbitrum"], - chainMapping: { - avalanche: "avax", // this is needed temporarily, need to fix and remove - }, - }, + // { + // id: 17, + // displayName: "Axelar", + // bridgeDbName: "axelar", + // iconLink: "icons:axelar", + // largeTxThreshold: 10000, + // url: "", + // chains: ["Ethereum", "Polygon", "Avalanche", "BSC", "Fantom", "Arbitrum"], + // chainMapping: { + // avalanche: "avax", // this is needed temporarily, need to fix and remove + // }, + // }, { id: 18, displayName: "Rainbow Bridge", @@ -478,9 +478,22 @@ export default [ iconLink: "icons:axelar", largeTxThreshold: 10000, url: "", - chains: ["Ethereum", "Polygon", "Avalanche", "BSC", "Fantom", "Arbitrum", "Base", "Linea", "Celo", "Moonbeam", "Kava", "Filecoin"], + chains: [ + "Ethereum", + "Polygon", + "Avalanche", + "BSC", + "Fantom", + "Arbitrum", + "Base", + "Linea", + "Celo", + "Moonbeam", + "Kava", + "Filecoin", + ], chainMapping: { avalanche: "avax", // this is needed temporarily, need to fix and remove }, - }, + }, ] as BridgeNetwork[];