|
| 1 | +import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type"; |
| 2 | +import { Chain } from "@defillama/sdk/build/general"; |
| 3 | +import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions"; |
| 4 | +import { BigNumber } from "ethers"; |
| 5 | + |
| 6 | +const contractAddresses = { |
| 7 | + ethereum: { |
| 8 | + gateway: "0x27ca963c279c93801941e1eb8799c23f407d68e7", // Gateway address |
| 9 | + agent: "0xd803472c47a87D7B63E888DE53f03B4191B846a8", // Agent address |
| 10 | + tokens: [ |
| 11 | + { |
| 12 | + token: "0xaa7a9ca87d3694b5755f213b5d04094b8d0f0a6f", // TracToken |
| 13 | + }, |
| 14 | + { |
| 15 | + token: "0xba41ddf06b7ffd89d1267b5a93bfef2424eb2003", // MYTH |
| 16 | + }, |
| 17 | + { |
| 18 | + token: "0x18084fba666a33d37592fa2633fd49a74dd93a88", // tBTC v2 |
| 19 | + }, |
| 20 | + { |
| 21 | + token: "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0", // wstETH |
| 22 | + }, |
| 23 | + { |
| 24 | + token: "0x45804880De22913dAFE09f4980848ECE6EcbAf78", // PAXG |
| 25 | + }, |
| 26 | + { |
| 27 | + token: "0x514910771af9ca656af840dff83e8264ecf986ca", // LINK |
| 28 | + }, |
| 29 | + { |
| 30 | + token: "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9", // AAVE |
| 31 | + }, |
| 32 | + { |
| 33 | + token: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH |
| 34 | + }, |
| 35 | + { |
| 36 | + token: "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497", // SUSDE |
| 37 | + }, |
| 38 | + { |
| 39 | + token: "0x5a98fcbea516cf06857215779fd812ca3bef1b32", // LDO |
| 40 | + }, |
| 41 | + { |
| 42 | + token: "0x5d3d01fd6d2ad1169b17918eb4f153c6616288eb", // KILT |
| 43 | + }, |
| 44 | + { |
| 45 | + token: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC |
| 46 | + }, |
| 47 | + { |
| 48 | + token: "0xdac17f958d2ee523a2206206994597c13d831ec7", // USDT |
| 49 | + }, |
| 50 | + { |
| 51 | + token: "0x56072C95FAA701256059aa122697B133aDEd9279", // SKY |
| 52 | + }, |
| 53 | + { |
| 54 | + token: "0x57e114B691Db790C35207b2e685D4A43181e6061", // ENA |
| 55 | + }, |
| 56 | + { |
| 57 | + token: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599", // WBTC |
| 58 | + }, |
| 59 | + ], |
| 60 | + }, |
| 61 | +} as { |
| 62 | + [chain: string]: { |
| 63 | + gateway: string; |
| 64 | + agent: string; |
| 65 | + tokens: { token: string }[]; |
| 66 | + }; |
| 67 | +}; |
| 68 | + |
| 69 | +const depositParams: PartialContractEventParams = { |
| 70 | + target: "", |
| 71 | + topic: "Transfer(address,address,uint256)", |
| 72 | + abi: ["event Transfer(address indexed from, address indexed to, uint256 value)"], |
| 73 | + logKeys: { |
| 74 | + blockNumber: "blockNumber", |
| 75 | + txHash: "transactionHash", |
| 76 | + }, |
| 77 | + argKeys: { |
| 78 | + amount: "value", |
| 79 | + from: "from", |
| 80 | + to: "to", |
| 81 | + }, |
| 82 | + argGetters: { |
| 83 | + amount: (log: any) => BigNumber.from(log.value), |
| 84 | + }, |
| 85 | + fixedEventData: { |
| 86 | + token: "", |
| 87 | + }, |
| 88 | + isDeposit: true, |
| 89 | +}; |
| 90 | + |
| 91 | +const withdrawalParams: PartialContractEventParams = { |
| 92 | + target: "", |
| 93 | + topic: "Transfer(address,address,uint256)", |
| 94 | + abi: ["event Transfer(address indexed from, address indexed to, uint256 value)"], |
| 95 | + logKeys: { |
| 96 | + blockNumber: "blockNumber", |
| 97 | + txHash: "transactionHash", |
| 98 | + }, |
| 99 | + argKeys: { |
| 100 | + amount: "value", |
| 101 | + from: "from", |
| 102 | + to: "to", |
| 103 | + }, |
| 104 | + fixedEventData: { |
| 105 | + token: "", |
| 106 | + }, |
| 107 | + isDeposit: false, |
| 108 | +}; |
| 109 | + |
| 110 | +const constructParams = (chain: string) => { |
| 111 | + let eventParams: PartialContractEventParams[] = []; |
| 112 | + |
| 113 | + const contractAddressesForChain = contractAddresses[chain]; |
| 114 | + const gateway = contractAddressesForChain?.gateway; |
| 115 | + const agent = contractAddressesForChain?.agent; |
| 116 | + const tokens = contractAddressesForChain?.tokens || []; |
| 117 | + |
| 118 | + tokens.map(({ token }) => { |
| 119 | + const tokenDepositParams: PartialContractEventParams = { |
| 120 | + ...depositParams, |
| 121 | + target: token, |
| 122 | + filter: { includeTo: [agent] }, |
| 123 | + fixedEventData: { ...depositParams.fixedEventData, token: token }, |
| 124 | + }; |
| 125 | + const tokenWithdrawalParams: PartialContractEventParams = { |
| 126 | + ...withdrawalParams, |
| 127 | + target: token, |
| 128 | + isDeposit: false, |
| 129 | + filter: { includeFrom: [agent] }, |
| 130 | + fixedEventData: { ...withdrawalParams.fixedEventData, token: token }, |
| 131 | + }; |
| 132 | + eventParams.push(tokenDepositParams, tokenWithdrawalParams); |
| 133 | + }); |
| 134 | + |
| 135 | + // Return a function to fetch transaction data from event logs |
| 136 | + return async (fromBlock: number, toBlock: number) => |
| 137 | + getTxDataFromEVMEventLogs("snowbridge", chain as Chain, fromBlock, toBlock, eventParams); |
| 138 | +}; |
| 139 | + |
| 140 | +// Step 6: Export the adapter |
| 141 | +const adapter: BridgeAdapter = Object.fromEntries( |
| 142 | + Object.keys(contractAddresses).map((chain) => [chain, constructParams(chain)]) |
| 143 | +); |
| 144 | + |
| 145 | +export default adapter; |
0 commit comments