@xchainjs/xchain-thorchain-query 0.1.0-beta → 0.1.0-beta2
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 +471 -135
- package/lib/index.js +434 -98
- package/lib/thorchain-cache.d.ts +12 -0
- package/lib/thorchain-query.d.ts +31 -2
- package/lib/types.d.ts +67 -7
- package/lib/utils/liquidity.d.ts +24 -17
- package/lib/utils/midgard.d.ts +19 -3
- package/lib/utils/thornode.d.ts +24 -1
- package/package.json +5 -5
package/lib/thorchain-cache.d.ts
CHANGED
|
@@ -105,8 +105,20 @@ export declare class ThorchainCache {
|
|
|
105
105
|
convert(input: CryptoAmount, outAsset: Asset): Promise<CryptoAmount>;
|
|
106
106
|
private getDecimalForAsset;
|
|
107
107
|
getRouterAddressForChain(chain: Chain): Promise<Address>;
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
* @returns - inbound adresses item
|
|
111
|
+
*/
|
|
108
112
|
getInboundAddressesItems(): Promise<Record<string, InboundAddressesItem>>;
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @returns - inbound details
|
|
116
|
+
*/
|
|
109
117
|
getInboundDetails(): Promise<Record<string, InboundDetail>>;
|
|
118
|
+
/**
|
|
119
|
+
*
|
|
120
|
+
* @returns - network values
|
|
121
|
+
*/
|
|
110
122
|
getNetworkValues(): Promise<Record<string, number>>;
|
|
111
123
|
getDeepestUSDPool(): Promise<LiquidityPool>;
|
|
112
124
|
}
|
package/lib/thorchain-query.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Asset, Chain } from '@xchainjs/xchain-util';
|
|
2
2
|
import { CryptoAmount } from './crypto-amount';
|
|
3
3
|
import { ThorchainCache } from './thorchain-cache';
|
|
4
|
-
import { ChainAttributes, EstimateSwapParams, TotalFees, TxDetails, TxStatus } from './types';
|
|
4
|
+
import { AddliquidityPosition, ChainAttributes, EstimateAddLP, EstimateSwapParams, EstimateWithdrawLP, LiquidityPosition, PoolRatios, RemoveLiquidityPosition, TotalFees, TxDetails, TxStatus } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* THORChain Class for interacting with THORChain.
|
|
7
7
|
* Recommended main class to use for swapping with THORChain
|
|
@@ -101,7 +101,7 @@ export declare class ThorchainQuery {
|
|
|
101
101
|
* @returns time in seconds before a Tx is confirmed by THORChain
|
|
102
102
|
* @see https://docs.thorchain.org/chain-clients/overview
|
|
103
103
|
*/
|
|
104
|
-
|
|
104
|
+
confCounting(inbound: CryptoAmount): Promise<number>;
|
|
105
105
|
/**
|
|
106
106
|
* Works out how long an outbound Tx will be held by THORChain before sending.
|
|
107
107
|
*
|
|
@@ -135,4 +135,33 @@ export declare class ThorchainQuery {
|
|
|
135
135
|
private checkOutboundQueue;
|
|
136
136
|
/** Stage 4 */
|
|
137
137
|
private checkOutboundTx;
|
|
138
|
+
/**
|
|
139
|
+
* Estimates a liquidity position for given crypto amount value, both asymmetrical and symetrical
|
|
140
|
+
* @param params - parameters needed for a estimated liquidity position
|
|
141
|
+
* @returns - type object EstimateLP
|
|
142
|
+
*/
|
|
143
|
+
estimateAddLP(params: AddliquidityPosition): Promise<EstimateAddLP>;
|
|
144
|
+
/**
|
|
145
|
+
* @param - Asset for lp
|
|
146
|
+
* @param address - address used for Lp
|
|
147
|
+
* @returns - Type Object liquidityPosition
|
|
148
|
+
*/
|
|
149
|
+
checkLiquidityPosition(asset: Asset, assetOrRuneAddress: string): Promise<LiquidityPosition>;
|
|
150
|
+
/**
|
|
151
|
+
* Do not send assetNativeRune, There is no pool for it.
|
|
152
|
+
* @param asset - asset required to find the pool
|
|
153
|
+
* @returns - object type ratios
|
|
154
|
+
*/
|
|
155
|
+
getPoolRatios(asset: Asset): Promise<PoolRatios>;
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
* @param params
|
|
159
|
+
*/
|
|
160
|
+
estimateWithdrawLP(params: RemoveLiquidityPosition): Promise<EstimateWithdrawLP>;
|
|
161
|
+
/**
|
|
162
|
+
* // can this become a quried constant? added to inbound_addresses or something
|
|
163
|
+
* @param asset - asset needed to retrieve dust values
|
|
164
|
+
* @returns - object type dust values
|
|
165
|
+
*/
|
|
166
|
+
private getDustValues;
|
|
138
167
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FeeOption } from '@xchainjs/xchain-client';
|
|
2
2
|
import { InboundAddressesItem } from '@xchainjs/xchain-midgard';
|
|
3
|
+
import { LiquidityProvider } from '@xchainjs/xchain-thornode';
|
|
3
4
|
import { Address, Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
4
5
|
import { BigNumber } from 'bignumber.js';
|
|
5
6
|
import { CryptoAmount } from './crypto-amount';
|
|
@@ -53,20 +54,21 @@ export declare type SwapOutput = {
|
|
|
53
54
|
slip: BigNumber;
|
|
54
55
|
};
|
|
55
56
|
export declare type UnitData = {
|
|
56
|
-
liquidityUnits:
|
|
57
|
-
totalUnits:
|
|
57
|
+
liquidityUnits: BaseAmount;
|
|
58
|
+
totalUnits: BaseAmount;
|
|
58
59
|
};
|
|
59
60
|
export declare type LiquidityData = {
|
|
60
|
-
rune:
|
|
61
|
-
asset:
|
|
61
|
+
rune: CryptoAmount;
|
|
62
|
+
asset: CryptoAmount;
|
|
62
63
|
};
|
|
63
64
|
export declare type Block = {
|
|
64
65
|
current: number;
|
|
65
|
-
lastAdded
|
|
66
|
+
lastAdded?: number;
|
|
66
67
|
fullProtection: number;
|
|
67
68
|
};
|
|
68
|
-
export declare type
|
|
69
|
-
|
|
69
|
+
export declare type ILProtectionData = {
|
|
70
|
+
ILProtection: CryptoAmount;
|
|
71
|
+
totalDays: string;
|
|
70
72
|
};
|
|
71
73
|
export declare type InboundDetail = {
|
|
72
74
|
vault: string;
|
|
@@ -108,3 +110,61 @@ export declare type TxStatus = {
|
|
|
108
110
|
stage: TxStage;
|
|
109
111
|
seconds: number;
|
|
110
112
|
};
|
|
113
|
+
export declare type LiquidityToAdd = {
|
|
114
|
+
asset: BaseAmount;
|
|
115
|
+
rune: BaseAmount;
|
|
116
|
+
};
|
|
117
|
+
export declare type PostionDepositValue = {
|
|
118
|
+
asset: BaseAmount;
|
|
119
|
+
rune: BaseAmount;
|
|
120
|
+
};
|
|
121
|
+
export declare type PoolShareDetail = {
|
|
122
|
+
assetShare: CryptoAmount;
|
|
123
|
+
runeShare: CryptoAmount;
|
|
124
|
+
};
|
|
125
|
+
export declare type EstimateAddLP = {
|
|
126
|
+
slipPercent: BigNumber;
|
|
127
|
+
poolShare: PoolShareDetail;
|
|
128
|
+
lpUnits: BaseAmount;
|
|
129
|
+
transactionFee: LPFees;
|
|
130
|
+
runeToAssetRatio: BigNumber;
|
|
131
|
+
estimatedWaitSeconds: number;
|
|
132
|
+
errors: string[];
|
|
133
|
+
canAdd: boolean;
|
|
134
|
+
};
|
|
135
|
+
export declare type EstimateWithdrawLP = {
|
|
136
|
+
slipPercent: BigNumber;
|
|
137
|
+
transactionFee: LPFees;
|
|
138
|
+
assetAmount: CryptoAmount;
|
|
139
|
+
runeAmount: CryptoAmount;
|
|
140
|
+
impermanentLossProtection: ILProtectionData;
|
|
141
|
+
estimatedWaitSeconds: number;
|
|
142
|
+
};
|
|
143
|
+
export declare type LPFees = {
|
|
144
|
+
runeFee: CryptoAmount;
|
|
145
|
+
assetFee: CryptoAmount;
|
|
146
|
+
totalFees: CryptoAmount;
|
|
147
|
+
};
|
|
148
|
+
export declare type DustValues = {
|
|
149
|
+
asset: CryptoAmount;
|
|
150
|
+
rune: CryptoAmount;
|
|
151
|
+
};
|
|
152
|
+
export declare type AddliquidityPosition = {
|
|
153
|
+
asset: CryptoAmount;
|
|
154
|
+
rune: CryptoAmount;
|
|
155
|
+
};
|
|
156
|
+
export declare type RemoveLiquidityPosition = {
|
|
157
|
+
asset: Asset;
|
|
158
|
+
percentage: number;
|
|
159
|
+
assetAddress?: string;
|
|
160
|
+
runeAddress?: string;
|
|
161
|
+
};
|
|
162
|
+
export declare type LiquidityPosition = {
|
|
163
|
+
poolShare: PoolShareDetail;
|
|
164
|
+
position: LiquidityProvider;
|
|
165
|
+
impermanentLossProtection: ILProtectionData;
|
|
166
|
+
};
|
|
167
|
+
export declare type PoolRatios = {
|
|
168
|
+
assetToRune: BigNumber;
|
|
169
|
+
runeToAsset: BigNumber;
|
|
170
|
+
};
|
package/lib/utils/liquidity.d.ts
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
import { BigNumber } from 'bignumber.js';
|
|
2
2
|
import { LiquidityPool } from '../liquidity-pool';
|
|
3
|
-
import { Block,
|
|
3
|
+
import { Block, ILProtectionData, LiquidityToAdd, PoolShareDetail, PostionDepositValue, UnitData } from '../types';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* https://dev.thorchain.org/thorchain-dev/interface-guide/math#lp-units-add
|
|
6
6
|
* @param liquidity - asset amount added
|
|
7
7
|
* @param pool - pool depths
|
|
8
|
-
* @returns liquidity units
|
|
8
|
+
* @returns liquidity units - ownership of pool
|
|
9
9
|
*/
|
|
10
|
-
export declare const getLiquidityUnits: (liquidity:
|
|
10
|
+
export declare const getLiquidityUnits: (liquidity: LiquidityToAdd, pool: LiquidityPool) => BigNumber;
|
|
11
11
|
/**
|
|
12
12
|
*
|
|
13
|
-
* @param unitData
|
|
14
|
-
* @param pool
|
|
15
|
-
* @returns
|
|
13
|
+
* @param unitData - units for both asset and rune
|
|
14
|
+
* @param pool - pool that the asset is bound to
|
|
15
|
+
* @returns - pool share of both asset and rune in percentage
|
|
16
16
|
*/
|
|
17
|
-
export declare const getPoolShare: (unitData: UnitData, pool: LiquidityPool) =>
|
|
17
|
+
export declare const getPoolShare: (unitData: UnitData, pool: LiquidityPool) => PoolShareDetail;
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @param pool
|
|
22
|
-
* @returns
|
|
20
|
+
* @param poolShare - the share of asset and rune added to the pool
|
|
21
|
+
* @param pool - Pool that the asset is attached to
|
|
22
|
+
* @returns - returns bignumber representing a slip percentage
|
|
23
23
|
*/
|
|
24
|
-
export declare const getSlipOnLiquidity: (
|
|
24
|
+
export declare const getSlipOnLiquidity: (stake: LiquidityToAdd, pool: LiquidityPool) => BigNumber;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param pool
|
|
29
|
-
* @param block
|
|
26
|
+
* https://docs.thorchain.org/thorchain-finance/continuous-liquidity-pools#impermanent-loss-protection
|
|
27
|
+
* @param poolShare - the share of asset and rune added to the pool
|
|
28
|
+
* @param pool - Pool that the asset is attached to
|
|
29
|
+
* @param block - blockl object with current, last added and the constant blocksforlossProtection
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
export declare const getLiquidityProtectionData: (
|
|
32
|
+
export declare const getLiquidityProtectionData: (depositValue: PostionDepositValue, poolShare: PoolShareDetail, block: Block) => ILProtectionData;
|
|
33
|
+
/**
|
|
34
|
+
* https://docs.thorchain.org/thorchain-finance/continuous-liquidity-pools#calculating-pool-ownership
|
|
35
|
+
* @param liquidity - asset amount added
|
|
36
|
+
* @param pool - pool depths
|
|
37
|
+
* @returns liquidity units - % ownership of pool
|
|
38
|
+
*/
|
|
39
|
+
export declare const getPoolOwnership: (liquidity: LiquidityToAdd, pool: LiquidityPool) => number;
|
package/lib/utils/midgard.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
-
import { Action, InboundAddressesItem, PoolDetail } from '@xchainjs/xchain-midgard';
|
|
2
|
+
import { Action, InboundAddressesItem, MemberDetails, PoolDetail, PoolStatsDetail } from '@xchainjs/xchain-midgard';
|
|
3
3
|
import { CryptoAmount } from '../crypto-amount';
|
|
4
4
|
import { InboundDetail, MidgardConfig } from '../types';
|
|
5
5
|
export declare class Midgard {
|
|
@@ -19,6 +19,10 @@ export declare class Midgard {
|
|
|
19
19
|
* @returns inbound details
|
|
20
20
|
*/
|
|
21
21
|
getInboundDetails(): Promise<Record<string, InboundDetail>>;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @returns - constants
|
|
25
|
+
*/
|
|
22
26
|
private getConstantsDetails;
|
|
23
27
|
/**
|
|
24
28
|
*
|
|
@@ -39,9 +43,21 @@ export declare class Midgard {
|
|
|
39
43
|
*/
|
|
40
44
|
getLatestBlockHeight(): Promise<number>;
|
|
41
45
|
/**
|
|
42
|
-
* Gets actions
|
|
46
|
+
* Gets actions object for any of the parameters
|
|
43
47
|
* @param txHash transaction id
|
|
44
48
|
* @returns Type Action array of objects
|
|
45
49
|
*/
|
|
46
|
-
getActions(
|
|
50
|
+
getActions(address?: string, txid?: string, asset?: string, type?: string, affiliate?: string, limit?: number, offset?: number): Promise<Action[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Function to return member details based on valid liquidity position
|
|
53
|
+
* @param address - needed to query for Lp details
|
|
54
|
+
* @returns - object type of Member Detail
|
|
55
|
+
*/
|
|
56
|
+
getMember(address: string): Promise<MemberDetails>;
|
|
57
|
+
/**
|
|
58
|
+
* Function to return pool statistics for a particular asset
|
|
59
|
+
* @param asset - asset string to query its pool stats
|
|
60
|
+
* @returns - type object poolstatsDetail
|
|
61
|
+
*/
|
|
62
|
+
getPoolStats(asset: string): Promise<PoolStatsDetail>;
|
|
47
63
|
}
|
package/lib/utils/thornode.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
-
import { LastBlock, Pool, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
|
|
2
|
+
import { LastBlock, LiquidityProvider, Pool, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
|
|
3
3
|
export declare type ThornodeConfig = {
|
|
4
4
|
apiRetries: number;
|
|
5
5
|
thornodeBaseUrls: string[];
|
|
@@ -11,6 +11,7 @@ export declare class Thornode {
|
|
|
11
11
|
private queueApi;
|
|
12
12
|
private networkApi;
|
|
13
13
|
private poolsApi;
|
|
14
|
+
private liquidityProvidersApi;
|
|
14
15
|
constructor(network?: Network, config?: ThornodeConfig);
|
|
15
16
|
/**
|
|
16
17
|
* Returns the oubound transactions held by THORChain due to outbound delay
|
|
@@ -20,7 +21,29 @@ export declare class Thornode {
|
|
|
20
21
|
*
|
|
21
22
|
*/
|
|
22
23
|
getscheduledQueue(): Promise<TxOutItem[]>;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param txHash - transaction hash
|
|
27
|
+
* @returns - transaction object
|
|
28
|
+
*/
|
|
23
29
|
getTxData(txHash: string): Promise<TxResponse>;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param height - optional thorchain height only
|
|
33
|
+
* @returns - last block data || or block data pertaining to that height number
|
|
34
|
+
*/
|
|
24
35
|
getLastBlock(height?: number): Promise<LastBlock[]>;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @returns - thorchain pool
|
|
39
|
+
*/
|
|
25
40
|
getPools(): Promise<Pool[]>;
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param asset - asset string
|
|
44
|
+
* @param address - address
|
|
45
|
+
* @param height - optional block height, defaults to current tip
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
getLiquidityProvider(asset: string, address: string, height?: number): Promise<LiquidityProvider | undefined>;
|
|
26
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-query",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-beta2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Thorchain query module that is resposible for estimating swap calculations and add/remove liquidity for thorchain ",
|
|
6
6
|
"keywords": [
|
|
@@ -33,20 +33,20 @@
|
|
|
33
33
|
"postversion": "git push --follow-tags"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@xchainjs/xchain-client": "^0.13.
|
|
36
|
+
"@xchainjs/xchain-client": "^0.13.1",
|
|
37
37
|
"@xchainjs/xchain-midgard": "^0.1.0-alpha2",
|
|
38
38
|
"@xchainjs/xchain-thornode": "^0.1.0-alpha4",
|
|
39
|
-
"@xchainjs/xchain-util": "^0.
|
|
39
|
+
"@xchainjs/xchain-util": "^0.10.0",
|
|
40
40
|
"axios": "^0.25.0",
|
|
41
41
|
"axios-retry": "^3.2.5",
|
|
42
42
|
"bignumber.js": "^9.0.0",
|
|
43
43
|
"rimraf": "~3.0.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@xchainjs/xchain-client": "^0.13.
|
|
46
|
+
"@xchainjs/xchain-client": "^0.13.1",
|
|
47
47
|
"@xchainjs/xchain-midgard": "^0.1.0-alpha2",
|
|
48
48
|
"@xchainjs/xchain-thornode": "^0.1.0-alpha4",
|
|
49
|
-
"@xchainjs/xchain-util": "^0.
|
|
49
|
+
"@xchainjs/xchain-util": "^0.10.0",
|
|
50
50
|
"axios": "^0.25.0",
|
|
51
51
|
"axios-retry": "^3.2.5",
|
|
52
52
|
"bignumber.js": "^9.0.0",
|