@shapeshiftoss/swapper 13.0.1 → 14.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.
Files changed (36) hide show
  1. package/dist/api.d.ts +6 -4
  2. package/dist/swappercli.js +3 -3
  3. package/dist/swappers/cow/cowApprovalNeeded/cowApprovalNeeded.js +1 -1
  4. package/dist/swappers/cow/cowApprove/cowApprove.js +3 -3
  5. package/dist/swappers/cow/cowBuildTrade/cowBuildTrade.js +4 -4
  6. package/dist/swappers/cow/cowExecuteTrade/cowExecuteTrade.js +1 -1
  7. package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +9 -7
  8. package/dist/swappers/osmosis/OsmosisSwapper.js +16 -16
  9. package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.js +5 -5
  10. package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +7 -7
  11. package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.js +1 -1
  12. package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.d.ts +1 -1
  13. package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.js +2 -2
  14. package/dist/swappers/thorchain/utils/cosmos/cosmosTxData.d.ts +1 -1
  15. package/dist/swappers/thorchain/utils/cosmos/cosmosTxData.js +4 -4
  16. package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.d.ts +2 -2
  17. package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.js +3 -3
  18. package/dist/swappers/thorchain/utils/ethereum/utils/getThorTxData.d.ts +1 -1
  19. package/dist/swappers/thorchain/utils/ethereum/utils/getThorTxData.js +3 -3
  20. package/dist/swappers/thorchain/utils/getLimit/getLimit.d.ts +2 -2
  21. package/dist/swappers/thorchain/utils/getLimit/getLimit.js +3 -3
  22. package/dist/swappers/thorchain/utils/getTradeRate/getTradeRate.d.ts +1 -1
  23. package/dist/swappers/thorchain/utils/getTradeRate/getTradeRate.js +6 -4
  24. package/dist/swappers/thorchain/utils/txFeeHelpers/btcTxFees/getBtcTxFees.d.ts +2 -2
  25. package/dist/swappers/thorchain/utils/txFeeHelpers/btcTxFees/getBtcTxFees.js +2 -2
  26. package/dist/swappers/utils/helpers/helpers.js +1 -1
  27. package/dist/swappers/utils/test-data/setupSwapQuote.d.ts +1 -1
  28. package/dist/swappers/utils/test-data/setupSwapQuote.js +5 -5
  29. package/dist/swappers/zrx/getZrxTradeQuote/getZrxTradeQuote.js +9 -7
  30. package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.d.ts +2 -2
  31. package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.js +2 -2
  32. package/dist/swappers/zrx/zrxApprovalNeeded/zrxApprovalNeeded.js +1 -1
  33. package/dist/swappers/zrx/zrxApprove/zrxApprove.js +1 -1
  34. package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +4 -4
  35. package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +1 -1
  36. package/package.json +1 -1
package/dist/api.d.ts CHANGED
@@ -77,7 +77,7 @@ export declare type SupportedSellAssetsInput = {
77
77
  declare type CommonTradeInput = {
78
78
  sellAsset: Asset;
79
79
  buyAsset: Asset;
80
- sellAmount: string;
80
+ sellAmountCryptoPrecision: string;
81
81
  sendMax: boolean;
82
82
  receiveAddress: string;
83
83
  bip44Params: BIP44Params;
@@ -105,8 +105,8 @@ export declare type BuildTradeInput = GetTradeQuoteInput & {
105
105
  wallet: HDWallet;
106
106
  };
107
107
  interface TradeBase<C extends ChainId> {
108
- buyAmount: string;
109
- sellAmount: string;
108
+ buyAmountCryptoPrecision: string;
109
+ sellAmountCryptoPrecision: string;
110
110
  feeData: QuoteFeeData<C>;
111
111
  rate: string;
112
112
  sources: SwapSource[];
@@ -116,8 +116,10 @@ interface TradeBase<C extends ChainId> {
116
116
  }
117
117
  export interface TradeQuote<C extends ChainId> extends TradeBase<C> {
118
118
  allowanceContract: string;
119
- minimum: string;
119
+ minimumCryptoHuman: string;
120
120
  maximum: string;
121
+ /** @deprecated Use sellAmountCryptoHuman instead */
122
+ minimum?: string;
121
123
  }
122
124
  export interface Trade<C extends ChainId> extends TradeBase<C> {
123
125
  receiveAddress: string;
@@ -143,7 +143,7 @@ const main = async () => {
143
143
  chainId: sellAsset.chainId,
144
144
  sellAsset,
145
145
  buyAsset,
146
- sellAmount: sellAmountBase,
146
+ sellAmountCryptoPrecision: sellAmountBase,
147
147
  sendMax: false,
148
148
  accountType: utxoAccountType || chain_adapters_1.bitcoin.ChainAdapter.defaultUtxoAccountType,
149
149
  bip44Params,
@@ -159,7 +159,7 @@ const main = async () => {
159
159
  console.warn('no quote returned');
160
160
  return;
161
161
  }
162
- const buyAmount = fromBaseUnit(quote.buyAmount || '0', buyAsset.precision);
162
+ const buyAmount = fromBaseUnit(quote.buyAmountCryptoPrecision || '0', buyAsset.precision);
163
163
  const answer = readline_sync_1.default.question(`Swap ${sellAmount} ${sellAsset.symbol} for ${buyAmount} ${buyAsset.symbol} on ${swapper.getType()}? (y/n): `);
164
164
  if (answer === 'y') {
165
165
  const trade = await swapper.buildTrade({
@@ -167,7 +167,7 @@ const main = async () => {
167
167
  wallet,
168
168
  buyAsset,
169
169
  sendMax: false,
170
- sellAmount: sellAmountBase,
170
+ sellAmountCryptoPrecision: sellAmountBase,
171
171
  sellAsset,
172
172
  receiveAddress: buyAssetReceiveAddr,
173
173
  accountType: utxoAccountType || chain_adapters_1.bitcoin.ChainAdapter.defaultUtxoAccountType,
@@ -27,7 +27,7 @@ async function cowApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
27
27
  });
28
28
  const allowanceOnChain = (0, bignumber_1.bnOrZero)(allowanceResult);
29
29
  return {
30
- approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
30
+ approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmountCryptoPrecision)),
31
31
  };
32
32
  }
33
33
  catch (e) {
@@ -10,7 +10,7 @@ async function cowApproveInfinite({ adapter, web3 }, { quote, wallet }) {
10
10
  const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
11
11
  quote: {
12
12
  ...quote,
13
- sellAmount: constants_1.MAX_ALLOWANCE,
13
+ sellAmountCryptoPrecision: constants_1.MAX_ALLOWANCE,
14
14
  },
15
15
  wallet,
16
16
  adapter,
@@ -31,11 +31,11 @@ async function cowApproveInfinite({ adapter, web3 }, { quote, wallet }) {
31
31
  exports.cowApproveInfinite = cowApproveInfinite;
32
32
  async function cowApproveAmount({ adapter, web3 }, { quote, wallet, amount }) {
33
33
  try {
34
- const approvalAmount = amount !== null && amount !== void 0 ? amount : quote.sellAmount;
34
+ const approvalAmount = amount !== null && amount !== void 0 ? amount : quote.sellAmountCryptoPrecision;
35
35
  const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
36
36
  quote: {
37
37
  ...quote,
38
- sellAmount: approvalAmount,
38
+ sellAmountCryptoPrecision: approvalAmount,
39
39
  },
40
40
  wallet,
41
41
  adapter,
@@ -12,7 +12,7 @@ const cowService_1 = require("../utils/cowService");
12
12
  const helpers_2 = require("../utils/helpers/helpers");
13
13
  async function cowBuildTrade(deps, input) {
14
14
  try {
15
- const { sellAsset, buyAsset, sellAmount, bip44Params, wallet } = input;
15
+ const { sellAsset, buyAsset, sellAmountCryptoPrecision, bip44Params, wallet } = input;
16
16
  const { adapter, web3 } = deps;
17
17
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
18
18
  const { assetReference: buyAssetErc20Address, chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
@@ -30,7 +30,7 @@ async function cowBuildTrade(deps, input) {
30
30
  }
31
31
  const buyToken = buyAsset.assetId !== caip_1.ethAssetId ? buyAssetErc20Address : constants_1.COW_SWAP_ETH_MARKER_ADDRESS;
32
32
  const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
33
- const normalizedSellAmount = (0, helpers_1.normalizeAmount)(sellAmount);
33
+ const normalizedSellAmount = (0, helpers_1.normalizeAmount)(sellAmountCryptoPrecision);
34
34
  /**
35
35
  * /v1/quote
36
36
  * params: {
@@ -87,8 +87,8 @@ async function cowBuildTrade(deps, input) {
87
87
  buyAssetTradeFeeUsd: '0',
88
88
  sellAssetTradeFeeUsd,
89
89
  },
90
- sellAmount: normalizedSellAmount,
91
- buyAmount: quote.buyAmount,
90
+ sellAmountCryptoPrecision: normalizedSellAmount,
91
+ buyAmountCryptoPrecision: quote.buyAmount,
92
92
  sources: constants_1.DEFAULT_SOURCE,
93
93
  buyAsset,
94
94
  sellAsset,
@@ -32,7 +32,7 @@ async function cowExecuteTrade({ apiUrl, adapter }, { trade, wallet }) {
32
32
  sellToken: sellAssetErc20Address,
33
33
  buyToken,
34
34
  sellAmount: sellAmountWithoutFee,
35
- buyAmount: trade.buyAmount,
35
+ buyAmount: trade.buyAmountCryptoPrecision,
36
36
  validTo: (0, helpers_1.getNowPlusThirtyMinutesTimestamp)(),
37
37
  appData: constants_1.DEFAULT_APP_DATA,
38
38
  feeAmount: feeAmountInSellToken,
@@ -17,7 +17,7 @@ const helpers_2 = require("../utils/helpers/helpers");
17
17
  async function getCowSwapTradeQuote(deps, input) {
18
18
  var _a, _b;
19
19
  try {
20
- const { sellAsset, buyAsset, sellAmount, bip44Params, receiveAddress } = input;
20
+ const { sellAsset, buyAsset, sellAmountCryptoPrecision, bip44Params, receiveAddress } = input;
21
21
  const { adapter, web3 } = deps;
22
22
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
23
23
  const { assetReference: buyAssetErc20Address, chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
@@ -37,7 +37,9 @@ async function getCowSwapTradeQuote(deps, input) {
37
37
  const { minimum, maximum } = await (0, getCowSwapMinMax_1.getCowSwapMinMax)(deps, sellAsset, buyAsset);
38
38
  const minQuoteSellAmount = (0, bignumber_1.bnOrZero)(minimum).times((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
39
39
  // making sure we do not have decimals for cowswap api (can happen at least from minQuoteSellAmount)
40
- const normalizedSellAmount = (0, helpers_1.normalizeIntegerAmount)((0, bignumber_1.bnOrZero)(sellAmount).lt(minQuoteSellAmount) ? minQuoteSellAmount : sellAmount);
40
+ const normalizedSellAmount = (0, helpers_1.normalizeIntegerAmount)((0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).lt(minQuoteSellAmount)
41
+ ? minQuoteSellAmount
42
+ : sellAmountCryptoPrecision);
41
43
  const apiInput = {
42
44
  sellToken: sellAssetErc20Address,
43
45
  buyToken,
@@ -88,12 +90,12 @@ async function getCowSwapTradeQuote(deps, input) {
88
90
  const feeData = feeDataOptions['fast'];
89
91
  // If original sellAmount is < minQuoteSellAmount, we don't want to replace it with normalizedSellAmount
90
92
  // The purpose of this was to get a quote from CowSwap even with small amounts
91
- const quoteSellAmount = (0, bignumber_1.bnOrZero)(sellAmount).lt(minQuoteSellAmount)
92
- ? sellAmount
93
+ const quoteSellAmount = (0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).lt(minQuoteSellAmount)
94
+ ? sellAmountCryptoPrecision
93
95
  : normalizedSellAmount;
94
96
  return {
95
97
  rate,
96
- minimum,
98
+ minimumCryptoHuman: minimum,
97
99
  maximum,
98
100
  feeData: {
99
101
  networkFee: '0',
@@ -107,8 +109,8 @@ async function getCowSwapTradeQuote(deps, input) {
107
109
  buyAssetTradeFeeUsd: '0',
108
110
  sellAssetTradeFeeUsd,
109
111
  },
110
- sellAmount: quoteSellAmount,
111
- buyAmount: quote.buyAmount,
112
+ sellAmountCryptoPrecision: quoteSellAmount,
113
+ buyAmountCryptoPrecision: quote.buyAmount,
112
114
  sources: constants_1.DEFAULT_SOURCE,
113
115
  allowanceContract: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
114
116
  buyAsset,
@@ -87,15 +87,15 @@ class OsmosisSwapper {
87
87
  return this.supportedAssetIds;
88
88
  }
89
89
  async buildTrade(args) {
90
- const { sellAsset, buyAsset, sellAmount, receiveAddress, bip44Params } = args;
91
- if (!sellAmount) {
92
- throw new api_1.SwapError('sellAmount is required', {
90
+ const { sellAsset, buyAsset, sellAmountCryptoPrecision, receiveAddress, bip44Params } = args;
91
+ if (!sellAmountCryptoPrecision) {
92
+ throw new api_1.SwapError('sellAmountCryptoPrecision is required', {
93
93
  code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
94
94
  });
95
95
  }
96
- const { buyAssetTradeFeeUsd, rate, buyAmount } = await (0, helpers_1.getRateInfo)(sellAsset.symbol, buyAsset.symbol, sellAmount !== '0' ? sellAmount : '1', this.deps.osmoUrl);
96
+ const { buyAssetTradeFeeUsd, rate, buyAmount } = await (0, helpers_1.getRateInfo)(sellAsset.symbol, buyAsset.symbol, sellAmountCryptoPrecision !== '0' ? sellAmountCryptoPrecision : '1', this.deps.osmoUrl);
97
97
  //convert amount to base
98
- const amountBaseSell = String((0, bignumber_1.bnOrZero)(sellAmount).dp(0));
98
+ const sellAmountCryptoBase = String((0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).dp(0));
99
99
  const osmosisAdapter = this.deps.adapterManager.get(caip_1.osmosisChainId);
100
100
  if (!osmosisAdapter)
101
101
  throw new api_1.SwapError('Failed to get Osmosis adapter', {
@@ -104,7 +104,7 @@ class OsmosisSwapper {
104
104
  const feeData = await osmosisAdapter.getFeeData({});
105
105
  const fee = feeData.fast.txFee;
106
106
  return {
107
- buyAmount,
107
+ buyAmountCryptoPrecision: buyAmount,
108
108
  buyAsset,
109
109
  feeData: {
110
110
  networkFee: fee,
@@ -113,20 +113,20 @@ class OsmosisSwapper {
113
113
  },
114
114
  rate,
115
115
  receiveAddress,
116
- sellAmount: amountBaseSell,
116
+ sellAmountCryptoPrecision: sellAmountCryptoBase,
117
117
  sellAsset,
118
118
  bip44Params,
119
119
  sources: [{ name: 'Osmosis', proportion: '100' }],
120
120
  };
121
121
  }
122
122
  async getTradeQuote(input) {
123
- const { bip44Params, sellAsset, buyAsset, sellAmount } = input;
124
- if (!sellAmount) {
123
+ const { bip44Params, sellAsset, buyAsset, sellAmountCryptoPrecision } = input;
124
+ if (!sellAmountCryptoPrecision) {
125
125
  throw new api_1.SwapError('sellAmount is required', {
126
126
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
127
127
  });
128
128
  }
129
- const { buyAssetTradeFeeUsd, rate, buyAmount } = await (0, helpers_1.getRateInfo)(sellAsset.symbol, buyAsset.symbol, sellAmount !== '0' ? sellAmount : '1', this.deps.osmoUrl);
129
+ const { buyAssetTradeFeeUsd, rate, buyAmount } = await (0, helpers_1.getRateInfo)(sellAsset.symbol, buyAsset.symbol, sellAmountCryptoPrecision !== '0' ? sellAmountCryptoPrecision : '1', this.deps.osmoUrl);
130
130
  const { minimum, maximum } = await this.getMinMax(input);
131
131
  const osmosisAdapter = this.deps.adapterManager.get(caip_1.osmosisChainId);
132
132
  if (!osmosisAdapter)
@@ -143,18 +143,18 @@ class OsmosisSwapper {
143
143
  buyAssetTradeFeeUsd,
144
144
  },
145
145
  maximum,
146
- minimum,
146
+ minimumCryptoHuman: minimum,
147
147
  bip44Params,
148
148
  rate,
149
149
  sellAsset,
150
- sellAmount,
151
- buyAmount,
150
+ sellAmountCryptoPrecision,
151
+ buyAmountCryptoPrecision: buyAmount,
152
152
  sources: constants_1.DEFAULT_SOURCE,
153
153
  allowanceContract: '',
154
154
  };
155
155
  }
156
156
  async executeTrade({ trade, wallet }) {
157
- const { sellAsset, buyAsset, sellAmount, bip44Params, receiveAddress } = trade;
157
+ const { sellAsset, buyAsset, sellAmountCryptoPrecision, bip44Params, receiveAddress } = trade;
158
158
  const isFromOsmo = sellAsset.assetId === caip_1.osmosisAssetId;
159
159
  const sellAssetDenom = helpers_1.symbolDenomMapping[sellAsset.symbol];
160
160
  const buyAssetDenom = helpers_1.symbolDenomMapping[buyAsset.symbol];
@@ -179,7 +179,7 @@ class OsmosisSwapper {
179
179
  const transfer = {
180
180
  sender: sellAddress,
181
181
  receiver: receiveAddress,
182
- amount: sellAmount,
182
+ amount: sellAmountCryptoPrecision,
183
183
  };
184
184
  const responseAccount = await cosmosAdapter.getAccount(sellAddress);
185
185
  const accountNumber = responseAccount.chainSpecific.accountNumber || '0';
@@ -211,7 +211,7 @@ class OsmosisSwapper {
211
211
  adapter: osmosisAdapter,
212
212
  buyAssetDenom,
213
213
  sellAssetDenom,
214
- sellAmount: ibcSellAmount !== null && ibcSellAmount !== void 0 ? ibcSellAmount : sellAmount,
214
+ sellAmount: ibcSellAmount !== null && ibcSellAmount !== void 0 ? ibcSellAmount : sellAmountCryptoPrecision,
215
215
  gas,
216
216
  wallet,
217
217
  });
@@ -12,7 +12,7 @@ const makeTradeTx_1 = require("../utils/ethereum/makeTradeTx");
12
12
  const buildTrade = async ({ deps, input, }) => {
13
13
  var _a, _b, _c, _d;
14
14
  try {
15
- const { buyAsset, receiveAddress: destinationAddress, sellAmount, sellAsset, bip44Params, slippage: slippageTolerance = constants_1.DEFAULT_SLIPPAGE, wallet, sendMax, } = input;
15
+ const { buyAsset, receiveAddress: destinationAddress, sellAmountCryptoPrecision, sellAsset, bip44Params, slippage: slippageTolerance = constants_1.DEFAULT_SLIPPAGE, wallet, sendMax, } = input;
16
16
  const quote = await (0, getTradeQuote_1.getThorTradeQuote)({ deps, input });
17
17
  const sellAdapter = deps.adapterManager.get(sellAsset.chainId);
18
18
  if (!sellAdapter)
@@ -30,7 +30,7 @@ const buildTrade = async ({ deps, input, }) => {
30
30
  sellAsset,
31
31
  buyAsset,
32
32
  adapter: sellAdapter,
33
- sellAmount,
33
+ sellAmountCryptoPrecision,
34
34
  destinationAddress,
35
35
  deps,
36
36
  gasPrice: (_b = (_a = quote.feeData.chainSpecific) === null || _a === void 0 ? void 0 : _a.gasPrice) !== null && _b !== void 0 ? _b : '0',
@@ -49,14 +49,14 @@ const buildTrade = async ({ deps, input, }) => {
49
49
  deps,
50
50
  sellAsset,
51
51
  buyAsset,
52
- sellAmount,
52
+ sellAmountCryptoPrecision,
53
53
  slippageTolerance,
54
54
  destinationAddress,
55
55
  xpub: input.xpub,
56
56
  buyAssetTradeFeeUsd: quote.feeData.buyAssetTradeFeeUsd,
57
57
  });
58
58
  const buildTxResponse = await sellAdapter.buildSendTransaction({
59
- value: sellAmount,
59
+ value: sellAmountCryptoPrecision,
60
60
  wallet,
61
61
  to: vault,
62
62
  bip44Params: input.bip44Params,
@@ -83,7 +83,7 @@ const buildTrade = async ({ deps, input, }) => {
83
83
  bip44Params,
84
84
  deps,
85
85
  sellAdapter: sellAdapter,
86
- sellAmount,
86
+ sellAmountCryptoPrecision,
87
87
  sellAsset,
88
88
  slippageTolerance,
89
89
  chainId: input.chainId,
@@ -17,7 +17,7 @@ const isRune_1 = require("../utils/isRune/isRune");
17
17
  const getBtcTxFees_1 = require("../utils/txFeeHelpers/btcTxFees/getBtcTxFees");
18
18
  const getEthTxFees_1 = require("../utils/txFeeHelpers/ethTxFees/getEthTxFees");
19
19
  const getThorTradeQuote = async ({ deps, input }) => {
20
- const { sellAsset, buyAsset, sellAmount: sellAmountCryptoPrecision, bip44Params, chainId, receiveAddress, sendMax, } = input;
20
+ const { sellAsset, buyAsset, sellAmountCryptoPrecision, bip44Params, chainId, receiveAddress, sendMax, } = input;
21
21
  if (!bip44Params) {
22
22
  throw new Error('bip44Params required in getThorTradeQuote');
23
23
  }
@@ -60,13 +60,13 @@ const getThorTradeQuote = async ({ deps, input }) => {
60
60
  const commonQuoteFields = {
61
61
  rate,
62
62
  maximum: constants_3.MAX_THORCHAIN_TRADE,
63
- sellAmount: sellAmountCryptoPrecision,
64
- buyAmount: buyAmountCryptoPrecision,
63
+ sellAmountCryptoPrecision,
64
+ buyAmountCryptoPrecision,
65
65
  sources: [{ name: 'thorchain', proportion: '1' }],
66
66
  buyAsset,
67
67
  sellAsset,
68
68
  bip44Params,
69
- minimum: minimumSellAssetAmountPaddedCryptoHuman,
69
+ minimumCryptoHuman: minimumSellAssetAmountPaddedCryptoHuman,
70
70
  };
71
71
  const { chainNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
72
72
  switch (chainNamespace) {
@@ -76,7 +76,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
76
76
  deps,
77
77
  sellAsset,
78
78
  buyAsset,
79
- sellAmount: sellAmountCryptoPrecision,
79
+ sellAmountCryptoPrecision,
80
80
  slippageTolerance: constants_1.DEFAULT_SLIPPAGE,
81
81
  destinationAddress: receiveAddress,
82
82
  buyAssetTradeFeeUsd: estimatedBuyAssetTradeFeeUsd,
@@ -98,14 +98,14 @@ const getThorTradeQuote = async ({ deps, input }) => {
98
98
  deps,
99
99
  sellAsset,
100
100
  buyAsset,
101
- sellAmount: sellAmountCryptoPrecision,
101
+ sellAmountCryptoPrecision,
102
102
  slippageTolerance: constants_1.DEFAULT_SLIPPAGE,
103
103
  destinationAddress: receiveAddress,
104
104
  xpub: input.xpub,
105
105
  buyAssetTradeFeeUsd: estimatedBuyAssetTradeFeeUsd,
106
106
  });
107
107
  const feeData = await (0, getBtcTxFees_1.getBtcTxFees)({
108
- sellAmount: sellAmountCryptoPrecision,
108
+ sellAmountCryptoPrecision,
109
109
  vault,
110
110
  opReturnData,
111
111
  pubkey,
@@ -47,7 +47,7 @@ const thorTradeApprovalNeeded = async ({ deps, input, }) => {
47
47
  details: { feeData: quote.feeData },
48
48
  });
49
49
  return {
50
- approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
50
+ approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmountCryptoPrecision)),
51
51
  };
52
52
  }
53
53
  catch (e) {
@@ -4,7 +4,7 @@ declare type GetBtcThorTxInfoArgs = {
4
4
  deps: ThorchainSwapperDeps;
5
5
  sellAsset: Asset;
6
6
  buyAsset: Asset;
7
- sellAmount: string;
7
+ sellAmountCryptoPrecision: string;
8
8
  slippageTolerance: string;
9
9
  destinationAddress: string;
10
10
  xpub: string;
@@ -5,7 +5,7 @@ const api_1 = require("../../../../../api");
5
5
  const getLimit_1 = require("../../getLimit/getLimit");
6
6
  const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
7
7
  const thorService_1 = require("../../thorService");
8
- const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, xpub, buyAssetTradeFeeUsd, }) => {
8
+ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoPrecision, slippageTolerance, destinationAddress, xpub, buyAssetTradeFeeUsd, }) => {
9
9
  try {
10
10
  const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.daemonUrl}/lcd/thorchain/inbound_addresses`);
11
11
  const sellAssetInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === sellAsset.symbol.toUpperCase());
@@ -18,7 +18,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
18
18
  const limit = await (0, getLimit_1.getLimit)({
19
19
  buyAssetId: buyAsset.assetId,
20
20
  destinationAddress,
21
- sellAmount,
21
+ sellAmountCryptoPrecision,
22
22
  sellAsset,
23
23
  buyAsset,
24
24
  slippageTolerance,
@@ -9,7 +9,7 @@ export declare const cosmosTxData: (input: {
9
9
  bip44Params: BIP44Params;
10
10
  destinationAddress: string;
11
11
  deps: ThorchainSwapperDeps;
12
- sellAmount: string;
12
+ sellAmountCryptoPrecision: string;
13
13
  sellAsset: Asset;
14
14
  buyAsset: Asset;
15
15
  slippageTolerance: string;
@@ -7,7 +7,7 @@ const getLimit_1 = require("../getLimit/getLimit");
7
7
  const makeSwapMemo_1 = require("../makeSwapMemo/makeSwapMemo");
8
8
  const thorService_1 = require("../thorService");
9
9
  const cosmosTxData = async (input) => {
10
- const { bip44Params, deps, destinationAddress, sellAmount, sellAsset, buyAsset, slippageTolerance, quote, wallet, sellAdapter, } = input;
10
+ const { bip44Params, deps, destinationAddress, sellAmountCryptoPrecision, sellAsset, buyAsset, slippageTolerance, quote, wallet, sellAdapter, } = input;
11
11
  const fromThorAsset = sellAsset.chainId == types_1.KnownChainIds.ThorchainMainnet;
12
12
  const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.daemonUrl}/lcd/thorchain/inbound_addresses`);
13
13
  const atomInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === 'GAIA');
@@ -21,7 +21,7 @@ const cosmosTxData = async (input) => {
21
21
  const limit = await (0, getLimit_1.getLimit)({
22
22
  buyAssetId: buyAsset.assetId,
23
23
  destinationAddress,
24
- sellAmount,
24
+ sellAmountCryptoPrecision,
25
25
  sellAsset,
26
26
  buyAsset,
27
27
  slippageTolerance,
@@ -36,7 +36,7 @@ const cosmosTxData = async (input) => {
36
36
  if (fromThorAsset) {
37
37
  const buildTxResponse = await sellAdapter.buildDepositTransaction({
38
38
  bip44Params,
39
- value: sellAmount,
39
+ value: sellAmountCryptoPrecision,
40
40
  wallet,
41
41
  memo,
42
42
  gas: quote.feeData.chainSpecific.estimatedGas,
@@ -52,7 +52,7 @@ const cosmosTxData = async (input) => {
52
52
  });
53
53
  const buildTxResponse = await sellAdapter.buildSendTransaction({
54
54
  bip44Params,
55
- value: sellAmount,
55
+ value: sellAmountCryptoPrecision,
56
56
  wallet,
57
57
  to: vault,
58
58
  memo,
@@ -3,10 +3,10 @@ import { ethereum } from '@shapeshiftoss/chain-adapters';
3
3
  import { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
4
4
  import { BIP44Params } from '@shapeshiftoss/types';
5
5
  import { ThorchainSwapperDeps } from '../../types';
6
- export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }: {
6
+ export declare const makeTradeTx: ({ wallet, bip44Params, sellAmountCryptoPrecision, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }: {
7
7
  wallet: HDWallet;
8
8
  bip44Params: BIP44Params;
9
- sellAmount: string;
9
+ sellAmountCryptoPrecision: string;
10
10
  buyAsset: Asset;
11
11
  sellAsset: Asset;
12
12
  destinationAddress: string;
@@ -5,7 +5,7 @@ const caip_1 = require("@shapeshiftoss/caip");
5
5
  const web3_utils_1 = require("web3-utils");
6
6
  const api_1 = require("../../../../api");
7
7
  const getThorTxData_1 = require("../ethereum/utils/getThorTxData");
8
- const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }) => {
8
+ const makeTradeTx = async ({ wallet, bip44Params, sellAmountCryptoPrecision, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }) => {
9
9
  try {
10
10
  const { assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
11
11
  const isErc20Trade = assetNamespace === 'erc20';
@@ -13,7 +13,7 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsse
13
13
  deps,
14
14
  sellAsset,
15
15
  buyAsset,
16
- sellAmount,
16
+ sellAmountCryptoPrecision,
17
17
  slippageTolerance,
18
18
  destinationAddress,
19
19
  buyAssetTradeFeeUsd,
@@ -31,7 +31,7 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsse
31
31
  maxFeePerGas,
32
32
  maxPriorityFeePerGas,
33
33
  }),
34
- value: isErc20Trade ? '0x0' : (0, web3_utils_1.numberToHex)(sellAmount),
34
+ value: isErc20Trade ? '0x0' : (0, web3_utils_1.numberToHex)(sellAmountCryptoPrecision),
35
35
  data,
36
36
  });
37
37
  }
@@ -4,7 +4,7 @@ declare type GetBtcThorTxInfoArgs = {
4
4
  deps: ThorchainSwapperDeps;
5
5
  sellAsset: Asset;
6
6
  buyAsset: Asset;
7
- sellAmount: string;
7
+ sellAmountCryptoPrecision: string;
8
8
  slippageTolerance: string;
9
9
  destinationAddress: string;
10
10
  buyAssetTradeFeeUsd: string;
@@ -7,7 +7,7 @@ const getLimit_1 = require("../../getLimit/getLimit");
7
7
  const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
8
8
  const thorService_1 = require("../../thorService");
9
9
  const routerCalldata_1 = require("../routerCalldata");
10
- const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, buyAssetTradeFeeUsd, }) => {
10
+ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoPrecision, slippageTolerance, destinationAddress, buyAssetTradeFeeUsd, }) => {
11
11
  try {
12
12
  const { assetReference, assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
13
13
  const isErc20Trade = assetNamespace === 'erc20';
@@ -23,7 +23,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
23
23
  const limit = await (0, getLimit_1.getLimit)({
24
24
  buyAssetId: buyAsset.assetId,
25
25
  destinationAddress,
26
- sellAmount,
26
+ sellAmountCryptoPrecision,
27
27
  sellAsset,
28
28
  buyAsset,
29
29
  slippageTolerance,
@@ -35,7 +35,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
35
35
  destinationAddress,
36
36
  limit,
37
37
  });
38
- const data = await (0, routerCalldata_1.deposit)(router, vault, isErc20Trade ? assetReference : '0x0000000000000000000000000000000000000000', sellAmount, memo);
38
+ const data = await (0, routerCalldata_1.deposit)(router, vault, isErc20Trade ? assetReference : '0x0000000000000000000000000000000000000000', sellAmountCryptoPrecision, memo);
39
39
  return {
40
40
  data,
41
41
  memo,
@@ -1,11 +1,11 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { ThorchainSwapperDeps } from '../../types';
3
- export declare const getLimit: ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, buyAssetTradeFeeUsd, }: {
3
+ export declare const getLimit: ({ sellAsset, buyAsset, sellAmountCryptoPrecision, deps, slippageTolerance, buyAssetTradeFeeUsd, }: {
4
4
  buyAssetId: string;
5
5
  destinationAddress: string;
6
6
  sellAsset: Asset;
7
7
  buyAsset: Asset;
8
- sellAmount: string;
8
+ sellAmountCryptoPrecision: string;
9
9
  deps: ThorchainSwapperDeps;
10
10
  slippageTolerance: string;
11
11
  buyAssetTradeFeeUsd: string;
@@ -6,10 +6,10 @@ const bignumber_1 = require("../../../utils/bignumber");
6
6
  const constants_1 = require("../constants");
7
7
  const getTradeRate_1 = require("../getTradeRate/getTradeRate");
8
8
  const getUsdRate_1 = require("../getUsdRate/getUsdRate");
9
- const getLimit = async ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, buyAssetTradeFeeUsd, }) => {
10
- const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmount, deps);
9
+ const getLimit = async ({ sellAsset, buyAsset, sellAmountCryptoPrecision, deps, slippageTolerance, buyAssetTradeFeeUsd, }) => {
10
+ const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmountCryptoPrecision, deps);
11
11
  const buyAssetUsdRate = await (0, getUsdRate_1.getUsdRate)({ deps, input: { assetId: buyAsset.assetId } });
12
- const expectedBuyAmountCryptoPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).times(tradeRate), sellAsset.precision), constants_1.THORCHAIN_FIXED_PRECISION);
12
+ const expectedBuyAmountCryptoPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).times(tradeRate), sellAsset.precision), constants_1.THORCHAIN_FIXED_PRECISION);
13
13
  const isValidSlippageRange = (0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1);
14
14
  if ((0, bignumber_1.bnOrZero)(expectedBuyAmountCryptoPrecision8).lt(0) || !isValidSlippageRange)
15
15
  throw new api_1.SwapError('[getThorTxInfo]: bad expected buy amount or bad slippage tolerance', {
@@ -1,4 +1,4 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { AssetId } from '@shapeshiftoss/caip';
3
3
  import { ThorchainSwapperDeps } from '../../types';
4
- export declare const getTradeRate: (sellAsset: Asset, buyAssetId: AssetId, sellAmount: string, deps: ThorchainSwapperDeps) => Promise<string>;
4
+ export declare const getTradeRate: (sellAsset: Asset, buyAssetId: AssetId, sellAmountCryptoPrecision: string, deps: ThorchainSwapperDeps) => Promise<string>;
@@ -32,9 +32,9 @@ const getDoubleSwapOutput = (input, inputPool, outputPool) => {
32
32
  // https://docs.thorchain.org/how-it-works/prices
33
33
  // TODO this does not support swaps between native "RUNE"
34
34
  // Rune swaps use a different calculation because its 1 hop between pools instead of 2
35
- const getTradeRate = async (sellAsset, buyAssetId, sellAmount, deps) => {
35
+ const getTradeRate = async (sellAsset, buyAssetId, sellAmountCryptoPrecision, deps) => {
36
36
  // we can't get a quote for a zero amount so use getPriceRatio between pools instead
37
- if ((0, bignumber_1.bnOrZero)(sellAmount).eq(0)) {
37
+ if ((0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).eq(0)) {
38
38
  return (0, getPriceRatio_1.getPriceRatio)(deps, {
39
39
  sellAssetId: sellAsset.assetId,
40
40
  buyAssetId,
@@ -74,9 +74,11 @@ const getTradeRate = async (sellAsset, buyAssetId, sellAmount, deps) => {
74
74
  });
75
75
  }
76
76
  // All thorchain pool amounts are base 8 regardless of token precision
77
- const sellBaseAmount = (0, bignumber_1.bn)((0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)(sellAmount, sellAsset.precision), THOR_PRECISION));
77
+ const sellBaseAmount = (0, bignumber_1.bn)((0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)(sellAmountCryptoPrecision, sellAsset.precision), THOR_PRECISION));
78
78
  const outputAmountBase8 = getDoubleSwapOutput(sellBaseAmount, sellPool, buyPool);
79
79
  const outputAmount = (0, bignumber_1.fromBaseUnit)(outputAmountBase8, THOR_PRECISION);
80
- return (0, bignumber_1.bn)(outputAmount).div((0, bignumber_1.fromBaseUnit)(sellAmount, sellAsset.precision)).toString();
80
+ return (0, bignumber_1.bn)(outputAmount)
81
+ .div((0, bignumber_1.fromBaseUnit)(sellAmountCryptoPrecision, sellAsset.precision))
82
+ .toString();
81
83
  };
82
84
  exports.getTradeRate = getTradeRate;
@@ -3,11 +3,11 @@ import { QuoteFeeData, UtxoSupportedChainIds } from '../../../../../api';
3
3
  declare type GetBtcTxFeesInput = {
4
4
  opReturnData: string;
5
5
  vault: string;
6
- sellAmount: string;
6
+ sellAmountCryptoPrecision: string;
7
7
  sellAdapter: UtxoBaseAdapter<UtxoSupportedChainIds>;
8
8
  pubkey: string;
9
9
  buyAssetTradeFeeUsd: string;
10
10
  sendMax: boolean;
11
11
  };
12
- export declare const getBtcTxFees: ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }: GetBtcTxFeesInput) => Promise<QuoteFeeData<UtxoSupportedChainIds>>;
12
+ export declare const getBtcTxFees: ({ opReturnData, vault, sellAmountCryptoPrecision, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }: GetBtcTxFeesInput) => Promise<QuoteFeeData<UtxoSupportedChainIds>>;
13
13
  export {};
@@ -4,11 +4,11 @@ exports.getBtcTxFees = void 0;
4
4
  const types_1 = require("@shapeshiftoss/types");
5
5
  const api_1 = require("../../../../../api");
6
6
  const bignumber_1 = require("../../../../utils/bignumber");
7
- const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }) => {
7
+ const getBtcTxFees = async ({ opReturnData, vault, sellAmountCryptoPrecision, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }) => {
8
8
  try {
9
9
  const feeDataOptions = await sellAdapter.getFeeData({
10
10
  to: vault,
11
- value: sellAmount,
11
+ value: sellAmountCryptoPrecision,
12
12
  chainSpecific: { pubkey, opReturnData },
13
13
  sendMax,
14
14
  });
@@ -54,7 +54,7 @@ const grantAllowance = async ({ quote, wallet, adapter, erc20Abi, web3, }) => {
54
54
  const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(quote.sellAsset.assetId);
55
55
  const erc20Contract = new web3.eth.Contract(erc20Abi, sellAssetErc20Address);
56
56
  const approveTx = erc20Contract.methods
57
- .approve(quote.allowanceContract, quote.sellAmount)
57
+ .approve(quote.allowanceContract, quote.sellAmountCryptoPrecision)
58
58
  .encodeABI();
59
59
  const { bip44Params } = quote;
60
60
  const { txToSign } = await adapter.buildSendTransaction({
@@ -12,7 +12,7 @@ export declare const setupBuildTrade: () => {
12
12
  buildTradeInput: {
13
13
  sellAsset: Asset;
14
14
  buyAsset: Asset;
15
- sellAmount: string;
15
+ sellAmountCryptoPrecision: string;
16
16
  sendMax: boolean;
17
17
  receiveAddress: string;
18
18
  bip44Params: import("@shapeshiftoss/types").BIP44Params;
@@ -7,13 +7,13 @@ const setupQuote = () => {
7
7
  const sellAsset = { ...assets_1.FOX };
8
8
  const buyAsset = { ...assets_1.WETH };
9
9
  const tradeQuote = {
10
- buyAmount: '',
11
- sellAmount: '1000000000000000000',
10
+ buyAmountCryptoPrecision: '',
11
+ sellAmountCryptoPrecision: '1000000000000000000',
12
12
  sellAsset,
13
13
  buyAsset,
14
14
  allowanceContract: 'allowanceContractAddress',
15
15
  bip44Params: { purpose: 44, coinType: 60, accountNumber: 0 },
16
- minimum: '0',
16
+ minimumCryptoHuman: '0',
17
17
  maximum: '999999999999',
18
18
  feeData: {
19
19
  chainSpecific: {},
@@ -26,7 +26,7 @@ const setupQuote = () => {
26
26
  };
27
27
  const quoteInput = {
28
28
  chainId: types_1.KnownChainIds.EthereumMainnet,
29
- sellAmount: '1000000000000000000',
29
+ sellAmountCryptoPrecision: '1000000000000000000',
30
30
  sellAsset,
31
31
  buyAsset,
32
32
  bip44Params: { purpose: 44, coinType: 60, accountNumber: 0 },
@@ -41,7 +41,7 @@ const setupBuildTrade = () => {
41
41
  const buyAsset = { ...assets_1.WETH };
42
42
  const buildTradeInput = {
43
43
  chainId: types_1.KnownChainIds.EthereumMainnet,
44
- sellAmount: '1000000000000000000',
44
+ sellAmountCryptoPrecision: '1000000000000000000',
45
45
  buyAsset,
46
46
  sendMax: false,
47
47
  bip44Params: { purpose: 44, coinType: 60, accountNumber: 0 },
@@ -12,7 +12,7 @@ const helpers_2 = require("../utils/helpers/helpers");
12
12
  const zrxService_1 = require("../utils/zrxService");
13
13
  async function getZrxTradeQuote(input) {
14
14
  try {
15
- const { sellAsset, buyAsset, sellAmount, bip44Params } = input;
15
+ const { sellAsset, buyAsset, sellAmountCryptoPrecision, bip44Params } = input;
16
16
  if (buyAsset.chainId !== input.chainId || sellAsset.chainId !== input.chainId) {
17
17
  throw new api_1.SwapError('[getZrxTradeQuote] - Both assets need to be on the same supported EVM chain to use Zrx', {
18
18
  code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
@@ -21,12 +21,14 @@ async function getZrxTradeQuote(input) {
21
21
  }
22
22
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
23
23
  const { assetReference: buyAssetErc20Address, assetNamespace: buyAssetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
24
- const useSellAmount = !!sellAmount;
24
+ const useSellAmount = !!sellAmountCryptoPrecision;
25
25
  const buyToken = buyAssetNamespace === 'erc20' ? buyAssetErc20Address : buyAsset.symbol;
26
26
  const sellToken = sellAssetNamespace === 'erc20' ? sellAssetErc20Address : sellAsset.symbol;
27
27
  const { minimum, maximum } = await (0, getZrxMinMax_1.getZrxMinMax)(sellAsset, buyAsset);
28
- const minQuoteSellAmount = (0, bignumber_1.bnOrZero)(minimum).times((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
29
- const normalizedSellAmount = (0, helpers_1.normalizeAmount)((0, bignumber_1.bnOrZero)(sellAmount).eq(0) ? minQuoteSellAmount : sellAmount);
28
+ const minQuotesellAmountCryptoPrecision = (0, bignumber_1.bnOrZero)(minimum).times((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
29
+ const normalizedSellAmount = (0, helpers_1.normalizeAmount)((0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).eq(0)
30
+ ? minQuotesellAmountCryptoPrecision
31
+ : sellAmountCryptoPrecision);
30
32
  const baseUrl = (0, helpers_2.baseUrlFromChainId)(buyAsset.chainId);
31
33
  const zrxService = (0, zrxService_1.zrxServiceFactory)(baseUrl);
32
34
  /**
@@ -55,7 +57,7 @@ async function getZrxTradeQuote(input) {
55
57
  (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(gasPrice)).toString();
56
58
  const tradeQuote = {
57
59
  rate,
58
- minimum,
60
+ minimumCryptoHuman: minimum,
59
61
  maximum,
60
62
  feeData: {
61
63
  chainSpecific: {
@@ -67,8 +69,8 @@ async function getZrxTradeQuote(input) {
67
69
  buyAssetTradeFeeUsd: '0',
68
70
  sellAssetTradeFeeUsd: '0',
69
71
  },
70
- sellAmount: sellAmountResponse,
71
- buyAmount,
72
+ sellAmountCryptoPrecision: sellAmountResponse,
73
+ buyAmountCryptoPrecision: buyAmount,
72
74
  sources: (sources === null || sources === void 0 ? void 0 : sources.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
73
75
  allowanceContract: allowanceTarget,
74
76
  buyAsset,
@@ -7,13 +7,13 @@ export declare const setupZrxTradeQuoteResponse: () => {
7
7
  };
8
8
  export declare const setupExecuteTrade: () => {
9
9
  executeTradeInput: {
10
- sellAmount: string;
10
+ sellAmountCryptoPrecision: string;
11
11
  allowanceTarget: string;
12
12
  price: string;
13
13
  to: string;
14
14
  gas: string;
15
15
  gasPrice: string;
16
- buyAmount: string;
16
+ buyAmountCryptoPrecision: string;
17
17
  buyAsset: Asset;
18
18
  sellAsset: Asset;
19
19
  sendMax: boolean;
@@ -23,13 +23,13 @@ const setupExecuteTrade = () => {
23
23
  const sellAsset = { ...assets_1.FOX };
24
24
  const buyAsset = { ...assets_1.WETH };
25
25
  const executeTradeInput = {
26
- sellAmount: '1000000000000000000',
26
+ sellAmountCryptoPrecision: '1000000000000000000',
27
27
  allowanceTarget: 'allowanceTargetAddress',
28
28
  price: '1',
29
29
  to: '0x123',
30
30
  gas: '1235',
31
31
  gasPrice: '1236',
32
- buyAmount: '',
32
+ buyAmountCryptoPrecision: '',
33
33
  buyAsset,
34
34
  sellAsset,
35
35
  sendMax: false,
@@ -42,7 +42,7 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
42
42
  details: { feeData: quote.feeData },
43
43
  });
44
44
  return {
45
- approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
45
+ approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmountCryptoPrecision)),
46
46
  };
47
47
  }
48
48
  catch (e) {
@@ -31,7 +31,7 @@ const grantAllowanceForAmount = async ({ adapter, web3 }, { quote, wallet }, app
31
31
  async function zrxApproveAmount(deps, args) {
32
32
  var _a;
33
33
  try {
34
- const sellAmount = args.quote.sellAmount;
34
+ const sellAmount = args.quote.sellAmountCryptoPrecision;
35
35
  // If no amount is specified we use the quotes sell amount
36
36
  const approvalAmount = (_a = args.amount) !== null && _a !== void 0 ? _a : sellAmount;
37
37
  return grantAllowanceForAmount(deps, args, approvalAmount);
@@ -37,7 +37,7 @@ const helpers_2 = require("../utils/helpers/helpers");
37
37
  const zrxService_1 = require("../utils/zrxService");
38
38
  async function zrxBuildTrade({ adapter, web3 }, input) {
39
39
  var _a;
40
- const { sellAsset, buyAsset, sellAmount, slippage, bip44Params, receiveAddress } = input;
40
+ const { sellAsset, buyAsset, sellAmountCryptoPrecision, slippage, bip44Params, receiveAddress } = input;
41
41
  try {
42
42
  const { assetReference: buyAssetErc20Address, assetNamespace: buyAssetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
43
43
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
@@ -82,7 +82,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
82
82
  params: {
83
83
  buyToken,
84
84
  sellToken,
85
- sellAmount: (0, helpers_1.normalizeAmount)(sellAmount),
85
+ sellAmount: (0, helpers_1.normalizeAmount)(sellAmountCryptoPrecision),
86
86
  takerAddress: receiveAddress,
87
87
  slippagePercentage,
88
88
  skipValidation: false,
@@ -122,8 +122,8 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
122
122
  sellAssetTradeFeeUsd: '0',
123
123
  },
124
124
  txData: data.data,
125
- sellAmount: data.sellAmount,
126
- buyAmount: data.buyAmount,
125
+ sellAmountCryptoPrecision: data.sellAmount,
126
+ buyAmountCryptoPrecision: data.buyAmount,
127
127
  sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
128
128
  };
129
129
  return trade;
@@ -9,7 +9,7 @@ async function zrxExecuteTrade({ adapter }, { trade, wallet }) {
9
9
  const { bip44Params, sellAsset } = trade;
10
10
  try {
11
11
  // value is 0 for erc20s
12
- const value = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? trade.sellAmount : '0';
12
+ const value = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? trade.sellAmountCryptoPrecision : '0';
13
13
  const buildTxResponse = await adapter.buildSendTransaction({
14
14
  value,
15
15
  wallet,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "13.0.1",
3
+ "version": "14.0.0",
4
4
  "description": "An interface and implementations to trade coins via various protocols",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",