@xchainjs/xchain-mayachain-query 2.1.2 → 2.1.4
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 +23 -16
- package/lib/index.js +23 -16
- package/lib/mayachain-query.d.ts +7 -1
- package/lib/types.d.ts +2 -1
- package/lib/utils/mayanode.d.ts +1 -1
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -81,13 +81,12 @@ class Mayanode {
|
|
|
81
81
|
* @param height - block height
|
|
82
82
|
* @returns quotes swap object response
|
|
83
83
|
*/
|
|
84
|
-
getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, toleranceBps, affiliateBps, affiliate, height) {
|
|
84
|
+
getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliate, height) {
|
|
85
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
86
|
for (const api of this.quoteApis) {
|
|
87
87
|
try {
|
|
88
|
-
return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, //
|
|
89
|
-
streamingInterval, streamingQuantity, toleranceBps,
|
|
90
|
-
affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
|
|
88
|
+
return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, //refund address
|
|
89
|
+
streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps, affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
|
|
91
90
|
}
|
|
92
91
|
catch (_e) { }
|
|
93
92
|
}
|
|
@@ -543,14 +542,15 @@ class MayachainQuery {
|
|
|
543
542
|
* @returns {QuoteSwap} A quote for the swap operation.
|
|
544
543
|
*/
|
|
545
544
|
quoteSwap(_a) {
|
|
546
|
-
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
|
|
545
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
|
|
547
546
|
const fromAssetString = assetToString(fromAsset);
|
|
548
547
|
const toAssetString = assetToString(destinationAsset);
|
|
549
548
|
// Endpoint allows 10 decimals for Cacao, 8 for the rest of assets
|
|
550
|
-
const inputAmount =
|
|
549
|
+
const inputAmount = eqAsset(fromAsset, CacaoAsset)
|
|
551
550
|
? amount.baseAmount.amount()
|
|
552
|
-
: getBaseAmountWithDiffDecimals(amount,
|
|
553
|
-
const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, toleranceBps, affiliateBps, affiliateAddress, height);
|
|
551
|
+
: getBaseAmountWithDiffDecimals(amount, this.getQuoteAssetDecimals(fromAsset));
|
|
552
|
+
const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height);
|
|
553
|
+
// Check if the response indicates an error by examining memo and other required field
|
|
554
554
|
const response = JSON.parse(JSON.stringify(swapQuote));
|
|
555
555
|
if (response.error) {
|
|
556
556
|
return {
|
|
@@ -582,23 +582,22 @@ class MayachainQuery {
|
|
|
582
582
|
}
|
|
583
583
|
const feeAsset = assetFromStringEx(swapQuote.fees.asset);
|
|
584
584
|
const errors = [];
|
|
585
|
-
if (swapQuote.memo === undefined)
|
|
585
|
+
if (swapQuote.memo === undefined || swapQuote.memo === '')
|
|
586
586
|
errors.push(`Error parsing swap quote: Memo is ${swapQuote.memo}`);
|
|
587
|
-
const isFeeAssetCacao = swapQuote.fees.asset === assetToString(CacaoAsset);
|
|
588
587
|
return {
|
|
589
588
|
toAddress: swapQuote.inbound_address || '',
|
|
590
589
|
memo: swapQuote.memo || '',
|
|
591
|
-
expectedAmount: new CryptoAmount(baseAmount(swapQuote.expected_amount_out,
|
|
590
|
+
expectedAmount: new CryptoAmount(baseAmount(swapQuote.expected_amount_out, this.getQuoteAssetDecimals(destinationAsset)), destinationAsset),
|
|
592
591
|
dustThreshold: this.getChainDustValue(fromAsset.chain),
|
|
593
592
|
fees: {
|
|
594
593
|
asset: feeAsset,
|
|
595
|
-
affiliateFee: new CryptoAmount(baseAmount(swapQuote.fees.affiliate,
|
|
596
|
-
outboundFee: new CryptoAmount(baseAmount(swapQuote.fees.outbound,
|
|
597
|
-
liquidityFee: new CryptoAmount(baseAmount(swapQuote.fees.liquidity,
|
|
598
|
-
totalFee: new CryptoAmount(baseAmount(swapQuote.fees.total,
|
|
594
|
+
affiliateFee: new CryptoAmount(baseAmount(swapQuote.fees.affiliate, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
|
|
595
|
+
outboundFee: new CryptoAmount(baseAmount(swapQuote.fees.outbound, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
|
|
596
|
+
liquidityFee: new CryptoAmount(baseAmount(swapQuote.fees.liquidity, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
|
|
597
|
+
totalFee: new CryptoAmount(baseAmount(swapQuote.fees.total, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
|
|
599
598
|
},
|
|
600
599
|
expiry: swapQuote.expiry,
|
|
601
|
-
recommendedMinAmountIn: new CryptoAmount(baseAmount(swapQuote.recommended_min_amount_in || '0',
|
|
600
|
+
recommendedMinAmountIn: new CryptoAmount(baseAmount(swapQuote.recommended_min_amount_in || '0', this.getQuoteAssetDecimals(fromAsset)), fromAsset),
|
|
602
601
|
router: swapQuote.router,
|
|
603
602
|
recommendedGasRate: swapQuote.recommended_gas_rate,
|
|
604
603
|
gasRateUnits: swapQuote.gas_rate_units,
|
|
@@ -965,6 +964,14 @@ class MayachainQuery {
|
|
|
965
964
|
});
|
|
966
965
|
});
|
|
967
966
|
}
|
|
967
|
+
/**
|
|
968
|
+
* Get the hardcoded decimal precision for quote calculations
|
|
969
|
+
* @param asset The asset to get decimals for
|
|
970
|
+
* @returns 10 for Cacao, 8 for other assets (used in quote calculations)
|
|
971
|
+
*/
|
|
972
|
+
getQuoteAssetDecimals(asset) {
|
|
973
|
+
return eqAsset(asset, CacaoAsset) ? 10 : 8;
|
|
974
|
+
}
|
|
968
975
|
}
|
|
969
976
|
|
|
970
977
|
export { ArbAsset, ArbChain, BtcAsset, BtcChain, CacaoAsset, DEFAULT_MAYACHAIN_DECIMALS, DashAsset, DashChain, EthAsset, EthChain, KujiraAsset, KujiraChain, MayaChain, MayachainCache, MayachainQuery, Mayanode, RuneAsset, ThorChain, XdrAsset, XdrChain, ZecAsset, ZecChain, getBaseAmountWithDiffDecimals, getCryptoAmountWithNotation, isCacaoAsset };
|
package/lib/index.js
CHANGED
|
@@ -89,13 +89,12 @@ class Mayanode {
|
|
|
89
89
|
* @param height - block height
|
|
90
90
|
* @returns quotes swap object response
|
|
91
91
|
*/
|
|
92
|
-
getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, toleranceBps, affiliateBps, affiliate, height) {
|
|
92
|
+
getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliate, height) {
|
|
93
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
94
|
for (const api of this.quoteApis) {
|
|
95
95
|
try {
|
|
96
|
-
return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, //
|
|
97
|
-
streamingInterval, streamingQuantity, toleranceBps,
|
|
98
|
-
affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
|
|
96
|
+
return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, //refund address
|
|
97
|
+
streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps, affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
|
|
99
98
|
}
|
|
100
99
|
catch (_e) { }
|
|
101
100
|
}
|
|
@@ -551,14 +550,15 @@ class MayachainQuery {
|
|
|
551
550
|
* @returns {QuoteSwap} A quote for the swap operation.
|
|
552
551
|
*/
|
|
553
552
|
quoteSwap(_a) {
|
|
554
|
-
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
|
|
553
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
|
|
555
554
|
const fromAssetString = xchainUtil.assetToString(fromAsset);
|
|
556
555
|
const toAssetString = xchainUtil.assetToString(destinationAsset);
|
|
557
556
|
// Endpoint allows 10 decimals for Cacao, 8 for the rest of assets
|
|
558
|
-
const inputAmount =
|
|
557
|
+
const inputAmount = xchainUtil.eqAsset(fromAsset, CacaoAsset)
|
|
559
558
|
? amount.baseAmount.amount()
|
|
560
|
-
: getBaseAmountWithDiffDecimals(amount,
|
|
561
|
-
const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, toleranceBps, affiliateBps, affiliateAddress, height);
|
|
559
|
+
: getBaseAmountWithDiffDecimals(amount, this.getQuoteAssetDecimals(fromAsset));
|
|
560
|
+
const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height);
|
|
561
|
+
// Check if the response indicates an error by examining memo and other required field
|
|
562
562
|
const response = JSON.parse(JSON.stringify(swapQuote));
|
|
563
563
|
if (response.error) {
|
|
564
564
|
return {
|
|
@@ -590,23 +590,22 @@ class MayachainQuery {
|
|
|
590
590
|
}
|
|
591
591
|
const feeAsset = xchainUtil.assetFromStringEx(swapQuote.fees.asset);
|
|
592
592
|
const errors = [];
|
|
593
|
-
if (swapQuote.memo === undefined)
|
|
593
|
+
if (swapQuote.memo === undefined || swapQuote.memo === '')
|
|
594
594
|
errors.push(`Error parsing swap quote: Memo is ${swapQuote.memo}`);
|
|
595
|
-
const isFeeAssetCacao = swapQuote.fees.asset === xchainUtil.assetToString(CacaoAsset);
|
|
596
595
|
return {
|
|
597
596
|
toAddress: swapQuote.inbound_address || '',
|
|
598
597
|
memo: swapQuote.memo || '',
|
|
599
|
-
expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out,
|
|
598
|
+
expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out, this.getQuoteAssetDecimals(destinationAsset)), destinationAsset),
|
|
600
599
|
dustThreshold: this.getChainDustValue(fromAsset.chain),
|
|
601
600
|
fees: {
|
|
602
601
|
asset: feeAsset,
|
|
603
|
-
affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.affiliate,
|
|
604
|
-
outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.outbound,
|
|
605
|
-
liquidityFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.liquidity,
|
|
606
|
-
totalFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.total,
|
|
602
|
+
affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.affiliate, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
|
|
603
|
+
outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.outbound, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
|
|
604
|
+
liquidityFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.liquidity, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
|
|
605
|
+
totalFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.total, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
|
|
607
606
|
},
|
|
608
607
|
expiry: swapQuote.expiry,
|
|
609
|
-
recommendedMinAmountIn: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.recommended_min_amount_in || '0',
|
|
608
|
+
recommendedMinAmountIn: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.recommended_min_amount_in || '0', this.getQuoteAssetDecimals(fromAsset)), fromAsset),
|
|
610
609
|
router: swapQuote.router,
|
|
611
610
|
recommendedGasRate: swapQuote.recommended_gas_rate,
|
|
612
611
|
gasRateUnits: swapQuote.gas_rate_units,
|
|
@@ -973,6 +972,14 @@ class MayachainQuery {
|
|
|
973
972
|
});
|
|
974
973
|
});
|
|
975
974
|
}
|
|
975
|
+
/**
|
|
976
|
+
* Get the hardcoded decimal precision for quote calculations
|
|
977
|
+
* @param asset The asset to get decimals for
|
|
978
|
+
* @returns 10 for Cacao, 8 for other assets (used in quote calculations)
|
|
979
|
+
*/
|
|
980
|
+
getQuoteAssetDecimals(asset) {
|
|
981
|
+
return xchainUtil.eqAsset(asset, CacaoAsset) ? 10 : 8;
|
|
982
|
+
}
|
|
976
983
|
}
|
|
977
984
|
|
|
978
985
|
exports.ArbAsset = ArbAsset;
|
package/lib/mayachain-query.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class MayachainQuery {
|
|
|
32
32
|
* @param {QuoteSwapParams} quoteSwapParams - Parameters for the quote swap operation.
|
|
33
33
|
* @returns {QuoteSwap} A quote for the swap operation.
|
|
34
34
|
*/
|
|
35
|
-
quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<QuoteSwap>;
|
|
35
|
+
quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<QuoteSwap>;
|
|
36
36
|
/**
|
|
37
37
|
* Return mayachain supported chains dust amounts
|
|
38
38
|
* @returns a map where chain is the key and dust amount cryptoAmount as value
|
|
@@ -122,4 +122,10 @@ export declare class MayachainQuery {
|
|
|
122
122
|
* @returns {TradeAssetAccounts} All trade accounts for the asset
|
|
123
123
|
*/
|
|
124
124
|
getTradeAssetAccounts({ asset, height }: TradeAssetAccountsParams): Promise<TradeAssetAccounts>;
|
|
125
|
+
/**
|
|
126
|
+
* Get the hardcoded decimal precision for quote calculations
|
|
127
|
+
* @param asset The asset to get decimals for
|
|
128
|
+
* @returns 10 for Cacao, 8 for other assets (used in quote calculations)
|
|
129
|
+
*/
|
|
130
|
+
private getQuoteAssetDecimals;
|
|
125
131
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TxHash } from '@xchainjs/xchain-client';
|
|
2
2
|
import { Address, Asset, AssetCryptoAmount, Chain, CryptoAmount, SynthAsset, TokenAsset, TradeAsset, TradeCryptoAmount } from '@xchainjs/xchain-util';
|
|
3
3
|
import type BigNumber from 'bignumber.js';
|
|
4
|
-
export type CompatibleAsset = Asset | TokenAsset | SynthAsset;
|
|
4
|
+
export type CompatibleAsset = Asset | TokenAsset | SynthAsset | TradeAsset;
|
|
5
5
|
/**
|
|
6
6
|
* Represents fees associated with a swap.
|
|
7
7
|
*/
|
|
@@ -79,6 +79,7 @@ export type QuoteSwapParams = {
|
|
|
79
79
|
fromAddress?: string;
|
|
80
80
|
destinationAddress?: string;
|
|
81
81
|
height?: number;
|
|
82
|
+
liquidityToleranceBps?: number;
|
|
82
83
|
toleranceBps?: number;
|
|
83
84
|
affiliateBps?: number;
|
|
84
85
|
affiliateAddress?: string;
|
package/lib/utils/mayanode.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class Mayanode {
|
|
|
31
31
|
* @param height - block height
|
|
32
32
|
* @returns quotes swap object response
|
|
33
33
|
*/
|
|
34
|
-
getSwapQuote(fromAsset: string, toAsset: string, amount: number, destinationAddress?: string, streamingInterval?: number, streamingQuantity?: number, toleranceBps?: number, affiliateBps?: number, affiliate?: string, height?: number): Promise<QuoteSwapResponse>;
|
|
34
|
+
getSwapQuote(fromAsset: string, toAsset: string, amount: number, destinationAddress?: string, streamingInterval?: number, streamingQuantity?: number, liquidityToleranceBps?: number, toleranceBps?: number, affiliateBps?: number, affiliate?: string, height?: number): Promise<QuoteSwapResponse>;
|
|
35
35
|
/**
|
|
36
36
|
* Get current active mimir configuration.
|
|
37
37
|
* @returns mimir configuration
|
package/package.json
CHANGED