@shapeshiftoss/swapper 11.5.0 → 11.5.1

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.
@@ -36,7 +36,7 @@ const constants_2 = require("../utils/constants");
36
36
  const helpers_2 = require("../utils/helpers/helpers");
37
37
  const zrxService_1 = require("../utils/zrxService");
38
38
  async function zrxBuildTrade({ adapter, web3 }, input) {
39
- var _a, _b, _c;
39
+ var _a;
40
40
  const { sellAsset, buyAsset, sellAmount, slippage, bip44Params, receiveAddress } = input;
41
41
  try {
42
42
  const { assetReference: buyAssetErc20Address, assetNamespace: buyAssetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
@@ -92,6 +92,18 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
92
92
  const { data } = quoteResponse;
93
93
  const estimatedGas = (0, bignumber_1.bnOrZero)(data.gas || 0);
94
94
  const networkFee = (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString();
95
+ const allowanceRequired = await (0, helpers_1.getAllowanceRequired)({
96
+ adapter,
97
+ sellAsset,
98
+ allowanceContract: data.allowanceTarget,
99
+ receiveAddress,
100
+ sellAmount: data.sellAmount,
101
+ web3,
102
+ erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi,
103
+ });
104
+ const approvalFee = (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT)
105
+ .multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice))
106
+ .toString();
95
107
  const trade = {
96
108
  sellAsset,
97
109
  buyAsset,
@@ -104,6 +116,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
104
116
  chainSpecific: {
105
117
  estimatedGas: estimatedGas.toString(),
106
118
  gasPrice: data.gasPrice,
119
+ approvalFee: allowanceRequired.gt(0) ? approvalFee : undefined,
107
120
  },
108
121
  tradeFee: '0',
109
122
  networkFee,
@@ -115,27 +128,6 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
115
128
  buyAmount: data.buyAmount,
116
129
  sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
117
130
  };
118
- const allowanceRequired = await (0, helpers_1.getAllowanceRequired)({
119
- adapter,
120
- sellAsset,
121
- allowanceContract: data.allowanceTarget,
122
- receiveAddress,
123
- sellAmount: data.sellAmount,
124
- web3,
125
- erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi,
126
- });
127
- if (allowanceRequired) {
128
- trade.feeData = {
129
- fee: ((_b = trade.feeData) === null || _b === void 0 ? void 0 : _b.fee) || '0',
130
- chainSpecific: {
131
- ...(_c = trade.feeData) === null || _c === void 0 ? void 0 : _c.chainSpecific,
132
- approvalFee: (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT)
133
- .multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice))
134
- .toString(),
135
- },
136
- tradeFee: '0',
137
- };
138
- }
139
131
  return trade;
140
132
  }
141
133
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "11.5.0",
3
+ "version": "11.5.1",
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",