@shapeshiftoss/swapper 5.9.0 → 5.10.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
@@ -33,9 +33,14 @@ declare type ChainSpecificQuoteFeeData<T1> = ChainSpecific<T1, {
33
33
  approvalFee?: string;
34
34
  totalFee?: string;
35
35
  };
36
+ 'bip122:000000000019d6689c085ae165831e93': {
37
+ byteCount: string;
38
+ satsPerByte: string;
39
+ };
36
40
  }>;
37
41
  export declare type QuoteFeeData<T1 extends SupportedChainIds> = {
38
42
  fee: string;
43
+ tradeFee: string;
39
44
  } & ChainSpecificQuoteFeeData<T1>;
40
45
  export declare type ByPairInput = {
41
46
  sellAssetId: AssetId;
@@ -62,8 +67,6 @@ export declare type BuildTradeInput = CommonTradeInput & {
62
67
  wallet: HDWallet;
63
68
  };
64
69
  interface TradeBase<C extends SupportedChainIds> {
65
- success: boolean;
66
- statusReason: string;
67
70
  buyAmount: string;
68
71
  sellAmount: string;
69
72
  feeData: QuoteFeeData<C>;
@@ -170,7 +173,7 @@ export interface Swapper {
170
173
  /**
171
174
  * Get the usd rate from either the assets symbol or tokenId
172
175
  */
173
- getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
176
+ getUsdRate(input: Asset): Promise<string>;
174
177
  /**
175
178
  * Execute a trade built with buildTrade by signing and broadcasting
176
179
  */
@@ -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) {
@@ -117,10 +106,6 @@ const main = async () => {
117
106
  return;
118
107
  }
119
108
  console.info('quote = ', JSON.stringify(quote));
120
- if (!quote.success) {
121
- console.error('Obtaining the quote failed: ', quote.statusReason);
122
- return;
123
- }
124
109
  const buyAmount = fromBaseUnit(quote.buyAmount || '0', buyAsset.precision);
125
110
  const answer = readline_sync_1.default.question(`Swap ${sellAmount} ${sellAsset.symbol} for ${buyAmount} ${buyAsset.symbol} on ${swapper.getType()}? (y/n): `);
126
111
  if (answer === 'y') {
@@ -3,6 +3,7 @@ import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
3
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
+ private swapSupportedChainIds;
6
7
  private supportedAssetIds;
7
8
  deps: ThorchainSwapperDeps;
8
9
  constructor(deps: ThorchainSwapperDeps);
@@ -7,6 +7,10 @@ const getUsdRate_1 = require("./utils/getUsdRate/getUsdRate");
7
7
  const thorService_1 = require("./utils/thorService");
8
8
  class ThorchainSwapper {
9
9
  constructor(deps) {
10
+ this.swapSupportedChainIds = {
11
+ 'eip155:1': true,
12
+ 'bip122:000000000019d6689c085ae165831e93': true
13
+ };
10
14
  this.supportedAssetIds = [];
11
15
  this.deps = deps;
12
16
  }
@@ -15,7 +19,7 @@ class ThorchainSwapper {
15
19
  const { data: responseData } = await thorService_1.thorService.get(`${this.deps.midgardUrl}/pools`);
16
20
  const supportedAssetIds = responseData.reduce((acc, midgardPool) => {
17
21
  const assetId = caip_1.adapters.poolAssetIdToAssetId(midgardPool.asset);
18
- if (!assetId)
22
+ if (!assetId || !this.swapSupportedChainIds[(0, caip_1.fromAssetId)(assetId).chainId])
19
23
  return acc;
20
24
  acc.push(assetId);
21
25
  return acc;
@@ -1,4 +1,3 @@
1
- import { SupportedChainIds } from '@shapeshiftoss/types';
2
1
  import { ApprovalNeededInput, ApprovalNeededOutput } from '../../../api';
3
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
4
- export declare function ZrxApprovalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
3
+ export declare function ZrxApprovalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
@@ -15,9 +15,9 @@ 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
- executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
20
- approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
18
+ getUsdRate(input: Asset): Promise<string>;
19
+ executeTrade(args: ExecuteTradeInput<'eip155:1'>): Promise<TradeResult>;
20
+ approvalNeeded(args: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
21
21
  approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
22
22
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
23
23
  filterAssetIdsBySellable(assetIds?: AssetId[]): AssetId[];
@@ -46,8 +46,6 @@ async function getZrxTradeQuote(input) {
46
46
  const estimatedGas = (0, bignumber_1.bnOrZero)(data.estimatedGas).times(1.5);
47
47
  const rate = useSellAmount ? data.price : (0, bignumber_1.bn)(1).div(data.price).toString();
48
48
  return {
49
- success: true,
50
- statusReason: '',
51
49
  rate,
52
50
  minimum,
53
51
  maximum,
@@ -58,7 +56,8 @@ async function getZrxTradeQuote(input) {
58
56
  gasPrice: data.gasPrice,
59
57
  approvalFee: sellAssetErc20Address &&
60
58
  (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString()
61
- }
59
+ },
60
+ tradeFee: '0'
62
61
  },
63
62
  sellAmount: data.sellAmount,
64
63
  buyAmount: data.buyAmount,
@@ -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
  };
@@ -3,7 +3,7 @@ import { TradeQuote } from '../../../../api';
3
3
  import { ZrxQuoteResponse } from '../../types';
4
4
  export declare const setupQuote: () => {
5
5
  quoteInput: import("../../../../api").CommonTradeInput;
6
- tradeQuote: TradeQuote<"eip155:1" | "bip122:000000000019d6689c085ae165831e93" | "cosmos:cosmoshub-4" | "cosmos:osmosis-1">;
6
+ tradeQuote: TradeQuote<"eip155:1">;
7
7
  buyAsset: Asset;
8
8
  sellAsset: Asset;
9
9
  };
@@ -44,11 +44,10 @@ export declare const setupExecuteTrade: () => {
44
44
  txData: string;
45
45
  depositAddress: string;
46
46
  receiveAddress: string;
47
- success: boolean;
48
- statusReason: string;
49
47
  feeData: {
50
48
  fee: string;
51
49
  chainSpecific: {};
50
+ tradeFee: string;
52
51
  };
53
52
  rate: string;
54
53
  allowanceContract: string;
@@ -6,8 +6,6 @@ const setupQuote = () => {
6
6
  const sellAsset = { ...assets_1.FOX };
7
7
  const buyAsset = { ...assets_1.WETH };
8
8
  const tradeQuote = {
9
- success: true,
10
- statusReason: '',
11
9
  buyAmount: '',
12
10
  sellAmount: '1000000000000000000',
13
11
  sellAsset,
@@ -16,7 +14,7 @@ const setupQuote = () => {
16
14
  sellAssetAccountId: '0',
17
15
  minimum: '0',
18
16
  maximum: '999999999999',
19
- feeData: { fee: '0' },
17
+ feeData: { fee: '0', tradeFee: '0', chainSpecific: {} },
20
18
  rate: '1',
21
19
  sources: []
22
20
  };
@@ -83,9 +81,7 @@ const setupExecuteTrade = () => {
83
81
  txData: '0x0',
84
82
  depositAddress: '0x0',
85
83
  receiveAddress: '0x0',
86
- success: true,
87
- statusReason: '',
88
- feeData: { fee: '0', chainSpecific: {} },
84
+ feeData: { fee: '0', chainSpecific: {}, tradeFee: '0' },
89
85
  rate: '0',
90
86
  allowanceContract: '0x0',
91
87
  sources: []
@@ -92,8 +92,6 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
92
92
  const trade = {
93
93
  sellAsset,
94
94
  buyAsset,
95
- success: true,
96
- statusReason: '',
97
95
  sellAssetAccountId,
98
96
  receiveAddress,
99
97
  rate: data.price,
@@ -103,7 +101,8 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
103
101
  chainSpecific: {
104
102
  estimatedGas: estimatedGas.toString(),
105
103
  gasPrice: data.gasPrice
106
- }
104
+ },
105
+ tradeFee: '0'
107
106
  },
108
107
  txData: data.data,
109
108
  sellAmount: data.sellAmount,
@@ -125,7 +124,8 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
125
124
  chainSpecific: {
126
125
  ...(_c = trade.feeData) === null || _c === void 0 ? void 0 : _c.chainSpecific,
127
126
  approvalFee: (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString()
128
- }
127
+ },
128
+ tradeFee: '0'
129
129
  };
130
130
  }
131
131
  return trade;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "5.9.0",
3
+ "version": "5.10.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": "^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",