Skip to content

Commit f466deb

Browse files
committed
refactor: remove transfer to save contract size
1 parent 38ada8a commit f466deb

25 files changed

+13
-101
lines changed

program/rust/src/processor.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ use {
1717
},
1818
solana_program::{
1919
entrypoint::ProgramResult,
20-
program::invoke,
2120
pubkey::Pubkey,
22-
system_instruction,
2321
sysvar::slot_history::AccountInfo,
2422
},
2523
};
@@ -109,30 +107,15 @@ pub fn process_instruction(
109107
}
110108
}
111109

112-
fn reserve_new_price_feed_index<'a>(
113-
funding_account: &AccountInfo<'a>,
114-
permissions_account: &AccountInfo<'a>,
115-
system_program: &AccountInfo<'a>,
116-
) -> Result<u32, ProgramError> {
110+
fn reserve_new_price_feed_index(permissions_account: &AccountInfo) -> Result<u32, ProgramError> {
117111
if permissions_account.data_len() < PermissionAccount::MIN_SIZE_WITH_LAST_FEED_INDEX {
118112
let new_size = PermissionAccount::MIN_SIZE_WITH_LAST_FEED_INDEX;
119113
let rent = Rent::get()?;
120114
let new_minimum_balance = rent.minimum_balance(new_size);
121-
let lamports_diff = new_minimum_balance.saturating_sub(permissions_account.lamports());
122-
if lamports_diff > 0 {
123-
invoke(
124-
&system_instruction::transfer(
125-
funding_account.key,
126-
permissions_account.key,
127-
lamports_diff,
128-
),
129-
&[
130-
funding_account.clone(),
131-
permissions_account.clone(),
132-
system_program.clone(),
133-
],
134-
)?;
135-
}
115+
pyth_assert(
116+
permissions_account.lamports() >= new_minimum_balance,
117+
ProgramError::AccountNotRentExempt,
118+
)?;
136119

137120
permissions_account.realloc(new_size, true)?;
138121
let mut header = load_account_as_mut::<AccountHeader>(permissions_account)?;

program/rust/src/processor/add_price.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use {
3737
// account[1] product account [writable]
3838
// account[2] new price account [writable]
3939
// account[3] permissions account [writable]
40-
// account[4] system program account []
4140
pub fn add_price(
4241
program_id: &Pubkey,
4342
accounts: &[AccountInfo],
@@ -51,12 +50,10 @@ pub fn add_price(
5150
ProgramError::InvalidArgument,
5251
)?;
5352

54-
55-
let (funding_account, product_account, price_account, permissions_account, system_program) =
56-
match accounts {
57-
[x, y, z, p, q] => Ok((x, y, z, p, q)),
58-
_ => Err(OracleError::InvalidNumberOfAccounts),
59-
}?;
53+
let (funding_account, product_account, price_account, permissions_account) = match accounts {
54+
[x, y, z, p] => Ok((x, y, z, p)),
55+
_ => Err(OracleError::InvalidNumberOfAccounts),
56+
}?;
6057

6158
check_valid_funding_account(funding_account)?;
6259
check_permissioned_funding_account(
@@ -74,10 +71,6 @@ pub fn add_price(
7471
&cmd_args.header,
7572
)?;
7673
check_valid_writable_account(program_id, permissions_account)?;
77-
pyth_assert(
78-
solana_program::system_program::check_id(system_program.key),
79-
OracleError::InvalidSystemAccount.into(),
80-
)?;
8174

8275
let mut product_data =
8376
load_checked::<ProductAccount>(product_account, cmd_args.header.version)?;
@@ -89,8 +82,7 @@ pub fn add_price(
8982
price_data.product_account = *product_account.key;
9083
price_data.next_price_account = product_data.first_price_account;
9184
price_data.min_pub_ = PRICE_ACCOUNT_DEFAULT_MIN_PUB;
92-
price_data.feed_index =
93-
reserve_new_price_feed_index(funding_account, permissions_account, system_program)?;
85+
price_data.feed_index = reserve_new_price_feed_index(permissions_account)?;
9486
product_data.first_price_account = *price_account.key;
9587

9688
Ok(())

program/rust/src/processor/add_product.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ pub fn add_product(
6565
hdr,
6666
)?;
6767

68-
6968
let mut mapping_data = load_checked::<MappingAccount>(tail_mapping_account, hdr.version)?;
7069
// The mapping account must have free space to add the product account
7170
pyth_assert(

program/rust/src/processor/del_product.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub fn del_product(
6868
cmd_args,
6969
)?;
7070

71-
7271
{
7372
let mut mapping_data = load_checked::<MappingAccount>(mapping_account, cmd_args.version)?;
7473
let product_data = load_checked::<ProductAccount>(product_account, cmd_args.version)?;

program/rust/src/processor/init_price.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub fn init_price(
5555
&cmd_args.header,
5656
)?;
5757

58-
5958
let mut price_data = load_checked::<PriceAccount>(price_account, cmd_args.header.version)?;
6059
pyth_assert(
6160
price_data.price_type == cmd_args.price_type,

program/rust/src/processor/init_price_feed_index.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use {
2828
// account[0] funding account [signer writable]
2929
// account[1] price account [writable]
3030
// account[2] permissions account [writable]
31-
// account[3] system program account []
3231
pub fn init_price_feed_index(
3332
program_id: &Pubkey,
3433
accounts: &[AccountInfo],
@@ -41,8 +40,8 @@ pub fn init_price_feed_index(
4140
ProgramError::InvalidArgument,
4241
)?;
4342

44-
let (funding_account, price_account, permissions_account, system_program) = match accounts {
45-
[x, y, p, z] => Ok((x, y, p, z)),
43+
let (funding_account, price_account, permissions_account) = match accounts {
44+
[x, y, p] => Ok((x, y, p)),
4645
_ => Err(OracleError::InvalidNumberOfAccounts),
4746
}?;
4847

@@ -55,18 +54,13 @@ pub fn init_price_feed_index(
5554
cmd,
5655
)?;
5756
check_valid_writable_account(program_id, permissions_account)?;
58-
pyth_assert(
59-
solana_program::system_program::check_id(system_program.key),
60-
OracleError::InvalidSystemAccount.into(),
61-
)?;
6257

6358
let mut price_account_data = load_checked::<PriceAccount>(price_account, cmd.version)?;
6459
pyth_assert(
6560
price_account_data.feed_index == 0,
6661
OracleError::FeedIndexAlreadyInitialized.into(),
6762
)?;
68-
price_account_data.feed_index =
69-
reserve_new_price_feed_index(funding_account, permissions_account, system_program)?;
63+
price_account_data.feed_index = reserve_new_price_feed_index(permissions_account)?;
7064

7165
Ok(())
7266
}

program/rust/src/processor/set_min_pub.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ pub fn set_min_pub(
5151
&cmd.header,
5252
)?;
5353

54-
5554
let mut price_account_data = load_checked::<PriceAccount>(price_account, cmd.header.version)?;
5655
price_account_data.min_pub_ = cmd.minimum_publishers;
5756

program/rust/src/processor/upd_permissions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub fn upd_permissions(
6161
OracleError::InvalidSystemAccount.into(),
6262
)?;
6363

64-
6564
// Create PermissionAccount if it doesn't exist
6665
PermissionAccount::initialize_pda(
6766
permissions_account,

program/rust/src/processor/upd_product.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub fn upd_product(
4747
hdr,
4848
)?;
4949

50-
5150
{
5251
// Validate that product_account contains the appropriate account header
5352
let mut _product_data = load_checked::<ProductAccount>(product_account, hdr.version)?;

program/rust/src/tests/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ mod test_upd_price_with_validator;
2828
mod test_upd_product;
2929
mod test_utils;
3030

31-
3231
mod test_twap;
3332
mod test_upd_price_v2;

0 commit comments

Comments
 (0)