@shapeshiftoss/swapper 8.3.1 → 8.4.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.
|
@@ -4,13 +4,27 @@ exports.thorTradeApproveInfinite = void 0;
|
|
|
4
4
|
const types_1 = require("@shapeshiftoss/types");
|
|
5
5
|
const api_1 = require("../../../api");
|
|
6
6
|
const erc20_abi_1 = require("../../utils/abi/erc20-abi");
|
|
7
|
+
const constants_1 = require("../../utils/constants");
|
|
7
8
|
const helpers_1 = require("../../utils/helpers/helpers");
|
|
8
|
-
const
|
|
9
|
+
const constants_2 = require("../utils/constants");
|
|
9
10
|
const thorTradeApproveInfinite = async ({ deps, input }) => {
|
|
10
11
|
try {
|
|
11
12
|
const { adapterManager, web3 } = deps;
|
|
12
13
|
const { quote, wallet } = input;
|
|
13
|
-
const
|
|
14
|
+
const approvalQuote = {
|
|
15
|
+
...quote,
|
|
16
|
+
sellAmount: constants_2.MAX_ALLOWANCE,
|
|
17
|
+
feeData: {
|
|
18
|
+
...quote.feeData,
|
|
19
|
+
chainSpecific: {
|
|
20
|
+
...quote.feeData.chainSpecific,
|
|
21
|
+
// Thor approvals are cheaper than trades, but we don't have dynamic quote data for them.
|
|
22
|
+
// Instead, we use a hardcoded gasLimit estimate in place of the estimatedGas in the Thor quote response.
|
|
23
|
+
estimatedGas: constants_1.APPROVAL_GAS_LIMIT
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const sellAssetChainId = approvalQuote.sellAsset.chainId;
|
|
14
28
|
const adapter = adapterManager.get(types_1.KnownChainIds.EthereumMainnet);
|
|
15
29
|
if (!adapter)
|
|
16
30
|
throw new api_1.SwapError(`[thorTradeApproveInfinite] - No chain adapter found for ${sellAssetChainId}.`, {
|
|
@@ -18,10 +32,7 @@ const thorTradeApproveInfinite = async ({ deps, input }) => {
|
|
|
18
32
|
details: { sellAssetChainId }
|
|
19
33
|
});
|
|
20
34
|
const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
|
|
21
|
-
quote:
|
|
22
|
-
...quote,
|
|
23
|
-
sellAmount: constants_1.MAX_ALLOWANCE
|
|
24
|
-
},
|
|
35
|
+
quote: approvalQuote,
|
|
25
36
|
wallet,
|
|
26
37
|
adapter,
|
|
27
38
|
erc20Abi: erc20_abi_1.erc20Abi,
|
|
@@ -11,7 +11,6 @@ const constants_2 = require("../utils/constants");
|
|
|
11
11
|
const helpers_2 = require("../utils/helpers/helpers");
|
|
12
12
|
const zrxService_1 = require("../utils/zrxService");
|
|
13
13
|
async function getZrxTradeQuote(input) {
|
|
14
|
-
var _a;
|
|
15
14
|
try {
|
|
16
15
|
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber } = input;
|
|
17
16
|
if (buyAsset.chainId !== input.chainId || sellAsset.chainId !== input.chainId) {
|
|
@@ -46,27 +45,31 @@ async function getZrxTradeQuote(input) {
|
|
|
46
45
|
sellAmount: normalizedSellAmount
|
|
47
46
|
}
|
|
48
47
|
});
|
|
49
|
-
const { data } = quoteResponse;
|
|
50
|
-
const estimatedGas = (0, bignumber_1.bnOrZero)(
|
|
51
|
-
const rate = useSellAmount ?
|
|
48
|
+
const { data: { estimatedGas: estimatedGasResponse, gasPrice, price, sellAmount: sellAmountResponse, buyAmount, sources, allowanceTarget } } = quoteResponse;
|
|
49
|
+
const estimatedGas = (0, bignumber_1.bnOrZero)(estimatedGasResponse).times(1.5);
|
|
50
|
+
const rate = useSellAmount ? price : (0, bignumber_1.bn)(1).div(price).toString();
|
|
51
|
+
const fee = (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(gasPrice)).toString();
|
|
52
|
+
// 0x approvals are cheaper than trades, but we don't have dynamic quote data for them.
|
|
53
|
+
// Instead, we use a hardcoded gasLimit estimate in place of the estimatedGas in the 0x quote response.
|
|
54
|
+
const approvalFee = sellAssetErc20Address &&
|
|
55
|
+
(0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(gasPrice)).toString();
|
|
52
56
|
return {
|
|
53
57
|
rate,
|
|
54
58
|
minimum,
|
|
55
59
|
maximum,
|
|
56
60
|
feeData: {
|
|
57
|
-
fee
|
|
61
|
+
fee,
|
|
58
62
|
chainSpecific: {
|
|
59
63
|
estimatedGas: estimatedGas.toString(),
|
|
60
|
-
gasPrice
|
|
61
|
-
approvalFee
|
|
62
|
-
(0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString()
|
|
64
|
+
gasPrice,
|
|
65
|
+
approvalFee
|
|
63
66
|
},
|
|
64
67
|
tradeFee: '0'
|
|
65
68
|
},
|
|
66
|
-
sellAmount:
|
|
67
|
-
buyAmount
|
|
68
|
-
sources: (
|
|
69
|
-
allowanceContract:
|
|
69
|
+
sellAmount: sellAmountResponse,
|
|
70
|
+
buyAmount,
|
|
71
|
+
sources: (sources === null || sources === void 0 ? void 0 : sources.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
|
|
72
|
+
allowanceContract: allowanceTarget,
|
|
70
73
|
buyAsset,
|
|
71
74
|
sellAsset,
|
|
72
75
|
sellAssetAccountNumber
|
|
@@ -3,15 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.zrxApproveInfinite = void 0;
|
|
4
4
|
const api_1 = require("../../../api");
|
|
5
5
|
const erc20_abi_1 = require("../../utils/abi/erc20-abi");
|
|
6
|
+
const constants_1 = require("../../utils/constants");
|
|
6
7
|
const helpers_1 = require("../../utils/helpers/helpers");
|
|
7
|
-
const
|
|
8
|
+
const constants_2 = require("../utils/constants");
|
|
8
9
|
async function zrxApproveInfinite({ adapter, web3 }, { quote, wallet }) {
|
|
9
10
|
try {
|
|
11
|
+
const approvalQuote = {
|
|
12
|
+
...quote,
|
|
13
|
+
sellAmount: constants_2.MAX_ALLOWANCE,
|
|
14
|
+
feeData: {
|
|
15
|
+
...quote.feeData,
|
|
16
|
+
chainSpecific: {
|
|
17
|
+
...quote.feeData.chainSpecific,
|
|
18
|
+
// 0x approvals are cheaper than trades, but we don't have dynamic quote data for them.
|
|
19
|
+
// Instead, we use a hardcoded gasLimit estimate in place of the estimatedGas in the 0x quote response.
|
|
20
|
+
estimatedGas: constants_1.APPROVAL_GAS_LIMIT
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
10
24
|
const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
|
|
11
|
-
quote:
|
|
12
|
-
...quote,
|
|
13
|
-
sellAmount: constants_1.MAX_ALLOWANCE
|
|
14
|
-
},
|
|
25
|
+
quote: approvalQuote,
|
|
15
26
|
wallet,
|
|
16
27
|
adapter,
|
|
17
28
|
erc20Abi: erc20_abi_1.erc20Abi,
|
package/package.json
CHANGED