@shapeshiftoss/swapper 5.1.5 → 5.2.2

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;
@@ -90,11 +90,7 @@ export declare type ExecuteTradeInput<C extends SupportedChainIds> = {
90
90
  wallet: HDWallet;
91
91
  };
92
92
  export declare type TradeResult = {
93
- txid: string;
94
- };
95
- export declare type SwapSource = {
96
- name: string;
97
- proportion: string;
93
+ tradeId: string;
98
94
  };
99
95
  export declare type ApproveInfiniteInput<C extends SupportedChainIds> = {
100
96
  quote: TradeQuote<C>;
@@ -104,6 +100,32 @@ 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
+ }
125
+ export declare type TradeTxs = {
126
+ sellTxid: string;
127
+ buyTxid?: string;
128
+ };
107
129
  export declare enum SwapErrorTypes {
108
130
  ALLOWANCE_REQUIRED_FAILED = "ALLOWANCE_REQUIRED_FAILED",
109
131
  APPROVE_INFINITE_FAILED = "APPROVE_INFINITE_FAILED",
@@ -122,6 +144,8 @@ export declare enum SwapErrorTypes {
122
144
  VALIDATION_FAILED = "VALIDATION_FAILED"
123
145
  }
124
146
  export interface Swapper {
147
+ /** perform any necessary async initialization */
148
+ initialize(): Promise<void>;
125
149
  /** Returns the swapper type */
126
150
  getType(): SwapperType;
127
151
  /**
@@ -143,7 +167,7 @@ export interface Swapper {
143
167
  /**
144
168
  * Execute a trade built with buildTrade by signing and broadcasting
145
169
  */
146
- executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<ExecQuoteOutput>;
170
+ executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
147
171
  /**
148
172
  * Get a boolean if a quote needs approval
149
173
  */
@@ -160,5 +184,6 @@ export interface Swapper {
160
184
  * Get supported sell assetIds
161
185
  */
162
186
  filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
187
+ getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
163
188
  }
164
189
  export {};
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, TradeTxs } 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,6 @@ 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>;
22
+ getTradeTxs(): Promise<TradeTxs>;
21
23
  }
@@ -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);
@@ -49,5 +52,8 @@ class TestSwapper {
49
52
  async executeTrade() {
50
53
  throw new Error('TestSwapper: executeTrade unimplemented');
51
54
  }
55
+ async getTradeTxs() {
56
+ throw new Error('TestSwapper: executeTrade unimplemented');
57
+ }
52
58
  }
53
59
  exports.TestSwapper = TestSwapper;
@@ -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, TradeTxs } 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,6 @@ 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>;
16
+ getTradeTxs(): Promise<TradeTxs>;
15
17
  }
@@ -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');
@@ -35,5 +38,8 @@ class ThorchainSwapper {
35
38
  async executeTrade() {
36
39
  throw new Error('ThorchainSwapper: executeTrade unimplemented');
37
40
  }
41
+ async getTradeTxs() {
42
+ throw new Error('ThorchainSwapper: executeTrade unimplemented');
43
+ }
38
44
  }
39
45
  exports.ThorchainSwapper = ThorchainSwapper;
@@ -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, TradeTxs, ZrxTrade } from '../../api';
6
6
  export declare type ZrxSwapperDeps = {
7
7
  adapterManager: ChainAdapterManager;
8
8
  web3: Web3;
@@ -11,14 +11,16 @@ 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[];
23
24
  filterAssetIdsBySellable(assetIds?: AssetId[]): AssetId[];
25
+ getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
24
26
  }
@@ -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);
@@ -47,6 +50,12 @@ class ZrxSwapper {
47
50
  filterAssetIdsBySellable(assetIds = []) {
48
51
  return assetIds.filter((id) => id.startsWith('eip155:1') && !blacklist_1.UNSUPPORTED_ASSETS.includes(id));
49
52
  }
53
+ async getTradeTxs(tradeResult) {
54
+ return {
55
+ sellTxid: tradeResult.tradeId,
56
+ buyTxid: tradeResult.tradeId
57
+ };
58
+ }
50
59
  }
51
60
  exports.ZrxSwapper = ZrxSwapper;
52
61
  ZrxSwapper.swapperName = 'ZrxSwapper';
@@ -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>;
@@ -30,14 +30,14 @@ async function zrxExecuteTrade({ adapterManager }, { trade, wallet }) {
30
30
  if (wallet.supportsOfflineSigning()) {
31
31
  const signedTx = await adapter.signTransaction({ txToSign: txWithQuoteData, wallet });
32
32
  const txid = await adapter.broadcastTransaction(signedTx);
33
- return { txid };
33
+ return { tradeId: txid };
34
34
  }
35
35
  else if (wallet.supportsBroadcast() && adapter.signAndBroadcastTransaction) {
36
36
  const txid = await ((_f = adapter.signAndBroadcastTransaction) === null || _f === void 0 ? void 0 : _f.call(adapter, {
37
37
  txToSign: txWithQuoteData,
38
38
  wallet
39
39
  }));
40
- return { txid };
40
+ return { tradeId: txid };
41
41
  }
42
42
  else {
43
43
  throw new api_1.SwapError('[zrxExecuteTrade]', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "5.1.5",
3
+ "version": "5.2.2",
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",
33
+ "@shapeshiftoss/asset-service": "^4.2.4",
34
34
  "@shapeshiftoss/caip": "^5.0.0",
35
- "@shapeshiftoss/chain-adapters": "^4.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",
41
+ "@shapeshiftoss/asset-service": "^4.2.4",
42
42
  "@shapeshiftoss/caip": "^5.0.0",
43
- "@shapeshiftoss/chain-adapters": "^4.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",