@perena/vault-sdk 1.0.27 → 1.0.29

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.js CHANGED
@@ -150,7 +150,7 @@ var require_compat = __commonJS({
150
150
  exports2.toWeb3PublicKey = toWeb3PublicKey;
151
151
  exports2.asWeb3PublicKey = asWeb3PublicKey2;
152
152
  exports2.toKitInstruction = toKitInstruction30;
153
- exports2.fromKitInstruction = fromKitInstruction2;
153
+ exports2.fromKitInstruction = fromKitInstruction3;
154
154
  var kit_1 = require("@solana/kit");
155
155
  var web3_js_1 = require("@solana/web3.js");
156
156
  function fromWeb3PublicKey(pubkey) {
@@ -175,7 +175,7 @@ var require_compat = __commonJS({
175
175
  }))
176
176
  };
177
177
  }
178
- function fromKitInstruction2(ix) {
178
+ function fromKitInstruction3(ix) {
179
179
  return new web3_js_1.TransactionInstruction({
180
180
  programId: toWeb3PublicKey(ix.programAddress),
181
181
  keys: (ix.accounts ?? []).map((account) => ({
@@ -342,7 +342,7 @@ var require_refs = __commonJS({
342
342
  "use strict";
343
343
  Object.defineProperty(exports2, "__esModule", { value: true });
344
344
  exports2.createMultiCpiRefs = createMultiCpiRefs;
345
- exports2.createCpiRefs = createCpiRefs3;
345
+ exports2.createCpiRefs = createCpiRefs4;
346
346
  var kit_1 = require("@solana/kit");
347
347
  var roles_1 = require_roles();
348
348
  var accounts_1 = require_accounts();
@@ -478,7 +478,7 @@ var require_refs = __commonJS({
478
478
  lookupTables: collectLookupTables(allCpis)
479
479
  };
480
480
  }
481
- function createCpiRefs3(cpis, options) {
481
+ function createCpiRefs4(cpis, options) {
482
482
  const accountLists = toCpiAccountLists(cpis);
483
483
  const { pool, poolIndex } = buildPool(accountLists, options);
484
484
  const trackedIndices = resolveTrackedIndices(poolIndex, options?.trackAddresses);
@@ -592,11 +592,11 @@ var require_transaction = __commonJS({
592
592
  "../common/dist/utils/transaction.js"(exports2) {
593
593
  "use strict";
594
594
  Object.defineProperty(exports2, "__esModule", { value: true });
595
- exports2.fetchLookupTables = fetchLookupTables2;
595
+ exports2.fetchLookupTables = fetchLookupTables3;
596
596
  exports2.getSignatureStatus = getSignatureStatus;
597
597
  exports2.sendVersionedTransaction = sendVersionedTransaction;
598
598
  var web3_js_1 = require("@solana/web3.js");
599
- async function fetchLookupTables2(connection, lookupTables) {
599
+ async function fetchLookupTables3(connection, lookupTables) {
600
600
  const accounts2 = await Promise.all(lookupTables.map(async (lookupTable) => {
601
601
  const response = await connection.getAddressLookupTable(new web3_js_1.PublicKey(lookupTable));
602
602
  if (!response.value) {
@@ -613,7 +613,7 @@ var require_transaction = __commonJS({
613
613
  }
614
614
  async function sendVersionedTransaction({ connection, payer, instructions: instructions2, lookupTables }) {
615
615
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
616
- const lookupTableAccounts = await fetchLookupTables2(connection, lookupTables);
616
+ const lookupTableAccounts = await fetchLookupTables3(connection, lookupTables);
617
617
  const message2 = new web3_js_1.TransactionMessage({
618
618
  payerKey: payer.publicKey,
619
619
  recentBlockhash: blockhash,
@@ -2921,7 +2921,7 @@ var require_client = __commonJS({
2921
2921
  var extract_1 = require_extract();
2922
2922
  var routePreInstructions_1 = require_routePreInstructions();
2923
2923
  var constants_1 = require_constants4();
2924
- var JupiterSwapClient = class {
2924
+ var JupiterSwapClient2 = class {
2925
2925
  constructor(rpc, config = {}) {
2926
2926
  this.rpc = rpc;
2927
2927
  this.config = config;
@@ -3012,7 +3012,7 @@ var require_client = __commonJS({
3012
3012
  };
3013
3013
  }
3014
3014
  };
3015
- exports2.JupiterSwapClient = JupiterSwapClient;
3015
+ exports2.JupiterSwapClient = JupiterSwapClient2;
3016
3016
  }
3017
3017
  });
3018
3018
 
@@ -3232,6 +3232,7 @@ var require_dist4 = __commonJS({
3232
3232
  var index_exports = {};
3233
3233
  __export(index_exports, {
3234
3234
  ASSET_DECIMALS: () => ASSET_DECIMALS,
3235
+ ASSET_REBALANCE_COOLDOWN_SECS: () => ASSET_REBALANCE_COOLDOWN_SECS,
3235
3236
  AccountClient: () => AccountClient,
3236
3237
  ActivateCircuitBreakerBuilder: () => ActivateCircuitBreakerBuilder,
3237
3238
  CONSENSUS_ORACLE_VARIANT: () => CONSENSUS_ORACLE_VARIANT,
@@ -3242,15 +3243,20 @@ __export(index_exports, {
3242
3243
  CreateAssetHoldingBuilder: () => CreateAssetHoldingBuilder,
3243
3244
  CreateTrancheStateBuilder: () => CreateTrancheStateBuilder,
3244
3245
  CreateVaultBuilder: () => CreateVaultBuilder,
3246
+ DEFAULT_CU_PRICE_MICRO_LAMPORTS: () => DEFAULT_CU_PRICE_MICRO_LAMPORTS,
3245
3247
  DEFAULT_JUNIOR_EARLY_UNSTAKE_FEE_BPS: () => DEFAULT_JUNIOR_EARLY_UNSTAKE_FEE_BPS,
3246
3248
  DEFAULT_JUNIOR_STANDARD_UNSTAKE_FEE_BPS: () => DEFAULT_JUNIOR_STANDARD_UNSTAKE_FEE_BPS,
3247
3249
  DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS: () => DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS,
3248
3250
  DEFAULT_MAX_ACCEPTABLE_APY_BPS: () => DEFAULT_MAX_ACCEPTABLE_APY_BPS,
3251
+ DEFAULT_MAX_ACCOUNTS: () => DEFAULT_MAX_ACCOUNTS,
3249
3252
  DEFAULT_MIN_AMOUNT_UI: () => DEFAULT_MIN_AMOUNT_UI,
3250
3253
  DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS: () => DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS,
3251
3254
  DEFAULT_PRICE_ORACLE_ACCOUNT: () => DEFAULT_PRICE_ORACLE_ACCOUNT,
3252
3255
  DEFAULT_PRICE_STALENESS_SECS: () => DEFAULT_PRICE_STALENESS_SECS,
3253
3256
  DEFAULT_PRICE_STALENESS_THRESHOLD_SECS: () => DEFAULT_PRICE_STALENESS_THRESHOLD_SECS,
3257
+ DEFAULT_REBALANCE_BAND_BPS: () => DEFAULT_REBALANCE_BAND_BPS,
3258
+ DEFAULT_SLIPPAGE_BPS: () => DEFAULT_SLIPPAGE_BPS,
3259
+ DEFAULT_TARGET_LOCAL_BPS: () => DEFAULT_TARGET_LOCAL_BPS,
3254
3260
  DEFAULT_VAULT_ID: () => DEFAULT_VAULT_ID,
3255
3261
  DisableCircuitBreakerBuilder: () => DisableCircuitBreakerBuilder,
3256
3262
  EXTERNAL_POSITION_SAMPLES: () => EXTERNAL_POSITION_SAMPLES,
@@ -3264,6 +3270,9 @@ __export(index_exports, {
3264
3270
  FEE_VAULT_CACHE_CATEGORY: () => FEE_VAULT_CACHE_CATEGORY,
3265
3271
  FulfillJuniorTrancheWithdrawBuilder: () => FulfillJuniorTrancheWithdrawBuilder,
3266
3272
  IDL: () => IDL,
3273
+ IDLE_RESERVE_FLOOR_BPS: () => IDLE_RESERVE_FLOOR_BPS,
3274
+ IDLE_RESERVE_TARGET_BPS: () => IDLE_RESERVE_TARGET_BPS,
3275
+ IdleLiquidityService: () => IdleLiquidityService,
3267
3276
  InitializeVaultRolesBuilder: () => InitializeVaultRolesBuilder,
3268
3277
  JupiterBalanceSource: () => JupiterBalanceSource,
3269
3278
  JupiterPriceSource: () => JupiterPriceSource,
@@ -3377,6 +3386,7 @@ __export(index_exports, {
3377
3386
  mintTokensTo: () => mintTokensTo,
3378
3387
  mostFrequent: () => mostFrequent,
3379
3388
  parseExternalLiquidityRefs: () => parseExternalLiquidityRefs,
3389
+ planRebalance: () => planRebalance,
3380
3390
  prepareVaultTransaction: () => prepareVaultTransaction,
3381
3391
  priceInAccountingUnit: () => priceInAccountingUnit,
3382
3392
  readI64LE: () => readI64LE,
@@ -3469,13 +3479,13 @@ var import_path = __toESM(require("path"));
3469
3479
  var import_core18 = require("@anchor-lang/core");
3470
3480
  var import_web320 = require("@solana/web3.js");
3471
3481
  var import_kit10 = require("@solana/kit");
3472
- var import_common36 = __toESM(require_dist());
3482
+ var import_common37 = __toESM(require_dist());
3473
3483
 
3474
3484
  // src/client/client.ts
3475
3485
  var import_core17 = require("@anchor-lang/core");
3476
3486
  var import_kit9 = require("@solana/kit");
3477
3487
  var import_web319 = require("@solana/web3.js");
3478
- var import_common35 = __toESM(require_dist());
3488
+ var import_common36 = __toESM(require_dist());
3479
3489
 
3480
3490
  // src/idl/vault.ts
3481
3491
  var IDL = {
@@ -8162,66 +8172,6 @@ var IDL = {
8162
8172
  }
8163
8173
  }
8164
8174
  },
8165
- {
8166
- "name": "fee_collector"
8167
- },
8168
- {
8169
- "name": "fee_collector_output_ata",
8170
- "writable": true,
8171
- "pda": {
8172
- "seeds": [
8173
- {
8174
- "kind": "account",
8175
- "path": "fee_collector"
8176
- },
8177
- {
8178
- "kind": "account",
8179
- "path": "asset_token_program"
8180
- },
8181
- {
8182
- "kind": "account",
8183
- "path": "output_mint"
8184
- }
8185
- ],
8186
- "program": {
8187
- "kind": "const",
8188
- "value": [
8189
- 140,
8190
- 151,
8191
- 37,
8192
- 143,
8193
- 78,
8194
- 36,
8195
- 137,
8196
- 241,
8197
- 187,
8198
- 61,
8199
- 16,
8200
- 41,
8201
- 20,
8202
- 142,
8203
- 13,
8204
- 131,
8205
- 11,
8206
- 90,
8207
- 19,
8208
- 153,
8209
- 218,
8210
- 255,
8211
- 16,
8212
- 132,
8213
- 4,
8214
- 142,
8215
- 123,
8216
- 216,
8217
- 219,
8218
- 233,
8219
- 248,
8220
- 89
8221
- ]
8222
- }
8223
- }
8224
- },
8225
8175
  {
8226
8176
  "name": "queue_input_ata",
8227
8177
  "writable": true,
@@ -8294,7 +8244,24 @@ var IDL = {
8294
8244
  "address": "11111111111111111111111111111111"
8295
8245
  }
8296
8246
  ],
8297
- "args": []
8247
+ "args": [
8248
+ {
8249
+ "name": "external_withdraw_ix_refs",
8250
+ "type": {
8251
+ "option": {
8252
+ "defined": {
8253
+ "name": "InstructionRefs"
8254
+ }
8255
+ }
8256
+ }
8257
+ },
8258
+ {
8259
+ "name": "external_liquidity_source",
8260
+ "type": {
8261
+ "option": "u8"
8262
+ }
8263
+ }
8264
+ ]
8298
8265
  },
8299
8266
  {
8300
8267
  "name": "fulfill_junior_tranche_withdraw_fee_exempt",
@@ -8461,66 +8428,6 @@ var IDL = {
8461
8428
  }
8462
8429
  }
8463
8430
  },
8464
- {
8465
- "name": "fee_collector"
8466
- },
8467
- {
8468
- "name": "fee_collector_output_ata",
8469
- "writable": true,
8470
- "pda": {
8471
- "seeds": [
8472
- {
8473
- "kind": "account",
8474
- "path": "fee_collector"
8475
- },
8476
- {
8477
- "kind": "account",
8478
- "path": "asset_token_program"
8479
- },
8480
- {
8481
- "kind": "account",
8482
- "path": "output_mint"
8483
- }
8484
- ],
8485
- "program": {
8486
- "kind": "const",
8487
- "value": [
8488
- 140,
8489
- 151,
8490
- 37,
8491
- 143,
8492
- 78,
8493
- 36,
8494
- 137,
8495
- 241,
8496
- 187,
8497
- 61,
8498
- 16,
8499
- 41,
8500
- 20,
8501
- 142,
8502
- 13,
8503
- 131,
8504
- 11,
8505
- 90,
8506
- 19,
8507
- 153,
8508
- 218,
8509
- 255,
8510
- 16,
8511
- 132,
8512
- 4,
8513
- 142,
8514
- 123,
8515
- 216,
8516
- 219,
8517
- 233,
8518
- 248,
8519
- 89
8520
- ]
8521
- }
8522
- }
8523
- },
8524
8431
  {
8525
8432
  "name": "queue_input_ata",
8526
8433
  "writable": true,
@@ -8594,6 +8501,22 @@ var IDL = {
8594
8501
  }
8595
8502
  ],
8596
8503
  "args": [
8504
+ {
8505
+ "name": "external_withdraw_ix_refs",
8506
+ "type": {
8507
+ "option": {
8508
+ "defined": {
8509
+ "name": "InstructionRefs"
8510
+ }
8511
+ }
8512
+ }
8513
+ },
8514
+ {
8515
+ "name": "external_liquidity_source",
8516
+ "type": {
8517
+ "option": "u8"
8518
+ }
8519
+ },
8597
8520
  {
8598
8521
  "name": "signer_seeds",
8599
8522
  "type": {
@@ -12933,239 +12856,229 @@ var IDL = {
12933
12856
  ],
12934
12857
  "errors": [
12935
12858
  {
12936
- "code": 14001,
12937
- "name": "Unauthorized",
12938
- "msg": "You are not authorized to perform this action."
12939
- },
12940
- {
12941
- "code": 14002,
12942
- "name": "InvalidBankMint",
12943
- "msg": "Invalid mint"
12944
- },
12945
- {
12946
- "code": 14003,
12947
- "name": "AccountingIssue",
12948
- "msg": "Accounting issue"
12859
+ "code": 6e3,
12860
+ "name": "MintSupplyNonZero",
12861
+ "msg": "Supplied share mint already has non-zero supply"
12949
12862
  },
12950
12863
  {
12951
- "code": 14004,
12952
- "name": "VaultAccountingIssue",
12953
- "msg": "Vault accounting issue"
12864
+ "code": 6001,
12865
+ "name": "InvalidAssetMint",
12866
+ "msg": "Supplied mint is not accepted by this vault"
12954
12867
  },
12955
12868
  {
12956
- "code": 14005,
12957
- "name": "BankAccountingIssue",
12958
- "msg": "Bank accounting issue"
12869
+ "code": 6002,
12870
+ "name": "ZeroDepositAmount",
12871
+ "msg": "Deposit amount must be greater than zero"
12959
12872
  },
12960
12873
  {
12961
- "code": 14006,
12962
- "name": "OnchainAccountingIssue",
12963
- "msg": "Onchain accounting issue"
12874
+ "code": 6003,
12875
+ "name": "ExceedsTvlLimit",
12876
+ "msg": "Deposit would exceed the vault's TVL limit"
12964
12877
  },
12965
12878
  {
12966
- "code": 14007,
12967
- "name": "ExternalAccountingIssue",
12968
- "msg": "External accounting issue"
12879
+ "code": 6004,
12880
+ "name": "ZeroBurnAmount",
12881
+ "msg": "Burn amount must be greater than zero"
12969
12882
  },
12970
12883
  {
12971
- "code": 14008,
12972
- "name": "MintSlippage",
12973
- "msg": "Minting failed due to slippage."
12884
+ "code": 6005,
12885
+ "name": "ZeroAssetAmount",
12886
+ "msg": "Asset amount must be greater than zero"
12974
12887
  },
12975
12888
  {
12976
- "code": 14009,
12977
- "name": "BurningSlippage",
12978
- "msg": "Burning failed due to slippage."
12889
+ "code": 6006,
12890
+ "name": "InsufficientVaultLiquidity",
12891
+ "msg": "Insufficient vault liquidity to satisfy withdrawal"
12979
12892
  },
12980
12893
  {
12981
- "code": 14010,
12982
- "name": "TeamAccountAlreadyExists",
12983
- "msg": "Team account already exists"
12894
+ "code": 6007,
12895
+ "name": "MintAuthorityNotCurator",
12896
+ "msg": "Mint authority is not the curator"
12984
12897
  },
12985
12898
  {
12986
- "code": 14011,
12987
- "name": "OracleAccountAlreadyExists",
12988
- "msg": "Oracle account already exists"
12899
+ "code": 6008,
12900
+ "name": "ZeroTotalSupply",
12901
+ "msg": "Vault total supply is zero"
12989
12902
  },
12990
12903
  {
12991
- "code": 14012,
12904
+ "code": 6009,
12992
12905
  "name": "StaleOracle",
12993
- "msg": "Stale oracle"
12906
+ "msg": "Vault oracle is stale"
12994
12907
  },
12995
12908
  {
12996
- "code": 14013,
12997
- "name": "LocalSignificantPriceChange",
12998
- "msg": "Price change is too large locally"
12909
+ "code": 6010,
12910
+ "name": "InvalidOracleUpdate",
12911
+ "msg": "Invalid oracle update"
12999
12912
  },
13000
12913
  {
13001
- "code": 14014,
13002
- "name": "SignificantPriceChange",
13003
- "msg": "Price change is too large"
12914
+ "code": 6011,
12915
+ "name": "InvalidInitialMintSharePrice",
12916
+ "msg": "Initial mint share price must be greater than zero"
13004
12917
  },
13005
12918
  {
13006
- "code": 14015,
13007
- "name": "RoundingImpact",
13008
- "msg": "Rounding impacts the protocol"
12919
+ "code": 6012,
12920
+ "name": "MaxApyExceeded",
12921
+ "msg": "Oracle NAV update exceeds the vault's maximum acceptable APY"
13009
12922
  },
13010
12923
  {
13011
- "code": 14016,
13012
- "name": "BankIsHalted",
13013
- "msg": "Bank is halted"
12924
+ "code": 6013,
12925
+ "name": "InvalidApyConfig",
12926
+ "msg": "Invalid APY configuration"
13014
12927
  },
13015
12928
  {
13016
- "code": 14017,
13017
- "name": "VaultIsHalted",
13018
- "msg": "Vault is halted"
12929
+ "code": 6014,
12930
+ "name": "InvalidFeeConfig",
12931
+ "msg": "Invalid fee configuration"
13019
12932
  },
13020
12933
  {
13021
- "code": 14018,
13022
- "name": "ConversionOverflow",
13023
- "msg": "Conversion Overflow"
12934
+ "code": 6015,
12935
+ "name": "VaultHasLiveAssets",
12936
+ "msg": "Vault has live supply, TVL, or holdings"
13024
12937
  },
13025
12938
  {
13026
- "code": 14019,
13027
- "name": "_Reserved8019",
13028
- "msg": "Reserved"
12939
+ "code": 6016,
12940
+ "name": "DepositMintsZeroShares",
12941
+ "msg": "Deposit would mint zero shares"
13029
12942
  },
13030
12943
  {
13031
- "code": 14020,
13032
- "name": "InvalidArgument",
13033
- "msg": "Invalid argument"
12944
+ "code": 6017,
12945
+ "name": "InsufficientAccruedApyBalance",
12946
+ "msg": "Insufficient accrued APY balance"
13034
12947
  },
13035
12948
  {
13036
- "code": 14021,
13037
- "name": "UserSanityCheck",
13038
- "msg": "User Sanity Check"
12949
+ "code": 6018,
12950
+ "name": "InvalidRole",
12951
+ "msg": "Invalid role configuration"
13039
12952
  },
13040
12953
  {
13041
- "code": 14022,
13042
- "name": "MathOverflow",
13043
- "msg": "Math overflow"
12954
+ "code": 6019,
12955
+ "name": "InvalidProtocolInteraction",
12956
+ "msg": "Invalid protocol interaction CPI"
13044
12957
  },
13045
12958
  {
13046
- "code": 14023,
13047
- "name": "InvalidMarginFiAccount",
13048
- "msg": "Invalid MarginFi account - must be correct PDA for this vault"
12959
+ "code": 6020,
12960
+ "name": "_Reserved7020",
12961
+ "msg": "Reserved"
13049
12962
  },
13050
12963
  {
13051
- "code": 14024,
13052
- "name": "InvalidStartMarker",
13053
- "msg": "Invalid start marker"
12964
+ "code": 6021,
12965
+ "name": "InvalidExternalLiquidity",
12966
+ "msg": "Invalid external liquidity configuration"
13054
12967
  },
13055
12968
  {
13056
- "code": 14025,
13057
- "name": "OracleUpdateOnEmptyReserve",
13058
- "msg": "Unable to push oracle update on an empty vault reserve"
12969
+ "code": 6022,
12970
+ "name": "SwapBalanceUnchanged",
12971
+ "msg": "Swap did not change both source and destination balances"
13059
12972
  },
13060
12973
  {
13061
- "code": 14026,
13062
- "name": "InvalidRemainingAccountsLength",
13063
- "msg": "Invalid remaining accounts length"
12974
+ "code": 6023,
12975
+ "name": "ProtocolBalanceUnchanged",
12976
+ "msg": "Protocol interaction did not change the affected token balance"
13064
12977
  },
13065
12978
  {
13066
- "code": 14027,
13067
- "name": "WithdrawalExceedsBalance",
13068
- "msg": "Specified withdrawal exceeds available balance"
12979
+ "code": 6024,
12980
+ "name": "ExcessiveSwapSlippage",
12981
+ "msg": "Swap TVL loss exceeds the allowed slippage"
13069
12982
  },
13070
12983
  {
13071
- "code": 14028,
13072
- "name": "InsufficientPendingYield",
13073
- "msg": "Insufficient pending yield"
12984
+ "code": 6025,
12985
+ "name": "TranchingNotEnabled",
12986
+ "msg": "Vault tranching is not enabled"
13074
12987
  },
13075
12988
  {
13076
- "code": 14029,
13077
- "name": "NotSupported",
13078
- "msg": "Not supported"
12989
+ "code": 6026,
12990
+ "name": "TranchingAlreadyEnabled",
12991
+ "msg": "Vault tranching is already enabled"
13079
12992
  },
13080
12993
  {
13081
- "code": 14030,
13082
- "name": "ExceedsMaxYieldingTvl",
13083
- "msg": "Exceeds maximum yielding TVL"
12994
+ "code": 6027,
12995
+ "name": "TrancheStateRequired",
12996
+ "msg": "Tranche state account is required"
13084
12997
  },
13085
12998
  {
13086
- "code": 14031,
13087
- "name": "TranchingNotEnabled",
13088
- "msg": "Tranching is not enabled for this bank"
12999
+ "code": 6028,
13000
+ "name": "InvalidTrancheConfig",
13001
+ "msg": "Invalid tranche configuration"
13089
13002
  },
13090
13003
  {
13091
- "code": 14032,
13092
- "name": "InvalidLeverageFactor",
13093
- "msg": "Invalid leverage factor - must be at least 10000 (1x)"
13004
+ "code": 6029,
13005
+ "name": "InvalidTrancheMint",
13006
+ "msg": "Invalid tranche mint"
13094
13007
  },
13095
13008
  {
13096
- "code": 14033,
13097
- "name": "InsufficientStakedAmount",
13098
- "msg": "Insufficient staked amount"
13009
+ "code": 6030,
13010
+ "name": "LossesDisabled",
13011
+ "msg": "Vault losses are not enabled"
13099
13012
  },
13100
13013
  {
13101
- "code": 14034,
13102
- "name": "JuniorTrancheEmpty",
13103
- "msg": "Junior tranche has no value"
13014
+ "code": 6031,
13015
+ "name": "WithdrawalQueueNotExpired",
13016
+ "msg": "Withdrawal queue is not yet expired"
13104
13017
  },
13105
13018
  {
13106
- "code": 14035,
13107
- "name": "InvalidTrancheConfig",
13108
- "msg": "Invalid tranche config parameter"
13019
+ "code": 6032,
13020
+ "name": "InvalidWithdrawalQueue",
13021
+ "msg": "Invalid withdrawal queue"
13109
13022
  },
13110
13023
  {
13111
- "code": 14036,
13112
- "name": "WithdrawalQueueNotExpired",
13113
- "msg": "Withdrawal queue lockup period has not expired"
13024
+ "code": 6033,
13025
+ "name": "AssetPriceNotSet",
13026
+ "msg": "Destination asset has no price set; a consensus oracle price is required before swapping"
13114
13027
  },
13115
13028
  {
13116
- "code": 14037,
13117
- "name": "InvalidWithdrawalQueue",
13118
- "msg": "Withdrawal queue entry is not in a valid state"
13029
+ "code": 6034,
13030
+ "name": "AssetHoldingNotEmpty",
13031
+ "msg": "Asset holding still has a balance and cannot be removed"
13119
13032
  },
13120
13033
  {
13121
- "code": 14038,
13122
- "name": "InvalidAccount",
13123
- "msg": "Account does not belong to the expected parent"
13034
+ "code": 6035,
13035
+ "name": "CannotRemoveBaseHolding",
13036
+ "msg": "The base asset holding cannot be removed"
13124
13037
  },
13125
13038
  {
13126
- "code": 14039,
13127
- "name": "MissingAccount",
13128
- "msg": "Required optional account is missing"
13039
+ "code": 6036,
13040
+ "name": "UnauthorizedPriceUpdater",
13041
+ "msg": "Caller is not authorized to trigger an asset price update"
13129
13042
  },
13130
13043
  {
13131
- "code": 14040,
13132
- "name": "TrancheWipedOut",
13133
- "msg": "Junior tranche is wiped out and cannot accept new stakes"
13044
+ "code": 6037,
13045
+ "name": "InvalidStalenessConfig",
13046
+ "msg": "Invalid asset-price staleness threshold"
13134
13047
  },
13135
13048
  {
13136
- "code": 14041,
13137
- "name": "VaultLossNotAccepted",
13138
- "msg": "Vault does not accept losses \u2014 enable losses_accepted before retrying"
13049
+ "code": 6038,
13050
+ "name": "AssetRebalanceRateLimitExceeded",
13051
+ "msg": "Asset was rebalanced too recently"
13139
13052
  },
13140
13053
  {
13141
- "code": 14042,
13142
- "name": "CapitalLossExceedsReserve",
13143
- "msg": "Capital loss exceeds available yielding reserve"
13054
+ "code": 6039,
13055
+ "name": "InvalidShareTokenProgram",
13056
+ "msg": "Share token program does not match the vault/tranche mint configuration"
13144
13057
  },
13145
13058
  {
13146
- "code": 14043,
13147
- "name": "RollingWithdrawalLimitExceeded",
13148
- "msg": "Rolling withdrawal limit exceeded"
13059
+ "code": 6040,
13060
+ "name": "UnauthorizedVaultCreator",
13061
+ "msg": "Caller is not on the vault-creator whitelist"
13149
13062
  },
13150
13063
  {
13151
- "code": 14044,
13152
- "name": "VaultAlreadyMigrated",
13153
- "msg": "Legacy vault has already been migrated"
13064
+ "code": 6041,
13065
+ "name": "InvalidShareMintDecimals",
13066
+ "msg": "Share mint decimals must match the vault accounting decimals"
13154
13067
  },
13155
13068
  {
13156
- "code": 14045,
13157
- "name": "InvalidMigrationState",
13158
- "msg": "Legacy vault migration is incomplete or invalid"
13069
+ "code": 6042,
13070
+ "name": "InvalidFeeExemption",
13071
+ "msg": "Invalid fee-exemption PDA signer or seeds"
13159
13072
  },
13160
13073
  {
13161
- "code": 14046,
13162
- "name": "InvalidMigrationMintAuthority",
13163
- "msg": "Mint authority does not match the expected migration source"
13074
+ "code": 6043,
13075
+ "name": "ExceedsJuniorDepositCap",
13076
+ "msg": "Deposit would exceed the junior tranche deposit cap"
13164
13077
  },
13165
13078
  {
13166
- "code": 14047,
13167
- "name": "BankMigrationIncomplete",
13168
- "msg": "Legacy bank or tranche migration is incomplete \u2014 source accounting and escrow must be fully drained before mint authority transfer"
13079
+ "code": 6044,
13080
+ "name": "InvalidShareSupply",
13081
+ "msg": "Physical share-mint supply does not match effective supply accounting"
13169
13082
  }
13170
13083
  ],
13171
13084
  "types": [
@@ -13546,9 +13459,7 @@ var IDL = {
13546
13459
  "Holdings are addressed by their slot index (1 byte) to keep instruction data",
13547
13460
  "small. To register a brand-new consensus holding, set `mint` to its mint",
13548
13461
  "(and pass the matching `asset_mint` account); the created slot's index is used",
13549
- "and `holding_index` is ignored. For existing holdings leave `mint` as `None`.",
13550
- "The price is authoritative only for ConsensusOracle holdings. Pyth and nested-vault",
13551
- "holdings use the report only for external_amount and retain their live-oracle price."
13462
+ "and `holding_index` is ignored. For existing holdings leave `mint` as `None`."
13552
13463
  ],
13553
13464
  "type": {
13554
13465
  "kind": "struct",
@@ -14425,6 +14336,106 @@ var IDL = {
14425
14336
  ]
14426
14337
  }
14427
14338
  },
14339
+ {
14340
+ "name": "RollingRebalanceLimit",
14341
+ "docs": [
14342
+ "Rolling-window cap on rebalance (Jupiter swap) throughput, expressed as a",
14343
+ "share of current TVL rather than a fixed amount.",
14344
+ "",
14345
+ "Sibling of [`super::withdrawal_limits::RollingWithdrawalLimit`]: same",
14346
+ "window-slide-then-charge mechanics, but the ceiling is recomputed from live",
14347
+ "TVL on every call, so the cap tracks the vault as it grows or shrinks",
14348
+ "instead of going stale at whatever amount the curator last set.",
14349
+ "",
14350
+ "Both swap directions charge the same window \u2014 the cap bounds total value",
14351
+ "routed through Jupiter per window, regardless of which asset is sold."
14352
+ ],
14353
+ "serialization": "bytemuck",
14354
+ "repr": {
14355
+ "kind": "c"
14356
+ },
14357
+ "type": {
14358
+ "kind": "struct",
14359
+ "fields": [
14360
+ {
14361
+ "name": "window_start_ts",
14362
+ "docs": [
14363
+ "Unix timestamp the current window opened."
14364
+ ],
14365
+ "type": "i64"
14366
+ },
14367
+ {
14368
+ "name": "window_duration_seconds",
14369
+ "docs": [
14370
+ "Window length, in seconds (e.g. 3_600 for an hourly limit)."
14371
+ ],
14372
+ "type": "u64"
14373
+ },
14374
+ {
14375
+ "name": "value_in_window",
14376
+ "docs": [
14377
+ "Value rebalanced inside the current window, in the vault's accounting",
14378
+ "unit."
14379
+ ],
14380
+ "type": "u64"
14381
+ },
14382
+ {
14383
+ "name": "window_limit_bps",
14384
+ "docs": [
14385
+ "Cap as a share of TVL, in bps. `0` disables the limit."
14386
+ ],
14387
+ "type": "u16"
14388
+ },
14389
+ {
14390
+ "name": "_padding1",
14391
+ "type": {
14392
+ "array": [
14393
+ "u8",
14394
+ 6
14395
+ ]
14396
+ }
14397
+ },
14398
+ {
14399
+ "name": "_padding2",
14400
+ "type": {
14401
+ "array": [
14402
+ "u64",
14403
+ 4
14404
+ ]
14405
+ }
14406
+ }
14407
+ ]
14408
+ }
14409
+ },
14410
+ {
14411
+ "name": "RollingRebalanceLimitConfig",
14412
+ "docs": [
14413
+ "Rolling rebalance-limit config applied via [`SetVaultConfigArgs`].",
14414
+ "",
14415
+ "The cap is a share of TVL rather than a fixed amount, so it stays",
14416
+ "meaningful as the vault grows. Both fields must be zero (disable the cap)",
14417
+ "or both non-zero (enable it)."
14418
+ ],
14419
+ "type": {
14420
+ "kind": "struct",
14421
+ "fields": [
14422
+ {
14423
+ "name": "window_limit_bps",
14424
+ "docs": [
14425
+ "Max share of TVL rebalanced inside one window, in bps (`0` disables)."
14426
+ ],
14427
+ "type": "u16"
14428
+ },
14429
+ {
14430
+ "name": "window_duration_seconds",
14431
+ "docs": [
14432
+ "Window length in seconds (`0` only valid when `window_limit_bps` is `0`)."
14433
+ ],
14434
+ "type": "u64"
14435
+ }
14436
+ ]
14437
+ }
14438
+ },
14428
14439
  {
14429
14440
  "name": "SetAssetPriceOracleArgs",
14430
14441
  "type": {
@@ -14610,13 +14621,27 @@ var IDL = {
14610
14621
  }
14611
14622
  }
14612
14623
  }
14613
- }
14614
- ]
14615
- }
14616
- },
14617
- {
14618
- "name": "TeamAccounting",
14619
- "serialization": "bytemuck",
14624
+ },
14625
+ {
14626
+ "name": "rebalance_limit",
14627
+ "docs": [
14628
+ "Rolling cap on rebalance (Jupiter swap) throughput. `None` leaves",
14629
+ "unchanged."
14630
+ ],
14631
+ "type": {
14632
+ "option": {
14633
+ "defined": {
14634
+ "name": "RollingRebalanceLimitConfig"
14635
+ }
14636
+ }
14637
+ }
14638
+ }
14639
+ ]
14640
+ }
14641
+ },
14642
+ {
14643
+ "name": "TeamAccounting",
14644
+ "serialization": "bytemuck",
14620
14645
  "repr": {
14621
14646
  "kind": "c"
14622
14647
  },
@@ -15293,7 +15318,8 @@ var IDL = {
15293
15318
  {
15294
15319
  "name": "losses_enabled",
15295
15320
  "docs": [
15296
- "Allows consensus-oracle NAV losses beyond the protocol's small-loss tolerance. Losses inside that tolerance settle without this flag."
15321
+ "Allows consensus-oracle NAV losses beyond the protocol's small-loss",
15322
+ "tolerance. Losses inside that tolerance settle without this flag."
15297
15323
  ],
15298
15324
  "type": {
15299
15325
  "defined": {
@@ -15530,6 +15556,14 @@ var IDL = {
15530
15556
  "name": "senior_fixed_apy_bps",
15531
15557
  "type": "u16"
15532
15558
  },
15559
+ {
15560
+ "name": "junior_floor_apy_bps",
15561
+ "docs": [
15562
+ "Floor APY for the junior tranche, in basis points. Zero disables the",
15563
+ "floor. Shortfalls are funded from the untranched sleeve, never senior."
15564
+ ],
15565
+ "type": "u16"
15566
+ },
15533
15567
  {
15534
15568
  "name": "early_unstake_fee_bps",
15535
15569
  "type": "u16"
@@ -16355,12 +16389,38 @@ var IDL = {
16355
16389
  ],
16356
16390
  "type": "u64"
16357
16391
  },
16392
+ {
16393
+ "name": "junior_floor_apy_bps",
16394
+ "docs": [
16395
+ "Curator-set floor APY for the junior tranche, in basis points. Zero",
16396
+ "disables the floor.",
16397
+ "",
16398
+ "When junior's realized growth falls short of this floor, the shortfall is",
16399
+ "topped up from the *untranched* (regular) sleeve's value, never from the",
16400
+ "senior tranche -- senior's fixed-APY entitlement is settled first and is",
16401
+ "untouched by the floor. The top-up is best-effort: it is capped by the",
16402
+ "untranched sleeve's available value, and any unpaid remainder stays",
16403
+ "outstanding against the durable junior anchor",
16404
+ "(`VaultTrancheState::junior_apy_anchor_share_price`) so it can be paid on",
16405
+ "a later settlement."
16406
+ ],
16407
+ "type": "u16"
16408
+ },
16409
+ {
16410
+ "name": "_padding1",
16411
+ "type": {
16412
+ "array": [
16413
+ "u8",
16414
+ 6
16415
+ ]
16416
+ }
16417
+ },
16358
16418
  {
16359
16419
  "name": "_padding2",
16360
16420
  "type": {
16361
16421
  "array": [
16362
16422
  "u64",
16363
- 13
16423
+ 12
16364
16424
  ]
16365
16425
  }
16366
16426
  }
@@ -16438,12 +16498,28 @@ var IDL = {
16438
16498
  ],
16439
16499
  "type": "i64"
16440
16500
  },
16501
+ {
16502
+ "name": "junior_apy_anchor_share_price",
16503
+ "docs": [
16504
+ "Junior share price at the start of the current floor-APY regime. The",
16505
+ "anchor is durable across settlements so an unpaid floor shortfall stays",
16506
+ "outstanding and can be caught up later."
16507
+ ],
16508
+ "type": "u64"
16509
+ },
16510
+ {
16511
+ "name": "junior_apy_anchor_ts",
16512
+ "docs": [
16513
+ "Unix timestamp when the junior floor-APY anchor was set."
16514
+ ],
16515
+ "type": "i64"
16516
+ },
16441
16517
  {
16442
16518
  "name": "_padding2",
16443
16519
  "type": {
16444
16520
  "array": [
16445
16521
  "u64",
16446
- 29
16522
+ 27
16447
16523
  ]
16448
16524
  }
16449
16525
  }
@@ -16461,6 +16537,17 @@ var IDL = {
16461
16537
  "option": "u16"
16462
16538
  }
16463
16539
  },
16540
+ {
16541
+ "name": "junior_floor_apy_bps",
16542
+ "docs": [
16543
+ "Floor APY for the junior tranche, in basis points. Zero disables the",
16544
+ "floor. Setting this starts a fresh regime: any shortfall accrued under",
16545
+ "the previous value is forfeited."
16546
+ ],
16547
+ "type": {
16548
+ "option": "u16"
16549
+ }
16550
+ },
16464
16551
  {
16465
16552
  "name": "early_unstake_fee_bps",
16466
16553
  "type": {
@@ -16743,12 +16830,25 @@ var IDL = {
16743
16830
  ],
16744
16831
  "type": "u64"
16745
16832
  },
16833
+ {
16834
+ "name": "rebalance_limit",
16835
+ "docs": [
16836
+ "Rolling cap on rebalance (Jupiter swap) throughput per window, as a",
16837
+ "share of TVL. Carved out of `_padding1`, so the account layout and size",
16838
+ "are unchanged and existing vaults decode it as disabled."
16839
+ ],
16840
+ "type": {
16841
+ "defined": {
16842
+ "name": "RollingRebalanceLimit"
16843
+ }
16844
+ }
16845
+ },
16746
16846
  {
16747
16847
  "name": "_padding1",
16748
16848
  "type": {
16749
16849
  "array": [
16750
16850
  "u64",
16751
- 30
16851
+ 22
16752
16852
  ]
16753
16853
  }
16754
16854
  },
@@ -17887,6 +17987,7 @@ var CreateTrancheStateBuilder = class extends VaultBuilderBase {
17887
17987
  async getIx(args) {
17888
17988
  return this.program.methods.vaultCreateTrancheState({
17889
17989
  seniorFixedApyBps: args.seniorFixedApyBps,
17990
+ juniorFloorApyBps: args.juniorFloorApyBps,
17890
17991
  earlyUnstakeFeeBps: args.earlyUnstakeFeeBps,
17891
17992
  standardUnstakeFeeBps: args.standardUnstakeFeeBps,
17892
17993
  targetLockupDurationSecs: args.targetLockupDurationSecs,
@@ -17930,6 +18031,7 @@ var CreateTrancheStateBuilder = class extends VaultBuilderBase {
17930
18031
  seniorShareMint: txArgs.seniorShareMint,
17931
18032
  vaultOracle,
17932
18033
  seniorFixedApyBps: txArgs.seniorFixedApyBps ?? 0,
18034
+ juniorFloorApyBps: txArgs.juniorFloorApyBps ?? 0,
17933
18035
  earlyUnstakeFeeBps: txArgs.earlyUnstakeFeeBps ?? DEFAULT_JUNIOR_EARLY_UNSTAKE_FEE_BPS,
17934
18036
  standardUnstakeFeeBps: txArgs.standardUnstakeFeeBps ?? DEFAULT_JUNIOR_STANDARD_UNSTAKE_FEE_BPS,
17935
18037
  targetLockupDurationSecs: new import_core.BN(
@@ -18005,7 +18107,8 @@ function toAnchorSetVaultConfigArgs(args) {
18005
18107
  lossesEnabled: args.lossesEnabled,
18006
18108
  priceStalenessThresholdSecs: args.priceStalenessThresholdSecs,
18007
18109
  userBurnLimit: args.userBurnLimit,
18008
- managerPullLimit: args.managerPullLimit
18110
+ managerPullLimit: args.managerPullLimit,
18111
+ rebalanceLimit: args.rebalanceLimit
18009
18112
  };
18010
18113
  }
18011
18114
  function toAnchorConsensusUpdates(updates) {
@@ -18213,6 +18316,12 @@ var SetVaultConfigBuilder = class extends VaultBuilderBase {
18213
18316
  windowDurationSeconds: new import_core4.BN(
18214
18317
  txArgs.managerPullLimit.windowDurationSeconds.toString()
18215
18318
  )
18319
+ } : null,
18320
+ rebalanceLimit: txArgs.rebalanceLimit !== void 0 ? {
18321
+ windowLimitBps: txArgs.rebalanceLimit.windowLimitBps,
18322
+ windowDurationSeconds: new import_core4.BN(
18323
+ txArgs.rebalanceLimit.windowDurationSeconds.toString()
18324
+ )
18216
18325
  } : null
18217
18326
  }
18218
18327
  };
@@ -18466,10 +18575,13 @@ var CrankPerformanceFeesBuilder = class extends VaultBuilderBase {
18466
18575
  vault: txArgs.vault,
18467
18576
  shareMint,
18468
18577
  feeCollector,
18578
+ // The vault fee collector is a role that is routinely a Squads vault
18579
+ // (off-curve PDA), so allow an off-curve owner here too.
18469
18580
  feeCollectorShareAta: (0, import_common18.getAtaAddress)(
18470
18581
  shareMint,
18471
18582
  feeCollector,
18472
- shareTokenProgram
18583
+ shareTokenProgram,
18584
+ true
18473
18585
  ),
18474
18586
  protocolFeeCollector,
18475
18587
  // The protocol fee recipient is a hardcoded protocol-controlled address
@@ -19195,8 +19307,11 @@ var ExecuteTrancheWithdrawBuilder = class extends VaultBuilderBase {
19195
19307
 
19196
19308
  // src/client/builders/executeWithdraw.ts
19197
19309
  var import_core10 = require("@anchor-lang/core");
19198
- var import_kit7 = require("@solana/kit");
19199
19310
  var import_spl_token11 = require("@solana/spl-token");
19311
+ var import_common28 = __toESM(require_dist());
19312
+
19313
+ // src/client/builders/externalLiquidity.ts
19314
+ var import_kit7 = require("@solana/kit");
19200
19315
  var import_web312 = require("@solana/web3.js");
19201
19316
  var import_common27 = __toESM(require_dist());
19202
19317
  var import_marginfi = __toESM(require_dist2());
@@ -19215,22 +19330,71 @@ function toWeb3AccountMeta(account) {
19215
19330
  isSigner: account.role === import_kit7.AccountRole.READONLY_SIGNER || account.role === import_kit7.AccountRole.WRITABLE_SIGNER
19216
19331
  };
19217
19332
  }
19333
+ function resolveExternalWithdraw({
19334
+ externalLiquidity,
19335
+ vault,
19336
+ assetMint,
19337
+ vaultAssetAta,
19338
+ overrides
19339
+ }) {
19340
+ const externalWithdrawIxRefs = overrides?.externalWithdrawIxRefs ?? null;
19341
+ const externalLiquiditySource = overrides?.externalLiquiditySource ?? null;
19342
+ const externalWithdrawAccounts = overrides?.externalWithdrawAccounts ?? [];
19343
+ if (externalWithdrawIxRefs != null || externalLiquiditySource != null || overrides?.skipExternalLiquidity) {
19344
+ return {
19345
+ externalWithdrawIxRefs,
19346
+ externalLiquiditySource,
19347
+ externalWithdrawAccounts
19348
+ };
19349
+ }
19350
+ const slot0 = parseMarginfiSlot(externalLiquidity[0]);
19351
+ if (!slot0) {
19352
+ return {
19353
+ externalWithdrawIxRefs: null,
19354
+ externalLiquiditySource: null,
19355
+ externalWithdrawAccounts
19356
+ };
19357
+ }
19358
+ const marginfiAccounts = (0, import_marginfi.marginfiAccountsForMint)(assetMint);
19359
+ if (!marginfiAccounts) {
19360
+ return {
19361
+ externalWithdrawIxRefs: null,
19362
+ externalLiquiditySource: null,
19363
+ externalWithdrawAccounts
19364
+ };
19365
+ }
19366
+ const marginfiClient = new import_marginfi.CpiClient({ accounts: marginfiAccounts });
19367
+ const withdrawRefs = (0, import_common27.createCpiRefs)([
19368
+ marginfiClient.withdraw_cpi({
19369
+ marginfiAccount: slot0.userAccount,
19370
+ authority: vault,
19371
+ destinationTokenAccount: vaultAssetAta
19372
+ })
19373
+ ]);
19374
+ return {
19375
+ externalWithdrawIxRefs: withdrawRefs.refs,
19376
+ externalLiquiditySource: 0,
19377
+ externalWithdrawAccounts: withdrawRefs.accounts
19378
+ };
19379
+ }
19380
+
19381
+ // src/client/builders/executeWithdraw.ts
19218
19382
  var ExecuteWithdrawBuilder = class extends VaultBuilderBase {
19219
19383
  getIxAccounts(args) {
19220
19384
  return {
19221
- user: (0, import_common27.toWeb3Pk)(args.user),
19222
- vault: (0, import_common27.toWeb3Pk)(args.vault),
19223
- vaultOracle: (0, import_common27.toWeb3Pk)(args.vaultOracle),
19224
- vaultTrancheState: args.vaultTrancheState ? (0, import_common27.toWeb3Pk)(args.vaultTrancheState) : null,
19225
- assetMint: (0, import_common27.toWeb3Pk)(args.assetMint),
19226
- shareMint: (0, import_common27.toWeb3Pk)(args.shareMint),
19227
- userAssetAta: (0, import_common27.toWeb3Pk)(args.userAssetAta),
19228
- vaultAssetAta: (0, import_common27.toWeb3Pk)(args.vaultAssetAta),
19229
- feeVault: (0, import_common27.toWeb3Pk)(args.feeVault),
19230
- feeVaultAta: (0, import_common27.toWeb3Pk)(args.feeVaultAta),
19231
- userShareAta: (0, import_common27.toWeb3Pk)(args.userShareAta),
19232
- assetTokenProgram: (0, import_common27.toWeb3Pk)(args.assetTokenProgram),
19233
- shareTokenProgram: (0, import_common27.toWeb3Pk)(args.shareTokenProgram)
19385
+ user: (0, import_common28.toWeb3Pk)(args.user),
19386
+ vault: (0, import_common28.toWeb3Pk)(args.vault),
19387
+ vaultOracle: (0, import_common28.toWeb3Pk)(args.vaultOracle),
19388
+ vaultTrancheState: args.vaultTrancheState ? (0, import_common28.toWeb3Pk)(args.vaultTrancheState) : null,
19389
+ assetMint: (0, import_common28.toWeb3Pk)(args.assetMint),
19390
+ shareMint: (0, import_common28.toWeb3Pk)(args.shareMint),
19391
+ userAssetAta: (0, import_common28.toWeb3Pk)(args.userAssetAta),
19392
+ vaultAssetAta: (0, import_common28.toWeb3Pk)(args.vaultAssetAta),
19393
+ feeVault: (0, import_common28.toWeb3Pk)(args.feeVault),
19394
+ feeVaultAta: (0, import_common28.toWeb3Pk)(args.feeVaultAta),
19395
+ userShareAta: (0, import_common28.toWeb3Pk)(args.userShareAta),
19396
+ assetTokenProgram: (0, import_common28.toWeb3Pk)(args.assetTokenProgram),
19397
+ shareTokenProgram: (0, import_common28.toWeb3Pk)(args.shareTokenProgram)
19234
19398
  };
19235
19399
  }
19236
19400
  getIxData(args) {
@@ -19260,7 +19424,7 @@ var ExecuteWithdrawBuilder = class extends VaultBuilderBase {
19260
19424
  ) : this.program.methods.executeWithdraw(data.shareAmount);
19261
19425
  return methods.accountsPartial(
19262
19426
  this.getIxAccounts(args)
19263
- ).remainingAccounts(args.externalWithdrawAccounts.map(toWeb3AccountMeta)).instruction().then(import_common27.toKitInstruction);
19427
+ ).remainingAccounts(args.externalWithdrawAccounts.map(toWeb3AccountMeta)).instruction().then(import_common28.toKitInstruction);
19264
19428
  }
19265
19429
  async deriveIxArgs(txArgs) {
19266
19430
  const connection = this.program.provider.connection;
@@ -19294,36 +19458,23 @@ var ExecuteWithdrawBuilder = class extends VaultBuilderBase {
19294
19458
  ),
19295
19459
  this.account.fetchVault(txArgs.vault)
19296
19460
  ]);
19297
- const vaultAssetAta = (0, import_common27.getAtaAddress)(
19461
+ const vaultAssetAta = (0, import_common28.getAtaAddress)(
19298
19462
  txArgs.assetMint,
19299
19463
  txArgs.vault,
19300
19464
  assetTokenProgram,
19301
19465
  true
19302
19466
  );
19303
- let externalWithdrawIxRefs = txArgs.externalWithdrawIxRefs ?? null;
19304
- let externalLiquiditySource = txArgs.externalLiquiditySource ?? null;
19305
- let externalWithdrawAccounts = txArgs.externalWithdrawAccounts ?? [];
19306
- if (externalWithdrawIxRefs == null && externalLiquiditySource == null && !txArgs.skipExternalLiquidity) {
19307
- const slot0 = parseMarginfiSlot(vaultData.externalLiquidity[0]);
19308
- if (slot0) {
19309
- const marginfiAccounts = (0, import_marginfi.marginfiAccountsForMint)(txArgs.assetMint);
19310
- if (marginfiAccounts) {
19311
- const marginfiClient = new import_marginfi.CpiClient({
19312
- accounts: marginfiAccounts
19313
- });
19314
- const withdrawRefs = (0, import_common27.createCpiRefs)([
19315
- marginfiClient.withdraw_cpi({
19316
- marginfiAccount: slot0.userAccount,
19317
- authority: txArgs.vault,
19318
- destinationTokenAccount: vaultAssetAta
19319
- })
19320
- ]);
19321
- externalWithdrawIxRefs = withdrawRefs.refs;
19322
- externalLiquiditySource = 0;
19323
- externalWithdrawAccounts = withdrawRefs.accounts;
19324
- }
19325
- }
19326
- }
19467
+ const {
19468
+ externalWithdrawIxRefs,
19469
+ externalLiquiditySource,
19470
+ externalWithdrawAccounts
19471
+ } = resolveExternalWithdraw({
19472
+ externalLiquidity: vaultData.externalLiquidity,
19473
+ vault: txArgs.vault,
19474
+ assetMint: txArgs.assetMint,
19475
+ vaultAssetAta,
19476
+ overrides: txArgs
19477
+ });
19327
19478
  return {
19328
19479
  user: txArgs.user,
19329
19480
  vault: txArgs.vault,
@@ -19334,16 +19485,16 @@ var ExecuteWithdrawBuilder = class extends VaultBuilderBase {
19334
19485
  shareAmount: new import_core10.BN(txArgs.shareAmount.toString()),
19335
19486
  assetTokenProgram,
19336
19487
  shareTokenProgram,
19337
- userAssetAta: txArgs.userAssetAta ?? (0, import_common27.getAtaAddress)(txArgs.assetMint, txArgs.user, assetTokenProgram),
19488
+ userAssetAta: txArgs.userAssetAta ?? (0, import_common28.getAtaAddress)(txArgs.assetMint, txArgs.user, assetTokenProgram),
19338
19489
  vaultAssetAta,
19339
19490
  feeVault,
19340
- feeVaultAta: (0, import_common27.getAtaAddress)(
19491
+ feeVaultAta: (0, import_common28.getAtaAddress)(
19341
19492
  txArgs.assetMint,
19342
19493
  feeVault,
19343
19494
  assetTokenProgram,
19344
19495
  true
19345
19496
  ),
19346
- userShareAta: txArgs.userShareAta ?? (0, import_common27.getAtaAddress)(txArgs.shareMint, txArgs.user, shareTokenProgram),
19497
+ userShareAta: txArgs.userShareAta ?? (0, import_common28.getAtaAddress)(txArgs.shareMint, txArgs.user, shareTokenProgram),
19347
19498
  externalWithdrawIxRefs,
19348
19499
  externalLiquiditySource,
19349
19500
  externalWithdrawAccounts,
@@ -19354,31 +19505,31 @@ var ExecuteWithdrawBuilder = class extends VaultBuilderBase {
19354
19505
  return txArgs.lookupTables;
19355
19506
  }
19356
19507
  async buildPreambleInstructions(args) {
19357
- const defaultUserAssetAta = (0, import_common27.getAtaAddress)(
19508
+ const defaultUserAssetAta = (0, import_common28.getAtaAddress)(
19358
19509
  args.assetMint,
19359
19510
  args.user,
19360
19511
  args.assetTokenProgram
19361
19512
  );
19362
- const payer = (0, import_common27.toWeb3Pk)(args.user);
19363
- const createUserAssetAta = (0, import_common27.toWeb3Pk)(args.userAssetAta).equals(
19364
- (0, import_common27.toWeb3Pk)(defaultUserAssetAta)
19513
+ const payer = (0, import_common28.toWeb3Pk)(args.user);
19514
+ const createUserAssetAta = (0, import_common28.toWeb3Pk)(args.userAssetAta).equals(
19515
+ (0, import_common28.toWeb3Pk)(defaultUserAssetAta)
19365
19516
  ) ? (0, import_spl_token11.createAssociatedTokenAccountIdempotentInstruction)(
19366
19517
  payer,
19367
- (0, import_common27.toWeb3Pk)(args.userAssetAta),
19518
+ (0, import_common28.toWeb3Pk)(args.userAssetAta),
19368
19519
  payer,
19369
- (0, import_common27.toWeb3Pk)(args.assetMint),
19370
- (0, import_common27.toWeb3Pk)(args.assetTokenProgram),
19520
+ (0, import_common28.toWeb3Pk)(args.assetMint),
19521
+ (0, import_common28.toWeb3Pk)(args.assetTokenProgram),
19371
19522
  import_spl_token11.ASSOCIATED_TOKEN_PROGRAM_ID
19372
19523
  ) : null;
19373
19524
  const createFeeVaultAta = (0, import_spl_token11.createAssociatedTokenAccountIdempotentInstruction)(
19374
19525
  payer,
19375
- (0, import_common27.toWeb3Pk)(args.feeVaultAta),
19376
- (0, import_common27.toWeb3Pk)(args.feeVault),
19377
- (0, import_common27.toWeb3Pk)(args.assetMint),
19378
- (0, import_common27.toWeb3Pk)(args.assetTokenProgram),
19526
+ (0, import_common28.toWeb3Pk)(args.feeVaultAta),
19527
+ (0, import_common28.toWeb3Pk)(args.feeVault),
19528
+ (0, import_common28.toWeb3Pk)(args.assetMint),
19529
+ (0, import_common28.toWeb3Pk)(args.assetTokenProgram),
19379
19530
  import_spl_token11.ASSOCIATED_TOKEN_PROGRAM_ID
19380
19531
  );
19381
- return [createUserAssetAta, createFeeVaultAta].filter((ix) => ix != null).map(import_common27.toKitInstruction);
19532
+ return [createUserAssetAta, createFeeVaultAta].filter((ix) => ix != null).map(import_common28.toKitInstruction);
19382
19533
  }
19383
19534
  async buildPlanExtras(args) {
19384
19535
  return {
@@ -19390,33 +19541,38 @@ var ExecuteWithdrawBuilder = class extends VaultBuilderBase {
19390
19541
  // src/client/builders/fulfillJuniorTrancheWithdraw.ts
19391
19542
  var import_spl_token12 = require("@solana/spl-token");
19392
19543
  var import_web313 = require("@solana/web3.js");
19393
- var import_common28 = __toESM(require_dist());
19544
+ var import_common29 = __toESM(require_dist());
19394
19545
  var FulfillJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19395
19546
  async getIx(args) {
19547
+ const externalWithdrawIxRefs = args.externalWithdrawIxRefs ?? null;
19548
+ const externalLiquiditySource = args.externalLiquiditySource ?? null;
19396
19549
  const methods = args.addressSeeds ? this.program.methods.fulfillJuniorTrancheWithdrawFeeExempt(
19550
+ externalWithdrawIxRefs,
19551
+ externalLiquiditySource,
19397
19552
  args.addressSeeds.map((seed) => Buffer.from(seed))
19398
- ) : this.program.methods.fulfillJuniorTrancheWithdraw();
19553
+ ) : this.program.methods.fulfillJuniorTrancheWithdraw(
19554
+ externalWithdrawIxRefs,
19555
+ externalLiquiditySource
19556
+ );
19399
19557
  return methods.accountsPartial({
19400
- signer: (0, import_common28.toWeb3Pk)(args.signer),
19401
- owner: (0, import_common28.toWeb3Pk)(args.owner),
19402
- queuePayer: (0, import_common28.toWeb3Pk)(args.queuePayer),
19403
- vault: (0, import_common28.toWeb3Pk)(args.vault),
19404
- vaultOracle: (0, import_common28.toWeb3Pk)(args.vaultOracle),
19405
- vaultTrancheState: (0, import_common28.toWeb3Pk)(args.vaultTrancheState),
19406
- withdrawalQueue: (0, import_common28.toWeb3Pk)(args.withdrawalQueue),
19407
- outputMint: (0, import_common28.toWeb3Pk)(args.outputMint),
19408
- inputMint: (0, import_common28.toWeb3Pk)(args.inputMint),
19409
- ownerInputAta: (0, import_common28.toWeb3Pk)(args.ownerInputAta),
19410
- ownerOutputAta: (0, import_common28.toWeb3Pk)(args.ownerOutputAta),
19411
- vaultOutputAta: (0, import_common28.toWeb3Pk)(args.vaultOutputAta),
19412
- feeCollector: (0, import_common28.toWeb3Pk)(args.feeCollector),
19413
- feeCollectorOutputAta: (0, import_common28.toWeb3Pk)(args.feeCollectorOutputAta),
19414
- queueInputAta: (0, import_common28.toWeb3Pk)(args.queueInputAta),
19415
- assetTokenProgram: (0, import_common28.toWeb3Pk)(args.assetTokenProgram),
19416
- shareTokenProgram: (0, import_common28.toWeb3Pk)(args.shareTokenProgram),
19558
+ signer: (0, import_common29.toWeb3Pk)(args.signer),
19559
+ owner: (0, import_common29.toWeb3Pk)(args.owner),
19560
+ queuePayer: (0, import_common29.toWeb3Pk)(args.queuePayer),
19561
+ vault: (0, import_common29.toWeb3Pk)(args.vault),
19562
+ vaultOracle: (0, import_common29.toWeb3Pk)(args.vaultOracle),
19563
+ vaultTrancheState: (0, import_common29.toWeb3Pk)(args.vaultTrancheState),
19564
+ withdrawalQueue: (0, import_common29.toWeb3Pk)(args.withdrawalQueue),
19565
+ outputMint: (0, import_common29.toWeb3Pk)(args.outputMint),
19566
+ inputMint: (0, import_common29.toWeb3Pk)(args.inputMint),
19567
+ ownerInputAta: (0, import_common29.toWeb3Pk)(args.ownerInputAta),
19568
+ ownerOutputAta: (0, import_common29.toWeb3Pk)(args.ownerOutputAta),
19569
+ vaultOutputAta: (0, import_common29.toWeb3Pk)(args.vaultOutputAta),
19570
+ queueInputAta: (0, import_common29.toWeb3Pk)(args.queueInputAta),
19571
+ assetTokenProgram: (0, import_common29.toWeb3Pk)(args.assetTokenProgram),
19572
+ shareTokenProgram: (0, import_common29.toWeb3Pk)(args.shareTokenProgram),
19417
19573
  associatedTokenProgram: import_spl_token12.ASSOCIATED_TOKEN_PROGRAM_ID,
19418
19574
  systemProgram: import_web313.SystemProgram.programId
19419
- }).instruction().then(import_common28.toKitInstruction);
19575
+ }).remainingAccounts(args.externalWithdrawAccounts.map(toWeb3AccountMeta)).instruction().then(import_common29.toKitInstruction);
19420
19576
  }
19421
19577
  async deriveIxArgs(txArgs) {
19422
19578
  const connection = this.program.provider.connection;
@@ -19426,9 +19582,9 @@ var FulfillJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19426
19582
  [vaultOracle],
19427
19583
  [vaultTrancheState],
19428
19584
  [withdrawalQueue],
19429
- feeCollector,
19430
19585
  assetTokenProgram,
19431
- juniorShare
19586
+ juniorShare,
19587
+ vaultData
19432
19588
  ] = await Promise.all([
19433
19589
  this.pda.deriveVaultOraclePda(txArgs.vault),
19434
19590
  this.pda.deriveVaultTrancheStatePda(txArgs.vault),
@@ -19437,7 +19593,6 @@ var FulfillJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19437
19593
  txArgs.owner,
19438
19594
  txArgs.queueId
19439
19595
  ),
19440
- resolveVaultFeeCollector(this.account, txArgs.vault, txArgs.feeCollector),
19441
19596
  resolveHoldingTokenProgram(
19442
19597
  this.account,
19443
19598
  connection,
@@ -19453,10 +19608,28 @@ var FulfillJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19453
19608
  mint: txArgs.juniorShareMint,
19454
19609
  tokenProgram: txArgs.shareTokenProgram
19455
19610
  }
19456
- )
19611
+ ),
19612
+ this.account.fetchVault(txArgs.vault)
19457
19613
  ]);
19458
19614
  const { mint: juniorShareMint, tokenProgram: shareTokenProgram } = juniorShare;
19459
19615
  const queuePda = txArgs.withdrawalQueue ?? withdrawalQueue;
19616
+ const vaultOutputAta = (0, import_common29.getAtaAddress)(
19617
+ txArgs.assetMint,
19618
+ txArgs.vault,
19619
+ assetTokenProgram,
19620
+ true
19621
+ );
19622
+ const {
19623
+ externalWithdrawIxRefs,
19624
+ externalLiquiditySource,
19625
+ externalWithdrawAccounts
19626
+ } = resolveExternalWithdraw({
19627
+ externalLiquidity: vaultData.externalLiquidity,
19628
+ vault: txArgs.vault,
19629
+ assetMint: txArgs.assetMint,
19630
+ vaultAssetAta: vaultOutputAta,
19631
+ overrides: txArgs
19632
+ });
19460
19633
  return {
19461
19634
  signer,
19462
19635
  owner: txArgs.owner,
@@ -19469,50 +19642,45 @@ var FulfillJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19469
19642
  inputMint: juniorShareMint,
19470
19643
  assetTokenProgram,
19471
19644
  shareTokenProgram,
19472
- ownerInputAta: txArgs.ownerInputAta ?? (0, import_common28.getAtaAddress)(juniorShareMint, txArgs.owner, shareTokenProgram),
19473
- ownerOutputAta: (0, import_common28.getAtaAddress)(
19645
+ ownerInputAta: txArgs.ownerInputAta ?? (0, import_common29.getAtaAddress)(juniorShareMint, txArgs.owner, shareTokenProgram),
19646
+ ownerOutputAta: (0, import_common29.getAtaAddress)(
19474
19647
  txArgs.assetMint,
19475
19648
  txArgs.owner,
19476
19649
  assetTokenProgram
19477
19650
  ),
19478
- vaultOutputAta: (0, import_common28.getAtaAddress)(
19479
- txArgs.assetMint,
19480
- txArgs.vault,
19481
- assetTokenProgram,
19482
- true
19483
- ),
19484
- feeCollector,
19485
- feeCollectorOutputAta: (0, import_common28.getAtaAddress)(
19486
- txArgs.assetMint,
19487
- feeCollector,
19488
- assetTokenProgram
19489
- ),
19490
- queueInputAta: (0, import_common28.getAtaAddress)(
19651
+ vaultOutputAta,
19652
+ queueInputAta: (0, import_common29.getAtaAddress)(
19491
19653
  juniorShareMint,
19492
19654
  queuePda,
19493
19655
  shareTokenProgram,
19494
19656
  true
19495
19657
  ),
19658
+ externalWithdrawIxRefs,
19659
+ externalLiquiditySource,
19660
+ externalWithdrawAccounts,
19496
19661
  addressSeeds: txArgs.addressSeeds
19497
19662
  };
19498
19663
  }
19664
+ async buildLookupTables(_args, txArgs) {
19665
+ return txArgs.lookupTables;
19666
+ }
19499
19667
  async buildPreambleInstructions(args) {
19500
- const defaultOwnerInputAta = (0, import_common28.getAtaAddress)(
19668
+ const defaultOwnerInputAta = (0, import_common29.getAtaAddress)(
19501
19669
  args.inputMint,
19502
19670
  args.owner,
19503
19671
  args.shareTokenProgram
19504
19672
  );
19505
- if (!(0, import_common28.toWeb3Pk)(args.ownerInputAta).equals((0, import_common28.toWeb3Pk)(defaultOwnerInputAta))) {
19673
+ if (!(0, import_common29.toWeb3Pk)(args.ownerInputAta).equals((0, import_common29.toWeb3Pk)(defaultOwnerInputAta))) {
19506
19674
  return [];
19507
19675
  }
19508
19676
  return [
19509
- (0, import_common28.toKitInstruction)(
19677
+ (0, import_common29.toKitInstruction)(
19510
19678
  (0, import_spl_token12.createAssociatedTokenAccountIdempotentInstruction)(
19511
- (0, import_common28.toWeb3Pk)(args.signer),
19512
- (0, import_common28.toWeb3Pk)(args.ownerInputAta),
19513
- (0, import_common28.toWeb3Pk)(args.owner),
19514
- (0, import_common28.toWeb3Pk)(args.inputMint),
19515
- (0, import_common28.toWeb3Pk)(args.shareTokenProgram),
19679
+ (0, import_common29.toWeb3Pk)(args.signer),
19680
+ (0, import_common29.toWeb3Pk)(args.ownerInputAta),
19681
+ (0, import_common29.toWeb3Pk)(args.owner),
19682
+ (0, import_common29.toWeb3Pk)(args.inputMint),
19683
+ (0, import_common29.toWeb3Pk)(args.shareTokenProgram),
19516
19684
  import_spl_token12.ASSOCIATED_TOKEN_PROGRAM_ID
19517
19685
  )
19518
19686
  )
@@ -19533,21 +19701,22 @@ var FulfillJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19533
19701
 
19534
19702
  // src/client/builders/updateTrancheConfig.ts
19535
19703
  var import_core11 = require("@anchor-lang/core");
19536
- var import_common29 = __toESM(require_dist());
19704
+ var import_common30 = __toESM(require_dist());
19537
19705
  var UpdateTrancheConfigBuilder = class extends VaultBuilderBase {
19538
19706
  async getIx(args) {
19539
19707
  return this.program.methods.vaultUpdateTrancheConfig({
19540
19708
  seniorFixedApyBps: args.seniorFixedApyBps,
19709
+ juniorFloorApyBps: args.juniorFloorApyBps,
19541
19710
  earlyUnstakeFeeBps: args.earlyUnstakeFeeBps,
19542
19711
  standardUnstakeFeeBps: args.standardUnstakeFeeBps,
19543
19712
  targetLockupDurationSecs: args.targetLockupDurationSecs,
19544
19713
  juniorDepositCap: args.juniorDepositCap
19545
19714
  }).accountsPartial({
19546
- curator: (0, import_common29.toWeb3Pk)(args.curator),
19547
- vault: (0, import_common29.toWeb3Pk)(args.vault),
19548
- vaultTrancheState: (0, import_common29.toWeb3Pk)(args.vaultTrancheState),
19549
- vaultOracle: (0, import_common29.toWeb3Pk)(args.vaultOracle)
19550
- }).instruction().then(import_common29.toKitInstruction);
19715
+ curator: (0, import_common30.toWeb3Pk)(args.curator),
19716
+ vault: (0, import_common30.toWeb3Pk)(args.vault),
19717
+ vaultTrancheState: (0, import_common30.toWeb3Pk)(args.vaultTrancheState),
19718
+ vaultOracle: (0, import_common30.toWeb3Pk)(args.vaultOracle)
19719
+ }).instruction().then(import_common30.toKitInstruction);
19551
19720
  }
19552
19721
  async deriveIxArgs(txArgs) {
19553
19722
  const [vaultTrancheState] = await this.pda.deriveVaultTrancheStatePda(
@@ -19560,6 +19729,7 @@ var UpdateTrancheConfigBuilder = class extends VaultBuilderBase {
19560
19729
  vaultTrancheState: txArgs.vaultTrancheState ?? vaultTrancheState,
19561
19730
  vaultOracle: txArgs.vaultOracle ?? vaultOracle,
19562
19731
  seniorFixedApyBps: txArgs.seniorFixedApyBps ?? null,
19732
+ juniorFloorApyBps: txArgs.juniorFloorApyBps ?? null,
19563
19733
  earlyUnstakeFeeBps: txArgs.earlyUnstakeFeeBps ?? null,
19564
19734
  standardUnstakeFeeBps: txArgs.standardUnstakeFeeBps ?? null,
19565
19735
  targetLockupDurationSecs: txArgs.targetLockupDurationSecs === void 0 ? null : new import_core11.BN(txArgs.targetLockupDurationSecs.toString()),
@@ -19579,22 +19749,22 @@ var UpdateTrancheConfigBuilder = class extends VaultBuilderBase {
19579
19749
  var import_core12 = require("@anchor-lang/core");
19580
19750
  var import_spl_token13 = require("@solana/spl-token");
19581
19751
  var import_web314 = require("@solana/web3.js");
19582
- var import_common30 = __toESM(require_dist());
19752
+ var import_common31 = __toESM(require_dist());
19583
19753
  var ManagerRedepositAssetBuilder = class extends VaultBuilderBase {
19584
19754
  async getIx(args) {
19585
19755
  return this.program.methods.managerRedepositAsset({
19586
19756
  depositAmount: args.depositAmount,
19587
19757
  externalAmount: args.externalAmount
19588
19758
  }).accountsPartial({
19589
- manager: (0, import_common30.toWeb3Pk)(args.manager),
19590
- vault: (0, import_common30.toWeb3Pk)(args.vault),
19591
- assetMint: (0, import_common30.toWeb3Pk)(args.assetMint),
19592
- vaultAssetAta: (0, import_common30.toWeb3Pk)(args.vaultAssetAta),
19593
- managerAssetAta: (0, import_common30.toWeb3Pk)(args.managerAssetAta),
19594
- assetTokenProgram: (0, import_common30.toWeb3Pk)(args.assetTokenProgram),
19759
+ manager: (0, import_common31.toWeb3Pk)(args.manager),
19760
+ vault: (0, import_common31.toWeb3Pk)(args.vault),
19761
+ assetMint: (0, import_common31.toWeb3Pk)(args.assetMint),
19762
+ vaultAssetAta: (0, import_common31.toWeb3Pk)(args.vaultAssetAta),
19763
+ managerAssetAta: (0, import_common31.toWeb3Pk)(args.managerAssetAta),
19764
+ assetTokenProgram: (0, import_common31.toWeb3Pk)(args.assetTokenProgram),
19595
19765
  associatedTokenProgram: import_spl_token13.ASSOCIATED_TOKEN_PROGRAM_ID,
19596
19766
  systemProgram: import_web314.SystemProgram.programId
19597
- }).instruction().then(import_common30.toKitInstruction);
19767
+ }).instruction().then(import_common31.toKitInstruction);
19598
19768
  }
19599
19769
  async deriveIxArgs(txArgs) {
19600
19770
  const connection = this.program.provider.connection;
@@ -19611,13 +19781,13 @@ var ManagerRedepositAssetBuilder = class extends VaultBuilderBase {
19611
19781
  depositAmount: new import_core12.BN(txArgs.depositAmount.toString()),
19612
19782
  externalAmount: new import_core12.BN(externalAmount.toString()),
19613
19783
  assetTokenProgram,
19614
- vaultAssetAta: (0, import_common30.getAtaAddress)(
19784
+ vaultAssetAta: (0, import_common31.getAtaAddress)(
19615
19785
  txArgs.assetMint,
19616
19786
  txArgs.vault,
19617
19787
  assetTokenProgram,
19618
19788
  true
19619
19789
  ),
19620
- managerAssetAta: (0, import_common30.getAtaAddress)(
19790
+ managerAssetAta: (0, import_common31.getAtaAddress)(
19621
19791
  txArgs.assetMint,
19622
19792
  txArgs.manager,
19623
19793
  assetTokenProgram
@@ -19635,19 +19805,19 @@ var ManagerRedepositAssetBuilder = class extends VaultBuilderBase {
19635
19805
  var import_core13 = require("@anchor-lang/core");
19636
19806
  var import_spl_token14 = require("@solana/spl-token");
19637
19807
  var import_web315 = require("@solana/web3.js");
19638
- var import_common31 = __toESM(require_dist());
19808
+ var import_common32 = __toESM(require_dist());
19639
19809
  var ManagerWithdrawAssetBuilder = class extends VaultBuilderBase {
19640
19810
  async getIx(args) {
19641
19811
  return this.program.methods.managerWithdrawAsset(args.amount).accountsPartial({
19642
- manager: (0, import_common31.toWeb3Pk)(args.manager),
19643
- vault: (0, import_common31.toWeb3Pk)(args.vault),
19644
- assetMint: (0, import_common31.toWeb3Pk)(args.assetMint),
19645
- vaultAssetAta: (0, import_common31.toWeb3Pk)(args.vaultAssetAta),
19646
- managerAssetAta: (0, import_common31.toWeb3Pk)(args.managerAssetAta),
19647
- assetTokenProgram: (0, import_common31.toWeb3Pk)(args.assetTokenProgram),
19812
+ manager: (0, import_common32.toWeb3Pk)(args.manager),
19813
+ vault: (0, import_common32.toWeb3Pk)(args.vault),
19814
+ assetMint: (0, import_common32.toWeb3Pk)(args.assetMint),
19815
+ vaultAssetAta: (0, import_common32.toWeb3Pk)(args.vaultAssetAta),
19816
+ managerAssetAta: (0, import_common32.toWeb3Pk)(args.managerAssetAta),
19817
+ assetTokenProgram: (0, import_common32.toWeb3Pk)(args.assetTokenProgram),
19648
19818
  associatedTokenProgram: import_spl_token14.ASSOCIATED_TOKEN_PROGRAM_ID,
19649
19819
  systemProgram: import_web315.SystemProgram.programId
19650
- }).instruction().then(import_common31.toKitInstruction);
19820
+ }).instruction().then(import_common32.toKitInstruction);
19651
19821
  }
19652
19822
  async deriveIxArgs(txArgs) {
19653
19823
  const connection = this.program.provider.connection;
@@ -19662,13 +19832,13 @@ var ManagerWithdrawAssetBuilder = class extends VaultBuilderBase {
19662
19832
  assetMint: txArgs.assetMint,
19663
19833
  amount: new import_core13.BN(txArgs.amount.toString()),
19664
19834
  assetTokenProgram,
19665
- vaultAssetAta: (0, import_common31.getAtaAddress)(
19835
+ vaultAssetAta: (0, import_common32.getAtaAddress)(
19666
19836
  txArgs.assetMint,
19667
19837
  txArgs.vault,
19668
19838
  assetTokenProgram,
19669
19839
  true
19670
19840
  ),
19671
- managerAssetAta: (0, import_common31.getAtaAddress)(
19841
+ managerAssetAta: (0, import_common32.getAtaAddress)(
19672
19842
  txArgs.assetMint,
19673
19843
  txArgs.manager,
19674
19844
  assetTokenProgram
@@ -19687,7 +19857,7 @@ var import_core14 = require("@anchor-lang/core");
19687
19857
  var import_kit8 = require("@solana/kit");
19688
19858
  var import_spl_token15 = require("@solana/spl-token");
19689
19859
  var import_web316 = require("@solana/web3.js");
19690
- var import_common32 = __toESM(require_dist());
19860
+ var import_common33 = __toESM(require_dist());
19691
19861
  var DEFAULT_PYTH_PRICE_MAX_AGE_SECS = 90n;
19692
19862
  function toAssetPriceOracleConfig(args) {
19693
19863
  return {
@@ -19702,7 +19872,7 @@ function toAssetPriceOracleConfig(args) {
19702
19872
  function toAnchorAssetPriceOracleConfig(config) {
19703
19873
  return {
19704
19874
  ...config,
19705
- priceOracleAccount: (0, import_common32.toWeb3Pk)(config.priceOracleAccount)
19875
+ priceOracleAccount: (0, import_common33.toWeb3Pk)(config.priceOracleAccount)
19706
19876
  };
19707
19877
  }
19708
19878
  function toWeb3AccountMeta2(account) {
@@ -19716,14 +19886,14 @@ var ProtocolInteractionBuilder = class extends VaultBuilderBase {
19716
19886
  async getIx(args) {
19717
19887
  return this.program.methods.protocolInteraction(args.refs, {
19718
19888
  externalLiquidityIndex: args.externalLiquidityIndex,
19719
- affectedAssetMint: args.affectedAssetMint ? (0, import_common32.toWeb3Pk)(args.affectedAssetMint) : null
19889
+ affectedAssetMint: args.affectedAssetMint ? (0, import_common33.toWeb3Pk)(args.affectedAssetMint) : null
19720
19890
  }).accountsPartial({
19721
- hwManager: (0, import_common32.toWeb3Pk)(args.hwManager),
19722
- vault: (0, import_common32.toWeb3Pk)(args.vault),
19723
- affectedAssetMint: args.affectedAssetMint ? (0, import_common32.toWeb3Pk)(args.affectedAssetMint) : null,
19724
- affectedVaultAta: args.affectedVaultAta ? (0, import_common32.toWeb3Pk)(args.affectedVaultAta) : null,
19725
- affectedTokenProgram: args.affectedTokenProgram ? (0, import_common32.toWeb3Pk)(args.affectedTokenProgram) : null
19726
- }).remainingAccounts(args.accounts.map(toWeb3AccountMeta2)).instruction().then(import_common32.toKitInstruction);
19891
+ hwManager: (0, import_common33.toWeb3Pk)(args.hwManager),
19892
+ vault: (0, import_common33.toWeb3Pk)(args.vault),
19893
+ affectedAssetMint: args.affectedAssetMint ? (0, import_common33.toWeb3Pk)(args.affectedAssetMint) : null,
19894
+ affectedVaultAta: args.affectedVaultAta ? (0, import_common33.toWeb3Pk)(args.affectedVaultAta) : null,
19895
+ affectedTokenProgram: args.affectedTokenProgram ? (0, import_common33.toWeb3Pk)(args.affectedTokenProgram) : null
19896
+ }).remainingAccounts(args.accounts.map(toWeb3AccountMeta2)).instruction().then(import_common33.toKitInstruction);
19727
19897
  }
19728
19898
  async deriveIxArgs(txArgs) {
19729
19899
  const affectedTokenProgram = txArgs.affectedAssetMint ? txArgs.affectedTokenProgram ?? TOKEN_PROGRAM_ID : null;
@@ -19735,7 +19905,7 @@ var ProtocolInteractionBuilder = class extends VaultBuilderBase {
19735
19905
  accounts: txArgs.accounts,
19736
19906
  affectedAssetMint: txArgs.affectedAssetMint ?? null,
19737
19907
  affectedTokenProgram,
19738
- affectedVaultAta: txArgs.affectedAssetMint && affectedTokenProgram ? (0, import_common32.getAtaAddress)(
19908
+ affectedVaultAta: txArgs.affectedAssetMint && affectedTokenProgram ? (0, import_common33.getAtaAddress)(
19739
19909
  txArgs.affectedAssetMint,
19740
19910
  txArgs.vault,
19741
19911
  affectedTokenProgram,
@@ -19754,18 +19924,18 @@ var JupiterSwapBuilder = class extends VaultBuilderBase {
19754
19924
  args.destinationPriceOracle
19755
19925
  )
19756
19926
  }).accountsPartial({
19757
- hwManager: (0, import_common32.toWeb3Pk)(args.hwManager),
19758
- vault: (0, import_common32.toWeb3Pk)(args.vault),
19759
- sourceMint: (0, import_common32.toWeb3Pk)(args.sourceMint),
19760
- destinationMint: (0, import_common32.toWeb3Pk)(args.destinationMint),
19761
- vaultSourceAta: (0, import_common32.toWeb3Pk)(args.vaultSourceAta),
19762
- vaultDestinationAta: (0, import_common32.toWeb3Pk)(args.vaultDestinationAta),
19763
- sourceTokenProgram: (0, import_common32.toWeb3Pk)(args.sourceTokenProgram),
19764
- destinationTokenProgram: (0, import_common32.toWeb3Pk)(args.destinationTokenProgram),
19765
- destinationOracleAccount: args.destinationOracleAccount ? (0, import_common32.toWeb3Pk)(args.destinationOracleAccount) : null,
19766
- vaultOracle: (0, import_common32.toWeb3Pk)(args.vaultOracle),
19767
- vaultTrancheState: args.vaultTrancheState ? (0, import_common32.toWeb3Pk)(args.vaultTrancheState) : null
19768
- }).remainingAccounts(args.accounts.map(toWeb3AccountMeta2)).instruction().then(import_common32.toKitInstruction);
19927
+ hwManager: (0, import_common33.toWeb3Pk)(args.hwManager),
19928
+ vault: (0, import_common33.toWeb3Pk)(args.vault),
19929
+ sourceMint: (0, import_common33.toWeb3Pk)(args.sourceMint),
19930
+ destinationMint: (0, import_common33.toWeb3Pk)(args.destinationMint),
19931
+ vaultSourceAta: (0, import_common33.toWeb3Pk)(args.vaultSourceAta),
19932
+ vaultDestinationAta: (0, import_common33.toWeb3Pk)(args.vaultDestinationAta),
19933
+ sourceTokenProgram: (0, import_common33.toWeb3Pk)(args.sourceTokenProgram),
19934
+ destinationTokenProgram: (0, import_common33.toWeb3Pk)(args.destinationTokenProgram),
19935
+ destinationOracleAccount: args.destinationOracleAccount ? (0, import_common33.toWeb3Pk)(args.destinationOracleAccount) : null,
19936
+ vaultOracle: (0, import_common33.toWeb3Pk)(args.vaultOracle),
19937
+ vaultTrancheState: args.vaultTrancheState ? (0, import_common33.toWeb3Pk)(args.vaultTrancheState) : null
19938
+ }).remainingAccounts(args.accounts.map(toWeb3AccountMeta2)).instruction().then(import_common33.toKitInstruction);
19769
19939
  }
19770
19940
  async deriveIxArgs(txArgs) {
19771
19941
  const sourceTokenProgram = txArgs.sourceTokenProgram ?? TOKEN_PROGRAM_ID;
@@ -19786,13 +19956,13 @@ var JupiterSwapBuilder = class extends VaultBuilderBase {
19786
19956
  accounts: txArgs.accounts,
19787
19957
  sourceTokenProgram,
19788
19958
  destinationTokenProgram,
19789
- vaultSourceAta: (0, import_common32.getAtaAddress)(
19959
+ vaultSourceAta: (0, import_common33.getAtaAddress)(
19790
19960
  txArgs.sourceMint,
19791
19961
  txArgs.vault,
19792
19962
  sourceTokenProgram,
19793
19963
  true
19794
19964
  ),
19795
- vaultDestinationAta: (0, import_common32.getAtaAddress)(
19965
+ vaultDestinationAta: (0, import_common33.getAtaAddress)(
19796
19966
  txArgs.destinationMint,
19797
19967
  txArgs.vault,
19798
19968
  destinationTokenProgram,
@@ -19801,24 +19971,24 @@ var JupiterSwapBuilder = class extends VaultBuilderBase {
19801
19971
  };
19802
19972
  }
19803
19973
  async buildPreambleInstructions(args) {
19804
- const payer = (0, import_common32.toWeb3Pk)(args.hwManager);
19974
+ const payer = (0, import_common33.toWeb3Pk)(args.hwManager);
19805
19975
  const createSourceAta = (0, import_spl_token15.createAssociatedTokenAccountIdempotentInstruction)(
19806
19976
  payer,
19807
- (0, import_common32.toWeb3Pk)(args.vaultSourceAta),
19808
- (0, import_common32.toWeb3Pk)(args.vault),
19809
- (0, import_common32.toWeb3Pk)(args.sourceMint),
19810
- (0, import_common32.toWeb3Pk)(args.sourceTokenProgram),
19977
+ (0, import_common33.toWeb3Pk)(args.vaultSourceAta),
19978
+ (0, import_common33.toWeb3Pk)(args.vault),
19979
+ (0, import_common33.toWeb3Pk)(args.sourceMint),
19980
+ (0, import_common33.toWeb3Pk)(args.sourceTokenProgram),
19811
19981
  import_spl_token15.ASSOCIATED_TOKEN_PROGRAM_ID
19812
19982
  );
19813
19983
  const createDestinationAta = (0, import_spl_token15.createAssociatedTokenAccountIdempotentInstruction)(
19814
19984
  payer,
19815
- (0, import_common32.toWeb3Pk)(args.vaultDestinationAta),
19816
- (0, import_common32.toWeb3Pk)(args.vault),
19817
- (0, import_common32.toWeb3Pk)(args.destinationMint),
19818
- (0, import_common32.toWeb3Pk)(args.destinationTokenProgram),
19985
+ (0, import_common33.toWeb3Pk)(args.vaultDestinationAta),
19986
+ (0, import_common33.toWeb3Pk)(args.vault),
19987
+ (0, import_common33.toWeb3Pk)(args.destinationMint),
19988
+ (0, import_common33.toWeb3Pk)(args.destinationTokenProgram),
19819
19989
  import_spl_token15.ASSOCIATED_TOKEN_PROGRAM_ID
19820
19990
  );
19821
- return [createSourceAta, createDestinationAta].map(import_common32.toKitInstruction);
19991
+ return [createSourceAta, createDestinationAta].map(import_common33.toKitInstruction);
19822
19992
  }
19823
19993
  async buildLookupTables(_args, txArgs) {
19824
19994
  return txArgs.lookupTables;
@@ -19854,24 +20024,24 @@ var JupiterSwapBuilder = class extends VaultBuilderBase {
19854
20024
  var import_core15 = require("@anchor-lang/core");
19855
20025
  var import_spl_token16 = require("@solana/spl-token");
19856
20026
  var import_web317 = require("@solana/web3.js");
19857
- var import_common33 = __toESM(require_dist());
20027
+ var import_common34 = __toESM(require_dist());
19858
20028
  var RequestJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19859
20029
  async getIx(args) {
19860
20030
  return this.program.methods.requestJuniorTrancheWithdraw(args.queueId, args.shareAmount).accountsPartial({
19861
- user: (0, import_common33.toWeb3Pk)(args.user),
19862
- payer: (0, import_common33.toWeb3Pk)(args.payer),
19863
- vault: (0, import_common33.toWeb3Pk)(args.vault),
19864
- vaultOracle: (0, import_common33.toWeb3Pk)(args.vaultOracle),
19865
- vaultTrancheState: (0, import_common33.toWeb3Pk)(args.vaultTrancheState),
19866
- withdrawalQueue: (0, import_common33.toWeb3Pk)(args.withdrawalQueue),
19867
- outputMint: (0, import_common33.toWeb3Pk)(args.outputMint),
19868
- inputMint: (0, import_common33.toWeb3Pk)(args.inputMint),
19869
- userInputAta: (0, import_common33.toWeb3Pk)(args.userInputAta),
19870
- queueInputAta: (0, import_common33.toWeb3Pk)(args.queueInputAta),
19871
- shareTokenProgram: (0, import_common33.toWeb3Pk)(args.shareTokenProgram),
20031
+ user: (0, import_common34.toWeb3Pk)(args.user),
20032
+ payer: (0, import_common34.toWeb3Pk)(args.payer),
20033
+ vault: (0, import_common34.toWeb3Pk)(args.vault),
20034
+ vaultOracle: (0, import_common34.toWeb3Pk)(args.vaultOracle),
20035
+ vaultTrancheState: (0, import_common34.toWeb3Pk)(args.vaultTrancheState),
20036
+ withdrawalQueue: (0, import_common34.toWeb3Pk)(args.withdrawalQueue),
20037
+ outputMint: (0, import_common34.toWeb3Pk)(args.outputMint),
20038
+ inputMint: (0, import_common34.toWeb3Pk)(args.inputMint),
20039
+ userInputAta: (0, import_common34.toWeb3Pk)(args.userInputAta),
20040
+ queueInputAta: (0, import_common34.toWeb3Pk)(args.queueInputAta),
20041
+ shareTokenProgram: (0, import_common34.toWeb3Pk)(args.shareTokenProgram),
19872
20042
  associatedTokenProgram: import_spl_token16.ASSOCIATED_TOKEN_PROGRAM_ID,
19873
20043
  systemProgram: import_web317.SystemProgram.programId
19874
- }).instruction().then(import_common33.toKitInstruction);
20044
+ }).instruction().then(import_common34.toKitInstruction);
19875
20045
  }
19876
20046
  async deriveIxArgs(txArgs) {
19877
20047
  const payer = txArgs.payer ?? txArgs.user;
@@ -19907,8 +20077,8 @@ var RequestJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19907
20077
  queueId: txArgs.queueId,
19908
20078
  shareAmount: new import_core15.BN(txArgs.shareAmount.toString()),
19909
20079
  shareTokenProgram,
19910
- userInputAta: txArgs.userInputAta ?? (0, import_common33.getAtaAddress)(juniorShareMint, txArgs.user, shareTokenProgram),
19911
- queueInputAta: (0, import_common33.getAtaAddress)(
20080
+ userInputAta: txArgs.userInputAta ?? (0, import_common34.getAtaAddress)(juniorShareMint, txArgs.user, shareTokenProgram),
20081
+ queueInputAta: (0, import_common34.getAtaAddress)(
19912
20082
  juniorShareMint,
19913
20083
  queuePda,
19914
20084
  shareTokenProgram,
@@ -19933,7 +20103,7 @@ var RequestJuniorTrancheWithdrawBuilder = class extends VaultBuilderBase {
19933
20103
  var import_core16 = require("@anchor-lang/core");
19934
20104
  var import_spl_token17 = require("@solana/spl-token");
19935
20105
  var import_web318 = require("@solana/web3.js");
19936
- var import_common34 = __toESM(require_dist());
20106
+ var import_common35 = __toESM(require_dist());
19937
20107
  var DEFAULT_PYTH_PRICE_MAX_AGE_SECS2 = 90n;
19938
20108
  function toAssetPriceOracleConfig2(args) {
19939
20109
  return {
@@ -19948,7 +20118,7 @@ function toAssetPriceOracleConfig2(args) {
19948
20118
  function toAnchorAssetPriceOracleConfig2(config) {
19949
20119
  return {
19950
20120
  ...config,
19951
- priceOracleAccount: (0, import_common34.toWeb3Pk)(config.priceOracleAccount)
20121
+ priceOracleAccount: (0, import_common35.toWeb3Pk)(config.priceOracleAccount)
19952
20122
  };
19953
20123
  }
19954
20124
  var VaultReallocationBuilder = class extends VaultBuilderBase {
@@ -19957,35 +20127,35 @@ var VaultReallocationBuilder = class extends VaultBuilderBase {
19957
20127
  amount: args.amount,
19958
20128
  assetPriceOracle: toAnchorAssetPriceOracleConfig2(args.assetPriceOracle)
19959
20129
  }).accountsPartial({
19960
- manager: (0, import_common34.toWeb3Pk)(args.manager),
19961
- allocationVault: (0, import_common34.toWeb3Pk)(args.allocationVault),
19962
- sourceVault: args.sourceVault ? (0, import_common34.toWeb3Pk)(args.sourceVault) : null,
19963
- sourceVaultOracle: args.sourceVaultOracle ? (0, import_common34.toWeb3Pk)(args.sourceVaultOracle) : null,
19964
- destinationVault: (0, import_common34.toWeb3Pk)(args.destinationVault),
19965
- destinationVaultOracle: (0, import_common34.toWeb3Pk)(args.destinationVaultOracle),
19966
- mint: (0, import_common34.toWeb3Pk)(args.mint),
19967
- sourceShareMint: args.sourceShareMint ? (0, import_common34.toWeb3Pk)(args.sourceShareMint) : null,
19968
- destinationShareMint: (0, import_common34.toWeb3Pk)(args.destinationShareMint),
19969
- allocationMintAta: (0, import_common34.toWeb3Pk)(args.allocationMintAta),
19970
- sourceVaultMintAta: args.sourceVaultMintAta ? (0, import_common34.toWeb3Pk)(args.sourceVaultMintAta) : null,
19971
- destinationVaultMintAta: (0, import_common34.toWeb3Pk)(args.destinationVaultMintAta),
19972
- destinationFeeVault: (0, import_common34.toWeb3Pk)(args.destinationFeeVault),
19973
- destinationFeeVaultMintAta: (0, import_common34.toWeb3Pk)(args.destinationFeeVaultMintAta),
19974
- allocationSourceShareAta: args.allocationSourceShareAta ? (0, import_common34.toWeb3Pk)(args.allocationSourceShareAta) : null,
19975
- allocationDestinationShareAta: (0, import_common34.toWeb3Pk)(
20130
+ manager: (0, import_common35.toWeb3Pk)(args.manager),
20131
+ allocationVault: (0, import_common35.toWeb3Pk)(args.allocationVault),
20132
+ sourceVault: args.sourceVault ? (0, import_common35.toWeb3Pk)(args.sourceVault) : null,
20133
+ sourceVaultOracle: args.sourceVaultOracle ? (0, import_common35.toWeb3Pk)(args.sourceVaultOracle) : null,
20134
+ destinationVault: (0, import_common35.toWeb3Pk)(args.destinationVault),
20135
+ destinationVaultOracle: (0, import_common35.toWeb3Pk)(args.destinationVaultOracle),
20136
+ mint: (0, import_common35.toWeb3Pk)(args.mint),
20137
+ sourceShareMint: args.sourceShareMint ? (0, import_common35.toWeb3Pk)(args.sourceShareMint) : null,
20138
+ destinationShareMint: (0, import_common35.toWeb3Pk)(args.destinationShareMint),
20139
+ allocationMintAta: (0, import_common35.toWeb3Pk)(args.allocationMintAta),
20140
+ sourceVaultMintAta: args.sourceVaultMintAta ? (0, import_common35.toWeb3Pk)(args.sourceVaultMintAta) : null,
20141
+ destinationVaultMintAta: (0, import_common35.toWeb3Pk)(args.destinationVaultMintAta),
20142
+ destinationFeeVault: (0, import_common35.toWeb3Pk)(args.destinationFeeVault),
20143
+ destinationFeeVaultMintAta: (0, import_common35.toWeb3Pk)(args.destinationFeeVaultMintAta),
20144
+ allocationSourceShareAta: args.allocationSourceShareAta ? (0, import_common35.toWeb3Pk)(args.allocationSourceShareAta) : null,
20145
+ allocationDestinationShareAta: (0, import_common35.toWeb3Pk)(
19976
20146
  args.allocationDestinationShareAta
19977
20147
  ),
19978
- sourceVaultTrancheState: args.sourceVaultTrancheState ? (0, import_common34.toWeb3Pk)(args.sourceVaultTrancheState) : null,
19979
- destinationVaultTrancheState: args.destinationVaultTrancheState ? (0, import_common34.toWeb3Pk)(args.destinationVaultTrancheState) : null,
19980
- assetOracleAccount: args.assetOracleAccount ? (0, import_common34.toWeb3Pk)(args.assetOracleAccount) : null,
19981
- assetTokenProgram: (0, import_common34.toWeb3Pk)(args.assetTokenProgram),
19982
- sourceShareTokenProgram: (0, import_common34.toWeb3Pk)(args.sourceShareTokenProgram),
19983
- destinationShareTokenProgram: (0, import_common34.toWeb3Pk)(
20148
+ sourceVaultTrancheState: args.sourceVaultTrancheState ? (0, import_common35.toWeb3Pk)(args.sourceVaultTrancheState) : null,
20149
+ destinationVaultTrancheState: args.destinationVaultTrancheState ? (0, import_common35.toWeb3Pk)(args.destinationVaultTrancheState) : null,
20150
+ assetOracleAccount: args.assetOracleAccount ? (0, import_common35.toWeb3Pk)(args.assetOracleAccount) : null,
20151
+ assetTokenProgram: (0, import_common35.toWeb3Pk)(args.assetTokenProgram),
20152
+ sourceShareTokenProgram: (0, import_common35.toWeb3Pk)(args.sourceShareTokenProgram),
20153
+ destinationShareTokenProgram: (0, import_common35.toWeb3Pk)(
19984
20154
  args.destinationShareTokenProgram
19985
20155
  ),
19986
20156
  associatedTokenProgram: import_spl_token17.ASSOCIATED_TOKEN_PROGRAM_ID,
19987
20157
  systemProgram: import_web318.SystemProgram.programId
19988
- }).instruction().then(import_common34.toKitInstruction);
20158
+ }).instruction().then(import_common35.toKitInstruction);
19989
20159
  }
19990
20160
  async deriveIxArgs(txArgs) {
19991
20161
  const assetTokenProgram = txArgs.assetTokenProgram ?? TOKEN_PROGRAM_ID;
@@ -20018,33 +20188,33 @@ var VaultReallocationBuilder = class extends VaultBuilderBase {
20018
20188
  assetTokenProgram,
20019
20189
  sourceShareTokenProgram,
20020
20190
  destinationShareTokenProgram,
20021
- allocationMintAta: (0, import_common34.getAtaAddress)(
20191
+ allocationMintAta: (0, import_common35.getAtaAddress)(
20022
20192
  txArgs.mint,
20023
20193
  txArgs.allocationVault,
20024
20194
  assetTokenProgram,
20025
20195
  true
20026
20196
  ),
20027
- sourceVaultMintAta: sourceVault ? (0, import_common34.getAtaAddress)(txArgs.mint, sourceVault, assetTokenProgram, true) : null,
20028
- destinationVaultMintAta: (0, import_common34.getAtaAddress)(
20197
+ sourceVaultMintAta: sourceVault ? (0, import_common35.getAtaAddress)(txArgs.mint, sourceVault, assetTokenProgram, true) : null,
20198
+ destinationVaultMintAta: (0, import_common35.getAtaAddress)(
20029
20199
  txArgs.mint,
20030
20200
  txArgs.destinationVault,
20031
20201
  assetTokenProgram,
20032
20202
  true
20033
20203
  ),
20034
20204
  destinationFeeVault,
20035
- destinationFeeVaultMintAta: (0, import_common34.getAtaAddress)(
20205
+ destinationFeeVaultMintAta: (0, import_common35.getAtaAddress)(
20036
20206
  txArgs.mint,
20037
20207
  destinationFeeVault,
20038
20208
  assetTokenProgram,
20039
20209
  true
20040
20210
  ),
20041
- allocationSourceShareAta: sourceShareMint && sourceVault ? (0, import_common34.getAtaAddress)(
20211
+ allocationSourceShareAta: sourceShareMint && sourceVault ? (0, import_common35.getAtaAddress)(
20042
20212
  sourceShareMint,
20043
20213
  txArgs.allocationVault,
20044
20214
  sourceShareTokenProgram,
20045
20215
  true
20046
20216
  ) : null,
20047
- allocationDestinationShareAta: (0, import_common34.getAtaAddress)(
20217
+ allocationDestinationShareAta: (0, import_common35.getAtaAddress)(
20048
20218
  txArgs.destinationShareMint,
20049
20219
  txArgs.allocationVault,
20050
20220
  destinationShareTokenProgram,
@@ -20053,38 +20223,38 @@ var VaultReallocationBuilder = class extends VaultBuilderBase {
20053
20223
  };
20054
20224
  }
20055
20225
  async buildPreambleInstructions(args) {
20056
- const payer = (0, import_common34.toWeb3Pk)(args.manager);
20226
+ const payer = (0, import_common35.toWeb3Pk)(args.manager);
20057
20227
  const instructions2 = [
20058
20228
  (0, import_spl_token17.createAssociatedTokenAccountIdempotentInstruction)(
20059
20229
  payer,
20060
- (0, import_common34.toWeb3Pk)(args.allocationMintAta),
20061
- (0, import_common34.toWeb3Pk)(args.allocationVault),
20062
- (0, import_common34.toWeb3Pk)(args.mint),
20063
- (0, import_common34.toWeb3Pk)(args.assetTokenProgram),
20230
+ (0, import_common35.toWeb3Pk)(args.allocationMintAta),
20231
+ (0, import_common35.toWeb3Pk)(args.allocationVault),
20232
+ (0, import_common35.toWeb3Pk)(args.mint),
20233
+ (0, import_common35.toWeb3Pk)(args.assetTokenProgram),
20064
20234
  import_spl_token17.ASSOCIATED_TOKEN_PROGRAM_ID
20065
20235
  ),
20066
20236
  (0, import_spl_token17.createAssociatedTokenAccountIdempotentInstruction)(
20067
20237
  payer,
20068
- (0, import_common34.toWeb3Pk)(args.destinationVaultMintAta),
20069
- (0, import_common34.toWeb3Pk)(args.destinationVault),
20070
- (0, import_common34.toWeb3Pk)(args.mint),
20071
- (0, import_common34.toWeb3Pk)(args.assetTokenProgram),
20238
+ (0, import_common35.toWeb3Pk)(args.destinationVaultMintAta),
20239
+ (0, import_common35.toWeb3Pk)(args.destinationVault),
20240
+ (0, import_common35.toWeb3Pk)(args.mint),
20241
+ (0, import_common35.toWeb3Pk)(args.assetTokenProgram),
20072
20242
  import_spl_token17.ASSOCIATED_TOKEN_PROGRAM_ID
20073
20243
  ),
20074
20244
  (0, import_spl_token17.createAssociatedTokenAccountIdempotentInstruction)(
20075
20245
  payer,
20076
- (0, import_common34.toWeb3Pk)(args.destinationFeeVaultMintAta),
20077
- (0, import_common34.toWeb3Pk)(args.destinationFeeVault),
20078
- (0, import_common34.toWeb3Pk)(args.mint),
20079
- (0, import_common34.toWeb3Pk)(args.assetTokenProgram),
20246
+ (0, import_common35.toWeb3Pk)(args.destinationFeeVaultMintAta),
20247
+ (0, import_common35.toWeb3Pk)(args.destinationFeeVault),
20248
+ (0, import_common35.toWeb3Pk)(args.mint),
20249
+ (0, import_common35.toWeb3Pk)(args.assetTokenProgram),
20080
20250
  import_spl_token17.ASSOCIATED_TOKEN_PROGRAM_ID
20081
20251
  ),
20082
20252
  (0, import_spl_token17.createAssociatedTokenAccountIdempotentInstruction)(
20083
20253
  payer,
20084
- (0, import_common34.toWeb3Pk)(args.allocationDestinationShareAta),
20085
- (0, import_common34.toWeb3Pk)(args.allocationVault),
20086
- (0, import_common34.toWeb3Pk)(args.destinationShareMint),
20087
- (0, import_common34.toWeb3Pk)(args.destinationShareTokenProgram),
20254
+ (0, import_common35.toWeb3Pk)(args.allocationDestinationShareAta),
20255
+ (0, import_common35.toWeb3Pk)(args.allocationVault),
20256
+ (0, import_common35.toWeb3Pk)(args.destinationShareMint),
20257
+ (0, import_common35.toWeb3Pk)(args.destinationShareTokenProgram),
20088
20258
  import_spl_token17.ASSOCIATED_TOKEN_PROGRAM_ID
20089
20259
  )
20090
20260
  ];
@@ -20092,23 +20262,23 @@ var VaultReallocationBuilder = class extends VaultBuilderBase {
20092
20262
  instructions2.push(
20093
20263
  (0, import_spl_token17.createAssociatedTokenAccountIdempotentInstruction)(
20094
20264
  payer,
20095
- (0, import_common34.toWeb3Pk)(args.sourceVaultMintAta),
20096
- (0, import_common34.toWeb3Pk)(args.sourceVault),
20097
- (0, import_common34.toWeb3Pk)(args.mint),
20098
- (0, import_common34.toWeb3Pk)(args.assetTokenProgram),
20265
+ (0, import_common35.toWeb3Pk)(args.sourceVaultMintAta),
20266
+ (0, import_common35.toWeb3Pk)(args.sourceVault),
20267
+ (0, import_common35.toWeb3Pk)(args.mint),
20268
+ (0, import_common35.toWeb3Pk)(args.assetTokenProgram),
20099
20269
  import_spl_token17.ASSOCIATED_TOKEN_PROGRAM_ID
20100
20270
  ),
20101
20271
  (0, import_spl_token17.createAssociatedTokenAccountIdempotentInstruction)(
20102
20272
  payer,
20103
- (0, import_common34.toWeb3Pk)(args.allocationSourceShareAta),
20104
- (0, import_common34.toWeb3Pk)(args.allocationVault),
20105
- (0, import_common34.toWeb3Pk)(args.sourceShareMint),
20106
- (0, import_common34.toWeb3Pk)(args.sourceShareTokenProgram),
20273
+ (0, import_common35.toWeb3Pk)(args.allocationSourceShareAta),
20274
+ (0, import_common35.toWeb3Pk)(args.allocationVault),
20275
+ (0, import_common35.toWeb3Pk)(args.sourceShareMint),
20276
+ (0, import_common35.toWeb3Pk)(args.sourceShareTokenProgram),
20107
20277
  import_spl_token17.ASSOCIATED_TOKEN_PROGRAM_ID
20108
20278
  )
20109
20279
  );
20110
20280
  }
20111
- return instructions2.map(import_common34.toKitInstruction);
20281
+ return instructions2.map(import_common35.toKitInstruction);
20112
20282
  }
20113
20283
  async buildPlanExtras(args) {
20114
20284
  return {
@@ -20213,7 +20383,7 @@ var VaultClient = class {
20213
20383
  async sendTransaction(payer, plan, extraSigners = []) {
20214
20384
  const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash("confirmed");
20215
20385
  const tx = new import_web319.Transaction().add(
20216
- ...plan.instructions.map(import_common35.fromKitInstruction)
20386
+ ...plan.instructions.map(import_common36.fromKitInstruction)
20217
20387
  );
20218
20388
  tx.feePayer = payer.publicKey;
20219
20389
  tx.recentBlockhash = blockhash;
@@ -20240,11 +20410,11 @@ var VaultClient = class {
20240
20410
  const { blockhash } = await this.provider.connection.getLatestBlockhash(
20241
20411
  "confirmed"
20242
20412
  );
20243
- const lookupTableAccounts = plan.lookupTables?.length ? await (0, import_common35.fetchLookupTables)(this.provider.connection, plan.lookupTables) : [];
20413
+ const lookupTableAccounts = plan.lookupTables?.length ? await (0, import_common36.fetchLookupTables)(this.provider.connection, plan.lookupTables) : [];
20244
20414
  const message2 = new import_web319.TransactionMessage({
20245
20415
  payerKey: payer.publicKey,
20246
20416
  recentBlockhash: blockhash,
20247
- instructions: plan.instructions.map(import_common35.fromKitInstruction)
20417
+ instructions: plan.instructions.map(import_common36.fromKitInstruction)
20248
20418
  }).compileToV0Message(lookupTableAccounts);
20249
20419
  const tx = new import_web319.VersionedTransaction(message2);
20250
20420
  const result = await this.provider.connection.simulateTransaction(tx, {
@@ -20322,7 +20492,11 @@ function loadKeypair(keypairPath) {
20322
20492
  const raw = import_fs.default.readFileSync(resolveKeypairPath(keypairPath), "utf-8");
20323
20493
  return import_web320.Keypair.fromSecretKey(new Uint8Array(JSON.parse(raw)));
20324
20494
  }
20495
+ var ENV_AGNOSTIC_ROLES = /* @__PURE__ */ new Set(["fulfiller", "rebalancer"]);
20325
20496
  function defaultKeypairPath(env, role = "vault") {
20497
+ if (ENV_AGNOSTIC_ROLES.has(role)) {
20498
+ return `~/.config/solana/${role}.json`;
20499
+ }
20326
20500
  return `~/.config/solana/${role}-${env}.json`;
20327
20501
  }
20328
20502
  function createVaultClient(env, opts = {}) {
@@ -20340,11 +20514,11 @@ function createVaultClient(env, opts = {}) {
20340
20514
  client,
20341
20515
  provider,
20342
20516
  payer,
20343
- signer: (0, import_common36.fromWeb3Pk)(payer.publicKey)
20517
+ signer: (0, import_common37.fromWeb3Pk)(payer.publicKey)
20344
20518
  };
20345
20519
  }
20346
20520
  function keypairAddress(keypairPath) {
20347
- return (0, import_common36.fromWeb3Pk)(loadKeypair(keypairPath).publicKey);
20521
+ return (0, import_common37.fromWeb3Pk)(loadKeypair(keypairPath).publicKey);
20348
20522
  }
20349
20523
 
20350
20524
  // src/utils/math.ts
@@ -20482,7 +20656,7 @@ async function prepareVaultTransaction(args) {
20482
20656
  // src/utils/token.ts
20483
20657
  var import_spl_token18 = require("@solana/spl-token");
20484
20658
  var import_web322 = require("@solana/web3.js");
20485
- var import_common37 = __toESM(require_dist());
20659
+ var import_common38 = __toESM(require_dist());
20486
20660
  async function createTokenMintIxs(connection, payer, authority, decimals, tokenProgram = import_spl_token18.TOKEN_2022_PROGRAM_ID) {
20487
20661
  const mint = import_web322.Keypair.generate();
20488
20662
  const lamports = await (0, import_spl_token18.getMinimumBalanceForRentExemptMint)(connection);
@@ -20527,7 +20701,7 @@ async function createTokenMint(connection, payer, decimals, tokenProgram = impor
20527
20701
  return mint.publicKey;
20528
20702
  }
20529
20703
  async function mintTokensTo(connection, payer, mint, destination, amount, tokenProgram = import_spl_token18.TOKEN_2022_PROGRAM_ID, allowOwnerOffCurve = false) {
20530
- const tokenProgramPk = (0, import_common37.asWeb3PublicKey)(tokenProgram);
20704
+ const tokenProgramPk = (0, import_common38.asWeb3PublicKey)(tokenProgram);
20531
20705
  const ata = (0, import_spl_token18.getAssociatedTokenAddressSync)(
20532
20706
  mint,
20533
20707
  destination,
@@ -20806,7 +20980,7 @@ async function getTotalOutstandingYield(accountNames, start, end) {
20806
20980
  }
20807
20981
 
20808
20982
  // src/services/withdrawalQueueService.ts
20809
- var import_common38 = __toESM(require_dist());
20983
+ var import_common39 = __toESM(require_dist());
20810
20984
  function bnToBigInt(value) {
20811
20985
  return BigInt(value.toString());
20812
20986
  }
@@ -20827,7 +21001,7 @@ var WithdrawalQueueService = class {
20827
21001
  const program = this.client.program.account;
20828
21002
  const accounts2 = await program.vaultWithdrawalQueue.all();
20829
21003
  return accounts2.map(
20830
- (entry) => this.toSnapshot((0, import_common38.fromWeb3Pk)(entry.publicKey), entry.account)
21004
+ (entry) => this.toSnapshot((0, import_common39.fromWeb3Pk)(entry.publicKey), entry.account)
20831
21005
  );
20832
21006
  }
20833
21007
  /** Withdrawal queues for a single vault. */
@@ -20868,7 +21042,7 @@ var WithdrawalQueueService = class {
20868
21042
  async fulfill(signer, queue) {
20869
21043
  const plan = await this.client.tx.fulfillJuniorTrancheWithdraw.getTx({
20870
21044
  owner: queue.owner,
20871
- signer: (0, import_common38.fromWeb3Pk)(signer.publicKey),
21045
+ signer: (0, import_common39.fromWeb3Pk)(signer.publicKey),
20872
21046
  queuePayer: queue.payer,
20873
21047
  vault: queue.vault,
20874
21048
  withdrawalQueue: queue.pda,
@@ -20901,6 +21075,9 @@ var WithdrawalQueueService = class {
20901
21075
  continue;
20902
21076
  }
20903
21077
  try {
21078
+ log?.(
21079
+ `fulfilling ${queue.pda} \u2014 paying ${queue.inputAmount} junior shares worth of ${queue.outputMint} to owner ${queue.owner}`
21080
+ );
20904
21081
  const sig = await this.fulfill(signer, queue);
20905
21082
  summary.fulfilled += 1;
20906
21083
  summary.signatures.push(sig);
@@ -20919,12 +21096,12 @@ var WithdrawalQueueService = class {
20919
21096
  const a = account;
20920
21097
  return {
20921
21098
  pda,
20922
- vault: (0, import_common38.fromWeb3Pk)(a.parties.vault),
20923
- owner: (0, import_common38.fromWeb3Pk)(a.parties.owner),
20924
- payer: (0, import_common38.fromWeb3Pk)(a.parties.payer),
21099
+ vault: (0, import_common39.fromWeb3Pk)(a.parties.vault),
21100
+ owner: (0, import_common39.fromWeb3Pk)(a.parties.owner),
21101
+ payer: (0, import_common39.fromWeb3Pk)(a.parties.payer),
20925
21102
  queueId: a.header.queueId,
20926
- inputMint: (0, import_common38.fromWeb3Pk)(a.mints.inputMint),
20927
- outputMint: (0, import_common38.fromWeb3Pk)(a.mints.outputMint),
21103
+ inputMint: (0, import_common39.fromWeb3Pk)(a.mints.inputMint),
21104
+ outputMint: (0, import_common39.fromWeb3Pk)(a.mints.outputMint),
20928
21105
  inputAmount: bnToBigInt(a.request.inputAmount),
20929
21106
  requestTs: bnToNumber(a.request.requestTs),
20930
21107
  expiryTs: bnToNumber(a.request.expiryTs)
@@ -20934,7 +21111,7 @@ var WithdrawalQueueService = class {
20934
21111
 
20935
21112
  // src/services/oracleService.ts
20936
21113
  var import_kit11 = require("@solana/kit");
20937
- var import_common39 = __toESM(require_dist());
21114
+ var import_common40 = __toESM(require_dist());
20938
21115
  var SYSTEM_PROGRAM = "11111111111111111111111111111111";
20939
21116
  var DEFAULT_PRICE_STALENESS_THRESHOLD_SECS2 = 86400n;
20940
21117
  var PRICE_ORACLE_TYPES_BY_INDEX = [
@@ -20998,7 +21175,7 @@ var OracleService = class {
20998
21175
  */
20999
21176
  async updateAssetConsensusPrice(signer, args, log) {
21000
21177
  const plan = await this.client.tx.updateConsensusOracle.getTx({
21001
- signer: (0, import_common39.fromWeb3Pk)(signer.publicKey),
21178
+ signer: (0, import_common40.fromWeb3Pk)(signer.publicKey),
21002
21179
  vault: args.vault,
21003
21180
  updates: args.updates,
21004
21181
  assetMint: args.assetMint,
@@ -21014,7 +21191,7 @@ var OracleService = class {
21014
21191
  /** Settle the vault NAV from its current holdings (permissionless). */
21015
21192
  async crankNav(cranker, args, log) {
21016
21193
  const plan = await this.client.tx.crankNav.getTx({
21017
- cranker: (0, import_common39.fromWeb3Pk)(cranker.publicKey),
21194
+ cranker: (0, import_common40.fromWeb3Pk)(cranker.publicKey),
21018
21195
  vault: args.vault,
21019
21196
  vaultTrancheState: args.vaultTrancheState
21020
21197
  });
@@ -21087,7 +21264,7 @@ var OracleService = class {
21087
21264
  /** Re-price one live-oracle holding from its bound Pyth/nested-vault account. */
21088
21265
  async refreshAssetPrice(updater, args, log) {
21089
21266
  const plan = await this.client.tx.updateAssetPrice.getTx({
21090
- updater: (0, import_common39.fromWeb3Pk)(updater.publicKey),
21267
+ updater: (0, import_common40.fromWeb3Pk)(updater.publicKey),
21091
21268
  vault: args.vault,
21092
21269
  mint: args.mint,
21093
21270
  oracleAccount: args.oracleAccount,
@@ -21209,10 +21386,10 @@ function toBigInt2(value) {
21209
21386
 
21210
21387
  // src/services/consensusOracle/utils/holdings.ts
21211
21388
  var import_web323 = require("@solana/web3.js");
21212
- var import_common40 = __toESM(require_dist());
21389
+ var import_common41 = __toESM(require_dist());
21213
21390
  function selectReportableHoldings(holdings, excludedMints = /* @__PURE__ */ new Set()) {
21214
21391
  return holdings.map((holding, holdingIndex) => ({ holding, holdingIndex })).filter(({ holding }) => {
21215
- const mint = (0, import_common40.fromWeb3Pk)(holding.mint);
21392
+ const mint = (0, import_common41.fromWeb3Pk)(holding.mint);
21216
21393
  return mint !== SYSTEM_PROGRAM2 && !excludedMints.has(mint.toString()) && REPORTABLE_ORACLE_VARIANTS.has(
21217
21394
  variantName2(holding.priceOracleType).toLowerCase()
21218
21395
  );
@@ -21308,7 +21485,7 @@ async function collectSamples(read, { samples, minSamples, onError }) {
21308
21485
 
21309
21486
  // src/services/consensusOracle/pipeline/dryRunSettlement.ts
21310
21487
  var import_web325 = require("@solana/web3.js");
21311
- var import_common41 = __toESM(require_dist());
21488
+ var import_common42 = __toESM(require_dist());
21312
21489
 
21313
21490
  // src/services/consensusOracle/settlement/settlementSimulator.ts
21314
21491
  var import_kit12 = require("@solana/kit");
@@ -21608,21 +21785,27 @@ function settleVault(args) {
21608
21785
  args.grossNav,
21609
21786
  args.nowTs
21610
21787
  );
21788
+ const trancheValueBeforeFees = args.tranche.junior.value + args.tranche.senior.value;
21789
+ const juniorFees = settleShareClassPerformanceFee(
21790
+ args.tranche.junior,
21791
+ args.performanceFeeBps,
21792
+ args.protocolFeeBps
21793
+ );
21794
+ const juniorFloorTopup = applyJuniorFloorTopup(
21795
+ args.tranche,
21796
+ regularGrossValue,
21797
+ args.nowTs
21798
+ );
21611
21799
  regularValue = settleFixedApyNav({
21612
21800
  currentSharePrice: args.currentSharePrice,
21613
- reportedNav: regularGrossValue,
21801
+ reportedNav: regularGrossValue - juniorFloorTopup,
21614
21802
  nowTs: args.nowTs,
21615
21803
  totalSupply: args.totalSupply,
21616
21804
  fixedApyBps: args.fixedApyBps,
21617
21805
  anchorSharePrice: args.apyAnchorSharePrice,
21618
21806
  anchorTs: args.apyAnchorTs
21619
21807
  });
21620
- settledAccountingNav = regularValue + args.tranche.junior.value + args.tranche.senior.value;
21621
- const juniorFees = settleShareClassPerformanceFee(
21622
- args.tranche.junior,
21623
- args.performanceFeeBps,
21624
- args.protocolFeeBps
21625
- );
21808
+ settledAccountingNav = regularValue + trancheValueBeforeFees + juniorFloorTopup;
21626
21809
  const regularFees = settleRegularPerformanceFee(
21627
21810
  regularValue,
21628
21811
  args.totalSupply,
@@ -21743,6 +21926,31 @@ function seniorEntitlement(tranche, nowTs) {
21743
21926
  );
21744
21927
  return targetValue > tranche.senior.value ? targetValue - tranche.senior.value : 0n;
21745
21928
  }
21929
+ function applyJuniorFloorTopup(tranche, availableRegularValue, nowTs) {
21930
+ if (tranche.juniorApyAnchorTs <= 0n) {
21931
+ tranche.juniorApyAnchorSharePrice = tranche.junior.sharePrice;
21932
+ tranche.juniorApyAnchorTs = tranche.lastSettledTs > 0n ? tranche.lastSettledTs : nowTs;
21933
+ }
21934
+ if (tranche.juniorFloorApyBps === 0 || tranche.juniorApyAnchorSharePrice === 0n || tranche.junior.totalSupply === 0n || tranche.juniorApyAnchorTs <= 0n || nowTs <= tranche.juniorApyAnchorTs) {
21935
+ return 0n;
21936
+ }
21937
+ const targetPrice = applyEffectiveApy(
21938
+ tranche.juniorApyAnchorSharePrice,
21939
+ tranche.juniorFloorApyBps,
21940
+ nowTs - tranche.juniorApyAnchorTs
21941
+ );
21942
+ const targetValue = mulDiv2(
21943
+ targetPrice,
21944
+ tranche.junior.totalSupply,
21945
+ DEFAULT_SHARE_PRICE
21946
+ );
21947
+ const shortfall = targetValue > tranche.junior.value ? targetValue - tranche.junior.value : 0n;
21948
+ const topup = shortfall < availableRegularValue ? shortfall : availableRegularValue;
21949
+ if (topup === 0n) return 0n;
21950
+ tranche.junior.value += topup;
21951
+ refreshShareClass(tranche.junior);
21952
+ return topup;
21953
+ }
21746
21954
  function settleShareClassPerformanceFee(shareClass, performanceFeeBps, protocolFeeBps) {
21747
21955
  refreshShareClass(shareClass);
21748
21956
  const grossPrice = shareClass.sharePrice;
@@ -21963,9 +22171,12 @@ function decodeTrancheState(decoded, args, warnings, blockers) {
21963
22171
  junior,
21964
22172
  senior,
21965
22173
  seniorFixedApyBps: number(decoded.config.seniorFixedApyBps),
22174
+ juniorFloorApyBps: number(decoded.config.juniorFloorApyBps),
21966
22175
  lastSettledTs: bigint(decoded.lastSettledTs),
21967
22176
  seniorApyAnchorSharePrice: bigint(decoded.seniorApyAnchorSharePrice),
21968
- seniorApyAnchorTs: bigint(decoded.seniorApyAnchorTs)
22177
+ seniorApyAnchorTs: bigint(decoded.seniorApyAnchorTs),
22178
+ juniorApyAnchorSharePrice: bigint(decoded.juniorApyAnchorSharePrice),
22179
+ juniorApyAnchorTs: bigint(decoded.juniorApyAnchorTs)
21969
22180
  };
21970
22181
  }
21971
22182
  function decodeShareClass(value) {
@@ -22338,7 +22549,7 @@ async function simulateDryRunSettlement({
22338
22549
  oracleData: oracleState.data,
22339
22550
  trancheState,
22340
22551
  updates,
22341
- signer: (0, import_common41.fromWeb3Pk)(signer.publicKey),
22552
+ signer: (0, import_common42.fromWeb3Pk)(signer.publicKey),
22342
22553
  nowTs: nowSecs,
22343
22554
  physicalShareSupply: supplies[0],
22344
22555
  physicalJuniorSupply: tranchingEnabled ? supplies[1] : void 0,
@@ -22347,7 +22558,7 @@ async function simulateDryRunSettlement({
22347
22558
  }
22348
22559
 
22349
22560
  // src/services/consensusOracle/pipeline/holdingUpdates.ts
22350
- var import_common42 = __toESM(require_dist());
22561
+ var import_common43 = __toESM(require_dist());
22351
22562
  async function buildUpdates(yieldTracker, reportableHoldings, inputs) {
22352
22563
  const updates = [];
22353
22564
  for (const entry of reportableHoldings) {
@@ -22357,7 +22568,7 @@ async function buildUpdates(yieldTracker, reportableHoldings, inputs) {
22357
22568
  }
22358
22569
  async function buildHoldingUpdate(yieldTracker, entry, inputs) {
22359
22570
  const { holding, holdingIndex } = entry;
22360
- const mint = (0, import_common42.fromWeb3Pk)(holding.mint);
22571
+ const mint = (0, import_common43.fromWeb3Pk)(holding.mint);
22361
22572
  const mintKey = mint.toString();
22362
22573
  const oracleType = variantName2(holding.priceOracleType).toLowerCase();
22363
22574
  let usd;
@@ -22407,13 +22618,13 @@ async function resolveTrackedAmounts(yieldTracker, cfg, decimals) {
22407
22618
  cfg.yieldAccountNames
22408
22619
  );
22409
22620
  return {
22410
- principalAmount: tracked.principal > 0 ? (0, import_common42.fromUiAmount)(tracked.principal, decimals) : 0n,
22411
- yieldAmount: tracked.outstandingYield > 0 ? (0, import_common42.fromUiAmount)(tracked.outstandingYield, decimals) : 0n
22621
+ principalAmount: tracked.principal > 0 ? (0, import_common43.fromUiAmount)(tracked.principal, decimals) : 0n,
22622
+ yieldAmount: tracked.outstandingYield > 0 ? (0, import_common43.fromUiAmount)(tracked.outstandingYield, decimals) : 0n
22412
22623
  };
22413
22624
  }
22414
22625
 
22415
22626
  // src/services/consensusOracle/pipeline/livePriceRefresh.ts
22416
- var import_common43 = __toESM(require_dist());
22627
+ var import_common44 = __toESM(require_dist());
22417
22628
  async function refreshLiveOraclePrices({
22418
22629
  oracle,
22419
22630
  signer,
@@ -22432,7 +22643,7 @@ async function refreshLiveOraclePrices({
22432
22643
  for (const holding of vaultState.holdings) {
22433
22644
  const oracleType = variantName2(holding.priceOracleType).toLowerCase();
22434
22645
  if (!LIVE_ORACLE_VARIANTS.has(oracleType)) continue;
22435
- const mint = (0, import_common43.fromWeb3Pk)(holding.mint);
22646
+ const mint = (0, import_common44.fromWeb3Pk)(holding.mint);
22436
22647
  if (mint.toString() === SYSTEM_PROGRAM2) continue;
22437
22648
  const activeAmount = toBigInt2(holding.localAmount) + toBigInt2(holding.externalAmount);
22438
22649
  if (activeAmount === 0n) continue;
@@ -22447,7 +22658,7 @@ async function refreshLiveOraclePrices({
22447
22658
  );
22448
22659
  continue;
22449
22660
  }
22450
- const oracleAccount = (0, import_common43.fromWeb3Pk)(holding.priceOracleAccount);
22661
+ const oracleAccount = (0, import_common44.fromWeb3Pk)(holding.priceOracleAccount);
22451
22662
  if (oracleAccount.toString() === SYSTEM_PROGRAM2) {
22452
22663
  log(
22453
22664
  `vault ${vault}: cannot refresh ${mint}; ${oracleType} holding has no oracle account`
@@ -22471,15 +22682,15 @@ async function refreshLiveOraclePrices({
22471
22682
  }
22472
22683
 
22473
22684
  // src/services/consensusOracle/pipeline/pricingInputs.ts
22474
- var import_common44 = __toESM(require_dist());
22685
+ var import_common45 = __toESM(require_dist());
22475
22686
  async function gatherPricingInputs(deps, target, vaultState, reportableHoldings, log = () => {
22476
22687
  }) {
22477
- const manager = (0, import_common44.fromWeb3Pk)(vaultState.roles.manager);
22688
+ const manager = (0, import_common45.fromWeb3Pk)(vaultState.roles.manager);
22478
22689
  const consensusMints = reportableHoldings.filter(
22479
22690
  ({ holding }) => variantName2(holding.priceOracleType).toLowerCase() === CONSENSUS_ORACLE_VARIANT
22480
- ).map(({ holding }) => (0, import_common44.fromWeb3Pk)(holding.mint));
22691
+ ).map(({ holding }) => (0, import_common45.fromWeb3Pk)(holding.mint));
22481
22692
  const baseHolding = vaultState.holdings.find((h) => coerceBool3(h.isBase));
22482
- const baseMint = baseHolding ? (0, import_common44.fromWeb3Pk)(baseHolding.mint) : consensusMints[0];
22693
+ const baseMint = baseHolding ? (0, import_common45.fromWeb3Pk)(baseHolding.mint) : consensusMints[0];
22483
22694
  if (!baseMint) {
22484
22695
  throw new Error(`vault has no holdings \u2014 cannot determine base asset`);
22485
22696
  }
@@ -22572,11 +22783,11 @@ function reconcilePositionSnapshots(snapshots, vault, log) {
22572
22783
  }
22573
22784
 
22574
22785
  // src/services/consensusOracle/pipeline/receiptMints.ts
22575
- var import_common45 = __toESM(require_dist());
22786
+ var import_common46 = __toESM(require_dist());
22576
22787
  async function fetchReceiptMints(client, vault, vaultState) {
22577
22788
  const receiptMints = /* @__PURE__ */ new Set();
22578
22789
  if (vaultState.mint) {
22579
- receiptMints.add((0, import_common45.fromWeb3Pk)(vaultState.mint).toString());
22790
+ receiptMints.add((0, import_common46.fromWeb3Pk)(vaultState.mint).toString());
22580
22791
  }
22581
22792
  if (!coerceBool3(vaultState.tranchingEnabled)) return receiptMints;
22582
22793
  const trancheState = await client.account.fetchVaultTrancheStateForVault(
@@ -22584,19 +22795,19 @@ async function fetchReceiptMints(client, vault, vaultState) {
22584
22795
  { fresh: true }
22585
22796
  );
22586
22797
  receiptMints.add(
22587
- (0, import_common45.fromWeb3Pk)(trancheState.config.juniorMint).toString()
22798
+ (0, import_common46.fromWeb3Pk)(trancheState.config.juniorMint).toString()
22588
22799
  );
22589
22800
  receiptMints.add(
22590
- (0, import_common45.fromWeb3Pk)(trancheState.config.seniorMint).toString()
22801
+ (0, import_common46.fromWeb3Pk)(trancheState.config.seniorMint).toString()
22591
22802
  );
22592
22803
  return receiptMints;
22593
22804
  }
22594
22805
 
22595
22806
  // src/services/consensusOracle/pipeline/settlement.ts
22596
- var import_common47 = __toESM(require_dist());
22807
+ var import_common48 = __toESM(require_dist());
22597
22808
 
22598
22809
  // src/services/consensusOracle/pipeline/yieldAccounts.ts
22599
- var import_common46 = __toESM(require_dist());
22810
+ var import_common47 = __toESM(require_dist());
22600
22811
  async function assertNoUnconfirmedYieldPayments(yieldTracker, target) {
22601
22812
  const accountNames = [
22602
22813
  ...new Set(
@@ -22636,7 +22847,7 @@ async function withDiscoveredYieldAccounts(yieldTracker, target, vaultState, exc
22636
22847
  );
22637
22848
  if (namesToAttach.length === 0) return target;
22638
22849
  const baseHolding = vaultState.holdings.find((holding) => {
22639
- const mint = (0, import_common46.fromWeb3Pk)(holding.mint).toString();
22850
+ const mint = (0, import_common47.fromWeb3Pk)(holding.mint).toString();
22640
22851
  return coerceBool3(holding.isBase) && !excludedMints.has(mint);
22641
22852
  });
22642
22853
  if (!baseHolding) {
@@ -22644,7 +22855,7 @@ async function withDiscoveredYieldAccounts(yieldTracker, target, vaultState, exc
22644
22855
  `vault ${target.vault}: tagged yield accounts found but no base holding is available`
22645
22856
  );
22646
22857
  }
22647
- const baseMint = (0, import_common46.fromWeb3Pk)(baseHolding.mint);
22858
+ const baseMint = (0, import_common47.fromWeb3Pk)(baseHolding.mint);
22648
22859
  const holdings = [...target.holdings ?? []];
22649
22860
  const existingIndex = holdings.findIndex(
22650
22861
  (holding) => holding.mint.toString() === baseMint.toString()
@@ -22735,7 +22946,7 @@ async function logProspectiveApy({
22735
22946
  );
22736
22947
  const prospectiveNav = vaultState.holdings.reduce(
22737
22948
  (sum, holding, holdingIndex) => {
22738
- const mint = (0, import_common47.fromWeb3Pk)(holding.mint).toString();
22949
+ const mint = (0, import_common48.fromWeb3Pk)(holding.mint).toString();
22739
22950
  if (mint === SYSTEM_PROGRAM2) return sum;
22740
22951
  const update = updatesByIndex.get(holdingIndex);
22741
22952
  const localAmount = toBigInt2(holding.localAmount);
@@ -23244,7 +23455,7 @@ function createLiveConsensusOracleDeps(connection, opts = {}) {
23244
23455
  }
23245
23456
 
23246
23457
  // src/services/consensusOracle/consensusOracleService.ts
23247
- var import_common48 = __toESM(require_dist());
23458
+ var import_common49 = __toESM(require_dist());
23248
23459
  var ConsensusOracleService = class {
23249
23460
  constructor(client, deps) {
23250
23461
  this.client = client;
@@ -23280,7 +23491,7 @@ var ConsensusOracleService = class {
23280
23491
  receiptMints
23281
23492
  );
23282
23493
  const filteredCount = vaultState.holdings.filter(
23283
- (holding) => receiptMints.has((0, import_common48.fromWeb3Pk)(holding.mint).toString())
23494
+ (holding) => receiptMints.has((0, import_common49.fromWeb3Pk)(holding.mint).toString())
23284
23495
  ).length;
23285
23496
  if (filteredCount > 0) {
23286
23497
  log(
@@ -23456,9 +23667,12 @@ async function runLiveConsensusOracle(env, oracleSigner, opts = {}) {
23456
23667
  // src/services/externalLiquidityIntegrityService.ts
23457
23668
  var import_kit15 = require("@solana/kit");
23458
23669
  var import_web328 = require("@solana/web3.js");
23459
- var import_common49 = __toESM(require_dist());
23670
+ var import_common50 = __toESM(require_dist());
23460
23671
  var import_marginfi3 = __toESM(require_dist2());
23461
23672
  var DEFAULT_MIN_AMOUNT_UI = 1;
23673
+ var DEFAULT_TARGET_LOCAL_BPS = 100;
23674
+ var DEFAULT_REBALANCE_BAND_BPS = 2e3;
23675
+ var BPS_DENOMINATOR3 = 10000n;
23462
23676
  function toRawAmount(uiAmount, decimals) {
23463
23677
  return BigInt(Math.floor(uiAmount * 10 ** decimals));
23464
23678
  }
@@ -23475,7 +23689,7 @@ function parseActiveSlots(externalLiquidity) {
23475
23689
  if (discriminant === 0) continue;
23476
23690
  if (discriminant !== 1) continue;
23477
23691
  const pubkeyBytes = new Uint8Array(data.slice(8, 40));
23478
- const userAccount = (0, import_common49.toAddress)(new import_web328.PublicKey(pubkeyBytes));
23692
+ const userAccount = (0, import_common50.toAddress)(new import_web328.PublicKey(pubkeyBytes));
23479
23693
  results.push({ index: i, source: "marginfi", userAccount });
23480
23694
  }
23481
23695
  return results;
@@ -23495,26 +23709,50 @@ function pubkeyStr(value) {
23495
23709
  function isZeroPubkey2(pk) {
23496
23710
  return !pk || /^1+$/.test(pk) || pk === "11111111111111111111111111111111";
23497
23711
  }
23712
+ function planRebalance(params) {
23713
+ const { localAmount, externalAmount, targetLocalBps, rebalanceBandBps, minRaw } = params;
23714
+ const total = localAmount + externalAmount;
23715
+ const targetLocal = total * BigInt(Math.round(targetLocalBps)) / BPS_DENOMINATOR3;
23716
+ const band = targetLocal * BigInt(Math.round(rebalanceBandBps)) / BPS_DENOMINATOR3;
23717
+ const threshold = band > minRaw ? band : minRaw;
23718
+ if (localAmount > targetLocal) {
23719
+ const amount2 = localAmount - targetLocal;
23720
+ if (amount2 < threshold) return null;
23721
+ return { direction: "deposit", amount: amount2, targetLocal };
23722
+ }
23723
+ const shortfall = targetLocal - localAmount;
23724
+ if (shortfall < threshold) return null;
23725
+ const amount = shortfall < externalAmount ? shortfall : externalAmount;
23726
+ if (amount < minRaw) return null;
23727
+ return { direction: "withdraw", amount, targetLocal };
23728
+ }
23498
23729
  var ExternalLiquidityIntegrityService = class {
23499
23730
  constructor(client) {
23500
23731
  this.client = client;
23501
23732
  }
23502
23733
  /**
23503
- * Scan all vaults and deposit any idle local balance into configured external
23504
- * liquidity positions. Non-fatal per vault — errors are logged and counted.
23734
+ * Scan all vaults and rebalance each holding toward its target local share.
23735
+ * Non-fatal per vault — errors are logged and counted.
23505
23736
  */
23506
23737
  async runAll(hwManager, opts = {}) {
23507
23738
  const log = opts.log ?? (() => {
23508
23739
  });
23509
23740
  const dryRun = opts.dryRun ?? false;
23510
23741
  const minAmountUi = opts.minAmountUi ?? DEFAULT_MIN_AMOUNT_UI;
23511
- if (dryRun) log("DRY RUN \u2014 deposits will be simulated, not sent");
23512
- log(`Minimum deposit: ${minAmountUi} token(s) (~$${minAmountUi})`);
23742
+ const targetLocalBps = opts.targetLocalBps ?? DEFAULT_TARGET_LOCAL_BPS;
23743
+ const rebalanceBandBps = opts.rebalanceBandBps ?? DEFAULT_REBALANCE_BAND_BPS;
23744
+ if (dryRun) log("DRY RUN \u2014 rebalances will be simulated, not sent");
23745
+ log(`Minimum rebalance: ${minAmountUi} token(s) (~$${minAmountUi})`);
23746
+ log(`Target local share: ${targetLocalBps / 100}% of each holding`);
23747
+ log(
23748
+ `Rebalance band: ${rebalanceBandBps / 100}% of target (${targetLocalBps * (1 - rebalanceBandBps / 1e4) / 100}%\u2013${targetLocalBps * (1 + rebalanceBandBps / 1e4) / 100}% of holding)`
23749
+ );
23513
23750
  const allVaults = await this.client.account.fetchAllVaults({ fresh: true });
23514
23751
  log(`Discovered ${allVaults.length} vault(s) on-chain`);
23515
23752
  const summary = {
23516
23753
  vaultsProcessed: 0,
23517
23754
  totalDeposited: 0,
23755
+ totalWithdrawn: 0,
23518
23756
  totalSkipped: 0,
23519
23757
  totalFailed: 0,
23520
23758
  dryRun
@@ -23525,25 +23763,29 @@ var ExternalLiquidityIntegrityService = class {
23525
23763
  vaultState,
23526
23764
  hwManager,
23527
23765
  log,
23528
- { dryRun, minAmountUi }
23766
+ { dryRun, minAmountUi, targetLocalBps, rebalanceBandBps }
23529
23767
  );
23530
23768
  summary.vaultsProcessed++;
23531
23769
  summary.totalDeposited += result.deposited;
23770
+ summary.totalWithdrawn += result.withdrawn;
23532
23771
  summary.totalSkipped += result.skipped;
23533
23772
  summary.totalFailed += result.failed;
23534
23773
  }
23535
23774
  return summary;
23536
23775
  }
23537
23776
  /**
23538
- * Process a single vault: for each active external liquidity slot, deposit
23539
- * any holdings that have a non-zero local_amount.
23777
+ * Process a single vault: for each active external liquidity slot, move each
23778
+ * holding's balance toward the target local/external split.
23540
23779
  */
23541
23780
  async processVault(vault, vaultState, hwManager, log, opts = {}) {
23542
23781
  const dryRun = opts.dryRun ?? false;
23543
23782
  const minAmountUi = opts.minAmountUi ?? DEFAULT_MIN_AMOUNT_UI;
23783
+ const targetLocalBps = opts.targetLocalBps ?? DEFAULT_TARGET_LOCAL_BPS;
23784
+ const rebalanceBandBps = opts.rebalanceBandBps ?? DEFAULT_REBALANCE_BAND_BPS;
23544
23785
  const result = {
23545
23786
  vault,
23546
23787
  deposited: 0,
23788
+ withdrawn: 0,
23547
23789
  skipped: 0,
23548
23790
  failed: 0,
23549
23791
  signatures: []
@@ -23553,7 +23795,7 @@ var ExternalLiquidityIntegrityService = class {
23553
23795
  result.skipped++;
23554
23796
  return result;
23555
23797
  }
23556
- const hwManagerAddress = (0, import_common49.fromWeb3Pk)(hwManager.publicKey);
23798
+ const hwManagerAddress = (0, import_common50.fromWeb3Pk)(hwManager.publicKey);
23557
23799
  const vaultPk = new import_web328.PublicKey(vault.toString());
23558
23800
  const registeredHwManager = pubkeyStr(
23559
23801
  vaultState.roles.hwManager
@@ -23573,24 +23815,33 @@ var ExternalLiquidityIntegrityService = class {
23573
23815
  }
23574
23816
  const holdings = vaultState.holdings.filter((h) => {
23575
23817
  const mint = pubkeyStr(h.mint);
23576
- return !isZeroPubkey2(mint) && toBigInt3(h.localAmount) > 0n;
23818
+ if (isZeroPubkey2(mint)) return false;
23819
+ return toBigInt3(h.localAmount) > 0n || toBigInt3(h.externalAmount) > 0n;
23577
23820
  });
23578
23821
  if (holdings.length === 0) {
23579
- log(`Vault ${vault} slot ${slot.index}: no local balance to deploy`);
23822
+ log(`Vault ${vault} slot ${slot.index}: no balance to rebalance`);
23580
23823
  result.skipped++;
23581
23824
  continue;
23582
23825
  }
23583
23826
  for (const holding of holdings) {
23584
23827
  const mintAddress = (0, import_kit15.address)(pubkeyStr(holding.mint));
23585
23828
  const localAmount = toBigInt3(holding.localAmount);
23829
+ const externalAmount = toBigInt3(holding.externalAmount);
23586
23830
  const decimals = Number(holding.decimals ?? 0);
23587
23831
  const minRaw = toRawAmount(minAmountUi, decimals);
23588
- if (localAmount < minRaw) {
23832
+ const plan = planRebalance({
23833
+ localAmount,
23834
+ externalAmount,
23835
+ targetLocalBps,
23836
+ rebalanceBandBps,
23837
+ minRaw
23838
+ });
23839
+ if (!plan) {
23589
23840
  log(
23590
- `Vault ${vault} slot ${slot.index}: mint ${mintAddress} has ${formatUi(
23591
- localAmount,
23841
+ `Vault ${vault} slot ${slot.index}: mint ${mintAddress} within band (local ${formatUi(localAmount, decimals)}, external ${formatUi(
23842
+ externalAmount,
23592
23843
  decimals
23593
- )} < minimum ${minAmountUi} \u2014 skipping`
23844
+ )}) \u2014 skipping`
23594
23845
  );
23595
23846
  result.skipped++;
23596
23847
  continue;
@@ -23604,31 +23855,36 @@ var ExternalLiquidityIntegrityService = class {
23604
23855
  continue;
23605
23856
  }
23606
23857
  log(
23607
- `Vault ${vault} slot ${slot.index}: ${dryRun ? "simulating deposit of" : "depositing"} ${localAmount} of mint ${mintAddress} into marginfi`
23858
+ `Vault ${vault} slot ${slot.index}: ${dryRun ? "simulating " : ""}${plan.direction} of ${formatUi(plan.amount, decimals)} ${mintAddress} (local ${formatUi(localAmount, decimals)} \u2192 target ${formatUi(
23859
+ plan.targetLocal,
23860
+ decimals
23861
+ )})`
23608
23862
  );
23609
23863
  try {
23610
- const outcome = await this.depositIntoMarginfi({
23864
+ const outcome = await this.rebalanceMarginfi({
23611
23865
  vault,
23612
23866
  vaultPk,
23613
23867
  hwManager,
23614
23868
  hwManagerAddress,
23615
23869
  slot,
23616
23870
  mintAddress,
23617
- amount: localAmount,
23871
+ direction: plan.direction,
23872
+ amount: plan.amount,
23618
23873
  marginfiAccounts,
23619
23874
  dryRun,
23620
23875
  log
23621
23876
  });
23622
23877
  if (outcome.signature) {
23623
23878
  log(
23624
- `Vault ${vault} slot ${slot.index}: deposit tx ${outcome.signature}`
23879
+ `Vault ${vault} slot ${slot.index}: ${plan.direction} tx ${outcome.signature}`
23625
23880
  );
23626
23881
  result.signatures.push(outcome.signature);
23627
23882
  }
23628
- result.deposited++;
23883
+ if (plan.direction === "deposit") result.deposited++;
23884
+ else result.withdrawn++;
23629
23885
  } catch (err) {
23630
23886
  log(
23631
- `Vault ${vault} slot ${slot.index}: deposit failed \u2014 ${err.message}`
23887
+ `Vault ${vault} slot ${slot.index}: ${plan.direction} failed \u2014 ${err.message}`
23632
23888
  );
23633
23889
  result.failed++;
23634
23890
  }
@@ -23636,48 +23892,60 @@ var ExternalLiquidityIntegrityService = class {
23636
23892
  }
23637
23893
  return result;
23638
23894
  }
23639
- async depositIntoMarginfi(params) {
23895
+ /**
23896
+ * Move `amount` of `mintAddress` between the vault's own token account and
23897
+ * its Marginfi position, in `direction`, through `protocol_interaction`.
23898
+ */
23899
+ async rebalanceMarginfi(params) {
23640
23900
  const {
23641
23901
  vault,
23642
23902
  hwManager,
23643
23903
  hwManagerAddress,
23644
23904
  slot,
23645
23905
  mintAddress,
23906
+ direction,
23646
23907
  amount,
23647
23908
  marginfiAccounts,
23648
23909
  dryRun = false,
23649
23910
  log = () => {
23650
23911
  }
23651
23912
  } = params;
23652
- const marginfiClient = new import_marginfi3.CpiClient();
23913
+ const marginfiClient = new import_marginfi3.CpiClient({
23914
+ accounts: marginfiAccounts
23915
+ });
23653
23916
  const { getAtaAddress: getAtaAddress16 } = await Promise.resolve().then(() => __toESM(require_dist()));
23654
- const signerTokenAccount = getAtaAddress16(
23917
+ const vaultAta = getAtaAddress16(
23655
23918
  mintAddress,
23656
23919
  vault,
23657
23920
  marginfiAccounts.tokenProgram,
23658
23921
  true
23659
23922
  );
23660
- const depositRefs = (0, import_common49.createCpiRefs)([
23661
- marginfiClient.deposit_cpi({
23923
+ const cpiRefs = (0, import_common50.createCpiRefs)([
23924
+ direction === "deposit" ? marginfiClient.deposit_cpi({
23925
+ marginfiAccount: slot.userAccount,
23926
+ authority: vault,
23927
+ signerTokenAccount: vaultAta,
23928
+ amount
23929
+ }) : marginfiClient.withdraw_cpi({
23662
23930
  marginfiAccount: slot.userAccount,
23663
23931
  authority: vault,
23664
- signerTokenAccount,
23932
+ destinationTokenAccount: vaultAta,
23665
23933
  amount
23666
23934
  })
23667
23935
  ]);
23668
23936
  const ix = await this.client.tx.protocolInteraction.getIx({
23669
23937
  hwManager: hwManagerAddress,
23670
23938
  vault,
23671
- refs: depositRefs.refs,
23939
+ refs: cpiRefs.refs,
23672
23940
  externalLiquidityIndex: slot.index,
23673
23941
  affectedAssetMint: mintAddress,
23674
- affectedVaultAta: signerTokenAccount,
23942
+ affectedVaultAta: vaultAta,
23675
23943
  affectedTokenProgram: marginfiAccounts.tokenProgram,
23676
- accounts: depositRefs.accounts
23944
+ accounts: cpiRefs.accounts
23677
23945
  });
23678
23946
  const plan = {
23679
23947
  instructions: [ix],
23680
- ...depositRefs.lookupTables?.length ? { lookupTables: depositRefs.lookupTables } : {}
23948
+ ...cpiRefs.lookupTables?.length ? { lookupTables: cpiRefs.lookupTables } : {}
23681
23949
  };
23682
23950
  if (dryRun) {
23683
23951
  const sim = await this.client.simulateTransaction(hwManager, plan);
@@ -23685,9 +23953,7 @@ var ExternalLiquidityIntegrityService = class {
23685
23953
  log(` | ${line}`);
23686
23954
  }
23687
23955
  if (sim.err) {
23688
- throw new Error(
23689
- `simulation failed: ${JSON.stringify(sim.err)}`
23690
- );
23956
+ throw new Error(`simulation failed: ${JSON.stringify(sim.err)}`);
23691
23957
  }
23692
23958
  log(
23693
23959
  `Vault ${vault} slot ${slot.index}: simulation OK (${sim.unitsConsumed ?? "?"} CU)`
@@ -23697,9 +23963,408 @@ var ExternalLiquidityIntegrityService = class {
23697
23963
  return { signature: await this.client.sendTransaction(hwManager, plan) };
23698
23964
  }
23699
23965
  };
23966
+
23967
+ // src/services/idleLiquidityService.ts
23968
+ var import_kit16 = require("@solana/kit");
23969
+ var import_spl_token19 = require("@solana/spl-token");
23970
+ var import_web329 = require("@solana/web3.js");
23971
+ var import_common51 = __toESM(require_dist());
23972
+ var import_jupiter3 = __toESM(require_dist3());
23973
+ var IDLE_RESERVE_FLOOR_BPS = 400;
23974
+ var IDLE_RESERVE_TARGET_BPS = 500;
23975
+ var DEFAULT_SLIPPAGE_BPS = 30;
23976
+ var DEFAULT_CU_PRICE_MICRO_LAMPORTS = 1e4;
23977
+ var DEFAULT_MAX_ACCOUNTS = 20;
23978
+ var COMPUTE_UNIT_LIMIT = 12e5;
23979
+ var ASSET_REBALANCE_COOLDOWN_SECS = 60;
23980
+ function toBigInt4(value) {
23981
+ if (typeof value === "bigint") return value;
23982
+ if (value !== null && value !== void 0) return BigInt(String(value));
23983
+ return 0n;
23984
+ }
23985
+ function pubkeyStr2(value) {
23986
+ if (typeof value === "string") return value;
23987
+ if (value && typeof value.toBase58 === "function") {
23988
+ return value.toBase58();
23989
+ }
23990
+ return String(value);
23991
+ }
23992
+ function coerceBool4(value) {
23993
+ if (typeof value === "boolean") return value;
23994
+ if (typeof value === "number") return value !== 0;
23995
+ const inner = value?.[0];
23996
+ if (typeof inner === "number") return inner !== 0;
23997
+ return false;
23998
+ }
23999
+ function formatUi2(raw, decimals) {
24000
+ return (Number(raw) / 10 ** decimals).toFixed(Math.min(decimals, 6));
24001
+ }
24002
+ function readHolding(raw) {
24003
+ const h = raw;
24004
+ return {
24005
+ mint: pubkeyStr2(h.mint),
24006
+ price: toBigInt4(h.price),
24007
+ decimals: Number(h.decimals ?? 0),
24008
+ localAmount: toBigInt4(h.localAmount),
24009
+ externalAmount: toBigInt4(h.externalAmount),
24010
+ lastUpdateTs: Number(toBigInt4(h.lastUpdateTs)),
24011
+ lastRebalanceTs: Number(toBigInt4(h.lastRebalanceTs))
24012
+ };
24013
+ }
24014
+ function findHolding2(vaultState, mint) {
24015
+ const holdings = vaultState.holdings ?? [];
24016
+ return holdings.map(readHolding).find((h) => h.mint === mint);
24017
+ }
24018
+ function holdingValue2(holding, amount) {
24019
+ return amount * holding.price / 10n ** BigInt(holding.decimals);
24020
+ }
24021
+ var IdleLiquidityService = class {
24022
+ constructor(client) {
24023
+ this.client = client;
24024
+ }
24025
+ /** Current unix time in seconds (override in tests). */
24026
+ now() {
24027
+ return Math.floor(Date.now() / 1e3);
24028
+ }
24029
+ /**
24030
+ * Top up the vault's idle USDC reserve if it has fallen below the floor.
24031
+ * Never throws for an expected no-op — inspect `status` on the result.
24032
+ */
24033
+ async run(vault, hwManager, opts = {}) {
24034
+ const log = opts.log ?? (() => {
24035
+ });
24036
+ const vaultState = await this.client.account.fetchVault(vault, {
24037
+ fresh: true
24038
+ });
24039
+ const registeredHwManager = pubkeyStr2(
24040
+ vaultState.roles.hwManager
24041
+ );
24042
+ if (registeredHwManager !== hwManager.publicKey.toBase58()) {
24043
+ throw new Error(
24044
+ `Signer ${hwManager.publicKey.toBase58()} is not the vault hw_manager ${registeredHwManager}`
24045
+ );
24046
+ }
24047
+ const assessment = this.assess(vault, vaultState, log);
24048
+ if (assessment.result) return assessment.result;
24049
+ const { usdc, pst, base } = assessment;
24050
+ const pstInput = this.sizePstInput(base.shortfallUsdc, usdc, pst);
24051
+ if (pstInput === 0n) {
24052
+ const reason = "top-up rounds to zero PST";
24053
+ return { ...base, status: "above-floor", reason };
24054
+ }
24055
+ const cap = opts.maxPstInput !== void 0 && opts.maxPstInput < pst.localAmount ? opts.maxPstInput : pst.localAmount;
24056
+ if (pstInput > cap) {
24057
+ const reason = `top-up needs ${formatUi2(
24058
+ pstInput,
24059
+ pst.decimals
24060
+ )} PST but only ${formatUi2(cap, pst.decimals)} is available`;
24061
+ log(`Vault ${vault}: ${reason} \u2014 skipping`);
24062
+ return { ...base, status: "insufficient-pst", reason };
24063
+ }
24064
+ const jupiter = new import_jupiter3.JupiterSwapClient(
24065
+ (0, import_kit16.createSolanaRpc)(this.client.provider.connection.rpcEndpoint)
24066
+ );
24067
+ let quote;
24068
+ try {
24069
+ quote = await jupiter.getQuote({
24070
+ inputMint: import_common51.PST_MINT,
24071
+ outputMint: import_common51.USDC_MINT,
24072
+ amount: pstInput,
24073
+ slippageBps: opts.slippageBps ?? DEFAULT_SLIPPAGE_BPS,
24074
+ maxAccounts: DEFAULT_MAX_ACCOUNTS
24075
+ });
24076
+ } catch (err) {
24077
+ log(`Vault ${vault}: Jupiter quote failed \u2014 ${err.message}`);
24078
+ return { ...base, status: "failed", reason: err.message };
24079
+ }
24080
+ log(
24081
+ `Vault ${vault}: swapping ${formatUi2(
24082
+ quote.inputAmount,
24083
+ pst.decimals
24084
+ )} PST -> ${formatUi2(
24085
+ quote.outputAmount,
24086
+ usdc.decimals
24087
+ )} USDC (price impact ${quote.priceImpactPct})`
24088
+ );
24089
+ try {
24090
+ const outcome = await this.executeSwap({
24091
+ vault,
24092
+ vaultState,
24093
+ hwManager,
24094
+ jupiter,
24095
+ quote,
24096
+ cuPriceMicroLamports: opts.cuPriceMicroLamports ?? DEFAULT_CU_PRICE_MICRO_LAMPORTS,
24097
+ dryRun: opts.dryRun ?? false,
24098
+ log
24099
+ });
24100
+ return {
24101
+ ...base,
24102
+ status: outcome.signature ? "swapped" : "simulated",
24103
+ reason: outcome.signature ? `swapped in ${outcome.signature}` : "dry run \u2014 simulation succeeded, nothing submitted",
24104
+ pstSpent: quote.inputAmount,
24105
+ usdcReceived: quote.outputAmount,
24106
+ ...outcome.signature ? { signature: outcome.signature } : {}
24107
+ };
24108
+ } catch (err) {
24109
+ log(`Vault ${vault}: swap failed \u2014 ${err.message}`);
24110
+ return { ...base, status: "failed", reason: err.message };
24111
+ }
24112
+ }
24113
+ // ── Assessment ──────────────────────────────────────────────────────────
24114
+ /**
24115
+ * Decide whether a top-up is warranted. Returns either a terminal `result`
24116
+ * (nothing to do) or the holdings and sizing needed to build the swap.
24117
+ */
24118
+ assess(vault, vaultState, log) {
24119
+ const tvl = toBigInt4(
24120
+ vaultState.accounting?.tvl
24121
+ );
24122
+ const empty = {
24123
+ vault,
24124
+ tvl,
24125
+ idleValue: 0n,
24126
+ idleBps: 0,
24127
+ shortfallUsdc: 0n,
24128
+ pstSpent: 0n,
24129
+ usdcReceived: 0n
24130
+ };
24131
+ if (tvl === 0n) {
24132
+ const reason = "vault TVL is zero";
24133
+ log(`Vault ${vault}: ${reason} \u2014 skipping`);
24134
+ return { result: { ...empty, status: "no-tvl", reason } };
24135
+ }
24136
+ const usdc = findHolding2(vaultState, import_common51.USDC_MINT);
24137
+ const pst = findHolding2(vaultState, import_common51.PST_MINT);
24138
+ if (!usdc || !pst) {
24139
+ const reason = `vault has no ${usdc ? "PST" : "USDC"} holding`;
24140
+ log(`Vault ${vault}: ${reason} \u2014 skipping`);
24141
+ return { result: { ...empty, status: "missing-holding", reason } };
24142
+ }
24143
+ const stalenessThreshold = this.stalenessThresholdSecs(vaultState);
24144
+ const now = this.now();
24145
+ for (const [name, holding] of [
24146
+ ["USDC", usdc],
24147
+ ["PST", pst]
24148
+ ]) {
24149
+ if (holding.price === 0n) {
24150
+ const reason = `${name} holding has no price set`;
24151
+ log(`Vault ${vault}: ${reason} \u2014 skipping`);
24152
+ return { result: { ...empty, status: "stale-price", reason } };
24153
+ }
24154
+ if (now - holding.lastUpdateTs > stalenessThreshold) {
24155
+ const reason = `${name} holding price is stale (last update ${holding.lastUpdateTs})`;
24156
+ log(`Vault ${vault}: ${reason} \u2014 skipping`);
24157
+ return { result: { ...empty, status: "stale-price", reason } };
24158
+ }
24159
+ }
24160
+ const idleAmount = usdc.localAmount + usdc.externalAmount;
24161
+ const idleValue = holdingValue2(usdc, idleAmount);
24162
+ const idleBps = Number(idleValue * 10000n / tvl);
24163
+ const base = { ...empty, idleValue, idleBps };
24164
+ log(
24165
+ `Vault ${vault}: idle USDC ${formatUi2(
24166
+ idleAmount,
24167
+ usdc.decimals
24168
+ )} = ${idleBps}bps of TVL (floor ${IDLE_RESERVE_FLOOR_BPS}bps, target ${IDLE_RESERVE_TARGET_BPS}bps)`
24169
+ );
24170
+ if (idleBps >= IDLE_RESERVE_FLOOR_BPS) {
24171
+ const reason = `idle USDC ${idleBps}bps is at or above the ${IDLE_RESERVE_FLOOR_BPS}bps floor`;
24172
+ return { result: { ...base, status: "above-floor", reason } };
24173
+ }
24174
+ for (const [name, holding] of [
24175
+ ["USDC", usdc],
24176
+ ["PST", pst]
24177
+ ]) {
24178
+ if (holding.lastRebalanceTs !== 0 && now < holding.lastRebalanceTs + ASSET_REBALANCE_COOLDOWN_SECS) {
24179
+ const reason = `${name} holding is in its rebalance cooldown until ${holding.lastRebalanceTs + ASSET_REBALANCE_COOLDOWN_SECS}`;
24180
+ log(`Vault ${vault}: ${reason} \u2014 skipping`);
24181
+ return { result: { ...base, status: "rebalance-cooldown", reason } };
24182
+ }
24183
+ }
24184
+ const targetValue = tvl * BigInt(IDLE_RESERVE_TARGET_BPS) / 10000n;
24185
+ let shortfallValue = targetValue - idleValue;
24186
+ const allowance = this.remainingRebalanceAllowance(vaultState, tvl, now);
24187
+ if (allowance !== void 0 && allowance < shortfallValue) {
24188
+ if (allowance === 0n) {
24189
+ const reason = "rolling rebalance limit is exhausted for this window";
24190
+ log(`Vault ${vault}: ${reason} \u2014 skipping`);
24191
+ return { result: { ...base, status: "rebalance-limit", reason } };
24192
+ }
24193
+ log(
24194
+ `Vault ${vault}: rolling rebalance limit caps this run at ${allowance} of ${shortfallValue} accounting units`
24195
+ );
24196
+ shortfallValue = allowance;
24197
+ }
24198
+ const shortfallUsdc = shortfallValue * 10n ** BigInt(usdc.decimals) / usdc.price;
24199
+ if (shortfallUsdc <= 0n) {
24200
+ const reason = "computed shortfall rounds to zero";
24201
+ return { result: { ...base, status: "above-floor", reason } };
24202
+ }
24203
+ if (pst.localAmount === 0n) {
24204
+ const reason = "vault holds no local PST";
24205
+ log(`Vault ${vault}: ${reason} \u2014 skipping`);
24206
+ return {
24207
+ result: { ...base, shortfallUsdc, status: "insufficient-pst", reason }
24208
+ };
24209
+ }
24210
+ return { usdc, pst, base: { ...base, shortfallUsdc } };
24211
+ }
24212
+ /**
24213
+ * Value still chargeable against the vault's rolling rebalance window, in
24214
+ * accounting units. `undefined` when the cap is disabled (unlimited).
24215
+ */
24216
+ remainingRebalanceAllowance(vaultState, tvl, now) {
24217
+ const limit = vaultState.accounting?.rebalanceLimit;
24218
+ const bps = Number(toBigInt4(limit?.windowLimitBps));
24219
+ if (!limit || bps === 0) return void 0;
24220
+ const windowStartTs = Number(toBigInt4(limit.windowStartTs));
24221
+ const windowDuration = Number(toBigInt4(limit.windowDurationSeconds));
24222
+ const consumed = windowStartTs === 0 || now >= windowStartTs + windowDuration ? 0n : toBigInt4(limit.valueInWindow);
24223
+ const ceiling = tvl * BigInt(bps) / 10000n;
24224
+ return ceiling > consumed ? ceiling - consumed : 0n;
24225
+ }
24226
+ /**
24227
+ * PST input that buys `shortfallUsdc` at the holdings' recorded prices.
24228
+ * Both prices share the vault's accounting unit, so this is a straight
24229
+ * value conversion; slippage is absorbed by landing slightly under target.
24230
+ */
24231
+ sizePstInput(shortfallUsdc, usdc, pst) {
24232
+ const shortfallValue = holdingValue2(usdc, shortfallUsdc);
24233
+ return shortfallValue * 10n ** BigInt(pst.decimals) / pst.price;
24234
+ }
24235
+ stalenessThresholdSecs(vaultState) {
24236
+ const configured = Number(
24237
+ toBigInt4(
24238
+ vaultState.config?.priceStalenessThresholdSecs
24239
+ )
24240
+ );
24241
+ return configured > 0 ? configured : DEFAULT_PRICE_STALENESS_THRESHOLD_SECS;
24242
+ }
24243
+ // ── Execution ───────────────────────────────────────────────────────────
24244
+ /**
24245
+ * Token program owning a mint. Read from the chain rather than from the
24246
+ * holding's enum so a Token-2022 mint can never be passed to the classic
24247
+ * program (and vice versa).
24248
+ */
24249
+ async mintTokenProgram(mint) {
24250
+ const account = await this.client.provider.connection.getAccountInfo(
24251
+ new import_web329.PublicKey(mint),
24252
+ "confirmed"
24253
+ );
24254
+ if (!account) throw new Error(`Mint account not found: ${mint}`);
24255
+ if (!account.owner.equals(import_spl_token19.TOKEN_PROGRAM_ID) && !account.owner.equals(import_spl_token19.TOKEN_2022_PROGRAM_ID)) {
24256
+ throw new Error(
24257
+ `Unsupported token program ${account.owner.toBase58()} for mint ${mint}`
24258
+ );
24259
+ }
24260
+ return (0, import_common51.fromWeb3Pk)(account.owner);
24261
+ }
24262
+ /**
24263
+ * Build, simulate, and (unless `dryRun`) submit the `jupiter_swap`.
24264
+ *
24265
+ * Built as a versioned transaction here rather than through
24266
+ * `client.sendTransaction`, because a Jupiter route needs address lookup
24267
+ * tables and a raised compute-unit limit to fit.
24268
+ */
24269
+ async executeSwap(params) {
24270
+ const {
24271
+ vault,
24272
+ vaultState,
24273
+ hwManager,
24274
+ jupiter,
24275
+ quote,
24276
+ cuPriceMicroLamports,
24277
+ dryRun,
24278
+ log
24279
+ } = params;
24280
+ const signer = (0, import_common51.fromWeb3Pk)(hwManager.publicKey);
24281
+ const [sourceTokenProgram, destinationTokenProgram] = await Promise.all([
24282
+ this.mintTokenProgram(import_common51.PST_MINT),
24283
+ this.mintTokenProgram(import_common51.USDC_MINT)
24284
+ ]);
24285
+ const jupiterCpi = await jupiter.getSwapCpiData(quote, vault, {
24286
+ payer: signer
24287
+ });
24288
+ const { accounts: accounts2, refs, lookupTables } = (0, import_common51.createCpiRefs)([jupiterCpi]);
24289
+ const vaultTrancheState = coerceBool4(
24290
+ vaultState.tranchingEnabled
24291
+ ) ? (await this.client.pda.deriveVaultTrancheStatePda(vault))[0] : void 0;
24292
+ const plan = await this.client.tx.jupiterSwap.getTx({
24293
+ hwManager: signer,
24294
+ vault,
24295
+ sourceMint: import_common51.PST_MINT,
24296
+ destinationMint: import_common51.USDC_MINT,
24297
+ refs,
24298
+ accounts: accounts2,
24299
+ sourceTokenProgram,
24300
+ destinationTokenProgram,
24301
+ vaultTrancheState,
24302
+ lookupTables
24303
+ });
24304
+ const connection = this.client.provider.connection;
24305
+ const instructions2 = [
24306
+ import_web329.ComputeBudgetProgram.setComputeUnitLimit({ units: COMPUTE_UNIT_LIMIT }),
24307
+ ...cuPriceMicroLamports > 0 ? [
24308
+ import_web329.ComputeBudgetProgram.setComputeUnitPrice({
24309
+ microLamports: cuPriceMicroLamports
24310
+ })
24311
+ ] : [],
24312
+ ...(jupiterCpi.preInstructions ?? []).map(import_common51.fromKitInstruction),
24313
+ ...plan.instructions.map(import_common51.fromKitInstruction)
24314
+ ];
24315
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
24316
+ const lookupTableAccounts = await (0, import_common51.fetchLookupTables)(
24317
+ connection,
24318
+ plan.lookupTables ?? []
24319
+ );
24320
+ const message2 = new import_web329.TransactionMessage({
24321
+ payerKey: hwManager.publicKey,
24322
+ recentBlockhash: blockhash,
24323
+ instructions: instructions2
24324
+ }).compileToV0Message(lookupTableAccounts);
24325
+ const transaction = new import_web329.VersionedTransaction(message2);
24326
+ transaction.sign([hwManager]);
24327
+ const simulation = await connection.simulateTransaction(transaction, {
24328
+ sigVerify: true,
24329
+ commitment: "confirmed"
24330
+ });
24331
+ if (simulation.value.err) {
24332
+ for (const line of simulation.value.logs ?? []) log(` | ${line}`);
24333
+ throw new Error(
24334
+ `simulation failed: ${JSON.stringify(simulation.value.err)}`
24335
+ );
24336
+ }
24337
+ log(
24338
+ `Vault ${vault}: simulation OK (${simulation.value.unitsConsumed ?? "?"} CU)`
24339
+ );
24340
+ if (dryRun) {
24341
+ log(`Vault ${vault}: dry run \u2014 transaction NOT submitted`);
24342
+ return {};
24343
+ }
24344
+ const signature = await connection.sendRawTransaction(
24345
+ transaction.serialize(),
24346
+ { skipPreflight: false, maxRetries: 5 }
24347
+ );
24348
+ const confirmation = await connection.confirmTransaction(
24349
+ { signature, blockhash, lastValidBlockHeight },
24350
+ "confirmed"
24351
+ );
24352
+ if (confirmation.value.err) {
24353
+ throw new Error(
24354
+ `transaction ${signature} failed: ${JSON.stringify(
24355
+ confirmation.value.err
24356
+ )}`
24357
+ );
24358
+ }
24359
+ this.client.applyCacheInvalidations(plan);
24360
+ log(`Vault ${vault}: swap tx ${signature}`);
24361
+ return { signature };
24362
+ }
24363
+ };
23700
24364
  // Annotate the CommonJS export names for ESM import in node:
23701
24365
  0 && (module.exports = {
23702
24366
  ASSET_DECIMALS,
24367
+ ASSET_REBALANCE_COOLDOWN_SECS,
23703
24368
  AccountClient,
23704
24369
  ActivateCircuitBreakerBuilder,
23705
24370
  CONSENSUS_ORACLE_VARIANT,
@@ -23710,15 +24375,20 @@ var ExternalLiquidityIntegrityService = class {
23710
24375
  CreateAssetHoldingBuilder,
23711
24376
  CreateTrancheStateBuilder,
23712
24377
  CreateVaultBuilder,
24378
+ DEFAULT_CU_PRICE_MICRO_LAMPORTS,
23713
24379
  DEFAULT_JUNIOR_EARLY_UNSTAKE_FEE_BPS,
23714
24380
  DEFAULT_JUNIOR_STANDARD_UNSTAKE_FEE_BPS,
23715
24381
  DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS,
23716
24382
  DEFAULT_MAX_ACCEPTABLE_APY_BPS,
24383
+ DEFAULT_MAX_ACCOUNTS,
23717
24384
  DEFAULT_MIN_AMOUNT_UI,
23718
24385
  DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS,
23719
24386
  DEFAULT_PRICE_ORACLE_ACCOUNT,
23720
24387
  DEFAULT_PRICE_STALENESS_SECS,
23721
24388
  DEFAULT_PRICE_STALENESS_THRESHOLD_SECS,
24389
+ DEFAULT_REBALANCE_BAND_BPS,
24390
+ DEFAULT_SLIPPAGE_BPS,
24391
+ DEFAULT_TARGET_LOCAL_BPS,
23722
24392
  DEFAULT_VAULT_ID,
23723
24393
  DisableCircuitBreakerBuilder,
23724
24394
  EXTERNAL_POSITION_SAMPLES,
@@ -23732,6 +24402,9 @@ var ExternalLiquidityIntegrityService = class {
23732
24402
  FEE_VAULT_CACHE_CATEGORY,
23733
24403
  FulfillJuniorTrancheWithdrawBuilder,
23734
24404
  IDL,
24405
+ IDLE_RESERVE_FLOOR_BPS,
24406
+ IDLE_RESERVE_TARGET_BPS,
24407
+ IdleLiquidityService,
23735
24408
  InitializeVaultRolesBuilder,
23736
24409
  JupiterBalanceSource,
23737
24410
  JupiterPriceSource,
@@ -23845,6 +24518,7 @@ var ExternalLiquidityIntegrityService = class {
23845
24518
  mintTokensTo,
23846
24519
  mostFrequent,
23847
24520
  parseExternalLiquidityRefs,
24521
+ planRebalance,
23848
24522
  prepareVaultTransaction,
23849
24523
  priceInAccountingUnit,
23850
24524
  readI64LE,