diff --git a/app/scripts/controllers/swaps.js b/app/scripts/controllers/swaps.js index e1baff4e14c7..8c7e2c2148d6 100644 --- a/app/scripts/controllers/swaps.js +++ b/app/scripts/controllers/swaps.js @@ -691,15 +691,15 @@ export default class SwapsController { destinationAmount = 0, destinationToken, destinationTokenInfo, - gasEstimate, + gasEstimateWithRefund, sourceAmount, sourceToken, trade, fee: metaMaskFee, } = quote; - const tradeGasLimitForCalculation = gasEstimate - ? new BigNumber(gasEstimate, 16) + const tradeGasLimitForCalculation = gasEstimateWithRefund + ? new BigNumber(gasEstimateWithRefund, 16) : new BigNumber(averageGas || MAX_GAS_LIMIT, 10); const totalGasLimitForCalculation = tradeGasLimitForCalculation diff --git a/app/scripts/controllers/swaps.test.js b/app/scripts/controllers/swaps.test.js index ea3be085a548..685a13e4da74 100644 --- a/app/scripts/controllers/swaps.test.js +++ b/app/scripts/controllers/swaps.test.js @@ -426,9 +426,9 @@ describe('SwapsController', function () { const expectedResultQuotes = getTopQuoteAndSavingsBaseExpectedResults(); delete expectedResultQuotes[TEST_AGG_ID_6]; expectedResultQuotes[TEST_AGG_ID_1].savings = { - total: '0.0292', + total: '0.0092', performance: '0.0297', - fee: '0.02', + fee: '0', metaMaskFee: '0.0205', medianMetaMaskFee: '0.0202', }; @@ -450,27 +450,27 @@ describe('SwapsController', function () { const expectedResultQuotes = { [TEST_AGG_ID_1]: { ...testInput[TEST_AGG_ID_1], - ethFee: '0.01', + ethFee: '0.25', }, [TEST_AGG_ID_2]: { ...testInput[TEST_AGG_ID_2], - ethFee: '0.02', + ethFee: '0.25', }, [TEST_AGG_ID_3]: { ...testInput[TEST_AGG_ID_3], - ethFee: '0.03', + ethFee: '0.25', }, [TEST_AGG_ID_4]: { ...testInput[TEST_AGG_ID_4], - ethFee: '0.04', + ethFee: '0.25', }, [TEST_AGG_ID_5]: { ...testInput[TEST_AGG_ID_5], - ethFee: '0.05', + ethFee: '0.25', }, [TEST_AGG_ID_6]: { ...testInput[TEST_AGG_ID_6], - ethFee: '0.06', + ethFee: '0.25', }, }; @@ -498,42 +498,42 @@ describe('SwapsController', function () { sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '2.0195', + overallValueOfQuote: '1.7795', }, [TEST_AGG_ID_2]: { ...baseExpectedResultQuotes[TEST_AGG_ID_2], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.9996', + overallValueOfQuote: '1.7696', }, [TEST_AGG_ID_3]: { ...baseExpectedResultQuotes[TEST_AGG_ID_3], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.9698', + overallValueOfQuote: '1.7498', }, [TEST_AGG_ID_4]: { ...baseExpectedResultQuotes[TEST_AGG_ID_4], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.94', + overallValueOfQuote: '1.73', }, [TEST_AGG_ID_5]: { ...baseExpectedResultQuotes[TEST_AGG_ID_5], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.9102', + overallValueOfQuote: '1.7102', }, [TEST_AGG_ID_6]: { ...baseExpectedResultQuotes[TEST_AGG_ID_6], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.8705', + overallValueOfQuote: '1.6805', }, }; @@ -563,22 +563,22 @@ describe('SwapsController', function () { sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8b553ece48ec0000' }, - overallValueOfQuote: '1.9795', - ethFee: '0.05', + overallValueOfQuote: '1.7395', + ethFee: '0.29', }, [TEST_AGG_ID_2]: { ...baseExpectedResultQuotes[TEST_AGG_ID_2], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.9996', + overallValueOfQuote: '1.7696', isBestQuote: true, savings: { - total: '0.0243', - performance: '0.0297', - fee: '0.015', + total: '0.01445', + performance: '0.01485', + fee: '0.02', metaMaskFee: '0.0204', - medianMetaMaskFee: '0.0201', + medianMetaMaskFee: '0.02025', }, }, [TEST_AGG_ID_3]: { @@ -586,28 +586,28 @@ describe('SwapsController', function () { sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.9698', + overallValueOfQuote: '1.7498', }, [TEST_AGG_ID_4]: { ...baseExpectedResultQuotes[TEST_AGG_ID_4], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.94', + overallValueOfQuote: '1.73', }, [TEST_AGG_ID_5]: { ...baseExpectedResultQuotes[TEST_AGG_ID_5], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.9102', + overallValueOfQuote: '1.7102', }, [TEST_AGG_ID_6]: { ...baseExpectedResultQuotes[TEST_AGG_ID_6], sourceToken: ETH_SWAPS_TOKEN_OBJECT.address, destinationToken: '0x1111111111111111111111111111111111111111', trade: { value: '0x8ac7230489e80000' }, - overallValueOfQuote: '1.8705', + overallValueOfQuote: '1.6805', }, }; delete expectedResultQuotes[TEST_AGG_ID_1].isBestQuote; @@ -630,18 +630,18 @@ describe('SwapsController', function () { [TEST_AGG_ID_1]: { ...baseExpectedResultQuotes[TEST_AGG_ID_1], trade: { value: '0x8e1bc9bf040000' }, - overallValueOfQuote: '1.9795', - ethFee: '0.05', + overallValueOfQuote: '1.7395', + ethFee: '0.29', }, [TEST_AGG_ID_2]: { ...baseExpectedResultQuotes[TEST_AGG_ID_2], isBestQuote: true, savings: { - total: '0.0243', - performance: '0.0297', - fee: '0.015', + total: '0.01445', + performance: '0.01485', + fee: '0.02', metaMaskFee: '0.0204', - medianMetaMaskFee: '0.0201', + medianMetaMaskFee: '0.02025', }, }, }; @@ -686,14 +686,14 @@ describe('SwapsController', function () { gasEstimate: 2000000, gasEstimateWithRefund: '0xb8cae', savings: { - fee: '0', + fee: '-0.061067', metaMaskFee: '0.5050505050505050505', performance: '6', - total: '5.4949494949494949495', + total: '5.4338824949494949495', medianMetaMaskFee: '0.44444444444444444444', }, - ethFee: '5.033165', - overallValueOfQuote: '44.966835', + ethFee: '0.113536', + overallValueOfQuote: '49.886464', metaMaskFeeInEth: '0.5050505050505050505', ethValueOfTokens: '50', }); @@ -1337,50 +1337,50 @@ function getTopQuoteAndSavingsBaseExpectedResults() { [TEST_AGG_ID_1]: { ...baseTestInput[TEST_AGG_ID_1], isBestQuote: true, - ethFee: '0.01', - overallValueOfQuote: '2.0195', + ethFee: '0.25', + overallValueOfQuote: '1.7795', metaMaskFeeInEth: '0.0205', ethValueOfTokens: '2.0295', savings: { - total: '0.0441', + total: '0.0191', performance: '0.0396', - fee: '0.025', + fee: '0', metaMaskFee: '0.0205', medianMetaMaskFee: '0.0201', }, }, [TEST_AGG_ID_2]: { ...baseTestInput[TEST_AGG_ID_2], - ethFee: '0.02', - overallValueOfQuote: '1.9996', + ethFee: '0.25', + overallValueOfQuote: '1.7696', metaMaskFeeInEth: '0.0204', ethValueOfTokens: '2.0196', }, [TEST_AGG_ID_3]: { ...baseTestInput[TEST_AGG_ID_3], - ethFee: '0.03', - overallValueOfQuote: '1.9698', + ethFee: '0.25', + overallValueOfQuote: '1.7498', metaMaskFeeInEth: '0.0202', ethValueOfTokens: '1.9998', }, [TEST_AGG_ID_4]: { ...baseTestInput[TEST_AGG_ID_4], - ethFee: '0.04', - overallValueOfQuote: '1.94', + ethFee: '0.25', + overallValueOfQuote: '1.73', metaMaskFeeInEth: '0.02', ethValueOfTokens: '1.98', }, [TEST_AGG_ID_5]: { ...baseTestInput[TEST_AGG_ID_5], - ethFee: '0.05', - overallValueOfQuote: '1.9102', + ethFee: '0.25', + overallValueOfQuote: '1.7102', metaMaskFeeInEth: '0.0198', ethValueOfTokens: '1.9602', }, [TEST_AGG_ID_6]: { ...baseTestInput[TEST_AGG_ID_6], - ethFee: '0.06', - overallValueOfQuote: '1.8705', + ethFee: '0.25', + overallValueOfQuote: '1.6805', metaMaskFeeInEth: '0.0195', ethValueOfTokens: '1.9305', },