@xchainjs/xchain-thorchain-query 0.6.13 → 0.7.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/lib/index.js CHANGED
@@ -87,100 +87,6 @@ const DefaultChainAttributes = {
87
87
  },
88
88
  };
89
89
 
90
- /**
91
- * Utility Class to combine an amount (asset/base) with the Asset
92
- *
93
- */
94
- class CryptoAmount {
95
- constructor(amount, asset) {
96
- this.asset = asset;
97
- this.baseAmount = amount;
98
- }
99
- plus(v) {
100
- this.check(v);
101
- const assetAmountResult = xchainUtil.assetToBase(this.assetAmount.plus(v.assetAmount));
102
- return new CryptoAmount(assetAmountResult, this.asset);
103
- }
104
- minus(v) {
105
- this.check(v);
106
- const assetAmountResult = xchainUtil.assetToBase(this.assetAmount.minus(v.assetAmount));
107
- return new CryptoAmount(assetAmountResult, this.asset);
108
- }
109
- times(v) {
110
- this.check(v);
111
- if (v instanceof CryptoAmount) {
112
- const assetAmountResult = xchainUtil.assetToBase(this.assetAmount.times(v.assetAmount));
113
- return new CryptoAmount(assetAmountResult, this.asset);
114
- }
115
- else {
116
- const assetAmountResult = xchainUtil.assetToBase(this.assetAmount.times(v));
117
- return new CryptoAmount(assetAmountResult, this.asset);
118
- }
119
- }
120
- div(v) {
121
- this.check(v);
122
- if (v instanceof CryptoAmount) {
123
- const assetAmountResult = xchainUtil.assetToBase(this.assetAmount.div(v.assetAmount));
124
- return new CryptoAmount(assetAmountResult, this.asset);
125
- }
126
- else {
127
- const assetAmountResult = xchainUtil.assetToBase(this.assetAmount.div(v));
128
- return new CryptoAmount(assetAmountResult, this.asset);
129
- }
130
- }
131
- lt(v) {
132
- this.check(v);
133
- return this.assetAmount.lt(v.assetAmount);
134
- }
135
- lte(v) {
136
- this.check(v);
137
- return this.assetAmount.lte(v.assetAmount);
138
- }
139
- gt(v) {
140
- this.check(v);
141
- return this.assetAmount.gt(v.assetAmount);
142
- }
143
- gte(v) {
144
- this.check(v);
145
- return this.assetAmount.gte(v.assetAmount);
146
- }
147
- eq(v) {
148
- this.check(v);
149
- return this.assetAmount.eq(v.assetAmount);
150
- }
151
- formatedAssetString() {
152
- return xchainUtil.formatAssetAmountCurrency({
153
- amount: this.assetAmount,
154
- asset: this.asset,
155
- trimZeros: true,
156
- });
157
- }
158
- assetAmountFixedString() {
159
- return this.assetAmount.amount().toFixed();
160
- }
161
- get assetAmount() {
162
- return xchainUtil.baseToAsset(this.baseAmount);
163
- }
164
- /**
165
- * This guard protects against trying to perform math with different assets
166
- *
167
- * Example.
168
- * const x = new CryptoAmount(assetAmount(1),AssetBTC)
169
- * const y = new CryptoAmount(assetAmount(1),AssetETH)
170
- *
171
- * x.plus(y) <- will throw error "cannot perform math on 2 diff assets BTC.BTC ETH.ETH
172
- *
173
- * @param v - CryptoNumeric
174
- */
175
- check(v) {
176
- if (v instanceof CryptoAmount) {
177
- if (!xchainUtil.eqAsset(this.asset, v.asset)) {
178
- throw Error(`cannot perform math on 2 diff assets ${xchainUtil.assetToString(this.asset)} ${xchainUtil.assetToString(v.asset)}`);
179
- }
180
- }
181
- }
182
- }
183
-
184
90
  /**
185
91
  * Represent a Liquidity Pool in Thorchain
186
92
  */
@@ -280,48 +186,48 @@ const getChainAsset = (chain) => {
280
186
  const calcNetworkFee = (asset, inbound) => {
281
187
  // synths are always 0.02R fee
282
188
  if (asset.synth)
283
- return new CryptoAmount(xchainUtil.baseAmount(2000000), AssetRuneNative);
189
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(2000000), AssetRuneNative);
284
190
  // if you are swapping a non-gas asset on a multiAsset chain (ex. ERC-20 on ETH), the
285
191
  // gas fees will be paid in a diff asset than the one you are swapping
286
192
  switch (asset.chain) {
287
193
  case BTCChain:
288
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBTC);
194
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBTC);
289
195
  case BCHChain:
290
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBCH);
196
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBCH);
291
197
  case LTCChain:
292
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetLTC);
198
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetLTC);
293
199
  case DOGEChain:
294
200
  // NOTE: UTXO chains estimate fees with a 250 byte size
295
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetDOGE);
201
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetDOGE);
296
202
  case BNBChain:
297
203
  //flat fee
298
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetBNB);
204
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetBNB);
299
205
  case ETHChain:
300
206
  const gasRateinETHGwei = inbound.gasRate;
301
207
  const gasRateinETHWei = xchainUtil.baseAmount(gasRateinETHGwei.multipliedBy(Math.pow(10, 9)), 18);
302
208
  if (xchainUtil.eqAsset(asset, AssetETH)) {
303
- return new CryptoAmount(gasRateinETHWei.times(21000), AssetETH);
209
+ return new xchainUtil.CryptoAmount(gasRateinETHWei.times(21000), AssetETH);
304
210
  }
305
211
  else {
306
- return new CryptoAmount(gasRateinETHWei.times(70000), AssetETH);
212
+ return new xchainUtil.CryptoAmount(gasRateinETHWei.times(70000), AssetETH);
307
213
  }
308
214
  case AVAXChain:
309
215
  const gasRateinAVAXGwei = inbound.gasRate;
310
216
  const gasRateinAVAXWei = xchainUtil.baseAmount(gasRateinAVAXGwei.multipliedBy(Math.pow(10, 9)), 18);
311
217
  if (xchainUtil.eqAsset(asset, AssetAVAX)) {
312
- return new CryptoAmount(gasRateinAVAXWei.times(21000), AssetAVAX);
218
+ return new xchainUtil.CryptoAmount(gasRateinAVAXWei.times(21000), AssetAVAX);
313
219
  }
314
220
  else {
315
- return new CryptoAmount(gasRateinAVAXWei.times(70000), AssetAVAX);
221
+ return new xchainUtil.CryptoAmount(gasRateinAVAXWei.times(70000), AssetAVAX);
316
222
  }
317
223
  case GAIAChain:
318
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetATOM);
224
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetATOM);
319
225
  case THORChain:
320
- return new CryptoAmount(xchainUtil.baseAmount(2000000), AssetRuneNative);
226
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(2000000), AssetRuneNative);
321
227
  case BSCChain:
322
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetBSC);
228
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetBSC);
323
229
  case MAYAChain:
324
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetMAYA);
230
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetMAYA);
325
231
  }
326
232
  throw new Error(`could not calculate inbound fee for ${asset.chain}`);
327
233
  };
@@ -336,32 +242,32 @@ const calcNetworkFee = (asset, inbound) => {
336
242
  */
337
243
  const calcOutboundFee = (asset, inbound) => {
338
244
  if (asset.synth)
339
- return new CryptoAmount(xchainUtil.baseAmount(2000000), AssetRuneNative);
245
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(2000000), AssetRuneNative);
340
246
  switch (asset.chain) {
341
247
  case BTCChain:
342
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBTC);
248
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBTC);
343
249
  case BCHChain:
344
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBCH);
250
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBCH);
345
251
  case LTCChain:
346
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetLTC);
252
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetLTC);
347
253
  case DOGEChain:
348
254
  // NOTE: UTXO chains estimate fees with a 250 byte size
349
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetDOGE);
255
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetDOGE);
350
256
  case BNBChain:
351
257
  //flat fee
352
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBNB);
258
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBNB);
353
259
  case ETHChain:
354
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), AssetETH);
260
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), AssetETH);
355
261
  case AVAXChain:
356
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), AssetAVAX);
262
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), AssetAVAX);
357
263
  case GAIAChain:
358
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetATOM);
264
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetATOM);
359
265
  case BSCChain:
360
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBSC);
266
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBSC);
361
267
  case THORChain:
362
- return new CryptoAmount(xchainUtil.baseAmount(2000000), AssetRuneNative);
268
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(2000000), AssetRuneNative);
363
269
  case MAYAChain:
364
- return new CryptoAmount(xchainUtil.baseAmount(2000000), AssetMAYA);
270
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(2000000), AssetMAYA);
365
271
  }
366
272
  throw new Error(`could not calculate outbound fee for ${asset.chain}`);
367
273
  };
@@ -401,8 +307,8 @@ const getPoolShare = (unitData, pool) => {
401
307
  const asset = T.times(units).div(total);
402
308
  const rune = R.times(units).div(total);
403
309
  const poolShareDetail = {
404
- assetShare: new CryptoAmount(xchainUtil.baseAmount(asset), pool.asset),
405
- runeShare: new CryptoAmount(xchainUtil.baseAmount(rune), AssetRuneNative),
310
+ assetShare: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(asset), pool.asset),
311
+ runeShare: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(rune), AssetRuneNative),
406
312
  };
407
313
  return poolShareDetail;
408
314
  };
@@ -451,7 +357,7 @@ const getLiquidityProtectionData = (depositValue, poolShare, block) => {
451
357
  const result = coverage.times(protectionProgress); // impermanent loss protection result
452
358
  const maxILP = result.lt(0) ? new bignumber_js.BigNumber(0) : result; // max negative ILP to 0
453
359
  const ILProtection = {
454
- ILProtection: new CryptoAmount(xchainUtil.baseAmount(maxILP), AssetRuneNative),
360
+ ILProtection: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(maxILP), AssetRuneNative),
455
361
  totalDays: (fractionOfFullILPProtection * 100).toFixed(2),
456
362
  };
457
363
  return ILProtection;
@@ -1101,7 +1007,7 @@ class ThorchainCache {
1101
1007
  const adjustDecimals = outDecimals - inDecimals;
1102
1008
  baseAmountOut = baseAmountOut.times(Math.pow(10, adjustDecimals));
1103
1009
  const amt = xchainUtil.baseAmount(baseAmountOut, outDecimals);
1104
- const result = new CryptoAmount(amt, outAsset);
1010
+ const result = new xchainUtil.CryptoAmount(amt, outAsset);
1105
1011
  return result;
1106
1012
  });
1107
1013
  }
@@ -1187,21 +1093,21 @@ class ThorchainQuery {
1187
1093
  return {
1188
1094
  memo: ``,
1189
1095
  toAddress: ``,
1190
- dustThreshold: new CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative),
1096
+ dustThreshold: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative),
1191
1097
  expiry: new Date(),
1192
1098
  txEstimate: {
1193
1099
  totalFees: {
1194
1100
  asset: destinationAsset,
1195
- affiliateFee: new CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative),
1196
- outboundFee: new CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative),
1101
+ affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative),
1102
+ outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative),
1197
1103
  },
1198
1104
  slipBasisPoints: 0,
1199
- netOutput: new CryptoAmount(xchainUtil.baseAmount(0), destinationAsset),
1105
+ netOutput: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), destinationAsset),
1200
1106
  outboundDelaySeconds: 0,
1201
1107
  inboundConfirmationSeconds: 0,
1202
1108
  canSwap: false,
1203
1109
  errors,
1204
- netOutputStreaming: new CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative),
1110
+ netOutputStreaming: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative),
1205
1111
  maxStreamingQuantity: 0,
1206
1112
  outboundDelayBlocks: 0,
1207
1113
  streamingSlipBasisPoints: 0,
@@ -1223,18 +1129,18 @@ class ThorchainQuery {
1223
1129
  // No errors ? and memo is returned ? return quote flag canSwap to true
1224
1130
  const txDetails = {
1225
1131
  memo: swapQuote.memo ? swapQuote.memo : '',
1226
- dustThreshold: new CryptoAmount(xchainUtil.baseAmount(swapQuote.dust_threshold), fromAsset),
1132
+ dustThreshold: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.dust_threshold), fromAsset),
1227
1133
  toAddress: swapQuote.inbound_address ? swapQuote.inbound_address : '',
1228
1134
  expiry: new Date(swapQuote.expiry * 1000),
1229
1135
  txEstimate: {
1230
1136
  totalFees: {
1231
1137
  asset: fromAsset,
1232
- affiliateFee: new CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.affiliate), feeAsset),
1233
- outboundFee: new CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.outbound), feeAsset),
1138
+ affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.affiliate), feeAsset),
1139
+ outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.outbound), feeAsset),
1234
1140
  },
1235
1141
  slipBasisPoints: swapQuote.slippage_bps,
1236
- netOutput: new CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out), destinationAsset),
1237
- netOutputStreaming: new CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out_streaming), destinationAsset),
1142
+ netOutput: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out), destinationAsset),
1143
+ netOutputStreaming: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out_streaming), destinationAsset),
1238
1144
  outboundDelaySeconds: swapQuote.outbound_delay_seconds,
1239
1145
  inboundConfirmationSeconds: swapQuote.inbound_confirmation_seconds,
1240
1146
  recommendedMinAmountIn: swapQuote.recommended_min_amount_in,
@@ -1274,13 +1180,13 @@ class ThorchainQuery {
1274
1180
  outboundDelay(outboundAmount) {
1275
1181
  return __awaiter(this, void 0, void 0, function* () {
1276
1182
  const networkValues = yield this.thorchainCache.getNetworkValues();
1277
- const minTxOutVolumeThreshold = new CryptoAmount(xchainUtil.baseAmount(networkValues['MINTXOUTVOLUMETHRESHOLD']), AssetRuneNative);
1183
+ const minTxOutVolumeThreshold = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(networkValues['MINTXOUTVOLUMETHRESHOLD']), AssetRuneNative);
1278
1184
  const maxTxOutOffset = networkValues['MAXTXOUTOFFSET'];
1279
- let txOutDelayRate = new CryptoAmount(xchainUtil.baseAmount(networkValues['TXOUTDELAYRATE']), AssetRuneNative).assetAmount
1185
+ let txOutDelayRate = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(networkValues['TXOUTDELAYRATE']), AssetRuneNative).assetAmount
1280
1186
  .amount()
1281
1187
  .toNumber();
1282
1188
  const getQueue = yield this.thorchainCache.thornode.getQueue();
1283
- const outboundValue = new CryptoAmount(xchainUtil.baseAmount(getQueue.scheduled_outbound_value), AssetRuneNative);
1189
+ const outboundValue = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(getQueue.scheduled_outbound_value), AssetRuneNative);
1284
1190
  const thorChainblocktime = this.chainAttributes[THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1285
1191
  // If asset is equal to Rune set runeValue as outbound amount else set it to the asset's value in rune
1286
1192
  const runeValue = yield this.thorchainCache.convert(outboundAmount, AssetRuneNative);
@@ -1394,8 +1300,8 @@ class ThorchainQuery {
1394
1300
  const assetWaitTimeSeconds = yield this.confCounting(params.asset);
1395
1301
  const runeWaitTimeSeconds = yield this.confCounting(params.rune);
1396
1302
  const waitTimeSeconds = assetWaitTimeSeconds > runeWaitTimeSeconds ? assetWaitTimeSeconds : runeWaitTimeSeconds;
1397
- let assetInboundFee = new CryptoAmount(xchainUtil.baseAmount(0), params.asset.asset);
1398
- let runeInboundFee = new CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative);
1303
+ let assetInboundFee = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), params.asset.asset);
1304
+ let runeInboundFee = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), AssetRuneNative);
1399
1305
  if (!params.asset.assetAmount.eq(0)) {
1400
1306
  assetInboundFee = calcNetworkFee(params.asset.asset, inboundDetails[params.asset.asset.chain]);
1401
1307
  if (assetInboundFee.assetAmount.amount().times(3).gt(params.asset.assetAmount.amount()))
@@ -1582,8 +1488,8 @@ class ThorchainQuery {
1582
1488
  switch (asset.chain) {
1583
1489
  case 'BNB':
1584
1490
  dustValues = {
1585
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.000001)), AssetBNB),
1586
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1491
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.000001)), AssetBNB),
1492
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1587
1493
  };
1588
1494
  return dustValues;
1589
1495
  case 'BTC':
@@ -1591,57 +1497,57 @@ class ThorchainQuery {
1591
1497
  case `LTC`:
1592
1498
  // 10k sats
1593
1499
  dustValues = {
1594
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.0001)), asset),
1595
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1500
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.0001)), asset),
1501
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1596
1502
  };
1597
1503
  return dustValues;
1598
1504
  case 'ETH':
1599
1505
  // 0 wei
1600
1506
  dustValues = {
1601
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1602
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1507
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1508
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1603
1509
  };
1604
1510
  return dustValues;
1605
1511
  case 'THOR':
1606
1512
  // 0 Rune
1607
1513
  dustValues = {
1608
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1609
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1514
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1515
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1610
1516
  };
1611
1517
  return dustValues;
1612
1518
  case 'GAIA':
1613
1519
  // 0 GAIA
1614
1520
  dustValues = {
1615
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1616
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1521
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1522
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1617
1523
  };
1618
1524
  return dustValues;
1619
1525
  case 'DOGE':
1620
1526
  // 1 million sats
1621
1527
  dustValues = {
1622
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.01)), asset),
1623
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1528
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.01)), asset),
1529
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1624
1530
  };
1625
1531
  return dustValues;
1626
1532
  case 'AVAX':
1627
1533
  // 0 AVAX
1628
1534
  dustValues = {
1629
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1630
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1535
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1536
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1631
1537
  };
1632
1538
  return dustValues;
1633
1539
  case 'BSC':
1634
1540
  // 0 BSC
1635
1541
  dustValues = {
1636
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1637
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1542
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1543
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1638
1544
  };
1639
1545
  return dustValues;
1640
1546
  case 'MAYA':
1641
1547
  // 0 MAYA
1642
1548
  dustValues = {
1643
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1644
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1549
+ asset: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
1550
+ rune: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), AssetRuneNative),
1645
1551
  };
1646
1552
  return dustValues;
1647
1553
  default:
@@ -1673,12 +1579,12 @@ class ThorchainQuery {
1673
1579
  if (errors.length > 0) {
1674
1580
  return {
1675
1581
  assetAmount: addAmount,
1676
- estimatedDepositValue: new CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
1582
+ estimatedDepositValue: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
1677
1583
  fee: {
1678
- affiliate: new CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
1584
+ affiliate: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
1679
1585
  asset: addAmount.asset,
1680
- outbound: new CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
1681
- liquidity: new CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
1586
+ outbound: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
1587
+ liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
1682
1588
  totalBps: depositQuote.fees.total_bps || 0,
1683
1589
  },
1684
1590
  expiry: new Date(0),
@@ -1695,18 +1601,18 @@ class ThorchainQuery {
1695
1601
  const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).thornodeDetails;
1696
1602
  // Organise fees
1697
1603
  const saverFees = {
1698
- affiliate: new CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.affiliate), addAmount.asset),
1604
+ affiliate: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.affiliate), addAmount.asset),
1699
1605
  asset: xchainUtil.assetFromStringEx(depositQuote.fees.asset),
1700
- outbound: new CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.outbound), addAmount.asset),
1701
- liquidity: new CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.liquidity), addAmount.asset),
1606
+ outbound: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.outbound), addAmount.asset),
1607
+ liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.liquidity), addAmount.asset),
1702
1608
  totalBps: depositQuote.fees.total_bps || 0,
1703
1609
  };
1704
1610
  // define savers filled capacity
1705
1611
  const saverCapFilledPercent = (Number(pool.synth_supply) / Number(pool.balance_asset)) * 100;
1706
1612
  // return object
1707
1613
  const estimateAddSaver = {
1708
- assetAmount: new CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_out), addAmount.asset),
1709
- estimatedDepositValue: new CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_deposit), addAmount.asset),
1614
+ assetAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_out), addAmount.asset),
1615
+ estimatedDepositValue: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_deposit), addAmount.asset),
1710
1616
  fee: saverFees,
1711
1617
  expiry: new Date(depositQuote.expiry),
1712
1618
  toAddress: depositQuote.inbound_address,
@@ -1740,14 +1646,14 @@ class ThorchainQuery {
1740
1646
  errors.push(checkPositon.errors[i]);
1741
1647
  }
1742
1648
  return {
1743
- dustAmount: new CryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
1744
- dustThreshold: new CryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
1745
- expectedAssetAmount: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(checkPositon.redeemableValue.assetAmount.amount())), withdrawParams.asset),
1649
+ dustAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
1650
+ dustThreshold: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
1651
+ expectedAssetAmount: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(checkPositon.redeemableValue.assetAmount.amount())), withdrawParams.asset),
1746
1652
  fee: {
1747
- affiliate: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
1653
+ affiliate: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
1748
1654
  asset: withdrawParams.asset,
1749
- liquidity: new CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
1750
- outbound: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(calcOutboundFee(withdrawParams.asset, inboundDetails[withdrawParams.asset.chain]).assetAmount.amount())), withdrawParams.asset),
1655
+ liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
1656
+ outbound: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(calcOutboundFee(withdrawParams.asset, inboundDetails[withdrawParams.asset.chain]).assetAmount.amount())), withdrawParams.asset),
1751
1657
  totalBps: 0,
1752
1658
  },
1753
1659
  expiry: new Date(0),
@@ -1769,14 +1675,14 @@ class ThorchainQuery {
1769
1675
  errors.push(`Thornode request quote failed: ${response.error}`);
1770
1676
  if (errors.length > 0) {
1771
1677
  return {
1772
- dustAmount: new CryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
1773
- dustThreshold: new CryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
1774
- expectedAssetAmount: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
1678
+ dustAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
1679
+ dustThreshold: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
1680
+ expectedAssetAmount: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
1775
1681
  fee: {
1776
- affiliate: new CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
1682
+ affiliate: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
1777
1683
  asset: withdrawParams.asset,
1778
- liquidity: new CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
1779
- outbound: new CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
1684
+ liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
1685
+ outbound: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
1780
1686
  totalBps: 0,
1781
1687
  },
1782
1688
  expiry: new Date(0),
@@ -1792,14 +1698,14 @@ class ThorchainQuery {
1792
1698
  }
1793
1699
  const withdrawAsset = xchainUtil.assetFromStringEx(withdrawQuote.fees.asset);
1794
1700
  const estimateWithdrawSaver = {
1795
- dustAmount: new CryptoAmount(xchainUtil.baseAmount(withdrawQuote.dust_amount), getChainAsset(withdrawParams.asset.chain)),
1796
- dustThreshold: new CryptoAmount(xchainUtil.baseAmount(withdrawQuote.dust_threshold), getChainAsset(withdrawParams.asset.chain)),
1797
- expectedAssetAmount: new CryptoAmount(xchainUtil.baseAmount(withdrawQuote.expected_amount_out), withdrawParams.asset),
1701
+ dustAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.dust_amount), getChainAsset(withdrawParams.asset.chain)),
1702
+ dustThreshold: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.dust_threshold), getChainAsset(withdrawParams.asset.chain)),
1703
+ expectedAssetAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.expected_amount_out), withdrawParams.asset),
1798
1704
  fee: {
1799
- affiliate: new CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.affiliate), withdrawAsset),
1705
+ affiliate: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.affiliate), withdrawAsset),
1800
1706
  asset: withdrawAsset,
1801
- liquidity: new CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.liquidity), withdrawAsset),
1802
- outbound: new CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.outbound), withdrawAsset),
1707
+ liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.liquidity), withdrawAsset),
1708
+ outbound: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.outbound), withdrawAsset),
1803
1709
  totalBps: withdrawQuote.fees.total_bps || 0,
1804
1710
  },
1805
1711
  expiry: new Date(withdrawQuote.expiry),
@@ -1844,8 +1750,8 @@ class ThorchainQuery {
1844
1750
  const saverUnits = Number(pool.savers_units);
1845
1751
  const assetDepth = Number(pool.savers_depth);
1846
1752
  const redeemableValue = (ownerUnits / saverUnits) * assetDepth;
1847
- const depositAmount = new CryptoAmount(xchainUtil.baseAmount(savers === null || savers === void 0 ? void 0 : savers.asset_deposit_value), params.asset);
1848
- const redeemableAssetAmount = new CryptoAmount(xchainUtil.baseAmount(redeemableValue), params.asset);
1753
+ const depositAmount = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(savers === null || savers === void 0 ? void 0 : savers.asset_deposit_value), params.asset);
1754
+ const redeemableAssetAmount = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(redeemableValue), params.asset);
1849
1755
  const saversAge = (Number(blockData === null || blockData === void 0 ? void 0 : blockData.thorchain) - lastAdded) / ((365 * 86400) / 6);
1850
1756
  const saverGrowth = redeemableAssetAmount.minus(depositAmount).div(depositAmount).times(100);
1851
1757
  const saversPos = {
@@ -1875,7 +1781,7 @@ class ThorchainQuery {
1875
1781
  const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).thornodeDetails;
1876
1782
  if (pool.status.toLowerCase() !== 'available')
1877
1783
  errors.push(`Pool is not available for this asset ${xchainUtil.assetToString(addAmount.asset)}`);
1878
- const inboundFee = new CryptoAmount(xchainUtil.baseAmount(inboundDetails[addAmount.asset.chain].gasRate), addAmount.asset); // only needs to check against inbound fee, not network fee.
1784
+ const inboundFee = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inboundDetails[addAmount.asset.chain].gasRate), addAmount.asset); // only needs to check against inbound fee, not network fee.
1879
1785
  const inboundFeeInAddAmountAsset = yield this.convert(inboundFee, addAmount.asset); // to make sure maths is being done on same assets
1880
1786
  if (addAmount.lte(inboundFeeInAddAmountAsset))
1881
1787
  errors.push(`Add amount does not cover fees`);
@@ -2114,7 +2020,7 @@ class ThorchainQuery {
2114
2020
  const constantsDetails = yield this.thorchainCache.thornode.getTcConstants();
2115
2021
  const oneTimeFee = params.isUpdate ? xchainUtil.baseAmount(0) : xchainUtil.baseAmount(constantsDetails['TNSRegisterFee']);
2116
2022
  const totalFeePerBlock = xchainUtil.baseAmount(constantsDetails['TNSFeePerBlock']).times(numberOfBlocksToAddToExpirity > 0 ? numberOfBlocksToAddToExpirity : 0);
2117
- const totalCost = new CryptoAmount(oneTimeFee.plus(totalFeePerBlock), AssetRuneNative);
2023
+ const totalCost = new xchainUtil.CryptoAmount(oneTimeFee.plus(totalFeePerBlock), AssetRuneNative);
2118
2024
  const thornameMemo = `~:${params.thorname}:${params.chain}:${params.chainAddress}:${params.owner ? params.owner : ''}:${params.preferredAsset ? xchainUtil.assetToString(params.preferredAsset) : ''}:${params.isUpdate ? '' : currentHeightForExpirity + numberOfBlocksToAddToExpirity}`.replace(/^:+|:+$/g, '');
2119
2025
  return {
2120
2026
  memo: thornameMemo,
@@ -2271,7 +2177,7 @@ class TransactionStage {
2271
2177
  getCryptoAmount(baseAmt, asset) {
2272
2178
  return __awaiter(this, void 0, void 0, function* () {
2273
2179
  const decimals = THORChain === asset.chain ? 8 : Number(yield this.thorchainCache.midgardQuery.getDecimalForAsset(asset));
2274
- return new CryptoAmount(xchainUtil.baseAmount(baseAmt, decimals), asset);
2180
+ return new xchainUtil.CryptoAmount(xchainUtil.baseAmount(baseAmt, decimals), asset);
2275
2181
  });
2276
2182
  }
2277
2183
  determineObserved(txData) {
@@ -2574,7 +2480,6 @@ exports.BCHChain = BCHChain;
2574
2480
  exports.BNBChain = BNBChain;
2575
2481
  exports.BSCChain = BSCChain;
2576
2482
  exports.BTCChain = BTCChain;
2577
- exports.CryptoAmount = CryptoAmount;
2578
2483
  exports.DOGEChain = DOGEChain;
2579
2484
  exports.DefaultChainAttributes = DefaultChainAttributes;
2580
2485
  exports.ETHChain = ETHChain;