fix close

This commit is contained in:
Hardhat Chad
2025-07-15 11:24:42 -07:00
parent 4ce1883cf6
commit 39cbd72f00
5 changed files with 48 additions and 21 deletions

4
Cargo.lock generated
View File

@@ -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",

View File

@@ -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

View File

@@ -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),

View File

@@ -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<Vec<(Pubkey, Block)>, 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<solana_sdk::signature::Signature, anyhow::Error> {
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,

View File

@@ -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(())
}