mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Use "gasEstimateWithRefund" instead of "gasEstimate" (#15968)
* Use gasEstimateWithRefund instead of gasEstimate * Update unit tests
This commit is contained in:
parent
c836f2f2ac
commit
e4798b2536
@ -691,15 +691,15 @@ export default class SwapsController {
|
|||||||
destinationAmount = 0,
|
destinationAmount = 0,
|
||||||
destinationToken,
|
destinationToken,
|
||||||
destinationTokenInfo,
|
destinationTokenInfo,
|
||||||
gasEstimate,
|
gasEstimateWithRefund,
|
||||||
sourceAmount,
|
sourceAmount,
|
||||||
sourceToken,
|
sourceToken,
|
||||||
trade,
|
trade,
|
||||||
fee: metaMaskFee,
|
fee: metaMaskFee,
|
||||||
} = quote;
|
} = quote;
|
||||||
|
|
||||||
const tradeGasLimitForCalculation = gasEstimate
|
const tradeGasLimitForCalculation = gasEstimateWithRefund
|
||||||
? new BigNumber(gasEstimate, 16)
|
? new BigNumber(gasEstimateWithRefund, 16)
|
||||||
: new BigNumber(averageGas || MAX_GAS_LIMIT, 10);
|
: new BigNumber(averageGas || MAX_GAS_LIMIT, 10);
|
||||||
|
|
||||||
const totalGasLimitForCalculation = tradeGasLimitForCalculation
|
const totalGasLimitForCalculation = tradeGasLimitForCalculation
|
||||||
|
@ -426,9 +426,9 @@ describe('SwapsController', function () {
|
|||||||
const expectedResultQuotes = getTopQuoteAndSavingsBaseExpectedResults();
|
const expectedResultQuotes = getTopQuoteAndSavingsBaseExpectedResults();
|
||||||
delete expectedResultQuotes[TEST_AGG_ID_6];
|
delete expectedResultQuotes[TEST_AGG_ID_6];
|
||||||
expectedResultQuotes[TEST_AGG_ID_1].savings = {
|
expectedResultQuotes[TEST_AGG_ID_1].savings = {
|
||||||
total: '0.0292',
|
total: '0.0092',
|
||||||
performance: '0.0297',
|
performance: '0.0297',
|
||||||
fee: '0.02',
|
fee: '0',
|
||||||
metaMaskFee: '0.0205',
|
metaMaskFee: '0.0205',
|
||||||
medianMetaMaskFee: '0.0202',
|
medianMetaMaskFee: '0.0202',
|
||||||
};
|
};
|
||||||
@ -450,27 +450,27 @@ describe('SwapsController', function () {
|
|||||||
const expectedResultQuotes = {
|
const expectedResultQuotes = {
|
||||||
[TEST_AGG_ID_1]: {
|
[TEST_AGG_ID_1]: {
|
||||||
...testInput[TEST_AGG_ID_1],
|
...testInput[TEST_AGG_ID_1],
|
||||||
ethFee: '0.01',
|
ethFee: '0.25',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_2]: {
|
[TEST_AGG_ID_2]: {
|
||||||
...testInput[TEST_AGG_ID_2],
|
...testInput[TEST_AGG_ID_2],
|
||||||
ethFee: '0.02',
|
ethFee: '0.25',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_3]: {
|
[TEST_AGG_ID_3]: {
|
||||||
...testInput[TEST_AGG_ID_3],
|
...testInput[TEST_AGG_ID_3],
|
||||||
ethFee: '0.03',
|
ethFee: '0.25',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_4]: {
|
[TEST_AGG_ID_4]: {
|
||||||
...testInput[TEST_AGG_ID_4],
|
...testInput[TEST_AGG_ID_4],
|
||||||
ethFee: '0.04',
|
ethFee: '0.25',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_5]: {
|
[TEST_AGG_ID_5]: {
|
||||||
...testInput[TEST_AGG_ID_5],
|
...testInput[TEST_AGG_ID_5],
|
||||||
ethFee: '0.05',
|
ethFee: '0.25',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_6]: {
|
[TEST_AGG_ID_6]: {
|
||||||
...testInput[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,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '2.0195',
|
overallValueOfQuote: '1.7795',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_2]: {
|
[TEST_AGG_ID_2]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_2],
|
...baseExpectedResultQuotes[TEST_AGG_ID_2],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.9996',
|
overallValueOfQuote: '1.7696',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_3]: {
|
[TEST_AGG_ID_3]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_3],
|
...baseExpectedResultQuotes[TEST_AGG_ID_3],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.9698',
|
overallValueOfQuote: '1.7498',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_4]: {
|
[TEST_AGG_ID_4]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_4],
|
...baseExpectedResultQuotes[TEST_AGG_ID_4],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.94',
|
overallValueOfQuote: '1.73',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_5]: {
|
[TEST_AGG_ID_5]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_5],
|
...baseExpectedResultQuotes[TEST_AGG_ID_5],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.9102',
|
overallValueOfQuote: '1.7102',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_6]: {
|
[TEST_AGG_ID_6]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_6],
|
...baseExpectedResultQuotes[TEST_AGG_ID_6],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.8705',
|
overallValueOfQuote: '1.6805',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -563,22 +563,22 @@ describe('SwapsController', function () {
|
|||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8b553ece48ec0000' },
|
trade: { value: '0x8b553ece48ec0000' },
|
||||||
overallValueOfQuote: '1.9795',
|
overallValueOfQuote: '1.7395',
|
||||||
ethFee: '0.05',
|
ethFee: '0.29',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_2]: {
|
[TEST_AGG_ID_2]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_2],
|
...baseExpectedResultQuotes[TEST_AGG_ID_2],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.9996',
|
overallValueOfQuote: '1.7696',
|
||||||
isBestQuote: true,
|
isBestQuote: true,
|
||||||
savings: {
|
savings: {
|
||||||
total: '0.0243',
|
total: '0.01445',
|
||||||
performance: '0.0297',
|
performance: '0.01485',
|
||||||
fee: '0.015',
|
fee: '0.02',
|
||||||
metaMaskFee: '0.0204',
|
metaMaskFee: '0.0204',
|
||||||
medianMetaMaskFee: '0.0201',
|
medianMetaMaskFee: '0.02025',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_3]: {
|
[TEST_AGG_ID_3]: {
|
||||||
@ -586,28 +586,28 @@ describe('SwapsController', function () {
|
|||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.9698',
|
overallValueOfQuote: '1.7498',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_4]: {
|
[TEST_AGG_ID_4]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_4],
|
...baseExpectedResultQuotes[TEST_AGG_ID_4],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.94',
|
overallValueOfQuote: '1.73',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_5]: {
|
[TEST_AGG_ID_5]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_5],
|
...baseExpectedResultQuotes[TEST_AGG_ID_5],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.9102',
|
overallValueOfQuote: '1.7102',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_6]: {
|
[TEST_AGG_ID_6]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_6],
|
...baseExpectedResultQuotes[TEST_AGG_ID_6],
|
||||||
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
sourceToken: ETH_SWAPS_TOKEN_OBJECT.address,
|
||||||
destinationToken: '0x1111111111111111111111111111111111111111',
|
destinationToken: '0x1111111111111111111111111111111111111111',
|
||||||
trade: { value: '0x8ac7230489e80000' },
|
trade: { value: '0x8ac7230489e80000' },
|
||||||
overallValueOfQuote: '1.8705',
|
overallValueOfQuote: '1.6805',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
delete expectedResultQuotes[TEST_AGG_ID_1].isBestQuote;
|
delete expectedResultQuotes[TEST_AGG_ID_1].isBestQuote;
|
||||||
@ -630,18 +630,18 @@ describe('SwapsController', function () {
|
|||||||
[TEST_AGG_ID_1]: {
|
[TEST_AGG_ID_1]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_1],
|
...baseExpectedResultQuotes[TEST_AGG_ID_1],
|
||||||
trade: { value: '0x8e1bc9bf040000' },
|
trade: { value: '0x8e1bc9bf040000' },
|
||||||
overallValueOfQuote: '1.9795',
|
overallValueOfQuote: '1.7395',
|
||||||
ethFee: '0.05',
|
ethFee: '0.29',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_2]: {
|
[TEST_AGG_ID_2]: {
|
||||||
...baseExpectedResultQuotes[TEST_AGG_ID_2],
|
...baseExpectedResultQuotes[TEST_AGG_ID_2],
|
||||||
isBestQuote: true,
|
isBestQuote: true,
|
||||||
savings: {
|
savings: {
|
||||||
total: '0.0243',
|
total: '0.01445',
|
||||||
performance: '0.0297',
|
performance: '0.01485',
|
||||||
fee: '0.015',
|
fee: '0.02',
|
||||||
metaMaskFee: '0.0204',
|
metaMaskFee: '0.0204',
|
||||||
medianMetaMaskFee: '0.0201',
|
medianMetaMaskFee: '0.02025',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -686,14 +686,14 @@ describe('SwapsController', function () {
|
|||||||
gasEstimate: 2000000,
|
gasEstimate: 2000000,
|
||||||
gasEstimateWithRefund: '0xb8cae',
|
gasEstimateWithRefund: '0xb8cae',
|
||||||
savings: {
|
savings: {
|
||||||
fee: '0',
|
fee: '-0.061067',
|
||||||
metaMaskFee: '0.5050505050505050505',
|
metaMaskFee: '0.5050505050505050505',
|
||||||
performance: '6',
|
performance: '6',
|
||||||
total: '5.4949494949494949495',
|
total: '5.4338824949494949495',
|
||||||
medianMetaMaskFee: '0.44444444444444444444',
|
medianMetaMaskFee: '0.44444444444444444444',
|
||||||
},
|
},
|
||||||
ethFee: '5.033165',
|
ethFee: '0.113536',
|
||||||
overallValueOfQuote: '44.966835',
|
overallValueOfQuote: '49.886464',
|
||||||
metaMaskFeeInEth: '0.5050505050505050505',
|
metaMaskFeeInEth: '0.5050505050505050505',
|
||||||
ethValueOfTokens: '50',
|
ethValueOfTokens: '50',
|
||||||
});
|
});
|
||||||
@ -1337,50 +1337,50 @@ function getTopQuoteAndSavingsBaseExpectedResults() {
|
|||||||
[TEST_AGG_ID_1]: {
|
[TEST_AGG_ID_1]: {
|
||||||
...baseTestInput[TEST_AGG_ID_1],
|
...baseTestInput[TEST_AGG_ID_1],
|
||||||
isBestQuote: true,
|
isBestQuote: true,
|
||||||
ethFee: '0.01',
|
ethFee: '0.25',
|
||||||
overallValueOfQuote: '2.0195',
|
overallValueOfQuote: '1.7795',
|
||||||
metaMaskFeeInEth: '0.0205',
|
metaMaskFeeInEth: '0.0205',
|
||||||
ethValueOfTokens: '2.0295',
|
ethValueOfTokens: '2.0295',
|
||||||
savings: {
|
savings: {
|
||||||
total: '0.0441',
|
total: '0.0191',
|
||||||
performance: '0.0396',
|
performance: '0.0396',
|
||||||
fee: '0.025',
|
fee: '0',
|
||||||
metaMaskFee: '0.0205',
|
metaMaskFee: '0.0205',
|
||||||
medianMetaMaskFee: '0.0201',
|
medianMetaMaskFee: '0.0201',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_2]: {
|
[TEST_AGG_ID_2]: {
|
||||||
...baseTestInput[TEST_AGG_ID_2],
|
...baseTestInput[TEST_AGG_ID_2],
|
||||||
ethFee: '0.02',
|
ethFee: '0.25',
|
||||||
overallValueOfQuote: '1.9996',
|
overallValueOfQuote: '1.7696',
|
||||||
metaMaskFeeInEth: '0.0204',
|
metaMaskFeeInEth: '0.0204',
|
||||||
ethValueOfTokens: '2.0196',
|
ethValueOfTokens: '2.0196',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_3]: {
|
[TEST_AGG_ID_3]: {
|
||||||
...baseTestInput[TEST_AGG_ID_3],
|
...baseTestInput[TEST_AGG_ID_3],
|
||||||
ethFee: '0.03',
|
ethFee: '0.25',
|
||||||
overallValueOfQuote: '1.9698',
|
overallValueOfQuote: '1.7498',
|
||||||
metaMaskFeeInEth: '0.0202',
|
metaMaskFeeInEth: '0.0202',
|
||||||
ethValueOfTokens: '1.9998',
|
ethValueOfTokens: '1.9998',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_4]: {
|
[TEST_AGG_ID_4]: {
|
||||||
...baseTestInput[TEST_AGG_ID_4],
|
...baseTestInput[TEST_AGG_ID_4],
|
||||||
ethFee: '0.04',
|
ethFee: '0.25',
|
||||||
overallValueOfQuote: '1.94',
|
overallValueOfQuote: '1.73',
|
||||||
metaMaskFeeInEth: '0.02',
|
metaMaskFeeInEth: '0.02',
|
||||||
ethValueOfTokens: '1.98',
|
ethValueOfTokens: '1.98',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_5]: {
|
[TEST_AGG_ID_5]: {
|
||||||
...baseTestInput[TEST_AGG_ID_5],
|
...baseTestInput[TEST_AGG_ID_5],
|
||||||
ethFee: '0.05',
|
ethFee: '0.25',
|
||||||
overallValueOfQuote: '1.9102',
|
overallValueOfQuote: '1.7102',
|
||||||
metaMaskFeeInEth: '0.0198',
|
metaMaskFeeInEth: '0.0198',
|
||||||
ethValueOfTokens: '1.9602',
|
ethValueOfTokens: '1.9602',
|
||||||
},
|
},
|
||||||
[TEST_AGG_ID_6]: {
|
[TEST_AGG_ID_6]: {
|
||||||
...baseTestInput[TEST_AGG_ID_6],
|
...baseTestInput[TEST_AGG_ID_6],
|
||||||
ethFee: '0.06',
|
ethFee: '0.25',
|
||||||
overallValueOfQuote: '1.8705',
|
overallValueOfQuote: '1.6805',
|
||||||
metaMaskFeeInEth: '0.0195',
|
metaMaskFeeInEth: '0.0195',
|
||||||
ethValueOfTokens: '1.9305',
|
ethValueOfTokens: '1.9305',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user