@instadapp/interop-x 0.0.0-dev.a861339 → 0.0.0-dev.a9cd1d2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/package.json +12 -11
  2. package/dist/src/abi/index.js +2 -2
  3. package/dist/src/abi/interopX.json +1436 -0
  4. package/dist/src/api/index.js +1 -1
  5. package/dist/src/constants/addresses.js +2 -7
  6. package/dist/src/constants/tokens.js +62 -39
  7. package/dist/src/db/models/transaction.js +10 -10
  8. package/dist/src/gnosis/actions/withdraw/index.js +106 -33
  9. package/dist/src/gnosis/index.js +3 -3
  10. package/dist/src/index.js +1 -1
  11. package/dist/src/tasks/{InteropXContract/SyncBridgeRequestEvents.js → InteropX/SyncLogSubmitEvents.js} +20 -14
  12. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +4 -2
  13. package/dist/src/tasks/index.js +4 -10
  14. package/dist/src/typechain/{InteropXContract.js → InteropX.js} +0 -0
  15. package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
  16. package/dist/src/typechain/factories/index.js +3 -3
  17. package/dist/src/typechain/index.js +3 -3
  18. package/dist/src/utils/index.js +36 -9
  19. package/package.json +12 -11
  20. package/src/abi/index.ts +2 -2
  21. package/src/abi/interopX.json +1436 -0
  22. package/src/api/index.ts +1 -1
  23. package/src/constants/addresses.ts +3 -8
  24. package/src/constants/tokens.ts +63 -40
  25. package/src/db/models/transaction.ts +29 -34
  26. package/src/gnosis/actions/withdraw/index.ts +141 -42
  27. package/src/gnosis/index.ts +3 -3
  28. package/src/tasks/{InteropXContract/SyncBridgeRequestEvents.ts → InteropX/SyncLogSubmitEvents.ts} +39 -19
  29. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +4 -2
  30. package/src/tasks/index.ts +5 -13
  31. package/src/typechain/InteropX.ts +1216 -0
  32. package/src/typechain/factories/InteropX__factory.ts +1932 -0
  33. package/src/typechain/factories/index.ts +1 -1
  34. package/src/typechain/index.ts +2 -2
  35. package/src/utils/index.ts +88 -39
  36. package/dist/src/abi/interopXContract.json +0 -391
  37. package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +0 -147
  38. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +0 -80
  39. package/dist/src/typechain/factories/InteropXContract__factory.js +0 -526
  40. package/src/abi/interopXContract.json +0 -391
  41. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +0 -211
  42. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +0 -112
  43. package/src/typechain/InteropXContract.ts +0 -524
  44. package/src/typechain/factories/InteropXContract__factory.ts +0 -533
@@ -3,4 +3,4 @@
3
3
  /* eslint-disable */
4
4
  export { Erc20__factory } from "./Erc20__factory";
5
5
  export { GnosisSafe__factory } from "./GnosisSafe__factory";
6
- export { InteropXContract__factory } from "./InteropXContract__factory";
6
+ export { InteropX__factory } from "./InteropX__factory";
@@ -3,8 +3,8 @@
3
3
  /* eslint-disable */
4
4
  export type { Erc20 } from "./Erc20";
5
5
  export type { GnosisSafe } from "./GnosisSafe";
6
- export type { InteropXContract } from "./InteropXContract";
6
+ export type { InteropX } from "./InteropX";
7
7
  export * as factories from "./factories";
8
8
  export { Erc20__factory } from "./factories/Erc20__factory";
9
9
  export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
10
- export { InteropXContract__factory } from "./factories/InteropXContract__factory";
10
+ export { InteropX__factory } from "./factories/InteropX__factory";
@@ -7,6 +7,8 @@ import { addresses } from '@/constants';
7
7
  import { ChainId } from '@/types'
8
8
  import { ethers } from 'ethers';
9
9
  import { GnosisSafe } from '@/typechain';
10
+ import retry from 'async-retry'
11
+
10
12
  export const http = axios.create();
11
13
 
12
14
  axiosRetry(http, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
@@ -131,14 +133,35 @@ export const asyncCallWithTimeout = async <T>(asyncPromise: Promise<T>, timeout:
131
133
  }
132
134
 
133
135
 
134
- export const generateInteropTransactionHash = (data: { action: string, bridger: string, requestTransactionHash: string, sourceChainId: string | number, targetChainId: string | number }) => {
135
- return ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string', 'string'], [
136
- String(data.action),
137
- String(data.bridger),
138
- String(data.requestTransactionHash),
139
- String(data.sourceChainId),
140
- String(data.targetChainId),
141
- ]);
136
+ type GenerateInteropTransactionHashParam = {
137
+ actionId: string,
138
+ vnonce: string,
139
+ sourceSender: string,
140
+ sourceChainId: string | number,
141
+ sourceDsaId: string,
142
+ targetChainId: string | number,
143
+ targetDsaId: string,
144
+ };
145
+
146
+ export const generateInteropTransactionHash = (data: GenerateInteropTransactionHashParam) => {
147
+ return ethers.utils.solidityKeccak256(
148
+ Array.from(Array(7), () => 'string'),
149
+ [
150
+ String(data.actionId),
151
+ String(data.vnonce),
152
+ String(data.sourceSender),
153
+ String(data.sourceChainId),
154
+ String(data.sourceDsaId),
155
+ String(data.targetChainId),
156
+ String(data.targetDsaId),
157
+ ]);
158
+ }
159
+
160
+
161
+ export class ContractError extends Error {
162
+ method: string;
163
+ address: string;
164
+ args: any[];
142
165
  }
143
166
 
144
167
  export function getContract<TContract extends ethers.Contract>(address: string, contractInterface: ethers.ContractInterface | any, signerOrProvider?: ethers.Signer | ethers.providers.Provider) {
@@ -164,11 +187,24 @@ export function getContract<TContract extends ethers.Contract>(address: string,
164
187
  const value = Reflect.get(target, prop, receiver);
165
188
 
166
189
  if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
190
+ let isConstant = false;
191
+
192
+ try {
193
+ isConstant = contract.interface.getFunction(String(prop)).constant
194
+ } catch (error) {
195
+ }
196
+
167
197
  return async (...args: any[]) => {
168
198
  try {
169
- return await value.bind(contract)(...args);
199
+ return await retry(async () => await value.bind(contract)(...args), { retries: isConstant ? 1 : 3 });
170
200
  } catch (error) {
171
- throw new Error(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`)
201
+ const err = new ContractError(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`)
202
+
203
+ err.method = String(prop)
204
+ err.address = address
205
+ err.args = [...args]
206
+
207
+ throw err
172
208
  }
173
209
  }
174
210
  }
@@ -184,9 +220,15 @@ export function getContract<TContract extends ethers.Contract>(address: string,
184
220
  if (typeof value === 'function') {
185
221
  return async (...args: any[]) => {
186
222
  try {
187
- return await value.bind(contract)(...args);
223
+ return await retry(async () => await value.bind(contract)(...args), { retries: parentProp === 'callStatic' ? 3 : 1 });
188
224
  } catch (error) {
189
- throw new Error(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`)
225
+ const err = new ContractError(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`)
226
+
227
+ err.method = String(prop)
228
+ err.address = address
229
+ err.args = [...args]
230
+
231
+ throw err
190
232
  }
191
233
  }
192
234
  }
@@ -203,38 +245,45 @@ export const generateGnosisTransaction = async (transactionData: any, safeContra
203
245
  console.log(transactionData);
204
246
 
205
247
  let isExecuted = await safeContract.dataHashes(
206
- await safeContract.getTransactionHash(
207
- transactionData.to,
208
- transactionData.value,
209
- transactionData.data,
210
- transactionData.operation,
211
- transactionData.safeTxGas,
212
- transactionData.baseGas,
213
- transactionData.gasPrice,
214
- transactionData.gasToken,
215
- transactionData.refundReceiver,
216
- transactionData.nonce
217
- )
248
+ await safeContract.getTransactionHash(
249
+ transactionData.to,
250
+ transactionData.value,
251
+ transactionData.data,
252
+ transactionData.operation,
253
+ transactionData.safeTxGas,
254
+ transactionData.baseGas,
255
+ transactionData.gasPrice,
256
+ transactionData.gasToken,
257
+ transactionData.refundReceiver,
258
+ transactionData.nonce
259
+ )
218
260
  )
219
261
 
220
262
  while (isExecuted == 1) {
221
- transactionData.safeTxGas = ethers.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString()
222
-
223
- isExecuted = await safeContract.dataHashes(
224
- await safeContract.getTransactionHash(
225
- transactionData.to,
226
- transactionData.value,
227
- transactionData.data,
228
- transactionData.operation,
229
- transactionData.safeTxGas,
230
- transactionData.baseGas,
231
- transactionData.gasPrice,
232
- transactionData.gasToken,
233
- transactionData.refundReceiver,
234
- transactionData.nonce
235
- )
263
+ transactionData.safeTxGas = ethers.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString()
264
+
265
+ isExecuted = await safeContract.dataHashes(
266
+ await safeContract.getTransactionHash(
267
+ transactionData.to,
268
+ transactionData.value,
269
+ transactionData.data,
270
+ transactionData.operation,
271
+ transactionData.safeTxGas,
272
+ transactionData.baseGas,
273
+ transactionData.gasPrice,
274
+ transactionData.gasToken,
275
+ transactionData.refundReceiver,
276
+ transactionData.nonce
236
277
  )
278
+ )
237
279
  }
238
280
 
239
281
  return transactionData
282
+ }
283
+
284
+ export class LiquidityError extends Error {
285
+ constructor(message?: string) {
286
+ super(message || 'Not enough liquidity');
287
+ Object.setPrototypeOf(this, new.target.prototype);
288
+ }
240
289
  }
@@ -1,391 +0,0 @@
1
- [
2
- {
3
- "anonymous": false,
4
- "inputs": [
5
- {
6
- "indexed": true,
7
- "internalType": "address",
8
- "name": "bridger",
9
- "type": "address"
10
- },
11
- {
12
- "components": [
13
- {
14
- "components": [
15
- {
16
- "internalType": "address",
17
- "name": "sourceToken",
18
- "type": "address"
19
- },
20
- {
21
- "internalType": "address",
22
- "name": "targetToken",
23
- "type": "address"
24
- },
25
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
26
- ],
27
- "internalType": "struct InteropXContractBeta.TokenInfo[]",
28
- "name": "supply",
29
- "type": "tuple[]"
30
- },
31
- {
32
- "components": [
33
- {
34
- "internalType": "address",
35
- "name": "sourceToken",
36
- "type": "address"
37
- },
38
- {
39
- "internalType": "address",
40
- "name": "targetToken",
41
- "type": "address"
42
- },
43
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
44
- ],
45
- "internalType": "struct InteropXContractBeta.TokenInfo[]",
46
- "name": "withdraw",
47
- "type": "tuple[]"
48
- }
49
- ],
50
- "indexed": false,
51
- "internalType": "struct InteropXContractBeta.Position",
52
- "name": "position",
53
- "type": "tuple"
54
- },
55
- {
56
- "indexed": true,
57
- "internalType": "uint32",
58
- "name": "sourceChainId",
59
- "type": "uint32"
60
- },
61
- {
62
- "indexed": false,
63
- "internalType": "uint32",
64
- "name": "targetChainId",
65
- "type": "uint32"
66
- },
67
- {
68
- "indexed": true,
69
- "internalType": "bytes32",
70
- "name": "requestTransactionHash",
71
- "type": "bytes32"
72
- },
73
- {
74
- "indexed": false,
75
- "internalType": "bytes",
76
- "name": "metadata",
77
- "type": "bytes"
78
- }
79
- ],
80
- "name": "LogBridgeCommitted",
81
- "type": "event"
82
- },
83
- {
84
- "anonymous": false,
85
- "inputs": [
86
- {
87
- "indexed": true,
88
- "internalType": "address",
89
- "name": "bridger",
90
- "type": "address"
91
- },
92
- {
93
- "components": [
94
- {
95
- "components": [
96
- {
97
- "internalType": "address",
98
- "name": "sourceToken",
99
- "type": "address"
100
- },
101
- {
102
- "internalType": "address",
103
- "name": "targetToken",
104
- "type": "address"
105
- },
106
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
107
- ],
108
- "internalType": "struct InteropXContractBeta.TokenInfo[]",
109
- "name": "supply",
110
- "type": "tuple[]"
111
- },
112
- {
113
- "components": [
114
- {
115
- "internalType": "address",
116
- "name": "sourceToken",
117
- "type": "address"
118
- },
119
- {
120
- "internalType": "address",
121
- "name": "targetToken",
122
- "type": "address"
123
- },
124
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
125
- ],
126
- "internalType": "struct InteropXContractBeta.TokenInfo[]",
127
- "name": "withdraw",
128
- "type": "tuple[]"
129
- }
130
- ],
131
- "indexed": false,
132
- "internalType": "struct InteropXContractBeta.Position",
133
- "name": "position",
134
- "type": "tuple"
135
- },
136
- {
137
- "indexed": false,
138
- "internalType": "uint256",
139
- "name": "sourceChainId",
140
- "type": "uint256"
141
- },
142
- {
143
- "indexed": true,
144
- "internalType": "uint256",
145
- "name": "targetChainId",
146
- "type": "uint256"
147
- },
148
- {
149
- "indexed": true,
150
- "internalType": "bytes32",
151
- "name": "requestTransactionHash",
152
- "type": "bytes32"
153
- },
154
- {
155
- "indexed": false,
156
- "internalType": "bytes32",
157
- "name": "targetCommittedTransactionHash",
158
- "type": "bytes32"
159
- },
160
- {
161
- "indexed": false,
162
- "internalType": "bytes",
163
- "name": "metadata",
164
- "type": "bytes"
165
- }
166
- ],
167
- "name": "LogBridgeCompleted",
168
- "type": "event"
169
- },
170
- {
171
- "anonymous": false,
172
- "inputs": [
173
- {
174
- "indexed": true,
175
- "internalType": "address",
176
- "name": "bridger",
177
- "type": "address"
178
- },
179
- {
180
- "components": [
181
- {
182
- "components": [
183
- {
184
- "internalType": "address",
185
- "name": "sourceToken",
186
- "type": "address"
187
- },
188
- {
189
- "internalType": "address",
190
- "name": "targetToken",
191
- "type": "address"
192
- },
193
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
194
- ],
195
- "internalType": "struct InteropXContractBeta.TokenInfo[]",
196
- "name": "supply",
197
- "type": "tuple[]"
198
- },
199
- {
200
- "components": [
201
- {
202
- "internalType": "address",
203
- "name": "sourceToken",
204
- "type": "address"
205
- },
206
- {
207
- "internalType": "address",
208
- "name": "targetToken",
209
- "type": "address"
210
- },
211
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
212
- ],
213
- "internalType": "struct InteropXContractBeta.TokenInfo[]",
214
- "name": "withdraw",
215
- "type": "tuple[]"
216
- }
217
- ],
218
- "indexed": false,
219
- "internalType": "struct InteropXContractBeta.Position",
220
- "name": "position",
221
- "type": "tuple"
222
- },
223
- {
224
- "indexed": false,
225
- "internalType": "uint256",
226
- "name": "sourceChainId",
227
- "type": "uint256"
228
- },
229
- {
230
- "indexed": true,
231
- "internalType": "uint256",
232
- "name": "targetChainId",
233
- "type": "uint256"
234
- },
235
- {
236
- "indexed": false,
237
- "internalType": "bytes",
238
- "name": "metadata",
239
- "type": "bytes"
240
- }
241
- ],
242
- "name": "LogBridgeRequest",
243
- "type": "event"
244
- },
245
- {
246
- "anonymous": false,
247
- "inputs": [
248
- {
249
- "indexed": true,
250
- "internalType": "address",
251
- "name": "bridger",
252
- "type": "address"
253
- },
254
- {
255
- "components": [
256
- {
257
- "components": [
258
- {
259
- "internalType": "address",
260
- "name": "sourceToken",
261
- "type": "address"
262
- },
263
- {
264
- "internalType": "address",
265
- "name": "targetToken",
266
- "type": "address"
267
- },
268
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
269
- ],
270
- "internalType": "struct InteropXContractBeta.TokenInfo[]",
271
- "name": "supply",
272
- "type": "tuple[]"
273
- },
274
- {
275
- "components": [
276
- {
277
- "internalType": "address",
278
- "name": "sourceToken",
279
- "type": "address"
280
- },
281
- {
282
- "internalType": "address",
283
- "name": "targetToken",
284
- "type": "address"
285
- },
286
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
287
- ],
288
- "internalType": "struct InteropXContractBeta.TokenInfo[]",
289
- "name": "withdraw",
290
- "type": "tuple[]"
291
- }
292
- ],
293
- "indexed": false,
294
- "internalType": "struct InteropXContractBeta.Position",
295
- "name": "position",
296
- "type": "tuple"
297
- },
298
- {
299
- "indexed": false,
300
- "internalType": "uint32",
301
- "name": "sourceChainId",
302
- "type": "uint32"
303
- },
304
- {
305
- "indexed": true,
306
- "internalType": "uint32",
307
- "name": "targetChainId",
308
- "type": "uint32"
309
- },
310
- {
311
- "indexed": true,
312
- "internalType": "bytes32",
313
- "name": "requestTransactionHash",
314
- "type": "bytes32"
315
- },
316
- {
317
- "indexed": false,
318
- "internalType": "bytes",
319
- "name": "metadata",
320
- "type": "bytes"
321
- }
322
- ],
323
- "name": "LogBridgeRequestSent",
324
- "type": "event"
325
- },
326
- {
327
- "inputs": [],
328
- "name": "_vnonce",
329
- "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
330
- "stateMutability": "view",
331
- "type": "function"
332
- },
333
- {
334
- "inputs": [
335
- { "internalType": "address", "name": "to_", "type": "address" },
336
- { "internalType": "address", "name": "sourceToken_", "type": "address" },
337
- { "internalType": "address", "name": "targetToken_", "type": "address" },
338
- { "internalType": "uint256", "name": "amount_", "type": "uint256" },
339
- { "internalType": "uint32", "name": "targetChainId_", "type": "uint32" },
340
- {
341
- "internalType": "bytes32",
342
- "name": "transactionHash_",
343
- "type": "bytes32"
344
- },
345
- { "internalType": "bytes", "name": "metadata_", "type": "bytes" }
346
- ],
347
- "name": "completeBridge",
348
- "outputs": [],
349
- "stateMutability": "nonpayable",
350
- "type": "function"
351
- },
352
- {
353
- "inputs": [
354
- { "internalType": "address", "name": "sourceToken_", "type": "address" },
355
- { "internalType": "address", "name": "targetToken_", "type": "address" },
356
- { "internalType": "uint256", "name": "amount_", "type": "uint256" },
357
- { "internalType": "uint32", "name": "targetChainId_", "type": "uint32" },
358
- { "internalType": "bytes", "name": "metadata_", "type": "bytes" }
359
- ],
360
- "name": "requestWithdraw",
361
- "outputs": [],
362
- "stateMutability": "nonpayable",
363
- "type": "function"
364
- },
365
- {
366
- "inputs": [{ "internalType": "address", "name": "", "type": "address" }],
367
- "name": "whitelistedMapping",
368
- "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
369
- "stateMutability": "view",
370
- "type": "function"
371
- },
372
- {
373
- "inputs": [
374
- { "internalType": "address", "name": "user_", "type": "address" },
375
- { "internalType": "address", "name": "sourceToken_", "type": "address" },
376
- { "internalType": "address", "name": "targetToken_", "type": "address" },
377
- { "internalType": "uint256", "name": "amount_", "type": "uint256" },
378
- { "internalType": "uint32", "name": "chainId_", "type": "uint32" },
379
- {
380
- "internalType": "bytes32",
381
- "name": "transactionHash_",
382
- "type": "bytes32"
383
- },
384
- { "internalType": "bytes", "name": "metadata_", "type": "bytes" }
385
- ],
386
- "name": "withdrawRequested",
387
- "outputs": [],
388
- "stateMutability": "nonpayable",
389
- "type": "function"
390
- }
391
- ]