Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao committed Jan 27, 2025
1 parent 77fde13 commit c3dde1d
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 1,083 deletions.
20 changes: 9 additions & 11 deletions anchor/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ wallet = "~/.config/solana/id.json"

[scripts]
test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_crud"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_vault"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_share_class"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_investor"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_drift"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_marinade"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_staking"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_jupiter"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_openfunds"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_wsol"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_sol_msol"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_policy_hook"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_mint"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_investor"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_drift"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_marinade"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_staking"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_jupiter"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_openfunds"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_wsol"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_policy_hook"

[test]
startup_wait = 50000
Expand Down
33 changes: 14 additions & 19 deletions anchor/programs/glam/src/instructions/investor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anchor_spl::token::Token;
use anchor_spl::token_interface::{
burn, mint_to, transfer_checked, Burn, Mint, MintTo, Token2022, TokenAccount, TransferChecked,
};
use glam_macros::share_class_signer_seeds;
use glam_macros::vault_signer_seeds;
use marinade::state::delayed_unstake_ticket::TicketAccountData;
use pyth_solana_receiver_sdk::price_update::Price;
Expand All @@ -24,7 +25,7 @@ fn log_decimal(amount: u64, minus_decimals: i32) -> f64 {
}

#[derive(Accounts)]
#[instruction(_share_class_id: u8)]
#[instruction(share_class_id: u8)]
pub struct Subscribe<'info> {
#[account()]
pub state: Box<Account<'info, StateAccount>>,
Expand All @@ -35,16 +36,16 @@ pub struct Subscribe<'info> {
// the shares to mint
#[account(
mut,
seeds = [SEED_MINT.as_bytes(), &[_share_class_id], state.key().as_ref()],
seeds = [SEED_MINT.as_bytes(), &[share_class_id], state.key().as_ref()],
bump,
mint::authority = share_class,
mint::authority = share_class_mint,
mint::token_program = token_2022_program
)]
pub share_class: Box<InterfaceAccount<'info, Mint>>,
pub share_class_mint: Box<InterfaceAccount<'info, Mint>>,

#[account(
mut,
associated_token::mint = share_class,
associated_token::mint = share_class_mint,
associated_token::authority = signer,
associated_token::token_program = token_2022_program
)]
Expand Down Expand Up @@ -83,9 +84,10 @@ pub struct Subscribe<'info> {
pub token_2022_program: Program<'info, Token2022>,
}

#[share_class_signer_seeds]
pub fn subscribe_handler<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, Subscribe<'info>>,
_share_class_id: u8,
share_class_id: u8,
amount: u64,
skip_state: bool,
) -> Result<()> {
Expand All @@ -107,7 +109,7 @@ pub fn subscribe_handler<'c: 'info, 'info>(
}
require!(state.mints.len() > 0, StateError::NoShareClass);
require!(
state.mints[0] == ctx.accounts.share_class.key(),
state.mints[0] == ctx.accounts.share_class_mint.key(),
InvestorError::InvalidShareClass
);

Expand Down Expand Up @@ -168,7 +170,7 @@ pub fn subscribe_handler<'c: 'info, 'info>(
//
// Compute amount of shares to mint
//
let share_class = &ctx.accounts.share_class;
let share_class = &ctx.accounts.share_class_mint;
let share_expo = -(share_class.decimals as i32);
let total_shares = share_class.supply;
let use_fixed_price = total_shares == 0;
Expand Down Expand Up @@ -256,23 +258,16 @@ pub fn subscribe_handler<'c: 'info, 'info>(
if skip_state {
// TODO: we should read share class symbol from metadata so that we don't need to pass it as an argument
// mint shares to signer
let state_key = ctx.accounts.state.key();
let seeds = &[
"share".as_bytes(),
&[0u8],
state_key.as_ref(),
&[ctx.bumps.share_class],
];
let signer_seeds = &[&seeds[..]];

mint_to(
CpiContext::new_with_signer(
ctx.accounts.token_2022_program.to_account_info(),
MintTo {
authority: ctx.accounts.share_class.to_account_info(),
authority: ctx.accounts.share_class_mint.to_account_info(),
to: ctx.accounts.signer_share_ata.to_account_info(),
mint: ctx.accounts.share_class.to_account_info(),
mint: ctx.accounts.share_class_mint.to_account_info(),
},
signer_seeds,
share_class_signer_seeds,
),
amount_shares,
)?;
Expand Down
3 changes: 3 additions & 0 deletions anchor/programs/glam/src/instructions/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ pub fn initialize_state_handler<'c: 'info, 'info>(
if let Some(openfunds_metadata) = &mut ctx.accounts.openfunds_metadata {
openfunds_metadata.set_inner(OpenfundsMetadataAccount::from(state_model));
openfunds_metadata.fund_id = state.key();

// Update metadata pubkey
state.metadata.as_mut().unwrap().pubkey = openfunds_metadata.key();
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions anchor/src/client/investor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class InvestorClient {
const signer = txOptions.signer || this.base.getSigner();

// share class token to receive
const shareClass = this.base.getShareClassPda(statePda, shareClassId);
const signerShareAta = this.base.getShareClassAta(signer, shareClass);
const shareClassMint = this.base.getShareClassPda(statePda, shareClassId);
const signerShareAta = this.base.getShareClassAta(signer, shareClassMint);

// asset token to transfer
const assetMeta = this.base.getAssetMeta(asset.toBase58());
Expand Down Expand Up @@ -128,7 +128,7 @@ export class InvestorClient {
});

remainingAccounts = remainingAccounts.concat(
stateModel.externalVaultAccounts.map((address) => ({
(stateModel.externalVaultAccounts || []).map((address) => ({
pubkey: address,
isSigner: false,
isWritable: false,
Expand Down Expand Up @@ -156,7 +156,7 @@ export class InvestorClient {
signer,
signerShareAta,
signer,
shareClass,
shareClassMint,
TOKEN_2022_PROGRAM_ID,
),
];
Expand Down Expand Up @@ -186,12 +186,11 @@ export class InvestorClient {
}
}

// @ts-ignore
const tx = await this.base.program.methods
.subscribe(0, amount, skipState)
.accounts({
state: statePda,
shareClass,
shareClassMint,
asset,
vaultAta,
signerAssetAta,
Expand Down
2 changes: 1 addition & 1 deletion anchor/src/client/shareclass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class ShareClassClient {
* @param shareClassId
* @param recipient Recipient's wallet address
* @param amount Amount of shares to mint
* @param forceThaw If true, force thaw token account before minting
* @param forceThaw If true, force unfreezing token account before minting
* @param txOptions
* @returns Transaction signature
*/
Expand Down
54 changes: 47 additions & 7 deletions anchor/target/idl/glam.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"address": "Gco1pcjxCMYjKJjSNJ7mKV7qezeUTE7arXJgy7PAPNRc",
"address": "GLAMpLuXu78TA4ao3DPZvT1zQ7woxoQ8ahdYbhnqY9mP",
"metadata": {
"name": "glam",
"version": "0.4.0",
Expand Down Expand Up @@ -4484,7 +4484,7 @@
}
},
{
"name": "share_class",
"name": "share_class_mint",
"writable": true
},
{
Expand All @@ -4502,7 +4502,7 @@
},
{
"kind": "account",
"path": "share_class"
"path": "share_class_mint"
}
],
"program": {
Expand Down Expand Up @@ -5800,13 +5800,53 @@
"errors": [
{
"code": 6000,
"name": "InvalidAssetForSwap",
"msg": "Asset cannot be swapped"
"name": "InvalidAccountType",
"msg": "Invalid account type"
},
{
"code": 6001,
"name": "InvalidSwap",
"msg": "Swap failed"
"name": "InvalidName",
"msg": "Name too long: max 64 chars"
},
{
"code": 6002,
"name": "InvalidSymbol",
"msg": "Symbol too long: max 32 chars"
},
{
"code": 6003,
"name": "InvalidUri",
"msg": "Uri too long: max 128 chars"
},
{
"code": 6004,
"name": "InvalidAssetsLen",
"msg": "Too many assets: max 100"
},
{
"code": 6005,
"name": "Disabled",
"msg": "State account is disabled"
},
{
"code": 6006,
"name": "NoShareClass",
"msg": "No share class found"
},
{
"code": 6007,
"name": "ShareClassesNotClosed",
"msg": "Glam state account can't be closed. Close share classes first"
},
{
"code": 6008,
"name": "CloseNotEmptyError",
"msg": "Error closing state account: not empty"
},
{
"code": 6009,
"name": "WithdrawDenied",
"msg": "Withdraw denied. Only vaults allow withdraws (funds and mints don't)"
}
],
"types": [
Expand Down
52 changes: 46 additions & 6 deletions anchor/target/types/glam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4490,7 +4490,7 @@ export type Glam = {
}
},
{
"name": "shareClass",
"name": "shareClassMint",
"writable": true
},
{
Expand All @@ -4508,7 +4508,7 @@ export type Glam = {
},
{
"kind": "account",
"path": "shareClass"
"path": "shareClassMint"
}
],
"program": {
Expand Down Expand Up @@ -5806,13 +5806,53 @@ export type Glam = {
"errors": [
{
"code": 6000,
"name": "invalidAssetForSwap",
"msg": "Asset cannot be swapped"
"name": "invalidAccountType",
"msg": "Invalid account type"
},
{
"code": 6001,
"name": "invalidSwap",
"msg": "Swap failed"
"name": "invalidName",
"msg": "Name too long: max 64 chars"
},
{
"code": 6002,
"name": "invalidSymbol",
"msg": "Symbol too long: max 32 chars"
},
{
"code": 6003,
"name": "invalidUri",
"msg": "Uri too long: max 128 chars"
},
{
"code": 6004,
"name": "invalidAssetsLen",
"msg": "Too many assets: max 100"
},
{
"code": 6005,
"name": "disabled",
"msg": "State account is disabled"
},
{
"code": 6006,
"name": "noShareClass",
"msg": "No share class found"
},
{
"code": 6007,
"name": "shareClassesNotClosed",
"msg": "Glam state account can't be closed. Close share classes first"
},
{
"code": 6008,
"name": "closeNotEmptyError",
"msg": "Error closing state account: not empty"
},
{
"code": 6009,
"name": "withdrawDenied",
"msg": "Withdraw denied. Only vaults allow withdraws (funds and mints don't)"
}
],
"types": [
Expand Down
2 changes: 1 addition & 1 deletion anchor/tests/glam_drift.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("glam_drift", () => {

// Enable drift integration
const updated = {
integrationAcls: [{ name: { drift: {} }, features: [] }],
integrations: [{ drift: {} }],
};
try {
const txSig = await glamClient.state.updateState(statePda, updated);
Expand Down
Loading

0 comments on commit c3dde1d

Please sign in to comment.