Skip to content

Commit

Permalink
refactor(sdk): add calculateVaultAllTimeNotionalPnl
Browse files Browse the repository at this point in the history
  • Loading branch information
ChesterSim committed Jan 7, 2025
1 parent f3e422c commit e3a1c5b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ts/sdk/src/vaultClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,32 @@ export class VaultClient {
}
}

public async calculateVaultAllTimeNotionalPnl(params: {
address?: PublicKey;
vault?: Vault;
}): Promise<BN> {
try {
let vaultAccount: Vault;
if (params.address !== undefined) {
// @ts-ignore
vaultAccount = await this.program.account.vault.fetch(params.address);
} else if (params.vault !== undefined) {
vaultAccount = params.vault;
} else {
throw new Error('Must supply address or vault');
}

const user = await this.getSubscribedVaultUser(vaultAccount.user);
const allTimeTotalPnl = user.getTotalAllTimePnl();

return allTimeTotalPnl;
} catch (err) {
console.error('VaultClient ~ err:', err);
return ZERO;
}
}


/**
*
* @param vault pubkey
Expand Down

0 comments on commit e3a1c5b

Please sign in to comment.