@xchainjs/xchain-thorchain-amm 0.7.0 → 0.7.2
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.esm.js +73 -2
- package/lib/index.js +72 -1
- package/lib/thorchain-amm.d.ts +6 -0
- package/lib/types.d.ts +16 -0
- package/lib/wallet.d.ts +26 -1
- package/package.json +3 -3
package/lib/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client as Client$9, defaultAvaxParams } from '@xchainjs/xchain-avax';
|
|
2
2
|
import { Client as Client$5 } from '@xchainjs/xchain-binance';
|
|
3
|
-
import { Client as Client$1 } from '@xchainjs/xchain-bitcoin';
|
|
3
|
+
import { Client as Client$1, BTCChain } from '@xchainjs/xchain-bitcoin';
|
|
4
4
|
import { Client } from '@xchainjs/xchain-bitcoincash';
|
|
5
5
|
import { Client as Client$a, defaultBscParams } from '@xchainjs/xchain-bsc';
|
|
6
6
|
import { FeeOption } from '@xchainjs/xchain-client';
|
|
@@ -10,8 +10,8 @@ import { Client as Client$8, defaultEthParams } from '@xchainjs/xchain-ethereum'
|
|
|
10
10
|
import { Client as Client$3 } from '@xchainjs/xchain-litecoin';
|
|
11
11
|
import { Client as Client$7 } from '@xchainjs/xchain-mayachain';
|
|
12
12
|
import { Client as Client$4, THORChain } from '@xchainjs/xchain-thorchain';
|
|
13
|
+
import { eqAsset, getContractAddressFromAsset, baseAmount, assetFromString } from '@xchainjs/xchain-util';
|
|
13
14
|
import { abi, MAX_APPROVAL } from '@xchainjs/xchain-evm';
|
|
14
|
-
import { eqAsset, getContractAddressFromAsset, baseAmount } from '@xchainjs/xchain-util';
|
|
15
15
|
import { ethers } from 'ethers';
|
|
16
16
|
import { ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
|
|
17
17
|
|
|
@@ -533,6 +533,67 @@ class Wallet {
|
|
|
533
533
|
}
|
|
534
534
|
});
|
|
535
535
|
}
|
|
536
|
+
/**
|
|
537
|
+
* Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
|
|
538
|
+
* By default owner is getting from wallet
|
|
539
|
+
* @param thorname - Name to register
|
|
540
|
+
* @param chain - Chain to add alias
|
|
541
|
+
* @param chainAddress - Address to add to chain alias
|
|
542
|
+
* @param owner - Owner address (rune address)
|
|
543
|
+
* @param preferredAsset - referred asset
|
|
544
|
+
* @param expirity - expirity of the domain in MILLISECONDS
|
|
545
|
+
* @param isUpdate - true only if the domain is already register and you want to update its data
|
|
546
|
+
* @returns memo and value of deposit
|
|
547
|
+
*/
|
|
548
|
+
registerThorname(params) {
|
|
549
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
550
|
+
const chainClient = this.clients[params.chain || BTCChain];
|
|
551
|
+
const thorClient = this.clients.THOR;
|
|
552
|
+
if (!chainClient || !thorClient) {
|
|
553
|
+
throw Error('Can not find a wallet client');
|
|
554
|
+
}
|
|
555
|
+
const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || BTCChain, chainAddress: params.chainAddress || chainClient.getAddress(), owner: params.owner || thorClient.getAddress() }));
|
|
556
|
+
const castedThorClient = thorClient;
|
|
557
|
+
const result = yield castedThorClient.deposit({
|
|
558
|
+
asset: thornameEstimation.value.asset,
|
|
559
|
+
amount: thornameEstimation.value.baseAmount,
|
|
560
|
+
memo: thornameEstimation.memo,
|
|
561
|
+
});
|
|
562
|
+
return result;
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
|
|
567
|
+
* By default owner is getting from wallet
|
|
568
|
+
* @param thorname - Name to register
|
|
569
|
+
* @param chain - Chain to add alias
|
|
570
|
+
* @param chainAddress - Address to add to chain alias
|
|
571
|
+
* @param owner - Owner address (rune address)
|
|
572
|
+
* @param preferredAsset - referred asset
|
|
573
|
+
* @param expirity - expirity of the domain in MILLISECONDS
|
|
574
|
+
* @returns memo and value of deposit
|
|
575
|
+
*/
|
|
576
|
+
updateThorname(params) {
|
|
577
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
578
|
+
const chainClient = this.clients[params.chain || BTCChain];
|
|
579
|
+
const thorClient = this.clients.THOR;
|
|
580
|
+
if (!chainClient || !thorClient) {
|
|
581
|
+
throw Error('Can not find a wallet client');
|
|
582
|
+
}
|
|
583
|
+
const thornameDetail = yield this.thorchainQuery.getThornameDetails(params.thorname);
|
|
584
|
+
if ((thornameDetail === null || thornameDetail === void 0 ? void 0 : thornameDetail.owner) !== thorClient.getAddress()) {
|
|
585
|
+
throw Error('You cannot update a domain that is not yours');
|
|
586
|
+
}
|
|
587
|
+
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 || chainClient.getAddress() }));
|
|
588
|
+
const castedThorClient = thorClient;
|
|
589
|
+
const result = yield castedThorClient.deposit({
|
|
590
|
+
asset: thornameEstimation.value.asset,
|
|
591
|
+
amount: thornameEstimation.value.baseAmount,
|
|
592
|
+
memo: thornameEstimation.memo,
|
|
593
|
+
});
|
|
594
|
+
return result;
|
|
595
|
+
});
|
|
596
|
+
}
|
|
536
597
|
/** Function handles liquidity add for all non rune assets
|
|
537
598
|
*
|
|
538
599
|
* @param params - parameters for add liquidity
|
|
@@ -916,6 +977,16 @@ class ThorchainAMM {
|
|
|
916
977
|
});
|
|
917
978
|
});
|
|
918
979
|
}
|
|
980
|
+
/**
|
|
981
|
+
* Get all Thornames and its data associated owned by an address
|
|
982
|
+
* @param address - address
|
|
983
|
+
* @returns thornames data
|
|
984
|
+
*/
|
|
985
|
+
getThornamesByAddress(address) {
|
|
986
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
987
|
+
return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
|
|
988
|
+
});
|
|
989
|
+
}
|
|
919
990
|
}
|
|
920
991
|
|
|
921
992
|
export { ThorchainAMM, Wallet };
|
package/lib/index.js
CHANGED
|
@@ -14,8 +14,8 @@ var xchainEthereum = require('@xchainjs/xchain-ethereum');
|
|
|
14
14
|
var xchainLitecoin = require('@xchainjs/xchain-litecoin');
|
|
15
15
|
var xchainMayachain = require('@xchainjs/xchain-mayachain');
|
|
16
16
|
var xchainThorchain = require('@xchainjs/xchain-thorchain');
|
|
17
|
-
var xchainEvm = require('@xchainjs/xchain-evm');
|
|
18
17
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
18
|
+
var xchainEvm = require('@xchainjs/xchain-evm');
|
|
19
19
|
var ethers = require('ethers');
|
|
20
20
|
var xchainThorchainQuery = require('@xchainjs/xchain-thorchain-query');
|
|
21
21
|
|
|
@@ -537,6 +537,67 @@ class Wallet {
|
|
|
537
537
|
}
|
|
538
538
|
});
|
|
539
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
|
|
542
|
+
* By default owner is getting from wallet
|
|
543
|
+
* @param thorname - Name to register
|
|
544
|
+
* @param chain - Chain to add alias
|
|
545
|
+
* @param chainAddress - Address to add to chain alias
|
|
546
|
+
* @param owner - Owner address (rune address)
|
|
547
|
+
* @param preferredAsset - referred asset
|
|
548
|
+
* @param expirity - expirity of the domain in MILLISECONDS
|
|
549
|
+
* @param isUpdate - true only if the domain is already register and you want to update its data
|
|
550
|
+
* @returns memo and value of deposit
|
|
551
|
+
*/
|
|
552
|
+
registerThorname(params) {
|
|
553
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
554
|
+
const chainClient = this.clients[params.chain || xchainBitcoin.BTCChain];
|
|
555
|
+
const thorClient = this.clients.THOR;
|
|
556
|
+
if (!chainClient || !thorClient) {
|
|
557
|
+
throw Error('Can not find a wallet client');
|
|
558
|
+
}
|
|
559
|
+
const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || xchainBitcoin.BTCChain, chainAddress: params.chainAddress || chainClient.getAddress(), owner: params.owner || thorClient.getAddress() }));
|
|
560
|
+
const castedThorClient = thorClient;
|
|
561
|
+
const result = yield castedThorClient.deposit({
|
|
562
|
+
asset: thornameEstimation.value.asset,
|
|
563
|
+
amount: thornameEstimation.value.baseAmount,
|
|
564
|
+
memo: thornameEstimation.memo,
|
|
565
|
+
});
|
|
566
|
+
return result;
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
|
|
571
|
+
* By default owner is getting from wallet
|
|
572
|
+
* @param thorname - Name to register
|
|
573
|
+
* @param chain - Chain to add alias
|
|
574
|
+
* @param chainAddress - Address to add to chain alias
|
|
575
|
+
* @param owner - Owner address (rune address)
|
|
576
|
+
* @param preferredAsset - referred asset
|
|
577
|
+
* @param expirity - expirity of the domain in MILLISECONDS
|
|
578
|
+
* @returns memo and value of deposit
|
|
579
|
+
*/
|
|
580
|
+
updateThorname(params) {
|
|
581
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
582
|
+
const chainClient = this.clients[params.chain || xchainBitcoin.BTCChain];
|
|
583
|
+
const thorClient = this.clients.THOR;
|
|
584
|
+
if (!chainClient || !thorClient) {
|
|
585
|
+
throw Error('Can not find a wallet client');
|
|
586
|
+
}
|
|
587
|
+
const thornameDetail = yield this.thorchainQuery.getThornameDetails(params.thorname);
|
|
588
|
+
if ((thornameDetail === null || thornameDetail === void 0 ? void 0 : thornameDetail.owner) !== thorClient.getAddress()) {
|
|
589
|
+
throw Error('You cannot update a domain that is not yours');
|
|
590
|
+
}
|
|
591
|
+
const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || xchainBitcoin.BTCChain, isUpdate: true, preferredAsset: params.preferredAsset || xchainUtil.assetFromString(thornameDetail.preferredAsset), chainAddress: params.chainAddress || chainClient.getAddress() }));
|
|
592
|
+
const castedThorClient = thorClient;
|
|
593
|
+
const result = yield castedThorClient.deposit({
|
|
594
|
+
asset: thornameEstimation.value.asset,
|
|
595
|
+
amount: thornameEstimation.value.baseAmount,
|
|
596
|
+
memo: thornameEstimation.memo,
|
|
597
|
+
});
|
|
598
|
+
return result;
|
|
599
|
+
});
|
|
600
|
+
}
|
|
540
601
|
/** Function handles liquidity add for all non rune assets
|
|
541
602
|
*
|
|
542
603
|
* @param params - parameters for add liquidity
|
|
@@ -920,6 +981,16 @@ class ThorchainAMM {
|
|
|
920
981
|
});
|
|
921
982
|
});
|
|
922
983
|
}
|
|
984
|
+
/**
|
|
985
|
+
* Get all Thornames and its data associated owned by an address
|
|
986
|
+
* @param address - address
|
|
987
|
+
* @returns thornames data
|
|
988
|
+
*/
|
|
989
|
+
getThornamesByAddress(address) {
|
|
990
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
991
|
+
return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
|
|
992
|
+
});
|
|
993
|
+
}
|
|
923
994
|
}
|
|
924
995
|
|
|
925
996
|
exports.ThorchainAMM = ThorchainAMM;
|
package/lib/thorchain-amm.d.ts
CHANGED
|
@@ -120,4 +120,10 @@ export declare class ThorchainAMM {
|
|
|
120
120
|
* @returns
|
|
121
121
|
*/
|
|
122
122
|
withdrawLoan(wallet: Wallet, loanCloseParams: LoanCloseParams): Promise<TxSubmitted>;
|
|
123
|
+
/**
|
|
124
|
+
* Get all Thornames and its data associated owned by an address
|
|
125
|
+
* @param address - address
|
|
126
|
+
* @returns thornames data
|
|
127
|
+
*/
|
|
128
|
+
getThornamesByAddress(address: string): Promise<import("@xchainjs/xchain-midgard/lib").ReverseTHORNames | undefined>;
|
|
123
129
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -56,3 +56,19 @@ export type LoanCloseParams = {
|
|
|
56
56
|
amount: CryptoAmount;
|
|
57
57
|
toAddress: Address;
|
|
58
58
|
};
|
|
59
|
+
export type RegisterThornameParams = {
|
|
60
|
+
thorname: string;
|
|
61
|
+
owner?: string;
|
|
62
|
+
chain?: string;
|
|
63
|
+
chainAddress?: string;
|
|
64
|
+
preferredAsset?: Asset;
|
|
65
|
+
expirity?: Date;
|
|
66
|
+
};
|
|
67
|
+
export type UpdateThornameParams = {
|
|
68
|
+
thorname: string;
|
|
69
|
+
owner?: string;
|
|
70
|
+
chain?: string;
|
|
71
|
+
chainAddress?: string;
|
|
72
|
+
preferredAsset?: Asset;
|
|
73
|
+
expirity?: Date;
|
|
74
|
+
};
|
package/lib/wallet.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Network, XChainClient } from '@xchainjs/xchain-client';
|
|
2
2
|
import { CryptoAmount, ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
|
|
3
3
|
import { Address } from '@xchainjs/xchain-util';
|
|
4
|
-
import { AddLiquidity, AllBalances, ExecuteSwap, LoanCloseParams, LoanOpenParams, TxSubmitted, WithdrawLiquidity } from './types';
|
|
4
|
+
import { AddLiquidity, AllBalances, ExecuteSwap, LoanCloseParams, LoanOpenParams, RegisterThornameParams, TxSubmitted, UpdateThornameParams, WithdrawLiquidity } from './types';
|
|
5
5
|
import { EvmHelper } from './utils/evm-helper';
|
|
6
6
|
export type NodeUrls = Record<Network, string>;
|
|
7
7
|
/**
|
|
@@ -81,6 +81,31 @@ export declare class Wallet {
|
|
|
81
81
|
withdrawSavers(assetAmount: CryptoAmount, memo: string, toAddress: Address): Promise<TxSubmitted>;
|
|
82
82
|
loanOpen(params: LoanOpenParams): Promise<TxSubmitted>;
|
|
83
83
|
loanClose(params: LoanCloseParams): Promise<TxSubmitted>;
|
|
84
|
+
/**
|
|
85
|
+
* Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
|
|
86
|
+
* By default owner is getting from wallet
|
|
87
|
+
* @param thorname - Name to register
|
|
88
|
+
* @param chain - Chain to add alias
|
|
89
|
+
* @param chainAddress - Address to add to chain alias
|
|
90
|
+
* @param owner - Owner address (rune address)
|
|
91
|
+
* @param preferredAsset - referred asset
|
|
92
|
+
* @param expirity - expirity of the domain in MILLISECONDS
|
|
93
|
+
* @param isUpdate - true only if the domain is already register and you want to update its data
|
|
94
|
+
* @returns memo and value of deposit
|
|
95
|
+
*/
|
|
96
|
+
registerThorname(params: RegisterThornameParams): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
|
|
99
|
+
* By default owner is getting from wallet
|
|
100
|
+
* @param thorname - Name to register
|
|
101
|
+
* @param chain - Chain to add alias
|
|
102
|
+
* @param chainAddress - Address to add to chain alias
|
|
103
|
+
* @param owner - Owner address (rune address)
|
|
104
|
+
* @param preferredAsset - referred asset
|
|
105
|
+
* @param expirity - expirity of the domain in MILLISECONDS
|
|
106
|
+
* @returns memo and value of deposit
|
|
107
|
+
*/
|
|
108
|
+
updateThorname(params: UpdateThornameParams): Promise<string>;
|
|
84
109
|
/** Function handles liquidity add for all non rune assets
|
|
85
110
|
*
|
|
86
111
|
* @param params - parameters for add liquidity
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-amm",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@xchainjs/xchain-midgard": "^0.5.1",
|
|
56
56
|
"@xchainjs/xchain-thorchain": "^0.28.6",
|
|
57
57
|
"@xchainjs/xchain-thornode": "^0.3.6",
|
|
58
|
-
"@xchainjs/xchain-thorchain-query": "^0.6.
|
|
58
|
+
"@xchainjs/xchain-thorchain-query": "^0.6.2",
|
|
59
59
|
"@xchainjs/xchain-util": "^0.13.1",
|
|
60
60
|
"@xchainjs/xchain-utxo-providers": "^0.2.2",
|
|
61
61
|
"axios": "^1.3.6",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@xchainjs/xchain-midgard": "^0.5.1",
|
|
92
92
|
"@xchainjs/xchain-thorchain": "^0.28.6",
|
|
93
93
|
"@xchainjs/xchain-thornode": "^0.3.6",
|
|
94
|
-
"@xchainjs/xchain-thorchain-query": "^0.6.
|
|
94
|
+
"@xchainjs/xchain-thorchain-query": "^0.6.2",
|
|
95
95
|
"@xchainjs/xchain-util": "^0.13.1",
|
|
96
96
|
"@xchainjs/xchain-utxo-providers": "^0.2.2",
|
|
97
97
|
"axios": "^1.3.6",
|