@xchainjs/xchain-mayachain-query 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 MAYAChain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # `@xchainjs/xchain-mayachain-query`
2
+
3
+ Mayachain-query module to query mayachain for estimation of swaps/ add and remove Liquidity and checking a transaction stage.
4
+ Returns a TxDetail object with all the information needed to conduct a swap, or add liquidity. This includes estimateAddSavers()
5
+
6
+ ## Installation
7
+
8
+ ```
9
+ yarn add @xchainjs/xchain-maychain-query
10
+ ```
11
+
12
+ Following peer dependencies have to be installed into your project. These are not included in `@xchainjs/xchain-maychain-query`.
13
+
14
+ ```
15
+ yarn add @xchainjs/xchain-client @xchainjs/xchain-util @xchainjs/xchain-midgard @xchainjs/xchain-mayanode axios
16
+
17
+ ```
18
+
19
+ ## Examples
20
+
21
+ Estimation example from a swap of 2 BTC to CACAO
22
+
23
+ ```ts
24
+ {
25
+ memo: '=:CACAO.CACAO::2071168559999',
26
+ expiry: 2022-09-07T02:16:45.732Z,
27
+ toAddress: '',
28
+ txEstimate: {
29
+ input: '₿ 2',
30
+ totalFees: {
31
+ // @@@ Update icons
32
+ inboundFee: 'ᚱ 0.02',
33
+ swapFee: 'ᚱ 52.85380999',
34
+ outboundFee: 'ᚱ 0.06',
35
+ affiliateFee: 'ᚱ 0'
36
+ },
37
+ slipPercentage: '0.00246920801878638026',
38
+ netOutput: 'ᚱ 21,352.25318742',
39
+ waitTimeSeconds: '1248',
40
+ canSwap: true,
41
+ errors: []
42
+ }
43
+ }
44
+ ```
45
+
46
+ Estimation of add symetric liquidity
47
+ ```ts
48
+ {
49
+ rune: 'ᚱ 12,000',
50
+ asset: '⚡ 0',
51
+ slipPercent: '0.0747',
52
+ lpUnits: '154224962883',
53
+ runeToAssetRatio: '20064.69985077',
54
+ // @@@ Update references to rune
55
+ transactionFee: { assetFee: '⚡ 0', runeFee: 'ᚱ 0.02', totalFees: 'ᚱ 0.02' },
56
+ estimatedWaitSeconds: 6,
57
+ errors: [],
58
+ canAdd: true
59
+ }
60
+ ```
61
+
62
+ Estimation of remove Liquidity
63
+ ```ts
64
+ {
65
+ asset: { chain: 'BTC', symbol: 'BTC', ticker: 'BTC', synth: false },
66
+ percentage: 100,
67
+ assetAddress: 'bc1qufc5hvfvszphksqawadpc63ujarhjpn26je2jn',
68
+ runeAddress: ''
69
+ }
70
+ {
71
+ slipPercent: '0.0000',
72
+ runeAmount: 'ᚱ 1,664,891.55918601',
73
+ assetAmount: '₿ 83.01517361',
74
+ inbound: {
75
+ assetFee: '⚡ 10,000',
76
+ runeFee: 'ᚱ 0.02',
77
+ totalFees: 'ᚱ 2.02552681'
78
+ },
79
+ impermanentLossProtection: {
80
+ ILProtection: CryptoAmount { asset: [Object], baseAmount: [Object] },
81
+ totalDays: '346.62'
82
+ },
83
+ estimatedWaitSeconds: 8400
84
+ }
85
+ ```
86
+
87
+ Estimation of Add Saver
88
+ ```ts
89
+ {
90
+ assetAmount: '₿ 0.5',
91
+ estimatedDepositValue: '₿ 0.49937395',
92
+ fee: {
93
+ affiliateFee: '⚡ 0',
94
+ asset: { chain: 'BTC', symbol: 'BTC', ticker: 'BTC', synth: true },
95
+ outbound: '⚡ 0'
96
+ },
97
+ expiry: 2023-03-29T05:58:34.415Z,
98
+ toAddress: 'bc1qucjrczghvwl5d66klz6npv7tshkpwpzlw0zzj8',
99
+ memo: '+:BTC/BTC',
100
+ estimateWaitTime: 600,
101
+ saverCapFilledPercent: 266.3662135203711,
102
+ slipBasisPoints: 12,
103
+ canAdd: true,
104
+ errors: []
105
+ }
106
+ ```
107
+
108
+ ## Documentation
109
+
110
+ [`Overview `](https://dev.thorchain.org/thorchain-dev/xchainjs-integration-guide/query-package)
111
+
112
+ For bash exmples, see example folder at the base of this repository xchainjs/xchainjs-lib/examples/liquidity.
113
+
114
+ ### [`xchain-mayachain-query`](http://docs.xchainjs.org/xchain-thorchain-query/)
115
+
116
+ How xchain-mayachain-query works: http://docs.xchainjs.org/xchain-mayachain-query/how-it-works.html\
117
+ How to use xchain-mayachain-query: http://docs.xchainjs.org/xchain-mayachain-query/how-to-use.html
118
+
119
+ ## For Live examples
120
+
121
+ // @@@ Check if we have an equivalent
122
+ Estimate swap: https://replit.com/@thorchain/estimateSwap#index.ts\
123
+ Estimate add: https://replit.com/@thorchain/estimateAddliquidity\
124
+ Estimate withdraw: https://replit.com/@thorchain/estimateWithdrawLiquidity\
125
+ Check liquidity: https://replit.com/@thorchain/checkLiquidity\
126
+ List pools: https://replit.com/@thorchain/listPools#package.json\
127
+ Get Network Values: https://replit.com/@thorchain/networkValues#index.ts\
128
+
129
+ Estimate AddSaver() & WithdrawSaver() & getSaverPosition() https://replit.com/@thorchain/quoteDepositTS#index.ts
130
+
131
+ Check transaction Stage
132
+
133
+ ### Setting Headers for Nine Realms endpoints
134
+
135
+ 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
136
+
137
+ - https://midgard.ninerealms.com
138
+ - https://haskoin.ninerealms.com (BTC/BCH/LTC)
139
+ - https://thornode.ninerealms.com
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
+ For a complete example please see this [test](https://github.com/xchainjs/xchainjs-lib/blob/master/packages/xchain-mayachain-amm/__e2e__/wallet.e2e.ts)
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './mayachain-query';
2
+ export * from './mayachain-cache';
3
+ export * from './types';
4
+ export * from './utils';
@@ -0,0 +1,358 @@
1
+ import { assetFromStringEx, assetToString, baseAmount, CachedValue, CryptoAmount } from '@xchainjs/xchain-util';
2
+ import { MidgardQuery } from '@xchainjs/xchain-mayamidgard-query';
3
+ import { BigNumber } from 'bignumber.js';
4
+ import { Network } from '@xchainjs/xchain-client';
5
+ import { QuoteApi, Configuration, MimirApi, NetworkApi } from '@xchainjs/xchain-mayanode';
6
+ import axios from 'axios';
7
+ import axiosRetry from 'axios-retry';
8
+
9
+ /******************************************************************************
10
+ Copyright (c) Microsoft Corporation.
11
+
12
+ Permission to use, copy, modify, and/or distribute this software for any
13
+ purpose with or without fee is hereby granted.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
+ PERFORMANCE OF THIS SOFTWARE.
22
+ ***************************************************************************** */
23
+
24
+ function __awaiter(thisArg, _arguments, P, generator) {
25
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
+ return new (P || (P = Promise))(function (resolve, reject) {
27
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
31
+ });
32
+ }
33
+
34
+ const defaultMayanodeConfig = {
35
+ mainnet: {
36
+ apiRetries: 3,
37
+ mayanodeBaseUrls: ['https://mayanode.mayachain.info'],
38
+ },
39
+ stagenet: {
40
+ apiRetries: 3,
41
+ mayanodeBaseUrls: ['https://stagenet.mayanode.mayachain.info'],
42
+ },
43
+ testnet: {
44
+ apiRetries: 3,
45
+ // There is no testnet for mayanode
46
+ mayanodeBaseUrls: ['https://stagenet.mayanode.mayachain.info'],
47
+ },
48
+ };
49
+ class Mayanode {
50
+ constructor(network = Network.Mainnet, config) {
51
+ this.network = network;
52
+ this.config = config !== null && config !== void 0 ? config : defaultMayanodeConfig[this.network];
53
+ this.quoteApis = this.config.mayanodeBaseUrls.map((url) => new QuoteApi(new Configuration({ basePath: url })));
54
+ this.mimirApis = this.config.mayanodeBaseUrls.map((url) => new MimirApi(new Configuration({ basePath: url })));
55
+ this.networkApis = this.config.mayanodeBaseUrls.map((url) => new NetworkApi(new Configuration({ basePath: url })));
56
+ axiosRetry(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry.exponentialDelay });
57
+ }
58
+ /**
59
+ * TODO
60
+ * @param fromAsset - input asset
61
+ * @param toAsset - output asset
62
+ * @param amount - amount to swap
63
+ * @param destinationAddress - destination address for the swap
64
+ * @param toleranceBps - slip percent
65
+ * @param affiliateBps - affiliate percent
66
+ * @param affiliate - affiliate address
67
+ * @param height - block height
68
+ * @returns quotes swap object response
69
+ */
70
+ getSwapQuote(fromAsset, toAsset, amount, fromAddress, destinationAddress, toleranceBps, affiliateBps, affiliate, height) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ for (const api of this.quoteApis) {
73
+ try {
74
+ return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, fromAddress, toleranceBps, affiliateBps, affiliate)).data;
75
+ }
76
+ catch (e) { }
77
+ }
78
+ throw new Error(`MAYANode not responding`);
79
+ });
80
+ }
81
+ /**
82
+ * Get current active mimir configuration.
83
+ * @returns mimir configuration
84
+ */
85
+ getMimir() {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ for (const api of this.mimirApis) {
88
+ try {
89
+ return (yield api.mimir()).data;
90
+ }
91
+ catch (e) { }
92
+ }
93
+ throw Error(`MAYANode not responding`);
94
+ });
95
+ }
96
+ /**
97
+ * Get the set of asgard addresses that should be used for inbound transactions.
98
+ * @returns MAYA inbound addresses
99
+ */
100
+ getInboundAddresses() {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ for (const api of this.networkApis) {
103
+ try {
104
+ const resp = (yield api.inboundAddresses()).data;
105
+ return resp;
106
+ }
107
+ catch (e) { }
108
+ }
109
+ throw new Error(`MAYANode not responding`);
110
+ });
111
+ }
112
+ }
113
+
114
+ const BtcAsset = assetFromStringEx('BTC.BTC');
115
+ const EthAsset = assetFromStringEx('ETH.ETH');
116
+ const CacaoAsset = assetFromStringEx('MAYA.CACAO');
117
+ const RuneAsset = assetFromStringEx('THOR.RUNE');
118
+ const DashAsset = assetFromStringEx('DASH.DASH');
119
+ const KujiraAsset = assetFromStringEx('KUJI.KUJI');
120
+ const BtcChain = 'BTC';
121
+ const EthChain = 'ETH';
122
+ const MayaChain = 'MAYA';
123
+ const ThorChain = 'THOR';
124
+ const DashChain = 'DASH';
125
+ const KujiraChain = 'KUJI';
126
+ const DEFAULT_MAYACHAIN_DECIMALS = 8;
127
+
128
+ const isCacaoAsset = (asset) => assetToString(asset) === assetToString(CacaoAsset);
129
+ const getBaseAmountWithDiffDecimals = (inputAmount, outDecimals) => {
130
+ const inDecimals = inputAmount.baseAmount.decimal;
131
+ let baseAmountOut = inputAmount.baseAmount.amount();
132
+ const adjustDecimals = outDecimals - inDecimals;
133
+ baseAmountOut = baseAmountOut.times(Math.pow(10, adjustDecimals));
134
+ return baseAmount(baseAmountOut, outDecimals).amount();
135
+ };
136
+
137
+ /**
138
+ * This class manages retrieving information from up to date Mayachain
139
+ */
140
+ class MayachainCache {
141
+ /**
142
+ * Constructor to create a MayachainCache
143
+ *
144
+ * @param midgardQuery - an instance of the Maya MidgardQuery API
145
+ * @param mayanode
146
+ * @returns MayachainCache
147
+ */
148
+ constructor(midgardQuery = new MidgardQuery(), mayanode = new Mayanode(), configuration) {
149
+ this.midgardQuery = midgardQuery;
150
+ this.mayanode = mayanode;
151
+ this.conf = Object.assign({ expirationTimeInboundAddress: 6000 }, configuration);
152
+ this.inboundDetailCache = new CachedValue(() => this.refreshInboundDetailCache(), this.conf.expirationTimeInboundAddress);
153
+ }
154
+ /**
155
+ * Get inbound addresses details
156
+ * @returns Inbound details
157
+ */
158
+ getInboundDetails() {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ if (!this.inboundDetailCache)
161
+ throw Error(`Could not refresh inbound details`);
162
+ return yield this.inboundDetailCache.getValue();
163
+ });
164
+ }
165
+ /**
166
+ * Refreshes the InboundDetailCache Cache
167
+ */
168
+ refreshInboundDetailCache() {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ const [mimirDetails, allInboundAddresses] = yield Promise.all([
171
+ this.mayanode.getMimir(),
172
+ this.mayanode.getInboundAddresses(),
173
+ ]);
174
+ const inboundDetails = {};
175
+ for (const inbound of allInboundAddresses) {
176
+ const chain = inbound.chain;
177
+ if (!chain ||
178
+ !inbound.gas_rate ||
179
+ !inbound.address ||
180
+ !inbound.gas_rate_units ||
181
+ !inbound.outbound_tx_size ||
182
+ !inbound.outbound_fee ||
183
+ !inbound.gas_rate_units)
184
+ throw new Error(`Missing required inbound info`);
185
+ inboundDetails[chain] = {
186
+ chain: chain,
187
+ address: inbound.address,
188
+ router: inbound.router,
189
+ gasRate: new BigNumber(inbound.gas_rate),
190
+ gasRateUnits: inbound.gas_rate_units,
191
+ outboundTxSize: new BigNumber(inbound.outbound_tx_size),
192
+ outboundFee: new BigNumber(inbound.outbound_fee),
193
+ haltedChain: (inbound === null || inbound === void 0 ? void 0 : inbound.halted) || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],
194
+ haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],
195
+ haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],
196
+ };
197
+ }
198
+ // add mock MAYAChain inbound details
199
+ inboundDetails[MayaChain] = {
200
+ chain: MayaChain,
201
+ address: '',
202
+ router: '',
203
+ gasRate: new BigNumber(0),
204
+ gasRateUnits: '',
205
+ outboundTxSize: new BigNumber(0),
206
+ outboundFee: new BigNumber(0),
207
+ haltedChain: false,
208
+ haltedTrading: !!mimirDetails['HALTTRADING'],
209
+ haltedLP: false, //
210
+ };
211
+ return inboundDetails;
212
+ });
213
+ }
214
+ }
215
+
216
+ /**
217
+ * MAYAChain Class for interacting with MAYAChain.
218
+ * Recommended main class to use for swapping with MAYAChain
219
+ * Has access to Midgard and MAYANode data
220
+ */
221
+ class MayachainQuery {
222
+ /**
223
+ * Constructor to create a MayachainAMM
224
+ * @param mayachainCache - an instance of the MayachainCache (could be pointing to stagenet,testnet,mainnet)
225
+ * @param chainAttributes - attributes used to calculate waitTime & conf counting
226
+ * @returns MayachainAMM
227
+ */
228
+ constructor(mayachainCache = new MayachainCache()) {
229
+ this.mayachainCache = mayachainCache;
230
+ }
231
+ /**
232
+ * Get the mayachain query is working with
233
+ * @returns
234
+ */
235
+ getNetwork() {
236
+ return this.mayachainCache.midgardQuery.getNetwork();
237
+ }
238
+ /**
239
+ * Quote a swap
240
+ * @param {QuoteSwapParams} quoteSwapParams - quote swap input params
241
+ * @returns {QuoteSwap}
242
+ */
243
+ quoteSwap({ fromAsset, destinationAsset, amount, fromAddress, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, }) {
244
+ return __awaiter(this, void 0, void 0, function* () {
245
+ const fromAssetString = assetToString(fromAsset);
246
+ const toAssetString = assetToString(destinationAsset);
247
+ const inputAmount = getBaseAmountWithDiffDecimals(amount, 8);
248
+ const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), fromAddress, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height);
249
+ const response = JSON.parse(JSON.stringify(swapQuote));
250
+ if (response.error) {
251
+ return {
252
+ toAddress: ``,
253
+ memo: ``,
254
+ expectedAmount: new CryptoAmount(baseAmount(0), destinationAsset),
255
+ dustThreshold: this.getChainDustValue(fromAsset.chain),
256
+ fees: {
257
+ asset: destinationAsset,
258
+ affiliateFee: new CryptoAmount(baseAmount(0), fromAsset),
259
+ outboundFee: new CryptoAmount(baseAmount(0), destinationAsset),
260
+ },
261
+ outboundDelayBlocks: 0,
262
+ outboundDelaySeconds: 0,
263
+ inboundConfirmationSeconds: 0,
264
+ inboundConfirmationBlocks: 0,
265
+ canSwap: false,
266
+ errors: [`Mayanode request quote: ${response.error}`],
267
+ slipBasisPoints: 0,
268
+ totalSwapSeconds: 0,
269
+ warning: '',
270
+ };
271
+ }
272
+ const feeAsset = assetFromStringEx(swapQuote.fees.asset);
273
+ const errors = [];
274
+ if (swapQuote.memo === undefined)
275
+ errors.push(`Error parsing swap quote: Memo is ${swapQuote.memo}`);
276
+ return {
277
+ toAddress: swapQuote.inbound_address || '',
278
+ memo: swapQuote.memo || '',
279
+ expectedAmount: new CryptoAmount(baseAmount(swapQuote.expected_amount_out), destinationAsset),
280
+ dustThreshold: this.getChainDustValue(fromAsset.chain),
281
+ fees: {
282
+ asset: feeAsset,
283
+ affiliateFee: new CryptoAmount(baseAmount(swapQuote.fees.affiliate), feeAsset),
284
+ outboundFee: new CryptoAmount(baseAmount(swapQuote.fees.outbound), feeAsset),
285
+ },
286
+ slipBasisPoints: swapQuote.slippage_bps,
287
+ outboundDelayBlocks: swapQuote.outbound_delay_blocks,
288
+ outboundDelaySeconds: swapQuote.outbound_delay_seconds,
289
+ inboundConfirmationSeconds: swapQuote.inbound_confirmation_seconds,
290
+ inboundConfirmationBlocks: swapQuote.inbound_confirmation_blocks,
291
+ totalSwapSeconds: (swapQuote.inbound_confirmation_seconds || 0) + swapQuote.outbound_delay_seconds,
292
+ canSwap: !(!swapQuote.memo || errors.length > 0),
293
+ errors,
294
+ warning: '',
295
+ };
296
+ });
297
+ }
298
+ /**
299
+ * Return mayachain supported chains dust amounts
300
+ * @returns a map where chain is the key and dust amount cryptoAmount as value
301
+ */
302
+ getDustValues() {
303
+ // TODO: Find out how to fetch native asset decimals
304
+ return {
305
+ [BtcChain]: new CryptoAmount(baseAmount(10000, 8), BtcAsset),
306
+ [EthChain]: new CryptoAmount(baseAmount(0, 8), EthAsset),
307
+ [DashChain]: new CryptoAmount(baseAmount(10000, 8), DashAsset),
308
+ [KujiraChain]: new CryptoAmount(baseAmount(0, 8), KujiraAsset),
309
+ [ThorChain]: new CryptoAmount(baseAmount(0, 8), RuneAsset),
310
+ [MayaChain]: new CryptoAmount(baseAmount(0, 8), CacaoAsset),
311
+ };
312
+ }
313
+ /**
314
+ * Return the dust crypto amount from the given chain
315
+ * @param {string} chain Chain to retrieve the dust amount of
316
+ * @returns a map where chain is the key and dust amount cryptoAmount as value
317
+ */
318
+ getChainDustValue(chain) {
319
+ const dustValue = this.getDustValues()[chain];
320
+ if (!dustValue)
321
+ throw Error(`No dust value known for ${chain} chain`);
322
+ return dustValue;
323
+ }
324
+ /**
325
+ * Get MAYAname details
326
+ * @param {string} MAYAName
327
+ * @returns {MAYANameDetails | undefined} MAYANames details or undefined it is does not exist
328
+ */
329
+ getMAYANameDetails(MAYAName) {
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ return this.mayachainCache.midgardQuery.getMAYANameDetails(MAYAName);
332
+ });
333
+ }
334
+ /**
335
+ * Get inbound addresses details
336
+ * @returns Inbound details
337
+ */
338
+ getInboundDetails() {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ return this.mayachainCache.getInboundDetails();
341
+ });
342
+ }
343
+ /**
344
+ * Get chain inbound address details
345
+ * @returns Inbound details
346
+ */
347
+ getChainInboundDetails(chain) {
348
+ return __awaiter(this, void 0, void 0, function* () {
349
+ const inboundDetails = yield this.getInboundDetails();
350
+ if (inboundDetails[chain])
351
+ throw Error(`No inbound details known for ${chain} chain`);
352
+ return inboundDetails[chain];
353
+ });
354
+ }
355
+ }
356
+
357
+ export { BtcAsset, BtcChain, CacaoAsset, DEFAULT_MAYACHAIN_DECIMALS, DashAsset, DashChain, EthAsset, EthChain, KujiraAsset, KujiraChain, MayaChain, MayachainCache, MayachainQuery, Mayanode, RuneAsset, ThorChain, getBaseAmountWithDiffDecimals, isCacaoAsset };
358
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/utils/mayanode.ts","../src/utils/const.ts","../src/utils/utils.ts","../src/mayachain-cache.ts","../src/mayachain-query.ts"],"sourcesContent":["import { Network } from '@xchainjs/xchain-client'\nimport {\n Configuration,\n InboundAddress,\n MimirApi,\n MimirResponse,\n NetworkApi,\n QuoteApi,\n QuoteSwapResponse,\n} from '@xchainjs/xchain-mayanode'\nimport axios from 'axios'\nimport axiosRetry from 'axios-retry'\n\nexport type MayanodeConfig = {\n apiRetries: number\n mayanodeBaseUrls: string[]\n}\n\nconst defaultMayanodeConfig: Record<Network, MayanodeConfig> = {\n mainnet: {\n apiRetries: 3,\n mayanodeBaseUrls: ['https://mayanode.mayachain.info'],\n },\n stagenet: {\n apiRetries: 3,\n mayanodeBaseUrls: ['https://stagenet.mayanode.mayachain.info'],\n },\n testnet: {\n apiRetries: 3,\n // There is no testnet for mayanode\n mayanodeBaseUrls: ['https://stagenet.mayanode.mayachain.info'],\n },\n}\n\nexport class Mayanode {\n private config: MayanodeConfig\n private network: Network\n private quoteApis: QuoteApi[]\n private mimirApis: MimirApi[]\n private networkApis: NetworkApi[]\n\n constructor(network: Network = Network.Mainnet, config?: MayanodeConfig) {\n this.network = network\n this.config = config ?? defaultMayanodeConfig[this.network]\n this.quoteApis = this.config.mayanodeBaseUrls.map((url) => new QuoteApi(new Configuration({ basePath: url })))\n this.mimirApis = this.config.mayanodeBaseUrls.map((url) => new MimirApi(new Configuration({ basePath: url })))\n this.networkApis = this.config.mayanodeBaseUrls.map((url) => new NetworkApi(new Configuration({ basePath: url })))\n\n axiosRetry(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry.exponentialDelay })\n }\n\n /**\n * TODO\n * @param fromAsset - input asset\n * @param toAsset - output asset\n * @param amount - amount to swap\n * @param destinationAddress - destination address for the swap\n * @param toleranceBps - slip percent\n * @param affiliateBps - affiliate percent\n * @param affiliate - affiliate address\n * @param height - block height\n * @returns quotes swap object response\n */\n public async getSwapQuote(\n fromAsset: string,\n toAsset: string,\n amount: number,\n fromAddress?: string,\n destinationAddress?: string,\n toleranceBps?: number,\n affiliateBps?: number,\n affiliate?: string,\n height?: number,\n ): Promise<QuoteSwapResponse> {\n for (const api of this.quoteApis) {\n try {\n return (\n await api.quoteswap(\n height,\n fromAsset,\n toAsset,\n amount,\n destinationAddress,\n fromAddress,\n toleranceBps,\n affiliateBps,\n affiliate,\n )\n ).data\n } catch (e) {}\n }\n throw new Error(`MAYANode not responding`)\n }\n\n /**\n * Get current active mimir configuration.\n * @returns mimir configuration\n */\n public async getMimir(): Promise<MimirResponse> {\n for (const api of this.mimirApis) {\n try {\n return (await api.mimir()).data\n } catch (e) {}\n }\n throw Error(`MAYANode not responding`)\n }\n\n /**\n * Get the set of asgard addresses that should be used for inbound transactions.\n * @returns MAYA inbound addresses\n */\n public async getInboundAddresses(): Promise<InboundAddress[]> {\n for (const api of this.networkApis) {\n try {\n const resp = (await api.inboundAddresses()).data\n return resp\n } catch (e) {}\n }\n throw new Error(`MAYANode not responding`)\n }\n}\n","import { assetFromStringEx } from '@xchainjs/xchain-util'\n\nexport const BtcAsset = assetFromStringEx('BTC.BTC')\nexport const EthAsset = assetFromStringEx('ETH.ETH')\nexport const CacaoAsset = assetFromStringEx('MAYA.CACAO')\nexport const RuneAsset = assetFromStringEx('THOR.RUNE')\nexport const DashAsset = assetFromStringEx('DASH.DASH')\nexport const KujiraAsset = assetFromStringEx('KUJI.KUJI')\n\nexport const BtcChain = 'BTC'\nexport const EthChain = 'ETH'\nexport const MayaChain = 'MAYA'\nexport const ThorChain = 'THOR'\nexport const DashChain = 'DASH'\nexport const KujiraChain = 'KUJI'\n\nexport const DEFAULT_MAYACHAIN_DECIMALS = 8\n","import { Asset, CryptoAmount, assetToString, baseAmount } from '@xchainjs/xchain-util'\nimport BigNumber from 'bignumber.js'\n\nimport { CacaoAsset } from './const'\n\nexport const isCacaoAsset = (asset: Asset): boolean => assetToString(asset) === assetToString(CacaoAsset)\n\nexport const getBaseAmountWithDiffDecimals = (inputAmount: CryptoAmount, outDecimals: number): BigNumber => {\n const inDecimals = inputAmount.baseAmount.decimal\n let baseAmountOut = inputAmount.baseAmount.amount()\n const adjustDecimals = outDecimals - inDecimals\n baseAmountOut = baseAmountOut.times(10 ** adjustDecimals)\n return baseAmount(baseAmountOut, outDecimals).amount()\n}\n","import { MidgardQuery } from '@xchainjs/xchain-mayamidgard-query'\nimport { CachedValue } from '@xchainjs/xchain-util'\nimport { BigNumber } from 'bignumber.js'\n\nimport { InboundDetail } from './types'\nimport { MayaChain, Mayanode } from './utils'\n\nexport type MayachainCacheConf = {\n expirationTimeInboundAddress: number\n}\n/**\n * This class manages retrieving information from up to date Mayachain\n */\nexport class MayachainCache {\n readonly midgardQuery: MidgardQuery\n readonly mayanode: Mayanode\n private conf: MayachainCacheConf\n private readonly inboundDetailCache: CachedValue<Record<string, InboundDetail>>\n /**\n * Constructor to create a MayachainCache\n *\n * @param midgardQuery - an instance of the Maya MidgardQuery API\n * @param mayanode\n * @returns MayachainCache\n */\n constructor(\n midgardQuery = new MidgardQuery(),\n mayanode = new Mayanode(),\n configuration?: Partial<MayachainCacheConf>,\n ) {\n this.midgardQuery = midgardQuery\n this.mayanode = mayanode\n this.conf = { expirationTimeInboundAddress: 6000, ...configuration }\n\n this.inboundDetailCache = new CachedValue<Record<string, InboundDetail>>(\n () => this.refreshInboundDetailCache(),\n this.conf.expirationTimeInboundAddress,\n )\n }\n\n /**\n * Get inbound addresses details\n * @returns Inbound details\n */\n public async getInboundDetails(): Promise<Record<string, InboundDetail>> {\n if (!this.inboundDetailCache) throw Error(`Could not refresh inbound details`)\n return await this.inboundDetailCache.getValue()\n }\n\n /**\n * Refreshes the InboundDetailCache Cache\n */\n private async refreshInboundDetailCache(): Promise<Record<string, InboundDetail>> {\n const [mimirDetails, allInboundAddresses] = await Promise.all([\n this.mayanode.getMimir(),\n this.mayanode.getInboundAddresses(),\n ])\n const inboundDetails: Record<string, InboundDetail> = {}\n for (const inbound of allInboundAddresses) {\n const chain = inbound.chain\n if (\n !chain ||\n !inbound.gas_rate ||\n !inbound.address ||\n !inbound.gas_rate_units ||\n !inbound.outbound_tx_size ||\n !inbound.outbound_fee ||\n !inbound.gas_rate_units\n )\n throw new Error(`Missing required inbound info`)\n\n inboundDetails[chain] = {\n chain: chain,\n address: inbound.address,\n router: inbound.router,\n gasRate: new BigNumber(inbound.gas_rate),\n gasRateUnits: inbound.gas_rate_units,\n outboundTxSize: new BigNumber(inbound.outbound_tx_size),\n outboundFee: new BigNumber(inbound.outbound_fee),\n haltedChain: inbound?.halted || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],\n haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],\n haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],\n }\n }\n // add mock MAYAChain inbound details\n inboundDetails[MayaChain] = {\n chain: MayaChain,\n address: '',\n router: '',\n gasRate: new BigNumber(0),\n gasRateUnits: '',\n outboundTxSize: new BigNumber(0),\n outboundFee: new BigNumber(0),\n haltedChain: false,\n haltedTrading: !!mimirDetails['HALTTRADING'],\n haltedLP: false, //\n }\n\n return inboundDetails\n }\n}\n","import { Network } from '@xchainjs/xchain-client'\nimport { MAYANameDetails } from '@xchainjs/xchain-mayamidgard-query'\nimport { QuoteSwapResponse } from '@xchainjs/xchain-mayanode'\nimport { CryptoAmount, assetFromStringEx, assetToString, baseAmount } from '@xchainjs/xchain-util'\n\nimport { MayachainCache } from './mayachain-cache'\nimport { InboundDetail, QuoteSwap, QuoteSwapParams } from './types'\nimport {\n BtcAsset,\n BtcChain,\n CacaoAsset,\n DashAsset,\n DashChain,\n EthAsset,\n EthChain,\n KujiraAsset,\n KujiraChain,\n MayaChain,\n RuneAsset,\n ThorChain,\n getBaseAmountWithDiffDecimals,\n} from './utils'\n\n/**\n * MAYAChain Class for interacting with MAYAChain.\n * Recommended main class to use for swapping with MAYAChain\n * Has access to Midgard and MAYANode data\n */\nexport class MayachainQuery {\n private mayachainCache: MayachainCache\n\n /**\n * Constructor to create a MayachainAMM\n * @param mayachainCache - an instance of the MayachainCache (could be pointing to stagenet,testnet,mainnet)\n * @param chainAttributes - attributes used to calculate waitTime & conf counting\n * @returns MayachainAMM\n */\n constructor(mayachainCache = new MayachainCache()) {\n this.mayachainCache = mayachainCache\n }\n\n /**\n * Get the mayachain query is working with\n * @returns\n */\n public getNetwork(): Network {\n return this.mayachainCache.midgardQuery.getNetwork()\n }\n\n /**\n * Quote a swap\n * @param {QuoteSwapParams} quoteSwapParams - quote swap input params\n * @returns {QuoteSwap}\n */\n public async quoteSwap({\n fromAsset,\n destinationAsset,\n amount,\n fromAddress,\n destinationAddress,\n toleranceBps,\n affiliateBps,\n affiliateAddress,\n height,\n }: QuoteSwapParams): Promise<QuoteSwap> {\n const fromAssetString = assetToString(fromAsset)\n const toAssetString = assetToString(destinationAsset)\n const inputAmount = getBaseAmountWithDiffDecimals(amount, 8)\n\n const swapQuote: QuoteSwapResponse = await this.mayachainCache.mayanode.getSwapQuote(\n fromAssetString,\n toAssetString,\n inputAmount.toNumber(),\n fromAddress,\n destinationAddress,\n toleranceBps,\n affiliateBps,\n affiliateAddress,\n height,\n )\n\n const response: { error?: string } = JSON.parse(JSON.stringify(swapQuote))\n if (response.error) {\n return {\n toAddress: ``,\n memo: ``,\n expectedAmount: new CryptoAmount(baseAmount(0), destinationAsset),\n dustThreshold: this.getChainDustValue(fromAsset.chain),\n fees: {\n asset: destinationAsset,\n affiliateFee: new CryptoAmount(baseAmount(0), fromAsset),\n outboundFee: new CryptoAmount(baseAmount(0), destinationAsset),\n },\n outboundDelayBlocks: 0,\n outboundDelaySeconds: 0,\n inboundConfirmationSeconds: 0,\n inboundConfirmationBlocks: 0,\n canSwap: false,\n errors: [`Mayanode request quote: ${response.error}`],\n slipBasisPoints: 0,\n totalSwapSeconds: 0,\n warning: '',\n }\n }\n\n const feeAsset = assetFromStringEx(swapQuote.fees.asset)\n\n const errors: string[] = []\n if (swapQuote.memo === undefined) errors.push(`Error parsing swap quote: Memo is ${swapQuote.memo}`)\n\n return {\n toAddress: swapQuote.inbound_address || '',\n memo: swapQuote.memo || '',\n expectedAmount: new CryptoAmount(baseAmount(swapQuote.expected_amount_out), destinationAsset),\n dustThreshold: this.getChainDustValue(fromAsset.chain),\n fees: {\n asset: feeAsset,\n affiliateFee: new CryptoAmount(baseAmount(swapQuote.fees.affiliate), feeAsset),\n outboundFee: new CryptoAmount(baseAmount(swapQuote.fees.outbound), feeAsset),\n },\n slipBasisPoints: swapQuote.slippage_bps,\n outboundDelayBlocks: swapQuote.outbound_delay_blocks,\n outboundDelaySeconds: swapQuote.outbound_delay_seconds,\n inboundConfirmationSeconds: swapQuote.inbound_confirmation_seconds,\n inboundConfirmationBlocks: swapQuote.inbound_confirmation_blocks,\n totalSwapSeconds: (swapQuote.inbound_confirmation_seconds || 0) + swapQuote.outbound_delay_seconds,\n canSwap: !(!swapQuote.memo || errors.length > 0),\n errors,\n warning: '',\n }\n }\n\n /**\n * Return mayachain supported chains dust amounts\n * @returns a map where chain is the key and dust amount cryptoAmount as value\n */\n public getDustValues(): Record<string, CryptoAmount> {\n // TODO: Find out how to fetch native asset decimals\n return {\n [BtcChain]: new CryptoAmount(baseAmount(10000, 8), BtcAsset),\n [EthChain]: new CryptoAmount(baseAmount(0, 8), EthAsset),\n [DashChain]: new CryptoAmount(baseAmount(10000, 8), DashAsset),\n [KujiraChain]: new CryptoAmount(baseAmount(0, 8), KujiraAsset),\n [ThorChain]: new CryptoAmount(baseAmount(0, 8), RuneAsset),\n [MayaChain]: new CryptoAmount(baseAmount(0, 8), CacaoAsset),\n }\n }\n\n /**\n * Return the dust crypto amount from the given chain\n * @param {string} chain Chain to retrieve the dust amount of\n * @returns a map where chain is the key and dust amount cryptoAmount as value\n */\n public getChainDustValue(chain: string): CryptoAmount {\n const dustValue = this.getDustValues()[chain]\n if (!dustValue) throw Error(`No dust value known for ${chain} chain`)\n return dustValue\n }\n\n /**\n * Get MAYAname details\n * @param {string} MAYAName\n * @returns {MAYANameDetails | undefined} MAYANames details or undefined it is does not exist\n */\n public async getMAYANameDetails(MAYAName: string): Promise<MAYANameDetails | undefined> {\n return this.mayachainCache.midgardQuery.getMAYANameDetails(MAYAName)\n }\n\n /**\n * Get inbound addresses details\n * @returns Inbound details\n */\n public async getInboundDetails(): Promise<Record<string, InboundDetail>> {\n return this.mayachainCache.getInboundDetails()\n }\n\n /**\n * Get chain inbound address details\n * @returns Inbound details\n */\n public async getChainInboundDetails(chain: string): Promise<InboundDetail> {\n const inboundDetails = await this.getInboundDetails()\n if (inboundDetails[chain]) throw Error(`No inbound details known for ${chain} chain`)\n return inboundDetails[chain]\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,qBAAqB,GAAoC;AAC7D,IAAA,OAAO,EAAE;AACP,QAAA,UAAU,EAAE,CAAC;QACb,gBAAgB,EAAE,CAAC,iCAAiC,CAAC;AACtD,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,UAAU,EAAE,CAAC;QACb,gBAAgB,EAAE,CAAC,0CAA0C,CAAC;AAC/D,KAAA;AACD,IAAA,OAAO,EAAE;AACP,QAAA,UAAU,EAAE,CAAC;;QAEb,gBAAgB,EAAE,CAAC,0CAA0C,CAAC;AAC/D,KAAA;CACF,CAAA;MAEY,QAAQ,CAAA;AAOnB,IAAA,WAAA,CAAY,OAAmB,GAAA,OAAO,CAAC,OAAO,EAAE,MAAuB,EAAA;AACrE,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;AACtB,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,aAAN,MAAM,KAAA,KAAA,CAAA,GAAN,MAAM,GAAI,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAC3D,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,QAAQ,CAAC,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;AAC9G,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,QAAQ,CAAC,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;A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BAAsB,CAAC,KAAa,EAAA;;AAC/C,YAAA,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAA;YACrD,IAAI,cAAc,CAAC,KAAK,CAAC;AAAE,gBAAA,MAAM,KAAK,CAAC,CAAA,6BAAA,EAAgC,KAAK,CAAA,MAAA,CAAQ,CAAC,CAAA;AACrF,YAAA,OAAO,cAAc,CAAC,KAAK,CAAC,CAAA;SAC7B,CAAA,CAAA;AAAA,KAAA;AACF;;;;"}
package/lib/index.js ADDED
@@ -0,0 +1,384 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var xchainUtil = require('@xchainjs/xchain-util');
6
+ var xchainMayamidgardQuery = require('@xchainjs/xchain-mayamidgard-query');
7
+ var bignumber_js = require('bignumber.js');
8
+ var xchainClient = require('@xchainjs/xchain-client');
9
+ var xchainMayanode = require('@xchainjs/xchain-mayanode');
10
+ var axios = require('axios');
11
+ var axiosRetry = require('axios-retry');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
16
+ var axiosRetry__default = /*#__PURE__*/_interopDefaultLegacy(axiosRetry);
17
+
18
+ /******************************************************************************
19
+ Copyright (c) Microsoft Corporation.
20
+
21
+ Permission to use, copy, modify, and/or distribute this software for any
22
+ purpose with or without fee is hereby granted.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
25
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
26
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
27
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
28
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
29
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
30
+ PERFORMANCE OF THIS SOFTWARE.
31
+ ***************************************************************************** */
32
+
33
+ function __awaiter(thisArg, _arguments, P, generator) {
34
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
+ return new (P || (P = Promise))(function (resolve, reject) {
36
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
37
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
38
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
39
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
40
+ });
41
+ }
42
+
43
+ const defaultMayanodeConfig = {
44
+ mainnet: {
45
+ apiRetries: 3,
46
+ mayanodeBaseUrls: ['https://mayanode.mayachain.info'],
47
+ },
48
+ stagenet: {
49
+ apiRetries: 3,
50
+ mayanodeBaseUrls: ['https://stagenet.mayanode.mayachain.info'],
51
+ },
52
+ testnet: {
53
+ apiRetries: 3,
54
+ // There is no testnet for mayanode
55
+ mayanodeBaseUrls: ['https://stagenet.mayanode.mayachain.info'],
56
+ },
57
+ };
58
+ class Mayanode {
59
+ constructor(network = xchainClient.Network.Mainnet, config) {
60
+ this.network = network;
61
+ this.config = config !== null && config !== void 0 ? config : defaultMayanodeConfig[this.network];
62
+ this.quoteApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.QuoteApi(new xchainMayanode.Configuration({ basePath: url })));
63
+ this.mimirApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.MimirApi(new xchainMayanode.Configuration({ basePath: url })));
64
+ this.networkApis = this.config.mayanodeBaseUrls.map((url) => new xchainMayanode.NetworkApi(new xchainMayanode.Configuration({ basePath: url })));
65
+ axiosRetry__default["default"](axios__default["default"], { retries: this.config.apiRetries, retryDelay: axiosRetry__default["default"].exponentialDelay });
66
+ }
67
+ /**
68
+ * TODO
69
+ * @param fromAsset - input asset
70
+ * @param toAsset - output asset
71
+ * @param amount - amount to swap
72
+ * @param destinationAddress - destination address for the swap
73
+ * @param toleranceBps - slip percent
74
+ * @param affiliateBps - affiliate percent
75
+ * @param affiliate - affiliate address
76
+ * @param height - block height
77
+ * @returns quotes swap object response
78
+ */
79
+ getSwapQuote(fromAsset, toAsset, amount, fromAddress, destinationAddress, toleranceBps, affiliateBps, affiliate, height) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ for (const api of this.quoteApis) {
82
+ try {
83
+ return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, fromAddress, toleranceBps, affiliateBps, affiliate)).data;
84
+ }
85
+ catch (e) { }
86
+ }
87
+ throw new Error(`MAYANode not responding`);
88
+ });
89
+ }
90
+ /**
91
+ * Get current active mimir configuration.
92
+ * @returns mimir configuration
93
+ */
94
+ getMimir() {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ for (const api of this.mimirApis) {
97
+ try {
98
+ return (yield api.mimir()).data;
99
+ }
100
+ catch (e) { }
101
+ }
102
+ throw Error(`MAYANode not responding`);
103
+ });
104
+ }
105
+ /**
106
+ * Get the set of asgard addresses that should be used for inbound transactions.
107
+ * @returns MAYA inbound addresses
108
+ */
109
+ getInboundAddresses() {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ for (const api of this.networkApis) {
112
+ try {
113
+ const resp = (yield api.inboundAddresses()).data;
114
+ return resp;
115
+ }
116
+ catch (e) { }
117
+ }
118
+ throw new Error(`MAYANode not responding`);
119
+ });
120
+ }
121
+ }
122
+
123
+ const BtcAsset = xchainUtil.assetFromStringEx('BTC.BTC');
124
+ const EthAsset = xchainUtil.assetFromStringEx('ETH.ETH');
125
+ const CacaoAsset = xchainUtil.assetFromStringEx('MAYA.CACAO');
126
+ const RuneAsset = xchainUtil.assetFromStringEx('THOR.RUNE');
127
+ const DashAsset = xchainUtil.assetFromStringEx('DASH.DASH');
128
+ const KujiraAsset = xchainUtil.assetFromStringEx('KUJI.KUJI');
129
+ const BtcChain = 'BTC';
130
+ const EthChain = 'ETH';
131
+ const MayaChain = 'MAYA';
132
+ const ThorChain = 'THOR';
133
+ const DashChain = 'DASH';
134
+ const KujiraChain = 'KUJI';
135
+ const DEFAULT_MAYACHAIN_DECIMALS = 8;
136
+
137
+ const isCacaoAsset = (asset) => xchainUtil.assetToString(asset) === xchainUtil.assetToString(CacaoAsset);
138
+ const getBaseAmountWithDiffDecimals = (inputAmount, outDecimals) => {
139
+ const inDecimals = inputAmount.baseAmount.decimal;
140
+ let baseAmountOut = inputAmount.baseAmount.amount();
141
+ const adjustDecimals = outDecimals - inDecimals;
142
+ baseAmountOut = baseAmountOut.times(Math.pow(10, adjustDecimals));
143
+ return xchainUtil.baseAmount(baseAmountOut, outDecimals).amount();
144
+ };
145
+
146
+ /**
147
+ * This class manages retrieving information from up to date Mayachain
148
+ */
149
+ class MayachainCache {
150
+ /**
151
+ * Constructor to create a MayachainCache
152
+ *
153
+ * @param midgardQuery - an instance of the Maya MidgardQuery API
154
+ * @param mayanode
155
+ * @returns MayachainCache
156
+ */
157
+ constructor(midgardQuery = new xchainMayamidgardQuery.MidgardQuery(), mayanode = new Mayanode(), configuration) {
158
+ this.midgardQuery = midgardQuery;
159
+ this.mayanode = mayanode;
160
+ this.conf = Object.assign({ expirationTimeInboundAddress: 6000 }, configuration);
161
+ this.inboundDetailCache = new xchainUtil.CachedValue(() => this.refreshInboundDetailCache(), this.conf.expirationTimeInboundAddress);
162
+ }
163
+ /**
164
+ * Get inbound addresses details
165
+ * @returns Inbound details
166
+ */
167
+ getInboundDetails() {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ if (!this.inboundDetailCache)
170
+ throw Error(`Could not refresh inbound details`);
171
+ return yield this.inboundDetailCache.getValue();
172
+ });
173
+ }
174
+ /**
175
+ * Refreshes the InboundDetailCache Cache
176
+ */
177
+ refreshInboundDetailCache() {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ const [mimirDetails, allInboundAddresses] = yield Promise.all([
180
+ this.mayanode.getMimir(),
181
+ this.mayanode.getInboundAddresses(),
182
+ ]);
183
+ const inboundDetails = {};
184
+ for (const inbound of allInboundAddresses) {
185
+ const chain = inbound.chain;
186
+ if (!chain ||
187
+ !inbound.gas_rate ||
188
+ !inbound.address ||
189
+ !inbound.gas_rate_units ||
190
+ !inbound.outbound_tx_size ||
191
+ !inbound.outbound_fee ||
192
+ !inbound.gas_rate_units)
193
+ throw new Error(`Missing required inbound info`);
194
+ inboundDetails[chain] = {
195
+ chain: chain,
196
+ address: inbound.address,
197
+ router: inbound.router,
198
+ gasRate: new bignumber_js.BigNumber(inbound.gas_rate),
199
+ gasRateUnits: inbound.gas_rate_units,
200
+ outboundTxSize: new bignumber_js.BigNumber(inbound.outbound_tx_size),
201
+ outboundFee: new bignumber_js.BigNumber(inbound.outbound_fee),
202
+ haltedChain: (inbound === null || inbound === void 0 ? void 0 : inbound.halted) || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],
203
+ haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],
204
+ haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],
205
+ };
206
+ }
207
+ // add mock MAYAChain inbound details
208
+ inboundDetails[MayaChain] = {
209
+ chain: MayaChain,
210
+ address: '',
211
+ router: '',
212
+ gasRate: new bignumber_js.BigNumber(0),
213
+ gasRateUnits: '',
214
+ outboundTxSize: new bignumber_js.BigNumber(0),
215
+ outboundFee: new bignumber_js.BigNumber(0),
216
+ haltedChain: false,
217
+ haltedTrading: !!mimirDetails['HALTTRADING'],
218
+ haltedLP: false, //
219
+ };
220
+ return inboundDetails;
221
+ });
222
+ }
223
+ }
224
+
225
+ /**
226
+ * MAYAChain Class for interacting with MAYAChain.
227
+ * Recommended main class to use for swapping with MAYAChain
228
+ * Has access to Midgard and MAYANode data
229
+ */
230
+ class MayachainQuery {
231
+ /**
232
+ * Constructor to create a MayachainAMM
233
+ * @param mayachainCache - an instance of the MayachainCache (could be pointing to stagenet,testnet,mainnet)
234
+ * @param chainAttributes - attributes used to calculate waitTime & conf counting
235
+ * @returns MayachainAMM
236
+ */
237
+ constructor(mayachainCache = new MayachainCache()) {
238
+ this.mayachainCache = mayachainCache;
239
+ }
240
+ /**
241
+ * Get the mayachain query is working with
242
+ * @returns
243
+ */
244
+ getNetwork() {
245
+ return this.mayachainCache.midgardQuery.getNetwork();
246
+ }
247
+ /**
248
+ * Quote a swap
249
+ * @param {QuoteSwapParams} quoteSwapParams - quote swap input params
250
+ * @returns {QuoteSwap}
251
+ */
252
+ quoteSwap({ fromAsset, destinationAsset, amount, fromAddress, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, }) {
253
+ return __awaiter(this, void 0, void 0, function* () {
254
+ const fromAssetString = xchainUtil.assetToString(fromAsset);
255
+ const toAssetString = xchainUtil.assetToString(destinationAsset);
256
+ const inputAmount = getBaseAmountWithDiffDecimals(amount, 8);
257
+ const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), fromAddress, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height);
258
+ const response = JSON.parse(JSON.stringify(swapQuote));
259
+ if (response.error) {
260
+ return {
261
+ toAddress: ``,
262
+ memo: ``,
263
+ expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), destinationAsset),
264
+ dustThreshold: this.getChainDustValue(fromAsset.chain),
265
+ fees: {
266
+ asset: destinationAsset,
267
+ affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), fromAsset),
268
+ outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), destinationAsset),
269
+ },
270
+ outboundDelayBlocks: 0,
271
+ outboundDelaySeconds: 0,
272
+ inboundConfirmationSeconds: 0,
273
+ inboundConfirmationBlocks: 0,
274
+ canSwap: false,
275
+ errors: [`Mayanode request quote: ${response.error}`],
276
+ slipBasisPoints: 0,
277
+ totalSwapSeconds: 0,
278
+ warning: '',
279
+ };
280
+ }
281
+ const feeAsset = xchainUtil.assetFromStringEx(swapQuote.fees.asset);
282
+ const errors = [];
283
+ if (swapQuote.memo === undefined)
284
+ errors.push(`Error parsing swap quote: Memo is ${swapQuote.memo}`);
285
+ return {
286
+ toAddress: swapQuote.inbound_address || '',
287
+ memo: swapQuote.memo || '',
288
+ expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out), destinationAsset),
289
+ dustThreshold: this.getChainDustValue(fromAsset.chain),
290
+ fees: {
291
+ asset: feeAsset,
292
+ affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.affiliate), feeAsset),
293
+ outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.outbound), feeAsset),
294
+ },
295
+ slipBasisPoints: swapQuote.slippage_bps,
296
+ outboundDelayBlocks: swapQuote.outbound_delay_blocks,
297
+ outboundDelaySeconds: swapQuote.outbound_delay_seconds,
298
+ inboundConfirmationSeconds: swapQuote.inbound_confirmation_seconds,
299
+ inboundConfirmationBlocks: swapQuote.inbound_confirmation_blocks,
300
+ totalSwapSeconds: (swapQuote.inbound_confirmation_seconds || 0) + swapQuote.outbound_delay_seconds,
301
+ canSwap: !(!swapQuote.memo || errors.length > 0),
302
+ errors,
303
+ warning: '',
304
+ };
305
+ });
306
+ }
307
+ /**
308
+ * Return mayachain supported chains dust amounts
309
+ * @returns a map where chain is the key and dust amount cryptoAmount as value
310
+ */
311
+ getDustValues() {
312
+ // TODO: Find out how to fetch native asset decimals
313
+ return {
314
+ [BtcChain]: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(10000, 8), BtcAsset),
315
+ [EthChain]: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, 8), EthAsset),
316
+ [DashChain]: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(10000, 8), DashAsset),
317
+ [KujiraChain]: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, 8), KujiraAsset),
318
+ [ThorChain]: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, 8), RuneAsset),
319
+ [MayaChain]: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, 8), CacaoAsset),
320
+ };
321
+ }
322
+ /**
323
+ * Return the dust crypto amount from the given chain
324
+ * @param {string} chain Chain to retrieve the dust amount of
325
+ * @returns a map where chain is the key and dust amount cryptoAmount as value
326
+ */
327
+ getChainDustValue(chain) {
328
+ const dustValue = this.getDustValues()[chain];
329
+ if (!dustValue)
330
+ throw Error(`No dust value known for ${chain} chain`);
331
+ return dustValue;
332
+ }
333
+ /**
334
+ * Get MAYAname details
335
+ * @param {string} MAYAName
336
+ * @returns {MAYANameDetails | undefined} MAYANames details or undefined it is does not exist
337
+ */
338
+ getMAYANameDetails(MAYAName) {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ return this.mayachainCache.midgardQuery.getMAYANameDetails(MAYAName);
341
+ });
342
+ }
343
+ /**
344
+ * Get inbound addresses details
345
+ * @returns Inbound details
346
+ */
347
+ getInboundDetails() {
348
+ return __awaiter(this, void 0, void 0, function* () {
349
+ return this.mayachainCache.getInboundDetails();
350
+ });
351
+ }
352
+ /**
353
+ * Get chain inbound address details
354
+ * @returns Inbound details
355
+ */
356
+ getChainInboundDetails(chain) {
357
+ return __awaiter(this, void 0, void 0, function* () {
358
+ const inboundDetails = yield this.getInboundDetails();
359
+ if (inboundDetails[chain])
360
+ throw Error(`No inbound details known for ${chain} chain`);
361
+ return inboundDetails[chain];
362
+ });
363
+ }
364
+ }
365
+
366
+ exports.BtcAsset = BtcAsset;
367
+ exports.BtcChain = BtcChain;
368
+ exports.CacaoAsset = CacaoAsset;
369
+ exports.DEFAULT_MAYACHAIN_DECIMALS = DEFAULT_MAYACHAIN_DECIMALS;
370
+ exports.DashAsset = DashAsset;
371
+ exports.DashChain = DashChain;
372
+ exports.EthAsset = EthAsset;
373
+ exports.EthChain = EthChain;
374
+ exports.KujiraAsset = KujiraAsset;
375
+ exports.KujiraChain = KujiraChain;
376
+ exports.MayaChain = MayaChain;
377
+ exports.MayachainCache = MayachainCache;
378
+ exports.MayachainQuery = MayachainQuery;
379
+ exports.Mayanode = Mayanode;
380
+ exports.RuneAsset = RuneAsset;
381
+ exports.ThorChain = ThorChain;
382
+ exports.getBaseAmountWithDiffDecimals = getBaseAmountWithDiffDecimals;
383
+ exports.isCacaoAsset = isCacaoAsset;
384
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/utils/mayanode.ts","../src/utils/const.ts","../src/utils/utils.ts","../src/mayachain-cache.ts","../src/mayachain-query.ts"],"sourcesContent":["import { Network } from '@xchainjs/xchain-client'\nimport {\n Configuration,\n InboundAddress,\n MimirApi,\n MimirResponse,\n NetworkApi,\n QuoteApi,\n QuoteSwapResponse,\n} from '@xchainjs/xchain-mayanode'\nimport axios from 'axios'\nimport axiosRetry from 'axios-retry'\n\nexport type MayanodeConfig = {\n apiRetries: number\n mayanodeBaseUrls: string[]\n}\n\nconst defaultMayanodeConfig: Record<Network, MayanodeConfig> = {\n mainnet: {\n apiRetries: 3,\n mayanodeBaseUrls: ['https://mayanode.mayachain.info'],\n },\n stagenet: {\n apiRetries: 3,\n mayanodeBaseUrls: ['https://stagenet.mayanode.mayachain.info'],\n },\n testnet: {\n apiRetries: 3,\n // There is no testnet for mayanode\n mayanodeBaseUrls: ['https://stagenet.mayanode.mayachain.info'],\n },\n}\n\nexport class Mayanode {\n private config: MayanodeConfig\n private network: Network\n private quoteApis: QuoteApi[]\n private mimirApis: MimirApi[]\n private networkApis: NetworkApi[]\n\n constructor(network: Network = Network.Mainnet, config?: MayanodeConfig) {\n this.network = network\n this.config = config ?? defaultMayanodeConfig[this.network]\n this.quoteApis = this.config.mayanodeBaseUrls.map((url) => new QuoteApi(new Configuration({ basePath: url })))\n this.mimirApis = this.config.mayanodeBaseUrls.map((url) => new MimirApi(new Configuration({ basePath: url })))\n this.networkApis = this.config.mayanodeBaseUrls.map((url) => new NetworkApi(new Configuration({ basePath: url })))\n\n axiosRetry(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry.exponentialDelay })\n }\n\n /**\n * TODO\n * @param fromAsset - input asset\n * @param toAsset - output asset\n * @param amount - amount to swap\n * @param destinationAddress - destination address for the swap\n * @param toleranceBps - slip percent\n * @param affiliateBps - affiliate percent\n * @param affiliate - affiliate address\n * @param height - block height\n * @returns quotes swap object response\n */\n public async getSwapQuote(\n fromAsset: string,\n toAsset: string,\n amount: number,\n fromAddress?: string,\n destinationAddress?: string,\n toleranceBps?: number,\n affiliateBps?: number,\n affiliate?: string,\n height?: number,\n ): Promise<QuoteSwapResponse> {\n for (const api of this.quoteApis) {\n try {\n return (\n await api.quoteswap(\n height,\n fromAsset,\n toAsset,\n amount,\n destinationAddress,\n fromAddress,\n toleranceBps,\n affiliateBps,\n affiliate,\n )\n ).data\n } catch (e) {}\n }\n throw new Error(`MAYANode not responding`)\n }\n\n /**\n * Get current active mimir configuration.\n * @returns mimir configuration\n */\n public async getMimir(): Promise<MimirResponse> {\n for (const api of this.mimirApis) {\n try {\n return (await api.mimir()).data\n } catch (e) {}\n }\n throw Error(`MAYANode not responding`)\n }\n\n /**\n * Get the set of asgard addresses that should be used for inbound transactions.\n * @returns MAYA inbound addresses\n */\n public async getInboundAddresses(): Promise<InboundAddress[]> {\n for (const api of this.networkApis) {\n try {\n const resp = (await api.inboundAddresses()).data\n return resp\n } catch (e) {}\n }\n throw new Error(`MAYANode not responding`)\n }\n}\n","import { assetFromStringEx } from '@xchainjs/xchain-util'\n\nexport const BtcAsset = assetFromStringEx('BTC.BTC')\nexport const EthAsset = assetFromStringEx('ETH.ETH')\nexport const CacaoAsset = assetFromStringEx('MAYA.CACAO')\nexport const RuneAsset = assetFromStringEx('THOR.RUNE')\nexport const DashAsset = assetFromStringEx('DASH.DASH')\nexport const KujiraAsset = assetFromStringEx('KUJI.KUJI')\n\nexport const BtcChain = 'BTC'\nexport const EthChain = 'ETH'\nexport const MayaChain = 'MAYA'\nexport const ThorChain = 'THOR'\nexport const DashChain = 'DASH'\nexport const KujiraChain = 'KUJI'\n\nexport const DEFAULT_MAYACHAIN_DECIMALS = 8\n","import { Asset, CryptoAmount, assetToString, baseAmount } from '@xchainjs/xchain-util'\nimport BigNumber from 'bignumber.js'\n\nimport { CacaoAsset } from './const'\n\nexport const isCacaoAsset = (asset: Asset): boolean => assetToString(asset) === assetToString(CacaoAsset)\n\nexport const getBaseAmountWithDiffDecimals = (inputAmount: CryptoAmount, outDecimals: number): BigNumber => {\n const inDecimals = inputAmount.baseAmount.decimal\n let baseAmountOut = inputAmount.baseAmount.amount()\n const adjustDecimals = outDecimals - inDecimals\n baseAmountOut = baseAmountOut.times(10 ** adjustDecimals)\n return baseAmount(baseAmountOut, outDecimals).amount()\n}\n","import { MidgardQuery } from '@xchainjs/xchain-mayamidgard-query'\nimport { CachedValue } from '@xchainjs/xchain-util'\nimport { BigNumber } from 'bignumber.js'\n\nimport { InboundDetail } from './types'\nimport { MayaChain, Mayanode } from './utils'\n\nexport type MayachainCacheConf = {\n expirationTimeInboundAddress: number\n}\n/**\n * This class manages retrieving information from up to date Mayachain\n */\nexport class MayachainCache {\n readonly midgardQuery: MidgardQuery\n readonly mayanode: Mayanode\n private conf: MayachainCacheConf\n private readonly inboundDetailCache: CachedValue<Record<string, InboundDetail>>\n /**\n * Constructor to create a MayachainCache\n *\n * @param midgardQuery - an instance of the Maya MidgardQuery API\n * @param mayanode\n * @returns MayachainCache\n */\n constructor(\n midgardQuery = new MidgardQuery(),\n mayanode = new Mayanode(),\n configuration?: Partial<MayachainCacheConf>,\n ) {\n this.midgardQuery = midgardQuery\n this.mayanode = mayanode\n this.conf = { expirationTimeInboundAddress: 6000, ...configuration }\n\n this.inboundDetailCache = new CachedValue<Record<string, InboundDetail>>(\n () => this.refreshInboundDetailCache(),\n this.conf.expirationTimeInboundAddress,\n )\n }\n\n /**\n * Get inbound addresses details\n * @returns Inbound details\n */\n public async getInboundDetails(): Promise<Record<string, InboundDetail>> {\n if (!this.inboundDetailCache) throw Error(`Could not refresh inbound details`)\n return await this.inboundDetailCache.getValue()\n }\n\n /**\n * Refreshes the InboundDetailCache Cache\n */\n private async refreshInboundDetailCache(): Promise<Record<string, InboundDetail>> {\n const [mimirDetails, allInboundAddresses] = await Promise.all([\n this.mayanode.getMimir(),\n this.mayanode.getInboundAddresses(),\n ])\n const inboundDetails: Record<string, InboundDetail> = {}\n for (const inbound of allInboundAddresses) {\n const chain = inbound.chain\n if (\n !chain ||\n !inbound.gas_rate ||\n !inbound.address ||\n !inbound.gas_rate_units ||\n !inbound.outbound_tx_size ||\n !inbound.outbound_fee ||\n !inbound.gas_rate_units\n )\n throw new Error(`Missing required inbound info`)\n\n inboundDetails[chain] = {\n chain: chain,\n address: inbound.address,\n router: inbound.router,\n gasRate: new BigNumber(inbound.gas_rate),\n gasRateUnits: inbound.gas_rate_units,\n outboundTxSize: new BigNumber(inbound.outbound_tx_size),\n outboundFee: new BigNumber(inbound.outbound_fee),\n haltedChain: inbound?.halted || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],\n haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],\n haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],\n }\n }\n // add mock MAYAChain inbound details\n inboundDetails[MayaChain] = {\n chain: MayaChain,\n address: '',\n router: '',\n gasRate: new BigNumber(0),\n gasRateUnits: '',\n outboundTxSize: new BigNumber(0),\n outboundFee: new BigNumber(0),\n haltedChain: false,\n haltedTrading: !!mimirDetails['HALTTRADING'],\n haltedLP: false, //\n }\n\n return inboundDetails\n }\n}\n","import { Network } from '@xchainjs/xchain-client'\nimport { MAYANameDetails } from '@xchainjs/xchain-mayamidgard-query'\nimport { QuoteSwapResponse } from '@xchainjs/xchain-mayanode'\nimport { CryptoAmount, assetFromStringEx, assetToString, baseAmount } from '@xchainjs/xchain-util'\n\nimport { MayachainCache } from './mayachain-cache'\nimport { InboundDetail, QuoteSwap, QuoteSwapParams } from './types'\nimport {\n BtcAsset,\n BtcChain,\n CacaoAsset,\n DashAsset,\n DashChain,\n EthAsset,\n EthChain,\n KujiraAsset,\n KujiraChain,\n MayaChain,\n RuneAsset,\n ThorChain,\n getBaseAmountWithDiffDecimals,\n} from './utils'\n\n/**\n * MAYAChain Class for interacting with MAYAChain.\n * Recommended main class to use for swapping with MAYAChain\n * Has access to Midgard and MAYANode data\n */\nexport class MayachainQuery {\n private mayachainCache: MayachainCache\n\n /**\n * Constructor to create a MayachainAMM\n * @param mayachainCache - an instance of the MayachainCache (could be pointing to stagenet,testnet,mainnet)\n * @param chainAttributes - attributes used to calculate waitTime & conf counting\n * @returns MayachainAMM\n */\n constructor(mayachainCache = new MayachainCache()) {\n this.mayachainCache = mayachainCache\n }\n\n /**\n * Get the mayachain query is working with\n * @returns\n */\n public getNetwork(): Network {\n return this.mayachainCache.midgardQuery.getNetwork()\n }\n\n /**\n * Quote a swap\n * @param {QuoteSwapParams} quoteSwapParams - quote swap input params\n * @returns {QuoteSwap}\n */\n public async quoteSwap({\n fromAsset,\n destinationAsset,\n amount,\n fromAddress,\n destinationAddress,\n toleranceBps,\n affiliateBps,\n affiliateAddress,\n height,\n }: QuoteSwapParams): Promise<QuoteSwap> {\n const fromAssetString = assetToString(fromAsset)\n const toAssetString = assetToString(destinationAsset)\n const inputAmount = getBaseAmountWithDiffDecimals(amount, 8)\n\n const swapQuote: QuoteSwapResponse = await this.mayachainCache.mayanode.getSwapQuote(\n fromAssetString,\n toAssetString,\n inputAmount.toNumber(),\n fromAddress,\n destinationAddress,\n toleranceBps,\n affiliateBps,\n affiliateAddress,\n height,\n )\n\n const response: { error?: string } = JSON.parse(JSON.stringify(swapQuote))\n if (response.error) {\n return {\n toAddress: ``,\n memo: ``,\n expectedAmount: new CryptoAmount(baseAmount(0), destinationAsset),\n dustThreshold: this.getChainDustValue(fromAsset.chain),\n fees: {\n asset: destinationAsset,\n affiliateFee: new CryptoAmount(baseAmount(0), fromAsset),\n outboundFee: new CryptoAmount(baseAmount(0), destinationAsset),\n },\n outboundDelayBlocks: 0,\n outboundDelaySeconds: 0,\n inboundConfirmationSeconds: 0,\n inboundConfirmationBlocks: 0,\n canSwap: false,\n errors: [`Mayanode request quote: ${response.error}`],\n slipBasisPoints: 0,\n totalSwapSeconds: 0,\n warning: '',\n }\n }\n\n const feeAsset = assetFromStringEx(swapQuote.fees.asset)\n\n const errors: string[] = []\n if (swapQuote.memo === undefined) errors.push(`Error parsing swap quote: Memo is ${swapQuote.memo}`)\n\n return {\n toAddress: swapQuote.inbound_address || '',\n memo: swapQuote.memo || '',\n expectedAmount: new CryptoAmount(baseAmount(swapQuote.expected_amount_out), destinationAsset),\n dustThreshold: this.getChainDustValue(fromAsset.chain),\n fees: {\n asset: feeAsset,\n affiliateFee: new CryptoAmount(baseAmount(swapQuote.fees.affiliate), feeAsset),\n outboundFee: new CryptoAmount(baseAmount(swapQuote.fees.outbound), feeAsset),\n },\n slipBasisPoints: swapQuote.slippage_bps,\n outboundDelayBlocks: swapQuote.outbound_delay_blocks,\n outboundDelaySeconds: swapQuote.outbound_delay_seconds,\n inboundConfirmationSeconds: swapQuote.inbound_confirmation_seconds,\n inboundConfirmationBlocks: swapQuote.inbound_confirmation_blocks,\n totalSwapSeconds: (swapQuote.inbound_confirmation_seconds || 0) + swapQuote.outbound_delay_seconds,\n canSwap: !(!swapQuote.memo || errors.length > 0),\n errors,\n warning: '',\n }\n }\n\n /**\n * Return mayachain supported chains dust amounts\n * @returns a map where chain is the key and dust amount cryptoAmount as value\n */\n public getDustValues(): Record<string, CryptoAmount> {\n // TODO: Find out how to fetch native asset decimals\n return {\n [BtcChain]: new CryptoAmount(baseAmount(10000, 8), BtcAsset),\n [EthChain]: new CryptoAmount(baseAmount(0, 8), EthAsset),\n [DashChain]: new CryptoAmount(baseAmount(10000, 8), DashAsset),\n [KujiraChain]: new CryptoAmount(baseAmount(0, 8), KujiraAsset),\n [ThorChain]: new CryptoAmount(baseAmount(0, 8), RuneAsset),\n [MayaChain]: new CryptoAmount(baseAmount(0, 8), CacaoAsset),\n }\n }\n\n /**\n * Return the dust crypto amount from the given chain\n * @param {string} chain Chain to retrieve the dust amount of\n * @returns a map where chain is the key and dust amount cryptoAmount as value\n */\n public getChainDustValue(chain: string): CryptoAmount {\n const dustValue = this.getDustValues()[chain]\n if (!dustValue) throw Error(`No dust value known for ${chain} chain`)\n return dustValue\n }\n\n /**\n * Get MAYAname details\n * @param {string} MAYAName\n * @returns {MAYANameDetails | undefined} MAYANames details or undefined it is does not exist\n */\n public async getMAYANameDetails(MAYAName: string): Promise<MAYANameDetails | undefined> {\n return this.mayachainCache.midgardQuery.getMAYANameDetails(MAYAName)\n }\n\n /**\n * Get inbound addresses details\n * @returns Inbound details\n */\n public async getInboundDetails(): Promise<Record<string, InboundDetail>> {\n return this.mayachainCache.getInboundDetails()\n }\n\n /**\n * Get chain inbound address details\n * @returns Inbound details\n */\n public async getChainInboundDetails(chain: string): Promise<InboundDetail> {\n const inboundDetails = await this.getInboundDetails()\n if (inboundDetails[chain]) throw Error(`No inbound details known for ${chain} chain`)\n return inboundDetails[chain]\n }\n}\n"],"names":["Network","QuoteApi","Configuration","MimirApi","NetworkApi","axiosRetry","axios","assetFromStringEx","assetToString","baseAmount","MidgardQuery","CachedValue","BigNumber","CryptoAmount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,qBAAqB,GAAoC;AAC7D,IAAA,OAAO,EAAE;AACP,QAAA,UAAU,EAAE,CAAC;QACb,gBAAgB,EAAE,CAAC,iCAAiC,CAAC;AACtD,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,UAAU,EAAE,CAAC;QACb,gBAAgB,EAAE,C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A;AACF;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,32 @@
1
+ import { MidgardQuery } from '@xchainjs/xchain-mayamidgard-query';
2
+ import { InboundDetail } from './types';
3
+ import { Mayanode } from './utils';
4
+ export type MayachainCacheConf = {
5
+ expirationTimeInboundAddress: number;
6
+ };
7
+ /**
8
+ * This class manages retrieving information from up to date Mayachain
9
+ */
10
+ export declare class MayachainCache {
11
+ readonly midgardQuery: MidgardQuery;
12
+ readonly mayanode: Mayanode;
13
+ private conf;
14
+ private readonly inboundDetailCache;
15
+ /**
16
+ * Constructor to create a MayachainCache
17
+ *
18
+ * @param midgardQuery - an instance of the Maya MidgardQuery API
19
+ * @param mayanode
20
+ * @returns MayachainCache
21
+ */
22
+ constructor(midgardQuery?: MidgardQuery, mayanode?: Mayanode, configuration?: Partial<MayachainCacheConf>);
23
+ /**
24
+ * Get inbound addresses details
25
+ * @returns Inbound details
26
+ */
27
+ getInboundDetails(): Promise<Record<string, InboundDetail>>;
28
+ /**
29
+ * Refreshes the InboundDetailCache Cache
30
+ */
31
+ private refreshInboundDetailCache;
32
+ }
@@ -0,0 +1,58 @@
1
+ import { Network } from '@xchainjs/xchain-client';
2
+ import { MAYANameDetails } from '@xchainjs/xchain-mayamidgard-query';
3
+ import { CryptoAmount } from '@xchainjs/xchain-util';
4
+ import { MayachainCache } from './mayachain-cache';
5
+ import { InboundDetail, QuoteSwap, QuoteSwapParams } from './types';
6
+ /**
7
+ * MAYAChain Class for interacting with MAYAChain.
8
+ * Recommended main class to use for swapping with MAYAChain
9
+ * Has access to Midgard and MAYANode data
10
+ */
11
+ export declare class MayachainQuery {
12
+ private mayachainCache;
13
+ /**
14
+ * Constructor to create a MayachainAMM
15
+ * @param mayachainCache - an instance of the MayachainCache (could be pointing to stagenet,testnet,mainnet)
16
+ * @param chainAttributes - attributes used to calculate waitTime & conf counting
17
+ * @returns MayachainAMM
18
+ */
19
+ constructor(mayachainCache?: MayachainCache);
20
+ /**
21
+ * Get the mayachain query is working with
22
+ * @returns
23
+ */
24
+ getNetwork(): Network;
25
+ /**
26
+ * Quote a swap
27
+ * @param {QuoteSwapParams} quoteSwapParams - quote swap input params
28
+ * @returns {QuoteSwap}
29
+ */
30
+ quoteSwap({ fromAsset, destinationAsset, amount, fromAddress, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, }: QuoteSwapParams): Promise<QuoteSwap>;
31
+ /**
32
+ * Return mayachain supported chains dust amounts
33
+ * @returns a map where chain is the key and dust amount cryptoAmount as value
34
+ */
35
+ getDustValues(): Record<string, CryptoAmount>;
36
+ /**
37
+ * Return the dust crypto amount from the given chain
38
+ * @param {string} chain Chain to retrieve the dust amount of
39
+ * @returns a map where chain is the key and dust amount cryptoAmount as value
40
+ */
41
+ getChainDustValue(chain: string): CryptoAmount;
42
+ /**
43
+ * Get MAYAname details
44
+ * @param {string} MAYAName
45
+ * @returns {MAYANameDetails | undefined} MAYANames details or undefined it is does not exist
46
+ */
47
+ getMAYANameDetails(MAYAName: string): Promise<MAYANameDetails | undefined>;
48
+ /**
49
+ * Get inbound addresses details
50
+ * @returns Inbound details
51
+ */
52
+ getInboundDetails(): Promise<Record<string, InboundDetail>>;
53
+ /**
54
+ * Get chain inbound address details
55
+ * @returns Inbound details
56
+ */
57
+ getChainInboundDetails(chain: string): Promise<InboundDetail>;
58
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { Address, Asset, Chain, CryptoAmount } from '@xchainjs/xchain-util';
2
+ import { BigNumber } from 'bignumber.js';
3
+ /**
4
+ * Quote swap types
5
+ */
6
+ export type Fees = {
7
+ asset: Asset;
8
+ affiliateFee: CryptoAmount;
9
+ outboundFee: CryptoAmount;
10
+ };
11
+ export type QuoteSwap = {
12
+ toAddress: Address;
13
+ memo: string;
14
+ expectedAmount: CryptoAmount;
15
+ dustThreshold: CryptoAmount;
16
+ fees: Fees;
17
+ inboundConfirmationSeconds?: number;
18
+ inboundConfirmationBlocks?: number;
19
+ outboundDelaySeconds: number;
20
+ outboundDelayBlocks: number;
21
+ totalSwapSeconds: number;
22
+ slipBasisPoints: number;
23
+ canSwap: boolean;
24
+ errors: string[];
25
+ warning: string;
26
+ };
27
+ export type QuoteSwapParams = {
28
+ fromAsset: Asset;
29
+ destinationAsset: Asset;
30
+ amount: CryptoAmount;
31
+ fromAddress?: string;
32
+ destinationAddress?: string;
33
+ height?: number;
34
+ toleranceBps?: number;
35
+ affiliateBps?: number;
36
+ affiliateAddress?: string;
37
+ };
38
+ /**
39
+ * Inbound address
40
+ */
41
+ export type InboundDetail = {
42
+ chain: Chain;
43
+ address: Address;
44
+ router?: Address;
45
+ gasRate: BigNumber;
46
+ gasRateUnits: string;
47
+ outboundTxSize: BigNumber;
48
+ outboundFee: BigNumber;
49
+ haltedChain: boolean;
50
+ haltedTrading: boolean;
51
+ haltedLP: boolean;
52
+ };
@@ -0,0 +1,13 @@
1
+ export declare const BtcAsset: import("@xchainjs/xchain-util").Asset;
2
+ export declare const EthAsset: import("@xchainjs/xchain-util").Asset;
3
+ export declare const CacaoAsset: import("@xchainjs/xchain-util").Asset;
4
+ export declare const RuneAsset: import("@xchainjs/xchain-util").Asset;
5
+ export declare const DashAsset: import("@xchainjs/xchain-util").Asset;
6
+ export declare const KujiraAsset: import("@xchainjs/xchain-util").Asset;
7
+ export declare const BtcChain = "BTC";
8
+ export declare const EthChain = "ETH";
9
+ export declare const MayaChain = "MAYA";
10
+ export declare const ThorChain = "THOR";
11
+ export declare const DashChain = "DASH";
12
+ export declare const KujiraChain = "KUJI";
13
+ export declare const DEFAULT_MAYACHAIN_DECIMALS = 8;
@@ -0,0 +1,3 @@
1
+ export * from './mayanode';
2
+ export * from './const';
3
+ export * from './utils';
@@ -0,0 +1,37 @@
1
+ import { Network } from '@xchainjs/xchain-client';
2
+ import { InboundAddress, MimirResponse, QuoteSwapResponse } from '@xchainjs/xchain-mayanode';
3
+ export type MayanodeConfig = {
4
+ apiRetries: number;
5
+ mayanodeBaseUrls: string[];
6
+ };
7
+ export declare class Mayanode {
8
+ private config;
9
+ private network;
10
+ private quoteApis;
11
+ private mimirApis;
12
+ private networkApis;
13
+ constructor(network?: Network, config?: MayanodeConfig);
14
+ /**
15
+ * TODO
16
+ * @param fromAsset - input asset
17
+ * @param toAsset - output asset
18
+ * @param amount - amount to swap
19
+ * @param destinationAddress - destination address for the swap
20
+ * @param toleranceBps - slip percent
21
+ * @param affiliateBps - affiliate percent
22
+ * @param affiliate - affiliate address
23
+ * @param height - block height
24
+ * @returns quotes swap object response
25
+ */
26
+ getSwapQuote(fromAsset: string, toAsset: string, amount: number, fromAddress?: string, destinationAddress?: string, toleranceBps?: number, affiliateBps?: number, affiliate?: string, height?: number): Promise<QuoteSwapResponse>;
27
+ /**
28
+ * Get current active mimir configuration.
29
+ * @returns mimir configuration
30
+ */
31
+ getMimir(): Promise<MimirResponse>;
32
+ /**
33
+ * Get the set of asgard addresses that should be used for inbound transactions.
34
+ * @returns MAYA inbound addresses
35
+ */
36
+ getInboundAddresses(): Promise<InboundAddress[]>;
37
+ }
@@ -0,0 +1,4 @@
1
+ import { Asset, CryptoAmount } from '@xchainjs/xchain-util';
2
+ import BigNumber from 'bignumber.js';
3
+ export declare const isCacaoAsset: (asset: Asset) => boolean;
4
+ export declare const getBaseAmountWithDiffDecimals: (inputAmount: CryptoAmount, outDecimals: number) => BigNumber;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@xchainjs/xchain-mayachain-query",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Mayachain query module that is responsible for estimating swap calculations and add/remove liquidity for thorchain",
6
+ "keywords": [
7
+ "XChain",
8
+ "Mayachain-query"
9
+ ],
10
+ "author": "MAYAChain",
11
+ "homepage": "https://github.com/xchainjs/xchainjs-lib#readme",
12
+ "main": "lib/index.js",
13
+ "module": "lib/index.esm.js",
14
+ "typings": "lib/index.d.ts",
15
+ "directories": {
16
+ "lib": "lib",
17
+ "test": "__tests__"
18
+ },
19
+ "files": [
20
+ "lib"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git@github.com:xchainjs/xchainjs-lib.git"
25
+ },
26
+ "scripts": {
27
+ "clean": "rimraf lib/**",
28
+ "build": "yarn clean && rollup -c",
29
+ "test": "jest",
30
+ "e2e": "jest --config jest.config.e2e.js",
31
+ "lint": "eslint \"{src,__tests__}/**/*.ts\" --fix --max-warnings 0",
32
+ "prepublishOnly": "yarn build",
33
+ "postversion": "git push --follow-tags"
34
+ },
35
+ "devDependencies": {
36
+ "@xchainjs/xchain-client": "^0.14.1",
37
+ "@xchainjs/xchain-mayamidgard-query": "^0.1.0",
38
+ "@xchainjs/xchain-mayanode": "^0.1.2",
39
+ "@xchainjs/xchain-util": "^0.13.0",
40
+ "axios": "^1.3.6",
41
+ "axios-retry": "^3.2.5",
42
+ "bignumber.js": "^9.0.0"
43
+ },
44
+ "peerDependencies": {
45
+ "@xchainjs/xchain-client": "^0.14.1",
46
+ "@xchainjs/xchain-mayamidgard-query": "^0.1.0",
47
+ "@xchainjs/xchain-mayanode": "^0.1.2",
48
+ "@xchainjs/xchain-util": "^0.13.0",
49
+ "axios": "^1.3.6",
50
+ "axios-retry": "^3.2.5",
51
+ "bignumber.js": "^9.0.0"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }