Crates.io | marginfi-cpi |
lib.rs | marginfi-cpi |
version | 0.1.3 |
source | src |
created_at | 2022-07-30 14:07:45.539269 |
updated_at | 2022-08-07 09:34:11.602901 |
description | marginfi CPI interface |
homepage | |
repository | https://github.com/mrgnlabs/marginfi-sdk/tree/main/rust/marginfi-cpi |
max_upload_size | |
id | 635510 |
size | 63,210 |
marginfi is a decentralized portfolio margining protocol for trading on Solana. The protocol gives traders a unified account to access margin, compose a portfolio, and improve capital efficiency across underlying trading protocols.
This crate provides a CPI interface to the marginfi program. It leverages the anchor-gen tool to generate it from the program IDL.
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod example_cpi {
use super::*;
/// -----------------------------------------------------------------------
/// INITIALIZE
/// -----------------------------------------------------------------------
#[derive(Accounts)]
pub struct InitializeAccount<'info> {
/// CHECK: no validation, for educational purpose only
pub marginfi_program: AccountInfo<'info>,
/// CHECK: no validation, for educational purpose only
pub marginfi_group: AccountInfo<'info>,
/// CHECK: no validation, for educational purpose only
#[account(zero)]
pub marginfi_account: AccountInfo<'info>,
#[account(mut)]
signer: Signer<'info>,
pub system_program: Program<'info, System>,
}
pub fn initialize_account(ctx: Context<InitializeAccount>) -> Result<()> {
let ctx = CpiContext::new(
ctx.accounts.marginfi_program.to_account_info(),
marginfi_cpi::cpi::accounts::InitMarginfiAccount {
authority: ctx.accounts.signer.to_account_info(),
marginfi_account: ctx.accounts.marginfi_account.to_account_info(),
marginfi_group: ctx.accounts.marginfi_group.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
},
);
marginfi_cpi::cpi::init_marginfi_account(ctx)?;
Ok(())
}
}
For a more complete example usage, check out the sample program