Skip to content

soda-protocol/soda-lending

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Soda Lending Contract

program id

SodatMqSurD1AuSB8MBrYKe29Du25nzqTPGk6xhJyNJ


pack transaction

init obligation

  • create obligation keypair
  • instructions
  • signing keypairs
    • obligation
    • authority

deposit + pledge

borrow

repay

  • instructions
  • signing keypairs
    • authorrity

withdraw 1

withdraw 2


instructions for front end

init obligation

  • accounts
    • rent pubkey
    • clock pubkey
    • manager pubkey
    • obligation pubkey Writable
    • user authority pubkey
  • data
    • InitUserObligation

update obligation

  • accounts
    • clock pubkey
    • obligation pubkey Writable
    • market reserve 1 pubkey
    • market reserve 2 pubkey
    • market reserve .. pubkey
  • data
    • RefreshUserObligation
  • remark
    • market reserve pubkeys 是用户obligation中collaterals和loans里包含的所有market reserve

update market reserves

  • accounts
    • clock pubkey
    • market reserve 1 pubkey Writable
    • price oracle 1 pubkey
    • rate oracle 1 pubkey
    • market reserve 2 pubkey Writable
    • price oracle 2 pubkey
    • rate oracle 2 pubkey
    • market reserve .. pubkey Writable
    • price oracle .. pubkey
    • rate oracle .. pubkey
  • data
    • RefreshMarketReserves
  • remark
    • market reserve pubkey 要按照用户obligation中collaterals和loans里的market reserve依次排序,rate oracle和price oracle要和market reserve对应

deposit

  • accounts
    • clock pubkey
    • manager pubkey
    • manager authority pubkey
    • market reserve pubkey Writable
    • sotoken mint pubkey Writable
    • manager token account pubkey Writable
    • rate oracle pubkey
    • user authority pubkey Signer
    • user token account pubkey Writable
    • user sotoken account pubkey Writable
    • spl token program
  • data
    • Deposit{ amount }

pledge

  • accounts
    • market reserve pubkey
    • sotoken mint pubkey Writable
    • user obligation pubkey Writable
    • user authority pubkey Signer
    • user sotoken account pubkey Writable
    • spl token program
  • data
    • PledgeCollateral{ amount }

borrow

  • accounts
    • clock pubkey
    • manager pubkey
    • manager authority pubkey
    • market reserve pubkey Writable
    • manager token account key Writable
    • user obligation pubkey Writable
    • user authority pubkey Signer
    • user token account key Writable
    • spl token program
  • data
    • BorrowLiquidity{ amount }

repay

  • accounts
    • clock pubkey
    • market reserve pubkey Writable
    • manager token account key Writable
    • rate oracle pubkey
    • user obligation pubkey Writable
    • user authority pubkey Signer
    • user token account key Writable
    • spl token program
  • data
    • RepayLoan{ amount }

redeem

  • accounts
    • clock pubkey
    • manager pubkey
    • manager authority pubkey
    • market reserve pubkey
    • sotoken mint pubkey Writable
    • user obligation pubkey Writable
    • user authority pubkey Signer
    • user sotoken account pubkey Writable
    • spl token program
  • data
    • RedeemCollateral{ amount }

redeem without loan

  • accounts
    • manager pubkey
    • manager authority pubkey
    • market reserve pubkey
    • sotoken mint pubkey Writable
    • user obligation pubkey Writable
    • user authority pubkey Signer
    • user sotoken account pubkey Writable
    • spl token program
  • data
    • RedeemCollateralWithoutLoan{ amount }

withdraw

  • accounts
    • clock pubkey
    • manager pubkey
    • manager authority pubkey
    • market reserve pubkey Writable
    • sotoken mint pubkey Writable
    • manager token account pubkey Writable
    • rate oracle pubkey
    • user authority pubkey Signer
    • user token account pubkey Writable
    • user sotoken account pubkey Writable
    • spl token program
  • data
    • Withdraw{ amount }

instructions for unique credit

  • data struct
pub struct UniqueCredit {
    /// 
    pub version: u8,
    ///
    pub owner: Pubkey,
    ///
    pub reserve: Pubkey,
    ///
    pub borrow_limit: u64,
    ///
    pub acc_borrow_rate_wads: Decimal,
    ///
    pub borrowed_amount_wads: Decimal,
}

pub struct MarketReserve {
    ///
    pub version: u8,
    ///
    pub last_update: LastUpdate,
    /// size: 32 byte (used in instruction)
    pub manager: Pubkey,
    /// 
    pub market_price: Decimal,
    /// 
    pub token_config: TokenConfig,
    /// size: 43 byte
    pub collateral_info: CollateralInfo,
    /// size: 83 byte
    pub liquidity_info: LiquidityInfo,
    /// size: 33 byte
    pub rate_model: RateModel,
    /// padding size: 256 byte
}

pub struct TokenConfig {
    ///
    pub mint_pubkey: Pubkey,
    ///
    pub supply_account: Pubkey,
    ///
    pub price_oracle: Pubkey,
    ///
    pub decimal: u8,
}
  • borrow liquidity
    • soda will approve final amount from supply_token_account_key for authority_key as delegate
pub fn borrow_liquidity_by_unique_credit(
    // manager pubkey which owns by soda program (should equals to field in MarketReserve)
    manager_key: Pubkey,
    // market reserve pubkey which owns by soda program
    market_reserve_key: Pubkey,
    // supply token account of reserve which owns by soda program (should equals to field in TokenConfig)
    supply_token_account_key: Pubkey, 
    // credit pubket which owns by soda program (created by soda admin)
    unique_credit_key: Pubkey,
    // authority of credit owner
    authority_key: Pubkey,
    // borrow amount (u64::MAX represents borrow all liquidity from reserve)
    amount: u64,
) -> Instruction {
    let program_id = id();
    let (manager_authority_key, _bump_seed) = Pubkey::find_program_address(
        &[manager_key.as_ref()],
        &program_id,
    );

    Instruction {
        program_id,
        accounts: vec![
            AccountMeta::new_readonly(sysvar::clock::id(), false),
            AccountMeta::new_readonly(manager_key, false),
            AccountMeta::new_readonly(manager_authority_key, false),
            AccountMeta::new(market_reserve_key, false),
            AccountMeta::new(supply_token_account_key, false),
            AccountMeta::new(unique_credit_key, false),
            AccountMeta::new_readonly(authority_key, true),
            AccountMeta::new_readonly(spl_token::id(), false),
        ],
        data: LendingInstruction::BorrowLiquidityByUniqueCredit{ amount }.pack(),
    }
}
  • repay loan
    • credit owner should approve repaying amount from source_token_account_key for manager_authority_key as delegate
pub fn repay_loan_by_unique_credit(
    manager_key: Pubkey,
    market_reserve_key: Pubkey,
    supply_token_account_key: Pubkey,
    unique_credit_key: Pubkey,
    // repaying token account
    source_token_account_key: Pubkey,
    // borrow amount (u64::MAX represents repaying as much as possible,
    // both considering token account balance and dept amount)
    amount: u64,
) -> Instruction {
    let program_id = id();
    let (manager_authority_key, _bump_seed) = Pubkey::find_program_address(
        &[manager_key.as_ref()],
        &program_id,
    );

    Instruction {
        program_id,
        accounts: vec![
            AccountMeta::new_readonly(sysvar::clock::id(), false),
            AccountMeta::new_readonly(manager_key, false),
            AccountMeta::new_readonly(manager_authority_key, false),
            AccountMeta::new(market_reserve_key, false),
            AccountMeta::new(supply_token_account_key, false),
            AccountMeta::new(unique_credit_key, false),
            AccountMeta::new(source_token_account_key, false),
            AccountMeta::new_readonly(spl_token::id(), false),
        ],
        data: LendingInstruction::RepayLoanByUniqueCredit{ amount }.pack(),
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages