@0dotxyz/p0-ts-sdk 2.0.0-alpha.0 → 2.0.0-alpha.2

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
@@ -13723,6 +13723,12 @@ var AccountType = /* @__PURE__ */ ((AccountType2) => {
13723
13723
  AccountType2["Bank"] = "bank";
13724
13724
  return AccountType2;
13725
13725
  })(AccountType || {});
13726
+ function resolveAmount(amount) {
13727
+ if (typeof amount === "object" && amount !== null && "type" in amount && "value" in amount) {
13728
+ return amount;
13729
+ }
13730
+ return { value: amount, type: "uiToken" };
13731
+ }
13726
13732
 
13727
13733
  // src/services/bank/utils/deserialize.utils.ts
13728
13734
  function decodeBankRaw(encoded, idl) {
@@ -17688,11 +17694,11 @@ var AccountFlags = /* @__PURE__ */ ((AccountFlags2) => {
17688
17694
  AccountFlags2[AccountFlags2["ACCOUNT_TRANSFER_AUTHORITY_ALLOWED"] = 8] = "ACCOUNT_TRANSFER_AUTHORITY_ALLOWED";
17689
17695
  return AccountFlags2;
17690
17696
  })(AccountFlags || {});
17691
- var MarginRequirementType = /* @__PURE__ */ ((MarginRequirementType4) => {
17692
- MarginRequirementType4[MarginRequirementType4["Initial"] = 0] = "Initial";
17693
- MarginRequirementType4[MarginRequirementType4["Maintenance"] = 1] = "Maintenance";
17694
- MarginRequirementType4[MarginRequirementType4["Equity"] = 2] = "Equity";
17695
- return MarginRequirementType4;
17697
+ var MarginRequirementType = /* @__PURE__ */ ((MarginRequirementType5) => {
17698
+ MarginRequirementType5[MarginRequirementType5["Initial"] = 0] = "Initial";
17699
+ MarginRequirementType5[MarginRequirementType5["Maintenance"] = 1] = "Maintenance";
17700
+ MarginRequirementType5[MarginRequirementType5["Equity"] = 2] = "Equity";
17701
+ return MarginRequirementType5;
17696
17702
  })(MarginRequirementType || {});
17697
17703
 
17698
17704
  // src/services/account/types/simulation.types.ts
@@ -17912,6 +17918,47 @@ function healthCacheToDto(healthCache) {
17912
17918
  simulationStatus: healthCache.simulationStatus
17913
17919
  };
17914
17920
  }
17921
+ function getEmodePairs(banks) {
17922
+ const emodePairs = [];
17923
+ banks.forEach((bank) => {
17924
+ const emodeTag = bank.emode.emodeTag;
17925
+ if (emodeTag === 0 /* UNSET */) {
17926
+ return;
17927
+ }
17928
+ bank.emode.emodeEntries.forEach((emodeEntry) => {
17929
+ emodePairs.push({
17930
+ collateralBanks: banks.filter((b) => b.emode.emodeTag === emodeEntry.collateralBankEmodeTag).map((b) => b.address),
17931
+ collateralBankTag: emodeEntry.collateralBankEmodeTag,
17932
+ liabilityBank: bank.address,
17933
+ liabilityBankTag: emodeTag,
17934
+ assetWeightMaint: emodeEntry.assetWeightMaint,
17935
+ assetWeightInit: emodeEntry.assetWeightInit
17936
+ });
17937
+ });
17938
+ });
17939
+ return emodePairs;
17940
+ }
17941
+ function computeLowestEmodeWeights(emodePairs) {
17942
+ const result = /* @__PURE__ */ new Map();
17943
+ emodePairs.forEach((emodePair) => {
17944
+ emodePair.collateralBanks.forEach((collateralBankPk) => {
17945
+ const bankPkStr = collateralBankPk.toBase58();
17946
+ const existing = result.get(bankPkStr);
17947
+ if (!existing) {
17948
+ result.set(bankPkStr, {
17949
+ assetWeightInit: emodePair.assetWeightInit,
17950
+ assetWeightMaint: emodePair.assetWeightMaint
17951
+ });
17952
+ } else {
17953
+ result.set(bankPkStr, {
17954
+ assetWeightInit: BigNumber4__default.default.min(existing.assetWeightInit, emodePair.assetWeightInit),
17955
+ assetWeightMaint: BigNumber4__default.default.min(existing.assetWeightMaint, emodePair.assetWeightMaint)
17956
+ });
17957
+ }
17958
+ });
17959
+ });
17960
+ return result;
17961
+ }
17915
17962
  function createActiveEmodePairFromPairs(pairs) {
17916
17963
  if (pairs.length === 0) {
17917
17964
  return void 0;
@@ -17928,28 +17975,20 @@ function createActiveEmodePairFromPairs(pairs) {
17928
17975
  pairs.map((p) => p.collateralBanks).flat().map((bank) => [bank.toBase58(), bank])
17929
17976
  ).values()
17930
17977
  ),
17931
- collateralBankTags: Array.from(
17932
- new Set(pairs.map((p) => p.collateralBankTag).flat())
17933
- ),
17978
+ collateralBankTags: Array.from(new Set(pairs.map((p) => p.collateralBankTag).flat())),
17934
17979
  liabilityBanks: Array.from(
17935
17980
  new Map(
17936
17981
  pairs.map((p) => p.liabilityBank).flat().map((bank) => [bank.toBase58(), bank])
17937
17982
  ).values()
17938
17983
  ),
17939
- liabilityBankTags: Array.from(
17940
- new Set(pairs.map((p) => p.liabilityBankTag).flat())
17941
- ),
17984
+ liabilityBankTags: Array.from(new Set(pairs.map((p) => p.liabilityBankTag).flat())),
17942
17985
  assetWeightMaint: bestPair.assetWeightMaint,
17943
17986
  assetWeightInit: bestPair.assetWeightInit
17944
17987
  };
17945
17988
  }
17946
17989
  function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, allBanks) {
17947
17990
  const toKey = (k) => k.toBase58();
17948
- const basePairs = computeActiveEmodePairs(
17949
- emodePairs,
17950
- activeLiabilities,
17951
- activeCollateral
17952
- );
17991
+ const basePairs = computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral);
17953
17992
  const baseOn = basePairs.length > 0;
17954
17993
  const liabTagMap = /* @__PURE__ */ new Map();
17955
17994
  for (const p of emodePairs) {
@@ -17974,9 +18013,7 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
17974
18013
  return 1 /* ExtendEmode */;
17975
18014
  }
17976
18015
  function simulate(bank, action) {
17977
- bank.equals(
17978
- new web3_js.PublicKey("CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh")
17979
- );
18016
+ bank.equals(new web3_js.PublicKey("CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh"));
17980
18017
  let L = [...activeLiabilities], C = [...activeCollateral];
17981
18018
  switch (action) {
17982
18019
  case "borrow":
@@ -18036,9 +18073,7 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
18036
18073
  if (!activeCollateral.some((x) => x.equals(bank))) {
18037
18074
  impact.borrowImpact = simulate(bank, "borrow");
18038
18075
  }
18039
- const collSet = new Set(
18040
- emodePairs.flatMap((p) => p.collateralBanks.map((c) => c.toBase58()))
18041
- );
18076
+ const collSet = new Set(emodePairs.flatMap((p) => p.collateralBanks.map((c) => c.toBase58())));
18042
18077
  if (collSet.has(key) && !activeCollateral.some((x) => x.equals(bank)) && !activeLiabilities.some((x) => x.equals(bank))) {
18043
18078
  impact.supplyImpact = simulate(bank, "supply");
18044
18079
  }
@@ -18058,10 +18093,7 @@ function computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral
18058
18093
  );
18059
18094
  const liabTagByBank = /* @__PURE__ */ new Map();
18060
18095
  for (const p of configured) {
18061
- liabTagByBank.set(
18062
- p.liabilityBank.toBase58(),
18063
- p.liabilityBankTag.toString()
18064
- );
18096
+ liabTagByBank.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
18065
18097
  }
18066
18098
  const requiredTags = /* @__PURE__ */ new Set();
18067
18099
  for (const liab of activeLiabilities) {
@@ -42040,7 +42072,7 @@ async function makeKaminoWithdrawIx3({
42040
42072
  bank,
42041
42073
  bankMap,
42042
42074
  tokenProgram,
42043
- amount,
42075
+ cTokenAmount,
42044
42076
  marginfiAccount,
42045
42077
  reserve,
42046
42078
  authority,
@@ -42109,7 +42141,7 @@ async function makeKaminoWithdrawIx3({
42109
42141
  reserveFarmState: reserveFarm
42110
42142
  },
42111
42143
  {
42112
- amount: uiToNative(amount, bank.mintDecimals),
42144
+ amount: uiToNative(cTokenAmount, bank.mintDecimals),
42113
42145
  isFinalWithdrawal: withdrawAll
42114
42146
  },
42115
42147
  remainingAccounts.map((account) => ({
@@ -42136,7 +42168,7 @@ async function makeKaminoWithdrawIx3({
42136
42168
  group: opts.overrideInferAccounts?.group ?? marginfiAccount.group
42137
42169
  },
42138
42170
  {
42139
- amount: uiToNative(amount, bank.mintDecimals),
42171
+ amount: uiToNative(cTokenAmount, bank.mintDecimals),
42140
42172
  isFinalWithdrawal: withdrawAll
42141
42173
  },
42142
42174
  remainingAccounts.map((account) => ({
@@ -42310,11 +42342,13 @@ async function makeWithdrawTx(params) {
42310
42342
  return { transactions, actionTxIndex: transactions.length - 1 };
42311
42343
  }
42312
42344
  async function makeKaminoWithdrawTx(params) {
42313
- const { luts, connection, amount, ...withdrawIxParams } = params;
42345
+ const { luts, connection, amount, assetShareValueMultiplierByBank, ...withdrawIxParams } = params;
42314
42346
  if (!withdrawIxParams.bank.kaminoIntegrationAccounts) {
42315
42347
  throw new Error("Bank has no kamino integration accounts");
42316
42348
  }
42317
- const adjustedAmount = new BigNumber4.BigNumber(amount).div(withdrawIxParams.bank.assetShareValue).toNumber();
42349
+ const { value: amountValue, type: amountType } = resolveAmount(amount);
42350
+ const multiplier = assetShareValueMultiplierByBank.get(withdrawIxParams.bank.address.toBase58()) ?? new BigNumber4.BigNumber(1);
42351
+ const adjustedAmount = amountType === "cToken" ? new BigNumber4.BigNumber(amountValue).toNumber() : new BigNumber4.BigNumber(amountValue).div(multiplier).toNumber();
42318
42352
  const refreshIxs = makeRefreshKaminoBanksIxs(
42319
42353
  params.marginfiAccount,
42320
42354
  params.bankMap,
@@ -42328,7 +42362,7 @@ async function makeKaminoWithdrawTx(params) {
42328
42362
  params.bankMetadataMap
42329
42363
  );
42330
42364
  const withdrawIxs = await makeKaminoWithdrawIx3({
42331
- amount: adjustedAmount,
42365
+ cTokenAmount: adjustedAmount,
42332
42366
  ...withdrawIxParams
42333
42367
  });
42334
42368
  const { instructions: updateFeedIxs, luts: feedLuts } = await makeSmartCrankSwbFeedIx({
@@ -43427,6 +43461,7 @@ async function buildRepayWithCollatFlashloanTx({
43427
43461
  withdrawOpts,
43428
43462
  repayOpts,
43429
43463
  bankMetadataMap,
43464
+ assetShareValueMultiplierByBank,
43430
43465
  addressLookupTableAccounts,
43431
43466
  connection,
43432
43467
  swapOpts,
@@ -43499,13 +43534,14 @@ async function buildRepayWithCollatFlashloanTx({
43499
43534
  withdrawOpts.withdrawBank.tokenSymbol
43500
43535
  );
43501
43536
  }
43502
- const adjustedAmount = new BigNumber4.BigNumber(withdrawOpts.withdrawAmount).div(withdrawOpts.withdrawBank.assetShareValue).times(1.0001).toNumber();
43537
+ const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new BigNumber4.BigNumber(1);
43538
+ const adjustedAmount = new BigNumber4.BigNumber(withdrawOpts.withdrawAmount).div(multiplier).times(1.0001).toNumber();
43503
43539
  withdrawIxs = await makeKaminoWithdrawIx3({
43504
43540
  program,
43505
43541
  bank: withdrawOpts.withdrawBank,
43506
43542
  bankMap,
43507
43543
  tokenProgram: withdrawOpts.tokenProgram,
43508
- amount: adjustedAmount,
43544
+ cTokenAmount: adjustedAmount,
43509
43545
  marginfiAccount,
43510
43546
  authority: marginfiAccount.authority,
43511
43547
  reserve,
@@ -43798,6 +43834,7 @@ async function buildSwapCollateralFlashloanTx({
43798
43834
  depositOpts,
43799
43835
  swapOpts,
43800
43836
  bankMetadataMap,
43837
+ assetShareValueMultiplierByBank,
43801
43838
  addressLookupTableAccounts,
43802
43839
  connection,
43803
43840
  overrideInferAccounts,
@@ -43835,13 +43872,14 @@ async function buildSwapCollateralFlashloanTx({
43835
43872
  withdrawOpts.withdrawBank.tokenSymbol
43836
43873
  );
43837
43874
  }
43838
- const adjustedAmount = new BigNumber4.BigNumber(actualWithdrawAmount).div(withdrawOpts.withdrawBank.assetShareValue).times(1.0001).toNumber();
43875
+ const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new BigNumber4.BigNumber(1);
43876
+ const adjustedAmount = new BigNumber4.BigNumber(actualWithdrawAmount).div(multiplier).times(1.0001).toNumber();
43839
43877
  withdrawIxs = await makeKaminoWithdrawIx3({
43840
43878
  program,
43841
43879
  bank: withdrawBank,
43842
43880
  bankMap,
43843
43881
  tokenProgram: withdrawTokenProgram,
43844
- amount: adjustedAmount,
43882
+ cTokenAmount: adjustedAmount,
43845
43883
  marginfiAccount,
43846
43884
  authority: marginfiAccount.authority,
43847
43885
  reserve,
@@ -44853,7 +44891,7 @@ function computeMaxBorrowForBank(params) {
44853
44891
  });
44854
44892
  const liabWeight = getLiabilityWeight(bank.config, 0 /* Initial */);
44855
44893
  if (assetWeight.eq(0)) {
44856
- return computeQuantityUi(balance, bank).assets.plus(
44894
+ return computeQuantityUi(balance, bank, assetShareValueMultiplier).assets.plus(
44857
44895
  freeCollateral.minus(untiedCollateralForBank).div(priceHighestBias.times(liabWeight))
44858
44896
  );
44859
44897
  } else {
@@ -45303,7 +45341,9 @@ async function computeSmartCrank({
45303
45341
  };
45304
45342
  }
45305
45343
  async function makeSmartCrankSwbFeedIx(params) {
45344
+ console.log("[makeSmartCrankSwbFeedIx] Called");
45306
45345
  const crankResult = await computeSmartCrank(params);
45346
+ console.log("[makeSmartCrankSwbFeedIx] Crank result:", crankResult);
45307
45347
  if (crankResult.uncrankableLiabilities.length > 0) {
45308
45348
  console.log(
45309
45349
  "Uncrankable liability details:",
@@ -45339,6 +45379,7 @@ async function makeSmartCrankSwbFeedIx(params) {
45339
45379
  );
45340
45380
  }
45341
45381
  const oraclesToCrank = crankResult.requiredOracles;
45382
+ console.log("[makeSmartCrankSwbFeedIx] Oracles to crank:", oraclesToCrank);
45342
45383
  const { instructions: instructions2, luts } = await makeUpdateSwbFeedIx({
45343
45384
  swbPullOracles: oraclesToCrank,
45344
45385
  feePayer: params.marginfiAccount.authority,
@@ -45375,6 +45416,9 @@ async function makeCrankSwbFeedIx(marginfiAccount, bankMap, newBanksPk, provider
45375
45416
  }
45376
45417
  }
45377
45418
  async function makeUpdateSwbFeedIx(props) {
45419
+ console.log(
45420
+ `[makeUpdateSwbFeedIx] Called with ${props.swbPullOracles.length} oracles, feePayer: ${props.feePayer.toBase58()}`
45421
+ );
45378
45422
  const seen = /* @__PURE__ */ new Set();
45379
45423
  const uniqueOracles = props.swbPullOracles.filter((oracle) => {
45380
45424
  const key = oracle.key.toBase58();
@@ -45382,21 +45426,21 @@ async function makeUpdateSwbFeedIx(props) {
45382
45426
  seen.add(key);
45383
45427
  return true;
45384
45428
  });
45429
+ console.log(
45430
+ `[makeUpdateSwbFeedIx] ${uniqueOracles.length} unique oracles after dedup (removed ${props.swbPullOracles.length - uniqueOracles.length})`
45431
+ );
45432
+ uniqueOracles.forEach(
45433
+ (o) => console.log(
45434
+ `[makeUpdateSwbFeedIx] - ${o.key.toBase58()} (hasSwitchboardData: ${!!o.price?.switchboardData})`
45435
+ )
45436
+ );
45385
45437
  const swbProgram = await onDemand.AnchorUtils.loadProgramFromConnection(props.connection);
45386
45438
  const pullFeedInstances = uniqueOracles.map((oracle) => {
45387
45439
  const pullFeed = new onDemand.PullFeed(swbProgram, oracle.key);
45388
- if (oracle.price?.switchboardData) {
45389
- const swbData = oracle.price?.switchboardData;
45390
- pullFeed.data = {
45391
- queue: new web3_js.PublicKey(swbData.queue),
45392
- feedHash: new Uint8Array(Buffer.from(swbData.feedHash, "hex")),
45393
- maxVariance: new BN11.BN(swbData.maxVariance),
45394
- minResponses: swbData.minResponses
45395
- };
45396
- }
45397
45440
  return pullFeed;
45398
45441
  });
45399
45442
  if (pullFeedInstances.length === 0) {
45443
+ console.log(`[makeUpdateSwbFeedIx] No pull feed instances, returning early`);
45400
45444
  return { instructions: [], luts: [] };
45401
45445
  }
45402
45446
  const crossbarClient = new common.CrossbarClient(
@@ -45418,6 +45462,7 @@ async function makeUpdateSwbFeedIx(props) {
45418
45462
  payer: props.feePayer,
45419
45463
  crossbarClient
45420
45464
  });
45465
+ console.log(`[makeUpdateSwbFeedIx] Got ${pullIx.length} instructions, ${luts.length} LUTs`);
45421
45466
  return { instructions: pullIx, luts };
45422
45467
  }
45423
45468
 
@@ -49034,6 +49079,30 @@ var MarginfiAccountWrapper = class {
49034
49079
  });
49035
49080
  }
49036
49081
  // ----------------------------------------------------------------------------
49082
+ // E-mode state — derived from client.emodePairs + account balances
49083
+ // ----------------------------------------------------------------------------
49084
+ /**
49085
+ * Returns the active emode pairs for this account based on current positions.
49086
+ */
49087
+ getActiveEmodePairs() {
49088
+ return this.account.computeActiveEmodePairs(this.client.emodePairs);
49089
+ }
49090
+ /**
49091
+ * Returns the lowest emode weights per collateral bank for currently active pairs.
49092
+ * Keyed by bank address string → { assetWeightInit, assetWeightMaint }.
49093
+ */
49094
+ getActiveEmodeWeightsByBank() {
49095
+ const activePairs = this.getActiveEmodePairs();
49096
+ return computeLowestEmodeWeights(activePairs);
49097
+ }
49098
+ /**
49099
+ * Computes emode impacts for all banks using the client's emode pairs.
49100
+ */
49101
+ getEmodeImpacts() {
49102
+ const bankAddresses = this.client.banks.map((b) => b.address);
49103
+ return this.account.computeEmodeImpacts(this.client.emodePairs, bankAddresses);
49104
+ }
49105
+ // ----------------------------------------------------------------------------
49037
49106
  // Computation methods with auto-injected client data
49038
49107
  // ----------------------------------------------------------------------------
49039
49108
  /**
@@ -49046,8 +49115,7 @@ var MarginfiAccountWrapper = class {
49046
49115
  oraclePricesByBank: this.client.oraclePriceByBank,
49047
49116
  bankIntegrationMap: this.client.bankIntegrationMap,
49048
49117
  assetShareValueMultiplierByBank: this.client.assetShareValueMultiplierByBank,
49049
- activeEmodeWeightsByBank: /* @__PURE__ */ new Map()
49050
- // TODO
49118
+ activeEmodeWeightsByBank: this.getActiveEmodeWeightsByBank()
49051
49119
  });
49052
49120
  }
49053
49121
  /**
@@ -49058,8 +49126,7 @@ var MarginfiAccountWrapper = class {
49058
49126
  banksMap: this.client.bankMap,
49059
49127
  oraclePricesByBank: this.client.oraclePriceByBank,
49060
49128
  assetShareValueMultiplierByBank: this.client.assetShareValueMultiplierByBank,
49061
- activeEmodeWeightsByBank: /* @__PURE__ */ new Map()
49062
- // TODO
49129
+ activeEmodeWeightsByBank: this.getActiveEmodeWeightsByBank()
49063
49130
  });
49064
49131
  }
49065
49132
  /**
@@ -49091,15 +49158,17 @@ var MarginfiAccountWrapper = class {
49091
49158
  * @param opts - Optional configuration for emode and volatility
49092
49159
  */
49093
49160
  computeMaxBorrowForBank(bankAddress, opts) {
49161
+ const bankKey = bankAddress.toBase58();
49162
+ const emodeImpacts = this.getEmodeImpacts();
49163
+ const bankImpact = emodeImpacts[bankKey];
49164
+ const borrowImpact = bankImpact?.borrowImpact;
49094
49165
  return this.account.computeMaxBorrowForBank({
49095
49166
  banksMap: this.client.bankMap,
49096
49167
  oraclePricesByBank: this.client.oraclePriceByBank,
49097
49168
  bankAddress,
49098
49169
  assetShareValueMultiplierByBank: this.client.assetShareValueMultiplierByBank,
49099
- emodeImpactStatus: void 0,
49100
- // TODO
49101
- activePair: void 0,
49102
- // TODO
49170
+ emodeImpactStatus: borrowImpact?.status,
49171
+ activePair: borrowImpact?.activePair,
49103
49172
  volatilityFactor: opts?.volatilityFactor
49104
49173
  });
49105
49174
  }
@@ -49110,18 +49179,20 @@ var MarginfiAccountWrapper = class {
49110
49179
  * @param opts - Optional configuration for volatility and emode
49111
49180
  */
49112
49181
  computeMaxWithdrawForBank(bankAddress, opts) {
49182
+ const activePairs = this.getActiveEmodePairs();
49183
+ const activePair = activePairs.length > 0 ? createActiveEmodePairFromPairs(activePairs) : void 0;
49113
49184
  return this.account.computeMaxWithdrawForBank({
49114
49185
  banksMap: this.client.bankMap,
49115
49186
  oraclePricesByBank: this.client.oraclePriceByBank,
49116
49187
  bankAddress,
49117
49188
  assetShareValueMultiplierByBank: this.client.assetShareValueMultiplierByBank,
49118
- activePair: void 0,
49119
- // TODO
49189
+ activePair,
49120
49190
  volatilityFactor: opts?.volatilityFactor
49121
49191
  });
49122
49192
  }
49123
49193
  /**
49124
- * Computes active emode pairs.
49194
+ * Computes active emode pairs for custom emode pair sets.
49195
+ * For typical usage, prefer `getActiveEmodePairs()` which uses client data.
49125
49196
  *
49126
49197
  * @param emodePairs - All available emode pairs
49127
49198
  */
@@ -49129,7 +49200,8 @@ var MarginfiAccountWrapper = class {
49129
49200
  return this.account.computeActiveEmodePairs(emodePairs);
49130
49201
  }
49131
49202
  /**
49132
- * Computes emode impacts.
49203
+ * Computes emode impacts for custom emode pair sets.
49204
+ * For typical usage, prefer `getEmodeImpacts()` which uses client data.
49133
49205
  *
49134
49206
  * @param emodePairs - All available emode pairs
49135
49207
  * @param banks - Array of bank addresses to analyze
@@ -49164,7 +49236,7 @@ var MarginfiAccountWrapper = class {
49164
49236
  }
49165
49237
  };
49166
49238
  var Project0Client = class _Project0Client {
49167
- constructor(program, group, bankMap, bankIntegrationMap, assetShareValueMultiplierByBank, oraclePriceByBank, mintDataByBank, addressLookupTables) {
49239
+ constructor(program, group, bankMap, bankIntegrationMap, assetShareValueMultiplierByBank, oraclePriceByBank, mintDataByBank, addressLookupTables, emodePairs) {
49168
49240
  this.program = program;
49169
49241
  this.group = group;
49170
49242
  this.bankMap = bankMap;
@@ -49173,6 +49245,7 @@ var Project0Client = class _Project0Client {
49173
49245
  this.oraclePriceByBank = oraclePriceByBank;
49174
49246
  this.mintDataByBank = mintDataByBank;
49175
49247
  this.addressLookupTables = addressLookupTables;
49248
+ this.emodePairs = emodePairs;
49176
49249
  }
49177
49250
  /**
49178
49251
  * Gets all banks as an array.
@@ -49293,11 +49366,15 @@ var Project0Client = class _Project0Client {
49293
49366
  );
49294
49367
  if (!skipHealthCache) {
49295
49368
  const bankMap = new Map(this.banks.map((b) => [b.address.toBase58(), b]));
49369
+ const activePairs = marginfiAccountParsed.computeActiveEmodePairs(this.emodePairs);
49370
+ const activeEmodeWeightsByBank = computeLowestEmodeWeights(activePairs);
49296
49371
  const { account: simulatedAccount } = await marginfiAccountParsed.simulateHealthCache({
49297
49372
  program: this.program,
49298
49373
  banksMap: bankMap,
49299
49374
  oraclePricesByBank: this.oraclePriceByBank,
49300
- bankIntegrationMap: this.bankIntegrationMap
49375
+ bankIntegrationMap: this.bankIntegrationMap,
49376
+ assetShareValueMultiplierByBank: this.assetShareValueMultiplierByBank,
49377
+ activeEmodeWeightsByBank
49301
49378
  });
49302
49379
  marginfiAccountParsed = simulatedAccount;
49303
49380
  }
@@ -49394,6 +49471,7 @@ var Project0Client = class _Project0Client {
49394
49471
  break;
49395
49472
  }
49396
49473
  });
49474
+ const emodePairs = getEmodePairs(banksArray);
49397
49475
  return new _Project0Client(
49398
49476
  program,
49399
49477
  group,
@@ -49402,7 +49480,8 @@ var Project0Client = class _Project0Client {
49402
49480
  assetShareMultiplierByBank,
49403
49481
  bankOraclePriceMap,
49404
49482
  mintDataByBank,
49405
- addressLookupTables
49483
+ addressLookupTables,
49484
+ emodePairs
49406
49485
  );
49407
49486
  }
49408
49487
  };
@@ -49557,6 +49636,7 @@ exports.computeLiabilityHealthComponent = computeLiabilityHealthComponent;
49557
49636
  exports.computeLiabilityUsdValue = computeLiabilityUsdValue;
49558
49637
  exports.computeLiquidationPriceForBank = computeLiquidationPriceForBank;
49559
49638
  exports.computeLoopingParams = computeLoopingParams;
49639
+ exports.computeLowestEmodeWeights = computeLowestEmodeWeights;
49560
49640
  exports.computeMaxBorrowForBank = computeMaxBorrowForBank;
49561
49641
  exports.computeMaxLeverage = computeMaxLeverage;
49562
49642
  exports.computeMaxWithdrawForBank = computeMaxWithdrawForBank;
@@ -49645,6 +49725,7 @@ exports.getConfig = getConfig;
49645
49725
  exports.getDriftCTokenMultiplier = getDriftCTokenMultiplier;
49646
49726
  exports.getDriftMetadata = getDriftMetadata;
49647
49727
  exports.getDriftStatesDto = getDriftStatesDto;
49728
+ exports.getEmodePairs = getEmodePairs;
49648
49729
  exports.getHealthCacheStatusDescription = getHealthCacheStatusDescription;
49649
49730
  exports.getHealthSimulationTransactions = getHealthSimulationTransactions;
49650
49731
  exports.getJupiterSwapIxsForFlashloan = getJupiterSwapIxsForFlashloan;
@@ -49736,6 +49817,7 @@ exports.parseRiskTier = parseRiskTier;
49736
49817
  exports.parseRpcPythPriceData = parseRpcPythPriceData;
49737
49818
  exports.parseSwbOraclePriceData = parseSwbOraclePriceData;
49738
49819
  exports.partitionBanksByCrankability = partitionBanksByCrankability;
49820
+ exports.resolveAmount = resolveAmount;
49739
49821
  exports.serializeBankConfigOpt = serializeBankConfigOpt;
49740
49822
  exports.serializeInterestRateConfig = serializeInterestRateConfig;
49741
49823
  exports.serializeOperationalState = serializeOperationalState;