@gearbox-protocol/sdk 13.3.2 → 13.4.0-beta.1

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.
@@ -18,106 +18,16 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var api_exports = {};
20
20
  __export(api_exports, {
21
- GearboxRewardsApi: () => GearboxRewardsApi
21
+ RewardAmountAPI: () => RewardAmountAPI
22
22
  });
23
23
  module.exports = __toCommonJS(api_exports);
24
24
  var import_viem = require("viem");
25
- var import_iFarmingPool = require("../../abi/iFarmingPool.js");
26
25
  var import_common_utils = require("../../common-utils/index.js");
27
26
  var import_sdk = require("../../sdk/index.js");
28
27
  var import_merkl_api = require("./merkl-api.js");
29
- class GearboxRewardsApi {
28
+ class RewardAmountAPI {
30
29
  constructor() {
31
30
  }
32
- static async getLmRewardsV3({
33
- pools,
34
- tokensList,
35
- provider,
36
- account,
37
- reportError
38
- }) {
39
- const poolByStakedDiesel = Object.values(pools).reduce((acc, p) => {
40
- p.stakedDieselToken.forEach((t) => {
41
- if (t) acc[t] = p.address;
42
- });
43
- p.stakedDieselToken_old.forEach((t) => {
44
- if (t) acc[t] = p.address;
45
- });
46
- return acc;
47
- }, {});
48
- const stakedDieselTokens = Object.keys(poolByStakedDiesel);
49
- const farmInfoCalls = stakedDieselTokens.map((address) => ({
50
- address,
51
- abi: import_iFarmingPool.iFarmingPoolAbi,
52
- functionName: "farmInfo",
53
- args: []
54
- }));
55
- const rewardTokenCalls = stakedDieselTokens.map((address) => ({
56
- address,
57
- abi: POOL_REWARDS_ABI,
58
- functionName: "rewardsToken",
59
- args: []
60
- }));
61
- const farmedCalls = stakedDieselTokens.map((address) => ({
62
- address,
63
- abi: import_iFarmingPool.iFarmingPoolAbi,
64
- functionName: "farmed",
65
- args: [account]
66
- }));
67
- const [response] = await Promise.allSettled([
68
- provider.multicall({
69
- allowFailure: false,
70
- contracts: [...farmInfoCalls, ...rewardTokenCalls, ...farmedCalls],
71
- batchSize: 0
72
- })
73
- ]);
74
- const safeResponse = GearboxRewardsApi.extractFulfilled(response, reportError, "v3Rewards") || [];
75
- const farmInfoCallsEnd = farmInfoCalls.length;
76
- const farmInfo = safeResponse.slice(
77
- 0,
78
- farmInfoCallsEnd
79
- );
80
- const rewardTokenCallsEnd = farmInfoCallsEnd + rewardTokenCalls.length;
81
- const rewardTokens = safeResponse.slice(
82
- farmInfoCallsEnd,
83
- rewardTokenCallsEnd
84
- );
85
- const farmedCallsEnd = rewardTokenCallsEnd + farmedCalls.length;
86
- const farmedList = safeResponse.slice(
87
- rewardTokenCallsEnd,
88
- farmedCallsEnd
89
- );
90
- const gearboxLmRewards = stakedDieselTokens.map(
91
- (address, i) => {
92
- const pool = poolByStakedDiesel[address];
93
- const info = farmInfo[i];
94
- const rewardToken = rewardTokens[i]?.toLowerCase();
95
- const farmed = farmedList[i];
96
- if (!pool || !info || !rewardToken) return void 0;
97
- return {
98
- pool,
99
- poolToken: address,
100
- rewardToken,
101
- rewardTokenDecimals: tokensList[rewardToken]?.decimals || 18,
102
- rewardTokenSymbol: tokensList[rewardToken]?.symbol || "unknown",
103
- amount: farmed ?? 0n,
104
- type: "stakedV3"
105
- };
106
- }
107
- );
108
- const { zero, nonZero } = gearboxLmRewards.reduce(
109
- (acc, r) => {
110
- if (r && r.amount > 0n) {
111
- acc.nonZero.push(r);
112
- } else if (r) {
113
- acc.zero.push(r);
114
- }
115
- return acc;
116
- },
117
- { nonZero: [], zero: [] }
118
- );
119
- return [...nonZero, zero];
120
- }
121
31
  static async getLmRewardsMerkle({
122
32
  pools,
123
33
  account,
@@ -134,7 +44,7 @@ class GearboxRewardsApi {
134
44
  })
135
45
  )
136
46
  ]);
137
- const merkleXYZLm = GearboxRewardsApi.extractFulfilled(
47
+ const merkleXYZLm = RewardAmountAPI.extractFulfilled(
138
48
  merkleXYZLMResponse,
139
49
  reportError,
140
50
  "merkleXYZLm"
@@ -189,38 +99,8 @@ class GearboxRewardsApi {
189
99
  return void 0;
190
100
  }
191
101
  }
192
- static async claimLmRewardsV3({
193
- reward,
194
- signer,
195
- account
196
- }) {
197
- const pool = (0, import_viem.getContract)({
198
- address: reward.poolToken,
199
- abi: import_iFarmingPool.iFarmingPoolAbi,
200
- client: signer
201
- });
202
- return pool.write.claim({
203
- account,
204
- chain: signer.chain
205
- });
206
- }
207
102
  }
208
- const POOL_REWARDS_ABI = [
209
- {
210
- inputs: [],
211
- name: "rewardsToken",
212
- outputs: [
213
- {
214
- internalType: "contract IERC20",
215
- name: "",
216
- type: "address"
217
- }
218
- ],
219
- stateMutability: "view",
220
- type: "function"
221
- }
222
- ];
223
103
  // Annotate the CommonJS export names for ESM import in node:
224
104
  0 && (module.exports = {
225
- GearboxRewardsApi
105
+ RewardAmountAPI
226
106
  });
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var extra_apy_exports = {};
30
30
  __export(extra_apy_exports, {
31
- GearboxRewardsExtraApy: () => GearboxRewardsExtraApy,
31
+ PoolPointsAPI: () => PoolPointsAPI,
32
32
  getKeyForPoolPointsInfo: () => getKeyForPoolPointsInfo
33
33
  });
34
34
  module.exports = __toCommonJS(extra_apy_exports);
@@ -47,7 +47,7 @@ function getKeyForPoolPointsInfo(i) {
47
47
  i.condition
48
48
  ].join("-");
49
49
  }
50
- class GearboxRewardsExtraApy {
50
+ class PoolPointsAPI {
51
51
  constructor() {
52
52
  }
53
53
  static async getTotalTokensOnProtocol({
@@ -57,9 +57,7 @@ class GearboxRewardsExtraApy {
57
57
  }) {
58
58
  const list = [...new Set(tokensToCheck)];
59
59
  const res = await Promise.allSettled(
60
- list.map(
61
- (t) => GearboxRewardsExtraApy.getTokenTotal(t, network, tokensList)
62
- )
60
+ list.map((t) => PoolPointsAPI.getTokenTotal(t, network, tokensList))
63
61
  );
64
62
  return res.map((r, i) => [
65
63
  list[i],
@@ -89,7 +87,7 @@ class GearboxRewardsExtraApy {
89
87
  (acc2, pointsInfo2) => {
90
88
  const { address: tokenAddress } = tokensList[pointsInfo2.token] || {};
91
89
  const tokenBalance = totalTokenBalances[tokenAddress || ""];
92
- const points = GearboxRewardsExtraApy.getPoolTokenPoints(
90
+ const points = PoolPointsAPI.getPoolTokenPoints(
93
91
  tokenBalance,
94
92
  p,
95
93
  tokensList,
@@ -127,6 +125,6 @@ class GearboxRewardsExtraApy {
127
125
  }
128
126
  // Annotate the CommonJS export names for ESM import in node:
129
127
  0 && (module.exports = {
130
- GearboxRewardsExtraApy,
128
+ PoolPointsAPI,
131
129
  getKeyForPoolPointsInfo
132
130
  });
@@ -16,13 +16,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var rewards_exports = {};
17
17
  module.exports = __toCommonJS(rewards_exports);
18
18
  __reExport(rewards_exports, require("./api.js"), module.exports);
19
- __reExport(rewards_exports, require("./apy.js"), module.exports);
20
19
  __reExport(rewards_exports, require("./extra-apy.js"), module.exports);
21
- __reExport(rewards_exports, require("./merkl-api.js"), module.exports);
22
20
  // Annotate the CommonJS export names for ESM import in node:
23
21
  0 && (module.exports = {
24
22
  ...require("./api.js"),
25
- ...require("./apy.js"),
26
- ...require("./extra-apy.js"),
27
- ...require("./merkl-api.js")
23
+ ...require("./extra-apy.js")
28
24
  });
@@ -35,6 +35,7 @@ var import_constants = require("../constants/index.js");
35
35
  var import_router = require("../router/index.js");
36
36
  var import_utils = require("../utils/index.js");
37
37
  var import_viem2 = require("../utils/viem/index.js");
38
+ var import_multicall_utils = require("./multicall-utils.js");
38
39
  const COMPRESSORS = {
39
40
  [import_chains.chains.Mainnet.id]: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023",
40
41
  [import_chains.chains.Monad.id]: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023"
@@ -334,12 +335,12 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
334
335
  keepAssets,
335
336
  debtOnly
336
337
  });
337
- const priceUpdates = await this.getPriceUpdatesForFacade({
338
- creditManager: account.creditManager,
339
- creditAccount: account,
340
- ignoreReservePrices
341
- });
342
- const calls = [...priceUpdates, ...routerCloseResult.calls];
338
+ const calls = await this.prependPriceUpdates(
339
+ account.creditManager,
340
+ routerCloseResult.calls,
341
+ account,
342
+ { ignoreReservePrices }
343
+ );
343
344
  let lossPolicyData;
344
345
  if (applyLossPolicy) {
345
346
  const market = this.sdk.marketRegister.findByCreditManager(
@@ -394,12 +395,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
394
395
  creditManager: cm.creditManager,
395
396
  slippage
396
397
  });
397
- const priceUpdates = await this.getPriceUpdatesForFacade({
398
- creditManager: ca.creditManager,
399
- creditAccount: ca
400
- });
401
- const calls = [
402
- ...operation === "close" ? [] : priceUpdates,
398
+ const operationCalls = [
403
399
  ...routerCloseResult.calls,
404
400
  ...this.prepareDisableQuotas(ca),
405
401
  ...this.prepareDecreaseDebt(ca),
@@ -407,6 +403,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
407
403
  (t) => this.prepareWithdrawToken(ca.creditFacade, t, import_constants.MAX_UINT256, to)
408
404
  )
409
405
  ];
406
+ const calls = operation === "close" ? operationCalls : await this.prependPriceUpdates(ca.creditManager, operationCalls, ca);
410
407
  const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
411
408
  return { tx, calls, routerCloseResult, creditFacade: cm.creditFacade };
412
409
  }
@@ -426,17 +423,15 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
426
423
  const cm = this.sdk.marketRegister.findCreditManager(
427
424
  creditAccount.creditManager
428
425
  );
429
- const priceUpdates = await this.getPriceUpdatesForFacade({
430
- creditManager: creditAccount.creditManager,
426
+ const operationCalls = this.prepareUpdateQuotas(
427
+ creditAccount.creditFacade,
428
+ { minQuota, averageQuota }
429
+ );
430
+ const calls = await this.prependPriceUpdates(
431
+ creditAccount.creditManager,
432
+ operationCalls,
431
433
  creditAccount
432
- });
433
- const calls = [
434
- ...priceUpdates,
435
- ...this.prepareUpdateQuotas(creditAccount.creditFacade, {
436
- minQuota,
437
- averageQuota
438
- })
439
- ];
434
+ );
440
435
  const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
441
436
  return { tx, calls, creditFacade: cm.creditFacade };
442
437
  }
@@ -462,13 +457,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
462
457
  const cm = this.sdk.marketRegister.findCreditManager(
463
458
  creditAccount.creditManager
464
459
  );
465
- const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
466
- creditManager: creditAccount.creditManager,
467
- creditAccount,
468
- desiredQuotas: averageQuota
469
- });
470
- const calls = [
471
- ...priceUpdatesCalls,
460
+ const operationCalls = [
472
461
  ...this.prepareAddCollateral(
473
462
  creditAccount.creditFacade,
474
463
  [asset],
@@ -479,6 +468,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
479
468
  averageQuota
480
469
  })
481
470
  ];
471
+ const calls = await this.prependPriceUpdates(
472
+ creditAccount.creditManager,
473
+ operationCalls,
474
+ creditAccount
475
+ );
482
476
  const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
483
477
  tx.value = ethAmount.toString(10);
484
478
  return { tx, calls, creditFacade: cm.creditFacade };
@@ -506,10 +500,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
506
500
  const cm = this.sdk.marketRegister.findCreditManager(
507
501
  creditAccount.creditManager
508
502
  );
509
- const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
510
- creditManager: creditAccount.creditManager,
511
- creditAccount
512
- });
513
503
  const addCollateralCalls = addCollateral && isDecrease ? this.prepareAddCollateral(
514
504
  creditAccount.creditFacade,
515
505
  [
@@ -520,11 +510,15 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
520
510
  ],
521
511
  {}
522
512
  ) : [];
523
- const calls = [
524
- ...priceUpdatesCalls,
513
+ const operationCalls = [
525
514
  ...addCollateralCalls,
526
515
  this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
527
516
  ];
517
+ const calls = await this.prependPriceUpdates(
518
+ creditAccount.creditManager,
519
+ operationCalls,
520
+ creditAccount
521
+ );
528
522
  const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
529
523
  return { tx, calls, creditFacade: cm.creditFacade };
530
524
  }
@@ -547,19 +541,18 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
547
541
  const cm = this.sdk.marketRegister.findCreditManager(
548
542
  creditAccount.creditManager
549
543
  );
550
- const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
551
- creditManager: creditAccount.creditManager,
552
- creditAccount,
553
- desiredQuotas: averageQuota
554
- });
555
- const calls = [
556
- ...priceUpdatesCalls,
544
+ const operationCalls = [
557
545
  ...swapCalls,
558
546
  ...this.prepareUpdateQuotas(creditAccount.creditFacade, {
559
547
  minQuota,
560
548
  averageQuota
561
549
  })
562
550
  ];
551
+ const calls = await this.prependPriceUpdates(
552
+ creditAccount.creditManager,
553
+ operationCalls,
554
+ creditAccount
555
+ );
563
556
  const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
564
557
  return { tx, calls, creditFacade: cm.creditFacade };
565
558
  }
@@ -661,13 +654,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
661
654
  args: []
662
655
  })
663
656
  };
664
- const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
665
- creditManager: creditAccount.creditManager,
666
- creditAccount,
667
- desiredQuotas: averageQuota
668
- });
669
- const calls = [
670
- ...priceUpdatesCalls,
657
+ const operationCalls = [
671
658
  storeExpectedBalances,
672
659
  ...preview.requestCalls,
673
660
  compareBalances,
@@ -676,6 +663,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
676
663
  averageQuota
677
664
  })
678
665
  ];
666
+ const calls = await this.prependPriceUpdates(
667
+ creditAccount.creditManager,
668
+ operationCalls,
669
+ creditAccount
670
+ );
679
671
  const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
680
672
  return { tx, calls, creditFacade: cm.creditFacade };
681
673
  }
@@ -725,22 +717,21 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
725
717
  args: []
726
718
  })
727
719
  };
728
- const priceUpdatesCalls = zeroDebt ? [] : await this.getPriceUpdatesForFacade({
729
- creditManager: creditAccount.creditManager,
730
- creditAccount,
731
- desiredQuotas: averageQuota
732
- });
733
720
  const quotaCalls = zeroDebt ? [] : this.prepareUpdateQuotas(creditAccount.creditFacade, {
734
721
  minQuota,
735
722
  averageQuota
736
723
  });
737
- const calls = [
738
- ...priceUpdatesCalls,
724
+ const operationCalls = [
739
725
  storeExpectedBalances,
740
726
  ...claimableNow.claimCalls,
741
727
  compareBalances,
742
728
  ...quotaCalls
743
729
  ];
730
+ const calls = zeroDebt ? operationCalls : await this.prependPriceUpdates(
731
+ creditAccount.creditManager,
732
+ operationCalls,
733
+ creditAccount
734
+ );
744
735
  const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
745
736
  return { tx, calls, creditFacade: cm.creditFacade };
746
737
  }
@@ -783,12 +774,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
783
774
  }) {
784
775
  const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
785
776
  const cm = cmSuite.creditManager;
786
- const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
787
- creditManager: cm.address,
788
- desiredQuotas: averageQuota
789
- });
790
- const calls = [
791
- ...priceUpdatesCalls,
777
+ const operationCalls = [
792
778
  this.#prepareIncreaseDebt(cm.creditFacade, debt),
793
779
  ...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
794
780
  ...openPathCalls,
@@ -798,6 +784,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
798
784
  averageQuota
799
785
  })
800
786
  ];
787
+ const calls = await this.prependPriceUpdates(cm.address, operationCalls);
801
788
  const tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
802
789
  tx.value = ethAmount.toString(10);
803
790
  return { calls, tx, creditFacade: cmSuite.creditFacade };
@@ -882,37 +869,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
882
869
  );
883
870
  return resp;
884
871
  }
885
- /**
886
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
887
- *
888
- * This can be used by batch liquidator
889
- * @param accounts
890
- * @returns
891
- */
892
- async getUpdateForAccounts(accounts) {
893
- const tokensByPool = /* @__PURE__ */ new Map();
894
- const oracleByPool = /* @__PURE__ */ new Map();
895
- for (const acc of accounts) {
896
- const market = this.sdk.marketRegister.findByCreditManager(
897
- acc.creditManager
898
- );
899
- const pool = market.pool.pool.address;
900
- oracleByPool.set(pool, market.priceOracle);
901
- for (const t of acc.tokens) {
902
- if (t.balance > 10n) {
903
- const tokens = tokensByPool.get(pool) ?? /* @__PURE__ */ new Set();
904
- tokens.add(t.token);
905
- tokensByPool.set(pool, tokens);
906
- }
907
- }
908
- }
909
- const priceFeeds = [];
910
- for (const [pool, oracle] of oracleByPool.entries()) {
911
- const tokens = Array.from(tokensByPool.get(pool) ?? []);
912
- priceFeeds.push(...oracle.priceFeedsForTokens(tokens));
913
- }
914
- return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
915
- }
916
872
  async getUpdateForAccount(options) {
917
873
  const { creditManager, creditAccount, desiredQuotas, ignoreReservePrices } = options;
918
874
  const quotaRecord = desiredQuotas ? (0, import_router.assetsMap)(desiredQuotas) : desiredQuotas;
@@ -976,19 +932,113 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
976
932
  return market.priceOracle.onDemandPriceUpdates(
977
933
  cm.creditFacade.address,
978
934
  update
935
+ ).raw;
936
+ }
937
+ /**
938
+ * Analyzes a multicall array and prepends necessary on-demand price feed updates.
939
+ *
940
+ * Deduplicates existing `onDemandPriceUpdates` calls
941
+ *
942
+ * @param creditManager - Address of the credit manager
943
+ * @param calls - The multicall array to prepend price updates to
944
+ * @param ca - Credit account slice, undefined when opening a new account
945
+ * @param options - Optional settings for price update generation
946
+ * @returns A new array with a single consolidated price update call prepended,
947
+ * followed by the non-price-update calls in their original order
948
+ */
949
+ async prependPriceUpdates(creditManager, calls, ca, options) {
950
+ const market = this.sdk.marketRegister.findByCreditManager(creditManager);
951
+ const cm = this.sdk.marketRegister.findCreditManager(creditManager).creditManager;
952
+ const { priceUpdates: existingUpdates, remainingCalls } = (0, import_multicall_utils.extractPriceUpdates)(calls);
953
+ const tokens = new import_utils.AddressSet([
954
+ cm.underlying,
955
+ // underlying - always included
956
+ ...(0, import_multicall_utils.extractQuotaTokens)(calls)
957
+ // tokens from `updateQuota` calls
958
+ ]);
959
+ if (ca) {
960
+ for (const t of ca.tokens) {
961
+ const isEnabled = (t.mask & ca.enabledTokensMask) !== 0n;
962
+ if (t.balance > 10n && isEnabled) {
963
+ tokens.add(t.token);
964
+ }
965
+ }
966
+ }
967
+ const ignoreReservePrices = options?.ignoreReservePrices;
968
+ const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens), {
969
+ main: true,
970
+ reserve: !ignoreReservePrices
971
+ });
972
+ const tStr = tokens.map((t) => this.labelAddress(t)).join(", ");
973
+ const remark = ignoreReservePrices ? " main" : "";
974
+ this.logger?.debug(
975
+ { account: ca?.creditAccount, manager: cm.name },
976
+ `prependPriceUpdates for ${tStr} from ${priceFeeds.length}${remark} price feeds`
979
977
  );
978
+ const generatedUpdates = await this.sdk.priceFeeds.generatePriceFeedsUpdates(priceFeeds);
979
+ const merged = (0, import_multicall_utils.mergePriceUpdates)(existingUpdates, generatedUpdates);
980
+ if (merged.length === 0) {
981
+ return remainingCalls;
982
+ }
983
+ return [
984
+ {
985
+ target: cm.creditFacade,
986
+ callData: (0, import_viem.encodeFunctionData)({
987
+ abi: import_generated.iCreditFacadeMulticallV310Abi,
988
+ functionName: "onDemandPriceUpdates",
989
+ args: [merged]
990
+ })
991
+ },
992
+ ...remainingCalls
993
+ ];
980
994
  }
981
995
  /**
982
- * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
983
- * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
984
- * - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
985
- * - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
986
- * @param acc
987
- * @returns
996
+ * Executes a multicall on a credit account, automatically prepending
997
+ * necessary on-demand price feed updates.
998
+ *
999
+ * @param creditAccount - Credit account to execute multicall on
1000
+ * @param calls - Array of multicall operations (price updates will be inferred)
1001
+ * @param options - Optional settings for price update generation
1002
+ * @returns Raw transaction ready to be signed and sent
988
1003
  */
989
- async getPriceUpdatesForFacade(options) {
990
- const updates = await this.getOnDemandPriceUpdates(options);
991
- return updates.multicall;
1004
+ async multicall(creditAccount, calls, options) {
1005
+ const cm = this.sdk.marketRegister.findCreditManager(
1006
+ creditAccount.creditManager
1007
+ );
1008
+ const callsWithPrices = await this.prependPriceUpdates(
1009
+ creditAccount.creditManager,
1010
+ calls,
1011
+ creditAccount,
1012
+ options
1013
+ );
1014
+ return cm.creditFacade.multicall(
1015
+ creditAccount.creditAccount,
1016
+ callsWithPrices
1017
+ );
1018
+ }
1019
+ /**
1020
+ * Executes a bot multicall on a credit account, automatically prepending
1021
+ * necessary on-demand price feed updates.
1022
+ *
1023
+ * @param creditAccount - Credit account to execute bot multicall on
1024
+ * @param calls - Array of multicall operations (price updates will be inferred)
1025
+ * @param options - Optional settings for price update generation
1026
+ * @returns Raw transaction ready to be signed and sent
1027
+ */
1028
+ async botMulticall(creditAccount, calls, options) {
1029
+ const cm = this.sdk.marketRegister.findCreditManager(
1030
+ creditAccount.creditManager
1031
+ );
1032
+ const callsWithPrices = await this.prependPriceUpdates(
1033
+ creditAccount.creditManager,
1034
+ calls,
1035
+ creditAccount,
1036
+ options
1037
+ );
1038
+ return cm.creditFacade.botMulticall(
1039
+ creditAccount.creditAccount,
1040
+ callsWithPrices
1041
+ );
992
1042
  }
993
1043
  prepareDisableQuotas(ca) {
994
1044
  const calls = [];
@@ -1110,79 +1160,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1110
1160
  )[0];
1111
1161
  }
1112
1162
  }
1113
- const iMellowClaimerAdapterAbi = [
1114
- {
1115
- type: "function",
1116
- name: "getMultiVaultSubvaultIndices",
1117
- inputs: [{ name: "multiVault", type: "address", internalType: "address" }],
1118
- outputs: [
1119
- {
1120
- name: "subvaultIndices",
1121
- type: "uint256[]",
1122
- internalType: "uint256[]"
1123
- },
1124
- {
1125
- name: "withdrawalIndices",
1126
- type: "uint256[][]",
1127
- internalType: "uint256[][]"
1128
- }
1129
- ],
1130
- stateMutability: "view"
1131
- },
1132
- {
1133
- type: "function",
1134
- name: "getUserSubvaultIndices",
1135
- inputs: [
1136
- { name: "multiVault", type: "address", internalType: "address" },
1137
- { name: "user", type: "address", internalType: "address" }
1138
- ],
1139
- outputs: [
1140
- {
1141
- name: "subvaultIndices",
1142
- type: "uint256[]",
1143
- internalType: "uint256[]"
1144
- },
1145
- {
1146
- name: "withdrawalIndices",
1147
- type: "uint256[][]",
1148
- internalType: "uint256[][]"
1149
- }
1150
- ],
1151
- stateMutability: "view"
1152
- },
1153
- {
1154
- type: "function",
1155
- name: "multiAccept",
1156
- inputs: [
1157
- { name: "multiVault", type: "address", internalType: "address" },
1158
- {
1159
- name: "subvaultIndices",
1160
- type: "uint256[]",
1161
- internalType: "uint256[]"
1162
- },
1163
- { name: "indices", type: "uint256[][]", internalType: "uint256[][]" }
1164
- ],
1165
- outputs: [{ name: "", type: "bool", internalType: "bool" }],
1166
- stateMutability: "nonpayable"
1167
- },
1168
- {
1169
- type: "function",
1170
- name: "multiAcceptAndClaim",
1171
- inputs: [
1172
- { name: "multiVault", type: "address", internalType: "address" },
1173
- {
1174
- name: "subvaultIndices",
1175
- type: "uint256[]",
1176
- internalType: "uint256[]"
1177
- },
1178
- { name: "indices", type: "uint256[][]", internalType: "uint256[][]" },
1179
- { name: "", type: "address", internalType: "address" },
1180
- { name: "maxAssets", type: "uint256", internalType: "uint256" }
1181
- ],
1182
- outputs: [{ name: "", type: "bool", internalType: "bool" }],
1183
- stateMutability: "nonpayable"
1184
- }
1185
- ];
1186
1163
  // Annotate the CommonJS export names for ESM import in node:
1187
1164
  0 && (module.exports = {
1188
1165
  AbstractCreditAccountService,