solendprotocol / solana-program-library Goto Github PK
View Code? Open in Web Editor NEWThis project forked from solana-labs/solana-program-library
Solend main lending program
Home Page: https://solend.fi
License: Other
This project forked from solana-labs/solana-program-library
Solend main lending program
Home Page: https://solend.fi
License: Other
Deposit, Repay, Borrow, WIthdraw, Liquidate now all affect rewards calculations, so reward variables have to be "refreshed" at the start of each instruction now.
I think easiest way is to modify _refresh_reserve_interest to also refresh the rewards
struct ReserveRewardInfo {
id: u8,
token_account: Pubkey,
mint: Pubkey,
accumulated_reward_rate: Decimal,
last_updated_slot: u64,
rewards_attributed: Decimal,
total_rewards: u64
}
struct ObligationRewardInfo {
id: u8,
old_accumulator: Decimal,
claimed_rewards: Decimal,
unclaimed_rewards: Decimal
}
Other considerations:
We want to store LendingMarket/Reserve metadata onchain (instead of serving it from the backend). This metadata can be managed by our current program.
Implementation:
Testing should include:
Seems important to test
Explanation of invoke below:
https://docs.rs/solana-program/1.13.5/src/solana_program/program.rs.html#30-32
(which effectively disables the rate limiter)
Description:
Liquidations in Solend V2 have a dynamic bonus, depending on how unhealthy the obligation is. For example, an obligation that is barely eligible for liquidation will have a liquidation bonus of 0%, while a very unhealthy obligation will have a liquidation bonus of 10%.
Implementation Details:
The ReserveConfig will have the following new fields:
/// loan to value ratio at which the obligation gets liquidated for the maximum bonus
pub max_liquidation_threshold: u8,
/// max liquidation bonus. liquidation bonuses will be interpolated to be a value between liquidation bonus
/// and max liquidation bonus
pub max_liquidation_bonus: u8
The Obligation will have the following new fields:
/// ie sum(d.deposited_amount * d.max_liquidation_threshold * d.current_spot_price for d in deposits)
/// used to calculate the liquidation bonus
pub super_unhealthy_borrow_value: Decimal
The liquidation bonus will be calculated as follows (1):
let weight = (borrowed_value - unhealthy_borrowed_value) / (super_unhealthy_borrow_value - unhealthy_borrow_value)
let bonus = liquidation_bonus + weight * (max_liquidation_bonus - liquidation_bonus)
return bonus + reserve.protocol_liquidation_fee
Explanation for protocol_liquidation_fee:
Currently the protocol liquidation fee is calculated as a percentage of the bonus. However, it makes sense for the program to always make money on a liquidation. In cases where the bonuses are set to zero, the program will not make money. Therefore, on a liquidation, the protocol liquidation bonus (ie the protocol_liquidation_fee) is always included.
Extra care is required to make this specific change because the protocol_liquidation_fee is currently typically 30%, so it's important to handle cases of really high protocol bonuses. It would make sense to cap the protocol liquidation fee value during the Reserve::unpack function. Likewise it probably makes sense to have a global bonus max in (1), so things don't accidentally go crazy.
I had a PR for this but it went stale #98 not too much work to revive it i guess
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.