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

Return unoptimized quote in SwapQuote #62

Merged
merged 2 commits into from
Dec 1, 2020

Conversation

xianny
Copy link
Contributor

@xianny xianny commented Dec 1, 2020

Description

Supports new feature: calculating user savings.
Blocks: 0xProject/0x-api#435

This PR adds new fields unoptimizedQuoteInfo and unoptimizedOrders to the SwapQuote.

These new fields represent the best rate available from a single source, which would be the best alternative to our multi-source optimized path.

Testing instructions

Types of changes

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@xianny xianny requested review from dekz and dorothy-zbornak and removed request for BMillman19 and dave4506 December 1, 2020 00:41
* on a single quote info instead of using best and worst case
* Orders must be derived from the same path as the quote info
*/
export function getQuoteInfoMinBuyAmount(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use this in 0x-api to calculate affiliate fees if any

makerTokenDecimals,
takerTokenDecimals,
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a little refactoring but functionality should be the same

Comment on lines +181 to +189
// Calculate the unoptimised alternative
const unoptimizedFillResult = simulateBestCaseFill({
gasPrice,
orders: optimizedOrders,
orders: unoptimizedPath.orders,
side: operation,
fillAmount: assetFillAmount,
opts: { gasSchedule },
});
const unoptimizedQuoteInfo = fillResultsToQuoteInfo(unoptimizedFillResult);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new, the rest is refactoring

bestCaseQuoteInfo,
worstCaseQuoteInfo,
unoptimizedQuoteInfo,
unoptimizedOrders: unoptimizedPath.orders,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is new too, the rest is refactoring

Copy link
Contributor

@dorothy-zbornak dorothy-zbornak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this makes sense. Have you hooked it up to API to see if it looks right?

Comment on lines 22 to 24
const paths = fills.map(singleSourceFills => Path.create(side, singleSourceFills, targetInput, opts));
// Sort fill arrays by descending adjusted completed rate.
const sortedPaths = paths.sort((a, b) => b.adjustedCompleteRate().comparedTo(a.adjustedCompleteRate()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duped below. Can we refactor to avoid the dupe? Maybe add a fillsToPathsSortedByAdjustedCompletedRate()?

@xianny
Copy link
Contributor Author

xianny commented Dec 1, 2020

Ya, it looks like this in API: 0xProject/0x-api#435 (comment)

Pretty unambiguous!

@xianny xianny force-pushed the feat/return-unoptimized-amounts branch from aa12232 to 5bc0457 Compare December 1, 2020 20:18
@xianny xianny merged commit db81a94 into development Dec 1, 2020
@xianny xianny deleted the feat/return-unoptimized-amounts branch December 1, 2020 20:40
xianny added a commit that referenced this pull request Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants