mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-26 23:16:45 +00:00
fix close
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -5310,9 +5310,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel"
|
name = "steel"
|
||||||
version = "4.0.0"
|
version = "4.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "21be30219d8df5a7c09a52a8a25ec5a681476f849db44e053cfd288a3d412281"
|
checksum = "8aacdf8cc9261c6c801c5cfdf7ddc427d299665899d0612389841ba9920c4065"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"fixed",
|
"fixed",
|
||||||
|
|||||||
@@ -32,13 +32,12 @@ solana-sdk = "^2.1"
|
|||||||
spl-token = { version = "^4", features = ["no-entrypoint"] }
|
spl-token = { version = "^4", features = ["no-entrypoint"] }
|
||||||
spl-token-2022 = "^7"
|
spl-token-2022 = "^7"
|
||||||
spl-associated-token-account = { version = "^6", features = [ "no-entrypoint" ] }
|
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"
|
thiserror = "1.0.57"
|
||||||
tokio = { version = "1.37.0", features = ["full"] }
|
tokio = { version = "1.37.0", features = ["full"] }
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
overflow-checks = true
|
overflow-checks = true
|
||||||
|
|
||||||
|
|||||||
@@ -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(
|
pub fn close(
|
||||||
signer: Pubkey,
|
signer: Pubkey,
|
||||||
fee_collector: Pubkey,
|
fee_collector: Pubkey,
|
||||||
@@ -78,7 +80,7 @@ pub fn close(
|
|||||||
AccountMeta::new(MINT_ADDRESS, false),
|
AccountMeta::new(MINT_ADDRESS, false),
|
||||||
AccountMeta::new(opener, false),
|
AccountMeta::new(opener, false),
|
||||||
AccountMeta::new(recipient, false),
|
AccountMeta::new(recipient, false),
|
||||||
AccountMeta::new_readonly(TREASURY_ADDRESS, false),
|
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||||
AccountMeta::new(vault_base, false),
|
AccountMeta::new(vault_base, false),
|
||||||
AccountMeta::new(vault_quote, false),
|
AccountMeta::new(vault_quote, false),
|
||||||
AccountMeta::new_readonly(system_program::ID, false),
|
AccountMeta::new_readonly(system_program::ID, false),
|
||||||
|
|||||||
@@ -106,6 +106,11 @@ async fn close_all(
|
|||||||
let blocks = get_blocks(rpc).await?;
|
let blocks = get_blocks(rpc).await?;
|
||||||
for (_, block) in blocks {
|
for (_, block) in blocks {
|
||||||
if clock.slot > block.start_slot + 1500 {
|
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(
|
let ix = ore_api::sdk::close(
|
||||||
payer.pubkey(),
|
payer.pubkey(),
|
||||||
config.fee_collector,
|
config.fee_collector,
|
||||||
@@ -114,6 +119,7 @@ async fn close_all(
|
|||||||
block.id,
|
block.id,
|
||||||
);
|
);
|
||||||
submit_transaction(rpc, payer, &[ix]).await?;
|
submit_transaction(rpc, payer, &[ix]).await?;
|
||||||
|
// simulate_transaction(rpc, payer, &[ix]).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -241,13 +247,33 @@ async fn get_blocks(rpc: &RpcClient) -> Result<Vec<(Pubkey, Block)>, anyhow::Err
|
|||||||
Ok(blocks)
|
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(
|
async fn submit_transaction(
|
||||||
rpc: &RpcClient,
|
rpc: &RpcClient,
|
||||||
payer: &solana_sdk::signer::keypair::Keypair,
|
payer: &solana_sdk::signer::keypair::Keypair,
|
||||||
instructions: &[solana_sdk::instruction::Instruction],
|
instructions: &[solana_sdk::instruction::Instruction],
|
||||||
) -> Result<solana_sdk::signature::Signature, anyhow::Error> {
|
) -> Result<solana_sdk::signature::Signature, anyhow::Error> {
|
||||||
let blockhash = rpc.get_latest_blockhash().await?;
|
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);
|
all_instructions.extend_from_slice(instructions);
|
||||||
let transaction = Transaction::new_signed_with_payer(
|
let transaction = Transaction::new_signed_with_payer(
|
||||||
&all_instructions,
|
&all_instructions,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
|||||||
.has_address(&collateral_pda(block.id).0)?
|
.has_address(&collateral_pda(block.id).0)?
|
||||||
.as_token_account()?
|
.as_token_account()?
|
||||||
.assert(|t| t.mint() == *mint_quote_info.key)?
|
.assert(|t| t.mint() == *mint_quote_info.key)?
|
||||||
.assert(|t| t.owner() == *market_info.key)?;
|
.assert(|t| t.owner() == *block_info.key)?;
|
||||||
commitment_info
|
commitment_info
|
||||||
.is_writable()?
|
.is_writable()?
|
||||||
.has_address(&commitment_pda(block.id).0)?
|
.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()],
|
&[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 accounts.
|
||||||
close_token_account_signed(
|
close_token_account_signed(
|
||||||
vault_base_info,
|
vault_base_info,
|
||||||
@@ -172,19 +186,5 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
|||||||
// Close market.
|
// Close market.
|
||||||
market_info.close(opener_info)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user