@shapeshiftoss/swapper 11.4.1 → 11.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.
Files changed (28) hide show
  1. package/dist/api.d.ts +5 -0
  2. package/dist/swappers/cow/cowBuildTrade/cowBuildTrade.js +9 -1
  3. package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +6 -4
  4. package/dist/swappers/osmosis/OsmosisSwapper.js +16 -4
  5. package/dist/swappers/osmosis/utils/helpers.d.ts +1 -1
  6. package/dist/swappers/osmosis/utils/helpers.js +4 -2
  7. package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.js +2 -2
  8. package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +10 -7
  9. package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.d.ts +1 -1
  10. package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.js +2 -2
  11. package/dist/swappers/thorchain/utils/cosmos/cosmosTxData.d.ts +1 -2
  12. package/dist/swappers/thorchain/utils/cosmos/cosmosTxData.js +1 -1
  13. package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.d.ts +2 -2
  14. package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.js +2 -2
  15. package/dist/swappers/thorchain/utils/ethereum/utils/getThorTxData.d.ts +1 -1
  16. package/dist/swappers/thorchain/utils/ethereum/utils/getThorTxData.js +2 -2
  17. package/dist/swappers/thorchain/utils/getLimit/getLimit.d.ts +2 -2
  18. package/dist/swappers/thorchain/utils/getLimit/getLimit.js +2 -2
  19. package/dist/swappers/thorchain/utils/txFeeHelpers/btcTxFees/getBtcTxFees.d.ts +2 -2
  20. package/dist/swappers/thorchain/utils/txFeeHelpers/btcTxFees/getBtcTxFees.js +7 -4
  21. package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.d.ts +2 -2
  22. package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.js +5 -2
  23. package/dist/swappers/utils/test-data/setupSwapQuote.js +8 -1
  24. package/dist/swappers/zrx/getZrxTradeQuote/getZrxTradeQuote.js +5 -1
  25. package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.d.ts +3 -0
  26. package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.js +8 -1
  27. package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +5 -1
  28. package/package.json +1 -1
package/dist/api.d.ts CHANGED
@@ -59,7 +59,12 @@ declare type ChainSpecificQuoteFeeData<T extends ChainId> = ChainSpecific<T, {
59
59
  };
60
60
  }>;
61
61
  export declare type QuoteFeeData<T extends ChainId> = {
62
+ networkFee: string;
63
+ buyAssetTradeFeeUsd: string;
64
+ sellAssetTradeFeeUsd?: string;
65
+ /** @deprecated Use networkFee instead */
62
66
  fee: string;
67
+ /** @deprecated Use sellAssetTradeFeeUsd instead */
63
68
  tradeFee: string;
64
69
  } & ChainSpecificQuoteFeeData<T>;
65
70
  export declare type ByPairInput = {
@@ -57,6 +57,11 @@ async function cowBuildTrade(deps, input) {
57
57
  sellAmountBeforeFee: normalizedSellAmount,
58
58
  });
59
59
  const { data: { quote }, } = quoteResponse;
60
+ const sellAssetUsdRate = await (0, helpers_2.getUsdRate)(deps, sellAsset);
61
+ const sellAssetTradeFeeUsd = (0, bignumber_1.bnOrZero)(quote.feeAmount)
62
+ .div((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision))
63
+ .multipliedBy((0, bignumber_1.bnOrZero)(sellAssetUsdRate))
64
+ .toString();
60
65
  const buyCryptoAmount = (0, bignumber_1.bn)(quote.buyAmount).div((0, bignumber_1.bn)(10).exponentiatedBy(buyAsset.precision));
61
66
  const sellCryptoAmount = (0, bignumber_1.bn)(quote.sellAmount).div((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
62
67
  const rate = buyCryptoAmount.div(sellCryptoAmount).toString();
@@ -75,11 +80,14 @@ async function cowBuildTrade(deps, input) {
75
80
  rate,
76
81
  feeData: {
77
82
  fee: '0',
83
+ networkFee: '0',
78
84
  chainSpecific: {
79
85
  estimatedGas: feeData.chainSpecific.gasLimit,
80
86
  gasPrice: feeData.chainSpecific.gasPrice,
81
87
  },
82
- tradeFee: '0', // Trade fees for buy Asset are always 0 since trade fees are subtracted from sell asset
88
+ tradeFee: '0',
89
+ buyAssetTradeFeeUsd: '0',
90
+ sellAssetTradeFeeUsd,
83
91
  },
84
92
  sellAmount: normalizedSellAmount,
85
93
  buyAmount: quote.buyAmount,
@@ -81,12 +81,11 @@ async function getCowSwapTradeQuote(deps, input) {
81
81
  }),
82
82
  (0, helpers_2.getUsdRate)(deps, sellAsset),
83
83
  ]);
84
- const feeData = feeDataOptions['fast'];
85
- // calculating trade fee in USD
86
- const tradeFeeFiat = (0, bignumber_1.bnOrZero)(quote.feeAmount)
84
+ const sellAssetTradeFeeUsd = (0, bignumber_1.bnOrZero)(quote.feeAmount)
87
85
  .div((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision))
88
86
  .multipliedBy((0, bignumber_1.bnOrZero)(sellAssetUsdRate))
89
87
  .toString();
88
+ const feeData = feeDataOptions['fast'];
90
89
  // If original sellAmount is < minQuoteSellAmount, we don't want to replace it with normalizedSellAmount
91
90
  // The purpose of this was to get a quote from CowSwap even with small amounts
92
91
  const quoteSellAmount = (0, bignumber_1.bnOrZero)(sellAmount).lt(minQuoteSellAmount)
@@ -98,6 +97,7 @@ async function getCowSwapTradeQuote(deps, input) {
98
97
  maximum,
99
98
  feeData: {
100
99
  fee: '0',
100
+ networkFee: '0',
101
101
  chainSpecific: {
102
102
  estimatedGas: feeData.chainSpecific.gasLimit,
103
103
  gasPrice: feeData.chainSpecific.gasPrice,
@@ -105,7 +105,9 @@ async function getCowSwapTradeQuote(deps, input) {
105
105
  .multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
106
106
  .toString(),
107
107
  },
108
- tradeFee: tradeFeeFiat,
108
+ tradeFee: '0',
109
+ buyAssetTradeFeeUsd: '0',
110
+ sellAssetTradeFeeUsd,
109
111
  },
110
112
  sellAmount: quoteSellAmount,
111
113
  buyAmount: quote.buyAmount,
@@ -93,7 +93,7 @@ class OsmosisSwapper {
93
93
  code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
94
94
  });
95
95
  }
96
- const { tradeFee, rate, buyAmount } = await (0, helpers_1.getRateInfo)(sellAsset.symbol, buyAsset.symbol, sellAmount !== '0' ? sellAmount : '1', this.deps.osmoUrl);
96
+ const { buyAssetTradeFeeUsd, rate, buyAmount } = await (0, helpers_1.getRateInfo)(sellAsset.symbol, buyAsset.symbol, sellAmount !== '0' ? sellAmount : '1', this.deps.osmoUrl);
97
97
  //convert amount to base
98
98
  const amountBaseSell = String((0, bignumber_1.bnOrZero)(sellAmount).dp(0));
99
99
  const osmosisAdapter = this.deps.adapterManager.get(caip_1.osmosisChainId);
@@ -106,7 +106,13 @@ class OsmosisSwapper {
106
106
  return {
107
107
  buyAmount,
108
108
  buyAsset,
109
- feeData: { fee, tradeFee },
109
+ feeData: {
110
+ fee,
111
+ tradeFee: buyAssetTradeFeeUsd,
112
+ networkFee: fee,
113
+ sellAssetTradeFeeUsd: '0',
114
+ buyAssetTradeFeeUsd,
115
+ },
110
116
  rate,
111
117
  receiveAddress,
112
118
  sellAmount: amountBaseSell,
@@ -122,7 +128,7 @@ class OsmosisSwapper {
122
128
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
123
129
  });
124
130
  }
125
- const { tradeFee, rate, buyAmount } = await (0, helpers_1.getRateInfo)(sellAsset.symbol, buyAsset.symbol, sellAmount !== '0' ? sellAmount : '1', this.deps.osmoUrl);
131
+ const { buyAssetTradeFeeUsd, rate, buyAmount } = await (0, helpers_1.getRateInfo)(sellAsset.symbol, buyAsset.symbol, sellAmount !== '0' ? sellAmount : '1', this.deps.osmoUrl);
126
132
  const { minimum, maximum } = await this.getMinMax(input);
127
133
  const osmosisAdapter = this.deps.adapterManager.get(caip_1.osmosisChainId);
128
134
  if (!osmosisAdapter)
@@ -133,7 +139,13 @@ class OsmosisSwapper {
133
139
  const fee = feeData.fast.txFee;
134
140
  return {
135
141
  buyAsset,
136
- feeData: { fee, tradeFee },
142
+ feeData: {
143
+ fee,
144
+ tradeFee: buyAssetTradeFeeUsd,
145
+ networkFee: fee,
146
+ sellAssetTradeFeeUsd: '0',
147
+ buyAssetTradeFeeUsd,
148
+ },
137
149
  maximum,
138
150
  minimum,
139
151
  bip44Params,
@@ -18,7 +18,7 @@ export declare const pollForAtomChannelBalance: (address: string, osmoUrl: strin
18
18
  export declare const getRateInfo: (sellAsset: string, buyAsset: string, sellAmount: string, osmoUrl: string) => Promise<{
19
19
  rate: string;
20
20
  priceImpact: string;
21
- tradeFee: string;
21
+ buyAssetTradeFeeUsd: string;
22
22
  buyAmount: string;
23
23
  }>;
24
24
  export declare const performIbcTransfer: (input: IbcTransferInput, adapter: CosmosSdkSupportedChainAdapters, wallet: HDWallet, blockBaseUrl: string, denom: string, sourceChannel: string, feeAmount: string, accountNumber: string, sequence: string, gas: string, feeDenom: string) => Promise<TradeResult>;
@@ -145,11 +145,13 @@ const getInfoFromPool = (sellAmount, pool, sellAssetIndex, buyAssetIndex) => {
145
145
  const rate = (0, bignumber_1.bnOrZero)(buyAmount).dividedBy(sellAmount).toString();
146
146
  const priceImpact = (0, bignumber_1.bn)(1).minus(initialMarketPrice.dividedBy(finalMarketPrice)).abs().toString();
147
147
  const tradeFeeBase = (0, bignumber_1.bnOrZero)(buyAmount).times((0, bignumber_1.bnOrZero)(pool.poolParams.swapFee));
148
- const tradeFee = tradeFeeBase.dividedBy((0, bignumber_1.bn)(10).exponentiatedBy(constants_1.OSMOSIS_PRECISION)).toString();
148
+ const buyAssetTradeFeeUsd = tradeFeeBase
149
+ .dividedBy((0, bignumber_1.bn)(10).exponentiatedBy(constants_1.OSMOSIS_PRECISION))
150
+ .toString();
149
151
  return {
150
152
  rate,
151
153
  priceImpact,
152
- tradeFee,
154
+ buyAssetTradeFeeUsd,
153
155
  buyAmount,
154
156
  };
155
157
  };
@@ -35,7 +35,7 @@ const buildTrade = async ({ deps, input, }) => {
35
35
  deps,
36
36
  gasPrice: (_b = (_a = quote.feeData.chainSpecific) === null || _a === void 0 ? void 0 : _a.gasPrice) !== null && _b !== void 0 ? _b : '0',
37
37
  gasLimit: (_d = (_c = quote.feeData.chainSpecific) === null || _c === void 0 ? void 0 : _c.estimatedGas) !== null && _d !== void 0 ? _d : '0',
38
- tradeFee: quote.feeData.tradeFee,
38
+ buyAssetTradeFeeUsd: quote.feeData.buyAssetTradeFeeUsd,
39
39
  });
40
40
  return {
41
41
  chainId: types_1.KnownChainIds.EthereumMainnet,
@@ -53,7 +53,7 @@ const buildTrade = async ({ deps, input, }) => {
53
53
  slippageTolerance,
54
54
  destinationAddress,
55
55
  xpub: input.xpub,
56
- tradeFee: quote.feeData.tradeFee,
56
+ buyAssetTradeFeeUsd: quote.feeData.buyAssetTradeFeeUsd,
57
57
  });
58
58
  const buildTxResponse = await sellAdapter.buildSendTransaction({
59
59
  value: sellAmount,
@@ -32,10 +32,10 @@ const getThorTradeQuote = async ({ deps, input }) => {
32
32
  const estimatedTradeFee = await (0, estimateTradeFee_1.estimateTradeFee)(deps, buyAsset);
33
33
  const buyAssetUsdRate = await (0, getUsdRate_1.getUsdRate)({ deps, input: { assetId: buyAsset.assetId } });
34
34
  const minTradeFeeAmount = MINIMUM_USD_TRADE_AMOUNT.div(buyAssetUsdRate);
35
- const tradeFee = minTradeFeeAmount.gt(estimatedTradeFee)
35
+ const buyAssetTradeFeeUsd = minTradeFeeAmount.gt(estimatedTradeFee)
36
36
  ? minTradeFeeAmount.toString()
37
37
  : estimatedTradeFee;
38
- const sellAssetTradeFee = (0, bignumber_1.bnOrZero)(tradeFee).dividedBy((0, bignumber_1.bnOrZero)(rate));
38
+ const sellAssetTradeFee = (0, bignumber_1.bnOrZero)(buyAssetTradeFeeUsd).dividedBy((0, bignumber_1.bnOrZero)(rate));
39
39
  // minimum is tradeFee padded by an amount to be sure they get something back
40
40
  // usually it will be slightly more than the amount because sellAssetTradeFee is already a high estimate
41
41
  const minimum = (0, bignumber_1.bnOrZero)(sellAssetTradeFee).times(constants_2.THOR_MINIMUM_PADDING).toString();
@@ -61,12 +61,12 @@ const getThorTradeQuote = async ({ deps, input }) => {
61
61
  sellAmount,
62
62
  slippageTolerance: constants_1.DEFAULT_SLIPPAGE,
63
63
  destinationAddress: receiveAddress,
64
- tradeFee,
64
+ buyAssetTradeFeeUsd,
65
65
  });
66
66
  const feeData = await (0, getEthTxFees_1.getEthTxFees)({
67
67
  adapterManager: deps.adapterManager,
68
68
  sellAssetReference,
69
- tradeFee,
69
+ buyAssetTradeFeeUsd,
70
70
  });
71
71
  return {
72
72
  ...commonQuoteFields,
@@ -84,7 +84,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
84
84
  slippageTolerance: constants_1.DEFAULT_SLIPPAGE,
85
85
  destinationAddress: receiveAddress,
86
86
  xpub: input.xpub,
87
- tradeFee,
87
+ buyAssetTradeFeeUsd,
88
88
  });
89
89
  const feeData = await (0, getBtcTxFees_1.getBtcTxFees)({
90
90
  sellAmount,
@@ -92,7 +92,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
92
92
  opReturnData,
93
93
  pubkey,
94
94
  sellAdapter: sellAdapter,
95
- tradeFee,
95
+ buyAssetTradeFeeUsd,
96
96
  });
97
97
  return {
98
98
  ...commonQuoteFields,
@@ -108,7 +108,10 @@ const getThorTradeQuote = async ({ deps, input }) => {
108
108
  allowanceContract: '0x0',
109
109
  feeData: {
110
110
  fee: feeData.fast.txFee,
111
- tradeFee,
111
+ networkFee: feeData.fast.txFee,
112
+ tradeFee: buyAssetTradeFeeUsd,
113
+ buyAssetTradeFeeUsd,
114
+ sellAssetTradeFeeUsd: '0',
112
115
  chainSpecific: { estimatedGas: feeData.fast.chainSpecific.gasLimit },
113
116
  },
114
117
  };
@@ -8,7 +8,7 @@ declare type GetBtcThorTxInfoArgs = {
8
8
  slippageTolerance: string;
9
9
  destinationAddress: string;
10
10
  xpub: string;
11
- tradeFee: string;
11
+ buyAssetTradeFeeUsd: string;
12
12
  };
13
13
  declare type GetBtcThorTxInfoReturn = Promise<{
14
14
  opReturnData: string;
@@ -5,7 +5,7 @@ const api_1 = require("../../../../../api");
5
5
  const getLimit_1 = require("../../getLimit/getLimit");
6
6
  const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
7
7
  const thorService_1 = require("../../thorService");
8
- const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, xpub, tradeFee, }) => {
8
+ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, xpub, buyAssetTradeFeeUsd, }) => {
9
9
  try {
10
10
  const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.daemonUrl}/lcd/thorchain/inbound_addresses`);
11
11
  const sellAssetInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === sellAsset.symbol.toUpperCase());
@@ -23,7 +23,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
23
23
  buyAsset,
24
24
  slippageTolerance,
25
25
  deps,
26
- tradeFee,
26
+ buyAssetTradeFeeUsd,
27
27
  });
28
28
  const memo = (0, makeSwapMemo_1.makeSwapMemo)({
29
29
  buyAssetId: buyAsset.assetId,
@@ -2,8 +2,7 @@ import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { ChainId } from '@shapeshiftoss/caip';
3
3
  import { ChainAdapter } from '@shapeshiftoss/chain-adapters';
4
4
  import { HDWallet } from '@shapeshiftoss/hdwallet-core';
5
- import { KnownChainIds } from '@shapeshiftoss/types';
6
- import { BIP44Params } from '@shapeshiftoss/types';
5
+ import { BIP44Params, KnownChainIds } from '@shapeshiftoss/types';
7
6
  import { TradeQuote } from '../../../../api';
8
7
  import { ThorchainSwapperDeps } from '../../types';
9
8
  export declare const cosmosTxData: (input: {
@@ -26,7 +26,7 @@ const cosmosTxData = async (input) => {
26
26
  buyAsset,
27
27
  slippageTolerance,
28
28
  deps,
29
- tradeFee: quote.feeData.tradeFee,
29
+ buyAssetTradeFeeUsd: quote.feeData.buyAssetTradeFeeUsd,
30
30
  });
31
31
  const memo = (0, makeSwapMemo_1.makeSwapMemo)({
32
32
  buyAssetId: buyAsset.assetId,
@@ -3,7 +3,7 @@ import { ethereum } from '@shapeshiftoss/chain-adapters';
3
3
  import { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
4
4
  import { BIP44Params } from '@shapeshiftoss/types';
5
5
  import { ThorchainSwapperDeps } from '../../types';
6
- export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, tradeFee, }: {
6
+ export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }: {
7
7
  wallet: HDWallet;
8
8
  bip44Params: BIP44Params;
9
9
  sellAmount: string;
@@ -14,7 +14,7 @@ export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset,
14
14
  slippageTolerance: string;
15
15
  deps: ThorchainSwapperDeps;
16
16
  gasLimit: string;
17
- tradeFee: string;
17
+ buyAssetTradeFeeUsd: string;
18
18
  } & ({
19
19
  gasPrice: string;
20
20
  maxFeePerGas?: undefined;
@@ -5,7 +5,7 @@ const caip_1 = require("@shapeshiftoss/caip");
5
5
  const web3_utils_1 = require("web3-utils");
6
6
  const api_1 = require("../../../../api");
7
7
  const getThorTxData_1 = require("../ethereum/utils/getThorTxData");
8
- const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, tradeFee, }) => {
8
+ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }) => {
9
9
  try {
10
10
  const { assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
11
11
  const isErc20Trade = assetNamespace === 'erc20';
@@ -16,7 +16,7 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsse
16
16
  sellAmount,
17
17
  slippageTolerance,
18
18
  destinationAddress,
19
- tradeFee,
19
+ buyAssetTradeFeeUsd,
20
20
  });
21
21
  return adapter.buildCustomTx({
22
22
  wallet,
@@ -7,7 +7,7 @@ declare type GetBtcThorTxInfoArgs = {
7
7
  sellAmount: string;
8
8
  slippageTolerance: string;
9
9
  destinationAddress: string;
10
- tradeFee: string;
10
+ buyAssetTradeFeeUsd: string;
11
11
  };
12
12
  declare type GetBtcThorTxInfoReturn = Promise<{
13
13
  data: string;
@@ -7,7 +7,7 @@ const getLimit_1 = require("../../getLimit/getLimit");
7
7
  const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
8
8
  const thorService_1 = require("../../thorService");
9
9
  const routerCalldata_1 = require("../routerCalldata");
10
- const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, tradeFee, }) => {
10
+ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, buyAssetTradeFeeUsd, }) => {
11
11
  try {
12
12
  const { assetReference, assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
13
13
  const isErc20Trade = assetNamespace === 'erc20';
@@ -28,7 +28,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
28
28
  buyAsset,
29
29
  slippageTolerance,
30
30
  deps,
31
- tradeFee,
31
+ buyAssetTradeFeeUsd,
32
32
  });
33
33
  const memo = (0, makeSwapMemo_1.makeSwapMemo)({
34
34
  buyAssetId: buyAsset.assetId,
@@ -1,6 +1,6 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { ThorchainSwapperDeps } from '../../types';
3
- export declare const getLimit: ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, tradeFee, }: {
3
+ export declare const getLimit: ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, buyAssetTradeFeeUsd, }: {
4
4
  buyAssetId: string;
5
5
  destinationAddress: string;
6
6
  sellAsset: Asset;
@@ -8,5 +8,5 @@ export declare const getLimit: ({ sellAsset, buyAsset, sellAmount, deps, slippag
8
8
  sellAmount: string;
9
9
  deps: ThorchainSwapperDeps;
10
10
  slippageTolerance: string;
11
- tradeFee: string;
11
+ buyAssetTradeFeeUsd: string;
12
12
  }) => Promise<string>;
@@ -5,7 +5,7 @@ const api_1 = require("../../../../api");
5
5
  const bignumber_1 = require("../../../utils/bignumber");
6
6
  const constants_1 = require("../constants");
7
7
  const getTradeRate_1 = require("../getTradeRate/getTradeRate");
8
- const getLimit = async ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, tradeFee, }) => {
8
+ const getLimit = async ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, buyAssetTradeFeeUsd, }) => {
9
9
  const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmount, deps);
10
10
  const expectedBuyAmountPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).times(tradeRate), sellAsset.precision), constants_1.THORCHAIN_FIXED_PRECISION);
11
11
  const isValidSlippageRange = (0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1);
@@ -14,7 +14,7 @@ const getLimit = async ({ sellAsset, buyAsset, sellAmount, deps, slippageToleran
14
14
  code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
15
15
  details: { expectedBuyAmountPrecision8, slippageTolerance },
16
16
  });
17
- const tradeFeePrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(tradeFee), constants_1.THORCHAIN_FIXED_PRECISION);
17
+ const tradeFeePrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(buyAssetTradeFeeUsd), constants_1.THORCHAIN_FIXED_PRECISION);
18
18
  return (0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8)
19
19
  .times((0, bignumber_1.bn)(1).minus(slippageTolerance))
20
20
  .minus((0, bignumber_1.bnOrZero)(tradeFeePrecision8))
@@ -1,10 +1,10 @@
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, tradeFee, }: {
3
+ export declare const getBtcTxFees: ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, buyAssetTradeFeeUsd, }: {
4
4
  opReturnData: string;
5
5
  vault: string;
6
6
  sellAmount: string;
7
7
  sellAdapter: UtxoBaseAdapter<UtxoSupportedChainIds>;
8
8
  pubkey: string;
9
- tradeFee: string;
9
+ buyAssetTradeFeeUsd: string;
10
10
  }) => Promise<QuoteFeeData<UtxoSupportedChainIds>>;
@@ -4,7 +4,7 @@ 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, tradeFee, }) => {
7
+ const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, buyAssetTradeFeeUsd, }) => {
8
8
  try {
9
9
  const feeDataOptions = await sellAdapter.getFeeData({
10
10
  to: vault,
@@ -19,11 +19,14 @@ const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubk
19
19
  // Bumping BCH fees here resolves this for now until we have time to find a better solution
20
20
  const isFromBch = sellAdapter.getChainId() === types_1.KnownChainIds.BitcoinCashMainnet;
21
21
  const feeMultiplier = isFromBch ? (0, bignumber_1.bn)(1.5) : (0, bignumber_1.bn)(1);
22
- const fee = feeMultiplier.times(feeData.txFee).dp(0).toString();
22
+ const networkFee = feeMultiplier.times(feeData.txFee).dp(0).toString();
23
23
  const satsPerByte = feeMultiplier.times(feeData.chainSpecific.satoshiPerByte).dp(0).toString();
24
24
  return {
25
- fee,
26
- tradeFee,
25
+ fee: networkFee,
26
+ networkFee,
27
+ tradeFee: buyAssetTradeFeeUsd,
28
+ buyAssetTradeFeeUsd,
29
+ sellAssetTradeFeeUsd: '0',
27
30
  chainSpecific: {
28
31
  satsPerByte,
29
32
  byteCount: (0, bignumber_1.bn)(feeData.txFee)
@@ -2,8 +2,8 @@ import { AssetReference } from '@shapeshiftoss/caip';
2
2
  import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
3
3
  import { KnownChainIds } from '@shapeshiftoss/types';
4
4
  import { QuoteFeeData } from '../../../../../api';
5
- export declare const getEthTxFees: ({ adapterManager, sellAssetReference, tradeFee, }: {
5
+ export declare const getEthTxFees: ({ adapterManager, sellAssetReference, buyAssetTradeFeeUsd, }: {
6
6
  adapterManager: ChainAdapterManager;
7
7
  sellAssetReference: AssetReference | string;
8
- tradeFee: string;
8
+ buyAssetTradeFeeUsd: string;
9
9
  }) => Promise<QuoteFeeData<KnownChainIds.EthereumMainnet>>;
@@ -7,7 +7,7 @@ const api_1 = require("../../../../../api");
7
7
  const bignumber_1 = require("../../../../utils/bignumber");
8
8
  const constants_1 = require("../../../../utils/constants");
9
9
  const constants_2 = require("../../constants");
10
- const getEthTxFees = async ({ adapterManager, sellAssetReference, tradeFee, }) => {
10
+ const getEthTxFees = async ({ adapterManager, sellAssetReference, buyAssetTradeFeeUsd, }) => {
11
11
  try {
12
12
  const adapter = adapterManager.get(types_1.KnownChainIds.EthereumMainnet);
13
13
  if (!adapter) {
@@ -32,6 +32,7 @@ const getEthTxFees = async ({ adapterManager, sellAssetReference, tradeFee, }) =
32
32
  const feeData = feeDataOptions['fast'];
33
33
  return {
34
34
  fee: feeData.txFee,
35
+ networkFee: feeData.txFee,
35
36
  chainSpecific: {
36
37
  estimatedGas: feeData.chainSpecific.gasLimit,
37
38
  gasPrice: feeData.chainSpecific.gasPrice,
@@ -40,7 +41,9 @@ const getEthTxFees = async ({ adapterManager, sellAssetReference, tradeFee, }) =
40
41
  .multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
41
42
  .toString(),
42
43
  },
43
- tradeFee,
44
+ tradeFee: buyAssetTradeFeeUsd,
45
+ buyAssetTradeFeeUsd,
46
+ sellAssetTradeFeeUsd: '0',
44
47
  };
45
48
  }
46
49
  catch (e) {
@@ -15,7 +15,14 @@ const setupQuote = () => {
15
15
  bip44Params: { purpose: 44, coinType: 60, accountNumber: 0 },
16
16
  minimum: '0',
17
17
  maximum: '999999999999',
18
- feeData: { fee: '0', tradeFee: '0', chainSpecific: {} },
18
+ feeData: {
19
+ fee: '0',
20
+ tradeFee: '0',
21
+ chainSpecific: {},
22
+ sellAssetTradeFeeUsd: '0',
23
+ networkFee: '0',
24
+ buyAssetTradeFeeUsd: '0',
25
+ },
19
26
  rate: '1',
20
27
  sources: [],
21
28
  };
@@ -53,7 +53,7 @@ async function getZrxTradeQuote(input) {
53
53
  // Instead, we use a hardcoded gasLimit estimate in place of the estimatedGas in the 0x quote response.
54
54
  const approvalFee = sellAssetErc20Address &&
55
55
  (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(gasPrice)).toString();
56
- return {
56
+ const tradeQuote = {
57
57
  rate,
58
58
  minimum,
59
59
  maximum,
@@ -65,6 +65,9 @@ async function getZrxTradeQuote(input) {
65
65
  approvalFee,
66
66
  },
67
67
  tradeFee: '0',
68
+ networkFee: fee,
69
+ buyAssetTradeFeeUsd: '0',
70
+ sellAssetTradeFeeUsd: '0',
68
71
  },
69
72
  sellAmount: sellAmountResponse,
70
73
  buyAmount,
@@ -74,6 +77,7 @@ async function getZrxTradeQuote(input) {
74
77
  sellAsset,
75
78
  bip44Params,
76
79
  };
80
+ return tradeQuote;
77
81
  }
78
82
  catch (e) {
79
83
  if (e instanceof api_1.SwapError)
@@ -29,6 +29,9 @@ export declare const setupExecuteTrade: () => {
29
29
  fee: string;
30
30
  chainSpecific: {};
31
31
  tradeFee: string;
32
+ buyAssetTradeFeeUsd: string;
33
+ sellAssetTradeFeeUsd: string;
34
+ networkFee: string;
32
35
  };
33
36
  rate: string;
34
37
  sources: never[];
@@ -37,7 +37,14 @@ const setupExecuteTrade = () => {
37
37
  txData: '0x0',
38
38
  depositAddress: '0x0',
39
39
  receiveAddress: '0x0',
40
- feeData: { fee: '0', chainSpecific: {}, tradeFee: '0' },
40
+ feeData: {
41
+ fee: '0',
42
+ chainSpecific: {},
43
+ tradeFee: '0',
44
+ buyAssetTradeFeeUsd: '0',
45
+ sellAssetTradeFeeUsd: '0',
46
+ networkFee: '0',
47
+ },
41
48
  rate: '0',
42
49
  sources: [],
43
50
  };
@@ -91,6 +91,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
91
91
  });
92
92
  const { data } = quoteResponse;
93
93
  const estimatedGas = (0, bignumber_1.bnOrZero)(data.gas || 0);
94
+ const networkFee = (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString();
94
95
  const trade = {
95
96
  sellAsset,
96
97
  buyAsset,
@@ -99,12 +100,15 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
99
100
  rate: data.price,
100
101
  depositAddress: data.to,
101
102
  feeData: {
102
- fee: (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString(),
103
+ fee: networkFee,
103
104
  chainSpecific: {
104
105
  estimatedGas: estimatedGas.toString(),
105
106
  gasPrice: data.gasPrice,
106
107
  },
107
108
  tradeFee: '0',
109
+ networkFee,
110
+ buyAssetTradeFeeUsd: '0',
111
+ sellAssetTradeFeeUsd: '0',
108
112
  },
109
113
  txData: data.data,
110
114
  sellAmount: data.sellAmount,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "11.4.1",
3
+ "version": "11.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",