Abehjati/repo-improvement (#395)

* Use a new rustfmt file

* Run cosmwasm action only when needed

* Remove pre-commit from remote-executor action

* Fix formatting

* Run precommit for all files

As previous PR was merged without pre-commit
This commit is contained in:
Ali Behjati 2022-11-25 11:16:58 +01:00 committed by GitHub
parent c3fefc78fa
commit becc216853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 1181 additions and 1195 deletions

View File

@ -1,14 +1,14 @@
on:
pull_request:
paths:
- ethereum/**
- third_party/pyth/xc-governance-sdk-js/**
paths:
- ethereum/**
- third_party/pyth/xc-governance-sdk-js/**
push:
branches:
- main
paths:
- ethereum/**
- third_party/pyth/xc-governance-sdk-js/**
paths:
- ethereum/**
- third_party/pyth/xc-governance-sdk-js/**
name: Ethereum Contract
@ -33,7 +33,7 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install Forge dependencies
run: npm run install-forge-deps

View File

@ -2,9 +2,15 @@ name: Pyth CosmWasm Contract
on:
pull_request:
paths:
- cosmwasm/**
- third_party/pyth/p2w-sdk/rust/**
push:
branches:
- main
paths:
- cosmwasm/**
- third_party/pyth/p2w-sdk/rust/**
env:
CARGO_TERM_COLOR: always

View File

@ -17,7 +17,6 @@ jobs:
profile: minimal
toolchain: nightly
components: rustfmt, clippy
- uses: pre-commit/action@v2.0.3
- name: Install Solana
run: |
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"

View File

@ -17,10 +17,10 @@ repos:
- repo: local
hooks:
# Hooks for the remote executor
- id: cargo-fmt-executor
name: Cargo format executor
- id: cargo-fmt-executor-remote-executor
name: Cargo format executor for remote executor
language: "rust"
entry: cargo +nightly fmt --manifest-path ./pythnet/remote-executor/Cargo.toml --all
entry: cargo +nightly fmt --manifest-path ./pythnet/remote-executor/Cargo.toml --all -- --config-path rustfmt.toml
pass_filenames: false
files: pythnet/remote-executor/
- id: cargo-clippy-executor
@ -30,9 +30,16 @@ repos:
pass_filenames: false
files: pythnet/remote-executor/
# Hooks for the attester
- id: cargo-fmt-executor
name: Cargo format executor
- id: cargo-fmt-executor-attester
name: Cargo format executor for attester
language: "rust"
entry: cargo +nightly fmt --manifest-path ./solana/pyth2wormhole/Cargo.toml --all
entry: cargo +nightly fmt --manifest-path ./solana/pyth2wormhole/Cargo.toml --all -- --config-path rustfmt.toml
pass_filenames: false
files: solana/pyth2wormhole/
# Hooks for cosmwasm contract
- id: cargo-fmt-executor-cosmwasm
name: Cargo format executor form cosmwasm contract
language: "rust"
entry: cargo +nightly fmt --manifest-path ./cosmwasm/Cargo.toml --all -- --config-path rustfmt.toml
pass_filenames: false
files: cosmwasm/

View File

@ -1,52 +1,52 @@
use std::collections::HashSet;
use cosmwasm_std::{
entry_point,
to_binary,
Binary,
Deps,
DepsMut,
Env,
MessageInfo,
QueryRequest,
Response,
StdResult,
Timestamp,
WasmQuery,
use {
crate::{
error::PythContractError,
msg::{
ExecuteMsg,
InstantiateMsg,
MigrateMsg,
PriceFeedResponse,
QueryMsg,
},
state::{
config,
config_read,
price_info,
price_info_read,
ConfigInfo,
PriceInfo,
PythDataSource,
VALID_TIME_PERIOD,
},
},
cosmwasm_std::{
entry_point,
to_binary,
Binary,
Deps,
DepsMut,
Env,
MessageInfo,
QueryRequest,
Response,
StdResult,
Timestamp,
WasmQuery,
},
p2w_sdk::BatchPriceAttestation,
pyth_sdk_cw::{
PriceFeed,
PriceIdentifier,
PriceStatus,
ProductIdentifier,
},
std::collections::HashSet,
wormhole::{
msg::QueryMsg as WormholeQueryMsg,
state::ParsedVAA,
},
};
use pyth_sdk_cw::{
PriceFeed,
PriceIdentifier,
PriceStatus,
ProductIdentifier,
};
use crate::msg::{
ExecuteMsg,
InstantiateMsg,
MigrateMsg,
PriceFeedResponse,
QueryMsg,
};
use crate::state::{
config,
config_read,
price_info,
price_info_read,
ConfigInfo,
PriceInfo,
PythDataSource,
VALID_TIME_PERIOD,
};
use crate::error::PythContractError;
use p2w_sdk::BatchPriceAttestation;
use wormhole::msg::QueryMsg as WormholeQueryMsg;
use wormhole::state::ParsedVAA;
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
Ok(Response::new())
@ -303,26 +303,27 @@ pub fn query_price_feed(deps: Deps, env: Env, address: &[u8]) -> StdResult<Price
price_feed: price_info.price_feed,
})
}
Err(_) => Err(PythContractError::PriceFeedNotFound)?
Err(_) => Err(PythContractError::PriceFeedNotFound)?,
}
}
#[cfg(test)]
mod test {
use cosmwasm_std::testing::{
mock_dependencies,
mock_env,
mock_info,
MockApi,
MockQuerier,
MockStorage,
use {
super::*,
cosmwasm_std::{
testing::{
mock_dependencies,
mock_env,
mock_info,
MockApi,
MockQuerier,
MockStorage,
},
Addr,
OwnedDeps,
},
};
use cosmwasm_std::{
Addr,
OwnedDeps,
};
use super::*;
fn setup_test() -> (OwnedDeps<MockStorage, MockApi, MockQuerier>, Env) {
(mock_dependencies(), mock_env())

View File

@ -1,5 +1,7 @@
use cosmwasm_std::StdError;
use thiserror::Error;
use {
cosmwasm_std::StdError,
thiserror::Error,
};
#[derive(Error, Debug)]
pub enum PythContractError {

View File

@ -1,12 +1,13 @@
use cosmwasm_std::Binary;
use schemars::JsonSchema;
use serde::{
Deserialize,
Serialize,
use {
crate::state::PythDataSource,
cosmwasm_std::Binary,
schemars::JsonSchema,
serde::{
Deserialize,
Serialize,
},
};
use crate::state::PythDataSource;
type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]

View File

@ -1,29 +1,30 @@
use std::collections::HashSet;
use std::time::Duration;
use pyth_sdk_cw::PriceFeed;
use schemars::JsonSchema;
use serde::{
Deserialize,
Serialize,
};
use cosmwasm_std::{
Addr,
Binary,
Storage,
Timestamp,
};
use cosmwasm_storage::{
bucket,
bucket_read,
singleton,
singleton_read,
Bucket,
ReadonlyBucket,
ReadonlySingleton,
Singleton,
use {
cosmwasm_std::{
Addr,
Binary,
Storage,
Timestamp,
},
cosmwasm_storage::{
bucket,
bucket_read,
singleton,
singleton_read,
Bucket,
ReadonlyBucket,
ReadonlySingleton,
Singleton,
},
pyth_sdk_cw::PriceFeed,
schemars::JsonSchema,
serde::{
Deserialize,
Serialize,
},
std::{
collections::HashSet,
time::Duration,
},
};
pub static CONFIG_KEY: &[u8] = b"config";

View File

@ -1,22 +0,0 @@
# Merge similar crates together to avoid multiple use statements.
imports_granularity = "Module"
# Consistency in formatting makes tool based searching/editing better.
empty_item_single_line = false
# Easier editing when arbitrary mixed use statements do not collapse.
imports_layout = "Vertical"
# Default rustfmt formatting of match arms with branches is awful.
match_arm_leading_pipes = "Preserve"
# Align Fields
enum_discrim_align_threshold = 80
struct_field_align_threshold = 80
# Allow up to two blank lines for grouping.
blank_lines_upper_bound = 2
# Wrap comments
comment_width = 120
wrap_comments = true

View File

@ -1,11 +1,13 @@
//! CLI options
use clap::{
Parser,
Subcommand,
};
use solana_sdk::{
commitment_config::CommitmentConfig,
pubkey::Pubkey,
use {
clap::{
Parser,
Subcommand,
},
solana_sdk::{
commitment_config::CommitmentConfig,
pubkey::Pubkey,
},
};
#[derive(Parser, Debug)]
@ -17,7 +19,7 @@ pub struct Cli {
#[clap(long, default_value = "confirmed")]
pub commitment: CommitmentConfig,
#[clap(subcommand)]
pub action: Action,
pub action: Action,
}
#[derive(Subcommand, Debug)]
@ -25,7 +27,7 @@ pub enum Action {
#[clap(about = "Post a VAA and execute it through the remote executor")]
PostAndExecute {
#[clap(short = 'v', long = "vaa")]
vaa: String,
vaa: String,
#[clap(
long,
default_value = "~/.config/solana/id.json",
@ -47,22 +49,22 @@ pub enum Action {
#[clap(about = "Get set upgrade authority payload for squads-cli")]
GetSetUpgradeAuthorityPayload {
#[clap(short, long, help = "Current authority")]
current: Pubkey,
current: Pubkey,
#[clap(short, long, help = "New authority")]
new: Pubkey,
new: Pubkey,
#[clap(short, long, help = "Program id")]
program_id: Pubkey,
},
#[clap(about = "Get upgrade program payload for squads-cli")]
GetUpgradeProgramPayload {
#[clap(short, long, help = "Current authority")]
authority: Pubkey,
authority: Pubkey,
#[clap(short, long, help = "Program id")]
program_id: Pubkey,
#[clap(short, long, help = "New buffer")]
new_buffer: Pubkey,
#[clap(short, long, help = "Spill address")]
spill: Pubkey,
spill: Pubkey,
},
#[clap(about = "Map solana key to pythnet key")]
MapKey {

View File

@ -1,69 +1,70 @@
#![deny(warnings)]
pub mod cli;
use std::str::FromStr;
use anchor_client::{
anchor_lang::{
AccountDeserialize,
AnchorDeserialize,
AnchorSerialize,
InstructionData as AnchorInstructionData,
Owner,
ToAccountMetas,
use {
anchor_client::{
anchor_lang::{
AccountDeserialize,
AnchorDeserialize,
AnchorSerialize,
InstructionData as AnchorInstructionData,
Owner,
ToAccountMetas,
},
solana_sdk::bpf_loader_upgradeable,
},
solana_sdk::bpf_loader_upgradeable,
};
use clap::Parser;
use cli::{
Action,
Cli,
};
use anyhow::Result;
use remote_executor::{
accounts::ExecutePostedVaa,
state::governance_payload::InstructionData,
EXECUTOR_KEY_SEED,
ID,
};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{
instruction::{
AccountMeta,
Instruction,
anyhow::Result,
clap::Parser,
cli::{
Action,
Cli,
},
pubkey::Pubkey,
signature::{
read_keypair_file,
Keypair,
remote_executor::{
accounts::ExecutePostedVaa,
state::{
governance_payload::{
ExecutorPayload,
GovernanceHeader,
InstructionData,
},
posted_vaa::AnchorVaa,
},
EXECUTOR_KEY_SEED,
ID,
},
signer::Signer,
system_instruction,
system_instruction::transfer,
transaction::Transaction,
};
use wormhole_solana::{
instructions::{
post_message,
post_vaa,
verify_signatures_txs,
PostVAAData,
solana_client::rpc_client::RpcClient,
solana_sdk::{
instruction::{
AccountMeta,
Instruction,
},
pubkey::Pubkey,
signature::{
read_keypair_file,
Keypair,
},
signer::Signer,
system_instruction::{
self,
transfer,
},
transaction::Transaction,
},
Account,
Config,
FeeCollector,
GuardianSet,
VAA as PostedVAA,
};
use remote_executor::state::{
governance_payload::{
ExecutorPayload,
GovernanceHeader,
std::str::FromStr,
wormhole::VAA,
wormhole_solana::{
instructions::{
post_message,
post_vaa,
verify_signatures_txs,
PostVAAData,
},
Account,
Config,
FeeCollector,
GuardianSet,
VAA as PostedVAA,
},
posted_vaa::AnchorVaa,
};
use wormhole::VAA;
fn main() -> Result<()> {
let cli = Cli::parse();
@ -130,15 +131,15 @@ fn main() -> Result<()> {
// Post VAA
let post_vaa_data = PostVAAData {
version: vaa.version,
version: vaa.version,
guardian_set_index: vaa.guardian_set_index,
timestamp: vaa.timestamp,
nonce: vaa.nonce,
emitter_chain: vaa.emitter_chain.into(),
emitter_address: vaa.emitter_address,
sequence: vaa.sequence,
consistency_level: vaa.consistency_level,
payload: vaa.payload,
timestamp: vaa.timestamp,
nonce: vaa.nonce,
emitter_chain: vaa.emitter_chain.into(),
emitter_address: vaa.emitter_address,
sequence: vaa.sequence,
consistency_level: vaa.consistency_level,
payload: vaa.payload,
};
process_transaction(
@ -184,7 +185,7 @@ fn main() -> Result<()> {
Config::try_from_slice(&rpc_client.get_account_data(&wormhole_config)?)?;
let payload = ExecutorPayload {
header: GovernanceHeader::executor_governance_header(),
header: GovernanceHeader::executor_governance_header(),
instructions: vec![],
}
.try_to_vec()?;
@ -212,7 +213,7 @@ fn main() -> Result<()> {
}
Action::GetTestPayload {} => {
let payload = ExecutorPayload {
header: GovernanceHeader::executor_governance_header(),
header: GovernanceHeader::executor_governance_header(),
instructions: vec![],
}
.try_to_vec()?;
@ -239,7 +240,7 @@ fn main() -> Result<()> {
instruction.accounts[2].is_signer = true; // Require signature of new authority for safety
println!("New authority : {:}", instruction.accounts[2].pubkey);
let payload = ExecutorPayload {
header: GovernanceHeader::executor_governance_header(),
header: GovernanceHeader::executor_governance_header(),
instructions: vec![InstructionData::from(&instruction)],
}
.try_to_vec()?;
@ -261,7 +262,7 @@ fn main() -> Result<()> {
instruction.accounts[3].pubkey
);
let payload = ExecutorPayload {
header: GovernanceHeader::executor_governance_header(),
header: GovernanceHeader::executor_governance_header(),
instructions: vec![InstructionData::from(&instruction)],
}
.try_to_vec()?;
@ -310,8 +311,8 @@ pub fn get_execute_instruction(
.0;
account_metas.push(AccountMeta {
pubkey: executor_key,
is_signer: false,
pubkey: executor_key,
is_signer: false,
is_writable: true,
});
@ -319,8 +320,8 @@ pub fn get_execute_instruction(
for instruction in executor_payload.instructions {
// Push program_id
account_metas.push(AccountMeta {
pubkey: instruction.program_id,
is_signer: false,
pubkey: instruction.program_id,
is_signer: false,
is_writable: false,
});
// Push other accounts
@ -333,7 +334,7 @@ pub fn get_execute_instruction(
Ok(Instruction {
program_id: ID,
accounts: account_metas,
data: remote_executor::instruction::ExecutePostedVaa.data(),
accounts: account_metas,
data: remote_executor::instruction::ExecutePostedVaa.data(),
})
}

View File

@ -1,19 +1,21 @@
#![deny(warnings)]
#![allow(clippy::result_large_err)]
use anchor_lang::{
prelude::*,
solana_program::borsh::get_packed_len,
system_program,
};
use error::ExecutorError;
use state::{
claim_record::ClaimRecord,
posted_vaa::AnchorVaa,
};
use wormhole::Chain::{
self,
Solana,
use {
anchor_lang::{
prelude::*,
solana_program::borsh::get_packed_len,
system_program,
},
error::ExecutorError,
state::{
claim_record::ClaimRecord,
posted_vaa::AnchorVaa,
},
wormhole::Chain::{
self,
Solana,
},
};
mod error;
@ -27,15 +29,15 @@ declare_id!("exe6S3AxPVNmy46L4Nj6HrnnAVQUhwyYzMSNcnRn3qq");
#[program]
pub mod remote_executor {
use anchor_lang::solana_program::{
instruction::Instruction,
program::invoke_signed,
use {
super::*,
crate::state::governance_payload::ExecutorPayload,
anchor_lang::solana_program::{
instruction::Instruction,
program::invoke_signed,
},
};
use crate::state::governance_payload::ExecutorPayload;
use super::*;
pub fn execute_posted_vaa(ctx: Context<ExecutePostedVaa>) -> Result<()> {
let posted_vaa = &ctx.accounts.posted_vaa;
let claim_record = &mut ctx.accounts.claim_record;
@ -71,12 +73,12 @@ pub const CLAIM_RECORD_SEED: &str = "CLAIM_RECORD";
#[derive(Accounts)]
pub struct ExecutePostedVaa<'info> {
#[account(mut)]
pub payer: Signer<'info>,
pub payer: Signer<'info>,
#[account(constraint = Chain::from(posted_vaa.emitter_chain) == Solana @ ExecutorError::EmitterChainNotSolana, constraint = posted_vaa.sequence > claim_record.sequence @ExecutorError::NonIncreasingSequence, constraint = (&posted_vaa.magic == b"vaa" || &posted_vaa.magic == b"msg" || &posted_vaa.magic == b"msu") @ExecutorError::PostedVaaHeaderWrongMagicNumber )]
pub posted_vaa: Account<'info, AnchorVaa>,
pub posted_vaa: Account<'info, AnchorVaa>,
/// The reason claim_record has different seeds than executor_key is that executor key might need to pay in the CPI, so we want it to be a native wallet
#[account(init_if_needed, space = 8 + get_packed_len::<ClaimRecord>(), payer=payer, seeds = [CLAIM_RECORD_SEED.as_bytes(), &posted_vaa.emitter_address], bump)]
pub claim_record: Account<'info, ClaimRecord>,
pub claim_record: Account<'info, ClaimRecord>,
pub system_program: Program<'info, System>,
// Additional accounts passed to the instruction will be passed down to the CPIs. Very importantly executor_key needs to be passed as it will be the signer of the CPIs.
// Below is the "anchor specification" of that account

View File

@ -1,18 +1,18 @@
use std::{
io::ErrorKind,
mem::size_of,
ops::Deref,
use {
crate::error::ExecutorError,
anchor_lang::{
prelude::*,
solana_program::instruction::Instruction,
},
boolinator::Boolinator,
std::{
io::ErrorKind,
mem::size_of,
ops::Deref,
},
wormhole::Chain,
};
use anchor_lang::{
prelude::*,
solana_program::instruction::Instruction,
};
use boolinator::Boolinator;
use wormhole::Chain;
use crate::error::ExecutorError;
pub const MAGIC_NUMBER: u32 = 0x4d475450; // Reverse order of the solidity contract because borsh uses little endian numbers (the solidity contract uses 0x5054474d)
#[derive(AnchorDeserialize, AnchorSerialize, Debug, PartialEq, Eq)]
@ -41,9 +41,9 @@ pub enum Action {
#[derive(AnchorDeserialize, AnchorSerialize, Eq, PartialEq, Debug)]
pub struct GovernanceHeader {
pub magic_number: u32,
pub module: Module,
pub action: Action,
pub chain: BigEndianU16,
pub module: Module,
pub action: Action,
pub chain: BigEndianU16,
}
impl GovernanceHeader {
@ -51,9 +51,9 @@ impl GovernanceHeader {
pub fn executor_governance_header() -> Self {
Self {
magic_number: MAGIC_NUMBER,
module: Module::Executor,
action: Action::ExecutePostedVaa,
chain: BigEndianU16 {
module: Module::Executor,
action: Action::ExecutePostedVaa,
chain: BigEndianU16 {
value: Chain::Pythnet.try_into().unwrap(),
},
}
@ -100,18 +100,18 @@ pub struct InstructionData {
/// Pubkey of the instruction processor that executes this instruction
pub program_id: Pubkey,
/// Metadata for what accounts should be passed to the instruction processor
pub accounts: Vec<AccountMetaData>,
pub accounts: Vec<AccountMetaData>,
/// Opaque data passed to the instruction processor
pub data: Vec<u8>,
pub data: Vec<u8>,
}
/// Account metadata used to define Instructions
#[derive(Clone, Debug, PartialEq, Eq, AnchorDeserialize, AnchorSerialize)]
pub struct AccountMetaData {
/// An account's public key
pub pubkey: Pubkey,
pub pubkey: Pubkey,
/// True if an Instruction requires a Transaction signature matching `pubkey`.
pub is_signer: bool,
pub is_signer: bool,
/// True if the `pubkey` can be loaded as a read-write account.
pub is_writable: bool,
}
@ -120,16 +120,16 @@ impl From<&InstructionData> for Instruction {
fn from(instruction: &InstructionData) -> Self {
Instruction {
program_id: instruction.program_id,
accounts: instruction
accounts: instruction
.accounts
.iter()
.map(|a| AccountMeta {
pubkey: a.pubkey,
is_signer: a.is_signer,
pubkey: a.pubkey,
is_signer: a.is_signer,
is_writable: a.is_writable,
})
.collect(),
data: instruction.data.clone(),
data: instruction.data.clone(),
}
}
}
@ -138,16 +138,16 @@ impl From<&Instruction> for InstructionData {
fn from(instruction: &Instruction) -> Self {
InstructionData {
program_id: instruction.program_id,
accounts: instruction
accounts: instruction
.accounts
.iter()
.map(|a| AccountMetaData {
pubkey: a.pubkey,
is_signer: a.is_signer,
pubkey: a.pubkey,
is_signer: a.is_signer,
is_writable: a.is_writable,
})
.collect(),
data: instruction.data.clone(),
data: instruction.data.clone(),
}
}
}
@ -170,24 +170,25 @@ impl ExecutorPayload {
#[cfg(test)]
pub mod tests {
use crate::{
error,
error::ExecutorError,
state::governance_payload::InstructionData,
};
use super::ExecutorPayload;
use anchor_lang::{
prelude::Pubkey,
AnchorDeserialize,
AnchorSerialize,
use {
super::ExecutorPayload,
crate::{
error,
error::ExecutorError,
state::governance_payload::InstructionData,
},
anchor_lang::{
prelude::Pubkey,
AnchorDeserialize,
AnchorSerialize,
},
};
#[test]
fn test_check_deserialization_serialization() {
// No instructions
let payload = ExecutorPayload {
header: super::GovernanceHeader::executor_governance_header(),
header: super::GovernanceHeader::executor_governance_header(),
instructions: vec![],
};

View File

@ -1,10 +1,12 @@
use anchor_lang::prelude::*;
use std::{
io::Write,
ops::Deref,
str::FromStr,
use {
anchor_lang::prelude::*,
std::{
io::Write,
ops::Deref,
str::FromStr,
},
wormhole_solana::VAA,
};
use wormhole_solana::VAA;
// The current chain's wormhole bridge owns the VAA accounts
impl Owner for AnchorVaa {
@ -50,5 +52,5 @@ impl Deref for AnchorVaa {
#[derive(Clone, AnchorDeserialize, AnchorSerialize)]
pub struct AnchorVaa {
pub magic: [u8; 3],
pub vaa: VAA,
pub vaa: VAA,
}

View File

@ -1,68 +1,69 @@
use anchor_lang::{
prelude::{
AccountMeta,
ProgramError,
Pubkey,
Rent,
UpgradeableLoaderState,
},
solana_program::hash::Hash,
AccountDeserialize,
AnchorDeserialize,
AnchorSerialize,
InstructionData as AnchorInstructionData,
Key,
Owner,
ToAccountMetas,
};
use solana_program_test::{
find_file,
read_file,
BanksClient,
BanksClientError,
ProgramTest,
ProgramTestBanksClientExt,
};
use solana_sdk::{
account::Account,
bpf_loader_upgradeable,
instruction::{
Instruction,
InstructionError,
},
signature::Keypair,
signer::Signer,
stake_history::Epoch,
system_instruction,
transaction::{
Transaction,
TransactionError,
},
};
use std::collections::HashMap;
use wormhole::Chain;
use wormhole_solana::VAA;
use crate::{
error::ExecutorError,
state::{
claim_record::ClaimRecord,
governance_payload::{
ExecutorPayload,
GovernanceHeader,
InstructionData,
use {
crate::{
error::ExecutorError,
state::{
claim_record::ClaimRecord,
governance_payload::{
ExecutorPayload,
GovernanceHeader,
InstructionData,
},
posted_vaa::AnchorVaa,
},
posted_vaa::AnchorVaa,
CLAIM_RECORD_SEED,
EXECUTOR_KEY_SEED,
},
CLAIM_RECORD_SEED,
EXECUTOR_KEY_SEED,
anchor_lang::{
prelude::{
AccountMeta,
ProgramError,
Pubkey,
Rent,
UpgradeableLoaderState,
},
solana_program::hash::Hash,
AccountDeserialize,
AnchorDeserialize,
AnchorSerialize,
InstructionData as AnchorInstructionData,
Key,
Owner,
ToAccountMetas,
},
solana_program_test::{
find_file,
read_file,
BanksClient,
BanksClientError,
ProgramTest,
ProgramTestBanksClientExt,
},
solana_sdk::{
account::Account,
bpf_loader_upgradeable,
instruction::{
Instruction,
InstructionError,
},
signature::Keypair,
signer::Signer,
stake_history::Epoch,
system_instruction,
transaction::{
Transaction,
TransactionError,
},
},
std::collections::HashMap,
wormhole::Chain,
wormhole_solana::VAA,
};
/// Bench for the tests, the goal of this struct is to be able to setup solana accounts before starting the local validator
pub struct ExecutorBench {
program_test: ProgramTest,
program_id: Pubkey,
seqno: HashMap<Pubkey, u64>,
program_id: Pubkey,
seqno: HashMap<Pubkey, u64>,
}
/// When passed to `add_vaa_account` modify the posted vaa in a way that makes the vaa invalid
@ -94,7 +95,7 @@ impl ExecutorBench {
programdata_address: programdata_key,
};
let programdata_deserialized = UpgradeableLoaderState::ProgramData {
slot: 1,
slot: 1,
upgrade_authority_address: Some(upgrade_authority_keypair.pubkey()),
};
@ -105,16 +106,16 @@ impl ExecutorBench {
programdata_vec.append(&mut bpf_data);
let program_account = Account {
lamports: Rent::default().minimum_balance(program_vec.len()),
data: program_vec,
owner: bpf_loader_upgradeable::ID,
lamports: Rent::default().minimum_balance(program_vec.len()),
data: program_vec,
owner: bpf_loader_upgradeable::ID,
executable: true,
rent_epoch: Epoch::default(),
};
let programdata_account = Account {
lamports: Rent::default().minimum_balance(programdata_vec.len()),
data: programdata_vec,
owner: bpf_loader_upgradeable::ID,
lamports: Rent::default().minimum_balance(programdata_vec.len()),
data: programdata_vec,
owner: bpf_loader_upgradeable::ID,
executable: false,
rent_epoch: Epoch::default(),
};
@ -166,7 +167,7 @@ impl ExecutorBench {
};
let payload = ExecutorPayload {
header: GovernanceHeader::executor_governance_header(),
header: GovernanceHeader::executor_governance_header(),
instructions: instructions
.iter()
.map(|x| InstructionData::from(x))
@ -177,7 +178,7 @@ impl ExecutorBench {
let vaa = AnchorVaa {
magic: *vaa_magic,
vaa: VAA {
vaa: VAA {
vaa_version: 0,
consistency_level: 0,
vaa_time: 0,
@ -232,10 +233,10 @@ impl ExecutorBench {
}
}
pub struct ExecutorSimulator {
banks_client: BanksClient,
payer: Keypair,
banks_client: BanksClient,
payer: Keypair,
last_blockhash: Hash,
program_id: Pubkey,
program_id: Pubkey,
}
/// When passed to execute_posted_vaa, try to impersonate some of the accounts
@ -333,8 +334,8 @@ impl ExecutorSimulator {
// We need to add `executor_key` to the list of accounts
account_metas.push(AccountMeta {
pubkey: executor_key,
is_signer: false,
pubkey: executor_key,
is_signer: false,
is_writable: true,
});
@ -342,8 +343,8 @@ impl ExecutorSimulator {
for instruction in executor_payload.instructions {
// Push program_id
account_metas.push(AccountMeta {
pubkey: instruction.program_id,
is_signer: false,
pubkey: instruction.program_id,
is_signer: false,
is_writable: false,
});
// Push other accounts
@ -356,8 +357,8 @@ impl ExecutorSimulator {
let instruction = Instruction {
program_id: self.program_id,
accounts: account_metas,
data: crate::instruction::ExecutePostedVaa.data(),
accounts: account_metas,
data: crate::instruction::ExecutePostedVaa.data(),
};
self.process_ix(instruction, signers).await

View File

@ -1,21 +1,22 @@
use crate::error::ExecutorError;
use super::executor_simulator::{
ExecutorAttack,
ExecutorBench,
VaaAttack,
};
use anchor_lang::prelude::{
ErrorCode,
ProgramError,
Pubkey,
Rent,
};
use solana_sdk::{
instruction::InstructionError,
native_token::LAMPORTS_PER_SOL,
system_instruction::transfer,
transaction::TransactionError,
use {
super::executor_simulator::{
ExecutorAttack,
ExecutorBench,
VaaAttack,
},
crate::error::ExecutorError,
anchor_lang::prelude::{
ErrorCode,
ProgramError,
Pubkey,
Rent,
},
solana_sdk::{
instruction::InstructionError,
native_token::LAMPORTS_PER_SOL,
system_instruction::transfer,
transaction::TransactionError,
},
};
#[tokio::test]

View File

@ -1,28 +1,29 @@
use crate::{
error::ExecutorError,
tests::executor_simulator::{
ExecutorAttack,
VaaAttack,
use {
super::executor_simulator::ExecutorBench,
crate::{
error::ExecutorError,
tests::executor_simulator::{
ExecutorAttack,
VaaAttack,
},
},
};
use super::executor_simulator::ExecutorBench;
use anchor_lang::{
prelude::{
Pubkey,
Rent,
anchor_lang::{
prelude::{
Pubkey,
Rent,
},
solana_program::{
system_instruction::create_account,
system_program,
},
},
solana_program::{
system_instruction::create_account,
system_program,
solana_sdk::{
native_token::LAMPORTS_PER_SOL,
signature::Keypair,
signer::Signer,
system_instruction::transfer,
},
};
use solana_sdk::{
native_token::LAMPORTS_PER_SOL,
signature::Keypair,
signer::Signer,
system_instruction::transfer,
};
#[tokio::test]
/// This test file tests that the executor can :

View File

@ -1,11 +0,0 @@
# Merge similar crates together to avoid multiple use statements.
imports_granularity = "Crate"
# Consistency in formatting makes tool based searching/editing better.
empty_item_single_line = false
# Easier editing when arbitrary mixed use statements do not collapse.
imports_layout = "Vertical"
# Default rustfmt formatting of match arms with branches is awful.
match_arm_leading_pipes = "Preserve"

17
rustfmt.toml Normal file
View File

@ -0,0 +1,17 @@
# Merge all imports into a clean vertical list of module imports.
imports_granularity = "One"
group_imports = "One"
imports_layout = "Vertical"
# Better grep-ability.
empty_item_single_line = false
# Consistent pipe layout.
match_arm_leading_pipes = "Preserve"
# Align Fields
enum_discrim_align_threshold = 80
struct_field_align_threshold = 80
# Allow up to two blank lines for visual grouping.
blank_lines_upper_bound = 2

View File

@ -1,39 +1,38 @@
use std::{
collections::{
HashMap,
HashSet,
use {
crate::BatchState,
log::info,
serde::{
de::Error,
Deserialize,
Deserializer,
Serialize,
Serializer,
},
solana_program::pubkey::Pubkey,
std::{
collections::{
HashMap,
HashSet,
},
iter,
str::FromStr,
},
iter,
str::FromStr,
};
use log::info;
use serde::{
de::Error,
Deserialize,
Deserializer,
Serialize,
Serializer,
};
use solana_program::pubkey::Pubkey;
use crate::BatchState;
/// Pyth2wormhole config specific to attestation requests
#[derive(Clone, Debug, Hash, Deserialize, Serialize, PartialEq)]
pub struct AttestationConfig {
#[serde(default = "default_min_msg_reuse_interval_ms")]
pub min_msg_reuse_interval_ms: u64,
pub min_msg_reuse_interval_ms: u64,
#[serde(default = "default_max_msg_accounts")]
pub max_msg_accounts: u64,
pub max_msg_accounts: u64,
/// Optionally, we take a mapping account to add remaining symbols from a Pyth deployments. These symbols are processed under attestation conditions for the `default` symbol group.
#[serde(
deserialize_with = "opt_pubkey_string_de",
serialize_with = "opt_pubkey_string_ser",
default // Uses Option::default() which is None
)]
pub mapping_addr: Option<Pubkey>,
pub mapping_addr: Option<Pubkey>,
/// The known symbol list will be reloaded based off this
/// interval, to account for mapping changes. Note: This interval
/// will only work if the mapping address is defined. Whenever
@ -45,8 +44,8 @@ pub struct AttestationConfig {
pub mapping_reload_interval_mins: u64,
#[serde(default = "default_min_rpc_interval_ms")]
/// Rate-limiting minimum delay between RPC requests in milliseconds"
pub min_rpc_interval_ms: u64,
pub symbol_groups: Vec<SymbolGroup>,
pub min_rpc_interval_ms: u64,
pub symbol_groups: Vec<SymbolGroup>,
}
impl AttestationConfig {
@ -75,9 +74,9 @@ impl AttestationConfig {
.map(|(prod, prices)| iter::zip(iter::repeat(prod), prices)) // Convert to iterator over flat (prod, price) tuples
.flatten() // Flatten the tuple iterators
.map(|(prod, price)| P2WSymbol {
name: None,
name: None,
product_addr: prod,
price_addr: price,
price_addr: price,
})
.collect::<Vec<P2WSymbol>>();
@ -129,7 +128,7 @@ pub struct SymbolGroup {
pub group_name: String,
/// Attestation conditions applied to all symbols in this group
pub conditions: AttestationConditions,
pub symbols: Vec<P2WSymbol>,
pub symbols: Vec<P2WSymbol>,
}
pub const fn default_max_msg_accounts() -> u64 {
@ -202,9 +201,9 @@ impl AttestationConditions {
impl Default for AttestationConditions {
fn default() -> Self {
Self {
min_interval_secs: default_min_interval_secs(),
max_batch_jobs: default_max_batch_jobs(),
price_changed_bps: None,
min_interval_secs: default_min_interval_secs(),
max_batch_jobs: default_max_batch_jobs(),
price_changed_bps: None,
publish_time_min_delta_secs: None,
}
}
@ -225,7 +224,7 @@ pub struct P2WSymbol {
deserialize_with = "pubkey_string_de",
serialize_with = "pubkey_string_ser"
)]
pub price_addr: Pubkey,
pub price_addr: Pubkey,
}
impl ToString for P2WSymbol {
@ -275,9 +274,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use solitaire::ErrBox;
use {
super::*,
solitaire::ErrBox,
};
#[test]
fn test_sanity() -> Result<(), ErrBox> {
@ -287,7 +287,7 @@ mod tests {
min_interval_secs: 5,
..Default::default()
},
symbols: vec![
symbols: vec![
P2WSymbol {
name: Some("ETHUSD".to_owned()),
..Default::default()
@ -305,7 +305,7 @@ mod tests {
min_interval_secs: 200,
..Default::default()
},
symbols: vec![
symbols: vec![
P2WSymbol {
name: Some("CNYAUD".to_owned()),
..Default::default()
@ -318,12 +318,12 @@ mod tests {
};
let cfg = AttestationConfig {
min_msg_reuse_interval_ms: 1000,
max_msg_accounts: 100_000,
min_rpc_interval_ms: 2123,
mapping_addr: None,
min_msg_reuse_interval_ms: 1000,
max_msg_accounts: 100_000,
min_rpc_interval_ms: 2123,
mapping_addr: None,
mapping_reload_interval_mins: 42,
symbol_groups: vec![fastbois, slowbois],
symbol_groups: vec![fastbois, slowbois],
};
let serialized = serde_yaml::to_string(&cfg)?;
@ -338,12 +338,12 @@ mod tests {
#[test]
fn test_add_symbols_works() -> Result<(), ErrBox> {
let empty_config = AttestationConfig {
min_msg_reuse_interval_ms: 1000,
max_msg_accounts: 100,
min_rpc_interval_ms: 42422,
mapping_addr: None,
min_msg_reuse_interval_ms: 1000,
max_msg_accounts: 100,
min_rpc_interval_ms: 42422,
mapping_addr: None,
mapping_reload_interval_mins: 42,
symbol_groups: vec![],
symbol_groups: vec![],
};
let mock_new_symbols = (0..255)

View File

@ -1,30 +1,29 @@
use log::{
debug,
warn,
};
use solana_client::nonblocking::rpc_client::RpcClient;
use pyth_sdk_solana::state::PriceAccount;
use std::time::{
Duration,
Instant,
};
use crate::{
AttestationConditions,
P2WSymbol,
use {
crate::{
AttestationConditions,
P2WSymbol,
},
log::{
debug,
warn,
},
pyth_sdk_solana::state::PriceAccount,
solana_client::nonblocking::rpc_client::RpcClient,
std::time::{
Duration,
Instant,
},
};
/// Runtime representation of a batch. It refers to the original group
/// from the config.
#[derive(Debug)]
pub struct BatchState {
pub group_name: String,
pub symbols: Vec<P2WSymbol>,
pub group_name: String,
pub symbols: Vec<P2WSymbol>,
pub last_known_symbol_states: Vec<Option<PriceAccount>>,
pub conditions: AttestationConditions,
pub last_job_finished_at: Instant,
pub conditions: AttestationConditions,
pub last_job_finished_at: Instant,
}
impl<'a> BatchState {

View File

@ -1,12 +1,13 @@
//! CLI options
use solana_program::pubkey::Pubkey;
use solana_sdk::commitment_config::CommitmentConfig;
use std::path::PathBuf;
use clap::{
Parser,
Subcommand,
use {
clap::{
Parser,
Subcommand,
},
solana_program::pubkey::Pubkey,
solana_sdk::commitment_config::CommitmentConfig,
std::path::PathBuf,
};
#[derive(Parser)]
@ -20,15 +21,15 @@ pub struct Cli {
help = "Identity JSON file for the entity meant to cover transaction costs",
default_value = "~/.config/solana/id.json"
)]
pub payer: String,
pub payer: String,
#[clap(short, long, default_value = "http://localhost:8899")]
pub rpc_url: String,
pub rpc_url: String,
#[clap(long, default_value = "confirmed")]
pub commitment: CommitmentConfig,
#[clap(long)]
pub p2w_addr: Pubkey,
pub p2w_addr: Pubkey,
#[clap(subcommand)]
pub action: Action,
pub action: Action,
}
#[derive(Subcommand)]
@ -37,16 +38,16 @@ pub enum Action {
Init {
/// The bridge program account
#[clap(short = 'w', long = "wh-prog")]
wh_prog: Pubkey,
wh_prog: Pubkey,
#[clap(short = 'o', long = "owner")]
owner_addr: Pubkey,
owner_addr: Pubkey,
#[clap(short = 'p', long = "pyth-owner")]
pyth_owner_addr: Pubkey,
/// Option<> makes sure not specifying this flag does not imply "false"
#[clap(long = "is-active")]
is_active: Option<bool>,
is_active: Option<bool>,
#[clap(long = "ops-owner")]
ops_owner_addr: Option<Pubkey>,
ops_owner_addr: Option<Pubkey>,
},
#[clap(
about = "Use an existing pyth2wormhole program to attest product price information to another chain"
@ -54,14 +55,14 @@ pub enum Action {
// Note: defaults target SOL mainnet-beta conditions at implementation time
Attest {
#[clap(short = 'f', long = "--config", help = "Attestation YAML config")]
attestation_cfg: PathBuf,
attestation_cfg: PathBuf,
#[clap(
short = 'n',
long = "--n-retries",
help = "How many times to retry send_transaction() on each batch before flagging a failure. Only active outside daemon mode",
default_value = "5"
)]
n_retries: usize,
n_retries: usize,
#[clap(
short = 'i',
long = "--retry-interval",
@ -69,13 +70,13 @@ pub enum Action {
retries. Only active outside daemon mode",
default_value = "5"
)]
retry_interval_secs: u64,
retry_interval_secs: u64,
#[clap(
short = 'd',
long = "--daemon",
help = "Do not stop attesting. In this mode, this program will behave more like a daemon and continuously attest the specified symbols."
)]
daemon: bool,
daemon: bool,
#[clap(
short = 't',
long = "--timeout",
@ -94,20 +95,20 @@ pub enum Action {
default_value = "~/.config/solana/id.json",
help = "Keypair file for the current config owner"
)]
owner: String,
owner: String,
/// New owner to set
#[clap(long = "new-owner")]
new_owner_addr: Option<Pubkey>,
new_owner_addr: Option<Pubkey>,
#[clap(long = "new-wh-prog")]
new_wh_prog: Option<Pubkey>,
new_wh_prog: Option<Pubkey>,
#[clap(long = "new-pyth-owner")]
new_pyth_owner_addr: Option<Pubkey>,
#[clap(long = "is-active")]
is_active: Option<bool>,
is_active: Option<bool>,
#[clap(long = "ops-owner")]
ops_owner_addr: Option<Pubkey>,
ops_owner_addr: Option<Pubkey>,
#[clap(long = "remove-ops-owner", conflicts_with = "ops-owner-addr")]
remove_ops_owner: bool,
remove_ops_owner: bool,
},
#[clap(
about = "Migrate existing pyth2wormhole program settings to a newer format version. Client version must match the deployed contract."
@ -131,7 +132,7 @@ pub enum Action {
default_value = "~/.config/solana/id.json",
help = "Keypair file for the current ops owner"
)]
ops_owner: String,
ops_owner: String,
#[clap(
index = 1,
possible_values = ["true", "false"],

View File

@ -8,9 +8,9 @@ pub struct Config {
pub struct P2WSymbol {
/// Optional human-readable name, never used on-chain; makes
/// attester logs and the config easier to understand
name: Option<String>,
name: Option<String>,
product: Pubkey,
price: Pubkey,
price: Pubkey,
}
#[testmod]

View File

@ -3,91 +3,88 @@ pub mod batch_state;
pub mod message;
pub mod util;
use borsh::{
BorshDeserialize,
BorshSerialize,
};
use log::{
debug,
trace,
warn,
};
use pyth_sdk_solana::state::{
load_mapping_account,
load_price_account,
load_product_account,
};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_program::{
hash::Hash,
instruction::{
AccountMeta,
Instruction,
pub use {
attestation_cfg::{
AttestationConditions,
AttestationConfig,
P2WSymbol,
},
pubkey::Pubkey,
system_program,
sysvar::{
clock,
rent,
batch_state::BatchState,
message::P2WMessageQueue,
pyth2wormhole::Pyth2WormholeConfig,
util::{
RLMutex,
RLMutexGuard,
},
};
use solana_sdk::{
signer::{
keypair::Keypair,
Signer,
use {
borsh::{
BorshDeserialize,
BorshSerialize,
},
transaction::Transaction,
};
use solitaire::{
processors::seeded::Seeded,
AccountState,
ErrBox,
};
use bridge::{
accounts::{
Bridge,
FeeCollector,
Sequence,
SequenceDerivationData,
bridge::{
accounts::{
Bridge,
FeeCollector,
Sequence,
SequenceDerivationData,
},
types::ConsistencyLevel,
},
types::ConsistencyLevel,
};
use std::collections::{
HashMap,
HashSet,
};
use p2w_sdk::P2WEmitter;
use pyth2wormhole::{
config::{
OldP2WConfigAccount,
P2WConfigAccount,
log::{
debug,
trace,
warn,
},
message::{
P2WMessage,
P2WMessageDrvData,
p2w_sdk::P2WEmitter,
pyth2wormhole::{
config::{
OldP2WConfigAccount,
P2WConfigAccount,
},
message::{
P2WMessage,
P2WMessageDrvData,
},
AttestData,
},
pyth_sdk_solana::state::{
load_mapping_account,
load_price_account,
load_product_account,
},
solana_client::nonblocking::rpc_client::RpcClient,
solana_program::{
hash::Hash,
instruction::{
AccountMeta,
Instruction,
},
pubkey::Pubkey,
system_program,
sysvar::{
clock,
rent,
},
},
solana_sdk::{
signer::{
keypair::Keypair,
Signer,
},
transaction::Transaction,
},
solitaire::{
processors::seeded::Seeded,
AccountState,
ErrBox,
},
std::collections::{
HashMap,
HashSet,
},
AttestData,
};
pub use pyth2wormhole::Pyth2WormholeConfig;
pub use attestation_cfg::{
AttestationConditions,
AttestationConfig,
P2WSymbol,
};
pub use batch_state::BatchState;
pub use util::{
RLMutex,
RLMutexGuard,
};
pub use message::P2WMessageQueue;
/// Future-friendly version of solitaire::ErrBox
pub type ErrBoxSend = Box<dyn std::error::Error + Send + Sync>;
@ -362,8 +359,8 @@ pub fn gen_attest_tx(
AccountMeta::new(
P2WMessage::key(
&P2WMessageDrvData {
id: wh_msg_id,
batch_size: symbols.len() as u16,
id: wh_msg_id,
batch_size: symbols.len() as u16,
message_owner: payer.pubkey(),
},
&p2w_addr,
@ -384,7 +381,7 @@ pub fn gen_attest_tx(
let ix_data = (
pyth2wormhole::instruction::Instruction::Attest,
AttestData {
consistency_level: ConsistencyLevel::Confirmed,
consistency_level: ConsistencyLevel::Confirmed,
message_account_id: wh_msg_id,
},
);

View File

@ -1,67 +1,65 @@
pub mod cli;
use std::{
fs::File,
sync::Arc,
time::{
Duration,
Instant,
use {
clap::Parser,
cli::{
Action,
Cli,
},
futures::future::{
Future,
TryFutureExt,
},
generic_array::GenericArray,
log::{
debug,
error,
info,
warn,
LevelFilter,
},
p2w_sdk::P2WEmitter,
pyth2wormhole::{
attest::P2W_MAX_BATCH_SIZE,
Pyth2WormholeConfig,
},
pyth2wormhole_client::*,
sha3::{
Digest,
Sha3_256,
},
solana_client::{
nonblocking::rpc_client::RpcClient,
rpc_config::RpcTransactionConfig,
},
solana_program::pubkey::Pubkey,
solana_sdk::{
commitment_config::CommitmentConfig,
signature::read_keypair_file,
signer::keypair::Keypair,
},
solana_transaction_status::UiTransactionEncoding,
solitaire::{
processors::seeded::Seeded,
ErrBox,
},
std::{
fs::File,
sync::Arc,
time::{
Duration,
Instant,
},
},
tokio::{
sync::{
Mutex,
Semaphore,
},
task::JoinHandle,
},
};
use clap::Parser;
use futures::future::{
Future,
TryFutureExt,
};
use generic_array::GenericArray;
use log::{
debug,
error,
info,
warn,
LevelFilter,
};
use sha3::{
Digest,
Sha3_256,
};
use solana_client::{
nonblocking::rpc_client::RpcClient,
rpc_config::RpcTransactionConfig,
};
use solana_program::pubkey::Pubkey;
use solana_sdk::{
commitment_config::CommitmentConfig,
signature::read_keypair_file,
signer::keypair::Keypair,
};
use solana_transaction_status::UiTransactionEncoding;
use solitaire::{
processors::seeded::Seeded,
ErrBox,
};
use tokio::{
sync::{
Mutex,
Semaphore,
},
task::JoinHandle,
};
use cli::{
Action,
Cli,
};
use p2w_sdk::P2WEmitter;
use pyth2wormhole::{
attest::P2W_MAX_BATCH_SIZE,
Pyth2WormholeConfig,
};
use pyth2wormhole_client::*;
pub const SEQNO_PREFIX: &'static str = "Program log: Sequence: ";
#[tokio::main(flavor = "multi_thread")]
@ -143,12 +141,12 @@ async fn main() -> Result<(), ErrBox> {
p2w_addr,
read_keypair_file(&*shellexpand::tilde(&owner))?,
Pyth2WormholeConfig {
owner: new_owner_addr.unwrap_or(old_config.owner),
wh_prog: new_wh_prog.unwrap_or(old_config.wh_prog),
pyth_owner: new_pyth_owner_addr.unwrap_or(old_config.pyth_owner),
is_active: is_active.unwrap_or(old_config.is_active),
owner: new_owner_addr.unwrap_or(old_config.owner),
wh_prog: new_wh_prog.unwrap_or(old_config.wh_prog),
pyth_owner: new_pyth_owner_addr.unwrap_or(old_config.pyth_owner),
is_active: is_active.unwrap_or(old_config.is_active),
max_batch_size: P2W_MAX_BATCH_SIZE,
ops_owner: new_ops_owner,
ops_owner: new_ops_owner,
},
latest_blockhash,
)?;
@ -195,8 +193,8 @@ async fn main() -> Result<(), ErrBox> {
// between RPC accesses.
let rpc_cfg = Arc::new(RLMutex::new(
RpcCfg {
url: cli.rpc_url,
timeout: Duration::from_secs(confirmation_timeout_secs),
url: cli.rpc_url,
timeout: Duration::from_secs(confirmation_timeout_secs),
commitment: cli.commitment.clone(),
},
Duration::from_millis(attestation_cfg.min_rpc_interval_ms),
@ -374,8 +372,8 @@ async fn handle_attest_daemon_mode(
#[derive(Clone)]
pub struct RpcCfg {
pub url: String,
pub timeout: Duration,
pub url: String,
pub timeout: Duration,
pub commitment: CommitmentConfig,
}
@ -511,13 +509,13 @@ fn prepare_attestation_sched_jobs(
/// The argument count on attestation_sched_job got out of hand. This
/// helps keep the correct order in check.
pub struct AttestationSchedJobArgs {
pub batch: BatchState,
pub batch_no: usize,
pub batch_count: usize,
pub rpc_cfg: Arc<RLMutex<RpcCfg>>,
pub p2w_addr: Pubkey,
pub config: Pyth2WormholeConfig,
pub payer: Keypair,
pub batch: BatchState,
pub batch_no: usize,
pub batch_count: usize,
pub rpc_cfg: Arc<RLMutex<RpcCfg>>,
pub p2w_addr: Pubkey,
pub config: Pyth2WormholeConfig,
pub payer: Keypair,
pub message_q_mtx: Arc<Mutex<P2WMessageQueue>>,
}
@ -621,17 +619,17 @@ async fn attestation_sched_job(args: AttestationSchedJobArgs) -> Result<(), ErrB
}
pub struct AttestationRetryJobArgs {
pub batch_no: usize,
pub batch_count: usize,
pub group_name: String,
pub symbols: Vec<P2WSymbol>,
pub n_retries: usize,
pub batch_no: usize,
pub batch_count: usize,
pub group_name: String,
pub symbols: Vec<P2WSymbol>,
pub n_retries: usize,
pub retry_interval: Duration,
pub rpc_cfg: Arc<RLMutex<RpcCfg>>,
pub p2w_addr: Pubkey,
pub p2w_config: Pyth2WormholeConfig,
pub payer: Keypair,
pub message_q_mtx: Arc<Mutex<P2WMessageQueue>>,
pub rpc_cfg: Arc<RLMutex<RpcCfg>>,
pub p2w_addr: Pubkey,
pub p2w_config: Pyth2WormholeConfig,
pub payer: Keypair,
pub message_q_mtx: Arc<Mutex<P2WMessageQueue>>,
}
/// A future that cranks a batch up to n_retries times, pausing for
@ -685,14 +683,14 @@ async fn attestation_retry_job(args: AttestationRetryJobArgs) -> Result<(), ErrB
/// Arguments for attestation_job(). This struct rules out same-type
/// ordering errors due to the large argument count
pub struct AttestationJobArgs {
pub rlmtx: Arc<RLMutex<RpcCfg>>,
pub batch_no: usize,
pub batch_count: usize,
pub group_name: String,
pub p2w_addr: Pubkey,
pub config: Pyth2WormholeConfig,
pub payer: Keypair,
pub symbols: Vec<P2WSymbol>,
pub rlmtx: Arc<RLMutex<RpcCfg>>,
pub batch_no: usize,
pub batch_count: usize,
pub group_name: String,
pub p2w_addr: Pubkey,
pub config: Pyth2WormholeConfig,
pub payer: Keypair,
pub symbols: Vec<P2WSymbol>,
pub max_jobs_sema: Arc<Semaphore>,
pub message_q_mtx: Arc<Mutex<P2WMessageQueue>>,
}
@ -743,8 +741,8 @@ async fn attestation_job(args: AttestationJobArgs) -> Result<(), ErrBoxSend> {
.get_transaction_with_config(
&sig,
RpcTransactionConfig {
encoding: Some(UiTransactionEncoding::Json),
commitment: Some(rpc.commitment()),
encoding: Some(UiTransactionEncoding::Json),
commitment: Some(rpc.commitment()),
max_supported_transaction_version: None,
},
)

View File

@ -1,21 +1,22 @@
//! Re-usable message scheme for pyth2wormhole
use log::debug;
use std::{
collections::VecDeque,
time::{
Duration,
Instant,
use {
crate::ErrBoxSend,
log::debug,
std::{
collections::VecDeque,
time::{
Duration,
Instant,
},
},
};
use crate::ErrBoxSend;
/// One of the accounts tracked by the attestation client.
#[derive(Clone, Debug)]
pub struct P2WMessageAccount {
/// Unique ID that lets us derive unique accounts for use on-chain
pub id: u64,
pub id: u64,
/// Last time we've posted a message to wormhole with this account
pub last_used: Instant,
}
@ -24,7 +25,7 @@ pub struct P2WMessageAccount {
#[derive(Clone, Debug)]
pub struct P2WMessageQueue {
/// The tracked accounts. Sorted from oldest to newest, as guaranteed by get_account()
accounts: VecDeque<P2WMessageAccount>,
accounts: VecDeque<P2WMessageAccount>,
/// How much time needs to pass between reuses
grace_period: Duration,
/// A hard cap on how many accounts will be created.
@ -72,13 +73,13 @@ impl P2WMessageQueue {
// Use a new account instead
P2WMessageAccount {
id: self.accounts.len() as u64,
id: self.accounts.len() as u64,
last_used: Instant::now(),
}
}
// Base case: Queue is empty, use a new account
None => P2WMessageAccount {
id: self.accounts.len() as u64,
id: self.accounts.len() as u64,
last_used: Instant::now(),
},
};

View File

@ -1,23 +1,24 @@
use log::trace;
use std::{
ops::{
Deref,
DerefMut,
use {
log::trace,
std::{
ops::{
Deref,
DerefMut,
},
time::{
Duration,
Instant,
},
},
time::{
Duration,
Instant,
tokio::sync::{
Mutex,
MutexGuard,
},
};
use tokio::sync::{
Mutex,
MutexGuard,
};
/// Rate-limited mutex. Ensures there's a period of minimum rl_interval between lock acquisitions
pub struct RLMutex<T> {
mtx: Mutex<RLMutexState<T>>,
mtx: Mutex<RLMutexState<T>>,
rl_interval: Duration,
}
@ -25,7 +26,7 @@ pub struct RLMutex<T> {
pub struct RLMutexState<T> {
/// Helps make sure regular passage of time is subtracted from sleep duration
last_released: Instant,
val: T,
val: T,
}
impl<T> Deref for RLMutexState<T> {

View File

@ -1,12 +1,13 @@
//! Trivial program for mocking other programs easily
use solana_program::{
account_info::AccountInfo,
msg,
program_error::ProgramError,
use {
solana_program::{
account_info::AccountInfo,
msg,
program_error::ProgramError,
},
solana_program_test::*,
solana_sdk::pubkey::Pubkey,
};
use solana_sdk::pubkey::Pubkey;
use solana_program_test::*;
pub fn passthrough_entrypoint(
program_id: &Pubkey,

View File

@ -1,21 +1,21 @@
//! This module contains test fixtures for instantiating plausible
//! Pyth accounts for testing purposes.
use solana_program_test::*;
use solana_sdk::{
account::Account,
pubkey::Pubkey,
rent::Rent,
};
use pyth_client::{
AccKey,
AccountType,
Price,
Product,
MAGIC,
PROD_ATTR_SIZE,
VERSION,
use {
pyth_client::{
AccKey,
AccountType,
Price,
Product,
MAGIC,
PROD_ATTR_SIZE,
VERSION,
},
solana_program_test::*,
solana_sdk::{
account::Account,
pubkey::Pubkey,
rent::Rent,
},
};
/// Create a pair of brand new product/price accounts that point at each other
@ -27,14 +27,14 @@ pub fn add_test_symbol(pt: &mut ProgramTest, owner: &Pubkey) -> (Pubkey, Pubkey)
// Instantiate
let prod = {
Product {
magic: MAGIC,
ver: VERSION,
atype: AccountType::Product as u32,
size: 0,
magic: MAGIC,
ver: VERSION,
atype: AccountType::Product as u32,
size: 0,
px_acc: AccKey {
val: price_id.to_bytes(),
},
attr: [0u8; PROD_ATTR_SIZE],
attr: [0u8; PROD_ATTR_SIZE],
}
};
@ -66,16 +66,16 @@ pub fn add_test_symbol(pt: &mut ProgramTest, owner: &Pubkey) -> (Pubkey, Pubkey)
// Populate the accounts
let mut prod_acc = Account {
lamports: prod_lamports,
data: (*prod_bytes).to_vec(),
owner: owner.clone(),
lamports: prod_lamports,
data: (*prod_bytes).to_vec(),
owner: owner.clone(),
rent_epoch: 0,
executable: false,
};
let mut price_acc = Account {
lamports: price_lamports,
data: (*price_bytes).to_vec(),
owner: owner.clone(),
lamports: price_lamports,
data: (*price_bytes).to_vec(),
owner: owner.clone(),
rent_epoch: 0,
executable: false,
};

View File

@ -1,41 +1,39 @@
pub mod fixtures;
use solana_program_test::*;
use solana_sdk::{
account::Account,
instruction::{
AccountMeta,
Instruction,
use {
bridge::accounts::{
Bridge,
BridgeConfig,
BridgeData,
},
pubkey::Pubkey,
rent::Rent,
signature::Signer,
signer::keypair::Keypair,
transaction::Transaction,
};
use bridge::accounts::{
Bridge,
BridgeConfig,
BridgeData,
};
use pyth2wormhole::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
};
use pyth2wormhole_client as p2wc;
use solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
};
use std::time::Duration;
use fixtures::{
passthrough,
pyth,
fixtures::{
passthrough,
pyth,
},
pyth2wormhole::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
pyth2wormhole_client as p2wc,
solana_program_test::*,
solana_sdk::{
account::Account,
instruction::{
AccountMeta,
Instruction,
},
pubkey::Pubkey,
rent::Rent,
signature::Signer,
signer::keypair::Keypair,
transaction::Transaction,
},
solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
},
std::time::Duration,
};
#[tokio::test]
@ -77,9 +75,9 @@ async fn test_happy_path() -> Result<(), p2wc::ErrBoxSend> {
// Plant a filled config account
let p2w_config_bytes = p2w_config.try_to_vec()?;
let p2w_config_account = Account {
lamports: Rent::default().minimum_balance(p2w_config_bytes.len()),
data: p2w_config_bytes,
owner: p2w_program_id,
lamports: Rent::default().minimum_balance(p2w_config_bytes.len()),
data: p2w_config_bytes,
owner: p2w_program_id,
executable: false,
rent_epoch: 0,
};
@ -91,9 +89,9 @@ async fn test_happy_path() -> Result<(), p2wc::ErrBoxSend> {
// Plant a bridge config
let bridge_config_bytes = bridge_config.try_to_vec()?;
let wh_bridge_config_account = Account {
lamports: Rent::default().minimum_balance(bridge_config_bytes.len()),
data: bridge_config_bytes,
owner: wh_fixture_program_id,
lamports: Rent::default().minimum_balance(bridge_config_bytes.len()),
data: bridge_config_bytes,
owner: wh_fixture_program_id,
executable: false,
rent_epoch: 0,
};
@ -109,9 +107,9 @@ async fn test_happy_path() -> Result<(), p2wc::ErrBoxSend> {
let mut ctx = p2w_test.start_with_context().await;
let symbols = vec![p2wc::P2WSymbol {
name: Some("Mock symbol".to_owned()),
name: Some("Mock symbol".to_owned()),
product_addr: prod_id,
price_addr: price_id,
price_addr: price_id,
}];
let attest_tx = p2wc::gen_attest_tx(

View File

@ -2,45 +2,43 @@
pub mod fixtures;
use solana_program::system_program;
use solana_program_test::*;
use solana_sdk::{
account::Account,
instruction::{
AccountMeta,
Instruction,
use {
bridge::accounts::{
Bridge,
BridgeConfig,
BridgeData,
},
fixtures::{
passthrough,
pyth,
},
log::info,
pyth2wormhole::config::{
OldP2WConfigAccount,
OldPyth2WormholeConfig,
P2WConfigAccount,
Pyth2WormholeConfig,
},
pyth2wormhole_client as p2wc,
solana_program::system_program,
solana_program_test::*,
solana_sdk::{
account::Account,
instruction::{
AccountMeta,
Instruction,
},
pubkey::Pubkey,
rent::Rent,
signature::Signer,
signer::keypair::Keypair,
transaction::Transaction,
},
solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
},
pubkey::Pubkey,
rent::Rent,
signature::Signer,
signer::keypair::Keypair,
transaction::Transaction,
};
use bridge::accounts::{
Bridge,
BridgeConfig,
BridgeData,
};
use log::info;
use pyth2wormhole::config::{
OldP2WConfigAccount,
OldPyth2WormholeConfig,
P2WConfigAccount,
Pyth2WormholeConfig,
};
use pyth2wormhole_client as p2wc;
use solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
};
use fixtures::{
passthrough,
pyth,
};
#[tokio::test]
@ -75,9 +73,9 @@ async fn test_migrate_works() -> Result<(), solitaire::ErrBox> {
// Plant filled config accounts
let old_p2w_config_bytes = old_p2w_config.try_to_vec()?;
let old_p2w_config_account = Account {
lamports: Rent::default().minimum_balance(old_p2w_config_bytes.len()),
data: old_p2w_config_bytes,
owner: p2w_program_id,
lamports: Rent::default().minimum_balance(old_p2w_config_bytes.len()),
data: old_p2w_config_bytes,
owner: p2w_program_id,
executable: false,
rent_epoch: 0,
};
@ -147,9 +145,9 @@ async fn test_migrate_already_migrated() -> Result<(), solitaire::ErrBox> {
// Plant filled config accounts
let old_p2w_config_bytes = old_p2w_config.try_to_vec()?;
let old_p2w_config_account = Account {
lamports: Rent::default().minimum_balance(old_p2w_config_bytes.len()),
data: old_p2w_config_bytes,
owner: p2w_program_id,
lamports: Rent::default().minimum_balance(old_p2w_config_bytes.len()),
data: old_p2w_config_bytes,
owner: p2w_program_id,
executable: false,
rent_epoch: 0,
};
@ -157,9 +155,9 @@ async fn test_migrate_already_migrated() -> Result<(), solitaire::ErrBox> {
let new_p2w_config_bytes = new_p2w_config.try_to_vec()?;
let new_p2w_config_account = Account {
lamports: Rent::default().minimum_balance(new_p2w_config_bytes.len()),
data: new_p2w_config_bytes,
owner: p2w_program_id,
lamports: Rent::default().minimum_balance(new_p2w_config_bytes.len()),
data: new_p2w_config_bytes,
owner: p2w_program_id,
executable: false,
rent_epoch: 0,
};

View File

@ -1,25 +1,26 @@
pub mod fixtures;
use borsh::BorshDeserialize;
use p2wc::get_config_account;
use solana_program_test::*;
use solana_sdk::{
account::Account,
pubkey::Pubkey,
rent::Rent,
signature::Signer,
signer::keypair::Keypair,
};
use pyth2wormhole::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
};
use pyth2wormhole_client as p2wc;
use solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
use {
borsh::BorshDeserialize,
p2wc::get_config_account,
pyth2wormhole::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
pyth2wormhole_client as p2wc,
solana_program_test::*,
solana_sdk::{
account::Account,
pubkey::Pubkey,
rent::Rent,
signature::Signer,
signer::keypair::Keypair,
},
solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
},
};
fn clone_keypair(keypair: &Keypair) -> Keypair {
@ -58,9 +59,9 @@ async fn test_setting_is_active_works() -> Result<(), p2wc::ErrBoxSend> {
// Plant a filled config account
let p2w_config_bytes = p2w_config.try_to_vec()?;
let p2w_config_account = Account {
lamports: Rent::default().minimum_balance(p2w_config_bytes.len()),
data: p2w_config_bytes,
owner: p2w_program_id,
lamports: Rent::default().minimum_balance(p2w_config_bytes.len()),
data: p2w_config_bytes,
owner: p2w_program_id,
executable: false,
rent_epoch: 0,
};
@ -145,12 +146,12 @@ async fn test_setting_is_active_does_not_work_without_ops_owner() -> Result<(),
// On-chain state
let p2w_config = Pyth2WormholeConfig {
owner: p2w_owner,
wh_prog: wh_fixture_program_id,
owner: p2w_owner,
wh_prog: wh_fixture_program_id,
max_batch_size: pyth2wormhole::attest::P2W_MAX_BATCH_SIZE,
pyth_owner: pyth_owner.pubkey(),
is_active: true,
ops_owner: None,
pyth_owner: pyth_owner.pubkey(),
is_active: true,
ops_owner: None,
};
// Populate test environment
@ -163,9 +164,9 @@ async fn test_setting_is_active_does_not_work_without_ops_owner() -> Result<(),
// Plant a filled config account
let p2w_config_bytes = p2w_config.try_to_vec()?;
let p2w_config_account = Account {
lamports: Rent::default().minimum_balance(p2w_config_bytes.len()),
data: p2w_config_bytes,
owner: p2w_program_id,
lamports: Rent::default().minimum_balance(p2w_config_bytes.len()),
data: p2w_config_bytes,
owner: p2w_program_id,
executable: false,
rent_epoch: 0,
};

View File

@ -1,11 +1,12 @@
//! CLI options
use clap::{
Parser,
Subcommand,
use {
clap::{
Parser,
Subcommand,
},
solana_sdk::pubkey::Pubkey,
};
use solana_sdk::pubkey::Pubkey;
#[derive(Parser, Debug)]
#[clap(
about = "A cli for the remote executor",
@ -21,33 +22,33 @@ pub enum Action {
#[clap(about = "Get set upgrade authority payload for squads-cli")]
GetSetConfig {
#[clap(long, help = "Program id")]
program_id: Pubkey,
program_id: Pubkey,
#[clap(long, help = "Current owner")]
owner: Pubkey,
owner: Pubkey,
#[clap(long, help = "Payer")]
payer: Pubkey,
payer: Pubkey,
#[clap(long, help = "Config : New owner")]
new_owner: Pubkey,
new_owner: Pubkey,
#[clap(long, help = "Config : Wormhole program id")]
wormhole: Pubkey,
wormhole: Pubkey,
#[clap(long, help = "Config : Pyth program id")]
pyth_owner: Pubkey,
pyth_owner: Pubkey,
#[clap(long, help = "Config : Max batch size")]
max_batch_size: u16,
#[clap(long, help = "Config : Is active")]
is_active: bool,
is_active: bool,
#[clap(long, help = "Config : Ops owner")]
ops_owner: Option<Pubkey>,
ops_owner: Option<Pubkey>,
},
#[clap(about = "Get upgrade program payload for squads-cli")]
GetSetIsActive {
#[clap(long, help = "Program id")]
program_id: Pubkey,
#[clap(long, help = "Current ops owner")]
ops_owner: Pubkey,
ops_owner: Pubkey,
#[clap(long, help = "Payer")]
payer: Pubkey,
payer: Pubkey,
#[clap(long, help = "Config : Is active")]
is_active: bool,
is_active: bool,
},
}

View File

@ -1,20 +1,21 @@
use anyhow::Result;
use clap::Parser;
use cli::{
Action,
Cli,
};
use pyth2wormhole_client::{
get_set_config_ix,
Pyth2WormholeConfig,
};
use borsh::BorshSerialize;
use pyth2wormhole_client::get_set_is_active_ix;
use remote_executor::state::governance_payload::{
ExecutorPayload,
GovernanceHeader,
InstructionData,
use {
anyhow::Result,
borsh::BorshSerialize,
clap::Parser,
cli::{
Action,
Cli,
},
pyth2wormhole_client::{
get_set_config_ix,
get_set_is_active_ix,
Pyth2WormholeConfig,
},
remote_executor::state::governance_payload::{
ExecutorPayload,
GovernanceHeader,
InstructionData,
},
};
mod cli;
@ -43,7 +44,7 @@ fn main() -> Result<()> {
};
let ix = get_set_config_ix(&program_id, &owner, &payer, new_config).unwrap();
let payload = ExecutorPayload {
header: GovernanceHeader::executor_governance_header(),
header: GovernanceHeader::executor_governance_header(),
instructions: vec![InstructionData::from(&ix)],
}
.try_to_vec()?;
@ -58,7 +59,7 @@ fn main() -> Result<()> {
} => {
let ix = get_set_is_active_ix(&program_id, &ops_owner, &payer, is_active).unwrap();
let payload = ExecutorPayload {
header: GovernanceHeader::executor_governance_header(),
header: GovernanceHeader::executor_governance_header(),
instructions: vec![InstructionData::from(&ix)],
}
.try_to_vec()?;

View File

@ -1,60 +1,59 @@
use crate::{
config::P2WConfigAccount,
message::{
P2WMessage,
P2WMessageDrvData,
use {
crate::{
config::P2WConfigAccount,
message::{
P2WMessage,
P2WMessageDrvData,
},
},
};
use borsh::{
BorshDeserialize,
BorshSerialize,
};
use solana_program::{
clock::Clock,
instruction::{
AccountMeta,
Instruction,
borsh::{
BorshDeserialize,
BorshSerialize,
},
program::{
invoke,
invoke_signed,
bridge::{
accounts::BridgeData,
types::ConsistencyLevel,
PostMessageData,
},
p2w_sdk::{
BatchPriceAttestation,
Identifier,
P2WEmitter,
PriceAttestation,
},
solana_program::{
clock::Clock,
instruction::{
AccountMeta,
Instruction,
},
program::{
invoke,
invoke_signed,
},
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar as SolanaSysvar,
},
solitaire::{
invoke_seeded,
trace,
AccountState,
Derive,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Seeded,
Signer,
SolitaireError,
Sysvar,
},
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar as SolanaSysvar,
};
use p2w_sdk::{
BatchPriceAttestation,
Identifier,
P2WEmitter,
PriceAttestation,
};
use bridge::{
accounts::BridgeData,
types::ConsistencyLevel,
PostMessageData,
};
use solitaire::{
invoke_seeded,
trace,
AccountState,
Derive,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Seeded,
Signer,
SolitaireError,
Sysvar,
};
/// Important: must be manually maintained until native Solitaire
@ -69,26 +68,26 @@ pub const P2W_MAX_BATCH_SIZE: u16 = 5;
#[derive(FromAccounts)]
pub struct Attest<'b> {
// Payer also used for wormhole
pub payer: Mut<Signer<Info<'b>>>,
pub payer: Mut<Signer<Info<'b>>>,
pub system_program: Info<'b>,
pub config: P2WConfigAccount<'b, { AccountState::Initialized }>,
pub config: P2WConfigAccount<'b, { AccountState::Initialized }>,
// Hardcoded product/price pairs, bypassing Solitaire's variable-length limitations
// Any change to the number of accounts must include an appropriate change to P2W_MAX_BATCH_SIZE
pub pyth_product: Info<'b>,
pub pyth_price: Info<'b>,
pub pyth_price: Info<'b>,
pub pyth_product2: Option<Info<'b>>,
pub pyth_price2: Option<Info<'b>>,
pub pyth_price2: Option<Info<'b>>,
pub pyth_product3: Option<Info<'b>>,
pub pyth_price3: Option<Info<'b>>,
pub pyth_price3: Option<Info<'b>>,
pub pyth_product4: Option<Info<'b>>,
pub pyth_price4: Option<Info<'b>>,
pub pyth_price4: Option<Info<'b>>,
pub pyth_product5: Option<Info<'b>>,
pub pyth_price5: Option<Info<'b>>,
pub pyth_price5: Option<Info<'b>>,
// Did you read the comment near `pyth_product`?
// pub pyth_product6: Option<Info<'b>>,
@ -139,7 +138,7 @@ pub struct Attest<'b> {
#[derive(BorshDeserialize, BorshSerialize)]
pub struct AttestData {
pub consistency_level: ConsistencyLevel,
pub consistency_level: ConsistencyLevel,
pub message_account_id: u64,
}
@ -266,8 +265,8 @@ pub fn attest(ctx: &ExecutionContext, accs: &mut Attest, data: AttestData) -> So
let wh_msg_drv_data = P2WMessageDrvData {
message_owner: accs.payer.key.clone(),
batch_size: batch_attestation.price_attestations.len() as u16,
id: data.message_account_id,
batch_size: batch_attestation.price_attestations.len() as u16,
id: data.message_account_id,
};
if !P2WMessage::key(&wh_msg_drv_data, ctx.program_id).eq(accs.wh_message.info().key) {

View File

@ -20,17 +20,19 @@
//! 6. (optional) Remove/comment out config structs and aliases from
//! before version Y.
use borsh::{
BorshDeserialize,
BorshSerialize,
};
use solana_program::pubkey::Pubkey;
use solitaire::{
processors::seeded::AccountOwner,
AccountState,
Data,
Derive,
Owned,
use {
borsh::{
BorshDeserialize,
BorshSerialize,
},
solana_program::pubkey::Pubkey,
solitaire::{
processors::seeded::AccountOwner,
AccountState,
Data,
Derive,
Owned,
},
};
/// Aliases for current config schema (to migrate into)
@ -59,11 +61,11 @@ impl Owned for OldPyth2WormholeConfig {
#[cfg_attr(feature = "client", derive(Debug))]
pub struct Pyth2WormholeConfigV1 {
/// Authority owning this contract
pub owner: Pubkey,
pub owner: Pubkey,
/// Wormhole bridge program
pub wh_prog: Pubkey,
pub wh_prog: Pubkey,
/// Authority owning Pyth price data
pub pyth_owner: Pubkey,
pub pyth_owner: Pubkey,
pub max_batch_size: u16,
}
@ -75,11 +77,11 @@ pub type P2WConfigAccountV1<'b, const IsInitialized: AccountState> =
#[cfg_attr(feature = "client", derive(Debug))]
pub struct Pyth2WormholeConfigV2 {
/// Authority owning this contract
pub owner: Pubkey,
pub owner: Pubkey,
/// Wormhole bridge program
pub wh_prog: Pubkey,
pub wh_prog: Pubkey,
/// Authority owning Pyth price data
pub pyth_owner: Pubkey,
pub pyth_owner: Pubkey,
/// How many product/price pairs can be sent and attested at once
///
/// Important: Whenever the corresponding logic in attest.rs
@ -123,11 +125,11 @@ impl From<Pyth2WormholeConfigV1> for Pyth2WormholeConfigV2 {
#[cfg_attr(feature = "client", derive(Debug))]
pub struct Pyth2WormholeConfigV3 {
/// Authority owning this contract
pub owner: Pubkey,
pub owner: Pubkey,
/// Wormhole bridge program
pub wh_prog: Pubkey,
pub wh_prog: Pubkey,
/// Authority owning Pyth price data
pub pyth_owner: Pubkey,
pub pyth_owner: Pubkey,
/// How many product/price pairs can be sent and attested at once
///
/// Important: Whenever the corresponding logic in attest.rs

View File

@ -1,33 +1,34 @@
use solana_program::{
program::invoke,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar,
};
use solitaire::{
trace,
AccountState,
CreationLamports,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Signer,
};
use crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
use {
crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
solana_program::{
program::invoke,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar,
},
solitaire::{
trace,
AccountState,
CreationLamports,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Signer,
},
};
#[derive(FromAccounts)]
pub struct Initialize<'b> {
pub new_config: Mut<P2WConfigAccount<'b, { AccountState::Uninitialized }>>,
pub payer: Mut<Signer<Info<'b>>>,
pub new_config: Mut<P2WConfigAccount<'b, { AccountState::Uninitialized }>>,
pub payer: Mut<Signer<Info<'b>>>,
pub system_program: Info<'b>,
}

View File

@ -8,32 +8,31 @@ pub mod set_config;
pub mod set_is_active;
use solitaire::solitaire;
pub use attest::{
attest,
Attest,
AttestData,
pub use {
attest::{
attest,
Attest,
AttestData,
},
config::Pyth2WormholeConfig,
initialize::{
initialize,
Initialize,
},
migrate::{
migrate,
Migrate,
},
pyth_client,
set_config::{
set_config,
SetConfig,
},
set_is_active::{
set_is_active,
SetIsActive,
},
};
pub use config::Pyth2WormholeConfig;
pub use initialize::{
initialize,
Initialize,
};
pub use migrate::{
migrate,
Migrate,
};
pub use set_config::{
set_config,
SetConfig,
};
pub use set_is_active::{
set_is_active,
SetIsActive,
};
pub use pyth_client;
solitaire! {
Attest => attest,

View File

@ -7,19 +7,21 @@
//! derived with their address as message_owner in
//! `P2WMessageDrvData`.
use borsh::{
BorshDeserialize,
BorshSerialize,
};
use bridge::PostedMessageUnreliable;
use solana_program::pubkey::Pubkey;
use solitaire::{
processors::seeded::Seeded,
AccountState,
Data,
Info,
Mut,
Signer,
use {
borsh::{
BorshDeserialize,
BorshSerialize,
},
bridge::PostedMessageUnreliable,
solana_program::pubkey::Pubkey,
solitaire::{
processors::seeded::Seeded,
AccountState,
Data,
Info,
Mut,
Signer,
},
};
pub type P2WMessage<'a> = Mut<PostedMessageUnreliable<'a, { AccountState::MaybeInitialized }>>;
@ -34,9 +36,9 @@ pub struct P2WMessageDrvData {
/// Currently wormhole does not resize accounts if they have different
/// payload sizes; this (along with versioning the seed literal below) is
/// a workaround to have different PDAs for different batch sizes.
pub batch_size: u16,
pub batch_size: u16,
/// Index for keeping many accounts per owner
pub id: u64,
pub id: u64,
}
impl<'a> Seeded<&P2WMessageDrvData> for P2WMessage<'a> {

View File

@ -1,36 +1,36 @@
//! Instruction used to migrate on-chain configuration from an older format
use solana_program::{
program::invoke,
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
system_program,
sysvar::Sysvar,
};
use solitaire::{
trace,
AccountSize,
AccountState,
CreationLamports,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Signer,
SolitaireError,
};
use crate::config::{
OldP2WConfigAccount,
OldPyth2WormholeConfig,
P2WConfigAccount,
Pyth2WormholeConfig,
use {
crate::config::{
OldP2WConfigAccount,
OldPyth2WormholeConfig,
P2WConfigAccount,
Pyth2WormholeConfig,
},
solana_program::{
program::invoke,
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
system_program,
sysvar::Sysvar,
},
solitaire::{
trace,
AccountSize,
AccountState,
CreationLamports,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Signer,
SolitaireError,
},
};
/// Migration accounts meant to evolve with subsequent config accounts
@ -40,13 +40,13 @@ use crate::config::{
#[derive(FromAccounts)]
pub struct Migrate<'b> {
/// New config account to be populated. Must be unused.
pub new_config: Mut<P2WConfigAccount<'b, { AccountState::Uninitialized }>>,
pub new_config: Mut<P2WConfigAccount<'b, { AccountState::Uninitialized }>>,
/// Old config using the previous format.
pub old_config: Mut<OldP2WConfigAccount<'b>>,
pub old_config: Mut<OldP2WConfigAccount<'b>>,
/// Current owner authority of the program
pub current_owner: Mut<Signer<Info<'b>>>,
pub current_owner: Mut<Signer<Info<'b>>>,
/// Payer account for updating the account data
pub payer: Mut<Signer<Info<'b>>>,
pub payer: Mut<Signer<Info<'b>>>,
/// For creating the new config account
pub system_program: Info<'b>,
}

View File

@ -1,42 +1,41 @@
use borsh::BorshSerialize;
use solana_program::{
program::invoke,
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar,
use {
crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
borsh::BorshSerialize,
solana_program::{
program::invoke,
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar,
},
solitaire::{
trace,
AccountState,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Signer,
SolitaireError,
},
std::cmp::Ordering,
};
use solitaire::{
trace,
AccountState,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Signer,
SolitaireError,
};
use crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
};
use std::cmp::Ordering;
#[derive(FromAccounts)]
pub struct SetConfig<'b> {
/// Current config used by the program
pub config: Mut<P2WConfigAccount<'b, { AccountState::Initialized }>>,
pub config: Mut<P2WConfigAccount<'b, { AccountState::Initialized }>>,
/// Current owner authority of the program
pub current_owner: Mut<Signer<Info<'b>>>,
pub current_owner: Mut<Signer<Info<'b>>>,
/// Payer account for updating the account data
pub payer: Mut<Signer<Info<'b>>>,
pub payer: Mut<Signer<Info<'b>>>,
/// Used for rent adjustment transfer
pub system_program: Info<'b>,
}

View File

@ -1,30 +1,31 @@
use solitaire::{
trace,
AccountState,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Signer,
SolitaireError,
};
use crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
use {
crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
solitaire::{
trace,
AccountState,
ExecutionContext,
FromAccounts,
Info,
Keyed,
Mut,
Peel,
Result as SoliResult,
Signer,
SolitaireError,
},
};
#[derive(FromAccounts)]
pub struct SetIsActive<'b> {
/// Current config used by the program
pub config: Mut<P2WConfigAccount<'b, { AccountState::Initialized }>>,
pub config: Mut<P2WConfigAccount<'b, { AccountState::Initialized }>>,
/// Current owner authority of the program
pub ops_owner: Mut<Signer<Info<'b>>>,
/// Payer account for updating the account data
pub payer: Mut<Signer<Info<'b>>>,
pub payer: Mut<Signer<Info<'b>>>,
}
/// Alters the current settings of pyth2wormhole

View File

@ -1,11 +0,0 @@
# Merge similar crates together to avoid multiple use statements.
imports_granularity = "Crate"
# Consistency in formatting makes tool based searching/editing better.
empty_item_single_line = false
# Easier editing when arbitrary mixed use statements do not collapse.
imports_layout = "Vertical"
# Default rustfmt formatting of match arms with branches is awful.
match_arm_leading_pipes = "Preserve"

View File

@ -1,18 +0,0 @@
# Merge similar crates together to avoid multiple use statements.
imports_granularity = "Module"
# Consistency in formatting makes tool based searching/editing better.
empty_item_single_line = false
# Easier editing when arbitrary mixed use statements do not collapse.
imports_layout = "Vertical"
# Default rustfmt formatting of match arms with branches is awful.
match_arm_leading_pipes = "Preserve"
# Align Fields
enum_discrim_align_threshold = 80
struct_field_align_threshold = 80
# Allow up to two blank lines for grouping.
blank_lines_upper_bound = 2

View File

@ -6,29 +6,30 @@
//! similar human-readable names and provide a failsafe for some of
//! the probable adversarial scenarios.
use serde::{
Deserialize,
Serialize,
Serializer,
};
use std::borrow::Borrow;
use std::convert::TryInto;
use std::io::Read;
use std::iter::Iterator;
use std::mem;
pub use pyth_sdk::{
Identifier,
PriceStatus,
UnixTimestamp,
};
#[cfg(feature = "solana")]
use solitaire::{
Derive,
Info,
};
use {
serde::{
Deserialize,
Serialize,
Serializer,
},
std::{
borrow::Borrow,
convert::TryInto,
io::Read,
iter::Iterator,
mem,
},
};
#[cfg(feature = "wasm")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
@ -472,8 +473,10 @@ impl PriceAttestation {
/// using `cargo test -- --nocapture`.
#[cfg(test)]
mod tests {
use super::*;
use pyth_sdk_solana::state::PriceStatus;
use {
super::*,
pyth_sdk_solana::state::PriceStatus,
};
fn mock_attestation(prod: Option<[u8; 32]>, price: Option<[u8; 32]>) -> PriceAttestation {
let product_id_bytes = prod.unwrap_or([21u8; 32]);

View File

@ -1,13 +1,13 @@
use solana_program::pubkey::Pubkey;
use solitaire::Seeded;
use std::str::FromStr;
use wasm_bindgen::prelude::*;
use crate::{
BatchPriceAttestation,
P2WEmitter,
PriceAttestation,
use {
crate::{
BatchPriceAttestation,
P2WEmitter,
PriceAttestation,
},
solana_program::pubkey::Pubkey,
solitaire::Seeded,
std::str::FromStr,
wasm_bindgen::prelude::*,
};
#[wasm_bindgen]