mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-25 07:26:50 +00:00
5x5
This commit is contained in:
233
api/src/sdk.rs
233
api/src/sdk.rs
@@ -7,36 +7,22 @@ use crate::{
|
||||
state::*,
|
||||
};
|
||||
|
||||
pub fn log(signer: Pubkey, msg: &[u8]) -> Instruction {
|
||||
let mut data = Log {}.to_bytes();
|
||||
data.extend_from_slice(msg);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![AccountMeta::new(signer, true)],
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn program_log(accounts: &[AccountInfo], msg: &[u8]) -> Result<(), ProgramError> {
|
||||
invoke_signed(&log(*accounts[0].key, msg), accounts, &crate::ID, &[MARKET])
|
||||
}
|
||||
// let [signer_info, board_info, config_info, mint_info, treasury_info, vault_info, system_program, token_program, associated_token_program] =
|
||||
|
||||
pub fn initialize(signer: Pubkey) -> Instruction {
|
||||
let config_address = config_pda().0;
|
||||
let market_address = market_pda().0;
|
||||
let board_address = board_pda().0;
|
||||
let mint_address = MINT_ADDRESS;
|
||||
let treasury_address = TREASURY_ADDRESS;
|
||||
let treasury_tokens_address = treasury_tokens_address();
|
||||
let vault_address = vault_address();
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(board_address, false),
|
||||
AccountMeta::new(config_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(mint_address, false),
|
||||
AccountMeta::new(treasury_address, false),
|
||||
AccountMeta::new(treasury_tokens_address, false),
|
||||
AccountMeta::new(vault_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
@@ -46,41 +32,41 @@ pub fn initialize(signer: Pubkey) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mine(signer: Pubkey, id: u64, nonce: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let miner_address = miner_pda(signer).0;
|
||||
let market_address = market_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Mine {
|
||||
nonce: nonce.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
// let [signer_info, square_info, system_program] = accounts else {
|
||||
|
||||
pub fn open(signer: Pubkey, id: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let market_address = market_pda().0;
|
||||
pub fn initialize_squares(signer: Pubkey) -> Instruction {
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new(square_pda(0).0, false),
|
||||
AccountMeta::new(square_pda(1).0, false),
|
||||
AccountMeta::new(square_pda(2).0, false),
|
||||
AccountMeta::new(square_pda(3).0, false),
|
||||
AccountMeta::new(square_pda(4).0, false),
|
||||
AccountMeta::new(square_pda(5).0, false),
|
||||
AccountMeta::new(square_pda(6).0, false),
|
||||
AccountMeta::new(square_pda(7).0, false),
|
||||
AccountMeta::new(square_pda(8).0, false),
|
||||
AccountMeta::new(square_pda(9).0, false),
|
||||
AccountMeta::new(square_pda(10).0, false),
|
||||
AccountMeta::new(square_pda(11).0, false),
|
||||
AccountMeta::new(square_pda(12).0, false),
|
||||
AccountMeta::new(square_pda(13).0, false),
|
||||
AccountMeta::new(square_pda(14).0, false),
|
||||
AccountMeta::new(square_pda(15).0, false),
|
||||
AccountMeta::new(square_pda(16).0, false),
|
||||
AccountMeta::new(square_pda(17).0, false),
|
||||
AccountMeta::new(square_pda(18).0, false),
|
||||
AccountMeta::new(square_pda(19).0, false),
|
||||
AccountMeta::new(square_pda(20).0, false),
|
||||
AccountMeta::new(square_pda(21).0, false),
|
||||
AccountMeta::new(square_pda(22).0, false),
|
||||
AccountMeta::new(square_pda(23).0, false),
|
||||
AccountMeta::new(square_pda(24).0, false),
|
||||
],
|
||||
data: Open {
|
||||
id: id.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
data: InitializeSquare {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,106 +93,63 @@ pub fn claim(signer: Pubkey, amount: u64) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close(signer: Pubkey, opener: Pubkey, winner: Pubkey, id: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let market_address = market_pda().0;
|
||||
let miner_address = miner_pda(winner).0;
|
||||
let miner_tokens_address = get_associated_token_address(&miner_address, &MINT_ADDRESS);
|
||||
// let [signer_info, board_info, mint_info, treasury_info, reserve_tokens_info, vault_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
|
||||
pub fn reset(signer: Pubkey, miners: Vec<Pubkey>) -> Instruction {
|
||||
let board_address = board_pda().0;
|
||||
let mint_address = MINT_ADDRESS;
|
||||
let treasury_address = TREASURY_ADDRESS;
|
||||
let treasury_tokens_address = treasury_tokens_address();
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new_readonly(market_address, false),
|
||||
AccountMeta::new(miner_tokens_address, false),
|
||||
AccountMeta::new(mint_address, false),
|
||||
AccountMeta::new(opener, false),
|
||||
AccountMeta::new(treasury_address, false),
|
||||
AccountMeta::new(treasury_tokens_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
|
||||
],
|
||||
data: Close {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
// let [signer_info, block_prev_info, block_next_info, config_info, market_info, mint_info, reserve_tokens_info, treasury_info, treasury_tokens_info, vault_info, system_program, token_program, ore_program, slot_hashes_sysvar] =
|
||||
|
||||
pub fn reset(signer: Pubkey, id: u64) -> Instruction {
|
||||
let block_prev_adddress = block_pda(id).0;
|
||||
let block_next_adddress = block_pda(id + 1).0;
|
||||
let config_address = config_pda().0;
|
||||
let market_address = market_pda().0;
|
||||
let mint_address = MINT_ADDRESS;
|
||||
let treasury_address = TREASURY_ADDRESS;
|
||||
let treasury_tokens_address = treasury_tokens_address();
|
||||
let reserve_tokens_address = BOOST_RESERVE_TOKEN;
|
||||
let vault_address = vault_address();
|
||||
let mut accounts = vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(board_address, false),
|
||||
AccountMeta::new(mint_address, false),
|
||||
AccountMeta::new(treasury_address, false),
|
||||
AccountMeta::new(reserve_tokens_address, false),
|
||||
AccountMeta::new(vault_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
];
|
||||
for miner in miners {
|
||||
if miner != Pubkey::default() {
|
||||
accounts.push(AccountMeta::new(miner_pda(miner).0, false));
|
||||
}
|
||||
}
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_prev_adddress, false),
|
||||
AccountMeta::new(block_next_adddress, false),
|
||||
AccountMeta::new_readonly(config_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(mint_address, false),
|
||||
AccountMeta::new(BOOST_RESERVE_TOKEN, false),
|
||||
AccountMeta::new(treasury_address, false),
|
||||
AccountMeta::new(treasury_tokens_address, false),
|
||||
AccountMeta::new(vault_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
accounts,
|
||||
data: Reset {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
// let [signer_info, block_info, config_info, fee_collector_info, market_info, miner_info, mint_info, tokens_info, vault_info, system_program, token_program, associated_token_program, ore_program] =
|
||||
|
||||
pub fn swap(
|
||||
signer: Pubkey,
|
||||
id: u64,
|
||||
fee_collector: Pubkey,
|
||||
amount: u64,
|
||||
direction: SwapDirection,
|
||||
precision: SwapPrecision,
|
||||
seed: [u8; 32],
|
||||
) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
// let [signer_info, board_info, config_info, fee_collector_info, miner_info, mint_info, sender_info, square_info, vault_info, system_program, token_program, associated_token_program] =
|
||||
|
||||
pub fn prospect(signer: Pubkey, fee_collector: Pubkey, amount: u64, square_id: u64) -> Instruction {
|
||||
let board_address = board_pda().0;
|
||||
let config_address = config_pda().0;
|
||||
let market_address = market_pda().0;
|
||||
let miner_address = miner_pda(signer).0;
|
||||
let tokens_address = get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
let sender_address = get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
let square_address = square_pda(square_id).0;
|
||||
let vault_address = vault_address();
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(board_address, false),
|
||||
AccountMeta::new(config_address, false),
|
||||
AccountMeta::new(fee_collector, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(tokens_address, false),
|
||||
AccountMeta::new(sender_address, false),
|
||||
AccountMeta::new(square_address, false),
|
||||
AccountMeta::new(vault_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
data: Swap {
|
||||
data: Prospect {
|
||||
amount: amount.to_le_bytes(),
|
||||
direction: direction as u8,
|
||||
precision: precision as u8,
|
||||
seed: seed,
|
||||
square_id: square_id.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
@@ -228,22 +171,6 @@ pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_block_duration(signer: Pubkey, block_duration: u64) -> Instruction {
|
||||
let config_address = config_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(config_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
],
|
||||
data: SetBlockDuration {
|
||||
block_duration: block_duration.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
|
||||
let config_address = config_pda().0;
|
||||
Instruction {
|
||||
@@ -260,38 +187,6 @@ pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_fee_rate(signer: Pubkey, fee_rate: u64) -> Instruction {
|
||||
let config_address = config_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(config_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
],
|
||||
data: SetFeeRate {
|
||||
fee_rate: fee_rate.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_sniper_fee_duration(signer: Pubkey, sniper_fee_duration: u64) -> Instruction {
|
||||
let config_address = config_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(config_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
],
|
||||
data: SetSniperFeeDuration {
|
||||
sniper_fee_duration: sniper_fee_duration.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn claim_seeker(signer: Pubkey, mint: Pubkey) -> Instruction {
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
|
||||
Reference in New Issue
Block a user