From 07ba515cbcc3556e1b24dd22b8c95757d49a8b15 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 13 Sep 2024 16:45:03 +0100 Subject: [PATCH 1/5] go --- staking/cli/src/instructions.rs | 69 +++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index 945f24a1..7d6542fa 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -227,23 +227,23 @@ pub fn process_write_encoded_vaa( data: wormhole_core_bridge_solana::instruction::InitEncodedVaa.data(), }; - let write_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::WriteEncodedVaa { - write_authority: payer.pubkey(), - draft_vaa: encoded_vaa_keypair.pubkey(), - } - .to_account_metas(None); + process_transaction( + rpc_client, + &[create_encoded_vaa, init_encoded_vaa_instruction], + &[payer, &encoded_vaa_keypair], + ); - let write_encoded_vaa_accounts_instruction = Instruction { - program_id: wormhole, - accounts: write_encoded_vaa_accounts.clone(), - data: wormhole_core_bridge_solana::instruction::WriteEncodedVaa { - args: WriteEncodedVaaArgs { - index: 0, - data: vaa.to_vec(), - }, - } - .data(), - }; + for i in (0..vaa.len()).step_by(1000) { + let chunk = &vaa[i..min(i + 1000, vaa.len())]; + + write_encoded_vaa( + rpc_client, + payer, + &encoded_vaa_keypair.pubkey(), + &wormhole, + chunk, + ); + } let (header, _): (Header, Body<&RawMessage>) = serde_wormhole::from_slice(vaa).unwrap(); let guardian_set = GuardianSet::key(&wormhole, header.guardian_set_index); @@ -267,19 +267,48 @@ pub fn process_write_encoded_vaa( process_transaction( rpc_client, &[ - create_encoded_vaa, - init_encoded_vaa_instruction, - write_encoded_vaa_accounts_instruction, verify_encoded_vaa_instruction, request_compute_units_instruction, ], - &[payer, &encoded_vaa_keypair], + &[payer], ); encoded_vaa_keypair.pubkey() } +pub fn write_encoded_vaa( + rpc_client: &RpcClient, + payer: &Keypair, + encoded_vaa: &Pubkey, + wormhole: &Pubkey, + chunk: &[u8], +) { + let write_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::WriteEncodedVaa { + write_authority: payer.pubkey(), + draft_vaa: *encoded_vaa, + } + .to_account_metas(None); + + let write_encoded_vaa_accounts_instruction = Instruction { + program_id: *wormhole, + accounts: write_encoded_vaa_accounts.clone(), + data: wormhole_core_bridge_solana::instruction::WriteEncodedVaa { + args: WriteEncodedVaaArgs { + index: 0, + data: chunk.to_vec(), + }, + } + .data(), + }; + + process_transaction( + rpc_client, + &[write_encoded_vaa_accounts_instruction], + &[payer], + ); +} + pub fn initialize_reward_custody(rpc_client: &RpcClient, payer: &Keypair) { let pool_config = get_pool_config_address(); From 97fcca0fdaec8c87c1d3af45112d9f01d9a96744 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 13 Sep 2024 23:11:17 +0100 Subject: [PATCH 2/5] go --- staking/Cargo.lock | 50 ++++++++++++++++----------------- staking/cli/Cargo.toml | 2 +- staking/cli/src/cli.rs | 4 +++ staking/cli/src/instructions.rs | 18 ++++++++++++ staking/cli/src/main.rs | 4 +++ 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/staking/Cargo.lock b/staking/Cargo.lock index 08a01734..dfdfdb95 100644 --- a/staking/Cargo.lock +++ b/staking/Cargo.lock @@ -3371,31 +3371,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" -[[package]] -name = "remote-executor-cli" -version = "0.1.0" -dependencies = [ - "anchor-lang", - "anchor-spl", - "base64 0.22.1", - "byteorder", - "clap 3.2.25", - "integration-tests", - "integrity-pool", - "publisher-caps", - "pyth-staking-program", - "pythnet-sdk", - "reqwest", - "serde_json", - "serde_wormhole", - "shellexpand", - "solana-client", - "solana-sdk", - "wormhole-core-bridge-solana", - "wormhole-solana", - "wormhole-vaas-serde", -] - [[package]] name = "reqwest" version = "0.11.27" @@ -5341,6 +5316,31 @@ dependencies = [ "spl-program-error 0.4.4", ] +[[package]] +name = "staking-cli" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "anchor-spl", + "base64 0.22.1", + "byteorder", + "clap 3.2.25", + "integration-tests", + "integrity-pool", + "publisher-caps", + "pyth-staking-program", + "pythnet-sdk", + "reqwest", + "serde_json", + "serde_wormhole", + "shellexpand", + "solana-client", + "solana-sdk", + "wormhole-core-bridge-solana", + "wormhole-solana", + "wormhole-vaas-serde", +] + [[package]] name = "static_assertions" version = "1.1.0" diff --git a/staking/cli/Cargo.toml b/staking/cli/Cargo.toml index b068ac1f..cab64a7a 100644 --- a/staking/cli/Cargo.toml +++ b/staking/cli/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "remote-executor-cli" +name = "staking-cli" version = "0.1.0" edition = "2018" diff --git a/staking/cli/src/cli.rs b/staking/cli/src/cli.rs index 904c687a..536e6f61 100644 --- a/staking/cli/src/cli.rs +++ b/staking/cli/src/cli.rs @@ -97,4 +97,8 @@ pub enum Action { #[clap(long, help = "New Y")] y: u64, }, + ClosePublisherCaps { + #[clap(long, help = "Publisher caps")] + publisher_caps: Pubkey, + }, } diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index a069b62f..7f5435e7 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -141,6 +141,24 @@ pub fn write_publisher_caps( process_transaction(rpc_client, &[instruction], &[payer]); } +pub fn close_publisher_caps(rpc_client: &RpcClient, payer: &Keypair, publisher_caps: Pubkey) { + let accounts = publisher_caps::accounts::ClosePublisherCaps { + write_authority: payer.pubkey(), + publisher_caps, + }; + + let instruction_data = publisher_caps::instruction::ClosePublisherCaps {}; + + let instruction = Instruction { + program_id: publisher_caps::ID, + accounts: accounts.to_account_metas(None), + data: instruction_data.data(), + }; + + process_transaction(rpc_client, &[instruction], &[payer]); +} + + pub fn verify_publisher_caps( rpc_client: &RpcClient, payer: &Keypair, diff --git a/staking/cli/src/main.rs b/staking/cli/src/main.rs index 4f2b50e3..238629ad 100644 --- a/staking/cli/src/main.rs +++ b/staking/cli/src/main.rs @@ -8,6 +8,7 @@ use { Cli, }, instructions::{ + close_publisher_caps, create_slash_event, fetch_publisher_caps_and_advance, initialize_pool, @@ -77,5 +78,8 @@ fn main() { stake_account_positions, } => slash(&rpc_client, &keypair, &publisher, &stake_account_positions), Action::UpdateY { y } => update_y(&rpc_client, &keypair, y), + Action::ClosePublisherCaps { publisher_caps } => { + close_publisher_caps(&rpc_client, &keypair, publisher_caps) + } } } From 7c0df8299d5bd76e8ed891965cf56673b1c88486 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 13 Sep 2024 23:19:16 +0100 Subject: [PATCH 3/5] add close after advance --- staking/cli/src/instructions.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index 9676d25f..9ed21d86 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -516,6 +516,7 @@ pub fn fetch_publisher_caps_and_advance( ); advance(rpc_client, payer, publisher_caps); + close_publisher_caps(rpc_client, payer, publisher_caps); } pub fn update_delegation_fee(rpc_client: &RpcClient, payer: &Keypair, delegation_fee: u64) { From 7f27ab5e3e33ae60e6d0adbedfcc9cc4fe0b946a Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Mon, 16 Sep 2024 16:56:08 +0100 Subject: [PATCH 4/5] close vaa too --- staking/cli/src/instructions.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index 9ed21d86..b9d2eb86 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -339,6 +339,22 @@ pub fn write_encoded_vaa( ); } +pub fn close_encoded_vaa(rpc_client: &RpcClient, payer: &Keypair, encoded_vaa: Pubkey) { + let close_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::CloseEncodedVaa { + write_authority: payer.pubkey(), + encoded_vaa, + } + .to_account_metas(None); + + let close_encoded_vaa_instruction = Instruction { + program_id: wormhole_core_bridge_solana::ID, + accounts: close_encoded_vaa_accounts, + data: wormhole_core_bridge_solana::instruction::CloseEncodedVaa {}.data(), + }; + + process_transaction(rpc_client, &[close_encoded_vaa_instruction], &[payer]); +} + pub fn initialize_reward_custody(rpc_client: &RpcClient, payer: &Keypair) { let pool_config = get_pool_config_address(); @@ -517,6 +533,7 @@ pub fn fetch_publisher_caps_and_advance( advance(rpc_client, payer, publisher_caps); close_publisher_caps(rpc_client, payer, publisher_caps); + close_encoded_vaa(rpc_client, payer, encoded_vaa); } pub fn update_delegation_fee(rpc_client: &RpcClient, payer: &Keypair, delegation_fee: u64) { From 590b79341df4c9ec0e82d85d8aa9f6721ff6203d Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Mon, 16 Sep 2024 20:30:09 +0100 Subject: [PATCH 5/5] set index --- staking/cli/src/instructions.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index b9d2eb86..b560271d 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -271,6 +271,7 @@ pub fn process_write_encoded_vaa( payer, &encoded_vaa_keypair.pubkey(), &wormhole, + i, chunk, ); } @@ -312,6 +313,7 @@ pub fn write_encoded_vaa( payer: &Keypair, encoded_vaa: &Pubkey, wormhole: &Pubkey, + index: usize, chunk: &[u8], ) { let write_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::WriteEncodedVaa { @@ -325,7 +327,7 @@ pub fn write_encoded_vaa( accounts: write_encoded_vaa_accounts.clone(), data: wormhole_core_bridge_solana::instruction::WriteEncodedVaa { args: WriteEncodedVaaArgs { - index: 0, + index: index as u32, data: chunk.to_vec(), }, }