fix: worstCaseQuoteInfo calculating buys incorrectly [TKR-296] (#402)

* fix: WorstCaseQuoteInfo buy encoding

* CHANGELOG
This commit is contained in:
Jacob Evans 2022-01-31 17:01:17 +10:00 committed by GitHub
parent e5ed8b2c81
commit 97575bbde9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,13 @@
[
{
"version": "16.49.1",
"changes": [
{
"note": "Fix WorstCaseQuoteInfo encoding bug",
"pr": 402
}
]
},
{
"version": "16.49.0",
"changes": [

View File

@ -599,24 +599,25 @@ function calculateTwoHopQuoteInfo(
secondHopSource: _.pick(secondHopFill, 'source', 'fillData'),
}),
).toNumber();
const isSell = operation === MarketOperation.Sell;
return {
bestCaseQuoteInfo: {
makerAmount: operation === MarketOperation.Sell ? secondHopFill.output : secondHopFill.input,
takerAmount: operation === MarketOperation.Sell ? firstHopFill.input : firstHopFill.output,
totalTakerAmount: operation === MarketOperation.Sell ? firstHopFill.input : firstHopFill.output,
makerAmount: isSell ? secondHopFill.output : secondHopFill.input,
takerAmount: isSell ? firstHopFill.input : firstHopFill.output,
totalTakerAmount: isSell ? firstHopFill.input : firstHopFill.output,
feeTakerTokenAmount: constants.ZERO_AMOUNT,
protocolFeeInWeiAmount: constants.ZERO_AMOUNT,
gas,
},
// TODO jacob consolidate this with quote simulation worstCase
worstCaseQuoteInfo: {
makerAmount: MarketOperation.Sell
makerAmount: isSell
? secondHopOrder.makerAmount.times(1 - slippage).integerValue()
: secondHopOrder.makerAmount,
takerAmount: MarketOperation.Sell
takerAmount: isSell
? firstHopOrder.takerAmount
: firstHopOrder.takerAmount.times(1 + slippage).integerValue(),
totalTakerAmount: MarketOperation.Sell
totalTakerAmount: isSell
? firstHopOrder.takerAmount
: firstHopOrder.takerAmount.times(1 + slippage).integerValue(),
feeTakerTokenAmount: constants.ZERO_AMOUNT,