@@ -63,9 +63,9 @@ use crate::{
6363 kilt:: { DipProofError , DipProofRequest , DotName , NativeAndForeignAssets , UniqueLinkingDeployment } ,
6464 parachain:: ConsensusHook ,
6565 xcm:: UniversalLocation ,
66- AssetSwitchPool1 , Aura , Block , BondedFungibles , DotNames , Executive , InherentDataExt , ParachainStaking ,
67- ParachainSystem , Runtime , RuntimeCall , RuntimeGenesisConfig , SessionKeys , TransactionPayment , UniqueLinking ,
68- VERSION ,
66+ AssetSwitchPool1 , Aura , Block , BondedCurrencies , BondedFungibles , DotNames , Executive , InherentDataExt ,
67+ ParachainStaking , ParachainSystem , Runtime , RuntimeCall , RuntimeGenesisConfig , SessionKeys , TransactionPayment ,
68+ UniqueLinking , VERSION ,
6969} ;
7070
7171// This is necessary since by default `RUNTIME_API_VERSIONS` generated by
@@ -506,37 +506,34 @@ impl_runtime_apis! {
506506
507507 let currency_supply = BondedFungibles :: total_issuance( currency_id. to_owned( ) ) ;
508508
509- let ( low, high, _ ) = match operation {
509+ let ( low, high, rounding ) = match operation {
510510 Operation :: Mint ( amount) => ( currency_supply, currency_supply. saturating_add( amount) , Round :: Up ) ,
511511 Operation :: Burn ( amount) => ( currency_supply. saturating_sub( amount) , currency_supply, Round :: Down ) ,
512512 } ;
513513
514- Self :: quote_for_low_and_high_bounds( pool_id, currency_idx, low, high)
514+ Self :: quote_for_low_and_high_bounds( pool_id, currency_idx, low, high, rounding )
515515 }
516516
517517 fn quote_for_low_and_high_bounds(
518518 pool_id: AccountId ,
519519 currency_idx: u8 ,
520520 low: Balance ,
521521 high: Balance ,
522+ rounding: Round ,
522523 ) -> Result <Balance , BondedCurrencyError > {
523524 let pool = Pools :: <Runtime >:: get( pool_id) . ok_or( BondedCurrencyError :: PoolNotFound ) ?;
524525 let PoolDetailsOf :: <Runtime > { curve, bonded_currencies, denomination, collateral, .. } = pool;
525- let currency_id = bonded_currencies. get( currency_idx. saturated_into:: <usize >( ) ) . ok_or( BondedCurrencyError :: CurrencyNotFound ) ?;
526-
527526 let collateral_denomination = NativeAndForeignAssets :: decimals( collateral) ;
528527
529- let normalized_low = balance_to_fixed( low, denomination, Round :: Down ) . map_err( |_| BondedCurrencyError :: BalanceConversion ) ?;
530- let normalized_high = balance_to_fixed( high, denomination, Round :: Up ) . map_err( |_| BondedCurrencyError :: BalanceConversion ) ?;
528+ let normalized_low = balance_to_fixed( low, denomination, rounding) . map_err( |_| BondedCurrencyError :: BalanceConversion ) ?;
529+ let normalized_high = balance_to_fixed( high, denomination, rounding) . map_err( |_| BondedCurrencyError :: BalanceConversion ) ?;
530+
531531
532- let passive_supply = bonded_currencies
533- . iter( )
534- . filter_map( |id| ( id != currency_id) . then_some( BondedFungibles :: total_issuance( id. to_owned( ) ) ) )
535- . map( |supply| balance_to_fixed( supply, denomination, Round :: Up ) . map_err( |_| BondedCurrencyError :: BalanceConversion ) )
536- . collect:: <Result <Vec <FixedPoint >, BondedCurrencyError >>( ) ?;
532+ let ( _, passive_supply) = BondedCurrencies :: calculate_normalized_passive_issuance( & bonded_currencies, denomination, currency_idx. into( ) , rounding)
533+ . map_err( |_| BondedCurrencyError :: BalanceConversion ) ?;
537534
538535 let normalized_collateral = curve. calculate_costs( normalized_low, normalized_high, passive_supply) . map_err( |_| BondedCurrencyError :: CalculationError ) ?;
539- fixed_to_balance( normalized_collateral, collateral_denomination, Round :: Up ) . map_err( |_| BondedCurrencyError :: BalanceConversion )
536+ fixed_to_balance( normalized_collateral, collateral_denomination, rounding ) . map_err( |_| BondedCurrencyError :: BalanceConversion )
540537 }
541538
542539 fn query_pools_by_manager( account: AccountId ) -> Vec <PoolDetails <AccountId , Balance , BondedAssetId , AssetId >> {
0 commit comments