@neutral-trade/sdk 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +25 -2
- package/dist/index.mjs +61 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5014,6 +5014,9 @@ interface VaultBalanceData {
|
|
|
5014
5014
|
/** Total profit share fee paid by the user */
|
|
5015
5015
|
feesPaid?: number;
|
|
5016
5016
|
pendingProfitShareFee?: number;
|
|
5017
|
+
/** Unpaid / accrued fees in deposit token; null if not applicable. Bundle: mgmt+perf estimate; Drift: pending profit share. */
|
|
5018
|
+
pendingFee: number | null;
|
|
5019
|
+
pendingFeeUsd: number | null;
|
|
5017
5020
|
spotPrice: number;
|
|
5018
5021
|
/** User's vault shares (raw number, not divided by decimals) */
|
|
5019
5022
|
vaultShares?: number;
|
|
@@ -5066,6 +5069,8 @@ declare function createBundlePrograms(connection: Connection): {
|
|
|
5066
5069
|
* These are auto-generated from the vault registry
|
|
5067
5070
|
*/
|
|
5068
5071
|
declare enum VaultId {
|
|
5072
|
+
/** Volatility Alpha */
|
|
5073
|
+
volatility_alpha_74 = 74,
|
|
5069
5074
|
/** Great Debasement */
|
|
5070
5075
|
great_debasement_73 = 73,
|
|
5071
5076
|
/** CTA-Adaptive Alpha - Atlas Research */
|
|
@@ -5227,7 +5232,7 @@ declare function getBundleProgramId(vault: VaultRegistryEntry): BundleProgramId
|
|
|
5227
5232
|
* Uses registry value if present, otherwise defaults to VAULT_PROGRAM_ID
|
|
5228
5233
|
*/
|
|
5229
5234
|
declare function getDriftProgramId(vault: VaultRegistryEntry): string | undefined;
|
|
5230
|
-
declare const vaults: VaultRegistry;
|
|
5235
|
+
declare const vaults$1: VaultRegistry;
|
|
5231
5236
|
declare function isValidVaultAddress(address: string): boolean;
|
|
5232
5237
|
declare function getVaultByAddress(address: string): VaultRegistryEntry | undefined;
|
|
5233
5238
|
declare function getVaultById(vaultId: number): VaultRegistryEntry | undefined;
|
|
@@ -5274,6 +5279,24 @@ declare class NeutralTrade {
|
|
|
5274
5279
|
}): Promise<UserBalanceResult>;
|
|
5275
5280
|
}
|
|
5276
5281
|
//#endregion
|
|
5282
|
+
//#region src/utils/bundle.d.ts
|
|
5283
|
+
/**
|
|
5284
|
+
* Estimated unpaid bundle fees in deposit token (mgmt + performance), matching on-chain `charge_user_fees`.
|
|
5285
|
+
*/
|
|
5286
|
+
declare function estimatePendingBundleFeeToken({
|
|
5287
|
+
oracleData,
|
|
5288
|
+
bundleData,
|
|
5289
|
+
userBundle,
|
|
5290
|
+
assetDecimals,
|
|
5291
|
+
nowUnixSeconds
|
|
5292
|
+
}: {
|
|
5293
|
+
oracleData: OracleData;
|
|
5294
|
+
bundleData: BundleAccount;
|
|
5295
|
+
userBundle: UserBundleAccount;
|
|
5296
|
+
assetDecimals: number;
|
|
5297
|
+
nowUnixSeconds?: number;
|
|
5298
|
+
}): number;
|
|
5299
|
+
//#endregion
|
|
5277
5300
|
//#region src/utils/pda.d.ts
|
|
5278
5301
|
/**
|
|
5279
5302
|
* Derive Oracle PDA for Bundle vault
|
|
@@ -5289,4 +5312,4 @@ declare function deriveUserPDA(userKey: PublicKey, bundlePDA: PublicKey, program
|
|
|
5289
5312
|
*/
|
|
5290
5313
|
declare function getVaultDepositorAddressSync(programId: PublicKey, vault: PublicKey, authority: PublicKey): PublicKey;
|
|
5291
5314
|
//#endregion
|
|
5292
|
-
export { type BundleAccount, BundleProgramId, NeutralTrade, type NeutralTradeConfig, type OracleData, type PointsVaultEntry, SupportedChain, SupportedToken, type Token, type UserBalanceResult, type UserBundleAccount, type UserBundleTempData, type VaultBalanceData, VaultCategory, type VaultRegistryEntry as VaultConfig, type VaultRegistry as VaultConfigRecord, VaultId, VaultType, createBundleProgramV1, createBundleProgramV2, createBundlePrograms, deriveOraclePDA, deriveUserPDA, getBundleProgramId, getDriftProgramId, getPointsVaults, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults };
|
|
5315
|
+
export { type BundleAccount, BundleProgramId, NeutralTrade, type NeutralTradeConfig, type OracleData, type PointsVaultEntry, SupportedChain, SupportedToken, type Token, type UserBalanceResult, type UserBundleAccount, type UserBundleTempData, type VaultBalanceData, VaultCategory, type VaultRegistryEntry as VaultConfig, type VaultRegistry as VaultConfigRecord, VaultId, VaultType, createBundleProgramV1, createBundleProgramV2, createBundlePrograms, deriveOraclePDA, deriveUserPDA, estimatePendingBundleFeeToken, getBundleProgramId, getDriftProgramId, getPointsVaults, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults$1 as vaults };
|
package/dist/index.mjs
CHANGED
|
@@ -8148,6 +8148,8 @@ function createBundlePrograms(connection) {
|
|
|
8148
8148
|
* These are auto-generated from the vault registry
|
|
8149
8149
|
*/
|
|
8150
8150
|
let VaultId = /* @__PURE__ */ function(VaultId$1) {
|
|
8151
|
+
/** Volatility Alpha */
|
|
8152
|
+
VaultId$1[VaultId$1["volatility_alpha_74"] = 74] = "volatility_alpha_74";
|
|
8151
8153
|
/** Great Debasement */
|
|
8152
8154
|
VaultId$1[VaultId$1["great_debasement_73"] = 73] = "great_debasement_73";
|
|
8153
8155
|
/** CTA-Adaptive Alpha - Atlas Research */
|
|
@@ -8302,6 +8304,16 @@ let VaultId = /* @__PURE__ */ function(VaultId$1) {
|
|
|
8302
8304
|
//#endregion
|
|
8303
8305
|
//#region src/registry/vaults.json
|
|
8304
8306
|
var vaults_default = [
|
|
8307
|
+
{
|
|
8308
|
+
"vaultId": 74,
|
|
8309
|
+
"name": "Volatility Alpha",
|
|
8310
|
+
"type": "Bundle",
|
|
8311
|
+
"category": "Market Neutral",
|
|
8312
|
+
"vaultAddress": "4QBTzqUbn1crLg2PDUGt8abJfqHjeuZkjNLjCCit69ui",
|
|
8313
|
+
"depositToken": "USDC",
|
|
8314
|
+
"pointsMultiplier": 1,
|
|
8315
|
+
"pointsEnabled": true
|
|
8316
|
+
},
|
|
8305
8317
|
{
|
|
8306
8318
|
"vaultId": 73,
|
|
8307
8319
|
"name": "Great Debasement",
|
|
@@ -9344,6 +9356,43 @@ function getVaultDepositorAddressSync(programId, vault, authority) {
|
|
|
9344
9356
|
|
|
9345
9357
|
//#endregion
|
|
9346
9358
|
//#region src/utils/bundle.ts
|
|
9359
|
+
const SECONDS_PER_YEAR = 365n * 24n * 60n * 60n;
|
|
9360
|
+
function bnToBigInt(v) {
|
|
9361
|
+
if (v == null) return 0n;
|
|
9362
|
+
return BigInt(v.toString());
|
|
9363
|
+
}
|
|
9364
|
+
/**
|
|
9365
|
+
* Estimated unpaid bundle fees in deposit token (mgmt + performance), matching on-chain `charge_user_fees`.
|
|
9366
|
+
*/
|
|
9367
|
+
function estimatePendingBundleFeeToken({ oracleData, bundleData, userBundle, assetDecimals, nowUnixSeconds = Math.floor(Date.now() / 1e3) }) {
|
|
9368
|
+
const userShares = bnToBigInt(userBundle.shares);
|
|
9369
|
+
if (userShares <= 0n) return 0;
|
|
9370
|
+
const totalShares = bnToBigInt(bundleData.totalShares);
|
|
9371
|
+
const totalAssets = bnToBigInt(oracleData.averageExternalEquity) + bnToBigInt(bundleData.bundleUnderlyingBalance);
|
|
9372
|
+
const extra = bundleData;
|
|
9373
|
+
const assetPrec = extra.assetPrecision != null ? BigInt(extra.assetPrecision.toString()) : BigInt(10 ** assetDecimals);
|
|
9374
|
+
const sharePrice = totalShares > 0n ? totalAssets * assetPrec / totalShares : assetPrec;
|
|
9375
|
+
const managementFeeBps = BigInt(Number(extra.managementFeeBps ?? 0));
|
|
9376
|
+
const performanceFeeBps = BigInt(Number(extra.performanceFee ?? 0));
|
|
9377
|
+
const lastMgmtTs = bnToBigInt(userBundle.lastManagementFeeTimestamp);
|
|
9378
|
+
const nowTs = BigInt(nowUnixSeconds);
|
|
9379
|
+
let managementFeeShares = 0n;
|
|
9380
|
+
if (lastMgmtTs > 0n && managementFeeBps > 0n) {
|
|
9381
|
+
const secondsElapsed = nowTs > lastMgmtTs ? nowTs - lastMgmtTs : 0n;
|
|
9382
|
+
if (secondsElapsed > 0n) managementFeeShares = userShares * secondsElapsed * managementFeeBps / (SECONDS_PER_YEAR * 10000n);
|
|
9383
|
+
}
|
|
9384
|
+
const hwmPerShare = bnToBigInt(userBundle.hwmPerShare);
|
|
9385
|
+
let performanceFeeShares = 0n;
|
|
9386
|
+
if (performanceFeeBps > 0n && sharePrice > 0n) {
|
|
9387
|
+
const hwmValue = hwmPerShare === 0n ? sharePrice : hwmPerShare;
|
|
9388
|
+
if (sharePrice > hwmValue) performanceFeeShares = (sharePrice - hwmValue) * userShares * performanceFeeBps / (sharePrice * 10000n);
|
|
9389
|
+
}
|
|
9390
|
+
const totalFeeShares = managementFeeShares + performanceFeeShares;
|
|
9391
|
+
if (totalFeeShares === 0n) return 0;
|
|
9392
|
+
const feeValueRaw = totalFeeShares * sharePrice / assetPrec;
|
|
9393
|
+
const divisor = 10 ** assetDecimals;
|
|
9394
|
+
return Number(feeValueRaw) / divisor;
|
|
9395
|
+
}
|
|
9347
9396
|
/**
|
|
9348
9397
|
* Calculate on-chain PPS for Bundle vault
|
|
9349
9398
|
* Formula: (Oracle Average External Equity + USDC on Bundle PDA) / Total Shares
|
|
@@ -9370,6 +9419,12 @@ function calculateBundleUserBalance({ oracleData, bundleData, userBundle, assetD
|
|
|
9370
9419
|
const feesPaid = Number(userBundle.totalFeeCharged.toString()) / divisor;
|
|
9371
9420
|
const userEarnings = userBalance - netDeposits;
|
|
9372
9421
|
const highWaterMark = Math.floor(Number(userBundle.hwmPerShare.toString()) * userSharesNum / divisor) / divisor;
|
|
9422
|
+
const pendingFeeToken = estimatePendingBundleFeeToken({
|
|
9423
|
+
oracleData,
|
|
9424
|
+
bundleData,
|
|
9425
|
+
userBundle,
|
|
9426
|
+
assetDecimals
|
|
9427
|
+
});
|
|
9373
9428
|
return {
|
|
9374
9429
|
balanceToken: userBalance,
|
|
9375
9430
|
balanceUsd: userBalance * spotPrice,
|
|
@@ -9380,6 +9435,8 @@ function calculateBundleUserBalance({ oracleData, bundleData, userBundle, assetD
|
|
|
9380
9435
|
pendingDeposit,
|
|
9381
9436
|
highWaterMark: highWaterMark + pendingDeposit,
|
|
9382
9437
|
feesPaid,
|
|
9438
|
+
pendingFee: pendingFeeToken,
|
|
9439
|
+
pendingFeeUsd: pendingFeeToken * spotPrice,
|
|
9383
9440
|
spotPrice,
|
|
9384
9441
|
vaultShares: userSharesNum,
|
|
9385
9442
|
netDeposit: netDeposits,
|
|
@@ -9504,7 +9561,7 @@ async function calculateDriftVaultBalance({ vault, vaultDepositor, driftVaultCli
|
|
|
9504
9561
|
netDepositToken: netDeposit,
|
|
9505
9562
|
requestWithdrawToken,
|
|
9506
9563
|
balanceToken
|
|
9507
|
-
})
|
|
9564
|
+
});
|
|
9508
9565
|
const totalDeposit = balanceToken + requestWithdrawToken;
|
|
9509
9566
|
return {
|
|
9510
9567
|
balanceToken,
|
|
@@ -9520,6 +9577,8 @@ async function calculateDriftVaultBalance({ vault, vaultDepositor, driftVaultCli
|
|
|
9520
9577
|
feesPaid: profitShareFeePaid,
|
|
9521
9578
|
highWaterMark,
|
|
9522
9579
|
pendingProfitShareFee,
|
|
9580
|
+
pendingFee: pendingProfitShareFee,
|
|
9581
|
+
pendingFeeUsd: pendingProfitShareFee * spotPrice,
|
|
9523
9582
|
asset
|
|
9524
9583
|
};
|
|
9525
9584
|
}
|
|
@@ -9735,4 +9794,4 @@ var NeutralTrade = class NeutralTrade {
|
|
|
9735
9794
|
};
|
|
9736
9795
|
|
|
9737
9796
|
//#endregion
|
|
9738
|
-
export { BundleProgramId, NeutralTrade, SupportedChain, SupportedToken, VaultCategory, VaultId, VaultType, createBundleProgramV1, createBundleProgramV2, createBundlePrograms, deriveOraclePDA, deriveUserPDA, getBundleProgramId, getDriftProgramId, getPointsVaults, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults };
|
|
9797
|
+
export { BundleProgramId, NeutralTrade, SupportedChain, SupportedToken, VaultCategory, VaultId, VaultType, createBundleProgramV1, createBundleProgramV2, createBundlePrograms, deriveOraclePDA, deriveUserPDA, estimatePendingBundleFeeToken, getBundleProgramId, getDriftProgramId, getPointsVaults, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults };
|