From 39cbd72f0050a8043fdc85dbfa6abdebbb05577c Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Tue, 15 Jul 2025 11:24:42 -0700 Subject: [PATCH] fix close --- Cargo.lock | 4 ++-- Cargo.toml | 3 +-- api/src/sdk.rs | 4 +++- cli/src/main.rs | 28 +++++++++++++++++++++++++++- program/src/close.rs | 30 +++++++++++++++--------------- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcd7774..cd06c83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5310,9 +5310,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel" -version = "4.0.0" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21be30219d8df5a7c09a52a8a25ec5a681476f849db44e053cfd288a3d412281" +checksum = "8aacdf8cc9261c6c801c5cfdf7ddc427d299665899d0612389841ba9920c4065" dependencies = [ "bytemuck", "fixed", diff --git a/Cargo.toml b/Cargo.toml index 1f87aaf..7d5ade2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,13 +32,12 @@ solana-sdk = "^2.1" spl-token = { version = "^4", features = ["no-entrypoint"] } spl-token-2022 = "^7" spl-associated-token-account = { version = "^6", features = [ "no-entrypoint" ] } -steel = { features = ["spl"], version = "4.0" } +steel = { features = ["spl"], version = "4.0.2" } thiserror = "1.0.57" tokio = { version = "1.37.0", features = ["full"] } [patch.crates-io] - [profile.release] overflow-checks = true diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 8eb229e..55cd2ca 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -45,6 +45,8 @@ pub fn open(signer: Pubkey, id: u64) -> Instruction { } } +// let [signer_info, block_info, config_info, collateral_info, commitment_info, fee_collector_info, market_info, miner_info, mint_base_info, mint_quote_info, opener_info, recipient_info, treasury_info, vault_base_info, vault_quote_info, system_program, token_program, ore_program] = + pub fn close( signer: Pubkey, fee_collector: Pubkey, @@ -78,7 +80,7 @@ pub fn close( AccountMeta::new(MINT_ADDRESS, false), AccountMeta::new(opener, false), AccountMeta::new(recipient, false), - AccountMeta::new_readonly(TREASURY_ADDRESS, false), + AccountMeta::new(TREASURY_ADDRESS, false), AccountMeta::new(vault_base, false), AccountMeta::new(vault_quote, false), AccountMeta::new_readonly(system_program::ID, false), diff --git a/cli/src/main.rs b/cli/src/main.rs index 9192f0a..89c9b60 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -106,6 +106,11 @@ async fn close_all( let blocks = get_blocks(rpc).await?; for (_, block) in blocks { if clock.slot > block.start_slot + 1500 { + println!("Closing block {}", block.id); + println!(" fee_collector: {}", config.fee_collector); + println!(" opener: {}", block.opener); + println!(" payer: {}", payer.pubkey()); + println!(" id: {}", block.id); let ix = ore_api::sdk::close( payer.pubkey(), config.fee_collector, @@ -114,6 +119,7 @@ async fn close_all( block.id, ); submit_transaction(rpc, payer, &[ix]).await?; + // simulate_transaction(rpc, payer, &[ix]).await; } } Ok(()) @@ -241,13 +247,33 @@ async fn get_blocks(rpc: &RpcClient) -> Result, anyhow::Err Ok(blocks) } +async fn simulate_transaction( + rpc: &RpcClient, + payer: &solana_sdk::signer::keypair::Keypair, + instructions: &[solana_sdk::instruction::Instruction], +) { + let blockhash = rpc.get_latest_blockhash().await.unwrap(); + let x = rpc + .simulate_transaction(&Transaction::new_signed_with_payer( + instructions, + Some(&payer.pubkey()), + &[payer], + blockhash, + )) + .await; + println!("Simulation result: {:?}", x); +} + async fn submit_transaction( rpc: &RpcClient, payer: &solana_sdk::signer::keypair::Keypair, instructions: &[solana_sdk::instruction::Instruction], ) -> Result { let blockhash = rpc.get_latest_blockhash().await?; - let mut all_instructions = vec![ComputeBudgetInstruction::set_compute_unit_limit(1_400_000)]; + let mut all_instructions = vec![ + ComputeBudgetInstruction::set_compute_unit_limit(1_400_000), + ComputeBudgetInstruction::set_compute_unit_price(1_000_000), + ]; all_instructions.extend_from_slice(instructions); let transaction = Transaction::new_signed_with_payer( &all_instructions, diff --git a/program/src/close.rs b/program/src/close.rs index 5b41974..a8edc77 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -20,7 +20,7 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul .has_address(&collateral_pda(block.id).0)? .as_token_account()? .assert(|t| t.mint() == *mint_quote_info.key)? - .assert(|t| t.owner() == *market_info.key)?; + .assert(|t| t.owner() == *block_info.key)?; commitment_info .is_writable()? .has_address(&commitment_pda(block.id).0)? @@ -143,6 +143,20 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul &[BLOCK, &block.id.to_le_bytes()], )?; + // Emit event. + program_log( + block.id, + &[block_info.clone(), ore_program.clone()], + &CloseEvent { + authority: *signer_info.key, + id: block.id, + burned_base: base_burned, + burned_quote: quote_burned, + ts: clock.unix_timestamp, + } + .to_bytes(), + )?; + // Close token accounts. close_token_account_signed( vault_base_info, @@ -172,19 +186,5 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul // Close market. market_info.close(opener_info)?; - // Emit event. - program_log( - block.id, - &[block_info.clone(), ore_program.clone()], - &CloseEvent { - authority: *signer_info.key, - id: block.id, - burned_base: base_burned, - burned_quote: quote_burned, - ts: clock.unix_timestamp, - } - .to_bytes(), - )?; - Ok(()) }