@shapeshiftoss/swapper 7.0.0 → 7.1.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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CowSwapper = void 0;
4
4
  const api_1 = require("../../api");
5
+ const blacklist_1 = require("./utils/blacklist");
5
6
  const helpers_1 = require("./utils/helpers/helpers");
6
7
  class CowSwapper {
7
8
  constructor(deps) {
@@ -36,12 +37,16 @@ class CowSwapper {
36
37
  throw new Error('CowSwapper: approveInfinite unimplemented');
37
38
  }
38
39
  filterBuyAssetsBySellAssetId(args) {
39
- console.info(args);
40
- return [];
40
+ const { assetIds = [], sellAssetId } = args;
41
+ if (!(sellAssetId === null || sellAssetId === void 0 ? void 0 : sellAssetId.startsWith('eip155:1/erc20')) ||
42
+ blacklist_1.COWSWAP_UNSUPPORTED_ASSETS.includes(sellAssetId))
43
+ return [];
44
+ return assetIds.filter((id) => id !== sellAssetId &&
45
+ id.startsWith('eip155:1/erc20') &&
46
+ !blacklist_1.COWSWAP_UNSUPPORTED_ASSETS.includes(id));
41
47
  }
42
48
  filterAssetIdsBySellable(assetIds) {
43
- console.info(assetIds);
44
- return [];
49
+ return assetIds.filter((id) => id.startsWith('eip155:1/erc20') && !blacklist_1.COWSWAP_UNSUPPORTED_ASSETS.includes(id));
45
50
  }
46
51
  async getTradeTxs() {
47
52
  throw new Error('CowSwapper: executeTrade unimplemented');
@@ -0,0 +1,4 @@
1
+ import { Asset } from '@shapeshiftoss/types';
2
+ import { MinMaxOutput } from '../../../api';
3
+ import { CowSwapperDeps } from '../CowSwapper';
4
+ export declare const getCowSwapMinMax: (deps: CowSwapperDeps, sellAsset: Asset, buyAsset: Asset) => Promise<MinMaxOutput>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCowSwapMinMax = void 0;
4
+ const api_1 = require("../../../api");
5
+ const bignumber_1 = require("../../utils/bignumber");
6
+ const constants_1 = require("../utils/constants");
7
+ const helpers_1 = require("../utils/helpers/helpers");
8
+ const getCowSwapMinMax = async (deps, sellAsset, buyAsset) => {
9
+ try {
10
+ if (!sellAsset.assetId.startsWith('eip155:1/erc20') ||
11
+ !buyAsset.assetId.startsWith('eip155:1/erc20')) {
12
+ throw new api_1.SwapError('[getCowSwapMinMax]', { code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR });
13
+ }
14
+ const usdRate = await (0, helpers_1.getUsdRate)(deps, sellAsset);
15
+ const minimum = (0, bignumber_1.bn)(1).dividedBy((0, bignumber_1.bnOrZero)(usdRate)).toString(); // $1 worth of the sell token.
16
+ const maximum = constants_1.MAX_COWSWAP_TRADE; // Arbitrarily large value. 10e+28 here.
17
+ return {
18
+ minimum,
19
+ maximum
20
+ };
21
+ }
22
+ catch (e) {
23
+ if (e instanceof api_1.SwapError)
24
+ throw e;
25
+ throw new api_1.SwapError('[getCowSwapMinMax]', { cause: e, code: api_1.SwapErrorTypes.MIN_MAX_FAILED });
26
+ }
27
+ };
28
+ exports.getCowSwapMinMax = getCowSwapMinMax;
@@ -0,0 +1 @@
1
+ export declare const COWSWAP_UNSUPPORTED_ASSETS: readonly string[];
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COWSWAP_UNSUPPORTED_ASSETS = void 0;
4
+ // CowSwap doesnt have an easily accessible master assets list.
5
+ // We assume all erc20's are supported and remove these explicitely unsupported assets
6
+ exports.COWSWAP_UNSUPPORTED_ASSETS = Object.freeze([
7
+ // Foxy token unsupported by cowswap
8
+ 'eip155:1/erc20:0xdc49108ce5c57bc3408c3a5e95f3d864ec386ed3'
9
+ ]);
@@ -0,0 +1 @@
1
+ export declare const MAX_COWSWAP_TRADE = "100000000000000000000000000";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_COWSWAP_TRADE = void 0;
4
+ exports.MAX_COWSWAP_TRADE = '100000000000000000000000000';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "7.0.0",
3
+ "version": "7.1.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",