@shapeshiftoss/swapper 1.11.11 → 1.14.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 (25) hide show
  1. package/dist/swappers/zrx/ZrxApprovalNeeded/ZrxApprovalNeeded.d.ts +3 -0
  2. package/dist/swappers/zrx/{approvalNeeded/approvalNeeded.js → ZrxApprovalNeeded/ZrxApprovalNeeded.js} +5 -5
  3. package/dist/swappers/zrx/ZrxApproveInfinite/ZrxApproveInfinite.d.ts +3 -0
  4. package/dist/swappers/zrx/{approveInfinite/approveInfinite.js → ZrxApproveInfinite/ZrxApproveInfinite.js} +3 -3
  5. package/dist/swappers/zrx/ZrxBuildQuoteTx/ZrxBuildQuoteTx.d.ts +3 -0
  6. package/dist/swappers/zrx/{buildQuoteTx/buildQuoteTx.js → ZrxBuildQuoteTx/ZrxBuildQuoteTx.js} +9 -9
  7. package/dist/swappers/zrx/ZrxExecuteQuote/ZrxExecuteQuote.d.ts +3 -0
  8. package/dist/swappers/zrx/{executeQuote/executeQuote.js → ZrxExecuteQuote/ZrxExecuteQuote.js} +14 -14
  9. package/dist/swappers/zrx/ZrxSwapper.js +14 -14
  10. package/dist/swappers/zrx/getZrxMinMax/getZrxMinMax.d.ts +2 -0
  11. package/dist/swappers/zrx/{getMinMax/getMinMax.js → getZrxMinMax/getZrxMinMax.js} +4 -4
  12. package/dist/swappers/zrx/{getQuote/getQuote.d.ts → getZrxQuote/getZrxQuote.d.ts} +0 -0
  13. package/dist/swappers/zrx/{getQuote/getQuote.js → getZrxQuote/getZrxQuote.js} +0 -0
  14. package/dist/swappers/zrx/getZrxSendMaxAmount/getZrxSendMaxAmount.d.ts +3 -0
  15. package/dist/swappers/zrx/{getSendMaxAmount/getSendMaxAmount.js → getZrxSendMaxAmount/getZrxSendMaxAmount.js} +7 -4
  16. package/dist/swappers/zrx/utils/test-data/assets.js +3 -0
  17. package/dist/swappers/zrx/utils/test-data/setupZrxDeps.d.ts +6 -1
  18. package/dist/swappers/zrx/utils/test-data/setupZrxDeps.js +2 -1
  19. package/package.json +12 -4
  20. package/dist/swappers/zrx/approvalNeeded/approvalNeeded.d.ts +0 -3
  21. package/dist/swappers/zrx/approveInfinite/approveInfinite.d.ts +0 -3
  22. package/dist/swappers/zrx/buildQuoteTx/buildQuoteTx.d.ts +0 -3
  23. package/dist/swappers/zrx/executeQuote/executeQuote.d.ts +0 -3
  24. package/dist/swappers/zrx/getMinMax/getMinMax.d.ts +0 -2
  25. package/dist/swappers/zrx/getSendMaxAmount/getSendMaxAmount.d.ts +0 -3
@@ -0,0 +1,3 @@
1
+ import { ApprovalNeededInput, ApprovalNeededOutput, ChainTypes, SwapperType } from '@shapeshiftoss/types';
2
+ import { ZrxSwapperDeps } from '../ZrxSwapper';
3
+ export declare function ZrxApprovalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<ChainTypes, SwapperType>): Promise<ApprovalNeededOutput>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.approvalNeeded = void 0;
3
+ exports.ZrxApprovalNeeded = void 0;
4
4
  const types_1 = require("@shapeshiftoss/types");
5
5
  const bignumber_js_1 = require("bignumber.js");
6
6
  const api_1 = require("../../../api");
@@ -8,13 +8,13 @@ const erc20Allowance_abi_1 = require("../utils/abi/erc20Allowance-abi");
8
8
  const constants_1 = require("../utils/constants");
9
9
  const helpers_1 = require("../utils/helpers/helpers");
10
10
  const zrxService_1 = require("../utils/zrxService");
11
- async function approvalNeeded({ adapterManager, web3 }, { quote, wallet }) {
11
+ async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
12
12
  const { sellAsset } = quote;
13
13
  if (sellAsset.symbol === 'ETH') {
14
14
  return { approvalNeeded: false };
15
15
  }
16
16
  if (sellAsset.chain !== types_1.ChainTypes.Ethereum) {
17
- throw new api_1.SwapError('ZrxSwapper:approvalNeeded only Ethereum chain type is supported');
17
+ throw new api_1.SwapError('ZrxSwapper:ZrxApprovalNeeded only Ethereum chain type is supported');
18
18
  }
19
19
  const accountNumber = quote.sellAssetAccountId ? Number(quote.sellAssetAccountId) : 0;
20
20
  const adapter = adapterManager.byChain(sellAsset.chain);
@@ -42,7 +42,7 @@ async function approvalNeeded({ adapterManager, web3 }, { quote, wallet }) {
42
42
  });
43
43
  const { data } = quoteResponse;
44
44
  if (!quote.sellAsset.tokenId || !data.allowanceTarget) {
45
- throw new api_1.SwapError('approvalNeeded - tokenId and allowanceTarget are required');
45
+ throw new api_1.SwapError('ZrxApprovalNeeded - tokenId and allowanceTarget are required');
46
46
  }
47
47
  const allowanceResult = await (0, helpers_1.getERC20Allowance)({
48
48
  web3,
@@ -58,4 +58,4 @@ async function approvalNeeded({ adapterManager, web3 }, { quote, wallet }) {
58
58
  gasPrice: data.gasPrice
59
59
  };
60
60
  }
61
- exports.approvalNeeded = approvalNeeded;
61
+ exports.ZrxApprovalNeeded = ZrxApprovalNeeded;
@@ -0,0 +1,3 @@
1
+ import { ApproveInfiniteInput, ChainTypes, SwapperType } from '@shapeshiftoss/types';
2
+ import { ZrxSwapperDeps } from '../ZrxSwapper';
3
+ export declare function ZrxApproveInfinite({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<ChainTypes, SwapperType>): Promise<string>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.approveInfinite = void 0;
3
+ exports.ZrxApproveInfinite = void 0;
4
4
  const types_1 = require("@shapeshiftoss/types");
5
5
  const api_1 = require("../../../api");
6
6
  const erc20_abi_1 = require("../utils/abi/erc20-abi");
@@ -8,7 +8,7 @@ const bignumber_1 = require("../utils/bignumber");
8
8
  const constants_1 = require("../utils/constants");
9
9
  const helpers_1 = require("../utils/helpers/helpers");
10
10
  const zrxService_1 = require("../utils/zrxService");
11
- async function approveInfinite({ adapterManager, web3 }, { quote, wallet }) {
11
+ async function ZrxApproveInfinite({ adapterManager, web3 }, { quote, wallet }) {
12
12
  const adapter = adapterManager.byChain(types_1.ChainTypes.Ethereum);
13
13
  const bip32Params = adapter.buildBIP32Params({
14
14
  accountNumber: (0, bignumber_1.bnOrZero)(quote.sellAssetAccountId).toNumber()
@@ -51,4 +51,4 @@ async function approveInfinite({ adapterManager, web3 }, { quote, wallet }) {
51
51
  });
52
52
  return allowanceGrantRequired;
53
53
  }
54
- exports.approveInfinite = approveInfinite;
54
+ exports.ZrxApproveInfinite = ZrxApproveInfinite;
@@ -0,0 +1,3 @@
1
+ import { BuildQuoteTxInput, ChainTypes, Quote, SwapperType } from '@shapeshiftoss/types';
2
+ import { ZrxSwapperDeps } from '../ZrxSwapper';
3
+ export declare function ZrxBuildQuoteTx({ adapterManager, web3 }: ZrxSwapperDeps, { input, wallet }: BuildQuoteTxInput): Promise<Quote<ChainTypes, SwapperType>>;
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.buildQuoteTx = void 0;
25
+ exports.ZrxBuildQuoteTx = void 0;
26
26
  const types_1 = require("@shapeshiftoss/types");
27
27
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
28
28
  const rax = __importStar(require("retry-axios"));
@@ -32,31 +32,31 @@ const applyAxiosRetry_1 = require("../utils/applyAxiosRetry");
32
32
  const constants_1 = require("../utils/constants");
33
33
  const helpers_1 = require("../utils/helpers/helpers");
34
34
  const zrxService_1 = require("../utils/zrxService");
35
- async function buildQuoteTx({ adapterManager, web3 }, { input, wallet }) {
35
+ async function ZrxBuildQuoteTx({ adapterManager, web3 }, { input, wallet }) {
36
36
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
37
37
  const { sellAsset, buyAsset, sellAmount, buyAmount, slippage, sellAssetAccountId, buyAssetAccountId, priceImpact } = input;
38
38
  if ((buyAmount && sellAmount) || (!buyAmount && !sellAmount)) {
39
- throw new __1.SwapError('ZrxSwapper:buildQuoteTx Exactly one of buyAmount or sellAmount is required');
39
+ throw new __1.SwapError('ZrxSwapper:ZrxBuildQuoteTx Exactly one of buyAmount or sellAmount is required');
40
40
  }
41
41
  if (!sellAssetAccountId || !buyAssetAccountId) {
42
- throw new __1.SwapError('ZrxSwapper:buildQuoteTx Both sellAssetAccountId and buyAssetAccountId are required');
42
+ throw new __1.SwapError('ZrxSwapper:ZrxBuildQuoteTx Both sellAssetAccountId and buyAssetAccountId are required');
43
43
  }
44
44
  const buyToken = buyAsset.tokenId || buyAsset.symbol || buyAsset.network;
45
45
  const sellToken = sellAsset.tokenId || sellAsset.symbol || sellAsset.network;
46
46
  if (!buyToken) {
47
- throw new __1.SwapError('ZrxSwapper:buildQuoteTx One of buyAssetContract or buyAssetSymbol or buyAssetNetwork are required');
47
+ throw new __1.SwapError('ZrxSwapper:ZrxBuildQuoteTx One of buyAssetContract or buyAssetSymbol or buyAssetNetwork are required');
48
48
  }
49
49
  if (!sellToken) {
50
- throw new __1.SwapError('ZrxSwapper:buildQuoteTx One of sellAssetContract or sellAssetSymbol or sellAssetNetwork are required');
50
+ throw new __1.SwapError('ZrxSwapper:ZrxBuildQuoteTx One of sellAssetContract or sellAssetSymbol or sellAssetNetwork are required');
51
51
  }
52
52
  if (buyAsset.chain !== types_1.ChainTypes.Ethereum) {
53
- throw new __1.SwapError(`ZrxSwapper:buildQuoteTx buyAsset must be on chain [${types_1.ChainTypes.Ethereum}]`);
53
+ throw new __1.SwapError(`ZrxSwapper:ZrxBuildQuoteTx buyAsset must be on chain [${types_1.ChainTypes.Ethereum}]`);
54
54
  }
55
55
  const adapter = adapterManager.byChain(buyAsset.chain);
56
56
  const bip32Params = adapter.buildBIP32Params({ accountNumber: Number(buyAssetAccountId) });
57
57
  const receiveAddress = await adapter.getAddress({ wallet, bip32Params });
58
58
  if (new bignumber_js_1.default(slippage || 0).gt(constants_1.MAX_SLIPPAGE)) {
59
- throw new __1.SwapError(`ZrxSwapper:buildQuoteTx slippage value of ${slippage} is greater than max slippage value of ${constants_1.MAX_SLIPPAGE}`);
59
+ throw new __1.SwapError(`ZrxSwapper:ZrxBuildQuoteTx slippage value of ${slippage} is greater than max slippage value of ${constants_1.MAX_SLIPPAGE}`);
60
60
  }
61
61
  const slippagePercentage = slippage
62
62
  ? new bignumber_js_1.default(slippage).div(100).toString()
@@ -161,4 +161,4 @@ async function buildQuoteTx({ adapterManager, web3 }, { input, wallet }) {
161
161
  };
162
162
  }
163
163
  }
164
- exports.buildQuoteTx = buildQuoteTx;
164
+ exports.ZrxBuildQuoteTx = ZrxBuildQuoteTx;
@@ -0,0 +1,3 @@
1
+ import { ChainTypes, ExecQuoteInput, ExecQuoteOutput, SwapperType } from '@shapeshiftoss/types';
2
+ import { ZrxSwapperDeps } from '../ZrxSwapper';
3
+ export declare function ZrxExecuteQuote({ adapterManager }: ZrxSwapperDeps, { quote, wallet }: ExecQuoteInput<ChainTypes.Ethereum, SwapperType>): Promise<ExecQuoteOutput>;
@@ -1,25 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeQuote = void 0;
3
+ exports.ZrxExecuteQuote = void 0;
4
4
  const web3_utils_1 = require("web3-utils");
5
5
  const api_1 = require("../../../api");
6
- async function executeQuote({ adapterManager }, { quote, wallet }) {
6
+ async function ZrxExecuteQuote({ adapterManager }, { quote, wallet }) {
7
7
  var _a, _b, _c, _d, _e, _f;
8
8
  const { sellAsset } = quote;
9
9
  if (!quote.success) {
10
- throw new api_1.SwapError('ZrxSwapper:executeQuote Cannot execute a failed quote');
10
+ throw new api_1.SwapError('ZrxSwapper:ZrxExecuteQuote Cannot execute a failed quote');
11
11
  }
12
12
  if (!sellAsset.network || !sellAsset.symbol) {
13
- throw new api_1.SwapError('ZrxSwapper:executeQuote sellAssetNetwork and sellAssetSymbol are required');
13
+ throw new api_1.SwapError('ZrxSwapper:ZrxExecuteQuote sellAssetNetwork and sellAssetSymbol are required');
14
14
  }
15
15
  if (!quote.sellAssetAccountId) {
16
- throw new api_1.SwapError('ZrxSwapper:executeQuote sellAssetAccountId is required');
16
+ throw new api_1.SwapError('ZrxSwapper:ZrxExecuteQuote sellAssetAccountId is required');
17
17
  }
18
18
  if (!quote.sellAmount) {
19
- throw new api_1.SwapError('ZrxSwapper:executeQuote sellAmount is required');
19
+ throw new api_1.SwapError('ZrxSwapper:ZrxExecuteQuote sellAmount is required');
20
20
  }
21
21
  if (!quote.depositAddress) {
22
- throw new api_1.SwapError('ZrxSwapper:executeQuote depositAddress is required');
22
+ throw new api_1.SwapError('ZrxSwapper:ZrxExecuteQuote depositAddress is required');
23
23
  }
24
24
  // value is 0 for erc20s
25
25
  const value = sellAsset.symbol === 'ETH' ? quote.sellAmount : '0';
@@ -41,7 +41,7 @@ async function executeQuote({ adapterManager }, { quote, wallet }) {
41
41
  });
42
42
  }
43
43
  catch (error) {
44
- throw new api_1.SwapError(`executeQuote - buildSendTransaction error: ${error}`);
44
+ throw new api_1.SwapError(`ZrxExecuteQuote - buildSendTransaction error: ${error}`);
45
45
  }
46
46
  const { txToSign } = buildTxResponse;
47
47
  const txWithQuoteData = { ...txToSign, data: (_e = quote.txData) !== null && _e !== void 0 ? _e : '' };
@@ -50,16 +50,16 @@ async function executeQuote({ adapterManager }, { quote, wallet }) {
50
50
  signedTx = await adapter.signTransaction({ txToSign: txWithQuoteData, wallet });
51
51
  }
52
52
  catch (error) {
53
- throw new api_1.SwapError(`executeQuote - signTransaction error: ${error}`);
53
+ throw new api_1.SwapError(`ZrxExecuteQuote - signTransaction error: ${error}`);
54
54
  }
55
55
  if (!signedTx) {
56
- throw new api_1.SwapError(`executeQuote - Signed transaction is required: ${signedTx}`);
56
+ throw new api_1.SwapError(`ZrxExecuteQuote - Signed transaction is required: ${signedTx}`);
57
57
  }
58
58
  try {
59
59
  txid = await adapter.broadcastTransaction(signedTx);
60
60
  }
61
61
  catch (error) {
62
- throw new api_1.SwapError(`executeQuote - broadcastTransaction error: ${error}`);
62
+ throw new api_1.SwapError(`ZrxExecuteQuote - broadcastTransaction error: ${error}`);
63
63
  }
64
64
  return { txid };
65
65
  }
@@ -68,12 +68,12 @@ async function executeQuote({ adapterManager }, { quote, wallet }) {
68
68
  txid = await ((_f = adapter.signAndBroadcastTransaction) === null || _f === void 0 ? void 0 : _f.call(adapter, { txToSign: txWithQuoteData, wallet }));
69
69
  }
70
70
  catch (error) {
71
- throw new api_1.SwapError(`executeQuote - signAndBroadcastTransaction error: ${error}`);
71
+ throw new api_1.SwapError(`ZrxExecuteQuote - signAndBroadcastTransaction error: ${error}`);
72
72
  }
73
73
  return { txid };
74
74
  }
75
75
  else {
76
- throw new api_1.SwapError('executeQuote - invalid HDWallet config');
76
+ throw new api_1.SwapError('ZrxExecuteQuote - invalid HDWallet config');
77
77
  }
78
78
  }
79
- exports.executeQuote = executeQuote;
79
+ exports.ZrxExecuteQuote = ZrxExecuteQuote;
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZrxSwapper = exports.ZrxError = void 0;
4
4
  const types_1 = require("@shapeshiftoss/types");
5
- const approvalNeeded_1 = require("./approvalNeeded/approvalNeeded");
6
- const approveInfinite_1 = require("./approveInfinite/approveInfinite");
7
- const buildQuoteTx_1 = require("./buildQuoteTx/buildQuoteTx");
8
- const executeQuote_1 = require("./executeQuote/executeQuote");
9
- const getMinMax_1 = require("./getMinMax/getMinMax");
10
- const getQuote_1 = require("./getQuote/getQuote");
11
- const getSendMaxAmount_1 = require("./getSendMaxAmount/getSendMaxAmount");
5
+ const getZrxMinMax_1 = require("./getZrxMinMax/getZrxMinMax");
6
+ const getZrxQuote_1 = require("./getZrxQuote/getZrxQuote");
7
+ const getZrxSendMaxAmount_1 = require("./getZrxSendMaxAmount/getZrxSendMaxAmount");
12
8
  const helpers_1 = require("./utils/helpers/helpers");
9
+ const ZrxApprovalNeeded_1 = require("./ZrxApprovalNeeded/ZrxApprovalNeeded");
10
+ const ZrxApproveInfinite_1 = require("./ZrxApproveInfinite/ZrxApproveInfinite");
11
+ const ZrxBuildQuoteTx_1 = require("./ZrxBuildQuoteTx/ZrxBuildQuoteTx");
12
+ const ZrxExecuteQuote_1 = require("./ZrxExecuteQuote/ZrxExecuteQuote");
13
13
  class ZrxError extends Error {
14
14
  constructor(message) {
15
15
  super(message);
@@ -25,16 +25,16 @@ class ZrxSwapper {
25
25
  return types_1.SwapperType.Zrx;
26
26
  }
27
27
  async buildQuoteTx(args) {
28
- return (0, buildQuoteTx_1.buildQuoteTx)(this.deps, args);
28
+ return (0, ZrxBuildQuoteTx_1.ZrxBuildQuoteTx)(this.deps, args);
29
29
  }
30
30
  async getQuote(input) {
31
- return (0, getQuote_1.getZrxQuote)(input);
31
+ return (0, getZrxQuote_1.getZrxQuote)(input);
32
32
  }
33
33
  async getUsdRate(input) {
34
34
  return (0, helpers_1.getUsdRate)(input);
35
35
  }
36
36
  async getMinMax(input) {
37
- return (0, getMinMax_1.getMinMax)(input);
37
+ return (0, getZrxMinMax_1.getZrxMinMax)(input);
38
38
  }
39
39
  getAvailableAssets(assets) {
40
40
  return assets.filter((asset) => asset.chain === types_1.ChainTypes.Ethereum);
@@ -49,16 +49,16 @@ class ZrxSwapper {
49
49
  return [ETH, FOX];
50
50
  }
51
51
  async executeQuote(args) {
52
- return (0, executeQuote_1.executeQuote)(this.deps, args);
52
+ return (0, ZrxExecuteQuote_1.ZrxExecuteQuote)(this.deps, args);
53
53
  }
54
54
  async approvalNeeded(args) {
55
- return (0, approvalNeeded_1.approvalNeeded)(this.deps, args);
55
+ return (0, ZrxApprovalNeeded_1.ZrxApprovalNeeded)(this.deps, args);
56
56
  }
57
57
  async approveInfinite(args) {
58
- return (0, approveInfinite_1.approveInfinite)(this.deps, args);
58
+ return (0, ZrxApproveInfinite_1.ZrxApproveInfinite)(this.deps, args);
59
59
  }
60
60
  async getSendMaxAmount(args) {
61
- return (0, getSendMaxAmount_1.getSendMaxAmount)(this.deps, args);
61
+ return (0, getZrxSendMaxAmount_1.getZrxSendMaxAmount)(this.deps, args);
62
62
  }
63
63
  }
64
64
  exports.ZrxSwapper = ZrxSwapper;
@@ -0,0 +1,2 @@
1
+ import { GetQuoteInput, MinMaxOutput } from '@shapeshiftoss/types';
2
+ export declare const getZrxMinMax: (input: Pick<GetQuoteInput, 'sellAsset' | 'buyAsset'>) => Promise<MinMaxOutput>;
@@ -3,18 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getMinMax = void 0;
6
+ exports.getZrxMinMax = void 0;
7
7
  const types_1 = require("@shapeshiftoss/types");
8
8
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
9
9
  const constants_1 = require("../utils/constants");
10
10
  const helpers_1 = require("../utils/helpers/helpers");
11
11
  const zrxService_1 = require("../utils/zrxService");
12
12
  const ZrxSwapper_1 = require("../ZrxSwapper");
13
- const getMinMax = async (input) => {
13
+ const getZrxMinMax = async (input) => {
14
14
  var _a;
15
15
  const { sellAsset, buyAsset } = input;
16
16
  if (sellAsset.chain !== types_1.ChainTypes.Ethereum || buyAsset.chain !== types_1.ChainTypes.Ethereum) {
17
- throw new ZrxSwapper_1.ZrxError('getMinMax - must be eth assets');
17
+ throw new ZrxSwapper_1.ZrxError('getZrxMinMax - must be eth assets');
18
18
  }
19
19
  const buyToken = buyAsset.tokenId || buyAsset.symbol;
20
20
  const sellToken = sellAsset.tokenId || sellAsset.symbol;
@@ -40,4 +40,4 @@ const getMinMax = async (input) => {
40
40
  maximum: constants_1.MAX_ZRX_TRADE
41
41
  };
42
42
  };
43
- exports.getMinMax = getMinMax;
43
+ exports.getZrxMinMax = getZrxMinMax;
@@ -0,0 +1,3 @@
1
+ import { SendMaxAmountInput } from '@shapeshiftoss/types';
2
+ import { ZrxSwapperDeps } from '../ZrxSwapper';
3
+ export declare function getZrxSendMaxAmount({ adapterManager }: ZrxSwapperDeps, { wallet, quote, sellAssetAccountId, feeEstimateKey }: SendMaxAmountInput): Promise<string>;
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSendMaxAmount = void 0;
6
+ exports.getZrxSendMaxAmount = void 0;
7
+ const caip_1 = require("@shapeshiftoss/caip");
7
8
  const types_1 = require("@shapeshiftoss/types");
8
9
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
9
10
  const api_1 = require("../../../api");
10
11
  const bignumber_1 = require("../utils/bignumber");
11
12
  const constants_1 = require("../utils/constants");
12
- async function getSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAccountId, feeEstimateKey = types_1.chainAdapters.FeeDataKey.Average }) {
13
+ async function getZrxSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAccountId, feeEstimateKey = types_1.chainAdapters.FeeDataKey.Average }) {
13
14
  var _a, _b, _c;
14
15
  const adapter = adapterManager.byChain(types_1.ChainTypes.Ethereum);
15
16
  const bip32Params = adapter.buildBIP32Params({
@@ -23,7 +24,9 @@ async function getSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAc
23
24
  const tokenId = (_a = quote.sellAsset) === null || _a === void 0 ? void 0 : _a.tokenId;
24
25
  let balance;
25
26
  if (tokenId) {
26
- balance = (_c = (_b = account.chainSpecific.tokens) === null || _b === void 0 ? void 0 : _b.find((token) => token.contract.toLowerCase() === tokenId.toLowerCase())) === null || _c === void 0 ? void 0 : _c.balance;
27
+ balance = (_c = (_b = account.chainSpecific.tokens) === null || _b === void 0 ? void 0 : _b.find((token) => {
28
+ return caip_1.caip19.fromCAIP19(token.caip19).tokenId === tokenId.toLowerCase();
29
+ })) === null || _c === void 0 ? void 0 : _c.balance;
27
30
  }
28
31
  else {
29
32
  balance = account.balance;
@@ -57,4 +60,4 @@ async function getSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAc
57
60
  }
58
61
  return sendMaxAmount.toString();
59
62
  }
60
- exports.getSendMaxAmount = getSendMaxAmount;
63
+ exports.getZrxSendMaxAmount = getZrxSendMaxAmount;
@@ -4,6 +4,7 @@ exports.FOX = exports.WETH = exports.BTC = void 0;
4
4
  const types_1 = require("@shapeshiftoss/types");
5
5
  exports.BTC = {
6
6
  caip19: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
7
+ caip2: 'bip122:000000000019d6689c085ae165831e93',
7
8
  name: 'bitcoin',
8
9
  chain: types_1.ChainTypes.Bitcoin,
9
10
  dataSource: types_1.AssetDataSource.CoinGecko,
@@ -23,6 +24,7 @@ exports.BTC = {
23
24
  };
24
25
  exports.WETH = {
25
26
  caip19: 'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
27
+ caip2: 'eip155:1',
26
28
  name: 'WETH',
27
29
  chain: types_1.ChainTypes.Ethereum,
28
30
  dataSource: types_1.AssetDataSource.CoinGecko,
@@ -43,6 +45,7 @@ exports.WETH = {
43
45
  };
44
46
  exports.FOX = {
45
47
  caip19: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d',
48
+ caip2: 'eip155:1',
46
49
  name: 'FOX',
47
50
  chain: types_1.ChainTypes.Ethereum,
48
51
  dataSource: types_1.AssetDataSource.CoinGecko,
@@ -12,11 +12,16 @@ export declare const chainAdapterMockFuncs: {
12
12
  }>, []>;
13
13
  signTransaction: jest.Mock<Promise<string>, []>;
14
14
  broadcastTransaction: jest.Mock<Promise<string>, []>;
15
+ getInfo: jest.Mock<Promise<{
16
+ data: {
17
+ network: string;
18
+ };
19
+ }>, []>;
15
20
  getAddress: jest.Mock<Promise<string>, []>;
16
21
  getAccount: jest.Mock<Promise<{
17
22
  chainSpecific: {
18
23
  tokens: {
19
- contract: string;
24
+ caip19: string;
20
25
  balance: string;
21
26
  }[];
22
27
  };
@@ -13,9 +13,10 @@ exports.chainAdapterMockFuncs = {
13
13
  buildSendTransaction: jest.fn(() => Promise.resolve({ txToSign: {} })),
14
14
  signTransaction: jest.fn(() => Promise.resolve('signedTx')),
15
15
  broadcastTransaction: jest.fn(() => Promise.resolve('broadcastedTx')),
16
+ getInfo: jest.fn(() => Promise.resolve({ data: { network: 'mainnet' } })),
16
17
  getAddress: jest.fn(() => Promise.resolve('address')),
17
18
  getAccount: jest.fn(() => Promise.resolve({
18
- chainSpecific: { tokens: [{ contract: 'contractAddress', balance: '1000000' }] }
19
+ chainSpecific: { tokens: [{ caip19: 'eip155:1/erc20:contractAddress', balance: '1000000' }] }
19
20
  })),
20
21
  getFeeData: jest.fn(() => Promise.resolve({
21
22
  [types_1.chainAdapters.FeeDataKey.Average]: { txFee: '10000' }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "1.11.11",
3
+ "version": "1.14.0",
4
4
  "description": "TODO: description",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",
@@ -21,16 +21,24 @@
21
21
  "swapcli": "yarn build && node ./dist/swappercli.js"
22
22
  },
23
23
  "dependencies": {
24
- "@shapeshiftoss/chain-adapters": "^1.16.2",
25
- "@shapeshiftoss/hdwallet-core": "^1.18.0",
26
- "@shapeshiftoss/types": "^1.12.0",
27
24
  "axios": "^0.21.4",
28
25
  "bignumber.js": "^9.0.1",
29
26
  "retry-axios": "^2.6.0",
30
27
  "web3": "^1.6.1"
31
28
  },
29
+ "peerDependencies": {
30
+ "@shapeshiftoss/asset-service": "^1.6.1",
31
+ "@shapeshiftoss/caip": "^1.6.1",
32
+ "@shapeshiftoss/chain-adapters": "^1.15.3",
33
+ "@shapeshiftoss/hdwallet-core": "^1.18.2",
34
+ "@shapeshiftoss/types": "^1.13.1"
35
+ },
32
36
  "devDependencies": {
33
37
  "@shapeshiftoss/asset-service": "^1.6.1",
38
+ "@shapeshiftoss/caip": "^1.6.1",
39
+ "@shapeshiftoss/chain-adapters": "^1.16.2",
40
+ "@shapeshiftoss/hdwallet-core": "^1.18.2",
41
+ "@shapeshiftoss/types": "^1.13.1",
34
42
  "@types/readline-sync": "^1.4.4",
35
43
  "readline-sync": "^1.4.10",
36
44
  "web3-utils": "^1.5.2"
@@ -1,3 +0,0 @@
1
- import { ApprovalNeededInput, ApprovalNeededOutput, ChainTypes, SwapperType } from '@shapeshiftoss/types';
2
- import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function approvalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<ChainTypes, SwapperType>): Promise<ApprovalNeededOutput>;
@@ -1,3 +0,0 @@
1
- import { ApproveInfiniteInput, ChainTypes, SwapperType } from '@shapeshiftoss/types';
2
- import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function approveInfinite({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<ChainTypes, SwapperType>): Promise<string>;
@@ -1,3 +0,0 @@
1
- import { BuildQuoteTxInput, ChainTypes, Quote, SwapperType } from '@shapeshiftoss/types';
2
- import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function buildQuoteTx({ adapterManager, web3 }: ZrxSwapperDeps, { input, wallet }: BuildQuoteTxInput): Promise<Quote<ChainTypes, SwapperType>>;
@@ -1,3 +0,0 @@
1
- import { ChainTypes, ExecQuoteInput, ExecQuoteOutput, SwapperType } from '@shapeshiftoss/types';
2
- import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function executeQuote({ adapterManager }: ZrxSwapperDeps, { quote, wallet }: ExecQuoteInput<ChainTypes.Ethereum, SwapperType>): Promise<ExecQuoteOutput>;
@@ -1,2 +0,0 @@
1
- import { GetQuoteInput, MinMaxOutput } from '@shapeshiftoss/types';
2
- export declare const getMinMax: (input: Pick<GetQuoteInput, 'sellAsset' | 'buyAsset'>) => Promise<MinMaxOutput>;
@@ -1,3 +0,0 @@
1
- import { SendMaxAmountInput } from '@shapeshiftoss/types';
2
- import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function getSendMaxAmount({ adapterManager }: ZrxSwapperDeps, { wallet, quote, sellAssetAccountId, feeEstimateKey }: SendMaxAmountInput): Promise<string>;