Skip to content

Commit

Permalink
make cli update only update if actually changing something and add an…
Browse files Browse the repository at this point in the history
…chor.toml
  • Loading branch information
nope-finance committed Aug 27, 2022
1 parent 1feaffc commit 70c8c5a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
13 changes: 13 additions & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
anchor_version = "0.13.2"

[workspace]
members = [
"token-lending/program",
]

[provider]
cluster = "mainnet"
wallet = "~/.config/solana/id.json"

[programs.mainnet]
spl_token_lending = "So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo"
56 changes: 39 additions & 17 deletions token-lending/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,9 @@ fn command_update_reserve(
) -> CommandResult {
let reserve_info = config.rpc_client.get_account(&reserve_pubkey)?;
let mut reserve = Reserve::unpack_from_slice(reserve_info.data.borrow())?;
if reserve_config.optimal_utilization_rate.is_some() {
let mut no_change = true;
if reserve_config.optimal_utilization_rate.is_some() && reserve.config.optimal_utilization_rate != reserve_config.optimal_utilization_rate.unwrap() {
no_change = false;
println!(
"Updating optimal_utilization_rate from {} to {}",
reserve.config.optimal_utilization_rate,
Expand All @@ -1110,7 +1112,8 @@ fn command_update_reserve(
reserve.config.optimal_utilization_rate = reserve_config.optimal_utilization_rate.unwrap();
}

if reserve_config.loan_to_value_ratio.is_some() {
if reserve_config.loan_to_value_ratio.is_some() && reserve.config.loan_to_value_ratio != reserve_config.loan_to_value_ratio.unwrap(){
no_change = false;
println!(
"Updating loan_to_value_ratio from {} to {}",
reserve.config.loan_to_value_ratio,
Expand All @@ -1119,7 +1122,8 @@ fn command_update_reserve(
reserve.config.loan_to_value_ratio = reserve_config.loan_to_value_ratio.unwrap();
}

if reserve_config.liquidation_bonus.is_some() {
if reserve_config.liquidation_bonus.is_some() && reserve.config.liquidation_bonus != reserve_config.liquidation_bonus.unwrap(){
no_change = false;
println!(
"Updating liquidation_bonus from {} to {}",
reserve.config.liquidation_bonus,
Expand All @@ -1128,7 +1132,8 @@ fn command_update_reserve(
reserve.config.liquidation_bonus = reserve_config.liquidation_bonus.unwrap();
}

if reserve_config.liquidation_threshold.is_some() {
if reserve_config.liquidation_threshold.is_some() && reserve.config.liquidation_threshold != reserve_config.liquidation_threshold.unwrap(){
no_change = false;
println!(
"Updating liquidation_threshold from {} to {}",
reserve.config.liquidation_threshold,
Expand All @@ -1137,7 +1142,8 @@ fn command_update_reserve(
reserve.config.liquidation_threshold = reserve_config.liquidation_threshold.unwrap();
}

if reserve_config.min_borrow_rate.is_some() {
if reserve_config.min_borrow_rate.is_some() && reserve.config.min_borrow_rate != reserve_config.min_borrow_rate.unwrap(){
no_change = false;
println!(
"Updating min_borrow_rate from {} to {}",
reserve.config.min_borrow_rate,
Expand All @@ -1146,7 +1152,8 @@ fn command_update_reserve(
reserve.config.min_borrow_rate = reserve_config.min_borrow_rate.unwrap();
}

if reserve_config.optimal_borrow_rate.is_some() {
if reserve_config.optimal_borrow_rate.is_some() && reserve.config.optimal_borrow_rate != reserve_config.optimal_borrow_rate.unwrap(){
no_change = false;
println!(
"Updating optimal_borrow_rate from {} to {}",
reserve.config.optimal_borrow_rate,
Expand All @@ -1155,7 +1162,8 @@ fn command_update_reserve(
reserve.config.optimal_borrow_rate = reserve_config.optimal_borrow_rate.unwrap();
}

if reserve_config.max_borrow_rate.is_some() {
if reserve_config.max_borrow_rate.is_some() && reserve.config.max_borrow_rate != reserve_config.max_borrow_rate.unwrap(){
no_change = false;
println!(
"Updating max_borrow_rate from {} to {}",
reserve.config.max_borrow_rate,
Expand All @@ -1164,7 +1172,8 @@ fn command_update_reserve(
reserve.config.max_borrow_rate = reserve_config.max_borrow_rate.unwrap();
}

if reserve_config.fees.borrow_fee_wad.is_some() {
if reserve_config.fees.borrow_fee_wad.is_some() && reserve.config.fees.borrow_fee_wad != reserve_config.fees.borrow_fee_wad.unwrap(){
no_change = false;
println!(
"Updating borrow_fee_wad from {} to {}",
reserve.config.fees.borrow_fee_wad,
Expand All @@ -1173,7 +1182,8 @@ fn command_update_reserve(
reserve.config.fees.borrow_fee_wad = reserve_config.fees.borrow_fee_wad.unwrap();
}

if reserve_config.fees.flash_loan_fee_wad.is_some() {
if reserve_config.fees.flash_loan_fee_wad.is_some() && reserve.config.fees.flash_loan_fee_wad != reserve_config.fees.flash_loan_fee_wad.unwrap(){
no_change = false;
println!(
"Updating flash_loan_fee_wad from {} to {}",
reserve.config.fees.flash_loan_fee_wad,
Expand All @@ -1182,7 +1192,8 @@ fn command_update_reserve(
reserve.config.fees.flash_loan_fee_wad = reserve_config.fees.flash_loan_fee_wad.unwrap();
}

if reserve_config.fees.host_fee_percentage.is_some() {
if reserve_config.fees.host_fee_percentage.is_some() && reserve.config.fees.host_fee_percentage != reserve_config.fees.host_fee_percentage.unwrap(){
no_change = false;
println!(
"Updating host_fee_percentage from {} to {}",
reserve.config.fees.host_fee_percentage,
Expand All @@ -1191,7 +1202,8 @@ fn command_update_reserve(
reserve.config.fees.host_fee_percentage = reserve_config.fees.host_fee_percentage.unwrap();
}

if reserve_config.deposit_limit.is_some() {
if reserve_config.deposit_limit.is_some() && reserve.config.deposit_limit != reserve_config.deposit_limit.unwrap() {
no_change = false;
println!(
"Updating deposit_limit from {} to {}",
amount_to_ui_amount(
Expand All @@ -1206,7 +1218,8 @@ fn command_update_reserve(
)
}

if reserve_config.borrow_limit.is_some() {
if reserve_config.borrow_limit.is_some() && reserve.config.borrow_limit != reserve_config.borrow_limit.unwrap(){
no_change = false;
println!(
"Updating borrow_limit from {} to {}",
amount_to_ui_amount(reserve.config.borrow_limit, reserve.liquidity.mint_decimals),
Expand All @@ -1218,7 +1231,8 @@ fn command_update_reserve(
)
}

if reserve_config.fee_receiver.is_some() {
if reserve_config.fee_receiver.is_some() && reserve.config.fee_receiver != reserve_config.fee_receiver.unwrap(){
no_change = false;
println!(
"Updating fee_receiver from {} to {}",
reserve.config.fee_receiver,
Expand All @@ -1227,7 +1241,8 @@ fn command_update_reserve(
reserve.config.fee_receiver = reserve_config.fee_receiver.unwrap();
}

if reserve_config.protocol_liquidation_fee.is_some() {
if reserve_config.protocol_liquidation_fee.is_some() && reserve.config.protocol_liquidation_fee != reserve_config.protocol_liquidation_fee.unwrap(){
no_change = false;
println!(
"Updating protocol_liquidation_fee from {} to {}",
reserve.config.protocol_liquidation_fee,
Expand All @@ -1236,7 +1251,8 @@ fn command_update_reserve(
reserve.config.protocol_liquidation_fee = reserve_config.protocol_liquidation_fee.unwrap();
}

if reserve_config.protocol_take_rate.is_some() {
if reserve_config.protocol_take_rate.is_some() && reserve.config.protocol_take_rate != reserve_config.protocol_take_rate.unwrap(){
no_change = false;
println!(
"Updating protocol_take_rate from {} to {}",
reserve.config.protocol_take_rate,
Expand All @@ -1246,7 +1262,8 @@ fn command_update_reserve(
}

let mut new_pyth_product_pubkey = solend_program::NULL_PUBKEY;
if pyth_price_pubkey.is_some() {
if pyth_price_pubkey.is_some() && reserve.liquidity.pyth_oracle_pubkey != pyth_price_pubkey.unwrap(){
no_change = false;
println!(
"Updating pyth oracle pubkey from {} to {}",
reserve.liquidity.pyth_oracle_pubkey,
Expand All @@ -1256,14 +1273,19 @@ fn command_update_reserve(
new_pyth_product_pubkey = pyth_product_pubkey.unwrap();
}

if switchboard_feed_pubkey.is_some() {
if switchboard_feed_pubkey.is_some() && reserve.liquidity.switchboard_oracle_pubkey != switchboard_feed_pubkey.unwrap(){
no_change = false;
println!(
"Updating switchboard_oracle_pubkey {} to {}",
reserve.liquidity.switchboard_oracle_pubkey,
switchboard_feed_pubkey.unwrap(),
);
reserve.liquidity.switchboard_oracle_pubkey = switchboard_feed_pubkey.unwrap();
}
if no_change {
println!("No changes made for reserve {}", reserve_pubkey.to_string());
return Ok(());
}

let recent_blockhash = config.rpc_client.get_latest_blockhash()?;

Expand Down

0 comments on commit 70c8c5a

Please sign in to comment.