mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 04:09:23 +00:00
Median by Position (#533)
* use median price instead of the highest sustained * add test for lexicographically reversing a byte slice * fix pr comments * fix CI fail * fix dex tests * Use a fuzz-tested list of prices * Working median algorithm based on position + lints --------- Co-authored-by: akildemir <aeg_asd@hotmail.com>
This commit is contained in:
@@ -216,23 +216,13 @@ pub mod pallet {
|
||||
type SortedAllocations<T: Config> =
|
||||
StorageMap<_, Identity, (NetworkId, [u8; 8], [u8; 16], Public), (), OptionQuery>;
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// A function which takes an amount and generates a byte array with a lexicographic order from
|
||||
/// high amount to low amount.
|
||||
#[inline]
|
||||
fn lexicographic_amount(amount: Amount) -> [u8; 8] {
|
||||
let mut bytes = amount.0.to_be_bytes();
|
||||
for byte in &mut bytes {
|
||||
*byte = !*byte;
|
||||
}
|
||||
bytes
|
||||
}
|
||||
#[inline]
|
||||
fn sorted_allocation_key(
|
||||
network: NetworkId,
|
||||
key: Public,
|
||||
amount: Amount,
|
||||
) -> (NetworkId, [u8; 8], [u8; 16], Public) {
|
||||
let amount = Self::lexicographic_amount(amount);
|
||||
let amount = reverse_lexicographic_order(amount.0.to_be_bytes());
|
||||
let hash = sp_io::hashing::blake2_128(&(network, amount, key).encode());
|
||||
(network, amount, hash, key)
|
||||
}
|
||||
@@ -769,7 +759,7 @@ pub mod pallet {
|
||||
use dex_pallet::HigherPrecisionBalance;
|
||||
|
||||
// This is inclusive to an increase in accuracy
|
||||
let sri_per_coin = Dex::<T>::oracle_value(balance.coin).unwrap_or(Amount(0));
|
||||
let sri_per_coin = Dex::<T>::security_oracle_value(balance.coin).unwrap_or(Amount(0));
|
||||
|
||||
// See dex-pallet for the reasoning on these
|
||||
let coin_decimals = balance.coin.decimals().max(5);
|
||||
|
||||
Reference in New Issue
Block a user