-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
state: tbtc -> config make config pda (remove generated keypair) fix tests
- Loading branch information
Showing
16 changed files
with
380 additions
and
346 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
32 changes: 19 additions & 13 deletions
32
cross-chain/solana/programs/tbtc/src/processor/admin/add_guardian.rs
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,37 +1,43 @@ | ||
use crate::{ | ||
error::TbtcError, | ||
state::{GuardianInfo, Tbtc}, | ||
state::{Config, GuardianInfo}, | ||
}; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct AddGuardian<'info> { | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX], | ||
bump, | ||
has_one = authority @ TbtcError::IsNotAuthority | ||
)] | ||
pub tbtc: Account<'info, Tbtc>, | ||
pub authority: Signer<'info>, | ||
/// CHECK: the guardian does not need to sign | ||
pub guardian: UncheckedAccount<'info>, | ||
config: Account<'info, Config>, | ||
|
||
#[account(mut)] | ||
pub payer: Signer<'info>, | ||
authority: Signer<'info>, | ||
|
||
#[account( | ||
init, | ||
payer = payer, | ||
space = GuardianInfo::MAXIMUM_SIZE, | ||
seeds = [GuardianInfo::SEED_PREFIX, tbtc.key().as_ref(), guardian.key().as_ref()], bump | ||
payer = authority, | ||
space = 8 + GuardianInfo::INIT_SPACE, | ||
seeds = [GuardianInfo::SEED_PREFIX, guardian.key().as_ref()], | ||
bump | ||
)] | ||
pub guardian_info: Account<'info, GuardianInfo>, | ||
pub system_program: Program<'info, System>, | ||
guardian_info: Account<'info, GuardianInfo>, | ||
|
||
/// CHECK: Required authority to pause contract. This pubkey lives in `GuardianInfo`. | ||
guardian: AccountInfo<'info>, | ||
|
||
system_program: Program<'info, System>, | ||
} | ||
|
||
pub fn add_guardian(ctx: Context<AddGuardian>) -> Result<()> { | ||
ctx.accounts.guardian_info.set_inner(GuardianInfo { | ||
guardian: ctx.accounts.guardian.key(), | ||
bump: *ctx.bumps.get("guardian_info").unwrap(), | ||
bump: ctx.bumps["guardian_info"], | ||
}); | ||
|
||
ctx.accounts.tbtc.guardians += 1; | ||
ctx.accounts.config.num_guardians += 1; | ||
Ok(()) | ||
} |
32 changes: 19 additions & 13 deletions
32
cross-chain/solana/programs/tbtc/src/processor/admin/add_minter.rs
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,37 +1,43 @@ | ||
use crate::{ | ||
error::TbtcError, | ||
state::{MinterInfo, Tbtc}, | ||
state::{Config, MinterInfo}, | ||
}; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct AddMinter<'info> { | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX], | ||
bump, | ||
has_one = authority @ TbtcError::IsNotAuthority | ||
)] | ||
pub tbtc: Account<'info, Tbtc>, | ||
pub authority: Signer<'info>, | ||
/// CHECK: the minter does not need to sign | ||
pub minter: UncheckedAccount<'info>, | ||
config: Account<'info, Config>, | ||
|
||
#[account(mut)] | ||
pub payer: Signer<'info>, | ||
authority: Signer<'info>, | ||
|
||
#[account( | ||
init, | ||
payer = payer, | ||
space = MinterInfo::MAXIMUM_SIZE, | ||
seeds = [MinterInfo::SEED_PREFIX, tbtc.key().as_ref(), minter.key().as_ref()], bump | ||
payer = authority, | ||
space = 8 + MinterInfo::INIT_SPACE, | ||
seeds = [MinterInfo::SEED_PREFIX, minter.key().as_ref()], | ||
bump | ||
)] | ||
pub minter_info: Account<'info, MinterInfo>, | ||
pub system_program: Program<'info, System>, | ||
minter_info: Account<'info, MinterInfo>, | ||
|
||
/// CHECK: Required authority to mint tokens. This pubkey lives in `MinterInfo`. | ||
minter: AccountInfo<'info>, | ||
|
||
system_program: Program<'info, System>, | ||
} | ||
|
||
pub fn add_minter(ctx: Context<AddMinter>) -> Result<()> { | ||
ctx.accounts.minter_info.set_inner(MinterInfo { | ||
minter: ctx.accounts.minter.key(), | ||
bump: *ctx.bumps.get("minter_info").unwrap(), | ||
bump: ctx.bumps["minter_info"], | ||
}); | ||
|
||
ctx.accounts.tbtc.minters += 1; | ||
ctx.accounts.config.num_minters += 1; | ||
Ok(()) | ||
} |
16 changes: 9 additions & 7 deletions
16
cross-chain/solana/programs/tbtc/src/processor/admin/change_authority.rs
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,22 @@ | ||
use crate::{error::TbtcError, state::Tbtc}; | ||
use crate::{error::TbtcError, state::Config}; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct ChangeAuthority<'info> { | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX], | ||
bump, | ||
has_one = authority @ TbtcError::IsNotAuthority | ||
)] | ||
pub tbtc: Account<'info, Tbtc>, | ||
pub authority: Signer<'info>, | ||
#[account(mut)] | ||
pub payer: Signer<'info>, | ||
pub new_authority: Signer<'info>, | ||
config: Account<'info, Config>, | ||
|
||
authority: Signer<'info>, | ||
|
||
new_authority: Signer<'info>, | ||
} | ||
|
||
pub fn change_authority(ctx: Context<ChangeAuthority>) -> Result<()> { | ||
ctx.accounts.tbtc.authority = ctx.accounts.new_authority.key(); | ||
ctx.accounts.config.authority = ctx.accounts.new_authority.key(); | ||
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
18 changes: 11 additions & 7 deletions
18
cross-chain/solana/programs/tbtc/src/processor/admin/pause.rs
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,26 +1,30 @@ | ||
use crate::{ | ||
error::TbtcError, | ||
state::{GuardianInfo, Tbtc}, | ||
state::{Config, GuardianInfo}, | ||
}; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct Pause<'info> { | ||
#[account( | ||
mut, | ||
constraint = !tbtc.paused @ TbtcError::IsPaused | ||
seeds = [Config::SEED_PREFIX], | ||
bump, | ||
constraint = !config.paused @ TbtcError::IsPaused | ||
)] | ||
pub tbtc: Account<'info, Tbtc>, | ||
config: Account<'info, Config>, | ||
|
||
#[account( | ||
has_one = guardian, | ||
seeds = [GuardianInfo::SEED_PREFIX, tbtc.key().as_ref(), guardian.key().as_ref()], | ||
seeds = [GuardianInfo::SEED_PREFIX, guardian.key().as_ref()], | ||
bump = guardian_info.bump | ||
)] | ||
pub guardian_info: Account<'info, GuardianInfo>, | ||
pub guardian: Signer<'info>, | ||
guardian_info: Account<'info, GuardianInfo>, | ||
|
||
guardian: Signer<'info>, | ||
} | ||
|
||
pub fn pause(ctx: Context<Pause>) -> Result<()> { | ||
ctx.accounts.tbtc.paused = true; | ||
ctx.accounts.config.paused = true; | ||
Ok(()) | ||
} |
20 changes: 12 additions & 8 deletions
20
cross-chain/solana/programs/tbtc/src/processor/admin/remove_guardian.rs
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,29 +1,33 @@ | ||
use crate::{ | ||
error::TbtcError, | ||
state::{GuardianInfo, Tbtc}, | ||
state::{Config, GuardianInfo}, | ||
}; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
#[instruction(guardian: Pubkey)] | ||
pub struct RemoveGuardian<'info> { | ||
#[account( | ||
mut, | ||
has_one = authority @ TbtcError::IsNotAuthority, | ||
)] | ||
pub tbtc: Account<'info, Tbtc>, | ||
pub authority: Signer<'info>, | ||
config: Account<'info, Config>, | ||
|
||
authority: Signer<'info>, | ||
|
||
#[account( | ||
mut, | ||
has_one = guardian, | ||
close = authority, | ||
seeds = [GuardianInfo::SEED_PREFIX, tbtc.key().as_ref(), guardian.as_ref()], | ||
seeds = [GuardianInfo::SEED_PREFIX, guardian.key().as_ref()], | ||
bump = guardian_info.bump, | ||
)] | ||
pub guardian_info: Account<'info, GuardianInfo>, | ||
guardian_info: Account<'info, GuardianInfo>, | ||
|
||
/// CHECK: Required authority to pause contract. This pubkey lives in `GuardianInfo`. | ||
guardian: AccountInfo<'info>, | ||
} | ||
|
||
pub fn remove_guardian(ctx: Context<RemoveGuardian>, _guardian: Pubkey) -> Result<()> { | ||
ctx.accounts.tbtc.guardians -= 1; | ||
pub fn remove_guardian(ctx: Context<RemoveGuardian>) -> Result<()> { | ||
ctx.accounts.config.num_guardians -= 1; | ||
Ok(()) | ||
} |
24 changes: 15 additions & 9 deletions
24
cross-chain/solana/programs/tbtc/src/processor/admin/remove_minter.rs
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,29 +1,35 @@ | ||
use crate::{ | ||
error::TbtcError, | ||
state::{MinterInfo, Tbtc}, | ||
state::{Config, MinterInfo}, | ||
}; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
#[instruction(minter: Pubkey)] | ||
pub struct RemoveMinter<'info> { | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX], | ||
bump, | ||
has_one = authority @ TbtcError::IsNotAuthority | ||
)] | ||
pub tbtc: Account<'info, Tbtc>, | ||
pub authority: Signer<'info>, | ||
config: Account<'info, Config>, | ||
|
||
authority: Signer<'info>, | ||
|
||
#[account( | ||
mut, | ||
constraint = minter_info.minter == minter, | ||
has_one = minter, | ||
close = authority, | ||
seeds = [MinterInfo::SEED_PREFIX, tbtc.key().as_ref(), minter.as_ref()], | ||
seeds = [MinterInfo::SEED_PREFIX, minter.key().as_ref()], | ||
bump = minter_info.bump, | ||
)] | ||
pub minter_info: Account<'info, MinterInfo>, | ||
minter_info: Account<'info, MinterInfo>, | ||
|
||
/// CHECK: Required authority to mint tokens. This pubkey lives in `MinterInfo`. | ||
minter: AccountInfo<'info>, | ||
} | ||
|
||
pub fn remove_minter(ctx: Context<RemoveMinter>, _minter: Pubkey) -> Result<()> { | ||
ctx.accounts.tbtc.minters -= 1; | ||
pub fn remove_minter(ctx: Context<RemoveMinter>) -> Result<()> { | ||
ctx.accounts.config.num_minters -= 1; | ||
Ok(()) | ||
} |
15 changes: 9 additions & 6 deletions
15
cross-chain/solana/programs/tbtc/src/processor/admin/unpause.rs
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,18 +1,21 @@ | ||
use crate::{error::TbtcError, state::Tbtc}; | ||
use crate::{error::TbtcError, state::Config}; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct Unpause<'info> { | ||
#[account( | ||
mut, | ||
constraint = tbtc.paused @ TbtcError::IsNotPaused, | ||
has_one = authority @ TbtcError::IsNotAuthority | ||
seeds = [Config::SEED_PREFIX], | ||
bump, | ||
has_one = authority @ TbtcError::IsNotAuthority, | ||
constraint = config.paused @ TbtcError::IsNotPaused | ||
)] | ||
pub tbtc: Account<'info, Tbtc>, | ||
pub authority: Signer<'info>, | ||
config: Account<'info, Config>, | ||
|
||
authority: Signer<'info>, | ||
} | ||
|
||
pub fn unpause(ctx: Context<Unpause>) -> Result<()> { | ||
ctx.accounts.tbtc.paused = false; | ||
ctx.accounts.config.paused = false; | ||
Ok(()) | ||
} |
Oops, something went wrong.