@xchainjs/xchain-mayachain-query 2.0.9 → 2.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 +30 -0
- package/lib/index.esm.js +162 -3
- package/lib/index.js +160 -1
- package/lib/mayachain-query.d.ts +30 -1
- package/lib/types.d.ts +99 -1
- package/lib/utils/mayanode.d.ts +33 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -105,6 +105,36 @@ Estimation of Add Saver
|
|
|
105
105
|
}
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
## Trade Accounts
|
|
109
|
+
|
|
110
|
+
Query trade account information and trade asset units:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { MayachainQuery } from '@xchainjs/xchain-mayachain-query'
|
|
114
|
+
import { assetFromStringEx, TradeAsset } from '@xchainjs/xchain-util'
|
|
115
|
+
|
|
116
|
+
const mayachainQuery = new MayachainQuery()
|
|
117
|
+
|
|
118
|
+
// Get trade asset units
|
|
119
|
+
const tradeAsset = assetFromStringEx('ETH~ETH') as TradeAsset
|
|
120
|
+
const units = await mayachainQuery.getTradeAssetUnits({ asset: tradeAsset })
|
|
121
|
+
console.log(`Units: ${units.units.assetAmount.amount()}`)
|
|
122
|
+
console.log(`Depth: ${units.depth.assetAmount.amount()}`)
|
|
123
|
+
|
|
124
|
+
// Get all trade assets units
|
|
125
|
+
const allUnits = await mayachainQuery.getTradeAssetsUnits()
|
|
126
|
+
|
|
127
|
+
// Get trade accounts for an address
|
|
128
|
+
const accounts = await mayachainQuery.getAddressTradeAccounts({
|
|
129
|
+
address: 'maya1...'
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
// Get all accounts for a trade asset
|
|
133
|
+
const assetAccounts = await mayachainQuery.getTradeAssetAccounts({
|
|
134
|
+
asset: tradeAsset
|
|
135
|
+
})
|
|
136
|
+
```
|
|
137
|
+
|
|
108
138
|
## Documentation
|
|
109
139
|
|
|
110
140
|
[`Overview `](https://dev.thorchain.org/thorchain-dev/xchainjs-integration-guide/query-package)
|
package/lib/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { assetFromStringEx, assetToString, baseAmount, CryptoAmount, CachedValue, AssetCryptoAmount, eqAsset, isSynthAsset, TRADE_ASSET_DELIMITER, SYNTH_ASSET_DELIMITER, TOKEN_ASSET_DELIMITER } from '@xchainjs/xchain-util';
|
|
1
|
+
import { assetFromStringEx, assetToString, baseAmount, CryptoAmount, CachedValue, AssetCryptoAmount, eqAsset, isSynthAsset, TRADE_ASSET_DELIMITER, SYNTH_ASSET_DELIMITER, TradeCryptoAmount, TOKEN_ASSET_DELIMITER } from '@xchainjs/xchain-util';
|
|
2
2
|
import { MidgardQuery } from '@xchainjs/xchain-mayamidgard-query';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { Network } from '@xchainjs/xchain-client';
|
|
5
|
-
import { QuoteApi, Configuration, MimirApi, NetworkApi } from '@xchainjs/xchain-mayanode';
|
|
5
|
+
import { QuoteApi, Configuration, MimirApi, NetworkApi, TradeUnitApi, TradeUnitsApi, TradeAccountApi, TradeAccountsApi } from '@xchainjs/xchain-mayanode';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import axiosRetry from 'axios-retry';
|
|
8
8
|
|
|
@@ -60,6 +60,10 @@ class Mayanode {
|
|
|
60
60
|
this.quoteApis = this.config.mayanodeBaseUrls.map((url) => new QuoteApi(new Configuration({ basePath: url })));
|
|
61
61
|
this.mimirApis = this.config.mayanodeBaseUrls.map((url) => new MimirApi(new Configuration({ basePath: url })));
|
|
62
62
|
this.networkApis = this.config.mayanodeBaseUrls.map((url) => new NetworkApi(new Configuration({ basePath: url })));
|
|
63
|
+
this.tradeUnitApis = this.config.mayanodeBaseUrls.map((url) => new TradeUnitApi(new Configuration({ basePath: url })));
|
|
64
|
+
this.tradeUnitsApis = this.config.mayanodeBaseUrls.map((url) => new TradeUnitsApi(new Configuration({ basePath: url })));
|
|
65
|
+
this.tradeAccountApis = this.config.mayanodeBaseUrls.map((url) => new TradeAccountApi(new Configuration({ basePath: url })));
|
|
66
|
+
this.tradeAccountsApis = this.config.mayanodeBaseUrls.map((url) => new TradeAccountsApi(new Configuration({ basePath: url })));
|
|
63
67
|
axiosRetry(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry.exponentialDelay });
|
|
64
68
|
}
|
|
65
69
|
/**
|
|
@@ -80,7 +84,9 @@ class Mayanode {
|
|
|
80
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
85
|
for (const api of this.quoteApis) {
|
|
82
86
|
try {
|
|
83
|
-
return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress,
|
|
87
|
+
return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, // refundAddress
|
|
88
|
+
streamingInterval, streamingQuantity, toleranceBps, undefined, // liquidityToleranceBps
|
|
89
|
+
affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
|
|
84
90
|
}
|
|
85
91
|
catch (e) { }
|
|
86
92
|
}
|
|
@@ -134,6 +140,77 @@ class Mayanode {
|
|
|
134
140
|
throw Error(`MAYANode not responding`);
|
|
135
141
|
});
|
|
136
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns the total units and depth of a trade asset
|
|
145
|
+
* @param {string} asset Trade asset (e.g., ETH~ETH)
|
|
146
|
+
* @param {number} height Optional - Block height
|
|
147
|
+
* @returns Returns the total units and depth of a trade asset
|
|
148
|
+
*/
|
|
149
|
+
getTradeAssetUnits(asset, height) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
for (const api of this.tradeUnitApis) {
|
|
152
|
+
try {
|
|
153
|
+
const resp = (yield api.tradeUnit(asset, height)).data;
|
|
154
|
+
return resp;
|
|
155
|
+
}
|
|
156
|
+
catch (e) { }
|
|
157
|
+
}
|
|
158
|
+
throw new Error(`MAYANode not responding. Can not get asset trade units`);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns the total units and depth for each trade asset
|
|
163
|
+
* @param {number} height Block height
|
|
164
|
+
* @returns Returns the total units and depth for each trade asset
|
|
165
|
+
*/
|
|
166
|
+
getTradeAssetsUnits(height) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
for (const api of this.tradeUnitsApis) {
|
|
169
|
+
try {
|
|
170
|
+
const resp = (yield api.tradeUnits(height)).data;
|
|
171
|
+
return resp;
|
|
172
|
+
}
|
|
173
|
+
catch (e) { }
|
|
174
|
+
}
|
|
175
|
+
throw new Error(`MAYANode not responding. Can not get trade units`);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Returns the units and depth of a trade account address
|
|
180
|
+
* @param {Address} address Maya address
|
|
181
|
+
* @param {number} height Optional - Block height
|
|
182
|
+
* @returns Returns the units and depth of a trade account
|
|
183
|
+
*/
|
|
184
|
+
getTradeAssetAccount(address, height) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
for (const api of this.tradeAccountApis) {
|
|
187
|
+
try {
|
|
188
|
+
const resp = (yield api.tradeAccount(address, height)).data;
|
|
189
|
+
return resp;
|
|
190
|
+
}
|
|
191
|
+
catch (e) { }
|
|
192
|
+
}
|
|
193
|
+
throw new Error(`MAYANode not responding. Can not get trade asset account`);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns all trade accounts for an asset
|
|
198
|
+
* @param {string} asset Trade asset (e.g., ETH~ETH)
|
|
199
|
+
* @param {number} height Optional - Block height
|
|
200
|
+
* @returns Returns all trade accounts for an asset
|
|
201
|
+
*/
|
|
202
|
+
getTradeAssetAccounts(asset, height) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
for (const api of this.tradeAccountsApis) {
|
|
205
|
+
try {
|
|
206
|
+
const resp = (yield api.tradeAccounts(asset, height)).data;
|
|
207
|
+
return resp;
|
|
208
|
+
}
|
|
209
|
+
catch (e) { }
|
|
210
|
+
}
|
|
211
|
+
throw new Error(`MAYANode not responding. Can not get trade asset accounts`);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
137
214
|
}
|
|
138
215
|
|
|
139
216
|
const BtcAsset = assetFromStringEx('BTC.BTC');
|
|
@@ -322,6 +399,13 @@ class MayachainQuery {
|
|
|
322
399
|
// Initialize MayachainCache instance
|
|
323
400
|
this.mayachainCache = mayachainCache;
|
|
324
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* Get the MayachainCache instance
|
|
404
|
+
* @returns MayachainCache instance
|
|
405
|
+
*/
|
|
406
|
+
getMayachainCache() {
|
|
407
|
+
return this.mayachainCache;
|
|
408
|
+
}
|
|
325
409
|
/**
|
|
326
410
|
* Get the Mayachain network.
|
|
327
411
|
* @returns
|
|
@@ -651,6 +735,81 @@ class MayachainQuery {
|
|
|
651
735
|
};
|
|
652
736
|
});
|
|
653
737
|
}
|
|
738
|
+
/**
|
|
739
|
+
* Get trade asset units
|
|
740
|
+
* @param {TradeAssetUnitsParams} params Trade asset units params
|
|
741
|
+
* @returns {TradeAssetUnits} Trade asset units
|
|
742
|
+
*/
|
|
743
|
+
getTradeAssetUnits(_a) {
|
|
744
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, height }) {
|
|
745
|
+
const assetString = assetToString(asset);
|
|
746
|
+
const response = yield this.mayachainCache.mayanode.getTradeAssetUnits(assetString, height);
|
|
747
|
+
return {
|
|
748
|
+
asset,
|
|
749
|
+
units: new TradeCryptoAmount(baseAmount(response.units), asset),
|
|
750
|
+
depth: new TradeCryptoAmount(baseAmount(response.depth), asset),
|
|
751
|
+
};
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Get all trade assets units
|
|
756
|
+
* @param {TradeAssetsUnitsParams} params Trade assets units params
|
|
757
|
+
* @returns {TradeAssetUnits[]} Array of trade asset units
|
|
758
|
+
*/
|
|
759
|
+
getTradeAssetsUnits() {
|
|
760
|
+
return __awaiter(this, arguments, void 0, function* ({ height } = {}) {
|
|
761
|
+
const response = yield this.mayachainCache.mayanode.getTradeAssetsUnits(height);
|
|
762
|
+
return response.map((item) => {
|
|
763
|
+
const asset = assetFromStringEx(item.asset);
|
|
764
|
+
return {
|
|
765
|
+
asset,
|
|
766
|
+
units: new TradeCryptoAmount(baseAmount(item.units), asset),
|
|
767
|
+
depth: new TradeCryptoAmount(baseAmount(item.depth), asset),
|
|
768
|
+
};
|
|
769
|
+
});
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Get trade accounts for an address
|
|
774
|
+
* @param {AddressTradeAccountsParams} params Address trade accounts params
|
|
775
|
+
* @returns {AddressTradeAccounts} Trade accounts for the address
|
|
776
|
+
*/
|
|
777
|
+
getAddressTradeAccounts(_a) {
|
|
778
|
+
return __awaiter(this, arguments, void 0, function* ({ address, height }) {
|
|
779
|
+
const response = yield this.mayachainCache.mayanode.getTradeAssetAccount(address, height);
|
|
780
|
+
return response.map((item) => {
|
|
781
|
+
const asset = assetFromStringEx(item.asset);
|
|
782
|
+
return {
|
|
783
|
+
asset,
|
|
784
|
+
units: new TradeCryptoAmount(baseAmount(item.units), asset),
|
|
785
|
+
owner: item.owner,
|
|
786
|
+
lastAddHeight: item.last_add_height,
|
|
787
|
+
lastWithdrawHeight: item.last_withdraw_height,
|
|
788
|
+
};
|
|
789
|
+
});
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Get all trade accounts for an asset
|
|
794
|
+
* @param {TradeAssetAccountsParams} params Trade asset accounts params
|
|
795
|
+
* @returns {TradeAssetAccounts} All trade accounts for the asset
|
|
796
|
+
*/
|
|
797
|
+
getTradeAssetAccounts(_a) {
|
|
798
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, height }) {
|
|
799
|
+
const assetString = assetToString(asset);
|
|
800
|
+
const response = yield this.mayachainCache.mayanode.getTradeAssetAccounts(assetString, height);
|
|
801
|
+
return response.map((item) => {
|
|
802
|
+
const tradeAsset = assetFromStringEx(item.asset);
|
|
803
|
+
return {
|
|
804
|
+
asset: tradeAsset,
|
|
805
|
+
units: new TradeCryptoAmount(baseAmount(item.units), tradeAsset),
|
|
806
|
+
owner: item.owner,
|
|
807
|
+
lastAddHeight: item.last_add_height,
|
|
808
|
+
lastWithdrawHeight: item.last_withdraw_height,
|
|
809
|
+
};
|
|
810
|
+
});
|
|
811
|
+
});
|
|
812
|
+
}
|
|
654
813
|
}
|
|
655
814
|
|
|
656
815
|
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
|
@@ -68,6 +68,10 @@ class Mayanode {
|
|
|
68
68
|
this.quoteApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.QuoteApi(new xchainMayanode.Configuration({ basePath: url })));
|
|
69
69
|
this.mimirApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.MimirApi(new xchainMayanode.Configuration({ basePath: url })));
|
|
70
70
|
this.networkApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.NetworkApi(new xchainMayanode.Configuration({ basePath: url })));
|
|
71
|
+
this.tradeUnitApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.TradeUnitApi(new xchainMayanode.Configuration({ basePath: url })));
|
|
72
|
+
this.tradeUnitsApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.TradeUnitsApi(new xchainMayanode.Configuration({ basePath: url })));
|
|
73
|
+
this.tradeAccountApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.TradeAccountApi(new xchainMayanode.Configuration({ basePath: url })));
|
|
74
|
+
this.tradeAccountsApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.TradeAccountsApi(new xchainMayanode.Configuration({ basePath: url })));
|
|
71
75
|
axiosRetry__default.default(axios__default.default, { retries: this.config.apiRetries, retryDelay: axiosRetry__default.default.exponentialDelay });
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
@@ -88,7 +92,9 @@ class Mayanode {
|
|
|
88
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
93
|
for (const api of this.quoteApis) {
|
|
90
94
|
try {
|
|
91
|
-
return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress,
|
|
95
|
+
return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, // refundAddress
|
|
96
|
+
streamingInterval, streamingQuantity, toleranceBps, undefined, // liquidityToleranceBps
|
|
97
|
+
affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
|
|
92
98
|
}
|
|
93
99
|
catch (e) { }
|
|
94
100
|
}
|
|
@@ -142,6 +148,77 @@ class Mayanode {
|
|
|
142
148
|
throw Error(`MAYANode not responding`);
|
|
143
149
|
});
|
|
144
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Returns the total units and depth of a trade asset
|
|
153
|
+
* @param {string} asset Trade asset (e.g., ETH~ETH)
|
|
154
|
+
* @param {number} height Optional - Block height
|
|
155
|
+
* @returns Returns the total units and depth of a trade asset
|
|
156
|
+
*/
|
|
157
|
+
getTradeAssetUnits(asset, height) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
for (const api of this.tradeUnitApis) {
|
|
160
|
+
try {
|
|
161
|
+
const resp = (yield api.tradeUnit(asset, height)).data;
|
|
162
|
+
return resp;
|
|
163
|
+
}
|
|
164
|
+
catch (e) { }
|
|
165
|
+
}
|
|
166
|
+
throw new Error(`MAYANode not responding. Can not get asset trade units`);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Returns the total units and depth for each trade asset
|
|
171
|
+
* @param {number} height Block height
|
|
172
|
+
* @returns Returns the total units and depth for each trade asset
|
|
173
|
+
*/
|
|
174
|
+
getTradeAssetsUnits(height) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
for (const api of this.tradeUnitsApis) {
|
|
177
|
+
try {
|
|
178
|
+
const resp = (yield api.tradeUnits(height)).data;
|
|
179
|
+
return resp;
|
|
180
|
+
}
|
|
181
|
+
catch (e) { }
|
|
182
|
+
}
|
|
183
|
+
throw new Error(`MAYANode not responding. Can not get trade units`);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Returns the units and depth of a trade account address
|
|
188
|
+
* @param {Address} address Maya address
|
|
189
|
+
* @param {number} height Optional - Block height
|
|
190
|
+
* @returns Returns the units and depth of a trade account
|
|
191
|
+
*/
|
|
192
|
+
getTradeAssetAccount(address, height) {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
for (const api of this.tradeAccountApis) {
|
|
195
|
+
try {
|
|
196
|
+
const resp = (yield api.tradeAccount(address, height)).data;
|
|
197
|
+
return resp;
|
|
198
|
+
}
|
|
199
|
+
catch (e) { }
|
|
200
|
+
}
|
|
201
|
+
throw new Error(`MAYANode not responding. Can not get trade asset account`);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns all trade accounts for an asset
|
|
206
|
+
* @param {string} asset Trade asset (e.g., ETH~ETH)
|
|
207
|
+
* @param {number} height Optional - Block height
|
|
208
|
+
* @returns Returns all trade accounts for an asset
|
|
209
|
+
*/
|
|
210
|
+
getTradeAssetAccounts(asset, height) {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
for (const api of this.tradeAccountsApis) {
|
|
213
|
+
try {
|
|
214
|
+
const resp = (yield api.tradeAccounts(asset, height)).data;
|
|
215
|
+
return resp;
|
|
216
|
+
}
|
|
217
|
+
catch (e) { }
|
|
218
|
+
}
|
|
219
|
+
throw new Error(`MAYANode not responding. Can not get trade asset accounts`);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
145
222
|
}
|
|
146
223
|
|
|
147
224
|
const BtcAsset = xchainUtil.assetFromStringEx('BTC.BTC');
|
|
@@ -330,6 +407,13 @@ class MayachainQuery {
|
|
|
330
407
|
// Initialize MayachainCache instance
|
|
331
408
|
this.mayachainCache = mayachainCache;
|
|
332
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Get the MayachainCache instance
|
|
412
|
+
* @returns MayachainCache instance
|
|
413
|
+
*/
|
|
414
|
+
getMayachainCache() {
|
|
415
|
+
return this.mayachainCache;
|
|
416
|
+
}
|
|
333
417
|
/**
|
|
334
418
|
* Get the Mayachain network.
|
|
335
419
|
* @returns
|
|
@@ -659,6 +743,81 @@ class MayachainQuery {
|
|
|
659
743
|
};
|
|
660
744
|
});
|
|
661
745
|
}
|
|
746
|
+
/**
|
|
747
|
+
* Get trade asset units
|
|
748
|
+
* @param {TradeAssetUnitsParams} params Trade asset units params
|
|
749
|
+
* @returns {TradeAssetUnits} Trade asset units
|
|
750
|
+
*/
|
|
751
|
+
getTradeAssetUnits(_a) {
|
|
752
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, height }) {
|
|
753
|
+
const assetString = xchainUtil.assetToString(asset);
|
|
754
|
+
const response = yield this.mayachainCache.mayanode.getTradeAssetUnits(assetString, height);
|
|
755
|
+
return {
|
|
756
|
+
asset,
|
|
757
|
+
units: new xchainUtil.TradeCryptoAmount(xchainUtil.baseAmount(response.units), asset),
|
|
758
|
+
depth: new xchainUtil.TradeCryptoAmount(xchainUtil.baseAmount(response.depth), asset),
|
|
759
|
+
};
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Get all trade assets units
|
|
764
|
+
* @param {TradeAssetsUnitsParams} params Trade assets units params
|
|
765
|
+
* @returns {TradeAssetUnits[]} Array of trade asset units
|
|
766
|
+
*/
|
|
767
|
+
getTradeAssetsUnits() {
|
|
768
|
+
return __awaiter(this, arguments, void 0, function* ({ height } = {}) {
|
|
769
|
+
const response = yield this.mayachainCache.mayanode.getTradeAssetsUnits(height);
|
|
770
|
+
return response.map((item) => {
|
|
771
|
+
const asset = xchainUtil.assetFromStringEx(item.asset);
|
|
772
|
+
return {
|
|
773
|
+
asset,
|
|
774
|
+
units: new xchainUtil.TradeCryptoAmount(xchainUtil.baseAmount(item.units), asset),
|
|
775
|
+
depth: new xchainUtil.TradeCryptoAmount(xchainUtil.baseAmount(item.depth), asset),
|
|
776
|
+
};
|
|
777
|
+
});
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Get trade accounts for an address
|
|
782
|
+
* @param {AddressTradeAccountsParams} params Address trade accounts params
|
|
783
|
+
* @returns {AddressTradeAccounts} Trade accounts for the address
|
|
784
|
+
*/
|
|
785
|
+
getAddressTradeAccounts(_a) {
|
|
786
|
+
return __awaiter(this, arguments, void 0, function* ({ address, height }) {
|
|
787
|
+
const response = yield this.mayachainCache.mayanode.getTradeAssetAccount(address, height);
|
|
788
|
+
return response.map((item) => {
|
|
789
|
+
const asset = xchainUtil.assetFromStringEx(item.asset);
|
|
790
|
+
return {
|
|
791
|
+
asset,
|
|
792
|
+
units: new xchainUtil.TradeCryptoAmount(xchainUtil.baseAmount(item.units), asset),
|
|
793
|
+
owner: item.owner,
|
|
794
|
+
lastAddHeight: item.last_add_height,
|
|
795
|
+
lastWithdrawHeight: item.last_withdraw_height,
|
|
796
|
+
};
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Get all trade accounts for an asset
|
|
802
|
+
* @param {TradeAssetAccountsParams} params Trade asset accounts params
|
|
803
|
+
* @returns {TradeAssetAccounts} All trade accounts for the asset
|
|
804
|
+
*/
|
|
805
|
+
getTradeAssetAccounts(_a) {
|
|
806
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, height }) {
|
|
807
|
+
const assetString = xchainUtil.assetToString(asset);
|
|
808
|
+
const response = yield this.mayachainCache.mayanode.getTradeAssetAccounts(assetString, height);
|
|
809
|
+
return response.map((item) => {
|
|
810
|
+
const tradeAsset = xchainUtil.assetFromStringEx(item.asset);
|
|
811
|
+
return {
|
|
812
|
+
asset: tradeAsset,
|
|
813
|
+
units: new xchainUtil.TradeCryptoAmount(xchainUtil.baseAmount(item.units), tradeAsset),
|
|
814
|
+
owner: item.owner,
|
|
815
|
+
lastAddHeight: item.last_add_height,
|
|
816
|
+
lastWithdrawHeight: item.last_withdraw_height,
|
|
817
|
+
};
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
}
|
|
662
821
|
}
|
|
663
822
|
|
|
664
823
|
exports.ArbAsset = ArbAsset;
|
package/lib/mayachain-query.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Network } from '@xchainjs/xchain-client';
|
|
|
2
2
|
import { PoolDetail } from '@xchainjs/xchain-mayamidgard';
|
|
3
3
|
import { Address, AssetCryptoAmount } from '@xchainjs/xchain-util';
|
|
4
4
|
import { MayachainCache } from './mayachain-cache';
|
|
5
|
-
import { CompatibleAsset, InboundDetail, MAYANameDetails, QuoteMAYAName, QuoteMAYANameParams, QuoteSwap, QuoteSwapParams, SwapHistoryParams, SwapsHistory } from './types';
|
|
5
|
+
import { AddressTradeAccounts, AddressTradeAccountsParams, CompatibleAsset, InboundDetail, MAYANameDetails, QuoteMAYAName, QuoteMAYANameParams, QuoteSwap, QuoteSwapParams, SwapHistoryParams, SwapsHistory, TradeAssetAccounts, TradeAssetAccountsParams, TradeAssetUnits, TradeAssetUnitsParams, TradeAssetsUnitsParams } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* MAYAChain Class for interacting with MAYAChain.
|
|
8
8
|
* Recommended main class to use for swapping with MAYAChain
|
|
@@ -17,6 +17,11 @@ export declare class MayachainQuery {
|
|
|
17
17
|
* @returns MayachainAMM
|
|
18
18
|
*/
|
|
19
19
|
constructor(mayachainCache?: MayachainCache);
|
|
20
|
+
/**
|
|
21
|
+
* Get the MayachainCache instance
|
|
22
|
+
* @returns MayachainCache instance
|
|
23
|
+
*/
|
|
24
|
+
getMayachainCache(): MayachainCache;
|
|
20
25
|
/**
|
|
21
26
|
* Get the Mayachain network.
|
|
22
27
|
* @returns
|
|
@@ -87,4 +92,28 @@ export declare class MayachainQuery {
|
|
|
87
92
|
* @returns {QuoteMAYAName} Memo to make the update or the registration and the estimation of the operation
|
|
88
93
|
*/
|
|
89
94
|
estimateMAYAName({ name, owner, isUpdate, expiry, chain, chainAddress, }: QuoteMAYANameParams): Promise<QuoteMAYAName>;
|
|
95
|
+
/**
|
|
96
|
+
* Get trade asset units
|
|
97
|
+
* @param {TradeAssetUnitsParams} params Trade asset units params
|
|
98
|
+
* @returns {TradeAssetUnits} Trade asset units
|
|
99
|
+
*/
|
|
100
|
+
getTradeAssetUnits({ asset, height }: TradeAssetUnitsParams): Promise<TradeAssetUnits>;
|
|
101
|
+
/**
|
|
102
|
+
* Get all trade assets units
|
|
103
|
+
* @param {TradeAssetsUnitsParams} params Trade assets units params
|
|
104
|
+
* @returns {TradeAssetUnits[]} Array of trade asset units
|
|
105
|
+
*/
|
|
106
|
+
getTradeAssetsUnits({ height }?: TradeAssetsUnitsParams): Promise<TradeAssetUnits[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Get trade accounts for an address
|
|
109
|
+
* @param {AddressTradeAccountsParams} params Address trade accounts params
|
|
110
|
+
* @returns {AddressTradeAccounts} Trade accounts for the address
|
|
111
|
+
*/
|
|
112
|
+
getAddressTradeAccounts({ address, height }: AddressTradeAccountsParams): Promise<AddressTradeAccounts>;
|
|
113
|
+
/**
|
|
114
|
+
* Get all trade accounts for an asset
|
|
115
|
+
* @param {TradeAssetAccountsParams} params Trade asset accounts params
|
|
116
|
+
* @returns {TradeAssetAccounts} All trade accounts for the asset
|
|
117
|
+
*/
|
|
118
|
+
getTradeAssetAccounts({ asset, height }: TradeAssetAccountsParams): Promise<TradeAssetAccounts>;
|
|
90
119
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TxHash } from '@xchainjs/xchain-client';
|
|
2
|
-
import { Address, Asset, AssetCryptoAmount, Chain, CryptoAmount, SynthAsset, TokenAsset } from '@xchainjs/xchain-util';
|
|
2
|
+
import { Address, Asset, AssetCryptoAmount, Chain, CryptoAmount, SynthAsset, TokenAsset, TradeAsset, TradeCryptoAmount } from '@xchainjs/xchain-util';
|
|
3
3
|
import type BigNumber from 'bignumber.js';
|
|
4
4
|
export type CompatibleAsset = Asset | TokenAsset | SynthAsset;
|
|
5
5
|
/**
|
|
@@ -239,3 +239,101 @@ export type QuoteMAYAName = {
|
|
|
239
239
|
*/
|
|
240
240
|
value: AssetCryptoAmount;
|
|
241
241
|
};
|
|
242
|
+
/**
|
|
243
|
+
* Trade asset units parameters
|
|
244
|
+
*/
|
|
245
|
+
export type TradeAssetUnitsParams = {
|
|
246
|
+
/**
|
|
247
|
+
* Trade asset to get units for
|
|
248
|
+
*/
|
|
249
|
+
asset: TradeAsset;
|
|
250
|
+
/**
|
|
251
|
+
* Optional block height
|
|
252
|
+
*/
|
|
253
|
+
height?: number;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Trade asset units response
|
|
257
|
+
*/
|
|
258
|
+
export type TradeAssetUnits = {
|
|
259
|
+
/**
|
|
260
|
+
* Trade asset
|
|
261
|
+
*/
|
|
262
|
+
asset: TradeAsset;
|
|
263
|
+
/**
|
|
264
|
+
* Total units of the trade asset
|
|
265
|
+
*/
|
|
266
|
+
units: TradeCryptoAmount;
|
|
267
|
+
/**
|
|
268
|
+
* Total depth of the trade asset
|
|
269
|
+
*/
|
|
270
|
+
depth: TradeCryptoAmount;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Trade assets units parameters
|
|
274
|
+
*/
|
|
275
|
+
export type TradeAssetsUnitsParams = {
|
|
276
|
+
/**
|
|
277
|
+
* Optional block height
|
|
278
|
+
*/
|
|
279
|
+
height?: number;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Address trade accounts parameters
|
|
283
|
+
*/
|
|
284
|
+
export type AddressTradeAccountsParams = {
|
|
285
|
+
/**
|
|
286
|
+
* Maya address to get trade accounts for
|
|
287
|
+
*/
|
|
288
|
+
address: Address;
|
|
289
|
+
/**
|
|
290
|
+
* Optional block height
|
|
291
|
+
*/
|
|
292
|
+
height?: number;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Address trade account
|
|
296
|
+
*/
|
|
297
|
+
export type AddressTradeAccount = {
|
|
298
|
+
/**
|
|
299
|
+
* Trade asset
|
|
300
|
+
*/
|
|
301
|
+
asset: TradeAsset;
|
|
302
|
+
/**
|
|
303
|
+
* Units of trade asset belonging to this owner
|
|
304
|
+
*/
|
|
305
|
+
units: TradeCryptoAmount;
|
|
306
|
+
/**
|
|
307
|
+
* Maya address of trade account owner
|
|
308
|
+
*/
|
|
309
|
+
owner: Address;
|
|
310
|
+
/**
|
|
311
|
+
* Last mayachain height trade assets were added
|
|
312
|
+
*/
|
|
313
|
+
lastAddHeight?: number;
|
|
314
|
+
/**
|
|
315
|
+
* Last mayachain height trade assets were withdrawn
|
|
316
|
+
*/
|
|
317
|
+
lastWithdrawHeight?: number;
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Address trade accounts response
|
|
321
|
+
*/
|
|
322
|
+
export type AddressTradeAccounts = AddressTradeAccount[];
|
|
323
|
+
/**
|
|
324
|
+
* Trade asset accounts parameters
|
|
325
|
+
*/
|
|
326
|
+
export type TradeAssetAccountsParams = {
|
|
327
|
+
/**
|
|
328
|
+
* Trade asset to get accounts for
|
|
329
|
+
*/
|
|
330
|
+
asset: TradeAsset;
|
|
331
|
+
/**
|
|
332
|
+
* Optional block height
|
|
333
|
+
*/
|
|
334
|
+
height?: number;
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Trade asset accounts response
|
|
338
|
+
*/
|
|
339
|
+
export type TradeAssetAccounts = AddressTradeAccount[];
|
package/lib/utils/mayanode.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
-
import { InboundAddress, LastBlock, MimirResponse, QuoteSwapResponse } from '@xchainjs/xchain-mayanode';
|
|
2
|
+
import { InboundAddress, LastBlock, MimirResponse, QuoteSwapResponse, TradeAccountsResponse, TradeUnitResponse, TradeUnitsResponse } from '@xchainjs/xchain-mayanode';
|
|
3
|
+
import { Address } from '@xchainjs/xchain-util';
|
|
3
4
|
export type MayanodeConfig = {
|
|
4
5
|
apiRetries: number;
|
|
5
6
|
mayanodeBaseUrls: string[];
|
|
@@ -10,6 +11,10 @@ export declare class Mayanode {
|
|
|
10
11
|
private quoteApis;
|
|
11
12
|
private mimirApis;
|
|
12
13
|
private networkApis;
|
|
14
|
+
private tradeUnitApis;
|
|
15
|
+
private tradeUnitsApis;
|
|
16
|
+
private tradeAccountApis;
|
|
17
|
+
private tradeAccountsApis;
|
|
13
18
|
constructor(network?: Network, config?: MayanodeConfig);
|
|
14
19
|
/**
|
|
15
20
|
* TODO
|
|
@@ -42,4 +47,31 @@ export declare class Mayanode {
|
|
|
42
47
|
* @returns - last block data or block data pertaining to that height number
|
|
43
48
|
*/
|
|
44
49
|
getLatestBlock(height?: number): Promise<LastBlock[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the total units and depth of a trade asset
|
|
52
|
+
* @param {string} asset Trade asset (e.g., ETH~ETH)
|
|
53
|
+
* @param {number} height Optional - Block height
|
|
54
|
+
* @returns Returns the total units and depth of a trade asset
|
|
55
|
+
*/
|
|
56
|
+
getTradeAssetUnits(asset: string, height?: number): Promise<TradeUnitResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the total units and depth for each trade asset
|
|
59
|
+
* @param {number} height Block height
|
|
60
|
+
* @returns Returns the total units and depth for each trade asset
|
|
61
|
+
*/
|
|
62
|
+
getTradeAssetsUnits(height?: number): Promise<TradeUnitsResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the units and depth of a trade account address
|
|
65
|
+
* @param {Address} address Maya address
|
|
66
|
+
* @param {number} height Optional - Block height
|
|
67
|
+
* @returns Returns the units and depth of a trade account
|
|
68
|
+
*/
|
|
69
|
+
getTradeAssetAccount(address: Address, height?: number): Promise<TradeAccountsResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* Returns all trade accounts for an asset
|
|
72
|
+
* @param {string} asset Trade asset (e.g., ETH~ETH)
|
|
73
|
+
* @param {number} height Optional - Block height
|
|
74
|
+
* @returns Returns all trade accounts for an asset
|
|
75
|
+
*/
|
|
76
|
+
getTradeAssetAccounts(asset: string, height?: number): Promise<TradeAccountsResponse>;
|
|
45
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-mayachain-query",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Mayachain query module that is responsible for estimating swap calculations and add/remove liquidity for thorchain",
|
|
6
6
|
"keywords": [
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"postversion": "git push --follow-tags"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@xchainjs/xchain-client": "2.0.
|
|
36
|
+
"@xchainjs/xchain-client": "2.0.8",
|
|
37
37
|
"@xchainjs/xchain-mayamidgard": "1.0.4",
|
|
38
|
-
"@xchainjs/xchain-mayamidgard-query": "1.0.
|
|
39
|
-
"@xchainjs/xchain-mayanode": "1.0
|
|
38
|
+
"@xchainjs/xchain-mayamidgard-query": "1.0.9",
|
|
39
|
+
"@xchainjs/xchain-mayanode": "1.1.0",
|
|
40
40
|
"@xchainjs/xchain-util": "2.0.4",
|
|
41
41
|
"axios": "1.8.4",
|
|
42
42
|
"axios-retry": "3.2.5",
|