@shapeshiftoss/swapper 3.0.1 → 3.0.2
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.
|
@@ -7,8 +7,8 @@ const api_1 = require("../../../api");
|
|
|
7
7
|
const erc20Allowance_abi_1 = require("../utils/abi/erc20Allowance-abi");
|
|
8
8
|
const constants_1 = require("../utils/constants");
|
|
9
9
|
const helpers_1 = require("../utils/helpers/helpers");
|
|
10
|
-
const zrxService_1 = require("../utils/zrxService");
|
|
11
10
|
async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
|
|
11
|
+
var _a, _b;
|
|
12
12
|
const { sellAsset } = quote;
|
|
13
13
|
if (sellAsset.symbol === 'ETH') {
|
|
14
14
|
return { approvalNeeded: false };
|
|
@@ -20,42 +20,21 @@ async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
|
|
|
20
20
|
const adapter = adapterManager.byChain(sellAsset.chain);
|
|
21
21
|
const bip44Params = adapter.buildBIP44Params({ accountNumber });
|
|
22
22
|
const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
|
|
23
|
-
|
|
24
|
-
* /swap/v1/quote
|
|
25
|
-
* params: {
|
|
26
|
-
* sellToken: contract address (or symbol) of token to sell
|
|
27
|
-
* buyToken: contractAddress (or symbol) of token to buy
|
|
28
|
-
* sellAmount?: integer string value of the smallest increment of the sell token
|
|
29
|
-
* buyAmount?: integer string value of the smallest incremtent of the buy token
|
|
30
|
-
* }
|
|
31
|
-
*/
|
|
32
|
-
const quoteResponse = await zrxService_1.zrxService.get('/swap/v1/quote', {
|
|
33
|
-
params: {
|
|
34
|
-
buyToken: 'ETH',
|
|
35
|
-
sellToken: quote.sellAsset.tokenId || quote.sellAsset.symbol || quote.sellAsset.chain,
|
|
36
|
-
buyAmount: constants_1.APPROVAL_BUY_AMOUNT,
|
|
37
|
-
takerAddress: receiveAddress,
|
|
38
|
-
slippagePercentage: constants_1.DEFAULT_SLIPPAGE,
|
|
39
|
-
skipValidation: true,
|
|
40
|
-
affiliateAddress: constants_1.AFFILIATE_ADDRESS
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const { data } = quoteResponse;
|
|
44
|
-
if (!quote.sellAsset.tokenId || !data.allowanceTarget) {
|
|
23
|
+
if (!quote.sellAsset.tokenId || !quote.allowanceContract) {
|
|
45
24
|
throw new api_1.SwapError('ZrxApprovalNeeded - tokenId and allowanceTarget are required');
|
|
46
25
|
}
|
|
47
26
|
const allowanceResult = await (0, helpers_1.getERC20Allowance)({
|
|
48
27
|
web3,
|
|
49
28
|
erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi,
|
|
50
29
|
tokenId: quote.sellAsset.tokenId,
|
|
51
|
-
spenderAddress:
|
|
30
|
+
spenderAddress: quote.allowanceContract,
|
|
52
31
|
ownerAddress: receiveAddress
|
|
53
32
|
});
|
|
54
33
|
const allowanceOnChain = new bignumber_js_1.BigNumber(allowanceResult || '0');
|
|
55
34
|
return {
|
|
56
35
|
approvalNeeded: allowanceOnChain.lt(new bignumber_js_1.BigNumber(quote.sellAmount || 1)),
|
|
57
36
|
gas: constants_1.APPROVAL_GAS_LIMIT,
|
|
58
|
-
gasPrice:
|
|
37
|
+
gasPrice: (_b = (_a = quote === null || quote === void 0 ? void 0 : quote.feeData) === null || _a === void 0 ? void 0 : _a.chainSpecific) === null || _b === void 0 ? void 0 : _b.gasPrice
|
|
59
38
|
};
|
|
60
39
|
}
|
|
61
40
|
exports.ZrxApprovalNeeded = ZrxApprovalNeeded;
|
|
@@ -2,46 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZrxApproveInfinite = void 0;
|
|
4
4
|
const types_1 = require("@shapeshiftoss/types");
|
|
5
|
-
const api_1 = require("../../../api");
|
|
6
5
|
const erc20_abi_1 = require("../utils/abi/erc20-abi");
|
|
7
|
-
const bignumber_1 = require("../utils/bignumber");
|
|
8
6
|
const constants_1 = require("../utils/constants");
|
|
9
7
|
const helpers_1 = require("../utils/helpers/helpers");
|
|
10
|
-
const zrxService_1 = require("../utils/zrxService");
|
|
11
8
|
async function ZrxApproveInfinite({ adapterManager, web3 }, { quote, wallet }) {
|
|
12
9
|
const adapter = adapterManager.byChain(types_1.ChainTypes.Ethereum);
|
|
13
|
-
const bip44Params = adapter.buildBIP44Params({
|
|
14
|
-
accountNumber: (0, bignumber_1.bnOrZero)(quote.sellAssetAccountId).toNumber()
|
|
15
|
-
}); // TODO: Add account number
|
|
16
|
-
const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
|
|
17
|
-
/**
|
|
18
|
-
* /swap/v1/quote
|
|
19
|
-
* params: {
|
|
20
|
-
* sellToken: contract address (or symbol) of token to sell
|
|
21
|
-
* buyToken: contractAddress (or symbol) of token to buy
|
|
22
|
-
* sellAmount?: integer string value of the smallest increment of the sell token
|
|
23
|
-
* buyAmount?: integer string value of the smallest incremtent of the buy token
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
const quoteResponse = await zrxService_1.zrxService.get('/swap/v1/quote', {
|
|
27
|
-
params: {
|
|
28
|
-
buyToken: 'ETH',
|
|
29
|
-
sellToken: quote.sellAsset.tokenId || quote.sellAsset.symbol || quote.sellAsset.network,
|
|
30
|
-
buyAmount: '100000000000000000',
|
|
31
|
-
takerAddress: receiveAddress,
|
|
32
|
-
slippagePercentage: constants_1.DEFAULT_SLIPPAGE,
|
|
33
|
-
skipValidation: true,
|
|
34
|
-
affiliateAddress: constants_1.AFFILIATE_ADDRESS
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
const { data } = quoteResponse;
|
|
38
|
-
if (!data.allowanceTarget) {
|
|
39
|
-
throw new api_1.SwapError('approveInfinite - allowanceTarget is required');
|
|
40
|
-
}
|
|
41
10
|
const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
|
|
42
11
|
quote: {
|
|
43
12
|
...quote,
|
|
44
|
-
allowanceContract:
|
|
13
|
+
allowanceContract: quote.allowanceContract,
|
|
45
14
|
sellAmount: constants_1.MAX_ALLOWANCE
|
|
46
15
|
},
|
|
47
16
|
wallet,
|
|
@@ -8,35 +8,19 @@ const types_1 = require("@shapeshiftoss/types");
|
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
9
|
const constants_1 = require("../utils/constants");
|
|
10
10
|
const helpers_1 = require("../utils/helpers/helpers");
|
|
11
|
-
const zrxService_1 = require("../utils/zrxService");
|
|
12
11
|
const ZrxSwapper_1 = require("../ZrxSwapper");
|
|
13
12
|
const getZrxMinMax = async (input) => {
|
|
14
|
-
var _a;
|
|
15
13
|
const { sellAsset, buyAsset } = input;
|
|
16
14
|
if (sellAsset.chain !== types_1.ChainTypes.Ethereum || buyAsset.chain !== types_1.ChainTypes.Ethereum) {
|
|
17
15
|
throw new ZrxSwapper_1.ZrxError('getZrxMinMax - must be eth assets');
|
|
18
16
|
}
|
|
19
|
-
const buyToken = buyAsset.tokenId || buyAsset.symbol;
|
|
20
|
-
const sellToken = sellAsset.tokenId || sellAsset.symbol;
|
|
21
17
|
const usdRate = await (0, helpers_1.getUsdRate)({
|
|
22
18
|
symbol: sellAsset.symbol,
|
|
23
19
|
tokenId: sellAsset.tokenId
|
|
24
20
|
});
|
|
25
|
-
const minimumWeiAmount = new bignumber_js_1.default(1)
|
|
26
|
-
.dividedBy(new bignumber_js_1.default(usdRate))
|
|
27
|
-
.times(new bignumber_js_1.default(10).exponentiatedBy(sellAsset.precision));
|
|
28
21
|
const minimum = new bignumber_js_1.default(1).dividedBy(new bignumber_js_1.default(usdRate)).toString();
|
|
29
|
-
const minimumPriceResult = await zrxService_1.zrxService.get('/swap/v1/price', {
|
|
30
|
-
params: {
|
|
31
|
-
sellToken,
|
|
32
|
-
buyToken,
|
|
33
|
-
sellAmount: (0, helpers_1.normalizeAmount)(minimumWeiAmount.toString())
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const minimumPrice = new bignumber_js_1.default((_a = minimumPriceResult === null || minimumPriceResult === void 0 ? void 0 : minimumPriceResult.data) === null || _a === void 0 ? void 0 : _a.price).toString();
|
|
37
22
|
return {
|
|
38
23
|
minimum,
|
|
39
|
-
minimumPrice,
|
|
40
24
|
maximum: constants_1.MAX_ZRX_TRADE
|
|
41
25
|
};
|
|
42
26
|
};
|
|
@@ -96,7 +96,8 @@ async function getZrxQuote(input) {
|
|
|
96
96
|
sellAmount: data.sellAmount,
|
|
97
97
|
buyAmount: data.buyAmount,
|
|
98
98
|
guaranteedPrice: data.guaranteedPrice,
|
|
99
|
-
sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_1.DEFAULT_SOURCE
|
|
99
|
+
sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_1.DEFAULT_SOURCE,
|
|
100
|
+
allowanceContract: data.allowanceTarget
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swapper",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "TODO: description",
|
|
5
5
|
"repository": "https://github.com/shapeshift/lib",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@shapeshiftoss/caip": "^2.0.0",
|
|
35
35
|
"@shapeshiftoss/chain-adapters": "^2.0.0",
|
|
36
36
|
"@shapeshiftoss/hdwallet-core": "1.20.0",
|
|
37
|
-
"@shapeshiftoss/types": "^
|
|
37
|
+
"@shapeshiftoss/types": "^3.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@shapeshiftoss/asset-service": "^2.0.0",
|