@xchainjs/xchain-mayachain-amm 2.0.13 → 3.0.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.esm.js CHANGED
@@ -8752,6 +8752,17 @@ var Denomination;
8752
8752
  Denomination["Asset"] = "ASSET";
8753
8753
  })(Denomination || (Denomination = {}));
8754
8754
 
8755
+ /**
8756
+ * Asset type
8757
+ */
8758
+ var AssetType;
8759
+ (function (AssetType) {
8760
+ AssetType[AssetType["NATIVE"] = 0] = "NATIVE";
8761
+ AssetType[AssetType["TOKEN"] = 1] = "TOKEN";
8762
+ AssetType[AssetType["SYNTH"] = 2] = "SYNTH";
8763
+ AssetType[AssetType["TRADE"] = 3] = "TRADE";
8764
+ })(AssetType || (AssetType = {}));
8765
+
8755
8766
  /**
8756
8767
  * Guard to check whether value is a BigNumber.Value or not
8757
8768
  *
@@ -8770,6 +8781,22 @@ const isBigNumberValue = (v) => typeof v === 'string' || typeof v === 'number' |
8770
8781
  * ```
8771
8782
  * */
8772
8783
  const ASSET_DECIMAL = 8;
8784
+ /**
8785
+ * Native asset delimiter
8786
+ */
8787
+ const NATIVE_ASSET_DELIMITER = '.';
8788
+ /**
8789
+ * Token asset delimiter
8790
+ */
8791
+ const TOKEN_ASSET_DELIMITER = '.';
8792
+ /**
8793
+ * Synth asset delimiter
8794
+ */
8795
+ const SYNTH_ASSET_DELIMITER = '/';
8796
+ /**
8797
+ * Trade asset delimiter
8798
+ */
8799
+ const TRADE_ASSET_DELIMITER = '~';
8773
8800
  /**
8774
8801
  * Factory to create values of assets (e.g. RUNE)
8775
8802
  *
@@ -8874,16 +8901,21 @@ const formatBaseAmount = (amount) => formatBN(amount.amount(), 0);
8874
8901
  * Based on definition in Thorchain `common`
8875
8902
  * @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
8876
8903
  */
8877
- const AssetBTC = { chain: 'BTC', symbol: 'BTC', ticker: 'BTC', synth: false };
8904
+ const AssetBTC = { chain: 'BTC', symbol: 'BTC', ticker: 'BTC', type: AssetType.NATIVE };
8878
8905
  /**
8879
8906
  * Base "chain" asset on ethereum main net.
8880
8907
  *
8881
8908
  * Based on definition in Thorchain `common`
8882
8909
  * @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
8883
8910
  */
8884
- const AssetETH = { chain: 'ETH', symbol: 'ETH', ticker: 'ETH', synth: false };
8885
- const SYNTH_DELIMITER = '/';
8886
- const NON_SYNTH_DELIMITER = '.';
8911
+ const AssetETH = { chain: 'ETH', symbol: 'ETH', ticker: 'ETH', type: AssetType.NATIVE };
8912
+ /**
8913
+ * Helper to check whether an asset is synth asset
8914
+ *
8915
+ * @param {Asset} asset
8916
+ * @returns {boolean} `true` or `false`
8917
+ */
8918
+ const isSynthAsset = (asset) => asset.type === AssetType.SYNTH;
8887
8919
  /**
8888
8920
  * Returns an `Asset` as a string using following naming convention:
8889
8921
  *
@@ -8899,9 +8931,17 @@ const NON_SYNTH_DELIMITER = '.';
8899
8931
  * @param {Asset} asset The given asset.
8900
8932
  * @returns {string} The string from the given asset.
8901
8933
  */
8902
- const assetToString = ({ chain, symbol, synth }) => {
8903
- const delimiter = synth ? SYNTH_DELIMITER : NON_SYNTH_DELIMITER;
8904
- return `${chain}${delimiter}${symbol}`;
8934
+ const assetToString = ({ chain, symbol, type }) => {
8935
+ switch (type) {
8936
+ case AssetType.SYNTH:
8937
+ return `${chain}${SYNTH_ASSET_DELIMITER}${symbol}`;
8938
+ case AssetType.TOKEN:
8939
+ return `${chain}${TOKEN_ASSET_DELIMITER}${symbol}`;
8940
+ case AssetType.TRADE:
8941
+ return `${chain}${TRADE_ASSET_DELIMITER}${symbol}`;
8942
+ default:
8943
+ return `${chain}${NATIVE_ASSET_DELIMITER}${symbol}`;
8944
+ }
8905
8945
  };
8906
8946
  /**
8907
8947
  * Currency symbols currently supported
@@ -8982,7 +9022,7 @@ const formatAssetAmountCurrency = ({ amount, asset, decimal, trimZeros: shouldTr
8982
9022
  * @param {Asset} b Asset two
8983
9023
  * @return {boolean} Result of equality check
8984
9024
  */
8985
- const eqAsset = (a, b) => a.chain === b.chain && a.symbol === b.symbol && a.ticker === b.ticker && a.synth === b.synth;
9025
+ const eqAsset = (a, b) => a.chain === b.chain && a.symbol === b.symbol && a.ticker === b.ticker && a.type === b.type;
8986
9026
  /**
8987
9027
  * Removes `0x` or `0X` from address
8988
9028
  */
@@ -8996,7 +9036,7 @@ const getContractAddressFromAsset = (asset) => {
8996
9036
  * Utility Class to combine an amount (asset/base) with the Asset
8997
9037
  *
8998
9038
  */
8999
- class CryptoAmount {
9039
+ class BaseCryptoAmount {
9000
9040
  constructor(amount, asset) {
9001
9041
  this.asset = asset;
9002
9042
  this.baseAmount = amount;
@@ -9004,33 +9044,33 @@ class CryptoAmount {
9004
9044
  plus(v) {
9005
9045
  this.check(v);
9006
9046
  const assetAmountResult = assetToBase(this.assetAmount.plus(v.assetAmount));
9007
- return new CryptoAmount(assetAmountResult, this.asset);
9047
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9008
9048
  }
9009
9049
  minus(v) {
9010
9050
  this.check(v);
9011
9051
  const assetAmountResult = assetToBase(this.assetAmount.minus(v.assetAmount));
9012
- return new CryptoAmount(assetAmountResult, this.asset);
9052
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9013
9053
  }
9014
9054
  times(v) {
9015
9055
  this.check(v);
9016
- if (v instanceof CryptoAmount) {
9056
+ if (v instanceof BaseCryptoAmount) {
9017
9057
  const assetAmountResult = assetToBase(this.assetAmount.times(v.assetAmount));
9018
- return new CryptoAmount(assetAmountResult, this.asset);
9058
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9019
9059
  }
9020
9060
  else {
9021
9061
  const assetAmountResult = assetToBase(this.assetAmount.times(v));
9022
- return new CryptoAmount(assetAmountResult, this.asset);
9062
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9023
9063
  }
9024
9064
  }
9025
9065
  div(v) {
9026
9066
  this.check(v);
9027
- if (v instanceof CryptoAmount) {
9067
+ if (v instanceof BaseCryptoAmount) {
9028
9068
  const assetAmountResult = assetToBase(this.assetAmount.div(v.assetAmount));
9029
- return new CryptoAmount(assetAmountResult, this.asset);
9069
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9030
9070
  }
9031
9071
  else {
9032
9072
  const assetAmountResult = assetToBase(this.assetAmount.div(v));
9033
- return new CryptoAmount(assetAmountResult, this.asset);
9073
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9034
9074
  }
9035
9075
  }
9036
9076
  lt(v) {
@@ -9078,13 +9118,17 @@ class CryptoAmount {
9078
9118
  * @param v - CryptoNumeric
9079
9119
  */
9080
9120
  check(v) {
9081
- if (v instanceof CryptoAmount) {
9121
+ if (v instanceof BaseCryptoAmount) {
9082
9122
  if (!eqAsset(this.asset, v.asset)) {
9083
9123
  throw Error(`cannot perform math on 2 diff assets ${assetToString(this.asset)} ${assetToString(v.asset)}`);
9084
9124
  }
9085
9125
  }
9086
9126
  }
9087
9127
  }
9128
+ class CryptoAmount extends BaseCryptoAmount {
9129
+ }
9130
+ class AssetCryptoAmount extends BaseCryptoAmount {
9131
+ }
9088
9132
 
9089
9133
  var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
9090
9134
 
@@ -89542,7 +89586,18 @@ const isProtocolEVMChain = (chain) => {
89542
89586
  */
89543
89587
  const isProtocolERC20Asset = (asset) => {
89544
89588
  return isProtocolEVMChain(asset.chain)
89545
- ? [AssetETH$1, AssetAETH].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, asset)) === -1 && !asset.synth
89589
+ ? [AssetETH$1, AssetAETH].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, asset)) === -1 && !isSynthAsset(asset)
89590
+ : false;
89591
+ };
89592
+ /**
89593
+ * Check if asset is ERC20
89594
+ * @param {Asset} asset to check
89595
+ * @returns true if asset is ERC20, otherwise, false
89596
+ */
89597
+ const isTokenCryptoAmount = (amount) => {
89598
+ return isProtocolEVMChain(amount.asset.chain)
89599
+ ? [AssetETH$1, AssetAETH].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, amount.asset)) === -1 &&
89600
+ !isSynthAsset(amount.asset)
89546
89601
  : false;
89547
89602
  };
89548
89603
  /**
@@ -89660,12 +89715,12 @@ class MayachainAction {
89660
89715
  });
89661
89716
  }
89662
89717
  static isNonProtocolParams(params) {
89663
- if ((params.assetAmount.asset.chain === MAYAChain || params.assetAmount.asset.synth) &&
89718
+ if ((params.assetAmount.asset.chain === MAYAChain || isSynthAsset(params.assetAmount.asset)) &&
89664
89719
  'address' in params &&
89665
89720
  !!params.address) {
89666
89721
  throw Error('Inconsistent params. Native actions do not support recipient');
89667
89722
  }
89668
- return params.assetAmount.asset.chain !== MAYAChain && !params.assetAmount.asset.synth;
89723
+ return params.assetAmount.asset.chain !== MAYAChain && !isSynthAsset(params.assetAmount.asset);
89669
89724
  }
89670
89725
  }
89671
89726
 
@@ -89701,7 +89756,7 @@ class MayachainAMM {
89701
89756
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters.
89702
89757
  * @returns {QuoteSwap} Quote swap result. If swap cannot be done, it returns an empty QuoteSwap with reasons.
89703
89758
  */
89704
- estimateSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, }) {
89759
+ estimateSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }) {
89705
89760
  return __awaiter$8(this, void 0, void 0, function* () {
89706
89761
  const errors = yield this.validateSwap({
89707
89762
  fromAsset,
@@ -89711,6 +89766,8 @@ class MayachainAMM {
89711
89766
  destinationAddress,
89712
89767
  affiliateAddress,
89713
89768
  affiliateBps,
89769
+ streamingInterval,
89770
+ streamingQuantity,
89714
89771
  });
89715
89772
  if (errors.length > 0) {
89716
89773
  return {
@@ -89722,6 +89779,8 @@ class MayachainAMM {
89722
89779
  asset: destinationAsset,
89723
89780
  affiliateFee: new CryptoAmount(baseAmount(0), destinationAsset),
89724
89781
  outboundFee: new CryptoAmount(baseAmount(0), destinationAsset),
89782
+ liquidityFee: new CryptoAmount(baseAmount(0), destinationAsset),
89783
+ totalFee: new CryptoAmount(baseAmount(0), destinationAsset),
89725
89784
  },
89726
89785
  outboundDelayBlocks: 0,
89727
89786
  outboundDelaySeconds: 0,
@@ -89731,6 +89790,7 @@ class MayachainAMM {
89731
89790
  errors,
89732
89791
  slipBasisPoints: 0,
89733
89792
  totalSwapSeconds: 0,
89793
+ expiry: 0,
89734
89794
  warning: '',
89735
89795
  };
89736
89796
  }
@@ -89743,6 +89803,8 @@ class MayachainAMM {
89743
89803
  affiliateAddress,
89744
89804
  affiliateBps,
89745
89805
  toleranceBps,
89806
+ streamingInterval,
89807
+ streamingQuantity,
89746
89808
  });
89747
89809
  });
89748
89810
  }
@@ -89752,12 +89814,12 @@ class MayachainAMM {
89752
89814
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters.
89753
89815
  * @returns {string[]} Reasons the swap cannot be executed. Empty array if the swap is valid.
89754
89816
  */
89755
- validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, }) {
89817
+ validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
89756
89818
  return __awaiter$8(this, void 0, void 0, function* () {
89757
89819
  const errors = [];
89758
89820
  // Validate destination address if provided
89759
89821
  if (destinationAddress &&
89760
- !validateAddress(this.mayachainQuery.getNetwork(), destinationAsset.synth ? MAYAChain : destinationAsset.chain, destinationAddress)) {
89822
+ !validateAddress(this.mayachainQuery.getNetwork(), isSynthAsset(destinationAsset) ? MAYAChain : destinationAsset.chain, destinationAddress)) {
89761
89823
  errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
89762
89824
  }
89763
89825
  // Validate affiliate address if provided
@@ -89773,12 +89835,23 @@ class MayachainAMM {
89773
89835
  }
89774
89836
  // Validate approval if asset is an ERC20 token and fromAddress is provided
89775
89837
  if (isProtocolERC20Asset(fromAsset) && fromAddress) {
89776
- const approveErrors = yield this.isRouterApprovedToSpend({
89777
- asset: fromAsset,
89778
- address: fromAddress,
89779
- amount,
89780
- });
89781
- errors.push(...approveErrors);
89838
+ if (!isTokenCryptoAmount(amount)) {
89839
+ errors.push(`${assetToString(amount.asset)} is not Token asset amount`);
89840
+ }
89841
+ else {
89842
+ const approveErrors = yield this.isRouterApprovedToSpend({
89843
+ asset: fromAsset,
89844
+ address: fromAddress,
89845
+ amount,
89846
+ });
89847
+ errors.push(...approveErrors);
89848
+ }
89849
+ }
89850
+ if (streamingQuantity && streamingQuantity < 0) {
89851
+ errors.push('streaming quantity can not be lower than 0');
89852
+ }
89853
+ if (streamingInterval && streamingInterval < 0) {
89854
+ errors.push('streaming interval can not be lower than 0');
89782
89855
  }
89783
89856
  return errors;
89784
89857
  });
@@ -89888,7 +89961,7 @@ class MayachainAMM {
89888
89961
  return {
89889
89962
  memo: '',
89890
89963
  errors,
89891
- value: new CryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89964
+ value: new AssetCryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89892
89965
  allowed: false,
89893
89966
  };
89894
89967
  }
@@ -89901,7 +89974,7 @@ class MayachainAMM {
89901
89974
  return {
89902
89975
  memo: '',
89903
89976
  errors: ['message' in e ? e.message : `Unknown error: ${e}`],
89904
- value: new CryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89977
+ value: new AssetCryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89905
89978
  allowed: false,
89906
89979
  };
89907
89980
  }
@@ -89930,7 +90003,7 @@ class MayachainAMM {
89930
90003
  return {
89931
90004
  memo: '',
89932
90005
  errors,
89933
- value: new CryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
90006
+ value: new AssetCryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89934
90007
  allowed: false,
89935
90008
  };
89936
90009
  }
@@ -89943,7 +90016,7 @@ class MayachainAMM {
89943
90016
  return {
89944
90017
  memo: '',
89945
90018
  errors: ['message' in e ? e.message : `Unknown error: ${e}`],
89946
- value: new CryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
90019
+ value: new AssetCryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89947
90020
  allowed: false,
89948
90021
  };
89949
90022
  }
package/lib/index.js CHANGED
@@ -8760,6 +8760,17 @@ var Denomination;
8760
8760
  Denomination["Asset"] = "ASSET";
8761
8761
  })(Denomination || (Denomination = {}));
8762
8762
 
8763
+ /**
8764
+ * Asset type
8765
+ */
8766
+ var AssetType;
8767
+ (function (AssetType) {
8768
+ AssetType[AssetType["NATIVE"] = 0] = "NATIVE";
8769
+ AssetType[AssetType["TOKEN"] = 1] = "TOKEN";
8770
+ AssetType[AssetType["SYNTH"] = 2] = "SYNTH";
8771
+ AssetType[AssetType["TRADE"] = 3] = "TRADE";
8772
+ })(AssetType || (AssetType = {}));
8773
+
8763
8774
  /**
8764
8775
  * Guard to check whether value is a BigNumber.Value or not
8765
8776
  *
@@ -8778,6 +8789,22 @@ const isBigNumberValue = (v) => typeof v === 'string' || typeof v === 'number' |
8778
8789
  * ```
8779
8790
  * */
8780
8791
  const ASSET_DECIMAL = 8;
8792
+ /**
8793
+ * Native asset delimiter
8794
+ */
8795
+ const NATIVE_ASSET_DELIMITER = '.';
8796
+ /**
8797
+ * Token asset delimiter
8798
+ */
8799
+ const TOKEN_ASSET_DELIMITER = '.';
8800
+ /**
8801
+ * Synth asset delimiter
8802
+ */
8803
+ const SYNTH_ASSET_DELIMITER = '/';
8804
+ /**
8805
+ * Trade asset delimiter
8806
+ */
8807
+ const TRADE_ASSET_DELIMITER = '~';
8781
8808
  /**
8782
8809
  * Factory to create values of assets (e.g. RUNE)
8783
8810
  *
@@ -8882,16 +8909,21 @@ const formatBaseAmount = (amount) => formatBN(amount.amount(), 0);
8882
8909
  * Based on definition in Thorchain `common`
8883
8910
  * @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
8884
8911
  */
8885
- const AssetBTC = { chain: 'BTC', symbol: 'BTC', ticker: 'BTC', synth: false };
8912
+ const AssetBTC = { chain: 'BTC', symbol: 'BTC', ticker: 'BTC', type: AssetType.NATIVE };
8886
8913
  /**
8887
8914
  * Base "chain" asset on ethereum main net.
8888
8915
  *
8889
8916
  * Based on definition in Thorchain `common`
8890
8917
  * @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
8891
8918
  */
8892
- const AssetETH = { chain: 'ETH', symbol: 'ETH', ticker: 'ETH', synth: false };
8893
- const SYNTH_DELIMITER = '/';
8894
- const NON_SYNTH_DELIMITER = '.';
8919
+ const AssetETH = { chain: 'ETH', symbol: 'ETH', ticker: 'ETH', type: AssetType.NATIVE };
8920
+ /**
8921
+ * Helper to check whether an asset is synth asset
8922
+ *
8923
+ * @param {Asset} asset
8924
+ * @returns {boolean} `true` or `false`
8925
+ */
8926
+ const isSynthAsset = (asset) => asset.type === AssetType.SYNTH;
8895
8927
  /**
8896
8928
  * Returns an `Asset` as a string using following naming convention:
8897
8929
  *
@@ -8907,9 +8939,17 @@ const NON_SYNTH_DELIMITER = '.';
8907
8939
  * @param {Asset} asset The given asset.
8908
8940
  * @returns {string} The string from the given asset.
8909
8941
  */
8910
- const assetToString = ({ chain, symbol, synth }) => {
8911
- const delimiter = synth ? SYNTH_DELIMITER : NON_SYNTH_DELIMITER;
8912
- return `${chain}${delimiter}${symbol}`;
8942
+ const assetToString = ({ chain, symbol, type }) => {
8943
+ switch (type) {
8944
+ case AssetType.SYNTH:
8945
+ return `${chain}${SYNTH_ASSET_DELIMITER}${symbol}`;
8946
+ case AssetType.TOKEN:
8947
+ return `${chain}${TOKEN_ASSET_DELIMITER}${symbol}`;
8948
+ case AssetType.TRADE:
8949
+ return `${chain}${TRADE_ASSET_DELIMITER}${symbol}`;
8950
+ default:
8951
+ return `${chain}${NATIVE_ASSET_DELIMITER}${symbol}`;
8952
+ }
8913
8953
  };
8914
8954
  /**
8915
8955
  * Currency symbols currently supported
@@ -8990,7 +9030,7 @@ const formatAssetAmountCurrency = ({ amount, asset, decimal, trimZeros: shouldTr
8990
9030
  * @param {Asset} b Asset two
8991
9031
  * @return {boolean} Result of equality check
8992
9032
  */
8993
- const eqAsset = (a, b) => a.chain === b.chain && a.symbol === b.symbol && a.ticker === b.ticker && a.synth === b.synth;
9033
+ const eqAsset = (a, b) => a.chain === b.chain && a.symbol === b.symbol && a.ticker === b.ticker && a.type === b.type;
8994
9034
  /**
8995
9035
  * Removes `0x` or `0X` from address
8996
9036
  */
@@ -9004,7 +9044,7 @@ const getContractAddressFromAsset = (asset) => {
9004
9044
  * Utility Class to combine an amount (asset/base) with the Asset
9005
9045
  *
9006
9046
  */
9007
- class CryptoAmount {
9047
+ class BaseCryptoAmount {
9008
9048
  constructor(amount, asset) {
9009
9049
  this.asset = asset;
9010
9050
  this.baseAmount = amount;
@@ -9012,33 +9052,33 @@ class CryptoAmount {
9012
9052
  plus(v) {
9013
9053
  this.check(v);
9014
9054
  const assetAmountResult = assetToBase(this.assetAmount.plus(v.assetAmount));
9015
- return new CryptoAmount(assetAmountResult, this.asset);
9055
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9016
9056
  }
9017
9057
  minus(v) {
9018
9058
  this.check(v);
9019
9059
  const assetAmountResult = assetToBase(this.assetAmount.minus(v.assetAmount));
9020
- return new CryptoAmount(assetAmountResult, this.asset);
9060
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9021
9061
  }
9022
9062
  times(v) {
9023
9063
  this.check(v);
9024
- if (v instanceof CryptoAmount) {
9064
+ if (v instanceof BaseCryptoAmount) {
9025
9065
  const assetAmountResult = assetToBase(this.assetAmount.times(v.assetAmount));
9026
- return new CryptoAmount(assetAmountResult, this.asset);
9066
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9027
9067
  }
9028
9068
  else {
9029
9069
  const assetAmountResult = assetToBase(this.assetAmount.times(v));
9030
- return new CryptoAmount(assetAmountResult, this.asset);
9070
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9031
9071
  }
9032
9072
  }
9033
9073
  div(v) {
9034
9074
  this.check(v);
9035
- if (v instanceof CryptoAmount) {
9075
+ if (v instanceof BaseCryptoAmount) {
9036
9076
  const assetAmountResult = assetToBase(this.assetAmount.div(v.assetAmount));
9037
- return new CryptoAmount(assetAmountResult, this.asset);
9077
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9038
9078
  }
9039
9079
  else {
9040
9080
  const assetAmountResult = assetToBase(this.assetAmount.div(v));
9041
- return new CryptoAmount(assetAmountResult, this.asset);
9081
+ return new BaseCryptoAmount(assetAmountResult, this.asset);
9042
9082
  }
9043
9083
  }
9044
9084
  lt(v) {
@@ -9086,13 +9126,17 @@ class CryptoAmount {
9086
9126
  * @param v - CryptoNumeric
9087
9127
  */
9088
9128
  check(v) {
9089
- if (v instanceof CryptoAmount) {
9129
+ if (v instanceof BaseCryptoAmount) {
9090
9130
  if (!eqAsset(this.asset, v.asset)) {
9091
9131
  throw Error(`cannot perform math on 2 diff assets ${assetToString(this.asset)} ${assetToString(v.asset)}`);
9092
9132
  }
9093
9133
  }
9094
9134
  }
9095
9135
  }
9136
+ class CryptoAmount extends BaseCryptoAmount {
9137
+ }
9138
+ class AssetCryptoAmount extends BaseCryptoAmount {
9139
+ }
9096
9140
 
9097
9141
  var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
9098
9142
 
@@ -89550,7 +89594,18 @@ const isProtocolEVMChain = (chain) => {
89550
89594
  */
89551
89595
  const isProtocolERC20Asset = (asset) => {
89552
89596
  return isProtocolEVMChain(asset.chain)
89553
- ? [xchainEthereum.AssetETH, xchainArbitrum.AssetAETH].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, asset)) === -1 && !asset.synth
89597
+ ? [xchainEthereum.AssetETH, xchainArbitrum.AssetAETH].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, asset)) === -1 && !isSynthAsset(asset)
89598
+ : false;
89599
+ };
89600
+ /**
89601
+ * Check if asset is ERC20
89602
+ * @param {Asset} asset to check
89603
+ * @returns true if asset is ERC20, otherwise, false
89604
+ */
89605
+ const isTokenCryptoAmount = (amount) => {
89606
+ return isProtocolEVMChain(amount.asset.chain)
89607
+ ? [xchainEthereum.AssetETH, xchainArbitrum.AssetAETH].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, amount.asset)) === -1 &&
89608
+ !isSynthAsset(amount.asset)
89554
89609
  : false;
89555
89610
  };
89556
89611
  /**
@@ -89668,12 +89723,12 @@ class MayachainAction {
89668
89723
  });
89669
89724
  }
89670
89725
  static isNonProtocolParams(params) {
89671
- if ((params.assetAmount.asset.chain === xchainMayachain.MAYAChain || params.assetAmount.asset.synth) &&
89726
+ if ((params.assetAmount.asset.chain === xchainMayachain.MAYAChain || isSynthAsset(params.assetAmount.asset)) &&
89672
89727
  'address' in params &&
89673
89728
  !!params.address) {
89674
89729
  throw Error('Inconsistent params. Native actions do not support recipient');
89675
89730
  }
89676
- return params.assetAmount.asset.chain !== xchainMayachain.MAYAChain && !params.assetAmount.asset.synth;
89731
+ return params.assetAmount.asset.chain !== xchainMayachain.MAYAChain && !isSynthAsset(params.assetAmount.asset);
89677
89732
  }
89678
89733
  }
89679
89734
 
@@ -89709,7 +89764,7 @@ class MayachainAMM {
89709
89764
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters.
89710
89765
  * @returns {QuoteSwap} Quote swap result. If swap cannot be done, it returns an empty QuoteSwap with reasons.
89711
89766
  */
89712
- estimateSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, }) {
89767
+ estimateSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }) {
89713
89768
  return __awaiter$8(this, void 0, void 0, function* () {
89714
89769
  const errors = yield this.validateSwap({
89715
89770
  fromAsset,
@@ -89719,6 +89774,8 @@ class MayachainAMM {
89719
89774
  destinationAddress,
89720
89775
  affiliateAddress,
89721
89776
  affiliateBps,
89777
+ streamingInterval,
89778
+ streamingQuantity,
89722
89779
  });
89723
89780
  if (errors.length > 0) {
89724
89781
  return {
@@ -89730,6 +89787,8 @@ class MayachainAMM {
89730
89787
  asset: destinationAsset,
89731
89788
  affiliateFee: new CryptoAmount(baseAmount(0), destinationAsset),
89732
89789
  outboundFee: new CryptoAmount(baseAmount(0), destinationAsset),
89790
+ liquidityFee: new CryptoAmount(baseAmount(0), destinationAsset),
89791
+ totalFee: new CryptoAmount(baseAmount(0), destinationAsset),
89733
89792
  },
89734
89793
  outboundDelayBlocks: 0,
89735
89794
  outboundDelaySeconds: 0,
@@ -89739,6 +89798,7 @@ class MayachainAMM {
89739
89798
  errors,
89740
89799
  slipBasisPoints: 0,
89741
89800
  totalSwapSeconds: 0,
89801
+ expiry: 0,
89742
89802
  warning: '',
89743
89803
  };
89744
89804
  }
@@ -89751,6 +89811,8 @@ class MayachainAMM {
89751
89811
  affiliateAddress,
89752
89812
  affiliateBps,
89753
89813
  toleranceBps,
89814
+ streamingInterval,
89815
+ streamingQuantity,
89754
89816
  });
89755
89817
  });
89756
89818
  }
@@ -89760,12 +89822,12 @@ class MayachainAMM {
89760
89822
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters.
89761
89823
  * @returns {string[]} Reasons the swap cannot be executed. Empty array if the swap is valid.
89762
89824
  */
89763
- validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, }) {
89825
+ validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
89764
89826
  return __awaiter$8(this, void 0, void 0, function* () {
89765
89827
  const errors = [];
89766
89828
  // Validate destination address if provided
89767
89829
  if (destinationAddress &&
89768
- !validateAddress(this.mayachainQuery.getNetwork(), destinationAsset.synth ? xchainMayachain.MAYAChain : destinationAsset.chain, destinationAddress)) {
89830
+ !validateAddress(this.mayachainQuery.getNetwork(), isSynthAsset(destinationAsset) ? xchainMayachain.MAYAChain : destinationAsset.chain, destinationAddress)) {
89769
89831
  errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
89770
89832
  }
89771
89833
  // Validate affiliate address if provided
@@ -89781,12 +89843,23 @@ class MayachainAMM {
89781
89843
  }
89782
89844
  // Validate approval if asset is an ERC20 token and fromAddress is provided
89783
89845
  if (isProtocolERC20Asset(fromAsset) && fromAddress) {
89784
- const approveErrors = yield this.isRouterApprovedToSpend({
89785
- asset: fromAsset,
89786
- address: fromAddress,
89787
- amount,
89788
- });
89789
- errors.push(...approveErrors);
89846
+ if (!isTokenCryptoAmount(amount)) {
89847
+ errors.push(`${assetToString(amount.asset)} is not Token asset amount`);
89848
+ }
89849
+ else {
89850
+ const approveErrors = yield this.isRouterApprovedToSpend({
89851
+ asset: fromAsset,
89852
+ address: fromAddress,
89853
+ amount,
89854
+ });
89855
+ errors.push(...approveErrors);
89856
+ }
89857
+ }
89858
+ if (streamingQuantity && streamingQuantity < 0) {
89859
+ errors.push('streaming quantity can not be lower than 0');
89860
+ }
89861
+ if (streamingInterval && streamingInterval < 0) {
89862
+ errors.push('streaming interval can not be lower than 0');
89790
89863
  }
89791
89864
  return errors;
89792
89865
  });
@@ -89896,7 +89969,7 @@ class MayachainAMM {
89896
89969
  return {
89897
89970
  memo: '',
89898
89971
  errors,
89899
- value: new CryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89972
+ value: new AssetCryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89900
89973
  allowed: false,
89901
89974
  };
89902
89975
  }
@@ -89909,7 +89982,7 @@ class MayachainAMM {
89909
89982
  return {
89910
89983
  memo: '',
89911
89984
  errors: ['message' in e ? e.message : `Unknown error: ${e}`],
89912
- value: new CryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89985
+ value: new AssetCryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89913
89986
  allowed: false,
89914
89987
  };
89915
89988
  }
@@ -89938,7 +90011,7 @@ class MayachainAMM {
89938
90011
  return {
89939
90012
  memo: '',
89940
90013
  errors,
89941
- value: new CryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
90014
+ value: new AssetCryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89942
90015
  allowed: false,
89943
90016
  };
89944
90017
  }
@@ -89951,7 +90024,7 @@ class MayachainAMM {
89951
90024
  return {
89952
90025
  memo: '',
89953
90026
  errors: ['message' in e ? e.message : `Unknown error: ${e}`],
89954
- value: new CryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
90027
+ value: new AssetCryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89955
90028
  allowed: false,
89956
90029
  };
89957
90030
  }
@@ -1,15 +1,16 @@
1
- import { Address, CryptoAmount } from '@xchainjs/xchain-util';
1
+ import { CompatibleAsset } from '@xchainjs/xchain-mayachain-query';
2
+ import { Address, Asset, CryptoAmount, TokenAsset } from '@xchainjs/xchain-util';
2
3
  import { Wallet } from '@xchainjs/xchain-wallet';
3
4
  import { TxSubmitted } from './types';
4
5
  export type NonProtocolActionParams = {
5
6
  wallet: Wallet;
6
- assetAmount: CryptoAmount;
7
+ assetAmount: CryptoAmount<Asset | TokenAsset>;
7
8
  recipient: Address;
8
9
  memo: string;
9
10
  };
10
11
  export type ProtocolActionParams = {
11
12
  wallet: Wallet;
12
- assetAmount: CryptoAmount;
13
+ assetAmount: CryptoAmount<CompatibleAsset>;
13
14
  memo: string;
14
15
  };
15
16
  export type ActionParams = ProtocolActionParams | NonProtocolActionParams;
@@ -25,14 +25,14 @@ export declare class MayachainAMM {
25
25
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters.
26
26
  * @returns {QuoteSwap} Quote swap result. If swap cannot be done, it returns an empty QuoteSwap with reasons.
27
27
  */
28
- estimateSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, }: QuoteSwapParams): Promise<QuoteSwap>;
28
+ estimateSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<QuoteSwap>;
29
29
  /**
30
30
  * Validate swap parameters before performing a swap operation.
31
31
  *
32
32
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters.
33
33
  * @returns {string[]} Reasons the swap cannot be executed. Empty array if the swap is valid.
34
34
  */
35
- validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, }: QuoteSwapParams): Promise<string[]>;
35
+ validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<string[]>;
36
36
  /**
37
37
  * Perform a swap operation between assets.
38
38
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters
package/lib/types.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import { QuoteMAYAName as BaseQuoteMAYAName } from '@xchainjs/xchain-mayachain-query';
2
- import { Address, Asset, CryptoAmount } from '@xchainjs/xchain-util';
2
+ import { Address, TokenAsset, TokenCryptoAmount } from '@xchainjs/xchain-util';
3
3
  export type TxSubmitted = {
4
4
  hash: string;
5
5
  url: string;
6
6
  };
7
7
  export type ApproveParams = {
8
- asset: Asset;
9
- amount: CryptoAmount | undefined;
8
+ asset: TokenAsset;
9
+ amount?: TokenCryptoAmount;
10
10
  };
11
11
  export type IsApprovedParams = {
12
- asset: Asset;
13
- amount: CryptoAmount;
12
+ asset: TokenAsset;
13
+ amount: TokenCryptoAmount;
14
14
  address: Address;
15
15
  };
16
16
  /**
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Network } from '@xchainjs/xchain-client';
2
- import { Address, Asset, Chain } from '@xchainjs/xchain-util';
2
+ import { CompatibleAsset } from '@xchainjs/xchain-mayachain-query';
3
+ import { Address, Chain, CryptoAmount, TokenAsset, TokenCryptoAmount } from '@xchainjs/xchain-util';
3
4
  /**
4
5
  * Check if a chain is EVM and supported by the protocol
5
6
  * @param {Chain} chain to check
@@ -11,7 +12,13 @@ export declare const isProtocolEVMChain: (chain: Chain) => boolean;
11
12
  * @param {Asset} asset to check
12
13
  * @returns true if asset is ERC20, otherwise, false
13
14
  */
14
- export declare const isProtocolERC20Asset: (asset: Asset) => boolean;
15
+ export declare const isProtocolERC20Asset: (asset: CompatibleAsset) => asset is TokenAsset;
16
+ /**
17
+ * Check if asset is ERC20
18
+ * @param {Asset} asset to check
19
+ * @returns true if asset is ERC20, otherwise, false
20
+ */
21
+ export declare const isTokenCryptoAmount: (amount: CryptoAmount) => amount is TokenCryptoAmount;
15
22
  /**
16
23
  * Check if a chain is EVM and supported by the protocol
17
24
  * @param {Chain} chain to check
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-mayachain-amm",
3
- "version": "2.0.13",
3
+ "version": "3.0.0",
4
4
  "description": "module that exposes estimating & swapping cryptocurrency assets on mayachain",
5
5
  "keywords": [
6
6
  "MAYAChain",
@@ -36,16 +36,16 @@
36
36
  "url": "https://github.com/xchainjs/xchainjs-lib/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@xchainjs/xchain-arbitrum": "0.1.14",
40
- "@xchainjs/xchain-bitcoin": "0.23.19",
41
- "@xchainjs/xchain-client": "0.16.8",
42
- "@xchainjs/xchain-dash": "0.3.6",
43
- "@xchainjs/xchain-ethereum": "0.32.6",
44
- "@xchainjs/xchain-kujira": "0.1.21",
45
- "@xchainjs/xchain-mayachain": "1.0.11",
46
- "@xchainjs/xchain-mayachain-query": "0.1.20",
47
- "@xchainjs/xchain-thorchain": "1.1.1",
48
- "@xchainjs/xchain-wallet": "0.1.19",
39
+ "@xchainjs/xchain-arbitrum": "1.0.0",
40
+ "@xchainjs/xchain-bitcoin": "1.0.0",
41
+ "@xchainjs/xchain-client": "1.0.0",
42
+ "@xchainjs/xchain-dash": "1.0.0",
43
+ "@xchainjs/xchain-ethereum": "1.0.0",
44
+ "@xchainjs/xchain-kujira": "1.0.0",
45
+ "@xchainjs/xchain-mayachain": "2.0.0",
46
+ "@xchainjs/xchain-mayachain-query": "1.0.0",
47
+ "@xchainjs/xchain-thorchain": "2.0.0",
48
+ "@xchainjs/xchain-wallet": "1.0.0",
49
49
  "ethers": "5.7.2"
50
50
  },
51
51
  "devDependencies": {