|
| 1 | +import { Chain } from "@defillama/sdk/build/general"; |
| 2 | +import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type"; |
| 3 | +import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions"; |
| 4 | + |
| 5 | +const contractAddresses = { |
| 6 | + bsc: { |
| 7 | + mosContract: "0xfeB2b97e4Efce787c08086dC16Ab69E063911380", |
| 8 | + tokens: { |
| 9 | + USDT: "0x55d398326f99059fF775485246999027B3197955", |
| 10 | + USDC: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d", |
| 11 | + DAI: "0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3", |
| 12 | + ETH: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", |
| 13 | + MAP: "0x8105ECe4ce08B6B6449539A5db23e23b973DfA8f" |
| 14 | + } |
| 15 | + }, |
| 16 | + polygon: { |
| 17 | + mosContract: "0xfeB2b97e4Efce787c08086dC16Ab69E063911380", |
| 18 | + tokens: { |
| 19 | + USDT: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f", |
| 20 | + USDC: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", |
| 21 | + DAI: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063", |
| 22 | + ETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619", |
| 23 | + MAP: "0xBAbceE78586d3e9E80E0d69601A17f983663Ba6a" |
| 24 | + } |
| 25 | + }, |
| 26 | + ethereum: { |
| 27 | + mosContract: "0xfeB2b97e4Efce787c08086dC16Ab69E063911380", |
| 28 | + tokens: { |
| 29 | + USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7", |
| 30 | + USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", |
| 31 | + DAI: "0x6B175474E89094C44Da98b954EedeAC495271d0F", |
| 32 | + ETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", |
| 33 | + MAP: "0x9e976f211daea0d652912ab99b0dc21a7fd728e4" |
| 34 | + } |
| 35 | + }, |
| 36 | + map: { |
| 37 | + mosContract: "0xfeB2b97e4Efce787c08086dC16Ab69E063911380", |
| 38 | + tokens: { |
| 39 | + USDT: "0x33daba9618a75a7aff103e53afe530fbacf4a3dd", |
| 40 | + USDC: "0x9f722b2cb30093f766221fd0d37964949ed66918", |
| 41 | + DAI: "0xEdDfAac857cb94aE8A0347e2b1b06f21AA1AAeFA", |
| 42 | + ETH: "0x05ab928d446d8ce6761e368c8e7be03c3168a9ec", |
| 43 | + MAP: "0x13cb04d4a5dfb6398fc5ab005a6c84337256ee23" |
| 44 | + } |
| 45 | + } |
| 46 | +} as { |
| 47 | + [chain: string]: { |
| 48 | + mosContract: string; |
| 49 | + tokens: {}; |
| 50 | + }; |
| 51 | +}; |
| 52 | + |
| 53 | +const tokenDepositParams: PartialContractEventParams = { |
| 54 | + target: "", |
| 55 | + topic: "mapSwapIn(uint256,uint256,bytes32,address,bytes,address,uint256)", |
| 56 | + abi: [ |
| 57 | + "event mapSwapIn(uint256 indexed fromChain, uint256 indexed toChain, bytes32 indexed orderId, address token, bytes from, address toAddress, uint256 amountOut)" |
| 58 | + ], |
| 59 | + logKeys: { |
| 60 | + blockNumber: "blockNumber", |
| 61 | + txHash: "transactionHash" |
| 62 | + }, |
| 63 | + argKeys: { |
| 64 | + from: "from", |
| 65 | + to: "toAddress", |
| 66 | + token: "token", |
| 67 | + amount: "amountOut" |
| 68 | + }, |
| 69 | + isDeposit: true |
| 70 | +}; |
| 71 | + |
| 72 | +const tokenWithdrawalParams: PartialContractEventParams = { |
| 73 | + target: "", |
| 74 | + topic: "mapSwapOut(uint256,uint256,bytes32,bytes,bytes,bytes,uint256,bytes)", |
| 75 | + abi: ["event mapSwapOut(uint256 indexed fromChain, uint256 indexed toChain, bytes32 orderId, bytes token, bytes from, bytes to, uint256 amount, bytes swapData)"], |
| 76 | + logKeys: { |
| 77 | + blockNumber: "blockNumber", |
| 78 | + txHash: "transactionHash" |
| 79 | + }, |
| 80 | + argKeys: { |
| 81 | + to: "to", |
| 82 | + amount: "amount" |
| 83 | + }, |
| 84 | + isDeposit: false |
| 85 | +}; |
| 86 | + |
| 87 | +const constructParams = (chain: string) => { |
| 88 | + let eventParams = [] as any; |
| 89 | + |
| 90 | + const chainAddresses = contractAddresses[chain] |
| 91 | + const mos = chainAddresses.mosContract; |
| 92 | + const tokens = chainAddresses.tokens; |
| 93 | + |
| 94 | + // const finalMOSDepositParams = { |
| 95 | + // ...tokenDepositParams, |
| 96 | + // target: mos, |
| 97 | + // fixedEventData: { |
| 98 | + // to: mos |
| 99 | + // } |
| 100 | + // }; |
| 101 | + // const finalMOSWithdrawalParams = { |
| 102 | + // ...tokenWithdrawalParams, |
| 103 | + // target: mos, |
| 104 | + // fixedEventData: { |
| 105 | + // from: mos |
| 106 | + // } |
| 107 | + // }; |
| 108 | + // eventParams.push(finalMOSDepositParams, finalMOSWithdrawalParams); |
| 109 | + |
| 110 | + for (let token of Object.values(tokens)) { |
| 111 | + const finalTokenDepositParams = { |
| 112 | + ...tokenDepositParams, |
| 113 | + target: token, |
| 114 | + fixedEventData: { |
| 115 | + to: mos, |
| 116 | + token: token |
| 117 | + } |
| 118 | + }; |
| 119 | + const finalTokenWithdrawalParams = { |
| 120 | + ...tokenWithdrawalParams, |
| 121 | + target: token, |
| 122 | + fixedEventData: { |
| 123 | + from: mos, |
| 124 | + token: token |
| 125 | + } |
| 126 | + }; |
| 127 | + eventParams.push(finalTokenDepositParams, finalTokenWithdrawalParams); |
| 128 | + } |
| 129 | + |
| 130 | + return async (fromBlock: number, toBlock: number) => |
| 131 | + getTxDataFromEVMEventLogs("butternetwork", chain as Chain, fromBlock, toBlock, eventParams); |
| 132 | +}; |
| 133 | + |
| 134 | + |
| 135 | +const adapter: BridgeAdapter = { |
| 136 | + bsc: constructParams("bsc"), |
| 137 | + polygon: constructParams("polygon"), |
| 138 | + ethereum: constructParams("ethereum"), |
| 139 | + 'map relay chain': constructParams("map") |
| 140 | +}; |
| 141 | + |
| 142 | +export default adapter; |
| 143 | + |
0 commit comments