fn do_update_oracle(
        pool: &mut Pool<AssetIdOf<T, I>, BalanceOf<T, I>, T::BlockNumber>,
    ) -> Result<(), DispatchError> {
        let block_timestamp = frame_system::Pallet::<T>::block_number();

        if pool.block_timestamp_last != block_timestamp {
            let time_elapsed: BalanceOf<T, I> = block_timestamp
                .saturating_sub(pool.block_timestamp_last)
                .saturated_into();

            // compute by multiplying the numerator with the time elapsed
            let price0_fraction = FixedU128::saturating_from_rational(
                time_elapsed
                    .get_big_uint()
                    .checked_mul(&pool.quote_amount.get_big_uint())
                    .ok_or(Error::<T, I>::ConversionToU128Failed)?
                    .to_u128()
                    .ok_or(ArithmeticError::Overflow)?,
                pool.base_amount,
            );
            let price1_fraction = FixedU128::saturating_from_rational(
                time_elapsed
                    .get_big_uint()
                    .checked_mul(&pool.base_amount.get_big_uint())
                    .ok_or(Error::<T, I>::ConversionToU128Failed)?
                    .to_u128()
                    .ok_or(ArithmeticError::Overflow)?,
                pool.quote_amount,
            );

            // convert stored u128 into FixedU128 before add
            pool.price_0_cumulative_last = FixedU128::from_inner(pool.price_0_cumulative_last)
                .checked_add(&price0_fraction)
                .ok_or(ArithmeticError::Overflow)?
                .into_inner();

            pool.price_1_cumulative_last = FixedU128::from_inner(pool.price_1_cumulative_last)
                .checked_add(&price1_fraction)
                .ok_or(ArithmeticError::Overflow)?
                .into_inner();

            // updates timestamp last so `time_elapsed` is correctly calculated
            pool.block_timestamp_last = block_timestamp;
        }

        Ok(())
    }
// update internal twap price oracle by calculating the number of blocks elapsed
// and update the pools cumulative prices
update internal twap price oracle by calculating the number of blocks elapsed
and update the pools cumulative prices
update internal twap price oracle by calculating the number of blocks elapsed and update the pools cumulative prices
fn do_update_oracle(
        pool: &mut Pool<AssetIdOf<T, I>, BalanceOf<T, I>, T::BlockNumber>,
    ) -> Result<(), DispatchError> {
        let block_timestamp = frame_system::Pallet::<T>::block_number();
        if pool.block_timestamp_last != block_timestamp {
            let time_elapsed: BalanceOf<T, I> = block_timestamp
                .saturating_sub(pool.block_timestamp_last)
                .saturated_into();
            // compute by multiplying the numerator with the time elapsed
            let price0_fraction = FixedU128::saturating_from_rational(
                time_elapsed
                    .get_big_uint()
                    .checked_mul(&pool.quote_amount.get_big_uint())
                    .ok_or(Error::<T, I>::ConversionToU128Failed)?
                    .to_u128()
                    .ok_or(ArithmeticError::Overflow)?,
                pool.base_amount,
            );
            let price1_fraction = FixedU128::saturating_from_rational(
                time_elapsed
                    .get_big_uint()
                    .checked_mul(&pool.base_amount.get_big_uint())
                    .ok_or(Error::<T, I>::ConversionToU128Failed)?
                    .to_u128()
                    .ok_or(ArithmeticError::Overflow)?,
                pool.quote_amount,
            );
            // convert stored u128 into FixedU128 before add
            pool.price_0_cumulative_last = FixedU128::from_inner(pool.price_0_cumulative_last)
                .checked_add(&price0_fraction)
                .ok_or(ArithmeticError::Overflow)?
                .into_inner();
            pool.price_1_cumulative_last = FixedU128::from_inner(pool.price_1_cumulative_last)
                .checked_add(&price1_fraction)
                .ok_or(ArithmeticError::Overflow)?
                .into_inner();
            // updates timestamp last so `time_elapsed` is correctly calculated
            pool.block_timestamp_last = block_timestamp;
        }
        Ok(())
    }
fn do_update_oracle ( pool : & mut Pool < AssetIdOf < T , I > , BalanceOf < T , I > , T :: BlockNumber > , ) -> Result < ( ) , DispatchError > { let block_timestamp = frame_system :: Pallet :: < T > :: block_number ( ) ; if pool . block_timestamp_last != block_timestamp { let time_elapsed : BalanceOf < T , I > = block_timestamp . saturating_sub ( pool . block_timestamp_last ) . saturated_into ( ) ; // compute by multiplying the numerator with the time elapsed let price0_fraction = FixedU128 :: saturating_from_rational ( time_elapsed . get_big_uint ( ) . checked_mul ( & pool . quote_amount . get_big_uint ( ) ) . ok_or ( Error :: < T , I > :: ConversionToU128Failed ) ? . to_u128 ( ) . ok_or ( ArithmeticError :: Overflow ) ? , pool . base_amount , ) ; let price1_fraction = FixedU128 :: saturating_from_rational ( time_elapsed . get_big_uint ( ) . checked_mul ( & pool . base_amount . get_big_uint ( ) ) . ok_or ( Error :: < T , I > :: ConversionToU128Failed ) ? . to_u128 ( ) . ok_or ( ArithmeticError :: Overflow ) ? , pool . quote_amount , ) ; // convert stored u128 into FixedU128 before add pool . price_0_cumulative_last = FixedU128 :: from_inner ( pool . price_0_cumulative_last ) . checked_add ( & price0_fraction ) . ok_or ( ArithmeticError :: Overflow ) ? . into_inner ( ) ; pool . price_1_cumulative_last = FixedU128 :: from_inner ( pool . price_1_cumulative_last ) . checked_add ( & price1_fraction ) . ok_or ( ArithmeticError :: Overflow ) ? . into_inner ( ) ; // updates timestamp last so `time_elapsed` is correctly calculated pool . block_timestamp_last = block_timestamp ; } Ok ( ( ) ) }
update internal twap price oracle by calculating the number of blocks elapsed
and update the pools cumulative prices
update internal twap price oracle by calculating the number of blocks elapsed and update the pools cumulative prices
pool
&mut Pool<AssetIdOf<T, I>, BalanceOf<T, I>, T::BlockNumber>
pool
&mut Pool<AssetIdOf<T, I>, BalanceOf<T, I>, T::BlockNumber>