GithubHelp home page GithubHelp logo

solendprotocol / solana-program-library Goto Github PK

View Code? Open in Web Editor NEW

This project forked from solana-labs/solana-program-library

83.0 83.0 65.0 19.03 MB

Solend main lending program

Home Page: https://solend.fi

License: Other

Rust 97.83% Shell 2.17%

solana-program-library's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

solana-program-library's Issues

Onchain Liquidity Mining

Instructions

New Instructions

AddLiquidityMiningRewards

arguments

  • reserve: Pubkey
  • RewardType: Deposit | Borrow
  • token address: Pubkey
  • token amount: u64
  • duration_in_slots: u64

behavior

  • transfer rewards to a token account owned by program

ClaimRewards

arguments

  • reserve: Pubkey
  • reward_id: u64

Modifying existing instructions

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

State

RewardInfo

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:

  • how to handle cases when the lm reward duration is finished? rewards can't accumulate forever. maybe best to have a cancelRewards function so the owner can withdraw
  • should we have a way to permissionlessly crank LM rewards? in case reward refreshing causes compute issues. Compute issues are scary because they can break liquidations.

Onchain Metadata

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:

  1. Define LendingMarketMetadata, ReserveMetadata accounts in the rust solend sdk. These should have the fields identical to MarketConfig,ReserveConfig in the backend + generous padding in case we need to add new stuff later. You can look at lending_market.rs to see how accounts are packed/unpacked
  2. Define instructions to create and update the metadata accounts. Some things to note:
  • only the lending market owner should be able to call these instructions
  • the LendingMarketMetadata, ReserveMetadata accounts should be pdas with seeds [lending_market.pubkey, "LendingMarketMetaData"], [reserve.pubkey, "ReserveMetaData"] respectively
  1. Update cli with support for new instructions
  2. Update typescript sdk with support for reading these accounts and calling these instructions.

Testing should include:

Dynamic Liquidation Bonus

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.

(Request) Anchor Bindings and a token-lending-common crate

  1. kind of annoying if users have to depend on the entire solend program if they want to use our structs. there's a non-zero change for dependency conflict.
  2. some people prefer using anchor bindings to make cpi calls.

I had a PR for this but it went stale #98 not too much work to revive it i guess

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.