@perena/vault-sdk 1.0.34 → 1.0.36

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/README.md CHANGED
@@ -72,6 +72,59 @@ const client = new VaultClient(makeProvider(connection, payer));
72
72
  const [vault] = await client.pda.deriveVaultPda(0); // vault id
73
73
  ```
74
74
 
75
+ ## NAV-priced yield-tracker accounts
76
+
77
+ The SDK supports both legacy APR accounts and NAV accounts whose share price is
78
+ read by the yield tracker from a configured JSON API. Cashflow amounts are USDC
79
+ base units; for NAV accounts the tracker records the exact shares purchased or
80
+ redeemed at the fetched price.
81
+
82
+ ```typescript
83
+ import {
84
+ addCashflowUpdate,
85
+ createAccount,
86
+ getNavValue,
87
+ getTrackedValue,
88
+ } from "@perena/vault-sdk";
89
+
90
+ await createAccount({
91
+ name: "piku-basis-trade",
92
+ type: "stockmarkettrbasistrade",
93
+ valuationModel: "nav",
94
+ navConfig: {
95
+ url: "https://public-api.piku.co/v1/tokens/stockmarkettrbasistrade",
96
+ price_path: "price",
97
+ },
98
+ tag: vault.toString(),
99
+ password: accountPassword,
100
+ adminSecret,
101
+ });
102
+
103
+ const deposit = await addCashflowUpdate({
104
+ accountName: "piku-basis-trade",
105
+ amount: 1_000_000, // 1 USDC at six decimals
106
+ cashflowType: "deposit",
107
+ valuationModel: "nav",
108
+ password: accountPassword,
109
+ });
110
+ console.log(deposit.share_amount, deposit.nav_price);
111
+
112
+ const nav = await getNavValue("piku-basis-trade");
113
+ console.log(nav.shares, nav.nav_price, nav.total_nav);
114
+
115
+ // Works for either APR or NAV accounts.
116
+ const tracked = await getTrackedValue("piku-basis-trade");
117
+ console.log(tracked.totalValue, tracked.valuationModel);
118
+ ```
119
+
120
+ Use `getAprYield(...)` when an APR-only response is required. The general
121
+ `getYield(...)` and `getBalance(...)` methods return discriminated APR/NAV
122
+ unions, with `isNavAccountValue(...)` and `isNavAccountBalance(...)` available
123
+ as type guards. Historical `start`, `end`, or `as_of` valuation is unavailable
124
+ for NAV accounts backed only by a current-price API. NAV cashflows have no
125
+ `date` or `fundingNextDay` parameter: they execute immediately at the price the
126
+ tracker fetches during submission.
127
+
75
128
  ## Creating transactions
76
129
 
77
130
  ### The builder pattern
package/dist/index.d.ts CHANGED
@@ -15161,29 +15161,73 @@ interface BasicAuthCredentials {
15161
15161
  }
15162
15162
  declare function dateToStr(date: Date): string;
15163
15163
  declare function roundToNextUtcMidnight(date: Date): Date;
15164
+ type YieldValuationModel = "apr" | "nav";
15165
+ interface NavPriceConfig {
15166
+ url: string;
15167
+ price_path: string;
15168
+ }
15169
+ interface YieldCashflow {
15170
+ id: string;
15171
+ account_name: string;
15172
+ /** Signed USDC amount in tracker base units. */
15173
+ amount: number;
15174
+ /** Present for NAV accounts: exact signed shares derived at submission. */
15175
+ share_amount?: string;
15176
+ nav_price?: string;
15177
+ nav_fetched_at?: Date;
15178
+ timestamp: Date;
15179
+ description?: string | null;
15180
+ created_at: Date;
15181
+ }
15164
15182
  interface YieldAccount {
15165
15183
  name: string;
15166
15184
  tag: string | null;
15167
15185
  type: string;
15168
- apy: number | null;
15186
+ /** `apr` is returned by single-account/create/update endpoints. */
15187
+ apr?: number | null;
15188
+ /** `apy` is the legacy list-endpoint name for the same APR value. */
15189
+ apy?: number | null;
15190
+ valuation_model?: YieldValuationModel;
15191
+ nav_config?: NavPriceConfig | null;
15169
15192
  description?: string | null;
15193
+ created_at?: Date;
15194
+ updated_at?: Date;
15195
+ cashflows?: YieldCashflow[];
15196
+ }
15197
+ interface NavYieldAccount extends YieldAccount {
15198
+ valuation_model: "nav";
15199
+ nav_config: NavPriceConfig;
15200
+ apr?: null;
15201
+ apy?: null;
15170
15202
  }
15203
+ declare function isNavYieldAccount(account: YieldAccount): account is NavYieldAccount;
15171
15204
  interface CreateAccountBaseParams {
15172
15205
  name: string;
15173
15206
  password: string;
15174
15207
  adminSecret?: string;
15175
- tag?: string;
15208
+ /** Vault address used by consensus-oracle account discovery. */
15209
+ tag: string;
15176
15210
  description?: string;
15177
15211
  }
15178
- type CreateAccountParams<TType extends string = string> = CreateAccountBaseParams & {
15212
+ type AprCreateAccountParams<TType extends string> = CreateAccountBaseParams & {
15179
15213
  type: TType;
15214
+ valuationModel?: "apr";
15215
+ navConfig?: never;
15180
15216
  } & (TType extends "dynamic" ? {
15181
15217
  apr: number;
15182
15218
  } : {
15183
15219
  apr?: number;
15184
15220
  });
15185
- declare function createAccount<TType extends string>(params: CreateAccountParams<TType>): Promise<any>;
15221
+ type NavCreateAccountParams<TType extends string> = CreateAccountBaseParams & {
15222
+ type: TType;
15223
+ valuationModel: "nav";
15224
+ navConfig: NavPriceConfig;
15225
+ apr?: never;
15226
+ };
15227
+ type CreateAccountParams<TType extends string = string> = AprCreateAccountParams<TType> | NavCreateAccountParams<TType>;
15228
+ declare function createAccount<TType extends string>(params: CreateAccountParams<TType>): Promise<YieldAccount>;
15186
15229
  declare function getAccounts(): Promise<YieldAccount[]>;
15230
+ declare function getAccount(accountName: string): Promise<YieldAccount>;
15187
15231
  interface UpdateAccountParams {
15188
15232
  accountName: string;
15189
15233
  password: string;
@@ -15192,6 +15236,8 @@ interface UpdateAccountParams {
15192
15236
  apr?: number;
15193
15237
  tag?: string | null;
15194
15238
  description?: string | null;
15239
+ valuationModel?: YieldValuationModel;
15240
+ navConfig?: NavPriceConfig;
15195
15241
  }
15196
15242
  declare function updateAccount(params: UpdateAccountParams): Promise<YieldAccount>;
15197
15243
  interface DeleteAccountParams {
@@ -15207,24 +15253,45 @@ interface UpdateDynamicAprParams {
15207
15253
  password: string;
15208
15254
  }
15209
15255
  declare function updateDynamicApr(params: UpdateDynamicAprParams): Promise<any>;
15210
- interface AddCashflowUpdateParams {
15256
+ interface AddCashflowUpdateBaseParams {
15211
15257
  accountName: string;
15212
15258
  amount: number;
15213
- date: Date;
15214
15259
  description?: string;
15215
15260
  password: string;
15216
15261
  cashflowType: "deposit" | "withdraw";
15262
+ }
15263
+ interface AddNavCashflowUpdateParams extends AddCashflowUpdateBaseParams {
15264
+ /** NAV cashflows always execute immediately at the fetched price. */
15265
+ valuationModel: "nav";
15266
+ }
15267
+ interface AddAprCashflowUpdateParams extends AddCashflowUpdateBaseParams {
15268
+ valuationModel?: "apr";
15269
+ date?: Date;
15217
15270
  fundingNextDay?: boolean;
15218
15271
  }
15219
- declare function addCashflowUpdate(params: AddCashflowUpdateParams): Promise<any>;
15220
- declare function getCashflows(accountName: string): Promise<any>;
15221
- interface AccountBalanceResponse {
15272
+ type AddCashflowUpdateParams = AddNavCashflowUpdateParams | AddAprCashflowUpdateParams;
15273
+ declare function addCashflowUpdate(params: AddCashflowUpdateParams): Promise<YieldCashflow>;
15274
+ declare function getCashflows(accountName: string): Promise<YieldCashflow[]>;
15275
+ interface AprAccountBalanceResponse {
15222
15276
  account_name: string;
15223
15277
  account_type: string;
15278
+ valuation_model?: "apr";
15224
15279
  apr: number;
15225
15280
  balance: number;
15226
15281
  as_of: Date;
15227
15282
  }
15283
+ interface NavAccountBalanceResponse {
15284
+ account_name: string;
15285
+ account_type: string;
15286
+ valuation_model: "nav";
15287
+ total_nav: string;
15288
+ shares: string;
15289
+ nav_price: string;
15290
+ nav_fetched_at: Date;
15291
+ as_of: Date;
15292
+ }
15293
+ type AccountBalanceResponse = AprAccountBalanceResponse | NavAccountBalanceResponse;
15294
+ declare function isNavAccountBalance(response: AccountBalanceResponse): response is NavAccountBalanceResponse;
15228
15295
  declare function getBalance(accountName: string, atTime?: Date): Promise<AccountBalanceResponse>;
15229
15296
  interface YieldCalculationLog {
15230
15297
  segment_number: number;
@@ -15237,7 +15304,8 @@ interface YieldCalculationLog {
15237
15304
  cumulative_yield: number;
15238
15305
  calculation_formula: string;
15239
15306
  }
15240
- interface AccountYieldResponse {
15307
+ interface AprAccountYieldResponse {
15308
+ valuation_model?: "apr";
15241
15309
  account: {
15242
15310
  name: string;
15243
15311
  type: string;
@@ -15256,6 +15324,16 @@ interface AccountYieldResponse {
15256
15324
  apr_used: number;
15257
15325
  calculation_log: YieldCalculationLog[];
15258
15326
  }
15327
+ interface NavAccountValueResponse {
15328
+ account: AprAccountYieldResponse["account"];
15329
+ valuation_model: "nav";
15330
+ total_nav: string;
15331
+ shares: string;
15332
+ nav_price: string;
15333
+ nav_fetched_at: Date;
15334
+ }
15335
+ type AccountYieldResponse = AprAccountYieldResponse | NavAccountValueResponse;
15336
+ declare function isNavAccountValue(response: AccountYieldResponse): response is NavAccountValueResponse;
15259
15337
  interface CreateYieldPaymentParams {
15260
15338
  accountName: string;
15261
15339
  amount: number;
@@ -15283,9 +15361,26 @@ declare function confirmYieldPayment(params: {
15283
15361
  }): Promise<YieldPaymentResponse>;
15284
15362
  declare function getYieldPayments(accountName: string): Promise<YieldPaymentResponse[]>;
15285
15363
  declare function getYield(accountName: string, start?: Date, end?: Date): Promise<AccountYieldResponse>;
15364
+ declare function getAprYield(accountName: string, start?: Date, end?: Date): Promise<AprAccountYieldResponse>;
15365
+ declare function getNavValue(accountName: string): Promise<NavAccountValueResponse>;
15366
+ interface TrackedAccountValue {
15367
+ totalValue: number;
15368
+ principal: number;
15369
+ outstandingYield: number;
15370
+ valuationModel: YieldValuationModel;
15371
+ }
15372
+ /** Normalize either yield-tracker response model into one current base-unit value. */
15373
+ declare function trackedValueFromResponse(response: AccountYieldResponse): TrackedAccountValue;
15374
+ declare function getTrackedValue(accountName: string): Promise<TrackedAccountValue>;
15286
15375
  declare function getTotalYield(accountNames: string[], start?: Date, end?: Date): Promise<BN>;
15287
15376
  /** Sum only confirmed-payment-adjusted yield that remains receivable. */
15288
15377
  declare function getTotalOutstandingYield(accountNames: string[], start?: Date, end?: Date): Promise<number>;
15378
+ /** Sum the complete current value of APR and NAV accounts in tracker base units. */
15379
+ declare function getTotalTrackedValue(accountNames: string[], start?: Date, end?: Date): Promise<{
15380
+ totalValue: number;
15381
+ principal: number;
15382
+ outstandingYield: number;
15383
+ }>;
15289
15384
 
15290
15385
  /**
15291
15386
  * Junior-tranche withdrawal-queue fulfillment.
@@ -15544,13 +15639,21 @@ interface YieldTracker {
15544
15639
  getAccountNamesForVault?(vault: Address): Promise<string[]>;
15545
15640
  /** All payments for an account, including payments not yet confirmed. */
15546
15641
  getYieldPayments(accountName: string): Promise<YieldPaymentSnapshot[]>;
15547
- /** Sum of oracle-safe outstanding yield across the named accounts. */
15642
+ /** Sum of oracle-safe outstanding yield across APR accounts. */
15548
15643
  getTotalOutstandingYield(accountNames: string[], start?: Date, end?: Date): Promise<number>;
15549
15644
  /**
15550
- * Sum the external principal and confirmed-payment-adjusted outstanding yield
15551
- * across the named accounts. Both values are UI token amounts.
15645
+ * Sum complete current account value across APR and NAV accounts. APR
15646
+ * diagnostics remain separate; NAV accounts contribute only to totalValue.
15647
+ * All values are UI token amounts.
15552
15648
  */
15553
- getTotalTrackedAmounts(accountNames: string[], start?: Date, end?: Date): Promise<{
15649
+ getTotalTrackedValue?(accountNames: string[], start?: Date, end?: Date): Promise<{
15650
+ totalValue: number;
15651
+ /** APR-account diagnostics; NAV accounts contribute zero here. */
15652
+ principal: number;
15653
+ outstandingYield: number;
15654
+ }>;
15655
+ /** @deprecated APR-only compatibility surface; use getTotalTrackedValue. */
15656
+ getTotalTrackedAmounts?(accountNames: string[], start?: Date, end?: Date): Promise<{
15554
15657
  principal: number;
15555
15658
  outstandingYield: number;
15556
15659
  }>;
@@ -15608,7 +15711,9 @@ interface HoldingUpdatePreview {
15608
15711
  yieldAmount: bigint;
15609
15712
  /** Yield-tracker principal attributed to this holding (base units). */
15610
15713
  trackedPrincipalAmount: bigint;
15611
- /** Total external balance pushed = wallet + LP + tracked principal + yield. */
15714
+ /** Complete tracked value, including NAV accounts (base units). */
15715
+ trackedValueAmount: bigint;
15716
+ /** Total external balance pushed = wallet + LP + complete tracked value. */
15612
15717
  externalAmount: bigint;
15613
15718
  }
15614
15719
  interface VaultOracleResult {
@@ -15905,6 +16010,7 @@ interface LargeBalanceChangeViolation {
15905
16010
  walletAmount: bigint;
15906
16011
  lpAmount: bigint;
15907
16012
  trackedPrincipalAmount: bigint;
16013
+ trackedValueAmount: bigint;
15908
16014
  yieldAmount: bigint;
15909
16015
  }
15910
16016
  interface StaleBalanceChangeBypass extends LargeBalanceChangeViolation {
@@ -15939,8 +16045,9 @@ declare function simulateDryRunSettlement({ client, signer, vault, vaultState, u
15939
16045
 
15940
16046
  declare function buildUpdates(yieldTracker: YieldTracker | undefined, reportableHoldings: ConsensusHoldingEntry[], inputs: VaultPricingInputs): Promise<HoldingUpdatePreview[]>;
15941
16047
  declare function buildHoldingUpdate(yieldTracker: YieldTracker | undefined, entry: ConsensusHoldingEntry, inputs: VaultPricingInputs): Promise<HoldingUpdatePreview>;
15942
- /** Tracked external principal + outstanding yield attributed to a holding. */
16048
+ /** Complete tracked account value attributed to a holding. */
15943
16049
  declare function resolveTrackedAmounts(yieldTracker: YieldTracker | undefined, cfg: ConsensusOracleHoldingConfig | undefined, decimals: number): Promise<{
16050
+ trackedValueAmount: bigint;
15944
16051
  principalAmount: bigint;
15945
16052
  yieldAmount: bigint;
15946
16053
  }>;
@@ -16268,6 +16375,12 @@ declare class MockYieldTracker implements YieldTracker {
16268
16375
  getYield(accountName: string, start?: Date, end?: Date): Promise<YieldAccountSnapshot>;
16269
16376
  getTotalYield(accountNames: string[], start?: Date, end?: Date): Promise<number>;
16270
16377
  getTotalOutstandingYield(accountNames: string[], start?: Date, end?: Date): Promise<number>;
16378
+ getTotalTrackedValue(accountNames: string[], start?: Date, end?: Date): Promise<{
16379
+ totalValue: number;
16380
+ principal: number;
16381
+ outstandingYield: number;
16382
+ }>;
16383
+ /** Backward-compatible APR-only breakdown. */
16271
16384
  getTotalTrackedAmounts(accountNames: string[], start?: Date, end?: Date): Promise<{
16272
16385
  principal: number;
16273
16386
  outstandingYield: number;
@@ -16613,4 +16726,4 @@ declare class IdleLiquidityService {
16613
16726
  private executeSwap;
16614
16727
  }
16615
16728
 
16616
- export { ASSET_DECIMALS, ASSET_REBALANCE_COOLDOWN_SECS, type AccountBalanceResponse, AccountClient, type AccountYieldResponse, ActivateCircuitBreakerBuilder, type ActivateCircuitBreakerIxArgs, type ActivateCircuitBreakerTxArgs, type AssetPriceOracleConfigIxArgs, type AssetPriceOracleConfigTxArgs, type AssetPriceRefreshTarget, type AssetRefreshResult, type AssetType, BALANCE_CHANGE_BASELINE_MAX_AGE_SECS, type Bankineco, type BasicAuthCredentials, type Bigintish, CONSENSUS_ORACLE_VARIANT, CancelJuniorTrancheWithdrawBuilder, type CancelJuniorTrancheWithdrawIxArgs, type CancelJuniorTrancheWithdrawTxArgs, type Clock, type CollectSamplesOptions, type ConsensusAssetUpdate, type ConsensusHoldingEntry, type ConsensusHoldingSimulation, type ConsensusOracleDeps, type ConsensusOracleHoldingConfig, ConsensusOracleService, type ConsensusOracleTarget, CrankNavBuilder, type CrankNavIxArgs, type CrankNavTxArgs, CrankPerformanceFeesBuilder, type CrankPerformanceFeesIxArgs, type CrankPerformanceFeesTxArgs, type CreateAccountParams, CreateAssetHoldingBuilder, type CreateAssetHoldingIxArgs, type CreateAssetHoldingTxArgs, type CreateTokenMintIxs, CreateTrancheStateBuilder, type CreateTrancheStateIxArgs, type CreateTrancheStateTxArgs, CreateVaultBuilder, type CreateVaultClientOptions, type CreateVaultIxArgs, type CreateVaultParams, type CreateVaultTxArgs, type CreateYieldPaymentParams, DEFAULT_CU_PRICE_MICRO_LAMPORTS, DEFAULT_JUNIOR_EARLY_UNSTAKE_FEE_BPS, DEFAULT_JUNIOR_STANDARD_UNSTAKE_FEE_BPS, DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS, DEFAULT_MAX_ACCEPTABLE_APY_BPS, DEFAULT_MAX_ACCOUNTS, DEFAULT_MINTS, DEFAULT_MIN_AMOUNT_UI, DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS, DEFAULT_PRICE_ORACLE_ACCOUNT, DEFAULT_PRICE_STALENESS_SECS, DEFAULT_PRICE_STALENESS_THRESHOLD_SECS, DEFAULT_REBALANCE_BAND_BPS, DEFAULT_SLIPPAGE_BPS, DEFAULT_TARGET_LOCAL_BPS, DEFAULT_VAULT_ID, type DecodedHolding, type DecodedVault, type DecodedVaultTrancheState, type DeleteAccountParams, DisableCircuitBreakerBuilder, type DisableCircuitBreakerIxArgs, type DisableCircuitBreakerTxArgs, EXTERNAL_POSITION_SAMPLES, ExecuteDepositBuilder, type ExecuteDepositIxArgs, type ExecuteDepositTxArgs, ExecuteShareSwapBuilder, type ExecuteShareSwapIxArgs, type ExecuteShareSwapTxArgs, ExecuteTrancheDepositBuilder, type ExecuteTrancheDepositIxArgs, type ExecuteTrancheDepositTxArgs, ExecuteTrancheWithdrawBuilder, type ExecuteTrancheWithdrawIxArgs, type ExecuteTrancheWithdrawTxArgs, ExecuteWithdrawBuilder, type ExecuteWithdrawIxArgs, type ExecuteWithdrawTxArgs, type ExternalLiquidityIntegrityOptions, type ExternalLiquidityIntegrityResult, ExternalLiquidityIntegrityService, type ExternalLiquidityIntegritySummary, type ExternalLiquiditySlot, type ExternalLiquiditySourceArgs, type ExternalPosition, type ExternalPositionContext, type ExternalPositionProvider, type ExternalPositionRef, ExternalPositionRegistry, FEE_VAULT_CACHE_CATEGORY, type FeeVaultAccountData, type FetchNestTokenPriceOptions, FulfillJuniorTrancheWithdrawBuilder, type FulfillJuniorTrancheWithdrawIxArgs, type FulfillJuniorTrancheWithdrawTxArgs, type FulfillSummary, type HoldingNavContribution, type HoldingUpdatePreview, IDL, IDLE_RESERVE_FLOOR_BPS, IDLE_RESERVE_TARGET_BPS, type IdleLiquidityOptions, type IdleLiquidityResult, IdleLiquidityService, type IdleLiquidityStatus, InitializeVaultRolesBuilder, type InitializeVaultRolesIxArgs, type InitializeVaultRolesTxArgs, type JuniorWithdrawalMode, JupiterBalanceSource, type JupiterBalanceSourceOptions, JupiterPriceSource, type JupiterPriceSourceOptions, JupiterSwapBuilder, type JupiterSwapIxArgs, type JupiterSwapTxArgs, KaminoPositionProvider, LIVE_ORACLE_VARIANTS, LIVE_PRICE_REFRESH_INTERVAL_SECS, LOCAL_PROTOCOL_ADMIN, LargeBalanceChangeError, type LargeBalanceChangeViolation, type LiveConsensusOracleDepsOptions, LivePriceSource, type LivePriceSourceOptions, MAX_BALANCE_CHANGE_BPS, MAX_CONSENSUS_SIGNERS, MAX_MANAGER_WITHDRAW_DESTINATIONS, MAX_PRICE_STALENESS_THRESHOLD_SECS, MIN_EXTERNAL_POSITION_SAMPLES, ManagerRedepositAssetBuilder, type ManagerRedepositAssetIxArgs, type ManagerRedepositAssetTxArgs, ManagerWithdrawAssetBuilder, type ManagerWithdrawAssetIxArgs, type ManagerWithdrawAssetTxArgs, MarginfiPositionProvider, type MintConfig, type MintIdentifier, type MintInfo, MintRegistry, type MintRegistryOptions, type MockYieldAccountConfig, MockYieldTracker, type MockYieldTrackerOptions, NEST_API_BASE_URL, NEST_RWA_SHARE_MINT, NEST_VAULT_SLUG, type NavCrankBlocker, type NavCrankBlockerReason, type NavCrankReadiness, type NavCrankResult, NestPriceSource, type NestPriceSourceOptions, ORACLE_ENTRIES_OFFSET, ORACLE_ENTRY_SIZE, ORACLE_SETTLED_NAV_TS_OFFSET, OracleService, PRICE_ORACLE_TYPES_BY_INDEX, PROGRAM_FEE_EXEMPT_OWNER_WHITELIST, PROTOCOL_ADMIN, PROTOCOL_FEE_RECIPIENT, PdaClient, type PreparedDirectTransaction, type PreparedSquadsTransaction, type PreparedVaultTransaction, type PriceOracleTypeArgs, type PriceSource, ProtocolInteractionBuilder, type ProtocolInteractionIxArgs, type ProtocolInteractionTxArgs, type QuoteFeeUnit, REPORTABLE_ORACLE_VARIANTS, type RefreshLiveOraclePricesParams, RemoveAssetHoldingBuilder, type RemoveAssetHoldingIxArgs, type RemoveAssetHoldingTxArgs, RequestJuniorTrancheWithdrawBuilder, type RequestJuniorTrancheWithdrawIxArgs, type RequestJuniorTrancheWithdrawTxArgs, type ResolvedSquadsWalletRoute, type RollingLimitConfig, type RollingRebalanceLimitConfig, type RunLiveConsensusOracleOptions, type RunOptions, type RunSummary, SHARE_DECIMALS, SYSTEM_PROGRAM, SetAssetPriceOracleBuilder, type SetAssetPriceOracleIxArgs, type SetAssetPriceOracleTxArgs, SetExternalLiquidityBuilder, type SetExternalLiquidityIxArgs, type SetExternalLiquidityTxArgs, SetManagerWithdrawDestinationBuilder, type SetManagerWithdrawDestinationIxArgs, type SetManagerWithdrawDestinationTxArgs, SetProtocolFeeBuilder, type SetProtocolFeeIxArgs, type SetProtocolFeeTxArgs, SetVaultConfigBuilder, type SetVaultConfigIxArgs, type SetVaultConfigTxArgs, type SettleVaultParams, type SettleVaultResult, type SettlementSimulation, type SettlementSimulationSnapshot, type SimulateDryRunSettlementParams, type SimulateSettlementArgs, type SimulatedShareClass, type SquadsWalletRouteConfig, type StaleBalanceChangeBypass, StaticPositionProvider, TOKEN_PROGRAM, TOKEN_PROGRAM_ID, type TrancheKindArgs, type TransactionBuilder, TransactionClient, USDC_MINT, USD_STAR_JUNIOR_MINT, USD_STAR_MINT, USD_STAR_PRINCIPAL_MINT, type UpdateAccountParams, UpdateAssetPriceBuilder, type UpdateAssetPriceIxArgs, type UpdateAssetPriceTxArgs, UpdateConsensusOracleBuilder, type UpdateConsensusOracleIxArgs, type UpdateConsensusOracleTxArgs, UpdateConsensusSignersBuilder, type UpdateConsensusSignersIxArgs, type UpdateConsensusSignersTxArgs, type UpdateDynamicAprParams, UpdateTrancheConfigBuilder, type UpdateTrancheConfigIxArgs, type UpdateTrancheConfigTxArgs, VAULT_CACHE_CATEGORY, VAULT_CREATOR_WHITELIST, VAULT_ENVIRONMENTS, VAULT_ORACLE_CACHE_CATEGORY, VAULT_PROGRAM_ID, VAULT_PROGRAM_IDS, VAULT_PROGRAM_PUBLIC_KEY, VAULT_ROLE_UPDATE_TIMELOCK_SECS, VAULT_TRANCHE_STATE_CACHE_CATEGORY, VAULT_TRANCHE_WITHDRAWAL_QUEUE_CACHE_CATEGORY, type Vault, type VaultAccountData, VaultBuilderBase, type VaultBuilderContext, type VaultCacheInvalidation, VaultClient, type VaultClientBundle, type VaultEnv, type VaultOracleAccountData, type VaultOracleResult, type VaultPricingInputs, type VaultQuote, type VaultQuoteArgs, VaultQuoteClient, type VaultQuoteDirection, type VaultQuoteShareClass, VaultReallocationBuilder, type VaultReallocationIxArgs, type VaultReallocationTxArgs, type VaultTrancheStateAccountData, type VaultTrancheWithdrawalQueueAccountData, type VaultTransactionPlan, type WalletBalanceSource, type WithdrawProtocolFeesIxArgs, type WithdrawProtocolFeesTxArgs, type WithdrawTrancheFeesIxArgs, type WithdrawTrancheFeesTxArgs, WithdrawalQueueService, type WithdrawalQueueSnapshot, type YieldAccount, type YieldAccountSnapshot, type YieldCalculationLog, type YieldPaymentResponse, type YieldPaymentSnapshot, type YieldTracker, accountingUnitPriceToUsd, addCashflowUpdate, applyEffectiveApy, assertNoLargeBalanceChanges, assertNoUnconfirmedYieldPayments, buildHoldingUpdate, buildUpdates, coerceBool, collectSamples, confirmYieldPayment, createAccount, createLiveConsensusOracleDeps, createRpcFromConnection, createTokenMint, createTokenMintIxs, createVaultClient, createYieldPayment, dateToStr, defaultKeypairPath, deleteAccount, discoverVaultsForSigner, fetchExternalPositions, fetchNestTokenPrice, fetchReceiptMints, filterTargetHoldings, findLargeBalanceChanges, findSquadsWalletRoute, formatSettlementSimulation, fromUiAmount, gatherPricingInputs, getAccounts, getBalance, getCashflows, getRpcUrl, getTotalOutstandingYield, getTotalYield, getVaultProgramId, getYield, getYieldPayments, indexConfigByMint, isVaultEnv, keypairAddress, loadKeypair, logProspectiveApy, makeProvider, mintTokensTo, mints, mostFrequent, parseExternalLiquidityRefs, planRebalance, prepareVaultTransaction, priceInAccountingUnit, readI64LE, readSplMintSupply, refreshLiveOraclePrices, resolveKeypairPath, resolveSquadsWalletRoute, resolveTrackedAmounts, roundToNextUtcMidnight, runLiveConsensusOracle, selectReportableHoldings, settleVault, signerInOracleData, simulateConsensusOracleSettlement, simulateDryRunSettlement, sumPositionsByMint, systemClock, toBigInt, toUiAmount, updateAccount, updateDynamicApr, validateSquadsWalletRoutes, variantName, vaultAuthorityForWallet, withDiscoveredYieldAccounts };
16729
+ export { ASSET_DECIMALS, ASSET_REBALANCE_COOLDOWN_SECS, type AccountBalanceResponse, AccountClient, type AccountYieldResponse, ActivateCircuitBreakerBuilder, type ActivateCircuitBreakerIxArgs, type ActivateCircuitBreakerTxArgs, type AddAprCashflowUpdateParams, type AddCashflowUpdateParams, type AddNavCashflowUpdateParams, type AprAccountBalanceResponse, type AprAccountYieldResponse, type AssetPriceOracleConfigIxArgs, type AssetPriceOracleConfigTxArgs, type AssetPriceRefreshTarget, type AssetRefreshResult, type AssetType, BALANCE_CHANGE_BASELINE_MAX_AGE_SECS, type Bankineco, type BasicAuthCredentials, type Bigintish, CONSENSUS_ORACLE_VARIANT, CancelJuniorTrancheWithdrawBuilder, type CancelJuniorTrancheWithdrawIxArgs, type CancelJuniorTrancheWithdrawTxArgs, type Clock, type CollectSamplesOptions, type ConsensusAssetUpdate, type ConsensusHoldingEntry, type ConsensusHoldingSimulation, type ConsensusOracleDeps, type ConsensusOracleHoldingConfig, ConsensusOracleService, type ConsensusOracleTarget, CrankNavBuilder, type CrankNavIxArgs, type CrankNavTxArgs, CrankPerformanceFeesBuilder, type CrankPerformanceFeesIxArgs, type CrankPerformanceFeesTxArgs, type CreateAccountParams, CreateAssetHoldingBuilder, type CreateAssetHoldingIxArgs, type CreateAssetHoldingTxArgs, type CreateTokenMintIxs, CreateTrancheStateBuilder, type CreateTrancheStateIxArgs, type CreateTrancheStateTxArgs, CreateVaultBuilder, type CreateVaultClientOptions, type CreateVaultIxArgs, type CreateVaultParams, type CreateVaultTxArgs, type CreateYieldPaymentParams, DEFAULT_CU_PRICE_MICRO_LAMPORTS, DEFAULT_JUNIOR_EARLY_UNSTAKE_FEE_BPS, DEFAULT_JUNIOR_STANDARD_UNSTAKE_FEE_BPS, DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS, DEFAULT_MAX_ACCEPTABLE_APY_BPS, DEFAULT_MAX_ACCOUNTS, DEFAULT_MINTS, DEFAULT_MIN_AMOUNT_UI, DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS, DEFAULT_PRICE_ORACLE_ACCOUNT, DEFAULT_PRICE_STALENESS_SECS, DEFAULT_PRICE_STALENESS_THRESHOLD_SECS, DEFAULT_REBALANCE_BAND_BPS, DEFAULT_SLIPPAGE_BPS, DEFAULT_TARGET_LOCAL_BPS, DEFAULT_VAULT_ID, type DecodedHolding, type DecodedVault, type DecodedVaultTrancheState, type DeleteAccountParams, DisableCircuitBreakerBuilder, type DisableCircuitBreakerIxArgs, type DisableCircuitBreakerTxArgs, EXTERNAL_POSITION_SAMPLES, ExecuteDepositBuilder, type ExecuteDepositIxArgs, type ExecuteDepositTxArgs, ExecuteShareSwapBuilder, type ExecuteShareSwapIxArgs, type ExecuteShareSwapTxArgs, ExecuteTrancheDepositBuilder, type ExecuteTrancheDepositIxArgs, type ExecuteTrancheDepositTxArgs, ExecuteTrancheWithdrawBuilder, type ExecuteTrancheWithdrawIxArgs, type ExecuteTrancheWithdrawTxArgs, ExecuteWithdrawBuilder, type ExecuteWithdrawIxArgs, type ExecuteWithdrawTxArgs, type ExternalLiquidityIntegrityOptions, type ExternalLiquidityIntegrityResult, ExternalLiquidityIntegrityService, type ExternalLiquidityIntegritySummary, type ExternalLiquiditySlot, type ExternalLiquiditySourceArgs, type ExternalPosition, type ExternalPositionContext, type ExternalPositionProvider, type ExternalPositionRef, ExternalPositionRegistry, FEE_VAULT_CACHE_CATEGORY, type FeeVaultAccountData, type FetchNestTokenPriceOptions, FulfillJuniorTrancheWithdrawBuilder, type FulfillJuniorTrancheWithdrawIxArgs, type FulfillJuniorTrancheWithdrawTxArgs, type FulfillSummary, type HoldingNavContribution, type HoldingUpdatePreview, IDL, IDLE_RESERVE_FLOOR_BPS, IDLE_RESERVE_TARGET_BPS, type IdleLiquidityOptions, type IdleLiquidityResult, IdleLiquidityService, type IdleLiquidityStatus, InitializeVaultRolesBuilder, type InitializeVaultRolesIxArgs, type InitializeVaultRolesTxArgs, type JuniorWithdrawalMode, JupiterBalanceSource, type JupiterBalanceSourceOptions, JupiterPriceSource, type JupiterPriceSourceOptions, JupiterSwapBuilder, type JupiterSwapIxArgs, type JupiterSwapTxArgs, KaminoPositionProvider, LIVE_ORACLE_VARIANTS, LIVE_PRICE_REFRESH_INTERVAL_SECS, LOCAL_PROTOCOL_ADMIN, LargeBalanceChangeError, type LargeBalanceChangeViolation, type LiveConsensusOracleDepsOptions, LivePriceSource, type LivePriceSourceOptions, MAX_BALANCE_CHANGE_BPS, MAX_CONSENSUS_SIGNERS, MAX_MANAGER_WITHDRAW_DESTINATIONS, MAX_PRICE_STALENESS_THRESHOLD_SECS, MIN_EXTERNAL_POSITION_SAMPLES, ManagerRedepositAssetBuilder, type ManagerRedepositAssetIxArgs, type ManagerRedepositAssetTxArgs, ManagerWithdrawAssetBuilder, type ManagerWithdrawAssetIxArgs, type ManagerWithdrawAssetTxArgs, MarginfiPositionProvider, type MintConfig, type MintIdentifier, type MintInfo, MintRegistry, type MintRegistryOptions, type MockYieldAccountConfig, MockYieldTracker, type MockYieldTrackerOptions, NEST_API_BASE_URL, NEST_RWA_SHARE_MINT, NEST_VAULT_SLUG, type NavAccountBalanceResponse, type NavAccountValueResponse, type NavCrankBlocker, type NavCrankBlockerReason, type NavCrankReadiness, type NavCrankResult, type NavPriceConfig, type NavYieldAccount, NestPriceSource, type NestPriceSourceOptions, ORACLE_ENTRIES_OFFSET, ORACLE_ENTRY_SIZE, ORACLE_SETTLED_NAV_TS_OFFSET, OracleService, PRICE_ORACLE_TYPES_BY_INDEX, PROGRAM_FEE_EXEMPT_OWNER_WHITELIST, PROTOCOL_ADMIN, PROTOCOL_FEE_RECIPIENT, PdaClient, type PreparedDirectTransaction, type PreparedSquadsTransaction, type PreparedVaultTransaction, type PriceOracleTypeArgs, type PriceSource, ProtocolInteractionBuilder, type ProtocolInteractionIxArgs, type ProtocolInteractionTxArgs, type QuoteFeeUnit, REPORTABLE_ORACLE_VARIANTS, type RefreshLiveOraclePricesParams, RemoveAssetHoldingBuilder, type RemoveAssetHoldingIxArgs, type RemoveAssetHoldingTxArgs, RequestJuniorTrancheWithdrawBuilder, type RequestJuniorTrancheWithdrawIxArgs, type RequestJuniorTrancheWithdrawTxArgs, type ResolvedSquadsWalletRoute, type RollingLimitConfig, type RollingRebalanceLimitConfig, type RunLiveConsensusOracleOptions, type RunOptions, type RunSummary, SHARE_DECIMALS, SYSTEM_PROGRAM, SetAssetPriceOracleBuilder, type SetAssetPriceOracleIxArgs, type SetAssetPriceOracleTxArgs, SetExternalLiquidityBuilder, type SetExternalLiquidityIxArgs, type SetExternalLiquidityTxArgs, SetManagerWithdrawDestinationBuilder, type SetManagerWithdrawDestinationIxArgs, type SetManagerWithdrawDestinationTxArgs, SetProtocolFeeBuilder, type SetProtocolFeeIxArgs, type SetProtocolFeeTxArgs, SetVaultConfigBuilder, type SetVaultConfigIxArgs, type SetVaultConfigTxArgs, type SettleVaultParams, type SettleVaultResult, type SettlementSimulation, type SettlementSimulationSnapshot, type SimulateDryRunSettlementParams, type SimulateSettlementArgs, type SimulatedShareClass, type SquadsWalletRouteConfig, type StaleBalanceChangeBypass, StaticPositionProvider, TOKEN_PROGRAM, TOKEN_PROGRAM_ID, type TrackedAccountValue, type TrancheKindArgs, type TransactionBuilder, TransactionClient, USDC_MINT, USD_STAR_JUNIOR_MINT, USD_STAR_MINT, USD_STAR_PRINCIPAL_MINT, type UpdateAccountParams, UpdateAssetPriceBuilder, type UpdateAssetPriceIxArgs, type UpdateAssetPriceTxArgs, UpdateConsensusOracleBuilder, type UpdateConsensusOracleIxArgs, type UpdateConsensusOracleTxArgs, UpdateConsensusSignersBuilder, type UpdateConsensusSignersIxArgs, type UpdateConsensusSignersTxArgs, type UpdateDynamicAprParams, UpdateTrancheConfigBuilder, type UpdateTrancheConfigIxArgs, type UpdateTrancheConfigTxArgs, VAULT_CACHE_CATEGORY, VAULT_CREATOR_WHITELIST, VAULT_ENVIRONMENTS, VAULT_ORACLE_CACHE_CATEGORY, VAULT_PROGRAM_ID, VAULT_PROGRAM_IDS, VAULT_PROGRAM_PUBLIC_KEY, VAULT_ROLE_UPDATE_TIMELOCK_SECS, VAULT_TRANCHE_STATE_CACHE_CATEGORY, VAULT_TRANCHE_WITHDRAWAL_QUEUE_CACHE_CATEGORY, type Vault, type VaultAccountData, VaultBuilderBase, type VaultBuilderContext, type VaultCacheInvalidation, VaultClient, type VaultClientBundle, type VaultEnv, type VaultOracleAccountData, type VaultOracleResult, type VaultPricingInputs, type VaultQuote, type VaultQuoteArgs, VaultQuoteClient, type VaultQuoteDirection, type VaultQuoteShareClass, VaultReallocationBuilder, type VaultReallocationIxArgs, type VaultReallocationTxArgs, type VaultTrancheStateAccountData, type VaultTrancheWithdrawalQueueAccountData, type VaultTransactionPlan, type WalletBalanceSource, type WithdrawProtocolFeesIxArgs, type WithdrawProtocolFeesTxArgs, type WithdrawTrancheFeesIxArgs, type WithdrawTrancheFeesTxArgs, WithdrawalQueueService, type WithdrawalQueueSnapshot, type YieldAccount, type YieldAccountSnapshot, type YieldCalculationLog, type YieldCashflow, type YieldPaymentResponse, type YieldPaymentSnapshot, type YieldTracker, type YieldValuationModel, accountingUnitPriceToUsd, addCashflowUpdate, applyEffectiveApy, assertNoLargeBalanceChanges, assertNoUnconfirmedYieldPayments, buildHoldingUpdate, buildUpdates, coerceBool, collectSamples, confirmYieldPayment, createAccount, createLiveConsensusOracleDeps, createRpcFromConnection, createTokenMint, createTokenMintIxs, createVaultClient, createYieldPayment, dateToStr, defaultKeypairPath, deleteAccount, discoverVaultsForSigner, fetchExternalPositions, fetchNestTokenPrice, fetchReceiptMints, filterTargetHoldings, findLargeBalanceChanges, findSquadsWalletRoute, formatSettlementSimulation, fromUiAmount, gatherPricingInputs, getAccount, getAccounts, getAprYield, getBalance, getCashflows, getNavValue, getRpcUrl, getTotalOutstandingYield, getTotalTrackedValue, getTotalYield, getTrackedValue, getVaultProgramId, getYield, getYieldPayments, indexConfigByMint, isNavAccountBalance, isNavAccountValue, isNavYieldAccount, isVaultEnv, keypairAddress, loadKeypair, logProspectiveApy, makeProvider, mintTokensTo, mints, mostFrequent, parseExternalLiquidityRefs, planRebalance, prepareVaultTransaction, priceInAccountingUnit, readI64LE, readSplMintSupply, refreshLiveOraclePrices, resolveKeypairPath, resolveSquadsWalletRoute, resolveTrackedAmounts, roundToNextUtcMidnight, runLiveConsensusOracle, selectReportableHoldings, settleVault, signerInOracleData, simulateConsensusOracleSettlement, simulateDryRunSettlement, sumPositionsByMint, systemClock, toBigInt, toUiAmount, trackedValueFromResponse, updateAccount, updateDynamicApr, validateSquadsWalletRoutes, variantName, vaultAuthorityForWallet, withDiscoveredYieldAccounts };
package/dist/index.js CHANGED
@@ -3393,16 +3393,24 @@ __export(index_exports, {
3393
3393
  formatSettlementSimulation: () => formatSettlementSimulation,
3394
3394
  fromUiAmount: () => fromUiAmount,
3395
3395
  gatherPricingInputs: () => gatherPricingInputs,
3396
+ getAccount: () => getAccount,
3396
3397
  getAccounts: () => getAccounts,
3398
+ getAprYield: () => getAprYield,
3397
3399
  getBalance: () => getBalance,
3398
3400
  getCashflows: () => getCashflows,
3401
+ getNavValue: () => getNavValue,
3399
3402
  getRpcUrl: () => getRpcUrl,
3400
3403
  getTotalOutstandingYield: () => getTotalOutstandingYield,
3404
+ getTotalTrackedValue: () => getTotalTrackedValue,
3401
3405
  getTotalYield: () => getTotalYield,
3406
+ getTrackedValue: () => getTrackedValue,
3402
3407
  getVaultProgramId: () => getVaultProgramId,
3403
3408
  getYield: () => getYield,
3404
3409
  getYieldPayments: () => getYieldPayments,
3405
3410
  indexConfigByMint: () => indexConfigByMint,
3411
+ isNavAccountBalance: () => isNavAccountBalance,
3412
+ isNavAccountValue: () => isNavAccountValue,
3413
+ isNavYieldAccount: () => isNavYieldAccount,
3406
3414
  isVaultEnv: () => isVaultEnv,
3407
3415
  keypairAddress: () => keypairAddress,
3408
3416
  loadKeypair: () => loadKeypair,
@@ -3432,6 +3440,7 @@ __export(index_exports, {
3432
3440
  systemClock: () => systemClock,
3433
3441
  toBigInt: () => toBigInt2,
3434
3442
  toUiAmount: () => toUiAmount,
3443
+ trackedValueFromResponse: () => trackedValueFromResponse,
3435
3444
  updateAccount: () => updateAccount,
3436
3445
  updateDynamicApr: () => updateDynamicApr,
3437
3446
  validateSquadsWalletRoutes: () => validateSquadsWalletRoutes,
@@ -20259,33 +20268,60 @@ function getAdminSecret(adminSecret) {
20259
20268
  }
20260
20269
  return secret;
20261
20270
  }
20271
+ function isNavYieldAccount(account) {
20272
+ return account.valuation_model === "nav";
20273
+ }
20262
20274
  async function createAccount(params) {
20263
- if (params.type === "dynamic" && params.apr === void 0) {
20275
+ const valuationModel = params.valuationModel ?? "apr";
20276
+ if (valuationModel === "nav" && !params.navConfig) {
20277
+ throw new Error("navConfig is required when creating a NAV account");
20278
+ }
20279
+ if (valuationModel === "nav" && params.apr !== void 0) {
20280
+ throw new Error("NAV accounts cannot define apr");
20281
+ }
20282
+ if (valuationModel === "apr" && params.type === "dynamic" && params.apr === void 0) {
20264
20283
  throw new Error("apr is required when creating a dynamic yield account");
20265
20284
  }
20266
20285
  if (params.apr !== void 0) {
20267
20286
  assertValidApr(params.apr);
20268
20287
  }
20269
- return await yieldApiReq(
20270
- "accounts/new",
20271
- "POST",
20272
- {
20273
- name: params.name,
20274
- type: params.type,
20275
- apr: params.apr,
20276
- tag: params.tag,
20277
- password: params.password,
20278
- description: params.description
20279
- },
20280
- {
20281
- adminSecret: getAdminSecret(params.adminSecret)
20282
- }
20288
+ return unwrapData(
20289
+ await yieldApiReq(
20290
+ "accounts/new",
20291
+ "POST",
20292
+ {
20293
+ name: params.name,
20294
+ type: params.type,
20295
+ apr: params.apr,
20296
+ valuation_model: valuationModel,
20297
+ nav_config: params.navConfig,
20298
+ tag: params.tag,
20299
+ password: params.password,
20300
+ description: params.description
20301
+ },
20302
+ {
20303
+ adminSecret: getAdminSecret(params.adminSecret)
20304
+ }
20305
+ )
20283
20306
  );
20284
20307
  }
20285
20308
  async function getAccounts() {
20286
20309
  return unwrapData(await yieldApiReq("accounts", "GET"));
20287
20310
  }
20311
+ async function getAccount(accountName) {
20312
+ return unwrapData(
20313
+ await yieldApiReq(accountEndpoint(accountName), "GET")
20314
+ );
20315
+ }
20288
20316
  async function updateAccount(params) {
20317
+ if (params.valuationModel === "nav") {
20318
+ if (!params.navConfig) {
20319
+ throw new Error("navConfig is required when switching to a NAV account");
20320
+ }
20321
+ if (params.apr !== void 0) {
20322
+ throw new Error("NAV accounts cannot define apr");
20323
+ }
20324
+ }
20289
20325
  if (params.apr !== void 0) {
20290
20326
  assertValidApr(params.apr);
20291
20327
  }
@@ -20306,7 +20342,9 @@ async function updateAccount(params) {
20306
20342
  type: params.type,
20307
20343
  apr: params.apr,
20308
20344
  tag: params.tag,
20309
- description: params.description
20345
+ description: params.description,
20346
+ valuation_model: params.valuationModel,
20347
+ nav_config: params.navConfig
20310
20348
  },
20311
20349
  auth.options
20312
20350
  )
@@ -20346,28 +20384,51 @@ async function updateDynamicApr(params) {
20346
20384
  );
20347
20385
  }
20348
20386
  async function addCashflowUpdate(params) {
20349
- if (params.fundingNextDay) {
20350
- params.date = roundToNextUtcMidnight(params.date);
20351
- }
20352
- return await yieldApiReq(
20353
- accountEndpoint(params.accountName, "cashflows"),
20354
- "POST",
20355
- {
20356
- amount: params.cashflowType === "deposit" ? params.amount : params.amount * -1,
20357
- timestamp: params.date ? dateToStr(params.date) : void 0,
20358
- description: params.description,
20359
- password: params.password
20387
+ const runtimeParams = params;
20388
+ if (params.valuationModel === "nav") {
20389
+ if (runtimeParams.date !== void 0 || runtimeParams.fundingNextDay !== void 0) {
20390
+ throw new Error(
20391
+ "NAV cashflows execute immediately and cannot specify date or fundingNextDay"
20392
+ );
20393
+ }
20394
+ if (!Number.isSafeInteger(params.amount)) {
20395
+ throw new Error(
20396
+ "NAV cashflow amount must be an integer number of base units"
20397
+ );
20360
20398
  }
20399
+ }
20400
+ const effectiveDate = params.valuationModel === "nav" ? void 0 : params.fundingNextDay ? roundToNextUtcMidnight(params.date ?? /* @__PURE__ */ new Date()) : params.date;
20401
+ return unwrapData(
20402
+ await yieldApiReq(
20403
+ accountEndpoint(params.accountName, "cashflows"),
20404
+ "POST",
20405
+ {
20406
+ amount: params.cashflowType === "deposit" ? Math.abs(params.amount) : -Math.abs(params.amount),
20407
+ timestamp: params.valuationModel === "nav" || !effectiveDate ? void 0 : dateToStr(effectiveDate),
20408
+ description: params.description,
20409
+ password: params.password
20410
+ }
20411
+ )
20361
20412
  );
20362
20413
  }
20363
20414
  async function getCashflows(accountName) {
20364
- return (await yieldApiReq(accountEndpoint(accountName, "cashflows"), "GET")).data;
20415
+ return unwrapData(
20416
+ await yieldApiReq(accountEndpoint(accountName, "cashflows"), "GET")
20417
+ );
20418
+ }
20419
+ function isNavAccountBalance(response) {
20420
+ return response.valuation_model === "nav";
20365
20421
  }
20366
20422
  async function getBalance(accountName, atTime) {
20367
- return (await yieldApiReq(
20368
- accountEndpoint(accountName, "balance") + (atTime ? `?as_of=${dateToStr(atTime)}` : ""),
20369
- "GET"
20370
- )).data;
20423
+ return unwrapData(
20424
+ await yieldApiReq(
20425
+ accountEndpoint(accountName, "balance") + (atTime ? `?as_of=${dateToStr(atTime)}` : ""),
20426
+ "GET"
20427
+ )
20428
+ );
20429
+ }
20430
+ function isNavAccountValue(response) {
20431
+ return response.valuation_model === "nav";
20371
20432
  }
20372
20433
  async function createYieldPayment(params) {
20373
20434
  return unwrapData(
@@ -20404,15 +20465,63 @@ async function getYieldPayments(accountName) {
20404
20465
  );
20405
20466
  }
20406
20467
  async function getYield(accountName, start, end) {
20407
- return (await yieldApiReq(
20408
- accountEndpoint(accountName, "yield") + (start ? `?start=${dateToStr(start)}` : "") + (start && end ? `&end=${dateToStr(end)}` : end ? `?end=${dateToStr(end)}` : ""),
20409
- "GET"
20410
- )).data;
20468
+ return unwrapData(
20469
+ await yieldApiReq(
20470
+ accountEndpoint(accountName, "yield") + (start ? `?start=${dateToStr(start)}` : "") + (start && end ? `&end=${dateToStr(end)}` : end ? `?end=${dateToStr(end)}` : ""),
20471
+ "GET"
20472
+ )
20473
+ );
20474
+ }
20475
+ async function getAprYield(accountName, start, end) {
20476
+ const response = await getYield(accountName, start, end);
20477
+ if (isNavAccountValue(response)) {
20478
+ throw new Error(`Account "${accountName}" uses NAV valuation, not APR`);
20479
+ }
20480
+ return response;
20481
+ }
20482
+ async function getNavValue(accountName) {
20483
+ const response = await getYield(accountName);
20484
+ if (!isNavAccountValue(response)) {
20485
+ throw new Error(`Account "${accountName}" uses APR valuation, not NAV`);
20486
+ }
20487
+ return response;
20488
+ }
20489
+ function trackedValueFromResponse(response) {
20490
+ if (isNavAccountValue(response)) {
20491
+ const totalValue2 = Number(response.total_nav);
20492
+ if (!Number.isFinite(totalValue2) || totalValue2 < 0) {
20493
+ throw new Error("NAV account returned an invalid total_nav");
20494
+ }
20495
+ return {
20496
+ totalValue: totalValue2,
20497
+ principal: 0,
20498
+ outstandingYield: 0,
20499
+ valuationModel: "nav"
20500
+ };
20501
+ }
20502
+ const totalValue = response.principal_at_end + response.outstanding_yield;
20503
+ if (!Number.isFinite(totalValue)) {
20504
+ throw new Error("APR account returned an invalid tracked value");
20505
+ }
20506
+ return {
20507
+ totalValue,
20508
+ principal: response.principal_at_end,
20509
+ outstandingYield: response.outstanding_yield,
20510
+ valuationModel: "apr"
20511
+ };
20512
+ }
20513
+ async function getTrackedValue(accountName) {
20514
+ return trackedValueFromResponse(await getYield(accountName));
20411
20515
  }
20412
20516
  async function getTotalYield(accountNames, start, end) {
20413
20517
  let totalYield = new import_core20.BN(0);
20414
20518
  for (const accountName of accountNames) {
20415
20519
  const res = await getYield(accountName, start, end);
20520
+ if (isNavAccountValue(res)) {
20521
+ throw new Error(
20522
+ `NAV account "${accountName}" does not report accrued yield`
20523
+ );
20524
+ }
20416
20525
  console.log(res);
20417
20526
  totalYield = totalYield.add(new import_core20.BN(res.total_yield));
20418
20527
  }
@@ -20422,10 +20531,28 @@ async function getTotalOutstandingYield(accountNames, start, end) {
20422
20531
  let total = 0;
20423
20532
  for (const accountName of accountNames) {
20424
20533
  const response = await getYield(accountName, start, end);
20534
+ if (isNavAccountValue(response)) {
20535
+ throw new Error(
20536
+ `NAV account "${accountName}" does not report outstanding yield`
20537
+ );
20538
+ }
20425
20539
  total += response.outstanding_yield;
20426
20540
  }
20427
20541
  return total;
20428
20542
  }
20543
+ async function getTotalTrackedValue(accountNames, start, end) {
20544
+ let totalValue = 0;
20545
+ let principal = 0;
20546
+ let outstandingYield = 0;
20547
+ for (const accountName of accountNames) {
20548
+ const response = await getYield(accountName, start, end);
20549
+ const tracked = trackedValueFromResponse(response);
20550
+ totalValue += tracked.totalValue;
20551
+ principal += tracked.principal;
20552
+ outstandingYield += tracked.outstandingYield;
20553
+ }
20554
+ return { totalValue, principal, outstandingYield };
20555
+ }
20429
20556
 
20430
20557
  // src/services/withdrawalQueueService.ts
20431
20558
  var import_common40 = __toESM(require_dist());
@@ -20987,6 +21114,7 @@ function evaluateBalanceChanges(vaultState, updates, thresholdBps, nowSecs) {
20987
21114
  walletAmount: update.walletAmount,
20988
21115
  lpAmount: update.lpAmount,
20989
21116
  trackedPrincipalAmount: update.trackedPrincipalAmount,
21117
+ trackedValueAmount: update.trackedValueAmount,
20990
21118
  yieldAmount: update.yieldAmount
20991
21119
  };
20992
21120
  const lastUpdateTs = toBigInt2(holding.lastUpdateTs);
@@ -21051,6 +21179,9 @@ function assertNoLargeBalanceChanges(vault, vaultState, updates, nowSecs, log =
21051
21179
  )} lp=${formatTokenAmount(
21052
21180
  violation.lpAmount,
21053
21181
  violation.decimals
21182
+ )} tracked=${formatTokenAmount(
21183
+ violation.trackedValueAmount,
21184
+ violation.decimals
21054
21185
  )} principal=${formatTokenAmount(
21055
21186
  violation.trackedPrincipalAmount,
21056
21187
  violation.decimals
@@ -22202,7 +22333,7 @@ async function buildHoldingUpdate(yieldTracker, entry, inputs) {
22202
22333
  }
22203
22334
  const walletAmount = inputs.walletBalances[mintKey] ?? 0n;
22204
22335
  const lpAmount = inputs.lpByMint.get(mintKey) ?? 0n;
22205
- const { principalAmount, yieldAmount } = await resolveTrackedAmounts(
22336
+ const { trackedValueAmount, principalAmount, yieldAmount } = await resolveTrackedAmounts(
22206
22337
  yieldTracker,
22207
22338
  inputs.configByMint.get(mintKey),
22208
22339
  holding.decimals
@@ -22217,17 +22348,36 @@ async function buildHoldingUpdate(yieldTracker, entry, inputs) {
22217
22348
  lpAmount,
22218
22349
  yieldAmount,
22219
22350
  trackedPrincipalAmount: principalAmount,
22220
- externalAmount: walletAmount + lpAmount + principalAmount + yieldAmount
22351
+ trackedValueAmount,
22352
+ externalAmount: walletAmount + lpAmount + trackedValueAmount
22221
22353
  };
22222
22354
  }
22223
22355
  async function resolveTrackedAmounts(yieldTracker, cfg, decimals) {
22224
22356
  if (!yieldTracker || !cfg?.yieldAccountNames?.length) {
22225
- return { principalAmount: 0n, yieldAmount: 0n };
22357
+ return {
22358
+ trackedValueAmount: 0n,
22359
+ principalAmount: 0n,
22360
+ yieldAmount: 0n
22361
+ };
22362
+ }
22363
+ let tracked;
22364
+ if (yieldTracker.getTotalTrackedValue) {
22365
+ tracked = await yieldTracker.getTotalTrackedValue(cfg.yieldAccountNames);
22366
+ } else if (yieldTracker.getTotalTrackedAmounts) {
22367
+ const legacy = await yieldTracker.getTotalTrackedAmounts(
22368
+ cfg.yieldAccountNames
22369
+ );
22370
+ tracked = {
22371
+ totalValue: legacy.principal + legacy.outstandingYield,
22372
+ ...legacy
22373
+ };
22374
+ } else {
22375
+ throw new Error(
22376
+ "yield tracker does not implement getTotalTrackedValue or its legacy fallback"
22377
+ );
22226
22378
  }
22227
- const tracked = await yieldTracker.getTotalTrackedAmounts(
22228
- cfg.yieldAccountNames
22229
- );
22230
22379
  return {
22380
+ trackedValueAmount: tracked.totalValue > 0 ? (0, import_common44.fromUiAmount)(tracked.totalValue, decimals) : 0n,
22231
22381
  principalAmount: tracked.principal > 0 ? (0, import_common44.fromUiAmount)(tracked.principal, decimals) : 0n,
22232
22382
  yieldAmount: tracked.outstandingYield > 0 ? (0, import_common44.fromUiAmount)(tracked.outstandingYield, decimals) : 0n
22233
22383
  };
@@ -22506,7 +22656,7 @@ async function settleVault2({
22506
22656
  log(`vault ${vault}: submitting ${updates.length} consensus asset update(s)`);
22507
22657
  for (const update of updates) {
22508
22658
  log(
22509
- ` holding #${update.holdingIndex} ${update.mint}: price=${update.price} external_amount=${update.externalAmount} [wallet=${update.walletAmount} lp=${update.lpAmount} principal=${update.trackedPrincipalAmount} yield=${update.yieldAmount}]`
22659
+ ` holding #${update.holdingIndex} ${update.mint}: price=${update.price} external_amount=${update.externalAmount} [wallet=${update.walletAmount} lp=${update.lpAmount} tracked=${update.trackedValueAmount} principal=${update.trackedPrincipalAmount} yield=${update.yieldAmount}]`
22510
22660
  );
22511
22661
  }
22512
22662
  await logProspectiveApy({
@@ -22943,7 +23093,7 @@ var MockYieldTracker = class {
22943
23093
  }
22944
23094
  return total;
22945
23095
  }
22946
- async getTotalTrackedAmounts(accountNames, start, end) {
23096
+ async getTotalTrackedValue(accountNames, start, end) {
22947
23097
  let principal = 0;
22948
23098
  let outstandingYield = 0;
22949
23099
  for (const name of accountNames) {
@@ -22951,7 +23101,19 @@ var MockYieldTracker = class {
22951
23101
  principal += snapshot2.principalAtEnd;
22952
23102
  outstandingYield += snapshot2.outstandingYield;
22953
23103
  }
22954
- return { principal, outstandingYield };
23104
+ return {
23105
+ totalValue: principal + outstandingYield,
23106
+ principal,
23107
+ outstandingYield
23108
+ };
23109
+ }
23110
+ /** Backward-compatible APR-only breakdown. */
23111
+ async getTotalTrackedAmounts(accountNames, start, end) {
23112
+ const tracked = await this.getTotalTrackedValue(accountNames, start, end);
23113
+ return {
23114
+ principal: tracked.principal,
23115
+ outstandingYield: tracked.outstandingYield
23116
+ };
22955
23117
  }
22956
23118
  async getBalance(accountName, atTime) {
22957
23119
  const snapshot2 = await this.getYield(accountName, void 0, atTime);
@@ -23041,17 +23203,12 @@ function createLiveConsensusOracleDeps(connection, opts = {}) {
23041
23203
  const raw = await getTotalOutstandingYield(accountNames, start, end);
23042
23204
  return raw / 10 ** YIELD_TRACKER_DECIMALS;
23043
23205
  },
23044
- async getTotalTrackedAmounts(accountNames, start, end) {
23045
- let principal = 0;
23046
- let outstandingYield = 0;
23047
- for (const accountName of accountNames) {
23048
- const snapshot2 = await getYield(accountName, start, end);
23049
- principal += snapshot2.principal_at_end;
23050
- outstandingYield += snapshot2.outstanding_yield;
23051
- }
23206
+ async getTotalTrackedValue(accountNames, start, end) {
23207
+ const tracked = await getTotalTrackedValue(accountNames, start, end);
23052
23208
  return {
23053
- principal: principal / 10 ** YIELD_TRACKER_DECIMALS,
23054
- outstandingYield: outstandingYield / 10 ** YIELD_TRACKER_DECIMALS
23209
+ totalValue: tracked.totalValue / 10 ** YIELD_TRACKER_DECIMALS,
23210
+ principal: tracked.principal / 10 ** YIELD_TRACKER_DECIMALS,
23211
+ outstandingYield: tracked.outstandingYield / 10 ** YIELD_TRACKER_DECIMALS
23055
23212
  };
23056
23213
  },
23057
23214
  getYieldPayments
@@ -24140,16 +24297,24 @@ var import_common53 = __toESM(require_dist());
24140
24297
  formatSettlementSimulation,
24141
24298
  fromUiAmount,
24142
24299
  gatherPricingInputs,
24300
+ getAccount,
24143
24301
  getAccounts,
24302
+ getAprYield,
24144
24303
  getBalance,
24145
24304
  getCashflows,
24305
+ getNavValue,
24146
24306
  getRpcUrl,
24147
24307
  getTotalOutstandingYield,
24308
+ getTotalTrackedValue,
24148
24309
  getTotalYield,
24310
+ getTrackedValue,
24149
24311
  getVaultProgramId,
24150
24312
  getYield,
24151
24313
  getYieldPayments,
24152
24314
  indexConfigByMint,
24315
+ isNavAccountBalance,
24316
+ isNavAccountValue,
24317
+ isNavYieldAccount,
24153
24318
  isVaultEnv,
24154
24319
  keypairAddress,
24155
24320
  loadKeypair,
@@ -24179,6 +24344,7 @@ var import_common53 = __toESM(require_dist());
24179
24344
  systemClock,
24180
24345
  toBigInt,
24181
24346
  toUiAmount,
24347
+ trackedValueFromResponse,
24182
24348
  updateAccount,
24183
24349
  updateDynamicApr,
24184
24350
  validateSquadsWalletRoutes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perena/vault-sdk",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
4
4
  "description": "Vault program helpers for Bankineco integrations.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",