From fa07a57c9d2ca21c5c4b1a61beea1829ea39b3a2 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Wed, 1 Feb 2023 13:56:11 +1000 Subject: [PATCH 01/22] refresh as per latest zeta-options state --- Cargo.toml | 5 +-- src/context.rs | 106 ++++++++++++++++++++++++----------------------- src/cpi.rs | 22 ++++++++++ src/dex.rs | 22 +--------- src/id.rs | 12 ------ src/lib.rs | 12 +++--- src/types.rs | 90 ++++++++++++---------------------------- src/zeta_keys.rs | 67 ------------------------------ 8 files changed, 111 insertions(+), 225 deletions(-) create mode 100644 src/cpi.rs delete mode 100644 src/zeta_keys.rs diff --git a/Cargo.toml b/Cargo.toml index da0b63b..18821c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,4 @@ anchor-spl = "0.24.2" solana-program = "1.9.13" bytemuck = { version = "1.4.0" } rust_decimal = { git = "https://github.com/zetamarkets/rust-decimal.git", features = ["maths"] } -pyth-sdk-solana = "0.4.1" -serde = "1" -serde_json = "1" -anyhow = "1.0.66" +chainlink_solana = "1.0.0" diff --git a/src/context.rs b/src/context.rs index 5e7342b..17082c9 100644 --- a/src/context.rs +++ b/src/context.rs @@ -9,55 +9,21 @@ pub struct InitializeMarginAccount<'info> { pub payer: Signer<'info>, pub zeta_program: Program<'info, id::ZetaProgram>, pub system_program: Program<'info, System>, - pub zeta_group: AccountLoader<'info, ZetaGroup>, -} - -#[derive(Accounts)] -pub struct Withdraw<'info> { - pub state: AccountLoader<'info, State>, - pub zeta_group: AccountLoader<'info, ZetaGroup>, - #[account(mut)] - pub vault: UncheckedAccount<'info>, - #[account(mut)] - pub margin_account: AccountLoader<'info, MarginAccount>, - #[account(mut)] - pub user_token_account: UncheckedAccount<'info>, - pub token_program: Program<'info, Token>, - pub authority: Signer<'info>, - pub greeks: AccountLoader<'info, Greeks>, - pub oracle: UncheckedAccount<'info>, - #[account(mut)] - pub socialized_loss_account: UncheckedAccount<'info>, -} - -#[derive(Accounts)] -pub struct Deposit<'info> { - pub zeta_group: AccountLoader<'info, ZetaGroup>, - #[account(mut)] - pub margin_account: AccountLoader<'info, MarginAccount>, - #[account(mut)] - pub vault: UncheckedAccount<'info>, - #[account(mut)] - pub user_token_account: UncheckedAccount<'info>, - #[account(mut)] - pub socialized_loss_account: UncheckedAccount<'info>, - pub authority: Signer<'info>, - pub token_program: Program<'info, Token>, - pub state: AccountLoader<'info, State>, - pub greeks: AccountLoader<'info, Greeks>, + pub zeta_group: UncheckedAccount<'info>, } #[derive(Accounts)] pub struct InitializeOpenOrders<'info> { pub state: AccountLoader<'info, State>, pub zeta_group: AccountLoader<'info, ZetaGroup>, - pub dex_program: Program<'info, id::Dex>, + pub dex_program: Program<'info, cpi::Dex>, pub system_program: Program<'info, System>, #[account(mut)] pub open_orders: UncheckedAccount<'info>, #[account(mut)] pub margin_account: AccountLoader<'info, MarginAccount>, pub authority: Signer<'info>, + // Marked mutable since it pays #[account(mut)] pub payer: Signer<'info>, pub market: UncheckedAccount<'info>, @@ -74,19 +40,21 @@ pub struct PlaceOrder<'info> { #[account(mut)] pub margin_account: AccountLoader<'info, MarginAccount>, pub authority: Signer<'info>, - pub dex_program: Program<'info, id::Dex>, + pub dex_program: Program<'info, cpi::Dex>, pub token_program: Program<'info, Token>, - pub serum_authority: UncheckedAccount<'info>, + pub serum_authority: AccountInfo<'info>, pub greeks: AccountLoader<'info, Greeks>, #[account(mut)] - pub open_orders: UncheckedAccount<'info>, + pub open_orders: AccountInfo<'info>, pub rent: Sysvar<'info, Rent>, pub market_accounts: MarketAccounts<'info>, pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, cpi::Chainlink>, #[account(mut)] pub market_node: UncheckedAccount<'info>, #[account(mut)] - pub market_mint: UncheckedAccount<'info>, + pub market_mint: Box>, pub mint_authority: UncheckedAccount<'info>, } @@ -97,26 +65,61 @@ pub struct PlacePerpOrder<'info> { #[account(mut)] pub margin_account: AccountLoader<'info, MarginAccount>, pub authority: Signer<'info>, - // Programs. - pub dex_program: Program<'info, id::Dex>, + pub dex_program: Program<'info, cpi::Dex>, pub token_program: Program<'info, Token>, - // Serum authority - pub serum_authority: UncheckedAccount<'info>, + pub serum_authority: AccountInfo<'info>, pub greeks: AccountLoader<'info, Greeks>, #[account(mut)] - pub open_orders: UncheckedAccount<'info>, + pub open_orders: AccountInfo<'info>, pub rent: Sysvar<'info, Rent>, pub market_accounts: MarketAccounts<'info>, pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, cpi::Chainlink>, #[account(mut)] - pub market_node: UncheckedAccount<'info>, - #[account(mut)] - pub market_mint: UncheckedAccount<'info>, + pub market_mint: Box>, pub mint_authority: UncheckedAccount<'info>, #[account(mut)] pub perp_sync_queue: UncheckedAccount<'info>, } +#[derive(Accounts)] +pub struct Deposit<'info> { + pub zeta_group: AccountLoader<'info, ZetaGroup>, + #[account(mut)] + pub margin_account: AccountLoader<'info, MarginAccount>, + #[account(mut)] + pub vault: Box>, + #[account(mut)] + pub user_token_account: Box>, + #[account(mut)] + pub socialized_loss_account: UncheckedAccount<'info>, + pub authority: Signer<'info>, + pub token_program: Program<'info, Token>, + pub state: AccountLoader<'info, State>, + pub greeks: AccountLoader<'info, Greeks>, +} + +#[derive(Accounts)] +#[instruction(amount: u64)] +pub struct Withdraw<'info> { + pub state: AccountLoader<'info, State>, + pub zeta_group: AccountLoader<'info, ZetaGroup>, + #[account(mut)] + pub vault: Box>, + #[account(mut)] + pub margin_account: AccountLoader<'info, MarginAccount>, + #[account(mut)] + pub user_token_account: Box>, + pub token_program: Program<'info, Token>, + pub authority: Signer<'info>, + pub greeks: AccountLoader<'info, Greeks>, + pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, cpi::Chainlink>, + #[account(mut)] + pub socialized_loss_account: UncheckedAccount<'info>, +} #[derive(Accounts)] pub struct CancelOrder<'info> { pub authority: Signer<'info>, @@ -125,7 +128,7 @@ pub struct CancelOrder<'info> { #[derive(Accounts)] pub struct ForceCancelOrders<'info> { - pub greeks: AccountLoader<'info, Greeks>, + pub greeks: UncheckedAccount<'info>, pub oracle: UncheckedAccount<'info>, pub cancel_accounts: CancelAccounts<'info>, } @@ -188,7 +191,7 @@ pub struct CancelAccounts<'info> { pub state: AccountLoader<'info, State>, #[account(mut)] pub margin_account: AccountLoader<'info, MarginAccount>, - pub dex_program: Program<'info, id::Dex>, + pub dex_program: Program<'info, cpi::Dex>, pub serum_authority: UncheckedAccount<'info>, #[account(mut)] pub open_orders: UncheckedAccount<'info>, @@ -200,5 +203,4 @@ pub struct CancelAccounts<'info> { pub asks: UncheckedAccount<'info>, #[account(mut)] pub event_queue: UncheckedAccount<'info>, - pub oracle: UncheckedAccount<'info>, } diff --git a/src/cpi.rs b/src/cpi.rs new file mode 100644 index 0000000..df65aed --- /dev/null +++ b/src/cpi.rs @@ -0,0 +1,22 @@ +use crate::*; + +#[derive(Clone)] +pub struct Dex; + +impl anchor_lang::Id for Dex { + fn id() -> Pubkey { + match cfg!(feature = "mainnet") { + true => pubkey!("zDEXqXEG7gAyxb1Kg9mK5fPnUdENCGKzWrM21RMdWRq"), + false => pubkey!("5CmWtUihvSrJpaUrpJ3H1jUa9DRjYz4v2xs6c3EgQWMf"), + } + } +} + +#[derive(Clone)] +pub struct Chainlink; + +impl anchor_lang::Id for Chainlink { + fn id() -> Pubkey { + chainlink_solana::ID + } +} diff --git a/src/dex.rs b/src/dex.rs index ec2d426..33b26b4 100644 --- a/src/dex.rs +++ b/src/dex.rs @@ -1,7 +1,5 @@ use crate::*; -use bytemuck::try_from_bytes; - #[cfg(target_endian = "little")] unsafe impl Zeroable for MarketStateV2 {} @@ -9,6 +7,7 @@ unsafe impl Zeroable for MarketStateV2 {} unsafe impl Pod for MarketStateV2 {} #[derive(Copy, Clone)] +#[allow(dead_code)] #[cfg_attr(target_endian = "little", derive(Debug))] #[repr(packed)] pub struct MarketStateV2 { @@ -91,25 +90,6 @@ pub struct MarketState { pub referrer_rebates_accrued: u64, } -impl MarketStateV2 { - pub fn deserialize(buf: &[u8]) -> Result { - const FLAGS: u64 = (AccountFlag::Initialized as u64) - | (AccountFlag::Market as u64) - | (AccountFlag::Permissioned as u64); - - let r: &Self = bytemuck::try_from_bytes(buf).unwrap(); - - if r._head_pad[..] != *"serum".as_bytes() - || r._tail_pad[..] != *"padding".as_bytes() - || r.inner.account_flags != FLAGS - { - panic!("Invalid buffer for market"); - } - - Ok(*r) - } -} - #[derive(Copy, Clone, Debug)] #[repr(u64)] pub enum AccountFlag { diff --git a/src/id.rs b/src/id.rs index 65169a6..6115785 100644 --- a/src/id.rs +++ b/src/id.rs @@ -13,15 +13,3 @@ impl anchor_lang::Id for ZetaProgram { ID } } - -#[derive(Clone)] -pub struct Dex; - -impl anchor_lang::Id for Dex { - fn id() -> Pubkey { - match cfg!(feature = "mainnet") { - true => pubkey!("zDEXqXEG7gAyxb1Kg9mK5fPnUdENCGKzWrM21RMdWRq"), - false => pubkey!("5CmWtUihvSrJpaUrpJ3H1jUa9DRjYz4v2xs6c3EgQWMf"), - } - } -} diff --git a/src/lib.rs b/src/lib.rs index f7efb9b..8c4a70f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,21 +1,21 @@ use anchor_lang::prelude::*; -use anchor_spl::token::Token; +use anchor_spl::token::{Mint, Token, TokenAccount}; use rust_decimal::prelude::*; use solana_program::pubkey; extern crate self as zeta_abi; pub mod context; +pub mod cpi; pub mod dex; pub mod id; pub mod types; -pub mod zeta_keys; pub use crate::context::*; +pub use crate::cpi::*; pub use crate::dex::*; pub use crate::id::*; pub use crate::types::*; -pub use crate::zeta_keys::*; use bytemuck::{Pod, Zeroable}; @@ -43,7 +43,7 @@ mod zeta { Ok(()) } - pub(crate) fn place_order_v3( + pub(crate) fn place_order_v4( ctx: Context, price: u64, size: u64, @@ -51,11 +51,12 @@ mod zeta { order_type: OrderType, client_order_id: Option, tag: Option, // Not stored, only used when sniffing the transactions + tif_offset: Option, ) -> Result<()> { Ok(()) } - pub(crate) fn place_perp_order( + pub(crate) fn place_perp_order_v2( ctx: Context, price: u64, size: u64, @@ -63,6 +64,7 @@ mod zeta { order_type: OrderType, client_order_id: Option, tag: Option, // Not stored, only used when sniffing the transactions + tif_offset: Option, ) -> Result<()> { Ok(()) } diff --git a/src/types.rs b/src/types.rs index 9d46256..e3a8ab7 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,13 +1,9 @@ -use crate::*; +#![allow(dead_code)] -use serde::Serialize; -use serde_json; -use std::fmt; -use std::slice::Iter; +use crate::*; #[account(zero_copy)] #[repr(packed)] -#[derive(Serialize, Debug)] pub struct State { // Admin authority pub admin: Pubkey, // 32 @@ -32,11 +28,8 @@ pub struct State { pub native_option_underlying_fee_percentage: u64, // 8 pub referrals_admin: Pubkey, // 32 pub referrals_rewards_wallet_nonce: u8, // 1 - pub _p1: [u8; 32], // 107 - pub _p2: [u8; 32], // 107 - pub _p3: [u8; 32], // 107 - pub _p4: [u8; 11], // 107 -} + pub _padding: [u8; 107], // 107 +} // 255 #[account(zero_copy)] #[repr(packed)] @@ -61,10 +54,11 @@ pub struct ZetaGroup { pub asset: Asset, // 1 pub expiry_interval_seconds: u32, // 4 pub new_expiry_threshold_seconds: u32, // 4 - pub perp_parameters: PerpParameters, // 56 + pub perp_parameters: PerpParameters, // 24 pub perp_sync_queue: Pubkey, // 32 + pub oracle_backup_feed: Pubkey, // 32 pub padding: [u8; 966], // 966 -} +} // 7696 #[zero_copy] #[repr(packed)] @@ -76,11 +70,10 @@ pub struct Product { // Tracks whether the market has been wiped after expiration pub dirty: bool, pub kind: Kind, -} +} // 32 + 9 + 1 + 1 = 43 bytes #[zero_copy] #[repr(packed)] -#[allow(dead_code)] #[derive(Debug)] pub struct Strike { is_set: bool, @@ -135,8 +128,7 @@ pub struct PerpParameters { pub min_funding_rate_percent: i64, // 8 pub max_funding_rate_percent: i64, // 8 pub impact_cash_delta: u64, // 8 - pub padding: [u8; 32], -} // 56 +} // 24 #[zero_copy] #[repr(packed)] @@ -164,9 +156,10 @@ pub struct MarginAccount { pub rebalance_amount: i64, // 8 pub asset: Asset, // 1 pub account_type: MarginAccountType, // 1 - pub last_funding_delta: i128, // 16 - pub _padding: [u8; 370], // 370 -} + pub last_funding_delta: AnchorDecimal, // 16 + pub delegated_pubkey: Pubkey, // 32 + pub _padding: [u8; 338], // 338 +} // 6144 #[zero_copy] #[derive(Default, Debug)] @@ -189,11 +182,11 @@ pub struct AnchorDecimal { #[account(zero_copy)] #[repr(packed)] -#[derive(Debug)] pub struct Greeks { pub nonce: u8, // 1 pub mark_prices: [u64; 46], // 8 * 46 = 368 - pub _mark_prices_padding: [u64; 92], // 8 * 92 = 736 + pub _mark_prices_padding: [u64; 91], // 8 * 91 = 728 + pub perp_mark_price: u64, // 8 pub product_greeks: [ProductGreeks; 22], // 22 * 40 = 880 pub _product_greeks_padding: [ProductGreeks; 44], // 44 * 40 = 1760 pub update_timestamp: [u64; 2], // 16 @@ -206,13 +199,13 @@ pub struct Greeks { pub volatility: [u64; 10], // 80 pub _volatility_padding: [u64; 20], // 160 pub node_keys: [Pubkey; 138], // 138 * 32 = 4416 - pub halt_force_pricing: [bool; 5], // 5 - pub halt_force_perp_pricing: bool, // 1 + pub halt_force_pricing: [bool; 6], // 6 pub perp_update_timestamp: u64, // 8 - pub perp_funding_delta: i128, // 16 - pub perp_latest_funding_rate: i128, // 16 - pub _padding: [u8; 1601], // 1601 -} + pub perp_funding_delta: AnchorDecimal, // 16 + pub perp_latest_funding_rate: AnchorDecimal, // 16 + pub perp_latest_midpoint: u64, // 8 + pub _padding: [u8; 1593], // 1593 +} // 10232 #[zero_copy] #[derive(Default, Debug)] @@ -255,7 +248,6 @@ pub enum MarginAccountType { #[repr(u8)] #[derive(PartialEq, Debug)] -#[allow(dead_code)] pub enum ExpirySeriesStatus { Uninitialized = 0, // Still in default state Initialized = 1, // Initialized but not active yet @@ -266,20 +258,20 @@ pub enum ExpirySeriesStatus { #[zero_copy] #[repr(packed)] -#[allow(dead_code)] #[derive(Debug)] pub struct HaltState { halted: bool, // 1 spot_price: u64, // 8 timestamp: u64, // 8 mark_prices_set: [bool; 2], // 2 - _mark_prices_set_padding: [bool; 4], // 4 + _mark_prices_set_padding: [bool; 3], // 3 + perp_mark_price_set: bool, // 1 market_nodes_cleaned: [bool; 2], // 2 _market_nodes_cleaned_padding: [bool; 4], // 4 market_cleaned: [bool; 46], // 46 _market_cleaned_padding: [bool; 91], // 91 perp_market_cleaned: bool, // 1 -} +} // 167 #[repr(u8)] #[derive(PartialEq, Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize)] @@ -297,6 +289,8 @@ pub enum OrderType { Limit = 0, PostOnly = 1, FillOrKill = 2, + ImmediateOrCancel = 3, + PostOnlySlide = 4, } #[repr(u8)] @@ -308,31 +302,6 @@ pub enum Asset { UNDEFINED = 255, } -impl Asset { - pub fn to_underlying_mint(&self) -> Pubkey { - match self { - Asset::SOL => { - pubkey!("So11111111111111111111111111111111111111112") - } - Asset::BTC => { - pubkey!("qfnqNqs3nCAHjnyCgLRDbBtq4p2MtHZxw8YjSyYhPoL") - } - Asset::ETH => { - pubkey!("FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf") - } - _ => { - assert!(false, "invalid asset"); - Pubkey::default() - } - } - } - - pub fn iterator() -> Iter<'static, Asset> { - static ASSETS: [Asset; 3] = [Asset::SOL, Asset::BTC, Asset::ETH]; - ASSETS.iter() - } -} - #[repr(u8)] #[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Clone, Copy)] pub enum OrderCompleteType { @@ -368,10 +337,3 @@ unsafe impl Zeroable for AnchorDecimal {} #[cfg(target_endian = "little")] unsafe impl Pod for AnchorDecimal {} - -impl fmt::Display for State { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let out = serde_json::to_string(self).unwrap_or_default(); - write!(f, "{}", out) - } -} diff --git a/src/zeta_keys.rs b/src/zeta_keys.rs deleted file mode 100644 index c37bf3b..0000000 --- a/src/zeta_keys.rs +++ /dev/null @@ -1,67 +0,0 @@ -use crate::*; - -use solana_program::pubkey::Pubkey; - -pub const STATE_SEED: &[u8] = b"state"; -pub const GREEKS_SEED: &[u8] = b"greeks"; -pub const MARKET_NODE_SEED: &[u8] = b"market-node"; -pub const OPEN_ORDERS_SEED: &[u8] = b"open-orders"; -pub const VAULT_SEED: &[u8] = b"vault"; -pub const SERUM_VAULT_SEED: &[u8] = b"serum-vault"; -pub const ZETA_VAULT_SEED: &[u8] = b"zeta-vault"; -pub const ZETA_GROUP_SEED: &[u8] = b"zeta-group"; -pub const WHITELIST_DEPOSIT_SEED: &[u8] = b"whitelist-deposit"; -pub const ZETA_INSURANCE_VAULT_SEED: &[u8] = b"zeta-insurance-vault"; -pub const ZETA_TREASURY_WALLET_SEED: &[u8] = b"zeta-treasury-wallet"; -pub const ZETA_REFERRALS_REWARDS_WALLET_SEED: &[u8] = b"zeta-referrals-rewards-wallet"; -pub const WHITELIST_INSURANCE_SEED: &[u8] = b"whitelist-insurance"; -pub const USER_INSURANCE_DEPOSIT_SEED: &[u8] = b"user-insurance-deposit"; -pub const WHITELIST_TRADING_FEES_SEED: &[u8] = b"whitelist-trading-fees"; -pub const SETTLEMENT_SEED: &[u8] = b"settlement"; -pub const MARGIN_SEED: &[u8] = b"margin"; -pub const SPREAD_SEED: &[u8] = b"spread"; -pub const UNDERLYING_SEED: &[u8] = b"underlying"; -pub const SERUM_SEED: &[u8] = b"serum"; -pub const MINT_AUTH_SEED: &[u8] = b"mint-auth"; -pub const BASE_MINT_SEED: &[u8] = b"base-mint"; -pub const QUOTE_MINT_SEED: &[u8] = b"quote-mint"; -pub const MARKET_SEED: &[u8] = b"market"; -pub const MARKET_INDEXES_SEED: &[u8] = b"market-indexes"; -pub const SOCIALIZED_LOSS_SEED: &[u8] = b"socialized-loss"; -pub const REFERRER_SEED: &[u8] = b"referrer"; -pub const REFERRAL_SEED: &[u8] = b"referral"; -pub const REFERRER_ALIAS_SEED: &[u8] = b"referrer-alias"; -pub const PERP_SYNC_QUEUE_SEED: &[u8] = b"perp-sync-queue"; - -pub fn get_state_address() -> Pubkey { - Pubkey::find_program_address(&[STATE_SEED], &ID).0 -} - -pub fn get_mint_authority_address() -> Pubkey { - Pubkey::find_program_address(&[MINT_AUTH_SEED], &ID).0 -} - -pub fn get_serum_authority_address() -> Pubkey { - Pubkey::find_program_address(&[SERUM_SEED], &ID).0 -} - -pub fn get_zeta_group_address(asset: Asset) -> Pubkey { - let underlying_mint = asset.to_underlying_mint(); - Pubkey::find_program_address(&[ZETA_GROUP_SEED, underlying_mint.as_ref()], &ID).0 -} - -pub fn get_greeks_address(zeta_group_address: Pubkey) -> Pubkey { - Pubkey::find_program_address(&[GREEKS_SEED, zeta_group_address.as_ref()], &ID).0 -} - -pub fn get_perp_sync_queue_address(zeta_group_address: Pubkey) -> Pubkey { - Pubkey::find_program_address(&[PERP_SYNC_QUEUE_SEED, zeta_group_address.as_ref()], &ID).0 -} - -pub fn get_vault_address(zeta_group_address: Pubkey) -> Pubkey { - Pubkey::find_program_address(&[VAULT_SEED, zeta_group_address.as_ref()], &ID).0 -} - -pub fn get_socialized_loss_account_address(zeta_group_address: Pubkey) -> Pubkey { - Pubkey::find_program_address(&[SOCIALIZED_LOSS_SEED, zeta_group_address.as_ref()], &ID).0 -} From 7554b20740eb34b92f9f1b39d5082c4fa7a497a9 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Wed, 1 Feb 2023 15:10:57 +1000 Subject: [PATCH 02/22] adding close apis, with accounts --- src/{types.rs => account.rs} | 6 ++++++ src/context.rs | 28 +++++++++++++++++++++++++++- src/lib.rs | 12 ++++++++++-- 3 files changed, 43 insertions(+), 3 deletions(-) rename src/{types.rs => account.rs} (99%) diff --git a/src/types.rs b/src/account.rs similarity index 99% rename from src/types.rs rename to src/account.rs index e3a8ab7..6eba553 100644 --- a/src/types.rs +++ b/src/account.rs @@ -207,6 +207,12 @@ pub struct Greeks { pub _padding: [u8; 1593], // 1593 } // 10232 +#[account] +#[derive(Default)] +pub struct OpenOrdersMap { + pub user_key: Pubkey, +} + #[zero_copy] #[derive(Default, Debug)] #[repr(packed)] diff --git a/src/context.rs b/src/context.rs index 17082c9..5922129 100644 --- a/src/context.rs +++ b/src/context.rs @@ -29,7 +29,7 @@ pub struct InitializeOpenOrders<'info> { pub market: UncheckedAccount<'info>, pub serum_authority: UncheckedAccount<'info>, #[account(mut)] - pub open_orders_map: UncheckedAccount<'info>, + pub open_orders_map: Box>, pub rent: Sysvar<'info, Rent>, } @@ -204,3 +204,29 @@ pub struct CancelAccounts<'info> { #[account(mut)] pub event_queue: UncheckedAccount<'info>, } + +#[derive(Accounts)] +pub struct CloseOpenOrders<'info> { + pub state: AccountLoader<'info, State>, + pub zeta_group: AccountLoader<'info, ZetaGroup>, + pub dex_program: Program<'info, cpi::Dex>, + #[account(mut)] + pub open_orders: UncheckedAccount<'info>, + #[account(mut)] + pub margin_account: AccountLoader<'info, MarginAccount>, + #[account(mut)] + pub authority: Signer<'info>, + pub market: UncheckedAccount<'info>, + pub serum_authority: UncheckedAccount<'info>, + #[account(mut)] + pub open_orders_map: Box>, +} + +#[derive(Accounts)] +pub struct CloseMarginAccount<'info> { + #[account(mut)] + pub margin_account: AccountLoader<'info, MarginAccount>, + #[account(mut)] + pub authority: Signer<'info>, + pub zeta_group: AccountLoader<'info, ZetaGroup>, +} diff --git a/src/lib.rs b/src/lib.rs index 8c4a70f..c63bc6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,17 +5,17 @@ use solana_program::pubkey; extern crate self as zeta_abi; +pub mod account; pub mod context; pub mod cpi; pub mod dex; pub mod id; -pub mod types; +pub use crate::account::*; pub use crate::context::*; pub use crate::cpi::*; pub use crate::dex::*; pub use crate::id::*; -pub use crate::types::*; use bytemuck::{Pod, Zeroable}; @@ -110,4 +110,12 @@ mod zeta { pub(crate) fn liquidate(ctx: Context, size: u64) -> Result<()> { Ok(()) } + + pub fn close_open_orders(ctx: Context, _map_nonce: u8) -> Result<()> { + Ok(()) + } + + pub(crate) fn close_margin_account(_ctx: Context) -> Result<()> { + Ok(()) + } } From e851404ce92c1f49846bc30720469e78570d0ad5 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Fri, 3 Feb 2023 06:10:13 +1000 Subject: [PATCH 03/22] moved module cpi => id, as abi compilation with cpi flag generates it's own cpi module --- README.md | 8 ++++++++ src/context.rs | 16 ++++++++-------- src/cpi.rs | 22 ---------------------- src/id.rs | 21 +++++++++++++++++++++ src/lib.rs | 4 ++-- 5 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 README.md delete mode 100644 src/cpi.rs diff --git a/README.md b/README.md new file mode 100644 index 0000000..05cdeb1 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Zeta DEX ABI + +Gateway to the Zeta DEX program, exposes functionality to: + +- initialize/close accounts +- deposit/withdraw +- place/cancel orders +- liquidate diff --git a/src/context.rs b/src/context.rs index 5922129..e4dfa3e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -16,7 +16,7 @@ pub struct InitializeMarginAccount<'info> { pub struct InitializeOpenOrders<'info> { pub state: AccountLoader<'info, State>, pub zeta_group: AccountLoader<'info, ZetaGroup>, - pub dex_program: Program<'info, cpi::Dex>, + pub dex_program: Program<'info, id::Dex>, pub system_program: Program<'info, System>, #[account(mut)] pub open_orders: UncheckedAccount<'info>, @@ -40,7 +40,7 @@ pub struct PlaceOrder<'info> { #[account(mut)] pub margin_account: AccountLoader<'info, MarginAccount>, pub authority: Signer<'info>, - pub dex_program: Program<'info, cpi::Dex>, + pub dex_program: Program<'info, id::Dex>, pub token_program: Program<'info, Token>, pub serum_authority: AccountInfo<'info>, pub greeks: AccountLoader<'info, Greeks>, @@ -50,7 +50,7 @@ pub struct PlaceOrder<'info> { pub market_accounts: MarketAccounts<'info>, pub oracle: UncheckedAccount<'info>, pub oracle_backup_feed: UncheckedAccount<'info>, - pub oracle_backup_program: Program<'info, cpi::Chainlink>, + pub oracle_backup_program: Program<'info, id::Chainlink>, #[account(mut)] pub market_node: UncheckedAccount<'info>, #[account(mut)] @@ -65,7 +65,7 @@ pub struct PlacePerpOrder<'info> { #[account(mut)] pub margin_account: AccountLoader<'info, MarginAccount>, pub authority: Signer<'info>, - pub dex_program: Program<'info, cpi::Dex>, + pub dex_program: Program<'info, id::Dex>, pub token_program: Program<'info, Token>, pub serum_authority: AccountInfo<'info>, pub greeks: AccountLoader<'info, Greeks>, @@ -75,7 +75,7 @@ pub struct PlacePerpOrder<'info> { pub market_accounts: MarketAccounts<'info>, pub oracle: UncheckedAccount<'info>, pub oracle_backup_feed: UncheckedAccount<'info>, - pub oracle_backup_program: Program<'info, cpi::Chainlink>, + pub oracle_backup_program: Program<'info, id::Chainlink>, #[account(mut)] pub market_mint: Box>, pub mint_authority: UncheckedAccount<'info>, @@ -116,7 +116,7 @@ pub struct Withdraw<'info> { pub greeks: AccountLoader<'info, Greeks>, pub oracle: UncheckedAccount<'info>, pub oracle_backup_feed: UncheckedAccount<'info>, - pub oracle_backup_program: Program<'info, cpi::Chainlink>, + pub oracle_backup_program: Program<'info, id::Chainlink>, #[account(mut)] pub socialized_loss_account: UncheckedAccount<'info>, } @@ -191,7 +191,7 @@ pub struct CancelAccounts<'info> { pub state: AccountLoader<'info, State>, #[account(mut)] pub margin_account: AccountLoader<'info, MarginAccount>, - pub dex_program: Program<'info, cpi::Dex>, + pub dex_program: Program<'info, id::Dex>, pub serum_authority: UncheckedAccount<'info>, #[account(mut)] pub open_orders: UncheckedAccount<'info>, @@ -209,7 +209,7 @@ pub struct CancelAccounts<'info> { pub struct CloseOpenOrders<'info> { pub state: AccountLoader<'info, State>, pub zeta_group: AccountLoader<'info, ZetaGroup>, - pub dex_program: Program<'info, cpi::Dex>, + pub dex_program: Program<'info, id::Dex>, #[account(mut)] pub open_orders: UncheckedAccount<'info>, #[account(mut)] diff --git a/src/cpi.rs b/src/cpi.rs deleted file mode 100644 index df65aed..0000000 --- a/src/cpi.rs +++ /dev/null @@ -1,22 +0,0 @@ -use crate::*; - -#[derive(Clone)] -pub struct Dex; - -impl anchor_lang::Id for Dex { - fn id() -> Pubkey { - match cfg!(feature = "mainnet") { - true => pubkey!("zDEXqXEG7gAyxb1Kg9mK5fPnUdENCGKzWrM21RMdWRq"), - false => pubkey!("5CmWtUihvSrJpaUrpJ3H1jUa9DRjYz4v2xs6c3EgQWMf"), - } - } -} - -#[derive(Clone)] -pub struct Chainlink; - -impl anchor_lang::Id for Chainlink { - fn id() -> Pubkey { - chainlink_solana::ID - } -} diff --git a/src/id.rs b/src/id.rs index 6115785..e9f7162 100644 --- a/src/id.rs +++ b/src/id.rs @@ -13,3 +13,24 @@ impl anchor_lang::Id for ZetaProgram { ID } } + +#[derive(Clone)] +pub struct Dex; + +impl anchor_lang::Id for Dex { + fn id() -> Pubkey { + match cfg!(feature = "mainnet") { + true => pubkey!("zDEXqXEG7gAyxb1Kg9mK5fPnUdENCGKzWrM21RMdWRq"), + false => pubkey!("5CmWtUihvSrJpaUrpJ3H1jUa9DRjYz4v2xs6c3EgQWMf"), + } + } +} + +#[derive(Clone)] +pub struct Chainlink; + +impl anchor_lang::Id for Chainlink { + fn id() -> Pubkey { + chainlink_solana::ID + } +} diff --git a/src/lib.rs b/src/lib.rs index c63bc6b..756d4f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![doc = include_str!("../README.md")] + use anchor_lang::prelude::*; use anchor_spl::token::{Mint, Token, TokenAccount}; use rust_decimal::prelude::*; @@ -7,13 +9,11 @@ extern crate self as zeta_abi; pub mod account; pub mod context; -pub mod cpi; pub mod dex; pub mod id; pub use crate::account::*; pub use crate::context::*; -pub use crate::cpi::*; pub use crate::dex::*; pub use crate::id::*; From 0b16a75ee7cdfea10a591643a76d059eca4abdf5 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Fri, 3 Feb 2023 14:44:05 +1000 Subject: [PATCH 04/22] removed unused functionality --- Cargo.toml | 1 - src/account.rs | 53 ++++++++++---------------------------------------- src/id.rs | 9 ++++++--- src/lib.rs | 1 - 4 files changed, 16 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 18821c3..e3e97d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,4 @@ anchor-lang = "0.24.2" anchor-spl = "0.24.2" solana-program = "1.9.13" bytemuck = { version = "1.4.0" } -rust_decimal = { git = "https://github.com/zetamarkets/rust-decimal.git", features = ["maths"] } chainlink_solana = "1.0.0" diff --git a/src/account.rs b/src/account.rs index 6eba553..36139b8 100644 --- a/src/account.rs +++ b/src/account.rs @@ -33,7 +33,6 @@ pub struct State { #[account(zero_copy)] #[repr(packed)] -#[derive(Debug)] pub struct ZetaGroup { pub nonce: u8, // 1 pub vault_nonce: u8, // 1 @@ -62,7 +61,6 @@ pub struct ZetaGroup { #[zero_copy] #[repr(packed)] -#[derive(Debug)] pub struct Product { // Serum market pub market: Pubkey, @@ -74,14 +72,13 @@ pub struct Product { #[zero_copy] #[repr(packed)] -#[derive(Debug)] pub struct Strike { is_set: bool, value: u64, } #[zero_copy] -#[derive(Default, Debug)] +#[derive(Default)] #[repr(packed)] pub struct PricingParameters { pub option_trade_normalizer: AnchorDecimal, // 16 @@ -97,7 +94,7 @@ pub struct PricingParameters { } // 112 #[zero_copy] -#[derive(Default, Debug)] +#[derive(Default)] #[repr(packed)] pub struct MarginParameters { // Futures @@ -122,7 +119,7 @@ pub struct MarginParameters { } // 120 bytes. #[zero_copy] -#[derive(Default, Debug)] +#[derive(Default)] #[repr(packed)] pub struct PerpParameters { pub min_funding_rate_percent: i64, // 8 @@ -132,7 +129,6 @@ pub struct PerpParameters { #[zero_copy] #[repr(packed)] -#[derive(Debug)] pub struct ExpirySeries { pub active_ts: u64, pub expiry_ts: u64, @@ -162,7 +158,7 @@ pub struct MarginAccount { } // 6144 #[zero_copy] -#[derive(Default, Debug)] +#[derive(Default)] #[repr(packed)] pub struct ProductGreeks { pub delta: u64, @@ -171,7 +167,7 @@ pub struct ProductGreeks { } // 40 #[zero_copy] -#[derive(Default, Debug)] +#[derive(Default)] #[repr(packed)] pub struct AnchorDecimal { pub flags: u32, @@ -214,7 +210,7 @@ pub struct OpenOrdersMap { } #[zero_copy] -#[derive(Default, Debug)] +#[derive(Default)] #[repr(packed)] pub struct Position { pub size: i64, @@ -222,7 +218,7 @@ pub struct Position { } // 16 #[zero_copy] -#[derive(Default, Debug)] +#[derive(Default)] #[repr(packed)] pub struct OrderState { pub closing_orders: u64, @@ -253,7 +249,7 @@ pub enum MarginAccountType { } #[repr(u8)] -#[derive(PartialEq, Debug)] +#[derive(PartialEq)] pub enum ExpirySeriesStatus { Uninitialized = 0, // Still in default state Initialized = 1, // Initialized but not active yet @@ -264,7 +260,6 @@ pub enum ExpirySeriesStatus { #[zero_copy] #[repr(packed)] -#[derive(Debug)] pub struct HaltState { halted: bool, // 1 spot_price: u64, // 8 @@ -280,7 +275,7 @@ pub struct HaltState { } // 167 #[repr(u8)] -#[derive(PartialEq, Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize)] +#[derive(PartialEq, Clone, Copy, AnchorSerialize, AnchorDeserialize)] pub enum Kind { Uninitialized = 0, Call = 1, @@ -300,7 +295,7 @@ pub enum OrderType { } #[repr(u8)] -#[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Clone, Copy, Debug)] +#[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Clone, Copy)] pub enum Asset { SOL = 0, BTC = 1, @@ -315,31 +310,3 @@ pub enum OrderCompleteType { Fill = 1, Booted = 2, } - -impl From for AnchorDecimal { - fn from(decimal: Decimal) -> AnchorDecimal { - AnchorDecimal { - flags: decimal.flags, - hi: decimal.hi, - lo: decimal.lo, - mid: decimal.mid, - } - } -} - -impl From for Decimal { - fn from(decimal: AnchorDecimal) -> Decimal { - Decimal { - flags: decimal.flags, - hi: decimal.hi, - lo: decimal.lo, - mid: decimal.mid, - } - } -} - -#[cfg(target_endian = "little")] -unsafe impl Zeroable for AnchorDecimal {} - -#[cfg(target_endian = "little")] -unsafe impl Pod for AnchorDecimal {} diff --git a/src/id.rs b/src/id.rs index e9f7162..6ee3f52 100644 --- a/src/id.rs +++ b/src/id.rs @@ -4,13 +4,16 @@ use crate::*; pub struct ZetaProgram; #[cfg(feature = "mainnet")] -declare_id!("ZETAxsqBRek56DhiGXrn75yj2NHU3aYUnxvHXpkf3aD"); +declare_id!("z6ikFPqPGi16hCFfytMBP2Ao2iNGaN57mBQHvFGAit7"); #[cfg(not(feature = "mainnet"))] -declare_id!("BG3oRikW8d16YjUEmX3ZxHm9SiJzrGtMhsSR8aCw1Cd7"); +declare_id!("zG36tRvqtkCtFEoXmQAq9aV19XCLn53QSceLmqorVFA"); impl anchor_lang::Id for ZetaProgram { fn id() -> Pubkey { - ID + match cfg!(feature = "mainnet") { + true => pubkey!("ZETAxsqBRek56DhiGXrn75yj2NHU3aYUnxvHXpkf3aD"), + false => pubkey!("BG3oRikW8d16YjUEmX3ZxHm9SiJzrGtMhsSR8aCw1Cd7"), + } } } diff --git a/src/lib.rs b/src/lib.rs index 756d4f9..5a2f17c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ use anchor_lang::prelude::*; use anchor_spl::token::{Mint, Token, TokenAccount}; -use rust_decimal::prelude::*; use solana_program::pubkey; extern crate self as zeta_abi; From d3216d2d461ec7b4df841efc52a1f7f6fa2e91a2 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Sat, 4 Feb 2023 07:57:51 +1000 Subject: [PATCH 05/22] fixes --- .gitignore | 2 +- Anchor.toml | 9 + Cargo.lock | 1443 ++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 8 +- src/context.rs | 13 - src/lib.rs | 4 +- 6 files changed, 1457 insertions(+), 22 deletions(-) create mode 100644 Anchor.toml create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index 96ef6c0..8adc5ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /target -Cargo.lock +*.bk diff --git a/Anchor.toml b/Anchor.toml new file mode 100644 index 0000000..9b87efd --- /dev/null +++ b/Anchor.toml @@ -0,0 +1,9 @@ +[provider] +cluster = "localnet" +wallet = "~/.config/solana/id.json" + +[programs.localnet] +zeta-abi = "z6ikFPqPGi16hCFfytMBP2Ao2iNGaN57mBQHvFGAit7" + +[workspace] +members = ["."] diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a79db55 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1443 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.8", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + +[[package]] +name = "anchor-attribute-access-control" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9b75d05b6b4ac9d95bb6e3b786b27d3a708c4c5a87c92ffaa25bbe9ae4c5d91" +dependencies = [ + "anchor-syn", + "anyhow", + "proc-macro2", + "quote", + "regex", + "syn", +] + +[[package]] +name = "anchor-attribute-account" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "485351a6d8157750d10d88c8e256f1bf8339262b2220ae9125aed3471309b5de" +dependencies = [ + "anchor-syn", + "anyhow", + "bs58 0.4.0", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "anchor-attribute-constant" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc632c540913dd051a78b00587cc47f57013d303163ddfaf4fa18717f7ccc1e0" +dependencies = [ + "anchor-syn", + "proc-macro2", + "syn", +] + +[[package]] +name = "anchor-attribute-error" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b5bd1dcfa7f3bc22dacef233d70a9e0bee269c4ac484510662f257cba2353a1" +dependencies = [ + "anchor-syn", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "anchor-attribute-event" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c6f9e6ce551ac9a177a45c99a65699a860c9e95fac68675138af1246e2591b0" +dependencies = [ + "anchor-syn", + "anyhow", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "anchor-attribute-interface" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d104aa17418cb329ed7418b227e083d5f326a27f26ce98f5d92e33da62a5f459" +dependencies = [ + "anchor-syn", + "anyhow", + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "anchor-attribute-program" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6831b920b173c004ddf7ae1167d1d25e9f002ffcb1773bbc5c7ce532a4441e1" +dependencies = [ + "anchor-syn", + "anyhow", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "anchor-attribute-state" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde147b10c71d95dc679785db0b5f3abac0091f789167aa62ac0135e2f54e8b9" +dependencies = [ + "anchor-syn", + "anyhow", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "anchor-derive-accounts" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cde98a0e1a56046b040ff591dfda391f88917af2b6487d02b45093c05be3514" +dependencies = [ + "anchor-syn", + "anyhow", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "anchor-lang" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a85dd2c5e29e20c7f4701a43724d6cd5406d0ee5694705522e43da0f26542a84" +dependencies = [ + "anchor-attribute-access-control", + "anchor-attribute-account", + "anchor-attribute-constant", + "anchor-attribute-error", + "anchor-attribute-event", + "anchor-attribute-interface", + "anchor-attribute-program", + "anchor-attribute-state", + "anchor-derive-accounts", + "arrayref", + "base64 0.13.1", + "bincode", + "borsh", + "bytemuck", + "solana-program", + "thiserror", +] + +[[package]] +name = "anchor-spl" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0188c33b4a3c124c4e593f2b440415aaea70a7650fac6ba0772395385d71c003" +dependencies = [ + "anchor-lang", + "solana-program", + "spl-associated-token-account", + "spl-token", +] + +[[package]] +name = "anchor-syn" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03549dc2eae0b20beba6333b14520e511822a6321cdb1760f841064a69347316" +dependencies = [ + "anyhow", + "bs58 0.3.1", + "heck", + "proc-macro2", + "proc-macro2-diagnostics", + "quote", + "serde", + "serde_json", + "sha2", + "syn", + "thiserror", +] + +[[package]] +name = "anyhow" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "blake3" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ae2468a89544a466886840aa467a25b766499f4f04bf7d9fcd10ecee9fccef" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", + "digest 0.10.6", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "block-padding", + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + +[[package]] +name = "borsh" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" +dependencies = [ + "borsh-derive", + "hashbrown 0.11.2", +] + +[[package]] +name = "borsh-derive" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" +dependencies = [ + "borsh-derive-internal", + "borsh-schema-derive-internal", + "proc-macro-crate 0.1.5", + "proc-macro2", + "syn", +] + +[[package]] +name = "borsh-derive-internal" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "borsh-schema-derive-internal" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bs58" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb" + +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + +[[package]] +name = "bumpalo" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" + +[[package]] +name = "bv" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8834bb1d8ee5dc048ee3124f2c7c1afcc6bc9aed03f11e9dfd8c69470a5db340" +dependencies = [ + "feature-probe", + "serde", +] + +[[package]] +name = "bytemuck" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c041d3eab048880cb0b86b256447da3f18859a163c3b8d8893f4e6368abe6393" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aca418a974d83d40a0c1f0c5cba6ff4bc28d8df099109ca459a2118d40b6322" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chainlink_solana" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1bc07ff7987366d193e8e1913b4aafcb83f919ad71be8c040b420bcedb6339b" +dependencies = [ + "borsh", + "borsh-derive", + "solana-program", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "console_log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501a375961cef1a0d44767200e66e4a559283097e91d0730b1d75dfb2f8a1494" +dependencies = [ + "log", + "web-sys", +] + +[[package]] +name = "constant_time_eq" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3ad85c1f65dc7b37604eb0e89748faf0b9653065f2a8ef69f96a687ec1e9279" + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer 0.10.3", + "crypto-common", + "subtle", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "feature-probe" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da" + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "serde", + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac", + "digest 0.9.0", +] + +[[package]] +name = "hmac-drbg" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" +dependencies = [ + "digest 0.9.0", + "generic-array", + "hmac", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" + +[[package]] +name = "js-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "keccak" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "libsecp256k1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d220bc1feda2ac231cb78c3d26f27676b8cf82c96971f7aeef3d0cf2797c73" +dependencies = [ + "arrayref", + "base64 0.12.3", + "digest 0.9.0", + "hmac-drbg", + "libsecp256k1-core", + "libsecp256k1-gen-ecmult", + "libsecp256k1-gen-genmult", + "rand", + "serde", + "sha2", + "typenum", +] + +[[package]] +name = "libsecp256k1-core" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f6ab710cec28cef759c5f18671a27dae2a5f952cdaaee1d8e2908cb2478a80" +dependencies = [ + "crunchy", + "digest 0.9.0", + "subtle", +] + +[[package]] +name = "libsecp256k1-gen-ecmult" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccab96b584d38fac86a83f07e659f0deafd0253dc096dab5a36d53efe653c5c3" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsecp256k1-gen-genmult" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67abfe149395e3aa1c48a2beb32b068e2334402df8181f818d3aee2b304c4f5d" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memmap2" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b182332558b18d807c4ce1ca8ca983b34c3ee32765e47b3f0f69b90355cc1dc" +dependencies = [ + "libc", +] + +[[package]] +name = "nom8" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" +dependencies = [ + "memchr", +] + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e" +dependencies = [ + "proc-macro-crate 1.3.0", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "once_cell" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + +[[package]] +name = "proc-macro-crate" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34" +dependencies = [ + "once_cell", + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proc-macro2-diagnostics" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "version_check", + "yansi", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" + +[[package]] +name = "ryu" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "semver" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" + +[[package]] +name = "serde" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718dc5fff5b36f99093fc49b280cfc96ce6fc824317783bff5a1fed0c7a64819" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer 0.9.0", + "digest 0.9.0", + "keccak", + "opaque-debug", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "solana-frozen-abi" +version = "1.9.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4fcb89eb3d0f30bd4b4a31ad1825c9d95cd638509acead00969d7601713288" +dependencies = [ + "bs58 0.4.0", + "bv", + "generic-array", + "log", + "memmap2", + "rustc_version", + "serde", + "serde_derive", + "sha2", + "solana-frozen-abi-macro", + "solana-logger", + "thiserror", +] + +[[package]] +name = "solana-frozen-abi-macro" +version = "1.9.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d63ab101db88ecccd8da34065b9097b88367e0744fdfd05cb7de87b4ede3717f" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + +[[package]] +name = "solana-logger" +version = "1.9.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1805d52fc8277a84c4803c7850c8f41471b57fb0dec7750338955ad6e43e2" +dependencies = [ + "env_logger", + "lazy_static", + "log", +] + +[[package]] +name = "solana-program" +version = "1.9.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5deafc4902425d40197f74166640300dd20b078e4ffd518c1bb56ceb7e01680" +dependencies = [ + "base64 0.13.1", + "bincode", + "bitflags", + "blake3", + "borsh", + "borsh-derive", + "bs58 0.4.0", + "bv", + "bytemuck", + "console_error_panic_hook", + "console_log", + "curve25519-dalek", + "getrandom 0.1.16", + "itertools", + "js-sys", + "lazy_static", + "libsecp256k1", + "log", + "num-derive", + "num-traits", + "parking_lot", + "rand", + "rustc_version", + "rustversion", + "serde", + "serde_bytes", + "serde_derive", + "sha2", + "sha3", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-logger", + "solana-sdk-macro", + "thiserror", + "wasm-bindgen", +] + +[[package]] +name = "solana-sdk-macro" +version = "1.9.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db4c93bd43c91290ad54fe6ff86179a859954f196507c4789a4876d38a62f17" +dependencies = [ + "bs58 0.4.0", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "spl-associated-token-account" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b013067447a1396303ddfc294f36e3d260a32f8a16c501c295bcdc7de39b490" +dependencies = [ + "borsh", + "solana-program", + "spl-token", +] + +[[package]] +name = "spl-token" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc67166ef99d10c18cb5e9c208901e6d8255c6513bb1f877977eba48e6cc4fb" +dependencies = [ + "arrayref", + "num-derive", + "num-traits", + "num_enum", + "solana-program", + "thiserror", +] + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_datetime" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" + +[[package]] +name = "toml_edit" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b" +dependencies = [ + "indexmap", + "nom8", + "toml_datetime", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "web-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "zeroize" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" + +[[package]] +name = "zeta-abi" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "anchor-spl", + "bytemuck", + "chainlink_solana", + "solana-program", +] diff --git a/Cargo.toml b/Cargo.toml index e3e97d9..90ab9e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,19 +3,17 @@ name = "zeta-abi" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [features] mainnet = [] no-entrypoint = [] no-idl = [] no-log-ix-name = [] cpi = ["no-entrypoint"] -default = ["no-entrypoint"] +default = ["no-entrypoint", "cpi"] [dependencies] anchor-lang = "0.24.2" anchor-spl = "0.24.2" solana-program = "1.9.13" -bytemuck = { version = "1.4.0" } -chainlink_solana = "1.0.0" +bytemuck = "1.4.0" +chainlink_solana = "1.0.0" \ No newline at end of file diff --git a/src/context.rs b/src/context.rs index e4dfa3e..f711f3e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -147,8 +147,6 @@ pub struct Liquidate<'info> { pub liquidated_margin_account: AccountLoader<'info, MarginAccount>, } -// Market accounts are the accounts used to place orders against the dex minus -// common accounts, i.e., program ids, sysvars, and the `pc_wallet`. #[derive(Accounts, Clone)] pub struct MarketAccounts<'info> { #[account(mut)] @@ -161,23 +159,12 @@ pub struct MarketAccounts<'info> { pub bids: UncheckedAccount<'info>, #[account(mut)] pub asks: UncheckedAccount<'info>, - // The `spl_token::Account` that funds will be taken from, i.e., transferred - // from the user into the market's vault. - // - // For bids, this is the base currency. For asks, the quote. - // This has to be owned by serum_authority PDA as serum checks that the owner - // of open orders also owns this token account #[account(mut)] pub order_payer_token_account: UncheckedAccount<'info>, - // Also known as the "base" currency. For a given A/B market, - // this is the vault for the A mint. #[account(mut)] pub coin_vault: UncheckedAccount<'info>, - // Also known as the "quote" currency. For a given A/B market, - // this is the vault for the B mint. #[account(mut)] pub pc_vault: UncheckedAccount<'info>, - // User wallets, used for settling. #[account(mut)] pub coin_wallet: UncheckedAccount<'info>, #[account(mut)] diff --git a/src/lib.rs b/src/lib.rs index 5a2f17c..a8673b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,6 @@ use anchor_lang::prelude::*; use anchor_spl::token::{Mint, Token, TokenAccount}; use solana_program::pubkey; -extern crate self as zeta_abi; - pub mod account; pub mod context; pub mod dex; @@ -19,7 +17,7 @@ pub use crate::id::*; use bytemuck::{Pod, Zeroable}; #[program] -mod zeta { +mod zeta_abi { #![allow(dead_code)] #![allow(unused_variables)] #![allow(clippy::too_many_arguments)] From 737e4a2b9ab879e8c155eab6865ba4774a805705 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 6 Feb 2023 10:30:41 +1000 Subject: [PATCH 06/22] adding for anchor compilation purposes --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 90ab9e7..43be585 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,7 @@ anchor-lang = "0.24.2" anchor-spl = "0.24.2" solana-program = "1.9.13" bytemuck = "1.4.0" -chainlink_solana = "1.0.0" \ No newline at end of file +chainlink_solana = "1.0.0" + +[workspace] +members = ["."] \ No newline at end of file From 45c67ff5ee0564d87584e6407e3f7bc8c6500a62 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 6 Feb 2023 14:38:36 +1000 Subject: [PATCH 07/22] wrong implementation of the cpi_program, fixing --- src/id.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/id.rs b/src/id.rs index 6ee3f52..62fb514 100644 --- a/src/id.rs +++ b/src/id.rs @@ -1,19 +1,16 @@ use crate::*; -#[derive(Clone)] -pub struct ZetaProgram; - #[cfg(feature = "mainnet")] -declare_id!("z6ikFPqPGi16hCFfytMBP2Ao2iNGaN57mBQHvFGAit7"); +declare_id!("ZETAxsqBRek56DhiGXrn75yj2NHU3aYUnxvHXpkf3aD"); #[cfg(not(feature = "mainnet"))] -declare_id!("zG36tRvqtkCtFEoXmQAq9aV19XCLn53QSceLmqorVFA"); +declare_id!("BG3oRikW8d16YjUEmX3ZxHm9SiJzrGtMhsSR8aCw1Cd7"); + +#[derive(Clone)] +pub struct ZetaProgram; impl anchor_lang::Id for ZetaProgram { fn id() -> Pubkey { - match cfg!(feature = "mainnet") { - true => pubkey!("ZETAxsqBRek56DhiGXrn75yj2NHU3aYUnxvHXpkf3aD"), - false => pubkey!("BG3oRikW8d16YjUEmX3ZxHm9SiJzrGtMhsSR8aCw1Cd7"), - } + ID } } From 6a41a12a978e75ee5b7a680224946e378ca56b90 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 6 Feb 2023 16:21:09 +1000 Subject: [PATCH 08/22] adding missed fields --- src/context.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/context.rs b/src/context.rs index f711f3e..5b5be23 100644 --- a/src/context.rs +++ b/src/context.rs @@ -130,6 +130,8 @@ pub struct CancelOrder<'info> { pub struct ForceCancelOrders<'info> { pub greeks: UncheckedAccount<'info>, pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, id::Chainlink>, pub cancel_accounts: CancelAccounts<'info>, } From 1c5f9f5ec743121f11162446ae48260155d0a153 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Tue, 7 Feb 2023 11:57:54 +1000 Subject: [PATCH 09/22] removing unnecessary Anfhor config, updating to latest lib versions --- Anchor.toml | 9 --------- Cargo.toml | 11 ++++------- 2 files changed, 4 insertions(+), 16 deletions(-) delete mode 100644 Anchor.toml diff --git a/Anchor.toml b/Anchor.toml deleted file mode 100644 index 9b87efd..0000000 --- a/Anchor.toml +++ /dev/null @@ -1,9 +0,0 @@ -[provider] -cluster = "localnet" -wallet = "~/.config/solana/id.json" - -[programs.localnet] -zeta-abi = "z6ikFPqPGi16hCFfytMBP2Ao2iNGaN57mBQHvFGAit7" - -[workspace] -members = ["."] diff --git a/Cargo.toml b/Cargo.toml index 43be585..cb38f22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,8 @@ cpi = ["no-entrypoint"] default = ["no-entrypoint", "cpi"] [dependencies] -anchor-lang = "0.24.2" -anchor-spl = "0.24.2" -solana-program = "1.9.13" +anchor-lang = "0.26.0" +anchor-spl = "0.26.0" +solana-program = "1.13.5" bytemuck = "1.4.0" -chainlink_solana = "1.0.0" - -[workspace] -members = ["."] \ No newline at end of file +chainlink_solana = "1.0.0" \ No newline at end of file From 9ee7b4bdeb046f5c114883c9e91115dc2198058d Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Tue, 14 Feb 2023 15:17:51 +1000 Subject: [PATCH 10/22] changed to UncheckedAccount --- src/context.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/context.rs b/src/context.rs index 5b5be23..299a666 100644 --- a/src/context.rs +++ b/src/context.rs @@ -42,10 +42,10 @@ pub struct PlaceOrder<'info> { pub authority: Signer<'info>, pub dex_program: Program<'info, id::Dex>, pub token_program: Program<'info, Token>, - pub serum_authority: AccountInfo<'info>, + pub serum_authority: UncheckedAccount<'info>, pub greeks: AccountLoader<'info, Greeks>, #[account(mut)] - pub open_orders: AccountInfo<'info>, + pub open_orders: UncheckedAccount<'info>, pub rent: Sysvar<'info, Rent>, pub market_accounts: MarketAccounts<'info>, pub oracle: UncheckedAccount<'info>, @@ -67,10 +67,10 @@ pub struct PlacePerpOrder<'info> { pub authority: Signer<'info>, pub dex_program: Program<'info, id::Dex>, pub token_program: Program<'info, Token>, - pub serum_authority: AccountInfo<'info>, + pub serum_authority: UncheckedAccount<'info>, pub greeks: AccountLoader<'info, Greeks>, #[account(mut)] - pub open_orders: AccountInfo<'info>, + pub open_orders: UncheckedAccount<'info>, pub rent: Sysvar<'info, Rent>, pub market_accounts: MarketAccounts<'info>, pub oracle: UncheckedAccount<'info>, From 609d7c78fcaad0200e0c2a51f1aa8d38776a3fc9 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Thu, 16 Feb 2023 14:57:06 +1000 Subject: [PATCH 11/22] wip --- src/context.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/context.rs b/src/context.rs index 299a666..66ae146 100644 --- a/src/context.rs +++ b/src/context.rs @@ -143,6 +143,8 @@ pub struct Liquidate<'info> { pub liquidator_margin_account: AccountLoader<'info, MarginAccount>, pub greeks: AccountLoader<'info, Greeks>, pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, id::Chainlink>, pub market: UncheckedAccount<'info>, pub zeta_group: AccountLoader<'info, ZetaGroup>, #[account(mut)] From 9d2e19535f6ae6b49907514d40e38b626eb9adb4 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Fri, 17 Feb 2023 12:47:27 +1000 Subject: [PATCH 12/22] wip --- src/context.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/context.rs b/src/context.rs index 66ae146..ea4ee36 100644 --- a/src/context.rs +++ b/src/context.rs @@ -208,6 +208,7 @@ pub struct CloseOpenOrders<'info> { #[account(mut)] pub authority: Signer<'info>, pub market: UncheckedAccount<'info>, + #[account(mut)] pub serum_authority: UncheckedAccount<'info>, #[account(mut)] pub open_orders_map: Box>, From 25169f264cac3f3b9c44606ea15ad9fc0178202b Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Sat, 18 Feb 2023 07:04:11 +1000 Subject: [PATCH 13/22] addresses issue1: porting of MArginAccount's get_initial_margin(), get_maintenance_margin(), get_unrealized_pnl() --- src/account.rs | 277 +++++++++++++++++++++++++++++++++++++++++++++++ src/constants.rs | 4 + src/errors.rs | 13 +++ src/lib.rs | 6 + src/utils.rs | 180 ++++++++++++++++++++++++++++++ 5 files changed, 480 insertions(+) create mode 100644 src/constants.rs create mode 100644 src/errors.rs create mode 100644 src/utils.rs diff --git a/src/account.rs b/src/account.rs index 36139b8..9e6528b 100644 --- a/src/account.rs +++ b/src/account.rs @@ -77,6 +77,38 @@ pub struct Strike { value: u64, } +impl Strike { + pub fn is_set(&self) -> bool { + self.is_set + } + + pub fn get_strike(&self) -> Result { + if !self.is_set() { + return Err(error!(ZetaError::ProductStrikeUninitialized)); + } + Ok(self.value) + } + + pub fn set(&mut self, strike: u64) -> Result<()> { + // There shouldn't be a case where you set a strike without resetting it first. + if self.is_set() { + return Err(error!(ZetaError::CannotSetInitializedStrike)); + } + self.is_set = true; + self.value = strike; + Ok(()) + } + + pub fn reset(&mut self) -> Result<()> { + if !self.is_set() { + return Err(error!(ZetaError::CannotResetUninitializedStrike)); + } + self.value = 0; + self.is_set = false; + Ok(()) + } +} + #[zero_copy] #[derive(Default)] #[repr(packed)] @@ -157,6 +189,94 @@ pub struct MarginAccount { pub _padding: [u8; 338], // 338 } // 6144 +impl MarginAccount { + // Calculates the total initial margin for all open orders and positions. + pub fn get_initial_margin(&self, greeks: &Greeks, zeta_group: &ZetaGroup, spot: u64) -> u64 { + let initial_margin_requirement: u64 = self + .product_ledgers + .iter() + .enumerate() + .map(|(i, ledger)| { + ledger.get_initial_margin( + greeks.mark_prices[i], + &zeta_group.products[i], + spot, + &zeta_group.margin_parameters, + ) + }) + .sum(); + + // Perps have a different layout + let perp_margin_requirement: u64 = self.perp_product_ledger.get_initial_margin( + spot, + &zeta_group.perp, + spot, + &zeta_group.margin_parameters, + ); + + msg!( + "get_initial_margin {} {}", + initial_margin_requirement, + perp_margin_requirement + ); + + initial_margin_requirement + .checked_add(perp_margin_requirement) + .unwrap() + } + + pub fn get_maintenance_margin( + &self, + greeks: &Greeks, + zeta_group: &ZetaGroup, + spot: u64, + ) -> u64 { + let maintenance_margin_requirement: u64 = self + .product_ledgers + .iter() + .enumerate() + .map(|(i, product_ledgers)| { + product_ledgers.get_maintenance_margin( + greeks.mark_prices[i], + &zeta_group.products[i], + spot, + &zeta_group.margin_parameters, + ) + }) + .sum(); + + // Perps have a different layout + let perp_margin_requirement: u64 = self.perp_product_ledger.get_maintenance_margin( + spot, + &zeta_group.perp, + spot, + &zeta_group.margin_parameters, + ); + + maintenance_margin_requirement + .checked_add(perp_margin_requirement) + .unwrap() + } + + pub fn get_unrealized_pnl(&self, greeks: &Greeks, spot: u64) -> i64 { + let pnl: i64 = self + .product_ledgers + .iter() + .enumerate() + .map(|(i, product_ledger)| { + (product_ledger + .position + .get_unrealized_pnl(greeks.mark_prices[i]) as i128) as i64 + }) + .sum(); + + // Perps have a different layout + let perp_pnl: i64 = self.perp_product_ledger.position.get_unrealized_pnl(spot); + + pnl.checked_add(perp_pnl).unwrap() + } +} + #[zero_copy] #[derive(Default)] #[repr(packed)] @@ -217,6 +337,38 @@ pub struct Position { pub cost_of_trades: u64, } // 16 +impl Position { + pub fn size_abs(&self) -> u64 { + self.size.abs() as u64 + } + + pub fn get_unrealized_pnl(&self, mark_price: u64) -> i64 { + if self.size == 0 { + 0 + } else if self.size > 0 { + (self.size as i128) + .checked_mul(mark_price as i128) + .unwrap() + .checked_div(POSITION_PRECISION_DENOMINATOR as i128) + .unwrap() + .checked_sub(self.cost_of_trades as i128) + .unwrap() + .try_into() + .unwrap() + } else { + (self.size as i128) + .checked_mul(mark_price as i128) + .unwrap() + .checked_div(POSITION_PRECISION_DENOMINATOR as i128) + .unwrap() + .checked_add(self.cost_of_trades as i128) + .unwrap() + .try_into() + .unwrap() + } + } +} + #[zero_copy] #[derive(Default)] #[repr(packed)] @@ -233,6 +385,131 @@ pub struct ProductLedger { pub order_state: OrderState, } // 40 +impl ProductLedger { + pub fn get_initial_margin( + &self, + mark_price: u64, + product: &Product, + spot: u64, + margin_parameters: &MarginParameters, + ) -> u64 { + let strike: u64 = match product.kind == Kind::Perp { + true => 0, + false => match product.strike.get_strike() { + Ok(strike) => strike, + Err(_) => return 0, + }, + }; + + let mut long_lots: u64 = self.order_state.opening_orders[BID_ORDERS_INDEX]; + let mut short_lots: u64 = self.order_state.opening_orders[ASK_ORDERS_INDEX]; + if self.position.size > 0 { + long_lots = long_lots.checked_add(self.position.size_abs()).unwrap(); + } else if self.position.size < 0 { + short_lots = short_lots.checked_add(self.position.size_abs()).unwrap(); + } + + let mut long_initial_margin: u128 = 0; + let mut short_initial_margin: u128 = 0; + + if long_lots > 0 { + long_initial_margin = (long_lots as u128) + .checked_mul( + get_initial_margin_per_lot( + spot, + strike, + mark_price, + product.kind, + Side::Bid, + margin_parameters, + ) + .unwrap() + .try_into() + .unwrap(), + ) + .unwrap(); + } + + if short_lots > 0 { + short_initial_margin = (short_lots as u128) + .checked_mul( + get_initial_margin_per_lot( + spot, + strike, + mark_price, + product.kind, + Side::Ask, + margin_parameters, + ) + .unwrap() + .try_into() + .unwrap(), + ) + .unwrap(); + } + + if product.kind == Kind::Future || product.kind == Kind::Perp { + if long_lots > short_lots { + return long_initial_margin + .checked_div(POSITION_PRECISION_DENOMINATOR) + .unwrap() + .try_into() + .unwrap(); + } else { + return short_initial_margin + .checked_div(POSITION_PRECISION_DENOMINATOR) + .unwrap() + .try_into() + .unwrap(); + } + } + + long_initial_margin + .checked_add(short_initial_margin) + .unwrap() + .checked_div(POSITION_PRECISION_DENOMINATOR) + .unwrap() + .try_into() + .unwrap() + } + + pub fn get_maintenance_margin( + &self, + mark_price: u64, + product: &Product, + spot: u64, + margin_parameters: &MarginParameters, + ) -> u64 { + if self.position.size == 0 { + return 0; + } + + let strike: u64 = match product.kind == Kind::Perp { + true => 0, + false => match product.strike.get_strike() { + Ok(strike) => strike, + Err(_) => return 0, + }, + }; + + let maintenance_margin_per_lot = get_maintenance_margin_per_lot( + spot, + strike, + mark_price, + product.kind, + self.position.size >= 0, + margin_parameters, + ) + .unwrap(); + + (self.position.size_abs() as u128) + .checked_mul(maintenance_margin_per_lot as u128) + .unwrap() + .checked_div(POSITION_PRECISION_DENOMINATOR) + .unwrap() as u64 + } +} + #[repr(u8)] #[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Clone, Copy)] pub enum Side { diff --git a/src/constants.rs b/src/constants.rs new file mode 100644 index 0000000..5d5f2c0 --- /dev/null +++ b/src/constants.rs @@ -0,0 +1,4 @@ +pub const POSITION_PRECISION_DENOMINATOR: u128 = 1_000; +pub const NATIVE_PRECISION_DENOMINATOR: u128 = 100_000_000; // 100% +pub const BID_ORDERS_INDEX: usize = 0; +pub const ASK_ORDERS_INDEX: usize = 1; diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..ac2be57 --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,13 @@ +use crate::*; + +#[error_code] +pub enum ZetaError { + #[msg("Product strike uninitialized")] + ProductStrikeUninitialized, + #[msg("Unsupported kind")] + UnsupportedKind, + #[msg("Cannot set initialized strike")] + CannotSetInitializedStrike, + #[msg("Cannot set initialized strike")] + CannotResetUninitializedStrike, +} diff --git a/src/lib.rs b/src/lib.rs index a8673b4..db15128 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,14 +5,20 @@ use anchor_spl::token::{Mint, Token, TokenAccount}; use solana_program::pubkey; pub mod account; +pub mod constants; pub mod context; pub mod dex; +pub mod errors; pub mod id; +pub mod utils; pub use crate::account::*; +pub use crate::constants::*; pub use crate::context::*; pub use crate::dex::*; +pub use crate::errors::*; pub use crate::id::*; +pub use crate::utils::*; use bytemuck::{Pod, Zeroable}; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..02709a1 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,180 @@ +use crate::*; + +pub fn get_maintenance_margin_per_lot( + spot: u64, + strike: u64, + mark: u64, + product: Kind, + long: bool, + margin_parameters: &MarginParameters, +) -> Result { + let maintenance_margin: u128 = match product { + Kind::Future | Kind::Perp => (spot as u128) + .checked_mul(margin_parameters.future_margin_maintenance.into()) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap(), + Kind::Call | Kind::Put => { + if long { + (spot as u128) + .checked_mul( + margin_parameters + .option_spot_percentage_long_maintenance + .into(), + ) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap() + .min( + (mark as u128) + .checked_mul( + margin_parameters + .option_mark_percentage_long_maintenance + .into(), + ) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap(), + ) + } else { + let otm_amount: u128 = get_otm_amount(spot, strike, product)?.into(); + let otm_pct = otm_amount + .checked_mul(NATIVE_PRECISION_DENOMINATOR) + .unwrap() + .checked_div(spot.into()) + .unwrap(); + + let dynamic_margin_pct: u128 = + (margin_parameters.option_dynamic_percentage_short_maintenance as u128) + .checked_sub(otm_pct) + .unwrap_or(0); + + let margin_pct = dynamic_margin_pct.max( + margin_parameters + .option_spot_percentage_short_maintenance + .into(), + ); + + margin_pct + .checked_mul(spot.into()) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap() + } + } + _ => return Err(error!(ZetaError::UnsupportedKind)), + }; + + if product == Kind::Put && !long { + let sell_put_cap_margin = (strike as u128) + .checked_mul(margin_parameters.option_short_put_cap_percentage as u128) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap(); + + return Ok(u64::try_from(maintenance_margin.min(sell_put_cap_margin)).unwrap()); + } + + Ok(u64::try_from(maintenance_margin).unwrap()) +} + +pub fn get_otm_amount(spot: u64, strike: u64, product: Kind) -> Result { + match product { + Kind::Call => Ok((strike as i128) + .checked_sub(spot as i128) + .unwrap() + .max(0) + .try_into() + .unwrap()), + Kind::Put => Ok((spot as i128) + .checked_sub(strike as i128) + .unwrap() + .max(0) + .try_into() + .unwrap()), + _ => return Err(error!(ZetaError::UnsupportedKind)), + } +} + +/// Initial margin for single product +// we maintain 6 d.p and 2 d.p for percentage calculations +// keep this consistent, could maybe make a function get_native_percentage? +// would just return percentage * 10^N, where N = 2 = percentage precision..... +pub fn get_initial_margin_per_lot( + spot: u64, + strike: u64, + mark: u64, + product: Kind, + side: Side, + margin_parameters: &MarginParameters, +) -> Result { + let initial_margin: u128 = match product { + // 15% of Spot + Kind::Future | Kind::Perp => (spot as u128) + .checked_mul(margin_parameters.future_margin_initial.into()) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap(), + Kind::Call | Kind::Put => { + match side { + Side::Bid => { + // min(100% * mark price, 15% of spot) + // Place holder calcs in place for 100% * mark price + (spot as u128) + .checked_mul(margin_parameters.option_spot_percentage_long_initial.into()) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap() + .min( + (mark as u128) + .checked_mul( + margin_parameters.option_mark_percentage_long_initial.into(), + ) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap(), + ) + } + Side::Ask => { + let otm_amount: u128 = get_otm_amount(spot, strike, product)?.into(); + // max(25% - OTM Amount/spot, 10%) + let otm_pct = otm_amount + .checked_mul(NATIVE_PRECISION_DENOMINATOR) + .unwrap() + .checked_div(spot.into()) + .unwrap(); + + let dynamic_margin_pct = + (margin_parameters.option_dynamic_percentage_short_initial as u128) + .checked_sub(otm_pct) + .unwrap_or(0); + + let margin_pct = dynamic_margin_pct.max( + margin_parameters + .option_spot_percentage_short_initial + .into(), + ); + margin_pct + .checked_mul(spot.into()) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap() + } + Side::Uninitialized => unreachable!(), + } + } + _ => return Err(error!(ZetaError::UnsupportedKind)), + }; + + if product == Kind::Put && side == Side::Ask { + let sell_put_cap_margin = (strike as u128) + .checked_mul(margin_parameters.option_short_put_cap_percentage as u128) + .unwrap() + .checked_div(NATIVE_PRECISION_DENOMINATOR) + .unwrap(); + + return Ok(u64::try_from(initial_margin.min(sell_put_cap_margin)).unwrap()); + } + + Ok(u64::try_from(initial_margin).unwrap()) +} From 44af10488a64aecc5ecd411649400d5235ee9109 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 20 Feb 2023 12:22:05 +1000 Subject: [PATCH 14/22] re-org to include abi-wrapper as a separate dir --- LICENCE | 201 ++ README.md | 72 +- abi-wrapper/Anchor.toml | 9 + abi-wrapper/Cargo.toml | 18 + abi-wrapper/Xargo.toml | 2 + abi-wrapper/src/lib.rs | 638 ++++++ abi-wrapper/target/idl/abi_wrapper.json | 1288 +++++++++++ abi-wrapper/target/types/abi_wrapper.ts | 2577 +++++++++++++++++++++++ 8 files changed, 4799 insertions(+), 6 deletions(-) create mode 100644 LICENCE create mode 100644 abi-wrapper/Anchor.toml create mode 100644 abi-wrapper/Cargo.toml create mode 100644 abi-wrapper/Xargo.toml create mode 100644 abi-wrapper/src/lib.rs create mode 100644 abi-wrapper/target/idl/abi_wrapper.json create mode 100644 abi-wrapper/target/types/abi_wrapper.ts diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..f49a4e1 --- /dev/null +++ b/LICENCE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index 05cdeb1..144d12f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,68 @@ -# Zeta DEX ABI +
+ -Gateway to the Zeta DEX program, exposes functionality to: +

Zeta ABI 🧬

-- initialize/close accounts -- deposit/withdraw -- place/cancel orders -- liquidate +

+ Discord Chat + License +

+
+ +# Zeta ABI + +ABI is Zeta's cross-program integration ecosystem. + +This repository contains the Zeta Cross Program Invocation (CPI) interface as well as a usage example [abi-wrapper](./abi-wrapper/). + +## Cross Program Invocations + +### Instructions + +The instructions currently supported are as follows: + +- `initialize_margin_account` - create and initialize a user's margin account +- `initialize_open_orders` - create and initialize user's open orders account +- `deposit` - deposit USDC collateral into the margin account +- `withdraw` - withdraw USDC collateral from the margin account +- `place_order_v4` - place a futures order of (price, size, side) on the relevant market +- `place_perp_order_v2` - place a perp order of (price, size, side) on the relevant market +- `cancel_order_xxx` - collection of order cancellation functions, by orderId, clientOrderId, market, etc +- `close_open_orders` - close open orders account +- `liquidate` - trigger liquidation + +### Accounts + +The accounts and relevant data that is currently supported (non-exhaustive): + +- `ZetaGroup` - contains information relating to all derivatives market for an underlying + - Underlying + - Serum Market + - Strike + - Kind (Call, Put, Future) + - Expiry +- `Greeks` + - Mark Price + - Delta + - Vega + - IV +- `MarginAccount` + - Balance + - Positions +- `Oracle` + - Price + +## Programs + +### abi-wrapper + +Basic usage example outlined in a dummy wrapper program, which simply calls the main zeta program instructions. Also includes account layouts and outlines how to read all relevant on-chain data from the Zeta program. +This should give all the boilerplate needed to execute core program functionality both as the smart contract and off-chain client. diff --git a/abi-wrapper/Anchor.toml b/abi-wrapper/Anchor.toml new file mode 100644 index 0000000..675f68b --- /dev/null +++ b/abi-wrapper/Anchor.toml @@ -0,0 +1,9 @@ +[provider] +cluster = "localnet" +wallet = "~/.config/solana/id.json" + +[programs.localnet] +zeta = "z6ikFPqPGi16hCFfytMBP2Ao2iNGaN57mBQHvFGAit7" + +[workspace] +members = ["."] \ No newline at end of file diff --git a/abi-wrapper/Cargo.toml b/abi-wrapper/Cargo.toml new file mode 100644 index 0000000..3d77435 --- /dev/null +++ b/abi-wrapper/Cargo.toml @@ -0,0 +1,18 @@ +[lib] +crate-type = ["cdylib", "lib"] + +[package] +name = "abi-wrapper" +version = "0.1.0" +edition = "2021" + +[features] +mainnet = [] +no-entrypoint = [] +no-idl = [] +cpi = ["no-entrypoint"] + +[dependencies] +anchor-lang = "0.26.0" +anchor-spl = "0.26.0" +zeta-abi = { path = "..", features = ["cpi"] } \ No newline at end of file diff --git a/abi-wrapper/Xargo.toml b/abi-wrapper/Xargo.toml new file mode 100644 index 0000000..1744f09 --- /dev/null +++ b/abi-wrapper/Xargo.toml @@ -0,0 +1,2 @@ +[target.bpfel-unknown-unknown.dependencies.std] +features = [] \ No newline at end of file diff --git a/abi-wrapper/src/lib.rs b/abi-wrapper/src/lib.rs new file mode 100644 index 0000000..4a937ec --- /dev/null +++ b/abi-wrapper/src/lib.rs @@ -0,0 +1,638 @@ +use anchor_lang::prelude::*; +use anchor_spl::token::{Mint, Token, TokenAccount}; +use zeta_abi::*; + +declare_id!("z6ikFPqPGi16hCFfytMBP2Ao2iNGaN57mBQHvFGAit7"); + +#[program] +pub mod abi_wrapper { + + use super::*; + + pub fn initialize_margin_account(ctx: Context) -> Result<()> { + msg!("In abi_wrapper::initialize_margin_account"); + let init_margin_accs = zeta_abi::cpi::accounts::InitializeMarginAccount { + margin_account: ctx.accounts.margin_account.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + payer: ctx.accounts.payer.to_account_info(), + zeta_program: ctx.accounts.zeta_program.to_account_info(), + system_program: ctx.accounts.system_program.to_account_info(), + zeta_group: ctx.accounts.zeta_group.to_account_info(), + }; + let init_margin_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + init_margin_accs, + ); + zeta_abi::cpi::initialize_margin_account(init_margin_ctx)?; + Ok(()) + } + + pub fn initialize_open_orders(ctx: Context) -> Result<()> { + let init_open_orders_accs = zeta_abi::cpi::accounts::InitializeOpenOrders { + state: ctx.accounts.state.to_account_info(), + zeta_group: ctx.accounts.zeta_group.to_account_info(), + dex_program: ctx.accounts.dex_program.to_account_info(), + system_program: ctx.accounts.system_program.to_account_info(), + open_orders: ctx.accounts.open_orders.to_account_info(), + margin_account: ctx.accounts.margin_account.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + payer: ctx.accounts.payer.to_account_info(), + market: ctx.accounts.market.to_account_info(), + serum_authority: ctx.accounts.serum_authority.to_account_info(), + open_orders_map: ctx.accounts.open_orders_map.to_account_info(), + rent: ctx.accounts.rent.to_account_info(), + }; + let init_open_orders_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + init_open_orders_accs, + ); + zeta_abi::cpi::initialize_open_orders(init_open_orders_ctx)?; + Ok(()) + } + + pub fn deposit(ctx: Context, amount: u64) -> Result<()> { + let deposit_accs = zeta_abi::cpi::accounts::Deposit { + zeta_group: ctx.accounts.zeta_group.to_account_info(), + margin_account: ctx.accounts.margin_account.to_account_info(), + vault: ctx.accounts.vault.to_account_info(), + user_token_account: ctx.accounts.user_token_account.to_account_info(), + socialized_loss_account: ctx.accounts.socialized_loss_account.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + token_program: ctx.accounts.token_program.to_account_info(), + state: ctx.accounts.state.to_account_info(), + greeks: ctx.accounts.greeks.to_account_info(), + }; + let deposit_ctx = + CpiContext::new(ctx.accounts.zeta_program.to_account_info(), deposit_accs); + zeta_abi::cpi::deposit(deposit_ctx, amount)?; + Ok(()) + } + + pub fn withdraw(ctx: Context, amount: u64) -> Result<()> { + let withdraw_accs = zeta_abi::cpi::accounts::Withdraw { + zeta_group: ctx.accounts.zeta_group.to_account_info(), + margin_account: ctx.accounts.margin_account.to_account_info(), + vault: ctx.accounts.vault.to_account_info(), + user_token_account: ctx.accounts.user_token_account.to_account_info(), + socialized_loss_account: ctx.accounts.socialized_loss_account.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + token_program: ctx.accounts.token_program.to_account_info(), + state: ctx.accounts.state.to_account_info(), + oracle: ctx.accounts.oracle.to_account_info(), + greeks: ctx.accounts.greeks.to_account_info(), + oracle_backup_feed: ctx.accounts.oracle_backup_feed.to_account_info(), + oracle_backup_program: ctx.accounts.oracle_backup_program.to_account_info(), + }; + let withdraw_ctx = + CpiContext::new(ctx.accounts.zeta_program.to_account_info(), withdraw_accs); + zeta_abi::cpi::withdraw(withdraw_ctx, amount)?; + Ok(()) + } + + pub fn place_order_v4( + ctx: Context, + price: u64, + size: u64, + side: Side, + order_type: OrderType, + client_order_id: Option, + tag: Option, + tif_offset: Option, + ) -> Result<()> { + let place_order_accs = zeta_abi::cpi::accounts::PlaceOrder { + state: ctx.accounts.state.to_account_info(), + zeta_group: ctx.accounts.zeta_group.to_account_info(), + margin_account: ctx.accounts.margin_account.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + dex_program: ctx.accounts.dex_program.to_account_info(), + token_program: ctx.accounts.token_program.to_account_info(), + serum_authority: ctx.accounts.serum_authority.to_account_info(), + greeks: ctx.accounts.greeks.to_account_info(), + open_orders: ctx.accounts.open_orders.to_account_info(), + rent: ctx.accounts.rent.to_account_info(), + market_accounts: market_accs!(ctx), + oracle: ctx.accounts.oracle.to_account_info(), + oracle_backup_feed: ctx.accounts.oracle_backup_feed.to_account_info(), + oracle_backup_program: ctx.accounts.oracle_backup_program.to_account_info(), + market_node: ctx.accounts.market_node.to_account_info(), + market_mint: ctx.accounts.market_mint.to_account_info(), + mint_authority: ctx.accounts.mint_authority.to_account_info(), + }; + let place_order_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + place_order_accs, + ); + zeta_abi::cpi::place_order_v4( + place_order_ctx, + price, + size, + side.into(), + order_type.into(), + client_order_id, + tag, + tif_offset, + )?; + Ok(()) + } + + pub fn place_perp_order_v2( + ctx: Context, + price: u64, + size: u64, + side: Side, + order_type: OrderType, + client_order_id: Option, + tag: Option, + tif_offset: Option, + ) -> Result<()> { + let place_perp_order_accs = zeta_abi::cpi::accounts::PlacePerpOrder { + state: ctx.accounts.state.to_account_info(), + zeta_group: ctx.accounts.zeta_group.to_account_info(), + margin_account: ctx.accounts.margin_account.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + dex_program: ctx.accounts.dex_program.to_account_info(), + token_program: ctx.accounts.token_program.to_account_info(), + serum_authority: ctx.accounts.serum_authority.to_account_info(), + greeks: ctx.accounts.greeks.to_account_info(), + open_orders: ctx.accounts.open_orders.to_account_info(), + rent: ctx.accounts.rent.to_account_info(), + oracle: ctx.accounts.oracle.to_account_info(), + oracle_backup_feed: ctx.accounts.oracle_backup_feed.to_account_info(), + oracle_backup_program: ctx.accounts.oracle_backup_program.to_account_info(), + market_mint: ctx.accounts.market_mint.to_account_info(), + mint_authority: ctx.accounts.mint_authority.to_account_info(), + market_accounts: market_accs!(ctx), + perp_sync_queue: ctx.accounts.perp_sync_queue.to_account_info(), + }; + let place_perp_order_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + place_perp_order_accs, + ); + zeta_abi::cpi::place_perp_order_v2( + place_perp_order_ctx, + price, + size, + side.into(), + order_type.into(), + client_order_id, + tag, + tif_offset, + )?; + Ok(()) + } + + pub fn cancel_order( + ctx: Context, + side: Side, + order_id: u128, + ) -> Result<()> { + let cancel_order_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + cancel_order_accs!(ctx.accounts), + ); + zeta_abi::cpi::cancel_order(cancel_order_ctx, side.into(), order_id)?; + Ok(()) + } + + pub fn cancel_order_no_error( + ctx: Context, + side: Side, + order_id: u128, + ) -> Result<()> { + let cancel_order_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + cancel_order_accs!(ctx.accounts), + ); + zeta_abi::cpi::cancel_order_no_error(cancel_order_ctx, side.into(), order_id)?; + Ok(()) + } + + pub fn cancel_all_market_orders(ctx: Context) -> Result<()> { + let cancel_order_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + cancel_order_accs!(ctx.accounts), + ); + zeta_abi::cpi::cancel_all_market_orders(cancel_order_ctx)?; + Ok(()) + } + + pub fn cancel_order_by_client_order_id( + ctx: Context, + client_order_id: u64, + ) -> Result<()> { + let cancel_order_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + cancel_order_accs!(ctx.accounts), + ); + zeta_abi::cpi::cancel_order_by_client_order_id(cancel_order_ctx, client_order_id)?; + Ok(()) + } + + pub fn cancel_order_by_client_order_id_no_error( + ctx: Context, + client_order_id: u64, + ) -> Result<()> { + let cancel_order_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + cancel_order_accs!(ctx.accounts), + ); + zeta_abi::cpi::cancel_order_by_client_order_id_no_error(cancel_order_ctx, client_order_id)?; + Ok(()) + } + + pub fn force_cancel_orders(ctx: Context) -> Result<()> { + let force_cancel_order_accs = zeta_abi::cpi::accounts::ForceCancelOrders { + greeks: ctx.accounts.greeks.to_account_info(), + oracle: ctx.accounts.oracle.to_account_info(), + oracle_backup_feed: ctx.accounts.oracle_backup_feed.to_account_info(), + oracle_backup_program: ctx.accounts.oracle_backup_program.to_account_info(), + cancel_accounts: cancel_accs!(ctx.accounts.cancel_accounts), + }; + let force_cancel_order_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + force_cancel_order_accs, + ); + zeta_abi::cpi::force_cancel_orders(force_cancel_order_ctx)?; + Ok(()) + } + + pub fn close_margin(ctx: Context) -> Result<()> { + let close_margin_account_accs = zeta_abi::cpi::accounts::CloseMarginAccount { + margin_account: ctx.accounts.margin_account.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + zeta_group: ctx.accounts.zeta_group.to_account_info(), + }; + let close_margin_account_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + close_margin_account_accs, + ); + zeta_abi::cpi::close_margin_account(close_margin_account_ctx)?; + Ok(()) + } + + pub fn close_open_orders(ctx: Context, map_nonce: u8) -> Result<()> { + let close_open_orders_accs = zeta_abi::cpi::accounts::CloseOpenOrders { + state: ctx.accounts.state.to_account_info(), + zeta_group: ctx.accounts.zeta_group.to_account_info(), + dex_program: ctx.accounts.dex_program.to_account_info(), + open_orders: ctx.accounts.open_orders.to_account_info(), + margin_account: ctx.accounts.margin_account.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + market: ctx.accounts.market.to_account_info(), + serum_authority: ctx.accounts.serum_authority.to_account_info(), + open_orders_map: ctx.accounts.open_orders_map.to_account_info(), + }; + let close_open_orders_ctx = CpiContext::new( + ctx.accounts.zeta_program.to_account_info(), + close_open_orders_accs, + ); + zeta_abi::cpi::close_open_orders(close_open_orders_ctx, map_nonce)?; + Ok(()) + } + + pub fn liquidate(ctx: Context, amount: u64) -> Result<()> { + let liquidate_accs = zeta_abi::cpi::accounts::Liquidate { + state: ctx.accounts.state.to_account_info(), + liquidator: ctx.accounts.liquidator.to_account_info(), + liquidator_margin_account: ctx.accounts.liquidator_margin_account.to_account_info(), + greeks: ctx.accounts.greeks.to_account_info(), + oracle: ctx.accounts.oracle.to_account_info(), + oracle_backup_feed: ctx.accounts.oracle_backup_feed.to_account_info(), + oracle_backup_program: ctx.accounts.oracle_backup_program.to_account_info(), + market: ctx.accounts.market.to_account_info(), + zeta_group: ctx.accounts.zeta_group.to_account_info(), + liquidated_margin_account: ctx.accounts.liquidated_margin_account.to_account_info(), + }; + let liquidate_ctx = + CpiContext::new(ctx.accounts.zeta_program.to_account_info(), liquidate_accs); + zeta_abi::cpi::liquidate(liquidate_ctx, amount)?; + Ok(()) + } +} + +#[derive(Accounts)] +pub struct InitializeMarginAccounts<'info> { + #[account(mut)] + pub margin_account: UncheckedAccount<'info>, + pub authority: Signer<'info>, + pub payer: Signer<'info>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, + pub system_program: Program<'info, System>, + pub zeta_group: UncheckedAccount<'info>, +} + +#[derive(Accounts)] +pub struct InitializeOpenOrdersAccounts<'info> { + pub state: UncheckedAccount<'info>, + pub zeta_group: UncheckedAccount<'info>, + pub dex_program: Program<'info, id::Dex>, + pub system_program: Program<'info, System>, + #[account(mut)] + pub open_orders: UncheckedAccount<'info>, + #[account(mut)] + pub margin_account: UncheckedAccount<'info>, + pub authority: Signer<'info>, + pub payer: Signer<'info>, + #[account(mut)] + pub market: UncheckedAccount<'info>, + pub serum_authority: UncheckedAccount<'info>, + #[account(mut)] + pub open_orders_map: UncheckedAccount<'info>, + pub rent: Sysvar<'info, Rent>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct DepositAccounts<'info> { + pub zeta_group: UncheckedAccount<'info>, + #[account(mut)] + pub margin_account: UncheckedAccount<'info>, + #[account(mut)] + pub vault: UncheckedAccount<'info>, + #[account(mut)] + pub user_token_account: UncheckedAccount<'info>, + #[account(mut)] + pub socialized_loss_account: UncheckedAccount<'info>, + pub authority: Signer<'info>, + pub token_program: Program<'info, Token>, + pub state: UncheckedAccount<'info>, + pub greeks: UncheckedAccount<'info>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct WithdrawAccounts<'info> { + pub zeta_group: UncheckedAccount<'info>, + #[account(mut)] + pub margin_account: UncheckedAccount<'info>, + #[account(mut)] + pub vault: UncheckedAccount<'info>, + #[account(mut)] + pub user_token_account: UncheckedAccount<'info>, + #[account(mut)] + pub socialized_loss_account: UncheckedAccount<'info>, + pub authority: Signer<'info>, + pub token_program: Program<'info, Token>, + pub state: UncheckedAccount<'info>, + pub greeks: UncheckedAccount<'info>, + #[account(mut)] + pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, id::Chainlink>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct PlaceOrderAccounts<'info> { + pub state: UncheckedAccount<'info>, + pub zeta_group: UncheckedAccount<'info>, + #[account(mut)] + pub margin_account: UncheckedAccount<'info>, + pub authority: Signer<'info>, + pub dex_program: Program<'info, id::Dex>, + pub token_program: Program<'info, Token>, + pub serum_authority: UncheckedAccount<'info>, + pub greeks: UncheckedAccount<'info>, + #[account(mut)] + pub open_orders: UncheckedAccount<'info>, + pub rent: UncheckedAccount<'info>, + pub market_accounts: MarketAccounts<'info>, + pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, id::Chainlink>, + #[account(mut)] + pub market_node: UncheckedAccount<'info>, + #[account(mut)] + pub market_mint: Box>, + pub mint_authority: UncheckedAccount<'info>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct PlacePerpOrderAccounts<'info> { + pub state: UncheckedAccount<'info>, + pub zeta_group: UncheckedAccount<'info>, + #[account(mut)] + pub margin_account: UncheckedAccount<'info>, + pub authority: Signer<'info>, + pub dex_program: Program<'info, id::Dex>, + pub token_program: Program<'info, Token>, + pub serum_authority: UncheckedAccount<'info>, + pub greeks: UncheckedAccount<'info>, + #[account(mut)] + pub open_orders: UncheckedAccount<'info>, + pub rent: UncheckedAccount<'info>, + pub market_accounts: MarketAccounts<'info>, + pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, id::Chainlink>, + #[account(mut)] + pub market_mint: Box>, + pub mint_authority: UncheckedAccount<'info>, + #[account(mut)] + pub perp_sync_queue: UncheckedAccount<'info>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct CancelOrderAccounts<'info> { + pub authority: Signer<'info>, + pub cancel_accounts: CancelAccounts<'info>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct ForceCancelOrdersAccounts<'info> { + pub greeks: UncheckedAccount<'info>, + pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, id::Chainlink>, + pub cancel_accounts: CancelAccounts<'info>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct CloseMarginAccounts<'info> { + #[account(mut)] + pub margin_account: UncheckedAccount<'info>, + #[account(mut)] + pub authority: Signer<'info>, + #[account(mut)] + pub zeta_group: UncheckedAccount<'info>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct CloseOpenOrdersAccounts<'info> { + pub state: AccountLoader<'info, State>, + pub zeta_group: UncheckedAccount<'info>, + pub dex_program: Program<'info, zeta_abi::id::Dex>, + #[account(mut)] + pub open_orders: UncheckedAccount<'info>, + #[account(mut)] + pub margin_account: UncheckedAccount<'info>, + #[account(mut)] + pub authority: Signer<'info>, + pub market: UncheckedAccount<'info>, + #[account(mut)] + pub serum_authority: UncheckedAccount<'info>, + #[account(mut)] + pub open_orders_map: UncheckedAccount<'info>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts)] +pub struct LiquidateAccounts<'info> { + pub state: AccountLoader<'info, State>, + pub liquidator: Signer<'info>, + #[account(mut)] + pub liquidator_margin_account: AccountLoader<'info, MarginAccount>, + pub greeks: AccountLoader<'info, Greeks>, + pub oracle: UncheckedAccount<'info>, + pub oracle_backup_feed: UncheckedAccount<'info>, + pub oracle_backup_program: Program<'info, id::Chainlink>, + pub market: UncheckedAccount<'info>, + pub zeta_group: AccountLoader<'info, ZetaGroup>, + #[account(mut)] + pub liquidated_margin_account: AccountLoader<'info, MarginAccount>, + pub zeta_program: Program<'info, zeta_abi::id::ZetaProgram>, +} + +#[derive(Accounts, Clone)] +pub struct MarketAccounts<'info> { + #[account(mut)] + pub market: UncheckedAccount<'info>, + #[account(mut)] + pub request_queue: UncheckedAccount<'info>, + #[account(mut)] + pub event_queue: UncheckedAccount<'info>, + #[account(mut)] + pub bids: UncheckedAccount<'info>, + #[account(mut)] + pub asks: UncheckedAccount<'info>, + #[account(mut)] + pub order_payer_token_account: Box>, + #[account(mut)] + pub coin_vault: Box>, + #[account(mut)] + pub pc_vault: Box>, + #[account(mut)] + pub coin_wallet: Box>, + #[account(mut)] + pub pc_wallet: Box>, +} + +#[derive(Accounts)] +pub struct CancelAccounts<'info> { + pub zeta_group: UncheckedAccount<'info>, + pub state: UncheckedAccount<'info>, + #[account(mut)] + pub margin_account: AccountLoader<'info, MarginAccount>, + pub dex_program: Program<'info, id::Dex>, + pub serum_authority: UncheckedAccount<'info>, + #[account(mut)] + pub open_orders: UncheckedAccount<'info>, + #[account(mut)] + pub market: UncheckedAccount<'info>, + #[account(mut)] + pub bids: UncheckedAccount<'info>, + #[account(mut)] + pub asks: UncheckedAccount<'info>, + #[account(mut)] + pub event_queue: UncheckedAccount<'info>, +} + +#[macro_export] +macro_rules! cancel_order_accs { + ($accs:expr) => { + zeta_abi::cpi::accounts::CancelOrder { + authority: $accs.authority.to_account_info(), + cancel_accounts: cancel_accs!($accs.cancel_accounts), + } + }; +} + +#[macro_export] +macro_rules! cancel_accs { + ($cancel_accs:expr) => { + zeta_abi::cpi::accounts::CancelAccounts { + zeta_group: $cancel_accs.zeta_group.to_account_info(), + state: $cancel_accs.state.to_account_info(), + margin_account: $cancel_accs.margin_account.to_account_info(), + dex_program: $cancel_accs.dex_program.to_account_info(), + serum_authority: $cancel_accs.serum_authority.to_account_info(), + open_orders: $cancel_accs.open_orders.to_account_info(), + market: $cancel_accs.market.to_account_info(), + bids: $cancel_accs.bids.to_account_info(), + asks: $cancel_accs.asks.to_account_info(), + event_queue: $cancel_accs.event_queue.to_account_info(), + } + }; +} + +#[macro_export] +macro_rules! market_accs { + ($ctx:expr) => { + zeta_abi::cpi::accounts::MarketAccounts { + market: $ctx.accounts.market_accounts.market.to_account_info(), + request_queue: $ctx + .accounts + .market_accounts + .request_queue + .to_account_info(), + event_queue: $ctx.accounts.market_accounts.event_queue.to_account_info(), + bids: $ctx.accounts.market_accounts.bids.to_account_info(), + asks: $ctx.accounts.market_accounts.asks.to_account_info(), + order_payer_token_account: $ctx + .accounts + .market_accounts + .order_payer_token_account + .to_account_info(), + coin_vault: $ctx.accounts.market_accounts.coin_vault.to_account_info(), + pc_vault: $ctx.accounts.market_accounts.pc_vault.to_account_info(), + coin_wallet: $ctx.accounts.market_accounts.coin_wallet.to_account_info(), + pc_wallet: $ctx.accounts.market_accounts.pc_wallet.to_account_info(), + } + }; +} + +// Needed for IDL +#[repr(u8)] +#[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Clone, Copy)] +pub enum Side { + Uninitialized = 0, + Bid = 1, + Ask = 2, +} + +impl From for zeta_abi::Side { + fn from(value: Side) -> zeta_abi::Side { + match value { + Side::Uninitialized => zeta_abi::Side::Uninitialized, + Side::Bid => zeta_abi::Side::Bid, + Side::Ask => zeta_abi::Side::Ask, + } + } +} + +#[repr(u8)] +#[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Clone, Copy)] +pub enum OrderType { + Limit = 0, + PostOnly = 1, + FillOrKill = 2, + ImmediateOrCancel = 3, + PostOnlySlide = 4, +} + +impl From for zeta_abi::OrderType { + fn from(value: OrderType) -> zeta_abi::OrderType { + match value { + OrderType::Limit => zeta_abi::OrderType::Limit, + OrderType::PostOnly => zeta_abi::OrderType::PostOnly, + OrderType::FillOrKill => zeta_abi::OrderType::FillOrKill, + OrderType::ImmediateOrCancel => zeta_abi::OrderType::ImmediateOrCancel, + OrderType::PostOnlySlide => zeta_abi::OrderType::PostOnlySlide, + } + } +} diff --git a/abi-wrapper/target/idl/abi_wrapper.json b/abi-wrapper/target/idl/abi_wrapper.json new file mode 100644 index 0000000..9824c64 --- /dev/null +++ b/abi-wrapper/target/idl/abi_wrapper.json @@ -0,0 +1,1288 @@ +{ + "version": "0.1.0", + "name": "abi_wrapper", + "instructions": [ + { + "name": "initializeMarginAccount", + "accounts": [ + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "payer", + "isMut": false, + "isSigner": true + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "initializeOpenOrders", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "payer", + "isMut": false, + "isSigner": true + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrdersMap", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "deposit", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "vault", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "socializedLossAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "withdraw", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "vault", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "socializedLossAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "placeOrderV4", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "marketAccounts", + "accounts": [ + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "requestQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "orderPayerTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "coinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "pcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "coinWallet", + "isMut": true, + "isSigner": false + }, + { + "name": "pcWallet", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "marketNode", + "isMut": true, + "isSigner": false + }, + { + "name": "marketMint", + "isMut": true, + "isSigner": false + }, + { + "name": "mintAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "price", + "type": "u64" + }, + { + "name": "size", + "type": "u64" + }, + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderType", + "type": { + "defined": "OrderType" + } + }, + { + "name": "clientOrderId", + "type": { + "option": "u64" + } + }, + { + "name": "tag", + "type": { + "option": "string" + } + }, + { + "name": "tifOffset", + "type": { + "option": "u16" + } + } + ] + }, + { + "name": "placePerpOrderV2", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "marketAccounts", + "accounts": [ + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "requestQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "orderPayerTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "coinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "pcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "coinWallet", + "isMut": true, + "isSigner": false + }, + { + "name": "pcWallet", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "marketMint", + "isMut": true, + "isSigner": false + }, + { + "name": "mintAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "perpSyncQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "price", + "type": "u64" + }, + { + "name": "size", + "type": "u64" + }, + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderType", + "type": { + "defined": "OrderType" + } + }, + { + "name": "clientOrderId", + "type": { + "option": "u64" + } + }, + { + "name": "tag", + "type": { + "option": "string" + } + }, + { + "name": "tifOffset", + "type": { + "option": "u16" + } + } + ] + }, + { + "name": "cancelOrder", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderId", + "type": "u128" + } + ] + }, + { + "name": "cancelOrderNoError", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderId", + "type": "u128" + } + ] + }, + { + "name": "cancelAllMarketOrders", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "cancelOrderByClientOrderId", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "clientOrderId", + "type": "u64" + } + ] + }, + { + "name": "cancelOrderByClientOrderIdNoError", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "clientOrderId", + "type": "u64" + } + ] + }, + { + "name": "forceCancelOrders", + "accounts": [ + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "closeMargin", + "accounts": [ + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": true, + "isSigner": true + }, + { + "name": "zetaGroup", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "closeOpenOrders", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": true, + "isSigner": true + }, + { + "name": "market", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": true, + "isSigner": false + }, + { + "name": "openOrdersMap", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "mapNonce", + "type": "u8" + } + ] + }, + { + "name": "liquidate", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "liquidator", + "isMut": false, + "isSigner": true + }, + { + "name": "liquidatorMarginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "market", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "liquidatedMarginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + } + ], + "types": [ + { + "name": "Side", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Uninitialized" + }, + { + "name": "Bid" + }, + { + "name": "Ask" + } + ] + } + }, + { + "name": "OrderType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Limit" + }, + { + "name": "PostOnly" + }, + { + "name": "FillOrKill" + }, + { + "name": "ImmediateOrCancel" + }, + { + "name": "PostOnlySlide" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/abi-wrapper/target/types/abi_wrapper.ts b/abi-wrapper/target/types/abi_wrapper.ts new file mode 100644 index 0000000..812becd --- /dev/null +++ b/abi-wrapper/target/types/abi_wrapper.ts @@ -0,0 +1,2577 @@ +export type AbiWrapper = { + "version": "0.1.0", + "name": "abi_wrapper", + "instructions": [ + { + "name": "initializeMarginAccount", + "accounts": [ + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "payer", + "isMut": false, + "isSigner": true + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "initializeOpenOrders", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "payer", + "isMut": false, + "isSigner": true + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrdersMap", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "deposit", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "vault", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "socializedLossAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "withdraw", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "vault", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "socializedLossAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "placeOrderV4", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "marketAccounts", + "accounts": [ + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "requestQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "orderPayerTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "coinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "pcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "coinWallet", + "isMut": true, + "isSigner": false + }, + { + "name": "pcWallet", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "marketNode", + "isMut": true, + "isSigner": false + }, + { + "name": "marketMint", + "isMut": true, + "isSigner": false + }, + { + "name": "mintAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "price", + "type": "u64" + }, + { + "name": "size", + "type": "u64" + }, + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderType", + "type": { + "defined": "OrderType" + } + }, + { + "name": "clientOrderId", + "type": { + "option": "u64" + } + }, + { + "name": "tag", + "type": { + "option": "string" + } + }, + { + "name": "tifOffset", + "type": { + "option": "u16" + } + } + ] + }, + { + "name": "placePerpOrderV2", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "marketAccounts", + "accounts": [ + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "requestQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "orderPayerTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "coinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "pcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "coinWallet", + "isMut": true, + "isSigner": false + }, + { + "name": "pcWallet", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "marketMint", + "isMut": true, + "isSigner": false + }, + { + "name": "mintAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "perpSyncQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "price", + "type": "u64" + }, + { + "name": "size", + "type": "u64" + }, + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderType", + "type": { + "defined": "OrderType" + } + }, + { + "name": "clientOrderId", + "type": { + "option": "u64" + } + }, + { + "name": "tag", + "type": { + "option": "string" + } + }, + { + "name": "tifOffset", + "type": { + "option": "u16" + } + } + ] + }, + { + "name": "cancelOrder", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderId", + "type": "u128" + } + ] + }, + { + "name": "cancelOrderNoError", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderId", + "type": "u128" + } + ] + }, + { + "name": "cancelAllMarketOrders", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "cancelOrderByClientOrderId", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "clientOrderId", + "type": "u64" + } + ] + }, + { + "name": "cancelOrderByClientOrderIdNoError", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "clientOrderId", + "type": "u64" + } + ] + }, + { + "name": "forceCancelOrders", + "accounts": [ + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "closeMargin", + "accounts": [ + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": true, + "isSigner": true + }, + { + "name": "zetaGroup", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "closeOpenOrders", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": true, + "isSigner": true + }, + { + "name": "market", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": true, + "isSigner": false + }, + { + "name": "openOrdersMap", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "mapNonce", + "type": "u8" + } + ] + }, + { + "name": "liquidate", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "liquidator", + "isMut": false, + "isSigner": true + }, + { + "name": "liquidatorMarginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "market", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "liquidatedMarginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + } + ], + "types": [ + { + "name": "Side", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Uninitialized" + }, + { + "name": "Bid" + }, + { + "name": "Ask" + } + ] + } + }, + { + "name": "OrderType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Limit" + }, + { + "name": "PostOnly" + }, + { + "name": "FillOrKill" + }, + { + "name": "ImmediateOrCancel" + }, + { + "name": "PostOnlySlide" + } + ] + } + } + ] +}; + +export const IDL: AbiWrapper = { + "version": "0.1.0", + "name": "abi_wrapper", + "instructions": [ + { + "name": "initializeMarginAccount", + "accounts": [ + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "payer", + "isMut": false, + "isSigner": true + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "initializeOpenOrders", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "payer", + "isMut": false, + "isSigner": true + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrdersMap", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "deposit", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "vault", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "socializedLossAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "withdraw", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "vault", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "socializedLossAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "placeOrderV4", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "marketAccounts", + "accounts": [ + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "requestQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "orderPayerTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "coinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "pcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "coinWallet", + "isMut": true, + "isSigner": false + }, + { + "name": "pcWallet", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "marketNode", + "isMut": true, + "isSigner": false + }, + { + "name": "marketMint", + "isMut": true, + "isSigner": false + }, + { + "name": "mintAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "price", + "type": "u64" + }, + { + "name": "size", + "type": "u64" + }, + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderType", + "type": { + "defined": "OrderType" + } + }, + { + "name": "clientOrderId", + "type": { + "option": "u64" + } + }, + { + "name": "tag", + "type": { + "option": "string" + } + }, + { + "name": "tifOffset", + "type": { + "option": "u16" + } + } + ] + }, + { + "name": "placePerpOrderV2", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "marketAccounts", + "accounts": [ + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "requestQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "orderPayerTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "coinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "pcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "coinWallet", + "isMut": true, + "isSigner": false + }, + { + "name": "pcWallet", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "marketMint", + "isMut": true, + "isSigner": false + }, + { + "name": "mintAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "perpSyncQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "price", + "type": "u64" + }, + { + "name": "size", + "type": "u64" + }, + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderType", + "type": { + "defined": "OrderType" + } + }, + { + "name": "clientOrderId", + "type": { + "option": "u64" + } + }, + { + "name": "tag", + "type": { + "option": "string" + } + }, + { + "name": "tifOffset", + "type": { + "option": "u16" + } + } + ] + }, + { + "name": "cancelOrder", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderId", + "type": "u128" + } + ] + }, + { + "name": "cancelOrderNoError", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "side", + "type": { + "defined": "Side" + } + }, + { + "name": "orderId", + "type": "u128" + } + ] + }, + { + "name": "cancelAllMarketOrders", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "cancelOrderByClientOrderId", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "clientOrderId", + "type": "u64" + } + ] + }, + { + "name": "cancelOrderByClientOrderIdNoError", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "clientOrderId", + "type": "u64" + } + ] + }, + { + "name": "forceCancelOrders", + "accounts": [ + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "cancelAccounts", + "accounts": [ + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "market", + "isMut": true, + "isSigner": false + }, + { + "name": "bids", + "isMut": true, + "isSigner": false + }, + { + "name": "asks", + "isMut": true, + "isSigner": false + }, + { + "name": "eventQueue", + "isMut": true, + "isSigner": false + } + ] + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "closeMargin", + "accounts": [ + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": true, + "isSigner": true + }, + { + "name": "zetaGroup", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "closeOpenOrders", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "dexProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "openOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "marginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "authority", + "isMut": true, + "isSigner": true + }, + { + "name": "market", + "isMut": false, + "isSigner": false + }, + { + "name": "serumAuthority", + "isMut": true, + "isSigner": false + }, + { + "name": "openOrdersMap", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "mapNonce", + "type": "u8" + } + ] + }, + { + "name": "liquidate", + "accounts": [ + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "liquidator", + "isMut": false, + "isSigner": true + }, + { + "name": "liquidatorMarginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "greeks", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupFeed", + "isMut": false, + "isSigner": false + }, + { + "name": "oracleBackupProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "market", + "isMut": false, + "isSigner": false + }, + { + "name": "zetaGroup", + "isMut": false, + "isSigner": false + }, + { + "name": "liquidatedMarginAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "zetaProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + } + ], + "types": [ + { + "name": "Side", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Uninitialized" + }, + { + "name": "Bid" + }, + { + "name": "Ask" + } + ] + } + }, + { + "name": "OrderType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Limit" + }, + { + "name": "PostOnly" + }, + { + "name": "FillOrKill" + }, + { + "name": "ImmediateOrCancel" + }, + { + "name": "PostOnlySlide" + } + ] + } + } + ] +}; From c5dbbdfa8d0d9dcd0b8b1d548646901754de08de Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 20 Feb 2023 12:25:34 +1000 Subject: [PATCH 15/22] wip --- logo.png | Bin 0 -> 9210 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 logo.png diff --git a/logo.png b/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..909c75842a9e61c9cb6c406d46d1f2c44d176c43 GIT binary patch literal 9210 zcmZvC2UJr_*CWJGIQqa*)x03F0=QX7(E?zY6>l_1s2S#12Od!NMlc6$ZGyW%9YjD%NKZg~4FdcK2-yfo|EUuYzzNy^ zTh}MN{Vxm=0Rh^XfaG5o6QI1l(tsQ2{clNJK=?lx3yA&;Jzqfl-};y9ZhyQobbx{! zsbTC*K)^zOeG@w7;{Xx}jh&ww`50+y$=G_h30vEF*w_mPxFN555y%C|097}8A8T-c zo2$FGOn^M^KM*oN{kmC%7yJ*1kBdC7k+vRK#ly=UEFml^EXu1u0S1HRyzCrg^i?1K z+Z}k4=XLV&LCT1T`1|_{``;J#@NyIpla`hi5fv8^7rzHU-181}_puJR=k5*p50d|j zN7dfj*2@{`eZk5sXa<&IXzQ(U0Cif5I|JU~KIC3J_ga1F1`46T4v;w3mP{@h=mu(6ZtQL4O z0s@{&nChda0fgJ;nhE^sh~bW}^A<0D6YMw#(mocNS$W8XnmE3xUwbJ|eW5sf6n}L9j6l2Vk8T&;}nSDKj7PbD>J^GW{!~VlDhTj90s@np&eRa!a z?=Px;h+(kI5m~fb>TGTsPUf)!-6Dz#``?NlK9X~jYJC2m-?=rrf9_P=N9C9$ztZR{ z%{sB^if$_kGLtyEYWM$f73cV<-kg;P9orMTYc6*c*&Vp)=}Z!<{|K>@`BTH&8*6_d zR>*@a00o_2#rj9N?}rRsu9sw|AVpjROfq?pw?JlcU8g3YjZz-QvT;7%^zPBv;j~7C zJ7`Oc=;Zt(Yo@=Voa}O(TZ+2_R&C>uIctJeihx8R_;qdF%WgF(s#0wk&e}xVh!JE1 zmK9Iall|p`01*e`m=RH_a+A70PgMqD#^C=3`2mD9lGZbV!9a$gcF&XD{jd*rDAeWB zC60)d!rl*tW8v^TBz3-fa?Pd#)gAUePJ$JOpLCEOYkR?Vi~%`W%S;J7gUX@B7nU(E z_*sLNqx~h-DwK1-YI^i0TlmY|Ekr!I;Mu|GOiAqQ-6wLEr$3`mhl4-kw`ORkJV@r; zm)lV9%l}Ss7r;`3Ebp-rk)gsUp|L2Jj+c3lWgv5et*A^HNg@z526?i0MZ>Kx0V127 zDap=8R))G4Xm#_{l9SLPgaez!T}9)`R}Uj;HcQ4wR9{%^sWH;%E8H8mc%CgV_t^Ke zk91SZ6|}`kbTvLhG0Dpj2i1VEj={LNJ4%eZOcVG2W>Hivm}Uo=flcpDz|)FvBLPs!69=xg0nI|Zjz+U51iRy z&-O$;US|93rzzYyJijEp)75uBry6-iF1G%gr^kA^?j`7R#}5Z(xCP$Ef-wpQHb43# z$%3Ca{VP~Ng2eAtPi())_pLNWgnpJ*%Z+`ulJR{uyr0bex3e8uBjLBhV;3?g7o_{l zOPRMHEPGy!o#2zj@A_Fg^PNN;-Y&}3TLO6aGODL6RHGeZelmLD1})*UboBR7^%%ko zd-qu;va<8#aF6B@y036Z0s`T8#ju;t&dZ_amKDVT?QbKa0>|8dFYlhgOd}mqTRjOS;KTR>P-QK-MO`gt6};$Al|3M~0(%XlRv; zq!;+5aK7Y|R`U;VLvX2Cz3Ffd<8)Gzni{+20|(Tb3!iMCS#Zvu4r4-c26iG-rG?fV z#PVN*^A{-Sy6Ea9Sg` zT;WyFGffxqRXsR{ud>za57pY3D?gY41Cmf)Ox**{BicTpdsVoybLk!!^OZFin~_ZJ#O zCw3I(j2$pZQf^U~LE|on3LZ z03F`MpY)dV0Br_w_-g3hI_r9zf@wv_&SlC~-t(4^A6Bik?IXRnpWI8CDOrqPF~+|} zX0nQnA!q~kUpAOd`;Iw6n^mN!YG5*^_@W z?-}kai4`x$=;s*#7`4_dF1I*jTx5xMTPFEr?e3n#l+br5uwEQd^=|Yv%j0giJE(!b z$y_k}6Q7Iol6AAn=O)J!MwITcsBIrVZ~Bs98s1~$xtas&Z^y`i41S ztj@y`+Q0jRS?FK~x6S$EPV9e;Ytz!mKZLEuM9$1fv!XR0exTE|(-&Ymy|sY>tsZIk z%CZr$KO(T^Pg?nMA$Z2xKEn)J9Wc2COY!OAG?gR6^A?>CZ((U$Sczgkc6zrhb`P2y zM))PeQb3bFHGk-TkaZBqm@G74AVDGDDlM7z!g=1$v_Yg)V%>_PbV%X-IyX1| z5k~8ND^INgQ7qRFlCoMH1N>5Qsjyx<%U44C!0z7ccX00IK^afz0X5FeI&$&ra0sGPR8b%=8qiF@Pt<9u6&5WOI8D9Uwsf=J$I}mLL|XByJcWm&2fRveA-uH9*~8kcZqx5u2oFIHG2&ZH;&BNtijW zdT4hM8!M#mbV1P)v%yh^P%{oX2Q80lw@9bFGbU!64+tJFU)M9lcu4fe|0HK;s(1uJlyoJ)A>^6@4Cm}b;3C9I#6a6}x)XXSP>tO6e0HGg z_e5cf9PfUvg$^HT2K>6fX~we{+J#y#>705eU2>LFdR8uT3B$Gmr5#=;_8lQ%gTVbE zOk=;8hDB!D>;SD3&tCTthVxH5#^>YjMn$OEf@UE287|V2I6DC;CivOGB!*|ym!(_N z+J3T=tmxg3EhwH%M;@<|aGxQbYODSCdV1(dg5}><^c|X>jdoP2be^@JzoyLal`ZW` z)$DumFz{neTYT(ys;*#|94?cw6d8SQ>9tPi8$mzXO5J^h>Eolu-9Ix4rH!0rV5BF! z9U~u!L5aQpLbe~CSSEfV_fdJN&^$P@MrHotY;xLyLGdS@m8VgKS8#z)*AyKLiS3wd zYMe||^wPjv;lRw){RKli+EH%r0=nv>v4nH0D=q!Ta1-SlAxK-ZQGQEV*5Q&e!$R4y z%uhAjB{kV1Po%!7$c!S|_O?X_TW$zgYUs+5#9_I@x+vn92=w?mQaln8jfWnx8^6M=`dZ- z8=7MJ`sPrwn=>la&d}A;xtu{#-!+mr>D%x; zHTUXN;i30C5fnq{r#Q+wzX0bE)d3i+De_3GtZtNr8^HHu(O*NhSJQI!Nb4qCLA1ygeBbenhtMpzkosP#~sdY2V z5oMZ>%#FnGqoD)*Ra?Uz#P~}=BZ>&O)r^{;sD6?6?U;M#WZAJQ*NkbwkMb*m+MQhU%}cWL9JE>IMobnLaR?7yY=2oemE# z6i&9_ODR0i6D)HiiJye{8g#Cy`>F;j_YIk;?{qZO(u-E7AQVkuiO`jGvr#z$$MX^7 z;UhbqA5O6=W~?lW(yuR-H$V8H6c877<`y2oN7OjAIG8o=&MSIW5@}miu9?T%4GPao z+B9ye&S?y)7Jxl@G#lcNpuQ72H7Vl^gxPCJZQ`F=JigL>HP02=VQmUJn#rHiL_V^e zNqRqM@6UCizO_ar%d){S?pqG6OYHAhUU@Q`T(@9wNEg3dK^4lj-bZZD_p?`}mLja+ zK37gtyDw@}B;DVwx$dXSbP;|SsyonmRF9#?y}lA1ket!qHHG9rLi|1q?a`+lD9WSS zK{3ywVv7Yig1fzH=ix0_w)LO>3NO)@Yt73mT02WQm|V)h+vCq()kw1sD0hveHEdDh zMT=J8EH@lbltxy}g!$Q9y;yj-?E#%N|CQcW;426L6BC)X6sHRL>$~fx^HNYztQZxI zmi%V!G;0r{o7=nkli^@KUjwE*A~Y|0L%rmoDYOa zrMtyZ@5cf+3g04sLI+u?L{m0Oys0%(ZhI5y%cOZm7EeET0v4+B;S&4xy4I^VzgkWQ zOIRkc-nUez&9G|8jF92`Cgp83?R(5mU9_16Tzh{dO?4XCy&Jfhg3XNXT2|pZvbK!kKpr?rS1w_rMLh z`dApSn_E{jjS;BhAq%xh*YAcOK3(zq-NJEJe$O1v#j@DXG3dg+4*vR4EvY8a(EN$% z9mvb1+x5vOzWovfHSq=}jtOqKB>MHIv$7DIWt~2zk5gg@{z!%0*^DmS+^jK}G0gfiB0@I3qwi^}C|UgV+1*~epQLhuLLTLx zoUjrG<>B7I-#wj}5`=W`xkc#K-o`N<=w&rw>O5y}k1#cGvPTm0C+qTXR7$|o**>*Z zWD?vUy@RwdBS5?8agxF|4`Y}dkC4_nx+FS9>Kj-Z=1taMukYMz*lGMG62prx?~23_ zjV(dY7{fZ#%)}^B$Eh>$A=kmvzYj6P#S<#4y=4>WEn*bB-Fn7V(4%)Vt1ZxqG(UqI#%trGX*=lpm8H(Zc_^WVm!)@*?U;UTDgNh#)e`HYiJ7k{ zTTK@RKWALwVjNFT;|qSBEp1%LR8gq;B#kr7546xs3eB-XIG>nz74x4Z(cH65$)VPy zgp!u7_v`BHV{(6A6$|DZZWH+c+$I|HltV$1LoOFaT$}3_?i&NXYY`|0(!4!$EU4Qf`=Dj}K5v zi*ZgS{MwF-wf#rSIyDf~`D@V#B1$$GJVi%e)7u89H!)O)FqZ*L9zxEKEc6b~<&(Vk zA_>KQ8xmNq!a$V7uooyfg0xAG#K`fua5*urM-V@j^0WMfXG8ho)bcf0p;|FSD;zTT zHqCRIUT10{sHs{QqV@iaaOfw0eXryXy2*0xHC`zg_>RLHJN~cN%r|1CC}Mv%Xk*@} z(C=32UTe$$_PkT^LM{{UF7*A|Wn5o^Et7EC1Ppz5qT*K6>syjwU zlR{pc|I|K+5!?dXD#8v(-qH<2X8GnlX@{}!T{;&tp|%un2nS&wpRswIrk(_Bl~K9( zo;hB){X1ZlB2t$C=f{c048)yH8A{zKMrD1PEoqOBLm>b|u#{(eHsg z1rYwJtTQdCiiZ0%`$a-XgsOy2)t+^%rEwtG@DwPQDnD)9JT8$QRbN{NuMXltV?OT` z((SxJ5m##C#E#-y(SJ;O6p#Eq_hJX--oDbOfu>(EK+JNHA%%Cr(*pBud~>70mkVgX zg#4w;_%U|*U=Ac1i9F}34YSMj`MoUVyTrH_S!--bQ}lYNP-iFD!mjGus=@IU^-)E9 zx%*C}eUZv$9cPloK(XGo`II~VsF7gs!S={-8W0}Ha1hr#FsJ)IDtml0^rY;Cr)-`9 zb3u|3<0gf#{f;u%FGzk7(H(~FM-KcWL~iJsAg=TccG`NgL!TjIOr)n0;Rf>z%<~wC z6I?pYQIP(#o-XpdUy(($*8I|?9VCXURPp8U{aw6w>C5<^AfG}wXrCv?_o``k-Xf+5 zEQk1K5{R=s_AgdVnDC8LVFw)K`~-!1uw3XB*$=sh=bA2HCF{~JDRW-~yE+w@R-SAW zq5~`z{T83WH*T00?mW+5Y|{6ilNfwcEv=Yk8+m9etTYG2;ReNOnPCe{?sB(ilXnv- zf$+`F^v6kA?HJC7Bt-dI6AB|!QJJfc7J4!mzW;&JHp5nB|4JKWr5fdJn+nB_-TWA` zw?Ni??!hEf<%A-@4swa~-YYp8ws;wJh%!)ky>K)wv0lEBF@%0BRd;f>8R~9bn*XbU z#gGwL^KSwGwRal6+UEGn)3HZ9&tQg^D^jVPN*V(x z(ndzc85c!H*ujr$^_U0C!mbDLASPQufw5QhEIGG^)Q9s{o~0kN4D$Z>188xGZdV=Rgmner#%#nR)d0+H$fZA8VOZ_Hr1xJd!psD7L#0C! zuVq$zzqBYn=%RZ#8VTe;@UGVUkJ>8_JxRaDGl_WiJ!N5$7A*DtRGiXKok}W;I1n23 zi=iHs6?nB$5x4dzqCpW6?)m2XMn>=ti2Nr9{ahcX1*%0CRv!wxf5gCPo9`8c!e)o0f-prk-Uj1 zZEYVy5ld*}DsD2s;mm>y-XyLhErPM%s2ASEm+x?(idh?L>2JNwwxC&+vk&?H8u_!` z%a$PLoe0_`Rn<)I5wJ1LJvelw<0A;2P1AFC&W__vgHFfKcN)?L zVeL#7gWS*KFan=%H&hay#VEI;Zri-h3U9Zb@KZyl@e>zlIYF#Ya_7C>-?8w>fZXw) z_MtiporATqXlo?7fdWfT0=tuLhJhP|A+kyQL|pQz2<~HgSI7)vu+ObHXioSYq4{gK zuX2raolc3z{dcY2Y*fcjpLABLACbwICut60gh|E4nP)nZCY~gxZ>5n>-mBU2_zQZF zqWcGK%|A2_$?J;dOYRqwda_4)KwJ|>%n!-=Nmom6bA(BPP*%`*oClpN7acafvy~MTtt4&zA(ra^gf$sSw>5aW);mOvC_@j*{{2 z>G6-QM~X2aa_ih7SE0k__6>D!LSKb?yh0}FIu=kjW3;UMMfxF#;&@4Yri+fdqqLD9 zO(gE)+dks3gL6ljLJ?s#A(tJQr#m;uS1%RDV13e$MuN%<}RVv10SN4I0?Bsof|W5 zn=#X&4}`EpDGezdsrE-th02qMgL8$qUpMp; z<7)h~=Qt9w%(}X51!Q)V4z$$c@XcGOmZ-W1BEMOKL}|1mc2|y+3>BWi`n4wttTJdF zN>!eIYuo7v#8O-4Q2CEc3CrFhnp6cJFC(e#vw1i~7@1}_O2$itZ#8LR>B`6`p-^vU zwN0?-I7Pau1L?~wZsJ)M?AT*yB&PeaN|XjjQ;*Y4@!+lOf=j*MgCR+N4EjZ@dDy{} z`)0=CB<`plFR{<}%{s7Wk(E|X**@)p97=WbgIJQR0C^H0ZhIiN3q^UqWG5ZZ!t>8; zBO{B4Us6ITQyhP~@b=Jj_G&Zmv%W=EwmTSmm(Je9w~6S;P(oc8oa}+un)6>!2J~q{ zF3H1ge?0c(Ii}$wiFQ&~fZ2QCEzm7N^gB~Ch-!>cmYorvd7>!7-97Rdo%*Exm2V36 zvpH>iw4=4X{m-hkD9{&}6wX|e0U=}Zs<8JC?r_C2sF)$N|6MIT(kP3J@W6WCdDkP` z6mKN9UR@%yZt;DZ6hB%PiNV0?i`cm|(yrNHR?;46*4{Xqcn_4f9X>PkQ2JzUe1IYU*Y(lFY&4KJku zBlq|?_zzxks~)qQS(hBgBPxjx2(K`jHCu0bBxSM(Y$dglncUdIGnL^ca>>y(R(=?t z-*zo16JA4T- zVu40WylILvK@PwjFpmoPS6AK|{?XhTv4;nY0<%NJ#2f&H-BS8n(M?x5Dz4YwkEB2 zt&35%HK}ByR3fcc0_2iD+*fm!CPv12^w3Ps@M&`YlsLxMArYwJ_JQTjloW&OMCuj^ zVTirxDg{etH(6an}+~Pm^=b? zj4~DEWSc`q+A=XC910}IbZC`=1{Cg%u~|OP8vqq2mi>XgWiWftZ~sUaEY|3`+gMnZ zI8&nXK8Y|{{SoMXL@!_Q(!s<87XJ7H%|%4d7ZjxIEs(o*SCZldr1;@cwJRAY@pHYd z!K7BaQ#0LJQupVdg|V77oSQwokl47js+(_MZ2>XA`gDx&4K>?{Z~M(SH%QN0s&WH? z&vGd5Cl=05&v2bvYsApOrAG2eQzK)d`K5LhaEEwC3bJj3Dax2X*JCm5YYdd5vAz}; z;mC4<2BzUn`OJF34OguzCG-kN7ZFJA@6hexxj*&(t{!pyq`bn+BAg+SBc}#Kfm;6DbsTWgu|3%MIgtNl#*b=Q09Stkv5p4x+fwMLt3ESp$3zoHJmQYMHcyIOsSx+yvLAja3KBuC_CtB%Y`Kh;y%C3BuC zclW+w_fbRD44^pjYGFC)=2lAbI+W zTfi&9M~Bj_(u@Y+EP4UqU`rkzxzz`~FCI(r@acinF>U54Jz19?u849_(^yrCxj-~O z3!3Z1_p#`cAM{Wv>qrj}@rsg+1f*&YJZtYBv3d*OR4g0j2PrZTK2o4B@RsZvpE~R> zM#OO$nz+LFIVhD5FbLGcU-Q>xLdxIkUvIMWRG`vek~NXXumc`}y6k|c*{S=Se?*hE z5gT&T>uF#>z1TF(H#2v<&+C4y-wU6KvIc=0UN&vTFm?PKQ1~e>5F-MqUEB4(zyMBe zO-1(k0<+eibn>9g%E!T)|NHk4|M^HlQf1)}VUrR%QoMIQ`uYPHn3|4ijk48W{|A>o B2I&9* literal 0 HcmV?d00001 From 82536f65ea253979a5dcaddbcd09af96dae3eedf Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 20 Feb 2023 12:34:01 +1000 Subject: [PATCH 16/22] wip --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 144d12f..0f4a1de 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ ABI is Zeta's cross-program integration ecosystem. -This repository contains the Zeta Cross Program Invocation (CPI) interface as well as a usage example [abi-wrapper](./abi-wrapper/). +This repository contains the Zeta Cross Program Invocation (CPI) interface as well as a usage example `abi-wrapper`. ## Cross Program Invocations @@ -57,8 +57,7 @@ The accounts and relevant data that is currently supported (non-exhaustive): - `MarginAccount` - Balance - Positions -- `Oracle` - - Price + - helper functions: get_initial_margin(), get_maintenance_margin(), get_unrealized_pnl() ## Programs From 36d421b87cde218a8c4ae942ae947ca48522e2e5 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 20 Feb 2023 13:39:54 +1000 Subject: [PATCH 17/22] adding .github build action --- .github/workflow/build.yml | 57 ++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflow/build.yml diff --git a/.github/workflow/build.yml b/.github/workflow/build.yml new file mode 100644 index 0000000..cf9efe8 --- /dev/null +++ b/.github/workflow/build.yml @@ -0,0 +1,57 @@ +name: Program + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + CARGO_TERM_COLOR: always + SOLANA_VERSION: "1.13.5" + ANCHOR_VERSION: "0.26.0" + + build: + name: Build program and test + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + name: Checkout source + - uses: actions/cache@v3 + name: Cache Cargo registry + index + with: + path: | + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: cargo-${{ runner.os }}-v0000-${{ hashFiles('**/Cargo.lock') }} + - uses: actions/cache@v3 + name: Cache Solana Tool Suite + id: cache_solana + with: + path: | + ~/.cache/solana/ + ~/.local/share/solana/ + key: solana-${{ runner.os }}-v0001-${{ env.SOLANA_VERSION }} + - uses: actions-rs/toolchain@v1 + if: steps.cache_solana.outputs.cache-hit != 'true' + name: Install Rust toolchain + with: + profile: minimal + toolchain: stable + - run: rustup component add rustfmt clippy + - name: Setup Solana CLI + run: | + sh -c "$(curl -sSfL https://release.solana.com/v${SOLANA_VERSION}/install)" + echo "$HOME/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH + PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH" + solana --version + yes | solana-keygen new + - name: Build zeta-abi + run: cargo build + - name: Build abi-wrapper + run: cd abi-wrapper && anchor build --skip-lint diff --git a/README.md b/README.md index 0f4a1de..7c1b0de 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ ABI is Zeta's cross-program integration ecosystem. This repository contains the Zeta Cross Program Invocation (CPI) interface as well as a usage example `abi-wrapper`. +[![build](../../workflows/build/badge.svg)](../../actions/workflows/build.yml) + ## Cross Program Invocations ### Instructions From 6bda8658155c6e3961a1b8651667666ff7a68704 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 20 Feb 2023 13:47:12 +1000 Subject: [PATCH 18/22] github actions fix --- .github/workflow/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflow/build.yml b/.github/workflow/build.yml index cf9efe8..b1a8b5b 100644 --- a/.github/workflow/build.yml +++ b/.github/workflow/build.yml @@ -13,6 +13,7 @@ env: SOLANA_VERSION: "1.13.5" ANCHOR_VERSION: "0.26.0" +jobs: build: name: Build program and test runs-on: ubuntu-20.04 From 7a1a318abf9be7c96567192bbf306d651be2204f Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 20 Feb 2023 13:52:34 +1000 Subject: [PATCH 19/22] github actions fix --- .github/workflow/build.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflow/build.yml b/.github/workflow/build.yml index b1a8b5b..332c30b 100644 --- a/.github/workflow/build.yml +++ b/.github/workflow/build.yml @@ -1,12 +1,6 @@ name: Program -on: - push: - branches: - - main - pull_request: - branches: - - main +on: [push, pull_request] env: CARGO_TERM_COLOR: always From 0b15302899040f393a5e7c283b735228b358dc81 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Mon, 20 Feb 2023 16:28:14 +1000 Subject: [PATCH 20/22] wip --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cb38f22..5623420 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,6 @@ default = ["no-entrypoint", "cpi"] [dependencies] anchor-lang = "0.26.0" anchor-spl = "0.26.0" -solana-program = "1.13.5" +solana-program = "<1.15.0" bytemuck = "1.4.0" chainlink_solana = "1.0.0" \ No newline at end of file From 7bfdd790d44ca932b264fea4dccdc391ee3262e2 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Tue, 21 Feb 2023 10:08:41 +1000 Subject: [PATCH 21/22] fixing as per PR comments --- src/account.rs | 30 ++++-------------------------- src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/account.rs b/src/account.rs index 9e6528b..e95d29a 100644 --- a/src/account.rs +++ b/src/account.rs @@ -56,7 +56,9 @@ pub struct ZetaGroup { pub perp_parameters: PerpParameters, // 24 pub perp_sync_queue: Pubkey, // 32 pub oracle_backup_feed: Pubkey, // 32 - pub padding: [u8; 966], // 966 + pub perps_only: bool, // 1 + pub flex_underlying: bool, // 1 + pub padding: [u8; 964], // 964 } // 7696 #[zero_copy] @@ -88,25 +90,6 @@ impl Strike { } Ok(self.value) } - - pub fn set(&mut self, strike: u64) -> Result<()> { - // There shouldn't be a case where you set a strike without resetting it first. - if self.is_set() { - return Err(error!(ZetaError::CannotSetInitializedStrike)); - } - self.is_set = true; - self.value = strike; - Ok(()) - } - - pub fn reset(&mut self) -> Result<()> { - if !self.is_set() { - return Err(error!(ZetaError::CannotResetUninitializedStrike)); - } - self.value = 0; - self.is_set = false; - Ok(()) - } } #[zero_copy] @@ -214,12 +197,6 @@ impl MarginAccount { &zeta_group.margin_parameters, ); - msg!( - "get_initial_margin {} {}", - initial_margin_requirement, - perp_margin_requirement - ); - initial_margin_requirement .checked_add(perp_margin_requirement) .unwrap() @@ -577,6 +554,7 @@ pub enum Asset { SOL = 0, BTC = 1, ETH = 2, + APT = 3, UNDEFINED = 255, } diff --git a/src/lib.rs b/src/lib.rs index db15128..c423ea2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,7 @@ mod zeta_abi { Ok(()) } - pub fn close_open_orders(ctx: Context, _map_nonce: u8) -> Result<()> { + pub(crate) fn close_open_orders(ctx: Context, _map_nonce: u8) -> Result<()> { Ok(()) } From 93f3958ea5c51aec962b7a573f1cbb11b39d2030 Mon Sep 17 00:00:00 2001 From: Konrad Sosnowski Date: Tue, 21 Feb 2023 10:29:00 +1000 Subject: [PATCH 22/22] adding changelog, bumping version --- CHANGELOG.md | 15 +++++++++++++++ Cargo.toml | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a41799c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +All notable changes to this project will be documented in this file. +Version changes are pinned to SDK releases. + +## [0.2.0] 21-02-2023 + +- program: Add support for new DEX APIs: place_order_v4, place_perp_order_v2, close_open_orders, close_margin_account ([#2](https://github.com/zetamarkets/zeta-abi/pull/2)) +- program: add APT asset +- program: MarginAccount helper functions: get_initial_margin(), get_maintenance_margin(), get_unrealized_pnl() +- abi-wrapper: introducing sample program that utilizes ABI CPIs + +## [0.1.0] - 2022-10-27 + +- program: First version with support for initialization of margin and open orders accounts, deposit, withdraw, order placement and cancellation diff --git a/Cargo.toml b/Cargo.toml index 5623420..bf4eccf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zeta-abi" -version = "0.1.0" +version = "0.2.0" edition = "2021" [features]