Skip to content

Commit

Permalink
Add back fund symbol (#27)
Browse files Browse the repository at this point in the history
In a previous change fund symbol was renamed to fund uri. This PR adds
back fund symbol.
  • Loading branch information
yurushao authored Apr 1, 2024
1 parent e74af40 commit b54a2a3
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 16 deletions.
6 changes: 5 additions & 1 deletion anchor/programs/glam/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ pub enum ManagerError {
NotAuthorizedError,
#[msg("Invalid fund name: max 30 chars")]
InvalidFundName,
#[msg("Too many assets: max 10")]
#[msg("Too many assets: max 50")]
InvalidFundSymbol,
#[msg("Too many assets: max 20")]
InvalidFundUri,
#[msg("Too many assets: max 100")]
InvalidAssetsLen,
#[msg("Number of weights should match number of assets")]
InvalidAssetsWeights,
Expand Down
12 changes: 9 additions & 3 deletions anchor/programs/glam/src/instructions/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct InitializeFund<'info> {
pub fn initialize_fund_handler<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, InitializeFund<'info>>,
fund_name: String,
fund_symbol: String,
fund_uri: String,
asset_weights: Vec<u32>,
activate: bool,
Expand All @@ -41,12 +42,16 @@ pub fn initialize_fund_handler<'c: 'info, 'info>(
// Validate the input
//
require!(
fund_name.as_bytes().len() <= 50,
fund_name.as_bytes().len() <= MAX_FUND_NAME,
ManagerError::InvalidFundName
);
require!(
fund_uri.as_bytes().len() <= 100,
ManagerError::InvalidFundName
fund_symbol.as_bytes().len() <= MAX_FUND_SYMBOL,
ManagerError::InvalidFundSymbol
);
require!(
fund_uri.as_bytes().len() <= MAX_FUND_URI,
ManagerError::InvalidFundUri
);

let assets_len = ctx.remaining_accounts.len();
Expand All @@ -65,6 +70,7 @@ pub fn initialize_fund_handler<'c: 'info, 'info>(
fund.manager = ctx.accounts.manager.key();
fund.treasury = treasury.key();
fund.name = fund_name;
fund.symbol = fund_symbol;
fund.uri = fund_uri;
fund.bump_fund = ctx.bumps.fund;
fund.bump_treasury = ctx.bumps.treasury;
Expand Down
2 changes: 2 additions & 0 deletions anchor/programs/glam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod glam {
pub fn initialize<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, InitializeFund<'info>>,
fund_name: String,
fund_symbol: String,
fund_uri: String,
asset_weights: Vec<u32>,
activate: bool,
Expand All @@ -29,6 +30,7 @@ pub mod glam {
manager::initialize_fund_handler(
ctx,
fund_name,
fund_symbol,
fund_uri,
asset_weights,
activate,
Expand Down
13 changes: 9 additions & 4 deletions anchor/programs/glam/src/state/fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use anchor_lang::prelude::*;

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;

#[account]
pub struct Fund {
Expand All @@ -16,8 +19,9 @@ pub struct Fund {
pub time_created: i64, // 8
pub bump_fund: u8, // 1
pub bump_treasury: u8, // 1
pub name: String, // max 50 chars
pub uri: String, // max 100 chars
pub name: String, // max MAX_FUND_NAME chars
pub symbol: String, // max MAX_FUND_SYMBOL chars
pub uri: String, // max MAX_FUND_URI chars
pub is_active: bool, // 1
}
impl Fund {
Expand All @@ -30,8 +34,9 @@ impl Fund {
+ 8
+ 1
+ 1
+ 50
+ 100
+ MAX_FUND_NAME
+ MAX_FUND_SYMBOL
+ MAX_FUND_URI
+ 1;
}

Expand Down
22 changes: 20 additions & 2 deletions anchor/target/idl/glam.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
"name": "fundName",
"type": "string"
},
{
"name": "fundSymbol",
"type": "string"
},
{
"name": "fundUri",
"type": "string"
Expand Down Expand Up @@ -598,6 +602,10 @@
"name": "name",
"type": "string"
},
{
"name": "symbol",
"type": "string"
},
{
"name": "uri",
"type": "string"
Expand Down Expand Up @@ -670,11 +678,21 @@
},
{
"code": 6003,
"name": "InvalidAssetsLen",
"msg": "Too many assets: max 10"
"name": "InvalidFundSymbol",
"msg": "Too many assets: max 50"
},
{
"code": 6004,
"name": "InvalidFundUri",
"msg": "Too many assets: max 20"
},
{
"code": 6005,
"name": "InvalidAssetsLen",
"msg": "Too many assets: max 100"
},
{
"code": 6006,
"name": "InvalidAssetsWeights",
"msg": "Number of weights should match number of assets"
}
Expand Down
44 changes: 40 additions & 4 deletions anchor/target/types/glam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export type Glam = {
"name": "fundName",
"type": "string"
},
{
"name": "fundSymbol",
"type": "string"
},
{
"name": "fundUri",
"type": "string"
Expand Down Expand Up @@ -598,6 +602,10 @@ export type Glam = {
"name": "name",
"type": "string"
},
{
"name": "symbol",
"type": "string"
},
{
"name": "uri",
"type": "string"
Expand Down Expand Up @@ -670,11 +678,21 @@ export type Glam = {
},
{
"code": 6003,
"name": "InvalidAssetsLen",
"msg": "Too many assets: max 10"
"name": "InvalidFundSymbol",
"msg": "Too many assets: max 50"
},
{
"code": 6004,
"name": "InvalidFundUri",
"msg": "Too many assets: max 20"
},
{
"code": 6005,
"name": "InvalidAssetsLen",
"msg": "Too many assets: max 100"
},
{
"code": 6006,
"name": "InvalidAssetsWeights",
"msg": "Number of weights should match number of assets"
}
Expand Down Expand Up @@ -736,6 +754,10 @@ export const IDL: Glam = {
"name": "fundName",
"type": "string"
},
{
"name": "fundSymbol",
"type": "string"
},
{
"name": "fundUri",
"type": "string"
Expand Down Expand Up @@ -1281,6 +1303,10 @@ export const IDL: Glam = {
"name": "name",
"type": "string"
},
{
"name": "symbol",
"type": "string"
},
{
"name": "uri",
"type": "string"
Expand Down Expand Up @@ -1353,11 +1379,21 @@ export const IDL: Glam = {
},
{
"code": 6003,
"name": "InvalidAssetsLen",
"msg": "Too many assets: max 10"
"name": "InvalidFundSymbol",
"msg": "Too many assets: max 50"
},
{
"code": 6004,
"name": "InvalidFundUri",
"msg": "Too many assets: max 20"
},
{
"code": 6005,
"name": "InvalidAssetsLen",
"msg": "Too many assets: max 100"
},
{
"code": 6006,
"name": "InvalidAssetsWeights",
"msg": "Number of weights should match number of assets"
}
Expand Down
7 changes: 5 additions & 2 deletions anchor/tests/glam_crud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ describe("glam_crud", () => {
const btc = new PublicKey("3BZPwbcqB5kKScF3TEXxwNfx5ipV13kbRVDvfVp5c6fv"); // 9 decimals
const BTC_TOKEN_PROGRAM_ID = TOKEN_2022_PROGRAM_ID;

const fundName = "Investment fund";
const fundUri = "https://glam.systems/fund/XYZ";
const fundName = "Glam Investment Fund XYZ";
const fundSymbol = "XYZ";
const fundUri = "https://devnet.glam.systems/fund/XYZ";
const [fundPDA, fundBump] = PublicKey.findProgramAddressSync(
[
anchor.utils.bytes.utf8.encode("fund"),
Expand All @@ -57,6 +58,7 @@ describe("glam_crud", () => {
const txId = await program.methods
.initialize(
fundName,
fundSymbol,
fundUri,
[0, 60, 40],
true,
Expand Down Expand Up @@ -87,6 +89,7 @@ describe("glam_crud", () => {
expect(fund.shareClassesLen).toEqual(1);
expect(fund.assetsLen).toEqual(3);
expect(fund.name).toEqual(fundName);
expect(fund.symbol).toEqual(fundSymbol);
expect(fund.uri).toEqual(fundUri);
expect(fund.isActive).toEqual(true);
});
Expand Down
1 change: 1 addition & 0 deletions web/src/app/glam/glam-data-access.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function useGlamProgram() {
program.methods
.initialize(
"fund name",
"fund symbol",
"fund uri",
[0, 60, 40],
true,
Expand Down

0 comments on commit b54a2a3

Please sign in to comment.