@@ -2,8 +2,10 @@ import { Chain } from "@defillama/sdk/build/general";
2
2
import { BridgeAdapter , PartialContractEventParams } from "../../helpers/bridgeAdapter.type" ;
3
3
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions" ;
4
4
import { ethers } from "ethers" ;
5
- import { fetchAssets , getTokenAddress } from "./utils" ;
6
- import { axelarGatewayAddresses , squidRouterAddresses } from "./constants" ;
5
+ import { fetchAssets , getTokenAddress , getTokenId } from "./utils" ;
6
+ import { axelarGatewayAddresses , squidRouterAddresses , coralSpokeAddresses , stablecoins } from "./constants" ;
7
+ import { isStablecoin } from "./utils" ;
8
+
7
9
8
10
const constructGatewayWithdrawalParams = ( assets : any [ ] , chain : string ) => {
9
11
const squidRouterAddress = squidRouterAddresses [ chain as keyof typeof squidRouterAddresses ] || squidRouterAddresses . default ;
@@ -31,48 +33,111 @@ const constructGatewayWithdrawalParams = (assets: any[], chain: string) => {
31
33
} ,
32
34
isDeposit : false ,
33
35
} ;
34
- }
36
+ } ;
35
37
36
38
const constructGatewayDepositParams = ( assets : any [ ] , chain : string ) => {
37
- const squidRouterAddress = squidRouterAddresses [ chain as keyof typeof squidRouterAddresses ] || squidRouterAddresses . default ;
38
-
39
- return {
40
- target : "" ,
41
- topic : "ContractCallApprovedWithMint(bytes32,string,string,address,bytes32,string,uint256,bytes32,uint256)" ,
42
- topics : [ ethers . utils . id ( "ContractCallApprovedWithMint(bytes32,string,string,address,bytes32,string,uint256,bytes32,uint256)" ) , null , ethers . utils . hexZeroPad ( squidRouterAddress , 32 ) ] ,
43
- abi : [ "event ContractCallApprovedWithMint(bytes32 indexed commandId, string sourceChain, string sourceAddress, address indexed contractAddress, bytes32 indexed payloadHash, string symbol, uint256 amount, bytes32 sourceTxHash, uint256 sourceEventIndex)" ] ,
44
- logKeys : {
45
- blockNumber : "blockNumber" ,
46
- txHash : "transactionHash" ,
47
- } ,
48
- argKeys : {
49
- from : "sourceAddress" ,
50
- amount : "amount" ,
51
- to : "contractAddress" ,
52
- token : "symbol"
53
- } ,
54
- argGetters : {
55
- from : ( log : any ) => log . sourceAddress ,
56
- amount : ( log : any ) => log . amount ,
57
- to : ( log : any ) => log . contractAddress ,
58
- token : ( log : any ) => getTokenAddress ( log . symbol , chain , assets )
59
- } ,
60
- isDeposit : true ,
61
- } ;
62
- }
39
+ const squidRouterAddress = squidRouterAddresses [ chain as keyof typeof squidRouterAddresses ] || squidRouterAddresses . default ;
40
+
41
+ return {
42
+ target : "" ,
43
+ topic : "ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)" ,
44
+ topics : [ ethers . utils . id ( "ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)" ) , ethers . utils . hexZeroPad ( squidRouterAddress , 32 ) ] ,
45
+ abi : [ "event ContractCallWithToken(address indexed sender, string destinationChain, string destinationContractAddress, bytes32 indexed payloadHash, bytes payload, string symbol, uint256 amount)" ] ,
46
+ logKeys : {
47
+ blockNumber : "blockNumber" ,
48
+ txHash : "transactionHash" ,
49
+ } ,
50
+ argKeys : {
51
+ from : "payload" ,
52
+ amount : "amount" ,
53
+ to : "destinationContractAddress" ,
54
+ token : "symbol"
55
+ } ,
56
+ argGetters : {
57
+ from : ( log : any ) => "0x" . concat ( log . payload . substr ( 90 , 40 ) ) ,
58
+ amount : ( log : any ) => log . amount ,
59
+ to : ( log : any ) => log . destinationContractAddress ,
60
+ token : ( log : any ) => getTokenAddress ( log . symbol , chain , assets ) ,
61
+ is_usd_volume : ( log : any ) => isStablecoin ( log . symbol , chain )
62
+ } ,
63
+ isDeposit : true ,
64
+ } ;
65
+ } ;
66
+
67
+ const constructCoralWithdrawParams = ( assets : any [ ] , chain : string ) => {
68
+ return {
69
+ target : coralSpokeAddresses . default ,
70
+ topic : "OrderCreated(bytes32,(address,address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))" ,
71
+ topics : [ ethers . utils . id ( "OrderCreated(bytes32,(address,address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))" ) ] ,
72
+ abi : [ "event OrderCreated(bytes32 indexed orderHash, tuple(address fromAddress, address toAddress, address filler, address fromToken, address toToken, uint256 expiry, uint256 fromAmount, uint256 fillAmount, uint256 feeRate, uint256 fromChain, uint256 toChain, bytes32 postHookHash) order)" ] ,
73
+ logKeys : {
74
+ blockNumber : "blockNumber" ,
75
+ txHash : "transactionHash" ,
76
+ } ,
77
+ argKeys : {
78
+ from : "args" ,
79
+ amount : "args" ,
80
+ to : "args" ,
81
+ token : "args"
82
+ } ,
83
+ argGetters : {
84
+ from : ( log : any ) => log [ 1 ] . fromAddress ,
85
+ amount : ( log : any ) => log [ 1 ] . fromAmount ,
86
+ to : ( log : any ) => log [ 1 ] . toAddress ,
87
+ token : ( log : any ) => getTokenAddress ( log [ 1 ] . fromToken , chain , assets ) ,
88
+ is_usd_volume : ( log : any ) => isStablecoin ( log [ 1 ] . fromToken , chain )
89
+ } ,
90
+ isDeposit : false ,
91
+ } ;
92
+ } ;
93
+
94
+ const constructCoralDepositParams = ( assets : any [ ] , chain : string ) => {
95
+ return {
96
+ target : coralSpokeAddresses . default ,
97
+ topic : "OrderFilled(bytes32,(address,address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))" ,
98
+ topics : [ ethers . utils . id ( "OrderFilled(bytes32,(address,address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))" ) ] ,
99
+ abi : [ "event OrderFilled(bytes32 indexed orderHash, tuple(address fromAddress, address toAddress, address filler, address fromToken, address toToken, uint256 expiry, uint256 fromAmount, uint256 fillAmount, uint256 feeRate, uint256 fromChain, uint256 toChain, bytes32 postHookHash) order)" ] ,
100
+ logKeys : {
101
+ blockNumber : "blockNumber" ,
102
+ txHash : "transactionHash" ,
103
+ } ,
104
+ argKeys : {
105
+ from : "args" ,
106
+ amount : "args" ,
107
+ to : "args" ,
108
+ token : "args"
109
+ } ,
110
+ argGetters : {
111
+ from : ( log : any ) => log [ 1 ] . fromAddress ,
112
+ amount : ( log : any ) => log [ 1 ] . fromAmount ,
113
+ to : ( log : any ) => log [ 1 ] . toAddress ,
114
+ token : ( log : any ) => getTokenAddress ( log [ 1 ] . fromToken , chain , assets ) ,
115
+ is_usd_volume : ( log : any ) => isStablecoin ( log [ 1 ] . fromToken , chain )
116
+ } ,
117
+ isDeposit : true ,
118
+ } ;
119
+ } ;
63
120
64
121
const constructParams = ( chain : string ) => {
65
122
return async ( fromBlock : number , toBlock : number ) => {
66
- let eventParams = [ ] as PartialContractEventParams [ ] ;
67
123
const assets = await fetchAssets ( ) ;
124
+ const eventParams = [ ] ;
125
+
126
+ // Gateway params
127
+ const gatewayDepositParams = constructGatewayDepositParams ( assets , chain ) ;
128
+ const gatewayWithdrawalParams = constructGatewayWithdrawalParams ( assets , chain ) ;
129
+
130
+ const deposit = { ...gatewayDepositParams , target : axelarGatewayAddresses [ chain ] } ;
131
+ const withdraw = { ...gatewayWithdrawalParams , target : axelarGatewayAddresses [ chain ] } ;
68
132
69
- const GatewayDepositParams = constructGatewayDepositParams ( assets , chain ) ;
70
- const deposit = { ...GatewayDepositParams , target : axelarGatewayAddresses [ chain ] } ;
133
+ // Coral params
134
+ const coralDepositParams = constructCoralDepositParams ( assets , chain ) ;
135
+ const coralWithdrawParams = constructCoralWithdrawParams ( assets , chain ) ;
71
136
72
- const GatewayWithdrawalParams = constructGatewayWithdrawalParams ( assets , chain ) ;
73
- const withdraw = { ...GatewayWithdrawalParams , target : axelarGatewayAddresses [ chain ] } ;
137
+ const coralDeposit = { ... coralDepositParams , target : coralSpokeAddresses . default } ;
138
+ const coralWithdraw = { ...coralWithdrawParams , target : coralSpokeAddresses . default } ;
74
139
75
- eventParams . push ( deposit , withdraw ) ;
140
+ eventParams . push ( deposit , withdraw , coralDeposit , coralWithdraw ) ;
76
141
77
142
return getTxDataFromEVMEventLogs ( "squid" , chain as Chain , fromBlock , toBlock , eventParams ) ;
78
143
}
@@ -93,7 +158,6 @@ const adapter: BridgeAdapter = {
93
158
filecoin : constructParams ( "filecoin" ) ,
94
159
optimism : constructParams ( "optimism" ) ,
95
160
mantle : constructParams ( "mantle" ) ,
96
- //new chains
97
161
scroll : constructParams ( "scroll" ) ,
98
162
blast : constructParams ( "blast" ) ,
99
163
fraxtal : constructParams ( "fraxtal" ) ,
0 commit comments