Skip to content

Commit

Permalink
anchor: rename treasury to vault (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao authored Jan 1, 2025
1 parent 645393c commit 87ad4c2
Show file tree
Hide file tree
Showing 34 changed files with 719 additions and 803 deletions.
10 changes: 5 additions & 5 deletions anchor/libs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ pub fn share_class_signer_seeds(_attr: TokenStream, item: TokenStream) -> TokenS
}

#[proc_macro_attribute]
pub fn treasury_signer_seeds(_attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn vault_signer_seeds(_attr: TokenStream, item: TokenStream) -> TokenStream {
// Parse the input as a function
let input = parse_macro_input!(item as ItemFn);
let func_attrs = &input.attrs;
let func_vis = &input.vis;
let func_sig = &input.sig;
let func_block = &input.block;

// Generate the modified function with `treasury_signer_seeds` added at the start of the body
// Generate the modified function with `vault_signer_seeds` added at the start of the body
let expanded = quote! {
#(#func_attrs)*
#func_vis #func_sig {
// We assume the fund account and the treasury bump seed are available in the context
// We assume the fund account and the vault bump seed are available in the context
let fund_key = ctx.accounts.fund.key();
let seeds = [
b"treasury".as_ref(),
fund_key.as_ref(),
&[ctx.bumps.treasury],
&[ctx.bumps.vault],
];
let treasury_signer_seeds = &[&seeds[..]];
let vault_signer_seeds = &[&seeds[..]];

// Original function body follows
#func_block
Expand Down
82 changes: 41 additions & 41 deletions anchor/programs/glam/src/instructions/drift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anchor_lang::prelude::*;
use anchor_spl::token::Token;
use anchor_spl::token_interface::TokenAccount;
use drift::{MarketType, PositionDirection};
use glam_macros::treasury_signer_seeds;
use glam_macros::vault_signer_seeds;

use crate::error::AccessError;
use crate::state::*;
Expand Down Expand Up @@ -35,7 +35,7 @@ pub struct DriftInitialize<'info> {
pub state: UncheckedAccount<'info>,

#[account(seeds = [b"treasury".as_ref(), fund.key().as_ref()], bump)]
pub treasury: SystemAccount<'info>,
pub vault: SystemAccount<'info>,

#[account(mut)]
pub signer: Signer<'info>,
Expand All @@ -47,19 +47,19 @@ pub struct DriftInitialize<'info> {

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftInitialize))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn initialize_handler(ctx: Context<DriftInitialize>) -> Result<()> {
initialize_user_stats(CpiContext::new_with_signer(
ctx.accounts.drift_program.to_account_info(),
InitializeUserStats {
user_stats: ctx.accounts.user_stats.to_account_info(),
state: ctx.accounts.state.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
payer: ctx.accounts.signer.to_account_info(),
rent: ctx.accounts.rent.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
))?;

let mut name = [0u8; 32];
Expand All @@ -72,12 +72,12 @@ pub fn initialize_handler(ctx: Context<DriftInitialize>) -> Result<()> {
user: ctx.accounts.user.to_account_info(),
user_stats: ctx.accounts.user_stats.to_account_info(),
state: ctx.accounts.state.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
payer: ctx.accounts.signer.to_account_info(),
rent: ctx.accounts.rent.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
),
0,
name,
Expand All @@ -96,7 +96,7 @@ pub struct DriftUpdate<'info> {
pub user: UncheckedAccount<'info>,

#[account(seeds = [b"treasury".as_ref(), fund.key().as_ref()], bump)]
pub treasury: SystemAccount<'info>,
pub vault: SystemAccount<'info>,

#[account(mut)]
pub signer: Signer<'info>,
Expand All @@ -106,7 +106,7 @@ pub struct DriftUpdate<'info> {

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftUpdateUser))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn update_user_custom_margin_ratio_handler(
ctx: Context<DriftUpdate>,
sub_account_id: u16,
Expand All @@ -117,9 +117,9 @@ pub fn update_user_custom_margin_ratio_handler(
ctx.accounts.drift_program.to_account_info(),
UpdateUserCustomMarginRatio {
user: ctx.accounts.user.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
),
sub_account_id,
margin_ratio,
Expand All @@ -130,7 +130,7 @@ pub fn update_user_custom_margin_ratio_handler(

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftUpdateUser))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn update_user_margin_trading_enabled_handler(
ctx: Context<DriftUpdate>,
sub_account_id: u16,
Expand All @@ -141,9 +141,9 @@ pub fn update_user_margin_trading_enabled_handler(
ctx.accounts.drift_program.to_account_info(),
UpdateUserMarginTradingEnabled {
user: ctx.accounts.user.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
),
sub_account_id,
margin_trading_enabled,
Expand All @@ -154,7 +154,7 @@ pub fn update_user_margin_trading_enabled_handler(

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftUpdateUser))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn update_user_delegate_handler(
ctx: Context<DriftUpdate>,
sub_account_id: u16,
Expand All @@ -165,9 +165,9 @@ pub fn update_user_delegate_handler(
ctx.accounts.drift_program.to_account_info(),
UpdateUserDelegate {
user: ctx.accounts.user.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
),
sub_account_id,
delegate,
Expand All @@ -192,12 +192,12 @@ pub struct DriftDeposit<'info> {
pub state: UncheckedAccount<'info>,

#[account(seeds = [b"treasury".as_ref(), fund.key().as_ref()], bump)]
pub treasury: SystemAccount<'info>,
pub vault: SystemAccount<'info>,

#[account(mut)]
pub drift_ata: Box<InterfaceAccount<'info, TokenAccount>>, // spot market vault
#[account(mut)]
pub treasury_ata: Box<InterfaceAccount<'info, TokenAccount>>,
pub vault_ata: Box<InterfaceAccount<'info, TokenAccount>>,

#[account(mut)]
pub signer: Signer<'info>,
Expand All @@ -208,7 +208,7 @@ pub struct DriftDeposit<'info> {

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftDeposit))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn deposit_handler<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, DriftDeposit<'info>>,
market_index: u16,
Expand All @@ -221,12 +221,12 @@ pub fn deposit_handler<'c: 'info, 'info>(
user: ctx.accounts.user.to_account_info(),
user_stats: ctx.accounts.user_stats.to_account_info(),
state: ctx.accounts.state.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
spot_market_vault: ctx.accounts.drift_ata.to_account_info(),
user_token_account: ctx.accounts.treasury_ata.to_account_info(),
user_token_account: ctx.accounts.vault_ata.to_account_info(),
token_program: ctx.accounts.token_program.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
)
.with_remaining_accounts(ctx.remaining_accounts.to_vec()),
market_index,
Expand Down Expand Up @@ -255,10 +255,10 @@ pub struct DriftWithdraw<'info> {
pub drift_signer: UncheckedAccount<'info>,

#[account(seeds = [b"treasury".as_ref(), fund.key().as_ref()], bump)]
pub treasury: SystemAccount<'info>,
pub vault: SystemAccount<'info>,

#[account(mut)]
pub treasury_ata: Box<InterfaceAccount<'info, TokenAccount>>,
pub vault_ata: Box<InterfaceAccount<'info, TokenAccount>>,
#[account(mut)]
pub drift_ata: Box<InterfaceAccount<'info, TokenAccount>>,

Expand All @@ -271,7 +271,7 @@ pub struct DriftWithdraw<'info> {

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftWithdraw))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn withdraw_handler<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, DriftWithdraw<'info>>,
market_index: u16,
Expand All @@ -284,13 +284,13 @@ pub fn withdraw_handler<'c: 'info, 'info>(
user: ctx.accounts.user.to_account_info(),
user_stats: ctx.accounts.user_stats.to_account_info(),
state: ctx.accounts.state.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
spot_market_vault: ctx.accounts.drift_ata.to_account_info(),
user_token_account: ctx.accounts.treasury_ata.to_account_info(),
user_token_account: ctx.accounts.vault_ata.to_account_info(),
token_program: ctx.accounts.token_program.to_account_info(),
drift_signer: ctx.accounts.drift_signer.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
)
.with_remaining_accounts(ctx.remaining_accounts.to_vec()),
market_index,
Expand All @@ -317,7 +317,7 @@ pub struct DriftDeleteUser<'info> {
pub state: UncheckedAccount<'info>,

#[account(seeds = [b"treasury".as_ref(), fund.key().as_ref()], bump)]
pub treasury: SystemAccount<'info>,
pub vault: SystemAccount<'info>,

#[account(mut)]
pub signer: Signer<'info>,
Expand All @@ -328,17 +328,17 @@ pub struct DriftDeleteUser<'info> {

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftDeleteUser))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn delete_user_handler(ctx: Context<DriftDeleteUser>) -> Result<()> {
delete_user(CpiContext::new_with_signer(
ctx.accounts.drift_program.to_account_info(),
DeleteUser {
user: ctx.accounts.user.to_account_info(),
user_stats: ctx.accounts.user_stats.to_account_info(),
state: ctx.accounts.state.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
))?;

Ok(())
Expand All @@ -358,7 +358,7 @@ pub struct DriftPlaceOrders<'info> {
pub state: UncheckedAccount<'info>,

#[account(seeds = [b"treasury".as_ref(), fund.key().as_ref()], bump)]
pub treasury: SystemAccount<'info>,
pub vault: SystemAccount<'info>,

#[account(mut)]
pub signer: Signer<'info>,
Expand All @@ -369,7 +369,7 @@ pub struct DriftPlaceOrders<'info> {

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftPlaceOrders))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn place_orders_handler<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, DriftPlaceOrders<'info>>,
order_params: Vec<OrderParams>,
Expand Down Expand Up @@ -420,9 +420,9 @@ pub fn place_orders_handler<'c: 'info, 'info>(
PlaceOrders {
user: ctx.accounts.user.to_account_info(),
state: ctx.accounts.state.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
)
.with_remaining_accounts(ctx.remaining_accounts.to_vec()),
order_params,
Expand All @@ -445,7 +445,7 @@ pub struct DriftCancelOrders<'info> {
pub state: UncheckedAccount<'info>,

#[account(seeds = [b"treasury".as_ref(), fund.key().as_ref()], bump)]
pub treasury: SystemAccount<'info>,
pub vault: SystemAccount<'info>,

#[account(mut)]
pub signer: Signer<'info>,
Expand All @@ -456,7 +456,7 @@ pub struct DriftCancelOrders<'info> {

#[access_control(acl::check_access(&ctx.accounts.fund, &ctx.accounts.signer.key, Permission::DriftCancelOrders))]
#[access_control(acl::check_integration(&ctx.accounts.fund, IntegrationName::Drift))]
#[treasury_signer_seeds]
#[vault_signer_seeds]
pub fn cancel_orders_handler<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, DriftCancelOrders<'info>>,
market_type: Option<MarketType>,
Expand All @@ -469,9 +469,9 @@ pub fn cancel_orders_handler<'c: 'info, 'info>(
CancelOrders {
user: ctx.accounts.user.to_account_info(),
state: ctx.accounts.state.to_account_info(),
authority: ctx.accounts.treasury.to_account_info(),
authority: ctx.accounts.vault.to_account_info(),
},
treasury_signer_seeds,
vault_signer_seeds,
)
.with_remaining_accounts(ctx.remaining_accounts.to_vec()),
market_type,
Expand Down
Loading

0 comments on commit 87ad4c2

Please sign in to comment.