@shapeshiftoss/swapper 5.1.0 → 5.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.d.ts CHANGED
@@ -79,9 +79,11 @@ export interface TradeQuote<C extends SupportedChainIds> extends TradeBase<C> {
79
79
  maximum: string;
80
80
  }
81
81
  export interface Trade<C extends SupportedChainIds> extends TradeBase<C> {
82
+ receiveAddress: string;
83
+ }
84
+ export interface ZrxTrade<C extends SupportedChainIds> extends Trade<C> {
82
85
  txData: string;
83
86
  depositAddress: string;
84
- receiveAddress: string;
85
87
  }
86
88
  export declare type ExecuteTradeInput<C extends SupportedChainIds> = {
87
89
  trade: Trade<C>;
@@ -14,6 +14,7 @@ export declare class SwapperManager {
14
14
  *
15
15
  * @param swapperType swapper type {SwapperType|string}
16
16
  * @returns {Swapper}
17
+ * @deprecated this will be removed, currently used in swapper tests
17
18
  */
18
19
  getSwapper(swapperType: SwapperType): Swapper;
19
20
  /**
@@ -22,7 +23,7 @@ export declare class SwapperManager {
22
23
  * @returns {SwapperManager}
23
24
  */
24
25
  removeSwapper(swapperType: SwapperType): this;
25
- getBestSwapper(args: ByPairInput): Promise<Swapper>;
26
+ getBestSwapper(args: ByPairInput): Promise<Swapper | undefined>;
26
27
  /**
27
28
  *
28
29
  * @param pair type {GetQuoteInput}
@@ -38,6 +38,7 @@ class SwapperManager {
38
38
  *
39
39
  * @param swapperType swapper type {SwapperType|string}
40
40
  * @returns {Swapper}
41
+ * @deprecated this will be removed, currently used in swapper tests
41
42
  */
42
43
  getSwapper(swapperType) {
43
44
  const swapper = this.swappers.get(swapperType);
@@ -84,7 +84,12 @@ const main = async () => {
84
84
  const manager = new SwapperManager_1.SwapperManager();
85
85
  const zrxSwapper = new ZrxSwapper_1.ZrxSwapper(zrxSwapperDeps);
86
86
  manager.addSwapper(types_1.SwapperType.Zrx, zrxSwapper);
87
- const swapper = manager.getSwapper(types_1.SwapperType.Zrx);
87
+ const swapper = await manager.getBestSwapper({
88
+ sellAssetId: 'eip155:1/slip44:60',
89
+ buyAssetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
90
+ });
91
+ if (!swapper)
92
+ return;
88
93
  const sellAmountBase = toBaseUnit(sellAmount, sellAsset.precision);
89
94
  let quote;
90
95
  try {
@@ -2,7 +2,7 @@ import { AssetId } from '@shapeshiftoss/caip';
2
2
  import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
3
3
  import { ApprovalNeededOutput, Asset, ExecQuoteOutput, GetMinMaxInput, MinMaxOutput, SupportedChainIds, SwapperType } from '@shapeshiftoss/types';
4
4
  import Web3 from 'web3';
5
- import { ApprovalNeededInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, Trade, TradeQuote } from '../../api';
5
+ import { ApprovalNeededInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, TradeQuote, ZrxTrade } from '../../api';
6
6
  export declare type ZrxSwapperDeps = {
7
7
  adapterManager: ChainAdapterManager;
8
8
  web3: Web3;
@@ -12,7 +12,7 @@ export declare class ZrxSwapper implements Swapper {
12
12
  deps: ZrxSwapperDeps;
13
13
  constructor(deps: ZrxSwapperDeps);
14
14
  getType(): SwapperType;
15
- buildTrade(args: BuildTradeInput): Promise<Trade<SupportedChainIds>>;
15
+ buildTrade(args: BuildTradeInput): Promise<ZrxTrade<SupportedChainIds>>;
16
16
  getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
17
17
  getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
18
18
  getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
@@ -4,6 +4,7 @@ exports.ZrxSwapper = void 0;
4
4
  const types_1 = require("@shapeshiftoss/types");
5
5
  const getZrxMinMax_1 = require("./getZrxMinMax/getZrxMinMax");
6
6
  const getZrxTradeQuote_1 = require("./getZrxTradeQuote/getZrxTradeQuote");
7
+ const blacklist_1 = require("./utils/blacklist");
7
8
  const helpers_1 = require("./utils/helpers/helpers");
8
9
  const ZrxApprovalNeeded_1 = require("./ZrxApprovalNeeded/ZrxApprovalNeeded");
9
10
  const ZrxApproveInfinite_1 = require("./ZrxApproveInfinite/ZrxApproveInfinite");
@@ -39,10 +40,12 @@ class ZrxSwapper {
39
40
  }
40
41
  filterBuyAssetsBySellAssetId(args) {
41
42
  const { assetIds = [], sellAssetId } = args;
42
- return assetIds.filter((id) => id.startsWith('eip155:1') && (sellAssetId === null || sellAssetId === void 0 ? void 0 : sellAssetId.startsWith('eip155:1')));
43
+ return assetIds.filter((id) => id.startsWith('eip155:1') &&
44
+ (sellAssetId === null || sellAssetId === void 0 ? void 0 : sellAssetId.startsWith('eip155:1')) &&
45
+ !blacklist_1.UNSUPPORTED_ASSETS.includes(id));
43
46
  }
44
47
  filterAssetIdsBySellable(assetIds = []) {
45
- return assetIds.filter((id) => id.startsWith('eip155:1'));
48
+ return assetIds.filter((id) => id.startsWith('eip155:1') && !blacklist_1.UNSUPPORTED_ASSETS.includes(id));
46
49
  }
47
50
  }
48
51
  exports.ZrxSwapper = ZrxSwapper;
@@ -22,7 +22,7 @@ async function getZrxTradeQuote(input) {
22
22
  const sellToken = sellAsset.tokenId || sellAsset.symbol;
23
23
  const { minimum, maximum } = await (0, getZrxMinMax_1.getZrxMinMax)(sellAsset, buyAsset);
24
24
  const minQuoteSellAmount = (0, bignumber_1.bnOrZero)(minimum).times((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
25
- const normalizedSellAmount = (0, helpers_1.normalizeAmount)((0, bignumber_1.bnOrZero)(sellAmount).eq(0) ? minQuoteSellAmount.toString() : sellAmount);
25
+ const normalizedSellAmount = (0, helpers_1.normalizeAmount)((0, bignumber_1.bnOrZero)(sellAmount).eq(0) ? minQuoteSellAmount : sellAmount);
26
26
  /**
27
27
  * /swap/v1/price
28
28
  * params: {
@@ -0,0 +1 @@
1
+ export declare const UNSUPPORTED_ASSETS: readonly string[];
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNSUPPORTED_ASSETS = void 0;
4
+ // Zrx doesnt have an easily accessible master assets list.
5
+ // We assume all erc20's are supported and remove these explicitely unsupported assets
6
+ exports.UNSUPPORTED_ASSETS = Object.freeze([
7
+ // Foxy token unsupported by zrx
8
+ 'eip155:1/erc20:0xdc49108ce5c57bc3408c3a5e95f3d864ec386ed3'
9
+ ]);
@@ -35,7 +35,7 @@ declare type GrantAllowanceArgs = {
35
35
  * ETH or ERC20, we still keep 7 decimal places.
36
36
  * @param amount
37
37
  */
38
- export declare const normalizeAmount: (amount: string | undefined) => string | undefined;
38
+ export declare const normalizeAmount: (amount: string | number | BigNumber) => string;
39
39
  export declare const getERC20Allowance: ({ erc20AllowanceAbi, web3, tokenId, ownerAddress, spenderAddress }: GetERC20AllowanceArgs) => Promise<any>;
40
40
  export declare const getAllowanceRequired: ({ receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi }: GetAllowanceRequiredArgs) => Promise<BigNumber>;
41
41
  export declare const getUsdRate: (input: Pick<Asset, 'symbol' | 'tokenId'>) => Promise<string>;
@@ -14,8 +14,6 @@ const zrxService_1 = require("../zrxService");
14
14
  * @param amount
15
15
  */
16
16
  const normalizeAmount = (amount) => {
17
- if (!amount)
18
- return;
19
17
  return (0, bignumber_1.bnOrZero)(amount).toNumber().toLocaleString('fullwide', { useGrouping: false });
20
18
  };
21
19
  exports.normalizeAmount = normalizeAmount;
@@ -1,4 +1,4 @@
1
1
  import { SupportedChainIds } from '@shapeshiftoss/types';
2
- import { BuildTradeInput, Trade } from '../../..';
2
+ import { BuildTradeInput, ZrxTrade } from '../../..';
3
3
  import { ZrxSwapperDeps } from '../ZrxSwapper';
4
- export declare function zrxBuildTrade({ adapterManager, web3 }: ZrxSwapperDeps, input: BuildTradeInput): Promise<Trade<SupportedChainIds>>;
4
+ export declare function zrxBuildTrade({ adapterManager, web3 }: ZrxSwapperDeps, input: BuildTradeInput): Promise<ZrxTrade<SupportedChainIds>>;
@@ -77,7 +77,7 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
77
77
  params: {
78
78
  buyToken,
79
79
  sellToken,
80
- sellAmount: (0, helpers_1.normalizeAmount)(sellAmount === null || sellAmount === void 0 ? void 0 : sellAmount.toString()),
80
+ sellAmount: (0, helpers_1.normalizeAmount)(sellAmount),
81
81
  takerAddress: receiveAddress,
82
82
  slippagePercentage,
83
83
  skipValidation: false,
@@ -6,7 +6,8 @@ const api_1 = require("../../../api");
6
6
  const bignumber_1 = require("../utils/bignumber");
7
7
  async function zrxExecuteTrade({ adapterManager }, { trade, wallet }) {
8
8
  var _a, _b, _c, _d, _e, _f;
9
- const { sellAsset } = trade;
9
+ const zrxTrade = trade;
10
+ const { sellAsset } = zrxTrade;
10
11
  try {
11
12
  // value is 0 for erc20s
12
13
  const value = sellAsset.assetId === 'eip155:1/slip44:60' ? trade.sellAmount : '0';
@@ -17,7 +18,7 @@ async function zrxExecuteTrade({ adapterManager }, { trade, wallet }) {
17
18
  const buildTxResponse = await adapter.buildSendTransaction({
18
19
  value,
19
20
  wallet,
20
- to: trade.depositAddress,
21
+ to: zrxTrade.depositAddress,
21
22
  chainSpecific: {
22
23
  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),
23
24
  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)
@@ -25,7 +26,7 @@ async function zrxExecuteTrade({ adapterManager }, { trade, wallet }) {
25
26
  bip44Params
26
27
  });
27
28
  const { txToSign } = buildTxResponse;
28
- const txWithQuoteData = { ...txToSign, data: (_e = trade.txData) !== null && _e !== void 0 ? _e : '' };
29
+ const txWithQuoteData = { ...txToSign, data: (_e = zrxTrade.txData) !== null && _e !== void 0 ? _e : '' };
29
30
  if (wallet.supportsOfflineSigning()) {
30
31
  const signedTx = await adapter.signTransaction({ txToSign: txWithQuoteData, wallet });
31
32
  const txid = await adapter.broadcastTransaction(signedTx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "5.1.0",
3
+ "version": "5.1.3",
4
4
  "description": "TODO: description",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",