#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(deprecated)]
use anchor_lang::prelude::*;
use state::{NetworkState, OraoTokenFeeConfig, Randomness, RandomnessV2};
pub use crate::error::Error;
pub mod error;
pub mod events;
pub mod state;
mod sdk;
#[cfg(feature = "sdk")]
pub use crate::sdk::*;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
declare_id!("VRFzZoJdhFWL8rkvu87LpKM3RbcVezpMEc6X5GVDr7y");
pub const RANDOMNESS_ACCOUNT_SEED: &[u8] = b"orao-vrf-randomness-request";
pub const CONFIG_ACCOUNT_SEED: &[u8] = b"orao-vrf-network-configuration";
pub const MAX_FULFILLMENT_AUTHORITIES_COUNT: usize = 10;
pub fn network_state_account_address(vrf_id: &Pubkey) -> Pubkey {
Pubkey::find_program_address(&[CONFIG_ACCOUNT_SEED], vrf_id).0
}
pub fn randomness_account_address(vrf_id: &Pubkey, seed: &[u8; 32]) -> Pubkey {
Pubkey::find_program_address(&[RANDOMNESS_ACCOUNT_SEED, &seed[..]], vrf_id).0
}
pub fn xor_array<const N: usize>(l: &mut [u8; N], r: &[u8; N]) {
for i in 0..N {
l[i] ^= r[i];
}
}
pub const fn quorum(count: usize, total: usize) -> bool {
count >= majority(total)
}
pub const fn majority(total: usize) -> usize {
total * 2 / 3 + 1
}
#[allow(unused_variables)]
#[program]
pub mod orao_vrf {
use super::*;
pub fn init_network(
ctx: Context<InitNetwork>,
fee: u64,
config_authority: Pubkey,
fulfillment_authorities: Vec<Pubkey>,
token_fee_config: Option<OraoTokenFeeConfig>,
) -> Result<()> {
Ok(())
}
pub fn update_network(
ctx: Context<UpdateNetwork>,
fee: u64,
config_authority: Pubkey,
fulfillment_authorities: Vec<Pubkey>,
token_fee_config: Option<OraoTokenFeeConfig>,
) -> Result<()> {
Ok(())
}
pub fn request<'info>(
ctx: Context<'_, '_, '_, 'info, Request<'info>>,
seed: [u8; 32],
) -> Result<()> {
Ok(())
}
pub fn fulfill(ctx: Context<Fulfill>) -> Result<()> {
Ok(())
}
pub fn request_v2<'info>(
ctx: Context<'_, '_, '_, 'info, RequestV2<'info>>,
seed: [u8; 32],
) -> Result<()> {
Ok(())
}
pub fn fulfill_v2(ctx: Context<FulfillV2>) -> Result<()> {
Ok(())
}
}
#[derive(Accounts)]
pub struct InitNetwork<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(
init,
payer = payer,
space = 8 + 464,
seeds = [CONFIG_ACCOUNT_SEED],
bump,
)]
pub network_state: Account<'info, NetworkState>,
pub treasury: AccountInfo<'info>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct UpdateNetwork<'info> {
#[account(mut)]
pub authority: Signer<'info>,
#[account(
mut,
seeds = [CONFIG_ACCOUNT_SEED],
bump,
constraint = network_state.config.authority == authority.key(),
)]
pub network_state: Account<'info, NetworkState>,
pub treasury: AccountInfo<'info>,
}
#[derive(Accounts)]
#[instruction(seed: [u8; 32])]
#[deprecated(since = "0.4.0", note = "See RequestV2")]
pub struct Request<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(
mut,
seeds = [CONFIG_ACCOUNT_SEED],
bump,
)]
pub network_state: Account<'info, NetworkState>,
#[account(
mut,
constraint = network_state.config.treasury == treasury.key() ||
network_state.config.token_fee_config.as_ref().map(|x| x.treasury) == Some(treasury.key())
@ Error::UnknownTreasuryGiven)]
pub treasury: AccountInfo<'info>,
#[account(
init,
payer = payer,
space = 8 + Randomness::SIZE,
seeds = [RANDOMNESS_ACCOUNT_SEED, &seed],
bump,
)]
pub request: Account<'info, Randomness>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
#[deprecated(since = "0.4.0", note = "See FulfillV2")]
pub struct Fulfill<'info> {
#[account(mut)]
pub payer: Signer<'info>,
pub instruction_acc: AccountInfo<'info>,
#[account(
mut,
seeds = [CONFIG_ACCOUNT_SEED],
bump,
)]
pub network_state: Account<'info, NetworkState>,
#[account(
mut,
seeds = [RANDOMNESS_ACCOUNT_SEED, &request.seed],
bump,
)]
pub request: Account<'info, Randomness>,
}
#[derive(Accounts)]
#[instruction(seed: [u8; 32])]
pub struct RequestV2<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(
mut,
seeds = [CONFIG_ACCOUNT_SEED],
bump,
)]
pub network_state: Account<'info, NetworkState>,
#[account(
mut,
constraint = network_state.config.treasury == treasury.key() ||
network_state.config.token_fee_config.as_ref().map(|x| x.treasury) == Some(treasury.key())
@ Error::UnknownTreasuryGiven)]
pub treasury: AccountInfo<'info>,
#[account(
init,
payer = payer,
space = 8 + RandomnessV2::PENDING_SIZE,
seeds = [RANDOMNESS_ACCOUNT_SEED, &seed],
bump,
)]
pub request: Account<'info, RandomnessV2>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct FulfillV2<'info> {
#[account(mut)]
pub payer: Signer<'info>,
pub instruction_acc: AccountInfo<'info>,
#[account(
mut,
seeds = [CONFIG_ACCOUNT_SEED],
bump,
)]
pub network_state: Account<'info, NetworkState>,
#[account(
mut,
seeds = [RANDOMNESS_ACCOUNT_SEED, request.seed()],
bump,
)]
pub request: Account<'info, RandomnessV2>,
#[account(mut, constraint = *request.client() == client.key())]
pub client: AccountInfo<'info>,
pub system_program: Program<'info, System>,
}