osmosis-labs / isotonic

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

Add rebasing to lendex-token #3

Closed ethanfrey closed 2 years ago

ethanfrey commented 2 years ago

The idea of rebasing is that the token supply can easily increase or decrease globally by a multiplier. This allows us to charge a 2% tax across the board, or gives 3% "inflation" to all holders.

It is done by storing a global "multiplier", which can start at 1.0. There is a privileged operation, only accessible by the controller, which can adjust this multiplier.

In our case, this is done to ensure that 1 L-Token equals 1 base asset. The same multiplier can just store a ratio for input/ouput. Such that at 1.2, I must deposit 12 base asset to mint 10 L-Token. However, if we adjust all Supply and Balance queries with this multiplier, we get the nice property for the user/UI that it maintains a 1:1 ratio.

In this case, I will deposit 12 base asset to mint 12 L-token. The multiplier is 1.2 now, so my balance stored in the storage is 10. Later that multiplier goes up to 1.4. When I query my balance, I see 14. I can send 7 to another user, and we both have 5 recorded in the raw storage, but 7 in all Balance queries.

Verify all operations apply this multiplier as necessary: display = storage * multiplier

To do so we need to add a few msg/query:

pub enum ExecuteMsg {
    /// Can only be called by the controller.
    /// config.multiplier *= ratio
    Rebase { ratio: Decimal },
}
pub enum QueryMsg {
    /// Returns the global multiplier factor.
    Multiplier { },
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MultiplierResponse {
    pub multiplier: Decimal,
}

Stored as Item<Decimal> in this contract. Different for each token contract.

Note from Jakub: Ensure we test every msg and query so nothing gets missed (or missed later)