@shapeshiftoss/swapper 6.2.1 → 7.1.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.
- package/dist/api.d.ts +25 -27
- package/dist/manager/SwapperManager.d.ts +6 -5
- package/dist/swappercli.js +35 -17
- package/dist/swappers/cow/CowSwapper.d.ts +8 -8
- package/dist/swappers/cow/CowSwapper.js +9 -4
- package/dist/swappers/cow/getCowSwapMinMax/getCowSwapMinMax.d.ts +4 -0
- package/dist/swappers/cow/getCowSwapMinMax/getCowSwapMinMax.js +28 -0
- package/dist/swappers/cow/utils/blacklist.d.ts +1 -0
- package/dist/swappers/cow/utils/blacklist.js +9 -0
- package/dist/swappers/cow/utils/constants.d.ts +1 -0
- package/dist/swappers/cow/utils/constants.js +4 -0
- package/dist/swappers/test/TestSwapper.d.ts +5 -5
- package/dist/swappers/thorchain/ThorchainSwapper.d.ts +7 -7
- package/dist/swappers/thorchain/ThorchainSwapper.js +9 -5
- package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.d.ts +7 -0
- package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +98 -0
- package/dist/swappers/thorchain/utils/constants.d.ts +1 -0
- package/dist/swappers/thorchain/utils/constants.js +4 -0
- package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.d.ts +0 -3
- package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.js +9 -50
- package/dist/swappers/thorchain/utils/ethereum/utils/getThorTxData.d.ts +15 -0
- package/dist/swappers/thorchain/utils/ethereum/utils/getThorTxData.js +55 -0
- package/dist/swappers/thorchain/utils/getTradeRate/getTradeRate.js +4 -4
- package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.d.ts +15 -0
- package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.js +44 -0
- package/dist/swappers/utils/bignumber.d.ts +2 -0
- package/dist/swappers/utils/bignumber.js +14 -1
- package/dist/swappers/utils/constants.d.ts +2 -0
- package/dist/swappers/utils/constants.js +5 -0
- package/dist/swappers/utils/helpers/helpers.d.ts +7 -0
- package/dist/swappers/utils/helpers/helpers.js +13 -0
- package/dist/swappers/utils/test-data/assets.js +0 -13
- package/dist/swappers/zrx/ZrxApprovalNeeded/ZrxApprovalNeeded.d.ts +1 -1
- package/dist/swappers/zrx/ZrxApprovalNeeded/ZrxApprovalNeeded.js +1 -2
- package/dist/swappers/zrx/ZrxApproveInfinite/ZrxApproveInfinite.d.ts +1 -2
- package/dist/swappers/zrx/ZrxApproveInfinite/ZrxApproveInfinite.js +2 -2
- package/dist/swappers/zrx/ZrxSwapper.d.ts +7 -7
- package/dist/swappers/zrx/getZrxTradeQuote/getZrxTradeQuote.js +4 -3
- package/dist/swappers/zrx/utils/constants.d.ts +0 -4
- package/dist/swappers/zrx/utils/constants.js +1 -5
- package/dist/swappers/zrx/utils/helpers/helpers.d.ts +7 -16
- package/dist/swappers/zrx/utils/helpers/helpers.js +2 -15
- package/dist/swappers/zrx/utils/test-data/setupZrxDeps.d.ts +3 -29
- package/dist/swappers/zrx/utils/test-data/setupZrxDeps.js +34 -32
- package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.d.ts +1 -2
- package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +9 -8
- package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.d.ts +1 -1
- package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +1 -2
- package/package.json +10 -10
|
@@ -1,63 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.makeTradeTx =
|
|
3
|
+
exports.makeTradeTx = void 0;
|
|
7
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
8
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
5
|
const api_1 = require("../../../../api");
|
|
10
|
-
const
|
|
11
|
-
const getPriceRatio_1 = require("../getPriceRatio/getPriceRatio");
|
|
12
|
-
const makeSwapMemo_1 = require("../makeSwapMemo/makeSwapMemo");
|
|
13
|
-
const thorService_1 = require("../thorService");
|
|
14
|
-
const routerCalldata_1 = require("./routerCalldata");
|
|
15
|
-
const fromBaseUnit = (value, decimals, displayDecimals = 6) => {
|
|
16
|
-
return (0, bignumber_1.bnOrZero)(value)
|
|
17
|
-
.div(`1e+${decimals}`)
|
|
18
|
-
.decimalPlaces(displayDecimals, bignumber_js_1.default.ROUND_DOWN)
|
|
19
|
-
.toString();
|
|
20
|
-
};
|
|
21
|
-
exports.fromBaseUnit = fromBaseUnit;
|
|
22
|
-
const toBaseUnit = (amount, precision) => {
|
|
23
|
-
return (0, bignumber_1.bnOrZero)(amount)
|
|
24
|
-
.times(new bignumber_js_1.default(10).exponentiatedBy((0, bignumber_1.bnOrZero)(precision)))
|
|
25
|
-
.toFixed(0);
|
|
26
|
-
};
|
|
27
|
-
exports.toBaseUnit = toBaseUnit;
|
|
6
|
+
const getThorTxData_1 = require("../ethereum/utils/getThorTxData");
|
|
28
7
|
const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, slippageTolerance, deps, gasLimit }) => {
|
|
29
8
|
try {
|
|
30
9
|
const { assetReference } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
31
10
|
const isErc20Trade = assetReference.startsWith('0x');
|
|
32
|
-
const { data
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
39
|
-
details: { inboundAddresses }
|
|
40
|
-
});
|
|
41
|
-
const priceRatio = await (0, getPriceRatio_1.getPriceRatio)(deps, {
|
|
42
|
-
buyAssetId: buyAsset.assetId,
|
|
43
|
-
sellAssetId: sellAsset.assetId
|
|
44
|
-
});
|
|
45
|
-
const expectedBuyAmount = (0, exports.toBaseUnit)((0, exports.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).dividedBy(priceRatio), sellAsset.precision), buyAsset.precision);
|
|
46
|
-
if (!(0, bignumber_1.bnOrZero)(expectedBuyAmount).gte(0) ||
|
|
47
|
-
!((0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1)))
|
|
48
|
-
throw new api_1.SwapError('[makeTradeTx]: bad expected buy amount or bad slippage tolerance', {
|
|
49
|
-
code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED
|
|
50
|
-
});
|
|
51
|
-
const limit = (0, bignumber_1.bnOrZero)(expectedBuyAmount)
|
|
52
|
-
.times(new bignumber_js_1.default(1).minus(slippageTolerance))
|
|
53
|
-
.decimalPlaces(0)
|
|
54
|
-
.toString();
|
|
55
|
-
const memo = (0, makeSwapMemo_1.makeSwapMemo)({
|
|
56
|
-
buyAssetId: buyAsset.assetId,
|
|
11
|
+
const { data, router } = await (0, getThorTxData_1.getThorTxInfo)({
|
|
12
|
+
deps,
|
|
13
|
+
sellAsset,
|
|
14
|
+
buyAsset,
|
|
15
|
+
sellAmount,
|
|
16
|
+
slippageTolerance,
|
|
57
17
|
destinationAddress,
|
|
58
|
-
|
|
18
|
+
isErc20Trade
|
|
59
19
|
});
|
|
60
|
-
const data = await (0, routerCalldata_1.deposit)(vault, router, isErc20Trade ? assetReference : '0x0000000000000000000000000000000000000000', sellAmount, memo);
|
|
61
20
|
return adapter.buildCustomTx({
|
|
62
21
|
wallet,
|
|
63
22
|
bip44Params,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Asset } from '@shapeshiftoss/types';
|
|
2
|
+
import { ThorchainSwapperDeps } from '../../../types';
|
|
3
|
+
export declare const getThorTxInfo: ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, isErc20Trade }: {
|
|
4
|
+
deps: ThorchainSwapperDeps;
|
|
5
|
+
sellAsset: Asset;
|
|
6
|
+
buyAsset: Asset;
|
|
7
|
+
sellAmount: string;
|
|
8
|
+
slippageTolerance: string;
|
|
9
|
+
destinationAddress: string;
|
|
10
|
+
isErc20Trade: boolean;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
data: any;
|
|
13
|
+
memo: string;
|
|
14
|
+
router: string;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getThorTxInfo = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const api_1 = require("../../../../../api");
|
|
6
|
+
const bignumber_1 = require("../../../../utils/bignumber");
|
|
7
|
+
const getPriceRatio_1 = require("../../getPriceRatio/getPriceRatio");
|
|
8
|
+
const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
|
|
9
|
+
const thorService_1 = require("../../thorService");
|
|
10
|
+
const routerCalldata_1 = require("../routerCalldata");
|
|
11
|
+
const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, isErc20Trade }) => {
|
|
12
|
+
try {
|
|
13
|
+
const { assetReference } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
14
|
+
const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.midgardUrl}/thorchain/inbound_addresses`);
|
|
15
|
+
const ethInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === 'ETH');
|
|
16
|
+
const vault = ethInboundAddresses === null || ethInboundAddresses === void 0 ? void 0 : ethInboundAddresses.address;
|
|
17
|
+
const router = ethInboundAddresses === null || ethInboundAddresses === void 0 ? void 0 : ethInboundAddresses.router;
|
|
18
|
+
if (!vault || !router)
|
|
19
|
+
throw new api_1.SwapError(`[getPriceRatio]: router or vault found for ETH`, {
|
|
20
|
+
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
21
|
+
details: { inboundAddresses }
|
|
22
|
+
});
|
|
23
|
+
const priceRatio = await (0, getPriceRatio_1.getPriceRatio)(deps, {
|
|
24
|
+
buyAssetId: buyAsset.assetId,
|
|
25
|
+
sellAssetId: sellAsset.assetId
|
|
26
|
+
});
|
|
27
|
+
const expectedBuyAmount = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).dividedBy(priceRatio), sellAsset.precision), buyAsset.precision);
|
|
28
|
+
if (!(0, bignumber_1.bnOrZero)(expectedBuyAmount).gte(0) ||
|
|
29
|
+
!((0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1)))
|
|
30
|
+
throw new api_1.SwapError('[makeTradeTx]: bad expected buy amount or bad slippage tolerance', {
|
|
31
|
+
code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED
|
|
32
|
+
});
|
|
33
|
+
const limit = (0, bignumber_1.bnOrZero)(expectedBuyAmount)
|
|
34
|
+
.times((0, bignumber_1.bn)(1).minus(slippageTolerance))
|
|
35
|
+
.decimalPlaces(0)
|
|
36
|
+
.toString();
|
|
37
|
+
const memo = (0, makeSwapMemo_1.makeSwapMemo)({
|
|
38
|
+
buyAssetId: buyAsset.assetId,
|
|
39
|
+
destinationAddress,
|
|
40
|
+
limit
|
|
41
|
+
});
|
|
42
|
+
const data = await (0, routerCalldata_1.deposit)(router, vault, isErc20Trade ? assetReference : '0x0000000000000000000000000000000000000000', sellAmount, memo);
|
|
43
|
+
return {
|
|
44
|
+
data,
|
|
45
|
+
memo,
|
|
46
|
+
router
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (e instanceof api_1.SwapError)
|
|
51
|
+
throw e;
|
|
52
|
+
throw new api_1.SwapError('[getThorTxInfo]', { cause: e, code: api_1.SwapErrorTypes.TRADE_QUOTE_FAILED });
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.getThorTxInfo = getThorTxInfo;
|
|
@@ -4,7 +4,7 @@ exports.getTradeRate = void 0;
|
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const api_1 = require("../../../../api");
|
|
6
6
|
const bignumber_1 = require("../../../utils/bignumber");
|
|
7
|
-
const
|
|
7
|
+
const bignumber_2 = require("../../../utils/bignumber");
|
|
8
8
|
const thorService_1 = require("../thorService");
|
|
9
9
|
const THOR_PRECISION = 8;
|
|
10
10
|
const getSwapOutput = (inputAmount, poolData, toRune) => {
|
|
@@ -41,7 +41,7 @@ const getTradeRate = async (sellAsset, buyAssetId, sellAmount, deps) => {
|
|
|
41
41
|
details: { buyPoolId, sellPoolId }
|
|
42
42
|
});
|
|
43
43
|
// All thorchain pool amounts are base 8 regardless of token precision
|
|
44
|
-
const sellBaseAmount = (0, bignumber_1.bn)((0,
|
|
44
|
+
const sellBaseAmount = (0, bignumber_1.bn)((0, bignumber_2.toBaseUnit)((0, bignumber_2.fromBaseUnit)(sellAmount, sellAsset.precision), THOR_PRECISION));
|
|
45
45
|
const sellAssetPoolData = {
|
|
46
46
|
assetBalance: (0, bignumber_1.bn)(sellPool.assetDepth),
|
|
47
47
|
runeBalance: (0, bignumber_1.bn)(sellPool.runeDepth)
|
|
@@ -51,7 +51,7 @@ const getTradeRate = async (sellAsset, buyAssetId, sellAmount, deps) => {
|
|
|
51
51
|
runeBalance: (0, bignumber_1.bn)(buyPool.runeDepth)
|
|
52
52
|
};
|
|
53
53
|
const outputAmountBase8 = getDoubleSwapOutput(sellBaseAmount, sellAssetPoolData, buyAssetPoolData);
|
|
54
|
-
const outputAmount = (0,
|
|
55
|
-
return (0, bignumber_1.bn)(outputAmount).div((0,
|
|
54
|
+
const outputAmount = (0, bignumber_2.fromBaseUnit)(outputAmountBase8, THOR_PRECISION);
|
|
55
|
+
return (0, bignumber_1.bn)(outputAmount).div((0, bignumber_2.fromBaseUnit)(sellAmount, sellAsset.precision)).toString();
|
|
56
56
|
};
|
|
57
57
|
exports.getTradeRate = getTradeRate;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AssetReference } from '@shapeshiftoss/caip';
|
|
2
|
+
import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import { Asset } from '@shapeshiftoss/types';
|
|
4
|
+
import { QuoteFeeData } from '../../../../../api';
|
|
5
|
+
import { ThorchainSwapperDeps } from '../../../types';
|
|
6
|
+
export declare const getEthTxFees: ({ deps, data, router, buyAsset, sellAmount, adapterManager, receiveAddress, sellAssetReference }: {
|
|
7
|
+
deps: ThorchainSwapperDeps;
|
|
8
|
+
data: string;
|
|
9
|
+
router: string;
|
|
10
|
+
buyAsset: Asset;
|
|
11
|
+
sellAmount: string;
|
|
12
|
+
sellAssetReference: AssetReference | string;
|
|
13
|
+
adapterManager: ChainAdapterManager;
|
|
14
|
+
receiveAddress: string;
|
|
15
|
+
}) => Promise<QuoteFeeData<'eip155:1'>>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEthTxFees = void 0;
|
|
4
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
5
|
+
const api_1 = require("../../../../../api");
|
|
6
|
+
const bignumber_1 = require("../../../../utils/bignumber");
|
|
7
|
+
const constants_1 = require("../../../../utils/constants");
|
|
8
|
+
const estimateTradeFee_1 = require("../../estimateTradeFee/estimateTradeFee");
|
|
9
|
+
const getEthTxFees = async ({ deps, data, router, buyAsset, sellAmount, adapterManager, receiveAddress, sellAssetReference }) => {
|
|
10
|
+
try {
|
|
11
|
+
const adapter = adapterManager.get(types_1.KnownChainIds.EthereumMainnet);
|
|
12
|
+
if (!adapter)
|
|
13
|
+
throw new api_1.SwapError(`[getThorTxInfo] - No chain adapter found for ${types_1.KnownChainIds.EthereumMainnet}.`, {
|
|
14
|
+
code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
|
|
15
|
+
details: { chainId: types_1.KnownChainIds.EthereumMainnet }
|
|
16
|
+
});
|
|
17
|
+
// TODO(ryankk): add falling back on hard coded gas Limit * new chain adapter method if it fails
|
|
18
|
+
const feeDataOptions = await adapter.getFeeData({
|
|
19
|
+
to: router,
|
|
20
|
+
value: sellAmount,
|
|
21
|
+
chainSpecific: { from: receiveAddress, contractData: data }
|
|
22
|
+
});
|
|
23
|
+
const feeData = feeDataOptions['fast'];
|
|
24
|
+
const tradeFee = await (0, estimateTradeFee_1.estimateTradeFee)(deps, buyAsset.assetId);
|
|
25
|
+
return {
|
|
26
|
+
fee: feeData.txFee,
|
|
27
|
+
chainSpecific: {
|
|
28
|
+
estimatedGas: feeData.chainSpecific.gasLimit,
|
|
29
|
+
gasPrice: feeData.chainSpecific.gasPrice,
|
|
30
|
+
approvalFee: sellAssetReference &&
|
|
31
|
+
(0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT)
|
|
32
|
+
.multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
|
|
33
|
+
.toString()
|
|
34
|
+
},
|
|
35
|
+
tradeFee
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
if (e instanceof api_1.SwapError)
|
|
40
|
+
throw e;
|
|
41
|
+
throw new api_1.SwapError('[getThorTxInfo]', { cause: e, code: api_1.SwapErrorTypes.TRADE_QUOTE_FAILED });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.getEthTxFees = getEthTxFees;
|
|
@@ -2,3 +2,5 @@ import BigNumber from 'bignumber.js';
|
|
|
2
2
|
export declare type BN = BigNumber;
|
|
3
3
|
export declare const bn: (n: BigNumber.Value, base?: number) => BN;
|
|
4
4
|
export declare const bnOrZero: (n: BigNumber.Value | null | undefined) => BN;
|
|
5
|
+
export declare const fromBaseUnit: (value: BigNumber.Value, decimals: number, displayDecimals?: number) => string;
|
|
6
|
+
export declare const toBaseUnit: (amount: BigNumber.Value | undefined, precision: number) => string;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.bnOrZero = exports.bn = void 0;
|
|
6
|
+
exports.toBaseUnit = exports.fromBaseUnit = exports.bnOrZero = exports.bn = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
8
|
const bn = (n, base = 10) => new bignumber_js_1.default(n, base);
|
|
9
9
|
exports.bn = bn;
|
|
@@ -12,3 +12,16 @@ const bnOrZero = (n) => {
|
|
|
12
12
|
return value.isNaN() ? (0, exports.bn)(0) : value;
|
|
13
13
|
};
|
|
14
14
|
exports.bnOrZero = bnOrZero;
|
|
15
|
+
const fromBaseUnit = (value, decimals, displayDecimals = 6) => {
|
|
16
|
+
return (0, exports.bnOrZero)(value)
|
|
17
|
+
.div(`1e+${decimals}`)
|
|
18
|
+
.decimalPlaces(displayDecimals, bignumber_js_1.default.ROUND_DOWN)
|
|
19
|
+
.toString();
|
|
20
|
+
};
|
|
21
|
+
exports.fromBaseUnit = fromBaseUnit;
|
|
22
|
+
const toBaseUnit = (amount, precision) => {
|
|
23
|
+
return (0, exports.bnOrZero)(amount)
|
|
24
|
+
.times(new bignumber_js_1.default(10).exponentiatedBy((0, exports.bnOrZero)(precision)))
|
|
25
|
+
.toFixed(0);
|
|
26
|
+
};
|
|
27
|
+
exports.toBaseUnit = toBaseUnit;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_SLIPPAGE = exports.APPROVAL_GAS_LIMIT = void 0;
|
|
4
|
+
exports.APPROVAL_GAS_LIMIT = '100000'; // Most approvals are around 40k, we've seen 72k in the wild, so 100000 for safety.
|
|
5
|
+
exports.DEFAULT_SLIPPAGE = '0.03'; // 3%
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BN } from '../bignumber';
|
|
2
|
+
/**
|
|
3
|
+
* This function keeps 17 significant digits, so even if we try to trade 1 Billion of an
|
|
4
|
+
* ETH or ERC20, we still keep 7 decimal places.
|
|
5
|
+
* @param amount
|
|
6
|
+
*/
|
|
7
|
+
export declare const normalizeAmount: (amount: string | number | BN) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeAmount = void 0;
|
|
4
|
+
const bignumber_1 = require("../bignumber");
|
|
5
|
+
/**
|
|
6
|
+
* This function keeps 17 significant digits, so even if we try to trade 1 Billion of an
|
|
7
|
+
* ETH or ERC20, we still keep 7 decimal places.
|
|
8
|
+
* @param amount
|
|
9
|
+
*/
|
|
10
|
+
const normalizeAmount = (amount) => {
|
|
11
|
+
return (0, bignumber_1.bnOrZero)(amount).toNumber().toLocaleString('fullwide', { useGrouping: false });
|
|
12
|
+
};
|
|
13
|
+
exports.normalizeAmount = normalizeAmount;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UNSUPPORTED = exports.ETH = exports.WBTC = exports.FOX = exports.WETH = exports.BTC = void 0;
|
|
4
|
-
const types_1 = require("@shapeshiftoss/types");
|
|
5
4
|
exports.BTC = {
|
|
6
5
|
assetId: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
|
|
7
6
|
chainId: 'bip122:000000000019d6689c085ae165831e93',
|
|
8
7
|
name: 'bitcoin',
|
|
9
|
-
chain: types_1.ChainTypes.Bitcoin,
|
|
10
|
-
network: types_1.NetworkTypes.MAINNET,
|
|
11
8
|
precision: 8,
|
|
12
9
|
color: '#FFFFFF',
|
|
13
10
|
icon: 'https://assets.coincap.io/assets/icons/btc@2x.png',
|
|
@@ -20,8 +17,6 @@ exports.WETH = {
|
|
|
20
17
|
assetId: 'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
21
18
|
chainId: 'eip155:1',
|
|
22
19
|
name: 'WETH',
|
|
23
|
-
chain: types_1.ChainTypes.Ethereum,
|
|
24
|
-
network: types_1.NetworkTypes.MAINNET,
|
|
25
20
|
precision: 18,
|
|
26
21
|
color: '#FFFFFF',
|
|
27
22
|
icon: 'https://assets.coingecko.com/coins/images/2518/thumb/weth.png?1628852295',
|
|
@@ -34,8 +29,6 @@ exports.FOX = {
|
|
|
34
29
|
assetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d',
|
|
35
30
|
chainId: 'eip155:1',
|
|
36
31
|
name: 'FOX',
|
|
37
|
-
chain: types_1.ChainTypes.Ethereum,
|
|
38
|
-
network: types_1.NetworkTypes.MAINNET,
|
|
39
32
|
precision: 18,
|
|
40
33
|
color: '#FFFFFF',
|
|
41
34
|
icon: 'https://assets.coincap.io/assets/icons/fox@2x.png',
|
|
@@ -48,21 +41,17 @@ exports.WBTC = {
|
|
|
48
41
|
assetId: 'eip155:1/erc20:0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
49
42
|
chainId: 'eip155:1',
|
|
50
43
|
color: '#FFFFFF',
|
|
51
|
-
chain: types_1.ChainTypes.Ethereum,
|
|
52
44
|
explorer: 'https://etherscan.io',
|
|
53
45
|
explorerAddressLink: 'https://etherscan.io/address/',
|
|
54
46
|
explorerTxLink: 'https://etherscan.io/tx/',
|
|
55
47
|
icon: 'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/logo.png',
|
|
56
48
|
name: 'Wrapped Bitcoin',
|
|
57
|
-
network: types_1.NetworkTypes.MAINNET,
|
|
58
49
|
precision: 8,
|
|
59
50
|
symbol: 'WBTC'
|
|
60
51
|
};
|
|
61
52
|
exports.ETH = {
|
|
62
53
|
assetId: 'eip155:1/slip44:60',
|
|
63
54
|
chainId: 'eip155:1',
|
|
64
|
-
chain: types_1.ChainTypes.Ethereum,
|
|
65
|
-
network: types_1.NetworkTypes.MAINNET,
|
|
66
55
|
symbol: 'ETH',
|
|
67
56
|
name: 'Ethereum',
|
|
68
57
|
precision: 18,
|
|
@@ -75,8 +64,6 @@ exports.ETH = {
|
|
|
75
64
|
exports.UNSUPPORTED = {
|
|
76
65
|
assetId: 'eip155:1/slip44:420',
|
|
77
66
|
chainId: 'eip155:1',
|
|
78
|
-
chain: types_1.ChainTypes.Ethereum,
|
|
79
|
-
network: types_1.NetworkTypes.MAINNET,
|
|
80
67
|
symbol: 'ETH',
|
|
81
68
|
name: 'Ethereum',
|
|
82
69
|
precision: 18,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ApprovalNeededInput, ApprovalNeededOutput } from '../../../api';
|
|
2
2
|
import { ZrxSwapperDeps } from '../ZrxSwapper';
|
|
3
|
-
export declare function ZrxApprovalNeeded({
|
|
3
|
+
export declare function ZrxApprovalNeeded({ adapter, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
|
|
@@ -6,7 +6,7 @@ const api_1 = require("../../../api");
|
|
|
6
6
|
const bignumber_1 = require("../../utils/bignumber");
|
|
7
7
|
const erc20Allowance_abi_1 = require("../utils/abi/erc20Allowance-abi");
|
|
8
8
|
const helpers_1 = require("../utils/helpers/helpers");
|
|
9
|
-
async function ZrxApprovalNeeded({
|
|
9
|
+
async function ZrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
10
10
|
var _a;
|
|
11
11
|
const { sellAsset } = quote;
|
|
12
12
|
const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
@@ -22,7 +22,6 @@ async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
|
|
|
22
22
|
return { approvalNeeded: false };
|
|
23
23
|
}
|
|
24
24
|
const accountNumber = quote.sellAssetAccountNumber;
|
|
25
|
-
const adapter = await adapterManager.byChainId(sellAsset.chainId);
|
|
26
25
|
const bip44Params = adapter.buildBIP44Params({ accountNumber });
|
|
27
26
|
const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
|
|
28
27
|
if (!quote.allowanceContract) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SupportedChainIds } from '@shapeshiftoss/types';
|
|
2
1
|
import { ApproveInfiniteInput } from '../../../api';
|
|
3
2
|
import { ZrxSwapperDeps } from '../ZrxSwapper';
|
|
4
|
-
export declare function ZrxApproveInfinite({
|
|
3
|
+
export declare function ZrxApproveInfinite({ adapter, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<'eip155:1'>): Promise<string>;
|
|
@@ -5,7 +5,7 @@ const api_1 = require("../../../api");
|
|
|
5
5
|
const erc20_abi_1 = require("../utils/abi/erc20-abi");
|
|
6
6
|
const constants_1 = require("../utils/constants");
|
|
7
7
|
const helpers_1 = require("../utils/helpers/helpers");
|
|
8
|
-
async function ZrxApproveInfinite({
|
|
8
|
+
async function ZrxApproveInfinite({ adapter, web3 }, { quote, wallet }) {
|
|
9
9
|
try {
|
|
10
10
|
const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
|
|
11
11
|
quote: {
|
|
@@ -13,7 +13,7 @@ async function ZrxApproveInfinite({ adapterManager, web3 }, { quote, wallet }) {
|
|
|
13
13
|
sellAmount: constants_1.MAX_ALLOWANCE
|
|
14
14
|
},
|
|
15
15
|
wallet,
|
|
16
|
-
|
|
16
|
+
adapter,
|
|
17
17
|
erc20Abi: erc20_abi_1.erc20Abi,
|
|
18
18
|
web3
|
|
19
19
|
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
import {
|
|
3
|
-
import { Asset
|
|
2
|
+
import { ethereum } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import { Asset } from '@shapeshiftoss/types';
|
|
4
4
|
import Web3 from 'web3';
|
|
5
5
|
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs, ZrxTrade } from '../../api';
|
|
6
6
|
export declare type ZrxSwapperDeps = {
|
|
7
|
-
|
|
7
|
+
adapter: ethereum.ChainAdapter;
|
|
8
8
|
web3: Web3;
|
|
9
9
|
};
|
|
10
|
-
export declare class ZrxSwapper implements Swapper {
|
|
10
|
+
export declare class ZrxSwapper implements Swapper<'eip155:1'> {
|
|
11
11
|
static swapperName: string;
|
|
12
12
|
deps: ZrxSwapperDeps;
|
|
13
13
|
constructor(deps: ZrxSwapperDeps);
|
|
14
14
|
initialize(): Promise<void>;
|
|
15
15
|
getType(): SwapperType;
|
|
16
|
-
buildTrade(args: BuildTradeInput): Promise<ZrxTrade
|
|
17
|
-
getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<
|
|
16
|
+
buildTrade(args: BuildTradeInput): Promise<ZrxTrade>;
|
|
17
|
+
getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<'eip155:1'>>;
|
|
18
18
|
getUsdRate(input: Asset): Promise<string>;
|
|
19
19
|
executeTrade(args: ExecuteTradeInput<'eip155:1'>): Promise<TradeResult>;
|
|
20
20
|
approvalNeeded(args: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
|
|
21
|
-
approveInfinite(args: ApproveInfiniteInput<
|
|
21
|
+
approveInfinite(args: ApproveInfiniteInput<'eip155:1'>): Promise<string>;
|
|
22
22
|
filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
|
|
23
23
|
filterAssetIdsBySellable(assetIds?: AssetId[]): AssetId[];
|
|
24
24
|
getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
|
|
@@ -4,9 +4,10 @@ exports.getZrxTradeQuote = void 0;
|
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const api_1 = require("../../../api");
|
|
6
6
|
const bignumber_1 = require("../../utils/bignumber");
|
|
7
|
+
const constants_1 = require("../../utils/constants");
|
|
8
|
+
const helpers_1 = require("../../utils/helpers/helpers");
|
|
7
9
|
const getZrxMinMax_1 = require("../getZrxMinMax/getZrxMinMax");
|
|
8
|
-
const
|
|
9
|
-
const helpers_1 = require("../utils/helpers/helpers");
|
|
10
|
+
const constants_2 = require("../utils/constants");
|
|
10
11
|
const zrxService_1 = require("../utils/zrxService");
|
|
11
12
|
async function getZrxTradeQuote(input) {
|
|
12
13
|
var _a;
|
|
@@ -61,7 +62,7 @@ async function getZrxTradeQuote(input) {
|
|
|
61
62
|
},
|
|
62
63
|
sellAmount: data.sellAmount,
|
|
63
64
|
buyAmount: data.buyAmount,
|
|
64
|
-
sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) ||
|
|
65
|
+
sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_2.DEFAULT_SOURCE,
|
|
65
66
|
allowanceContract: data.allowanceTarget,
|
|
66
67
|
buyAsset,
|
|
67
68
|
sellAsset,
|
|
@@ -5,7 +5,6 @@ export declare const FOX_TOKEN_CONTRACT_ADDRESS = "0xc770EEfAd204B5180dF6a14Ee19
|
|
|
5
5
|
export declare const WETH_TOKEN_CONTRACT_ADDRESS = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
6
6
|
export declare const UNISWAP_WETH_FOX_POOL_ADDRESS = "0x470e8de2ebaef52014a47cb5e6af86884947f08c";
|
|
7
7
|
export declare const MAX_ALLOWANCE = "100000000000000000000000000";
|
|
8
|
-
export declare const APPROVAL_GAS_LIMIT = "100000";
|
|
9
8
|
export declare const LIQUIDITY_GAS_LIMIT = "350000";
|
|
10
9
|
export declare const MAX_GAS_PRICE = "1000000000000";
|
|
11
10
|
export declare const MAX_ZRX_TRADE = "100000000000000000000000000";
|
|
@@ -13,8 +12,5 @@ export declare const DEFAULT_SOURCE: {
|
|
|
13
12
|
name: string;
|
|
14
13
|
proportion: string;
|
|
15
14
|
}[];
|
|
16
|
-
export declare const DEFAULT_SLIPPAGE = "0.03";
|
|
17
|
-
export declare const MAX_SLIPPAGE = "0.3";
|
|
18
|
-
export declare const ETH_FEE_ESTIMATE_PADDING = "1.2";
|
|
19
15
|
export declare const AFFILIATE_ADDRESS = "0xc770eefad204b5180df6a14ee197d99d808ee52d";
|
|
20
16
|
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.
|
|
3
|
+
exports.APPROVAL_BUY_AMOUNT = exports.AFFILIATE_ADDRESS = exports.DEFAULT_SOURCE = exports.MAX_ZRX_TRADE = exports.MAX_GAS_PRICE = exports.LIQUIDITY_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';
|
|
@@ -8,13 +8,9 @@ exports.FOX_TOKEN_CONTRACT_ADDRESS = '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d
|
|
|
8
8
|
exports.WETH_TOKEN_CONTRACT_ADDRESS = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
9
9
|
exports.UNISWAP_WETH_FOX_POOL_ADDRESS = '0x470e8de2ebaef52014a47cb5e6af86884947f08c';
|
|
10
10
|
exports.MAX_ALLOWANCE = '100000000000000000000000000';
|
|
11
|
-
exports.APPROVAL_GAS_LIMIT = '100000'; // Most approvals are around 40k, we've seen 72k in the wild, so 100000 for safety.
|
|
12
11
|
exports.LIQUIDITY_GAS_LIMIT = '350000'; // Most Liquidity txs are around 150000
|
|
13
12
|
exports.MAX_GAS_PRICE = '1000000000000'; // 1000 GWei
|
|
14
13
|
exports.MAX_ZRX_TRADE = '100000000000000000000000000';
|
|
15
14
|
exports.DEFAULT_SOURCE = [{ name: '0x', proportion: '1' }];
|
|
16
|
-
exports.DEFAULT_SLIPPAGE = '0.03'; // 3%
|
|
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.
|
|
19
15
|
exports.AFFILIATE_ADDRESS = '0xc770eefad204b5180df6a14ee197d99d808ee52d';
|
|
20
16
|
exports.APPROVAL_BUY_AMOUNT = '100000000000000000'; // A valid buy amount - 0.1 ETH
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ethereum } from '@shapeshiftoss/chain-adapters';
|
|
2
2
|
import { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
3
|
-
import { Asset
|
|
4
|
-
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { Asset } from '@shapeshiftoss/types';
|
|
5
4
|
import Web3 from 'web3';
|
|
6
5
|
import { AbiItem } from 'web3-utils';
|
|
7
6
|
import { TradeQuote } from '../../../../api';
|
|
7
|
+
import { BN } from '../../../utils/bignumber';
|
|
8
8
|
export declare type GetAllowanceRequiredArgs = {
|
|
9
9
|
receiveAddress: string;
|
|
10
10
|
allowanceContract: string;
|
|
@@ -21,23 +21,14 @@ export declare type GetERC20AllowanceArgs = {
|
|
|
21
21
|
spenderAddress: string;
|
|
22
22
|
};
|
|
23
23
|
declare type GrantAllowanceArgs = {
|
|
24
|
-
quote: TradeQuote<
|
|
24
|
+
quote: TradeQuote<'eip155:1'>;
|
|
25
25
|
wallet: HDWallet;
|
|
26
|
-
|
|
26
|
+
adapter: ethereum.ChainAdapter;
|
|
27
27
|
erc20Abi: AbiItem[];
|
|
28
28
|
web3: Web3;
|
|
29
29
|
};
|
|
30
|
-
/**
|
|
31
|
-
* Very large amounts like those found in ERC20s with a precision of 18 get converted
|
|
32
|
-
* to exponential notation ('1.6e+21') in javascript. The 0x api doesn't play well with
|
|
33
|
-
* exponential notation so we need to ensure that it is represented as an integer string.
|
|
34
|
-
* This function keeps 17 significant digits, so even if we try to trade 1 Billion of an
|
|
35
|
-
* ETH or ERC20, we still keep 7 decimal places.
|
|
36
|
-
* @param amount
|
|
37
|
-
*/
|
|
38
|
-
export declare const normalizeAmount: (amount: string | number | BigNumber) => string;
|
|
39
30
|
export declare const getERC20Allowance: ({ erc20AllowanceAbi, web3, sellAssetErc20Address, ownerAddress, spenderAddress }: GetERC20AllowanceArgs) => Promise<any>;
|
|
40
|
-
export declare const getAllowanceRequired: ({ receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi }: GetAllowanceRequiredArgs) => Promise<
|
|
31
|
+
export declare const getAllowanceRequired: ({ receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi }: GetAllowanceRequiredArgs) => Promise<BN>;
|
|
41
32
|
export declare const getUsdRate: (asset: Asset) => Promise<string>;
|
|
42
|
-
export declare const grantAllowance: ({ quote, wallet,
|
|
33
|
+
export declare const grantAllowance: ({ quote, wallet, adapter, erc20Abi, web3 }: GrantAllowanceArgs) => Promise<string>;
|
|
43
34
|
export {};
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.grantAllowance = exports.getUsdRate = exports.getAllowanceRequired = exports.getERC20Allowance =
|
|
3
|
+
exports.grantAllowance = exports.getUsdRate = exports.getAllowanceRequired = exports.getERC20Allowance = void 0;
|
|
4
4
|
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 bignumber_1 = require("../../../utils/bignumber");
|
|
8
8
|
const zrxService_1 = require("../zrxService");
|
|
9
|
-
/**
|
|
10
|
-
* Very large amounts like those found in ERC20s with a precision of 18 get converted
|
|
11
|
-
* to exponential notation ('1.6e+21') in javascript. The 0x api doesn't play well with
|
|
12
|
-
* exponential notation so we need to ensure that it is represented as an integer string.
|
|
13
|
-
* This function keeps 17 significant digits, so even if we try to trade 1 Billion of an
|
|
14
|
-
* ETH or ERC20, we still keep 7 decimal places.
|
|
15
|
-
* @param amount
|
|
16
|
-
*/
|
|
17
|
-
const normalizeAmount = (amount) => {
|
|
18
|
-
return (0, bignumber_1.bnOrZero)(amount).toNumber().toLocaleString('fullwide', { useGrouping: false });
|
|
19
|
-
};
|
|
20
|
-
exports.normalizeAmount = normalizeAmount;
|
|
21
9
|
const getERC20Allowance = async ({ erc20AllowanceAbi, web3, sellAssetErc20Address, ownerAddress, spenderAddress }) => {
|
|
22
10
|
const erc20Contract = new web3.eth.Contract(erc20AllowanceAbi, sellAssetErc20Address);
|
|
23
11
|
return erc20Contract.methods.allowance(ownerAddress, spenderAddress).call();
|
|
@@ -90,11 +78,10 @@ const getUsdRate = async (asset) => {
|
|
|
90
78
|
}
|
|
91
79
|
};
|
|
92
80
|
exports.getUsdRate = getUsdRate;
|
|
93
|
-
const grantAllowance = async ({ quote, wallet,
|
|
81
|
+
const grantAllowance = async ({ quote, wallet, adapter, erc20Abi, web3 }) => {
|
|
94
82
|
var _a, _b, _c, _d, _e;
|
|
95
83
|
try {
|
|
96
84
|
const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(quote.sellAsset.assetId);
|
|
97
|
-
const adapter = await adapterManager.byChainId('eip155:1');
|
|
98
85
|
const erc20Contract = new web3.eth.Contract(erc20Abi, sellAssetErc20Address);
|
|
99
86
|
const approveTx = erc20Contract.methods
|
|
100
87
|
.approve(quote.allowanceContract, quote.sellAmount)
|
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ethereum } from '@shapeshiftoss/chain-adapters';
|
|
2
2
|
import Web3 from 'web3';
|
|
3
|
-
export declare const chainAdapterMockFuncs: {
|
|
4
|
-
buildBIP44Params: jest.Mock<{
|
|
5
|
-
purpose: number;
|
|
6
|
-
coinType: number;
|
|
7
|
-
accountNumber: number;
|
|
8
|
-
}, []>;
|
|
9
|
-
buildSendTransaction: jest.Mock<Promise<{
|
|
10
|
-
txToSign: {};
|
|
11
|
-
}>, []>;
|
|
12
|
-
signTransaction: jest.Mock<Promise<string>, []>;
|
|
13
|
-
broadcastTransaction: jest.Mock<Promise<string>, []>;
|
|
14
|
-
getAddress: jest.Mock<Promise<string>, []>;
|
|
15
|
-
getAccount: jest.Mock<Promise<{
|
|
16
|
-
chainSpecific: {
|
|
17
|
-
tokens: {
|
|
18
|
-
assetId: string;
|
|
19
|
-
balance: string;
|
|
20
|
-
}[];
|
|
21
|
-
};
|
|
22
|
-
}>, []>;
|
|
23
|
-
getFeeData: jest.Mock<Promise<{
|
|
24
|
-
average: {
|
|
25
|
-
txFee: string;
|
|
26
|
-
};
|
|
27
|
-
}>, []>;
|
|
28
|
-
};
|
|
29
3
|
export declare const setupZrxDeps: () => {
|
|
30
|
-
|
|
31
|
-
|
|
4
|
+
web3: Web3;
|
|
5
|
+
adapter: ethereum.ChainAdapter;
|
|
32
6
|
};
|