osmosis-labs / isotonic

Smart Contracts for the Lendex Protocol
MIT License
1 stars 0 forks source link

Calculate Interest and Utilisation rate #8

Closed ethanfrey closed 2 years ago

ethanfrey commented 2 years ago

Utilisation rate is defined as bTokens / lTokens (having adjusted by the supply multiplier, so they are in units of base_asset).

Interest rate is calculated from utilisation rate. We will allow more complex formulas now, but to start with, we allow base + utilisation * slope. This should be defined in the init message.

Provide a query to return this information.

pub struct InstantiateMsg {
    /// other existing fields...
    pub interest_rate: Interest,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum Interest {
    Linear {
        /// what is charged at 0% utilization
        /// use "0.03" for tests
        base: Decimal,
        /// multiplier by the utilization 
        /// use "0.20" for tests
        slope: Decimal,
    }
}

And the following query:

pub enum QueryMsg {
    /// Returns current utilization and interest
    Interest {},
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct InterestResponse {
    pub utilization: Decimal,
    pub interest: Decimal,
}

// also update the existing response
pub struct MarketConfigResponse {
    pub base_asset: String,
    /// the two token addresses created on initialization
    pub l_token: String, 
    pub b_token: String,
    /// interest rate calculation
    pub rates: Interest,
}