mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-20 07:26:50 +00:00
proof of wager
This commit is contained in:
135
api/src/sdk.rs
135
api/src/sdk.rs
@@ -1,136 +1,3 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::{consts::*, instruction::*, state::proof_pda};
|
||||
|
||||
/// Builds a claim instruction.
|
||||
pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction {
|
||||
let proof = proof_pda(signer).0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(beneficiary, false),
|
||||
AccountMeta::new(proof, false),
|
||||
AccountMeta::new_readonly(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
],
|
||||
data: Claim {
|
||||
amount: amount.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds a close instruction.
|
||||
pub fn close(signer: Pubkey) -> Instruction {
|
||||
let proof = proof_pda(signer).0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(proof, false),
|
||||
AccountMeta::new_readonly(solana_program::system_program::ID, false),
|
||||
],
|
||||
data: Close {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds a mine instruction.
|
||||
pub fn mine(
|
||||
signer: Pubkey,
|
||||
authority: Pubkey,
|
||||
bus: Pubkey,
|
||||
nonce: u64,
|
||||
boost_config: Pubkey,
|
||||
) -> Instruction {
|
||||
let proof = proof_pda(authority).0;
|
||||
let accounts = vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(bus, false),
|
||||
AccountMeta::new_readonly(CONFIG_ADDRESS, false),
|
||||
AccountMeta::new(proof, false),
|
||||
AccountMeta::new_readonly(sysvar::instructions::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
AccountMeta::new_readonly(boost_config, false),
|
||||
AccountMeta::new(proof_pda(boost_config).0, false),
|
||||
];
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts,
|
||||
data: Mine {
|
||||
// digest: solution.d,
|
||||
nonce: nonce.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds an open instruction.
|
||||
pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction {
|
||||
let proof_pda = proof_pda(signer);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new_readonly(miner, false),
|
||||
AccountMeta::new(payer, true),
|
||||
AccountMeta::new(proof_pda.0, false),
|
||||
AccountMeta::new_readonly(solana_program::system_program::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
data: Open {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds a reset instruction.
|
||||
pub fn reset(signer: Pubkey, best_proof: Pubkey) -> Instruction {
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(CONFIG_ADDRESS, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(best_proof, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
],
|
||||
data: Reset {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
// Build an update instruction.
|
||||
pub fn update(signer: Pubkey, miner: Pubkey) -> Instruction {
|
||||
let proof = proof_pda(signer).0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new_readonly(miner, false),
|
||||
AccountMeta::new(proof, false),
|
||||
],
|
||||
data: Update {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
// Builds an initialize instruction.
|
||||
pub fn initialize(signer: Pubkey) -> Instruction {
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(CONFIG_ADDRESS, false),
|
||||
AccountMeta::new(METADATA_ADDRESS, false),
|
||||
AccountMeta::new(MINT_ADDRESS, 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),
|
||||
AccountMeta::new_readonly(mpl_token_metadata::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::rent::ID, false),
|
||||
],
|
||||
data: Initialize {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
use crate::{consts::*, instruction::*, state::*};
|
||||
|
||||
Reference in New Issue
Block a user