@shapeshiftoss/swapper 2.2.1 → 3.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.
package/dist/api.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CAIP19 } from '@shapeshiftoss/caip';
2
2
  import { HDWallet } from '@shapeshiftoss/hdwallet-core';
3
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote, SendMaxAmountInput, SwapperType } from '@shapeshiftoss/types';
3
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote, SwapperType } from '@shapeshiftoss/types';
4
4
  export declare type SupportedAssetInput = {
5
5
  assetIds: CAIP19[];
6
6
  };
@@ -23,11 +23,11 @@ export interface Swapper {
23
23
  /**
24
24
  * Get a Quote along with an unsigned transaction that can be signed and broadcast to execute the swap
25
25
  **/
26
- buildQuoteTx(args: BuildQuoteTxInput): Promise<Quote<ChainTypes, SwapperType>>;
26
+ buildQuoteTx(args: BuildQuoteTxInput): Promise<Quote<ChainTypes>>;
27
27
  /**
28
28
  * Get a basic quote (rate) for a trading pair
29
29
  */
30
- getQuote(input: GetQuoteInput, wallet?: HDWallet): Promise<Quote<ChainTypes, SwapperType>>;
30
+ getQuote(input: GetQuoteInput, wallet?: HDWallet): Promise<Quote<ChainTypes>>;
31
31
  /**
32
32
  * Get the usd rate from either the assets symbol or tokenId
33
33
  */
@@ -43,19 +43,15 @@ export interface Swapper {
43
43
  /**
44
44
  * Execute a quote built with buildQuoteTx by signing and broadcasting
45
45
  */
46
- executeQuote(args: ExecQuoteInput<ChainTypes, SwapperType>): Promise<ExecQuoteOutput>;
46
+ executeQuote(args: ExecQuoteInput<ChainTypes>): Promise<ExecQuoteOutput>;
47
47
  /**
48
48
  * Get a boolean if a quote needs approval
49
49
  */
50
- approvalNeeded(args: ApprovalNeededInput<ChainTypes, SwapperType>): Promise<ApprovalNeededOutput>;
50
+ approvalNeeded(args: ApprovalNeededInput<ChainTypes>): Promise<ApprovalNeededOutput>;
51
51
  /**
52
52
  * Get the txid of an approve infinite transaction
53
53
  */
54
- approveInfinite(args: ApproveInfiniteInput<ChainTypes, SwapperType>): Promise<string>;
55
- /**
56
- * Get max swap balance (minus fees) for sell asset
57
- */
58
- getSendMaxAmount(args: SendMaxAmountInput): Promise<string>;
54
+ approveInfinite(args: ApproveInfiniteInput<ChainTypes>): Promise<string>;
59
55
  /**
60
56
  * Get supported buyAssetId's by sellAssetId
61
57
  */
@@ -9,15 +9,14 @@ export declare class TestSwapper implements Swapper {
9
9
  supportAssets: string[];
10
10
  getType(): SwapperType;
11
11
  constructor();
12
- getQuote(): Promise<Quote<ChainTypes, SwapperType>>;
13
- buildQuoteTx(): Promise<Quote<ChainTypes, SwapperType>>;
12
+ getQuote(): Promise<Quote<ChainTypes>>;
13
+ buildQuoteTx(): Promise<Quote<ChainTypes>>;
14
14
  getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
15
15
  getMinMax(input: GetQuoteInput): Promise<MinMaxOutput>;
16
16
  executeQuote(): Promise<ExecQuoteOutput>;
17
17
  getDefaultPair(): [CAIP19, CAIP19];
18
18
  approvalNeeded(): Promise<ApprovalNeededOutput>;
19
19
  approveInfinite(): Promise<string>;
20
- getSendMaxAmount(): Promise<string>;
21
20
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): CAIP19[];
22
21
  filterAssetIdsBySellable(): CAIP19[];
23
22
  }
@@ -43,9 +43,6 @@ class TestSwapper {
43
43
  async approveInfinite() {
44
44
  throw new Error('TestSwapper: approveInfinite unimplemented');
45
45
  }
46
- async getSendMaxAmount() {
47
- throw new Error('TestSwapper: getSendMaxAmount unimplemented');
48
- }
49
46
  filterBuyAssetsBySellAssetId(args) {
50
47
  const { sellAssetId } = args;
51
48
  if (!this.supportAssets.includes(sellAssetId))
@@ -3,15 +3,14 @@ import { ApprovalNeededOutput, Asset, ChainTypes, ExecQuoteOutput, GetQuoteInput
3
3
  import { Swapper } from '../../api';
4
4
  export declare class ThorchainSwapper implements Swapper {
5
5
  getType(): SwapperType;
6
- getQuote(): Promise<Quote<ChainTypes, SwapperType>>;
7
- buildQuoteTx(): Promise<Quote<ChainTypes, SwapperType>>;
6
+ getQuote(): Promise<Quote<ChainTypes>>;
7
+ buildQuoteTx(): Promise<Quote<ChainTypes>>;
8
8
  getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
9
9
  getMinMax(input: GetQuoteInput): Promise<MinMaxOutput>;
10
10
  executeQuote(): Promise<ExecQuoteOutput>;
11
11
  getDefaultPair(): [CAIP19, CAIP19];
12
12
  approvalNeeded(): Promise<ApprovalNeededOutput>;
13
13
  approveInfinite(): Promise<string>;
14
- getSendMaxAmount(): Promise<string>;
15
14
  filterBuyAssetsBySellAssetId(): CAIP19[];
16
15
  filterAssetIdsBySellable(): CAIP19[];
17
16
  }
@@ -32,9 +32,6 @@ class ThorchainSwapper {
32
32
  async approveInfinite() {
33
33
  throw new Error('ThorchainSwapper: approveInfinite unimplemented');
34
34
  }
35
- async getSendMaxAmount() {
36
- throw new Error('ThorchainSwapper: getSendMaxAmount unimplemented');
37
- }
38
35
  filterBuyAssetsBySellAssetId() {
39
36
  return [];
40
37
  }
@@ -1,3 +1,3 @@
1
- import { ApprovalNeededInput, ApprovalNeededOutput, ChainTypes, SwapperType } from '@shapeshiftoss/types';
1
+ import { ApprovalNeededInput, ApprovalNeededOutput, ChainTypes } from '@shapeshiftoss/types';
2
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function ZrxApprovalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<ChainTypes, SwapperType>): Promise<ApprovalNeededOutput>;
3
+ export declare function ZrxApprovalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<ChainTypes>): Promise<ApprovalNeededOutput>;
@@ -1,3 +1,3 @@
1
- import { ApproveInfiniteInput, ChainTypes, SwapperType } from '@shapeshiftoss/types';
1
+ import { ApproveInfiniteInput, ChainTypes } from '@shapeshiftoss/types';
2
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function ZrxApproveInfinite({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<ChainTypes, SwapperType>): Promise<string>;
3
+ export declare function ZrxApproveInfinite({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<ChainTypes>): Promise<string>;
@@ -1,3 +1,3 @@
1
- import { BuildQuoteTxInput, ChainTypes, Quote, SwapperType } from '@shapeshiftoss/types';
1
+ import { BuildQuoteTxInput, ChainTypes, Quote } from '@shapeshiftoss/types';
2
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function ZrxBuildQuoteTx({ adapterManager, web3 }: ZrxSwapperDeps, { input, wallet }: BuildQuoteTxInput): Promise<Quote<ChainTypes, SwapperType>>;
3
+ export declare function ZrxBuildQuoteTx({ adapterManager, web3 }: ZrxSwapperDeps, { input, wallet }: BuildQuoteTxInput): Promise<Quote<ChainTypes>>;
@@ -1,3 +1,3 @@
1
- import { ChainTypes, ExecQuoteInput, ExecQuoteOutput, SwapperType } from '@shapeshiftoss/types';
1
+ import { ChainTypes, ExecQuoteInput, ExecQuoteOutput } from '@shapeshiftoss/types';
2
2
  import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function ZrxExecuteQuote({ adapterManager }: ZrxSwapperDeps, { quote, wallet }: ExecQuoteInput<ChainTypes.Ethereum, SwapperType>): Promise<ExecQuoteOutput>;
3
+ export declare function ZrxExecuteQuote({ adapterManager }: ZrxSwapperDeps, { quote, wallet }: ExecQuoteInput<ChainTypes.Ethereum>): Promise<ExecQuoteOutput>;
@@ -1,6 +1,6 @@
1
1
  import { CAIP19 } from '@shapeshiftoss/caip';
2
2
  import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
3
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote, SendMaxAmountInput, SwapperType } from '@shapeshiftoss/types';
3
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote, SwapperType } from '@shapeshiftoss/types';
4
4
  import Web3 from 'web3';
5
5
  import { BuyAssetBySellIdInput, Swapper } from '../../api';
6
6
  export declare type ZrxSwapperDeps = {
@@ -15,15 +15,14 @@ export declare class ZrxSwapper implements Swapper {
15
15
  deps: ZrxSwapperDeps;
16
16
  constructor(deps: ZrxSwapperDeps);
17
17
  getType(): SwapperType;
18
- buildQuoteTx(args: BuildQuoteTxInput): Promise<Quote<ChainTypes, SwapperType>>;
19
- getQuote(input: GetQuoteInput): Promise<Quote<ChainTypes, SwapperType>>;
18
+ buildQuoteTx(args: BuildQuoteTxInput): Promise<Quote<ChainTypes>>;
19
+ getQuote(input: GetQuoteInput): Promise<Quote<ChainTypes>>;
20
20
  getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
21
21
  getMinMax(input: GetQuoteInput): Promise<MinMaxOutput>;
22
22
  getDefaultPair(): [CAIP19, CAIP19];
23
- executeQuote(args: ExecQuoteInput<ChainTypes, SwapperType>): Promise<ExecQuoteOutput>;
24
- approvalNeeded(args: ApprovalNeededInput<ChainTypes, SwapperType>): Promise<ApprovalNeededOutput>;
25
- approveInfinite(args: ApproveInfiniteInput<ChainTypes, SwapperType>): Promise<string>;
26
- getSendMaxAmount(args: SendMaxAmountInput): Promise<string>;
23
+ executeQuote(args: ExecQuoteInput<ChainTypes>): Promise<ExecQuoteOutput>;
24
+ approvalNeeded(args: ApprovalNeededInput<ChainTypes>): Promise<ApprovalNeededOutput>;
25
+ approveInfinite(args: ApproveInfiniteInput<ChainTypes>): Promise<string>;
27
26
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): CAIP19[];
28
27
  filterAssetIdsBySellable(assetIds: CAIP19[]): CAIP19[];
29
28
  }
@@ -4,7 +4,6 @@ exports.ZrxSwapper = exports.ZrxError = void 0;
4
4
  const types_1 = require("@shapeshiftoss/types");
5
5
  const getZrxMinMax_1 = require("./getZrxMinMax/getZrxMinMax");
6
6
  const getZrxQuote_1 = require("./getZrxQuote/getZrxQuote");
7
- const getZrxSendMaxAmount_1 = require("./getZrxSendMaxAmount/getZrxSendMaxAmount");
8
7
  const helpers_1 = require("./utils/helpers/helpers");
9
8
  const ZrxApprovalNeeded_1 = require("./ZrxApprovalNeeded/ZrxApprovalNeeded");
10
9
  const ZrxApproveInfinite_1 = require("./ZrxApproveInfinite/ZrxApproveInfinite");
@@ -50,9 +49,6 @@ class ZrxSwapper {
50
49
  async approveInfinite(args) {
51
50
  return (0, ZrxApproveInfinite_1.ZrxApproveInfinite)(this.deps, args);
52
51
  }
53
- async getSendMaxAmount(args) {
54
- return (0, getZrxSendMaxAmount_1.getZrxSendMaxAmount)(this.deps, args);
55
- }
56
52
  filterBuyAssetsBySellAssetId(args) {
57
53
  const { assetIds, sellAssetId } = args;
58
54
  // TODO: pending changes to caip lib, we may want to import caip2 value instead.
@@ -1,2 +1,2 @@
1
- import { ChainTypes, GetQuoteInput, Quote, SwapperType } from '@shapeshiftoss/types';
2
- export declare function getZrxQuote(input: GetQuoteInput): Promise<Quote<ChainTypes.Ethereum, SwapperType>>;
1
+ import { ChainTypes, GetQuoteInput, Quote } from '@shapeshiftoss/types';
2
+ export declare function getZrxQuote(input: GetQuoteInput): Promise<Quote<ChainTypes.Ethereum>>;
@@ -1,11 +1,11 @@
1
1
  import { ChainAdapter } from '@shapeshiftoss/chain-adapters';
2
2
  import { HDWallet } from '@shapeshiftoss/hdwallet-core';
3
- import { Asset, ChainTypes, Quote, SwapperType } from '@shapeshiftoss/types';
3
+ import { Asset, ChainTypes, Quote } from '@shapeshiftoss/types';
4
4
  import BigNumber from 'bignumber.js';
5
5
  import Web3 from 'web3';
6
6
  import { AbiItem } from 'web3-utils';
7
7
  export declare type GetAllowanceRequiredArgs = {
8
- quote: Quote<ChainTypes, SwapperType>;
8
+ quote: Quote<ChainTypes>;
9
9
  web3: Web3;
10
10
  erc20AllowanceAbi: AbiItem[];
11
11
  };
@@ -17,7 +17,7 @@ export declare type GetERC20AllowanceArgs = {
17
17
  spenderAddress: string;
18
18
  };
19
19
  declare type GrantAllowanceArgs = {
20
- quote: Quote<ChainTypes, SwapperType>;
20
+ quote: Quote<ChainTypes>;
21
21
  wallet: HDWallet;
22
22
  adapter: ChainAdapter<ChainTypes.Ethereum>;
23
23
  erc20Abi: AbiItem[];
@@ -4,6 +4,8 @@ exports.FOX = exports.WETH = exports.BTC = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
5
  const types_1 = require("@shapeshiftoss/types");
6
6
  exports.BTC = {
7
+ assetId: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
8
+ chainId: 'bip122:000000000019d6689c085ae165831e93',
7
9
  caip19: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
8
10
  caip2: 'bip122:000000000019d6689c085ae165831e93',
9
11
  name: 'bitcoin',
@@ -24,6 +26,8 @@ exports.BTC = {
24
26
  symbol: 'BTC'
25
27
  };
26
28
  exports.WETH = {
29
+ assetId: 'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
30
+ chainId: 'eip155:1',
27
31
  caip19: 'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
28
32
  caip2: 'eip155:1',
29
33
  name: 'WETH',
@@ -45,6 +49,8 @@ exports.WETH = {
45
49
  symbol: 'WETH'
46
50
  };
47
51
  exports.FOX = {
52
+ assetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d',
53
+ chainId: 'eip155:1',
48
54
  caip19: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d',
49
55
  caip2: 'eip155:1',
50
56
  name: 'FOX',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "2.2.1",
3
+ "version": "3.0.0",
4
4
  "description": "TODO: description",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",
@@ -1,3 +0,0 @@
1
- import { SendMaxAmountInput } from '@shapeshiftoss/types';
2
- import { ZrxSwapperDeps } from '../ZrxSwapper';
3
- export declare function getZrxSendMaxAmount({ adapterManager }: ZrxSwapperDeps, { wallet, quote, sellAssetAccountId, feeEstimateKey }: SendMaxAmountInput): Promise<string>;
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getZrxSendMaxAmount = void 0;
7
- const caip_1 = require("@shapeshiftoss/caip");
8
- const types_1 = require("@shapeshiftoss/types");
9
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
10
- const api_1 = require("../../../api");
11
- const bignumber_1 = require("../utils/bignumber");
12
- const constants_1 = require("../utils/constants");
13
- async function getZrxSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAccountId, feeEstimateKey = types_1.chainAdapters.FeeDataKey.Average }) {
14
- var _a, _b, _c;
15
- const adapter = adapterManager.byChain(types_1.ChainTypes.Ethereum);
16
- const bip44Params = adapter.buildBIP44Params({
17
- accountNumber: (0, bignumber_1.bnOrZero)(sellAssetAccountId).toNumber()
18
- });
19
- const ethAddress = await adapter.getAddress({ wallet, bip44Params });
20
- const account = await adapter.getAccount(ethAddress);
21
- if (!quote.sellAsset) {
22
- throw new api_1.SwapError('quote.sellAsset is required');
23
- }
24
- const tokenId = (_a = quote.sellAsset) === null || _a === void 0 ? void 0 : _a.tokenId;
25
- let balance;
26
- if (tokenId) {
27
- balance = (_c = (_b = account.chainSpecific.tokens) === null || _b === void 0 ? void 0 : _b.find((token) => {
28
- return caip_1.caip19.fromCAIP19(token.caip19).assetReference === tokenId.toLowerCase();
29
- })) === null || _c === void 0 ? void 0 : _c.balance;
30
- }
31
- else {
32
- balance = account.balance;
33
- }
34
- if (!balance) {
35
- throw new api_1.SwapError(`No balance found for ${tokenId ? quote.sellAsset.symbol : 'ETH'}`);
36
- }
37
- // return the erc20 token balance. No need to subtract the fee.
38
- if (tokenId && new bignumber_js_1.default(balance).gt(0)) {
39
- return balance;
40
- }
41
- if (!quote.txData) {
42
- throw new api_1.SwapError('quote.txData is required to get correct fee estimate');
43
- }
44
- const feeEstimates = await adapter.getFeeData({
45
- to: quote.depositAddress,
46
- value: (0, bignumber_1.bnOrZero)(quote.sellAmount).toString(),
47
- chainSpecific: {
48
- from: ethAddress,
49
- contractData: quote.txData
50
- }
51
- });
52
- const estimatedFee = feeEstimates[feeEstimateKey].txFee;
53
- // (ryankk) We need to pad the fee for ETH max sends because the fee estimate is based off
54
- // of a minimum quote value (quote.sellAmount) and not the users full ETH balance.
55
- const paddedFee = new bignumber_js_1.default(estimatedFee).times(constants_1.ETH_FEE_ESTIMATE_PADDING);
56
- const sendMaxAmount = new bignumber_js_1.default(balance).minus(paddedFee);
57
- // gte covers if sendMaxAmount is NaN
58
- if (!sendMaxAmount.gte(0)) {
59
- throw new api_1.SwapError('ETH balance is less than estimated fee');
60
- }
61
- return sendMaxAmount.toString();
62
- }
63
- exports.getZrxSendMaxAmount = getZrxSendMaxAmount;