@shapeshiftoss/swapper 11.5.2 → 11.5.4

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.
@@ -12,7 +12,7 @@ const makeTradeTx_1 = require("../utils/ethereum/makeTradeTx");
12
12
  const buildTrade = async ({ deps, input, }) => {
13
13
  var _a, _b, _c, _d;
14
14
  try {
15
- const { buyAsset, receiveAddress: destinationAddress, sellAmount, sellAsset, bip44Params, slippage: slippageTolerance = constants_1.DEFAULT_SLIPPAGE, wallet, } = input;
15
+ const { buyAsset, receiveAddress: destinationAddress, sellAmount, sellAsset, bip44Params, slippage: slippageTolerance = constants_1.DEFAULT_SLIPPAGE, wallet, sendMax, } = input;
16
16
  const quote = await (0, getTradeQuote_1.getThorTradeQuote)({ deps, input });
17
17
  const sellAdapter = deps.adapterManager.get(sellAsset.chainId);
18
18
  if (!sellAdapter)
@@ -66,6 +66,7 @@ const buildTrade = async ({ deps, input, }) => {
66
66
  .satsPerByte,
67
67
  opReturnData,
68
68
  },
69
+ sendMax,
69
70
  });
70
71
  return {
71
72
  chainId: sellAsset.chainId,
@@ -16,7 +16,7 @@ const isRune_1 = require("../utils/isRune/isRune");
16
16
  const getBtcTxFees_1 = require("../utils/txFeeHelpers/btcTxFees/getBtcTxFees");
17
17
  const getEthTxFees_1 = require("../utils/txFeeHelpers/ethTxFees/getEthTxFees");
18
18
  const getThorTradeQuote = async ({ deps, input }) => {
19
- const { sellAsset, buyAsset, sellAmount: sellAmountCryptoPrecision, bip44Params, chainId, receiveAddress, } = input;
19
+ const { sellAsset, buyAsset, sellAmount: sellAmountCryptoPrecision, bip44Params, chainId, receiveAddress, sendMax, } = input;
20
20
  if (!bip44Params) {
21
21
  throw new Error('bip44Params required in getThorTradeQuote');
22
22
  }
@@ -107,6 +107,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
107
107
  pubkey,
108
108
  sellAdapter: sellAdapter,
109
109
  buyAssetTradeFeeUsd: buyAssetTradeFeeUsdOrMinimum,
110
+ sendMax,
110
111
  });
111
112
  return {
112
113
  ...commonQuoteFields,
@@ -28,6 +28,17 @@ const getPriceRatio = async (deps, input) => {
28
28
  const { data: responseData } = await thorService_1.thorService.get(`${deps.daemonUrl}/lcd/thorchain/pools`);
29
29
  const buyPool = responseData.find((response) => response.asset === buyPoolId);
30
30
  const sellPool = responseData.find((response) => response.asset === sellPoolId);
31
+ /**
32
+ * there is no rune pool, rune *is* the pool, special logic case buying RUNE
33
+ */
34
+ if ((0, isRune_1.isRune)(buyAssetId) && sellPool) {
35
+ const sellAssetBalance = (0, bignumber_1.bnOrZero)(sellPool.balance_asset);
36
+ const runeBalance = (0, bignumber_1.bnOrZero)(sellPool.balance_rune);
37
+ // guard against division by zero
38
+ if (sellAssetBalance.eq(0))
39
+ throw new api_1.SwapError(`[getPriceRatio] zero sell asset balance sellAssetId ${sellAssetId} buyAssetId ${buyAssetId}`);
40
+ return (0, bignumber_1.bn)(runeBalance).dividedBy(sellAssetBalance).toString();
41
+ }
31
42
  if (!buyPool || !sellPool) {
32
43
  throw new api_1.SwapError(`[getPriceRatio]: pools not found`, {
33
44
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
@@ -1,10 +1,13 @@
1
1
  import { UtxoBaseAdapter } from '@shapeshiftoss/chain-adapters';
2
2
  import { QuoteFeeData, UtxoSupportedChainIds } from '../../../../../api';
3
- export declare const getBtcTxFees: ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, buyAssetTradeFeeUsd, }: {
3
+ declare type GetBtcTxFeesInput = {
4
4
  opReturnData: string;
5
5
  vault: string;
6
6
  sellAmount: string;
7
7
  sellAdapter: UtxoBaseAdapter<UtxoSupportedChainIds>;
8
8
  pubkey: string;
9
9
  buyAssetTradeFeeUsd: string;
10
- }) => Promise<QuoteFeeData<UtxoSupportedChainIds>>;
10
+ sendMax: boolean;
11
+ };
12
+ export declare const getBtcTxFees: ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }: GetBtcTxFeesInput) => Promise<QuoteFeeData<UtxoSupportedChainIds>>;
13
+ export {};
@@ -4,12 +4,13 @@ exports.getBtcTxFees = void 0;
4
4
  const types_1 = require("@shapeshiftoss/types");
5
5
  const api_1 = require("../../../../../api");
6
6
  const bignumber_1 = require("../../../../utils/bignumber");
7
- const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, buyAssetTradeFeeUsd, }) => {
7
+ const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, buyAssetTradeFeeUsd, sendMax, }) => {
8
8
  try {
9
9
  const feeDataOptions = await sellAdapter.getFeeData({
10
10
  to: vault,
11
11
  value: sellAmount,
12
12
  chainSpecific: { pubkey, opReturnData },
13
+ sendMax,
13
14
  });
14
15
  const feeData = feeDataOptions['fast'];
15
16
  // BCH specific hack:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "11.5.2",
3
+ "version": "11.5.4",
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",