Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "gasEstimateWithRefund" instead of "gasEstimate" #15968

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/scripts/controllers/swaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 49 additions & 49 deletions app/scripts/controllers/swaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand All @@ -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',
},
};

Expand Down Expand Up @@ -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',
},
};

Expand Down Expand Up @@ -563,51 +563,51 @@ 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]: {
...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',
},
};
delete expectedResultQuotes[TEST_AGG_ID_1].isBestQuote;
Expand All @@ -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',
},
},
};
Expand Down Expand Up @@ -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',
});
Expand Down Expand Up @@ -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',
},
Expand Down