ore-legacy-api 0.1.0

Solana native store of value.
Documentation
use steel::{AccountMeta, Instruction, Pubkey};

use crate::{consts::*, prelude::*, state::*};

// Build claim instruction for ore v2 program.
pub fn ore_v2_claim(signer: Pubkey, amount: u64) -> Instruction {
    let proof_address = proof_pda(signer).0;
    let beneficiary_address =
        spl_associated_token_account::get_associated_token_address(&signer, &MINT_ADDRESS);
    Instruction {
        program_id: ORE_V2_PROGRAM_ID,
        accounts: vec![
            AccountMeta::new(signer, true),
            AccountMeta::new(beneficiary_address, false),
            AccountMeta::new(proof_address, false),
            AccountMeta::new_readonly(ORE_V2_TREASURY_ADDRESS, false),
            AccountMeta::new(ORE_V2_TREASURY_TOKENS_ADDRESS, false),
            AccountMeta::new_readonly(spl_token::ID, false),
        ],
        data: OREV2Claim {
            amount: amount.to_le_bytes(),
        }
        .to_bytes(),
    }
}

// Build claim instruction for pool program.
pub fn pool_claim(
    signer: Pubkey,
    beneficiary: Pubkey,
    pool_address: Pubkey,
    amount: u64,
) -> Instruction {
    let (member_pda, _) = member_pda(signer, pool_address);
    let (pool_proof_pda, _) = proof_pda(pool_address);
    let pool_tokens_address =
        spl_associated_token_account::get_associated_token_address(&pool_address, &MINT_ADDRESS);
    Instruction {
        program_id: POOL_PROGRAM_ID,
        accounts: vec![
            AccountMeta::new(signer, true),
            AccountMeta::new(beneficiary, false),
            AccountMeta::new(member_pda, false),
            AccountMeta::new(pool_address, false),
            AccountMeta::new(pool_tokens_address, false),
            AccountMeta::new(pool_proof_pda, false),
            AccountMeta::new_readonly(ORE_V2_TREASURY_ADDRESS, false),
            AccountMeta::new(ORE_V2_TREASURY_TOKENS_ADDRESS, false),
            AccountMeta::new_readonly(ORE_V2_PROGRAM_ID, false),
            AccountMeta::new_readonly(spl_token::ID, false),
        ],
        data: PoolClaim {
            amount: amount.to_le_bytes(),
            pool_bump: 0,
        }
        .to_bytes(),
    }
}

/// Builds an unstake instruction for legacy boost program.
pub fn pool_unstake(
    signer: Pubkey,
    mint: Pubkey,
    pool: Pubkey,
    recipient: Pubkey,
    amount: u64,
) -> Instruction {
    let (boost_pda, _) = boost_v1_pda(mint);
    let boost_tokens =
        spl_associated_token_account::get_associated_token_address(&boost_pda, &mint);
    let (member_pda, _) = member_pda(signer, pool);
    let pool_tokens = spl_associated_token_account::get_associated_token_address(&pool, &mint);
    let (share_pda, _) = share_pda(signer, pool, mint);
    let (stake_pda, _) = stake_v1_pda(pool, boost_pda);
    Instruction {
        program_id: POOL_PROGRAM_ID,
        accounts: vec![
            AccountMeta::new(signer, true),
            AccountMeta::new(boost_pda, false),
            AccountMeta::new(boost_tokens, false),
            AccountMeta::new_readonly(mint, false),
            AccountMeta::new_readonly(member_pda, false),
            AccountMeta::new(pool, false),
            AccountMeta::new(pool_tokens, false),
            AccountMeta::new(recipient, false),
            AccountMeta::new(share_pda, false),
            AccountMeta::new(stake_pda, false),
            AccountMeta::new_readonly(spl_token::ID, false),
            AccountMeta::new_readonly(BOOST_V1_PROGRAM_ID, false),
        ],
        data: PoolUnstake {
            amount: amount.to_le_bytes(),
        }
        .to_bytes(),
    }
}

// Build claim instruction.
pub fn boost_v2_claim(
    signer: Pubkey,
    beneficiary: Pubkey,
    mint: Pubkey,
    amount: u64,
) -> Instruction {
    let boost_address = boost_v2_pda(mint).0;
    let config_address = boost_v2_config_pda().0;
    let proof_address = proof_pda(config_address).0;
    let rewards_address =
        spl_associated_token_account::get_associated_token_address(&config_address, &MINT_ADDRESS);
    let stake_address = stake_v2_pda(signer, boost_address).0;
    Instruction {
        program_id: BOOST_V2_PROGRAM_ID,
        accounts: vec![
            AccountMeta::new(signer, true),
            AccountMeta::new(beneficiary, false),
            AccountMeta::new(boost_address, false),
            AccountMeta::new(config_address, false),
            AccountMeta::new(proof_address, false),
            AccountMeta::new(rewards_address, false),
            AccountMeta::new(stake_address, false),
            AccountMeta::new_readonly(ORE_V2_TREASURY_ADDRESS, false),
            AccountMeta::new(ORE_V2_TREASURY_TOKENS_ADDRESS, false),
            AccountMeta::new_readonly(ORE_V2_PROGRAM_ID, false),
            AccountMeta::new_readonly(spl_token::ID, false),
        ],
        data: BoostV2Claim {
            amount: amount.to_le_bytes(),
        }
        .to_bytes(),
    }
}

// Build withdraw instruction.
pub fn boost_v2_withdraw(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
    let boost_address = boost_v2_pda(mint).0;
    let config_address = boost_v2_config_pda().0;
    let deposits_address =
        spl_associated_token_account::get_associated_token_address(&boost_address, &mint);
    let proof_address = proof_pda(config_address).0;
    let rewards_address =
        spl_associated_token_account::get_associated_token_address(&config_address, &MINT_ADDRESS);
    let beneficiary_address =
        spl_associated_token_account::get_associated_token_address(&signer, &mint);
    let stake_address = stake_v2_pda(signer, boost_address).0;
    Instruction {
        program_id: BOOST_V2_PROGRAM_ID,
        accounts: vec![
            AccountMeta::new(signer, true),
            AccountMeta::new(beneficiary_address, false),
            AccountMeta::new(boost_address, false),
            AccountMeta::new(config_address, false),
            AccountMeta::new(deposits_address, false),
            AccountMeta::new_readonly(mint, false),
            AccountMeta::new(proof_address, false),
            AccountMeta::new(rewards_address, false),
            AccountMeta::new(stake_address, false),
            AccountMeta::new_readonly(ORE_V2_TREASURY_ADDRESS, false),
            AccountMeta::new(ORE_V2_TREASURY_TOKENS_ADDRESS, false),
            AccountMeta::new_readonly(ORE_V2_PROGRAM_ID, false),
            AccountMeta::new_readonly(spl_token::ID, false),
        ],
        data: BoostV2Withdraw {
            amount: amount.to_le_bytes(),
        }
        .to_bytes(),
    }
}