@gearbox-protocol/sdk 14.12.0-next.11 → 14.12.0-next.12

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.
@@ -1594,19 +1594,14 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
1594
1594
  );
1595
1595
  }
1596
1596
  /**
1597
- * {@inheritDoc ICreditAccountsService.assembleCaUpdateCalls}
1597
+ * {@inheritDoc ICreditAccountsService.assembleCaOperations}
1598
1598
  */
1599
- assembleCaUpdateCalls({
1599
+ assembleCaOperations({
1600
1600
  operations,
1601
- routerCallGroups,
1602
1601
  creditFacade,
1603
- withdrawTo,
1604
- creditAccount,
1605
- underlyingToken
1602
+ withdrawTo
1606
1603
  }) {
1607
1604
  const calls = [];
1608
- let swapGroupIndex = 0;
1609
- let routerGroupsConsumed = 0;
1610
1605
  for (const op of operations) {
1611
1606
  switch (op.type) {
1612
1607
  case "increaseDebt":
@@ -1634,18 +1629,10 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
1634
1629
  )
1635
1630
  );
1636
1631
  break;
1637
- case "swap": {
1638
- const routerCalls = routerCallGroups[swapGroupIndex];
1639
- if (!routerCalls) {
1640
- throw new Error(
1641
- `assembleCaUpdateCalls: missing router calls for swap leg ${swapGroupIndex}`
1642
- );
1643
- }
1644
- calls.push(...routerCalls);
1645
- swapGroupIndex += 1;
1646
- routerGroupsConsumed += 1;
1632
+ case "swap":
1633
+ case "wrapRwaCollateral":
1634
+ calls.push(...op.calls);
1647
1635
  break;
1648
- }
1649
1636
  case "changeQuota": {
1650
1637
  const quotaAssets = [...op.quotaIncrease, ...op.quotaDecrease];
1651
1638
  if (quotaAssets.length === 0) {
@@ -1659,43 +1646,110 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
1659
1646
  );
1660
1647
  break;
1661
1648
  }
1662
- case "closeCreditAccount": {
1663
- for (const group of routerCallGroups) {
1664
- calls.push(...group);
1665
- routerGroupsConsumed += 1;
1666
- }
1649
+ default: {
1650
+ const _exhaustive = op;
1651
+ throw new Error(
1652
+ `assembleCaOperations: unsupported operation ${JSON.stringify(_exhaustive)}`
1653
+ );
1654
+ }
1655
+ }
1656
+ }
1657
+ return calls;
1658
+ }
1659
+ /**
1660
+ * {@inheritDoc ICreditAccountsService.assembleCaUpdateCalls}
1661
+ * @deprecated Prefer {@link CreditAccountsServiceV310.assembleCaOperations}.
1662
+ */
1663
+ assembleCaUpdateCalls({
1664
+ operations,
1665
+ routerCallGroups,
1666
+ creditFacade,
1667
+ withdrawTo,
1668
+ creditAccount,
1669
+ underlyingToken
1670
+ }) {
1671
+ const calls = [];
1672
+ let swapGroupIndex = 0;
1673
+ let routerGroupsConsumed = 0;
1674
+ const encodableOps = [];
1675
+ let pendingClose = null;
1676
+ const flushEncodable = () => {
1677
+ if (encodableOps.length === 0) {
1678
+ return;
1679
+ }
1680
+ calls.push(
1681
+ ...this.assembleCaOperations({
1682
+ operations: encodableOps.splice(0, encodableOps.length),
1683
+ creditFacade,
1684
+ withdrawTo
1685
+ })
1686
+ );
1687
+ };
1688
+ for (const op of operations) {
1689
+ if (op.type === "closeCreditAccount") {
1690
+ flushEncodable();
1691
+ pendingClose = { routerGroupsStart: routerGroupsConsumed };
1692
+ for (const group of routerCallGroups.slice(routerGroupsConsumed)) {
1693
+ calls.push(...group);
1694
+ routerGroupsConsumed += 1;
1695
+ }
1696
+ calls.push(
1697
+ ...this.#prepareDisableQuotas({
1698
+ creditFacade,
1699
+ tokens: Object.entries(creditAccount.initialQuotas).map(
1700
+ ([token, { quota }]) => ({
1701
+ token,
1702
+ quota
1703
+ })
1704
+ )
1705
+ })
1706
+ );
1707
+ if (creditAccount.debt > 0n) {
1667
1708
  calls.push(
1668
- ...this.#prepareDisableQuotas({
1709
+ ...this.#prepareDecreaseDebt({
1669
1710
  creditFacade,
1670
- tokens: Object.entries(creditAccount.initialQuotas).map(
1671
- ([token, { quota }]) => ({
1672
- token,
1673
- quota
1674
- })
1675
- )
1711
+ debt: creditAccount.debt
1676
1712
  })
1677
1713
  );
1678
- if (creditAccount.debt > 0n) {
1679
- calls.push(
1680
- ...this.#prepareDecreaseDebt({
1681
- creditFacade,
1682
- debt: creditAccount.debt
1683
- })
1684
- );
1685
- }
1686
- const hasAssets = creditAccount.assets.some(
1687
- (asset) => asset.balance > 0n
1714
+ }
1715
+ const hasAssets = creditAccount.assets.some(
1716
+ (asset) => asset.balance > 0n
1717
+ );
1718
+ if (hasAssets) {
1719
+ calls.push(
1720
+ this.#prepareWithdrawToken(
1721
+ creditFacade,
1722
+ underlyingToken,
1723
+ import_constants.MAX_UINT256,
1724
+ withdrawTo
1725
+ )
1688
1726
  );
1689
- if (hasAssets) {
1690
- calls.push(
1691
- this.#prepareWithdrawToken(
1692
- creditFacade,
1693
- underlyingToken,
1694
- import_constants.MAX_UINT256,
1695
- withdrawTo
1696
- )
1727
+ }
1728
+ continue;
1729
+ }
1730
+ if (pendingClose !== null) {
1731
+ throw new Error(
1732
+ "assembleCaUpdateCalls: operations after closeCreditAccount are not supported"
1733
+ );
1734
+ }
1735
+ switch (op.type) {
1736
+ case "increaseDebt":
1737
+ case "decreaseDebt":
1738
+ case "addCollateral":
1739
+ case "withdrawCollateral":
1740
+ case "changeQuota":
1741
+ encodableOps.push(op);
1742
+ break;
1743
+ case "swap": {
1744
+ const routerCalls = routerCallGroups[swapGroupIndex];
1745
+ if (!routerCalls) {
1746
+ throw new Error(
1747
+ `assembleCaUpdateCalls: missing router calls for swap leg ${swapGroupIndex}`
1697
1748
  );
1698
1749
  }
1750
+ encodableOps.push({ type: "swap", calls: routerCalls });
1751
+ swapGroupIndex += 1;
1752
+ routerGroupsConsumed += 1;
1699
1753
  break;
1700
1754
  }
1701
1755
  default: {
@@ -1706,6 +1760,7 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
1706
1760
  }
1707
1761
  }
1708
1762
  }
1763
+ flushEncodable();
1709
1764
  if (routerGroupsConsumed !== routerCallGroups.length) {
1710
1765
  throw new Error(
1711
1766
  `assembleCaUpdateCalls: router call group mismatch (consumed ${routerGroupsConsumed}, got ${routerCallGroups.length})`
@@ -1589,19 +1589,14 @@ class CreditAccountsServiceV310 extends SDKConstruct {
1589
1589
  );
1590
1590
  }
1591
1591
  /**
1592
- * {@inheritDoc ICreditAccountsService.assembleCaUpdateCalls}
1592
+ * {@inheritDoc ICreditAccountsService.assembleCaOperations}
1593
1593
  */
1594
- assembleCaUpdateCalls({
1594
+ assembleCaOperations({
1595
1595
  operations,
1596
- routerCallGroups,
1597
1596
  creditFacade,
1598
- withdrawTo,
1599
- creditAccount,
1600
- underlyingToken
1597
+ withdrawTo
1601
1598
  }) {
1602
1599
  const calls = [];
1603
- let swapGroupIndex = 0;
1604
- let routerGroupsConsumed = 0;
1605
1600
  for (const op of operations) {
1606
1601
  switch (op.type) {
1607
1602
  case "increaseDebt":
@@ -1629,18 +1624,10 @@ class CreditAccountsServiceV310 extends SDKConstruct {
1629
1624
  )
1630
1625
  );
1631
1626
  break;
1632
- case "swap": {
1633
- const routerCalls = routerCallGroups[swapGroupIndex];
1634
- if (!routerCalls) {
1635
- throw new Error(
1636
- `assembleCaUpdateCalls: missing router calls for swap leg ${swapGroupIndex}`
1637
- );
1638
- }
1639
- calls.push(...routerCalls);
1640
- swapGroupIndex += 1;
1641
- routerGroupsConsumed += 1;
1627
+ case "swap":
1628
+ case "wrapRwaCollateral":
1629
+ calls.push(...op.calls);
1642
1630
  break;
1643
- }
1644
1631
  case "changeQuota": {
1645
1632
  const quotaAssets = [...op.quotaIncrease, ...op.quotaDecrease];
1646
1633
  if (quotaAssets.length === 0) {
@@ -1654,43 +1641,110 @@ class CreditAccountsServiceV310 extends SDKConstruct {
1654
1641
  );
1655
1642
  break;
1656
1643
  }
1657
- case "closeCreditAccount": {
1658
- for (const group of routerCallGroups) {
1659
- calls.push(...group);
1660
- routerGroupsConsumed += 1;
1661
- }
1644
+ default: {
1645
+ const _exhaustive = op;
1646
+ throw new Error(
1647
+ `assembleCaOperations: unsupported operation ${JSON.stringify(_exhaustive)}`
1648
+ );
1649
+ }
1650
+ }
1651
+ }
1652
+ return calls;
1653
+ }
1654
+ /**
1655
+ * {@inheritDoc ICreditAccountsService.assembleCaUpdateCalls}
1656
+ * @deprecated Prefer {@link CreditAccountsServiceV310.assembleCaOperations}.
1657
+ */
1658
+ assembleCaUpdateCalls({
1659
+ operations,
1660
+ routerCallGroups,
1661
+ creditFacade,
1662
+ withdrawTo,
1663
+ creditAccount,
1664
+ underlyingToken
1665
+ }) {
1666
+ const calls = [];
1667
+ let swapGroupIndex = 0;
1668
+ let routerGroupsConsumed = 0;
1669
+ const encodableOps = [];
1670
+ let pendingClose = null;
1671
+ const flushEncodable = () => {
1672
+ if (encodableOps.length === 0) {
1673
+ return;
1674
+ }
1675
+ calls.push(
1676
+ ...this.assembleCaOperations({
1677
+ operations: encodableOps.splice(0, encodableOps.length),
1678
+ creditFacade,
1679
+ withdrawTo
1680
+ })
1681
+ );
1682
+ };
1683
+ for (const op of operations) {
1684
+ if (op.type === "closeCreditAccount") {
1685
+ flushEncodable();
1686
+ pendingClose = { routerGroupsStart: routerGroupsConsumed };
1687
+ for (const group of routerCallGroups.slice(routerGroupsConsumed)) {
1688
+ calls.push(...group);
1689
+ routerGroupsConsumed += 1;
1690
+ }
1691
+ calls.push(
1692
+ ...this.#prepareDisableQuotas({
1693
+ creditFacade,
1694
+ tokens: Object.entries(creditAccount.initialQuotas).map(
1695
+ ([token, { quota }]) => ({
1696
+ token,
1697
+ quota
1698
+ })
1699
+ )
1700
+ })
1701
+ );
1702
+ if (creditAccount.debt > 0n) {
1662
1703
  calls.push(
1663
- ...this.#prepareDisableQuotas({
1704
+ ...this.#prepareDecreaseDebt({
1664
1705
  creditFacade,
1665
- tokens: Object.entries(creditAccount.initialQuotas).map(
1666
- ([token, { quota }]) => ({
1667
- token,
1668
- quota
1669
- })
1670
- )
1706
+ debt: creditAccount.debt
1671
1707
  })
1672
1708
  );
1673
- if (creditAccount.debt > 0n) {
1674
- calls.push(
1675
- ...this.#prepareDecreaseDebt({
1676
- creditFacade,
1677
- debt: creditAccount.debt
1678
- })
1679
- );
1680
- }
1681
- const hasAssets = creditAccount.assets.some(
1682
- (asset) => asset.balance > 0n
1709
+ }
1710
+ const hasAssets = creditAccount.assets.some(
1711
+ (asset) => asset.balance > 0n
1712
+ );
1713
+ if (hasAssets) {
1714
+ calls.push(
1715
+ this.#prepareWithdrawToken(
1716
+ creditFacade,
1717
+ underlyingToken,
1718
+ MAX_UINT256,
1719
+ withdrawTo
1720
+ )
1683
1721
  );
1684
- if (hasAssets) {
1685
- calls.push(
1686
- this.#prepareWithdrawToken(
1687
- creditFacade,
1688
- underlyingToken,
1689
- MAX_UINT256,
1690
- withdrawTo
1691
- )
1722
+ }
1723
+ continue;
1724
+ }
1725
+ if (pendingClose !== null) {
1726
+ throw new Error(
1727
+ "assembleCaUpdateCalls: operations after closeCreditAccount are not supported"
1728
+ );
1729
+ }
1730
+ switch (op.type) {
1731
+ case "increaseDebt":
1732
+ case "decreaseDebt":
1733
+ case "addCollateral":
1734
+ case "withdrawCollateral":
1735
+ case "changeQuota":
1736
+ encodableOps.push(op);
1737
+ break;
1738
+ case "swap": {
1739
+ const routerCalls = routerCallGroups[swapGroupIndex];
1740
+ if (!routerCalls) {
1741
+ throw new Error(
1742
+ `assembleCaUpdateCalls: missing router calls for swap leg ${swapGroupIndex}`
1692
1743
  );
1693
1744
  }
1745
+ encodableOps.push({ type: "swap", calls: routerCalls });
1746
+ swapGroupIndex += 1;
1747
+ routerGroupsConsumed += 1;
1694
1748
  break;
1695
1749
  }
1696
1750
  default: {
@@ -1701,6 +1755,7 @@ class CreditAccountsServiceV310 extends SDKConstruct {
1701
1755
  }
1702
1756
  }
1703
1757
  }
1758
+ flushEncodable();
1704
1759
  if (routerGroupsConsumed !== routerCallGroups.length) {
1705
1760
  throw new Error(
1706
1761
  `assembleCaUpdateCalls: router call group mismatch (consumed ${routerGroupsConsumed}, got ${routerCallGroups.length})`
@@ -6,7 +6,7 @@ import type { RWAOpenAccountRequirements } from "../market/rwa/index.js";
6
6
  import type { OnchainSDK } from "../OnchainSDK.js";
7
7
  import type { RouterCASlice } from "../router/index.js";
8
8
  import type { MultiCall, RawTx } from "../types/index.js";
9
- import type { AccountToCheck, AddCollateralProps, AssembleCaUpdateCallsProps, AssembleCloseCreditAccountCallsProps, AssembleRepayCreditAccountCallsProps, ChangeDeptProps, ClaimDelayedProps, ClaimFarmRewardsProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, CreditAccountTokensSlice, CreditManagerOperationResult, DefaultPartialLiquidationParams, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetOpenAccountRequirementsProps, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, ICreditAccountsService, OpenCAProps, PartiallyLiquidateProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, Rewards, SetBotProps, StartDelayedWithdrawalProps, UpdateQuotasProps, WithdrawCollateralProps } from "./types.js";
9
+ import type { AccountToCheck, AddCollateralProps, AssembleCaOperationsProps, AssembleCaUpdateCallsProps, AssembleCloseCreditAccountCallsProps, AssembleRepayCreditAccountCallsProps, ChangeDeptProps, ClaimDelayedProps, ClaimFarmRewardsProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, CreditAccountTokensSlice, CreditManagerOperationResult, DefaultPartialLiquidationParams, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetOpenAccountRequirementsProps, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, ICreditAccountsService, OpenCAProps, PartiallyLiquidateProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, Rewards, SetBotProps, StartDelayedWithdrawalProps, UpdateQuotasProps, WithdrawCollateralProps } from "./types.js";
10
10
  /**
11
11
  * Options for configuring the credit account service.
12
12
  **/
@@ -218,8 +218,13 @@ export declare class CreditAccountsServiceV310 extends SDKConstruct implements I
218
218
  prependPriceUpdates(creditManager: Address, calls: MultiCall[], creditAccount?: RouterCASlice, options?: {
219
219
  ignoreReservePrices?: boolean;
220
220
  }): Promise<MultiCall[]>;
221
+ /**
222
+ * {@inheritDoc ICreditAccountsService.assembleCaOperations}
223
+ */
224
+ assembleCaOperations({ operations, creditFacade, withdrawTo, }: AssembleCaOperationsProps): MultiCall[];
221
225
  /**
222
226
  * {@inheritDoc ICreditAccountsService.assembleCaUpdateCalls}
227
+ * @deprecated Prefer {@link CreditAccountsServiceV310.assembleCaOperations}.
223
228
  */
224
229
  assembleCaUpdateCalls({ operations, routerCallGroups, creditFacade, withdrawTo, creditAccount, underlyingToken, }: AssembleCaUpdateCallsProps): MultiCall[];
225
230
  /**
@@ -713,6 +713,10 @@ export type GetApprovalAddressProps = {
713
713
  *
714
714
  * Used by {@link ICreditAccountsService.assembleCaUpdateCalls} to build the
715
715
  * underlying credit facade multicall calls.
716
+ *
717
+ * @deprecated Prefer {@link EncodableCreditAccountOperation} with
718
+ * {@link ICreditAccountsService.assembleCaOperations}. Close stays on dedicated
719
+ * assemblers / this deprecated path only.
716
720
  */
717
721
  export type CreditAccountUpdateOperation = {
718
722
  type: "increaseDebt";
@@ -739,6 +743,9 @@ export type CreditAccountUpdateOperation = {
739
743
  };
740
744
  /**
741
745
  * Input for {@link ICreditAccountsService.assembleCaUpdateCalls}.
746
+ *
747
+ * @deprecated Prefer {@link AssembleCaOperationsProps} /
748
+ * {@link ICreditAccountsService.assembleCaOperations}.
742
749
  */
743
750
  export type AssembleCaUpdateCallsProps = {
744
751
  operations: Array<CreditAccountUpdateOperation>;
@@ -755,6 +762,47 @@ export type AssembleCaUpdateCallsProps = {
755
762
  };
756
763
  underlyingToken: Address;
757
764
  };
765
+ /**
766
+ * An enriched credit-account operation ready for encoding.
767
+ * Each op carries everything needed to build facade / adapter multicalls —
768
+ * swap and wrap attach concrete `calls` (no external routerCallGroups).
769
+ *
770
+ * Used by {@link ICreditAccountsService.assembleCaOperations}. Does not include
771
+ * close / repay (use dedicated assemblers).
772
+ */
773
+ export type EncodableCreditAccountOperation = {
774
+ type: "increaseDebt";
775
+ amount: bigint;
776
+ } | {
777
+ type: "decreaseDebt";
778
+ amount: bigint;
779
+ } | {
780
+ type: "addCollateral";
781
+ token: Address;
782
+ amount: bigint;
783
+ } | {
784
+ type: "withdrawCollateral";
785
+ token: Address;
786
+ amount: bigint;
787
+ } | {
788
+ type: "swap";
789
+ calls: Array<MultiCall>;
790
+ } | {
791
+ type: "wrapRwaCollateral";
792
+ calls: Array<MultiCall>;
793
+ } | {
794
+ type: "changeQuota";
795
+ quotaIncrease: Array<Asset>;
796
+ quotaDecrease: Array<Asset>;
797
+ };
798
+ /**
799
+ * Input for {@link ICreditAccountsService.assembleCaOperations}.
800
+ */
801
+ export type AssembleCaOperationsProps = {
802
+ operations: Array<EncodableCreditAccountOperation>;
803
+ creditFacade: Address;
804
+ withdrawTo: Address;
805
+ };
758
806
  export interface ICreditAccountsService extends Construct {
759
807
  sdk: OnchainSDK;
760
808
  /**
@@ -989,11 +1037,26 @@ export interface ICreditAccountsService extends Construct {
989
1037
  prependPriceUpdates(creditManager: Address, calls: Array<MultiCall>, creditAccount?: RouterCASlice, options?: {
990
1038
  ignoreReservePrices?: boolean;
991
1039
  }): Promise<Array<MultiCall>>;
1040
+ /**
1041
+ * Builds credit facade multicall calls from an enriched operation list.
1042
+ * Each operation must already carry concrete encoding data (e.g. swap/wrap
1043
+ * `calls`). Unknown operation types throw.
1044
+ *
1045
+ * Does not handle close or repay — use
1046
+ * {@link ICreditAccountsService.assembleCloseCreditAccountCalls} /
1047
+ * {@link ICreditAccountsService.assembleRepayCreditAccountCalls}.
1048
+ *
1049
+ * @param props - Encodable operations and account context
1050
+ * @returns Array of facade / adapter multicall calls (without price feed updates)
1051
+ */
1052
+ assembleCaOperations(props: AssembleCaOperationsProps): Array<MultiCall>;
992
1053
  /**
993
1054
  * Builds the credit facade multicall calls for a chain of update operations.
994
1055
  *
995
1056
  * @param props - Operation chain, router call groups and account context
996
1057
  * @returns Array of facade multicall calls (without price feed updates)
1058
+ * @deprecated Prefer {@link ICreditAccountsService.assembleCaOperations}. Close
1059
+ * remains on this method / dedicated close assembler only.
997
1060
  */
998
1061
  assembleCaUpdateCalls(props: AssembleCaUpdateCallsProps): Array<MultiCall>;
999
1062
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.12.0-next.11",
3
+ "version": "14.12.0-next.12",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {