1
+ import { BridgeAdapter , PartialContractEventParams } from "../../helpers/bridgeAdapter.type" ;
2
+ import { Chain } from "@defillama/sdk/build/general" ;
3
+ import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions" ;
4
+ import { ethers } from "ethers" ;
5
+
6
+ const contractAddresses = {
7
+ //EverclearSpoke contract addresses for each chain
8
+ ethereum : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
9
+ optimism : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
10
+ bsc : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
11
+ unichain : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
12
+ polygon : [ "0x7189C59e245135696bFd2906b56607755F84F3fD" ] ,
13
+ zksync : [ "0x7F5e085981C93C579c865554B9b723B058AaE4D3" ] ,
14
+ ronin : [ "0xdCA40903E271Cc76AECd62dF8D6c19f3Ac873E64" ] ,
15
+ base : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
16
+ apechain : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
17
+ mode : [ "0xeFa6Ac3F931620fD0449eC8c619f2A14A0A78E99" ] ,
18
+ arbitrum : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
19
+ avalanche : [ "0x9aA2Ecad5C77dfcB4f34893993f313ec4a370460" ] ,
20
+ zircuit : [ "0xD0E86F280D26Be67A672d1bFC9bB70500adA76fe" ] ,
21
+ linea : [ "0xc24dC29774fD2c1c0c5FA31325Bb9cbC11D8b751" ] ,
22
+ blast : [ "0x9ADA72CCbAfe94248aFaDE6B604D1bEAacc899A7" ] ,
23
+ scroll : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
24
+ taiko : [ "0x9ADA72CCbAfe94248aFaDE6B604D1bEAacc899A7" ] ,
25
+ sonic : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
26
+ berachain : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
27
+ mantle : [ "0xe0F010e465f15dcD42098dF9b99F1038c11B3056" ] ,
28
+ ink : [ "0xa05A3380889115bf313f1Db9d5f335157Be4D816" ] ,
29
+ } as const ;
30
+
31
+ // Helper function to convert bytes32 to address
32
+ function bytes32ToAddress ( bytes32 : string ) {
33
+ return ethers . utils . getAddress ( '0x' + bytes32 . slice ( 26 ) ) ;
34
+ }
35
+
36
+ // Deposit event (IntentAdded)
37
+ const depositIntent : PartialContractEventParams = {
38
+ target : "" ,
39
+ topic : "IntentAdded(bytes32,bytes32,(bytes32,bytes32,bytes32,bytes32,uint24,uint32,uint64,uint48,uint48,uint256,uint32[],bytes))" ,
40
+ abi : [
41
+ "event IntentAdded(bytes32 indexed _intentId, bytes32 indexed _queueId, tuple(bytes32 initiator, bytes32 receiver, bytes32 inputAsset, bytes32 outputAsset, uint24 maxFee, uint32 origin, uint64 nonce, uint48 timestamp, uint48 ttl, uint256 amount, uint32[] destinations, bytes data) _intent)" ,
42
+ ] ,
43
+ logKeys : {
44
+ blockNumber : "blockNumber" ,
45
+ txHash : "transactionHash" ,
46
+ } ,
47
+ argKeys : {
48
+ amount : "_intent.amount" ,
49
+ from : "_intent.initiator" ,
50
+ token : "_intent.inputAsset" ,
51
+ } ,
52
+ argGetters : {
53
+ from : ( logArgs : any ) => bytes32ToAddress ( logArgs . _intent . initiator ) ,
54
+ token : ( logArgs : any ) => bytes32ToAddress ( logArgs . _intent . inputAsset )
55
+ } ,
56
+ isDeposit : true ,
57
+ } ;
58
+
59
+ // Withdrawal event (Settled)
60
+ const withdrawalIntent : PartialContractEventParams = {
61
+ target : "" ,
62
+ topic : "Settled(bytes32,address,address,uint256)" ,
63
+ abi : [
64
+ "event Settled(bytes32 indexed _intentId, address _account, address _asset, uint256 _amount)" ,
65
+ ] ,
66
+ logKeys : {
67
+ blockNumber : "blockNumber" ,
68
+ txHash : "transactionHash" ,
69
+ } ,
70
+ argKeys : {
71
+ amount : "_amount" ,
72
+ to : "_account" ,
73
+ from : "_account" ,
74
+ token : "_asset" ,
75
+ } ,
76
+ isDeposit : false ,
77
+ } ;
78
+
79
+ const constructParams = ( chain : Chain ) => {
80
+ const chainConfig = contractAddresses [ chain as keyof typeof contractAddresses ] ;
81
+
82
+ // Create event params for both deposit and withdrawal events for each contract address
83
+ const eventParams : PartialContractEventParams [ ] = [ ] ;
84
+
85
+ // Add deposit (IntentAdded) events
86
+ chainConfig . forEach ( address => {
87
+ eventParams . push ( { ...depositIntent , target : address } ) ;
88
+ } ) ;
89
+
90
+ // Add withdrawal (Settled) events
91
+ chainConfig . forEach ( address => {
92
+ eventParams . push ( { ...withdrawalIntent , target : address } ) ;
93
+ } ) ;
94
+
95
+ return async ( fromBlock : number , toBlock : number ) => {
96
+ console . log ( "Fetching Everclear bridge volume from block:" , fromBlock , "to block:" , toBlock )
97
+ return getTxDataFromEVMEventLogs ( "everclear" , chain , fromBlock , toBlock , eventParams ) ;
98
+ } ;
99
+ } ;
100
+
101
+ const adapter : BridgeAdapter = {
102
+ ethereum : constructParams ( "ethereum" ) ,
103
+ optimism : constructParams ( "optimism" ) ,
104
+ bsc : constructParams ( "bsc" ) ,
105
+ unichain : constructParams ( "unichain" ) ,
106
+ polygon : constructParams ( "polygon" ) ,
107
+ zksync : constructParams ( "zksync" ) ,
108
+ ronin : constructParams ( "ronin" ) ,
109
+ base : constructParams ( "base" ) ,
110
+ apechain : constructParams ( "apechain" ) ,
111
+ mode : constructParams ( "mode" ) ,
112
+ arbitrum : constructParams ( "arbitrum" ) ,
113
+ avalanche : constructParams ( "avalanche" ) ,
114
+ zircuit : constructParams ( "zircuit" ) ,
115
+ linea : constructParams ( "linea" ) ,
116
+ blast : constructParams ( "blast" ) ,
117
+ scroll : constructParams ( "scroll" ) ,
118
+ taiko : constructParams ( "taiko" ) ,
119
+ sonic : constructParams ( "sonic" ) ,
120
+ berachain : constructParams ( "berachain" ) ,
121
+ mantle : constructParams ( "mantle" ) ,
122
+ ink : constructParams ( "ink" ) ,
123
+ } ;
124
+
125
+ export default adapter ;
0 commit comments