Repository navigation
Implement partial quote size for sushi market price #431
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -310,15 +310,49 @@ export class SharedState { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param skipFetch - (optional) Skips a fresh onchain call to fetch pools | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @returns The market price for the token pair or undefined if no route were found | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| getMarketPrice(fromToken: Token, toToken: Token, blockNumber?: bigint, skipFetch?: boolean) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.router.getMarketPrice({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| async getMarketPrice( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fromToken: Token, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| toToken: Token, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| blockNumber?: bigint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| skipFetch?: boolean, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const amountIn = parseUnits("1", fromToken.decimals); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await this.router.getMarketPrice({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fromToken, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| toToken, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| blockNumber, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| gasPrice: this.gasPrice, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| amountIn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| sushiRouteType: this.appOptions.route, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| skipFetch: !!skipFetch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.isOk()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const partialAmountIn = this.router.findLargestTradeSize( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { takeOrder: { quote: { ratio: 0n } } } as any, // ratio unused when absolute | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| toToken, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fromToken, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| amountIn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.gasPrice, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.appOptions.route, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| true, // absolute | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (typeof partialAmountIn !== "bigint") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const partialResult = await this.router.getMarketPrice({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fromToken, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| toToken, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| blockNumber, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| gasPrice: this.gasPrice, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| amountIn: parseUnits("1", fromToken.decimals), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| amountIn: partialAmountIn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| sushiRouteType: this.appOptions.route, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| skipFetch: !!skipFetch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+341
to
352
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against zero-sized partial quotes. 🔧 Suggested fix- if (typeof partialAmountIn !== "bigint") {
+ if (typeof partialAmountIn !== "bigint" || partialAmountIn <= 0n) {
return result;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (partialResult.isOk()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return partialResult; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.