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

feat: best trade swap router rpc #944

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gregdhill
Copy link
Member

@gregdhill gregdhill commented Feb 22, 2023

path: Vec<TradingPath>,
) -> Self {
let execution_price =
FixedU128::checked_from_rational(output_amount.value, input_amount.value).unwrap_or_default();
Copy link
Member

Choose a reason for hiding this comment

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

Won't this limit the precision of the comparisons? Why don't we just compare input/output amounts directly, rather than constructing the ratio?

Comment on lines +267 to +270
token0: CurrencyId,
token1: CurrencyId,
reserve0: u128,
reserve1: u128,
Copy link
Member

Choose a reason for hiding this comment

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

Would be slightly cleaner if this just holds 2 Amounts

Comment on lines +246 to +247
input_amount: T::Balance,
input_currency: T::CurrencyId,
Copy link
Member

Choose a reason for hiding this comment

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

Take Amount? In general, when you have a (Balance, Currency) pair, I think it's best to construct the Amount as soon as possible

}
}

fn get_output_amount(
Copy link
Member

Choose a reason for hiding this comment

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

This function is not very well tested. I think only rpc_find_best_trade hits this code code at all

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.

Add RPC to compute optimal trading path
2 participants