@shapeshiftoss/swapper 9.14.0 → 9.16.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 (78) hide show
  1. package/dist/api.d.ts +12 -2
  2. package/dist/api.js +1 -0
  3. package/dist/manager/SwapperManager.js +3 -3
  4. package/dist/swappercli.js +8 -8
  5. package/dist/swappers/cow/CowSwapper.d.ts +2 -1
  6. package/dist/swappers/cow/CowSwapper.js +5 -2
  7. package/dist/swappers/cow/cowApprovalNeeded/cowApprovalNeeded.js +4 -4
  8. package/dist/swappers/cow/{cowApproveInfinite/cowApproveInfinite.d.ts → cowApprove/cowApprove.d.ts} +2 -1
  9. package/dist/swappers/cow/cowApprove/cowApprove.js +56 -0
  10. package/dist/swappers/cow/cowBuildTrade/cowBuildTrade.js +11 -11
  11. package/dist/swappers/cow/cowExecuteTrade/cowExecuteTrade.js +7 -7
  12. package/dist/swappers/cow/cowGetTradeTxs/cowGetTradeTxs.js +4 -4
  13. package/dist/swappers/cow/getCowSwapMinMax/getCowSwapMinMax.js +1 -1
  14. package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +12 -12
  15. package/dist/swappers/cow/utils/blacklist.js +1 -1
  16. package/dist/swappers/cow/utils/cowService.js +2 -2
  17. package/dist/swappers/cow/utils/helpers/helpers.js +7 -7
  18. package/dist/swappers/osmosis/OsmosisSwapper.d.ts +1 -0
  19. package/dist/swappers/osmosis/OsmosisSwapper.js +24 -19
  20. package/dist/swappers/osmosis/utils/helpers.d.ts +1 -1
  21. package/dist/swappers/osmosis/utils/helpers.js +35 -35
  22. package/dist/swappers/test/TestSwapper.d.ts +1 -0
  23. package/dist/swappers/test/TestSwapper.js +6 -1
  24. package/dist/swappers/thorchain/ThorchainSwapper.d.ts +1 -0
  25. package/dist/swappers/thorchain/ThorchainSwapper.js +17 -12
  26. package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.d.ts +1 -1
  27. package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.js +14 -14
  28. package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +14 -14
  29. package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.d.ts +1 -1
  30. package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.js +7 -7
  31. package/dist/swappers/thorchain/thorTradeApproveInfinite/thorTradeApproveInfinite.d.ts +1 -1
  32. package/dist/swappers/thorchain/thorTradeApproveInfinite/thorTradeApproveInfinite.js +7 -7
  33. package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.js +5 -5
  34. package/dist/swappers/thorchain/utils/constants.js +1 -1
  35. package/dist/swappers/thorchain/utils/cosmos/cosmosTxData.js +6 -6
  36. package/dist/swappers/thorchain/utils/estimateTradeFee/estimateTradeFee.js +6 -6
  37. package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.d.ts +1 -1
  38. package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.js +6 -6
  39. package/dist/swappers/thorchain/utils/ethereum/utils/getThorTxData.js +5 -5
  40. package/dist/swappers/thorchain/utils/getLimit/getLimit.d.ts +1 -1
  41. package/dist/swappers/thorchain/utils/getLimit/getLimit.js +2 -2
  42. package/dist/swappers/thorchain/utils/getPriceRatio/getPriceRatio.js +3 -3
  43. package/dist/swappers/thorchain/utils/getTradeRate/getTradeRate.js +5 -5
  44. package/dist/swappers/thorchain/utils/getUsdRate/getUsdRate.d.ts +1 -1
  45. package/dist/swappers/thorchain/utils/getUsdRate/getUsdRate.js +4 -4
  46. package/dist/swappers/thorchain/utils/makeSwapMemo/makeSwapMemo.d.ts +1 -1
  47. package/dist/swappers/thorchain/utils/makeSwapMemo/makeSwapMemo.js +4 -4
  48. package/dist/swappers/thorchain/utils/test-data/midgardResponse.js +11 -11
  49. package/dist/swappers/thorchain/utils/test-data/setupThorswapDeps.js +9 -9
  50. package/dist/swappers/thorchain/utils/thorService.js +2 -2
  51. package/dist/swappers/thorchain/utils/txFeeHelpers/btcTxFees/getBtcTxFees.d.ts +1 -1
  52. package/dist/swappers/thorchain/utils/txFeeHelpers/btcTxFees/getBtcTxFees.js +4 -4
  53. package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.d.ts +1 -1
  54. package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.js +7 -7
  55. package/dist/swappers/utils/abi/erc20-abi.js +54 -54
  56. package/dist/swappers/utils/abi/erc20Allowance-abi.js +7 -7
  57. package/dist/swappers/utils/helpers/helpers.d.ts +4 -4
  58. package/dist/swappers/utils/helpers/helpers.js +13 -13
  59. package/dist/swappers/utils/test-data/assets.js +8 -8
  60. package/dist/swappers/utils/test-data/setupDeps.js +3 -3
  61. package/dist/swappers/utils/test-data/setupSwapQuote.js +3 -3
  62. package/dist/swappers/zrx/ZrxSwapper.d.ts +2 -1
  63. package/dist/swappers/zrx/ZrxSwapper.js +7 -4
  64. package/dist/swappers/zrx/getZrxMinMax/getZrxMinMax.js +1 -1
  65. package/dist/swappers/zrx/getZrxTradeQuote/getZrxTradeQuote.js +7 -7
  66. package/dist/swappers/zrx/utils/blacklist.js +1 -1
  67. package/dist/swappers/zrx/utils/helpers/helpers.js +6 -6
  68. package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.js +2 -2
  69. package/dist/swappers/zrx/utils/zrxService.js +2 -2
  70. package/dist/swappers/zrx/zrxApprovalNeeded/zrxApprovalNeeded.js +6 -6
  71. package/dist/swappers/zrx/zrxApprove/zrxApprove.d.ts +4 -0
  72. package/dist/swappers/zrx/zrxApprove/zrxApprove.js +62 -0
  73. package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +13 -11
  74. package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +6 -6
  75. package/package.json +1 -1
  76. package/dist/swappers/cow/cowApproveInfinite/cowApproveInfinite.js +0 -31
  77. package/dist/swappers/zrx/zrxApproveInfinite/zrxApproveInfinite.d.ts +0 -3
  78. package/dist/swappers/zrx/zrxApproveInfinite/zrxApproveInfinite.js +0 -42
@@ -12,7 +12,7 @@ exports.BTC = {
12
12
  explorer: 'https://live.blockcypher.com',
13
13
  explorerTxLink: 'https://live.blockcypher.com/btc/tx/',
14
14
  explorerAddressLink: 'https://live.blockcypher.com/btc/address/',
15
- symbol: 'BTC'
15
+ symbol: 'BTC',
16
16
  };
17
17
  exports.WETH = {
18
18
  assetId: 'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
@@ -24,7 +24,7 @@ exports.WETH = {
24
24
  explorer: 'https://etherscan.io',
25
25
  explorerTxLink: 'https://etherscan.io/tx/',
26
26
  explorerAddressLink: 'https://etherscan.io/address/',
27
- symbol: 'WETH'
27
+ symbol: 'WETH',
28
28
  };
29
29
  exports.FOX = {
30
30
  assetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d',
@@ -36,7 +36,7 @@ exports.FOX = {
36
36
  explorer: 'https://etherscan.io',
37
37
  explorerTxLink: 'https://etherscan.io/tx/',
38
38
  explorerAddressLink: 'https://etherscan.io/address/',
39
- symbol: 'FOX'
39
+ symbol: 'FOX',
40
40
  };
41
41
  exports.WBTC = {
42
42
  assetId: 'eip155:1/erc20:0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
@@ -48,7 +48,7 @@ exports.WBTC = {
48
48
  icon: 'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/logo.png',
49
49
  name: 'Wrapped Bitcoin',
50
50
  precision: 8,
51
- symbol: 'WBTC'
51
+ symbol: 'WBTC',
52
52
  };
53
53
  exports.ETH = {
54
54
  assetId: caip_1.ethAssetId,
@@ -60,7 +60,7 @@ exports.ETH = {
60
60
  icon: 'https://assets.coincap.io/assets/icons/eth@2x.png',
61
61
  explorer: 'https://etherscan.io',
62
62
  explorerTxLink: 'https://etherscan.io/tx/',
63
- explorerAddressLink: 'https://etherscan.io/address/'
63
+ explorerAddressLink: 'https://etherscan.io/address/',
64
64
  };
65
65
  exports.UNSUPPORTED = {
66
66
  assetId: 'eip155:1/slip44:420',
@@ -72,7 +72,7 @@ exports.UNSUPPORTED = {
72
72
  icon: 'https://assets.coincap.io/assets/icons/eth@2x.png',
73
73
  explorer: 'https://etherscan.io',
74
74
  explorerTxLink: 'https://etherscan.io/tx/',
75
- explorerAddressLink: 'https://etherscan.io/address/'
75
+ explorerAddressLink: 'https://etherscan.io/address/',
76
76
  };
77
77
  exports.USDC = {
78
78
  assetId: 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
@@ -84,7 +84,7 @@ exports.USDC = {
84
84
  icon: 'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png',
85
85
  explorer: 'https://etherscan.io',
86
86
  explorerAddressLink: 'https://etherscan.io/address/',
87
- explorerTxLink: 'https://etherscan.io/tx/'
87
+ explorerTxLink: 'https://etherscan.io/tx/',
88
88
  };
89
89
  exports.AVAX = {
90
90
  assetId: caip_1.avalancheAssetId,
@@ -96,5 +96,5 @@ exports.AVAX = {
96
96
  icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/avalanchec/info/logo.png',
97
97
  explorer: 'https://snowtrace.io',
98
98
  explorerAddressLink: 'https://snowtrace.io/address/',
99
- explorerTxLink: 'https://snowtrace.io/tx/'
99
+ explorerTxLink: 'https://snowtrace.io/tx/',
100
100
  };
@@ -39,10 +39,10 @@ const setupDeps = () => {
39
39
  providers: {
40
40
  ws: new unchained.ws.Client('wss://dev-api.ethereum.shapeshift.com'),
41
41
  http: new unchained.ethereum.V1Api(new unchained.ethereum.Configuration({
42
- basePath: 'https://dev-api.ethereum.shapeshift.com'
43
- }))
42
+ basePath: 'https://dev-api.ethereum.shapeshift.com',
43
+ })),
44
44
  },
45
- rpcUrl: 'https://mainnet.infura.io/v3/d734c7eebcdf400185d7eb67322a7e57'
45
+ rpcUrl: 'https://mainnet.infura.io/v3/d734c7eebcdf400185d7eb67322a7e57',
46
46
  });
47
47
  ethChainAdapter.getFeeAssetId = () => caip_1.ethAssetId;
48
48
  const ethNodeUrl = 'http://localhost:1000';
@@ -17,7 +17,7 @@ const setupQuote = () => {
17
17
  maximum: '999999999999',
18
18
  feeData: { fee: '0', tradeFee: '0', chainSpecific: {} },
19
19
  rate: '1',
20
- sources: []
20
+ sources: [],
21
21
  };
22
22
  const quoteInput = {
23
23
  chainId: types_1.KnownChainIds.EthereumMainnet,
@@ -27,7 +27,7 @@ const setupQuote = () => {
27
27
  sellAssetAccountNumber: 0,
28
28
  sendMax: false,
29
29
  receiveAddress: '0xc770eefad204b5180df6a14ee197d99d808ee52d',
30
- wallet: {}
30
+ wallet: {},
31
31
  };
32
32
  return { quoteInput, tradeQuote, buyAsset, sellAsset };
33
33
  };
@@ -43,7 +43,7 @@ const setupBuildTrade = () => {
43
43
  sellAssetAccountNumber: 0,
44
44
  sellAsset,
45
45
  wallet: {},
46
- receiveAddress: ''
46
+ receiveAddress: '',
47
47
  };
48
48
  return { buildTradeInput, buyAsset, sellAsset };
49
49
  };
@@ -1,6 +1,6 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
3
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, EvmSupportedChainIds, GetEvmTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
3
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveAmountInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, EvmSupportedChainIds, GetEvmTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
4
  import { ZrxExecuteTradeInput, ZrxSwapperDeps, ZrxTrade } from './types';
5
5
  export declare class ZrxSwapper<T extends EvmSupportedChainIds> implements Swapper<T> {
6
6
  readonly name = "0x";
@@ -14,6 +14,7 @@ export declare class ZrxSwapper<T extends EvmSupportedChainIds> implements Swapp
14
14
  executeTrade(args: ZrxExecuteTradeInput<T>): Promise<TradeResult>;
15
15
  approvalNeeded(args: ApprovalNeededInput<T>): Promise<ApprovalNeededOutput>;
16
16
  approveInfinite(args: ApproveInfiniteInput<T>): Promise<string>;
17
+ approveAmount(args: ApproveAmountInput<T>): Promise<string>;
17
18
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
18
19
  filterAssetIdsBySellable(assetIds?: AssetId[]): AssetId[];
19
20
  getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
@@ -7,7 +7,7 @@ const getZrxTradeQuote_1 = require("./getZrxTradeQuote/getZrxTradeQuote");
7
7
  const blacklist_1 = require("./utils/blacklist");
8
8
  const helpers_1 = require("./utils/helpers/helpers");
9
9
  const zrxApprovalNeeded_1 = require("./zrxApprovalNeeded/zrxApprovalNeeded");
10
- const zrxApproveInfinite_1 = require("./zrxApproveInfinite/zrxApproveInfinite");
10
+ const zrxApprove_1 = require("./zrxApprove/zrxApprove");
11
11
  const zrxBuildTrade_1 = require("./zrxBuildTrade/zrxBuildTrade");
12
12
  const zrxExecuteTrade_1 = require("./zrxExecuteTrade/zrxExecuteTrade");
13
13
  class ZrxSwapper {
@@ -24,7 +24,7 @@ class ZrxSwapper {
24
24
  return api_1.SwapperType.ZrxAvalanche;
25
25
  default:
26
26
  throw new api_1.SwapError('[getType]', {
27
- code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN
27
+ code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
28
28
  });
29
29
  }
30
30
  }
@@ -44,7 +44,10 @@ class ZrxSwapper {
44
44
  return (0, zrxApprovalNeeded_1.zrxApprovalNeeded)(this.deps, args);
45
45
  }
46
46
  async approveInfinite(args) {
47
- return (0, zrxApproveInfinite_1.zrxApproveInfinite)(this.deps, args);
47
+ return (0, zrxApprove_1.zrxApproveInfinite)(this.deps, args);
48
+ }
49
+ async approveAmount(args) {
50
+ return (0, zrxApprove_1.zrxApproveAmount)(this.deps, args);
48
51
  }
49
52
  filterBuyAssetsBySellAssetId(args) {
50
53
  const { assetIds = [], sellAssetId } = args;
@@ -58,7 +61,7 @@ class ZrxSwapper {
58
61
  async getTradeTxs(tradeResult) {
59
62
  return {
60
63
  sellTxid: tradeResult.tradeId,
61
- buyTxid: tradeResult.tradeId
64
+ buyTxid: tradeResult.tradeId,
62
65
  };
63
66
  }
64
67
  }
@@ -18,7 +18,7 @@ const getZrxMinMax = async (sellAsset, buyAsset) => {
18
18
  const maximum = constants_1.MAX_ZRX_TRADE; // Arbitrarily large value. 10e+28 here.
19
19
  return {
20
20
  minimum,
21
- maximum
21
+ maximum,
22
22
  };
23
23
  }
24
24
  catch (e) {
@@ -16,7 +16,7 @@ async function getZrxTradeQuote(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,
19
- details: { buyAssetChainId: buyAsset.chainId, sellAssetChainId: sellAsset.chainId }
19
+ details: { buyAssetChainId: buyAsset.chainId, sellAssetChainId: sellAsset.chainId },
20
20
  });
21
21
  }
22
22
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
@@ -42,10 +42,10 @@ async function getZrxTradeQuote(input) {
42
42
  params: {
43
43
  sellToken,
44
44
  buyToken,
45
- sellAmount: normalizedSellAmount
46
- }
45
+ sellAmount: normalizedSellAmount,
46
+ },
47
47
  });
48
- const { data: { estimatedGas: estimatedGasResponse, gasPrice, price, sellAmount: sellAmountResponse, buyAmount, sources, allowanceTarget } } = quoteResponse;
48
+ const { data: { estimatedGas: estimatedGasResponse, gasPrice, price, sellAmount: sellAmountResponse, buyAmount, sources, allowanceTarget, }, } = quoteResponse;
49
49
  const estimatedGas = (0, bignumber_1.bnOrZero)(estimatedGasResponse).times(1.5);
50
50
  const rate = useSellAmount ? price : (0, bignumber_1.bn)(1).div(price).toString();
51
51
  const fee = (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(gasPrice)).toString();
@@ -62,9 +62,9 @@ async function getZrxTradeQuote(input) {
62
62
  chainSpecific: {
63
63
  estimatedGas: estimatedGas.toString(),
64
64
  gasPrice,
65
- approvalFee
65
+ approvalFee,
66
66
  },
67
- tradeFee: '0'
67
+ tradeFee: '0',
68
68
  },
69
69
  sellAmount: sellAmountResponse,
70
70
  buyAmount,
@@ -72,7 +72,7 @@ async function getZrxTradeQuote(input) {
72
72
  allowanceContract: allowanceTarget,
73
73
  buyAsset,
74
74
  sellAsset,
75
- sellAssetAccountNumber
75
+ sellAssetAccountNumber,
76
76
  };
77
77
  }
78
78
  catch (e) {
@@ -5,5 +5,5 @@ exports.UNSUPPORTED_ASSETS = void 0;
5
5
  // We assume all erc20's are supported and remove these explicitely unsupported assets
6
6
  exports.UNSUPPORTED_ASSETS = Object.freeze([
7
7
  // Foxy token unsupported by zrx
8
- 'eip155:1/erc20:0xdc49108ce5c57bc3408c3a5e95f3d864ec386ed3'
8
+ 'eip155:1/erc20:0xdc49108ce5c57bc3408c3a5e95f3d864ec386ed3',
9
9
  ]);
@@ -15,7 +15,7 @@ const baseUrlFromChainId = (chainId) => {
15
15
  return 'https://avalanche.api.0x.org/';
16
16
  default:
17
17
  throw new api_1.SwapError(`baseUrlFromChainId] - Unsupported chainId: ${chainId}`, {
18
- code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN
18
+ code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
19
19
  });
20
20
  }
21
21
  };
@@ -29,7 +29,7 @@ const usdcContractFromChainId = (chainId) => {
29
29
  return '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e';
30
30
  default:
31
31
  throw new api_1.SwapError(`usdcContractFromChainId] - Unsupported chainId: ${chainId}`, {
32
- code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN
32
+ code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
33
33
  });
34
34
  }
35
35
  };
@@ -59,13 +59,13 @@ const getUsdRate = async (asset) => {
59
59
  params: {
60
60
  buyToken: USDC_CONTRACT_ADDRESS,
61
61
  buyAmount: '1000000000',
62
- sellToken: assetNamespace === 'erc20' ? erc20Address : symbol
63
- }
62
+ sellToken: assetNamespace === 'erc20' ? erc20Address : symbol,
63
+ },
64
64
  });
65
65
  const price = (0, bignumber_1.bnOrZero)(rateResponse.data.price);
66
66
  if (!price.gt(0))
67
67
  throw new api_1.SwapError('[getUsdRate] - Failed to get price data', {
68
- code: api_1.SwapErrorTypes.RESPONSE_ERROR
68
+ code: api_1.SwapErrorTypes.RESPONSE_ERROR,
69
69
  });
70
70
  return (0, bignumber_1.bn)(1).dividedBy(price).toString();
71
71
  }
@@ -74,7 +74,7 @@ const getUsdRate = async (asset) => {
74
74
  throw e;
75
75
  throw new api_1.SwapError('[getUsdRate]', {
76
76
  cause: e,
77
- code: api_1.SwapErrorTypes.USD_RATE_FAILED
77
+ code: api_1.SwapErrorTypes.USD_RATE_FAILED,
78
78
  });
79
79
  }
80
80
  };
@@ -14,7 +14,7 @@ const setupZrxTradeQuoteResponse = () => {
14
14
  gas: '1235',
15
15
  gasPrice: '1236',
16
16
  sources: [],
17
- buyAmount: ''
17
+ buyAmount: '',
18
18
  };
19
19
  return { quoteResponse, buyAsset, sellAsset };
20
20
  };
@@ -39,7 +39,7 @@ const setupExecuteTrade = () => {
39
39
  receiveAddress: '0x0',
40
40
  feeData: { fee: '0', chainSpecific: {}, tradeFee: '0' },
41
41
  rate: '0',
42
- sources: []
42
+ sources: [],
43
43
  };
44
44
  return { executeTradeInput, buyAsset, sellAsset };
45
45
  };
@@ -9,8 +9,8 @@ const axiosConfig = {
9
9
  timeout: 10000,
10
10
  headers: {
11
11
  Accept: 'application/json',
12
- 'Content-Type': 'application/json'
13
- }
12
+ 'Content-Type': 'application/json',
13
+ },
14
14
  };
15
15
  const zrxServiceFactory = (baseUrl) => axios_1.default.create({ ...axiosConfig, baseURL: baseUrl });
16
16
  exports.zrxServiceFactory = zrxServiceFactory;
@@ -14,7 +14,7 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
14
14
  if (sellAsset.chainId !== adapter.getChainId()) {
15
15
  throw new api_1.SwapError('[zrxApprovalNeeded] - sellAsset chainId is not supported', {
16
16
  code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
17
- details: { chainId: sellAsset.chainId }
17
+ details: { chainId: sellAsset.chainId },
18
18
  });
19
19
  }
20
20
  // No approval needed for selling a fee asset
@@ -27,7 +27,7 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
27
27
  if (!quote.allowanceContract) {
28
28
  throw new api_1.SwapError('[zrxApprovalNeeded] - allowanceTarget is required', {
29
29
  code: api_1.SwapErrorTypes.VALIDATION_FAILED,
30
- details: { chainId: sellAsset.chainId }
30
+ details: { chainId: sellAsset.chainId },
31
31
  });
32
32
  }
33
33
  const allowanceResult = await (0, helpers_1.getERC20Allowance)({
@@ -35,16 +35,16 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
35
35
  erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi,
36
36
  sellAssetErc20Address,
37
37
  spenderAddress: quote.allowanceContract,
38
- ownerAddress: receiveAddress
38
+ ownerAddress: receiveAddress,
39
39
  });
40
40
  const allowanceOnChain = (0, bignumber_1.bnOrZero)(allowanceResult);
41
41
  if (!((_a = quote.feeData.chainSpecific) === null || _a === void 0 ? void 0 : _a.gasPrice))
42
42
  throw new api_1.SwapError('[zrxApprovalNeeded] - no gas price with quote', {
43
43
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
44
- details: { feeData: quote.feeData }
44
+ details: { feeData: quote.feeData },
45
45
  });
46
46
  return {
47
- approvalNeeded: allowanceOnChain.lte((0, bignumber_1.bnOrZero)(quote.sellAmount))
47
+ approvalNeeded: allowanceOnChain.lte((0, bignumber_1.bnOrZero)(quote.sellAmount)),
48
48
  };
49
49
  }
50
50
  catch (e) {
@@ -52,7 +52,7 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
52
52
  throw e;
53
53
  throw new api_1.SwapError('[zrxApprovalNeeded]', {
54
54
  cause: e,
55
- code: api_1.SwapErrorTypes.CHECK_APPROVAL_FAILED
55
+ code: api_1.SwapErrorTypes.CHECK_APPROVAL_FAILED,
56
56
  });
57
57
  }
58
58
  }
@@ -0,0 +1,4 @@
1
+ import { ApproveAmountInput, ApproveInfiniteInput, EvmSupportedChainIds } from '../../../api';
2
+ import { ZrxSwapperDeps } from '../types';
3
+ export declare function zrxApproveAmount<T extends EvmSupportedChainIds>(deps: ZrxSwapperDeps, args: ApproveAmountInput<T>): Promise<string>;
4
+ export declare function zrxApproveInfinite<T extends EvmSupportedChainIds>(deps: ZrxSwapperDeps, args: ApproveInfiniteInput<T>): Promise<string>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zrxApproveInfinite = exports.zrxApproveAmount = void 0;
4
+ const api_1 = require("../../../api");
5
+ const erc20_abi_1 = require("../../utils/abi/erc20-abi");
6
+ const constants_1 = require("../../utils/constants");
7
+ const helpers_1 = require("../../utils/helpers/helpers");
8
+ const constants_2 = require("../utils/constants");
9
+ const grantAllowanceForAmount = async ({ adapter, web3 }, { quote, wallet }, approvalAmount) => {
10
+ const approvalQuote = {
11
+ ...quote,
12
+ sellAmount: approvalAmount,
13
+ feeData: {
14
+ ...quote.feeData,
15
+ chainSpecific: {
16
+ ...quote.feeData.chainSpecific,
17
+ // 0x approvals are cheaper than trades, but we don't have dynamic quote data for them.
18
+ // Instead, we use a hardcoded gasLimit estimate in place of the estimatedGas in the 0x quote response.
19
+ estimatedGas: constants_1.APPROVAL_GAS_LIMIT,
20
+ },
21
+ },
22
+ };
23
+ return await (0, helpers_1.grantAllowance)({
24
+ quote: approvalQuote,
25
+ wallet,
26
+ adapter,
27
+ erc20Abi: erc20_abi_1.erc20Abi,
28
+ web3,
29
+ });
30
+ };
31
+ async function zrxApproveAmount(deps, args) {
32
+ var _a;
33
+ try {
34
+ const sellAmount = args.quote.sellAmount;
35
+ // If no amount is specified we use the quotes sell amount
36
+ const approvalAmount = (_a = args.amount) !== null && _a !== void 0 ? _a : sellAmount;
37
+ return grantAllowanceForAmount(deps, args, approvalAmount);
38
+ }
39
+ catch (e) {
40
+ if (e instanceof api_1.SwapError)
41
+ throw e;
42
+ throw new api_1.SwapError('[zrxApproveAmount]', {
43
+ cause: e,
44
+ code: api_1.SwapErrorTypes.APPROVE_AMOUNT_FAILED,
45
+ });
46
+ }
47
+ }
48
+ exports.zrxApproveAmount = zrxApproveAmount;
49
+ async function zrxApproveInfinite(deps, args) {
50
+ try {
51
+ return grantAllowanceForAmount(deps, args, constants_2.MAX_ALLOWANCE);
52
+ }
53
+ catch (e) {
54
+ if (e instanceof api_1.SwapError)
55
+ throw e;
56
+ throw new api_1.SwapError('[zrxApproveInfinite]', {
57
+ cause: e,
58
+ code: api_1.SwapErrorTypes.APPROVE_INFINITE_FAILED,
59
+ });
60
+ }
61
+ }
62
+ exports.zrxApproveInfinite = zrxApproveInfinite;
@@ -47,7 +47,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
47
47
  if (buyAsset.chainId !== adapterChainId) {
48
48
  throw new api_1.SwapError(`[zrxBuildTrade] - buyAsset must be on chainId ${adapterChainId}`, {
49
49
  code: api_1.SwapErrorTypes.VALIDATION_FAILED,
50
- details: { chainId: sellAsset.chainId }
50
+ details: { chainId: sellAsset.chainId },
51
51
  });
52
52
  }
53
53
  const slippagePercentage = slippage ? (0, bignumber_1.bnOrZero)(slippage).div(100).toString() : constants_1.DEFAULT_SLIPPAGE;
@@ -76,7 +76,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
76
76
  return true;
77
77
  // Handle the request based on your other config options, e.g. `statusCodesToRetry`
78
78
  return rax.shouldRetryRequest(err);
79
- }
79
+ },
80
80
  });
81
81
  const quoteResponse = await zrxRetry.get('/swap/v1/quote', {
82
82
  params: {
@@ -86,8 +86,8 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
86
86
  takerAddress: receiveAddress,
87
87
  slippagePercentage,
88
88
  skipValidation: false,
89
- affiliateAddress: constants_2.AFFILIATE_ADDRESS
90
- }
89
+ affiliateAddress: constants_2.AFFILIATE_ADDRESS,
90
+ },
91
91
  });
92
92
  const { data } = quoteResponse;
93
93
  const estimatedGas = (0, bignumber_1.bnOrZero)(data.gas || 0);
@@ -102,14 +102,14 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
102
102
  fee: (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString(),
103
103
  chainSpecific: {
104
104
  estimatedGas: estimatedGas.toString(),
105
- gasPrice: data.gasPrice
105
+ gasPrice: data.gasPrice,
106
106
  },
107
- tradeFee: '0'
107
+ tradeFee: '0',
108
108
  },
109
109
  txData: data.data,
110
110
  sellAmount: data.sellAmount,
111
111
  buyAmount: data.buyAmount,
112
- sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE
112
+ sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
113
113
  };
114
114
  const allowanceRequired = await (0, helpers_1.getAllowanceRequired)({
115
115
  adapter,
@@ -118,16 +118,18 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
118
118
  receiveAddress,
119
119
  sellAmount: data.sellAmount,
120
120
  web3,
121
- erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi
121
+ erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi,
122
122
  });
123
123
  if (allowanceRequired) {
124
124
  trade.feeData = {
125
125
  fee: ((_b = trade.feeData) === null || _b === void 0 ? void 0 : _b.fee) || '0',
126
126
  chainSpecific: {
127
127
  ...(_c = trade.feeData) === null || _c === void 0 ? void 0 : _c.chainSpecific,
128
- approvalFee: (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString()
128
+ approvalFee: (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT)
129
+ .multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice))
130
+ .toString(),
129
131
  },
130
- tradeFee: '0'
132
+ tradeFee: '0',
131
133
  };
132
134
  }
133
135
  return trade;
@@ -136,7 +138,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
136
138
  if (e instanceof api_1.SwapError)
137
139
  throw e;
138
140
  throw new api_1.SwapError('[zrxBuildTrade]', {
139
- code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED
141
+ code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
140
142
  });
141
143
  }
142
144
  }
@@ -11,7 +11,7 @@ async function zrxExecuteTrade({ adapter }, { trade, wallet }) {
11
11
  // value is 0 for erc20s
12
12
  const value = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? trade.sellAmount : '0';
13
13
  const bip44Params = adapter.buildBIP44Params({
14
- accountNumber: trade.sellAssetAccountNumber
14
+ accountNumber: trade.sellAssetAccountNumber,
15
15
  });
16
16
  const buildTxResponse = await adapter.buildSendTransaction({
17
17
  value,
@@ -19,9 +19,9 @@ async function zrxExecuteTrade({ adapter }, { trade, wallet }) {
19
19
  to: trade.depositAddress,
20
20
  chainSpecific: {
21
21
  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),
22
- 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)
22
+ 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),
23
23
  },
24
- bip44Params
24
+ bip44Params,
25
25
  });
26
26
  const { txToSign } = buildTxResponse;
27
27
  const txWithQuoteData = { ...txToSign, data: (_e = trade.txData) !== null && _e !== void 0 ? _e : '' };
@@ -33,13 +33,13 @@ async function zrxExecuteTrade({ adapter }, { trade, wallet }) {
33
33
  else if (wallet.supportsBroadcast() && adapter.signAndBroadcastTransaction) {
34
34
  const txid = await ((_f = adapter.signAndBroadcastTransaction) === null || _f === void 0 ? void 0 : _f.call(adapter, {
35
35
  txToSign: txWithQuoteData,
36
- wallet
36
+ wallet,
37
37
  }));
38
38
  return { tradeId: txid };
39
39
  }
40
40
  else {
41
41
  throw new api_1.SwapError('[zrxExecuteTrade]', {
42
- code: api_1.SwapErrorTypes.SIGN_AND_BROADCAST_FAILED
42
+ code: api_1.SwapErrorTypes.SIGN_AND_BROADCAST_FAILED,
43
43
  });
44
44
  }
45
45
  }
@@ -48,7 +48,7 @@ async function zrxExecuteTrade({ adapter }, { trade, wallet }) {
48
48
  throw e;
49
49
  throw new api_1.SwapError('[zrxExecuteTrade]', {
50
50
  cause: e,
51
- code: api_1.SwapErrorTypes.EXECUTE_TRADE_FAILED
51
+ code: api_1.SwapErrorTypes.EXECUTE_TRADE_FAILED,
52
52
  });
53
53
  }
54
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "9.14.0",
3
+ "version": "9.16.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",
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cowApproveInfinite = void 0;
4
- const api_1 = require("../../../api");
5
- const erc20_abi_1 = require("../../utils/abi/erc20-abi");
6
- const helpers_1 = require("../../utils/helpers/helpers");
7
- const constants_1 = require("../utils/constants");
8
- async function cowApproveInfinite({ adapter, web3 }, { quote, wallet }) {
9
- try {
10
- const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
11
- quote: {
12
- ...quote,
13
- sellAmount: constants_1.MAX_ALLOWANCE
14
- },
15
- wallet,
16
- adapter,
17
- erc20Abi: erc20_abi_1.erc20Abi,
18
- web3
19
- });
20
- return allowanceGrantRequired;
21
- }
22
- catch (e) {
23
- if (e instanceof api_1.SwapError)
24
- throw e;
25
- throw new api_1.SwapError('[cowApproveInfinite]', {
26
- cause: e,
27
- code: api_1.SwapErrorTypes.APPROVE_INFINITE_FAILED
28
- });
29
- }
30
- }
31
- exports.cowApproveInfinite = cowApproveInfinite;
@@ -1,3 +0,0 @@
1
- import { ApproveInfiniteInput, EvmSupportedChainIds } from '../../../api';
2
- import { ZrxSwapperDeps } from '../types';
3
- export declare function zrxApproveInfinite<T extends EvmSupportedChainIds>({ adapter, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<T>): Promise<string>;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zrxApproveInfinite = void 0;
4
- const api_1 = require("../../../api");
5
- const erc20_abi_1 = require("../../utils/abi/erc20-abi");
6
- const constants_1 = require("../../utils/constants");
7
- const helpers_1 = require("../../utils/helpers/helpers");
8
- const constants_2 = require("../utils/constants");
9
- async function zrxApproveInfinite({ adapter, web3 }, { quote, wallet }) {
10
- try {
11
- const approvalQuote = {
12
- ...quote,
13
- sellAmount: constants_2.MAX_ALLOWANCE,
14
- feeData: {
15
- ...quote.feeData,
16
- chainSpecific: {
17
- ...quote.feeData.chainSpecific,
18
- // 0x approvals are cheaper than trades, but we don't have dynamic quote data for them.
19
- // Instead, we use a hardcoded gasLimit estimate in place of the estimatedGas in the 0x quote response.
20
- estimatedGas: constants_1.APPROVAL_GAS_LIMIT
21
- }
22
- }
23
- };
24
- const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
25
- quote: approvalQuote,
26
- wallet,
27
- adapter,
28
- erc20Abi: erc20_abi_1.erc20Abi,
29
- web3
30
- });
31
- return allowanceGrantRequired;
32
- }
33
- catch (e) {
34
- if (e instanceof api_1.SwapError)
35
- throw e;
36
- throw new api_1.SwapError('[zrxApproveInfinite]', {
37
- cause: e,
38
- code: api_1.SwapErrorTypes.APPROVE_INFINITE_FAILED
39
- });
40
- }
41
- }
42
- exports.zrxApproveInfinite = zrxApproveInfinite;