@xchainjs/xchain-thorchain-amm 0.3.9 → 0.3.11
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 +38 -19
- package/lib/index.esm.js +31 -387
- package/lib/index.js +27 -383
- package/package.json +31 -31
package/README.md
CHANGED
|
@@ -14,26 +14,25 @@ Following peer dependencies have to be installed into your project. These are no
|
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
"dependencies": {
|
|
17
|
-
|
|
18
|
-
"@cosmos-client/core": "0.
|
|
17
|
+
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
18
|
+
"@cosmos-client/core": "0.46.1",
|
|
19
19
|
"@psf/bitcoincashjs-lib": "^4.0.2",
|
|
20
|
-
"@
|
|
21
|
-
"@xchainjs/xchain-
|
|
22
|
-
"@xchainjs/xchain-
|
|
23
|
-
"@xchainjs/xchain-
|
|
24
|
-
"@xchainjs/xchain-
|
|
25
|
-
"@xchainjs/xchain-cosmos": "^0.20.0",
|
|
20
|
+
"@xchainjs/xchain-binance": "^5.6.6",
|
|
21
|
+
"@xchainjs/xchain-bitcoin": "^0.20.7",
|
|
22
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.6",
|
|
23
|
+
"@xchainjs/xchain-client": "^0.13.5",
|
|
24
|
+
"@xchainjs/xchain-cosmos": "^0.20.6",
|
|
26
25
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
27
|
-
"@xchainjs/xchain-doge": "^0.5.
|
|
28
|
-
"@xchainjs/xchain-ethereum": "^0.27.
|
|
29
|
-
"@xchainjs/xchain-evm": "^0.1.
|
|
30
|
-
"@xchainjs/xchain-avax": "^0.1.
|
|
31
|
-
"@xchainjs/xchain-litecoin": "^0.10.
|
|
32
|
-
"@xchainjs/xchain-midgard": "0.
|
|
33
|
-
"@xchainjs/xchain-thorchain": "^0.27.
|
|
34
|
-
"@xchainjs/xchain-thorchain-query": "^0.1.
|
|
35
|
-
"@xchainjs/xchain-thornode": "^0.1.
|
|
36
|
-
"@xchainjs/xchain-util": "^0.
|
|
26
|
+
"@xchainjs/xchain-doge": "^0.5.6",
|
|
27
|
+
"@xchainjs/xchain-ethereum": "^0.27.6",
|
|
28
|
+
"@xchainjs/xchain-evm": "^0.1.3",
|
|
29
|
+
"@xchainjs/xchain-avax": "^0.1.3",
|
|
30
|
+
"@xchainjs/xchain-litecoin": "^0.10.8",
|
|
31
|
+
"@xchainjs/xchain-midgard": "0.4.1",
|
|
32
|
+
"@xchainjs/xchain-thorchain": "^0.27.7",
|
|
33
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.12",
|
|
34
|
+
"@xchainjs/xchain-thornode": "^0.1.5",
|
|
35
|
+
"@xchainjs/xchain-util": "^0.12.0",
|
|
37
36
|
"axios": "^0.25.0",
|
|
38
37
|
"axios-retry": "^3.2.5",
|
|
39
38
|
"bchaddrjs": "^0.5.2",
|
|
@@ -41,7 +40,6 @@ Following peer dependencies have to be installed into your project. These are no
|
|
|
41
40
|
"bech32-buffer": "^0.2.0",
|
|
42
41
|
"bignumber.js": "^9.0.0",
|
|
43
42
|
"bitcoinjs-lib": "^5.2.0",
|
|
44
|
-
"dotenv": "^16.0.0",
|
|
45
43
|
"coininfo": "^5.1.0",
|
|
46
44
|
"coinselect": "^3.1.12",
|
|
47
45
|
"ethers": "^5.6.6",
|
|
@@ -79,3 +77,24 @@ tsconfig compiler options
|
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
```
|
|
80
|
+
|
|
81
|
+
### Setting Headers for Nine Realms endpoints
|
|
82
|
+
|
|
83
|
+
If you plan on using the publically accessible endpoints provided by Nine Realms(listed below), ensure that you add a valid 'x-client-id' to all requests
|
|
84
|
+
|
|
85
|
+
- https://midgard.ninerealms.com
|
|
86
|
+
- https://haskoin.ninerealms.com (BTC/BCH/LTC)
|
|
87
|
+
- https://thornode.ninerealms.com
|
|
88
|
+
|
|
89
|
+
Example
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import cosmosclient from '@cosmos-client/core'
|
|
93
|
+
import axios from 'axios'
|
|
94
|
+
import { register9Rheader } from '@xchainjs/xchain-util'
|
|
95
|
+
|
|
96
|
+
register9Rheader(axios)
|
|
97
|
+
register9Rheader(cosmosclient.config.globalAxios)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
For a complete example please see this [test](https://github.com/xchainjs/xchainjs-lib/blob/master/packages/xchain-thorchain-amm/__e2e__/wallet.e2e.ts)
|
package/lib/index.esm.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Client as Client$8, defaultAvaxParams } from '@xchainjs/xchain-avax';
|
|
1
|
+
import { Client as Client$8, defaultAvaxParams, AVAXChain } from '@xchainjs/xchain-avax';
|
|
2
2
|
import { Client as Client$6 } from '@xchainjs/xchain-binance';
|
|
3
3
|
import { Client as Client$1 } from '@xchainjs/xchain-bitcoin';
|
|
4
4
|
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 { AssetETH, abi, MAX_APPROVAL, ETH_DECIMAL, Client as Client$3, ETHChain } from '@xchainjs/xchain-ethereum';
|
|
9
9
|
import { Client as Client$5 } from '@xchainjs/xchain-litecoin';
|
|
10
|
-
import { Client as Client$4 } from '@xchainjs/xchain-thorchain';
|
|
11
|
-
import { eqAsset,
|
|
10
|
+
import { Client as Client$4, THORChain } from '@xchainjs/xchain-thorchain';
|
|
11
|
+
import { eqAsset, getContractAddressFromAsset, baseAmount } 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(),
|
|
@@ -649,7 +293,7 @@ class Wallet {
|
|
|
649
293
|
executeSwap(swap) {
|
|
650
294
|
return __awaiter(this, void 0, void 0, function* () {
|
|
651
295
|
this.validateSwap(swap);
|
|
652
|
-
if (swap.input.asset.chain ===
|
|
296
|
+
if (swap.input.asset.chain === THORChain || swap.input.asset.synth) {
|
|
653
297
|
return yield this.swapRuneTo(swap);
|
|
654
298
|
}
|
|
655
299
|
else {
|
|
@@ -663,8 +307,8 @@ class Wallet {
|
|
|
663
307
|
*/
|
|
664
308
|
validateSwap(swap) {
|
|
665
309
|
const errors = [];
|
|
666
|
-
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain ===
|
|
667
|
-
const chain = isThorchainDestinationAsset ?
|
|
310
|
+
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain === THORChain;
|
|
311
|
+
const chain = isThorchainDestinationAsset ? THORChain : swap.destinationAsset.chain;
|
|
668
312
|
if (!this.clients[chain].validateAddress(swap.destinationAddress)) {
|
|
669
313
|
errors.push(`destinationAddress ${swap.destinationAddress} is not a valid address`);
|
|
670
314
|
}
|
|
@@ -673,7 +317,7 @@ class Wallet {
|
|
|
673
317
|
if (checkAffiliateAddress.length > 4) {
|
|
674
318
|
const affiliateAddress = checkAffiliateAddress[4];
|
|
675
319
|
if (affiliateAddress.length > 0) {
|
|
676
|
-
const isValidThorchainAddress = this.clients[
|
|
320
|
+
const isValidThorchainAddress = this.clients[THORChain].validateAddress(affiliateAddress);
|
|
677
321
|
const isValidThorname = this.isThorname(affiliateAddress);
|
|
678
322
|
if (!(isValidThorchainAddress || isValidThorname))
|
|
679
323
|
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
@@ -717,7 +361,7 @@ class Wallet {
|
|
|
717
361
|
const inbound = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[swap.input.asset.chain];
|
|
718
362
|
if (!(inbound === null || inbound === void 0 ? void 0 : inbound.address))
|
|
719
363
|
throw Error(`no asgard address found for ${swap.input.asset.chain}`);
|
|
720
|
-
if (swap.input.asset.chain ===
|
|
364
|
+
if (swap.input.asset.chain === ETHChain) {
|
|
721
365
|
const params = {
|
|
722
366
|
walletIndex: 0,
|
|
723
367
|
asset: swap.input.asset,
|
|
@@ -728,7 +372,7 @@ class Wallet {
|
|
|
728
372
|
const hash = yield this.ethHelper.sendDeposit(params);
|
|
729
373
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
730
374
|
}
|
|
731
|
-
else if (swap.input.asset.chain ===
|
|
375
|
+
else if (swap.input.asset.chain === AVAXChain) {
|
|
732
376
|
const params = {
|
|
733
377
|
walletIndex: 0,
|
|
734
378
|
asset: swap.input.asset,
|
|
@@ -837,7 +481,7 @@ class Wallet {
|
|
|
837
481
|
addSavers(assetAmount, memo, toAddress, waitTimeSeconds) {
|
|
838
482
|
return __awaiter(this, void 0, void 0, function* () {
|
|
839
483
|
const assetClient = this.clients[assetAmount.asset.chain];
|
|
840
|
-
if (assetAmount.asset.chain ===
|
|
484
|
+
if (assetAmount.asset.chain === ETHChain) {
|
|
841
485
|
const addParams = {
|
|
842
486
|
wallIndex: 0,
|
|
843
487
|
asset: assetAmount.asset,
|
|
@@ -848,7 +492,7 @@ class Wallet {
|
|
|
848
492
|
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
849
493
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
850
494
|
}
|
|
851
|
-
else if (assetAmount.asset.chain ===
|
|
495
|
+
else if (assetAmount.asset.chain === AVAXChain) {
|
|
852
496
|
const addParams = {
|
|
853
497
|
wallIndex: 0,
|
|
854
498
|
asset: assetAmount.asset,
|
|
@@ -889,7 +533,7 @@ class Wallet {
|
|
|
889
533
|
withdrawSavers(dustAssetAmount, memo, toAddress, waitTimeSeconds) {
|
|
890
534
|
return __awaiter(this, void 0, void 0, function* () {
|
|
891
535
|
const assetClient = this.clients[dustAssetAmount.asset.chain];
|
|
892
|
-
if (dustAssetAmount.asset.chain ===
|
|
536
|
+
if (dustAssetAmount.asset.chain === ETHChain) {
|
|
893
537
|
const addParams = {
|
|
894
538
|
wallIndex: 0,
|
|
895
539
|
asset: dustAssetAmount.asset,
|
|
@@ -900,7 +544,7 @@ class Wallet {
|
|
|
900
544
|
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
901
545
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
902
546
|
}
|
|
903
|
-
else if (dustAssetAmount.asset.chain ===
|
|
547
|
+
else if (dustAssetAmount.asset.chain === AVAXChain) {
|
|
904
548
|
const addParams = {
|
|
905
549
|
wallIndex: 0,
|
|
906
550
|
asset: dustAssetAmount.asset,
|
|
@@ -942,7 +586,7 @@ class Wallet {
|
|
|
942
586
|
*/
|
|
943
587
|
addAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
944
588
|
return __awaiter(this, void 0, void 0, function* () {
|
|
945
|
-
if (params.asset.asset.chain ===
|
|
589
|
+
if (params.asset.asset.chain === ETHChain) {
|
|
946
590
|
const addParams = {
|
|
947
591
|
wallIndex: 0,
|
|
948
592
|
asset: params.asset.asset,
|
|
@@ -953,7 +597,7 @@ class Wallet {
|
|
|
953
597
|
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
954
598
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
955
599
|
}
|
|
956
|
-
else if (params.asset.asset.chain ===
|
|
600
|
+
else if (params.asset.asset.chain === AVAXChain) {
|
|
957
601
|
const addParams = {
|
|
958
602
|
wallIndex: 0,
|
|
959
603
|
asset: params.asset.asset,
|
|
@@ -995,7 +639,7 @@ class Wallet {
|
|
|
995
639
|
*/
|
|
996
640
|
withdrawAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
997
641
|
return __awaiter(this, void 0, void 0, function* () {
|
|
998
|
-
if (params.assetFee.asset.chain ===
|
|
642
|
+
if (params.assetFee.asset.chain === ETHChain) {
|
|
999
643
|
const withdrawParams = {
|
|
1000
644
|
wallIndex: 0,
|
|
1001
645
|
asset: params.assetFee.asset,
|
|
@@ -1007,7 +651,7 @@ class Wallet {
|
|
|
1007
651
|
const hash = yield this.ethHelper.sendDeposit(withdrawParams);
|
|
1008
652
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
1009
653
|
}
|
|
1010
|
-
else if (params.assetFee.asset.chain ===
|
|
654
|
+
else if (params.assetFee.asset.chain === AVAXChain) {
|
|
1011
655
|
const withdrawParams = {
|
|
1012
656
|
wallIndex: 0,
|
|
1013
657
|
asset: params.assetFee.asset,
|
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;
|
|
@@ -435,7 +72,7 @@ class EthHelper {
|
|
|
435
72
|
}
|
|
436
73
|
const address = this.client.getAddress(params.walletIndex);
|
|
437
74
|
const gasPrice = yield this.ethClient.estimateGasPrices();
|
|
438
|
-
if (xchainUtil.eqAsset(params.asset,
|
|
75
|
+
if (xchainUtil.eqAsset(params.asset, xchainEthereum.AssetETH)) {
|
|
439
76
|
//ETH is a simple transfer
|
|
440
77
|
return yield this.client.transfer({
|
|
441
78
|
walletIndex: params.walletIndex || 0,
|
|
@@ -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(),
|
|
@@ -653,7 +297,7 @@ class Wallet {
|
|
|
653
297
|
executeSwap(swap) {
|
|
654
298
|
return __awaiter(this, void 0, void 0, function* () {
|
|
655
299
|
this.validateSwap(swap);
|
|
656
|
-
if (swap.input.asset.chain ===
|
|
300
|
+
if (swap.input.asset.chain === xchainThorchain.THORChain || swap.input.asset.synth) {
|
|
657
301
|
return yield this.swapRuneTo(swap);
|
|
658
302
|
}
|
|
659
303
|
else {
|
|
@@ -667,8 +311,8 @@ class Wallet {
|
|
|
667
311
|
*/
|
|
668
312
|
validateSwap(swap) {
|
|
669
313
|
const errors = [];
|
|
670
|
-
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain ===
|
|
671
|
-
const chain = isThorchainDestinationAsset ?
|
|
314
|
+
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain === xchainThorchain.THORChain;
|
|
315
|
+
const chain = isThorchainDestinationAsset ? xchainThorchain.THORChain : swap.destinationAsset.chain;
|
|
672
316
|
if (!this.clients[chain].validateAddress(swap.destinationAddress)) {
|
|
673
317
|
errors.push(`destinationAddress ${swap.destinationAddress} is not a valid address`);
|
|
674
318
|
}
|
|
@@ -677,7 +321,7 @@ class Wallet {
|
|
|
677
321
|
if (checkAffiliateAddress.length > 4) {
|
|
678
322
|
const affiliateAddress = checkAffiliateAddress[4];
|
|
679
323
|
if (affiliateAddress.length > 0) {
|
|
680
|
-
const isValidThorchainAddress = this.clients[
|
|
324
|
+
const isValidThorchainAddress = this.clients[xchainThorchain.THORChain].validateAddress(affiliateAddress);
|
|
681
325
|
const isValidThorname = this.isThorname(affiliateAddress);
|
|
682
326
|
if (!(isValidThorchainAddress || isValidThorname))
|
|
683
327
|
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
@@ -721,7 +365,7 @@ class Wallet {
|
|
|
721
365
|
const inbound = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[swap.input.asset.chain];
|
|
722
366
|
if (!(inbound === null || inbound === void 0 ? void 0 : inbound.address))
|
|
723
367
|
throw Error(`no asgard address found for ${swap.input.asset.chain}`);
|
|
724
|
-
if (swap.input.asset.chain ===
|
|
368
|
+
if (swap.input.asset.chain === xchainEthereum.ETHChain) {
|
|
725
369
|
const params = {
|
|
726
370
|
walletIndex: 0,
|
|
727
371
|
asset: swap.input.asset,
|
|
@@ -732,7 +376,7 @@ class Wallet {
|
|
|
732
376
|
const hash = yield this.ethHelper.sendDeposit(params);
|
|
733
377
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
734
378
|
}
|
|
735
|
-
else if (swap.input.asset.chain ===
|
|
379
|
+
else if (swap.input.asset.chain === xchainAvax.AVAXChain) {
|
|
736
380
|
const params = {
|
|
737
381
|
walletIndex: 0,
|
|
738
382
|
asset: swap.input.asset,
|
|
@@ -841,7 +485,7 @@ class Wallet {
|
|
|
841
485
|
addSavers(assetAmount, memo, toAddress, waitTimeSeconds) {
|
|
842
486
|
return __awaiter(this, void 0, void 0, function* () {
|
|
843
487
|
const assetClient = this.clients[assetAmount.asset.chain];
|
|
844
|
-
if (assetAmount.asset.chain ===
|
|
488
|
+
if (assetAmount.asset.chain === xchainEthereum.ETHChain) {
|
|
845
489
|
const addParams = {
|
|
846
490
|
wallIndex: 0,
|
|
847
491
|
asset: assetAmount.asset,
|
|
@@ -852,7 +496,7 @@ class Wallet {
|
|
|
852
496
|
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
853
497
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
854
498
|
}
|
|
855
|
-
else if (assetAmount.asset.chain ===
|
|
499
|
+
else if (assetAmount.asset.chain === xchainAvax.AVAXChain) {
|
|
856
500
|
const addParams = {
|
|
857
501
|
wallIndex: 0,
|
|
858
502
|
asset: assetAmount.asset,
|
|
@@ -893,7 +537,7 @@ class Wallet {
|
|
|
893
537
|
withdrawSavers(dustAssetAmount, memo, toAddress, waitTimeSeconds) {
|
|
894
538
|
return __awaiter(this, void 0, void 0, function* () {
|
|
895
539
|
const assetClient = this.clients[dustAssetAmount.asset.chain];
|
|
896
|
-
if (dustAssetAmount.asset.chain ===
|
|
540
|
+
if (dustAssetAmount.asset.chain === xchainEthereum.ETHChain) {
|
|
897
541
|
const addParams = {
|
|
898
542
|
wallIndex: 0,
|
|
899
543
|
asset: dustAssetAmount.asset,
|
|
@@ -904,7 +548,7 @@ class Wallet {
|
|
|
904
548
|
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
905
549
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
906
550
|
}
|
|
907
|
-
else if (dustAssetAmount.asset.chain ===
|
|
551
|
+
else if (dustAssetAmount.asset.chain === xchainAvax.AVAXChain) {
|
|
908
552
|
const addParams = {
|
|
909
553
|
wallIndex: 0,
|
|
910
554
|
asset: dustAssetAmount.asset,
|
|
@@ -946,7 +590,7 @@ class Wallet {
|
|
|
946
590
|
*/
|
|
947
591
|
addAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
948
592
|
return __awaiter(this, void 0, void 0, function* () {
|
|
949
|
-
if (params.asset.asset.chain ===
|
|
593
|
+
if (params.asset.asset.chain === xchainEthereum.ETHChain) {
|
|
950
594
|
const addParams = {
|
|
951
595
|
wallIndex: 0,
|
|
952
596
|
asset: params.asset.asset,
|
|
@@ -957,7 +601,7 @@ class Wallet {
|
|
|
957
601
|
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
958
602
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
959
603
|
}
|
|
960
|
-
else if (params.asset.asset.chain ===
|
|
604
|
+
else if (params.asset.asset.chain === xchainAvax.AVAXChain) {
|
|
961
605
|
const addParams = {
|
|
962
606
|
wallIndex: 0,
|
|
963
607
|
asset: params.asset.asset,
|
|
@@ -999,7 +643,7 @@ class Wallet {
|
|
|
999
643
|
*/
|
|
1000
644
|
withdrawAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
1001
645
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1002
|
-
if (params.assetFee.asset.chain ===
|
|
646
|
+
if (params.assetFee.asset.chain === xchainEthereum.ETHChain) {
|
|
1003
647
|
const withdrawParams = {
|
|
1004
648
|
wallIndex: 0,
|
|
1005
649
|
asset: params.assetFee.asset,
|
|
@@ -1011,7 +655,7 @@ class Wallet {
|
|
|
1011
655
|
const hash = yield this.ethHelper.sendDeposit(withdrawParams);
|
|
1012
656
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
1013
657
|
}
|
|
1014
|
-
else if (params.assetFee.asset.chain ===
|
|
658
|
+
else if (params.assetFee.asset.chain === xchainAvax.AVAXChain) {
|
|
1015
659
|
const withdrawParams = {
|
|
1016
660
|
wallIndex: 0,
|
|
1017
661
|
asset: params.assetFee.asset,
|
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.11",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -37,24 +37,24 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
40
|
-
"@cosmos-client/core": "0.
|
|
40
|
+
"@cosmos-client/core": "0.46.1",
|
|
41
41
|
"@psf/bitcoincashjs-lib": "^4.0.2",
|
|
42
|
-
"@xchainjs/xchain-
|
|
43
|
-
"@xchainjs/xchain-
|
|
44
|
-
"@xchainjs/xchain-
|
|
45
|
-
"@xchainjs/xchain-
|
|
46
|
-
"@xchainjs/xchain-
|
|
42
|
+
"@xchainjs/xchain-avax": "^0.1.3",
|
|
43
|
+
"@xchainjs/xchain-binance": "^5.6.6",
|
|
44
|
+
"@xchainjs/xchain-bitcoin": "^0.20.7",
|
|
45
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.6",
|
|
46
|
+
"@xchainjs/xchain-client": "^0.13.5",
|
|
47
|
+
"@xchainjs/xchain-cosmos": "^0.20.6",
|
|
47
48
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
48
|
-
"@xchainjs/xchain-doge": "^0.5.
|
|
49
|
-
"@xchainjs/xchain-ethereum": "^0.27.
|
|
50
|
-
"@xchainjs/xchain-evm": "^0.1.
|
|
51
|
-
"@xchainjs/xchain-
|
|
52
|
-
"@xchainjs/xchain-litecoin": "^0.10.6",
|
|
49
|
+
"@xchainjs/xchain-doge": "^0.5.6",
|
|
50
|
+
"@xchainjs/xchain-ethereum": "^0.27.6",
|
|
51
|
+
"@xchainjs/xchain-evm": "^0.1.3",
|
|
52
|
+
"@xchainjs/xchain-litecoin": "^0.10.8",
|
|
53
53
|
"@xchainjs/xchain-midgard": "0.3.0",
|
|
54
|
-
"@xchainjs/xchain-thorchain": "^0.27.
|
|
55
|
-
"@xchainjs/xchain-thorchain-query": "^0.1.
|
|
54
|
+
"@xchainjs/xchain-thorchain": "^0.27.7",
|
|
55
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.12",
|
|
56
56
|
"@xchainjs/xchain-thornode": "^0.1.2",
|
|
57
|
-
"@xchainjs/xchain-util": "^0.
|
|
57
|
+
"@xchainjs/xchain-util": "^0.12.0",
|
|
58
58
|
"axios": "^0.25.0",
|
|
59
59
|
"axios-retry": "^3.2.5",
|
|
60
60
|
"bchaddrjs": "^0.5.2",
|
|
@@ -70,24 +70,24 @@
|
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
73
|
-
"@cosmos-client/core": "0.
|
|
73
|
+
"@cosmos-client/core": "0.46.1",
|
|
74
74
|
"@psf/bitcoincashjs-lib": "^4.0.2",
|
|
75
|
-
"@xchainjs/xchain-
|
|
76
|
-
"@xchainjs/xchain-
|
|
77
|
-
"@xchainjs/xchain-
|
|
78
|
-
"@xchainjs/xchain-
|
|
79
|
-
"@xchainjs/xchain-
|
|
75
|
+
"@xchainjs/xchain-avax": "^0.1.3",
|
|
76
|
+
"@xchainjs/xchain-binance": "^5.6.6",
|
|
77
|
+
"@xchainjs/xchain-bitcoin": "^0.20.7",
|
|
78
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.6",
|
|
79
|
+
"@xchainjs/xchain-client": "^0.13.5",
|
|
80
|
+
"@xchainjs/xchain-cosmos": "^0.20.6",
|
|
80
81
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
81
|
-
"@xchainjs/xchain-doge": "^0.5.
|
|
82
|
-
"@xchainjs/xchain-ethereum": "^0.27.
|
|
83
|
-
"@xchainjs/xchain-evm": "^0.1.
|
|
84
|
-
"@xchainjs/xchain-
|
|
85
|
-
"@xchainjs/xchain-
|
|
86
|
-
"@xchainjs/xchain-
|
|
87
|
-
"@xchainjs/xchain-thorchain": "^0.
|
|
88
|
-
"@xchainjs/xchain-
|
|
89
|
-
"@xchainjs/xchain-
|
|
90
|
-
"@xchainjs/xchain-util": "^0.11.0",
|
|
82
|
+
"@xchainjs/xchain-doge": "^0.5.6",
|
|
83
|
+
"@xchainjs/xchain-ethereum": "^0.27.6",
|
|
84
|
+
"@xchainjs/xchain-evm": "^0.1.3",
|
|
85
|
+
"@xchainjs/xchain-litecoin": "^0.10.8",
|
|
86
|
+
"@xchainjs/xchain-midgard": "0.4.1",
|
|
87
|
+
"@xchainjs/xchain-thorchain": "^0.27.7",
|
|
88
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.12",
|
|
89
|
+
"@xchainjs/xchain-thornode": "^0.1.5",
|
|
90
|
+
"@xchainjs/xchain-util": "^0.12.1",
|
|
91
91
|
"axios": "^0.25.0",
|
|
92
92
|
"axios-retry": "^3.2.5",
|
|
93
93
|
"bchaddrjs": "^0.5.2",
|