marginfi-cpi

Crates.iomarginfi-cpi
lib.rsmarginfi-cpi
version0.1.3
sourcesrc
created_at2022-07-30 14:07:45.539269
updated_at2022-08-07 09:34:11.602901
descriptionmarginfi CPI interface
homepage
repositoryhttps://github.com/mrgnlabs/marginfi-sdk/tree/main/rust/marginfi-cpi
max_upload_size
id635510
size63,210
man0s (losman0s)

documentation

https://docs.rs/marginfi-cpi

README

marginfi

License

marginfi.com

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.

Overview

This crate provides a CPI interface to the marginfi program. It leverages the anchor-gen tool to generate it from the program IDL.

Usage

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

Commit count: 0

cargo fmt