2022-02-10 01:04:47 -08:00
|
|
|
use anchor_lang::prelude::*;
|
2022-03-31 05:37:05 -07:00
|
|
|
use static_assertions::const_assert_eq;
|
|
|
|
use std::mem::size_of;
|
2022-02-10 01:04:47 -08:00
|
|
|
|
2022-02-22 00:32:21 -08:00
|
|
|
// TODO: Assuming we allow up to 65536 different tokens
|
|
|
|
pub type TokenIndex = u16;
|
2022-07-04 04:13:11 -07:00
|
|
|
pub const QUOTE_TOKEN_INDEX: TokenIndex = 0;
|
2022-02-22 00:32:21 -08:00
|
|
|
|
2022-12-06 00:25:43 -08:00
|
|
|
#[account(zero_copy(safe_bytemuck_derives))]
|
2022-07-05 10:31:47 -07:00
|
|
|
#[derive(Debug)]
|
2022-03-07 07:16:34 -08:00
|
|
|
pub struct Group {
|
2022-07-06 00:56:14 -07:00
|
|
|
// ABI: Clients rely on this being at offset 8
|
2022-07-31 00:28:16 -07:00
|
|
|
pub creator: Pubkey,
|
2022-02-22 00:32:21 -08:00
|
|
|
|
2022-07-06 00:56:14 -07:00
|
|
|
// ABI: Clients rely on this being at offset 40
|
|
|
|
pub group_num: u32,
|
|
|
|
|
2022-07-31 00:28:16 -07:00
|
|
|
pub admin: Pubkey,
|
|
|
|
|
|
|
|
// TODO: unused, use case - listing shit tokens with conservative parameters (mostly defaults)
|
|
|
|
pub fast_listing_admin: Pubkey,
|
|
|
|
|
2023-02-25 11:34:16 -08:00
|
|
|
// This is the token index of the mngo token listed on the group
|
|
|
|
pub mngo_token_index: TokenIndex,
|
|
|
|
pub padding: [u8; 2],
|
2022-07-06 00:56:14 -07:00
|
|
|
|
2022-07-04 04:13:11 -07:00
|
|
|
pub insurance_vault: Pubkey,
|
|
|
|
pub insurance_mint: Pubkey,
|
|
|
|
|
2022-02-25 06:14:15 -08:00
|
|
|
pub bump: u8,
|
2022-08-01 03:56:29 -07:00
|
|
|
|
2022-06-09 09:27:31 -07:00
|
|
|
pub testing: u8,
|
2022-08-01 03:56:29 -07:00
|
|
|
|
|
|
|
pub version: u8,
|
|
|
|
|
2023-02-25 11:34:16 -08:00
|
|
|
// Buyback fees with Mngo: allow exchanging fees with mngo at a bonus
|
|
|
|
pub buyback_fees: u8,
|
|
|
|
// Buyback fees with Mngo: how much should the bonus be,
|
|
|
|
// e.g. a bonus factor of 1.2 means 120$ worth fees could be swapped for mngo worth 100$ at current market price
|
|
|
|
pub buyback_fees_mngo_bonus_factor: f32,
|
2022-08-01 07:53:30 -07:00
|
|
|
|
2022-09-14 01:55:24 -07:00
|
|
|
pub address_lookup_tables: [Pubkey; 20],
|
|
|
|
|
2023-01-12 00:12:55 -08:00
|
|
|
pub security_admin: Pubkey,
|
|
|
|
|
2023-01-23 05:58:03 -08:00
|
|
|
// Deposit limit for a mango account in quote native, enforced on quote value of account assets
|
|
|
|
// Set to 0 to disable, which also means by default there is no limit
|
|
|
|
pub deposit_limit_quote: u64,
|
|
|
|
|
2023-01-26 11:27:39 -08:00
|
|
|
// Map of ixs and their state of gating
|
|
|
|
// 0 is chosen as enabled, becase we want to start out with all ixs enabled, 1 is disabled
|
|
|
|
pub ix_gate: u128,
|
|
|
|
|
2023-02-25 11:34:16 -08:00
|
|
|
// Buyback fees with Mngo:
|
|
|
|
// A mango account which would be counter party for settling fees with mngo
|
|
|
|
// This ensures that the system doesn't have a net deficit of tokens
|
|
|
|
// The workflow should be something like this
|
|
|
|
// - the dao deposits quote tokens in its respective mango account
|
|
|
|
// - the user deposits some mngo tokens in his mango account
|
|
|
|
// - the user then claims quote for mngo at a bonus rate
|
|
|
|
pub buyback_fees_swap_mango_account: Pubkey,
|
|
|
|
|
|
|
|
pub reserved: [u8; 1832],
|
2022-02-10 00:07:34 -08:00
|
|
|
}
|
2022-09-14 01:55:24 -07:00
|
|
|
const_assert_eq!(
|
|
|
|
size_of::<Group>(),
|
2023-02-25 11:34:16 -08:00
|
|
|
32 + 4 + 32 * 2 + 4 + 32 * 2 + 4 + 4 + 20 * 32 + 32 + 8 + 16 + 32 + 1832
|
2022-09-14 01:55:24 -07:00
|
|
|
);
|
2022-12-05 06:23:20 -08:00
|
|
|
const_assert_eq!(size_of::<Group>(), 2736);
|
2022-03-31 05:37:05 -07:00
|
|
|
const_assert_eq!(size_of::<Group>() % 8, 0);
|
2022-02-25 06:14:15 -08:00
|
|
|
|
2022-08-01 03:56:29 -07:00
|
|
|
impl Group {
|
2023-02-25 11:34:16 -08:00
|
|
|
pub fn buyback_fees(&self) -> bool {
|
|
|
|
self.buyback_fees == 1
|
|
|
|
}
|
|
|
|
|
2022-08-01 03:56:29 -07:00
|
|
|
pub fn is_testing(&self) -> bool {
|
|
|
|
self.testing == 1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn multiple_banks_supported(&self) -> bool {
|
2022-09-01 00:48:38 -07:00
|
|
|
self.is_testing() || self.version > 1
|
2022-08-01 03:56:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn serum3_supported(&self) -> bool {
|
|
|
|
self.is_testing() || self.version > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn perps_supported(&self) -> bool {
|
2022-09-01 00:48:38 -07:00
|
|
|
self.is_testing() || self.version > 1
|
2022-08-01 03:56:29 -07:00
|
|
|
}
|
2023-01-12 00:12:55 -08:00
|
|
|
|
2023-01-26 11:27:39 -08:00
|
|
|
pub fn is_ix_enabled(&self, ix: IxGate) -> bool {
|
|
|
|
self.ix_gate & (1 << ix as u128) == 0
|
2023-01-12 00:12:55 -08:00
|
|
|
}
|
2022-08-01 03:56:29 -07:00
|
|
|
}
|
|
|
|
|
2023-01-26 11:27:39 -08:00
|
|
|
/// Enum for lookup into ix gate
|
|
|
|
/// note:
|
|
|
|
/// total ix files 56,
|
|
|
|
/// ix files included 48,
|
|
|
|
/// ix files not included 8,
|
|
|
|
/// - Benchmark,
|
|
|
|
/// - ComputeAccountData,
|
|
|
|
/// - GroupCreate
|
|
|
|
/// - GroupEdit
|
|
|
|
/// - IxGateSet,
|
|
|
|
/// - PerpZeroOut,
|
|
|
|
/// - PerpEditMarket,
|
|
|
|
/// - TokenEdit,
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
pub enum IxGate {
|
|
|
|
AccountClose = 0,
|
|
|
|
AccountCreate = 1,
|
|
|
|
AccountEdit = 2,
|
|
|
|
AccountExpand = 3,
|
|
|
|
AccountToggleFreeze = 4,
|
|
|
|
AltExtend = 5,
|
|
|
|
AltSet = 6,
|
|
|
|
FlashLoan = 7,
|
|
|
|
GroupClose = 8,
|
|
|
|
GroupCreate = 9,
|
|
|
|
HealthRegion = 10,
|
|
|
|
PerpCancelAllOrders = 11,
|
|
|
|
PerpCancelAllOrdersBySide = 12,
|
|
|
|
PerpCancelOrder = 13,
|
|
|
|
PerpCancelOrderByClientOrderId = 14,
|
|
|
|
PerpCloseMarket = 15,
|
|
|
|
PerpConsumeEvents = 16,
|
|
|
|
PerpCreateMarket = 17,
|
|
|
|
PerpDeactivatePosition = 18,
|
2023-02-02 00:00:37 -08:00
|
|
|
PerpLiqBaseOrPositivePnl = 19,
|
2023-01-26 11:27:39 -08:00
|
|
|
PerpLiqForceCancelOrders = 20,
|
2023-02-02 00:00:37 -08:00
|
|
|
PerpLiqNegativePnlOrBankruptcy = 21,
|
2023-01-26 11:27:39 -08:00
|
|
|
PerpPlaceOrder = 22,
|
|
|
|
PerpSettleFees = 23,
|
|
|
|
PerpSettlePnl = 24,
|
|
|
|
PerpUpdateFunding = 25,
|
|
|
|
Serum3CancelAllOrders = 26,
|
|
|
|
Serum3CancelOrder = 27,
|
|
|
|
Serum3CloseOpenOrders = 28,
|
|
|
|
Serum3CreateOpenOrders = 29,
|
|
|
|
Serum3DeregisterMarket = 30,
|
|
|
|
Serum3EditMarket = 31,
|
|
|
|
Serum3LiqForceCancelOrders = 32,
|
|
|
|
Serum3PlaceOrder = 33,
|
|
|
|
Serum3RegisterMarket = 34,
|
|
|
|
Serum3SettleFunds = 35,
|
|
|
|
StubOracleClose = 36,
|
|
|
|
StubOracleCreate = 37,
|
|
|
|
StubOracleSet = 38,
|
|
|
|
TokenAddBank = 39,
|
|
|
|
TokenDeposit = 40,
|
|
|
|
TokenDeregister = 41,
|
|
|
|
TokenLiqBankruptcy = 42,
|
|
|
|
TokenLiqWithToken = 43,
|
|
|
|
TokenRegister = 44,
|
|
|
|
TokenRegisterTrustless = 45,
|
|
|
|
TokenUpdateIndexAndRate = 46,
|
|
|
|
TokenWithdraw = 47,
|
2023-02-25 11:34:16 -08:00
|
|
|
AccountBuybackFeesWithMngo = 48,
|
2023-01-26 11:27:39 -08:00
|
|
|
}
|
|
|
|
|
2022-07-31 00:28:16 -07:00
|
|
|
// note: using creator instead of admin, since admin can be changed
|
2022-02-25 06:14:15 -08:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! group_seeds {
|
|
|
|
( $group:expr ) => {
|
2022-05-27 00:23:17 -07:00
|
|
|
&[
|
|
|
|
b"Group".as_ref(),
|
2022-07-31 00:28:16 -07:00
|
|
|
$group.creator.as_ref(),
|
2022-05-27 00:23:17 -07:00
|
|
|
&$group.group_num.to_le_bytes(),
|
|
|
|
&[$group.bump],
|
|
|
|
]
|
2022-02-25 06:14:15 -08:00
|
|
|
};
|
|
|
|
}
|
2022-02-28 02:18:35 -08:00
|
|
|
|
|
|
|
pub use group_seeds;
|