mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
scaffold bury ix
This commit is contained in:
@@ -19,6 +19,7 @@ default = []
|
||||
|
||||
[dependencies]
|
||||
drillx.workspace = true
|
||||
meteora-pools-sdk.workspace = true
|
||||
mpl-token-metadata.workspace = true
|
||||
ore-api.workspace = true
|
||||
ore-boost-api.workspace = true
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn process_bet(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, wager_info, block_bets_info, sender_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
let [signer_info, block_info, block_bets_info, sender_info, wager_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
|
||||
69
program/src/bury.rs
Normal file
69
program/src/bury.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
use meteora_pools_sdk::instructions::{SwapCpi, SwapCpiAccounts, SwapInstructionArgs};
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
pub fn process_bury(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let (required_accounts, meteora_accounts) = accounts.split_at(5);
|
||||
let [signer_info, block_info, block_bets_info, block_ore_info, bet_mint_info, ore_mint_info] =
|
||||
required_accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?.has_address(&INITIALIZER_ADDRESS)?;
|
||||
block_info.as_account::<Block>(&ore_api::ID)?;
|
||||
let block_bets =
|
||||
block_bets_info.as_associated_token_account(block_info.key, bet_mint_info.key)?;
|
||||
block_ore_info.as_associated_token_account(block_info.key, &MINT_ADDRESS)?;
|
||||
bet_mint_info.as_mint()?;
|
||||
ore_mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
|
||||
// Load meteora accounts.
|
||||
let [pool_info, a_vault_info, b_vault_info, a_token_vault_info, b_token_vault_info, a_vault_lp_mint_info, b_vault_lp_mint_info, a_vault_lp_info, b_vault_lp_info, protocol_token_fee_info, vault_program_info, token_program_info, meteora_pools_program] =
|
||||
meteora_accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
meteora_pools_program.is_program(&meteora_pools_sdk::programs::AMM_ID)?;
|
||||
|
||||
// Execute swap.
|
||||
let swap = SwapCpi::new(
|
||||
&meteora_pools_program,
|
||||
SwapCpiAccounts {
|
||||
pool: pool_info,
|
||||
user_source_token: block_bets_info,
|
||||
user_destination_token: block_ore_info,
|
||||
a_vault: a_vault_info,
|
||||
b_vault: b_vault_info,
|
||||
a_token_vault: a_token_vault_info,
|
||||
b_token_vault: b_token_vault_info,
|
||||
a_vault_lp_mint: a_vault_lp_mint_info,
|
||||
b_vault_lp_mint: b_vault_lp_mint_info,
|
||||
a_vault_lp: a_vault_lp_info,
|
||||
b_vault_lp: b_vault_lp_info,
|
||||
protocol_token_fee: protocol_token_fee_info,
|
||||
user: block_info,
|
||||
vault_program: vault_program_info,
|
||||
token_program: token_program_info,
|
||||
},
|
||||
SwapInstructionArgs {
|
||||
in_amount: block_bets.amount(),
|
||||
minimum_out_amount: 0, // TODO: Calculate minimum out amount with slippage
|
||||
},
|
||||
);
|
||||
let block_bump = block_pda().1;
|
||||
swap.invoke_signed(&[&[BLOCK, &[block_bump]]])?;
|
||||
|
||||
// Burn (bury) the purchased ORE.
|
||||
let block_ore = block_ore_info.as_associated_token_account(block_info.key, &MINT_ADDRESS)?;
|
||||
burn_signed(
|
||||
block_ore_info,
|
||||
ore_mint_info,
|
||||
block_info,
|
||||
token_program_info,
|
||||
block_ore.amount(),
|
||||
&[BLOCK, &[block_bump]],
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use steel::*;
|
||||
/// Initialize sets up the ORE program to begin mining.
|
||||
pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let [signer_info, block_info, block_bets_info, sol_mint_info, system_program, token_program, associated_token_program] =
|
||||
let [signer_info, block_info, block_bets_info, block_ore_info, ore_mint_info, sol_mint_info, system_program, token_program, associated_token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -15,6 +15,8 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
.is_writable()?
|
||||
.has_seeds(&[BLOCK], &ore_api::ID)?;
|
||||
block_bets_info.is_empty()?.is_writable()?;
|
||||
block_ore_info.is_empty()?.is_writable()?;
|
||||
ore_mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
sol_mint_info
|
||||
.has_address(&spl_token::native_mint::ID)?
|
||||
.as_mint()?;
|
||||
@@ -41,7 +43,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
block.reward = 0;
|
||||
block.noise = [0; 32];
|
||||
|
||||
// Initialize treasury token account.
|
||||
// Initialize block token accounts.
|
||||
create_associated_token_account(
|
||||
signer_info,
|
||||
block_info,
|
||||
@@ -51,6 +53,15 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
token_program,
|
||||
associated_token_program,
|
||||
)?;
|
||||
create_associated_token_account(
|
||||
signer_info,
|
||||
block_info,
|
||||
block_ore_info,
|
||||
ore_mint_info,
|
||||
system_program,
|
||||
token_program,
|
||||
associated_token_program,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
mod bet;
|
||||
mod bury;
|
||||
mod close;
|
||||
mod initialize;
|
||||
mod payout;
|
||||
mod reset;
|
||||
|
||||
use bet::*;
|
||||
use bury::*;
|
||||
use close::*;
|
||||
use initialize::*;
|
||||
use payout::*;
|
||||
@@ -22,6 +24,7 @@ pub fn process_instruction(
|
||||
|
||||
match ix {
|
||||
OreInstruction::Bet => process_bet(accounts, data)?,
|
||||
OreInstruction::Bury => process_bury(accounts, data)?,
|
||||
OreInstruction::Close => process_close(accounts, data)?,
|
||||
OreInstruction::Reset => process_reset(accounts, data)?,
|
||||
OreInstruction::Initialize => process_initialize(accounts, data)?,
|
||||
|
||||
@@ -26,6 +26,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?;
|
||||
|
||||
// Load boost accounts.
|
||||
let [boost_config_info, boost_proof_info] = boost_accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user