Skip to content

Commit

Permalink
add profit share fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChesterSim committed Aug 4, 2023
1 parent 9f6233f commit 3fa3bc1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
33 changes: 31 additions & 2 deletions ts/sdk/src/accounts/vaultDepositorAccount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Program } from '@coral-xyz/anchor';
import { BulkAccountLoader } from '@drift-labs/sdk';
import { BN, Program } from '@coral-xyz/anchor';
import { BulkAccountLoader, PERCENTAGE_PRECISION, ZERO } from '@drift-labs/sdk';
import { PublicKey } from '@solana/web3.js';
import { DriftVaults } from '../types/drift_vaults';
import { VaultDepositor, VaultDepositorAccountEvents } from '../types/types';
Expand Down Expand Up @@ -37,4 +37,33 @@ export class VaultDepositorAccount extends VaultsProgramAccount<
): PublicKey {
return getVaultDepositorAddressSync(programId, vault, authority);
}

/**
* Calculates the proportion of a depositor's funds that will be paid as profit share fees.
*
* @param vaultProfitShare Vault's profit share fee
* @param depositorEquity Vault depositor's net deposit value
*/
calcProfitShareFeesProportion(
vaultProfitShare: BN,
depositorEquity: BN
): number {
const accountData = this.accountSubscriber.getAccountAndSlot().data;

const profit = depositorEquity
.sub(accountData.netDeposits)
.sub(accountData.cumulativeProfitShareAmount);

if (profit.lte(new BN(0))) {
return ZERO;
}

const profitShareAmount = profit
.mul(vaultProfitShare)
.div(PERCENTAGE_PRECISION);
const profitShareProportion =
profitShareAmount.toNumber() / depositorEquity.toNumber();

return profitShareProportion;
}
}
2 changes: 1 addition & 1 deletion ts/sdk/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { BN } from '@drift-labs/sdk';

export const VAULT_SHARES_PRECISION = new BN(6);
export const VAULT_SHARES_PRECISION_EXP = new BN(6);

0 comments on commit 3fa3bc1

Please sign in to comment.