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

@ -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,6 +1,25 @@
use std::collections::HashSet;
use cosmwasm_std::{
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,
@ -13,40 +32,21 @@ use cosmwasm_std::{
StdResult,
Timestamp,
WasmQuery,
};
use pyth_sdk_cw::{
},
p2w_sdk::BatchPriceAttestation,
pyth_sdk_cw::{
PriceFeed,
PriceIdentifier,
PriceStatus,
ProductIdentifier,
},
std::collections::HashSet,
wormhole::{
msg::QueryMsg as WormholeQueryMsg,
state::ParsedVAA,
},
};
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,27 +303,28 @@ 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::{
use {
super::*,
cosmwasm_std::{
testing::{
mock_dependencies,
mock_env,
mock_info,
MockApi,
MockQuerier,
MockStorage,
};
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::{
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,21 +1,11 @@
use std::collections::HashSet;
use std::time::Duration;
use pyth_sdk_cw::PriceFeed;
use schemars::JsonSchema;
use serde::{
Deserialize,
Serialize,
};
use cosmwasm_std::{
use {
cosmwasm_std::{
Addr,
Binary,
Storage,
Timestamp,
};
use cosmwasm_storage::{
},
cosmwasm_storage::{
bucket,
bucket_read,
singleton,
@ -24,6 +14,17 @@ use cosmwasm_storage::{
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::{
use {
clap::{
Parser,
Subcommand,
};
use solana_sdk::{
},
solana_sdk::{
commitment_config::CommitmentConfig,
pubkey::Pubkey,
},
};
#[derive(Parser, Debug)]

View File

@ -1,8 +1,7 @@
#![deny(warnings)]
pub mod cli;
use std::str::FromStr;
use anchor_client::{
use {
anchor_client::{
anchor_lang::{
AccountDeserialize,
AnchorDeserialize,
@ -12,22 +11,28 @@ use anchor_client::{
ToAccountMetas,
},
solana_sdk::bpf_loader_upgradeable,
};
use clap::Parser;
use cli::{
},
anyhow::Result,
clap::Parser,
cli::{
Action,
Cli,
};
use anyhow::Result;
use remote_executor::{
},
remote_executor::{
accounts::ExecutePostedVaa,
state::governance_payload::InstructionData,
state::{
governance_payload::{
ExecutorPayload,
GovernanceHeader,
InstructionData,
},
posted_vaa::AnchorVaa,
},
EXECUTOR_KEY_SEED,
ID,
};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{
},
solana_client::rpc_client::RpcClient,
solana_sdk::{
instruction::{
AccountMeta,
Instruction,
@ -38,11 +43,15 @@ use solana_sdk::{
Keypair,
},
signer::Signer,
system_instruction,
system_instruction::transfer,
system_instruction::{
self,
transfer,
},
transaction::Transaction,
};
use wormhole_solana::{
},
std::str::FromStr,
wormhole::VAA,
wormhole_solana::{
instructions::{
post_message,
post_vaa,
@ -54,16 +63,8 @@ use wormhole_solana::{
FeeCollector,
GuardianSet,
VAA as PostedVAA,
};
use remote_executor::state::{
governance_payload::{
ExecutorPayload,
GovernanceHeader,
},
posted_vaa::AnchorVaa,
};
use wormhole::VAA;
fn main() -> Result<()> {
let cli = Cli::parse();

View File

@ -1,19 +1,21 @@
#![deny(warnings)]
#![allow(clippy::result_large_err)]
use anchor_lang::{
use {
anchor_lang::{
prelude::*,
solana_program::borsh::get_packed_len,
system_program,
};
use error::ExecutorError;
use state::{
},
error::ExecutorError,
state::{
claim_record::ClaimRecord,
posted_vaa::AnchorVaa,
};
use wormhole::Chain::{
},
wormhole::Chain::{
self,
Solana,
},
};
mod error;
@ -27,15 +29,15 @@ declare_id!("exe6S3AxPVNmy46L4Nj6HrnnAVQUhwyYzMSNcnRn3qq");
#[program]
pub mod remote_executor {
use anchor_lang::solana_program::{
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;

View File

@ -1,18 +1,18 @@
use std::{
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)]
@ -170,17 +170,18 @@ impl ExecutorPayload {
#[cfg(test)]
pub mod tests {
use crate::{
use {
super::ExecutorPayload,
crate::{
error,
error::ExecutorError,
state::governance_payload::InstructionData,
};
use super::ExecutorPayload;
use anchor_lang::{
},
anchor_lang::{
prelude::Pubkey,
AnchorDeserialize,
AnchorSerialize,
},
};
#[test]

View File

@ -1,10 +1,12 @@
use anchor_lang::prelude::*;
use std::{
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 {

View File

@ -1,4 +1,19 @@
use anchor_lang::{
use {
crate::{
error::ExecutorError,
state::{
claim_record::ClaimRecord,
governance_payload::{
ExecutorPayload,
GovernanceHeader,
InstructionData,
},
posted_vaa::AnchorVaa,
},
CLAIM_RECORD_SEED,
EXECUTOR_KEY_SEED,
},
anchor_lang::{
prelude::{
AccountMeta,
ProgramError,
@ -14,16 +29,16 @@ use anchor_lang::{
Key,
Owner,
ToAccountMetas,
};
use solana_program_test::{
},
solana_program_test::{
find_file,
read_file,
BanksClient,
BanksClientError,
ProgramTest,
ProgramTestBanksClientExt,
};
use solana_sdk::{
},
solana_sdk::{
account::Account,
bpf_loader_upgradeable,
instruction::{
@ -38,24 +53,10 @@ use solana_sdk::{
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,
},
posted_vaa::AnchorVaa,
},
CLAIM_RECORD_SEED,
EXECUTOR_KEY_SEED,
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

View File

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

View File

@ -1,13 +1,13 @@
use crate::{
use {
super::executor_simulator::ExecutorBench,
crate::{
error::ExecutorError,
tests::executor_simulator::{
ExecutorAttack,
VaaAttack,
},
};
use super::executor_simulator::ExecutorBench;
use anchor_lang::{
},
anchor_lang::{
prelude::{
Pubkey,
Rent,
@ -16,12 +16,13 @@ use anchor_lang::{
system_instruction::create_account,
system_program,
},
};
use solana_sdk::{
},
solana_sdk::{
native_token::LAMPORTS_PER_SOL,
signature::Keypair,
signer::Signer,
system_instruction::transfer,
},
};
#[tokio::test]

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,25 +1,24 @@
use std::{
use {
crate::BatchState,
log::info,
serde::{
de::Error,
Deserialize,
Deserializer,
Serialize,
Serializer,
},
solana_program::pubkey::Pubkey,
std::{
collections::{
HashMap,
HashSet,
},
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 {
@ -275,9 +274,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use solitaire::ErrBox;
use {
super::*,
solitaire::ErrBox,
};
#[test]
fn test_sanity() -> Result<(), ErrBox> {

View File

@ -1,19 +1,18 @@
use log::{
debug,
warn,
};
use solana_client::nonblocking::rpc_client::RpcClient;
use pyth_sdk_solana::state::PriceAccount;
use std::time::{
Duration,
Instant,
};
use crate::{
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

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::{
use {
clap::{
Parser,
Subcommand,
},
solana_program::pubkey::Pubkey,
solana_sdk::commitment_config::CommitmentConfig,
std::path::PathBuf,
};
#[derive(Parser)]

View File

@ -3,22 +3,58 @@ pub mod batch_state;
pub mod message;
pub mod util;
use borsh::{
pub use {
attestation_cfg::{
AttestationConditions,
AttestationConfig,
P2WSymbol,
},
batch_state::BatchState,
message::P2WMessageQueue,
pyth2wormhole::Pyth2WormholeConfig,
util::{
RLMutex,
RLMutexGuard,
},
};
use {
borsh::{
BorshDeserialize,
BorshSerialize,
};
use log::{
},
bridge::{
accounts::{
Bridge,
FeeCollector,
Sequence,
SequenceDerivationData,
},
types::ConsistencyLevel,
},
log::{
debug,
trace,
warn,
};
use pyth_sdk_solana::state::{
},
p2w_sdk::P2WEmitter,
pyth2wormhole::{
config::{
OldP2WConfigAccount,
P2WConfigAccount,
},
message::{
P2WMessage,
P2WMessageDrvData,
},
AttestData,
},
pyth_sdk_solana::state::{
load_mapping_account,
load_price_account,
load_product_account,
};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_program::{
},
solana_client::nonblocking::rpc_client::RpcClient,
solana_program::{
hash::Hash,
instruction::{
AccountMeta,
@ -30,64 +66,25 @@ use solana_program::{
clock,
rent,
},
};
use solana_sdk::{
},
solana_sdk::{
signer::{
keypair::Keypair,
Signer,
},
transaction::Transaction,
};
use solitaire::{
},
solitaire::{
processors::seeded::Seeded,
AccountState,
ErrBox,
};
use bridge::{
accounts::{
Bridge,
FeeCollector,
Sequence,
SequenceDerivationData,
},
types::ConsistencyLevel,
};
use std::collections::{
std::collections::{
HashMap,
HashSet,
};
use p2w_sdk::P2WEmitter;
use pyth2wormhole::{
config::{
OldP2WConfigAccount,
P2WConfigAccount,
},
message::{
P2WMessage,
P2WMessageDrvData,
},
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>;

View File

@ -1,67 +1,65 @@
pub mod cli;
use std::{
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,
},
};
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::{
},
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")]

View File

@ -1,16 +1,17 @@
//! Re-usable message scheme for pyth2wormhole
use log::debug;
use std::{
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 {

View File

@ -1,6 +1,6 @@
use log::trace;
use std::{
use {
log::trace,
std::{
ops::{
Deref,
DerefMut,
@ -9,10 +9,11 @@ use std::{
Duration,
Instant,
},
};
use tokio::sync::{
},
tokio::sync::{
Mutex,
MutexGuard,
},
};
/// Rate-limited mutex. Ensures there's a period of minimum rl_interval between lock acquisitions

View File

@ -1,12 +1,13 @@
//! Trivial program for mocking other programs easily
use solana_program::{
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,14 +1,7 @@
//! 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::{
use {
pyth_client::{
AccKey,
AccountType,
Price,
@ -16,6 +9,13 @@ use pyth_client::{
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

View File

@ -1,7 +1,22 @@
pub mod fixtures;
use solana_program_test::*;
use solana_sdk::{
use {
bridge::accounts::{
Bridge,
BridgeConfig,
BridgeData,
},
fixtures::{
passthrough,
pyth,
},
pyth2wormhole::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
pyth2wormhole_client as p2wc,
solana_program_test::*,
solana_sdk::{
account::Account,
instruction::{
AccountMeta,
@ -12,30 +27,13 @@ use solana_sdk::{
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::{
},
solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
};
use std::time::Duration;
use fixtures::{
passthrough,
pyth,
},
std::time::Duration,
};
#[tokio::test]

View File

@ -2,9 +2,27 @@
pub mod fixtures;
use solana_program::system_program;
use solana_program_test::*;
use solana_sdk::{
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,
@ -15,32 +33,12 @@ use solana_sdk::{
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::{
},
solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
};
use fixtures::{
passthrough,
pyth,
},
};
#[tokio::test]

View File

@ -1,25 +1,26 @@
pub mod fixtures;
use borsh::BorshDeserialize;
use p2wc::get_config_account;
use solana_program_test::*;
use solana_sdk::{
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,
};
use pyth2wormhole::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
};
use pyth2wormhole_client as p2wc;
use solitaire::{
},
solitaire::{
processors::seeded::Seeded,
AccountState,
BorshSerialize,
},
};
fn clone_keypair(keypair: &Keypair) -> Keypair {

View File

@ -1,11 +1,12 @@
//! CLI options
use clap::{
use {
clap::{
Parser,
Subcommand,
},
solana_sdk::pubkey::Pubkey,
};
use solana_sdk::pubkey::Pubkey;
#[derive(Parser, Debug)]
#[clap(
about = "A cli for the remote executor",

View File

@ -1,20 +1,21 @@
use anyhow::Result;
use clap::Parser;
use cli::{
use {
anyhow::Result,
borsh::BorshSerialize,
clap::Parser,
cli::{
Action,
Cli,
};
use pyth2wormhole_client::{
},
pyth2wormhole_client::{
get_set_config_ix,
get_set_is_active_ix,
Pyth2WormholeConfig,
};
use borsh::BorshSerialize;
use pyth2wormhole_client::get_set_is_active_ix;
use remote_executor::state::governance_payload::{
},
remote_executor::state::governance_payload::{
ExecutorPayload,
GovernanceHeader,
InstructionData,
},
};
mod cli;

View File

@ -1,15 +1,27 @@
use crate::{
use {
crate::{
config::P2WConfigAccount,
message::{
P2WMessage,
P2WMessageDrvData,
},
};
use borsh::{
},
borsh::{
BorshDeserialize,
BorshSerialize,
};
use solana_program::{
},
bridge::{
accounts::BridgeData,
types::ConsistencyLevel,
PostMessageData,
},
p2w_sdk::{
BatchPriceAttestation,
Identifier,
P2WEmitter,
PriceAttestation,
},
solana_program::{
clock::Clock,
instruction::{
AccountMeta,
@ -24,22 +36,8 @@ use solana_program::{
rent::Rent,
system_instruction,
sysvar::Sysvar as SolanaSysvar,
};
use p2w_sdk::{
BatchPriceAttestation,
Identifier,
P2WEmitter,
PriceAttestation,
};
use bridge::{
accounts::BridgeData,
types::ConsistencyLevel,
PostMessageData,
};
use solitaire::{
},
solitaire::{
invoke_seeded,
trace,
AccountState,
@ -55,6 +53,7 @@ use solitaire::{
Signer,
SolitaireError,
Sysvar,
},
};
/// Important: must be manually maintained until native Solitaire

View File

@ -20,17 +20,19 @@
//! 6. (optional) Remove/comment out config structs and aliases from
//! before version Y.
use borsh::{
use {
borsh::{
BorshDeserialize,
BorshSerialize,
};
use solana_program::pubkey::Pubkey;
use solitaire::{
},
solana_program::pubkey::Pubkey,
solitaire::{
processors::seeded::AccountOwner,
AccountState,
Data,
Derive,
Owned,
},
};
/// Aliases for current config schema (to migrate into)

View File

@ -1,11 +1,16 @@
use solana_program::{
use {
crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
solana_program::{
program::invoke,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar,
};
use solitaire::{
},
solitaire::{
trace,
AccountState,
CreationLamports,
@ -17,11 +22,7 @@ use solitaire::{
Peel,
Result as SoliResult,
Signer,
};
use crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
};
#[derive(FromAccounts)]

View File

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

View File

@ -7,19 +7,21 @@
//! derived with their address as message_owner in
//! `P2WMessageDrvData`.
use borsh::{
use {
borsh::{
BorshDeserialize,
BorshSerialize,
};
use bridge::PostedMessageUnreliable;
use solana_program::pubkey::Pubkey;
use solitaire::{
},
bridge::PostedMessageUnreliable,
solana_program::pubkey::Pubkey,
solitaire::{
processors::seeded::Seeded,
AccountState,
Data,
Info,
Mut,
Signer,
},
};
pub type P2WMessage<'a> = Mut<PostedMessageUnreliable<'a, { AccountState::MaybeInitialized }>>;

View File

@ -1,6 +1,13 @@
//! Instruction used to migrate on-chain configuration from an older format
use solana_program::{
use {
crate::config::{
OldP2WConfigAccount,
OldPyth2WormholeConfig,
P2WConfigAccount,
Pyth2WormholeConfig,
},
solana_program::{
program::invoke,
program_error::ProgramError,
pubkey::Pubkey,
@ -8,9 +15,8 @@ use solana_program::{
system_instruction,
system_program,
sysvar::Sysvar,
};
use solitaire::{
},
solitaire::{
trace,
AccountSize,
AccountState,
@ -24,13 +30,7 @@ use solitaire::{
Result as SoliResult,
Signer,
SolitaireError,
};
use crate::config::{
OldP2WConfigAccount,
OldPyth2WormholeConfig,
P2WConfigAccount,
Pyth2WormholeConfig,
},
};
/// Migration accounts meant to evolve with subsequent config accounts

View File

@ -1,14 +1,18 @@
use borsh::BorshSerialize;
use solana_program::{
use {
crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
borsh::BorshSerialize,
solana_program::{
program::invoke,
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar,
};
use solitaire::{
},
solitaire::{
trace,
AccountState,
ExecutionContext,
@ -20,15 +24,10 @@ use solitaire::{
Result as SoliResult,
Signer,
SolitaireError,
},
std::cmp::Ordering,
};
use crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
};
use std::cmp::Ordering;
#[derive(FromAccounts)]
pub struct SetConfig<'b> {
/// Current config used by the program

View File

@ -1,4 +1,9 @@
use solitaire::{
use {
crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
solitaire::{
trace,
AccountState,
ExecutionContext,
@ -10,11 +15,7 @@ use solitaire::{
Result as SoliResult,
Signer,
SolitaireError,
};
use crate::config::{
P2WConfigAccount,
Pyth2WormholeConfig,
},
};
#[derive(FromAccounts)]

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::{
use {
crate::{
BatchPriceAttestation,
P2WEmitter,
PriceAttestation,
},
solana_program::pubkey::Pubkey,
solitaire::Seeded,
std::str::FromStr,
wasm_bindgen::prelude::*,
};
#[wasm_bindgen]