Giter Club home page Giter Club logo

anchor-comp's Introduction

anchor-comp

Anchor wrapper for additional non mango program not part of the SPL library.

MangoMarketV3 Solana program.

Follows structure of https://github.com/project-serum/anchor/blob/master/spl/src/dex.rs and https://github.com/project-serum/anchor/blob/master/spl/src/token.rs

Usage

[dependencies]
anchor-comp = { version = "0.1.0", git = "https://github.com/UXDProtocol/anchor-comp", features = ["no-entrypoint", "development"] }
# anchor-comp = { version = "0.1.0", git = "https://github.com/UXDProtocol/anchor-comp", features = ["no-entrypoint", "production"] }

Example CPI from Rust Solana program

    use anchor_comp::mango_markets_v3;
    use anchor_comp::mango_markets_v3::MangoMarketV3;

    #[derive(Accounts)]
    pub struct MyInstruction<'info> {

        // ...

        pub mango_program: Program<'info, MangoMarketV3>,
    }

    pub fn my_instruction(
        ctx: Context<MyInstruction>,
    ) -> Result<()> {

        // ...

        // - [MangoMarkets CPI - Place perp order]
        mango_markets_v3::place_perp_order2(
            ctx.accounts
                .into_open_mango_short_perp_context()
                .with_signer(depository_pda_signer),
            taker_side,
            limit_price_lot.to_num(),
            max_base_quantity.to_num(),
            i64::MAX,
            0,
            OrderType::ImmediateOrCancel,
            false,
            None,
            10,
        )?;

        // ...
    }


    impl<'info> MyInstruction<'info> {

        // ...

        pub fn into_open_mango_short_perp_context(
            &self,
        ) -> CpiContext<'_, '_, '_, 'info, mango_markets_v3::PlacePerpOrder2<'info>> {
            let cpi_accounts = mango_markets_v3::PlacePerpOrder2 {
                mango_group: self.mango_group.to_account_info(),
                mango_account: self.depository_mango_account.to_account_info(),
                owner: self.depository.to_account_info(),
                mango_cache: self.mango_cache.to_account_info(),
                perp_market: self.mango_perp_market.to_account_info(),
                bids: self.mango_bids.to_account_info(),
                asks: self.mango_asks.to_account_info(),
                event_queue: self.mango_event_queue.to_account_info(),
            };
            let cpi_program = self.mango_program.to_account_info();
            CpiContext::new(cpi_program, cpi_accounts)
        }
        
        // ...
    }

anchor-comp's People

Contributors

acamill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.