|
| 1 | +import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type"; |
| 2 | +import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions"; |
| 3 | +import { Chain } from "@defillama/sdk/build/general"; |
| 4 | + |
| 5 | +const depositParams = (contractAddress: string): PartialContractEventParams => { |
| 6 | + return { |
| 7 | + target: contractAddress, |
| 8 | + topic: "TokenLocked((uint256,address,address,address,uint112,uint112,address,uint256),bytes32,uint112,uint112)", |
| 9 | + abi: [ |
| 10 | + "event TokenLocked((uint256 remoteChainId, address provider, address sourceToken, address targetToken, uint112 totalFee, uint112 amount, address receiver, uint256 timestamp) params, bytes32 transferId, uint112 targetAmount, uint112 fee)", |
| 11 | + ], |
| 12 | + logKeys: { |
| 13 | + blockNumber: "blockNumber", |
| 14 | + txHash: "transactionHash", |
| 15 | + }, |
| 16 | + argKeys: { |
| 17 | + token: "params.sourceToken", |
| 18 | + amount: "targetAmount", |
| 19 | + to: "params.receiver", |
| 20 | + }, |
| 21 | + txKeys: { |
| 22 | + from: "from", |
| 23 | + }, |
| 24 | + isDeposit: true, |
| 25 | + }; |
| 26 | +} |
| 27 | + |
| 28 | +const withdrawalParams = (contractAddress: string): PartialContractEventParams => { |
| 29 | + return { |
| 30 | + target: contractAddress, |
| 31 | + topic: "TransferFilled(bytes32,address)", |
| 32 | + abi: [ |
| 33 | + "event TransferFilled(bytes32 transferId, address provider)", |
| 34 | + ], |
| 35 | + logKeys: { |
| 36 | + blockNumber: "blockNumber", |
| 37 | + txHash: "transactionHash", |
| 38 | + }, |
| 39 | + txKeys: { |
| 40 | + to: "to", |
| 41 | + }, |
| 42 | + inputDataExtraction: { |
| 43 | + inputDataABI: [ |
| 44 | + "function relay((uint256 remoteChainId, address provider, address sourceToken, address targetToken, uint112 sourceAmount, uint112 targetAmount, address receiver, uint256 timestamp) params, bytes32 expectedTransferId, bool relayBySelf)", |
| 45 | + ], |
| 46 | + inputDataFnName: "relay", |
| 47 | + inputDataKeys: { |
| 48 | + token: "params.targetToken", |
| 49 | + amount: "params.targetAmount", |
| 50 | + }, |
| 51 | + }, |
| 52 | + fixedEventData: { |
| 53 | + from: contractAddress, |
| 54 | + }, |
| 55 | + isDeposit: false, |
| 56 | + }; |
| 57 | +} |
| 58 | + |
| 59 | +const constructParams = (chain: Chain) => { |
| 60 | + const contractAddress = "0xbA5D580B18b6436411562981e02c8A9aA1776D10" |
| 61 | + |
| 62 | + const eventParams: PartialContractEventParams[] = [ |
| 63 | + depositParams(contractAddress), |
| 64 | + withdrawalParams(contractAddress) |
| 65 | + ]; |
| 66 | + |
| 67 | + return async (fromBlock: number, toBlock: number) => |
| 68 | + getTxDataFromEVMEventLogs("helixbridge", chain as Chain, fromBlock, toBlock, eventParams); |
| 69 | +} |
| 70 | + |
| 71 | +const adapter: BridgeAdapter = { |
| 72 | + arbitrum: constructParams("arbitrum"), |
| 73 | + darwinia: constructParams("darwinia"), |
| 74 | + polygon: constructParams("polygon"), |
| 75 | + bsc: constructParams("bsc"), |
| 76 | + linea: constructParams("linea"), |
| 77 | + mantle: constructParams("mantle"), |
| 78 | + scroll: constructParams("scroll"), |
| 79 | + optimism: constructParams("optimism"), |
| 80 | + gnosis: constructParams("gnosis"), |
| 81 | +}; |
| 82 | + |
| 83 | +export default adapter; |
0 commit comments