60 个版本

0.1.22 2024年2月12日
0.1.20 2024年2月12日
0.1.1 2024年1月25日
0.0.31 2024年2月4日
0.0.8 2023年12月1日

#1792 in 魔法豆

Download history 70/week @ 2024-03-10 173/week @ 2024-03-31

每月355次下载

Apache-2.0

61KB
1.5K SLoC

juper

Rust jupiter API 客户端,通过 AnyIx 提供与链上代理的兼容 jupiter 交换。基于 rust-jup-ag

crates

juper_swap_api

juper_swap_api 是 mvine 的 rust-jup-ag 的重写分支,提供异步和阻塞客户端,以及简单的路由缓存。

juper_swap_cpi

警告:不正确地使用此功能,包括以下示例,将导致可利用的程序。必须谨慎实现,开发者不对任何使用此功能造成的财务损失承担责任

jupiter-cpi 的轻量级版本,旨在与 AnyIx 一起使用。它允许无缝集成 Jupiter 的交换 API 和您的程序,实现像通过 Jupiter 路由的保险库复利等操作,具有链上访问控制等。

用法

1) 链上程序

在您的链上程序中定义一个函数和一个类似以下指令的账户对象。


#[derive(Accounts)]
pub struct JupiterSwap<'info> {
    /// CHECK: not needed
    #[account(signer)]
    pub authority: AccountInfo<'info>,
    /// CHECK: not needed
    ///
    /// an account that can be used to read various access control settings, etc..
    /// this is intended to be used to restrict access to the `jupiter_swap` function
    pub management: AccountInfo<'info>,
    /// CHECK: not needed
    /// 
    /// an account that is used to read values related to ownership of the token accounts
    /// etc.. this can be used to validate that the token account owners of the jupiter swap
    /// accounts are owned by specific pdas, etc..
    pub vault: AccountInfo<'info>,
    /// CHECK: not needed
    /// 
    /// the actual jupiter program itself
    pub jupiter_program: AccountInfo<'info>,
}

/// all accounts required by this instruction except thos listed in `JupiterSwap`
/// are provided via remaining_accounts, use with caution.
pub fn jupiter_swap<'a, 'b, 'c, 'info>(
    mut ctx: Context<'a, 'b, 'c, 'info, JupiterSwap<'info>>,
    // this must be encoded in the AnyIx format
    input_data: Vec<u8>
) -> Result<()> {
    juper_swap_cpi::process_instructions(
        pda,
        &ctx.accounts.jupiter_program,
        &mut ctx.remaining_accounts.to_owned(),
        &input_data[..],
        None,
    )?;
    Ok(())
}

2) 链下调用

有关链下指令生成的示例,请参阅 crates/juper_swap_api

依赖关系

~75MB
~1.5M SLoC