Skip to main content

solana_llm_oracle/
lib.rs

1pub mod constants;
2pub mod error;
3pub mod instructions;
4pub mod state;
5
6use anchor_lang::prelude::*;
7use ephemeral_rollups_sdk::anchor::ephemeral;
8
9use crate::state::AccountMeta;
10pub use constants::*;
11pub use instructions::*;
12pub use state::*;
13
14declare_id!("LLM4VF4uxgbcrUdwF9rBh7MUEypURp8FurEdZLhZqed");
15
16#[ephemeral]
17#[program]
18pub mod solana_llm_oracle {
19
20    use super::*;
21
22    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
23        ctx.accounts.initialize(&ctx.bumps)
24    }
25
26    pub fn create_chat(ctx: Context<CreateChat>, text: String, seed: u8) -> Result<()> {
27        ctx.accounts.create_new_chat(text, seed, &ctx.bumps)
28    }
29
30    pub fn create_llm_inference(
31        ctx: Context<CreateLlmInference>,
32        text: String,
33        callback_program_id: Pubkey,
34        callback_discriminator: [u8; 8],
35        account_metas: Option<Vec<AccountMeta>>,
36    ) -> Result<()> {
37        ctx.accounts.create_llm_inference(
38            text,
39            callback_program_id,
40            callback_discriminator,
41            account_metas,
42            &ctx.bumps,
43        )
44    }
45
46    pub fn delegate(ctx: Context<Delegate>) -> Result<()> {
47        ctx.accounts.delegate()
48    }
49
50    pub fn callback_from_llm<'info>(
51        ctx: Context<'_, '_, '_, 'info, CallbackFromLlm<'info>>,
52        response: String,
53    ) -> Result<()> {
54        // Check if payer is not in remaining accounts, oracle also sends callback_account_metas from client which are remaining accounts
55        if ctx
56            .remaining_accounts
57            .iter()
58            .any(|acc| acc.key().eq(&ctx.accounts.config.key()))
59        {
60            return Err(ProgramError::InvalidAccountData.into());
61        }
62        ctx.accounts
63            .callback_from_llm(response, ctx.remaining_accounts.to_vec())
64    }
65
66    pub fn callback_test(ctx: Context<CallbackTest>, response: String) -> Result<()> {
67        ctx.accounts.callback_test(response)
68    }
69}