@xchainjs/xchain-thorchain-query 3.0.4 → 3.1.0
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 +0 -11
- package/lib/index.esm.js +16 -4
- package/lib/index.js +16 -4
- package/lib/thorchain-query.d.ts +1 -1
- package/lib/types.d.ts +8 -0
- package/lib/utils/thornode.d.ts +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -138,15 +138,4 @@ If you plan on using the publicly accessible endpoints listed below, ensure that
|
|
|
138
138
|
- https://api.haskoin.com (BTC/BCH/LTC)
|
|
139
139
|
- https://gateway.liquify.com/chain/thorchain_api
|
|
140
140
|
|
|
141
|
-
## Example
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
import cosmosclient from '@cosmos-client/core'
|
|
145
|
-
import axios from 'axios'
|
|
146
|
-
import { register9Rheader } from '@xchainjs/xchain-util'
|
|
147
|
-
|
|
148
|
-
register9Rheader(axios)
|
|
149
|
-
register9Rheader(cosmosclient.config.globalAxios)
|
|
150
|
-
```
|
|
151
|
-
|
|
152
141
|
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
|
@@ -757,11 +757,17 @@ class Thornode {
|
|
|
757
757
|
* @param height - block height
|
|
758
758
|
* @returns quotes swap object response
|
|
759
759
|
*/
|
|
760
|
-
getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
760
|
+
getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
761
|
+
// `string` is accepted to carry the slash-delimited per-affiliate form (e.g. "10/20/30")
|
|
762
|
+
// used when multiple affiliates are passed. Single-affiliate callers pass a number as before.
|
|
763
|
+
affiliateBps, affiliate, height, refundAddress) {
|
|
761
764
|
return __awaiter(this, void 0, void 0, function* () {
|
|
762
765
|
for (const api of this.quoteApi) {
|
|
763
766
|
try {
|
|
764
|
-
const resp = (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, refundAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
767
|
+
const resp = (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, refundAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
768
|
+
// Generated client types this as `number`; axios serializes either number or string
|
|
769
|
+
// identically into the query string, so the runtime accepts both.
|
|
770
|
+
affiliateBps, affiliate)).data;
|
|
765
771
|
return resp;
|
|
766
772
|
}
|
|
767
773
|
catch (e) {
|
|
@@ -1190,7 +1196,7 @@ class ThorchainQuery {
|
|
|
1190
1196
|
* @returns Transaction details including memo, address, fees, etc.
|
|
1191
1197
|
*/
|
|
1192
1198
|
quoteSwap(_a) {
|
|
1193
|
-
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, }) {
|
|
1199
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, affiliates, height, }) {
|
|
1194
1200
|
// Validates swap and pushes error if there is one
|
|
1195
1201
|
const errors = [];
|
|
1196
1202
|
const error = yield this.validateAmount(amount);
|
|
@@ -1199,8 +1205,14 @@ class ThorchainQuery {
|
|
|
1199
1205
|
const fromAssetString = assetToString(fromAsset);
|
|
1200
1206
|
const toAssetString = assetToString(destinationAsset);
|
|
1201
1207
|
const inputAmount = getBaseAmountWithDiffDecimals(amount, 8);
|
|
1208
|
+
// If the caller passed a multi-affiliate array, collapse it into the slash-delimited
|
|
1209
|
+
// form the protocol's /quote/swap endpoint accepts. The endpoint requires per-affiliate bps
|
|
1210
|
+
// (it does not auto-expand a single shared bps), so both fields are joined in parallel.
|
|
1211
|
+
const hasAffiliates = Boolean(affiliates === null || affiliates === void 0 ? void 0 : affiliates.length);
|
|
1212
|
+
const quoteAffiliateAddress = hasAffiliates ? affiliates.map((a) => a.address).join('/') : affiliateAddress;
|
|
1213
|
+
const quoteAffiliateBps = hasAffiliates ? affiliates.map((a) => a.bps).join('/') : affiliateBps;
|
|
1202
1214
|
// Fetch quote
|
|
1203
|
-
const swapQuote = yield this.thorchainCache.thornode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
1215
|
+
const swapQuote = yield this.thorchainCache.thornode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps, quoteAffiliateBps, quoteAffiliateAddress, height);
|
|
1204
1216
|
let response;
|
|
1205
1217
|
// Check if swapQuote is a string, which we assume indicates an error message
|
|
1206
1218
|
if (typeof swapQuote === 'string') {
|
package/lib/index.js
CHANGED
|
@@ -765,11 +765,17 @@ class Thornode {
|
|
|
765
765
|
* @param height - block height
|
|
766
766
|
* @returns quotes swap object response
|
|
767
767
|
*/
|
|
768
|
-
getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
768
|
+
getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
769
|
+
// `string` is accepted to carry the slash-delimited per-affiliate form (e.g. "10/20/30")
|
|
770
|
+
// used when multiple affiliates are passed. Single-affiliate callers pass a number as before.
|
|
771
|
+
affiliateBps, affiliate, height, refundAddress) {
|
|
769
772
|
return __awaiter(this, void 0, void 0, function* () {
|
|
770
773
|
for (const api of this.quoteApi) {
|
|
771
774
|
try {
|
|
772
|
-
const resp = (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, refundAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
775
|
+
const resp = (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, refundAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
776
|
+
// Generated client types this as `number`; axios serializes either number or string
|
|
777
|
+
// identically into the query string, so the runtime accepts both.
|
|
778
|
+
affiliateBps, affiliate)).data;
|
|
773
779
|
return resp;
|
|
774
780
|
}
|
|
775
781
|
catch (e) {
|
|
@@ -1198,7 +1204,7 @@ class ThorchainQuery {
|
|
|
1198
1204
|
* @returns Transaction details including memo, address, fees, etc.
|
|
1199
1205
|
*/
|
|
1200
1206
|
quoteSwap(_a) {
|
|
1201
|
-
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, }) {
|
|
1207
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, affiliates, height, }) {
|
|
1202
1208
|
// Validates swap and pushes error if there is one
|
|
1203
1209
|
const errors = [];
|
|
1204
1210
|
const error = yield this.validateAmount(amount);
|
|
@@ -1207,8 +1213,14 @@ class ThorchainQuery {
|
|
|
1207
1213
|
const fromAssetString = xchainUtil.assetToString(fromAsset);
|
|
1208
1214
|
const toAssetString = xchainUtil.assetToString(destinationAsset);
|
|
1209
1215
|
const inputAmount = getBaseAmountWithDiffDecimals(amount, 8);
|
|
1216
|
+
// If the caller passed a multi-affiliate array, collapse it into the slash-delimited
|
|
1217
|
+
// form the protocol's /quote/swap endpoint accepts. The endpoint requires per-affiliate bps
|
|
1218
|
+
// (it does not auto-expand a single shared bps), so both fields are joined in parallel.
|
|
1219
|
+
const hasAffiliates = Boolean(affiliates === null || affiliates === void 0 ? void 0 : affiliates.length);
|
|
1220
|
+
const quoteAffiliateAddress = hasAffiliates ? affiliates.map((a) => a.address).join('/') : affiliateAddress;
|
|
1221
|
+
const quoteAffiliateBps = hasAffiliates ? affiliates.map((a) => a.bps).join('/') : affiliateBps;
|
|
1210
1222
|
// Fetch quote
|
|
1211
|
-
const swapQuote = yield this.thorchainCache.thornode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps,
|
|
1223
|
+
const swapQuote = yield this.thorchainCache.thornode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps, quoteAffiliateBps, quoteAffiliateAddress, height);
|
|
1212
1224
|
let response;
|
|
1213
1225
|
// Check if swapQuote is a string, which we assume indicates an error message
|
|
1214
1226
|
if (typeof swapQuote === 'string') {
|
package/lib/thorchain-query.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare class ThorchainQuery {
|
|
|
22
22
|
* @param quoteSwapParams - Input parameters for the swap quote.
|
|
23
23
|
* @returns Transaction details including memo, address, fees, etc.
|
|
24
24
|
*/
|
|
25
|
-
quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, }: QuoteSwapParams): Promise<TxDetails>;
|
|
25
|
+
quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, affiliates, height, }: QuoteSwapParams): Promise<TxDetails>;
|
|
26
26
|
/**
|
|
27
27
|
* Validate a cryptoAmount is well formed
|
|
28
28
|
* @param {CryptoAmount} cryptoAmount - CryptoAmount to validate
|
package/lib/types.d.ts
CHANGED
|
@@ -35,6 +35,13 @@ export type SwapEstimate = {
|
|
|
35
35
|
errors: string[];
|
|
36
36
|
warning: string;
|
|
37
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* A single affiliate entry. Used by the multi-affiliate `affiliates` field on QuoteSwapParams.
|
|
40
|
+
*/
|
|
41
|
+
export type Affiliate = {
|
|
42
|
+
address: string;
|
|
43
|
+
bps: number;
|
|
44
|
+
};
|
|
38
45
|
/**
|
|
39
46
|
* Represents parameters for requesting a swap quote.
|
|
40
47
|
*/
|
|
@@ -50,6 +57,7 @@ export type QuoteSwapParams = {
|
|
|
50
57
|
liquidityToleranceBps?: number;
|
|
51
58
|
affiliateAddress?: string;
|
|
52
59
|
affiliateBps?: number;
|
|
60
|
+
affiliates?: Affiliate[];
|
|
53
61
|
height?: number;
|
|
54
62
|
interfaceID?: string;
|
|
55
63
|
feeOption?: FeeOption;
|
package/lib/utils/thornode.d.ts
CHANGED
|
@@ -129,7 +129,7 @@ export declare class Thornode {
|
|
|
129
129
|
* @param height - block height
|
|
130
130
|
* @returns quotes swap object response
|
|
131
131
|
*/
|
|
132
|
-
getSwapQuote(fromAsset: string, toAsset: string, amount: number, destinationAddress?: string, streamingInterval?: number, streamingQuantity?: number, toleranceBps?: number, liquidityToleranceBps?: number, affiliateBps?: number, affiliate?: string, height?: number, refundAddress?: string): Promise<QuoteSwapResponse>;
|
|
132
|
+
getSwapQuote(fromAsset: string, toAsset: string, amount: number, destinationAddress?: string, streamingInterval?: number, streamingQuantity?: number, toleranceBps?: number, liquidityToleranceBps?: number, affiliateBps?: number | string, affiliate?: string, height?: number, refundAddress?: string): Promise<QuoteSwapResponse>;
|
|
133
133
|
getThornameDetails(thorname: string, height?: number): Promise<Thorname>;
|
|
134
134
|
getTradeAssetUnits(asset: string, height?: number): Promise<TradeUnitResponse>;
|
|
135
135
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-query",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
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": [
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"postversion": "git push --follow-tags"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@xchainjs/xchain-client": "2.0.
|
|
37
|
-
"@xchainjs/xchain-midgard-query": "2.0.
|
|
38
|
-
"@xchainjs/xchain-thornode": "1.2.
|
|
36
|
+
"@xchainjs/xchain-client": "2.0.14",
|
|
37
|
+
"@xchainjs/xchain-midgard-query": "2.0.17",
|
|
38
|
+
"@xchainjs/xchain-thornode": "1.2.1",
|
|
39
39
|
"@xchainjs/xchain-util": "2.0.7",
|
|
40
|
-
"axios": "1.
|
|
40
|
+
"axios": "1.16.1",
|
|
41
41
|
"axios-retry": "3.2.5",
|
|
42
42
|
"bignumber.js": "^11.0.0"
|
|
43
43
|
},
|