@shapeshiftoss/swapper 6.3.0 → 7.0.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/api.d.ts +24 -27
  2. package/dist/manager/SwapperManager.d.ts +6 -5
  3. package/dist/swappercli.js +34 -17
  4. package/dist/swappers/cow/CowSwapper.d.ts +8 -8
  5. package/dist/swappers/test/TestSwapper.d.ts +5 -5
  6. package/dist/swappers/thorchain/ThorchainSwapper.d.ts +6 -6
  7. package/dist/swappers/thorchain/ThorchainSwapper.js +6 -3
  8. package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.d.ts +2 -2
  9. package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +9 -5
  10. package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.js +7 -1
  11. package/dist/swappers/utils/test-data/assets.js +0 -13
  12. package/dist/swappers/zrx/ZrxApprovalNeeded/ZrxApprovalNeeded.d.ts +1 -1
  13. package/dist/swappers/zrx/ZrxApprovalNeeded/ZrxApprovalNeeded.js +1 -2
  14. package/dist/swappers/zrx/ZrxApproveInfinite/ZrxApproveInfinite.d.ts +1 -2
  15. package/dist/swappers/zrx/ZrxApproveInfinite/ZrxApproveInfinite.js +2 -2
  16. package/dist/swappers/zrx/ZrxSwapper.d.ts +7 -7
  17. package/dist/swappers/zrx/utils/helpers/helpers.d.ts +5 -5
  18. package/dist/swappers/zrx/utils/helpers/helpers.js +1 -2
  19. package/dist/swappers/zrx/utils/test-data/setupZrxDeps.d.ts +3 -29
  20. package/dist/swappers/zrx/utils/test-data/setupZrxDeps.js +34 -32
  21. package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.d.ts +1 -2
  22. package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +6 -8
  23. package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.d.ts +1 -1
  24. package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +1 -2
  25. package/package.json +10 -10
package/dist/api.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { AssetId } from '@shapeshiftoss/caip';
1
+ import { AssetId, ChainId } from '@shapeshiftoss/caip';
2
2
  import { BTCSignTx, ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
3
- import { Asset, ChainSpecific, SupportedChainIds } from '@shapeshiftoss/types';
3
+ import { Asset, ChainSpecific, KnownChainIds } from '@shapeshiftoss/types';
4
4
  export declare const SwapError: {
5
5
  new <V extends {
6
6
  cause?: unknown;
@@ -23,10 +23,7 @@ export declare const SwapError: {
23
23
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
24
24
  stackTraceLimit: number;
25
25
  };
26
- export declare type SupportedAssetInput = {
27
- assetIds: AssetId[];
28
- };
29
- declare type ChainSpecificQuoteFeeData<T1> = ChainSpecific<T1, {
26
+ declare type ChainSpecificQuoteFeeData<T extends ChainId> = ChainSpecific<T, {
30
27
  'eip155:1': {
31
28
  estimatedGas?: string;
32
29
  gasPrice?: string;
@@ -38,10 +35,10 @@ declare type ChainSpecificQuoteFeeData<T1> = ChainSpecific<T1, {
38
35
  satsPerByte: string;
39
36
  };
40
37
  }>;
41
- export declare type QuoteFeeData<T1 extends SupportedChainIds> = {
38
+ export declare type QuoteFeeData<T extends ChainId> = {
42
39
  fee: string;
43
40
  tradeFee: string;
44
- } & ChainSpecificQuoteFeeData<T1>;
41
+ } & ChainSpecificQuoteFeeData<T>;
45
42
  export declare type ByPairInput = {
46
43
  sellAssetId: AssetId;
47
44
  buyAssetId: AssetId;
@@ -67,7 +64,7 @@ export declare type BuildTradeInput = CommonTradeInput & {
67
64
  slippage?: string;
68
65
  wallet: HDWallet;
69
66
  };
70
- interface TradeBase<C extends SupportedChainIds> {
67
+ interface TradeBase<C extends ChainId> {
71
68
  buyAmount: string;
72
69
  sellAmount: string;
73
70
  feeData: QuoteFeeData<C>;
@@ -77,39 +74,39 @@ interface TradeBase<C extends SupportedChainIds> {
77
74
  sellAsset: Asset;
78
75
  sellAssetAccountNumber: number;
79
76
  }
80
- export interface TradeQuote<C extends SupportedChainIds> extends TradeBase<C> {
77
+ export interface TradeQuote<C extends ChainId> extends TradeBase<C> {
81
78
  allowanceContract: string;
82
79
  minimum: string;
83
80
  maximum: string;
84
81
  }
85
- export interface Trade<C extends SupportedChainIds> extends TradeBase<C> {
82
+ export interface Trade<C extends ChainId> extends TradeBase<C> {
86
83
  receiveAddress: string;
87
84
  }
88
- export interface ZrxTrade<C extends SupportedChainIds> extends Trade<C> {
85
+ export interface ZrxTrade extends Trade<'eip155:1'> {
89
86
  txData: string;
90
87
  depositAddress: string;
91
88
  }
92
- export interface BtcThorTrade<C extends SupportedChainIds> extends Trade<C> {
93
- chainId: 'bip122:000000000019d6689c085ae165831e93';
89
+ export interface BtcThorTrade<C extends ChainId> extends Trade<C> {
90
+ chainId: KnownChainIds.BitcoinMainnet;
94
91
  txData: BTCSignTx;
95
92
  }
96
- export interface EthThorTrade<C extends SupportedChainIds> extends Trade<C> {
97
- chainId: 'eip155:1';
93
+ export interface EthThorTrade<C extends ChainId> extends Trade<C> {
94
+ chainId: KnownChainIds.EthereumMainnet;
98
95
  txData: ETHSignTx;
99
96
  }
100
- export declare type ThorTrade<C extends SupportedChainIds> = BtcThorTrade<C> | EthThorTrade<C>;
101
- export declare type ExecuteTradeInput<C extends SupportedChainIds> = {
97
+ export declare type ThorTrade<C extends ChainId> = BtcThorTrade<C> | EthThorTrade<C>;
98
+ export declare type ExecuteTradeInput<C extends ChainId> = {
102
99
  trade: Trade<C>;
103
100
  wallet: HDWallet;
104
101
  };
105
102
  export declare type TradeResult = {
106
103
  tradeId: string;
107
104
  };
108
- export declare type ApproveInfiniteInput<C extends SupportedChainIds> = {
105
+ export declare type ApproveInfiniteInput<C extends ChainId> = {
109
106
  quote: TradeQuote<C>;
110
107
  wallet: HDWallet;
111
108
  };
112
- export declare type ApprovalNeededInput<C extends SupportedChainIds> = {
109
+ export declare type ApprovalNeededInput<C extends ChainId> = {
113
110
  quote: TradeQuote<C>;
114
111
  wallet: HDWallet;
115
112
  };
@@ -159,7 +156,7 @@ export declare enum SwapErrorTypes {
159
156
  PRICE_RATIO_FAILED = "PRICE_RATIO_FAILED",
160
157
  POOL_NOT_FOUND = "POOL_NOT_FOUND"
161
158
  }
162
- export interface Swapper {
159
+ export interface Swapper<T extends ChainId, TxType = unknown> {
163
160
  /** perform any necessary async initialization */
164
161
  initialize(): Promise<void>;
165
162
  /** Returns the swapper type */
@@ -167,11 +164,11 @@ export interface Swapper {
167
164
  /**
168
165
  * Get builds a trade with definitive rate & txData that can be executed with executeTrade
169
166
  **/
170
- buildTrade(args: BuildTradeInput): Promise<Trade<SupportedChainIds>>;
167
+ buildTrade(args: BuildTradeInput): Promise<Trade<T>>;
171
168
  /**
172
169
  * Get a trade quote
173
170
  */
174
- getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
171
+ getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<T>>;
175
172
  /**
176
173
  * Get the usd rate from either the assets symbol or tokenId
177
174
  */
@@ -179,15 +176,15 @@ export interface Swapper {
179
176
  /**
180
177
  * Execute a trade built with buildTrade by signing and broadcasting
181
178
  */
182
- executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
179
+ executeTrade(args: ExecuteTradeInput<T>): Promise<TradeResult>;
183
180
  /**
184
181
  * Get a boolean if a quote needs approval
185
182
  */
186
- approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
183
+ approvalNeeded(args: ApprovalNeededInput<T>): Promise<ApprovalNeededOutput>;
187
184
  /**
188
185
  * Get the txid of an approve infinite transaction
189
186
  */
190
- approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
187
+ approveInfinite(args: ApproveInfiniteInput<T>): Promise<string>;
191
188
  /**
192
189
  * Get supported buyAssetId's by sellAssetId
193
190
  */
@@ -196,6 +193,6 @@ export interface Swapper {
196
193
  * Get supported sell assetIds
197
194
  */
198
195
  filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
199
- getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
196
+ getTradeTxs(tradeResult: TradeResult): Promise<TxType>;
200
197
  }
201
198
  export {};
@@ -1,7 +1,8 @@
1
+ import { ChainId } from '@shapeshiftoss/caip';
1
2
  import { BuyAssetBySellIdInput, ByPairInput, SupportedSellAssetsInput, Swapper } from '..';
2
3
  import { SwapperType } from '../api';
3
4
  export declare class SwapperManager {
4
- swappers: Map<SwapperType, Swapper>;
5
+ swappers: Map<SwapperType, Swapper<ChainId>>;
5
6
  constructor();
6
7
  /**
7
8
  *
@@ -9,27 +10,27 @@ export declare class SwapperManager {
9
10
  * @param swapperInstance swapper instance {Swapper}
10
11
  * @returns {SwapperManager}
11
12
  */
12
- addSwapper(swapperType: SwapperType, swapperInstance: Swapper): this;
13
+ addSwapper(swapperType: SwapperType, swapperInstance: Swapper<ChainId>): this;
13
14
  /**
14
15
  *
15
16
  * @param swapperType swapper type {SwapperType|string}
16
17
  * @returns {Swapper}
17
18
  * @deprecated this will be removed, currently used in swapper tests
18
19
  */
19
- getSwapper(swapperType: SwapperType): Swapper;
20
+ getSwapper(swapperType: SwapperType): Swapper<ChainId>;
20
21
  /**
21
22
  *
22
23
  * @param swapperType swapper type {SwapperType|string}
23
24
  * @returns {SwapperManager}
24
25
  */
25
26
  removeSwapper(swapperType: SwapperType): this;
26
- getBestSwapper(args: ByPairInput): Promise<Swapper | undefined>;
27
+ getBestSwapper(args: ByPairInput): Promise<Swapper<ChainId> | undefined>;
27
28
  /**
28
29
  *
29
30
  * @param pair type {GetQuoteInput}
30
31
  * @returns {SwapperType}
31
32
  */
32
- getSwappersByPair(pair: ByPairInput): Swapper[];
33
+ getSwappersByPair(pair: ByPairInput): Swapper<ChainId>[];
33
34
  getSupportedBuyAssetIdsFromSellId(args: BuyAssetBySellIdInput): import("@shapeshiftoss/caip").AssetId[];
34
35
  getSupportedSellableAssetIds(args: SupportedSellAssetsInput): import("@shapeshiftoss/caip").AssetId[];
35
36
  }
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -6,14 +29,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
29
  const asset_service_1 = require("@shapeshiftoss/asset-service");
7
30
  const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
8
31
  const hdwallet_native_1 = require("@shapeshiftoss/hdwallet-native");
9
- const types_1 = require("@shapeshiftoss/types");
32
+ const unchained = __importStar(require("@shapeshiftoss/unchained-client"));
10
33
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
11
34
  const dotenv_1 = __importDefault(require("dotenv"));
12
35
  const readline_sync_1 = __importDefault(require("readline-sync"));
13
36
  const web3_1 = __importDefault(require("web3"));
14
37
  const api_1 = require("./api");
15
38
  const SwapperManager_1 = require("./manager/SwapperManager");
16
- const ThorchainSwapper_1 = require("./swappers/thorchain/ThorchainSwapper");
17
39
  const ZrxSwapper_1 = require("./swappers/zrx/ZrxSwapper");
18
40
  dotenv_1.default.config();
19
41
  const { UNCHAINED_HTTP_API = 'http://localhost:31300', UNCHAINED_WS_API = 'wss://localhost:31300', ETH_NODE_URL = 'http://localhost:3000', DEVICE_ID = 'device123', MNEMONIC = 'all all all all all all all all all all all all' } = process.env;
@@ -62,26 +84,21 @@ const main = async () => {
62
84
  }
63
85
  // Swapper Deps
64
86
  const wallet = await getWallet();
65
- const unchainedUrls = {
66
- [types_1.ChainTypes.Ethereum]: {
67
- httpUrl: UNCHAINED_HTTP_API,
68
- wsUrl: UNCHAINED_WS_API
69
- }
70
- };
71
- const adapterManager = new chain_adapters_1.ChainAdapterManager(unchainedUrls);
87
+ const ethChainAdapter = new chain_adapters_1.ethereum.ChainAdapter({
88
+ providers: {
89
+ ws: new unchained.ws.Client(UNCHAINED_WS_API),
90
+ http: new unchained.ethereum.V1Api(new unchained.ethereum.Configuration({
91
+ basePath: UNCHAINED_HTTP_API
92
+ }))
93
+ },
94
+ rpcUrl: 'https://mainnet.infura.io/v3/d734c7eebcdf400185d7eb67322a7e57'
95
+ });
72
96
  const web3Provider = new web3_1.default.providers.HttpProvider(ETH_NODE_URL);
73
97
  const web3 = new web3_1.default(web3Provider);
74
- const zrxSwapperDeps = { wallet, adapterManager, web3 };
75
- const thorchainSwapperDeps = {
76
- midgardUrl: 'https://midgard.thorchain.info/v2',
77
- adapterManager
78
- };
98
+ const zrxSwapperDeps = { wallet, adapter: ethChainAdapter, web3 };
79
99
  const manager = new SwapperManager_1.SwapperManager();
80
100
  const zrxSwapper = new ZrxSwapper_1.ZrxSwapper(zrxSwapperDeps);
81
- const thorchainSwapper = new ThorchainSwapper_1.ThorchainSwapper(thorchainSwapperDeps);
82
- await thorchainSwapper.initialize();
83
101
  manager.addSwapper(api_1.SwapperType.Zrx, zrxSwapper);
84
- manager.addSwapper(api_1.SwapperType.Thorchain, thorchainSwapper);
85
102
  const swapper = await manager.getBestSwapper({
86
103
  sellAssetId: 'eip155:1/slip44:60',
87
104
  buyAssetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
@@ -1,21 +1,21 @@
1
- import { AssetId } from '@shapeshiftoss/caip';
2
- import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
1
+ import { AssetId, ChainId } from '@shapeshiftoss/caip';
2
+ import { Asset } from '@shapeshiftoss/types';
3
3
  import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
4
  export declare type CowSwapperDeps = {
5
5
  apiUrl: string;
6
6
  };
7
- export declare class CowSwapper implements Swapper {
7
+ export declare class CowSwapper implements Swapper<ChainId> {
8
8
  static swapperName: string;
9
9
  deps: CowSwapperDeps;
10
10
  constructor(deps: CowSwapperDeps);
11
11
  initialize(): Promise<void>;
12
12
  getType(): SwapperType;
13
- buildTrade(args: BuildTradeInput): Promise<Trade<SupportedChainIds>>;
14
- getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
13
+ buildTrade(args: BuildTradeInput): Promise<Trade<ChainId>>;
14
+ getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<ChainId>>;
15
15
  getUsdRate(input: Asset): Promise<string>;
16
- executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
17
- approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
18
- approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
16
+ executeTrade(args: ExecuteTradeInput<ChainId>): Promise<TradeResult>;
17
+ approvalNeeded(args: ApprovalNeededInput<ChainId>): Promise<ApprovalNeededOutput>;
18
+ approveInfinite(args: ApproveInfiniteInput<ChainId>): Promise<string>;
19
19
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
20
20
  filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
21
21
  getTradeTxs(): Promise<TradeTxs>;
@@ -1,11 +1,11 @@
1
- import { AssetId } from '@shapeshiftoss/caip';
2
- import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
1
+ import { AssetId, ChainId } from '@shapeshiftoss/caip';
2
+ import { Asset } from '@shapeshiftoss/types';
3
3
  import { ApprovalNeededOutput, BuyAssetBySellIdInput, 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
- export declare class TestSwapper implements Swapper {
8
+ export declare class TestSwapper implements Swapper<ChainId> {
9
9
  supportAssets: string[];
10
10
  initialize(): Promise<void>;
11
11
  getType(): SwapperType;
@@ -15,8 +15,8 @@ export declare class TestSwapper implements Swapper {
15
15
  approveInfinite(): Promise<string>;
16
16
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
17
17
  filterAssetIdsBySellable(): AssetId[];
18
- buildTrade(): Promise<Trade<SupportedChainIds>>;
19
- getTradeQuote(): Promise<TradeQuote<SupportedChainIds>>;
18
+ buildTrade(): Promise<Trade<ChainId>>;
19
+ getTradeQuote(): Promise<TradeQuote<ChainId>>;
20
20
  executeTrade(): Promise<TradeResult>;
21
21
  getTradeTxs(): Promise<TradeTxs>;
22
22
  }
@@ -1,8 +1,8 @@
1
- import { AssetId } from '@shapeshiftoss/caip';
2
- import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
1
+ import { AssetId, ChainId } from '@shapeshiftoss/caip';
2
+ import type { Asset } from '@shapeshiftoss/types';
3
3
  import { ApprovalNeededOutput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
4
  import { ThorchainSwapperDeps } from './types';
5
- export declare class ThorchainSwapper implements Swapper {
5
+ export declare class ThorchainSwapper implements Swapper<ChainId> {
6
6
  private swapSupportedChainIds;
7
7
  private supportedAssetIds;
8
8
  deps: ThorchainSwapperDeps;
@@ -14,8 +14,8 @@ export declare class ThorchainSwapper implements Swapper {
14
14
  approveInfinite(): Promise<string>;
15
15
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
16
16
  filterAssetIdsBySellable(): AssetId[];
17
- buildTrade(): Promise<Trade<SupportedChainIds>>;
18
- getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
19
- executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
17
+ buildTrade(): Promise<Trade<ChainId>>;
18
+ getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<ChainId>>;
19
+ executeTrade(args: ExecuteTradeInput<ChainId>): Promise<TradeResult>;
20
20
  getTradeTxs(): Promise<TradeTxs>;
21
21
  }
@@ -61,10 +61,13 @@ class ThorchainSwapper {
61
61
  }
62
62
  async executeTrade(args) {
63
63
  const { trade, wallet } = args;
64
- const adapter = await this.deps.adapterManager.byChainId(trade.sellAsset.chainId);
65
- if (trade.sellAsset.chainId === 'eip155:1') {
64
+ const adapter = this.deps.adapterManager.get(trade.sellAsset.chainId);
65
+ if (adapter && trade.sellAsset.chainId === 'eip155:1') {
66
66
  const thorTradeEth = trade;
67
- const signedTx = await adapter.signTransaction({ txToSign: thorTradeEth.txData, wallet });
67
+ const signedTx = await adapter.signTransaction({
68
+ txToSign: thorTradeEth.txData,
69
+ wallet
70
+ });
68
71
  const txid = await adapter.broadcastTransaction(signedTx);
69
72
  return { tradeId: txid };
70
73
  }
@@ -1,7 +1,7 @@
1
- import { SupportedChainIds } from '@shapeshiftoss/types';
1
+ import { ChainId } from '@shapeshiftoss/caip';
2
2
  import { GetTradeQuoteInput, TradeQuote } from '../../../api';
3
3
  import { ThorchainSwapperDeps } from '../types';
4
4
  export declare const getThorTradeQuote: ({ deps, input }: {
5
5
  deps: ThorchainSwapperDeps;
6
6
  input: GetTradeQuoteInput;
7
- }) => Promise<TradeQuote<SupportedChainIds>>;
7
+ }) => Promise<TradeQuote<ChainId>>;
@@ -4,7 +4,6 @@ exports.getThorTradeQuote = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
5
  const api_1 = require("../../../api");
6
6
  const bignumber_1 = require("../../utils/bignumber");
7
- const bignumber_2 = require("../../utils/bignumber");
8
7
  const constants_1 = require("../../utils/constants");
9
8
  const helpers_1 = require("../../utils/helpers/helpers");
10
9
  const constants_2 = require("../utils/constants");
@@ -21,7 +20,12 @@ const getThorTradeQuote = async ({ deps, input }) => {
21
20
  const { assetReference: sellAssetErc20Address, chainReference, chainNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
22
21
  const isErc20Trade = sellAssetErc20Address.startsWith('0x');
23
22
  const sellAssetChainId = (0, caip_1.toChainId)({ chainReference, chainNamespace });
24
- const adapter = deps.adapterManager.byChainId(sellAssetChainId);
23
+ const adapter = deps.adapterManager.get(sellAssetChainId);
24
+ if (!adapter)
25
+ throw new api_1.SwapError(`[getThorTxInfo] - No chain adapter found for ${sellAssetChainId}.`, {
26
+ code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
27
+ details: { sellAssetChainId }
28
+ });
25
29
  const bip44Params = adapter.buildBIP44Params({ accountNumber: Number(sellAssetAccountNumber) });
26
30
  const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
27
31
  const { data, router } = await (0, getThorTxData_1.getThorTxInfo)({
@@ -63,9 +67,9 @@ const getThorTradeQuote = async ({ deps, input }) => {
63
67
  });
64
68
  const feeAssetRatio = await (0, getPriceRatio_1.getPriceRatio)(deps, { sellAssetId, buyAssetId: feeAssetId });
65
69
  const priceRatio = await (0, getPriceRatio_1.getPriceRatio)(deps, { sellAssetId, buyAssetId });
66
- const rate = (0, bignumber_2.bnOrZero)(1).div(priceRatio).toString();
67
- const buyAmount = (0, helpers_1.normalizeAmount)((0, bignumber_2.bnOrZero)(sellAmount).times(rate));
68
- const sellAssetTradeFee = (0, bignumber_2.bnOrZero)(feeData.tradeFee).times((0, bignumber_2.bnOrZero)(feeAssetRatio));
70
+ const rate = (0, bignumber_1.bnOrZero)(1).div(priceRatio).toString();
71
+ const buyAmount = (0, helpers_1.normalizeAmount)((0, bignumber_1.bnOrZero)(sellAmount).times(rate));
72
+ const sellAssetTradeFee = (0, bignumber_1.bnOrZero)(feeData.tradeFee).times((0, bignumber_1.bnOrZero)(feeAssetRatio));
69
73
  // padding minimum by 1.5 the trade fee to avoid thorchain "not enough to cover fee" errors.
70
74
  const minimum = (0, bignumber_1.fromBaseUnit)(sellAssetTradeFee.times(1.5).toString(), sellAsset.precision);
71
75
  return {
@@ -1,13 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEthTxFees = void 0;
4
+ const types_1 = require("@shapeshiftoss/types");
4
5
  const api_1 = require("../../../../../api");
5
6
  const bignumber_1 = require("../../../../utils/bignumber");
6
7
  const constants_1 = require("../../../../utils/constants");
7
8
  const estimateTradeFee_1 = require("../../estimateTradeFee/estimateTradeFee");
8
9
  const getEthTxFees = async ({ deps, data, router, buyAsset, sellAmount, adapterManager, receiveAddress, sellAssetReference }) => {
9
10
  try {
10
- const adapter = adapterManager.byChainId('eip155:1');
11
+ const adapter = adapterManager.get(types_1.KnownChainIds.EthereumMainnet);
12
+ if (!adapter)
13
+ throw new api_1.SwapError(`[getThorTxInfo] - No chain adapter found for ${types_1.KnownChainIds.EthereumMainnet}.`, {
14
+ code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
15
+ details: { chainId: types_1.KnownChainIds.EthereumMainnet }
16
+ });
11
17
  // TODO(ryankk): add falling back on hard coded gas Limit * new chain adapter method if it fails
12
18
  const feeDataOptions = await adapter.getFeeData({
13
19
  to: router,
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UNSUPPORTED = exports.ETH = exports.WBTC = exports.FOX = exports.WETH = exports.BTC = void 0;
4
- const types_1 = require("@shapeshiftoss/types");
5
4
  exports.BTC = {
6
5
  assetId: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
7
6
  chainId: 'bip122:000000000019d6689c085ae165831e93',
8
7
  name: 'bitcoin',
9
- chain: types_1.ChainTypes.Bitcoin,
10
- network: types_1.NetworkTypes.MAINNET,
11
8
  precision: 8,
12
9
  color: '#FFFFFF',
13
10
  icon: 'https://assets.coincap.io/assets/icons/btc@2x.png',
@@ -20,8 +17,6 @@ exports.WETH = {
20
17
  assetId: 'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
21
18
  chainId: 'eip155:1',
22
19
  name: 'WETH',
23
- chain: types_1.ChainTypes.Ethereum,
24
- network: types_1.NetworkTypes.MAINNET,
25
20
  precision: 18,
26
21
  color: '#FFFFFF',
27
22
  icon: 'https://assets.coingecko.com/coins/images/2518/thumb/weth.png?1628852295',
@@ -34,8 +29,6 @@ exports.FOX = {
34
29
  assetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d',
35
30
  chainId: 'eip155:1',
36
31
  name: 'FOX',
37
- chain: types_1.ChainTypes.Ethereum,
38
- network: types_1.NetworkTypes.MAINNET,
39
32
  precision: 18,
40
33
  color: '#FFFFFF',
41
34
  icon: 'https://assets.coincap.io/assets/icons/fox@2x.png',
@@ -48,21 +41,17 @@ exports.WBTC = {
48
41
  assetId: 'eip155:1/erc20:0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
49
42
  chainId: 'eip155:1',
50
43
  color: '#FFFFFF',
51
- chain: types_1.ChainTypes.Ethereum,
52
44
  explorer: 'https://etherscan.io',
53
45
  explorerAddressLink: 'https://etherscan.io/address/',
54
46
  explorerTxLink: 'https://etherscan.io/tx/',
55
47
  icon: 'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/logo.png',
56
48
  name: 'Wrapped Bitcoin',
57
- network: types_1.NetworkTypes.MAINNET,
58
49
  precision: 8,
59
50
  symbol: 'WBTC'
60
51
  };
61
52
  exports.ETH = {
62
53
  assetId: 'eip155:1/slip44:60',
63
54
  chainId: 'eip155:1',
64
- chain: types_1.ChainTypes.Ethereum,
65
- network: types_1.NetworkTypes.MAINNET,
66
55
  symbol: 'ETH',
67
56
  name: 'Ethereum',
68
57
  precision: 18,
@@ -75,8 +64,6 @@ exports.ETH = {
75
64
  exports.UNSUPPORTED = {
76
65
  assetId: 'eip155:1/slip44:420',
77
66
  chainId: 'eip155:1',
78
- chain: types_1.ChainTypes.Ethereum,
79
- network: types_1.NetworkTypes.MAINNET,
80
67
  symbol: 'ETH',
81
68
  name: 'Ethereum',
82
69
  precision: 18,
@@ -1,3 +1,3 @@
1
1
  import { ApprovalNeededInput, ApprovalNeededOutput } from '../../../api';
2
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function ZrxApprovalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
3
+ export declare function ZrxApprovalNeeded({ adapter, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
@@ -6,7 +6,7 @@ const api_1 = require("../../../api");
6
6
  const bignumber_1 = require("../../utils/bignumber");
7
7
  const erc20Allowance_abi_1 = require("../utils/abi/erc20Allowance-abi");
8
8
  const helpers_1 = require("../utils/helpers/helpers");
9
- async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
9
+ async function ZrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
10
10
  var _a;
11
11
  const { sellAsset } = quote;
12
12
  const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(sellAsset.assetId);
@@ -22,7 +22,6 @@ async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
22
22
  return { approvalNeeded: false };
23
23
  }
24
24
  const accountNumber = quote.sellAssetAccountNumber;
25
- const adapter = await adapterManager.byChainId(sellAsset.chainId);
26
25
  const bip44Params = adapter.buildBIP44Params({ accountNumber });
27
26
  const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
28
27
  if (!quote.allowanceContract) {
@@ -1,4 +1,3 @@
1
- import { SupportedChainIds } from '@shapeshiftoss/types';
2
1
  import { ApproveInfiniteInput } from '../../../api';
3
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
4
- export declare function ZrxApproveInfinite({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
3
+ export declare function ZrxApproveInfinite({ adapter, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<'eip155:1'>): Promise<string>;
@@ -5,7 +5,7 @@ const api_1 = require("../../../api");
5
5
  const erc20_abi_1 = require("../utils/abi/erc20-abi");
6
6
  const constants_1 = require("../utils/constants");
7
7
  const helpers_1 = require("../utils/helpers/helpers");
8
- async function ZrxApproveInfinite({ adapterManager, web3 }, { quote, wallet }) {
8
+ async function ZrxApproveInfinite({ adapter, web3 }, { quote, wallet }) {
9
9
  try {
10
10
  const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
11
11
  quote: {
@@ -13,7 +13,7 @@ async function ZrxApproveInfinite({ adapterManager, web3 }, { quote, wallet }) {
13
13
  sellAmount: constants_1.MAX_ALLOWANCE
14
14
  },
15
15
  wallet,
16
- adapterManager,
16
+ adapter,
17
17
  erc20Abi: erc20_abi_1.erc20Abi,
18
18
  web3
19
19
  });
@@ -1,24 +1,24 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
- import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
3
- import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
2
+ import { ethereum } from '@shapeshiftoss/chain-adapters';
3
+ import { Asset } from '@shapeshiftoss/types';
4
4
  import Web3 from 'web3';
5
5
  import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs, ZrxTrade } from '../../api';
6
6
  export declare type ZrxSwapperDeps = {
7
- adapterManager: ChainAdapterManager;
7
+ adapter: ethereum.ChainAdapter;
8
8
  web3: Web3;
9
9
  };
10
- export declare class ZrxSwapper implements Swapper {
10
+ export declare class ZrxSwapper implements Swapper<'eip155:1'> {
11
11
  static swapperName: string;
12
12
  deps: ZrxSwapperDeps;
13
13
  constructor(deps: ZrxSwapperDeps);
14
14
  initialize(): Promise<void>;
15
15
  getType(): SwapperType;
16
- buildTrade(args: BuildTradeInput): Promise<ZrxTrade<SupportedChainIds>>;
17
- getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
16
+ buildTrade(args: BuildTradeInput): Promise<ZrxTrade>;
17
+ getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<'eip155:1'>>;
18
18
  getUsdRate(input: Asset): Promise<string>;
19
19
  executeTrade(args: ExecuteTradeInput<'eip155:1'>): Promise<TradeResult>;
20
20
  approvalNeeded(args: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
21
- approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
21
+ approveInfinite(args: ApproveInfiniteInput<'eip155:1'>): Promise<string>;
22
22
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
23
23
  filterAssetIdsBySellable(assetIds?: AssetId[]): AssetId[];
24
24
  getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
@@ -1,6 +1,6 @@
1
- import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
1
+ import { ethereum } from '@shapeshiftoss/chain-adapters';
2
2
  import { HDWallet } from '@shapeshiftoss/hdwallet-core';
3
- import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
3
+ import { Asset } from '@shapeshiftoss/types';
4
4
  import Web3 from 'web3';
5
5
  import { AbiItem } from 'web3-utils';
6
6
  import { TradeQuote } from '../../../../api';
@@ -21,14 +21,14 @@ export declare type GetERC20AllowanceArgs = {
21
21
  spenderAddress: string;
22
22
  };
23
23
  declare type GrantAllowanceArgs = {
24
- quote: TradeQuote<SupportedChainIds>;
24
+ quote: TradeQuote<'eip155:1'>;
25
25
  wallet: HDWallet;
26
- adapterManager: ChainAdapterManager;
26
+ adapter: ethereum.ChainAdapter;
27
27
  erc20Abi: AbiItem[];
28
28
  web3: Web3;
29
29
  };
30
30
  export declare const getERC20Allowance: ({ erc20AllowanceAbi, web3, sellAssetErc20Address, ownerAddress, spenderAddress }: GetERC20AllowanceArgs) => Promise<any>;
31
31
  export declare const getAllowanceRequired: ({ receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi }: GetAllowanceRequiredArgs) => Promise<BN>;
32
32
  export declare const getUsdRate: (asset: Asset) => Promise<string>;
33
- export declare const grantAllowance: ({ quote, wallet, adapterManager, erc20Abi, web3 }: GrantAllowanceArgs) => Promise<string>;
33
+ export declare const grantAllowance: ({ quote, wallet, adapter, erc20Abi, web3 }: GrantAllowanceArgs) => Promise<string>;
34
34
  export {};
@@ -78,11 +78,10 @@ const getUsdRate = async (asset) => {
78
78
  }
79
79
  };
80
80
  exports.getUsdRate = getUsdRate;
81
- const grantAllowance = async ({ quote, wallet, adapterManager, erc20Abi, web3 }) => {
81
+ const grantAllowance = async ({ quote, wallet, adapter, erc20Abi, web3 }) => {
82
82
  var _a, _b, _c, _d, _e;
83
83
  try {
84
84
  const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(quote.sellAsset.assetId);
85
- const adapter = await adapterManager.byChainId('eip155:1');
86
85
  const erc20Contract = new web3.eth.Contract(erc20Abi, sellAssetErc20Address);
87
86
  const approveTx = erc20Contract.methods
88
87
  .approve(quote.allowanceContract, quote.sellAmount)
@@ -1,32 +1,6 @@
1
- import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
1
+ import { ethereum } from '@shapeshiftoss/chain-adapters';
2
2
  import Web3 from 'web3';
3
- export declare const chainAdapterMockFuncs: {
4
- buildBIP44Params: jest.Mock<{
5
- purpose: number;
6
- coinType: number;
7
- accountNumber: number;
8
- }, []>;
9
- buildSendTransaction: jest.Mock<Promise<{
10
- txToSign: {};
11
- }>, []>;
12
- signTransaction: jest.Mock<Promise<string>, []>;
13
- broadcastTransaction: jest.Mock<Promise<string>, []>;
14
- getAddress: jest.Mock<Promise<string>, []>;
15
- getAccount: jest.Mock<Promise<{
16
- chainSpecific: {
17
- tokens: {
18
- assetId: string;
19
- balance: string;
20
- }[];
21
- };
22
- }>, []>;
23
- getFeeData: jest.Mock<Promise<{
24
- average: {
25
- txFee: string;
26
- };
27
- }>, []>;
28
- };
29
3
  export declare const setupZrxDeps: () => {
30
- web3Instance: Web3;
31
- adapterManager: ChainAdapterManager;
4
+ web3: Web3;
5
+ adapter: ethereum.ChainAdapter;
32
6
  };
@@ -1,46 +1,48 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setupZrxDeps = exports.chainAdapterMockFuncs = void 0;
29
+ exports.setupZrxDeps = void 0;
7
30
  const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
8
- const types_1 = require("@shapeshiftoss/types");
31
+ const unchained = __importStar(require("@shapeshiftoss/unchained-client"));
9
32
  const web3_1 = __importDefault(require("web3"));
10
33
  jest.mock('@shapeshiftoss/chain-adapters');
11
- exports.chainAdapterMockFuncs = {
12
- buildBIP44Params: jest.fn(() => ({ purpose: 44, coinType: 60, accountNumber: 0 })),
13
- buildSendTransaction: jest.fn(() => Promise.resolve({ txToSign: {} })),
14
- signTransaction: jest.fn(() => Promise.resolve('signedTx')),
15
- broadcastTransaction: jest.fn(() => Promise.resolve('broadcastedTx')),
16
- getAddress: jest.fn(() => Promise.resolve('address')),
17
- getAccount: jest.fn(() => Promise.resolve({
18
- chainSpecific: { tokens: [{ assetId: 'eip155:1/erc20:contractAddress', balance: '1000000' }] }
19
- })),
20
- getFeeData: jest.fn(() => Promise.resolve({
21
- [types_1.chainAdapters.FeeDataKey.Average]: { txFee: '10000' }
22
- }))
23
- };
24
- // @ts-ignore
25
- chain_adapters_1.ChainAdapterManager.mockImplementation(() => ({
26
- byChain: jest.fn(() => exports.chainAdapterMockFuncs),
27
- byChainId: jest.fn(() => exports.chainAdapterMockFuncs)
28
- }));
29
34
  const setupZrxDeps = () => {
30
- const unchainedUrls = {
31
- [types_1.ChainTypes.Bitcoin]: {
32
- httpUrl: 'https://api.bitcoin.shapeshift.com',
33
- wsUrl: 'wss://api.bitcoin.shapeshift.com'
35
+ const ethChainAdapter = new chain_adapters_1.ethereum.ChainAdapter({
36
+ providers: {
37
+ ws: new unchained.ws.Client('wss://dev-api.ethereum.shapeshift.com'),
38
+ http: new unchained.ethereum.V1Api(new unchained.ethereum.Configuration({
39
+ basePath: 'https://dev-api.ethereum.shapeshift.com'
40
+ }))
34
41
  },
35
- [types_1.ChainTypes.Ethereum]: {
36
- httpUrl: 'https://api.ethereum.shapeshift.com',
37
- wsUrl: 'wss://api.ethereum.shapeshift.com'
38
- }
39
- };
42
+ rpcUrl: 'https://mainnet.infura.io/v3/d734c7eebcdf400185d7eb67322a7e57'
43
+ });
40
44
  const ethNodeUrl = 'http://localhost:1000';
41
- const adapterManager = new chain_adapters_1.ChainAdapterManager(unchainedUrls);
42
45
  const web3Provider = new web3_1.default.providers.HttpProvider(ethNodeUrl);
43
- const web3Instance = new web3_1.default(web3Provider);
44
- return { web3Instance, adapterManager };
46
+ return { web3: new web3_1.default(web3Provider), adapter: ethChainAdapter };
45
47
  };
46
48
  exports.setupZrxDeps = setupZrxDeps;
@@ -1,4 +1,3 @@
1
- import { SupportedChainIds } from '@shapeshiftoss/types';
2
1
  import { BuildTradeInput, ZrxTrade } from '../../..';
3
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
4
- export declare function zrxBuildTrade({ adapterManager, web3 }: ZrxSwapperDeps, input: BuildTradeInput): Promise<ZrxTrade<SupportedChainIds>>;
3
+ export declare function zrxBuildTrade({ adapter, web3 }: ZrxSwapperDeps, input: BuildTradeInput): Promise<ZrxTrade>;
@@ -29,14 +29,13 @@ const rax = __importStar(require("retry-axios"));
29
29
  const __1 = require("../../..");
30
30
  const bignumber_1 = require("../../utils/bignumber");
31
31
  const constants_1 = require("../../utils/constants");
32
- const constants_2 = require("../../utils/constants");
33
32
  const helpers_1 = require("../../utils/helpers/helpers");
34
33
  const erc20Allowance_abi_1 = require("../utils/abi/erc20Allowance-abi");
35
34
  const applyAxiosRetry_1 = require("../utils/applyAxiosRetry");
36
- const constants_3 = require("../utils/constants");
35
+ const constants_2 = require("../utils/constants");
37
36
  const helpers_2 = require("../utils/helpers/helpers");
38
37
  const zrxService_1 = require("../utils/zrxService");
39
- async function zrxBuildTrade({ adapterManager, web3 }, input) {
38
+ async function zrxBuildTrade({ adapter, web3 }, input) {
40
39
  var _a, _b, _c;
41
40
  const { sellAsset, buyAsset, sellAmount, slippage, sellAssetAccountNumber, buyAssetAccountNumber, wallet } = input;
42
41
  try {
@@ -50,8 +49,7 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
50
49
  details: { chainId: sellAsset.chainId }
51
50
  });
52
51
  }
53
- const adapter = await adapterManager.byChainId(buyAsset.chainId);
54
- const bip44Params = adapter.buildBIP44Params({ accountNumber: buyAssetAccountNumber });
52
+ const bip44Params = adapter.buildBIP44Params({ accountNumber: Number(buyAssetAccountNumber) });
55
53
  const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
56
54
  const slippagePercentage = slippage ? (0, bignumber_1.bnOrZero)(slippage).div(100).toString() : constants_1.DEFAULT_SLIPPAGE;
57
55
  /**
@@ -87,7 +85,7 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
87
85
  takerAddress: receiveAddress,
88
86
  slippagePercentage,
89
87
  skipValidation: false,
90
- affiliateAddress: constants_3.AFFILIATE_ADDRESS
88
+ affiliateAddress: constants_2.AFFILIATE_ADDRESS
91
89
  }
92
90
  });
93
91
  const { data } = quoteResponse;
@@ -110,7 +108,7 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
110
108
  txData: data.data,
111
109
  sellAmount: data.sellAmount,
112
110
  buyAmount: data.buyAmount,
113
- sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_3.DEFAULT_SOURCE
111
+ sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE
114
112
  };
115
113
  const allowanceRequired = await (0, helpers_2.getAllowanceRequired)({
116
114
  sellAsset,
@@ -125,7 +123,7 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
125
123
  fee: ((_b = trade.feeData) === null || _b === void 0 ? void 0 : _b.fee) || '0',
126
124
  chainSpecific: {
127
125
  ...(_c = trade.feeData) === null || _c === void 0 ? void 0 : _c.chainSpecific,
128
- approvalFee: (0, bignumber_1.bnOrZero)(constants_2.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString()
126
+ approvalFee: (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString()
129
127
  },
130
128
  tradeFee: '0'
131
129
  };
@@ -1,3 +1,3 @@
1
1
  import { ExecuteTradeInput, TradeResult } from '../../../api';
2
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function zrxExecuteTrade({ adapterManager }: ZrxSwapperDeps, { trade, wallet }: ExecuteTradeInput<'eip155:1'>): Promise<TradeResult>;
3
+ export declare function zrxExecuteTrade({ adapter }: ZrxSwapperDeps, { trade, wallet }: ExecuteTradeInput<'eip155:1'>): Promise<TradeResult>;
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.zrxExecuteTrade = void 0;
4
4
  const web3_utils_1 = require("web3-utils");
5
5
  const api_1 = require("../../../api");
6
- async function zrxExecuteTrade({ adapterManager }, { trade, wallet }) {
6
+ async function zrxExecuteTrade({ adapter }, { trade, wallet }) {
7
7
  var _a, _b, _c, _d, _e, _f;
8
8
  const zrxTrade = trade;
9
9
  const { sellAsset } = zrxTrade;
10
10
  try {
11
11
  // value is 0 for erc20s
12
12
  const value = sellAsset.assetId === 'eip155:1/slip44:60' ? trade.sellAmount : '0';
13
- const adapter = await adapterManager.byChainId(sellAsset.chainId);
14
13
  const bip44Params = adapter.buildBIP44Params({
15
14
  accountNumber: trade.sellAssetAccountNumber
16
15
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "6.3.0",
4
- "description": "TODO: description",
3
+ "version": "7.0.0",
4
+ "description": "An interface and implementations to trade coins via various protocols",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",
7
7
  "main": "./dist/index.js",
@@ -30,20 +30,20 @@
30
30
  "web3": "^1.7.3"
31
31
  },
32
32
  "peerDependencies": {
33
- "@shapeshiftoss/asset-service": "^4.6.0",
34
- "@shapeshiftoss/caip": "^5.2.2",
35
- "@shapeshiftoss/chain-adapters": "^5.0.0",
33
+ "@shapeshiftoss/asset-service": "^5.0.0",
34
+ "@shapeshiftoss/caip": "^5.3.0",
35
+ "@shapeshiftoss/chain-adapters": "^6.0.1",
36
36
  "@shapeshiftoss/errors": "^1.1.1",
37
37
  "@shapeshiftoss/hdwallet-core": "^1.23.0",
38
- "@shapeshiftoss/types": "^4.4.0"
38
+ "@shapeshiftoss/types": "^5.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@shapeshiftoss/asset-service": "^4.6.0",
42
- "@shapeshiftoss/caip": "^5.2.2",
43
- "@shapeshiftoss/chain-adapters": "^5.0.0",
41
+ "@shapeshiftoss/asset-service": "^5.0.0",
42
+ "@shapeshiftoss/caip": "^5.3.0",
43
+ "@shapeshiftoss/chain-adapters": "^6.0.1",
44
44
  "@shapeshiftoss/errors": "^1.1.1",
45
45
  "@shapeshiftoss/hdwallet-core": "^1.23.0",
46
- "@shapeshiftoss/types": "^4.4.0",
46
+ "@shapeshiftoss/types": "^5.0.0",
47
47
  "@types/readline-sync": "^1.4.4",
48
48
  "readline-sync": "^1.4.10",
49
49
  "web3-utils": "^1.7.3"