From 7a450467764ffc8e4630b7ad363ee3f356946431 Mon Sep 17 00:00:00 2001 From: yurushao Date: Sun, 31 Mar 2024 17:27:55 -0700 Subject: [PATCH 1/2] Add back fund symbol --- anchor/programs/glam/src/error.rs | 6 ++- .../programs/glam/src/instructions/manager.rs | 12 +++-- anchor/programs/glam/src/lib.rs | 2 + anchor/programs/glam/src/state/fund.rs | 13 ++++-- anchor/target/idl/glam.json | 22 +++++++++- anchor/target/types/glam.ts | 44 +++++++++++++++++-- anchor/tests/glam_crud.spec.ts | 7 ++- 7 files changed, 90 insertions(+), 16 deletions(-) diff --git a/anchor/programs/glam/src/error.rs b/anchor/programs/glam/src/error.rs index 43afc9de..75b340b9 100644 --- a/anchor/programs/glam/src/error.rs +++ b/anchor/programs/glam/src/error.rs @@ -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, diff --git a/anchor/programs/glam/src/instructions/manager.rs b/anchor/programs/glam/src/instructions/manager.rs index 12fe708c..9900dd29 100644 --- a/anchor/programs/glam/src/instructions/manager.rs +++ b/anchor/programs/glam/src/instructions/manager.rs @@ -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, activate: bool, @@ -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(); @@ -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; diff --git a/anchor/programs/glam/src/lib.rs b/anchor/programs/glam/src/lib.rs index 2019b42d..b63516fd 100644 --- a/anchor/programs/glam/src/lib.rs +++ b/anchor/programs/glam/src/lib.rs @@ -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, activate: bool, @@ -29,6 +30,7 @@ pub mod glam { manager::initialize_fund_handler( ctx, fund_name, + fund_symbol, fund_uri, asset_weights, activate, diff --git a/anchor/programs/glam/src/state/fund.rs b/anchor/programs/glam/src/state/fund.rs index 81e71861..16d2e144 100644 --- a/anchor/programs/glam/src/state/fund.rs +++ b/anchor/programs/glam/src/state/fund.rs @@ -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 { @@ -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 { @@ -30,8 +34,9 @@ impl Fund { + 8 + 1 + 1 - + 50 - + 100 + + MAX_FUND_NAME + + MAX_FUND_SYMBOL + + MAX_FUND_URI + 1; } diff --git a/anchor/target/idl/glam.json b/anchor/target/idl/glam.json index 1c6392de..605e5f0a 100644 --- a/anchor/target/idl/glam.json +++ b/anchor/target/idl/glam.json @@ -53,6 +53,10 @@ "name": "fundName", "type": "string" }, + { + "name": "fundSymbol", + "type": "string" + }, { "name": "fundUri", "type": "string" @@ -598,6 +602,10 @@ "name": "name", "type": "string" }, + { + "name": "symbol", + "type": "string" + }, { "name": "uri", "type": "string" @@ -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" } diff --git a/anchor/target/types/glam.ts b/anchor/target/types/glam.ts index ba92e376..78ce8189 100644 --- a/anchor/target/types/glam.ts +++ b/anchor/target/types/glam.ts @@ -53,6 +53,10 @@ export type Glam = { "name": "fundName", "type": "string" }, + { + "name": "fundSymbol", + "type": "string" + }, { "name": "fundUri", "type": "string" @@ -598,6 +602,10 @@ export type Glam = { "name": "name", "type": "string" }, + { + "name": "symbol", + "type": "string" + }, { "name": "uri", "type": "string" @@ -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" } @@ -736,6 +754,10 @@ export const IDL: Glam = { "name": "fundName", "type": "string" }, + { + "name": "fundSymbol", + "type": "string" + }, { "name": "fundUri", "type": "string" @@ -1281,6 +1303,10 @@ export const IDL: Glam = { "name": "name", "type": "string" }, + { + "name": "symbol", + "type": "string" + }, { "name": "uri", "type": "string" @@ -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" } diff --git a/anchor/tests/glam_crud.spec.ts b/anchor/tests/glam_crud.spec.ts index d81683c4..e0022545 100644 --- a/anchor/tests/glam_crud.spec.ts +++ b/anchor/tests/glam_crud.spec.ts @@ -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"), @@ -57,6 +58,7 @@ describe("glam_crud", () => { const txId = await program.methods .initialize( fundName, + fundSymbol, fundUri, [0, 60, 40], true, @@ -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); }); From d5796924cf726323ab97970d45a6e60a883150d1 Mon Sep 17 00:00:00 2001 From: yurushao Date: Sun, 31 Mar 2024 17:33:10 -0700 Subject: [PATCH 2/2] Fix web build --- web/src/app/glam/glam-data-access.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/web/src/app/glam/glam-data-access.tsx b/web/src/app/glam/glam-data-access.tsx index 101f8740..97898eda 100644 --- a/web/src/app/glam/glam-data-access.tsx +++ b/web/src/app/glam/glam-data-access.tsx @@ -37,6 +37,7 @@ export function useGlamProgram() { program.methods .initialize( "fund name", + "fund symbol", "fund uri", [0, 60, 40], true,