@shapeshiftoss/swapper 5.1.4 → 5.2.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.
package/dist/api.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
2
  import { HDWallet } from '@shapeshiftoss/hdwallet-core';
3
- import { ApprovalNeededOutput, Asset, ChainSpecific, ExecQuoteOutput, GetMinMaxInput, MinMaxOutput, SupportedChainIds, SwapperType } from '@shapeshiftoss/types';
3
+ import { Asset, ChainSpecific, SupportedChainIds } from '@shapeshiftoss/types';
4
4
  export declare const SwapError: {
5
5
  new <V extends {
6
6
  cause?: unknown;
@@ -92,10 +92,6 @@ export declare type ExecuteTradeInput<C extends SupportedChainIds> = {
92
92
  export declare type TradeResult = {
93
93
  txid: string;
94
94
  };
95
- export declare type SwapSource = {
96
- name: string;
97
- proportion: string;
98
- };
99
95
  export declare type ApproveInfiniteInput<C extends SupportedChainIds> = {
100
96
  quote: TradeQuote<C>;
101
97
  wallet: HDWallet;
@@ -104,6 +100,28 @@ export declare type ApprovalNeededInput<C extends SupportedChainIds> = {
104
100
  quote: TradeQuote<C>;
105
101
  wallet: HDWallet;
106
102
  };
103
+ export declare type SwapSource = {
104
+ name: string;
105
+ proportion: string;
106
+ };
107
+ export interface MinMaxOutput {
108
+ minimum: string;
109
+ maximum: string;
110
+ }
111
+ export declare type GetMinMaxInput = {
112
+ sellAsset: Asset;
113
+ buyAsset: Asset;
114
+ };
115
+ export declare type ApprovalNeededOutput = {
116
+ approvalNeeded: boolean;
117
+ gas?: string;
118
+ gasPrice?: string;
119
+ };
120
+ export declare enum SwapperType {
121
+ Zrx = "0x",
122
+ Thorchain = "Thorchain",
123
+ Test = "Test"
124
+ }
107
125
  export declare enum SwapErrorTypes {
108
126
  ALLOWANCE_REQUIRED_FAILED = "ALLOWANCE_REQUIRED_FAILED",
109
127
  APPROVE_INFINITE_FAILED = "APPROVE_INFINITE_FAILED",
@@ -122,6 +140,8 @@ export declare enum SwapErrorTypes {
122
140
  VALIDATION_FAILED = "VALIDATION_FAILED"
123
141
  }
124
142
  export interface Swapper {
143
+ /** perform any necessary async initialization */
144
+ initialize(): Promise<void>;
125
145
  /** Returns the swapper type */
126
146
  getType(): SwapperType;
127
147
  /**
@@ -143,7 +163,7 @@ export interface Swapper {
143
163
  /**
144
164
  * Execute a trade built with buildTrade by signing and broadcasting
145
165
  */
146
- executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<ExecQuoteOutput>;
166
+ executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
147
167
  /**
148
168
  * Get a boolean if a quote needs approval
149
169
  */
package/dist/api.js CHANGED
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwapErrorTypes = exports.SwapError = void 0;
3
+ exports.SwapErrorTypes = exports.SwapperType = exports.SwapError = void 0;
4
4
  const errors_1 = require("@shapeshiftoss/errors");
5
5
  exports.SwapError = (0, errors_1.createErrorClass)('SwapError');
6
+ var SwapperType;
7
+ (function (SwapperType) {
8
+ SwapperType["Zrx"] = "0x";
9
+ SwapperType["Thorchain"] = "Thorchain";
10
+ SwapperType["Test"] = "Test";
11
+ })(SwapperType = exports.SwapperType || (exports.SwapperType = {}));
6
12
  // Swap Errors
7
13
  var SwapErrorTypes;
8
14
  (function (SwapErrorTypes) {
@@ -1,5 +1,5 @@
1
- import { SwapperType } from '@shapeshiftoss/types';
2
1
  import { BuyAssetBySellIdInput, ByPairInput, SupportedSellAssetsInput, Swapper } from '..';
2
+ import { SwapperType } from '../api';
3
3
  export declare class SwapperManager {
4
4
  swappers: Map<SwapperType, Swapper>;
5
5
  constructor();
@@ -11,6 +11,7 @@ const bignumber_js_1 = __importDefault(require("bignumber.js"));
11
11
  const dotenv_1 = __importDefault(require("dotenv"));
12
12
  const readline_sync_1 = __importDefault(require("readline-sync"));
13
13
  const web3_1 = __importDefault(require("web3"));
14
+ const api_1 = require("./api");
14
15
  const SwapperManager_1 = require("./manager/SwapperManager");
15
16
  const ZrxSwapper_1 = require("./swappers/zrx/ZrxSwapper");
16
17
  dotenv_1.default.config();
@@ -83,7 +84,7 @@ const main = async () => {
83
84
  const zrxSwapperDeps = { wallet, adapterManager, web3 };
84
85
  const manager = new SwapperManager_1.SwapperManager();
85
86
  const zrxSwapper = new ZrxSwapper_1.ZrxSwapper(zrxSwapperDeps);
86
- manager.addSwapper(types_1.SwapperType.Zrx, zrxSwapper);
87
+ manager.addSwapper(api_1.SwapperType.Zrx, zrxSwapper);
87
88
  const swapper = await manager.getBestSwapper({
88
89
  sellAssetId: 'eip155:1/slip44:60',
89
90
  buyAssetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
@@ -1,12 +1,13 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
- import { ApprovalNeededOutput, Asset, ExecQuoteOutput, GetMinMaxInput, MinMaxOutput, SupportedChainIds, SwapperType } from '@shapeshiftoss/types';
3
- import { BuyAssetBySellIdInput, Swapper, Trade, TradeQuote } from '../../api';
2
+ import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
3
+ import { ApprovalNeededOutput, BuyAssetBySellIdInput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult } from '../../api';
4
4
  /**
5
5
  * Playground for testing different scenarios of multiple swappers in the manager.
6
6
  * Meant for local testing only
7
7
  */
8
8
  export declare class TestSwapper implements Swapper {
9
9
  supportAssets: string[];
10
+ initialize(): Promise<void>;
10
11
  getType(): SwapperType;
11
12
  constructor();
12
13
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
@@ -17,5 +18,5 @@ export declare class TestSwapper implements Swapper {
17
18
  filterAssetIdsBySellable(): AssetId[];
18
19
  buildTrade(): Promise<Trade<SupportedChainIds>>;
19
20
  getTradeQuote(): Promise<TradeQuote<SupportedChainIds>>;
20
- executeTrade(): Promise<ExecQuoteOutput>;
21
+ executeTrade(): Promise<TradeResult>;
21
22
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TestSwapper = void 0;
4
- const types_1 = require("@shapeshiftoss/types");
4
+ const api_1 = require("../../api");
5
5
  /**
6
6
  * Playground for testing different scenarios of multiple swappers in the manager.
7
7
  * Meant for local testing only
@@ -14,8 +14,11 @@ class TestSwapper {
14
14
  'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
15
15
  ];
16
16
  }
17
+ // noop for test
18
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
19
+ async initialize() { }
17
20
  getType() {
18
- return types_1.SwapperType.Test;
21
+ return api_1.SwapperType.Test;
19
22
  }
20
23
  getUsdRate(input) {
21
24
  console.info(input);
@@ -1,8 +1,9 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
- import { ApprovalNeededOutput, Asset, ExecQuoteOutput, GetMinMaxInput, MinMaxOutput, SupportedChainIds, SwapperType } from '@shapeshiftoss/types';
3
- import { Swapper, Trade, TradeQuote } from '../../api';
2
+ import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
3
+ import { ApprovalNeededOutput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult } from '../../api';
4
4
  export declare class ThorchainSwapper implements Swapper {
5
5
  getType(): SwapperType;
6
+ initialize(): Promise<void>;
6
7
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
7
8
  getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
8
9
  approvalNeeded(): Promise<ApprovalNeededOutput>;
@@ -11,5 +12,5 @@ export declare class ThorchainSwapper implements Swapper {
11
12
  filterAssetIdsBySellable(): AssetId[];
12
13
  buildTrade(): Promise<Trade<SupportedChainIds>>;
13
14
  getTradeQuote(): Promise<TradeQuote<SupportedChainIds>>;
14
- executeTrade(): Promise<ExecQuoteOutput>;
15
+ executeTrade(): Promise<TradeResult>;
15
16
  }
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ThorchainSwapper = void 0;
4
- const types_1 = require("@shapeshiftoss/types");
4
+ const api_1 = require("../../api");
5
5
  class ThorchainSwapper {
6
6
  getType() {
7
- return types_1.SwapperType.Thorchain;
7
+ return api_1.SwapperType.Thorchain;
8
8
  }
9
+ // TODO populate supported assets from midgard
10
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
11
+ async initialize() { }
9
12
  getUsdRate(input) {
10
13
  console.info(input);
11
14
  throw new Error('ThorchainSwapper: getUsdRate unimplemented');
@@ -1,4 +1,4 @@
1
- import { ApprovalNeededOutput, SupportedChainIds } from '@shapeshiftoss/types';
2
- import { ApprovalNeededInput } from '../../../api';
1
+ import { SupportedChainIds } from '@shapeshiftoss/types';
2
+ import { ApprovalNeededInput, ApprovalNeededOutput } from '../../../api';
3
3
  import { ZrxSwapperDeps } from '../ZrxSwapper';
4
4
  export declare function ZrxApprovalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
@@ -1,8 +1,8 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
2
  import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
3
- import { ApprovalNeededOutput, Asset, ExecQuoteOutput, GetMinMaxInput, MinMaxOutput, SupportedChainIds, SwapperType } from '@shapeshiftoss/types';
3
+ import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
4
4
  import Web3 from 'web3';
5
- import { ApprovalNeededInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, TradeQuote, ZrxTrade } from '../../api';
5
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetMinMaxInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, TradeQuote, TradeResult, ZrxTrade } from '../../api';
6
6
  export declare type ZrxSwapperDeps = {
7
7
  adapterManager: ChainAdapterManager;
8
8
  web3: Web3;
@@ -11,12 +11,13 @@ export declare class ZrxSwapper implements Swapper {
11
11
  static swapperName: string;
12
12
  deps: ZrxSwapperDeps;
13
13
  constructor(deps: ZrxSwapperDeps);
14
+ initialize(): Promise<void>;
14
15
  getType(): SwapperType;
15
16
  buildTrade(args: BuildTradeInput): Promise<ZrxTrade<SupportedChainIds>>;
16
17
  getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
17
18
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
18
19
  getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
19
- executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<ExecQuoteOutput>;
20
+ executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
20
21
  approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
21
22
  approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
22
23
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZrxSwapper = void 0;
4
- const types_1 = require("@shapeshiftoss/types");
4
+ const api_1 = require("../../api");
5
5
  const getZrxMinMax_1 = require("./getZrxMinMax/getZrxMinMax");
6
6
  const getZrxTradeQuote_1 = require("./getZrxTradeQuote/getZrxTradeQuote");
7
7
  const blacklist_1 = require("./utils/blacklist");
@@ -14,8 +14,11 @@ class ZrxSwapper {
14
14
  constructor(deps) {
15
15
  this.deps = deps;
16
16
  }
17
+ // noop for zrx
18
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
19
+ async initialize() { }
17
20
  getType() {
18
- return types_1.SwapperType.Zrx;
21
+ return api_1.SwapperType.Zrx;
19
22
  }
20
23
  async buildTrade(args) {
21
24
  return (0, zrxBuildTrade_1.zrxBuildTrade)(this.deps, args);
@@ -1,2 +1,3 @@
1
- import { Asset, MinMaxOutput } from '@shapeshiftoss/types';
1
+ import { Asset } from '@shapeshiftoss/types';
2
+ import { MinMaxOutput } from '../../../api';
2
3
  export declare const getZrxMinMax: (sellAsset: Asset, buyAsset: Asset) => Promise<MinMaxOutput>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "5.1.4",
3
+ "version": "5.2.1",
4
4
  "description": "TODO: description",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",
@@ -30,19 +30,19 @@
30
30
  "web3": "^1.6.1"
31
31
  },
32
32
  "peerDependencies": {
33
- "@shapeshiftoss/asset-service": "^3.0.0",
34
- "@shapeshiftoss/caip": "^4.0.1",
35
- "@shapeshiftoss/chain-adapters": "^4.0.0",
33
+ "@shapeshiftoss/asset-service": "^4.2.4",
34
+ "@shapeshiftoss/caip": "^5.0.0",
35
+ "@shapeshiftoss/chain-adapters": "^4.3.3",
36
36
  "@shapeshiftoss/hdwallet-core": "1.20.0",
37
- "@shapeshiftoss/types": "^4.0.0",
37
+ "@shapeshiftoss/types": "^4.3.1",
38
38
  "@shapeshiftoss/errors": "^1.1.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@shapeshiftoss/asset-service": "^3.0.0",
42
- "@shapeshiftoss/caip": "^4.0.1",
43
- "@shapeshiftoss/chain-adapters": "^4.0.0",
41
+ "@shapeshiftoss/asset-service": "^4.2.4",
42
+ "@shapeshiftoss/caip": "^5.0.0",
43
+ "@shapeshiftoss/chain-adapters": "^4.3.3",
44
44
  "@shapeshiftoss/hdwallet-core": "^1.20.0",
45
- "@shapeshiftoss/types": "^4.1.0",
45
+ "@shapeshiftoss/types": "^4.3.1",
46
46
  "@shapeshiftoss/errors": "^1.1.0",
47
47
  "@types/readline-sync": "^1.4.4",
48
48
  "readline-sync": "^1.4.10",