Welcome to Solend

Protocol

Architecture

Computing Supply & Borrows

- refreshreserve - handles all the tracking work + updates ratio
- refreshObligation - computes obligation balances based on reserve ratios

- cToken Ratio acts as a % ownership of the LP
- Imagine a pool with 99USDC, you deposit 1 USDC, you will own 1% of the pool
- When the RefreshReserve occurs, the pool now has 110 USDC. Your 1% is now worth 1.1 USDC.
- Total Reserves / cTokens Minted

- APY is used to update CumulativeBorrowRate as an index
- When borrowing, calculate the initial CumulativeBorrowRate (lets say 1)
- RefreshReserve â†’ Updates the CumulativeBorrowRate (lets say its 1.02 now)
- Obligation' borrows would be increased by *1.02/1 (2%).

1

/// Compound current borrow rate over elapsed slots

2

fn compound_interest(

3

&mut self,

4

current_borrow_rate: Rate,

5

slots_elapsed: u64,

6

) -> ProgramResult {

7

let slot_interest_rate = current_borrow_rate.try_div(SLOTS_PER_YEAR)?;

8

let compounded_interest_rate = Rate::one()

9

.try_add(slot_interest_rate)?

10

.try_pow(slots_elapsed)?;

11

self.cumulative_borrow_rate_wads = self

12

.cumulative_borrow_rate_wads

13

.try_mul(compounded_interest_rate)?;

14

self.borrowed_amount_wads = self

15

.borrowed_amount_wads

16

.try_mul(compounded_interest_rate)?;

17

Ok(())

18

}

19

}

Copied!

Last modified 1mo ago

Copy link