@xchainjs/xchain-thorchain-query 0.1.0-alpha
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/LICENSE +21 -0
- package/README.md +19 -0
- package/lib/chain-defaults.d.ts +4 -0
- package/lib/crypto-amount.d.ts +37 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.esm.js +1714 -0
- package/lib/index.js +1735 -0
- package/lib/liquidity-pool.d.ts +18 -0
- package/lib/thorchain-cache.d.ts +111 -0
- package/lib/thorchain-query.d.ts +138 -0
- package/lib/types.d.ts +107 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/liquidity.d.ts +32 -0
- package/lib/utils/midgard.d.ts +47 -0
- package/lib/utils/swap.d.ts +71 -0
- package/lib/utils/thornode.d.ts +26 -0
- package/package.json +58 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PoolDetail } from '@xchainjs/xchain-midgard/lib';
|
|
2
|
+
import { Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
3
|
+
import { BigNumber } from 'bignumber.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represent a Liquidity Pool in Thorchain
|
|
6
|
+
*/
|
|
7
|
+
export declare class LiquidityPool {
|
|
8
|
+
readonly pool: PoolDetail;
|
|
9
|
+
readonly assetBalance: BaseAmount;
|
|
10
|
+
readonly runeBalance: BaseAmount;
|
|
11
|
+
readonly decimals: number;
|
|
12
|
+
readonly asset: Asset;
|
|
13
|
+
readonly assetString: string;
|
|
14
|
+
readonly runeToAssetRatio: BigNumber;
|
|
15
|
+
readonly assetToRuneRatio: BigNumber;
|
|
16
|
+
constructor(pool: PoolDetail, decimals: number);
|
|
17
|
+
isAvailable(): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { InboundAddressesItem } from '@xchainjs/xchain-midgard';
|
|
2
|
+
import { Address, Asset, Chain } from '@xchainjs/xchain-util';
|
|
3
|
+
import { BigNumber } from 'bignumber.js';
|
|
4
|
+
import { CryptoAmount } from './crypto-amount';
|
|
5
|
+
import { LiquidityPool } from './liquidity-pool';
|
|
6
|
+
import { InboundDetail, SwapOutput } from './types';
|
|
7
|
+
import { Midgard } from './utils/midgard';
|
|
8
|
+
import { Thornode } from './utils/thornode';
|
|
9
|
+
/**
|
|
10
|
+
* This class manages retrieving information from up to date Thorchain
|
|
11
|
+
*/
|
|
12
|
+
export declare class ThorchainCache {
|
|
13
|
+
readonly midgard: Midgard;
|
|
14
|
+
readonly thornode: Thornode;
|
|
15
|
+
private poolCache;
|
|
16
|
+
private asgardAssetsCache;
|
|
17
|
+
private inboundDetailCache;
|
|
18
|
+
private networkValuesCache;
|
|
19
|
+
private expirePoolCacheMillis;
|
|
20
|
+
private expireAsgardCacheMillis;
|
|
21
|
+
private expireInboundDetailsCacheMillis;
|
|
22
|
+
private expireNetworkValuesCacheMillis;
|
|
23
|
+
/**
|
|
24
|
+
* Contrustor to create a ThorchainCache
|
|
25
|
+
*
|
|
26
|
+
* @param midgard - an instance of the midgard API (could be pointing to stagenet,testnet,mainnet)
|
|
27
|
+
* @param expirePoolCacheMillis - how long should the pools be cached before expiry
|
|
28
|
+
* @param expireAsgardCacheMillis - how long should the inboundAsgard Addresses be cached before expiry
|
|
29
|
+
* @param expireInboundDetailsCacheMillis - how long should the InboundDetails be cached before expiry
|
|
30
|
+
* @param expireNetworkValuesCacheMillis - how long should the Mimir/Constants be cached before expiry
|
|
31
|
+
* @returns ThorchainCache
|
|
32
|
+
*/
|
|
33
|
+
constructor(midgard: Midgard, thornode: Thornode, expirePoolCacheMillis?: number, expireAsgardCacheMillis?: number, expireInboundDetailsCacheMillis?: number, expireNetworkValuesCacheMillis?: number);
|
|
34
|
+
/**
|
|
35
|
+
* Gets the exchange rate of the from asset in terms on the to asset
|
|
36
|
+
*
|
|
37
|
+
* @param asset - cannot be RUNE.
|
|
38
|
+
* @returns Promise<BigNumber>
|
|
39
|
+
*/
|
|
40
|
+
getExchangeRate(from: Asset, to: Asset): Promise<BigNumber>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets the Liquidity Pool for a given Asset
|
|
43
|
+
*
|
|
44
|
+
* @param asset - cannot be RUNE, since Rune is the other side of each pool.
|
|
45
|
+
* @returns Promise<LiquidityPool>
|
|
46
|
+
*/
|
|
47
|
+
getPoolForAsset(asset: Asset): Promise<LiquidityPool>;
|
|
48
|
+
/**
|
|
49
|
+
* Get all the Liquidity Pools currently cached.
|
|
50
|
+
* if the cache is expired, the pools wioll be re-fetched from midgard
|
|
51
|
+
*
|
|
52
|
+
* @returns Promise<Record<string, LiquidityPool>>
|
|
53
|
+
*/
|
|
54
|
+
getPools(): Promise<Record<string, LiquidityPool>>;
|
|
55
|
+
/**
|
|
56
|
+
* Refreshes the Pool Cache
|
|
57
|
+
*
|
|
58
|
+
* NOTE: do not call refereshPoolCache() directly, call getPools() instead
|
|
59
|
+
* which will refresh the cache if it's expired
|
|
60
|
+
*/
|
|
61
|
+
private refereshPoolCache;
|
|
62
|
+
/**
|
|
63
|
+
* Refreshes the asgardAssetsCache Cache
|
|
64
|
+
*
|
|
65
|
+
* NOTE: do not call refereshAsgardCache() directly, call getAsgardAssets() instead
|
|
66
|
+
* which will refresh the cache if it's expired
|
|
67
|
+
*/
|
|
68
|
+
private refereshAsgardCache;
|
|
69
|
+
/**
|
|
70
|
+
* Refreshes the InboundDetailCache Cache
|
|
71
|
+
*
|
|
72
|
+
* NOTE: do not call refereshInboundDetailCache() directly, call getInboundDetails() instead
|
|
73
|
+
* which will refresh the cache if it's expired
|
|
74
|
+
*/
|
|
75
|
+
private refereshInboundDetailCache;
|
|
76
|
+
/**
|
|
77
|
+
* Refreshes the NetworkValuesCache Cache
|
|
78
|
+
*
|
|
79
|
+
* NOTE: do not call refereshNetworkValuesCache() directly, call getNetworkValuess() instead
|
|
80
|
+
* which will refresh the cache if it's expired
|
|
81
|
+
*/
|
|
82
|
+
private refereshNetworkValuesCache;
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* Calcuate the expected slip, output & swapFee given the current pool depths
|
|
86
|
+
*
|
|
87
|
+
* swapFee - the amount of asset lost according to slip calculations
|
|
88
|
+
* slip - the percent (0-1) of original amount lost to slipfees
|
|
89
|
+
* output - the amount of asset expected from the swap *
|
|
90
|
+
*
|
|
91
|
+
* @param inputAmount - CryptoAmount amount to swap from
|
|
92
|
+
* @param destinationAsset - destimation Asset to swap to
|
|
93
|
+
* @returns SwapOutput - swap output object - output - fee - slip
|
|
94
|
+
*/
|
|
95
|
+
getExpectedSwapOutput(inputAmount: CryptoAmount, destinationAsset: Asset): Promise<SwapOutput>;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the exchange of a CryptoAmount to a different Asset
|
|
98
|
+
*
|
|
99
|
+
* Ex. convert(input:100 BUSD, outAsset: BTC) -> 0.0001234 BTC
|
|
100
|
+
*
|
|
101
|
+
* @param input - amount/asset to convert to outAsset
|
|
102
|
+
* @param ouAsset - the Asset you want to convert to
|
|
103
|
+
* @returns CryptoAmount of input
|
|
104
|
+
*/
|
|
105
|
+
convert(input: CryptoAmount, outAsset: Asset): Promise<CryptoAmount>;
|
|
106
|
+
getRouterAddressForChain(chain: Chain): Promise<Address>;
|
|
107
|
+
getInboundAddressesItems(): Promise<Record<string, InboundAddressesItem>>;
|
|
108
|
+
getInboundDetails(): Promise<Record<string, InboundDetail>>;
|
|
109
|
+
getNetworkValues(): Promise<Record<string, number>>;
|
|
110
|
+
getDeepestUSDPool(): Promise<LiquidityPool>;
|
|
111
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Asset, Chain } from '@xchainjs/xchain-util';
|
|
2
|
+
import { CryptoAmount } from './crypto-amount';
|
|
3
|
+
import { ThorchainCache } from './thorchain-cache';
|
|
4
|
+
import { ChainAttributes, EstimateSwapParams, TotalFees, TxDetails, TxStatus } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* THORChain Class for interacting with THORChain.
|
|
7
|
+
* Recommended main class to use for swapping with THORChain
|
|
8
|
+
* Has access to Midgard and THORNode data
|
|
9
|
+
*/
|
|
10
|
+
export declare class ThorchainQuery {
|
|
11
|
+
readonly thorchainCache: ThorchainCache;
|
|
12
|
+
private chainAttributes;
|
|
13
|
+
/**
|
|
14
|
+
* Contructor to create a ThorchainAMM
|
|
15
|
+
*
|
|
16
|
+
* @param thorchainCache - an instance of the ThorchainCache (could be pointing to stagenet,testnet,mainnet)
|
|
17
|
+
* @param chainAttributes - atrributes used to calculate waitTime & conf counting
|
|
18
|
+
* @returns ThorchainAMM
|
|
19
|
+
*/
|
|
20
|
+
constructor(thorchainCache: ThorchainCache, chainAttributes?: Record<Chain, ChainAttributes>);
|
|
21
|
+
/**
|
|
22
|
+
* Provides a swap estimate for the given swap detail. Will check the params for errors before trying to get the estimate.
|
|
23
|
+
* Uses current pool data, works out inbound and outboud fee, affiliate fees and works out the expected wait time for the swap (in and out)
|
|
24
|
+
*
|
|
25
|
+
* @param params - amount to swap
|
|
26
|
+
|
|
27
|
+
* @returns The SwapEstimate
|
|
28
|
+
*/
|
|
29
|
+
estimateSwap(params: EstimateSwapParams, destinationAddress?: string, affiliateAddress?: string, interfaceID?: number): Promise<TxDetails>;
|
|
30
|
+
/**
|
|
31
|
+
* Basic Checks for swap information
|
|
32
|
+
* @param params
|
|
33
|
+
*/
|
|
34
|
+
private isValidSwap;
|
|
35
|
+
/**
|
|
36
|
+
* Does the calculations for the swap.
|
|
37
|
+
* Used by estimateSwap
|
|
38
|
+
*
|
|
39
|
+
* @param params
|
|
40
|
+
* @param sourceInboundDetails
|
|
41
|
+
* @param destinationInboundDetails
|
|
42
|
+
* @param sourcePool
|
|
43
|
+
* @param destinationPool
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
private calcSwapEstimate;
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param params - swap object
|
|
50
|
+
* @returns - constructed memo string
|
|
51
|
+
*/
|
|
52
|
+
private constructSwapMemo;
|
|
53
|
+
/**
|
|
54
|
+
* Looks for errors or issues within swap prams before doing the swap.
|
|
55
|
+
*
|
|
56
|
+
*
|
|
57
|
+
* @param params
|
|
58
|
+
* @param estimate
|
|
59
|
+
* @param sourcePool
|
|
60
|
+
* @param sourceInboundDetails
|
|
61
|
+
* @param destinationPool
|
|
62
|
+
* @param destinationInboundDetails
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
private getSwapEstimateErrors;
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param params
|
|
69
|
+
* @param estimate
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
private checkCoverFees;
|
|
73
|
+
/**
|
|
74
|
+
* Convenience method to convert TotalFees to a different CryptoAmount
|
|
75
|
+
*
|
|
76
|
+
* TotalFees are always calculated and returned in RUNE, this method can
|
|
77
|
+
* be used to show the equivalent fees in another Asset Type
|
|
78
|
+
*
|
|
79
|
+
* @param fees: TotalFees - the fees you want to convert
|
|
80
|
+
* @param asset: Asset - the asset you want the fees converted to
|
|
81
|
+
* @returns TotalFees in asset
|
|
82
|
+
*/
|
|
83
|
+
getFeesIn(fees: TotalFees, asset: Asset): Promise<TotalFees>;
|
|
84
|
+
/**
|
|
85
|
+
* Returns the exchange of a CryptoAmount to a different Asset
|
|
86
|
+
*
|
|
87
|
+
* Ex. convert(input:100 BUSD, outAsset: BTC) -> 0.0001234 BTC
|
|
88
|
+
*
|
|
89
|
+
* @param input - amount/asset to convert to outAsset
|
|
90
|
+
* @param ouAsset - the Asset you want to convert to
|
|
91
|
+
* @returns CryptoAmount of input
|
|
92
|
+
*/
|
|
93
|
+
convert(input: CryptoAmount, outAsset: Asset): Promise<CryptoAmount>;
|
|
94
|
+
/**
|
|
95
|
+
* Finds the required confCount required for an inbound or outbound Tx to THORChain. Estimate based on Midgard data only.
|
|
96
|
+
*
|
|
97
|
+
* Finds the gas asset of the given asset (e.g. BUSD is on BNB), finds the value of asset in Gas Asset then finds the required confirmation count.
|
|
98
|
+
* ConfCount is then times by 6 seconds.
|
|
99
|
+
*
|
|
100
|
+
* @param inbound: CryptoAmount - amount/asset of the outbound amount.
|
|
101
|
+
* @returns time in seconds before a Tx is confirmed by THORChain
|
|
102
|
+
* @see https://docs.thorchain.org/chain-clients/overview
|
|
103
|
+
*/
|
|
104
|
+
private confCounting;
|
|
105
|
+
/**
|
|
106
|
+
* Works out how long an outbound Tx will be held by THORChain before sending.
|
|
107
|
+
*
|
|
108
|
+
* @param outboundAmount: CryptoAmount being sent.
|
|
109
|
+
* @returns required delay in seconds
|
|
110
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/manager_txout_current.go#L548
|
|
111
|
+
*/
|
|
112
|
+
outboundDelay(outboundAmount: CryptoAmount): Promise<number>;
|
|
113
|
+
/**
|
|
114
|
+
* For a given in Tx Hash (as returned by THORChainAMM.DoSwap()), finds the status of any THORChain transaction
|
|
115
|
+
* This function should be polled.
|
|
116
|
+
* @param
|
|
117
|
+
* @param inboundTxHash - needed to determine transactions stage
|
|
118
|
+
* @param sourceChain - extra parameter
|
|
119
|
+
* @returns - object tx status
|
|
120
|
+
*/
|
|
121
|
+
checkTx(inboundTxHash: string, sourceChain?: Chain): Promise<TxStatus>;
|
|
122
|
+
/** Stage 1 */
|
|
123
|
+
private checkTxDefined;
|
|
124
|
+
/** Stage 2, THORNode has seen it. See if observed only (conf counting) or it has been processed by THORChain */
|
|
125
|
+
private checkObservedOnly;
|
|
126
|
+
/**
|
|
127
|
+
* Stage 3
|
|
128
|
+
* @param txStatus
|
|
129
|
+
* @param txData
|
|
130
|
+
* @param scheduledQueue
|
|
131
|
+
* @param scheduledQueueItem
|
|
132
|
+
* @param lastBlockHeight
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
private checkOutboundQueue;
|
|
136
|
+
/** Stage 4 */
|
|
137
|
+
private checkOutboundTx;
|
|
138
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { FeeOption } from '@xchainjs/xchain-client';
|
|
2
|
+
import { InboundAddressesItem } from '@xchainjs/xchain-midgard';
|
|
3
|
+
import { Address, Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
4
|
+
import { BigNumber } from 'bignumber.js';
|
|
5
|
+
import { CryptoAmount } from './crypto-amount';
|
|
6
|
+
import { LiquidityPool } from './liquidity-pool';
|
|
7
|
+
export declare type TotalFees = {
|
|
8
|
+
inboundFee: CryptoAmount;
|
|
9
|
+
swapFee: CryptoAmount;
|
|
10
|
+
outboundFee: CryptoAmount;
|
|
11
|
+
affiliateFee: CryptoAmount;
|
|
12
|
+
};
|
|
13
|
+
export declare type SwapEstimate = {
|
|
14
|
+
totalFees: TotalFees;
|
|
15
|
+
slipPercentage: BigNumber;
|
|
16
|
+
netOutput: CryptoAmount;
|
|
17
|
+
waitTimeSeconds: number;
|
|
18
|
+
canSwap: boolean;
|
|
19
|
+
errors: string[];
|
|
20
|
+
};
|
|
21
|
+
export declare type PoolCache = {
|
|
22
|
+
lastRefreshed: number;
|
|
23
|
+
pools: Record<string, LiquidityPool>;
|
|
24
|
+
};
|
|
25
|
+
export declare type AsgardCache = {
|
|
26
|
+
lastRefreshed: number;
|
|
27
|
+
inboundAddressesItems: Record<string, InboundAddressesItem>;
|
|
28
|
+
};
|
|
29
|
+
export declare type InboundDetailCache = {
|
|
30
|
+
lastRefreshed: number;
|
|
31
|
+
inboundDetails: Record<string, InboundDetail>;
|
|
32
|
+
};
|
|
33
|
+
export declare type NetworkValuesCache = {
|
|
34
|
+
lastRefreshed: number;
|
|
35
|
+
networkValues: Record<string, number>;
|
|
36
|
+
};
|
|
37
|
+
export declare type MidgardConfig = {
|
|
38
|
+
apiRetries: number;
|
|
39
|
+
midgardBaseUrls: string[];
|
|
40
|
+
};
|
|
41
|
+
export declare type EstimateSwapParams = {
|
|
42
|
+
input: CryptoAmount;
|
|
43
|
+
destinationAsset: Asset;
|
|
44
|
+
affiliateFeePercent?: number;
|
|
45
|
+
slipLimit?: BigNumber;
|
|
46
|
+
};
|
|
47
|
+
export declare type SwapOutput = {
|
|
48
|
+
output: CryptoAmount;
|
|
49
|
+
swapFee: CryptoAmount;
|
|
50
|
+
slip: BigNumber;
|
|
51
|
+
};
|
|
52
|
+
export declare type UnitData = {
|
|
53
|
+
liquidityUnits: BigNumber;
|
|
54
|
+
totalUnits: BigNumber;
|
|
55
|
+
};
|
|
56
|
+
export declare type LiquidityData = {
|
|
57
|
+
rune: BigNumber;
|
|
58
|
+
asset: BigNumber;
|
|
59
|
+
};
|
|
60
|
+
export declare type Block = {
|
|
61
|
+
current: number;
|
|
62
|
+
lastAdded: number;
|
|
63
|
+
fullProtection: number;
|
|
64
|
+
};
|
|
65
|
+
export declare type Coverage = {
|
|
66
|
+
poolRatio: BaseAmount;
|
|
67
|
+
};
|
|
68
|
+
export declare type InboundDetail = {
|
|
69
|
+
vault: string;
|
|
70
|
+
router?: string;
|
|
71
|
+
haltedChain: boolean;
|
|
72
|
+
haltedTrading: boolean;
|
|
73
|
+
haltedLP: boolean;
|
|
74
|
+
gas_rate: BigNumber;
|
|
75
|
+
};
|
|
76
|
+
export declare type ChainAttributes = {
|
|
77
|
+
blockReward: number;
|
|
78
|
+
avgBlockTimeInSecs: number;
|
|
79
|
+
};
|
|
80
|
+
export declare type ConstructMemo = {
|
|
81
|
+
input: CryptoAmount;
|
|
82
|
+
destinationAsset: Asset;
|
|
83
|
+
limit: BaseAmount;
|
|
84
|
+
destinationAddress: Address;
|
|
85
|
+
affiliateAddress: Address;
|
|
86
|
+
affiliateFee: BaseAmount;
|
|
87
|
+
feeOption?: FeeOption;
|
|
88
|
+
interfaceID: number;
|
|
89
|
+
};
|
|
90
|
+
export declare type TxDetails = {
|
|
91
|
+
memo: string;
|
|
92
|
+
toAddress: string;
|
|
93
|
+
expiry: Date;
|
|
94
|
+
txEstimate: SwapEstimate;
|
|
95
|
+
};
|
|
96
|
+
export declare enum TxStage {
|
|
97
|
+
INBOUND_CHAIN_UNCONFIRMED = 0,
|
|
98
|
+
CONF_COUNTING = 1,
|
|
99
|
+
TC_PROCESSING = 2,
|
|
100
|
+
OUTBOUND_QUEUED = 3,
|
|
101
|
+
OUTBOUND_CHAIN_UNCONFIRMED = 4,
|
|
102
|
+
OUTBOUND_CHAIN_CONFIRMED = 5
|
|
103
|
+
}
|
|
104
|
+
export declare type TxStatus = {
|
|
105
|
+
stage: TxStage;
|
|
106
|
+
seconds: number;
|
|
107
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BigNumber } from 'bignumber.js';
|
|
2
|
+
import { LiquidityPool } from '../liquidity-pool';
|
|
3
|
+
import { Block, LiquidityData, UnitData } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param liquidity - asset amount added
|
|
7
|
+
* @param pool - pool depths
|
|
8
|
+
* @returns liquidity units
|
|
9
|
+
*/
|
|
10
|
+
export declare const getLiquidityUnits: (liquidity: LiquidityData, pool: LiquidityPool) => BigNumber;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param unitData
|
|
14
|
+
* @param pool
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare const getPoolShare: (unitData: UnitData, pool: LiquidityPool) => LiquidityData;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param liquidity
|
|
21
|
+
* @param pool
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare const getSlipOnLiquidity: (liquidity: LiquidityData, pool: LiquidityPool) => BigNumber;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param liquidity
|
|
28
|
+
* @param pool
|
|
29
|
+
* @param block
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare const getLiquidityProtectionData: (liquidity: LiquidityData, pool: LiquidityPool, block: Block) => number;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Action, InboundAddressesItem, PoolDetail } from '@xchainjs/xchain-midgard';
|
|
3
|
+
import { CryptoAmount } from '../crypto-amount';
|
|
4
|
+
import { InboundDetail, MidgardConfig } from '../types';
|
|
5
|
+
export declare class Midgard {
|
|
6
|
+
private config;
|
|
7
|
+
readonly network: Network;
|
|
8
|
+
private midgardApis;
|
|
9
|
+
constructor(network?: Network, config?: MidgardConfig);
|
|
10
|
+
private getMimirDetails;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @returns an array of Pools
|
|
14
|
+
*/
|
|
15
|
+
getPools(): Promise<PoolDetail[]>;
|
|
16
|
+
getAllInboundAddresses(): Promise<InboundAddressesItem[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the Inbound Details
|
|
19
|
+
* @returns inbound details
|
|
20
|
+
*/
|
|
21
|
+
getInboundDetails(): Promise<Record<string, InboundDetail>>;
|
|
22
|
+
private getConstantsDetails;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @returns the outbound Tx Value in RUNE (Basemount)
|
|
26
|
+
*/
|
|
27
|
+
getScheduledOutboundValue(): Promise<CryptoAmount>;
|
|
28
|
+
/**
|
|
29
|
+
* Function that wraps Mimir and Constants to return the value from a given constant name. Searchs Mimir first.
|
|
30
|
+
*
|
|
31
|
+
* @param networkValueName the network value to be used to search the contsants
|
|
32
|
+
* @returns the mimir or constants value
|
|
33
|
+
*/
|
|
34
|
+
getNetworkValues(): Promise<Record<string, number>>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the latest block using the Health endpoint within Midgard
|
|
37
|
+
*
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
getLatestBlockHeight(): Promise<number>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets actions related to a txID
|
|
43
|
+
* @param txHash transaction id
|
|
44
|
+
* @returns Type Action array of objects
|
|
45
|
+
*/
|
|
46
|
+
getActions(txHash: string): Promise<Action[]>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Asset, Chain } from '@xchainjs/xchain-util';
|
|
2
|
+
import { BigNumber } from 'bignumber.js';
|
|
3
|
+
import { CryptoAmount } from '../crypto-amount';
|
|
4
|
+
import { LiquidityPool } from '../liquidity-pool';
|
|
5
|
+
import { ThorchainCache } from '../thorchain-cache';
|
|
6
|
+
import { SwapOutput } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param inputAmount - amount to swap
|
|
10
|
+
* @param pool - Pool Data, RUNE and ASSET Depths
|
|
11
|
+
* @param toRune - Direction of Swap. True if swapping to RUNE.
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare const getSwapFee: (inputAmount: CryptoAmount, pool: LiquidityPool, toRune: boolean) => CryptoAmount;
|
|
15
|
+
/**
|
|
16
|
+
* Works out the swap slip for a given swap.
|
|
17
|
+
*
|
|
18
|
+
* @param inputAmount - amount to swap
|
|
19
|
+
* @param pool - Pool Data, RUNE and ASSET Depths
|
|
20
|
+
* @param toRune - Direction of Swap. True if swapping to RUNE.
|
|
21
|
+
* @returns The amount of slip. Needs to * 100 to get percentage.
|
|
22
|
+
*/
|
|
23
|
+
export declare const getSwapSlip: (inputAmount: CryptoAmount, pool: LiquidityPool, toRune: boolean) => BigNumber;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param inputAmount - amount to swap
|
|
27
|
+
* @param pool - Pool Data, RUNE and ASSET Depths
|
|
28
|
+
* @param toRune - Direction of Swap. True if swapping to RUNE.
|
|
29
|
+
* @returns The output amount
|
|
30
|
+
*/
|
|
31
|
+
export declare const getSwapOutput: (inputAmount: CryptoAmount, pool: LiquidityPool, toRune: boolean) => CryptoAmount;
|
|
32
|
+
export declare const getDoubleSwapOutput: (inputAmount: CryptoAmount, pool1: LiquidityPool, pool2: LiquidityPool) => CryptoAmount;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param inputAmount - amount to swap
|
|
36
|
+
* @param pool - Pool Data, RUNE and ASSET Depths
|
|
37
|
+
* @returns swap output object - output - fee - slip
|
|
38
|
+
*/
|
|
39
|
+
export declare const getSingleSwap: (inputAmount: CryptoAmount, pool: LiquidityPool, toRune: boolean) => SwapOutput;
|
|
40
|
+
export declare const getDoubleSwapSlip: (inputAmount: CryptoAmount, pool1: LiquidityPool, pool2: LiquidityPool) => BigNumber;
|
|
41
|
+
export declare const getDoubleSwapFee: (inputAmount: CryptoAmount, pool1: LiquidityPool, pool2: LiquidityPool, thorchainCache: ThorchainCache) => Promise<CryptoAmount>;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param inputAmount - amount to swap
|
|
45
|
+
* @param pool - Pool Data, RUNE and ASSET Depths
|
|
46
|
+
* @param toRune - Direction of Swap. True if swapping to RUNE.
|
|
47
|
+
* @returns swap output object - output - fee - slip
|
|
48
|
+
*/
|
|
49
|
+
export declare const getDoubleSwap: (inputAmount: CryptoAmount, pool1: LiquidityPool, pool2: LiquidityPool, thorchainCache: ThorchainCache) => Promise<SwapOutput>;
|
|
50
|
+
/**
|
|
51
|
+
* Works out the required inbound or outbound fee based on the chain.
|
|
52
|
+
* Call getInboundDetails to get the current gasRate
|
|
53
|
+
*
|
|
54
|
+
* @param sourceAsset
|
|
55
|
+
* @param gasRate
|
|
56
|
+
* @see https://dev.thorchain.org/thorchain-dev/thorchain-and-fees#fee-calcuation-by-chain
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
export declare const calcNetworkFee: (asset: Asset, gasRate: BigNumber) => CryptoAmount;
|
|
60
|
+
/**
|
|
61
|
+
* Return the chain for a given Asset This method should live somewhere else.
|
|
62
|
+
* @param chain
|
|
63
|
+
* @returns the gas asset type for the given chain
|
|
64
|
+
*/
|
|
65
|
+
export declare const getChainAsset: (chain: Chain) => Asset;
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param chain - input chain string
|
|
69
|
+
* @returns - returns correct chain from string
|
|
70
|
+
*/
|
|
71
|
+
export declare const getChain: (chain: string) => Chain;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
+
import { LastBlock, Pool, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
|
|
3
|
+
export declare type ThornodeConfig = {
|
|
4
|
+
apiRetries: number;
|
|
5
|
+
thornodeBaseUrls: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare class Thornode {
|
|
8
|
+
private config;
|
|
9
|
+
private network;
|
|
10
|
+
private transactionsApi;
|
|
11
|
+
private queueApi;
|
|
12
|
+
private networkApi;
|
|
13
|
+
private poolsApi;
|
|
14
|
+
constructor(network?: Network, config?: ThornodeConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Returns the oubound transactions held by THORChain due to outbound delay
|
|
17
|
+
* May be empty if there are no transactions
|
|
18
|
+
*
|
|
19
|
+
* @returns {ScheduledQueueItem} Array
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
getscheduledQueue(): Promise<TxOutItem[]>;
|
|
23
|
+
getTxData(txHash: string): Promise<TxResponse>;
|
|
24
|
+
getLastBlock(height?: number): Promise<LastBlock[]>;
|
|
25
|
+
getPools(): Promise<Pool[]>;
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xchainjs/xchain-thorchain-query",
|
|
3
|
+
"version": "0.1.0-alpha",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Thorchain query module that is resposible for estimating swap calculations and add/remove liquidity for thorchain ",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"XChain",
|
|
8
|
+
"Thorchain-query"
|
|
9
|
+
],
|
|
10
|
+
"author": "THORChain",
|
|
11
|
+
"homepage": "https://github.com/xchainjs/xchainjs-lib#readme",
|
|
12
|
+
"main": "lib/index.js",
|
|
13
|
+
"module": "lib/index.esm.js",
|
|
14
|
+
"typings": "lib/index.d.ts",
|
|
15
|
+
"directories": {
|
|
16
|
+
"lib": "lib",
|
|
17
|
+
"test": "__tests__"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git@github.com:xchainjs/xchainjs-lib.git"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"clean": "rimraf lib/**",
|
|
28
|
+
"build": "yarn clean && rollup -c",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"e2e": "jest --config jest.config.e2e.js",
|
|
31
|
+
"lint": "eslint \"{src,__tests__}/**/*.ts\" --fix --max-warnings 0",
|
|
32
|
+
"prepublishOnly": "yarn build",
|
|
33
|
+
"postversion": "git push --follow-tags"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@xchainjs/xchain-client": "^0.13.0",
|
|
37
|
+
"@xchainjs/xchain-midgard": "^0.1.0-alpha2",
|
|
38
|
+
"@xchainjs/xchain-thornode": "^0.1.0-alpha4",
|
|
39
|
+
"@xchainjs/xchain-util": "^0.9.0",
|
|
40
|
+
"axios": "^0.25.0",
|
|
41
|
+
"axios-retry": "^3.2.5",
|
|
42
|
+
"bignumber.js": "^9.0.0",
|
|
43
|
+
"rimraf": "~3.0.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@xchainjs/xchain-client": "^0.13.0",
|
|
47
|
+
"@xchainjs/xchain-midgard": "^0.1.0-alpha2",
|
|
48
|
+
"@xchainjs/xchain-thornode": "^0.1.0-alpha4",
|
|
49
|
+
"@xchainjs/xchain-util": "^0.9.0",
|
|
50
|
+
"axios": "^0.25.0",
|
|
51
|
+
"axios-retry": "^3.2.5",
|
|
52
|
+
"bignumber.js": "^9.0.0",
|
|
53
|
+
"rimraf": "~3.0.2"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|