mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-16 07:26:51 +00:00
scaffolding
This commit is contained in:
137
api/src/sdk.rs
137
api/src/sdk.rs
@@ -1,19 +1,18 @@
|
||||
use meteora_pools_sdk::instructions::Swap;
|
||||
use spl_token::native_mint;
|
||||
use steel::*;
|
||||
|
||||
use crate::{instruction::*, state::*};
|
||||
use crate::{
|
||||
consts::{MINT_ADDRESS, TREASURY_ADDRESS, TREASURY_TOKENS_ADDRESS},
|
||||
instruction::*,
|
||||
state::*,
|
||||
};
|
||||
|
||||
pub fn bet(
|
||||
signer: Pubkey,
|
||||
mint: Pubkey,
|
||||
amount: u64,
|
||||
id: u64,
|
||||
round: u64,
|
||||
seed: Option<[u8; 32]>,
|
||||
) -> Instruction {
|
||||
pub fn bet(signer: Pubkey, mint: Pubkey, amount: u64, round: u64, seed: [u8; 32]) -> Instruction {
|
||||
let sender = spl_associated_token_account::get_associated_token_address(&signer, &mint);
|
||||
let block = block_pda().0;
|
||||
let block_bets = spl_associated_token_account::get_associated_token_address(&signer, &mint);
|
||||
let wager = wager_pda(round, id).0;
|
||||
let wager = wager_pda(round, seed).0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
@@ -22,14 +21,128 @@ pub fn bet(
|
||||
AccountMeta::new(block_bets, false),
|
||||
AccountMeta::new(sender, false),
|
||||
AccountMeta::new(wager, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
data: Bet {
|
||||
amount: amount.to_le_bytes(),
|
||||
seed: seed.unwrap_or([0; 32]),
|
||||
seed,
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bury(signer: Pubkey, swap: Swap) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
let block_bets = spl_associated_token_account::get_associated_token_address(
|
||||
&signer,
|
||||
&spl_token::native_mint::ID,
|
||||
);
|
||||
let block_ore =
|
||||
spl_associated_token_account::get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
// required accounts
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(block_bets, false),
|
||||
AccountMeta::new(block_ore, false),
|
||||
AccountMeta::new(spl_token::native_mint::ID, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
// swap accounts
|
||||
AccountMeta::new(swap.pool, false),
|
||||
AccountMeta::new(swap.user_source_token, false),
|
||||
AccountMeta::new(swap.user_destination_token, false),
|
||||
AccountMeta::new(swap.a_vault, false),
|
||||
AccountMeta::new(swap.b_vault, false),
|
||||
AccountMeta::new(swap.a_token_vault, false),
|
||||
AccountMeta::new(swap.b_token_vault, false),
|
||||
AccountMeta::new(swap.a_vault_lp_mint, false),
|
||||
AccountMeta::new(swap.b_vault_lp_mint, false),
|
||||
AccountMeta::new(swap.a_vault_lp, false),
|
||||
AccountMeta::new(swap.b_vault_lp, false),
|
||||
AccountMeta::new(swap.protocol_token_fee, false),
|
||||
AccountMeta::new_readonly(swap.vault_program, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(meteora_pools_sdk::programs::AMM_ID, false),
|
||||
],
|
||||
data: Close {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close(signer: Pubkey, wager: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(wager, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
],
|
||||
data: Close {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialize(signer: Pubkey, mint: Pubkey, ore_mint: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
let block_bets =
|
||||
spl_associated_token_account::get_associated_token_address(&signer, &native_mint::ID);
|
||||
let block_ore =
|
||||
spl_associated_token_account::get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(block_bets, false),
|
||||
AccountMeta::new(block_ore, false),
|
||||
AccountMeta::new(mint, false),
|
||||
AccountMeta::new(ore_mint, 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: Initialize {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn payout(signer: Pubkey, wager: Pubkey, recipient: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(wager, false),
|
||||
AccountMeta::new(recipient, 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(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
data: Payout {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(signer: Pubkey, boost_config: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
let boost_proof = proof_pda(boost_config).0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(boost_config, false),
|
||||
AccountMeta::new(boost_proof, false),
|
||||
],
|
||||
data: Reset {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,8 @@ pub fn proof_pda(authority: Pubkey) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id())
|
||||
}
|
||||
|
||||
pub fn wager_pda(round: u64, id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(
|
||||
&[WAGER, &round.to_le_bytes(), &id.to_le_bytes()],
|
||||
&crate::ID,
|
||||
)
|
||||
pub fn wager_pda(round: u64, seed: [u8; 32]) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[WAGER, &round.to_le_bytes(), &seed], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn treasury_pda() -> (Pubkey, u8) {
|
||||
|
||||
Reference in New Issue
Block a user