@xchainjs/xchain-thorchain-query 0.1.10 → 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/lib/index.esm.js +13 -9
- package/lib/index.js +12 -8
- package/lib/thorchain-query.d.ts +1 -0
- package/package.json +1 -1
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
|
-
|
|
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.
|
|
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 = `=:${
|
|
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
|
-
|
|
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.
|
|
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 = `=:${
|
|
1635
|
+
memo = `=:${this.abbreviateAssetString(params.destinationAsset)}:${params.destinationAddress}:${lim}`;
|
|
1632
1636
|
}
|
|
1633
1637
|
return memo;
|
|
1634
1638
|
}
|
package/lib/thorchain-query.d.ts
CHANGED
package/package.json
CHANGED