@xchainjs/xchain-thorchain-query 0.1.9 → 0.1.11

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/README.md CHANGED
@@ -62,3 +62,24 @@ List pools: https://replit.com/@thorchain/listPools#package.json\
62
62
  Get Network Values: https://replit.com/@thorchain/networkValues#index.ts\
63
63
 
64
64
  Estimate AddSaver() & WithdrawSaver() & getSaverPosition() https://replit.com/@thorchain/quoteDepositTS#index.ts
65
+
66
+ ### Setting Headers for Nine Realms endpoints
67
+
68
+ If you plan on using the publically accessible endpoints provided by Nine Realms(listed below), ensure that you add a valid 'x-client-id' to all requests
69
+
70
+ - https://midgard.ninerealms.com
71
+ - https://haskoin.ninerealms.com (BTC/BCH/LTC)
72
+ - https://thornode.ninerealms.com
73
+
74
+ Example
75
+
76
+ ```typescript
77
+ import cosmosclient from '@cosmos-client/core'
78
+ import axios from 'axios'
79
+ import { register9Rheader } from '@xchainjs/xchain-util'
80
+
81
+ register9Rheader(axios)
82
+ register9Rheader(cosmosclient.config.globalAxios)
83
+ ```
84
+
85
+ For a complete example please see this [test](https://github.com/xchainjs/xchainjs-lib/blob/master/packages/xchain-thorchain-amm/__e2e__/wallet.e2e.ts)
package/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { assetToBase, formatAssetAmountCurrency, baseToAsset, eqAsset, assetToString, assetFromString, baseAmount, AssetRuneNative, Chain, AssetAtom, AssetAVAX, AssetETH, AssetBNB, AssetDOGE, AssetLTC, AssetBCH, AssetBTC, AvalancheChain, DOGEChain, LTCChain, BCHChain, CosmosChain, THORChain, ETHChain, BTCChain, BNBChain, assetFromStringEx, isAssetRuneNative, assetAmount } from '@xchainjs/xchain-util';
1
+ import { assetToBase, formatAssetAmountCurrency, baseToAsset, eqAsset, assetToString, assetFromString, baseAmount, AssetRuneNative, Chain, AssetAtom, AssetAVAX, AssetETH, AssetBNB, AssetDOGE, AssetLTC, AssetBCH, AssetBTC, AvalancheChain, DOGEChain, LTCChain, BCHChain, CosmosChain, THORChain, ETHChain, BTCChain, BNBChain, assetFromStringEx, isAssetRuneNative, getContractAddressFromAsset, assetAmount } from '@xchainjs/xchain-util';
2
2
  import { BigNumber } from 'bignumber.js';
3
3
  import { Network } from '@xchainjs/xchain-client';
4
4
  import { MidgardApi, Configuration } from '@xchainjs/xchain-midgard';
@@ -1597,6 +1597,15 @@ class ThorchainQuery {
1597
1597
  return swapEstimate;
1598
1598
  });
1599
1599
  }
1600
+ abbreviateAssetString(asset) {
1601
+ const contractAddress = getContractAddressFromAsset(asset);
1602
+ if (contractAddress && contractAddress.length > 5) {
1603
+ const abrev = contractAddress.substring(contractAddress.length - 5);
1604
+ const sep = asset.chain !== Chain.THORChain && asset.synth ? '/' : '.';
1605
+ return `${asset.chain}${sep}${asset.ticker}-${abrev}`;
1606
+ }
1607
+ return assetToString(asset);
1608
+ }
1600
1609
  /**
1601
1610
  *
1602
1611
  * @param params - swap object
@@ -1605,21 +1614,16 @@ class ThorchainQuery {
1605
1614
  constructSwapMemo(params) {
1606
1615
  var _a;
1607
1616
  const limstring = params.limit.amount().toFixed();
1608
- // create LIM with interface ID
1609
1617
  const lim = limstring.substring(0, limstring.length - 3).concat(params.interfaceID);
1610
- // create the full memo
1611
- let memo = `=:${assetToString(params.destinationAsset)}`;
1618
+ let memo = `=:${this.abbreviateAssetString(params.destinationAsset)}:${params.destinationAddress}:${lim}`;
1612
1619
  // NOTE: we should validate affiliate address is EITHER: a thorname or valid thorchain address, currently we cannot do this without importing xchain-thorchain
1613
1620
  if (((_a = params.affiliateAddress) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1614
1621
  // NOTE: we should validate destinationAddress address is valid destination address for the asset type requested
1615
- memo = memo.concat(`:${params.destinationAddress}:${lim}:${params.affiliateAddress}:${params.affiliateFeeBasisPoints}`);
1616
- }
1617
- else {
1618
- memo = memo.concat(`:${params.destinationAddress}:${lim}`);
1622
+ memo = memo.concat(`:${params.affiliateAddress}:${params.affiliateFeeBasisPoints}`);
1619
1623
  }
1620
1624
  // If memo length is too long for BTC, trim it
1621
1625
  if (eqAsset(params.input.asset, AssetBTC) && memo.length > 80) {
1622
- memo = `=:${assetToString(params.destinationAsset)}:${params.destinationAddress}`;
1626
+ memo = `=:${this.abbreviateAssetString(params.destinationAsset)}:${params.destinationAddress}:${lim}`;
1623
1627
  }
1624
1628
  return memo;
1625
1629
  }
package/lib/index.js CHANGED
@@ -1606,6 +1606,15 @@ class ThorchainQuery {
1606
1606
  return swapEstimate;
1607
1607
  });
1608
1608
  }
1609
+ abbreviateAssetString(asset) {
1610
+ const contractAddress = xchainUtil.getContractAddressFromAsset(asset);
1611
+ if (contractAddress && contractAddress.length > 5) {
1612
+ const abrev = contractAddress.substring(contractAddress.length - 5);
1613
+ const sep = asset.chain !== xchainUtil.Chain.THORChain && asset.synth ? '/' : '.';
1614
+ return `${asset.chain}${sep}${asset.ticker}-${abrev}`;
1615
+ }
1616
+ return xchainUtil.assetToString(asset);
1617
+ }
1609
1618
  /**
1610
1619
  *
1611
1620
  * @param params - swap object
@@ -1614,21 +1623,16 @@ class ThorchainQuery {
1614
1623
  constructSwapMemo(params) {
1615
1624
  var _a;
1616
1625
  const limstring = params.limit.amount().toFixed();
1617
- // create LIM with interface ID
1618
1626
  const lim = limstring.substring(0, limstring.length - 3).concat(params.interfaceID);
1619
- // create the full memo
1620
- let memo = `=:${xchainUtil.assetToString(params.destinationAsset)}`;
1627
+ let memo = `=:${this.abbreviateAssetString(params.destinationAsset)}:${params.destinationAddress}:${lim}`;
1621
1628
  // NOTE: we should validate affiliate address is EITHER: a thorname or valid thorchain address, currently we cannot do this without importing xchain-thorchain
1622
1629
  if (((_a = params.affiliateAddress) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1623
1630
  // NOTE: we should validate destinationAddress address is valid destination address for the asset type requested
1624
- memo = memo.concat(`:${params.destinationAddress}:${lim}:${params.affiliateAddress}:${params.affiliateFeeBasisPoints}`);
1625
- }
1626
- else {
1627
- memo = memo.concat(`:${params.destinationAddress}:${lim}`);
1631
+ memo = memo.concat(`:${params.affiliateAddress}:${params.affiliateFeeBasisPoints}`);
1628
1632
  }
1629
1633
  // If memo length is too long for BTC, trim it
1630
1634
  if (xchainUtil.eqAsset(params.input.asset, xchainUtil.AssetBTC) && memo.length > 80) {
1631
- memo = `=:${xchainUtil.assetToString(params.destinationAsset)}:${params.destinationAddress}`;
1635
+ memo = `=:${this.abbreviateAssetString(params.destinationAsset)}:${params.destinationAddress}:${lim}`;
1632
1636
  }
1633
1637
  return memo;
1634
1638
  }
@@ -45,6 +45,7 @@ export declare class ThorchainQuery {
45
45
  * @returns
46
46
  */
47
47
  private calcSwapEstimate;
48
+ private abbreviateAssetString;
48
49
  /**
49
50
  *
50
51
  * @param params - swap object
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FeeOption } from '@xchainjs/xchain-client';
2
- import { LiquidityProvider } from '@xchainjs/xchain-thornode';
2
+ import { LiquidityProviderSummary } from '@xchainjs/xchain-thornode';
3
3
  import { Address, Asset, BaseAmount, Chain } from '@xchainjs/xchain-util';
4
4
  import { BigNumber } from 'bignumber.js';
5
5
  import { CryptoAmount } from './crypto-amount';
@@ -168,7 +168,7 @@ export declare type WithdrawLiquidityPosition = {
168
168
  };
169
169
  export declare type LiquidityPosition = {
170
170
  poolShare: PoolShareDetail;
171
- position: LiquidityProvider;
171
+ position: LiquidityProviderSummary;
172
172
  lpGrowth: string;
173
173
  impermanentLossProtection: ILProtectionData;
174
174
  };
@@ -1,5 +1,5 @@
1
1
  import { Network } from '@xchainjs/xchain-client';
2
- import { InboundAddress, LastBlock, LiquidityProvider, LiquidityProviderResponse, Pool, QuoteSaverDepositResponse, QuoteSaverWithdrawResponse, QuoteSwapResponse, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
2
+ import { InboundAddress, LastBlock, LiquidityProviderSummary, Pool, QuoteSaverDepositResponse, QuoteSaverWithdrawResponse, QuoteSwapResponse, SaverResponse, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
3
3
  import { SaversWithdraw } from '../types';
4
4
  export declare type ThornodeConfig = {
5
5
  apiRetries: number;
@@ -48,7 +48,7 @@ export declare class Thornode {
48
48
  * @param height - optional block height, defaults to current tip
49
49
  * @returns
50
50
  */
51
- getLiquidityProvider(asset: string, address: string, height?: number): Promise<LiquidityProvider | undefined>;
51
+ getLiquidityProvider(asset: string, address: string, height?: number): Promise<LiquidityProviderSummary | undefined>;
52
52
  /**
53
53
  *
54
54
  * @param asset - asset string
@@ -63,14 +63,14 @@ export declare class Thornode {
63
63
  * @param height - optional thorchain block height parameter
64
64
  * @returns - Liquidity Provider Object
65
65
  */
66
- getSavers(asset: string, height?: number): Promise<LiquidityProviderResponse>;
66
+ getSavers(asset: string, height?: number): Promise<SaverResponse>;
67
67
  /**
68
68
  *
69
69
  * @param asset - asset string
70
70
  * @param height - optional thorchain block height parameter
71
71
  * @returns - Liquidity Provider Object
72
72
  */
73
- getSaver(asset: string, address: string, height?: number): Promise<LiquidityProviderResponse>;
73
+ getSaver(asset: string, address: string, height?: number): Promise<SaverResponse>;
74
74
  /**
75
75
  *
76
76
  * @param asset - asset to add to savers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-query",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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,7 +33,7 @@
33
33
  "postversion": "git push --follow-tags"
34
34
  },
35
35
  "devDependencies": {
36
- "@xchainjs/xchain-client": "^0.13.3",
36
+ "@xchainjs/xchain-client": "^0.13.4",
37
37
  "@xchainjs/xchain-midgard": "^0.4.0",
38
38
  "@xchainjs/xchain-thornode": "^0.1.3",
39
39
  "@xchainjs/xchain-util": "^0.11.0",
@@ -43,10 +43,10 @@
43
43
  "rimraf": "~3.0.2"
44
44
  },
45
45
  "peerDependencies": {
46
- "@xchainjs/xchain-client": "^0.13.3",
47
- "@xchainjs/xchain-midgard": "^0.3.0",
48
- "@xchainjs/xchain-thornode": "^0.1.2",
49
- "@xchainjs/xchain-util": "^0.11.0",
46
+ "@xchainjs/xchain-client": "^0.13.4",
47
+ "@xchainjs/xchain-midgard": "^0.4.1",
48
+ "@xchainjs/xchain-thornode": "^0.1.5",
49
+ "@xchainjs/xchain-util": "^0.11.1",
50
50
  "axios": "^0.25.0",
51
51
  "axios-retry": "^3.2.5",
52
52
  "bignumber.js": "^9.0.0",