-
Notifications
You must be signed in to change notification settings - Fork 69
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: add spot price provider for specified route #796
Conversation
Crate versions that have been updated:
Runtime version has been increased. |
…r and pool pays the fee
amount: amount_in, | ||
}]; | ||
|
||
let share_amount = Self::calculate_shares(pool_id, &assets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this case is not calculated by the math
asset_a: T::AssetId, | ||
asset_b: T::AssetId, | ||
) -> Result<FixedU128, ExecutorError<Self::Error>> { | ||
match pool_type { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be ideal to have this whole method covered by single math function so it doesn't have to be reimplemented in SDK as well
Explanation for spot price calculations, including fees.
We calculate spot price based on sell trade as it should yield very similar result like buy, and it also simplifies the implementation
XYK:
amount_out
is reduced byfee
, it makesasset_out
more expensive, so the asset_in/asset_out spot price should be increased. So divide spot-price-without-fee by1-fee
to reflect correct amount out after the fee deductionLBP:
fee
is deducted fromasset_out
, so divide spot-price-without-fee by1-fee
amount_out
calculated based on wholeamount_in
. So the result should be the same tospot_price_without_fee
Omnipool
asset_out
, so we need to increase the asset_in/asset_out spot price with dividing by1-asset_fee
to reflect correctamount_out
after the fee deduction(1-protocol_fee)*(1-asset_fee)
to reflect correct amount out after the fee deductionStableswap
For stableswap there is no formula for trades involving share assets, so we need to do a trade with small amount.
amount_out
is reduced byfee
in SELL, makingasset_out
more expensive, so the asset_in/asset_out spot price should be increased. So divide spot-price-without-fee by1-fee
to reflect correct amount out after the fee deductionwithdraw_asset_amount
. We do this to prevent too low shares in calculationsremove_liquidity_one_asset
. We do this to prevent too low shares in calculationsTODOs: