@shapeshiftoss/swapper 1.11.6 → 1.11.10
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.
- package/dist/swappers/zrx/ZrxSwapper.js +2 -2
- package/dist/swappers/zrx/executeQuote/executeQuote.js +28 -13
- package/dist/swappers/zrx/getSendMaxAmount/getSendMaxAmount.js +11 -3
- package/dist/swappers/zrx/utils/constants.d.ts +1 -0
- package/dist/swappers/zrx/utils/constants.js +2 -1
- package/dist/swappers/zrx/utils/test-data/assets.js +3 -0
- package/package.json +2 -2
|
@@ -45,8 +45,8 @@ class ZrxSwapper {
|
|
|
45
45
|
}
|
|
46
46
|
getDefaultPair() {
|
|
47
47
|
const ETH = { name: 'Ethereum', chain: types_1.ChainTypes.Ethereum, symbol: 'ETH' };
|
|
48
|
-
const
|
|
49
|
-
return [ETH,
|
|
48
|
+
const FOX = { name: 'Fox', chain: types_1.ChainTypes.Ethereum, symbol: 'FOX' };
|
|
49
|
+
return [ETH, FOX];
|
|
50
50
|
}
|
|
51
51
|
async executeQuote(args) {
|
|
52
52
|
return (0, executeQuote_1.executeQuote)(this.deps, args);
|
|
@@ -4,7 +4,7 @@ exports.executeQuote = void 0;
|
|
|
4
4
|
const web3_utils_1 = require("web3-utils");
|
|
5
5
|
const api_1 = require("../../../api");
|
|
6
6
|
async function executeQuote({ adapterManager }, { quote, wallet }) {
|
|
7
|
-
var _a, _b, _c, _d, _e;
|
|
7
|
+
var _a, _b, _c, _d, _e, _f;
|
|
8
8
|
const { sellAsset } = quote;
|
|
9
9
|
if (!quote.success) {
|
|
10
10
|
throw new api_1.SwapError('ZrxSwapper:executeQuote Cannot execute a failed quote');
|
|
@@ -45,20 +45,35 @@ async function executeQuote({ adapterManager }, { quote, wallet }) {
|
|
|
45
45
|
}
|
|
46
46
|
const { txToSign } = buildTxResponse;
|
|
47
47
|
const txWithQuoteData = { ...txToSign, data: (_e = quote.txData) !== null && _e !== void 0 ? _e : '' };
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
if (wallet.supportsOfflineSigning()) {
|
|
49
|
+
try {
|
|
50
|
+
signedTx = await adapter.signTransaction({ txToSign: txWithQuoteData, wallet });
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new api_1.SwapError(`executeQuote - signTransaction error: ${error}`);
|
|
54
|
+
}
|
|
55
|
+
if (!signedTx) {
|
|
56
|
+
throw new api_1.SwapError(`executeQuote - Signed transaction is required: ${signedTx}`);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
txid = await adapter.broadcastTransaction(signedTx);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw new api_1.SwapError(`executeQuote - broadcastTransaction error: ${error}`);
|
|
63
|
+
}
|
|
64
|
+
return { txid };
|
|
50
65
|
}
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
else if (wallet.supportsBroadcast() && adapter.signAndBroadcastTransaction) {
|
|
67
|
+
try {
|
|
68
|
+
txid = await ((_f = adapter.signAndBroadcastTransaction) === null || _f === void 0 ? void 0 : _f.call(adapter, { txToSign: txWithQuoteData, wallet }));
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new api_1.SwapError(`executeQuote - signAndBroadcastTransaction error: ${error}`);
|
|
72
|
+
}
|
|
73
|
+
return { txid };
|
|
53
74
|
}
|
|
54
|
-
|
|
55
|
-
throw new api_1.SwapError(
|
|
56
|
-
try {
|
|
57
|
-
txid = await adapter.broadcastTransaction(signedTx);
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
throw new api_1.SwapError(`executeQuote - broadcastTransaction error: ${error}`);
|
|
75
|
+
else {
|
|
76
|
+
throw new api_1.SwapError('executeQuote - invalid HDWallet config');
|
|
61
77
|
}
|
|
62
|
-
return { txid };
|
|
63
78
|
}
|
|
64
79
|
exports.executeQuote = executeQuote;
|
|
@@ -8,6 +8,7 @@ const types_1 = require("@shapeshiftoss/types");
|
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
9
|
const api_1 = require("../../../api");
|
|
10
10
|
const bignumber_1 = require("../utils/bignumber");
|
|
11
|
+
const constants_1 = require("../utils/constants");
|
|
11
12
|
async function getSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAccountId, feeEstimateKey = types_1.chainAdapters.FeeDataKey.Average }) {
|
|
12
13
|
var _a, _b, _c;
|
|
13
14
|
const adapter = adapterManager.byChain(types_1.ChainTypes.Ethereum);
|
|
@@ -16,6 +17,9 @@ async function getSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAc
|
|
|
16
17
|
});
|
|
17
18
|
const ethAddress = await adapter.getAddress({ wallet, bip32Params });
|
|
18
19
|
const account = await adapter.getAccount(ethAddress);
|
|
20
|
+
if (!quote.sellAsset) {
|
|
21
|
+
throw new api_1.SwapError('quote.sellAsset is required');
|
|
22
|
+
}
|
|
19
23
|
const tokenId = (_a = quote.sellAsset) === null || _a === void 0 ? void 0 : _a.tokenId;
|
|
20
24
|
let balance;
|
|
21
25
|
if (tokenId) {
|
|
@@ -36,15 +40,19 @@ async function getSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAc
|
|
|
36
40
|
}
|
|
37
41
|
const feeEstimates = await adapter.getFeeData({
|
|
38
42
|
to: quote.depositAddress,
|
|
39
|
-
value:
|
|
43
|
+
value: (0, bignumber_1.bnOrZero)(quote.sellAmount).toString(),
|
|
40
44
|
chainSpecific: {
|
|
41
45
|
from: ethAddress,
|
|
42
46
|
contractData: quote.txData
|
|
43
47
|
}
|
|
44
48
|
});
|
|
45
49
|
const estimatedFee = feeEstimates[feeEstimateKey].txFee;
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
// (ryankk) We need to pad the fee for ETH max sends because the fee estimate is based off
|
|
51
|
+
// of a minimum quote value (quote.sellAmount) and not the users full ETH balance.
|
|
52
|
+
const paddedFee = new bignumber_js_1.default(estimatedFee).times(constants_1.ETH_FEE_ESTIMATE_PADDING);
|
|
53
|
+
const sendMaxAmount = new bignumber_js_1.default(balance).minus(paddedFee);
|
|
54
|
+
// gte covers if sendMaxAmount is NaN
|
|
55
|
+
if (!sendMaxAmount.gte(0)) {
|
|
48
56
|
throw new api_1.SwapError('ETH balance is less than estimated fee');
|
|
49
57
|
}
|
|
50
58
|
return sendMaxAmount.toString();
|
|
@@ -15,5 +15,6 @@ export declare const DEFAULT_SOURCE: {
|
|
|
15
15
|
}[];
|
|
16
16
|
export declare const DEFAULT_SLIPPAGE = "0.03";
|
|
17
17
|
export declare const MAX_SLIPPAGE = "0.3";
|
|
18
|
+
export declare const ETH_FEE_ESTIMATE_PADDING = "1.2";
|
|
18
19
|
export declare const AFFILIATE_ADDRESS = "0xc770eefad204b5180df6a14ee197d99d808ee52d";
|
|
19
20
|
export declare const APPROVAL_BUY_AMOUNT = "100000000000000000";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APPROVAL_BUY_AMOUNT = exports.AFFILIATE_ADDRESS = exports.MAX_SLIPPAGE = exports.DEFAULT_SLIPPAGE = exports.DEFAULT_SOURCE = exports.MAX_ZRX_TRADE = exports.MAX_GAS_PRICE = exports.LIQUIDITY_GAS_LIMIT = exports.APPROVAL_GAS_LIMIT = exports.MAX_ALLOWANCE = exports.UNISWAP_WETH_FOX_POOL_ADDRESS = exports.WETH_TOKEN_CONTRACT_ADDRESS = exports.FOX_TOKEN_CONTRACT_ADDRESS = exports.ZERO_ADDRESS = exports.UNISWAP_FACTORY_ADDRESS = exports.UNISWAP_ROUTER_ADDRESS = void 0;
|
|
3
|
+
exports.APPROVAL_BUY_AMOUNT = exports.AFFILIATE_ADDRESS = exports.ETH_FEE_ESTIMATE_PADDING = exports.MAX_SLIPPAGE = exports.DEFAULT_SLIPPAGE = exports.DEFAULT_SOURCE = exports.MAX_ZRX_TRADE = exports.MAX_GAS_PRICE = exports.LIQUIDITY_GAS_LIMIT = exports.APPROVAL_GAS_LIMIT = exports.MAX_ALLOWANCE = exports.UNISWAP_WETH_FOX_POOL_ADDRESS = exports.WETH_TOKEN_CONTRACT_ADDRESS = exports.FOX_TOKEN_CONTRACT_ADDRESS = exports.ZERO_ADDRESS = exports.UNISWAP_FACTORY_ADDRESS = exports.UNISWAP_ROUTER_ADDRESS = void 0;
|
|
4
4
|
exports.UNISWAP_ROUTER_ADDRESS = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D';
|
|
5
5
|
exports.UNISWAP_FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
|
|
6
6
|
exports.ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
@@ -15,5 +15,6 @@ exports.MAX_ZRX_TRADE = '100000000000000000000000000';
|
|
|
15
15
|
exports.DEFAULT_SOURCE = [{ name: '0x', proportion: '1' }];
|
|
16
16
|
exports.DEFAULT_SLIPPAGE = '0.03'; // 3%
|
|
17
17
|
exports.MAX_SLIPPAGE = '0.3'; // 30%
|
|
18
|
+
exports.ETH_FEE_ESTIMATE_PADDING = '1.2'; // Padding the fee estimate by 20% to avoid trade errors.
|
|
18
19
|
exports.AFFILIATE_ADDRESS = '0xc770eefad204b5180df6a14ee197d99d808ee52d';
|
|
19
20
|
exports.APPROVAL_BUY_AMOUNT = '100000000000000000'; // A valid buy amount - 0.1 ETH
|
|
@@ -16,6 +16,7 @@ exports.BTC = {
|
|
|
16
16
|
icon: 'https://assets.coincap.io/assets/icons/btc@2x.png',
|
|
17
17
|
explorer: 'https://live.blockcypher.com',
|
|
18
18
|
explorerTxLink: 'https://live.blockcypher.com/btc/tx/',
|
|
19
|
+
explorerAddressLink: 'https://live.blockcypher.com/btc/address/',
|
|
19
20
|
sendSupport: false,
|
|
20
21
|
receiveSupport: false,
|
|
21
22
|
symbol: 'BTC'
|
|
@@ -35,6 +36,7 @@ exports.WETH = {
|
|
|
35
36
|
slip44: 60,
|
|
36
37
|
explorer: 'https://etherscan.io',
|
|
37
38
|
explorerTxLink: 'https://etherscan.io/tx/',
|
|
39
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
38
40
|
sendSupport: true,
|
|
39
41
|
receiveSupport: true,
|
|
40
42
|
symbol: 'WETH'
|
|
@@ -55,6 +57,7 @@ exports.FOX = {
|
|
|
55
57
|
slip44: 60,
|
|
56
58
|
explorer: 'https://etherscan.io',
|
|
57
59
|
explorerTxLink: 'https://etherscan.io/tx/',
|
|
60
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
58
61
|
receiveSupport: true,
|
|
59
62
|
symbol: 'FOX'
|
|
60
63
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swapper",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.10",
|
|
4
4
|
"description": "TODO: description",
|
|
5
5
|
"repository": "https://github.com/shapeshift/lib",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@shapeshiftoss/chain-adapters": "^1.16.2",
|
|
25
|
-
"@shapeshiftoss/hdwallet-core": "^1.
|
|
25
|
+
"@shapeshiftoss/hdwallet-core": "^1.18.0",
|
|
26
26
|
"@shapeshiftoss/types": "^1.12.0",
|
|
27
27
|
"axios": "^0.21.4",
|
|
28
28
|
"bignumber.js": "^9.0.1",
|