Guibescos/expose attester instructions (#313)

* Add payload generators

* Executor cli no longer a lib

* Expose instructions in client

* Format
This commit is contained in:
guibescos 2022-09-29 09:15:42 -05:00 committed by GitHub
parent 3176d6a07f
commit c4238c7a91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 34 deletions

View File

@ -125,15 +125,12 @@ pub fn gen_init_tx(
Ok(tx_signed)
}
pub fn gen_set_config_tx(
payer: Keypair,
p2w_addr: Pubkey,
owner: Keypair,
pub fn get_set_config_ix(
p2w_addr: &Pubkey,
owner_pubkey: &Pubkey,
payer_pubkey: &Pubkey,
new_config: Pyth2WormholeConfig,
latest_blockhash: Hash,
) -> Result<Transaction, ErrBox> {
let payer_pubkey = payer.pubkey();
) -> Result<Instruction, ErrBox> {
let acc_metas = vec![
// config
AccountMeta::new(
@ -141,30 +138,71 @@ pub fn gen_set_config_tx(
false,
),
// current_owner
AccountMeta::new(owner.pubkey(), true),
AccountMeta::new(*owner_pubkey, true),
// payer
AccountMeta::new(payer.pubkey(), true),
AccountMeta::new(*payer_pubkey, true),
// system_program
AccountMeta::new(system_program::id(), false),
];
let ix_data = (
pyth2wormhole::instruction::Instruction::SetConfig,
new_config,
);
Ok(Instruction::new_with_bytes(
*p2w_addr,
ix_data.try_to_vec()?.as_slice(),
acc_metas,
))
}
let ix = Instruction::new_with_bytes(p2w_addr, ix_data.try_to_vec()?.as_slice(), acc_metas);
pub fn gen_set_config_tx(
payer: Keypair,
p2w_addr: Pubkey,
owner: Keypair,
new_config: Pyth2WormholeConfig,
latest_blockhash: Hash,
) -> Result<Transaction, ErrBox> {
let ix = get_set_config_ix(&p2w_addr, &owner.pubkey(), &payer.pubkey(), new_config)?;
let signers = vec![&owner, &payer];
let tx_signed = Transaction::new_signed_with_payer::<Vec<&Keypair>>(
&[ix],
Some(&payer_pubkey),
Some(&payer.pubkey()),
&signers,
latest_blockhash,
);
Ok(tx_signed)
}
pub fn get_set_is_active_ix(
p2w_addr: &Pubkey,
ops_owner_pubkey: &Pubkey,
payer_pubkey: &Pubkey,
new_is_active: bool,
) -> Result<Instruction, ErrBox> {
let acc_metas = vec![
// config
AccountMeta::new(
P2WConfigAccount::<{ AccountState::Initialized }>::key(None, &p2w_addr),
false,
),
// ops_owner
AccountMeta::new(*ops_owner_pubkey, true),
// payer
AccountMeta::new(*payer_pubkey, true),
];
let ix_data = (
pyth2wormhole::instruction::Instruction::SetIsActive,
new_is_active,
);
Ok(Instruction::new_with_bytes(
*p2w_addr,
ix_data.try_to_vec()?.as_slice(),
acc_metas,
))
}
pub fn gen_set_is_active_tx(
payer: Keypair,
p2w_addr: Pubkey,
@ -172,31 +210,17 @@ pub fn gen_set_is_active_tx(
new_is_active: bool,
latest_blockhash: Hash,
) -> Result<Transaction, ErrBox> {
let payer_pubkey = payer.pubkey();
let acc_metas = vec![
// config
AccountMeta::new(
P2WConfigAccount::<{ AccountState::Initialized }>::key(None, &p2w_addr),
false,
),
// ops_owner
AccountMeta::new(ops_owner.pubkey(), true),
// payer
AccountMeta::new(payer.pubkey(), true),
];
let ix_data = (
pyth2wormhole::instruction::Instruction::SetIsActive,
let ix = get_set_is_active_ix(
&p2w_addr,
&ops_owner.pubkey(),
&payer.pubkey(),
new_is_active,
);
let ix = Instruction::new_with_bytes(p2w_addr, ix_data.try_to_vec()?.as_slice(), acc_metas);
)?;
let signers = vec![&ops_owner, &payer];
let tx_signed = Transaction::new_signed_with_payer::<Vec<&Keypair>>(
&[ix],
Some(&payer_pubkey),
Some(&payer.pubkey()),
&signers,
latest_blockhash,
);

View File

@ -16,7 +16,7 @@ wasm = ["wasm-bindgen", "solana"]
[dependencies]
hex = "0.4.3"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
pyth-sdk = "*"
pyth-sdk = {version = "0.5.0"}
pyth-sdk-solana = { version = "0.5.0", optional = true }
wasm-bindgen = { version = "0.2.74", features = ["serde-serialize"], optional = true}
solitaire = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.8.9", optional = true}