@xchainjs/xchain-thorchain-query 2.0.5 → 2.0.7

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 CHANGED
@@ -5,4 +5,3 @@ export * from './liquidity-pool';
5
5
  export * from './chain-defaults';
6
6
  export * from './types';
7
7
  export * from './utils';
8
- export * from './chain-defaults';
package/lib/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { assetFromString, baseAmount, assetFromStringEx, assetToString, CryptoAmount, isSynthAsset, AssetCryptoAmount, eqAsset, CachedValue, isTradeAsset, isSecuredAsset, assetToBase, assetAmount, TRADE_ASSET_DELIMITER, SYNTH_ASSET_DELIMITER, SECURED_ASSET_DELIMITER, TOKEN_ASSET_DELIMITER } from '@xchainjs/xchain-util';
2
- import { BigNumber } from 'bignumber.js';
2
+ import BigNumber from 'bignumber.js';
3
3
  import { MidgardQuery } from '@xchainjs/xchain-midgard-query';
4
4
  import { Network } from '@xchainjs/xchain-client';
5
5
  import { TransactionsApi, Configuration, QueueApi, NetworkApi, PoolsApi, LiquidityProvidersApi, SaversApi, QuoteApi, MimirApi, ThornamesApi, TradeUnitApi, TradeUnitsApi, TradeAccountApi, TradeAccountsApi, RUNEPoolApi } from '@xchainjs/xchain-thornode';
@@ -88,6 +88,10 @@ const DefaultChainAttributes = {
88
88
  blockReward: 0,
89
89
  avgBlockTimeInSecs: 4, // Average block time for xrp in seconds
90
90
  },
91
+ SOL: {
92
+ blockReward: 0,
93
+ avgBlockTimeInSecs: 0.4, // Average block time for sol in seconds
94
+ },
91
95
  };
92
96
 
93
97
  /**
@@ -131,6 +135,7 @@ const assetUSDC = assetFromStringEx('ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE
131
135
  const AssetBNB = assetFromStringEx('BSC.BNB');
132
136
  const AssetBASE = assetFromStringEx('BASE.ETH');
133
137
  const AssetXRP = assetFromStringEx('XRP.XRP');
138
+ const AssetSOL = assetFromStringEx('SOL.SOL');
134
139
  const BNBChain = 'BNB';
135
140
  const BTCChain = 'BTC';
136
141
  const BCHChain = 'BCH';
@@ -144,6 +149,7 @@ const BSCChain = 'BSC';
144
149
  const THORChain = 'THOR';
145
150
  const BASEChain = 'BASE';
146
151
  const XRPChain = 'XRP';
152
+ const SOLChain = 'SOL';
147
153
  const THORCHAIN_DECIMAL = 8;
148
154
  const isAssetRuneNative = (asset) => assetToString(asset) === assetToString(AssetRuneNative);
149
155
 
@@ -190,6 +196,8 @@ const getChainAsset = (chain) => {
190
196
  return AssetBASE;
191
197
  case XRPChain:
192
198
  return AssetXRP;
199
+ case SOLChain:
200
+ return AssetSOL;
193
201
  default:
194
202
  throw Error('Unknown chain');
195
203
  }
@@ -249,6 +257,8 @@ const calcNetworkFee = (asset, inbound) => {
249
257
  return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetBASE);
250
258
  case XRPChain:
251
259
  return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetXRP);
260
+ case SOLChain:
261
+ return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetSOL);
252
262
  }
253
263
  throw new Error(`could not calculate inbound fee for ${asset.chain}`);
254
264
  };
@@ -287,7 +297,11 @@ const calcOutboundFee = (asset, inbound) => {
287
297
  case MAYAChain:
288
298
  return new AssetCryptoAmount(baseAmount(2000000), AssetMAYA);
289
299
  case BASEChain:
290
- return new AssetCryptoAmount(baseAmount(2000000), AssetBASE);
300
+ return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetBASE);
301
+ case XRPChain:
302
+ return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetXRP);
303
+ case SOLChain:
304
+ return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetSOL);
291
305
  }
292
306
  throw new Error(`could not calculate outbound fee for ${asset.chain}`);
293
307
  };
@@ -3165,4 +3179,4 @@ class TransactionStage {
3165
3179
  }
3166
3180
  }
3167
3181
 
3168
- export { AVAXChain, AddLpStatus, AddSaverStatus, AssetATOM, AssetAVAX, AssetBASE, AssetBCH, AssetBNB, AssetBSC, AssetBTC, AssetDOGE, AssetETH, AssetLTC, AssetMAYA, AssetRuneNative, AssetXRP, BASEChain, BCHChain, BNBChain, BSCChain, BTCChain, DOGEChain, DefaultChainAttributes, ETHChain, GAIAChain, InboundStatus, LTCChain, LiquidityPool, MAYAChain, RefundStatus, SwapStatus, THORCHAIN_DECIMAL, THORChain, ThorchainCache, ThorchainQuery, Thornode, TransactionStage, TxType, WithdrawStatus, XRPChain, assetUSDC, calcNetworkFee, getCryptoAmountWithNotation, getLiquidityProtectionData, getLiquidityUnits, getPoolShare, getSlipOnLiquidity, isAssetRuneNative };
3182
+ export { AVAXChain, AddLpStatus, AddSaverStatus, AssetATOM, AssetAVAX, AssetBASE, AssetBCH, AssetBNB, AssetBSC, AssetBTC, AssetDOGE, AssetETH, AssetLTC, AssetMAYA, AssetRuneNative, AssetSOL, AssetXRP, BASEChain, BCHChain, BNBChain, BSCChain, BTCChain, DOGEChain, DefaultChainAttributes, ETHChain, GAIAChain, InboundStatus, LTCChain, LiquidityPool, MAYAChain, RefundStatus, SOLChain, SwapStatus, THORCHAIN_DECIMAL, THORChain, ThorchainCache, ThorchainQuery, Thornode, TransactionStage, TxType, WithdrawStatus, XRPChain, assetUSDC, calcNetworkFee, getCryptoAmountWithNotation, getLiquidityProtectionData, getLiquidityUnits, getPoolShare, getSlipOnLiquidity, isAssetRuneNative };
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var xchainUtil = require('@xchainjs/xchain-util');
4
- var bignumber_js = require('bignumber.js');
4
+ var BigNumber = require('bignumber.js');
5
5
  var xchainMidgardQuery = require('@xchainjs/xchain-midgard-query');
6
6
  var xchainClient = require('@xchainjs/xchain-client');
7
7
  var xchainThornode = require('@xchainjs/xchain-thornode');
@@ -10,6 +10,7 @@ var axiosRetry = require('axios-retry');
10
10
 
11
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
12
 
13
+ var BigNumber__default = /*#__PURE__*/_interopDefault(BigNumber);
13
14
  var axios__default = /*#__PURE__*/_interopDefault(axios);
14
15
  var axiosRetry__default = /*#__PURE__*/_interopDefault(axiosRetry);
15
16
 
@@ -95,6 +96,10 @@ const DefaultChainAttributes = {
95
96
  blockReward: 0,
96
97
  avgBlockTimeInSecs: 4, // Average block time for xrp in seconds
97
98
  },
99
+ SOL: {
100
+ blockReward: 0,
101
+ avgBlockTimeInSecs: 0.4, // Average block time for sol in seconds
102
+ },
98
103
  };
99
104
 
100
105
  /**
@@ -138,6 +143,7 @@ const assetUSDC = xchainUtil.assetFromStringEx('ETH.USDC-0XA0B86991C6218B36C1D19
138
143
  const AssetBNB = xchainUtil.assetFromStringEx('BSC.BNB');
139
144
  const AssetBASE = xchainUtil.assetFromStringEx('BASE.ETH');
140
145
  const AssetXRP = xchainUtil.assetFromStringEx('XRP.XRP');
146
+ const AssetSOL = xchainUtil.assetFromStringEx('SOL.SOL');
141
147
  const BNBChain = 'BNB';
142
148
  const BTCChain = 'BTC';
143
149
  const BCHChain = 'BCH';
@@ -151,6 +157,7 @@ const BSCChain = 'BSC';
151
157
  const THORChain = 'THOR';
152
158
  const BASEChain = 'BASE';
153
159
  const XRPChain = 'XRP';
160
+ const SOLChain = 'SOL';
154
161
  const THORCHAIN_DECIMAL = 8;
155
162
  const isAssetRuneNative = (asset) => xchainUtil.assetToString(asset) === xchainUtil.assetToString(AssetRuneNative);
156
163
 
@@ -197,6 +204,8 @@ const getChainAsset = (chain) => {
197
204
  return AssetBASE;
198
205
  case XRPChain:
199
206
  return AssetXRP;
207
+ case SOLChain:
208
+ return AssetSOL;
200
209
  default:
201
210
  throw Error('Unknown chain');
202
211
  }
@@ -256,6 +265,8 @@ const calcNetworkFee = (asset, inbound) => {
256
265
  return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetBASE);
257
266
  case XRPChain:
258
267
  return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetXRP);
268
+ case SOLChain:
269
+ return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetSOL);
259
270
  }
260
271
  throw new Error(`could not calculate inbound fee for ${asset.chain}`);
261
272
  };
@@ -294,7 +305,11 @@ const calcOutboundFee = (asset, inbound) => {
294
305
  case MAYAChain:
295
306
  return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(2000000), AssetMAYA);
296
307
  case BASEChain:
297
- return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(2000000), AssetBASE);
308
+ return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBASE);
309
+ case XRPChain:
310
+ return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetXRP);
311
+ case SOLChain:
312
+ return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetSOL);
298
313
  }
299
314
  throw new Error(`could not calculate outbound fee for ${asset.chain}`);
300
315
  };
@@ -307,7 +322,7 @@ const calcOutboundFee = (asset, inbound) => {
307
322
  */
308
323
  const getLiquidityUnits = (liquidity, pool) => {
309
324
  const baseAmount8decimals = getBaseAmountWithDiffDecimals(liquidity.asset, 8);
310
- const P = new bignumber_js.BigNumber(pool.thornodeDetails.LP_units);
325
+ const P = new BigNumber__default.default(pool.thornodeDetails.LP_units);
311
326
  const r = liquidity.rune.baseAmount.amount();
312
327
  const a = baseAmount8decimals;
313
328
  const R = pool.runeBalance.amount();
@@ -382,7 +397,7 @@ const getLiquidityProtectionData = (depositValue, poolShare, block) => {
382
397
  const fractionOfFullILPProtection = (currentHeight - heightLastAdded) / blocksforfullprotection;
383
398
  const protectionProgress = Math.min(fractionOfFullILPProtection, 1); // percentage of entitlement, max 100%
384
399
  const result = coverage.times(protectionProgress); // impermanent loss protection result
385
- const maxILP = result.lt(0) ? new bignumber_js.BigNumber(0) : result; // max negative ILP to 0
400
+ const maxILP = result.lt(0) ? new BigNumber__default.default(0) : result; // max negative ILP to 0
386
401
  const ILProtection = {
387
402
  ILProtection: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(maxILP), AssetRuneNative),
388
403
  totalDays: (fractionOfFullILPProtection * 100).toFixed(2),
@@ -969,7 +984,7 @@ class Thornode {
969
984
  }
970
985
 
971
986
  // Constants
972
- const SAME_ASSET_EXCHANGE_RATE = new bignumber_js.BigNumber(1);
987
+ const SAME_ASSET_EXCHANGE_RATE = new BigNumber__default.default(1);
973
988
  const TEN_MINUTES = 10 * 60 * 1000;
974
989
  // Default instances
975
990
  const defaultThornode = new Thornode();
@@ -1125,10 +1140,10 @@ class ThorchainCache {
1125
1140
  chain: chain,
1126
1141
  address: inbound.address,
1127
1142
  router: inbound.router,
1128
- gasRate: new bignumber_js.BigNumber(inbound.gas_rate),
1143
+ gasRate: new BigNumber__default.default(inbound.gas_rate),
1129
1144
  gasRateUnits: inbound.gas_rate_units,
1130
- outboundTxSize: new bignumber_js.BigNumber(inbound.outbound_tx_size),
1131
- outboundFee: new bignumber_js.BigNumber(inbound.outbound_fee),
1145
+ outboundTxSize: new BigNumber__default.default(inbound.outbound_tx_size),
1146
+ outboundFee: new BigNumber__default.default(inbound.outbound_fee),
1132
1147
  haltedChain: (inbound === null || inbound === void 0 ? void 0 : inbound.halted) || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],
1133
1148
  haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],
1134
1149
  haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],
@@ -1140,10 +1155,10 @@ class ThorchainCache {
1140
1155
  chain: THORChain,
1141
1156
  address: '',
1142
1157
  router: '',
1143
- gasRate: new bignumber_js.BigNumber(0),
1158
+ gasRate: new BigNumber__default.default(0),
1144
1159
  gasRateUnits: '',
1145
- outboundTxSize: new bignumber_js.BigNumber(0),
1146
- outboundFee: new bignumber_js.BigNumber(0),
1160
+ outboundTxSize: new BigNumber__default.default(0),
1161
+ outboundFee: new BigNumber__default.default(0),
1147
1162
  haltedChain: false,
1148
1163
  haltedTrading: !!mimirDetails['HALTTRADING'],
1149
1164
  haltedLP: false, //
@@ -1490,7 +1505,7 @@ class ThorchainQuery {
1490
1505
  // Create unit data
1491
1506
  const unitData = {
1492
1507
  liquidityUnits: lpUnits,
1493
- totalUnits: new bignumber_js.BigNumber(assetPool.thornodeDetails.LP_units),
1508
+ totalUnits: new BigNumber__default.default(assetPool.thornodeDetails.LP_units),
1494
1509
  };
1495
1510
  // Calculate pool share
1496
1511
  const poolShare = getPoolShare(unitData, assetPool);
@@ -1558,8 +1573,8 @@ class ThorchainQuery {
1558
1573
  throw Error(`Could not get block data`);
1559
1574
  // Pools total units & Lp's total units
1560
1575
  const unitData = {
1561
- totalUnits: new bignumber_js.BigNumber(poolAsset.thornodeDetails.LP_units),
1562
- liquidityUnits: new bignumber_js.BigNumber(liquidityProvider.units),
1576
+ totalUnits: new BigNumber__default.default(poolAsset.thornodeDetails.LP_units),
1577
+ liquidityUnits: new BigNumber__default.default(liquidityProvider.units),
1563
1578
  };
1564
1579
  const networkValues = yield this.thorchainCache.thornode.getNetworkValues();
1565
1580
  // Create block object
@@ -1634,8 +1649,8 @@ class ThorchainQuery {
1634
1649
  const assetPool = yield this.thorchainCache.getPoolForAsset(params.asset);
1635
1650
  // Calculate pool share
1636
1651
  const poolShare = getPoolShare({
1637
- liquidityUnits: new bignumber_js.BigNumber(memberDetail.position.units),
1638
- totalUnits: new bignumber_js.BigNumber(assetPool.thornodeDetails.LP_units),
1652
+ liquidityUnits: new BigNumber__default.default(memberDetail.position.units),
1653
+ totalUnits: new BigNumber__default.default(assetPool.thornodeDetails.LP_units),
1639
1654
  }, assetPool);
1640
1655
  // Calculate slip on liquidity removal
1641
1656
  const slip = getSlipOnLiquidity({
@@ -3185,6 +3200,7 @@ exports.AssetETH = AssetETH;
3185
3200
  exports.AssetLTC = AssetLTC;
3186
3201
  exports.AssetMAYA = AssetMAYA;
3187
3202
  exports.AssetRuneNative = AssetRuneNative;
3203
+ exports.AssetSOL = AssetSOL;
3188
3204
  exports.AssetXRP = AssetXRP;
3189
3205
  exports.BASEChain = BASEChain;
3190
3206
  exports.BCHChain = BCHChain;
@@ -3198,6 +3214,7 @@ exports.GAIAChain = GAIAChain;
3198
3214
  exports.LTCChain = LTCChain;
3199
3215
  exports.LiquidityPool = LiquidityPool;
3200
3216
  exports.MAYAChain = MAYAChain;
3217
+ exports.SOLChain = SOLChain;
3201
3218
  exports.THORCHAIN_DECIMAL = THORCHAIN_DECIMAL;
3202
3219
  exports.THORChain = THORChain;
3203
3220
  exports.ThorchainCache = ThorchainCache;
@@ -1,6 +1,6 @@
1
- import { Pool } from '@xchainjs/xchain-thornode/lib';
1
+ import { Pool } from '@xchainjs/xchain-thornode';
2
2
  import { Asset, BaseAmount, TokenAsset } from '@xchainjs/xchain-util';
3
- import { BigNumber } from 'bignumber.js';
3
+ import type BigNumber from 'bignumber.js';
4
4
  /**
5
5
  * Represents a Liquidity Pool in Thorchain
6
6
  */
@@ -1,6 +1,6 @@
1
1
  import { MidgardQuery } from '@xchainjs/xchain-midgard-query';
2
2
  import { Address, Asset, Chain, CryptoAmount, SecuredAsset, SynthAsset, TokenAsset, TradeAsset } from '@xchainjs/xchain-util';
3
- import { BigNumber } from 'bignumber.js';
3
+ import BigNumber from 'bignumber.js';
4
4
  import { LiquidityPool } from './liquidity-pool';
5
5
  import { InboundDetail } from './types';
6
6
  import { Thornode } from './utils/thornode';
package/lib/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FeeOption, TxHash } from '@xchainjs/xchain-client';
2
2
  import { LiquidityProviderSummary } from '@xchainjs/xchain-thornode';
3
3
  import { Address, Asset, AssetCryptoAmount, BaseAmount, Chain, CryptoAmount, SecuredAsset, SynthAsset, TokenAsset, TradeAsset, TradeCryptoAmount } from '@xchainjs/xchain-util';
4
- import { BigNumber } from 'bignumber.js';
4
+ import type BigNumber from 'bignumber.js';
5
5
  export type CompatibleAsset = Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset;
6
6
  /**
7
7
  * Represents the total fees associated with a swap.
@@ -13,6 +13,7 @@ export declare const assetUSDC: TokenAsset;
13
13
  export declare const AssetBNB: Asset;
14
14
  export declare const AssetBASE: Asset;
15
15
  export declare const AssetXRP: Asset;
16
+ export declare const AssetSOL: Asset;
16
17
  export declare const BNBChain = "BNB";
17
18
  export declare const BTCChain = "BTC";
18
19
  export declare const BCHChain = "BCH";
@@ -26,5 +27,6 @@ export declare const BSCChain = "BSC";
26
27
  export declare const THORChain = "THOR";
27
28
  export declare const BASEChain = "BASE";
28
29
  export declare const XRPChain = "XRP";
30
+ export declare const SOLChain = "SOL";
29
31
  export declare const THORCHAIN_DECIMAL = 8;
30
32
  export declare const isAssetRuneNative: (asset: AnyAsset) => boolean;
@@ -1,4 +1,4 @@
1
- import { BigNumber } from 'bignumber.js';
1
+ import BigNumber from 'bignumber.js';
2
2
  import { LiquidityPool } from '../liquidity-pool';
3
3
  import { Block, ILProtectionData, LiquidityToAdd, PoolShareDetail, PostionDepositValue, UnitData } from '../types';
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { Asset, AssetCryptoAmount, Chain, CryptoAmount } from '@xchainjs/xchain-util';
2
- import { BigNumber } from 'bignumber.js';
2
+ import type BigNumber from 'bignumber.js';
3
3
  import { CompatibleAsset, InboundDetail } from '../types';
4
4
  export declare const getBaseAmountWithDiffDecimals: (inputAmount: CryptoAmount, outDecimals: number) => BigNumber;
5
5
  export declare const getCryptoAmountWithNotation: <T extends CompatibleAsset>(amount: CryptoAmount<T>, notation: number) => CryptoAmount<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-query",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "license": "MIT",
5
5
  "description": "Thorchain query module that is responsible for estimating swap calculations and add/remove liquidity for thorchain ",
6
6
  "keywords": [
@@ -28,15 +28,15 @@
28
28
  "build": "yarn clean && rollup -c --bundleConfigAsCjs",
29
29
  "build:release": "yarn exec rm -rf release && yarn pack && yarn exec \"mkdir release && tar zxvf package.tgz --directory release && rm package.tgz\"",
30
30
  "test": "jest",
31
- "e2e": "jest --config jest.config.e2e.js",
31
+ "e2e": "jest --config jest.config.e2e.mjs",
32
32
  "lint": "eslint \"{src,__tests__}/**/*.ts\" --fix --max-warnings 0",
33
33
  "postversion": "git push --follow-tags"
34
34
  },
35
35
  "dependencies": {
36
- "@xchainjs/xchain-client": "2.0.3",
37
- "@xchainjs/xchain-midgard-query": "2.0.3",
38
- "@xchainjs/xchain-thornode": "1.0.2",
39
- "@xchainjs/xchain-util": "2.0.2",
36
+ "@xchainjs/xchain-client": "2.0.5",
37
+ "@xchainjs/xchain-midgard-query": "2.0.5",
38
+ "@xchainjs/xchain-thornode": "1.0.4",
39
+ "@xchainjs/xchain-util": "2.0.3",
40
40
  "axios": "1.8.4",
41
41
  "axios-retry": "3.2.5",
42
42
  "bignumber.js": "^9.0.0"