@xchainjs/xchain-mayachain-amm 2.0.14 → 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
 
@@ -89764,7 +89819,7 @@ class MayachainAMM {
89764
89819
  const errors = [];
89765
89820
  // Validate destination address if provided
89766
89821
  if (destinationAddress &&
89767
- !validateAddress(this.mayachainQuery.getNetwork(), destinationAsset.synth ? MAYAChain : destinationAsset.chain, destinationAddress)) {
89822
+ !validateAddress(this.mayachainQuery.getNetwork(), isSynthAsset(destinationAsset) ? MAYAChain : destinationAsset.chain, destinationAddress)) {
89768
89823
  errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
89769
89824
  }
89770
89825
  // Validate affiliate address if provided
@@ -89780,12 +89835,17 @@ class MayachainAMM {
89780
89835
  }
89781
89836
  // Validate approval if asset is an ERC20 token and fromAddress is provided
89782
89837
  if (isProtocolERC20Asset(fromAsset) && fromAddress) {
89783
- const approveErrors = yield this.isRouterApprovedToSpend({
89784
- asset: fromAsset,
89785
- address: fromAddress,
89786
- amount,
89787
- });
89788
- 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
+ }
89789
89849
  }
89790
89850
  if (streamingQuantity && streamingQuantity < 0) {
89791
89851
  errors.push('streaming quantity can not be lower than 0');
@@ -89901,7 +89961,7 @@ class MayachainAMM {
89901
89961
  return {
89902
89962
  memo: '',
89903
89963
  errors,
89904
- value: new CryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89964
+ value: new AssetCryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89905
89965
  allowed: false,
89906
89966
  };
89907
89967
  }
@@ -89914,7 +89974,7 @@ class MayachainAMM {
89914
89974
  return {
89915
89975
  memo: '',
89916
89976
  errors: ['message' in e ? e.message : `Unknown error: ${e}`],
89917
- value: new CryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89977
+ value: new AssetCryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89918
89978
  allowed: false,
89919
89979
  };
89920
89980
  }
@@ -89943,7 +90003,7 @@ class MayachainAMM {
89943
90003
  return {
89944
90004
  memo: '',
89945
90005
  errors,
89946
- value: new CryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
90006
+ value: new AssetCryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89947
90007
  allowed: false,
89948
90008
  };
89949
90009
  }
@@ -89956,7 +90016,7 @@ class MayachainAMM {
89956
90016
  return {
89957
90017
  memo: '',
89958
90018
  errors: ['message' in e ? e.message : `Unknown error: ${e}`],
89959
- value: new CryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
90019
+ value: new AssetCryptoAmount(baseAmount(0, CACAO_DECIMAL), AssetCacao),
89960
90020
  allowed: false,
89961
90021
  };
89962
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
 
@@ -89772,7 +89827,7 @@ class MayachainAMM {
89772
89827
  const errors = [];
89773
89828
  // Validate destination address if provided
89774
89829
  if (destinationAddress &&
89775
- !validateAddress(this.mayachainQuery.getNetwork(), destinationAsset.synth ? xchainMayachain.MAYAChain : destinationAsset.chain, destinationAddress)) {
89830
+ !validateAddress(this.mayachainQuery.getNetwork(), isSynthAsset(destinationAsset) ? xchainMayachain.MAYAChain : destinationAsset.chain, destinationAddress)) {
89776
89831
  errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
89777
89832
  }
89778
89833
  // Validate affiliate address if provided
@@ -89788,12 +89843,17 @@ class MayachainAMM {
89788
89843
  }
89789
89844
  // Validate approval if asset is an ERC20 token and fromAddress is provided
89790
89845
  if (isProtocolERC20Asset(fromAsset) && fromAddress) {
89791
- const approveErrors = yield this.isRouterApprovedToSpend({
89792
- asset: fromAsset,
89793
- address: fromAddress,
89794
- amount,
89795
- });
89796
- 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
+ }
89797
89857
  }
89798
89858
  if (streamingQuantity && streamingQuantity < 0) {
89799
89859
  errors.push('streaming quantity can not be lower than 0');
@@ -89909,7 +89969,7 @@ class MayachainAMM {
89909
89969
  return {
89910
89970
  memo: '',
89911
89971
  errors,
89912
- value: new CryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89972
+ value: new AssetCryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89913
89973
  allowed: false,
89914
89974
  };
89915
89975
  }
@@ -89922,7 +89982,7 @@ class MayachainAMM {
89922
89982
  return {
89923
89983
  memo: '',
89924
89984
  errors: ['message' in e ? e.message : `Unknown error: ${e}`],
89925
- value: new CryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89985
+ value: new AssetCryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89926
89986
  allowed: false,
89927
89987
  };
89928
89988
  }
@@ -89951,7 +90011,7 @@ class MayachainAMM {
89951
90011
  return {
89952
90012
  memo: '',
89953
90013
  errors,
89954
- value: new CryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
90014
+ value: new AssetCryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89955
90015
  allowed: false,
89956
90016
  };
89957
90017
  }
@@ -89964,7 +90024,7 @@ class MayachainAMM {
89964
90024
  return {
89965
90025
  memo: '',
89966
90026
  errors: ['message' in e ? e.message : `Unknown error: ${e}`],
89967
- value: new CryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
90027
+ value: new AssetCryptoAmount(baseAmount(0, xchainMayachain.CACAO_DECIMAL), xchainMayachain.AssetCacao),
89968
90028
  allowed: false,
89969
90029
  };
89970
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;
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.14",
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.21",
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": {