@@ -9,30 +9,47 @@ describe('Chain abstraction orchestrator', () => {
9
9
'function approve(address spender, uint256 amount) public returns (bool)'
10
10
] ) ;
11
11
12
- // Address with 3 USDC on Base chain
12
+ // Funding address
13
13
const from_address_with_funds = "0x2aae531a81461f029cd55cb46703211c9227ba05" ;
14
- const usdc_funds_on_base = 3_000_000 ;
15
- const usdc_funds_on_optimism = 1_057_151 ;
14
+
15
+ // Receiver address
16
+ const receiver_address = "0x739ff389c8eBd9339E69611d46Eec6212179BB67" ;
17
+
18
+ // Supported chains
19
+ const chain_id_optimism = "eip155:10" ;
20
+ const chain_id_base = "eip155:8453" ;
21
+ const chain_id_arbitrum = "eip155:42161" ;
22
+
23
+ // Current funds on different chains
16
24
const usdc_token_symbol = "USDC" ;
25
+ let usdc_funds = { } ;
26
+ usdc_funds [ chain_id_base ] = 3_000_000 ;
27
+ usdc_funds [ chain_id_optimism ] = 1_057_151 ;
28
+
29
+ const usdt_token_symbol = "USDT" ;
30
+ let usdt_funds = { } ;
31
+ usdt_funds [ chain_id_arbitrum ] = 3_388_000 ;
32
+ usdt_funds [ chain_id_optimism ] = 1_050_000 ;
33
+
17
34
// Amount to send to Optimism
18
35
const amount_to_send = 3_000_000
19
36
// Amount bridging slippage
20
37
const amount_slippage = 2 ; // +2% topup
21
- // How much needs to be topped up
22
- const amount_to_topup = Math . round ( amount_to_send - usdc_funds_on_optimism ) ;
23
- const amount_to_topup_with_fees = Math . round ( ( ( amount_to_topup * amount_slippage ) / 100 ) + amount_to_topup ) ;
24
-
25
- const receiver_address = "0x739ff389c8eBd9339E69611d46Eec6212179BB67 " ;
26
- const chain_id_optimism = "eip155:10" ;
27
- const usdc_contract_optimism = "0x0b2c639c533813f4aa9d7837caf62653d097ff85 " ;
28
- const chain_id_base = "eip155:8453 " ;
29
- const usdc_contract_base = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913 " ;
38
+
39
+ let usdc_contracts = { } ;
40
+ usdc_contracts [ chain_id_optimism ] = "0x0b2c639c533813f4aa9d7837caf62653d097ff85" ;
41
+ usdc_contracts [ chain_id_base ] = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ;
42
+ usdc_contracts [ chain_id_arbitrum ] = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831 " ;
43
+ let usdt_contracts = { } ;
44
+ usdt_contracts [ chain_id_optimism ] = "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58 " ;
45
+ usdt_contracts [ chain_id_arbitrum ] = "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9 " ;
46
+ usdt_contracts [ chain_id_base ] = "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2 " ;
30
47
31
48
let orchestration_id = "" ;
32
49
33
50
it ( 'bridging unavailable (insufficient funds)' , async ( ) => {
34
51
// Having the USDC balance on Base chain less then the amount to send
35
- const amount_to_send_in_decimals = usdc_funds_on_base + 10_000_000
52
+ const amount_to_send_in_decimals = usdc_funds [ chain_id_base ] + 10_000_000
36
53
const data_encoded = erc20Interface . encodeFunctionData ( 'transfer' , [
37
54
receiver_address ,
38
55
amount_to_send_in_decimals ,
@@ -41,7 +58,7 @@ describe('Chain abstraction orchestrator', () => {
41
58
let transactionObj = {
42
59
transaction : {
43
60
from : from_address_with_funds ,
44
- to : usdc_contract_optimism ,
61
+ to : usdc_contracts [ chain_id_optimism ] ,
45
62
value : "0x00" , // Zero native tokens
46
63
input : data_encoded ,
47
64
chainId : chain_id_optimism ,
@@ -58,7 +75,7 @@ describe('Chain abstraction orchestrator', () => {
58
75
59
76
it ( 'bridging unavailable (empty wallet)' , async ( ) => {
60
77
// Checking an empty wallet
61
- const amount_to_send_in_decimals = usdc_funds_on_base
78
+ const amount_to_send_in_decimals = usdc_funds [ chain_id_base ]
62
79
const empty_wallet_address = ethers . Wallet . createRandom ( ) . address
63
80
const data_encoded = erc20Interface . encodeFunctionData ( 'transfer' , [
64
81
receiver_address ,
@@ -68,7 +85,7 @@ describe('Chain abstraction orchestrator', () => {
68
85
let transactionObj = {
69
86
transaction : {
70
87
from : empty_wallet_address ,
71
- to : usdc_contract_optimism ,
88
+ to : usdc_contracts [ chain_id_optimism ] ,
72
89
value : "0x00" , // Zero native tokens
73
90
input : data_encoded ,
74
91
chainId : chain_id_optimism ,
@@ -94,7 +111,7 @@ describe('Chain abstraction orchestrator', () => {
94
111
let transactionObj = {
95
112
transaction : {
96
113
from : from_address_with_funds ,
97
- to : usdc_contract_optimism ,
114
+ to : usdc_contracts [ chain_id_optimism ] ,
98
115
value : "0x00" , // Zero native tokens
99
116
input : data_encoded ,
100
117
chainId : chain_id_optimism ,
@@ -110,8 +127,14 @@ describe('Chain abstraction orchestrator', () => {
110
127
111
128
} )
112
129
113
- it ( 'bridging routes (routes available)' , async ( ) => {
114
- // Sending USDC to Optimism, but having the USDC balance on Base chain
130
+ it ( 'bridging routes (routes available, USDC Optimism ⇄ USDT Arbitrum)' , async ( ) => {
131
+ // Sending USDC to Optimism, but having the maximum balance of USDT on Arbitrum chain
132
+ // which expected to be used for bridging
133
+
134
+ // How much needs to be topped up
135
+ const amount_to_topup = Math . round ( amount_to_send - usdc_funds [ chain_id_optimism ] ) ;
136
+ const amount_to_topup_with_fees = Math . round ( ( ( amount_to_topup * amount_slippage ) / 100 ) + amount_to_topup ) ;
137
+
115
138
const data_encoded = erc20Interface . encodeFunctionData ( 'transfer' , [
116
139
receiver_address ,
117
140
amount_to_send ,
@@ -120,7 +143,7 @@ describe('Chain abstraction orchestrator', () => {
120
143
let transactionObj = {
121
144
transaction : {
122
145
from : from_address_with_funds ,
123
- to : usdc_contract_optimism ,
146
+ to : usdc_contracts [ chain_id_optimism ] ,
124
147
value : "0x00" , // Zero native tokens
125
148
input : data_encoded ,
126
149
chainId : chain_id_optimism ,
@@ -140,31 +163,31 @@ describe('Chain abstraction orchestrator', () => {
140
163
141
164
// First transaction expected to be the approval transaction
142
165
const approvalTransaction = data . transactions [ 0 ]
143
- expect ( approvalTransaction . chainId ) . toBe ( chain_id_base )
166
+ expect ( approvalTransaction . chainId ) . toBe ( chain_id_arbitrum )
144
167
expect ( approvalTransaction . nonce ) . not . toBe ( "0x00" )
145
168
expect ( ( ) => BigInt ( approvalTransaction . gasLimit ) ) . not . toThrow ( ) ;
146
169
const decodedData = erc20Interface . decodeFunctionData ( 'approve' , approvalTransaction . input ) ;
147
170
if ( decodedData . amount < BigInt ( amount_to_topup_with_fees ) ) {
148
171
throw new Error ( `Expected amount is lower then the minimal required` ) ;
149
172
}
150
173
151
- // Second transaction expected to be the bridging to the Base
174
+ // Second transaction expected to be the bridging to the Arbitrum
152
175
const bridgingTransaction = data . transactions [ 1 ]
153
- expect ( bridgingTransaction . chainId ) . toBe ( chain_id_base )
176
+ expect ( bridgingTransaction . chainId ) . toBe ( chain_id_arbitrum )
154
177
expect ( bridgingTransaction . nonce ) . not . toBe ( "0x00" )
155
178
expect ( ( ) => BigInt ( approvalTransaction . gasLimit ) ) . not . toThrow ( ) ;
156
179
157
180
// Check for the initialTransaction
158
181
const initialTransaction = data . initialTransaction ;
159
182
expect ( initialTransaction . from ) . toBe ( from_address_with_funds . toLowerCase ( ) ) ;
160
- expect ( initialTransaction . to ) . toBe ( usdc_contract_optimism . toLowerCase ( ) ) ;
183
+ expect ( initialTransaction . to ) . toBe ( usdc_contracts [ chain_id_optimism ] . toLowerCase ( ) ) ;
161
184
expect ( initialTransaction . gasLimit ) . not . toBe ( "0x00" ) ;
162
185
163
186
// Check the metadata fundingFrom
164
187
const fundingFrom = data . metadata . fundingFrom [ 0 ]
165
- expect ( fundingFrom . chainId ) . toBe ( chain_id_base )
166
- expect ( fundingFrom . symbol ) . toBe ( usdc_token_symbol )
167
- expect ( fundingFrom . tokenContract ) . toBe ( usdc_contract_base )
188
+ expect ( fundingFrom . chainId ) . toBe ( chain_id_arbitrum )
189
+ expect ( fundingFrom . symbol ) . toBe ( usdt_token_symbol )
190
+ expect ( fundingFrom . tokenContract ) . toBe ( usdt_contracts [ chain_id_arbitrum ] . toLowerCase ( ) )
168
191
if ( BigInt ( fundingFrom . amount ) <= BigInt ( amount_to_topup_with_fees ) ) {
169
192
throw new Error ( `Expected amount is lower then the minimal required` ) ;
170
193
}
@@ -175,7 +198,86 @@ describe('Chain abstraction orchestrator', () => {
175
198
const initialTransactionMetadata = data . metadata . initialTransaction
176
199
expect ( initialTransactionMetadata . symbol ) . toBe ( usdc_token_symbol )
177
200
expect ( initialTransactionMetadata . transferTo ) . toBe ( receiver_address . toLowerCase ( ) )
178
- expect ( initialTransactionMetadata . tokenContract ) . toBe ( usdc_contract_optimism . toLowerCase ( ) )
201
+ expect ( initialTransactionMetadata . tokenContract ) . toBe ( usdc_contracts [ chain_id_optimism ] . toLowerCase ( ) )
202
+
203
+ // Check the metadata checkIn
204
+ expect ( typeof data . metadata . checkIn ) . toBe ( 'number' )
205
+
206
+ // Set the Orchestration ID for the next test
207
+ orchestration_id = data . orchestrationId ;
208
+ } )
209
+
210
+ it ( 'bridging routes (routes available, USDT Optimism ⇄ USDT Arbitrum)' , async ( ) => {
211
+ // Sending USDT to Optimism, but having the USDT balance on Arbitrum.
212
+
213
+ // How much needs to be topped up
214
+ const amount_to_topup = Math . round ( amount_to_send - usdt_funds [ chain_id_optimism ] ) ;
215
+ const amount_to_topup_with_fees = Math . round ( ( ( amount_to_topup * amount_slippage ) / 100 ) + amount_to_topup ) ;
216
+
217
+ const data_encoded = erc20Interface . encodeFunctionData ( 'transfer' , [
218
+ receiver_address ,
219
+ amount_to_send ,
220
+ ] ) ;
221
+
222
+ let transactionObj = {
223
+ transaction : {
224
+ from : from_address_with_funds ,
225
+ to : usdt_contracts [ chain_id_optimism ] ,
226
+ value : "0x00" , // Zero native tokens
227
+ input : data_encoded ,
228
+ chainId : chain_id_optimism ,
229
+ }
230
+ }
231
+
232
+ let resp : any = await httpClient . post (
233
+ `${ baseUrl } /v1/ca/orchestrator/route?projectId=${ projectId } ` ,
234
+ transactionObj
235
+ )
236
+ expect ( resp . status ) . toBe ( 200 )
237
+
238
+ const data = resp . data
239
+ expect ( typeof data . orchestrationId ) . toBe ( 'string' )
240
+ // Expecting 2 transactions in the route
241
+ expect ( data . transactions . length ) . toBe ( 2 )
242
+
243
+ // First transaction expected to be the approval transaction
244
+ const approvalTransaction = data . transactions [ 0 ]
245
+ expect ( approvalTransaction . chainId ) . toBe ( chain_id_arbitrum )
246
+ expect ( approvalTransaction . nonce ) . not . toBe ( "0x00" )
247
+ expect ( ( ) => BigInt ( approvalTransaction . gasLimit ) ) . not . toThrow ( ) ;
248
+ const decodedData = erc20Interface . decodeFunctionData ( 'approve' , approvalTransaction . input ) ;
249
+ if ( decodedData . amount < BigInt ( amount_to_topup_with_fees ) ) {
250
+ throw new Error ( `Expected amount is lower then the minimal required` ) ;
251
+ }
252
+
253
+ // Second transaction expected to be the bridging to the Arbitrum
254
+ const bridgingTransaction = data . transactions [ 1 ]
255
+ expect ( bridgingTransaction . chainId ) . toBe ( chain_id_arbitrum )
256
+ expect ( bridgingTransaction . nonce ) . not . toBe ( "0x00" )
257
+ expect ( ( ) => BigInt ( approvalTransaction . gasLimit ) ) . not . toThrow ( ) ;
258
+
259
+ // Check for the initialTransaction
260
+ const initialTransaction = data . initialTransaction ;
261
+ expect ( initialTransaction . from ) . toBe ( from_address_with_funds . toLowerCase ( ) ) ;
262
+ expect ( initialTransaction . to ) . toBe ( usdt_contracts [ chain_id_optimism ] . toLowerCase ( ) ) ;
263
+ expect ( initialTransaction . gasLimit ) . not . toBe ( "0x00" ) ;
264
+
265
+ // Check the metadata fundingFrom
266
+ const fundingFrom = data . metadata . fundingFrom [ 0 ]
267
+ expect ( fundingFrom . chainId ) . toBe ( chain_id_arbitrum )
268
+ expect ( fundingFrom . symbol ) . toBe ( usdt_token_symbol )
269
+ expect ( fundingFrom . tokenContract ) . toBe ( usdt_contracts [ chain_id_arbitrum ] . toLowerCase ( ) )
270
+ if ( BigInt ( fundingFrom . amount ) <= BigInt ( amount_to_topup_with_fees ) ) {
271
+ throw new Error ( `Expected amount is lower then the minimal required` ) ;
272
+ }
273
+ if ( BigInt ( fundingFrom . bridgingFee ) != BigInt ( fundingFrom . amount - amount_to_topup ) ) {
274
+ throw new Error ( `Expected bridging fee is incorrect. ` ) ;
275
+ }
276
+ // Check the initialTransaction metadata
277
+ const initialTransactionMetadata = data . metadata . initialTransaction
278
+ expect ( initialTransactionMetadata . symbol ) . toBe ( usdt_token_symbol )
279
+ expect ( initialTransactionMetadata . transferTo ) . toBe ( receiver_address . toLowerCase ( ) )
280
+ expect ( initialTransactionMetadata . tokenContract ) . toBe ( usdt_contracts [ chain_id_optimism ] . toLowerCase ( ) )
179
281
180
282
// Check the metadata checkIn
181
283
expect ( typeof data . metadata . checkIn ) . toBe ( 'number' )
0 commit comments