Created
February 29, 2024 11:20
-
-
Save ochaloup/6aef924edead0d459458489f993bb932 to your computer and use it in GitHub Desktop.
Marinade state verification onchain program
This file contains 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
[package] | |
name = "test" | |
version = "0.1.0" | |
description = "Created with Anchor" | |
edition = "2021" | |
[lib] | |
crate-type = ["cdylib", "lib"] | |
name = "test" | |
[features] | |
no-entrypoint = [] | |
no-idl = [] | |
no-log-ix-name = [] | |
cpi = ["no-entrypoint"] | |
default = [] | |
[dependencies] | |
anchor-lang = "0.27.0" | |
marinade-sdk = { git = "https://github.com/marinade-finance/marinade-sdk" } | |
micro-anchor = { git = "https://github.com/marinade-finance/marinade-sdk" } |
This file contains 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
use crate::error::TestError; | |
use anchor_lang::prelude::*; | |
use marinade_sdk::{ | |
checks::check_owner_program, | |
state::{marinade::Marinade, validator_system::ValidatorRecord}, | |
ID as MARINADE_PROGRAM_ID, | |
}; | |
use micro_anchor::Discriminator; | |
/// Check if provided account is Marinade state | |
pub fn assert_is_marinade_account(account_info: &AccountInfo) -> Result<()> { | |
let state_info = account_info.to_account_info(); | |
let state_data: &[u8] = &state_info.try_borrow_data()?; | |
require!( | |
state_data[..8] == Marinade::DISCRIMINATOR, | |
TestError::MarinadeInvalidDiscriminator | |
); | |
check_owner_program(&state_info, &MARINADE_PROGRAM_ID, "marinade_state")?; | |
Ok(()) | |
} | |
/// Verification of existence of Marinade validator duplication flag account | |
/// When a validator vote account | |
pub fn assert_is_in_marinade( | |
marinade_state: &Pubkey, | |
validator_duplication_flag: &AccountInfo, | |
asserted_validator_vote: &Pubkey, | |
) -> Result<()> { | |
let (duplication_flag_pda_address, _bump) = | |
ValidatorRecord::find_duplication_flag(marinade_state, asserted_validator_vote); | |
require_keys_eq!( | |
*validator_duplication_flag.key, | |
duplication_flag_pda_address, | |
TestError::MarinadeNotRentExcemptDuplicationFlag | |
); | |
check_owner_program( | |
validator_duplication_flag, | |
&MARINADE_PROGRAM_ID, | |
"validator_duplication_flag", | |
)?; | |
require!( | |
Rent::get()?.is_exempt( | |
validator_duplication_flag.lamports(), | |
validator_duplication_flag.data_len() | |
), | |
TestError::MarinadeNotRentExcemptDuplicationFlag | |
); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment