Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whitelist liquidations #61

Open
wants to merge 3 commits into
base: upcoming
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions token-lending/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,14 @@ pub enum LendingError {
/// Not enough liquidity after flash loan
#[error("Not enough liquidity after flash loan")]
NotEnoughLiquidityAfterFlashLoan,

// 45
/// Null oracle config
#[error("Null oracle config")]
NullOracleConfig,
/// Non whitelist liquidator
#[error("Not a whitelisted liquidator")]
NonWhitelistLiquidator,
}

impl From<LendingError> for ProgramError {
Expand Down
26 changes: 26 additions & 0 deletions token-lending/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod state;

// Export current sdk types for downstream users building with a different sdk version
pub use solana_program;
pub use std::str::FromStr;

solana_program::declare_id!("So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo");

Expand All @@ -21,3 +22,28 @@ pub const NULL_PUBKEY: solana_program::pubkey::Pubkey =
11, 193, 238, 216, 208, 116, 241, 195, 55, 212, 76, 22, 75, 202, 40, 216, 76, 206, 27, 169,
138, 64, 177, 28, 19, 90, 156, 0, 0, 0, 0, 0,
]);

/// whitelist liquidator wallets
pub const WHITELIST_LIQUIDATORS : [solana_program::pubkey::Pubkey; 3] = [
// F4q2bm6k4AW2rgQMBfvoNnfn1xFkoD98We6uJd6tV7tq
solana_program::pubkey::Pubkey::new_from_array([
208, 254, 170, 18, 176, 113, 47, 78,
0, 176, 134, 93, 161, 19, 98, 161,
114, 185, 140, 222, 45, 158, 143, 251,
53, 114, 83, 154, 201, 207, 178, 198
]),
// owoD8aRRvKZXRfDiGvXYc18gfQ5cQBcKgEXFk6PCTva
solana_program::pubkey::Pubkey::new_from_array([
12, 6, 173, 17, 230, 35, 81, 149,
182, 240, 121, 19, 165, 180, 38, 237,
34, 50, 245, 8, 230, 123, 18, 122,
114, 60, 166, 205, 191, 247, 88, 195
]),
// 8i3ufSbnCDi3ZGyGJxDco26AQTGB5G81G1SBsUD55mK6 this is for tests
solana_program::pubkey::Pubkey::new_from_array([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This account has on-chain transactions from a year ago. Is that account's private key leaked?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's literally in the repo so yeah

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its the account they use for tests in repo

114, 133, 232, 227, 86, 67, 182, 15,
253, 36, 214, 87, 201, 19, 105, 189,
111, 157, 211, 250, 12, 167, 115, 73,
3, 116, 254, 73, 245, 75, 104, 105
])
];
12 changes: 10 additions & 2 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ fn process_repay_obligation_liquidity(
Ok(())
}


#[inline(never)] // avoid stack frame limit
fn process_liquidate_obligation(
program_id: &Pubkey,
Expand All @@ -1551,6 +1552,13 @@ fn process_liquidate_obligation(
let clock = &Clock::from_account_info(next_account_info(account_info_iter)?)?;
let token_program_id = next_account_info(account_info_iter)?;


if !spl_token_lending::WHITELIST_LIQUIDATORS.contains(&user_transfer_authority_info.key) {
msg!("Liquidator not part of whitelist");
return Err(LendingError::NonWhitelistLiquidator.into());
};


let lending_market = LendingMarket::unpack(&lending_market_info.data.borrow())?;
if lending_market_info.owner != program_id {
msg!("Lending market provided is not owned by the lending program");
Expand Down Expand Up @@ -2115,7 +2123,7 @@ fn get_price(
}

fn get_pyth_price(pyth_price_info: &AccountInfo, clock: &Clock) -> Result<Decimal, ProgramError> {
const STALE_AFTER_SLOTS_ELAPSED: u64 = 20;
const STALE_AFTER_SLOTS_ELAPSED: u64 = 240;

if *pyth_price_info.key == spl_token_lending::NULL_PUBKEY {
return Err(LendingError::NullOracleConfig.into());
Expand Down Expand Up @@ -2196,7 +2204,7 @@ fn get_switchboard_price(
switchboard_feed_info: &AccountInfo,
clock: &Clock,
) -> Result<Decimal, ProgramError> {
const STALE_AFTER_SLOTS_ELAPSED: u64 = 100;
const STALE_AFTER_SLOTS_ELAPSED: u64 = 240;

if *switchboard_feed_info.key == spl_token_lending::NULL_PUBKEY {
return Err(LendingError::NullOracleConfig.into());
Expand Down
5 changes: 3 additions & 2 deletions token-lending/program/tests/liquidate_obligation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use helpers::*;
use solana_program_test::*;
use solana_sdk::{
pubkey::Pubkey,
signature::{Keypair, Signer},
signature::{read_keypair_file, Keypair, Signer},
transaction::Transaction,
};
use spl_token::instruction::approve;
Expand Down Expand Up @@ -40,7 +40,8 @@ async fn test_success() {
const USDC_RESERVE_LIQUIDITY_FRACTIONAL: u64 = 2 * USDC_BORROW_AMOUNT_FRACTIONAL;

let user_accounts_owner = Keypair::new();
let user_transfer_authority = Keypair::new();
let user_transfer_authority =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested with a non whitelisted liquidator?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point yeh let me add

read_keypair_file("tests/fixtures/lending_market_owner.json").unwrap();
let lending_market = add_lending_market(&mut test);

let mut reserve_config = test_reserve_config();
Expand Down