ref-finance / ref-contracts

Smart contracts for Ref Finance
MIT License
96 stars 54 forks source link

RatedSwapPool for stNEAR/wNEAR pool #78

Closed vitalii427 closed 2 years ago

vitalii427 commented 2 years ago

Generic RatedSwapPool and implementation for stNEAR/wNEAR pool

Based on StableSwapPool source code

Major changes:

New external methods:

Add liquidity flow:

Remove liquidity by tokens flow:

Remove liquidity by shares flow:

Swap flow:

Rates acquisition implementation:

pub trait RatesTrait {
    /// Check that cached rates are actual
    fn are_actual(&self) -> bool;
    /// Get cached rates vector
    fn get(&self) -> &Vec<Balance>;
    /// Update cached rates
    ///  if cached rates are actual returns true
    ///  else returns cross-contract call promise
    fn update(&self) -> PromiseOrValue<bool>;
    /// Update callback
    ///  receives JSON encoded cross-contract call result
    ///  and updates cached rates
    fn update_callback(&mut self, cross_call_result: &Vec<u8>) -> bool;
}

Other: