Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uxdprotocol/anchor-comp
Anchor wrapper for interacting with the raw Solana program
https://github.com/uxdprotocol/anchor-comp
anchor mangomarkets solana
Last synced: about 1 month ago
JSON representation
Anchor wrapper for interacting with the raw Solana program
- Host: GitHub
- URL: https://github.com/uxdprotocol/anchor-comp
- Owner: UXDProtocol
- Created: 2022-02-23T02:40:33.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-15T11:54:58.000Z (about 2 years ago)
- Last Synced: 2023-03-03T22:48:18.277Z (almost 2 years ago)
- Topics: anchor, mangomarkets, solana
- Language: Rust
- Homepage:
- Size: 138 KB
- Stars: 19
- Watchers: 0
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# anchor-comp
Anchor wrapper for non anchor program. In v3, contains:
- SplGovernanceV3 Solana program.
Follows structure of and
## Usage
```toml
[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
```rust
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,
) -> 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)
}// ...
}```