@drift-labs/sdk
Version:
SDK for Drift Protocol
37 lines (36 loc) • 1.68 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMedianTriggerPrice = exports.getMaxNumberOfSubAccounts = exports.calculateInitUserFee = void 0;
const anchor_1 = require("@coral-xyz/anchor");
const numericConstants_1 = require("../constants/numericConstants");
const types_1 = require("../types");
function calculateInitUserFee(stateAccount) {
const maxInitFee = new anchor_1.BN(stateAccount.maxInitializeUserFee)
.mul(numericConstants_1.LAMPORTS_PRECISION)
.divn(100);
const targetUtilization = numericConstants_1.PERCENTAGE_PRECISION.muln(8).divn(10);
const accountSpaceUtilization = stateAccount.numberOfSubAccounts
.addn(1)
.mul(numericConstants_1.PERCENTAGE_PRECISION)
.div(getMaxNumberOfSubAccounts(stateAccount));
if (accountSpaceUtilization.gt(targetUtilization)) {
return maxInitFee
.mul(accountSpaceUtilization.sub(targetUtilization))
.div(numericConstants_1.PERCENTAGE_PRECISION.sub(targetUtilization));
}
else {
return numericConstants_1.ZERO;
}
}
exports.calculateInitUserFee = calculateInitUserFee;
function getMaxNumberOfSubAccounts(stateAccount) {
if (stateAccount.maxNumberOfSubAccounts <= 5) {
return new anchor_1.BN(stateAccount.maxNumberOfSubAccounts);
}
return new anchor_1.BN(stateAccount.maxNumberOfSubAccounts).muln(100);
}
exports.getMaxNumberOfSubAccounts = getMaxNumberOfSubAccounts;
function useMedianTriggerPrice(stateAccount) {
return ((stateAccount.featureBitFlags & types_1.FeatureBitFlags.MEDIAN_TRIGGER_PRICE) > 0);
}
exports.useMedianTriggerPrice = useMedianTriggerPrice;
;