@gearbox-protocol/sdk 13.4.0-beta.2 → 13.4.0

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.
@@ -670,33 +670,55 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
670
670
  /**
671
671
  * {@inheritDoc ICreditAccountsService.openCA}
672
672
  **/
673
- async openCA({
674
- ethAmount,
675
- creditManager,
676
- collateral,
677
- permits,
678
- debt,
679
- withdrawDebt,
680
- referralCode,
681
- to,
682
- calls: openPathCalls,
683
- minQuota,
684
- averageQuota
685
- }) {
673
+ async openCA(props) {
674
+ const {
675
+ ethAmount,
676
+ creditManager,
677
+ reopenCreditAccount,
678
+ collateral,
679
+ permits,
680
+ debt,
681
+ withdrawToken,
682
+ referralCode,
683
+ to,
684
+ calls: openPathCalls,
685
+ callsAfter,
686
+ minQuota,
687
+ averageQuota
688
+ } = props;
686
689
  const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
687
690
  const cm = cmSuite.creditManager;
691
+ let tokenToWithdraw;
692
+ if (withdrawToken === true) {
693
+ tokenToWithdraw = cm.underlying;
694
+ } else if (typeof withdrawToken === "string") {
695
+ tokenToWithdraw = withdrawToken;
696
+ }
688
697
  const operationCalls = [
689
698
  this.#prepareIncreaseDebt(cm.creditFacade, debt),
690
699
  ...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
691
700
  ...openPathCalls,
692
- ...withdrawDebt ? [this.prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : [],
701
+ ...tokenToWithdraw ? [
702
+ this.prepareWithdrawToken(
703
+ cm.creditFacade,
704
+ tokenToWithdraw,
705
+ import_constants.MAX_UINT256,
706
+ to
707
+ )
708
+ ] : [],
693
709
  ...this.prepareUpdateQuotas(cm.creditFacade, {
694
710
  minQuota,
695
711
  averageQuota
696
- })
712
+ }),
713
+ ...callsAfter ?? []
697
714
  ];
698
715
  const calls = await this.prependPriceUpdates(cm.address, operationCalls);
699
- const tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
716
+ let tx;
717
+ if (reopenCreditAccount) {
718
+ tx = await cmSuite.creditFacade.multicall(reopenCreditAccount, calls);
719
+ } else {
720
+ tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
721
+ }
700
722
  tx.value = ethAmount.toString(10);
701
723
  return { calls, tx, creditFacade: cmSuite.creditFacade };
702
724
  }
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sendRawTx_exports = {};
20
20
  __export(sendRawTx_exports, {
21
+ estimateRawTxGas: () => estimateRawTxGas,
21
22
  sendRawTx: () => sendRawTx
22
23
  });
23
24
  module.exports = __toCommonJS(sendRawTx_exports);
@@ -36,7 +37,22 @@ async function sendRawTx(client, params) {
36
37
  value: BigInt(tx.value)
37
38
  });
38
39
  }
40
+ async function estimateRawTxGas(client, params) {
41
+ const { tx, ...rest } = params;
42
+ return (0, import_utils.getAction)(
43
+ client,
44
+ import_actions.estimateGas,
45
+ "estimateGas"
46
+ )({
47
+ ...rest,
48
+ account: params.account,
49
+ data: tx.callData,
50
+ to: tx.to,
51
+ value: BigInt(tx.value)
52
+ });
53
+ }
39
54
  // Annotate the CommonJS export names for ESM import in node:
40
55
  0 && (module.exports = {
56
+ estimateRawTxGas,
41
57
  sendRawTx
42
58
  });
@@ -665,33 +665,55 @@ class AbstractCreditAccountService extends SDKConstruct {
665
665
  /**
666
666
  * {@inheritDoc ICreditAccountsService.openCA}
667
667
  **/
668
- async openCA({
669
- ethAmount,
670
- creditManager,
671
- collateral,
672
- permits,
673
- debt,
674
- withdrawDebt,
675
- referralCode,
676
- to,
677
- calls: openPathCalls,
678
- minQuota,
679
- averageQuota
680
- }) {
668
+ async openCA(props) {
669
+ const {
670
+ ethAmount,
671
+ creditManager,
672
+ reopenCreditAccount,
673
+ collateral,
674
+ permits,
675
+ debt,
676
+ withdrawToken,
677
+ referralCode,
678
+ to,
679
+ calls: openPathCalls,
680
+ callsAfter,
681
+ minQuota,
682
+ averageQuota
683
+ } = props;
681
684
  const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
682
685
  const cm = cmSuite.creditManager;
686
+ let tokenToWithdraw;
687
+ if (withdrawToken === true) {
688
+ tokenToWithdraw = cm.underlying;
689
+ } else if (typeof withdrawToken === "string") {
690
+ tokenToWithdraw = withdrawToken;
691
+ }
683
692
  const operationCalls = [
684
693
  this.#prepareIncreaseDebt(cm.creditFacade, debt),
685
694
  ...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
686
695
  ...openPathCalls,
687
- ...withdrawDebt ? [this.prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : [],
696
+ ...tokenToWithdraw ? [
697
+ this.prepareWithdrawToken(
698
+ cm.creditFacade,
699
+ tokenToWithdraw,
700
+ MAX_UINT256,
701
+ to
702
+ )
703
+ ] : [],
688
704
  ...this.prepareUpdateQuotas(cm.creditFacade, {
689
705
  minQuota,
690
706
  averageQuota
691
- })
707
+ }),
708
+ ...callsAfter ?? []
692
709
  ];
693
710
  const calls = await this.prependPriceUpdates(cm.address, operationCalls);
694
- const tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
711
+ let tx;
712
+ if (reopenCreditAccount) {
713
+ tx = await cmSuite.creditFacade.multicall(reopenCreditAccount, calls);
714
+ } else {
715
+ tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
716
+ }
695
717
  tx.value = ethAmount.toString(10);
696
718
  return { calls, tx, creditFacade: cmSuite.creditFacade };
697
719
  }
@@ -1,4 +1,7 @@
1
- import { sendTransaction } from "viem/actions";
1
+ import {
2
+ estimateGas,
3
+ sendTransaction
4
+ } from "viem/actions";
2
5
  import { getAction } from "viem/utils";
3
6
  async function sendRawTx(client, params) {
4
7
  const { tx, ...rest } = params;
@@ -13,6 +16,21 @@ async function sendRawTx(client, params) {
13
16
  value: BigInt(tx.value)
14
17
  });
15
18
  }
19
+ async function estimateRawTxGas(client, params) {
20
+ const { tx, ...rest } = params;
21
+ return getAction(
22
+ client,
23
+ estimateGas,
24
+ "estimateGas"
25
+ )({
26
+ ...rest,
27
+ account: params.account,
28
+ data: tx.callData,
29
+ to: tx.to,
30
+ value: BigInt(tx.value)
31
+ });
32
+ }
16
33
  export {
34
+ estimateRawTxGas,
17
35
  sendRawTx
18
36
  };
@@ -93,7 +93,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
93
93
  /**
94
94
  * {@inheritDoc ICreditAccountsService.openCA}
95
95
  **/
96
- openCA({ ethAmount, creditManager, collateral, permits, debt, withdrawDebt, referralCode, to, calls: openPathCalls, minQuota, averageQuota, }: OpenCAProps): Promise<CreditAccountOperationResult>;
96
+ openCA(props: OpenCAProps): Promise<CreditAccountOperationResult>;
97
97
  /**
98
98
  * {@inheritDoc ICreditAccountsService.getBorrowRate}
99
99
  **/
@@ -389,8 +389,9 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
389
389
  /**
390
390
  * Flag to withdraw debt to wallet after opening credit account;
391
391
  * used for borrowing functionality
392
+ * If true, will withdraw underlying token, otherwise will withdraw specified token
392
393
  */
393
- withdrawDebt?: boolean;
394
+ withdrawToken?: boolean | Address;
394
395
  /**
395
396
  * Permits of collateral tokens (in any permittable token is present) {@link PermitResult}
396
397
  */
@@ -400,10 +401,19 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
400
401
  * Used for trading and strategy functionality
401
402
  */
402
403
  calls: Array<MultiCall>;
404
+ /**
405
+ * Slot for optional call to execute after main tx.
406
+ * For example: add bots
407
+ */
408
+ callsAfter?: Array<MultiCall>;
403
409
  /**
404
410
  * Address of credit manager to open credit account on
405
411
  */
406
412
  creditManager: Address;
413
+ /**
414
+ * Optional address of credit account to reopen
415
+ */
416
+ reopenCreditAccount?: Address;
407
417
  /**
408
418
  * Wallet address to transfer credit account to
409
419
  */
@@ -1,7 +1,11 @@
1
1
  import type { Account, Chain, Client, SendTransactionRequest, SendTransactionReturnType, Transport } from "viem";
2
- import { type SendTransactionParameters } from "viem/actions";
2
+ import { type EstimateGasParameters, type SendTransactionParameters } from "viem/actions";
3
3
  import type { RawTx } from "../../types/index.js";
4
4
  export type SendRawTxParameters<chain extends Chain, account extends Account | undefined, request extends SendTransactionRequest<chain, chainOverride>, chainOverride extends Chain | undefined = undefined> = Omit<SendTransactionParameters<chain, account, chainOverride, request>, "data" | "to" | "value"> & {
5
5
  tx: Pick<RawTx, "to" | "callData" | "value">;
6
6
  };
7
7
  export declare function sendRawTx<chain extends Chain, account extends Account | undefined, const request extends SendTransactionRequest<chain, chainOverride>, chainOverride extends Chain | undefined>(client: Client<Transport, chain, account>, params: SendRawTxParameters<chain, account, request, chainOverride>): Promise<SendTransactionReturnType>;
8
+ export type EstimateRawTxGasParameters<chain extends Chain> = Omit<EstimateGasParameters<chain>, "data" | "to" | "value"> & {
9
+ tx: Pick<RawTx, "to" | "callData" | "value">;
10
+ };
11
+ export declare function estimateRawTxGas<chain extends Chain, account extends Account | undefined>(client: Client<Transport, chain, account>, params: EstimateRawTxGasParameters<chain>): Promise<bigint>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "13.4.0-beta.2",
3
+ "version": "13.4.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",