@shapeshiftoss/swapper 14.7.2 → 15.0.1

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 (42) hide show
  1. package/dist/api.d.ts +8 -8
  2. package/dist/swappercli.js +9 -11
  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 +15 -16
  6. package/dist/swappers/cow/cowExecuteTrade/cowExecuteTrade.js +2 -2
  7. package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +13 -15
  8. package/dist/swappers/cow/types.d.ts +2 -2
  9. package/dist/swappers/cow/utils/helpers/helpers.js +4 -4
  10. package/dist/swappers/cow/utils.js +1 -1
  11. package/dist/swappers/osmosis/OsmosisSwapper.js +16 -16
  12. package/dist/swappers/osmosis/utils/helpers.d.ts +1 -1
  13. package/dist/swappers/osmosis/utils/helpers.js +4 -4
  14. package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.js +6 -6
  15. package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +9 -9
  16. package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.js +2 -2
  17. package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.d.ts +1 -1
  18. package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.js +2 -2
  19. package/dist/swappers/thorchain/utils/cosmos/getCosmosTxData.d.ts +1 -1
  20. package/dist/swappers/thorchain/utils/cosmos/getCosmosTxData.js +6 -6
  21. package/dist/swappers/thorchain/utils/evm/makeTradeTx.d.ts +4 -4
  22. package/dist/swappers/thorchain/utils/evm/makeTradeTx.js +6 -4
  23. package/dist/swappers/thorchain/utils/evm/utils/getThorTxData.d.ts +1 -1
  24. package/dist/swappers/thorchain/utils/evm/utils/getThorTxData.js +3 -3
  25. package/dist/swappers/thorchain/utils/getLimit/getLimit.d.ts +2 -2
  26. package/dist/swappers/thorchain/utils/getLimit/getLimit.js +3 -3
  27. package/dist/swappers/thorchain/utils/test-data/setupThorswapDeps.js +1 -1
  28. package/dist/swappers/thorchain/utils/txFeeHelpers/evmTxFees/getEvmTxFees.js +3 -3
  29. package/dist/swappers/thorchain/utils/txFeeHelpers/utxoTxFees/getUtxoTxFees.d.ts +2 -2
  30. package/dist/swappers/thorchain/utils/txFeeHelpers/utxoTxFees/getUtxoTxFees.js +3 -3
  31. package/dist/swappers/utils/helpers/helpers.d.ts +2 -2
  32. package/dist/swappers/utils/helpers/helpers.js +4 -4
  33. package/dist/swappers/utils/test-data/setupSwapQuote.d.ts +1 -1
  34. package/dist/swappers/utils/test-data/setupSwapQuote.js +5 -5
  35. package/dist/swappers/zrx/getZrxTradeQuote/getZrxTradeQuote.js +15 -15
  36. package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.d.ts +3 -3
  37. package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.js +3 -3
  38. package/dist/swappers/zrx/zrxApprovalNeeded/zrxApprovalNeeded.js +2 -2
  39. package/dist/swappers/zrx/zrxApprove/zrxApprove.js +1 -1
  40. package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +19 -18
  41. package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +4 -2
  42. package/package.json +3 -3
@@ -5,7 +5,7 @@ const api_1 = require("../../../../../api");
5
5
  const getInboundAddressDataForChain_1 = require("../../getInboundAddressDataForChain");
6
6
  const getLimit_1 = require("../../getLimit/getLimit");
7
7
  const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
8
- const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoPrecision, slippageTolerance, destinationAddress, xpub, buyAssetTradeFeeUsd, }) => {
8
+ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoBaseUnit, slippageTolerance, destinationAddress, xpub, buyAssetTradeFeeUsd, }) => {
9
9
  try {
10
10
  const inboundAddress = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(deps.daemonUrl, sellAsset.assetId);
11
11
  const vault = inboundAddress === null || inboundAddress === void 0 ? void 0 : inboundAddress.address;
@@ -16,7 +16,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoPrecis
16
16
  });
17
17
  const limit = await (0, getLimit_1.getLimit)({
18
18
  buyAssetId: buyAsset.assetId,
19
- sellAmountCryptoPrecision,
19
+ sellAmountCryptoBaseUnit,
20
20
  sellAsset,
21
21
  slippageTolerance,
22
22
  deps,
@@ -9,7 +9,7 @@ declare type GetCosmosTxDataInput = {
9
9
  bip44Params: BIP44Params;
10
10
  destinationAddress: string;
11
11
  deps: ThorchainSwapperDeps;
12
- sellAmountCryptoPrecision: string;
12
+ sellAmountCryptoBaseUnit: string;
13
13
  sellAsset: Asset;
14
14
  buyAsset: Asset;
15
15
  slippageTolerance: string;
@@ -8,7 +8,7 @@ const getInboundAddressDataForChain_1 = require("../getInboundAddressDataForChai
8
8
  const getLimit_1 = require("../getLimit/getLimit");
9
9
  const makeSwapMemo_1 = require("../makeSwapMemo/makeSwapMemo");
10
10
  const getCosmosTxData = async (input) => {
11
- const { bip44Params, deps, destinationAddress, sellAmountCryptoPrecision, sellAsset, buyAsset, slippageTolerance, quote, wallet, sellAdapter, } = input;
11
+ const { bip44Params, deps, destinationAddress, sellAmountCryptoBaseUnit, sellAsset, buyAsset, slippageTolerance, quote, wallet, sellAdapter, } = input;
12
12
  const fromThorAsset = sellAsset.chainId == types_1.KnownChainIds.ThorchainMainnet;
13
13
  const gaiaAddressData = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(deps.daemonUrl, caip_1.cosmosAssetId);
14
14
  const vault = gaiaAddressData === null || gaiaAddressData === void 0 ? void 0 : gaiaAddressData.address;
@@ -20,7 +20,7 @@ const getCosmosTxData = async (input) => {
20
20
  });
21
21
  const limit = await (0, getLimit_1.getLimit)({
22
22
  buyAssetId: buyAsset.assetId,
23
- sellAmountCryptoPrecision,
23
+ sellAmountCryptoBaseUnit,
24
24
  sellAsset,
25
25
  slippageTolerance,
26
26
  deps,
@@ -36,12 +36,12 @@ const getCosmosTxData = async (input) => {
36
36
  case fromThorAsset:
37
37
  return await sellAdapter.buildDepositTransaction({
38
38
  bip44Params,
39
- value: sellAmountCryptoPrecision,
39
+ value: sellAmountCryptoBaseUnit,
40
40
  wallet,
41
41
  memo,
42
42
  chainSpecific: {
43
43
  gas: quote.feeData.chainSpecific.estimatedGas,
44
- fee: quote.feeData.networkFee,
44
+ fee: quote.feeData.networkFeeCryptoBaseUnit,
45
45
  },
46
46
  });
47
47
  default:
@@ -53,14 +53,14 @@ const getCosmosTxData = async (input) => {
53
53
  });
54
54
  return await sellAdapter.buildSendTransaction({
55
55
  bip44Params,
56
- value: sellAmountCryptoPrecision,
56
+ value: sellAmountCryptoBaseUnit,
57
57
  wallet,
58
58
  to: vault,
59
59
  memo,
60
60
  chainSpecific: {
61
61
  gas: quote.feeData.chainSpecific
62
62
  .estimatedGas,
63
- fee: quote.feeData.networkFee,
63
+ fee: quote.feeData.networkFeeCryptoBaseUnit,
64
64
  },
65
65
  });
66
66
  }
@@ -6,7 +6,7 @@ import type { ThorchainSwapperDeps } from '../../types';
6
6
  declare type MakeTradeTxArgs = {
7
7
  wallet: HDWallet;
8
8
  bip44Params: BIP44Params;
9
- sellAmountCryptoPrecision: string;
9
+ sellAmountCryptoBaseUnit: string;
10
10
  buyAsset: Asset;
11
11
  sellAsset: Asset;
12
12
  destinationAddress: string;
@@ -16,15 +16,15 @@ declare type MakeTradeTxArgs = {
16
16
  gasLimit: string;
17
17
  buyAssetTradeFeeUsd: string;
18
18
  } & ({
19
- gasPrice: string;
19
+ gasPriceCryptoBaseUnit: string;
20
20
  maxFeePerGas?: never;
21
21
  maxPriorityFeePerGas?: never;
22
22
  } | {
23
- gasPrice?: never;
23
+ gasPriceCryptoBaseUnit?: never;
24
24
  maxFeePerGas: string;
25
25
  maxPriorityFeePerGas: string;
26
26
  });
27
- export declare const makeTradeTx: ({ wallet, bip44Params, sellAmountCryptoPrecision, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }: MakeTradeTxArgs) => Promise<{
27
+ export declare const makeTradeTx: ({ wallet, bip44Params, sellAmountCryptoBaseUnit, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPriceCryptoBaseUnit, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }: MakeTradeTxArgs) => Promise<{
28
28
  txToSign: ETHSignTx;
29
29
  }>;
30
30
  export {};
@@ -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("./utils/getThorTxData");
8
- const makeTradeTx = async ({ wallet, bip44Params, sellAmountCryptoPrecision, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }) => {
8
+ const makeTradeTx = async ({ wallet, bip44Params, sellAmountCryptoBaseUnit, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPriceCryptoBaseUnit, 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, sellAmountCryptoPrecision, buy
13
13
  deps,
14
14
  sellAsset,
15
15
  buyAsset,
16
- sellAmountCryptoPrecision,
16
+ sellAmountCryptoBaseUnit,
17
17
  slippageTolerance,
18
18
  destinationAddress,
19
19
  buyAssetTradeFeeUsd,
@@ -23,8 +23,10 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmountCryptoPrecision, buy
23
23
  bip44Params,
24
24
  to: router,
25
25
  gasLimit,
26
- ...(gasPrice !== undefined ? { gasPrice } : { maxFeePerGas, maxPriorityFeePerGas }),
27
- value: isErc20Trade ? '0x0' : (0, web3_utils_1.numberToHex)(sellAmountCryptoPrecision),
26
+ ...(gasPriceCryptoBaseUnit !== undefined
27
+ ? { gasPrice: gasPriceCryptoBaseUnit }
28
+ : { maxFeePerGas, maxPriorityFeePerGas }),
29
+ value: isErc20Trade ? '0x0' : (0, web3_utils_1.numberToHex)(sellAmountCryptoBaseUnit),
28
30
  data,
29
31
  });
30
32
  }
@@ -4,7 +4,7 @@ declare type GetBtcThorTxInfoArgs = {
4
4
  deps: ThorchainSwapperDeps;
5
5
  sellAsset: Asset;
6
6
  buyAsset: Asset;
7
- sellAmountCryptoPrecision: string;
7
+ sellAmountCryptoBaseUnit: string;
8
8
  slippageTolerance: string;
9
9
  destinationAddress: string;
10
10
  buyAssetTradeFeeUsd: string;
@@ -7,7 +7,7 @@ const getInboundAddressDataForChain_1 = require("../../getInboundAddressDataForC
7
7
  const getLimit_1 = require("../../getLimit/getLimit");
8
8
  const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
9
9
  const routerCalldata_1 = require("../routerCalldata");
10
- const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoPrecision, slippageTolerance, destinationAddress, buyAssetTradeFeeUsd, }) => {
10
+ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoBaseUnit, slippageTolerance, destinationAddress, buyAssetTradeFeeUsd, }) => {
11
11
  try {
12
12
  const { assetReference, assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
13
13
  const isErc20Trade = assetNamespace === 'erc20';
@@ -21,7 +21,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoPrecis
21
21
  });
22
22
  const limit = await (0, getLimit_1.getLimit)({
23
23
  buyAssetId: buyAsset.assetId,
24
- sellAmountCryptoPrecision,
24
+ sellAmountCryptoBaseUnit,
25
25
  sellAsset,
26
26
  slippageTolerance,
27
27
  deps,
@@ -32,7 +32,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmountCryptoPrecis
32
32
  destinationAddress,
33
33
  limit,
34
34
  });
35
- const data = await (0, routerCalldata_1.deposit)(router, vault, isErc20Trade ? assetReference : '0x0000000000000000000000000000000000000000', sellAmountCryptoPrecision, memo);
35
+ const data = await (0, routerCalldata_1.deposit)(router, vault, isErc20Trade ? assetReference : '0x0000000000000000000000000000000000000000', sellAmountCryptoBaseUnit, memo);
36
36
  return { data, router };
37
37
  }
38
38
  catch (e) {
@@ -3,9 +3,9 @@ import { ThorchainSwapperDeps } from '../../types';
3
3
  export declare type GetLimitArgs = {
4
4
  buyAssetId: string;
5
5
  sellAsset: Asset;
6
- sellAmountCryptoPrecision: string;
6
+ sellAmountCryptoBaseUnit: string;
7
7
  deps: ThorchainSwapperDeps;
8
8
  slippageTolerance: string;
9
9
  buyAssetTradeFeeUsd: string;
10
10
  };
11
- export declare const getLimit: ({ sellAsset, buyAssetId, sellAmountCryptoPrecision, deps, slippageTolerance, buyAssetTradeFeeUsd, }: GetLimitArgs) => Promise<string>;
11
+ export declare const getLimit: ({ sellAsset, buyAssetId, sellAmountCryptoBaseUnit, deps, slippageTolerance, buyAssetTradeFeeUsd, }: GetLimitArgs) => Promise<string>;
@@ -15,9 +15,9 @@ const getInboundAddressDataForChain_1 = require("../getInboundAddressDataForChai
15
15
  const getTradeRate_1 = require("../getTradeRate/getTradeRate");
16
16
  const getUsdRate_1 = require("../getUsdRate/getUsdRate");
17
17
  const isRune_1 = require("../isRune/isRune");
18
- const getLimit = async ({ sellAsset, buyAssetId, sellAmountCryptoPrecision, deps, slippageTolerance, buyAssetTradeFeeUsd, }) => {
18
+ const getLimit = async ({ sellAsset, buyAssetId, sellAmountCryptoBaseUnit, deps, slippageTolerance, buyAssetTradeFeeUsd, }) => {
19
19
  var _a, _b;
20
- const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAssetId, sellAmountCryptoPrecision, deps);
20
+ const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAssetId, sellAmountCryptoBaseUnit, deps);
21
21
  const sellAssetChainFeeAssetId = (_a = deps.adapterManager.get(sellAsset.chainId)) === null || _a === void 0 ? void 0 : _a.getFeeAssetId();
22
22
  const buyAssetChainFeeAssetId = (_b = deps.adapterManager
23
23
  .get((0, caip_1.fromAssetId)(buyAssetId).chainId)) === null || _b === void 0 ? void 0 : _b.getFeeAssetId();
@@ -29,7 +29,7 @@ const getLimit = async ({ sellAsset, buyAssetId, sellAmountCryptoPrecision, deps
29
29
  }
30
30
  const sellFeeAssetUsdRate = await (0, getUsdRate_1.getUsdRate)(deps.daemonUrl, sellAssetChainFeeAssetId);
31
31
  const buyAssetUsdRate = await (0, getUsdRate_1.getUsdRate)(deps.daemonUrl, buyAssetId);
32
- const expectedBuyAmountCryptoPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).times(tradeRate), sellAsset.precision), constants_3.THORCHAIN_FIXED_PRECISION);
32
+ const expectedBuyAmountCryptoPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmountCryptoBaseUnit).times(tradeRate), sellAsset.precision), constants_3.THORCHAIN_FIXED_PRECISION);
33
33
  const isValidSlippageRange = (0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1);
34
34
  if ((0, bignumber_1.bnOrZero)(expectedBuyAmountCryptoPrecision8).lt(0) || !isValidSlippageRange)
35
35
  throw new api_1.SwapError('[getLimit]: bad expected buy amount or bad slippage tolerance', {
@@ -13,7 +13,7 @@ const setupThorswapDeps = () => {
13
13
  const feeData = {
14
14
  fast: {
15
15
  txFee: '1',
16
- chainSpecific: { approvalFee: '1', gasLimit: '1', gasPrice: '1' },
16
+ chainSpecific: { approvalFeeCryptoBaseUnit: '1', gasLimit: '1', gasPrice: '1' },
17
17
  tradeFee: '2',
18
18
  },
19
19
  };
@@ -24,11 +24,11 @@ const getEvmTxFees = async ({ adapter, sellAssetReference, buyAssetTradeFeeUsd,
24
24
  };
25
25
  const feeData = feeDataOptions['fast'];
26
26
  return {
27
- networkFee: feeData.txFee,
27
+ networkFeeCryptoBaseUnit: feeData.txFee,
28
28
  chainSpecific: {
29
29
  estimatedGas: feeData.chainSpecific.gasLimit,
30
- gasPrice: feeData.chainSpecific.gasPrice,
31
- approvalFee: sellAssetReference &&
30
+ gasPriceCryptoBaseUnit: feeData.chainSpecific.gasPrice,
31
+ approvalFeeCryptoBaseUnit: sellAssetReference &&
32
32
  (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT)
33
33
  .multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
34
34
  .toString(),
@@ -3,11 +3,11 @@ import { QuoteFeeData, UtxoSupportedChainIds } from '../../../../../api';
3
3
  declare type GetUtxoTxFeesInput = {
4
4
  opReturnData: string;
5
5
  vault: string;
6
- sellAmountCryptoPrecision: string;
6
+ sellAmountCryptoBaseUnit: string;
7
7
  sellAdapter: UtxoBaseAdapter<UtxoSupportedChainIds>;
8
8
  pubkey: string;
9
9
  buyAssetTradeFeeUsd: string;
10
10
  sendMax: boolean;
11
11
  };
12
- export declare const getUtxoTxFees: ({ opReturnData, vault, sellAmountCryptoPrecision, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }: GetUtxoTxFeesInput) => Promise<QuoteFeeData<UtxoSupportedChainIds>>;
12
+ export declare const getUtxoTxFees: ({ opReturnData, vault, sellAmountCryptoBaseUnit, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }: GetUtxoTxFeesInput) => Promise<QuoteFeeData<UtxoSupportedChainIds>>;
13
13
  export {};
@@ -4,11 +4,11 @@ exports.getUtxoTxFees = 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 getUtxoTxFees = async ({ opReturnData, vault, sellAmountCryptoPrecision, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }) => {
7
+ const getUtxoTxFees = async ({ opReturnData, vault, sellAmountCryptoBaseUnit, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }) => {
8
8
  try {
9
9
  const feeDataOptions = await sellAdapter.getFeeData({
10
10
  to: vault,
11
- value: sellAmountCryptoPrecision,
11
+ value: sellAmountCryptoBaseUnit,
12
12
  chainSpecific: { pubkey, opReturnData },
13
13
  sendMax,
14
14
  });
@@ -23,7 +23,7 @@ const getUtxoTxFees = async ({ opReturnData, vault, sellAmountCryptoPrecision, s
23
23
  const networkFee = feeMultiplier.times(feeData.txFee).dp(0).toString();
24
24
  const satsPerByte = feeMultiplier.times(feeData.chainSpecific.satoshiPerByte).dp(0).toString();
25
25
  return {
26
- networkFee,
26
+ networkFeeCryptoBaseUnit: networkFee,
27
27
  buyAssetTradeFeeUsd,
28
28
  sellAssetTradeFeeUsd: '0',
29
29
  chainSpecific: {
@@ -9,7 +9,7 @@ export declare type IsApprovalRequiredArgs = {
9
9
  receiveAddress: string;
10
10
  allowanceContract: string;
11
11
  sellAsset: Asset;
12
- sellAmount: string;
12
+ sellAmountExcludeFeeCryptoBaseUnit: string;
13
13
  web3: Web3;
14
14
  erc20AllowanceAbi: AbiItem[];
15
15
  };
@@ -33,7 +33,7 @@ declare type GrantAllowanceArgs<T extends EvmSupportedChainIds> = {
33
33
  web3: Web3;
34
34
  };
35
35
  export declare const getERC20Allowance: ({ erc20AllowanceAbi, web3, sellAssetErc20Address, ownerAddress, spenderAddress, }: GetERC20AllowanceArgs) => Promise<any>;
36
- export declare const isApprovalRequired: ({ adapter, receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi, }: IsApprovalRequiredArgs) => Promise<boolean>;
36
+ export declare const isApprovalRequired: ({ adapter, receiveAddress, allowanceContract, sellAsset, sellAmountExcludeFeeCryptoBaseUnit, web3, erc20AllowanceAbi, }: IsApprovalRequiredArgs) => Promise<boolean>;
37
37
  export declare const grantAllowance: <T extends EvmSupportedChainIds>({ quote, wallet, adapter, erc20Abi, web3, }: GrantAllowanceArgs<T>) => Promise<string>;
38
38
  /**
39
39
  * This function keeps 17 significant digits, so even if we try to trade 1 Billion of an
@@ -12,7 +12,7 @@ const getERC20Allowance = async ({ erc20AllowanceAbi, web3, sellAssetErc20Addres
12
12
  return erc20Contract.methods.allowance(ownerAddress, spenderAddress).call();
13
13
  };
14
14
  exports.getERC20Allowance = getERC20Allowance;
15
- const isApprovalRequired = async ({ adapter, receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi, }) => {
15
+ const isApprovalRequired = async ({ adapter, receiveAddress, allowanceContract, sellAsset, sellAmountExcludeFeeCryptoBaseUnit, web3, erc20AllowanceAbi, }) => {
16
16
  try {
17
17
  if (sellAsset.assetId === adapter.getFeeAssetId()) {
18
18
  return false;
@@ -35,7 +35,7 @@ const isApprovalRequired = async ({ adapter, receiveAddress, allowanceContract,
35
35
  }
36
36
  if ((0, bignumber_1.bn)(allowanceOnChain).isZero())
37
37
  return true;
38
- const allowanceRequired = (0, bignumber_1.bnOrZero)(sellAmount).minus(allowanceOnChain);
38
+ const allowanceRequired = (0, bignumber_1.bnOrZero)(sellAmountExcludeFeeCryptoBaseUnit).minus(allowanceOnChain);
39
39
  return allowanceRequired.gt(0);
40
40
  }
41
41
  catch (e) {
@@ -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.sellAmountCryptoPrecision)
57
+ .approve(quote.allowanceContract, quote.sellAmountBeforeFeesCryptoBaseUnit)
58
58
  .encodeABI();
59
59
  const { bip44Params } = quote;
60
60
  const { txToSign } = await adapter.buildSendTransaction({
@@ -64,7 +64,7 @@ const grantAllowance = async ({ quote, wallet, adapter, erc20Abi, web3, }) => {
64
64
  value: '0',
65
65
  chainSpecific: {
66
66
  erc20ContractAddress: sellAssetErc20Address,
67
- gasPrice: (0, web3_utils_1.numberToHex)(((_b = (_a = quote.feeData) === null || _a === void 0 ? void 0 : _a.chainSpecific) === null || _b === void 0 ? void 0 : _b.gasPrice) || 0),
67
+ gasPrice: (0, web3_utils_1.numberToHex)(((_b = (_a = quote.feeData) === null || _a === void 0 ? void 0 : _a.chainSpecific) === null || _b === void 0 ? void 0 : _b.gasPriceCryptoBaseUnit) || 0),
68
68
  gasLimit: (0, web3_utils_1.numberToHex)(((_d = (_c = quote.feeData) === null || _c === void 0 ? void 0 : _c.chainSpecific) === null || _d === void 0 ? void 0 : _d.estimatedGas) || 0),
69
69
  },
70
70
  });
@@ -12,7 +12,7 @@ export declare const setupBuildTrade: () => {
12
12
  buildTradeInput: {
13
13
  sellAsset: Asset;
14
14
  buyAsset: Asset;
15
- sellAmountCryptoPrecision: string;
15
+ sellAmountBeforeFeesCryptoBaseUnit: string;
16
16
  sendMax: boolean;
17
17
  receiveAddress: string;
18
18
  bip44Params: import("@shapeshiftoss/types").BIP44Params;
@@ -7,8 +7,8 @@ const setupQuote = () => {
7
7
  const sellAsset = { ...assets_1.FOX };
8
8
  const buyAsset = { ...assets_1.WETH };
9
9
  const tradeQuote = {
10
- buyAmountCryptoPrecision: '',
11
- sellAmountCryptoPrecision: '1000000000000000000',
10
+ buyAmountCryptoBaseUnit: '',
11
+ sellAmountBeforeFeesCryptoBaseUnit: '1000000000000000000',
12
12
  sellAsset,
13
13
  buyAsset,
14
14
  allowanceContract: 'allowanceContractAddress',
@@ -18,7 +18,7 @@ const setupQuote = () => {
18
18
  feeData: {
19
19
  chainSpecific: {},
20
20
  sellAssetTradeFeeUsd: '0',
21
- networkFee: '0',
21
+ networkFeeCryptoBaseUnit: '0',
22
22
  buyAssetTradeFeeUsd: '0',
23
23
  },
24
24
  rate: '1',
@@ -26,7 +26,7 @@ const setupQuote = () => {
26
26
  };
27
27
  const quoteInput = {
28
28
  chainId: types_1.KnownChainIds.EthereumMainnet,
29
- sellAmountCryptoPrecision: '1000000000000000000',
29
+ sellAmountBeforeFeesCryptoBaseUnit: '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
- sellAmountCryptoPrecision: '1000000000000000000',
44
+ sellAmountBeforeFeesCryptoBaseUnit: '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, sellAmountCryptoPrecision, bip44Params } = input;
15
+ const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, 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,14 +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 = !!sellAmountCryptoPrecision;
24
+ const useSellAmount = !!sellAmountCryptoBaseUnit;
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 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);
28
+ const minQuotesellAmountCryptoBaseUnit = (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)(sellAmountCryptoBaseUnit).eq(0)
30
+ ? minQuotesellAmountCryptoBaseUnit
31
+ : sellAmountCryptoBaseUnit);
32
32
  const baseUrl = (0, helpers_2.baseUrlFromChainId)(buyAsset.chainId);
33
33
  const zrxService = (0, zrxService_1.zrxServiceFactory)(baseUrl);
34
34
  /**
@@ -47,14 +47,14 @@ async function getZrxTradeQuote(input) {
47
47
  sellAmount: normalizedSellAmount,
48
48
  },
49
49
  });
50
- const { data: { estimatedGas: estimatedGasResponse, gasPrice, price, sellAmount: sellAmountResponse, buyAmount, sources, allowanceTarget, }, } = quoteResponse;
50
+ const { data: { estimatedGas: estimatedGasResponse, gasPrice: gasPriceCryptoBaseUnit, price, sellAmount: sellAmountResponse, buyAmount, sources, allowanceTarget, }, } = quoteResponse;
51
51
  const estimatedGas = (0, bignumber_1.bnOrZero)(estimatedGasResponse).times(1.5);
52
52
  const rate = useSellAmount ? price : (0, bignumber_1.bn)(1).div(price).toString();
53
- const fee = (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(gasPrice)).toString();
53
+ const fee = estimatedGas.multipliedBy((0, bignumber_1.bnOrZero)(gasPriceCryptoBaseUnit)).toString();
54
54
  // 0x approvals are cheaper than trades, but we don't have dynamic quote data for them.
55
55
  // Instead, we use a hardcoded gasLimit estimate in place of the estimatedGas in the 0x quote response.
56
- const approvalFee = sellAssetErc20Address &&
57
- (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(gasPrice)).toString();
56
+ const approvalFeeCryptoBaseUnit = sellAssetErc20Address &&
57
+ (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(gasPriceCryptoBaseUnit)).toString();
58
58
  const tradeQuote = {
59
59
  rate,
60
60
  minimumCryptoHuman: minimum,
@@ -62,15 +62,15 @@ async function getZrxTradeQuote(input) {
62
62
  feeData: {
63
63
  chainSpecific: {
64
64
  estimatedGas: estimatedGas.toString(),
65
- gasPrice,
66
- approvalFee,
65
+ gasPriceCryptoBaseUnit,
66
+ approvalFeeCryptoBaseUnit,
67
67
  },
68
- networkFee: fee,
68
+ networkFeeCryptoBaseUnit: fee,
69
69
  buyAssetTradeFeeUsd: '0',
70
70
  sellAssetTradeFeeUsd: '0',
71
71
  },
72
- sellAmountCryptoPrecision: sellAmountResponse,
73
- buyAmountCryptoPrecision: buyAmount,
72
+ sellAmountBeforeFeesCryptoBaseUnit: sellAmountResponse,
73
+ buyAmountCryptoBaseUnit: buyAmount,
74
74
  sources: (sources === null || sources === void 0 ? void 0 : sources.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
75
75
  allowanceContract: allowanceTarget,
76
76
  buyAsset,
@@ -7,13 +7,13 @@ export declare const setupZrxTradeQuoteResponse: () => {
7
7
  };
8
8
  export declare const setupExecuteTrade: () => {
9
9
  executeTradeInput: {
10
- sellAmountCryptoPrecision: string;
10
+ sellAmountBeforeFeesCryptoBaseUnit: string;
11
11
  allowanceTarget: string;
12
12
  price: string;
13
13
  to: string;
14
14
  gas: string;
15
15
  gasPrice: string;
16
- buyAmountCryptoPrecision: string;
16
+ buyAmountCryptoBaseUnit: string;
17
17
  buyAsset: Asset;
18
18
  sellAsset: Asset;
19
19
  sendMax: boolean;
@@ -29,7 +29,7 @@ export declare const setupExecuteTrade: () => {
29
29
  chainSpecific: {};
30
30
  buyAssetTradeFeeUsd: string;
31
31
  sellAssetTradeFeeUsd: string;
32
- networkFee: string;
32
+ networkFeeCryptoBaseUnit: string;
33
33
  };
34
34
  rate: string;
35
35
  sources: never[];
@@ -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
- sellAmountCryptoPrecision: '1000000000000000000',
26
+ sellAmountBeforeFeesCryptoBaseUnit: '1000000000000000000',
27
27
  allowanceTarget: 'allowanceTargetAddress',
28
28
  price: '1',
29
29
  to: '0x123',
30
30
  gas: '1235',
31
31
  gasPrice: '1236',
32
- buyAmountCryptoPrecision: '',
32
+ buyAmountCryptoBaseUnit: '',
33
33
  buyAsset,
34
34
  sellAsset,
35
35
  sendMax: false,
@@ -41,7 +41,7 @@ const setupExecuteTrade = () => {
41
41
  chainSpecific: {},
42
42
  buyAssetTradeFeeUsd: '0',
43
43
  sellAssetTradeFeeUsd: '0',
44
- networkFee: '0',
44
+ networkFeeCryptoBaseUnit: '0',
45
45
  },
46
46
  rate: '0',
47
47
  sources: [],
@@ -36,13 +36,13 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
36
36
  ownerAddress: receiveAddress,
37
37
  });
38
38
  const allowanceOnChain = (0, bignumber_1.bnOrZero)(allowanceResult);
39
- if (!((_a = quote.feeData.chainSpecific) === null || _a === void 0 ? void 0 : _a.gasPrice))
39
+ if (!((_a = quote.feeData.chainSpecific) === null || _a === void 0 ? void 0 : _a.gasPriceCryptoBaseUnit))
40
40
  throw new api_1.SwapError('[zrxApprovalNeeded] - no gas price with quote', {
41
41
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
42
42
  details: { feeData: quote.feeData },
43
43
  });
44
44
  return {
45
- approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmountCryptoPrecision)),
45
+ approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmountBeforeFeesCryptoBaseUnit)),
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.sellAmountCryptoPrecision;
34
+ const sellAmount = args.quote.sellAmountBeforeFeesCryptoBaseUnit;
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);
@@ -36,8 +36,7 @@ const constants_2 = require("../utils/constants");
36
36
  const helpers_2 = require("../utils/helpers/helpers");
37
37
  const zrxService_1 = require("../utils/zrxService");
38
38
  async function zrxBuildTrade({ adapter, web3 }, input) {
39
- var _a;
40
- const { sellAsset, buyAsset, sellAmountCryptoPrecision, slippage, bip44Params, receiveAddress } = input;
39
+ const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountExcludeFeeCryptoBaseUnit, slippage, bip44Params, receiveAddress, } = input;
41
40
  try {
42
41
  const { assetReference: buyAssetErc20Address, assetNamespace: buyAssetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
43
42
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
@@ -82,49 +81,51 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
82
81
  params: {
83
82
  buyToken,
84
83
  sellToken,
85
- sellAmount: (0, helpers_1.normalizeAmount)(sellAmountCryptoPrecision),
84
+ sellAmount: (0, helpers_1.normalizeAmount)(sellAmountExcludeFeeCryptoBaseUnit),
86
85
  takerAddress: receiveAddress,
87
86
  slippagePercentage,
88
87
  skipValidation: false,
89
88
  affiliateAddress: constants_2.AFFILIATE_ADDRESS,
90
89
  },
91
90
  });
92
- const { data } = quoteResponse;
93
- const estimatedGas = (0, bignumber_1.bnOrZero)(data.gas || 0);
94
- const networkFee = (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString();
91
+ const { data: { allowanceTarget, sellAmount, gasPrice: gasPriceCryptoBaseUnit, gas: gasCryptoBaseUnit, price, to, buyAmount: buyAmountCryptoBaseUnit, data: txData, sources, }, } = quoteResponse;
92
+ const estimatedGas = (0, bignumber_1.bnOrZero)(gasCryptoBaseUnit || 0);
93
+ const networkFee = (0, bignumber_1.bnOrZero)(estimatedGas)
94
+ .multipliedBy((0, bignumber_1.bnOrZero)(gasPriceCryptoBaseUnit))
95
+ .toString();
95
96
  const approvalRequired = await (0, helpers_1.isApprovalRequired)({
96
97
  adapter,
97
98
  sellAsset,
98
- allowanceContract: data.allowanceTarget,
99
+ allowanceContract: allowanceTarget,
99
100
  receiveAddress,
100
- sellAmount: data.sellAmount,
101
+ sellAmountExcludeFeeCryptoBaseUnit,
101
102
  web3,
102
103
  erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi,
103
104
  });
104
105
  const approvalFee = (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT)
105
- .multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice))
106
+ .multipliedBy((0, bignumber_1.bnOrZero)(gasPriceCryptoBaseUnit))
106
107
  .toString();
107
108
  const trade = {
108
109
  sellAsset,
109
110
  buyAsset,
110
111
  bip44Params,
111
112
  receiveAddress,
112
- rate: data.price,
113
- depositAddress: data.to,
113
+ rate: price,
114
+ depositAddress: to,
114
115
  feeData: {
115
116
  chainSpecific: {
116
117
  estimatedGas: estimatedGas.toString(),
117
- gasPrice: data.gasPrice,
118
- approvalFee: approvalRequired ? approvalFee : undefined,
118
+ gasPriceCryptoBaseUnit,
119
+ approvalFeeCryptoBaseUnit: approvalRequired ? approvalFee : undefined,
119
120
  },
120
- networkFee,
121
+ networkFeeCryptoBaseUnit: networkFee,
121
122
  buyAssetTradeFeeUsd: '0',
122
123
  sellAssetTradeFeeUsd: '0',
123
124
  },
124
- txData: data.data,
125
- sellAmountCryptoPrecision: data.sellAmount,
126
- buyAmountCryptoPrecision: data.buyAmount,
127
- sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
125
+ txData,
126
+ sellAmountBeforeFeesCryptoBaseUnit: sellAmount,
127
+ buyAmountCryptoBaseUnit,
128
+ sources: (sources === null || sources === void 0 ? void 0 : sources.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
128
129
  };
129
130
  return trade;
130
131
  }
@@ -9,13 +9,15 @@ 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.sellAmountCryptoPrecision : '0';
12
+ const value = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId)
13
+ ? trade.sellAmountBeforeFeesCryptoBaseUnit
14
+ : '0';
13
15
  const buildTxResponse = await adapter.buildSendTransaction({
14
16
  value,
15
17
  wallet,
16
18
  to: trade.depositAddress,
17
19
  chainSpecific: {
18
- gasPrice: (0, web3_utils_1.numberToHex)(((_b = (_a = trade.feeData) === null || _a === void 0 ? void 0 : _a.chainSpecific) === null || _b === void 0 ? void 0 : _b.gasPrice) || 0),
20
+ gasPrice: (0, web3_utils_1.numberToHex)(((_b = (_a = trade.feeData) === null || _a === void 0 ? void 0 : _a.chainSpecific) === null || _b === void 0 ? void 0 : _b.gasPriceCryptoBaseUnit) || 0),
19
21
  gasLimit: (0, web3_utils_1.numberToHex)(((_d = (_c = trade.feeData) === null || _c === void 0 ? void 0 : _c.chainSpecific) === null || _d === void 0 ? void 0 : _d.estimatedGas) || 0),
20
22
  },
21
23
  bip44Params,