@shapeshiftoss/swapper 14.4.0 → 14.5.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
@@ -118,7 +118,8 @@ export interface TradeQuote<C extends ChainId> extends TradeBase<C> {
118
118
  allowanceContract: string;
119
119
  minimumCryptoHuman: string;
120
120
  maximum: string;
121
- /** @deprecated Use sellAmountCryptoHuman instead */
121
+ recommendedSlippage?: string;
122
+ /** @deprecated Use minimumCryptoHuman instead */
122
123
  minimum?: string;
123
124
  }
124
125
  export interface Trade<C extends ChainId> extends TradeBase<C> {
@@ -244,6 +245,9 @@ export interface Swapper<T extends ChainId> {
244
245
  * Get supported sell assetIds
245
246
  */
246
247
  filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
248
+ /**
249
+ * Get transactions related to a trade
250
+ */
247
251
  getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
248
252
  }
249
253
  export {};
@@ -0,0 +1,23 @@
1
+ import { AssetId } from '@shapeshiftoss/caip';
2
+ import { BN } from '../../utils/bignumber';
3
+ import { ThornodePoolResponse } from '../types';
4
+ declare type GetSingleSwapSlippageArgs = {
5
+ inputAmountThorPrecision: BN;
6
+ pool: ThornodePoolResponse;
7
+ toRune: boolean;
8
+ };
9
+ export declare const getSingleSwapSlippage: ({ inputAmountThorPrecision, pool, toRune, }: GetSingleSwapSlippageArgs) => BN;
10
+ declare type GetDoubleSwapSlippageArgs = {
11
+ inputAmountThorPrecision: BN;
12
+ sellPool: ThornodePoolResponse;
13
+ buyPool: ThornodePoolResponse;
14
+ };
15
+ export declare const getDoubleSwapSlippage: ({ inputAmountThorPrecision, sellPool, buyPool, }: GetDoubleSwapSlippageArgs) => BN;
16
+ declare type GetSlippageArgs = {
17
+ inputAmountThorPrecision: BN;
18
+ daemonUrl: string;
19
+ buyAssetId: AssetId;
20
+ sellAssetId: AssetId;
21
+ };
22
+ export declare const getSlippage: ({ inputAmountThorPrecision, daemonUrl, buyAssetId, sellAssetId, }: GetSlippageArgs) => Promise<BN>;
23
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSlippage = exports.getDoubleSwapSlippage = exports.getSingleSwapSlippage = void 0;
4
+ const caip_1 = require("@shapeshiftoss/caip");
5
+ const utils_1 = require("../../../utils");
6
+ const getTradeRate_1 = require("../utils/getTradeRate/getTradeRate");
7
+ const isRune_1 = require("../utils/isRune/isRune");
8
+ const thorService_1 = require("../utils/thorService");
9
+ const getSingleSwapSlippage = ({ inputAmountThorPrecision, pool, toRune, }) => {
10
+ // formula: (inputAmount) / (inputAmount + inputBalance)
11
+ const inputBalance = toRune ? pool.balance_asset : pool.balance_rune; // input is asset if toRune
12
+ const denominator = inputAmountThorPrecision.plus(inputBalance);
13
+ return inputAmountThorPrecision.div(denominator);
14
+ };
15
+ exports.getSingleSwapSlippage = getSingleSwapSlippage;
16
+ const getDoubleSwapSlippage = ({ inputAmountThorPrecision, sellPool, buyPool, }) => {
17
+ // formula: getSwapOutput(input1) + getSingleSwapSlippage(getSwapOutput(input1) => input2)
18
+ const firstSwapSlippage = (0, exports.getSingleSwapSlippage)({
19
+ inputAmountThorPrecision,
20
+ pool: sellPool,
21
+ toRune: true,
22
+ });
23
+ const firstSwapOutput = (0, getTradeRate_1.getSwapOutput)(inputAmountThorPrecision, sellPool, true);
24
+ const secondSwapSlippage = (0, exports.getSingleSwapSlippage)({
25
+ inputAmountThorPrecision: firstSwapOutput,
26
+ pool: buyPool,
27
+ toRune: false,
28
+ });
29
+ return firstSwapSlippage.plus(secondSwapSlippage);
30
+ };
31
+ exports.getDoubleSwapSlippage = getDoubleSwapSlippage;
32
+ const getSlippage = async ({ inputAmountThorPrecision, daemonUrl, buyAssetId, sellAssetId, }) => {
33
+ try {
34
+ const { data: poolData } = await thorService_1.thorService.get(`${daemonUrl}/lcd/thorchain/pools`);
35
+ const buyPoolId = caip_1.adapters.assetIdToPoolAssetId({ assetId: buyAssetId });
36
+ const sellPoolId = caip_1.adapters.assetIdToPoolAssetId({ assetId: sellAssetId });
37
+ const buyPool = buyPoolId ? poolData.find((response) => response.asset === buyPoolId) : null;
38
+ const sellPool = sellPoolId ? poolData.find((response) => response.asset === sellPoolId) : null;
39
+ const toRune = (0, isRune_1.isRune)(buyAssetId);
40
+ const fromRune = (0, isRune_1.isRune)(sellAssetId);
41
+ switch (true) {
42
+ case toRune: {
43
+ (0, utils_1.assertIsDefined)(sellPool);
44
+ return (0, exports.getSingleSwapSlippage)({
45
+ inputAmountThorPrecision,
46
+ pool: sellPool,
47
+ toRune,
48
+ });
49
+ }
50
+ case fromRune: {
51
+ (0, utils_1.assertIsDefined)(buyPool);
52
+ return (0, exports.getSingleSwapSlippage)({
53
+ inputAmountThorPrecision,
54
+ pool: buyPool,
55
+ toRune,
56
+ });
57
+ }
58
+ default: {
59
+ (0, utils_1.assertIsDefined)(sellPool);
60
+ (0, utils_1.assertIsDefined)(buyPool);
61
+ return (0, exports.getDoubleSwapSlippage)({ inputAmountThorPrecision, sellPool, buyPool });
62
+ }
63
+ }
64
+ }
65
+ catch (e) {
66
+ throw new Error(`Failed to get pool data: ${e}`);
67
+ }
68
+ };
69
+ exports.getSlippage = getSlippage;
@@ -14,6 +14,7 @@ const getUsdRate_1 = require("../utils/getUsdRate/getUsdRate");
14
14
  const isRune_1 = require("../utils/isRune/isRune");
15
15
  const getEvmTxFees_1 = require("../utils/txFeeHelpers/evmTxFees/getEvmTxFees");
16
16
  const getUtxoTxFees_1 = require("../utils/txFeeHelpers/utxoTxFees/getUtxoTxFees");
17
+ const getSlippage_1 = require("./getSlippage");
17
18
  const getThorTradeQuote = async ({ deps, input }) => {
18
19
  const { sellAsset, buyAsset, sellAmountCryptoPrecision, bip44Params, chainId, receiveAddress, sendMax, } = input;
19
20
  if (!bip44Params) {
@@ -32,6 +33,13 @@ const getThorTradeQuote = async ({ deps, input }) => {
32
33
  const rate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmountCryptoPrecision, deps);
33
34
  const buyAmountCryptoPrecision = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)((0, bignumber_1.fromBaseUnit)(sellAmountCryptoPrecision, sellAsset.precision)).times(rate), buyAsset.precision);
34
35
  const buyAssetAddressData = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(deps.daemonUrl, buyAsset.assetId);
36
+ const sellAmountThorPrecision = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)(sellAmountCryptoPrecision, sellAsset.precision), constants_3.THORCHAIN_FIXED_PRECISION);
37
+ const recommendedSlippage = await (0, getSlippage_1.getSlippage)({
38
+ inputAmountThorPrecision: (0, bignumber_1.bn)(sellAmountThorPrecision),
39
+ daemonUrl: deps.daemonUrl,
40
+ buyAssetId: buyAsset.assetId,
41
+ sellAssetId: sellAsset.assetId,
42
+ });
35
43
  const estimatedBuyAssetTradeFeeFeeAssetCryptoHuman = (0, isRune_1.isRune)(buyAsset.assetId)
36
44
  ? constants_2.RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN.toString()
37
45
  : (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(buyAssetAddressData === null || buyAssetAddressData === void 0 ? void 0 : buyAssetAddressData.outbound_fee), constants_3.THORCHAIN_FIXED_PRECISION);
@@ -59,14 +67,15 @@ const getThorTradeQuote = async ({ deps, input }) => {
59
67
  sellAsset,
60
68
  bip44Params,
61
69
  minimumCryptoHuman: minimumSellAssetAmountPaddedCryptoHuman,
70
+ recommendedSlippage: recommendedSlippage.toPrecision(),
62
71
  };
63
72
  const { chainNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
64
73
  switch (chainNamespace) {
65
74
  case caip_1.CHAIN_NAMESPACE.Evm:
66
75
  return (async () => {
67
76
  const sellChainFeeAssetId = sellAdapter.getFeeAssetId();
68
- const ethAddressData = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(deps.daemonUrl, sellChainFeeAssetId);
69
- const router = ethAddressData === null || ethAddressData === void 0 ? void 0 : ethAddressData.router;
77
+ const evmAddressData = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(deps.daemonUrl, sellChainFeeAssetId);
78
+ const router = evmAddressData === null || evmAddressData === void 0 ? void 0 : evmAddressData.router;
70
79
  if (!router)
71
80
  throw new api_1.SwapError(`[getThorTradeQuote] No router address found for ${sellChainFeeAssetId}`);
72
81
  const feeData = await (0, getEvmTxFees_1.getEvmTxFees)({
@@ -1,7 +1,7 @@
1
1
  export declare const MAX_THORCHAIN_TRADE = "100000000000000000000000000";
2
2
  export declare const MAX_ALLOWANCE = "100000000000000000000000000";
3
3
  export declare const THOR_MINIMUM_PADDING = 1.2;
4
- export declare const THOR_ETH_GAS_LIMIT = "100000";
4
+ export declare const THOR_EVM_GAS_LIMIT = "100000";
5
5
  export declare const THORCHAIN_FIXED_PRECISION = 8;
6
6
  export declare const THORCHAIN_AFFILIATE_NAME = "ss";
7
7
  export declare const THORCHAIN_AFFILIATE_BIPS = "0";
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.THORCHAIN_AFFILIATE_BIPS = exports.THORCHAIN_AFFILIATE_NAME = exports.THORCHAIN_FIXED_PRECISION = exports.THOR_ETH_GAS_LIMIT = exports.THOR_MINIMUM_PADDING = exports.MAX_ALLOWANCE = exports.MAX_THORCHAIN_TRADE = void 0;
3
+ exports.THORCHAIN_AFFILIATE_BIPS = exports.THORCHAIN_AFFILIATE_NAME = exports.THORCHAIN_FIXED_PRECISION = exports.THOR_EVM_GAS_LIMIT = exports.THOR_MINIMUM_PADDING = exports.MAX_ALLOWANCE = exports.MAX_THORCHAIN_TRADE = void 0;
4
4
  exports.MAX_THORCHAIN_TRADE = '100000000000000000000000000';
5
5
  exports.MAX_ALLOWANCE = '100000000000000000000000000';
6
6
  exports.THOR_MINIMUM_PADDING = 1.2;
7
- exports.THOR_ETH_GAS_LIMIT = '100000'; // for sends of eth / erc20 into thorchain router
7
+ exports.THOR_EVM_GAS_LIMIT = '100000'; // for sends of eth / erc20 into thorchain router
8
8
  exports.THORCHAIN_FIXED_PRECISION = 8; // limit values are precision 8 regardless of the chain
9
9
  exports.THORCHAIN_AFFILIATE_NAME = 'ss';
10
10
  exports.THORCHAIN_AFFILIATE_BIPS = '0'; // affiliate fee in basis points (100 = 1%)
@@ -8,8 +8,9 @@ const caip_1 = require("@shapeshiftoss/caip");
8
8
  const max_1 = __importDefault(require("lodash/max"));
9
9
  const api_1 = require("../../../../api");
10
10
  const bignumber_1 = require("../../../utils/bignumber");
11
- const constants_1 = require("../../constants");
12
- const constants_2 = require("../constants");
11
+ const constants_1 = require("../../../utils/constants");
12
+ const constants_2 = require("../../constants");
13
+ const constants_3 = require("../constants");
13
14
  const getInboundAddressDataForChain_1 = require("../getInboundAddressDataForChain");
14
15
  const getTradeRate_1 = require("../getTradeRate/getTradeRate");
15
16
  const getUsdRate_1 = require("../getUsdRate/getUsdRate");
@@ -28,27 +29,27 @@ const getLimit = async ({ sellAsset, buyAssetId, sellAmountCryptoPrecision, deps
28
29
  }
29
30
  const sellFeeAssetUsdRate = await (0, getUsdRate_1.getUsdRate)(deps.daemonUrl, sellAssetChainFeeAssetId);
30
31
  const buyAssetUsdRate = await (0, getUsdRate_1.getUsdRate)(deps.daemonUrl, buyAssetId);
31
- const expectedBuyAmountCryptoPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).times(tradeRate), sellAsset.precision), constants_2.THORCHAIN_FIXED_PRECISION);
32
+ const expectedBuyAmountCryptoPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmountCryptoPrecision).times(tradeRate), sellAsset.precision), constants_3.THORCHAIN_FIXED_PRECISION);
32
33
  const isValidSlippageRange = (0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1);
33
34
  if ((0, bignumber_1.bnOrZero)(expectedBuyAmountCryptoPrecision8).lt(0) || !isValidSlippageRange)
34
35
  throw new api_1.SwapError('[getLimit]: bad expected buy amount or bad slippage tolerance', {
35
36
  code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
36
37
  details: { expectedBuyAmountCryptoPrecision8, slippageTolerance },
37
38
  });
38
- const buyAssetTradeFeeCryptoPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(buyAssetTradeFeeUsd).div(buyAssetUsdRate), constants_2.THORCHAIN_FIXED_PRECISION);
39
+ const buyAssetTradeFeeCryptoPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(buyAssetTradeFeeUsd).div(buyAssetUsdRate), constants_3.THORCHAIN_FIXED_PRECISION);
39
40
  const sellAssetAddressData = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(deps.daemonUrl, sellAsset.assetId);
40
41
  const refundFeeBuyAssetCryptoPrecision8 = (() => {
41
42
  switch (true) {
42
43
  // If the sell asset is on THOR the return fee is fixed at 0.02 RUNE
43
44
  case (0, isRune_1.isRune)(sellAsset.assetId): {
44
- const runeFeeUsd = constants_1.RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN.times(sellFeeAssetUsdRate);
45
- return (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(runeFeeUsd).div(buyAssetUsdRate), constants_2.THORCHAIN_FIXED_PRECISION);
45
+ const runeFeeUsd = constants_2.RUNE_OUTBOUND_TRANSACTION_FEE_CRYPTO_HUMAN.times(sellFeeAssetUsdRate);
46
+ return (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(runeFeeUsd).div(buyAssetUsdRate), constants_3.THORCHAIN_FIXED_PRECISION);
46
47
  }
47
48
  // Else the return fee is the outbound fee of the sell asset's chain
48
49
  default: {
49
- const sellAssetTradeFeeCryptoHuman = (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAssetAddressData === null || sellAssetAddressData === void 0 ? void 0 : sellAssetAddressData.outbound_fee), constants_2.THORCHAIN_FIXED_PRECISION);
50
+ const sellAssetTradeFeeCryptoHuman = (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAssetAddressData === null || sellAssetAddressData === void 0 ? void 0 : sellAssetAddressData.outbound_fee), constants_3.THORCHAIN_FIXED_PRECISION);
50
51
  const sellAssetTradeFeeUsd = (0, bignumber_1.bnOrZero)(sellAssetTradeFeeCryptoHuman).times(sellFeeAssetUsdRate);
51
- return (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(sellAssetTradeFeeUsd).div(buyAssetUsdRate), constants_2.THORCHAIN_FIXED_PRECISION);
52
+ return (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(sellAssetTradeFeeUsd).div(buyAssetUsdRate), constants_3.THORCHAIN_FIXED_PRECISION);
52
53
  }
53
54
  }
54
55
  })();
@@ -59,6 +60,7 @@ const getLimit = async ({ sellAsset, buyAssetId, sellAmountCryptoPrecision, deps
59
60
  ]);
60
61
  const expectedBuyAmountAfterHighestFeeCryptoPrecision8 = (0, bignumber_1.bnOrZero)(expectedBuyAmountCryptoPrecision8)
61
62
  .times((0, bignumber_1.bn)(1).minus(slippageTolerance))
63
+ .times((0, bignumber_1.bn)(1).minus(constants_1.ALLOWABLE_MARKET_MOVEMENT))
62
64
  .minus(highestPossibleFeeCryptoPrecision8 !== null && highestPossibleFeeCryptoPrecision8 !== void 0 ? highestPossibleFeeCryptoPrecision8 : 0)
63
65
  .decimalPlaces(0);
64
66
  // expectedBuyAmountAfterHighestFeeCryptoPrecision8 can be negative if the sell asset has a higher inbound_fee
@@ -1,4 +1,6 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { AssetId } from '@shapeshiftoss/caip';
3
- import { ThorchainSwapperDeps } from '../../types';
3
+ import { BN } from '../../../utils/bignumber';
4
+ import { ThorchainSwapperDeps, ThornodePoolResponse } from '../../types';
5
+ export declare const getSwapOutput: (inputAmount: BN, pool: ThornodePoolResponse, toRune: boolean) => BN;
4
6
  export declare const getTradeRate: (sellAsset: Asset, buyAssetId: AssetId, sellAmountCryptoPrecision: string, deps: ThorchainSwapperDeps) => Promise<string>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTradeRate = void 0;
3
+ exports.getTradeRate = exports.getSwapOutput = 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");
@@ -9,23 +9,23 @@ const isRune_1 = require("../isRune/isRune");
9
9
  const thorService_1 = require("../thorService");
10
10
  const THOR_PRECISION = 8;
11
11
  const getSwapOutput = (inputAmount, pool, toRune) => {
12
- const x = inputAmount;
13
- const X = toRune ? pool.balance_asset : pool.balance_rune;
14
- const Y = toRune ? pool.balance_rune : pool.balance_asset;
15
- const numerator = (0, bignumber_1.bn)(x).times(X).times(Y);
16
- const denominator = (0, bignumber_1.bn)(x).plus(X).pow(2);
12
+ const inputBalance = toRune ? pool.balance_asset : pool.balance_rune;
13
+ const outputBalance = toRune ? pool.balance_rune : pool.balance_asset;
14
+ const numerator = inputAmount.times(inputBalance).times(outputBalance);
15
+ const denominator = inputAmount.plus(inputBalance).pow(2);
17
16
  return numerator.div(denominator);
18
17
  };
18
+ exports.getSwapOutput = getSwapOutput;
19
19
  const getDoubleSwapOutput = (input, inputPool, outputPool) => {
20
20
  if (inputPool && outputPool) {
21
- const runeToOutput = getSwapOutput(input, inputPool, true);
22
- return getSwapOutput(runeToOutput, outputPool, false);
21
+ const runeToOutput = (0, exports.getSwapOutput)(input, inputPool, true);
22
+ return (0, exports.getSwapOutput)(runeToOutput, outputPool, false);
23
23
  }
24
24
  if (inputPool && !outputPool) {
25
- return getSwapOutput(input, inputPool, true);
25
+ return (0, exports.getSwapOutput)(input, inputPool, true);
26
26
  }
27
27
  if (!inputPool && outputPool) {
28
- return getSwapOutput(input, outputPool, false);
28
+ return (0, exports.getSwapOutput)(input, outputPool, false);
29
29
  }
30
30
  return (0, bignumber_1.bn)(0); // We should never reach this, but this makes tsc happy
31
31
  };
@@ -3,4 +3,5 @@ export declare const btcThornodePool: ThornodePoolResponse;
3
3
  export declare const ethThornodePool: ThornodePoolResponse;
4
4
  export declare const foxThornodePool: ThornodePoolResponse;
5
5
  export declare const usdcThornodePool: ThornodePoolResponse;
6
+ export declare const thornodePools: ThornodePoolResponse[];
6
7
  export declare const mockInboundAddresses: InboundAddressResponse[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mockInboundAddresses = exports.usdcThornodePool = exports.foxThornodePool = exports.ethThornodePool = exports.btcThornodePool = void 0;
3
+ exports.mockInboundAddresses = exports.thornodePools = exports.usdcThornodePool = exports.foxThornodePool = exports.ethThornodePool = exports.btcThornodePool = void 0;
4
4
  exports.btcThornodePool = {
5
5
  LP_units: '536055974608843',
6
6
  asset: 'BTC.BTC',
@@ -49,6 +49,12 @@ exports.usdcThornodePool = {
49
49
  synth_supply: '25598723155460',
50
50
  synth_units: '1936419947970',
51
51
  };
52
+ exports.thornodePools = [
53
+ exports.btcThornodePool,
54
+ exports.ethThornodePool,
55
+ exports.foxThornodePool,
56
+ exports.usdcThornodePool,
57
+ ];
52
58
  exports.mockInboundAddresses = [
53
59
  {
54
60
  chain: 'BCH',
@@ -9,9 +9,10 @@ const constants_2 = require("../../constants");
9
9
  const getEvmTxFees = async ({ adapter, sellAssetReference, buyAssetTradeFeeUsd, }) => {
10
10
  try {
11
11
  const gasFeeData = await adapter.getGasFeeData();
12
- // this is a good value to cover all thortrades out of eth/erc20
12
+ // this is a good value to cover all thortrades out of EVMs
13
13
  // in the future we may want to look at doing this more precisely and in a future-proof way
14
- const gasLimit = constants_2.THOR_ETH_GAS_LIMIT;
14
+ // TODO: calculate this dynamically
15
+ const gasLimit = constants_2.THOR_EVM_GAS_LIMIT;
15
16
  const feeDataOptions = {
16
17
  fast: {
17
18
  txFee: (0, bignumber_1.bn)(gasLimit).times(gasFeeData[chain_adapters_1.FeeDataKey.Fast].gasPrice).toString(),
@@ -1,2 +1,3 @@
1
1
  export declare const APPROVAL_GAS_LIMIT = "100000";
2
2
  export declare const DEFAULT_SLIPPAGE = "0.03";
3
+ export declare const ALLOWABLE_MARKET_MOVEMENT = "0.005";
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_SLIPPAGE = exports.APPROVAL_GAS_LIMIT = void 0;
3
+ exports.ALLOWABLE_MARKET_MOVEMENT = exports.DEFAULT_SLIPPAGE = exports.APPROVAL_GAS_LIMIT = void 0;
4
4
  exports.APPROVAL_GAS_LIMIT = '100000'; // Most approvals are around 40k, we've seen 72k in the wild, so 100000 for safety.
5
5
  exports.DEFAULT_SLIPPAGE = '0.03'; // 3%
6
+ exports.ALLOWABLE_MARKET_MOVEMENT = '0.005'; // 0.5% is what https://app.thorswap.finance/ uses
@@ -0,0 +1 @@
1
+ export declare function assertIsDefined<T>(val: T): asserts val is NonNullable<T>;
package/dist/utils.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertIsDefined = void 0;
4
+ const assert_1 = require("assert");
5
+ // asserts x is type doesn't work when using arrow functions
6
+ function assertIsDefined(val) {
7
+ if (val === undefined || val === null) {
8
+ throw new assert_1.AssertionError({ message: `Expected 'val' to be defined, but received ${val}` });
9
+ }
10
+ }
11
+ exports.assertIsDefined = assertIsDefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "14.4.0",
3
+ "version": "14.5.0",
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",