@shapeshiftoss/swapper 11.5.5 → 11.5.7

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
@@ -156,6 +156,13 @@ export interface MinMaxOutput {
156
156
  export declare type ApprovalNeededOutput = {
157
157
  approvalNeeded: boolean;
158
158
  };
159
+ export declare enum SwapperName {
160
+ Thorchain = "THORChain",
161
+ Osmosis = "Osmosis",
162
+ CowSwap = "CowSwap",
163
+ Zrx = "0x",
164
+ Test = "Test"
165
+ }
159
166
  export declare enum SwapperType {
160
167
  ZrxEthereum = "0xEthereum",
161
168
  ZrxAvalanche = "0xAvalanche",
package/dist/api.js CHANGED
@@ -1,9 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwapErrorTypes = exports.SwapperType = exports.SwapError = void 0;
3
+ exports.SwapErrorTypes = exports.SwapperType = exports.SwapperName = exports.SwapError = void 0;
4
4
  const errors_1 = require("@shapeshiftoss/errors");
5
5
  const types_1 = require("@shapeshiftoss/types");
6
6
  exports.SwapError = (0, errors_1.createErrorClass)('SwapError');
7
+ var SwapperName;
8
+ (function (SwapperName) {
9
+ SwapperName["Thorchain"] = "THORChain";
10
+ SwapperName["Osmosis"] = "Osmosis";
11
+ SwapperName["CowSwap"] = "CowSwap";
12
+ SwapperName["Zrx"] = "0x";
13
+ SwapperName["Test"] = "Test";
14
+ })(SwapperName = exports.SwapperName || (exports.SwapperName = {}));
7
15
  var SwapperType;
8
16
  (function (SwapperType) {
9
17
  SwapperType["ZrxEthereum"] = "0xEthereum";
@@ -3,7 +3,7 @@ import { AssetId } from '@shapeshiftoss/caip';
3
3
  import { ethereum } from '@shapeshiftoss/chain-adapters';
4
4
  import { KnownChainIds } from '@shapeshiftoss/types';
5
5
  import Web3 from 'web3';
6
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveAmountInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
6
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveAmountInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperName, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
7
7
  import { CowTrade } from './types';
8
8
  export declare type CowSwapperDeps = {
9
9
  apiUrl: string;
@@ -11,7 +11,7 @@ export declare type CowSwapperDeps = {
11
11
  web3: Web3;
12
12
  };
13
13
  export declare class CowSwapper implements Swapper<KnownChainIds.EthereumMainnet> {
14
- readonly name = "CowSwap";
14
+ readonly name = SwapperName.CowSwap;
15
15
  deps: CowSwapperDeps;
16
16
  constructor(deps: CowSwapperDeps);
17
17
  getType(): SwapperType;
@@ -28,7 +28,7 @@ const blacklist_1 = require("./utils/blacklist");
28
28
  const helpers_1 = require("./utils/helpers/helpers");
29
29
  class CowSwapper {
30
30
  constructor(deps) {
31
- this.name = 'CowSwap';
31
+ this.name = api_1.SwapperName.CowSwap;
32
32
  this.deps = deps;
33
33
  }
34
34
  getType() {
@@ -1,9 +1,9 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
3
- import { ApprovalNeededOutput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeTxs } from '../../api';
3
+ import { ApprovalNeededOutput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperName, SwapperType, Trade, TradeQuote, TradeTxs } from '../../api';
4
4
  import { OsmosisTradeResult, OsmoSwapperDeps } from './utils/types';
5
5
  export declare class OsmosisSwapper implements Swapper<ChainId> {
6
- readonly name = "Osmosis";
6
+ readonly name = SwapperName.Osmosis;
7
7
  supportedAssetIds: string[];
8
8
  deps: OsmoSwapperDeps;
9
9
  getType(): SwapperType;
@@ -8,7 +8,7 @@ const constants_1 = require("./utils/constants");
8
8
  const helpers_1 = require("./utils/helpers");
9
9
  class OsmosisSwapper {
10
10
  constructor(deps) {
11
- this.name = 'Osmosis';
11
+ this.name = api_1.SwapperName.Osmosis;
12
12
  this.deps = deps;
13
13
  this.supportedAssetIds = [caip_1.cosmosAssetId, caip_1.osmosisAssetId];
14
14
  }
@@ -1,12 +1,12 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
3
- import { ApprovalNeededOutput, BuyAssetBySellIdInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
3
+ import { ApprovalNeededOutput, BuyAssetBySellIdInput, Swapper, SwapperName, 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<ChainId> {
9
- readonly name = "Test";
9
+ readonly name = SwapperName.Test;
10
10
  supportAssets: string[];
11
11
  initialize(): Promise<void>;
12
12
  getType(): SwapperType;
@@ -8,7 +8,7 @@ const api_1 = require("../../api");
8
8
  */
9
9
  class TestSwapper {
10
10
  constructor() {
11
- this.name = 'Test';
11
+ this.name = api_1.SwapperName.Test;
12
12
  this.supportAssets = [
13
13
  'bip122:000000000019d6689c085ae165831e93/slip44:0',
14
14
  'cosmos:cosmoshub-4/slip44:118',
@@ -1,11 +1,11 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
3
3
  import { KnownChainIds } from '@shapeshiftoss/types';
4
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperName, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
5
5
  import { ThorchainSwapperDeps } from './types';
6
6
  export * from './types';
7
7
  export declare class ThorchainSwapper implements Swapper<ChainId> {
8
- readonly name = "Thorchain";
8
+ readonly name = SwapperName.Thorchain;
9
9
  private sellSupportedChainIds;
10
10
  private buySupportedChainIds;
11
11
  private supportedSellAssetIds;
@@ -27,7 +27,7 @@ const thorService_1 = require("./utils/thorService");
27
27
  __exportStar(require("./types"), exports);
28
28
  class ThorchainSwapper {
29
29
  constructor(deps) {
30
- this.name = 'Thorchain';
30
+ this.name = api_1.SwapperName.Thorchain;
31
31
  this.sellSupportedChainIds = {
32
32
  [types_1.KnownChainIds.EthereumMainnet]: true,
33
33
  [types_1.KnownChainIds.BitcoinMainnet]: true,
@@ -1,2 +1,3 @@
1
1
  export declare const RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN: import("bignumber.js").default;
2
2
  export declare const MINIMUM_USD_TRADE_AMOUNT: import("bignumber.js").default;
3
+ export declare const MINIMUM_USD_TRADE_AMOUNT_ETHEREUM_NETWORK: import("bignumber.js").default;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MINIMUM_USD_TRADE_AMOUNT = exports.RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN = void 0;
3
+ exports.MINIMUM_USD_TRADE_AMOUNT_ETHEREUM_NETWORK = exports.MINIMUM_USD_TRADE_AMOUNT = exports.RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN = void 0;
4
4
  const bignumber_1 = require("../utils/bignumber");
5
5
  // TODO: read from https://daemon.thorchain.shapeshift.com/lcd/thorchain/constants
6
6
  exports.RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN = (0, bignumber_1.bn)('0.02');
7
7
  exports.MINIMUM_USD_TRADE_AMOUNT = (0, bignumber_1.bn)(1);
8
+ exports.MINIMUM_USD_TRADE_AMOUNT_ETHEREUM_NETWORK = (0, bignumber_1.bn)(42);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getThorTradeQuote = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
+ const types_1 = require("@shapeshiftoss/types");
5
6
  const api_1 = require("../../../api");
6
7
  const bignumber_1 = require("../../utils/bignumber");
7
8
  const constants_1 = require("../../utils/constants");
@@ -36,10 +37,13 @@ const getThorTradeQuote = async ({ deps, input }) => {
36
37
  const estimatedBuyAssetTradeFeeUsd = (0, bignumber_1.bn)(buyAssetUsdRate)
37
38
  .times(estimatedBuyAssetTradeFeeCryptoHuman)
38
39
  .toString();
39
- const buyAssetTradeFeeUsdOrMinimum = constants_2.MINIMUM_USD_TRADE_AMOUNT.gt(estimatedBuyAssetTradeFeeUsd)
40
- ? constants_2.MINIMUM_USD_TRADE_AMOUNT.toString()
40
+ const minimumUsdAmount = buyAsset.chainId === types_1.KnownChainIds.EthereumMainnet
41
+ ? constants_2.MINIMUM_USD_TRADE_AMOUNT_ETHEREUM_NETWORK
42
+ : constants_2.MINIMUM_USD_TRADE_AMOUNT;
43
+ const buyAssetTradeFeeUsdOrMinimum = minimumUsdAmount.gt(estimatedBuyAssetTradeFeeUsd)
44
+ ? minimumUsdAmount.toString()
41
45
  : estimatedBuyAssetTradeFeeUsd;
42
- const sellAssetTradeFeeCryptoHuman = (() => {
46
+ const minimumSellAssetAmountCryptoHuman = (() => {
43
47
  // The 1$ minimum doesn't apply for swaps to RUNE, use OutboundTransactionFee in human value instead
44
48
  if ((0, isRune_1.isRune)(buyAsset === null || buyAsset === void 0 ? void 0 : buyAsset.assetId))
45
49
  return constants_2.RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN;
@@ -47,12 +51,12 @@ const getThorTradeQuote = async ({ deps, input }) => {
47
51
  })();
48
52
  // minimum is tradeFee padded by an amount to be sure they get something back
49
53
  // usually it will be slightly more than the amount because sellAssetTradeFee is already a high estimate
50
- const minimumCryptoHuman = (0, bignumber_1.bnOrZero)(sellAssetTradeFeeCryptoHuman)
54
+ const minimumSellAssetAmountPaddedCryptoHuman = (0, bignumber_1.bnOrZero)(minimumSellAssetAmountCryptoHuman)
51
55
  .times(constants_3.THOR_MINIMUM_PADDING)
52
56
  .toString();
53
57
  const buyAssetTradeFeeUsdOrDefault = (0, isRune_1.isRune)(buyAsset === null || buyAsset === void 0 ? void 0 : buyAsset.assetId)
54
58
  ? (0, bignumber_1.bn)(buyAssetUsdRate).times(constants_2.RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN).toString()
55
- : buyAssetTradeFeeUsdOrMinimum;
59
+ : estimatedBuyAssetTradeFeeUsd;
56
60
  const commonQuoteFields = {
57
61
  rate,
58
62
  maximum: constants_3.MAX_THORCHAIN_TRADE,
@@ -62,7 +66,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
62
66
  buyAsset,
63
67
  sellAsset,
64
68
  bip44Params,
65
- minimum: minimumCryptoHuman,
69
+ minimum: minimumSellAssetAmountPaddedCryptoHuman,
66
70
  };
67
71
  const { chainNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
68
72
  switch (chainNamespace) {
@@ -75,12 +79,12 @@ const getThorTradeQuote = async ({ deps, input }) => {
75
79
  sellAmount: sellAmountCryptoPrecision,
76
80
  slippageTolerance: constants_1.DEFAULT_SLIPPAGE,
77
81
  destinationAddress: receiveAddress,
78
- buyAssetTradeFeeUsd: buyAssetTradeFeeUsdOrMinimum,
82
+ buyAssetTradeFeeUsd: estimatedBuyAssetTradeFeeUsd,
79
83
  });
80
84
  const feeData = await (0, getEthTxFees_1.getEthTxFees)({
81
85
  adapterManager: deps.adapterManager,
82
86
  sellAssetReference,
83
- buyAssetTradeFeeUsd: buyAssetTradeFeeUsdOrMinimum,
87
+ buyAssetTradeFeeUsd: estimatedBuyAssetTradeFeeUsd,
84
88
  });
85
89
  return {
86
90
  ...commonQuoteFields,
@@ -98,7 +102,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
98
102
  slippageTolerance: constants_1.DEFAULT_SLIPPAGE,
99
103
  destinationAddress: receiveAddress,
100
104
  xpub: input.xpub,
101
- buyAssetTradeFeeUsd: buyAssetTradeFeeUsdOrMinimum,
105
+ buyAssetTradeFeeUsd: estimatedBuyAssetTradeFeeUsd,
102
106
  });
103
107
  const feeData = await (0, getBtcTxFees_1.getBtcTxFees)({
104
108
  sellAmount: sellAmountCryptoPrecision,
@@ -106,7 +110,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
106
110
  opReturnData,
107
111
  pubkey,
108
112
  sellAdapter: sellAdapter,
109
- buyAssetTradeFeeUsd: buyAssetTradeFeeUsdOrMinimum,
113
+ buyAssetTradeFeeUsd: estimatedBuyAssetTradeFeeUsd,
110
114
  sendMax,
111
115
  });
112
116
  return {
@@ -1,9 +1,9 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
3
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveAmountInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, EvmSupportedChainIds, GetEvmTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
3
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveAmountInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, EvmSupportedChainIds, GetEvmTradeQuoteInput, Swapper, SwapperName, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
4
  import { ZrxExecuteTradeInput, ZrxSwapperDeps, ZrxTrade } from './types';
5
5
  export declare class ZrxSwapper<T extends EvmSupportedChainIds> implements Swapper<T> {
6
- readonly name = "0x";
6
+ readonly name = SwapperName.Zrx;
7
7
  deps: ZrxSwapperDeps;
8
8
  chainId: ChainId;
9
9
  constructor(deps: ZrxSwapperDeps);
@@ -12,7 +12,7 @@ const zrxBuildTrade_1 = require("./zrxBuildTrade/zrxBuildTrade");
12
12
  const zrxExecuteTrade_1 = require("./zrxExecuteTrade/zrxExecuteTrade");
13
13
  class ZrxSwapper {
14
14
  constructor(deps) {
15
- this.name = '0x';
15
+ this.name = api_1.SwapperName.Zrx;
16
16
  this.deps = deps;
17
17
  this.chainId = deps.adapter.getChainId();
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "11.5.5",
3
+ "version": "11.5.7",
4
4
  "description": "An interface and implementations to trade coins via various protocols",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",