@gearbox-protocol/sdk 3.0.0-vfour.95 → 3.0.0-vfour.97

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.
@@ -20163,6 +20163,12 @@ var CreditFacadeV300Contract = class extends BaseContract {
20163
20163
  args: [ca, calls]
20164
20164
  });
20165
20165
  }
20166
+ openCreditAccount(to, calls, referralCode) {
20167
+ return this.createRawTx({
20168
+ functionName: "openCreditAccount",
20169
+ args: [to, calls, referralCode]
20170
+ });
20171
+ }
20166
20172
  parseFunctionParams(params) {
20167
20173
  switch (params.functionName) {
20168
20174
  case "openCreditAccount": {
@@ -20292,6 +20298,12 @@ var CreditFacadeV310Contract = class extends BaseContract {
20292
20298
  args: [ca, calls]
20293
20299
  });
20294
20300
  }
20301
+ openCreditAccount(to, calls, referralCode) {
20302
+ return this.createRawTx({
20303
+ functionName: "openCreditAccount",
20304
+ args: [to, calls, referralCode]
20305
+ });
20306
+ }
20295
20307
  parseFunctionParams(params) {
20296
20308
  switch (params.functionName) {
20297
20309
  case "openCreditAccount": {
@@ -21225,8 +21237,9 @@ var RedstoneUpdater = class extends SDKConstruct {
21225
21237
  setHistoricalTimestamp(timestampMs) {
21226
21238
  this.#historicalTimestampMs = 6e4 * Math.floor(timestampMs / 6e4);
21227
21239
  }
21228
- async getUpdateTxs(feeds) {
21240
+ async getUpdateTxs(feeds, logContext = {}) {
21229
21241
  this.#logger?.debug(
21242
+ logContext,
21230
21243
  `generating update transactions for ${feeds.length} redstone price feeds`
21231
21244
  );
21232
21245
  const groupedFeeds = {};
@@ -21265,6 +21278,7 @@ var RedstoneUpdater = class extends SDKConstruct {
21265
21278
  }
21266
21279
  }
21267
21280
  this.#logger?.debug(
21281
+ logContext,
21268
21282
  `generated ${results.length} update transactions for redstone price feeds`
21269
21283
  );
21270
21284
  return results;
@@ -21473,9 +21487,10 @@ var PriceFeedRegister = class extends SDKConstruct {
21473
21487
  /**
21474
21488
  * Returns RawTxs to update price feeds
21475
21489
  * @param priceFeeds top-level price feeds, actual updatable price feeds will be derived. If not provided will use all price feeds that are attached
21490
+ * @param logContext extra information for logging
21476
21491
  * @returns
21477
21492
  */
21478
- async generatePriceFeedsUpdateTxs(priceFeeds) {
21493
+ async generatePriceFeedsUpdateTxs(priceFeeds, logContext = {}) {
21479
21494
  const updateables = priceFeeds ? priceFeeds.flatMap((pf) => pf.updatableDependencies()) : this.#feeds.values();
21480
21495
  const txs = [];
21481
21496
  const redstonePFs = [];
@@ -21486,7 +21501,10 @@ var PriceFeedRegister = class extends SDKConstruct {
21486
21501
  }
21487
21502
  let maxTimestamp = 0;
21488
21503
  if (redstonePFs.length > 0) {
21489
- const redstoneUpdates = await this.#redstoneUpdater.getUpdateTxs(redstonePFs);
21504
+ const redstoneUpdates = await this.#redstoneUpdater.getUpdateTxs(
21505
+ redstonePFs,
21506
+ logContext
21507
+ );
21490
21508
  for (const { tx, timestamp } of redstoneUpdates) {
21491
21509
  if (timestamp > maxTimestamp) {
21492
21510
  maxTimestamp = timestamp;
@@ -21496,6 +21514,7 @@ var PriceFeedRegister = class extends SDKConstruct {
21496
21514
  }
21497
21515
  const result = { txs, timestamp: maxTimestamp };
21498
21516
  this.logger?.debug(
21517
+ logContext,
21499
21518
  `generated ${txs.length} price feed update transactions, timestamp: ${maxTimestamp}`
21500
21519
  );
21501
21520
  if (txs.length) {
@@ -22743,7 +22762,9 @@ var CreditAccountsService = class extends SDKConstruct {
22743
22762
  if (raw.success) {
22744
22763
  return raw;
22745
22764
  }
22746
- const { txs: priceUpdateTxs, timestamp: _ } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
22765
+ const { txs: priceUpdateTxs, timestamp: _ } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(void 0, {
22766
+ account
22767
+ });
22747
22768
  const resp = await simulateMulticall(this.provider.publicClient, {
22748
22769
  contracts: [
22749
22770
  ...priceUpdateTxs.map(rawTxToMulticallPriceUpdate),
@@ -23063,27 +23084,63 @@ var CreditAccountsService = class extends SDKConstruct {
23063
23084
  return { tx, calls };
23064
23085
  }
23065
23086
  async claimFarmRewards(props) {
23066
- const { tokensToDisable, calls: claimCalls, creditAccount } = props;
23087
+ const { tokensToDisable, calls: claimCalls, creditAccount: ca } = props;
23067
23088
  if (claimCalls.length === 0) throw new Error("No path to execute");
23068
- const cm = this.sdk.marketRegister.findCreditManager(
23069
- creditAccount.creditManager
23070
- );
23089
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
23071
23090
  const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
23072
- creditAccount.creditManager,
23073
- creditAccount,
23091
+ ca.creditManager,
23092
+ ca,
23074
23093
  props.averageQuota
23075
23094
  );
23076
23095
  const calls = [
23077
23096
  ...priceUpdatesCalls,
23078
23097
  ...claimCalls,
23079
23098
  ...tokensToDisable.map(
23080
- (a) => this.#prepareDisableToken(creditAccount.creditFacade, a.token)
23099
+ (a) => this.#prepareDisableToken(ca.creditFacade, a.token)
23081
23100
  ),
23082
- ...this.#prepareUpdateQuotas(creditAccount.creditFacade, props)
23101
+ ...this.#prepareUpdateQuotas(ca.creditFacade, props)
23083
23102
  ];
23084
- const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
23103
+ const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
23085
23104
  return { tx, calls };
23086
23105
  }
23106
+ async openCA(props) {
23107
+ const {
23108
+ ethAmount,
23109
+ creditManager,
23110
+ collateral,
23111
+ permits,
23112
+ debt,
23113
+ withdrawDebt,
23114
+ referralCode,
23115
+ to,
23116
+ calls: openPathCalls
23117
+ } = props;
23118
+ const cmFactory = this.sdk.marketRegister.findCreditManager(creditManager);
23119
+ const cm = cmFactory.creditManager;
23120
+ const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
23121
+ cm.address,
23122
+ void 0,
23123
+ props.averageQuota
23124
+ );
23125
+ const calls = [
23126
+ ...priceUpdatesCalls,
23127
+ this.#prepareIncreaseDebt(cm.creditFacade, debt),
23128
+ ...this.#prepareAddCollateral(cm.creditFacade, collateral, permits),
23129
+ ...this.#prepareUpdateQuotas(cm.creditFacade, props),
23130
+ ...openPathCalls,
23131
+ ...withdrawDebt ? [this.#prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : []
23132
+ ];
23133
+ const tx = cmFactory.creditFacade.openCreditAccount(
23134
+ to,
23135
+ calls,
23136
+ referralCode
23137
+ );
23138
+ tx.value = ethAmount.toString(10);
23139
+ return {
23140
+ calls,
23141
+ tx
23142
+ };
23143
+ }
23087
23144
  /**
23088
23145
  * Internal wrapper for CreditAccountCompressor.getCreditAccounts + price updates wrapped into multicall
23089
23146
  * @param args
@@ -23191,7 +23248,10 @@ var CreditAccountsService = class extends SDKConstruct {
23191
23248
  const tokens = Array.from(tokensByPool.get(pool2) ?? []);
23192
23249
  priceFeeds.push(...priceFeedFactory.priceFeedsForTokens(tokens));
23193
23250
  }
23194
- return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
23251
+ return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
23252
+ priceFeeds,
23253
+ creditAccount ? { account: creditAccount.creditAccount } : void 0
23254
+ );
23195
23255
  }
23196
23256
  /**
23197
23257
  * Returns account price updates in a non-encoded format
@@ -23307,6 +23367,16 @@ var CreditAccountsService = class extends SDKConstruct {
23307
23367
  })
23308
23368
  };
23309
23369
  }
23370
+ #prepareIncreaseDebt(creditFacade, debt) {
23371
+ return {
23372
+ target: creditFacade,
23373
+ callData: viem.encodeFunctionData({
23374
+ abi: iCreditFacadeV3MulticallAbi,
23375
+ functionName: "increaseDebt",
23376
+ args: [debt]
23377
+ })
23378
+ };
23379
+ }
23310
23380
  #prepareChangeDebt(creditFacade, change, isDecrease) {
23311
23381
  return {
23312
23382
  target: creditFacade,
@@ -22374,9 +22374,10 @@ declare class PriceFeedRegister extends SDKConstruct implements IHooks<PriceFeed
22374
22374
  /**
22375
22375
  * Returns RawTxs to update price feeds
22376
22376
  * @param priceFeeds top-level price feeds, actual updatable price feeds will be derived. If not provided will use all price feeds that are attached
22377
+ * @param logContext extra information for logging
22377
22378
  * @returns
22378
22379
  */
22379
- generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[]): Promise<UpdatePriceFeedsResult>;
22380
+ generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[], logContext?: Record<string, any>): Promise<UpdatePriceFeedsResult>;
22380
22381
  mustGet(address: Address): IPriceFeedContract;
22381
22382
  getOrCreate(data: PriceFeedTreeNode): IPriceFeedContract;
22382
22383
  /**
@@ -22934,6 +22935,7 @@ declare class CreditFacadeV300Contract extends BaseContract<abi$b> {
22934
22935
  liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[]): RawTx;
22935
22936
  closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
22936
22937
  multicall(ca: Address, calls: MultiCall[]): RawTx;
22938
+ openCreditAccount(to: Address, calls: MultiCall[], referralCode: bigint): RawTx;
22937
22939
  parseFunctionParams(params: DecodeFunctionDataReturnType<abi$b>): string[] | undefined;
22938
22940
  }
22939
22941
 
@@ -22949,6 +22951,7 @@ declare class CreditFacadeV310Contract extends BaseContract<abi$a> {
22949
22951
  liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[]): RawTx;
22950
22952
  closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
22951
22953
  multicall(ca: Address, calls: MultiCall[]): RawTx;
22954
+ openCreditAccount(to: Address, calls: MultiCall[], referralCode: bigint): RawTx;
22952
22955
  parseFunctionParams(params: DecodeFunctionDataReturnType<abi$a>): string[] | undefined;
22953
22956
  }
22954
22957
 
@@ -25303,6 +25306,17 @@ interface ClaimFarmRewardsProps extends PrepareUpdateQuotasProps {
25303
25306
  calls: Array<MultiCall>;
25304
25307
  creditAccount: CreditAccountDataSlice;
25305
25308
  }
25309
+ interface OpenCAProps extends PrepareUpdateQuotasProps {
25310
+ ethAmount: bigint;
25311
+ collateral: Array<Asset>;
25312
+ debt: bigint;
25313
+ withdrawDebt?: boolean;
25314
+ permits: Record<string, PermitResult>;
25315
+ calls: Array<MultiCall>;
25316
+ creditManager: Address;
25317
+ to: Address;
25318
+ referralCode: bigint;
25319
+ }
25306
25320
  interface ChangeDeptProps {
25307
25321
  creditAccount: CreditAccountDataSlice;
25308
25322
  amount: bigint;
@@ -25385,18 +25399,13 @@ declare class CreditAccountsService extends SDKConstruct {
25385
25399
  updateQuotas(props: UpdateQuotasProps): Promise<CommonResult>;
25386
25400
  addCollateral(props: AddCollateralProps): Promise<CommonResult>;
25387
25401
  changeDebt({ creditAccount, amount, }: ChangeDeptProps): Promise<CommonResult>;
25388
- withdrawCollateral(props: WithdrawCollateralProps): Promise<{
25389
- tx: RawTx;
25390
- calls: MultiCall[];
25391
- }>;
25392
- executeSwap(props: ExecuteSwapProps): Promise<{
25393
- tx: RawTx;
25394
- calls: MultiCall[];
25395
- }>;
25402
+ withdrawCollateral(props: WithdrawCollateralProps): Promise<CommonResult>;
25403
+ executeSwap(props: ExecuteSwapProps): Promise<CommonResult>;
25396
25404
  claimFarmRewards(props: ClaimFarmRewardsProps): Promise<{
25397
25405
  tx: RawTx;
25398
25406
  calls: MultiCall[];
25399
25407
  }>;
25408
+ openCA(props: OpenCAProps): Promise<CommonResult>;
25400
25409
  /**
25401
25410
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
25402
25411
  * @param accounts
@@ -22374,9 +22374,10 @@ declare class PriceFeedRegister extends SDKConstruct implements IHooks<PriceFeed
22374
22374
  /**
22375
22375
  * Returns RawTxs to update price feeds
22376
22376
  * @param priceFeeds top-level price feeds, actual updatable price feeds will be derived. If not provided will use all price feeds that are attached
22377
+ * @param logContext extra information for logging
22377
22378
  * @returns
22378
22379
  */
22379
- generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[]): Promise<UpdatePriceFeedsResult>;
22380
+ generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[], logContext?: Record<string, any>): Promise<UpdatePriceFeedsResult>;
22380
22381
  mustGet(address: Address): IPriceFeedContract;
22381
22382
  getOrCreate(data: PriceFeedTreeNode): IPriceFeedContract;
22382
22383
  /**
@@ -22934,6 +22935,7 @@ declare class CreditFacadeV300Contract extends BaseContract<abi$b> {
22934
22935
  liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[]): RawTx;
22935
22936
  closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
22936
22937
  multicall(ca: Address, calls: MultiCall[]): RawTx;
22938
+ openCreditAccount(to: Address, calls: MultiCall[], referralCode: bigint): RawTx;
22937
22939
  parseFunctionParams(params: DecodeFunctionDataReturnType<abi$b>): string[] | undefined;
22938
22940
  }
22939
22941
 
@@ -22949,6 +22951,7 @@ declare class CreditFacadeV310Contract extends BaseContract<abi$a> {
22949
22951
  liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[]): RawTx;
22950
22952
  closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
22951
22953
  multicall(ca: Address, calls: MultiCall[]): RawTx;
22954
+ openCreditAccount(to: Address, calls: MultiCall[], referralCode: bigint): RawTx;
22952
22955
  parseFunctionParams(params: DecodeFunctionDataReturnType<abi$a>): string[] | undefined;
22953
22956
  }
22954
22957
 
@@ -25303,6 +25306,17 @@ interface ClaimFarmRewardsProps extends PrepareUpdateQuotasProps {
25303
25306
  calls: Array<MultiCall>;
25304
25307
  creditAccount: CreditAccountDataSlice;
25305
25308
  }
25309
+ interface OpenCAProps extends PrepareUpdateQuotasProps {
25310
+ ethAmount: bigint;
25311
+ collateral: Array<Asset>;
25312
+ debt: bigint;
25313
+ withdrawDebt?: boolean;
25314
+ permits: Record<string, PermitResult>;
25315
+ calls: Array<MultiCall>;
25316
+ creditManager: Address;
25317
+ to: Address;
25318
+ referralCode: bigint;
25319
+ }
25306
25320
  interface ChangeDeptProps {
25307
25321
  creditAccount: CreditAccountDataSlice;
25308
25322
  amount: bigint;
@@ -25385,18 +25399,13 @@ declare class CreditAccountsService extends SDKConstruct {
25385
25399
  updateQuotas(props: UpdateQuotasProps): Promise<CommonResult>;
25386
25400
  addCollateral(props: AddCollateralProps): Promise<CommonResult>;
25387
25401
  changeDebt({ creditAccount, amount, }: ChangeDeptProps): Promise<CommonResult>;
25388
- withdrawCollateral(props: WithdrawCollateralProps): Promise<{
25389
- tx: RawTx;
25390
- calls: MultiCall[];
25391
- }>;
25392
- executeSwap(props: ExecuteSwapProps): Promise<{
25393
- tx: RawTx;
25394
- calls: MultiCall[];
25395
- }>;
25402
+ withdrawCollateral(props: WithdrawCollateralProps): Promise<CommonResult>;
25403
+ executeSwap(props: ExecuteSwapProps): Promise<CommonResult>;
25396
25404
  claimFarmRewards(props: ClaimFarmRewardsProps): Promise<{
25397
25405
  tx: RawTx;
25398
25406
  calls: MultiCall[];
25399
25407
  }>;
25408
+ openCA(props: OpenCAProps): Promise<CommonResult>;
25400
25409
  /**
25401
25410
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
25402
25411
  * @param accounts
@@ -20161,6 +20161,12 @@ var CreditFacadeV300Contract = class extends BaseContract {
20161
20161
  args: [ca, calls]
20162
20162
  });
20163
20163
  }
20164
+ openCreditAccount(to, calls, referralCode) {
20165
+ return this.createRawTx({
20166
+ functionName: "openCreditAccount",
20167
+ args: [to, calls, referralCode]
20168
+ });
20169
+ }
20164
20170
  parseFunctionParams(params) {
20165
20171
  switch (params.functionName) {
20166
20172
  case "openCreditAccount": {
@@ -20290,6 +20296,12 @@ var CreditFacadeV310Contract = class extends BaseContract {
20290
20296
  args: [ca, calls]
20291
20297
  });
20292
20298
  }
20299
+ openCreditAccount(to, calls, referralCode) {
20300
+ return this.createRawTx({
20301
+ functionName: "openCreditAccount",
20302
+ args: [to, calls, referralCode]
20303
+ });
20304
+ }
20293
20305
  parseFunctionParams(params) {
20294
20306
  switch (params.functionName) {
20295
20307
  case "openCreditAccount": {
@@ -21223,8 +21235,9 @@ var RedstoneUpdater = class extends SDKConstruct {
21223
21235
  setHistoricalTimestamp(timestampMs) {
21224
21236
  this.#historicalTimestampMs = 6e4 * Math.floor(timestampMs / 6e4);
21225
21237
  }
21226
- async getUpdateTxs(feeds) {
21238
+ async getUpdateTxs(feeds, logContext = {}) {
21227
21239
  this.#logger?.debug(
21240
+ logContext,
21228
21241
  `generating update transactions for ${feeds.length} redstone price feeds`
21229
21242
  );
21230
21243
  const groupedFeeds = {};
@@ -21263,6 +21276,7 @@ var RedstoneUpdater = class extends SDKConstruct {
21263
21276
  }
21264
21277
  }
21265
21278
  this.#logger?.debug(
21279
+ logContext,
21266
21280
  `generated ${results.length} update transactions for redstone price feeds`
21267
21281
  );
21268
21282
  return results;
@@ -21471,9 +21485,10 @@ var PriceFeedRegister = class extends SDKConstruct {
21471
21485
  /**
21472
21486
  * Returns RawTxs to update price feeds
21473
21487
  * @param priceFeeds top-level price feeds, actual updatable price feeds will be derived. If not provided will use all price feeds that are attached
21488
+ * @param logContext extra information for logging
21474
21489
  * @returns
21475
21490
  */
21476
- async generatePriceFeedsUpdateTxs(priceFeeds) {
21491
+ async generatePriceFeedsUpdateTxs(priceFeeds, logContext = {}) {
21477
21492
  const updateables = priceFeeds ? priceFeeds.flatMap((pf) => pf.updatableDependencies()) : this.#feeds.values();
21478
21493
  const txs = [];
21479
21494
  const redstonePFs = [];
@@ -21484,7 +21499,10 @@ var PriceFeedRegister = class extends SDKConstruct {
21484
21499
  }
21485
21500
  let maxTimestamp = 0;
21486
21501
  if (redstonePFs.length > 0) {
21487
- const redstoneUpdates = await this.#redstoneUpdater.getUpdateTxs(redstonePFs);
21502
+ const redstoneUpdates = await this.#redstoneUpdater.getUpdateTxs(
21503
+ redstonePFs,
21504
+ logContext
21505
+ );
21488
21506
  for (const { tx, timestamp } of redstoneUpdates) {
21489
21507
  if (timestamp > maxTimestamp) {
21490
21508
  maxTimestamp = timestamp;
@@ -21494,6 +21512,7 @@ var PriceFeedRegister = class extends SDKConstruct {
21494
21512
  }
21495
21513
  const result = { txs, timestamp: maxTimestamp };
21496
21514
  this.logger?.debug(
21515
+ logContext,
21497
21516
  `generated ${txs.length} price feed update transactions, timestamp: ${maxTimestamp}`
21498
21517
  );
21499
21518
  if (txs.length) {
@@ -22741,7 +22760,9 @@ var CreditAccountsService = class extends SDKConstruct {
22741
22760
  if (raw.success) {
22742
22761
  return raw;
22743
22762
  }
22744
- const { txs: priceUpdateTxs, timestamp: _ } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
22763
+ const { txs: priceUpdateTxs, timestamp: _ } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(void 0, {
22764
+ account
22765
+ });
22745
22766
  const resp = await simulateMulticall(this.provider.publicClient, {
22746
22767
  contracts: [
22747
22768
  ...priceUpdateTxs.map(rawTxToMulticallPriceUpdate),
@@ -23061,27 +23082,63 @@ var CreditAccountsService = class extends SDKConstruct {
23061
23082
  return { tx, calls };
23062
23083
  }
23063
23084
  async claimFarmRewards(props) {
23064
- const { tokensToDisable, calls: claimCalls, creditAccount } = props;
23085
+ const { tokensToDisable, calls: claimCalls, creditAccount: ca } = props;
23065
23086
  if (claimCalls.length === 0) throw new Error("No path to execute");
23066
- const cm = this.sdk.marketRegister.findCreditManager(
23067
- creditAccount.creditManager
23068
- );
23087
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
23069
23088
  const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
23070
- creditAccount.creditManager,
23071
- creditAccount,
23089
+ ca.creditManager,
23090
+ ca,
23072
23091
  props.averageQuota
23073
23092
  );
23074
23093
  const calls = [
23075
23094
  ...priceUpdatesCalls,
23076
23095
  ...claimCalls,
23077
23096
  ...tokensToDisable.map(
23078
- (a) => this.#prepareDisableToken(creditAccount.creditFacade, a.token)
23097
+ (a) => this.#prepareDisableToken(ca.creditFacade, a.token)
23079
23098
  ),
23080
- ...this.#prepareUpdateQuotas(creditAccount.creditFacade, props)
23099
+ ...this.#prepareUpdateQuotas(ca.creditFacade, props)
23081
23100
  ];
23082
- const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
23101
+ const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
23083
23102
  return { tx, calls };
23084
23103
  }
23104
+ async openCA(props) {
23105
+ const {
23106
+ ethAmount,
23107
+ creditManager,
23108
+ collateral,
23109
+ permits,
23110
+ debt,
23111
+ withdrawDebt,
23112
+ referralCode,
23113
+ to,
23114
+ calls: openPathCalls
23115
+ } = props;
23116
+ const cmFactory = this.sdk.marketRegister.findCreditManager(creditManager);
23117
+ const cm = cmFactory.creditManager;
23118
+ const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
23119
+ cm.address,
23120
+ void 0,
23121
+ props.averageQuota
23122
+ );
23123
+ const calls = [
23124
+ ...priceUpdatesCalls,
23125
+ this.#prepareIncreaseDebt(cm.creditFacade, debt),
23126
+ ...this.#prepareAddCollateral(cm.creditFacade, collateral, permits),
23127
+ ...this.#prepareUpdateQuotas(cm.creditFacade, props),
23128
+ ...openPathCalls,
23129
+ ...withdrawDebt ? [this.#prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : []
23130
+ ];
23131
+ const tx = cmFactory.creditFacade.openCreditAccount(
23132
+ to,
23133
+ calls,
23134
+ referralCode
23135
+ );
23136
+ tx.value = ethAmount.toString(10);
23137
+ return {
23138
+ calls,
23139
+ tx
23140
+ };
23141
+ }
23085
23142
  /**
23086
23143
  * Internal wrapper for CreditAccountCompressor.getCreditAccounts + price updates wrapped into multicall
23087
23144
  * @param args
@@ -23189,7 +23246,10 @@ var CreditAccountsService = class extends SDKConstruct {
23189
23246
  const tokens = Array.from(tokensByPool.get(pool2) ?? []);
23190
23247
  priceFeeds.push(...priceFeedFactory.priceFeedsForTokens(tokens));
23191
23248
  }
23192
- return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
23249
+ return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
23250
+ priceFeeds,
23251
+ creditAccount ? { account: creditAccount.creditAccount } : void 0
23252
+ );
23193
23253
  }
23194
23254
  /**
23195
23255
  * Returns account price updates in a non-encoded format
@@ -23305,6 +23365,16 @@ var CreditAccountsService = class extends SDKConstruct {
23305
23365
  })
23306
23366
  };
23307
23367
  }
23368
+ #prepareIncreaseDebt(creditFacade, debt) {
23369
+ return {
23370
+ target: creditFacade,
23371
+ callData: encodeFunctionData({
23372
+ abi: iCreditFacadeV3MulticallAbi,
23373
+ functionName: "increaseDebt",
23374
+ args: [debt]
23375
+ })
23376
+ };
23377
+ }
23308
23378
  #prepareChangeDebt(creditFacade, change, isDecrease) {
23309
23379
  return {
23310
23380
  target: creditFacade,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.95",
3
+ "version": "3.0.0-vfour.97",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.cjs",