mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
deposit, swap, commit
This commit is contained in:
@@ -93,6 +93,47 @@ pub fn mine(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
// let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, sender_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
|
||||
pub fn commit(
|
||||
signer: Pubkey,
|
||||
amount: u64,
|
||||
executor: Pubkey,
|
||||
fee: u64,
|
||||
id: u64,
|
||||
seed: [u8; 32],
|
||||
) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let market_address = market_pda(id).0;
|
||||
let base_mint_address = mint_pda(id).0;
|
||||
let miner_address = miner_pda(signer).0;
|
||||
let permit_address = permit_pda(signer, id).0;
|
||||
let commitment_address = get_associated_token_address(&block_adddress, &base_mint_address);
|
||||
let sender_address = get_associated_token_address(&signer, &base_mint_address);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(commitment_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new(base_mint_address, false),
|
||||
AccountMeta::new(permit_address, false),
|
||||
AccountMeta::new(sender_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
],
|
||||
data: Commit {
|
||||
amount: amount.to_le_bytes(),
|
||||
executor: executor.to_bytes(),
|
||||
fee: fee.to_le_bytes(),
|
||||
seed: seed,
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deposit(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let collateral_address = get_associated_token_address(&block_adddress, &MINT_ADDRESS);
|
||||
|
||||
@@ -48,6 +48,12 @@ async fn main() {
|
||||
"swap" => {
|
||||
swap(&rpc, &payer).await.unwrap();
|
||||
}
|
||||
"commit" => {
|
||||
commit(&rpc, &payer).await.unwrap();
|
||||
}
|
||||
// "uncommit" => {
|
||||
// uncommit(&rpc, &payer).await.unwrap();
|
||||
// }
|
||||
_ => panic!("Invalid command"),
|
||||
};
|
||||
}
|
||||
@@ -74,6 +80,17 @@ async fn close(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn commit(
|
||||
rpc: &RpcClient,
|
||||
payer: &solana_sdk::signer::keypair::Keypair,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let id_str = std::env::var("ID").expect("Missing ID env var");
|
||||
let id = id_str.parse::<u64>()?;
|
||||
let ix = ore_api::sdk::commit(payer.pubkey(), 10000000, Pubkey::default(), 0, id, [0; 32]);
|
||||
submit_transaction(rpc, payer, &[ix]).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn deposit(
|
||||
rpc: &RpcClient,
|
||||
payer: &solana_sdk::signer::keypair::Keypair,
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, sender_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, sender_info, system_program, token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -30,7 +30,6 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
.as_associated_token_account(signer_info.key, &mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?;
|
||||
|
||||
// Normalize amount.
|
||||
let amount = sender.amount().min(amount);
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, recipient_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, recipient_info, system_program, token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -37,7 +37,6 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
.as_associated_token_account(signer_info.key, &mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?;
|
||||
|
||||
// Normalize amount.
|
||||
let amount = permit.amount.min(amount);
|
||||
|
||||
Reference in New Issue
Block a user