Skip to content

Commit

Permalink
anchor: fund account -> state account (#363)
Browse files Browse the repository at this point in the history
TODOs
- [x] Type alias StateAccount and MetadataAccount
- [x] Rename fund and openfunds to state and metadata
- [x] FundModel -> StateModel

ShareClassModel -> MintModel is lower priority for now. Will start
another PR later on.
  • Loading branch information
yurushao authored Jan 12, 2025
1 parent e87178b commit aea9157
Show file tree
Hide file tree
Showing 87 changed files with 3,207 additions and 3,061 deletions.
9 changes: 4 additions & 5 deletions anchor/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,13 @@ filename = "./fixtures/accounts/J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn.jso
address = "3R3nGZpQs2aZo5FDQvd2MUQ6R7KhAPainds6uT6uE2mn"
filename = "./fixtures/accounts/3R3nGZpQs2aZo5FDQvd2MUQ6R7KhAPainds6uT6uE2mn.json"

[[test.validator.account]] # validator stake account
[[test.validator.account]] # stake account delegated to StepeLdhJ2znRjHcZdjwMWsC4nTRURNKQY8Nca82LJp
address = "HUQEx8TDgEnhtuq6iXj9Rg3yVyX4tF85kS1k7jTnAaqR"
filename = "./fixtures/accounts/HUQEx8TDgEnhtuq6iXj9Rg3yVyX4tF85kS1k7jTnAaqR.json"

# uncomment for stake-pool test
#[[test.validator.account]] # vote account
#address = "StepeLdhJ2znRjHcZdjwMWsC4nTRURNKQY8Nca82LJp"
#filename = "./fixtures/accounts/StepeLdhJ2znRjHcZdjwMWsC4nTRURNKQY8Nca82LJp.json"
[[test.validator.account]] # stake account delegated to GJQjnyhSG9jN1AdMHTSyTxUR44hJHEGCmNzkidw9z3y8
address = "8y2hnDmfyvP4FyotiTHWSq7es78zA8P9M46JSByy9Zma"
filename = "./fixtures/accounts/8y2hnDmfyvP4FyotiTHWSq7es78zA8P9M46JSByy9Zma.json"

#
# Stake pool - SanctumSpl
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pubkey": "8y2hnDmfyvP4FyotiTHWSq7es78zA8P9M46JSByy9Zma",
"account": {
"lamports": 3415789,
"data": [
"AgAAAIDVIgAAAAAAVOWeJMBRqKFKex6Xl/DhLN+nSQIWZTGVpqUSpvFmYCtU5Z4kwFGooUp7HpeX8OEs36dJAhZlMZWmpRKm8WZgKwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAONVBKBZtkLBgqo6N2h4u8hnluBrNVWmdWB3XmhnzRqnxUcRAAAAAACeAQAAAAAAAP//////////AAAAAAAA0D/BSx8UAAAAAAAAAAA=",
"base64"
],
"owner": "Stake11111111111111111111111111111111111111",
"executable": false,
"rentEpoch": 18446744073709551615,
"space": 200
}
}

This file was deleted.

10 changes: 5 additions & 5 deletions anchor/libs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ pub fn share_class_signer_seeds(_attr: TokenStream, item: TokenStream) -> TokenS
#(#func_attrs)*
#func_vis #func_sig {
// We assume the fund account and the treasury bump seed are available in the context
let fund_key = ctx.accounts.fund.key();
let state_key = ctx.accounts.state.key();
let seeds = &[
"share".as_bytes(),
&[share_class_id],
fund_key.as_ref(),
state_key.as_ref(),
&[ctx.bumps.share_class_mint],
];
let share_class_signer_seeds = &[&seeds[..]];
Expand All @@ -69,10 +69,10 @@ pub fn vault_signer_seeds(_attr: TokenStream, item: TokenStream) -> TokenStream
#(#func_attrs)*
#func_vis #func_sig {
// We assume the fund account and the vault bump seed are available in the context
let fund_key = ctx.accounts.fund.key();
let state_key = ctx.accounts.state.key();
let seeds = [
b"treasury".as_ref(),
fund_key.as_ref(),
"treasury".as_ref(),
state_key.as_ref(),
&[ctx.bumps.vault],
];
let vault_signer_seeds = &[&seeds[..]];
Expand Down
19 changes: 15 additions & 4 deletions anchor/programs/glam/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ use anchor_lang::prelude::*;
use solana_program::pubkey;

#[constant]
pub const SEED: &str = "anchor";
pub const SEED_STATE: &str = "fund";
#[constant]
pub const SEED_VAULT: &str = "treasury";
#[constant]
pub const SEED_METADATA: &str = "openfunds";
#[constant]
pub const SEED_MINT: &str = "share";

pub const DEFAULT_DRIFT_USER_NAME: [u8; 32] = [
b'G', b'L', b'A', b'M', b' ', b'*', b'.', b'+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
];

pub const MAX_ASSETS: usize = 5;
pub const MAX_SHARE_CLASSES: usize = 3;
pub const MAX_FUND_NAME: usize = 50;
pub const MAX_FUND_SYMBOL: usize = 20;
pub const MAX_FUND_URI: usize = 100;
pub const MAX_SIZE_NAME: usize = 50;
pub const MAX_SIZE_SYMBOL: usize = 20;
pub const MAX_SIZE_URI: usize = 100;

pub const WSOL: Pubkey = pubkey!("So11111111111111111111111111111111111111112");
pub const MSOL: Pubkey = pubkey!("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So");
Expand Down
50 changes: 27 additions & 23 deletions anchor/programs/glam/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,46 @@ use anchor_lang::prelude::*;
pub enum AccessError {
#[msg("Signer is not authorized")]
NotAuthorized,

#[msg("Integration is disabled")]
IntegrationDisabled,
}

#[error_code]
pub enum ManagerError {
#[msg("Error closing account: not empty")]
CloseNotEmptyError,
#[msg("Invalid fund name: max 50 chars")]
InvalidFundName,
#[msg("Too many assets: max 50")]
InvalidFundSymbol,
#[msg("Too many assets: max 20")]
InvalidFundUri,
pub enum StateError {
#[msg("Name too long: max 50 chars")]
InvalidName,

#[msg("Symbol too long: max 50 chars")]
InvalidSymbol,

#[msg("Uri too long: max 20")]
InvalidUri,

#[msg("Too many assets: max 100")]
InvalidAssetsLen,
#[msg("Number of weights should match number of assets")]
InvalidAssetsWeights,

#[msg("State account is disabled")]
Disabled,

#[msg("No share class found")]
NoShareClass,

#[msg("Glam state account can't be closed. Close share classes first")]
ShareClassesNotClosed,

#[msg("Error closing state account: not empty")]
CloseNotEmptyError,

#[msg("Withdraw denied. Only vaults allow withdraws (funds and mints don't)")]
WithdrawDenied,
}

#[error_code]
pub enum SwapError {
#[msg("Asset cannot be swapped")]
InvalidAssetForSwap,

#[msg("Swap failed")]
InvalidSwap,
}
Expand Down Expand Up @@ -58,18 +74,6 @@ pub enum InvestorError {
PriceTooOld,
}

#[error_code]
pub enum FundError {
#[msg("Fund is not active")]
FundNotActive,
#[msg("No share class found")]
NoShareClassInFund,
#[msg("Fund can't be closed. Close share classes first")]
CantCloseShareClasses,
#[msg("Withdraw denied. Only vaults allow withdraws (funds and mints don't).")]
WithdrawDenied,
}

#[error_code]
pub enum ShareClassError {
#[msg("Share class mint supply not zero")]
Expand Down
Loading

0 comments on commit aea9157

Please sign in to comment.