-
Notifications
You must be signed in to change notification settings - Fork 115
Add feed index for batch publish #416
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fe2abc4
batch publish wip
Riateche 70912fd
refactor: separate header checks and account data casts
Riateche 44bf125
feat: feed index (wip)
Riateche 9512981
feat: assign price feed indexes to old accounts
Riateche 38ada8a
feat: init feed index when creating prices and init permission account
Riateche f466deb
refactor: remove transfer to save contract size
Riateche 500b627
test: add test for price feed indexes
Riateche 2f3c39c
refactor: address feedback
Riateche 9342f63
chore: fix some outdated account list docs
Riateche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use { | ||
super::reserve_new_price_feed_index, | ||
crate::{ | ||
accounts::PriceAccount, | ||
deserialize::{ | ||
load, | ||
load_checked, | ||
}, | ||
instruction::CommandHeader, | ||
utils::{ | ||
check_permissioned_funding_account, | ||
check_valid_funding_account, | ||
check_valid_writable_account, | ||
pyth_assert, | ||
}, | ||
OracleError, | ||
}, | ||
solana_program::{ | ||
account_info::AccountInfo, | ||
entrypoint::ProgramResult, | ||
program_error::ProgramError, | ||
pubkey::Pubkey, | ||
}, | ||
std::mem::size_of, | ||
}; | ||
|
||
/// Init price feed index | ||
// account[0] funding account [signer writable] | ||
// account[1] price account [writable] | ||
// account[2] permissions account [writable] | ||
pub fn init_price_feed_index( | ||
program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
instruction_data: &[u8], | ||
) -> ProgramResult { | ||
let cmd = load::<CommandHeader>(instruction_data)?; | ||
|
||
pyth_assert( | ||
instruction_data.len() == size_of::<CommandHeader>(), | ||
ProgramError::InvalidArgument, | ||
)?; | ||
|
||
let (funding_account, price_account, permissions_account) = match accounts { | ||
[x, y, p] => Ok((x, y, p)), | ||
_ => Err(OracleError::InvalidNumberOfAccounts), | ||
}?; | ||
|
||
check_valid_funding_account(funding_account)?; | ||
check_permissioned_funding_account( | ||
program_id, | ||
price_account, | ||
funding_account, | ||
permissions_account, | ||
cmd, | ||
)?; | ||
check_valid_writable_account(program_id, permissions_account)?; | ||
guibescos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let mut price_account_data = load_checked::<PriceAccount>(price_account, cmd.version)?; | ||
pyth_assert( | ||
price_account_data.feed_index == 0, | ||
OracleError::FeedIndexAlreadyInitialized.into(), | ||
)?; | ||
price_account_data.feed_index = reserve_new_price_feed_index(permissions_account)?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.