@xchainjs/xchain-thorchain-amm 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 +106 -0
- package/lib/index.esm.js +1732 -0
- package/lib/index.js +1746 -0
- package/lib/xchain-thorchain-amm/src/chain-defaults.d.ts +4 -0
- package/lib/xchain-thorchain-amm/src/crypto-amount.d.ts +37 -0
- package/lib/xchain-thorchain-amm/src/index.d.ts +6 -0
- package/lib/xchain-thorchain-amm/src/liquidity-pool-cache.d.ts +73 -0
- package/lib/xchain-thorchain-amm/src/liquidity-pool.d.ts +17 -0
- package/lib/xchain-thorchain-amm/src/thorchain-amm.d.ts +115 -0
- package/lib/xchain-thorchain-amm/src/types.d.ts +90 -0
- package/lib/xchain-thorchain-amm/src/utils/index.d.ts +3 -0
- package/lib/xchain-thorchain-amm/src/utils/liquidity.d.ts +33 -0
- package/lib/xchain-thorchain-amm/src/utils/midgard.d.ts +44 -0
- package/lib/xchain-thorchain-amm/src/utils/swap.d.ts +68 -0
- package/lib/xchain-thorchain-amm/src/utils/thornode.d.ts +57 -0
- package/lib/xchain-thorchain-amm/src/wallet.d.ts +63 -0
- package/package.json +102 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Asset, AssetAmount, BaseAmount } from '@xchainjs/xchain-util';
|
|
2
|
+
import { BigNumber } from 'bignumber.js';
|
|
3
|
+
declare type CryptoNumeric = CryptoAmount | number | BigNumber;
|
|
4
|
+
/**
|
|
5
|
+
* Utility Class to combine an amount (asset/base) with the Asset
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare class CryptoAmount {
|
|
9
|
+
baseAmount: BaseAmount;
|
|
10
|
+
readonly asset: Asset;
|
|
11
|
+
constructor(amount: BaseAmount, asset: Asset);
|
|
12
|
+
plus(v: CryptoAmount): CryptoAmount;
|
|
13
|
+
minus(v: CryptoAmount): CryptoAmount;
|
|
14
|
+
times(v: CryptoNumeric): CryptoAmount;
|
|
15
|
+
div(v: CryptoNumeric): CryptoAmount;
|
|
16
|
+
lt(v: CryptoAmount): boolean;
|
|
17
|
+
lte(v: CryptoAmount): boolean;
|
|
18
|
+
gt(v: CryptoAmount): boolean;
|
|
19
|
+
gte(v: CryptoAmount): boolean;
|
|
20
|
+
eq(v: CryptoAmount): boolean;
|
|
21
|
+
formatedAssetString(): string;
|
|
22
|
+
assetAmountFixedString(): string;
|
|
23
|
+
get assetAmount(): AssetAmount;
|
|
24
|
+
/**
|
|
25
|
+
* This guard protects against trying to perform math with different assets
|
|
26
|
+
*
|
|
27
|
+
* Example.
|
|
28
|
+
* const x = new CryptoAmount(baseAmount(1),AssetBTC)
|
|
29
|
+
* const y = new CryptoAmount(baseAmount(1),AssetETH)
|
|
30
|
+
*
|
|
31
|
+
* x.plus(y) <- will throw error "cannot perform math on 2 diff assets BTC.BTC ETH.ETH
|
|
32
|
+
*
|
|
33
|
+
* @param v - CryptoNumeric
|
|
34
|
+
*/
|
|
35
|
+
private check;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Asset } from '@xchainjs/xchain-util';
|
|
2
|
+
import { BigNumber } from 'bignumber.js';
|
|
3
|
+
import { CryptoAmount } from './crypto-amount';
|
|
4
|
+
import { LiquidityPool } from './liquidity-pool';
|
|
5
|
+
import { SwapOutput } from './types';
|
|
6
|
+
import { Midgard } from './utils/midgard';
|
|
7
|
+
/**
|
|
8
|
+
* This class manages retrieving information from up to date Thorchain Liquidity Pools
|
|
9
|
+
*/
|
|
10
|
+
export declare class LiquidityPoolCache {
|
|
11
|
+
private midgard;
|
|
12
|
+
private poolCache;
|
|
13
|
+
private expirePoolCacheMillis;
|
|
14
|
+
/**
|
|
15
|
+
* Contrustor to create a LiquidityPoolCache
|
|
16
|
+
*
|
|
17
|
+
* @param midgard - an instance of the midgard API (could be pointing to stagenet,testnet,mainnet)
|
|
18
|
+
* @param expirePoolCacheMillis - how long should the pools be cached before expiry
|
|
19
|
+
* @returns LiquidityPoolCache
|
|
20
|
+
*/
|
|
21
|
+
constructor(midgard: Midgard, expirePoolCacheMillis?: number);
|
|
22
|
+
/**
|
|
23
|
+
* Gets the exchange rate of the from asset in terms on the to asset
|
|
24
|
+
*
|
|
25
|
+
* @param asset - cannot be RUNE.
|
|
26
|
+
* @returns Promise<BigNumber>
|
|
27
|
+
*/
|
|
28
|
+
getExchangeRate(from: Asset, to: Asset): Promise<BigNumber>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the Liquidity Pool for a given Asset
|
|
31
|
+
*
|
|
32
|
+
* @param asset - cannot be RUNE, since Rune is the other side of each pool.
|
|
33
|
+
* @returns Promise<LiquidityPool>
|
|
34
|
+
*/
|
|
35
|
+
getPoolForAsset(asset: Asset): Promise<LiquidityPool>;
|
|
36
|
+
/**
|
|
37
|
+
* Get all the Liquidity Pools currently cached.
|
|
38
|
+
* if the cache is expired, the pools wioll be re-fetched from midgard
|
|
39
|
+
*
|
|
40
|
+
* @returns Promise<Record<string, LiquidityPool>>
|
|
41
|
+
*/
|
|
42
|
+
getPools(): Promise<Record<string, LiquidityPool>>;
|
|
43
|
+
/**
|
|
44
|
+
* Refreshes the Pool Cache
|
|
45
|
+
*
|
|
46
|
+
* NOTE: do not call refereshPoolCache() directly, call getPools() instead
|
|
47
|
+
* which will refresh the cache if it's expired
|
|
48
|
+
*/
|
|
49
|
+
private refereshPoolCache;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* Calcuate the expected slip, output & swapFee given the current pool depths
|
|
53
|
+
*
|
|
54
|
+
* swapFee - the amount of asset lost according to slip calculations
|
|
55
|
+
* slip - the percent (0-1) of original amount lost to slipfees
|
|
56
|
+
* output - the amount of asset expected from the swap *
|
|
57
|
+
*
|
|
58
|
+
* @param inputAmount - CryptoAmount amount to swap from
|
|
59
|
+
* @param destinationAsset - destimation Asset to swap to
|
|
60
|
+
* @returns SwapOutput - swap output object - output - fee - slip
|
|
61
|
+
*/
|
|
62
|
+
getExpectedSwapOutput(inputAmount: CryptoAmount, destinationAsset: Asset): Promise<SwapOutput>;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the exchange of a CryptoAmount to a different Asset
|
|
65
|
+
*
|
|
66
|
+
* Ex. convert(input:100 BUSD, outAsset: BTC) -> 0.0001234 BTC
|
|
67
|
+
*
|
|
68
|
+
* @param input - amount/asset to convert to outAsset
|
|
69
|
+
* @param ouAsset - the Asset you want to convert to
|
|
70
|
+
* @returns CryptoAmount of input
|
|
71
|
+
*/
|
|
72
|
+
convert(input: CryptoAmount, outAsset: Asset): Promise<CryptoAmount>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
private pool;
|
|
9
|
+
readonly assetBalance: BaseAmount;
|
|
10
|
+
readonly runeBalance: BaseAmount;
|
|
11
|
+
readonly asset: Asset;
|
|
12
|
+
readonly assetString: string;
|
|
13
|
+
readonly runeToAssetRatio: BigNumber;
|
|
14
|
+
readonly assetToRuneRatio: BigNumber;
|
|
15
|
+
constructor(pool: PoolDetail);
|
|
16
|
+
isAvailable(): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Asset, Chain } from '@xchainjs/xchain-util';
|
|
2
|
+
import { CryptoAmount } from './crypto-amount';
|
|
3
|
+
import { ChainAttributes, EstimateSwapParams, SwapEstimate, SwapSubmitted, TotalFees } from './types';
|
|
4
|
+
import { Midgard } from './utils/midgard';
|
|
5
|
+
import { Wallet } from './wallet';
|
|
6
|
+
/**
|
|
7
|
+
* THORChain Class for interacting with THORChain.
|
|
8
|
+
* Recommended main class to use for swapping with THORChain
|
|
9
|
+
* Has access to Midgard and THORNode data
|
|
10
|
+
*/
|
|
11
|
+
export declare class ThorchainAMM {
|
|
12
|
+
private midgard;
|
|
13
|
+
private allPools;
|
|
14
|
+
private chainAttributes;
|
|
15
|
+
/**
|
|
16
|
+
* Contructor to create a ThorchainAMM
|
|
17
|
+
*
|
|
18
|
+
* @param midgard - an instance of the midgard API (could be pointing to stagenet,testnet,mainnet)
|
|
19
|
+
* @param expirePoolCacheMillis - how long should the pools be cached before expiry
|
|
20
|
+
* @param chainAttributes - atrributes used to calculate waitTime & conf counting
|
|
21
|
+
* @returns ThorchainAMM
|
|
22
|
+
*/
|
|
23
|
+
constructor(midgard: Midgard, expirePoolCacheMillis?: number, chainAttributes?: Record<Chain, ChainAttributes>);
|
|
24
|
+
/**
|
|
25
|
+
* Provides a swap estimate for the given swap detail. Will check the params for errors before trying to get the estimate.
|
|
26
|
+
* 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)
|
|
27
|
+
*
|
|
28
|
+
* @param params - amount to swap
|
|
29
|
+
|
|
30
|
+
* @returns The SwapEstimate
|
|
31
|
+
*/
|
|
32
|
+
estimateSwap(params: EstimateSwapParams): Promise<SwapEstimate>;
|
|
33
|
+
/**
|
|
34
|
+
* Convinience method to convert TotalFees to a different CryptoAmount
|
|
35
|
+
*
|
|
36
|
+
* TotalFees are always calculated and returned in RUNE, this method can
|
|
37
|
+
* be used to show the equivalent fees in another Asset Type
|
|
38
|
+
*
|
|
39
|
+
* @param fees: TotalFees - the fees you want to convert
|
|
40
|
+
* @param asset: Asset - the asset you want the fees converted to
|
|
41
|
+
* @returns TotalFees in asset
|
|
42
|
+
*/
|
|
43
|
+
getFeesIn(fees: TotalFees, asset: Asset): Promise<TotalFees>;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the exchange of a CryptoAmount to a different Asset
|
|
46
|
+
*
|
|
47
|
+
* Ex. convert(input:100 BUSD, outAsset: BTC) -> 0.0001234 BTC
|
|
48
|
+
*
|
|
49
|
+
* @param input - amount/asset to convert to outAsset
|
|
50
|
+
* @param ouAsset - the Asset you want to convert to
|
|
51
|
+
* @returns CryptoAmount of input
|
|
52
|
+
*/
|
|
53
|
+
convert(input: CryptoAmount, outAsset: Asset): Promise<CryptoAmount>;
|
|
54
|
+
/**
|
|
55
|
+
* Conducts a swap with the given inputs. Should be called after estimateSwap() to ensure the swap is valid
|
|
56
|
+
*
|
|
57
|
+
* @param wallet - wallet to use
|
|
58
|
+
* @param params - swap paraps
|
|
59
|
+
* @param destinationAddress - were to send the output of the swap
|
|
60
|
+
* @param affiliateAddress - were to send the affilate Address, should be a THOR address (optional)
|
|
61
|
+
* @param interfaceID - id if the calling interface (optional)
|
|
62
|
+
* @returns {SwapSubmitted} - Tx Hash, URL of BlockExplorer and expected wait time.
|
|
63
|
+
*/
|
|
64
|
+
protected doSwap(wallet: Wallet, params: EstimateSwapParams, destinationAddress: string, affiliateAddress?: string, interfaceID?: number): Promise<SwapSubmitted>;
|
|
65
|
+
/**
|
|
66
|
+
* Basic Checks for swap information
|
|
67
|
+
* @param params
|
|
68
|
+
*/
|
|
69
|
+
private isValidSwap;
|
|
70
|
+
/**
|
|
71
|
+
* Does the calculations for the swap.
|
|
72
|
+
* Used by estimateSwap
|
|
73
|
+
*
|
|
74
|
+
* @param params
|
|
75
|
+
* @param sourceInboundDetails
|
|
76
|
+
* @param destinationInboundDetails
|
|
77
|
+
* @param sourcePool
|
|
78
|
+
* @param destinationPool
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
private calcSwapEstimate;
|
|
82
|
+
/**
|
|
83
|
+
* Looks for errors or issues within swap prams before doing the swap.
|
|
84
|
+
*
|
|
85
|
+
*
|
|
86
|
+
* @param params
|
|
87
|
+
* @param estimate
|
|
88
|
+
* @param sourcePool
|
|
89
|
+
* @param sourceInboundDetails
|
|
90
|
+
* @param destinationPool
|
|
91
|
+
* @param destinationInboundDetails
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
private getSwapEstimateErrors;
|
|
95
|
+
private checkCoverFees;
|
|
96
|
+
/**
|
|
97
|
+
* Works out how long an outbound Tx will be held by THORChain before sending.
|
|
98
|
+
*
|
|
99
|
+
* @param outboundAmount: CryptoAmount being sent.
|
|
100
|
+
* @returns required delay in seconds
|
|
101
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/manager_txout_current.go#L548
|
|
102
|
+
*/
|
|
103
|
+
outboundDelay(outboundAmount: CryptoAmount): Promise<number>;
|
|
104
|
+
/**
|
|
105
|
+
* Finds the required confCount required for an inbound or outbound Tx to THORChain. Estimate based on Midgard data only.
|
|
106
|
+
*
|
|
107
|
+
* 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.
|
|
108
|
+
* ConfCount is then times by 6 seconds.
|
|
109
|
+
*
|
|
110
|
+
* @param inbound: CryptoAmount - amount/asset of the outbound amount.
|
|
111
|
+
* @returns time in seconds before a Tx is confirmed by THORChain
|
|
112
|
+
* @see https://docs.thorchain.org/chain-clients/overview
|
|
113
|
+
*/
|
|
114
|
+
private confCounting;
|
|
115
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Address, FeeOption } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
3
|
+
import { BigNumber } from 'bignumber.js';
|
|
4
|
+
import { CryptoAmount } from './crypto-amount';
|
|
5
|
+
import { LiquidityPool } from './liquidity-pool';
|
|
6
|
+
export declare type TotalFees = {
|
|
7
|
+
inboundFee: CryptoAmount;
|
|
8
|
+
swapFee: CryptoAmount;
|
|
9
|
+
outboundFee: CryptoAmount;
|
|
10
|
+
affiliateFee: CryptoAmount;
|
|
11
|
+
};
|
|
12
|
+
export declare type SwapEstimate = {
|
|
13
|
+
totalFees: TotalFees;
|
|
14
|
+
slipPercentage: BigNumber;
|
|
15
|
+
netOutput: CryptoAmount;
|
|
16
|
+
waitTimeSeconds: number;
|
|
17
|
+
canSwap: boolean;
|
|
18
|
+
errors?: string[];
|
|
19
|
+
};
|
|
20
|
+
export declare type PoolCache = {
|
|
21
|
+
lastRefreshed: number;
|
|
22
|
+
pools: Record<string, LiquidityPool>;
|
|
23
|
+
};
|
|
24
|
+
export declare type MidgardConfig = {
|
|
25
|
+
apiRetries: number;
|
|
26
|
+
midgardBaseUrls: string[];
|
|
27
|
+
};
|
|
28
|
+
export declare type EstimateSwapParams = {
|
|
29
|
+
input: CryptoAmount;
|
|
30
|
+
destinationAsset: Asset;
|
|
31
|
+
affiliateFeePercent?: number;
|
|
32
|
+
slipLimit?: BigNumber;
|
|
33
|
+
};
|
|
34
|
+
export declare type ExecuteSwap = {
|
|
35
|
+
fromBaseAmount: BaseAmount;
|
|
36
|
+
sourceAsset: Asset;
|
|
37
|
+
destinationAsset: Asset;
|
|
38
|
+
limit: BaseAmount;
|
|
39
|
+
destinationAddress: Address;
|
|
40
|
+
affiliateAddress: Address;
|
|
41
|
+
affiliateFee: BaseAmount;
|
|
42
|
+
feeOption?: FeeOption;
|
|
43
|
+
interfaceID: number;
|
|
44
|
+
waitTimeSeconds: number;
|
|
45
|
+
};
|
|
46
|
+
export declare type SwapSubmitted = {
|
|
47
|
+
hash: string;
|
|
48
|
+
url: string;
|
|
49
|
+
waitTimeSeconds: number;
|
|
50
|
+
};
|
|
51
|
+
export declare type DepositParams = {
|
|
52
|
+
walletIndex?: number;
|
|
53
|
+
asset: Asset;
|
|
54
|
+
amount: BaseAmount;
|
|
55
|
+
feeOption: FeeOption;
|
|
56
|
+
memo: string;
|
|
57
|
+
};
|
|
58
|
+
export declare type SwapOutput = {
|
|
59
|
+
output: BaseAmount;
|
|
60
|
+
swapFee: BaseAmount;
|
|
61
|
+
slip: BigNumber;
|
|
62
|
+
};
|
|
63
|
+
export declare type UnitData = {
|
|
64
|
+
liquidityUnits: BaseAmount;
|
|
65
|
+
totalUnits: BaseAmount;
|
|
66
|
+
};
|
|
67
|
+
export declare type LiquidityData = {
|
|
68
|
+
rune: BaseAmount;
|
|
69
|
+
asset: BaseAmount;
|
|
70
|
+
};
|
|
71
|
+
export declare type Block = {
|
|
72
|
+
current: number;
|
|
73
|
+
lastAdded: number;
|
|
74
|
+
fullProtection: number;
|
|
75
|
+
};
|
|
76
|
+
export declare type Coverage = {
|
|
77
|
+
poolRatio: BaseAmount;
|
|
78
|
+
};
|
|
79
|
+
export declare type InboundDetail = {
|
|
80
|
+
vault: string;
|
|
81
|
+
router?: string;
|
|
82
|
+
haltedChain: boolean;
|
|
83
|
+
haltedTrading: boolean;
|
|
84
|
+
haltedLP: boolean;
|
|
85
|
+
gas_rate: BigNumber;
|
|
86
|
+
};
|
|
87
|
+
export declare type ChainAttributes = {
|
|
88
|
+
blockReward: number;
|
|
89
|
+
avgBlockTimeInSecs: number;
|
|
90
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BaseAmount } from '@xchainjs/xchain-util';
|
|
2
|
+
import { BigNumber } from 'bignumber.js';
|
|
3
|
+
import { LiquidityPool } from '../liquidity-pool';
|
|
4
|
+
import { Block, LiquidityData, UnitData } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param liquidity - asset amount added
|
|
8
|
+
* @param pool - pool depths
|
|
9
|
+
* @returns liquidity units
|
|
10
|
+
*/
|
|
11
|
+
export declare const getLiquidityUnits: (liquidity: LiquidityData, pool: LiquidityPool) => BaseAmount;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param unitData
|
|
15
|
+
* @param pool
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare const getPoolShare: (unitData: UnitData, pool: LiquidityPool) => LiquidityData;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param liquidity
|
|
22
|
+
* @param pool
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare const getSlipOnLiquidity: (liquidity: LiquidityData, pool: LiquidityPool) => BigNumber;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param liquidity
|
|
29
|
+
* @param pool
|
|
30
|
+
* @param block
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export declare const getLiquidityProtectionData: (liquidity: LiquidityData, pool: LiquidityPool, block: Block) => number;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
+
import { InboundAddressesItem, PoolDetail } from '@xchainjs/xchain-midgard';
|
|
3
|
+
import { Chain } from '@xchainjs/xchain-util';
|
|
4
|
+
import { CryptoAmount } from '../crypto-amount';
|
|
5
|
+
import { InboundDetail, MidgardConfig } from '../types';
|
|
6
|
+
export declare class Midgard {
|
|
7
|
+
private config;
|
|
8
|
+
private network;
|
|
9
|
+
private midgardApis;
|
|
10
|
+
constructor(network?: Network, config?: MidgardConfig);
|
|
11
|
+
private getMimirDetails;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @returns an array of Pools
|
|
15
|
+
*/
|
|
16
|
+
getPools(): Promise<PoolDetail[]>;
|
|
17
|
+
getAllInboundAddresses(): Promise<InboundAddressesItem[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the Inbound Details for a given array of Chains.
|
|
20
|
+
* Will check if chain is THOR.
|
|
21
|
+
* @param chains - external chains
|
|
22
|
+
* @returns inbound details of given chains
|
|
23
|
+
*/
|
|
24
|
+
getInboundDetails(chains: Chain[]): Promise<InboundDetail[]>;
|
|
25
|
+
private getConstantsDetails;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @returns the outbound Tx Value in RUNE (Basemount)
|
|
29
|
+
*/
|
|
30
|
+
getScheduledOutboundValue(): Promise<CryptoAmount>;
|
|
31
|
+
/**
|
|
32
|
+
* Function that wraps Mimir and Constants to return the value from a given constant name. Searchs Mimir first.
|
|
33
|
+
*
|
|
34
|
+
* @param networkValueName the network value to be used to search the contsants
|
|
35
|
+
* @returns the mimir or constants value
|
|
36
|
+
*/
|
|
37
|
+
getNetworkValueByNames(networkValueNames: string[]): Promise<Record<string, string>>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the latest block using the Health endpoint within Midgard
|
|
40
|
+
*
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
getLatestBlockHeight(): Promise<number>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Address } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Asset, BaseAmount, 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 { 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: BaseAmount, pool: LiquidityPool, toRune: boolean) => BaseAmount;
|
|
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: BaseAmount, 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: BaseAmount, pool: LiquidityPool, toRune: boolean) => BaseAmount;
|
|
32
|
+
export declare const getDoubleSwapOutput: (inputAmount: BaseAmount, pool1: LiquidityPool, pool2: LiquidityPool) => BaseAmount;
|
|
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: BaseAmount, pool: LiquidityPool, toRune: boolean) => SwapOutput;
|
|
40
|
+
export declare const getDoubleSwapSlip: (inputAmount: BaseAmount, pool1: LiquidityPool, pool2: LiquidityPool) => BigNumber;
|
|
41
|
+
export declare const getValueOfRuneInAsset: (inputRune: BaseAmount, pool: LiquidityPool) => BaseAmount;
|
|
42
|
+
export declare const getValueOfAssetInRune: (inputAsset: BaseAmount, pool: LiquidityPool) => BaseAmount;
|
|
43
|
+
export declare const getDoubleSwapFee: (inputAmount: BaseAmount, pool1: LiquidityPool, pool2: LiquidityPool) => BaseAmount;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param inputAmount - amount to swap
|
|
47
|
+
* @param pool - Pool Data, RUNE and ASSET Depths
|
|
48
|
+
* @param toRune - Direction of Swap. True if swapping to RUNE.
|
|
49
|
+
* @returns swap output object - output - fee - slip
|
|
50
|
+
*/
|
|
51
|
+
export declare const getDoubleSwap: (inputAmount: BaseAmount, pool1: LiquidityPool, pool2: LiquidityPool) => SwapOutput;
|
|
52
|
+
export declare const getContractAddressFromAsset: (asset: Asset) => Address;
|
|
53
|
+
/**
|
|
54
|
+
* Works out the required inbound or outbound fee based on the chain.
|
|
55
|
+
* Call getInboundDetails to get the current gasRate
|
|
56
|
+
*
|
|
57
|
+
* @param sourceAsset
|
|
58
|
+
* @param gasRate
|
|
59
|
+
* @see https://dev.thorchain.org/thorchain-dev/thorchain-and-fees#fee-calcuation-by-chain
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
export declare const calcNetworkFee: (asset: Asset, gasRate: BigNumber) => CryptoAmount;
|
|
63
|
+
/**
|
|
64
|
+
* Return the chain for a given Asset This method should live somewhere else.
|
|
65
|
+
* @param chain
|
|
66
|
+
* @returns the gas asset type for the given chain
|
|
67
|
+
*/
|
|
68
|
+
export declare const getChainAsset: (chain: Chain) => Asset;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
+
import { LastBlock, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
|
|
3
|
+
import { Chain } from '@xchainjs/xchain-util';
|
|
4
|
+
import { ChainAttributes } from '../types';
|
|
5
|
+
export declare type ThornodeConfig = {
|
|
6
|
+
apiRetries: number;
|
|
7
|
+
thornodeBaseUrls: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare enum TxStage {
|
|
10
|
+
INBOUND_CHAIN_UNCONFIRMED = 0,
|
|
11
|
+
CONF_COUNTING = 1,
|
|
12
|
+
TC_PROCESSING = 2,
|
|
13
|
+
OUTBOUND_QUEUED = 3,
|
|
14
|
+
OUTBOUND_CHAIN_UNCONFIRMED = 4,
|
|
15
|
+
OUTBOUND_CHAIN_CONFIRMED = 5
|
|
16
|
+
}
|
|
17
|
+
export declare type TxStatus = {
|
|
18
|
+
stage: TxStage;
|
|
19
|
+
seconds: number;
|
|
20
|
+
};
|
|
21
|
+
export declare class Thornode {
|
|
22
|
+
private config;
|
|
23
|
+
private network;
|
|
24
|
+
private chainAttributes;
|
|
25
|
+
private transactionsApi;
|
|
26
|
+
private queueApi;
|
|
27
|
+
private networkApi;
|
|
28
|
+
constructor(network?: Network, config?: ThornodeConfig, chainAttributes?: Record<Chain, ChainAttributes>);
|
|
29
|
+
/**
|
|
30
|
+
* Returns the oubound transactions held by THORChain due to outbound delay
|
|
31
|
+
* May be empty if there are no transactions
|
|
32
|
+
*
|
|
33
|
+
* @returns {ScheduledQueueItem} Array
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
getscheduledQueue(): Promise<TxOutItem[]>;
|
|
37
|
+
getTxData(txHash: string): Promise<TxResponse>;
|
|
38
|
+
getLastBlock(height?: number): Promise<LastBlock[]>;
|
|
39
|
+
protected getChain: (chain: string) => Chain;
|
|
40
|
+
/**
|
|
41
|
+
* For a given in Tx Hash (as returned by THORChainAMM.DoSwap()), finds the status of any THORChain transaction
|
|
42
|
+
* This function should be polled.
|
|
43
|
+
* @param
|
|
44
|
+
* @param destinationChain
|
|
45
|
+
* @param inboundTxHash
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
checkTx(inboundTxHash: string, sourceChain?: Chain): Promise<TxStatus>;
|
|
49
|
+
/** Stage 1 */
|
|
50
|
+
private checkObservedTx;
|
|
51
|
+
/** Stage 2, THORNode has seen it. See if observed only (conf counting) or it has been processed by THORChain */
|
|
52
|
+
private checkObservedOnly;
|
|
53
|
+
/** Stage 3 */
|
|
54
|
+
private checkOutboundQueue;
|
|
55
|
+
/** Stage 4 */
|
|
56
|
+
private checkOutboundTx;
|
|
57
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Balance, Network, TxHash, XChainClient } from '@xchainjs/xchain-client';
|
|
2
|
+
import { InboundAddressesItem } from '@xchainjs/xchain-midgard/src/generated/midgardApi';
|
|
3
|
+
import { Asset, BaseAmount, Chain } from '@xchainjs/xchain-util';
|
|
4
|
+
import { ethers } from 'ethers';
|
|
5
|
+
import { DepositParams, ExecuteSwap, SwapSubmitted } from './types';
|
|
6
|
+
declare type AllBalances = {
|
|
7
|
+
chain: Chain;
|
|
8
|
+
address: string;
|
|
9
|
+
balances: Balance[] | string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Wallet Class for managing all xchain-* wallets with a mnemonic seed.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Wallet {
|
|
15
|
+
private network;
|
|
16
|
+
clients: Record<string, XChainClient>;
|
|
17
|
+
private asgardAssets;
|
|
18
|
+
private midgard;
|
|
19
|
+
/**
|
|
20
|
+
* Contructor to create a Wallet
|
|
21
|
+
*
|
|
22
|
+
* @param network - stagenet,testnet,mainnet
|
|
23
|
+
* @param phrase - mnemonic phrase
|
|
24
|
+
* @returns Wallet
|
|
25
|
+
*/
|
|
26
|
+
constructor(network: Network, phrase: string);
|
|
27
|
+
/**
|
|
28
|
+
* Fetch balances for all wallets
|
|
29
|
+
*
|
|
30
|
+
* @returns AllBalances[]
|
|
31
|
+
*/
|
|
32
|
+
getAllBalances(): Promise<AllBalances[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Executes a Swap from THORChainAMM.doSwap()
|
|
35
|
+
*
|
|
36
|
+
* @param swap object with all the required details for a swap.
|
|
37
|
+
* @returns transaction details and explorer url
|
|
38
|
+
* @see ThorchainAMM.doSwap()
|
|
39
|
+
*/
|
|
40
|
+
executeSwap(swap: ExecuteSwap): Promise<SwapSubmitted>;
|
|
41
|
+
private constructSwapMemo;
|
|
42
|
+
private validateSwap;
|
|
43
|
+
private swapRuneTo;
|
|
44
|
+
private swapNonRune;
|
|
45
|
+
private updateAsgardAddresses;
|
|
46
|
+
/**
|
|
47
|
+
* Transaction to THORChain inbound address.
|
|
48
|
+
*
|
|
49
|
+
* @param {DepositParams} params The transaction options.
|
|
50
|
+
* @returns {TxHash} The transaction hash.
|
|
51
|
+
*
|
|
52
|
+
* @throws {"halted chain"} Thrown if chain is halted.
|
|
53
|
+
* @throws {"halted trading"} Thrown if trading is halted.
|
|
54
|
+
* @throws {"amount is not approved"} Thrown if the amount is not allowed to spend
|
|
55
|
+
* @throws {"router address is not defined"} Thrown if router address is not defined
|
|
56
|
+
*/
|
|
57
|
+
sendETHDeposit(params: DepositParams): Promise<TxHash>;
|
|
58
|
+
isTCRouterApprovedToSpend(asset: Asset, amount: BaseAmount, walletIndex?: number): Promise<boolean>;
|
|
59
|
+
approveTCRouterToSpend(asset: Asset, amount?: ethers.BigNumber, walletIndex?: number): Promise<ethers.providers.TransactionResponse>;
|
|
60
|
+
private getRouterAddressForChain;
|
|
61
|
+
getAsgardAssets(): Promise<InboundAddressesItem[]>;
|
|
62
|
+
}
|
|
63
|
+
export {};
|