-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
- Loading branch information
1 parent
35d4a23
commit 808c2cc
Showing
6 changed files
with
159 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use crate::state::*; | ||
use crate::{error::MangoError, state::*}; | ||
|
||
#[derive(Accounts)] | ||
pub struct IxGateSet<'info> { | ||
#[account( | ||
mut, | ||
has_one = admin, | ||
// group <-> admin relation is checked at #1 | ||
)] | ||
pub group: AccountLoader<'info, Group>, | ||
pub admin: Signer<'info>, | ||
} | ||
|
||
pub fn ix_gate_set(ctx: Context<IxGateSet>, ix_gate: u128) -> Result<()> { | ||
let mut group = ctx.accounts.group.load_mut()?; | ||
|
||
msg!("old {:?}, new {:?}", group.ix_gate, ix_gate); | ||
|
||
let mut require_group_admin = false; | ||
for i in 0..=47 { | ||
// only admin can re-enable | ||
if group.ix_gate & (1 << i) == 1 && ix_gate & (1 << i) == 0 { | ||
require_group_admin = true; | ||
} | ||
} | ||
|
||
group.ix_gate = ix_gate; | ||
|
||
// account constraint #1 | ||
if require_group_admin { | ||
require!( | ||
group.admin == ctx.accounts.admin.key(), | ||
MangoError::SomeError | ||
); | ||
} else { | ||
require!( | ||
group.admin == ctx.accounts.admin.key() | ||
|| group.security_admin == ctx.accounts.admin.key(), | ||
MangoError::SomeError | ||
); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters