-
Notifications
You must be signed in to change notification settings - Fork 747
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
Changed LPFee to Percent type in Asset Conversion Pallet #1237
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -105,7 +105,7 @@ pub mod pallet { | |||||
}, | ||||||
BoundedBTreeSet, PalletId, | ||||||
}; | ||||||
use sp_arithmetic::Permill; | ||||||
use sp_arithmetic::{Percent, Permill}; | ||||||
use sp_runtime::{ | ||||||
traits::{IntegerSquareRoot, One, Zero}, | ||||||
Saturating, | ||||||
|
@@ -173,7 +173,7 @@ pub mod pallet { | |||||
|
||||||
/// A % the liquidity providers will take of every swap. Represents 10ths of a percent. | ||||||
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.
Suggested change
|
||||||
#[pallet::constant] | ||||||
type LPFee: Get<u32>; | ||||||
type LPFee: Get<Percent>; | ||||||
|
||||||
/// A one-time fee to setup the pool. | ||||||
#[pallet::constant] | ||||||
|
@@ -1124,18 +1124,16 @@ pub mod pallet { | |||||
return Err(Error::<T>::ZeroLiquidity.into()) | ||||||
} | ||||||
|
||||||
let amount_in_with_fee = amount_in | ||||||
.checked_mul(&(T::HigherPrecisionBalance::from(1000u32) - (T::LPFee::get().into()))) | ||||||
.ok_or(Error::<T>::Overflow)?; | ||||||
let fee_mult = T::HigherPrecisionBalance::from(T::LPFee::get() * 1u32); | ||||||
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. TODO, temporal, same as below |
||||||
|
||||||
let amount_in_with_fee = | ||||||
amount_in.checked_mul(&fee_mult).ok_or(Error::<T>::Overflow)?; | ||||||
|
||||||
let numerator = | ||||||
amount_in_with_fee.checked_mul(&reserve_out).ok_or(Error::<T>::Overflow)?; | ||||||
|
||||||
let denominator = reserve_in | ||||||
.checked_mul(&1000u32.into()) | ||||||
.ok_or(Error::<T>::Overflow)? | ||||||
.checked_add(&amount_in_with_fee) | ||||||
.ok_or(Error::<T>::Overflow)?; | ||||||
let denominator = | ||||||
reserve_in.checked_add(&amount_in_with_fee).ok_or(Error::<T>::Overflow)?; | ||||||
|
||||||
let result = numerator.checked_div(&denominator).ok_or(Error::<T>::Overflow)?; | ||||||
|
||||||
|
@@ -1163,16 +1161,14 @@ pub mod pallet { | |||||
Err(Error::<T>::AmountOutTooHigh.into())? | ||||||
} | ||||||
|
||||||
let numerator = reserve_in | ||||||
.checked_mul(&amount_out) | ||||||
.ok_or(Error::<T>::Overflow)? | ||||||
.checked_mul(&1000u32.into()) | ||||||
.ok_or(Error::<T>::Overflow)?; | ||||||
let numerator = reserve_in.checked_mul(&amount_out).ok_or(Error::<T>::Overflow)?; | ||||||
|
||||||
let fee_mult = T::HigherPrecisionBalance::from(T::LPFee::get() * 1u32); | ||||||
|
||||||
let denominator = reserve_out | ||||||
.checked_sub(&amount_out) | ||||||
.ok_or(Error::<T>::Overflow)? | ||||||
.checked_mul(&(T::HigherPrecisionBalance::from(1000u32) - T::LPFee::get().into())) | ||||||
.checked_mul(&fee_mult) | ||||||
.ok_or(Error::<T>::Overflow)?; | ||||||
|
||||||
let result = numerator | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Won't this be zero?
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.
yeah undesired, I meant (3, 1000) which is still rounded to either 0% or 1% depending on rounding rule. I probably need more accuracy for a 0.3% using Permill (there is no inbetween Percent and Permill right?) and then the fee calculations need to take this into consideration
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.
Yeah, it will have to be a
PerMill