@0dotxyz/p0-ts-sdk 2.3.1 → 2.3.3

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.cjs CHANGED
@@ -10,6 +10,7 @@ var bufferLayout = require('@solana/buffer-layout');
10
10
  var bufferLayoutUtils = require('@solana/buffer-layout-utils');
11
11
  var buffer = require('buffer');
12
12
  var borsh$1 = require('borsh');
13
+ var bs58 = require('bs58');
13
14
  var borsh = require('@coral-xyz/borsh');
14
15
  var WebSocket = require('ws');
15
16
  var msgpack = require('@msgpack/msgpack');
@@ -39,6 +40,7 @@ function _interopNamespace(e) {
39
40
  var BigNumber3__default = /*#__PURE__*/_interopDefault(BigNumber3);
40
41
  var BN11__default = /*#__PURE__*/_interopDefault(BN11);
41
42
  var Decimal3__default = /*#__PURE__*/_interopDefault(Decimal3);
43
+ var bs58__default = /*#__PURE__*/_interopDefault(bs58);
42
44
  var borsh__namespace = /*#__PURE__*/_interopNamespace(borsh);
43
45
  var WebSocket__default = /*#__PURE__*/_interopDefault(WebSocket);
44
46
 
@@ -229,6 +231,15 @@ var TransactionBuildingError = class _TransactionBuildingError extends Error {
229
231
  return new _TransactionBuildingError(code, message, details);
230
232
  }
231
233
  };
234
+ var DECOMPOSABLE_SWAP_ERROR_CODES = /* @__PURE__ */ new Set([
235
+ "SWAP_SIZE_EXCEEDED_LOOP" /* SWAP_SIZE_EXCEEDED_LOOP */,
236
+ "SWAP_SIZE_EXCEEDED_REPAY" /* SWAP_SIZE_EXCEEDED_REPAY */,
237
+ "SWAP_SIZE_EXCEEDED_POSITION_SWAP" /* SWAP_SIZE_EXCEEDED_POSITION_SWAP */,
238
+ "SWAP_QUOTE_FAILED" /* SWAP_QUOTE_FAILED */
239
+ ]);
240
+ function isDecomposableSwapError(e) {
241
+ return e instanceof TransactionBuildingError && DECOMPOSABLE_SWAP_ERROR_CODES.has(e.code);
242
+ }
232
243
  var PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED = Buffer.from("liquidity_vault_auth");
233
244
  var PDA_BANK_INSURANCE_VAULT_AUTH_SEED = Buffer.from("insurance_vault_auth");
234
245
  var PDA_BANK_FEE_VAULT_AUTH_SEED = Buffer.from("fee_vault_auth");
@@ -16043,8 +16054,10 @@ function toBankDto(bank) {
16043
16054
  emissionsRate: bank.emissionsRate,
16044
16055
  emissionsMint: bank.emissionsMint.toBase58(),
16045
16056
  emissionsRemaining: bank.emissionsRemaining.toString(),
16057
+ collectedProgramFeesOutstanding: bank.collectedProgramFeesOutstanding.toString(),
16046
16058
  oracleKey: bank.oracleKey.toBase58(),
16047
16059
  emode: toEmodeSettingsDto(bank.emode),
16060
+ rateLimiter: bank.rateLimiter ? toBankRateLimiterDto(bank.rateLimiter) : void 0,
16048
16061
  tokenSymbol: bank.tokenSymbol,
16049
16062
  feesDestinationAccount: bank.feesDestinationAccount?.toBase58(),
16050
16063
  lendingPositionCount: bank.lendingPositionCount?.toString(),
@@ -16069,6 +16082,21 @@ function toBankDto(bank) {
16069
16082
  } : void 0
16070
16083
  };
16071
16084
  }
16085
+ function toRateLimitWindowDto(window) {
16086
+ return {
16087
+ maxOutflow: window.maxOutflow.toString(),
16088
+ windowDuration: window.windowDuration,
16089
+ windowStart: window.windowStart,
16090
+ prevWindowOutflow: window.prevWindowOutflow.toString(),
16091
+ curWindowOutflow: window.curWindowOutflow.toString()
16092
+ };
16093
+ }
16094
+ function toBankRateLimiterDto(rateLimiter) {
16095
+ return {
16096
+ hourly: toRateLimitWindowDto(rateLimiter.hourly),
16097
+ daily: toRateLimitWindowDto(rateLimiter.daily)
16098
+ };
16099
+ }
16072
16100
  function toEmodeSettingsDto(emodeSettings) {
16073
16101
  return {
16074
16102
  emodeTag: emodeSettings.emodeTag,
@@ -16147,6 +16175,8 @@ function bankRawToDto(bankRaw) {
16147
16175
  emissionsRate: bankRaw.emissionsRate.toString(),
16148
16176
  emissionsRemaining: bankRaw.emissionsRemaining,
16149
16177
  emissionsMint: bankRaw.emissionsMint.toBase58(),
16178
+ collectedProgramFeesOutstanding: bankRaw.collectedProgramFeesOutstanding,
16179
+ rateLimiter: bankRaw.rateLimiter ? bankRateLimiterRawToDto(bankRaw.rateLimiter) : void 0,
16150
16180
  feesDestinationAccount: bankRaw?.feesDestinationAccount?.toBase58(),
16151
16181
  lendingPositionCount: bankRaw?.lendingPositionCount?.toString(),
16152
16182
  borrowingPositionCount: bankRaw?.borrowingPositionCount?.toString(),
@@ -16156,6 +16186,21 @@ function bankRawToDto(bankRaw) {
16156
16186
  integrationAcc3: bankRaw.integrationAcc3.toBase58()
16157
16187
  };
16158
16188
  }
16189
+ function rateLimitWindowRawToDto(window) {
16190
+ return {
16191
+ maxOutflow: window.maxOutflow.toString(),
16192
+ windowDuration: window.windowDuration.toString(),
16193
+ windowStart: window.windowStart.toString(),
16194
+ prevWindowOutflow: window.prevWindowOutflow.toString(),
16195
+ curWindowOutflow: window.curWindowOutflow.toString()
16196
+ };
16197
+ }
16198
+ function bankRateLimiterRawToDto(rateLimiter) {
16199
+ return {
16200
+ hourly: rateLimitWindowRawToDto(rateLimiter.hourly),
16201
+ daily: rateLimitWindowRawToDto(rateLimiter.daily)
16202
+ };
16203
+ }
16159
16204
  function emodeSettingsRawToDto(emodeSettingsRaw) {
16160
16205
  return {
16161
16206
  emodeTag: emodeSettingsRaw.emodeTag,
@@ -16255,6 +16300,21 @@ function parseEmodeSettingsRaw(emodeSettingsRaw) {
16255
16300
  };
16256
16301
  return emodeSettings;
16257
16302
  }
16303
+ function parseRateLimitWindowRaw(window) {
16304
+ return {
16305
+ maxOutflow: new BigNumber3__default.default(window.maxOutflow.toString()),
16306
+ windowDuration: window.windowDuration.toNumber(),
16307
+ windowStart: window.windowStart.toNumber(),
16308
+ prevWindowOutflow: new BigNumber3__default.default(window.prevWindowOutflow.toString()),
16309
+ curWindowOutflow: new BigNumber3__default.default(window.curWindowOutflow.toString())
16310
+ };
16311
+ }
16312
+ function parseBankRateLimiterRaw(rateLimiter) {
16313
+ return {
16314
+ hourly: parseRateLimitWindowRaw(rateLimiter.hourly),
16315
+ daily: parseRateLimitWindowRaw(rateLimiter.daily)
16316
+ };
16317
+ }
16258
16318
  function parseBankRaw(address, accountParsed, bankMetadata) {
16259
16319
  const flags = accountParsed.flags.toNumber();
16260
16320
  const mint = accountParsed.mint;
@@ -16286,8 +16346,10 @@ function parseBankRaw(address, accountParsed, bankMetadata) {
16286
16346
  const emissionsRate = accountParsed.emissionsRate.toNumber();
16287
16347
  const emissionsMint = accountParsed.emissionsMint;
16288
16348
  const emissionsRemaining = accountParsed.emissionsRemaining ? wrappedI80F48toBigNumber(accountParsed.emissionsRemaining) : new BigNumber3__default.default(0);
16349
+ const collectedProgramFeesOutstanding = accountParsed.collectedProgramFeesOutstanding ? wrappedI80F48toBigNumber(accountParsed.collectedProgramFeesOutstanding) : new BigNumber3__default.default(0);
16289
16350
  const { oracleKey } = { oracleKey: config.oracleKeys[0] };
16290
16351
  const emode = parseEmodeSettingsRaw(accountParsed.emode);
16352
+ const rateLimiter = accountParsed.rateLimiter ? parseBankRateLimiterRaw(accountParsed.rateLimiter) : void 0;
16291
16353
  const tokenSymbol = bankMetadata?.tokenSymbol;
16292
16354
  const feesDestinationAccount = accountParsed.feesDestinationAccount;
16293
16355
  const lendingPositionCount = accountParsed.lendingPositionCount ? new BigNumber3__default.default(accountParsed.lendingPositionCount.toString()) : new BigNumber3__default.default(0);
@@ -16348,11 +16410,13 @@ function parseBankRaw(address, accountParsed, bankMetadata) {
16348
16410
  emissionsRate,
16349
16411
  emissionsMint,
16350
16412
  emissionsRemaining,
16413
+ collectedProgramFeesOutstanding,
16351
16414
  oracleKey,
16352
16415
  feesDestinationAccount,
16353
16416
  lendingPositionCount,
16354
16417
  borrowingPositionCount,
16355
16418
  emode,
16419
+ rateLimiter,
16356
16420
  tokenSymbol,
16357
16421
  kaminoIntegrationAccounts,
16358
16422
  driftIntegrationAccounts,
@@ -16388,8 +16452,10 @@ function dtoToBank(bankDto) {
16388
16452
  emissionsRate: bankDto.emissionsRate,
16389
16453
  emissionsMint: new web3_js.PublicKey(bankDto.emissionsMint),
16390
16454
  emissionsRemaining: new BigNumber3__default.default(bankDto.emissionsRemaining),
16455
+ collectedProgramFeesOutstanding: new BigNumber3__default.default(bankDto.collectedProgramFeesOutstanding ?? "0"),
16391
16456
  oracleKey: new web3_js.PublicKey(bankDto.oracleKey),
16392
16457
  emode: dtoToEmodeSettings(bankDto.emode),
16458
+ rateLimiter: bankDto.rateLimiter ? dtoToBankRateLimiter(bankDto.rateLimiter) : void 0,
16393
16459
  tokenSymbol: bankDto.tokenSymbol,
16394
16460
  feesDestinationAccount: bankDto.feesDestinationAccount ? new web3_js.PublicKey(bankDto.feesDestinationAccount) : void 0,
16395
16461
  lendingPositionCount: bankDto.lendingPositionCount ? new BigNumber3__default.default(bankDto.lendingPositionCount) : void 0,
@@ -16414,6 +16480,21 @@ function dtoToBank(bankDto) {
16414
16480
  } : void 0
16415
16481
  };
16416
16482
  }
16483
+ function dtoToRateLimitWindow(window) {
16484
+ return {
16485
+ maxOutflow: new BigNumber3__default.default(window.maxOutflow),
16486
+ windowDuration: window.windowDuration,
16487
+ windowStart: window.windowStart,
16488
+ prevWindowOutflow: new BigNumber3__default.default(window.prevWindowOutflow),
16489
+ curWindowOutflow: new BigNumber3__default.default(window.curWindowOutflow)
16490
+ };
16491
+ }
16492
+ function dtoToBankRateLimiter(rateLimiter) {
16493
+ return {
16494
+ hourly: dtoToRateLimitWindow(rateLimiter.hourly),
16495
+ daily: dtoToRateLimitWindow(rateLimiter.daily)
16496
+ };
16497
+ }
16417
16498
  function dtoToEmodeSettings(emodeSettingsDto) {
16418
16499
  return {
16419
16500
  emodeTag: emodeSettingsDto.emodeTag,
@@ -16492,6 +16573,8 @@ function dtoToBankRaw(bankDto) {
16492
16573
  emissionsRate: new BN11__default.default(bankDto.emissionsRate),
16493
16574
  emissionsRemaining: bankDto.emissionsRemaining,
16494
16575
  emissionsMint: new web3_js.PublicKey(bankDto.emissionsMint),
16576
+ collectedProgramFeesOutstanding: bankDto.collectedProgramFeesOutstanding,
16577
+ rateLimiter: bankDto.rateLimiter ? dtoToBankRateLimiterRaw(bankDto.rateLimiter) : void 0,
16495
16578
  feesDestinationAccount: bankDto.feesDestinationAccount ? new web3_js.PublicKey(bankDto.feesDestinationAccount) : void 0,
16496
16579
  lendingPositionCount: bankDto.lendingPositionCount ? Number(bankDto.lendingPositionCount) : void 0,
16497
16580
  borrowingPositionCount: bankDto.borrowingPositionCount ? Number(bankDto.borrowingPositionCount) : void 0,
@@ -16501,6 +16584,21 @@ function dtoToBankRaw(bankDto) {
16501
16584
  integrationAcc3: new web3_js.PublicKey(bankDto.integrationAcc3)
16502
16585
  };
16503
16586
  }
16587
+ function dtoToRateLimitWindowRaw(window) {
16588
+ return {
16589
+ maxOutflow: new BN11__default.default(window.maxOutflow),
16590
+ windowDuration: new BN11__default.default(window.windowDuration),
16591
+ windowStart: new BN11__default.default(window.windowStart),
16592
+ prevWindowOutflow: new BN11__default.default(window.prevWindowOutflow),
16593
+ curWindowOutflow: new BN11__default.default(window.curWindowOutflow)
16594
+ };
16595
+ }
16596
+ function dtoToBankRateLimiterRaw(rateLimiter) {
16597
+ return {
16598
+ hourly: dtoToRateLimitWindowRaw(rateLimiter.hourly),
16599
+ daily: dtoToRateLimitWindowRaw(rateLimiter.daily)
16600
+ };
16601
+ }
16504
16602
  function dtoToEmodeSettingsRaw(emodeSettingsDto) {
16505
16603
  return {
16506
16604
  emodeTag: emodeSettingsDto.emodeTag,
@@ -62098,6 +62196,7 @@ async function buildRepayWithCollatFlashloanTx({
62098
62196
  // src/services/account/utils/flashloan-size.utils.ts
62099
62197
  var SWAP_MERGE_OVERHEAD = 150;
62100
62198
  var FL_IX_OVERHEAD = 52;
62199
+ var OVERSIZED_TX_SENTINEL = MAX_TX_SIZE * 4;
62101
62200
  function compactU16Size(n) {
62102
62201
  return n < 128 ? 1 : n < 16384 ? 2 : 3;
62103
62202
  }
@@ -62254,7 +62353,13 @@ function compileFlashloanPrecheck({
62254
62353
  recentBlockhash: web3_js.PublicKey.default.toBase58(),
62255
62354
  instructions: allIxs
62256
62355
  }).compileToV0Message(luts);
62257
- const rawSize = new web3_js.VersionedTransaction(msg).serialize().length;
62356
+ let rawSize;
62357
+ try {
62358
+ rawSize = new web3_js.VersionedTransaction(msg).serialize().length;
62359
+ } catch (e) {
62360
+ if (!(e instanceof RangeError)) throw e;
62361
+ rawSize = OVERSIZED_TX_SENTINEL;
62362
+ }
62258
62363
  const fullTxSize = rawSize + FL_IX_OVERHEAD;
62259
62364
  const overshoot = fullTxSize - MAX_TX_SIZE;
62260
62365
  const { header, staticAccountKeys, addressTableLookups } = msg;
@@ -65254,7 +65359,7 @@ function composeBundle(firstLegTxs, secondLegTxs, payer, blockhash, maxBundleTxs
65254
65359
  if (result.length > maxBundleTxs) return null;
65255
65360
  return result;
65256
65361
  }
65257
- function mergeBridgeQuotes(firstLeg, secondLeg) {
65362
+ function compoundQuoteRisk(firstLeg, secondLeg) {
65258
65363
  const compound = (a, b) => {
65259
65364
  if (a == null && b == null) return void 0;
65260
65365
  const x = Number(a ?? 0);
@@ -65262,13 +65367,36 @@ function mergeBridgeQuotes(firstLeg, secondLeg) {
65262
65367
  return String(1 - (1 - x) * (1 - y));
65263
65368
  };
65264
65369
  return {
65265
- inAmount: firstLeg.inAmount,
65266
- outAmount: secondLeg.outAmount,
65267
- otherAmountThreshold: secondLeg.otherAmountThreshold,
65268
65370
  slippageBps: Math.round(
65269
65371
  (1 - (1 - firstLeg.slippageBps / 1e4) * (1 - secondLeg.slippageBps / 1e4)) * 1e4
65270
65372
  ),
65271
- priceImpactPct: compound(firstLeg.priceImpactPct, secondLeg.priceImpactPct),
65373
+ priceImpactPct: compound(firstLeg.priceImpactPct, secondLeg.priceImpactPct)
65374
+ };
65375
+ }
65376
+ function mergeBridgeQuotes(firstLeg, secondLeg) {
65377
+ return {
65378
+ inAmount: firstLeg.inAmount,
65379
+ outAmount: secondLeg.outAmount,
65380
+ otherAmountThreshold: secondLeg.otherAmountThreshold,
65381
+ ...compoundQuoteRisk(firstLeg, secondLeg),
65382
+ provider: firstLeg.provider
65383
+ };
65384
+ }
65385
+ function mergeBridgeQuotesDebt(firstLeg, secondLeg) {
65386
+ return {
65387
+ inAmount: firstLeg.outAmount,
65388
+ outAmount: secondLeg.inAmount,
65389
+ otherAmountThreshold: secondLeg.inAmount,
65390
+ ...compoundQuoteRisk(firstLeg, secondLeg),
65391
+ provider: firstLeg.provider
65392
+ };
65393
+ }
65394
+ function mergeBridgeQuotesLoop(firstLeg, secondLeg) {
65395
+ return {
65396
+ inAmount: secondLeg.inAmount,
65397
+ outAmount: firstLeg.outAmount,
65398
+ otherAmountThreshold: firstLeg.otherAmountThreshold,
65399
+ ...compoundQuoteRisk(firstLeg, secondLeg),
65272
65400
  provider: firstLeg.provider
65273
65401
  };
65274
65402
  }
@@ -65711,6 +65839,76 @@ var fetchMarginfiAccountAddresses = async (program, authority, group) => {
65711
65839
  ])).map((a) => a.publicKey);
65712
65840
  return marginfiAccounts;
65713
65841
  };
65842
+ var MARGINFI_ACCOUNT_DISCRIMINATOR = Buffer.from([67, 178, 130, 109, 126, 114, 28, 42]);
65843
+ var GROUP_OFFSET = 8;
65844
+ var BALANCES_OFFSET = 72;
65845
+ var BALANCE_SIZE = 104;
65846
+ var BANK_PK_OFFSET_IN_BALANCE = 1;
65847
+ var MAX_BALANCES = 16;
65848
+ var scanBankSlots = async (program, group, bank, options) => {
65849
+ const connection = program.provider.connection;
65850
+ const programId = program.programId;
65851
+ const discriminatorBytes = bs58__default.default.encode(MARGINFI_ACCOUNT_DISCRIMINATOR);
65852
+ const groupBytes = group.toBase58();
65853
+ const bankBytes = bank.toBase58();
65854
+ const slotOffsets = Array.from(
65855
+ { length: MAX_BALANCES },
65856
+ (_, n) => BALANCES_OFFSET + BANK_PK_OFFSET_IN_BALANCE + n * BALANCE_SIZE
65857
+ );
65858
+ const scanSlot = (offset) => {
65859
+ const filters = [
65860
+ { memcmp: { offset: 0, bytes: discriminatorBytes } },
65861
+ { memcmp: { offset: GROUP_OFFSET, bytes: groupBytes } },
65862
+ { memcmp: { offset, bytes: bankBytes } }
65863
+ ];
65864
+ return connection.getProgramAccounts(programId, {
65865
+ filters,
65866
+ dataSlice: options.dataSlice
65867
+ });
65868
+ };
65869
+ const byAddress = /* @__PURE__ */ new Map();
65870
+ const collect = (slotResults) => {
65871
+ for (const { pubkey, account } of slotResults) {
65872
+ byAddress.set(pubkey.toBase58(), account);
65873
+ }
65874
+ };
65875
+ const concurrency = options.concurrency;
65876
+ if (concurrency === void 0 || concurrency >= slotOffsets.length) {
65877
+ (await Promise.all(slotOffsets.map(scanSlot))).forEach(collect);
65878
+ } else {
65879
+ const batchSize = Math.max(1, Math.floor(concurrency));
65880
+ for (let i = 0; i < slotOffsets.length; i += batchSize) {
65881
+ const batch = slotOffsets.slice(i, i + batchSize);
65882
+ (await Promise.all(batch.map(scanSlot))).forEach(collect);
65883
+ }
65884
+ }
65885
+ return byAddress;
65886
+ };
65887
+ var fetchMarginfiAccountAddressesHoldingBank = async (program, group, bank, options) => {
65888
+ const byAddress = await scanBankSlots(program, group, bank, {
65889
+ concurrency: options?.concurrency,
65890
+ dataSlice: { offset: 0, length: 0 }
65891
+ });
65892
+ return Array.from(byAddress.keys(), (a) => new web3_js.PublicKey(a));
65893
+ };
65894
+ var fetchMarginfiAccountActiveBalancesForBank = async (program, group, bank, options) => {
65895
+ const byAddress = await scanBankSlots(program, group, bank, {
65896
+ concurrency: options?.concurrency
65897
+ });
65898
+ const results = [];
65899
+ for (const [address, account] of byAddress) {
65900
+ const accountAddress = new web3_js.PublicKey(address);
65901
+ const raw = program.coder.accounts.decode(
65902
+ "marginfiAccount" /* MarginfiAccount */,
65903
+ account.data
65904
+ );
65905
+ const parsed = parseMarginfiAccountRaw(accountAddress, raw);
65906
+ const balance = parsed.balances.find((b) => b.active && b.bankPk.equals(bank));
65907
+ if (!balance) continue;
65908
+ results.push({ accountAddress, authority: parsed.authority, balance });
65909
+ }
65910
+ return results;
65911
+ };
65714
65912
  var fetchMarginfiAccountData = async (program, marginfiAccountPk, banksMap, bankIntegrationMap) => {
65715
65913
  const marginfiAccountRaw = await program.account.marginfiAccount.fetch(
65716
65914
  marginfiAccountPk,
@@ -65987,6 +66185,33 @@ function patchDepositAmount(ix, amountNative) {
65987
66185
  amountNative.toArrayLike(Buffer, "le", 8).copy(ix.data, DEPOSIT_AMOUNT_OFFSET);
65988
66186
  }
65989
66187
 
66188
+ // src/services/account/utils/bridge.utils.ts
66189
+ function accountConflictsWithBridge(account, bankPk, side) {
66190
+ const balance = account.balances.find((b) => b.active && b.bankPk.equals(bankPk));
66191
+ if (!balance) return false;
66192
+ return side === "deposit" ? balance.liabilityShares.gt(0) : balance.assetShares.gt(0);
66193
+ }
66194
+ function resolveBridgeBanks(params) {
66195
+ const { orderedBridgeMints, banks, marginfiAccount, side } = params;
66196
+ const passesSideFilter = side === "borrow" ? isStandardBorrowable : isStandardDepositable;
66197
+ const bridges = [];
66198
+ const conflicts = [];
66199
+ const seenMints = /* @__PURE__ */ new Set();
66200
+ for (const mint of orderedBridgeMints) {
66201
+ const mintKey = mint.toBase58();
66202
+ if (seenMints.has(mintKey)) continue;
66203
+ seenMints.add(mintKey);
66204
+ const bank = banks.find((b) => b.mint.equals(mint) && passesSideFilter(b));
66205
+ if (!bank) continue;
66206
+ if (accountConflictsWithBridge(marginfiAccount, bank.address, side)) {
66207
+ conflicts.push(bank);
66208
+ } else {
66209
+ bridges.push(bank);
66210
+ }
66211
+ }
66212
+ return { bridges, conflicts };
66213
+ }
66214
+
65990
66215
  // src/services/price/utils/smart-crank.utils.ts
65991
66216
  async function computeSmartCrank({
65992
66217
  marginfiAccount,
@@ -67487,6 +67712,14 @@ function computeRemainingCapacity(bank) {
67487
67712
  }
67488
67713
 
67489
67714
  // src/services/bank/utils/bank-metrics.utils.ts
67715
+ function isStandardBorrowable(bank) {
67716
+ const { assetTag, operationalState, borrowLimit } = bank.config;
67717
+ return (assetTag === 0 /* DEFAULT */ || assetTag === 1 /* SOL */) && operationalState === "Operational" /* Operational */ && borrowLimit.gt(0);
67718
+ }
67719
+ function isStandardDepositable(bank) {
67720
+ const { assetTag, operationalState } = bank.config;
67721
+ return (assetTag === 0 /* DEFAULT */ || assetTag === 1 /* SOL */) && operationalState === "Operational" /* Operational */;
67722
+ }
67490
67723
  function computeBankTotalDeposits(bank, assetShareValueMultiplier) {
67491
67724
  const totalAssets = getTotalAssetQuantity(bank).times(
67492
67725
  assetShareValueMultiplier ?? 1
@@ -68965,7 +69198,7 @@ async function fetchBankIntegrationMetadata(options) {
68965
69198
  return bankIntegrationMap;
68966
69199
  }
68967
69200
  var Bank = class _Bank {
68968
- constructor(address, mint, mintDecimals, group, assetShareValue, liabilityShareValue, liquidityVault, liquidityVaultBump, liquidityVaultAuthorityBump, insuranceVault, insuranceVaultBump, insuranceVaultAuthorityBump, collectedInsuranceFeesOutstanding, feeVault, feeVaultBump, feeVaultAuthorityBump, collectedGroupFeesOutstanding, lastUpdate, config, totalAssetShares, totalLiabilityShares, emissionsActiveBorrowing, emissionsActiveLending, emissionsRate, emissionsMint, emissionsRemaining, oracleKey, emode, kaminoIntegrationAccounts, driftIntegrationAccounts, solendIntegrationAccounts, jupLendIntegrationAccounts, feesDestinationAccount, lendingPositionCount, borrowingPositionCount, tokenSymbol) {
69201
+ constructor(address, mint, mintDecimals, group, assetShareValue, liabilityShareValue, liquidityVault, liquidityVaultBump, liquidityVaultAuthorityBump, insuranceVault, insuranceVaultBump, insuranceVaultAuthorityBump, collectedInsuranceFeesOutstanding, feeVault, feeVaultBump, feeVaultAuthorityBump, collectedGroupFeesOutstanding, lastUpdate, config, totalAssetShares, totalLiabilityShares, emissionsActiveBorrowing, emissionsActiveLending, emissionsRate, emissionsMint, emissionsRemaining, collectedProgramFeesOutstanding, oracleKey, emode, rateLimiter, kaminoIntegrationAccounts, driftIntegrationAccounts, solendIntegrationAccounts, jupLendIntegrationAccounts, feesDestinationAccount, lendingPositionCount, borrowingPositionCount, tokenSymbol) {
68969
69202
  this.address = address;
68970
69203
  this.mint = mint;
68971
69204
  this.mintDecimals = mintDecimals;
@@ -68992,8 +69225,10 @@ var Bank = class _Bank {
68992
69225
  this.emissionsRate = emissionsRate;
68993
69226
  this.emissionsMint = emissionsMint;
68994
69227
  this.emissionsRemaining = emissionsRemaining;
69228
+ this.collectedProgramFeesOutstanding = collectedProgramFeesOutstanding;
68995
69229
  this.oracleKey = oracleKey;
68996
69230
  this.emode = emode;
69231
+ this.rateLimiter = rateLimiter;
68997
69232
  this.kaminoIntegrationAccounts = kaminoIntegrationAccounts;
68998
69233
  this.driftIntegrationAccounts = driftIntegrationAccounts;
68999
69234
  this.solendIntegrationAccounts = solendIntegrationAccounts;
@@ -69061,8 +69296,10 @@ var Bank = class _Bank {
69061
69296
  bankType.emissionsRate,
69062
69297
  bankType.emissionsMint,
69063
69298
  bankType.emissionsRemaining,
69299
+ bankType.collectedProgramFeesOutstanding,
69064
69300
  bankType.oracleKey,
69065
69301
  bankType.emode,
69302
+ bankType.rateLimiter,
69066
69303
  bankType.kaminoIntegrationAccounts,
69067
69304
  bankType.driftIntegrationAccounts,
69068
69305
  bankType.solendIntegrationAccounts,
@@ -69102,8 +69339,10 @@ var Bank = class _Bank {
69102
69339
  props.emissionsRate,
69103
69340
  props.emissionsMint,
69104
69341
  props.emissionsRemaining,
69342
+ props.collectedProgramFeesOutstanding,
69105
69343
  props.oracleKey,
69106
69344
  props.emode,
69345
+ props.rateLimiter,
69107
69346
  props.kaminoIntegrationAccounts,
69108
69347
  props.driftIntegrationAccounts,
69109
69348
  props.solendIntegrationAccounts,
@@ -70170,6 +70409,69 @@ var Project0Client = class _Project0Client {
70170
70409
  async getAccountAddresses(authority) {
70171
70410
  return fetchMarginfiAccountAddresses(this.program, authority, this.group.address);
70172
70411
  }
70412
+ /**
70413
+ * Fetches the addresses of all marginfi accounts in the group that hold a position in a
70414
+ * specific bank.
70415
+ *
70416
+ * Because a marginfi account holds up to 16 balance slots (sorted descending by bank, so the
70417
+ * target can be at any slot), this scans all 16 slots in parallel via filtered
70418
+ * `getProgramAccounts` calls. It returns only addresses (no account data is transferred),
70419
+ * which keeps it viable across the group's ~500k accounts. Hydrate any address you care about
70420
+ * with `fetchAccount`.
70421
+ *
70422
+ * @param bank - The bank public key to search for in account balances
70423
+ * @param options - Optional settings:
70424
+ * - `concurrency`: max number of the 16 slot scans to run at once. Omit to fire all 16 in
70425
+ * parallel; pass a smaller value (e.g. 4) to batch them and avoid RPC rate limits.
70426
+ * @returns Deduplicated array of account addresses holding the bank
70427
+ */
70428
+ async getAccountAddressesHoldingBank(bank, options) {
70429
+ return fetchMarginfiAccountAddressesHoldingBank(
70430
+ this.program,
70431
+ this.group.address,
70432
+ bank,
70433
+ options
70434
+ );
70435
+ }
70436
+ /**
70437
+ * Fetches every account's active balance for a given mint, with its authority, account
70438
+ * address, and the deposited/borrowed amounts in UI units.
70439
+ *
70440
+ * A mint can map to multiple banks (e.g. DEFAULT + Kamino), so this resolves all matching
70441
+ * banks via {@link getBanksByMint}, scans each for accounts holding it, and emits one row per
70442
+ * (account, bank). An account that holds the mint in several banks yields several rows.
70443
+ *
70444
+ * Amounts are computed with each bank's share multiplier (`assetShareValueMultiplierByBank`)
70445
+ * and the bank's mint decimals, matching `Balance.computeQuantityUi`.
70446
+ *
70447
+ * @param mint - The mint to search account balances for
70448
+ * @param options - Optional settings:
70449
+ * - `assetTag`: restrict to banks with this asset tag (e.g. only Kamino banks for the mint)
70450
+ * - `concurrency`: max number of the 16 slot scans to run at once per bank (see
70451
+ * {@link getAccountAddressesHoldingBank})
70452
+ * @returns One row per (account, bank) holding the mint
70453
+ */
70454
+ async getAuthorityBalancesForMint(mint, options) {
70455
+ const banks = this.getBanksByMint(mint, options?.assetTag);
70456
+ const rows = [];
70457
+ for (const bank of banks) {
70458
+ const multiplier = this.assetShareValueMultiplierByBank.get(bank.address.toBase58());
70459
+ const balances = await fetchMarginfiAccountActiveBalancesForBank(
70460
+ this.program,
70461
+ this.group.address,
70462
+ bank.address,
70463
+ { concurrency: options?.concurrency }
70464
+ );
70465
+ for (const { accountAddress, authority, balance } of balances) {
70466
+ const { assets, liabilities } = Balance.fromBalanceType(balance).computeQuantityUi(
70467
+ bank,
70468
+ multiplier
70469
+ );
70470
+ rows.push({ authority, accountAddress, bank: bank.address, assets, liabilities });
70471
+ }
70472
+ }
70473
+ return rows;
70474
+ }
70173
70475
  /**
70174
70476
  * Fetches and wraps a marginfi account in one call.
70175
70477
  *
@@ -70448,6 +70750,7 @@ exports.USDC_DECIMALS = USDC_DECIMALS;
70448
70750
  exports.USDC_MINT = USDC_MINT;
70449
70751
  exports.WSOL_MINT = WSOL_MINT;
70450
70752
  exports.ZERO_ORACLE_KEY = ZERO_ORACLE_KEY;
70753
+ exports.accountConflictsWithBridge = accountConflictsWithBridge;
70451
70754
  exports.accountFlagToBN = accountFlagToBN;
70452
70755
  exports.addOracleToBanksIx = addOracleToBanksIx;
70453
70756
  exports.addTransactionMetadata = addTransactionMetadata;
@@ -70459,6 +70762,7 @@ exports.bankConfigRawToDto = bankConfigRawToDto;
70459
70762
  exports.bankConfigToBankConfigRaw = bankConfigToBankConfigRaw;
70460
70763
  exports.bankMetadataMapToDto = bankMetadataMapToDto;
70461
70764
  exports.bankMetadataToDto = bankMetadataToDto;
70765
+ exports.bankRateLimiterRawToDto = bankRateLimiterRawToDto;
70462
70766
  exports.bankRawToDto = bankRawToDto;
70463
70767
  exports.bigNumberToWrappedI80F48 = bigNumberToWrappedI80F48;
70464
70768
  exports.bpsToPercentile = bpsToPercentile;
@@ -70554,6 +70858,8 @@ exports.dtoToBankConfig = dtoToBankConfig;
70554
70858
  exports.dtoToBankConfigRaw = dtoToBankConfigRaw;
70555
70859
  exports.dtoToBankMetadata = dtoToBankMetadata;
70556
70860
  exports.dtoToBankMetadataMap = dtoToBankMetadataMap;
70861
+ exports.dtoToBankRateLimiter = dtoToBankRateLimiter;
70862
+ exports.dtoToBankRateLimiterRaw = dtoToBankRateLimiterRaw;
70557
70863
  exports.dtoToBankRaw = dtoToBankRaw;
70558
70864
  exports.dtoToEmodeSettings = dtoToEmodeSettings;
70559
70865
  exports.dtoToEmodeSettingsRaw = dtoToEmodeSettingsRaw;
@@ -70567,7 +70873,9 @@ exports.emodeSettingsRawToDto = emodeSettingsRawToDto;
70567
70873
  exports.extractPythOracleKeys = extractPythOracleKeys;
70568
70874
  exports.fetchBank = fetchBank;
70569
70875
  exports.fetchBankIntegrationMetadata = fetchBankIntegrationMetadata;
70876
+ exports.fetchMarginfiAccountActiveBalancesForBank = fetchMarginfiAccountActiveBalancesForBank;
70570
70877
  exports.fetchMarginfiAccountAddresses = fetchMarginfiAccountAddresses;
70878
+ exports.fetchMarginfiAccountAddressesHoldingBank = fetchMarginfiAccountAddressesHoldingBank;
70571
70879
  exports.fetchMarginfiAccountData = fetchMarginfiAccountData;
70572
70880
  exports.fetchMultipleBanks = fetchMultipleBanks;
70573
70881
  exports.fetchNativeStakeAccounts = fetchNativeStakeAccounts;
@@ -70643,8 +70951,11 @@ exports.hasEmodeEntryFlag = hasEmodeEntryFlag;
70643
70951
  exports.hasEmodeFlag = hasEmodeFlag;
70644
70952
  exports.hasHealthCacheFlag = hasHealthCacheFlag;
70645
70953
  exports.healthCacheToDto = healthCacheToDto;
70954
+ exports.isDecomposableSwapError = isDecomposableSwapError;
70646
70955
  exports.isDepositIx = isDepositIx;
70647
70956
  exports.isFlashloan = isFlashloan;
70957
+ exports.isStandardBorrowable = isStandardBorrowable;
70958
+ exports.isStandardDepositable = isStandardDepositable;
70648
70959
  exports.isV0Tx = isV0Tx;
70649
70960
  exports.isWeightedPrice = isWeightedPrice;
70650
70961
  exports.isWholePosition = isWholePosition;
@@ -70713,10 +71024,13 @@ exports.mapPythBanksToOraclePrices = mapPythBanksToOraclePrices;
70713
71024
  exports.mapSwbBanksToOraclePrices = mapSwbBanksToOraclePrices;
70714
71025
  exports.marginfiAccountToDto = marginfiAccountToDto;
70715
71026
  exports.mergeBridgeQuotes = mergeBridgeQuotes;
71027
+ exports.mergeBridgeQuotesDebt = mergeBridgeQuotesDebt;
71028
+ exports.mergeBridgeQuotesLoop = mergeBridgeQuotesLoop;
70716
71029
  exports.nativeToUi = nativeToUi;
70717
71030
  exports.oraclePriceToDto = oraclePriceToDto;
70718
71031
  exports.parseBalanceRaw = parseBalanceRaw;
70719
71032
  exports.parseBankConfigRaw = parseBankConfigRaw;
71033
+ exports.parseBankRateLimiterRaw = parseBankRateLimiterRaw;
70720
71034
  exports.parseBankRaw = parseBankRaw;
70721
71035
  exports.parseEmodeSettingsRaw = parseEmodeSettingsRaw;
70722
71036
  exports.parseEmodeTag = parseEmodeTag;
@@ -70731,6 +71045,7 @@ exports.parseSwbOraclePriceData = parseSwbOraclePriceData;
70731
71045
  exports.partitionBanksByCrankability = partitionBanksByCrankability;
70732
71046
  exports.patchDepositAmount = patchDepositAmount;
70733
71047
  exports.resolveAmount = resolveAmount;
71048
+ exports.resolveBridgeBanks = resolveBridgeBanks;
70734
71049
  exports.runSwapEngine = runSwapEngine;
70735
71050
  exports.selectLutsForAccountAction = selectLutsForAccountAction;
70736
71051
  exports.selectLutsForBanks = selectLutsForBanks;