@xchainjs/xchain-thorchain-amm 0.8.21 → 0.8.22
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/lib/index.d.ts +15 -0
- package/lib/index.esm.js +213 -136
- package/lib/index.js +213 -136
- package/lib/thorchain-amm.d.ts +58 -57
- package/lib/types.d.ts +33 -0
- package/lib/wallet.d.ts +91 -63
- package/package.json +4 -6
package/lib/index.esm.js
CHANGED
|
@@ -145,9 +145,9 @@ class Wallet {
|
|
|
145
145
|
/**
|
|
146
146
|
* Contructor to create a Wallet
|
|
147
147
|
*
|
|
148
|
-
* @param phrase -
|
|
149
|
-
* @param thorchainCache -
|
|
150
|
-
* @param chainConfigs -
|
|
148
|
+
* @param phrase - Mnemonic phrase
|
|
149
|
+
* @param thorchainCache - An instance of the ThorchainCache (could be pointing to stagenet,testnet,mainnet)
|
|
150
|
+
* @param chainConfigs - Configuration settings for different blockchain chains
|
|
151
151
|
* @returns Wallet
|
|
152
152
|
*/
|
|
153
153
|
constructor(phrase, thorchainQuery, chainConfigs = {}) {
|
|
@@ -173,20 +173,24 @@ class Wallet {
|
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
|
-
* Fetch
|
|
177
|
-
*
|
|
178
|
-
* @returns AllBalances[]
|
|
176
|
+
* Fetch the balance of all the chains.
|
|
177
|
+
* @returns An array of AllBalances objects containing balance information for all chains
|
|
179
178
|
*/
|
|
180
179
|
getAllBalances() {
|
|
181
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
182
181
|
const allBalances = [];
|
|
182
|
+
// Loop through each chain's client and fetch the balance
|
|
183
183
|
for (const [chain, client] of Object.entries(this.clients)) {
|
|
184
|
+
// Get the wallet address for the current chain
|
|
184
185
|
const address = yield client.getAddressAsync(0);
|
|
185
186
|
try {
|
|
187
|
+
// Fetch the balance for the wallet address
|
|
186
188
|
const balances = yield client.getBalance(address);
|
|
189
|
+
// Push the balance information to the allBalances array
|
|
187
190
|
allBalances.push({ chain, address, balances });
|
|
188
191
|
}
|
|
189
192
|
catch (err) {
|
|
193
|
+
// If an error occurs, push an error message to the allBalances array
|
|
190
194
|
allBalances.push({ chain, address, balances: err.message });
|
|
191
195
|
}
|
|
192
196
|
}
|
|
@@ -194,15 +198,16 @@ class Wallet {
|
|
|
194
198
|
});
|
|
195
199
|
}
|
|
196
200
|
/**
|
|
197
|
-
* Executes a
|
|
198
|
-
*
|
|
199
|
-
* @
|
|
200
|
-
* @returns transaction details and explorer url
|
|
201
|
+
* Executes a swap using the provided swap details.
|
|
202
|
+
* @param swap Object containing details required for the swap
|
|
203
|
+
* @returns Object containing transaction details and explorer URL
|
|
201
204
|
* @see ThorchainAMM.doSwap()
|
|
202
205
|
*/
|
|
203
206
|
executeSwap(swap) {
|
|
204
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
// Validate the swap details
|
|
205
209
|
yield this.validateSwap(swap);
|
|
210
|
+
// Determine whether the destination asset is THORChain or a synthetic asset
|
|
206
211
|
if (swap.input.asset.chain === THORChain || swap.input.asset.synth) {
|
|
207
212
|
return yield this.swapRuneTo(swap);
|
|
208
213
|
}
|
|
@@ -211,20 +216,20 @@ class Wallet {
|
|
|
211
216
|
}
|
|
212
217
|
});
|
|
213
218
|
}
|
|
214
|
-
/**
|
|
215
|
-
*
|
|
216
|
-
* @
|
|
219
|
+
/** Validates the swap object details.
|
|
220
|
+
* @param swap - Object containing swap parameters
|
|
221
|
+
* @returns An array of validation errors
|
|
217
222
|
*/
|
|
218
223
|
validateSwap(swap) {
|
|
219
224
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
225
|
const errors = [];
|
|
221
226
|
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain === THORChain;
|
|
222
227
|
const chain = isThorchainDestinationAsset ? THORChain : swap.destinationAsset.chain;
|
|
223
|
-
//
|
|
228
|
+
// Check if the destination address is valid
|
|
224
229
|
if (swap.destinationAddress && !this.clients[chain].validateAddress(swap.destinationAddress)) {
|
|
225
230
|
errors.push(`destinationAddress ${swap.destinationAddress} is not a valid address`);
|
|
226
231
|
}
|
|
227
|
-
// Affiliate address should be
|
|
232
|
+
// Affiliate address should be a valid THOR address or THORName
|
|
228
233
|
const checkAffiliateAddress = swap.memo.split(':');
|
|
229
234
|
if (checkAffiliateAddress.length > 4) {
|
|
230
235
|
const affiliateAddress = checkAffiliateAddress[4];
|
|
@@ -235,9 +240,10 @@ class Wallet {
|
|
|
235
240
|
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
236
241
|
}
|
|
237
242
|
}
|
|
238
|
-
//
|
|
243
|
+
// If input asset is synthetic, return errors
|
|
239
244
|
if (swap.input.asset.synth)
|
|
240
245
|
return errors;
|
|
246
|
+
// Check if the input asset is an ERC20 asset and whether the router has been approved to spend this amount
|
|
241
247
|
if (this.isERC20Asset(swap.input.asset)) {
|
|
242
248
|
const isApprovedResult = yield this.evmHelpers[swap.input.asset.chain].isTCRouterApprovedToSpend(swap.input.asset, swap.input.baseAmount, swap.walletIndex);
|
|
243
249
|
if (!isApprovedResult) {
|
|
@@ -247,16 +253,21 @@ class Wallet {
|
|
|
247
253
|
return errors;
|
|
248
254
|
});
|
|
249
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Checks if a given string is a valid THORName.
|
|
258
|
+
* @param name - Name to check
|
|
259
|
+
* @returns Boolean indicating whether the name is a valid THORName
|
|
260
|
+
*/
|
|
250
261
|
isThorname(name) {
|
|
251
262
|
return __awaiter(this, void 0, void 0, function* () {
|
|
252
263
|
const thornameDetails = yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(name); // Update when thorchainCache expose getTHORNameDetails method
|
|
253
264
|
return thornameDetails !== undefined;
|
|
254
265
|
});
|
|
255
266
|
}
|
|
256
|
-
/**
|
|
267
|
+
/** Swaps assets from RUNE to another asset.
|
|
257
268
|
*
|
|
258
|
-
* @param swap -
|
|
259
|
-
* @returns -
|
|
269
|
+
* @param swap - Swap details parameter
|
|
270
|
+
* @returns - Object containing transaction details and explorer URL
|
|
260
271
|
*/
|
|
261
272
|
swapRuneTo(swap) {
|
|
262
273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -269,17 +280,19 @@ class Wallet {
|
|
|
269
280
|
return { hash, url: this.clients.THOR.getExplorerTxUrl(hash) };
|
|
270
281
|
});
|
|
271
282
|
}
|
|
272
|
-
/**
|
|
273
|
-
*
|
|
274
|
-
* @
|
|
275
|
-
* @returns - TxSubmitted object
|
|
283
|
+
/** Swaps assets that are not RUNE.
|
|
284
|
+
* @param swap - swap details object
|
|
285
|
+
* @returns - Object containing transaction details and explorer URL
|
|
276
286
|
*/
|
|
277
287
|
swapNonRune(swap) {
|
|
278
288
|
return __awaiter(this, void 0, void 0, function* () {
|
|
279
289
|
const client = this.clients[swap.input.asset.chain];
|
|
290
|
+
// Retrieve inbound details for the asset's chain
|
|
280
291
|
const inbound = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[swap.input.asset.chain];
|
|
292
|
+
// Check if there is an inbound address for the asset's chain
|
|
281
293
|
if (!(inbound === null || inbound === void 0 ? void 0 : inbound.address))
|
|
282
294
|
throw Error(`no asgard address found for ${swap.input.asset.chain}`);
|
|
295
|
+
// Handle swaps for EVM chains
|
|
283
296
|
if (this.isEVMChain(swap.input.asset)) {
|
|
284
297
|
const params = {
|
|
285
298
|
walletIndex: 0,
|
|
@@ -292,6 +305,7 @@ class Wallet {
|
|
|
292
305
|
return { hash, url: client.getExplorerTxUrl(hash) };
|
|
293
306
|
}
|
|
294
307
|
else {
|
|
308
|
+
// Handle swaps for non-EVM chains
|
|
295
309
|
const params = {
|
|
296
310
|
walletIndex: 0,
|
|
297
311
|
asset: swap.input.asset,
|
|
@@ -304,10 +318,10 @@ class Wallet {
|
|
|
304
318
|
}
|
|
305
319
|
});
|
|
306
320
|
}
|
|
307
|
-
/**
|
|
321
|
+
/** Handles adding liquidity to the pool.
|
|
308
322
|
* BASED OFF https://dev.thorchain.or›g/thorchain-dev/network/memos
|
|
309
|
-
* @param params
|
|
310
|
-
* @returns transaction details submitted
|
|
323
|
+
* @param params Input parameters for adding liquidity
|
|
324
|
+
* @returns An array of transaction details submitted
|
|
311
325
|
*/
|
|
312
326
|
addLiquidity(params) {
|
|
313
327
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -320,7 +334,7 @@ class Wallet {
|
|
|
320
334
|
// const waitTimeSeconds = params.waitTimeSeconds
|
|
321
335
|
let constructedMemo = '';
|
|
322
336
|
const txSubmitted = [];
|
|
323
|
-
//
|
|
337
|
+
// Symmetrical add
|
|
324
338
|
if (params.asset.assetAmount.gt(0) && params.rune.assetAmount.gt(0)) {
|
|
325
339
|
constructedMemo = `+:${params.assetPool}:${addressRune}`;
|
|
326
340
|
txSubmitted.push(yield this.addAssetLP(params, constructedMemo, assetClient, inboundAsgard));
|
|
@@ -329,23 +343,22 @@ class Wallet {
|
|
|
329
343
|
return txSubmitted;
|
|
330
344
|
}
|
|
331
345
|
else if (params.asset.assetAmount.gt(0) && params.rune.assetAmount.eq(0)) {
|
|
332
|
-
//
|
|
346
|
+
// Asymmetrical asset only
|
|
333
347
|
constructedMemo = `+:${params.assetPool}`;
|
|
334
348
|
txSubmitted.push(yield this.addAssetLP(params, constructedMemo, assetClient, inboundAsgard));
|
|
335
349
|
return txSubmitted;
|
|
336
350
|
}
|
|
337
351
|
else {
|
|
338
|
-
//
|
|
352
|
+
// Asymmetrical rune only
|
|
339
353
|
constructedMemo = `+:${params.assetPool}`;
|
|
340
354
|
txSubmitted.push(yield this.addRuneLP(params, constructedMemo, thorchainClient));
|
|
341
355
|
return txSubmitted;
|
|
342
356
|
}
|
|
343
357
|
});
|
|
344
358
|
}
|
|
345
|
-
/**
|
|
346
|
-
*
|
|
347
|
-
* @
|
|
348
|
-
* @returns object with tx response, url and wait time in seconds
|
|
359
|
+
/** Handles withdrawing liquidity from the pool.
|
|
360
|
+
* @param params - Parameters required for liquidity position
|
|
361
|
+
* @returns Object with transaction response, URL, and wait time in seconds
|
|
349
362
|
*/
|
|
350
363
|
withdrawLiquidity(params) {
|
|
351
364
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -365,13 +378,13 @@ class Wallet {
|
|
|
365
378
|
return txSubmitted;
|
|
366
379
|
}
|
|
367
380
|
else if (params.assetAddress && !params.runeAddress) {
|
|
368
|
-
//
|
|
381
|
+
// Asymmetrical asset only
|
|
369
382
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
370
383
|
txSubmitted.push(yield this.withdrawAssetLP(params, constructedMemo, assetClient, inboundAsgard));
|
|
371
384
|
return txSubmitted;
|
|
372
385
|
}
|
|
373
386
|
else {
|
|
374
|
-
//
|
|
387
|
+
// Asymmetrical rune only
|
|
375
388
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
376
389
|
txSubmitted.push(yield this.withdrawRuneLP(params, constructedMemo, thorchainClient));
|
|
377
390
|
return txSubmitted;
|
|
@@ -379,15 +392,16 @@ class Wallet {
|
|
|
379
392
|
});
|
|
380
393
|
}
|
|
381
394
|
/**
|
|
382
|
-
*
|
|
383
|
-
* @param assetAmount - amount to add
|
|
384
|
-
* @param memo - memo required
|
|
395
|
+
* Adds funds to a savers account.
|
|
396
|
+
* @param assetAmount - The amount of assets to add.
|
|
397
|
+
* @param memo - The memo required for the transaction.
|
|
385
398
|
* @param waitTimeSeconds - expected wait for the transaction to be processed
|
|
386
|
-
* @returns
|
|
399
|
+
* @returns An object containing transaction details and explorer URL.
|
|
387
400
|
*/
|
|
388
401
|
addSavers(assetAmount, memo, toAddress) {
|
|
389
402
|
return __awaiter(this, void 0, void 0, function* () {
|
|
390
403
|
const assetClient = this.clients[assetAmount.asset.chain];
|
|
404
|
+
// Handle EVM chains
|
|
391
405
|
if (this.isEVMChain(assetAmount.asset)) {
|
|
392
406
|
const addParams = {
|
|
393
407
|
wallIndex: 0,
|
|
@@ -419,7 +433,7 @@ class Wallet {
|
|
|
419
433
|
return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()) };
|
|
420
434
|
}
|
|
421
435
|
}
|
|
422
|
-
else {
|
|
436
|
+
else { // Handle other chains
|
|
423
437
|
const addParams = {
|
|
424
438
|
wallIndex: 0,
|
|
425
439
|
asset: assetAmount.asset,
|
|
@@ -439,15 +453,16 @@ class Wallet {
|
|
|
439
453
|
});
|
|
440
454
|
}
|
|
441
455
|
/**
|
|
442
|
-
*
|
|
443
|
-
* @param assetAmount - amount to withdraw
|
|
444
|
-
* @param memo - memo required
|
|
456
|
+
* Withdraws funds from a savers account.
|
|
457
|
+
* @param assetAmount - The amount of assets to withdraw.
|
|
458
|
+
* @param memo - The memo required for the transaction.
|
|
445
459
|
* @param waitTimeSeconds - expected wait for the transaction to be processed
|
|
446
|
-
* @returns
|
|
460
|
+
* @returns An object containing transaction details and explorer URL.
|
|
447
461
|
*/
|
|
448
462
|
withdrawSavers(assetAmount, memo, toAddress) {
|
|
449
463
|
return __awaiter(this, void 0, void 0, function* () {
|
|
450
464
|
const assetClient = this.clients[assetAmount.asset.chain];
|
|
465
|
+
// Handle EVM chains
|
|
451
466
|
if (this.isEVMChain(assetAmount.asset)) {
|
|
452
467
|
const addParams = {
|
|
453
468
|
wallIndex: 0,
|
|
@@ -479,7 +494,7 @@ class Wallet {
|
|
|
479
494
|
return { hash, url: yield assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
|
|
480
495
|
}
|
|
481
496
|
}
|
|
482
|
-
else {
|
|
497
|
+
else { // Handle other chains
|
|
483
498
|
const addParams = {
|
|
484
499
|
wallIndex: 0,
|
|
485
500
|
asset: assetAmount.asset,
|
|
@@ -498,9 +513,15 @@ class Wallet {
|
|
|
498
513
|
}
|
|
499
514
|
});
|
|
500
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* Opens a new loan.
|
|
518
|
+
* @param params - Parameters required to open a loan.
|
|
519
|
+
* @returns An object containing transaction details and explorer URL.
|
|
520
|
+
*/
|
|
501
521
|
loanOpen(params) {
|
|
502
522
|
return __awaiter(this, void 0, void 0, function* () {
|
|
503
523
|
const assetClient = this.clients[params.amount.asset.chain];
|
|
524
|
+
// Handle EVM chains
|
|
504
525
|
if (this.isEVMChain(params.amount.asset)) {
|
|
505
526
|
const addParams = {
|
|
506
527
|
wallIndex: 0,
|
|
@@ -532,7 +553,7 @@ class Wallet {
|
|
|
532
553
|
return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
|
|
533
554
|
}
|
|
534
555
|
}
|
|
535
|
-
else {
|
|
556
|
+
else { // Handle other chains
|
|
536
557
|
const addParams = {
|
|
537
558
|
wallIndex: 0,
|
|
538
559
|
asset: params.amount.asset,
|
|
@@ -551,9 +572,15 @@ class Wallet {
|
|
|
551
572
|
}
|
|
552
573
|
});
|
|
553
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* Closes an existing loan.
|
|
577
|
+
* @param params - Parameters required to close a loan.
|
|
578
|
+
* @returns An object containing transaction details and explorer URL.
|
|
579
|
+
*/
|
|
554
580
|
loanClose(params) {
|
|
555
581
|
return __awaiter(this, void 0, void 0, function* () {
|
|
556
582
|
const assetClient = this.clients[params.amount.asset.chain];
|
|
583
|
+
// Handle EVM chains
|
|
557
584
|
if (this.isEVMChain(params.amount.asset)) {
|
|
558
585
|
const addParams = {
|
|
559
586
|
wallIndex: 0,
|
|
@@ -585,7 +612,7 @@ class Wallet {
|
|
|
585
612
|
return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
|
|
586
613
|
}
|
|
587
614
|
}
|
|
588
|
-
else {
|
|
615
|
+
else { // Handle other chains
|
|
589
616
|
const addParams = {
|
|
590
617
|
wallIndex: 0,
|
|
591
618
|
asset: params.amount.asset,
|
|
@@ -604,7 +631,7 @@ class Wallet {
|
|
|
604
631
|
}
|
|
605
632
|
});
|
|
606
633
|
}
|
|
607
|
-
/**
|
|
634
|
+
/**Registers a THORName with default parameters.
|
|
608
635
|
* Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
|
|
609
636
|
* By default owner is getting from wallet
|
|
610
637
|
* @param thorname - Name to register
|
|
@@ -618,13 +645,18 @@ class Wallet {
|
|
|
618
645
|
*/
|
|
619
646
|
registerThorname(params) {
|
|
620
647
|
return __awaiter(this, void 0, void 0, function* () {
|
|
648
|
+
// Obtain the client corresponding to the specified chain or default to BTCChain
|
|
621
649
|
const chainClient = this.clients[params.chain || BTCChain];
|
|
622
650
|
const thorClient = this.clients.THOR;
|
|
651
|
+
// Check if both chainClient and thorClient exist
|
|
623
652
|
if (!chainClient || !thorClient) {
|
|
624
653
|
throw Error('Can not find a wallet client');
|
|
625
654
|
}
|
|
655
|
+
// Estimate the THORName registration fee
|
|
626
656
|
const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || BTCChain, chainAddress: params.chainAddress || (yield chainClient.getAddressAsync()), owner: params.owner || (yield thorClient.getAddressAsync()) }));
|
|
657
|
+
// Cast thorClient to ThorchainClient
|
|
627
658
|
const castedThorClient = thorClient;
|
|
659
|
+
// Deposit the registration fee for the THORName
|
|
628
660
|
const result = yield castedThorClient.deposit({
|
|
629
661
|
asset: thornameEstimation.value.asset,
|
|
630
662
|
amount: thornameEstimation.value.baseAmount,
|
|
@@ -633,7 +665,7 @@ class Wallet {
|
|
|
633
665
|
return result;
|
|
634
666
|
});
|
|
635
667
|
}
|
|
636
|
-
/**
|
|
668
|
+
/**Updates an existing THORName with default parameters.
|
|
637
669
|
* Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
|
|
638
670
|
* By default owner is getting from wallet
|
|
639
671
|
* @param thorname - Name to register
|
|
@@ -646,17 +678,24 @@ class Wallet {
|
|
|
646
678
|
*/
|
|
647
679
|
updateThorname(params) {
|
|
648
680
|
return __awaiter(this, void 0, void 0, function* () {
|
|
681
|
+
// Obtain the client corresponding to the specified chain or default to BTCChain
|
|
649
682
|
const chainClient = this.clients[params.chain || BTCChain];
|
|
650
683
|
const thorClient = this.clients.THOR;
|
|
684
|
+
// Check if both chainClient and thorClient exist
|
|
651
685
|
if (!chainClient || !thorClient) {
|
|
652
686
|
throw Error('Can not find a wallet client');
|
|
653
687
|
}
|
|
688
|
+
// Retrieve details of the existing THORName
|
|
654
689
|
const thornameDetail = yield this.thorchainQuery.getThornameDetails(params.thorname);
|
|
690
|
+
// Verify ownership of the THORName
|
|
655
691
|
if ((thornameDetail === null || thornameDetail === void 0 ? void 0 : thornameDetail.owner) !== (yield thorClient.getAddressAsync())) {
|
|
656
692
|
throw Error('You cannot update a domain that is not yours');
|
|
657
693
|
}
|
|
694
|
+
// Estimate the updated THORName registration fee
|
|
658
695
|
const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || BTCChain, isUpdate: true, preferredAsset: params.preferredAsset || assetFromString(thornameDetail.preferredAsset), chainAddress: params.chainAddress || (yield chainClient.getAddressAsync()) }));
|
|
696
|
+
// Cast thorClient to ThorchainClient
|
|
659
697
|
const castedThorClient = thorClient;
|
|
698
|
+
// Deposit the updated registration fee for the THORName
|
|
660
699
|
const result = yield castedThorClient.deposit({
|
|
661
700
|
asset: thornameEstimation.value.asset,
|
|
662
701
|
amount: thornameEstimation.value.baseAmount,
|
|
@@ -665,18 +704,19 @@ class Wallet {
|
|
|
665
704
|
return result;
|
|
666
705
|
});
|
|
667
706
|
}
|
|
668
|
-
/**
|
|
669
|
-
*
|
|
670
|
-
* @param
|
|
671
|
-
* @param
|
|
672
|
-
* @param
|
|
673
|
-
* @param
|
|
674
|
-
* @
|
|
675
|
-
* @returns - tx object
|
|
707
|
+
/** Handles liquidity addition for non-RUNE assets.
|
|
708
|
+
* @param params - Parameters for add liquidity
|
|
709
|
+
* @param constructedMemo - Memo needed for thorchain
|
|
710
|
+
* @param waitTimeSeconds - Wait time for the tx to be confirmed
|
|
711
|
+
* @param assetClient - XChainClient for the asset.
|
|
712
|
+
* @param inboundAsgard - Inbound Asgard address for the LP.
|
|
713
|
+
* @returns - Transaction object.
|
|
676
714
|
*/
|
|
677
715
|
addAssetLP(params, constructedMemo, assetClient, inboundAsgard) {
|
|
678
716
|
return __awaiter(this, void 0, void 0, function* () {
|
|
717
|
+
// Handle EVM chains
|
|
679
718
|
if (this.isEVMChain(params.asset.asset)) {
|
|
719
|
+
// Prepare parameters for sending a deposit on EVM chains
|
|
680
720
|
const addParams = {
|
|
681
721
|
wallIndex: 0,
|
|
682
722
|
asset: params.asset.asset,
|
|
@@ -688,8 +728,10 @@ class Wallet {
|
|
|
688
728
|
const hash = yield evmHelper.sendDeposit(addParams);
|
|
689
729
|
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
690
730
|
}
|
|
691
|
-
else if (this.isUTXOChain(params.asset.asset)) {
|
|
731
|
+
else if (this.isUTXOChain(params.asset.asset)) { // Handle UTXO chains
|
|
732
|
+
// Get fee rates for UTXO chains
|
|
692
733
|
const feeRates = yield assetClient.getFeeRates(Protocol.THORCHAIN);
|
|
734
|
+
// Prepare parameters for transferring assets on UTXO chains
|
|
693
735
|
const addParams = {
|
|
694
736
|
wallIndex: 0,
|
|
695
737
|
asset: params.asset.asset,
|
|
@@ -699,15 +741,18 @@ class Wallet {
|
|
|
699
741
|
feeRate: feeRates.fast,
|
|
700
742
|
};
|
|
701
743
|
try {
|
|
744
|
+
// Transfer assets with the provided parameters
|
|
702
745
|
const hash = yield assetClient.transfer(addParams);
|
|
703
746
|
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
704
747
|
}
|
|
705
748
|
catch (err) {
|
|
749
|
+
// If an error occurs during the transfer, handle it and return the error message along with the explorer URL of the asset client's address
|
|
706
750
|
const hash = JSON.stringify(err);
|
|
707
751
|
return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
|
|
708
752
|
}
|
|
709
753
|
}
|
|
710
|
-
else {
|
|
754
|
+
else { // Handle other chains
|
|
755
|
+
// Prepare parameters for transferring assets on other chains
|
|
711
756
|
const addParams = {
|
|
712
757
|
wallIndex: 0,
|
|
713
758
|
asset: params.asset.asset,
|
|
@@ -716,28 +761,31 @@ class Wallet {
|
|
|
716
761
|
memo: constructedMemo,
|
|
717
762
|
};
|
|
718
763
|
try {
|
|
764
|
+
// Transfer assets with the provided parameters
|
|
719
765
|
const hash = yield assetClient.transfer(addParams);
|
|
720
766
|
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
721
767
|
}
|
|
722
768
|
catch (err) {
|
|
769
|
+
// If an error occurs during the transfer, handle it and return the error message along with the explorer URL of the asset client's address
|
|
723
770
|
const hash = JSON.stringify(err);
|
|
724
771
|
return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
|
|
725
772
|
}
|
|
726
773
|
}
|
|
727
774
|
});
|
|
728
775
|
}
|
|
729
|
-
/**
|
|
730
|
-
*
|
|
731
|
-
* @param
|
|
732
|
-
* @param
|
|
733
|
-
* @param
|
|
734
|
-
* @param
|
|
735
|
-
* @
|
|
736
|
-
* @returns - tx object
|
|
776
|
+
/** Handles liquidity withdrawal for non-RUNE assets.
|
|
777
|
+
* @param params - Parameters for withdrawing liquidity.
|
|
778
|
+
* @param constructedMemo - Memo needed for Thorchain execution.
|
|
779
|
+
* @param assetClient - Asset client to call transfer.
|
|
780
|
+
* @param waitTimeSeconds - Return back estimated wait
|
|
781
|
+
* @param inboundAsgard - Destination address.
|
|
782
|
+
* @returns - Transaction object.
|
|
737
783
|
*/
|
|
738
784
|
withdrawAssetLP(params, constructedMemo, assetClient, inboundAsgard) {
|
|
739
785
|
return __awaiter(this, void 0, void 0, function* () {
|
|
786
|
+
// Handle EVM chains
|
|
740
787
|
if (this.isEVMChain(params.assetFee.asset)) {
|
|
788
|
+
// Prepare parameters for sending a deposit on EVM chains
|
|
741
789
|
const withdrawParams = {
|
|
742
790
|
wallIndex: 0,
|
|
743
791
|
asset: params.assetFee.asset,
|
|
@@ -750,7 +798,9 @@ class Wallet {
|
|
|
750
798
|
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
751
799
|
}
|
|
752
800
|
else if (this.isUTXOChain(params.assetFee.asset)) {
|
|
801
|
+
// Handle UTXO chains
|
|
753
802
|
const feeRates = yield assetClient.getFeeRates(Protocol.THORCHAIN);
|
|
803
|
+
// Prepare parameters for transferring assets on UTXO chains
|
|
754
804
|
const withdrawParams = {
|
|
755
805
|
wallIndex: 0,
|
|
756
806
|
asset: params.assetFee.asset,
|
|
@@ -760,15 +810,18 @@ class Wallet {
|
|
|
760
810
|
feeRate: feeRates.fast,
|
|
761
811
|
};
|
|
762
812
|
try {
|
|
813
|
+
// Transfer assets with the provided parameters
|
|
763
814
|
const hash = yield assetClient.transfer(withdrawParams);
|
|
764
815
|
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
765
816
|
}
|
|
766
817
|
catch (err) {
|
|
818
|
+
// If an error occurs during the transfer, handle it and return the error message along with the explorer URL of the asset client's address
|
|
767
819
|
const hash = JSON.stringify(err);
|
|
768
820
|
return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
|
|
769
821
|
}
|
|
770
822
|
}
|
|
771
823
|
else {
|
|
824
|
+
// Handle other chains
|
|
772
825
|
const withdrawParams = {
|
|
773
826
|
wallIndex: 0,
|
|
774
827
|
asset: params.assetFee.asset,
|
|
@@ -777,21 +830,22 @@ class Wallet {
|
|
|
777
830
|
memo: constructedMemo,
|
|
778
831
|
};
|
|
779
832
|
try {
|
|
833
|
+
// Transfer assets with the provided parameters
|
|
780
834
|
const hash = yield assetClient.transfer(withdrawParams);
|
|
781
835
|
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
782
836
|
}
|
|
783
837
|
catch (err) {
|
|
838
|
+
// If an error occurs during the transfer, handle it and return the error message along with the explorer URL of the asset client's address
|
|
784
839
|
const hash = JSON.stringify(err);
|
|
785
840
|
return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
|
|
786
841
|
}
|
|
787
842
|
}
|
|
788
843
|
});
|
|
789
844
|
}
|
|
790
|
-
/**
|
|
791
|
-
*
|
|
792
|
-
* @param
|
|
793
|
-
* @
|
|
794
|
-
* @returns - tx object
|
|
845
|
+
/** Handles liquidity addition for Rune only.
|
|
846
|
+
* @param params - Deposit parameters
|
|
847
|
+
* @param memo - Memo needed to withdraw lp
|
|
848
|
+
* @returns - Transaction object.
|
|
795
849
|
*/
|
|
796
850
|
addRuneLP(params, memo, thorchainClient) {
|
|
797
851
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -805,11 +859,10 @@ class Wallet {
|
|
|
805
859
|
return { hash, url: thorchainClient.getExplorerTxUrl(hash) };
|
|
806
860
|
});
|
|
807
861
|
}
|
|
808
|
-
/**
|
|
809
|
-
*
|
|
810
|
-
* @param
|
|
811
|
-
* @
|
|
812
|
-
* @returns - tx object
|
|
862
|
+
/** Handles liquidity withdrawal for Rune only.
|
|
863
|
+
* @param params - Withdraw parameters
|
|
864
|
+
* @param memo - Memo needed to withdraw lp
|
|
865
|
+
* @returns - Transaction object.
|
|
813
866
|
*/
|
|
814
867
|
withdrawRuneLP(params, memo, thorchainClient) {
|
|
815
868
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -823,19 +876,35 @@ class Wallet {
|
|
|
823
876
|
return { hash, url: thorchainClient.getExplorerTxUrl(hash) };
|
|
824
877
|
});
|
|
825
878
|
}
|
|
879
|
+
/**
|
|
880
|
+
* Checks if an asset is an ERC20 asset.
|
|
881
|
+
* @param asset - Asset to check.
|
|
882
|
+
* @returns - Boolean indicating whether the asset is an ERC20 asset.
|
|
883
|
+
*/
|
|
826
884
|
isERC20Asset(asset) {
|
|
827
885
|
const isGasAsset = ['ETH', 'BSC', 'AVAX'].includes(asset.symbol);
|
|
828
886
|
return this.isEVMChain(asset) && !isGasAsset;
|
|
829
887
|
}
|
|
888
|
+
/**
|
|
889
|
+
* Checks if an asset belongs to an EVM chain.
|
|
890
|
+
* @param asset - Asset to check.
|
|
891
|
+
* @returns - Boolean indicating whether the asset belongs to an EVM chain.
|
|
892
|
+
*/
|
|
830
893
|
isEVMChain(asset) {
|
|
831
894
|
const isEvmChain = ['ETH', 'BSC', 'AVAX'].includes(asset.chain);
|
|
832
895
|
return isEvmChain;
|
|
833
896
|
}
|
|
897
|
+
/**
|
|
898
|
+
* Checks if an asset belongs to a UTXO chain.
|
|
899
|
+
* @param asset - Asset to check.
|
|
900
|
+
* @returns - Boolean indicating whether the asset belongs to a UTXO chain.
|
|
901
|
+
*/
|
|
834
902
|
isUTXOChain(asset) {
|
|
835
903
|
return ['BTC', 'BCH', 'DOGE'].includes(asset.chain);
|
|
836
904
|
}
|
|
837
905
|
}
|
|
838
906
|
|
|
907
|
+
// Create a default ThorchainQuery instance
|
|
839
908
|
const defaultQuery = new ThorchainQuery();
|
|
840
909
|
/**
|
|
841
910
|
* THORChain Class for interacting with THORChain.
|
|
@@ -844,7 +913,7 @@ const defaultQuery = new ThorchainQuery();
|
|
|
844
913
|
*/
|
|
845
914
|
class ThorchainAMM {
|
|
846
915
|
/**
|
|
847
|
-
* Contructor to create a ThorchainAMM
|
|
916
|
+
* Contructor to create a ThorchainAMM instance
|
|
848
917
|
*
|
|
849
918
|
* @param thorchainQuery - an instance of the ThorchainQuery
|
|
850
919
|
* @returns ThorchainAMM
|
|
@@ -853,16 +922,18 @@ class ThorchainAMM {
|
|
|
853
922
|
this.thorchainQuery = thorchainQuery;
|
|
854
923
|
}
|
|
855
924
|
/**
|
|
856
|
-
* Provides
|
|
857
|
-
*
|
|
858
|
-
*
|
|
859
|
-
*
|
|
925
|
+
* * Provides an estimate for a swap based on the given swap details.
|
|
926
|
+
* Checks the parameters for errors before attempting to retrieve the estimate.
|
|
927
|
+
* Utilizes current pool data to calculate inbound and outbound fees, affiliate fees,
|
|
928
|
+
* and the expected wait time for the swap (inbound and outbound).
|
|
929
|
+
* @param params Parameters for the swap, including the amount to swap.
|
|
860
930
|
|
|
861
|
-
* @returns The
|
|
931
|
+
* @returns The estimated swap details.
|
|
862
932
|
*/
|
|
863
933
|
estimateSwap({ fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress = '', interfaceID = `555`, affiliateBps = 0, toleranceBps, wallet, walletIndex, }) {
|
|
864
934
|
return __awaiter(this, void 0, void 0, function* () {
|
|
865
935
|
let errors = [];
|
|
936
|
+
// If a wallet is provided, validate the swap parameters
|
|
866
937
|
if (wallet) {
|
|
867
938
|
const params = {
|
|
868
939
|
input: amount,
|
|
@@ -874,6 +945,7 @@ class ThorchainAMM {
|
|
|
874
945
|
};
|
|
875
946
|
errors = yield wallet.validateSwap(params);
|
|
876
947
|
}
|
|
948
|
+
// Get the swap estimate from the ThorchainQuery instance
|
|
877
949
|
const estimate = yield this.thorchainQuery.quoteSwap({
|
|
878
950
|
fromAsset,
|
|
879
951
|
amount,
|
|
@@ -884,25 +956,27 @@ class ThorchainAMM {
|
|
|
884
956
|
affiliateBps,
|
|
885
957
|
toleranceBps,
|
|
886
958
|
});
|
|
959
|
+
// Add any validation errors to the estimate
|
|
887
960
|
estimate.txEstimate.errors.push(...errors);
|
|
888
961
|
estimate.txEstimate.canSwap = errors.length == 0;
|
|
889
962
|
return estimate;
|
|
890
963
|
});
|
|
891
964
|
}
|
|
892
965
|
/**
|
|
893
|
-
* Conducts a swap with the given inputs.
|
|
966
|
+
* Conducts a swap with the given inputs. This method should be called after estimateSwap() to ensure the swap is valid.
|
|
894
967
|
*
|
|
895
|
-
* @param wallet - wallet to use
|
|
896
|
-
* @param params - swap
|
|
897
|
-
* @returns {SwapSubmitted} -
|
|
968
|
+
* @param wallet - The wallet to use for the swap.
|
|
969
|
+
* @param params - The swap parameters.
|
|
970
|
+
* @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
|
|
898
971
|
*/
|
|
899
972
|
doSwap(wallet, params) {
|
|
900
973
|
return __awaiter(this, void 0, void 0, function* () {
|
|
901
|
-
//
|
|
974
|
+
// Retrieve swap details from ThorchainQuery to ensure validity
|
|
902
975
|
const txDetails = yield this.thorchainQuery.quoteSwap(params);
|
|
903
976
|
if (!txDetails.txEstimate.canSwap) {
|
|
904
977
|
throw Error(txDetails.txEstimate.errors.join('\n'));
|
|
905
978
|
}
|
|
979
|
+
// Execute the swap using the provided wallet
|
|
906
980
|
return yield wallet.executeSwap({
|
|
907
981
|
input: params.amount,
|
|
908
982
|
destinationAsset: params.destinationAsset,
|
|
@@ -914,19 +988,19 @@ class ThorchainAMM {
|
|
|
914
988
|
});
|
|
915
989
|
}
|
|
916
990
|
/**
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
991
|
+
* Wraps the estimate from ThorchainQuery for adding liquidity.
|
|
992
|
+
* @param params - The parameters for estimating adding liquidity.
|
|
993
|
+
* @returns - The estimated liquidity addition object.
|
|
994
|
+
*/
|
|
921
995
|
estimateAddLiquidity(params) {
|
|
922
996
|
return __awaiter(this, void 0, void 0, function* () {
|
|
923
997
|
return yield this.thorchainQuery.estimateAddLP(params);
|
|
924
998
|
});
|
|
925
999
|
}
|
|
926
1000
|
/**
|
|
927
|
-
* Wraps estimate
|
|
928
|
-
* @param params -
|
|
929
|
-
* @returns -
|
|
1001
|
+
* Wraps the estimate from ThorchainQuery for withdrawing liquidity.
|
|
1002
|
+
* @param params - The parameters for estimating withdrawing liquidity.
|
|
1003
|
+
* @returns - The estimated liquidity withdrawal object.
|
|
930
1004
|
*/
|
|
931
1005
|
estimateWithdrawLiquidity(params) {
|
|
932
1006
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -934,9 +1008,9 @@ class ThorchainAMM {
|
|
|
934
1008
|
});
|
|
935
1009
|
}
|
|
936
1010
|
/**
|
|
937
|
-
*
|
|
938
|
-
* @param wallet -
|
|
939
|
-
* @param params -
|
|
1011
|
+
* If there is no existing liquidity position, it is created automatically.
|
|
1012
|
+
* @param wallet - Wallet class
|
|
1013
|
+
* @param params - Liquidity parameter
|
|
940
1014
|
* @returns
|
|
941
1015
|
*/
|
|
942
1016
|
addLiquidityPosition(wallet, params) {
|
|
@@ -954,14 +1028,14 @@ class ThorchainAMM {
|
|
|
954
1028
|
});
|
|
955
1029
|
}
|
|
956
1030
|
/**
|
|
957
|
-
*
|
|
958
|
-
* @param params -
|
|
959
|
-
* @param wallet -
|
|
960
|
-
* @return
|
|
1031
|
+
* Withdraws liquidity from a position.
|
|
1032
|
+
* @param params - The wallet to perform the transaction.
|
|
1033
|
+
* @param wallet - The parameters for withdrawing liquidity.
|
|
1034
|
+
* @return - The array of transaction submissions.
|
|
961
1035
|
*/
|
|
962
1036
|
withdrawLiquidityPosition(wallet, params) {
|
|
963
1037
|
return __awaiter(this, void 0, void 0, function* () {
|
|
964
|
-
// Caution Dust Limits: BTC,BCH,LTC chains 10k sats; DOGE 1m Sats; ETH 0 wei; THOR 0 RUNE.
|
|
1038
|
+
// Caution Dust Limits: BTC, BCH, LTC chains: 10k sats; DOGE: 1m Sats; ETH: 0 wei; THOR: 0 RUNE.
|
|
965
1039
|
const withdrawParams = yield this.thorchainQuery.estimateWithdrawLP(params);
|
|
966
1040
|
return yield wallet.withdrawLiquidity({
|
|
967
1041
|
assetFee: withdrawParams.inbound.fees.asset,
|
|
@@ -975,9 +1049,9 @@ class ThorchainAMM {
|
|
|
975
1049
|
});
|
|
976
1050
|
}
|
|
977
1051
|
/**
|
|
978
|
-
*
|
|
979
|
-
* @param addAssetAmount
|
|
980
|
-
* @returns
|
|
1052
|
+
* Estimates adding to a saver.
|
|
1053
|
+
* @param addAssetAmount The amount to add to the saver.
|
|
1054
|
+
* @returns The estimated addition to the saver object.
|
|
981
1055
|
*/
|
|
982
1056
|
estimateAddSaver(addAssetAmount) {
|
|
983
1057
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -985,9 +1059,9 @@ class ThorchainAMM {
|
|
|
985
1059
|
});
|
|
986
1060
|
}
|
|
987
1061
|
/**
|
|
988
|
-
*
|
|
989
|
-
* @param withdrawParams
|
|
990
|
-
* @returns
|
|
1062
|
+
* Estimates withdrawing from a saver.
|
|
1063
|
+
* @param withdrawParams The parameters for withdrawing from the saver.
|
|
1064
|
+
* @returns The estimated withdrawal from the saver object.
|
|
991
1065
|
*/
|
|
992
1066
|
estimateWithdrawSaver(withdrawParams) {
|
|
993
1067
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -995,9 +1069,9 @@ class ThorchainAMM {
|
|
|
995
1069
|
});
|
|
996
1070
|
}
|
|
997
1071
|
/**
|
|
998
|
-
*
|
|
999
|
-
* @param getsaver
|
|
1000
|
-
* @returns
|
|
1072
|
+
* Retrieves the position of a saver.
|
|
1073
|
+
* @param getsaver The parameters to retrieve the saver position.
|
|
1074
|
+
* @returns The saver position object.
|
|
1001
1075
|
*/
|
|
1002
1076
|
getSaverPosition(getsaver) {
|
|
1003
1077
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1005,10 +1079,10 @@ class ThorchainAMM {
|
|
|
1005
1079
|
});
|
|
1006
1080
|
}
|
|
1007
1081
|
/**
|
|
1008
|
-
*
|
|
1082
|
+
* Adds assets to a saver.
|
|
1009
1083
|
* @param wallet - wallet needed to execute tx
|
|
1010
|
-
* @param addAssetAmount -
|
|
1011
|
-
* @returns - submitted
|
|
1084
|
+
* @param addAssetAmount - The amount to add to the saver.
|
|
1085
|
+
* @returns - The submitted transaction.
|
|
1012
1086
|
*/
|
|
1013
1087
|
addSaver(wallet, addAssetAmount) {
|
|
1014
1088
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1019,10 +1093,10 @@ class ThorchainAMM {
|
|
|
1019
1093
|
});
|
|
1020
1094
|
}
|
|
1021
1095
|
/**
|
|
1022
|
-
*
|
|
1023
|
-
* @param wallet - wallet to
|
|
1024
|
-
* @param withdrawParams -
|
|
1025
|
-
* @returns
|
|
1096
|
+
* Withdraws assets from a saver.
|
|
1097
|
+
* @param wallet - The wallet to perform the transaction.
|
|
1098
|
+
* @param withdrawParams - The parameters for withdrawing from the saver.
|
|
1099
|
+
* @returns The submitted transaction.
|
|
1026
1100
|
*/
|
|
1027
1101
|
withdrawSaver(wallet, withdrawParams) {
|
|
1028
1102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1033,9 +1107,9 @@ class ThorchainAMM {
|
|
|
1033
1107
|
});
|
|
1034
1108
|
}
|
|
1035
1109
|
/**
|
|
1036
|
-
*
|
|
1037
|
-
* @param loanOpenParams
|
|
1038
|
-
* @returns
|
|
1110
|
+
* Retrieves a quote for opening a loan.
|
|
1111
|
+
* @param loanOpenParams The parameters for opening the loan.
|
|
1112
|
+
* @returns The quote for opening the loan.
|
|
1039
1113
|
*/
|
|
1040
1114
|
getLoanQuoteOpen(loanOpenParams) {
|
|
1041
1115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1043,9 +1117,9 @@ class ThorchainAMM {
|
|
|
1043
1117
|
});
|
|
1044
1118
|
}
|
|
1045
1119
|
/**
|
|
1046
|
-
*
|
|
1047
|
-
* @param loanCloseParams
|
|
1048
|
-
* @returns
|
|
1120
|
+
* Retrieves a quote for closing a loan.
|
|
1121
|
+
* @param loanCloseParams The parameters for closing the loan.
|
|
1122
|
+
* @returns The quote for closing the loan.
|
|
1049
1123
|
*/
|
|
1050
1124
|
getLoanQuoteClose(loanCloseParams) {
|
|
1051
1125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1053,10 +1127,10 @@ class ThorchainAMM {
|
|
|
1053
1127
|
});
|
|
1054
1128
|
}
|
|
1055
1129
|
/**
|
|
1056
|
-
*
|
|
1057
|
-
* @param wallet - wallet
|
|
1058
|
-
* @param loanOpenParams -
|
|
1059
|
-
* @returns - submitted
|
|
1130
|
+
* Opens a loan.
|
|
1131
|
+
* @param wallet - The wallet to perform the transaction.
|
|
1132
|
+
* @param loanOpenParams - The parameters for opening the loan.
|
|
1133
|
+
* @returns - The submitted transaction.
|
|
1060
1134
|
*/
|
|
1061
1135
|
addLoan(wallet, loanOpenParams) {
|
|
1062
1136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1071,16 +1145,19 @@ class ThorchainAMM {
|
|
|
1071
1145
|
});
|
|
1072
1146
|
}
|
|
1073
1147
|
/**
|
|
1074
|
-
*
|
|
1075
|
-
* @param wallet - wallet to
|
|
1076
|
-
* @param loanCloseParams -
|
|
1077
|
-
* @returns
|
|
1148
|
+
* Withdraws assets from a loan.
|
|
1149
|
+
* @param wallet - The wallet to perform the transaction.
|
|
1150
|
+
* @param loanCloseParams - The parameters for withdrawing from the loan.
|
|
1151
|
+
* @returns The submitted transaction.
|
|
1078
1152
|
*/
|
|
1079
1153
|
withdrawLoan(wallet, loanCloseParams) {
|
|
1080
1154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1155
|
+
// Retrieves the quote for closing the loan
|
|
1081
1156
|
const withdrawLoan = yield this.thorchainQuery.getLoanQuoteClose(loanCloseParams);
|
|
1157
|
+
// Checks if there are any errors in the quote
|
|
1082
1158
|
if (withdrawLoan.errors.length > 0)
|
|
1083
1159
|
throw Error(`${withdrawLoan.errors}`);
|
|
1160
|
+
// Executes the loan close transaction
|
|
1084
1161
|
return yield wallet.loanClose({
|
|
1085
1162
|
memo: `${withdrawLoan.memo}`,
|
|
1086
1163
|
amount: loanCloseParams.amount,
|
|
@@ -1089,9 +1166,9 @@ class ThorchainAMM {
|
|
|
1089
1166
|
});
|
|
1090
1167
|
}
|
|
1091
1168
|
/**
|
|
1092
|
-
*
|
|
1093
|
-
* @param address - address
|
|
1094
|
-
* @returns
|
|
1169
|
+
* Retrieves all Thornames and their associated data owned by an address.
|
|
1170
|
+
* @param address - The address to retrieve Thornames for.
|
|
1171
|
+
* @returns The Thornames data.
|
|
1095
1172
|
*/
|
|
1096
1173
|
getThornamesByAddress(address) {
|
|
1097
1174
|
return __awaiter(this, void 0, void 0, function* () {
|