@xchainjs/xchain-thorchain-amm 0.3.8 → 0.3.10
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.
- package/README.md +26 -22
- package/lib/index.esm.js +14 -370
- package/lib/index.js +12 -368
- package/package.json +27 -28
package/README.md
CHANGED
|
@@ -21,45 +21,49 @@ Following peer dependencies have to be installed into your project. These are no
|
|
|
21
21
|
"@xchainjs/xchain-binance": "^5.6.0",
|
|
22
22
|
"@xchainjs/xchain-bitcoin": "^0.20.0",
|
|
23
23
|
"@xchainjs/xchain-bitcoincash": "^0.15.0",
|
|
24
|
-
"@xchainjs/xchain-client": "^0.13.
|
|
24
|
+
"@xchainjs/xchain-client": "^0.13.2",
|
|
25
25
|
"@xchainjs/xchain-cosmos": "^0.20.0",
|
|
26
26
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
27
27
|
"@xchainjs/xchain-doge": "^0.5.0",
|
|
28
28
|
"@xchainjs/xchain-ethereum": "^0.27.0",
|
|
29
|
-
"@xchainjs/xchain-evm": "^0.1.0
|
|
30
|
-
"@xchainjs/xchain-avax": "^0.1.0
|
|
31
|
-
"@xchainjs/xchain-litecoin": "^0.10.
|
|
32
|
-
"@xchainjs/xchain-midgard": "
|
|
33
|
-
"@xchainjs/xchain-
|
|
34
|
-
"@xchainjs/xchain-thorchain": "^0.
|
|
35
|
-
"@xchainjs/xchain-
|
|
36
|
-
"@xchainjs/xchain-
|
|
37
|
-
"
|
|
38
|
-
"axios": "^
|
|
39
|
-
"axios-retry": "^3.3.1",
|
|
29
|
+
"@xchainjs/xchain-evm": "^0.1.0",
|
|
30
|
+
"@xchainjs/xchain-avax": "^0.1.0",
|
|
31
|
+
"@xchainjs/xchain-litecoin": "^0.10.5",
|
|
32
|
+
"@xchainjs/xchain-midgard": "0.3.0",
|
|
33
|
+
"@xchainjs/xchain-thorchain": "^0.27.2",
|
|
34
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.8",
|
|
35
|
+
"@xchainjs/xchain-thornode": "^0.1.2",
|
|
36
|
+
"@xchainjs/xchain-util": "^0.11.0",
|
|
37
|
+
"axios": "^0.25.0",
|
|
38
|
+
"axios-retry": "^3.2.5",
|
|
40
39
|
"bchaddrjs": "^0.5.2",
|
|
40
|
+
"bech32": "^2.0.0",
|
|
41
41
|
"bech32-buffer": "^0.2.0",
|
|
42
|
-
"
|
|
42
|
+
"bignumber.js": "^9.0.0",
|
|
43
|
+
"bitcoinjs-lib": "^5.2.0",
|
|
43
44
|
"dotenv": "^16.0.0",
|
|
44
|
-
"
|
|
45
|
+
"coininfo": "^5.1.0",
|
|
46
|
+
"coinselect": "^3.1.12",
|
|
47
|
+
"ethers": "^5.6.6",
|
|
48
|
+
"wif": "^2.0.6"
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
```
|
|
48
52
|
|
|
49
|
-
##
|
|
53
|
+
## For live examples
|
|
54
|
+
|
|
55
|
+
Do Swap: https://replit.com/@thorchain/doSwap-Single \
|
|
56
|
+
Add Liquidity: https://replit.com/@thorchain/addLiquidity \
|
|
57
|
+
Withdraw liquidity: https://replit.com/@thorchain/removeLiquidity \
|
|
58
|
+
Add Savers & withdraw Savers: https://replit.com/@thorchain/saversTs#index.ts
|
|
50
59
|
|
|
51
60
|
## Documentation
|
|
52
61
|
|
|
53
|
-
[xchain
|
|
62
|
+
[xchain-thorchain-amm](http://docs.xchainjs.org/xchain-thorchain-amm/) \
|
|
54
63
|
[How thorchain-amm works](http://docs.xchainjs.org/xchain-thorchain-amm/how-it-works.html)\
|
|
55
64
|
[How to use thorchain-amm](http://docs.xchainjs.org/xchain-thorchain-amm/how-to-use.html)
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
[Do Swap](https://replit.com/@thorchain/doSwap-Single)
|
|
59
|
-
[Add Liquidity](https://replit.com/@thorchain/addLiquidity)
|
|
60
|
-
[Withdraw liquidity](https://replit.com/@thorchain/removeLiquidity)
|
|
61
|
-
|
|
62
|
-
##
|
|
66
|
+
## Compiler options
|
|
63
67
|
|
|
64
68
|
tsconfig compiler options
|
|
65
69
|
|
package/lib/index.esm.js
CHANGED
|
@@ -5,12 +5,12 @@ import { Client } from '@xchainjs/xchain-bitcoincash';
|
|
|
5
5
|
import { FeeOption } from '@xchainjs/xchain-client';
|
|
6
6
|
import { Client as Client$7 } from '@xchainjs/xchain-cosmos';
|
|
7
7
|
import { Client as Client$2 } from '@xchainjs/xchain-doge';
|
|
8
|
-
import { MAX_APPROVAL, ETH_DECIMAL, Client as Client$3 } from '@xchainjs/xchain-ethereum';
|
|
8
|
+
import { abi, MAX_APPROVAL, ETH_DECIMAL, Client as Client$3 } from '@xchainjs/xchain-ethereum';
|
|
9
9
|
import { Client as Client$5 } from '@xchainjs/xchain-litecoin';
|
|
10
10
|
import { Client as Client$4 } from '@xchainjs/xchain-thorchain';
|
|
11
11
|
import { eqAsset, AssetETH, getContractAddressFromAsset, baseAmount, Chain } from '@xchainjs/xchain-util';
|
|
12
12
|
import { ethers } from 'ethers';
|
|
13
|
-
import { MAX_APPROVAL as MAX_APPROVAL$1 } from '@xchainjs/xchain-evm';
|
|
13
|
+
import { abi as abi$1, MAX_APPROVAL as MAX_APPROVAL$1 } from '@xchainjs/xchain-evm';
|
|
14
14
|
import { ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
|
|
15
15
|
|
|
16
16
|
/*! *****************************************************************************
|
|
@@ -38,371 +38,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
var routerABI = [
|
|
42
|
-
{
|
|
43
|
-
inputs: [
|
|
44
|
-
],
|
|
45
|
-
stateMutability: "nonpayable",
|
|
46
|
-
type: "constructor"
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
anonymous: false,
|
|
50
|
-
inputs: [
|
|
51
|
-
{
|
|
52
|
-
indexed: true,
|
|
53
|
-
internalType: "address",
|
|
54
|
-
name: "to",
|
|
55
|
-
type: "address"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
indexed: true,
|
|
59
|
-
internalType: "address",
|
|
60
|
-
name: "asset",
|
|
61
|
-
type: "address"
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
indexed: false,
|
|
65
|
-
internalType: "uint256",
|
|
66
|
-
name: "amount",
|
|
67
|
-
type: "uint256"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
indexed: false,
|
|
71
|
-
internalType: "string",
|
|
72
|
-
name: "memo",
|
|
73
|
-
type: "string"
|
|
74
|
-
}
|
|
75
|
-
],
|
|
76
|
-
name: "Deposit",
|
|
77
|
-
type: "event"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
anonymous: false,
|
|
81
|
-
inputs: [
|
|
82
|
-
{
|
|
83
|
-
indexed: true,
|
|
84
|
-
internalType: "address",
|
|
85
|
-
name: "oldVault",
|
|
86
|
-
type: "address"
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
indexed: true,
|
|
90
|
-
internalType: "address",
|
|
91
|
-
name: "newVault",
|
|
92
|
-
type: "address"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
indexed: false,
|
|
96
|
-
internalType: "address",
|
|
97
|
-
name: "asset",
|
|
98
|
-
type: "address"
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
indexed: false,
|
|
102
|
-
internalType: "uint256",
|
|
103
|
-
name: "amount",
|
|
104
|
-
type: "uint256"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
indexed: false,
|
|
108
|
-
internalType: "string",
|
|
109
|
-
name: "memo",
|
|
110
|
-
type: "string"
|
|
111
|
-
}
|
|
112
|
-
],
|
|
113
|
-
name: "TransferAllowance",
|
|
114
|
-
type: "event"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
anonymous: false,
|
|
118
|
-
inputs: [
|
|
119
|
-
{
|
|
120
|
-
indexed: true,
|
|
121
|
-
internalType: "address",
|
|
122
|
-
name: "vault",
|
|
123
|
-
type: "address"
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
indexed: true,
|
|
127
|
-
internalType: "address",
|
|
128
|
-
name: "to",
|
|
129
|
-
type: "address"
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
indexed: false,
|
|
133
|
-
internalType: "address",
|
|
134
|
-
name: "asset",
|
|
135
|
-
type: "address"
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
indexed: false,
|
|
139
|
-
internalType: "uint256",
|
|
140
|
-
name: "amount",
|
|
141
|
-
type: "uint256"
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
indexed: false,
|
|
145
|
-
internalType: "string",
|
|
146
|
-
name: "memo",
|
|
147
|
-
type: "string"
|
|
148
|
-
}
|
|
149
|
-
],
|
|
150
|
-
name: "TransferOut",
|
|
151
|
-
type: "event"
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
anonymous: false,
|
|
155
|
-
inputs: [
|
|
156
|
-
{
|
|
157
|
-
indexed: true,
|
|
158
|
-
internalType: "address",
|
|
159
|
-
name: "oldVault",
|
|
160
|
-
type: "address"
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
indexed: true,
|
|
164
|
-
internalType: "address",
|
|
165
|
-
name: "newVault",
|
|
166
|
-
type: "address"
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
components: [
|
|
170
|
-
{
|
|
171
|
-
internalType: "address",
|
|
172
|
-
name: "asset",
|
|
173
|
-
type: "address"
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
internalType: "uint256",
|
|
177
|
-
name: "amount",
|
|
178
|
-
type: "uint256"
|
|
179
|
-
}
|
|
180
|
-
],
|
|
181
|
-
indexed: false,
|
|
182
|
-
internalType: "struct Router.Coin[]",
|
|
183
|
-
name: "coins",
|
|
184
|
-
type: "tuple[]"
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
indexed: false,
|
|
188
|
-
internalType: "string",
|
|
189
|
-
name: "memo",
|
|
190
|
-
type: "string"
|
|
191
|
-
}
|
|
192
|
-
],
|
|
193
|
-
name: "VaultTransfer",
|
|
194
|
-
type: "event"
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
inputs: [
|
|
198
|
-
],
|
|
199
|
-
name: "RUNE",
|
|
200
|
-
outputs: [
|
|
201
|
-
{
|
|
202
|
-
internalType: "address",
|
|
203
|
-
name: "",
|
|
204
|
-
type: "address"
|
|
205
|
-
}
|
|
206
|
-
],
|
|
207
|
-
stateMutability: "view",
|
|
208
|
-
type: "function"
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
inputs: [
|
|
212
|
-
{
|
|
213
|
-
internalType: "address[]",
|
|
214
|
-
name: "recipients",
|
|
215
|
-
type: "address[]"
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
components: [
|
|
219
|
-
{
|
|
220
|
-
internalType: "address",
|
|
221
|
-
name: "asset",
|
|
222
|
-
type: "address"
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
internalType: "uint256",
|
|
226
|
-
name: "amount",
|
|
227
|
-
type: "uint256"
|
|
228
|
-
}
|
|
229
|
-
],
|
|
230
|
-
internalType: "struct Router.Coin[]",
|
|
231
|
-
name: "coins",
|
|
232
|
-
type: "tuple[]"
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
internalType: "string[]",
|
|
236
|
-
name: "memos",
|
|
237
|
-
type: "string[]"
|
|
238
|
-
}
|
|
239
|
-
],
|
|
240
|
-
name: "batchTransferOut",
|
|
241
|
-
outputs: [
|
|
242
|
-
],
|
|
243
|
-
stateMutability: "payable",
|
|
244
|
-
type: "function"
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
inputs: [
|
|
248
|
-
{
|
|
249
|
-
internalType: "address payable",
|
|
250
|
-
name: "vault",
|
|
251
|
-
type: "address"
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
internalType: "address",
|
|
255
|
-
name: "asset",
|
|
256
|
-
type: "address"
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
internalType: "uint256",
|
|
260
|
-
name: "amount",
|
|
261
|
-
type: "uint256"
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
internalType: "string",
|
|
265
|
-
name: "memo",
|
|
266
|
-
type: "string"
|
|
267
|
-
}
|
|
268
|
-
],
|
|
269
|
-
name: "deposit",
|
|
270
|
-
outputs: [
|
|
271
|
-
],
|
|
272
|
-
stateMutability: "payable",
|
|
273
|
-
type: "function"
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
inputs: [
|
|
277
|
-
{
|
|
278
|
-
internalType: "address",
|
|
279
|
-
name: "router",
|
|
280
|
-
type: "address"
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
internalType: "address payable",
|
|
284
|
-
name: "asgard",
|
|
285
|
-
type: "address"
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
components: [
|
|
289
|
-
{
|
|
290
|
-
internalType: "address",
|
|
291
|
-
name: "asset",
|
|
292
|
-
type: "address"
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
internalType: "uint256",
|
|
296
|
-
name: "amount",
|
|
297
|
-
type: "uint256"
|
|
298
|
-
}
|
|
299
|
-
],
|
|
300
|
-
internalType: "struct Router.Coin[]",
|
|
301
|
-
name: "coins",
|
|
302
|
-
type: "tuple[]"
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
internalType: "string",
|
|
306
|
-
name: "memo",
|
|
307
|
-
type: "string"
|
|
308
|
-
}
|
|
309
|
-
],
|
|
310
|
-
name: "returnVaultAssets",
|
|
311
|
-
outputs: [
|
|
312
|
-
],
|
|
313
|
-
stateMutability: "payable",
|
|
314
|
-
type: "function"
|
|
315
|
-
},
|
|
316
|
-
{
|
|
317
|
-
inputs: [
|
|
318
|
-
{
|
|
319
|
-
internalType: "address",
|
|
320
|
-
name: "router",
|
|
321
|
-
type: "address"
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
internalType: "address",
|
|
325
|
-
name: "newVault",
|
|
326
|
-
type: "address"
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
internalType: "address",
|
|
330
|
-
name: "asset",
|
|
331
|
-
type: "address"
|
|
332
|
-
},
|
|
333
|
-
{
|
|
334
|
-
internalType: "uint256",
|
|
335
|
-
name: "amount",
|
|
336
|
-
type: "uint256"
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
internalType: "string",
|
|
340
|
-
name: "memo",
|
|
341
|
-
type: "string"
|
|
342
|
-
}
|
|
343
|
-
],
|
|
344
|
-
name: "transferAllowance",
|
|
345
|
-
outputs: [
|
|
346
|
-
],
|
|
347
|
-
stateMutability: "nonpayable",
|
|
348
|
-
type: "function"
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
inputs: [
|
|
352
|
-
{
|
|
353
|
-
internalType: "address payable",
|
|
354
|
-
name: "to",
|
|
355
|
-
type: "address"
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
internalType: "address",
|
|
359
|
-
name: "asset",
|
|
360
|
-
type: "address"
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
internalType: "uint256",
|
|
364
|
-
name: "amount",
|
|
365
|
-
type: "uint256"
|
|
366
|
-
},
|
|
367
|
-
{
|
|
368
|
-
internalType: "string",
|
|
369
|
-
name: "memo",
|
|
370
|
-
type: "string"
|
|
371
|
-
}
|
|
372
|
-
],
|
|
373
|
-
name: "transferOut",
|
|
374
|
-
outputs: [
|
|
375
|
-
],
|
|
376
|
-
stateMutability: "payable",
|
|
377
|
-
type: "function"
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
inputs: [
|
|
381
|
-
{
|
|
382
|
-
internalType: "address",
|
|
383
|
-
name: "",
|
|
384
|
-
type: "address"
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
internalType: "address",
|
|
388
|
-
name: "",
|
|
389
|
-
type: "address"
|
|
390
|
-
}
|
|
391
|
-
],
|
|
392
|
-
name: "vaultAllowance",
|
|
393
|
-
outputs: [
|
|
394
|
-
{
|
|
395
|
-
internalType: "uint256",
|
|
396
|
-
name: "",
|
|
397
|
-
type: "uint256"
|
|
398
|
-
}
|
|
399
|
-
],
|
|
400
|
-
stateMutability: "view",
|
|
401
|
-
type: "function"
|
|
402
|
-
}
|
|
403
|
-
];
|
|
404
|
-
|
|
405
41
|
const APPROVE_GASLIMIT_FALLBACK = '200000';
|
|
42
|
+
const FIFTEEN_MIN_IN_SECS = 15 * 60;
|
|
406
43
|
class EthHelper {
|
|
407
44
|
constructor(client, thorchainCache) {
|
|
408
45
|
this.ethClient = client;
|
|
@@ -449,15 +86,18 @@ class EthHelper {
|
|
|
449
86
|
}
|
|
450
87
|
const contractAddress = getContractAddressFromAsset(params.asset);
|
|
451
88
|
const checkSummedContractAddress = ethers.utils.getAddress(contractAddress);
|
|
89
|
+
const latestBlockTimeUnixSecs = (yield this.ethClient.getProvider().getBlock('latest')).timestamp;
|
|
90
|
+
const expiry = latestBlockTimeUnixSecs + FIFTEEN_MIN_IN_SECS;
|
|
452
91
|
const depositParams = [
|
|
453
92
|
inboundAsgard.address,
|
|
454
93
|
checkSummedContractAddress,
|
|
455
94
|
params.amount.amount().toFixed(),
|
|
456
95
|
params.memo,
|
|
96
|
+
expiry,
|
|
457
97
|
];
|
|
458
|
-
const routerContract = new ethers.Contract(inboundAsgard.router,
|
|
98
|
+
const routerContract = new ethers.Contract(inboundAsgard.router, abi.router);
|
|
459
99
|
const gasLimit = '80000';
|
|
460
|
-
const unsignedTx = yield routerContract.populateTransaction.
|
|
100
|
+
const unsignedTx = yield routerContract.populateTransaction.depositWithExpiry(...depositParams, {
|
|
461
101
|
from: address,
|
|
462
102
|
value: 0,
|
|
463
103
|
gasPrice: gasPrice.fast.amount().toFixed(),
|
|
@@ -498,6 +138,7 @@ class EthHelper {
|
|
|
498
138
|
}
|
|
499
139
|
}
|
|
500
140
|
|
|
141
|
+
const FIFTEEN_MIN_IN_SECS$1 = 15 * 60;
|
|
501
142
|
class EvmHelper {
|
|
502
143
|
constructor(client, thorchainCache) {
|
|
503
144
|
this.evmClient = client;
|
|
@@ -544,15 +185,18 @@ class EvmHelper {
|
|
|
544
185
|
}
|
|
545
186
|
const contractAddress = getContractAddressFromAsset(params.asset);
|
|
546
187
|
const checkSummedContractAddress = ethers.utils.getAddress(contractAddress);
|
|
188
|
+
const latestBlockTimeUnixSecs = (yield this.evmClient.getProvider().getBlock('latest')).timestamp;
|
|
189
|
+
const expiry = latestBlockTimeUnixSecs + FIFTEEN_MIN_IN_SECS$1;
|
|
547
190
|
const depositParams = [
|
|
548
191
|
inboundAsgard.address,
|
|
549
192
|
checkSummedContractAddress,
|
|
550
193
|
params.amount.amount().toFixed(),
|
|
551
194
|
params.memo,
|
|
195
|
+
expiry,
|
|
552
196
|
];
|
|
553
|
-
const routerContract = new ethers.Contract(inboundAsgard.router,
|
|
197
|
+
const routerContract = new ethers.Contract(inboundAsgard.router, abi$1.router);
|
|
554
198
|
const gasLimit = '80000';
|
|
555
|
-
const unsignedTx = yield routerContract.populateTransaction.
|
|
199
|
+
const unsignedTx = yield routerContract.populateTransaction.depositWithExpiry(...depositParams, {
|
|
556
200
|
from: address,
|
|
557
201
|
value: 0,
|
|
558
202
|
gasPrice: gasPrice.fast.amount().toFixed(),
|
package/lib/index.js
CHANGED
|
@@ -42,371 +42,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
var routerABI = [
|
|
46
|
-
{
|
|
47
|
-
inputs: [
|
|
48
|
-
],
|
|
49
|
-
stateMutability: "nonpayable",
|
|
50
|
-
type: "constructor"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
anonymous: false,
|
|
54
|
-
inputs: [
|
|
55
|
-
{
|
|
56
|
-
indexed: true,
|
|
57
|
-
internalType: "address",
|
|
58
|
-
name: "to",
|
|
59
|
-
type: "address"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
indexed: true,
|
|
63
|
-
internalType: "address",
|
|
64
|
-
name: "asset",
|
|
65
|
-
type: "address"
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
indexed: false,
|
|
69
|
-
internalType: "uint256",
|
|
70
|
-
name: "amount",
|
|
71
|
-
type: "uint256"
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
indexed: false,
|
|
75
|
-
internalType: "string",
|
|
76
|
-
name: "memo",
|
|
77
|
-
type: "string"
|
|
78
|
-
}
|
|
79
|
-
],
|
|
80
|
-
name: "Deposit",
|
|
81
|
-
type: "event"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
anonymous: false,
|
|
85
|
-
inputs: [
|
|
86
|
-
{
|
|
87
|
-
indexed: true,
|
|
88
|
-
internalType: "address",
|
|
89
|
-
name: "oldVault",
|
|
90
|
-
type: "address"
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
indexed: true,
|
|
94
|
-
internalType: "address",
|
|
95
|
-
name: "newVault",
|
|
96
|
-
type: "address"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
indexed: false,
|
|
100
|
-
internalType: "address",
|
|
101
|
-
name: "asset",
|
|
102
|
-
type: "address"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
indexed: false,
|
|
106
|
-
internalType: "uint256",
|
|
107
|
-
name: "amount",
|
|
108
|
-
type: "uint256"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
indexed: false,
|
|
112
|
-
internalType: "string",
|
|
113
|
-
name: "memo",
|
|
114
|
-
type: "string"
|
|
115
|
-
}
|
|
116
|
-
],
|
|
117
|
-
name: "TransferAllowance",
|
|
118
|
-
type: "event"
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
anonymous: false,
|
|
122
|
-
inputs: [
|
|
123
|
-
{
|
|
124
|
-
indexed: true,
|
|
125
|
-
internalType: "address",
|
|
126
|
-
name: "vault",
|
|
127
|
-
type: "address"
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
indexed: true,
|
|
131
|
-
internalType: "address",
|
|
132
|
-
name: "to",
|
|
133
|
-
type: "address"
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
indexed: false,
|
|
137
|
-
internalType: "address",
|
|
138
|
-
name: "asset",
|
|
139
|
-
type: "address"
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
indexed: false,
|
|
143
|
-
internalType: "uint256",
|
|
144
|
-
name: "amount",
|
|
145
|
-
type: "uint256"
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
indexed: false,
|
|
149
|
-
internalType: "string",
|
|
150
|
-
name: "memo",
|
|
151
|
-
type: "string"
|
|
152
|
-
}
|
|
153
|
-
],
|
|
154
|
-
name: "TransferOut",
|
|
155
|
-
type: "event"
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
anonymous: false,
|
|
159
|
-
inputs: [
|
|
160
|
-
{
|
|
161
|
-
indexed: true,
|
|
162
|
-
internalType: "address",
|
|
163
|
-
name: "oldVault",
|
|
164
|
-
type: "address"
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
indexed: true,
|
|
168
|
-
internalType: "address",
|
|
169
|
-
name: "newVault",
|
|
170
|
-
type: "address"
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
components: [
|
|
174
|
-
{
|
|
175
|
-
internalType: "address",
|
|
176
|
-
name: "asset",
|
|
177
|
-
type: "address"
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
internalType: "uint256",
|
|
181
|
-
name: "amount",
|
|
182
|
-
type: "uint256"
|
|
183
|
-
}
|
|
184
|
-
],
|
|
185
|
-
indexed: false,
|
|
186
|
-
internalType: "struct Router.Coin[]",
|
|
187
|
-
name: "coins",
|
|
188
|
-
type: "tuple[]"
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
indexed: false,
|
|
192
|
-
internalType: "string",
|
|
193
|
-
name: "memo",
|
|
194
|
-
type: "string"
|
|
195
|
-
}
|
|
196
|
-
],
|
|
197
|
-
name: "VaultTransfer",
|
|
198
|
-
type: "event"
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
inputs: [
|
|
202
|
-
],
|
|
203
|
-
name: "RUNE",
|
|
204
|
-
outputs: [
|
|
205
|
-
{
|
|
206
|
-
internalType: "address",
|
|
207
|
-
name: "",
|
|
208
|
-
type: "address"
|
|
209
|
-
}
|
|
210
|
-
],
|
|
211
|
-
stateMutability: "view",
|
|
212
|
-
type: "function"
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
inputs: [
|
|
216
|
-
{
|
|
217
|
-
internalType: "address[]",
|
|
218
|
-
name: "recipients",
|
|
219
|
-
type: "address[]"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
components: [
|
|
223
|
-
{
|
|
224
|
-
internalType: "address",
|
|
225
|
-
name: "asset",
|
|
226
|
-
type: "address"
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
internalType: "uint256",
|
|
230
|
-
name: "amount",
|
|
231
|
-
type: "uint256"
|
|
232
|
-
}
|
|
233
|
-
],
|
|
234
|
-
internalType: "struct Router.Coin[]",
|
|
235
|
-
name: "coins",
|
|
236
|
-
type: "tuple[]"
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
internalType: "string[]",
|
|
240
|
-
name: "memos",
|
|
241
|
-
type: "string[]"
|
|
242
|
-
}
|
|
243
|
-
],
|
|
244
|
-
name: "batchTransferOut",
|
|
245
|
-
outputs: [
|
|
246
|
-
],
|
|
247
|
-
stateMutability: "payable",
|
|
248
|
-
type: "function"
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
inputs: [
|
|
252
|
-
{
|
|
253
|
-
internalType: "address payable",
|
|
254
|
-
name: "vault",
|
|
255
|
-
type: "address"
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
internalType: "address",
|
|
259
|
-
name: "asset",
|
|
260
|
-
type: "address"
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
internalType: "uint256",
|
|
264
|
-
name: "amount",
|
|
265
|
-
type: "uint256"
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
internalType: "string",
|
|
269
|
-
name: "memo",
|
|
270
|
-
type: "string"
|
|
271
|
-
}
|
|
272
|
-
],
|
|
273
|
-
name: "deposit",
|
|
274
|
-
outputs: [
|
|
275
|
-
],
|
|
276
|
-
stateMutability: "payable",
|
|
277
|
-
type: "function"
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
inputs: [
|
|
281
|
-
{
|
|
282
|
-
internalType: "address",
|
|
283
|
-
name: "router",
|
|
284
|
-
type: "address"
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
internalType: "address payable",
|
|
288
|
-
name: "asgard",
|
|
289
|
-
type: "address"
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
components: [
|
|
293
|
-
{
|
|
294
|
-
internalType: "address",
|
|
295
|
-
name: "asset",
|
|
296
|
-
type: "address"
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
internalType: "uint256",
|
|
300
|
-
name: "amount",
|
|
301
|
-
type: "uint256"
|
|
302
|
-
}
|
|
303
|
-
],
|
|
304
|
-
internalType: "struct Router.Coin[]",
|
|
305
|
-
name: "coins",
|
|
306
|
-
type: "tuple[]"
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
internalType: "string",
|
|
310
|
-
name: "memo",
|
|
311
|
-
type: "string"
|
|
312
|
-
}
|
|
313
|
-
],
|
|
314
|
-
name: "returnVaultAssets",
|
|
315
|
-
outputs: [
|
|
316
|
-
],
|
|
317
|
-
stateMutability: "payable",
|
|
318
|
-
type: "function"
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
inputs: [
|
|
322
|
-
{
|
|
323
|
-
internalType: "address",
|
|
324
|
-
name: "router",
|
|
325
|
-
type: "address"
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
internalType: "address",
|
|
329
|
-
name: "newVault",
|
|
330
|
-
type: "address"
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
internalType: "address",
|
|
334
|
-
name: "asset",
|
|
335
|
-
type: "address"
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
internalType: "uint256",
|
|
339
|
-
name: "amount",
|
|
340
|
-
type: "uint256"
|
|
341
|
-
},
|
|
342
|
-
{
|
|
343
|
-
internalType: "string",
|
|
344
|
-
name: "memo",
|
|
345
|
-
type: "string"
|
|
346
|
-
}
|
|
347
|
-
],
|
|
348
|
-
name: "transferAllowance",
|
|
349
|
-
outputs: [
|
|
350
|
-
],
|
|
351
|
-
stateMutability: "nonpayable",
|
|
352
|
-
type: "function"
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
inputs: [
|
|
356
|
-
{
|
|
357
|
-
internalType: "address payable",
|
|
358
|
-
name: "to",
|
|
359
|
-
type: "address"
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
internalType: "address",
|
|
363
|
-
name: "asset",
|
|
364
|
-
type: "address"
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
internalType: "uint256",
|
|
368
|
-
name: "amount",
|
|
369
|
-
type: "uint256"
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
internalType: "string",
|
|
373
|
-
name: "memo",
|
|
374
|
-
type: "string"
|
|
375
|
-
}
|
|
376
|
-
],
|
|
377
|
-
name: "transferOut",
|
|
378
|
-
outputs: [
|
|
379
|
-
],
|
|
380
|
-
stateMutability: "payable",
|
|
381
|
-
type: "function"
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
inputs: [
|
|
385
|
-
{
|
|
386
|
-
internalType: "address",
|
|
387
|
-
name: "",
|
|
388
|
-
type: "address"
|
|
389
|
-
},
|
|
390
|
-
{
|
|
391
|
-
internalType: "address",
|
|
392
|
-
name: "",
|
|
393
|
-
type: "address"
|
|
394
|
-
}
|
|
395
|
-
],
|
|
396
|
-
name: "vaultAllowance",
|
|
397
|
-
outputs: [
|
|
398
|
-
{
|
|
399
|
-
internalType: "uint256",
|
|
400
|
-
name: "",
|
|
401
|
-
type: "uint256"
|
|
402
|
-
}
|
|
403
|
-
],
|
|
404
|
-
stateMutability: "view",
|
|
405
|
-
type: "function"
|
|
406
|
-
}
|
|
407
|
-
];
|
|
408
|
-
|
|
409
45
|
const APPROVE_GASLIMIT_FALLBACK = '200000';
|
|
46
|
+
const FIFTEEN_MIN_IN_SECS = 15 * 60;
|
|
410
47
|
class EthHelper {
|
|
411
48
|
constructor(client, thorchainCache) {
|
|
412
49
|
this.ethClient = client;
|
|
@@ -453,15 +90,18 @@ class EthHelper {
|
|
|
453
90
|
}
|
|
454
91
|
const contractAddress = xchainUtil.getContractAddressFromAsset(params.asset);
|
|
455
92
|
const checkSummedContractAddress = ethers.ethers.utils.getAddress(contractAddress);
|
|
93
|
+
const latestBlockTimeUnixSecs = (yield this.ethClient.getProvider().getBlock('latest')).timestamp;
|
|
94
|
+
const expiry = latestBlockTimeUnixSecs + FIFTEEN_MIN_IN_SECS;
|
|
456
95
|
const depositParams = [
|
|
457
96
|
inboundAsgard.address,
|
|
458
97
|
checkSummedContractAddress,
|
|
459
98
|
params.amount.amount().toFixed(),
|
|
460
99
|
params.memo,
|
|
100
|
+
expiry,
|
|
461
101
|
];
|
|
462
|
-
const routerContract = new ethers.ethers.Contract(inboundAsgard.router,
|
|
102
|
+
const routerContract = new ethers.ethers.Contract(inboundAsgard.router, xchainEthereum.abi.router);
|
|
463
103
|
const gasLimit = '80000';
|
|
464
|
-
const unsignedTx = yield routerContract.populateTransaction.
|
|
104
|
+
const unsignedTx = yield routerContract.populateTransaction.depositWithExpiry(...depositParams, {
|
|
465
105
|
from: address,
|
|
466
106
|
value: 0,
|
|
467
107
|
gasPrice: gasPrice.fast.amount().toFixed(),
|
|
@@ -502,6 +142,7 @@ class EthHelper {
|
|
|
502
142
|
}
|
|
503
143
|
}
|
|
504
144
|
|
|
145
|
+
const FIFTEEN_MIN_IN_SECS$1 = 15 * 60;
|
|
505
146
|
class EvmHelper {
|
|
506
147
|
constructor(client, thorchainCache) {
|
|
507
148
|
this.evmClient = client;
|
|
@@ -548,15 +189,18 @@ class EvmHelper {
|
|
|
548
189
|
}
|
|
549
190
|
const contractAddress = xchainUtil.getContractAddressFromAsset(params.asset);
|
|
550
191
|
const checkSummedContractAddress = ethers.ethers.utils.getAddress(contractAddress);
|
|
192
|
+
const latestBlockTimeUnixSecs = (yield this.evmClient.getProvider().getBlock('latest')).timestamp;
|
|
193
|
+
const expiry = latestBlockTimeUnixSecs + FIFTEEN_MIN_IN_SECS$1;
|
|
551
194
|
const depositParams = [
|
|
552
195
|
inboundAsgard.address,
|
|
553
196
|
checkSummedContractAddress,
|
|
554
197
|
params.amount.amount().toFixed(),
|
|
555
198
|
params.memo,
|
|
199
|
+
expiry,
|
|
556
200
|
];
|
|
557
|
-
const routerContract = new ethers.ethers.Contract(inboundAsgard.router,
|
|
201
|
+
const routerContract = new ethers.ethers.Contract(inboundAsgard.router, xchainEvm.abi.router);
|
|
558
202
|
const gasLimit = '80000';
|
|
559
|
-
const unsignedTx = yield routerContract.populateTransaction.
|
|
203
|
+
const unsignedTx = yield routerContract.populateTransaction.depositWithExpiry(...depositParams, {
|
|
560
204
|
from: address,
|
|
561
205
|
value: 0,
|
|
562
206
|
gasPrice: gasPrice.fast.amount().toFixed(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-amm",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -39,21 +39,20 @@
|
|
|
39
39
|
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
40
40
|
"@cosmos-client/core": "0.45.13",
|
|
41
41
|
"@psf/bitcoincashjs-lib": "^4.0.2",
|
|
42
|
-
"@
|
|
43
|
-
"@xchainjs/xchain-
|
|
44
|
-
"@xchainjs/xchain-
|
|
45
|
-
"@xchainjs/xchain-
|
|
46
|
-
"@xchainjs/xchain-
|
|
47
|
-
"@xchainjs/xchain-cosmos": "^0.20.0",
|
|
42
|
+
"@xchainjs/xchain-binance": "^5.6.5",
|
|
43
|
+
"@xchainjs/xchain-bitcoin": "^0.20.5",
|
|
44
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.4",
|
|
45
|
+
"@xchainjs/xchain-client": "^0.13.3",
|
|
46
|
+
"@xchainjs/xchain-cosmos": "^0.20.4",
|
|
48
47
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
49
|
-
"@xchainjs/xchain-doge": "^0.5.
|
|
50
|
-
"@xchainjs/xchain-ethereum": "^0.27.
|
|
51
|
-
"@xchainjs/xchain-evm": "^0.1.
|
|
52
|
-
"@xchainjs/xchain-avax": "^0.1.
|
|
53
|
-
"@xchainjs/xchain-litecoin": "^0.10.
|
|
48
|
+
"@xchainjs/xchain-doge": "^0.5.5",
|
|
49
|
+
"@xchainjs/xchain-ethereum": "^0.27.4",
|
|
50
|
+
"@xchainjs/xchain-evm": "^0.1.1",
|
|
51
|
+
"@xchainjs/xchain-avax": "^0.1.1",
|
|
52
|
+
"@xchainjs/xchain-litecoin": "^0.10.6",
|
|
54
53
|
"@xchainjs/xchain-midgard": "0.3.0",
|
|
55
|
-
"@xchainjs/xchain-thorchain": "^0.27.
|
|
56
|
-
"@xchainjs/xchain-thorchain-query": "^0.1.
|
|
54
|
+
"@xchainjs/xchain-thorchain": "^0.27.4",
|
|
55
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.9",
|
|
57
56
|
"@xchainjs/xchain-thornode": "^0.1.2",
|
|
58
57
|
"@xchainjs/xchain-util": "^0.11.0",
|
|
59
58
|
"axios": "^0.25.0",
|
|
@@ -73,21 +72,21 @@
|
|
|
73
72
|
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
74
73
|
"@cosmos-client/core": "0.45.13",
|
|
75
74
|
"@psf/bitcoincashjs-lib": "^4.0.2",
|
|
76
|
-
"@xchainjs/xchain-binance": "^5.6.
|
|
77
|
-
"@xchainjs/xchain-bitcoin": "^0.20.
|
|
78
|
-
"@xchainjs/xchain-bitcoincash": "^0.15.
|
|
79
|
-
"@xchainjs/xchain-client": "^0.13.
|
|
80
|
-
"@xchainjs/xchain-cosmos": "^0.20.
|
|
75
|
+
"@xchainjs/xchain-binance": "^5.6.5",
|
|
76
|
+
"@xchainjs/xchain-bitcoin": "^0.20.5",
|
|
77
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.4",
|
|
78
|
+
"@xchainjs/xchain-client": "^0.13.3",
|
|
79
|
+
"@xchainjs/xchain-cosmos": "^0.20.4",
|
|
81
80
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
82
|
-
"@xchainjs/xchain-doge": "^0.5.
|
|
83
|
-
"@xchainjs/xchain-ethereum": "^0.27.
|
|
84
|
-
"@xchainjs/xchain-evm": "^0.1.
|
|
85
|
-
"@xchainjs/xchain-avax": "^0.1.
|
|
86
|
-
"@xchainjs/xchain-litecoin": "^0.10.
|
|
87
|
-
"@xchainjs/xchain-midgard": "0.
|
|
88
|
-
"@xchainjs/xchain-
|
|
89
|
-
"@xchainjs/xchain-thorchain": "^0.
|
|
90
|
-
"@xchainjs/xchain-
|
|
81
|
+
"@xchainjs/xchain-doge": "^0.5.5",
|
|
82
|
+
"@xchainjs/xchain-ethereum": "^0.27.4",
|
|
83
|
+
"@xchainjs/xchain-evm": "^0.1.1",
|
|
84
|
+
"@xchainjs/xchain-avax": "^0.1.1",
|
|
85
|
+
"@xchainjs/xchain-litecoin": "^0.10.6",
|
|
86
|
+
"@xchainjs/xchain-midgard": "0.3.0",
|
|
87
|
+
"@xchainjs/xchain-thorchain": "^0.27.4",
|
|
88
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.9",
|
|
89
|
+
"@xchainjs/xchain-thornode": "^0.1.2",
|
|
91
90
|
"@xchainjs/xchain-util": "^0.11.0",
|
|
92
91
|
"axios": "^0.25.0",
|
|
93
92
|
"axios-retry": "^3.2.5",
|