@perena/vault-sdk 1.0.59 → 1.0.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -928,8 +928,11 @@ use that protocol; both initialized, registered positions are required for the
928
928
  USDC split. Other configured stablecoins continue to use Marginfi.
929
929
 
930
930
  Allocation uses each live position's supplied balance, including accrued value,
931
- and the actual vault token balance. Withdrawal capacity also checks bank/reserve
932
- cash, Kamino withdrawal caps and queued redemptions. Utilization can limit a
931
+ and the actual vault token balance. Marginfi withdrawal capacity is capped by both
932
+ bank cash and total assets minus total liabilities, retaining 0.1% of that capacity
933
+ for interest accrual and rounding. This cap does not reduce the position value
934
+ used for allocation weights. Kamino capacity checks reserve cash, withdrawal caps
935
+ and queued redemptions. Utilization can limit a
933
936
  rebalance to a partial transfer; subsequent runs retry if weights remain outside
934
937
  the band. Each
935
938
  mint's withdrawals and deposits share one atomic transaction and use the vault's
package/dist/index.d.ts CHANGED
@@ -13299,7 +13299,7 @@ interface WithdrawalPosition {
13299
13299
  index: number;
13300
13300
  /** Same account registered twice must not be spent twice. */
13301
13301
  positionKey: string;
13302
- /** Multiple positions can share one bank/reserve's available cash. */
13302
+ /** Multiple positions share one bank/reserve's cash and protocol limits. */
13303
13303
  poolKey: string;
13304
13304
  poolAvailable: bigint;
13305
13305
  capacity(poolAvailable: bigint): bigint;
package/dist/index.js CHANGED
@@ -18072,6 +18072,12 @@ function marginfiFixedPointBits(value) {
18072
18072
  }
18073
18073
  return BigInt(value.toString());
18074
18074
  }
18075
+ function marginfiWithdrawablePoolLiquidity(bank, cash) {
18076
+ const assets = marginfiFixedPointBits(bank.totalAssetShares.value) * marginfiFixedPointBits(bank.assetShareValue.value) >> 48n;
18077
+ const liabilities = marginfiFixedPointBits(bank.totalLiabilityShares.value) * marginfiFixedPointBits(bank.liabilityShareValue.value) >> 48n;
18078
+ const available = nonnegative(min(cash, assets - liabilities >> 48n));
18079
+ return available * 9990n / 10000n;
18080
+ }
18075
18081
  async function readTokenBalance(connection, tokenAccount, tokenProgram) {
18076
18082
  const key = new import_web316.PublicKey(tokenAccount);
18077
18083
  const info = await connection.getAccountInfo(key, "confirmed");
@@ -18239,10 +18245,9 @@ async function loadWithdrawalPosition(args) {
18239
18245
  const deposited = nonnegative(
18240
18246
  marginfiFixedPointBits(balances[target].assetShares.value) * marginfiFixedPointBits(bank.assetShareValue.value) >> 96n
18241
18247
  );
18242
- const poolAvailable = await readTokenBalance(
18243
- connection,
18244
- configured.liquidityVault,
18245
- tokenProgram
18248
+ const poolAvailable = marginfiWithdrawablePoolLiquidity(
18249
+ bank,
18250
+ await readTokenBalance(connection, configured.liquidityVault, tokenProgram)
18246
18251
  );
18247
18252
  const cpi = new import_marginfi.CpiClient({ accounts: configured }).withdraw_cpi({
18248
18253
  marginfiAccount: userAccount,
@@ -24937,6 +24942,14 @@ var ExternalLiquidityIntegrityService = class {
24937
24942
  result.skipped++;
24938
24943
  continue;
24939
24944
  }
24945
+ for (const position of snapshot2.positions) {
24946
+ const capacity = position.capacity(position.poolAvailable);
24947
+ if (capacity < position.balance) {
24948
+ log(
24949
+ `Vault ${vault} slot ${position.index} (${position.source}): withdrawal capacity ${formatUi(capacity, decimals)} of ${formatUi(position.balance, decimals)} supplied ${mintAddress}`
24950
+ );
24951
+ }
24952
+ }
24940
24953
  const externalAmount = snapshot2.positions.reduce(
24941
24954
  (total, p) => total + p.balance,
24942
24955
  0n
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perena/vault-sdk",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "Vault program helpers for Bankineco integrations.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",