@shapeshiftoss/swapper 5.8.0 → 5.10.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.
package/dist/api.d.ts CHANGED
@@ -123,8 +123,6 @@ export declare type GetMinMaxInput = {
123
123
  };
124
124
  export declare type ApprovalNeededOutput = {
125
125
  approvalNeeded: boolean;
126
- gas?: string;
127
- gasPrice?: string;
128
126
  };
129
127
  export declare enum SwapperType {
130
128
  Zrx = "0x",
@@ -172,11 +170,7 @@ export interface Swapper {
172
170
  /**
173
171
  * Get the usd rate from either the assets symbol or tokenId
174
172
  */
175
- getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
176
- /**
177
- * Get the minimum and maximum trade value of the sellAsset and buyAsset
178
- */
179
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
173
+ getUsdRate(input: Asset): Promise<string>;
180
174
  /**
181
175
  * Execute a trade built with buildTrade by signing and broadcasting
182
176
  */
@@ -48,19 +48,8 @@ const main = async () => {
48
48
  `);
49
49
  return;
50
50
  }
51
- const assetService = new asset_service_1.AssetService('');
52
- await assetService.initialize();
53
- const assets = assetService.byNetwork(types_1.NetworkTypes.MAINNET);
54
- if (!assets) {
55
- console.error('No assets found in asset service');
56
- return;
57
- }
58
- const assetMap = assets.reduce((acc, val) => {
59
- if (val) {
60
- acc[val.symbol] = val;
61
- }
62
- return acc;
63
- }, {});
51
+ const assetService = new asset_service_1.AssetService();
52
+ const assetMap = assetService.getAll();
64
53
  const sellAsset = assetMap[sellSymbol];
65
54
  const buyAsset = assetMap[buySymbol];
66
55
  if (!sellAsset) {
@@ -1,6 +1,6 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
2
  import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
3
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetMinMaxInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
3
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
4
  export declare class CowSwapper implements Swapper {
5
5
  static swapperName: string;
6
6
  initialize(): Promise<void>;
@@ -8,7 +8,6 @@ export declare class CowSwapper implements Swapper {
8
8
  buildTrade(args: BuildTradeInput): Promise<Trade<SupportedChainIds>>;
9
9
  getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
10
10
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
11
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
12
11
  executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
13
12
  approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
14
13
  approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
@@ -20,10 +20,6 @@ class CowSwapper {
20
20
  console.info(input);
21
21
  throw new Error('CowSwapper: getUsdRate unimplemented');
22
22
  }
23
- getMinMax(input) {
24
- console.info(input);
25
- throw new Error('CowSwapper: getMinMax unimplemented');
26
- }
27
23
  async executeTrade(args) {
28
24
  console.info(args);
29
25
  throw new Error('CowSwapper: executeTrade unimplemented');
@@ -1,6 +1,6 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
2
  import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
3
- import { ApprovalNeededOutput, BuyAssetBySellIdInput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
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
@@ -11,7 +11,6 @@ export declare class TestSwapper implements Swapper {
11
11
  getType(): SwapperType;
12
12
  constructor();
13
13
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
14
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
15
14
  approvalNeeded(): Promise<ApprovalNeededOutput>;
16
15
  approveInfinite(): Promise<string>;
17
16
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
@@ -24,10 +24,6 @@ class TestSwapper {
24
24
  console.info(input);
25
25
  throw new Error('TestSwapper: getUsdRate unimplemented');
26
26
  }
27
- getMinMax(input) {
28
- console.info(input);
29
- throw new Error('TestSwapper: getMinMax unimplemented');
30
- }
31
27
  async approvalNeeded() {
32
28
  throw new Error('TestSwapper: approvalNeeded unimplemented');
33
29
  }
@@ -1,6 +1,6 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
2
  import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
3
- import { ApprovalNeededOutput, BuyAssetBySellIdInput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
3
+ import { ApprovalNeededOutput, BuyAssetBySellIdInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
4
  import { ThorchainSwapperDeps } from './types';
5
5
  export declare class ThorchainSwapper implements Swapper {
6
6
  private supportedAssetIds;
@@ -9,7 +9,6 @@ export declare class ThorchainSwapper implements Swapper {
9
9
  initialize(): Promise<void>;
10
10
  getType(): SwapperType;
11
11
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
12
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
13
12
  approvalNeeded(): Promise<ApprovalNeededOutput>;
14
13
  approveInfinite(): Promise<string>;
15
14
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
@@ -35,10 +35,6 @@ class ThorchainSwapper {
35
35
  getUsdRate(input) {
36
36
  return (0, getUsdRate_1.getUsdRate)({ deps: this.deps, input });
37
37
  }
38
- getMinMax(input) {
39
- console.info(input);
40
- throw new Error('ThorchainSwapper: getMinMax unimplemented');
41
- }
42
38
  async approvalNeeded() {
43
39
  throw new Error('ThorchainSwapper: approvalNeeded unimplemented');
44
40
  }
@@ -5,10 +5,9 @@ const caip_1 = require("@shapeshiftoss/caip");
5
5
  const api_1 = require("../../../api");
6
6
  const erc20Allowance_abi_1 = require("../utils/abi/erc20Allowance-abi");
7
7
  const bignumber_1 = require("../utils/bignumber");
8
- const constants_1 = require("../utils/constants");
9
8
  const helpers_1 = require("../utils/helpers/helpers");
10
9
  async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
11
- var _a, _b;
10
+ var _a;
12
11
  const { sellAsset } = quote;
13
12
  const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(sellAsset.assetId);
14
13
  try {
@@ -46,9 +45,7 @@ async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
46
45
  details: { feeData: quote.feeData }
47
46
  });
48
47
  return {
49
- approvalNeeded: allowanceOnChain.lte((0, bignumber_1.bnOrZero)(quote.sellAmount)),
50
- gas: constants_1.APPROVAL_GAS_LIMIT,
51
- gasPrice: (_b = quote.feeData.chainSpecific) === null || _b === void 0 ? void 0 : _b.gasPrice
48
+ approvalNeeded: allowanceOnChain.lte((0, bignumber_1.bnOrZero)(quote.sellAmount))
52
49
  };
53
50
  }
54
51
  catch (e) {
@@ -2,7 +2,7 @@ import { AssetId } from '@shapeshiftoss/caip';
2
2
  import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
3
3
  import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
4
4
  import Web3 from 'web3';
5
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetMinMaxInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs, ZrxTrade } from '../../api';
5
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs, ZrxTrade } from '../../api';
6
6
  export declare type ZrxSwapperDeps = {
7
7
  adapterManager: ChainAdapterManager;
8
8
  web3: Web3;
@@ -15,8 +15,7 @@ export declare class ZrxSwapper implements Swapper {
15
15
  getType(): SwapperType;
16
16
  buildTrade(args: BuildTradeInput): Promise<ZrxTrade<SupportedChainIds>>;
17
17
  getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
18
- getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
19
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
18
+ getUsdRate(input: Asset): Promise<string>;
20
19
  executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
21
20
  approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
22
21
  approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZrxSwapper = void 0;
4
4
  const api_1 = require("../../api");
5
- const getZrxMinMax_1 = require("./getZrxMinMax/getZrxMinMax");
6
5
  const getZrxTradeQuote_1 = require("./getZrxTradeQuote/getZrxTradeQuote");
7
6
  const blacklist_1 = require("./utils/blacklist");
8
7
  const helpers_1 = require("./utils/helpers/helpers");
@@ -29,9 +28,6 @@ class ZrxSwapper {
29
28
  async getUsdRate(input) {
30
29
  return (0, helpers_1.getUsdRate)(input);
31
30
  }
32
- async getMinMax(input) {
33
- return (0, getZrxMinMax_1.getZrxMinMax)(input.sellAsset, input.buyAsset);
34
- }
35
31
  async executeTrade(args) {
36
32
  return (0, zrxExecuteTrade_1.zrxExecuteTrade)(this.deps, args);
37
33
  }
@@ -38,6 +38,6 @@ declare type GrantAllowanceArgs = {
38
38
  export declare const normalizeAmount: (amount: string | number | BigNumber) => string;
39
39
  export declare const getERC20Allowance: ({ erc20AllowanceAbi, web3, sellAssetErc20Address, ownerAddress, spenderAddress }: GetERC20AllowanceArgs) => Promise<any>;
40
40
  export declare const getAllowanceRequired: ({ receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi }: GetAllowanceRequiredArgs) => Promise<BigNumber>;
41
- export declare const getUsdRate: (input: Pick<Asset, 'symbol' | 'assetId'>) => Promise<string>;
41
+ export declare const getUsdRate: (asset: Asset) => Promise<string>;
42
42
  export declare const grantAllowance: ({ quote, wallet, adapterManager, erc20Abi, web3 }: GrantAllowanceArgs) => Promise<string>;
43
43
  export {};
@@ -59,9 +59,9 @@ const getAllowanceRequired = async ({ receiveAddress, allowanceContract, sellAss
59
59
  }
60
60
  };
61
61
  exports.getAllowanceRequired = getAllowanceRequired;
62
- const getUsdRate = async (input) => {
63
- const { symbol, assetId } = input;
64
- const { assetReference: erc20Address, assetNamespace } = (0, caip_1.fromAssetId)(assetId);
62
+ const getUsdRate = async (asset) => {
63
+ const { assetReference: erc20Address, assetNamespace } = (0, caip_1.fromAssetId)(asset.assetId);
64
+ const { symbol } = asset;
65
65
  try {
66
66
  const USDC_CONTRACT_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
67
67
  if ((erc20Address === null || erc20Address === void 0 ? void 0 : erc20Address.toLowerCase()) === USDC_CONTRACT_ADDRESS)
@@ -7,19 +7,13 @@ exports.BTC = {
7
7
  chainId: 'bip122:000000000019d6689c085ae165831e93',
8
8
  name: 'bitcoin',
9
9
  chain: types_1.ChainTypes.Bitcoin,
10
- dataSource: types_1.AssetDataSource.CoinGecko,
11
10
  network: types_1.NetworkTypes.MAINNET,
12
11
  precision: 8,
13
- slip44: 44,
14
- contractType: 'erc20',
15
12
  color: '#FFFFFF',
16
- secondaryColor: '#FFFFFF',
17
13
  icon: 'https://assets.coincap.io/assets/icons/btc@2x.png',
18
14
  explorer: 'https://live.blockcypher.com',
19
15
  explorerTxLink: 'https://live.blockcypher.com/btc/tx/',
20
16
  explorerAddressLink: 'https://live.blockcypher.com/btc/address/',
21
- sendSupport: false,
22
- receiveSupport: false,
23
17
  symbol: 'BTC'
24
18
  };
25
19
  exports.WETH = {
@@ -27,20 +21,13 @@ exports.WETH = {
27
21
  chainId: 'eip155:1',
28
22
  name: 'WETH',
29
23
  chain: types_1.ChainTypes.Ethereum,
30
- dataSource: types_1.AssetDataSource.CoinGecko,
31
24
  network: types_1.NetworkTypes.MAINNET,
32
25
  precision: 18,
33
- tokenId: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
34
- contractType: 'erc20',
35
26
  color: '#FFFFFF',
36
- secondaryColor: '#FFFFFF',
37
27
  icon: 'https://assets.coingecko.com/coins/images/2518/thumb/weth.png?1628852295',
38
- slip44: 60,
39
28
  explorer: 'https://etherscan.io',
40
29
  explorerTxLink: 'https://etherscan.io/tx/',
41
30
  explorerAddressLink: 'https://etherscan.io/address/',
42
- sendSupport: true,
43
- receiveSupport: true,
44
31
  symbol: 'WETH'
45
32
  };
46
33
  exports.FOX = {
@@ -48,19 +35,12 @@ exports.FOX = {
48
35
  chainId: 'eip155:1',
49
36
  name: 'FOX',
50
37
  chain: types_1.ChainTypes.Ethereum,
51
- dataSource: types_1.AssetDataSource.CoinGecko,
52
38
  network: types_1.NetworkTypes.MAINNET,
53
39
  precision: 18,
54
- tokenId: '0xc770eefad204b5180df6a14ee197d99d808ee52d',
55
- contractType: 'erc20',
56
40
  color: '#FFFFFF',
57
- secondaryColor: '#FFFFFF',
58
41
  icon: 'https://assets.coincap.io/assets/icons/fox@2x.png',
59
- sendSupport: true,
60
- slip44: 60,
61
42
  explorer: 'https://etherscan.io',
62
43
  explorerTxLink: 'https://etherscan.io/tx/',
63
44
  explorerAddressLink: 'https://etherscan.io/address/',
64
- receiveSupport: true,
65
45
  symbol: 'FOX'
66
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "5.8.0",
3
+ "version": "5.10.0",
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": "^4.2.4",
33
+ "@shapeshiftoss/asset-service": "^4.6.0",
34
34
  "@shapeshiftoss/caip": "^5.2.1",
35
- "@shapeshiftoss/chain-adapters": "^4.3.3",
35
+ "@shapeshiftoss/chain-adapters": "^4.7.0",
36
36
  "@shapeshiftoss/hdwallet-core": "1.20.0",
37
- "@shapeshiftoss/types": "^4.3.1",
37
+ "@shapeshiftoss/types": "^4.4.0",
38
38
  "@shapeshiftoss/errors": "^1.1.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@shapeshiftoss/asset-service": "^4.2.4",
41
+ "@shapeshiftoss/asset-service": "^4.6.0",
42
42
  "@shapeshiftoss/caip": "^5.2.1",
43
- "@shapeshiftoss/chain-adapters": "^4.3.3",
43
+ "@shapeshiftoss/chain-adapters": "^4.7.0",
44
44
  "@shapeshiftoss/hdwallet-core": "^1.20.0",
45
- "@shapeshiftoss/types": "^4.3.1",
45
+ "@shapeshiftoss/types": "^4.4.0",
46
46
  "@shapeshiftoss/errors": "^1.1.0",
47
47
  "@types/readline-sync": "^1.4.4",
48
48
  "readline-sync": "^1.4.10",