@gearbox-protocol/sdk 14.12.0-next.14 → 14.12.0-next.15
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.
|
@@ -1631,6 +1631,7 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
|
|
|
1631
1631
|
break;
|
|
1632
1632
|
case "swap":
|
|
1633
1633
|
case "wrapRwaCollateral":
|
|
1634
|
+
case "unwrapRwaCollateral":
|
|
1634
1635
|
calls.push(...op.calls);
|
|
1635
1636
|
break;
|
|
1636
1637
|
case "changeQuota": {
|
|
@@ -1656,118 +1657,6 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
|
|
|
1656
1657
|
}
|
|
1657
1658
|
return calls;
|
|
1658
1659
|
}
|
|
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) {
|
|
1708
|
-
calls.push(
|
|
1709
|
-
...this.#prepareDecreaseDebt({
|
|
1710
|
-
creditFacade,
|
|
1711
|
-
debt: creditAccount.debt
|
|
1712
|
-
})
|
|
1713
|
-
);
|
|
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
|
-
)
|
|
1726
|
-
);
|
|
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}`
|
|
1748
|
-
);
|
|
1749
|
-
}
|
|
1750
|
-
encodableOps.push({ type: "swap", calls: routerCalls });
|
|
1751
|
-
swapGroupIndex += 1;
|
|
1752
|
-
routerGroupsConsumed += 1;
|
|
1753
|
-
break;
|
|
1754
|
-
}
|
|
1755
|
-
default: {
|
|
1756
|
-
const _exhaustive = op;
|
|
1757
|
-
throw new Error(
|
|
1758
|
-
`assembleCaUpdateCalls: unsupported operation ${_exhaustive}`
|
|
1759
|
-
);
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
flushEncodable();
|
|
1764
|
-
if (routerGroupsConsumed !== routerCallGroups.length) {
|
|
1765
|
-
throw new Error(
|
|
1766
|
-
`assembleCaUpdateCalls: router call group mismatch (consumed ${routerGroupsConsumed}, got ${routerCallGroups.length})`
|
|
1767
|
-
);
|
|
1768
|
-
}
|
|
1769
|
-
return calls;
|
|
1770
|
-
}
|
|
1771
1660
|
/**
|
|
1772
1661
|
* {@inheritDoc ICreditAccountsService.executeCaUpdate}
|
|
1773
1662
|
*/
|
|
@@ -1626,6 +1626,7 @@ class CreditAccountsServiceV310 extends SDKConstruct {
|
|
|
1626
1626
|
break;
|
|
1627
1627
|
case "swap":
|
|
1628
1628
|
case "wrapRwaCollateral":
|
|
1629
|
+
case "unwrapRwaCollateral":
|
|
1629
1630
|
calls.push(...op.calls);
|
|
1630
1631
|
break;
|
|
1631
1632
|
case "changeQuota": {
|
|
@@ -1651,118 +1652,6 @@ class CreditAccountsServiceV310 extends SDKConstruct {
|
|
|
1651
1652
|
}
|
|
1652
1653
|
return calls;
|
|
1653
1654
|
}
|
|
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) {
|
|
1703
|
-
calls.push(
|
|
1704
|
-
...this.#prepareDecreaseDebt({
|
|
1705
|
-
creditFacade,
|
|
1706
|
-
debt: creditAccount.debt
|
|
1707
|
-
})
|
|
1708
|
-
);
|
|
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
|
-
)
|
|
1721
|
-
);
|
|
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}`
|
|
1743
|
-
);
|
|
1744
|
-
}
|
|
1745
|
-
encodableOps.push({ type: "swap", calls: routerCalls });
|
|
1746
|
-
swapGroupIndex += 1;
|
|
1747
|
-
routerGroupsConsumed += 1;
|
|
1748
|
-
break;
|
|
1749
|
-
}
|
|
1750
|
-
default: {
|
|
1751
|
-
const _exhaustive = op;
|
|
1752
|
-
throw new Error(
|
|
1753
|
-
`assembleCaUpdateCalls: unsupported operation ${_exhaustive}`
|
|
1754
|
-
);
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
flushEncodable();
|
|
1759
|
-
if (routerGroupsConsumed !== routerCallGroups.length) {
|
|
1760
|
-
throw new Error(
|
|
1761
|
-
`assembleCaUpdateCalls: router call group mismatch (consumed ${routerGroupsConsumed}, got ${routerCallGroups.length})`
|
|
1762
|
-
);
|
|
1763
|
-
}
|
|
1764
|
-
return calls;
|
|
1765
|
-
}
|
|
1766
1655
|
/**
|
|
1767
1656
|
* {@inheritDoc ICreditAccountsService.executeCaUpdate}
|
|
1768
1657
|
*/
|
|
@@ -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, AssembleCaOperationsProps,
|
|
9
|
+
import type { AccountToCheck, AddCollateralProps, AssembleCaOperationsProps, 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
|
**/
|
|
@@ -222,11 +222,6 @@ export declare class CreditAccountsServiceV310 extends SDKConstruct implements I
|
|
|
222
222
|
* {@inheritDoc ICreditAccountsService.assembleCaOperations}
|
|
223
223
|
*/
|
|
224
224
|
assembleCaOperations({ operations, creditFacade, withdrawTo, }: AssembleCaOperationsProps): MultiCall[];
|
|
225
|
-
/**
|
|
226
|
-
* {@inheritDoc ICreditAccountsService.assembleCaUpdateCalls}
|
|
227
|
-
* @deprecated Prefer {@link CreditAccountsServiceV310.assembleCaOperations}.
|
|
228
|
-
*/
|
|
229
|
-
assembleCaUpdateCalls({ operations, routerCallGroups, creditFacade, withdrawTo, creditAccount, underlyingToken, }: AssembleCaUpdateCallsProps): MultiCall[];
|
|
230
225
|
/**
|
|
231
226
|
* {@inheritDoc ICreditAccountsService.executeCaUpdate}
|
|
232
227
|
*/
|
|
@@ -708,64 +708,10 @@ export type GetApprovalAddressProps = {
|
|
|
708
708
|
creditManager: Address;
|
|
709
709
|
creditAccount: Address;
|
|
710
710
|
};
|
|
711
|
-
/**
|
|
712
|
-
* A single step in a generic credit account update operation chain.
|
|
713
|
-
*
|
|
714
|
-
* Used by {@link ICreditAccountsService.assembleCaUpdateCalls} to build the
|
|
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.
|
|
720
|
-
*/
|
|
721
|
-
export type CreditAccountUpdateOperation = {
|
|
722
|
-
type: "increaseDebt";
|
|
723
|
-
amount: bigint;
|
|
724
|
-
} | {
|
|
725
|
-
type: "decreaseDebt";
|
|
726
|
-
amount: bigint;
|
|
727
|
-
} | {
|
|
728
|
-
type: "addCollateral";
|
|
729
|
-
token: Address;
|
|
730
|
-
amount: bigint;
|
|
731
|
-
} | {
|
|
732
|
-
type: "withdrawCollateral";
|
|
733
|
-
token: Address;
|
|
734
|
-
amount: bigint;
|
|
735
|
-
} | {
|
|
736
|
-
type: "swap";
|
|
737
|
-
} | {
|
|
738
|
-
type: "changeQuota";
|
|
739
|
-
quotaIncrease: Array<Asset>;
|
|
740
|
-
quotaDecrease: Array<Asset>;
|
|
741
|
-
} | {
|
|
742
|
-
type: "closeCreditAccount";
|
|
743
|
-
};
|
|
744
|
-
/**
|
|
745
|
-
* Input for {@link ICreditAccountsService.assembleCaUpdateCalls}.
|
|
746
|
-
*
|
|
747
|
-
* @deprecated Prefer {@link AssembleCaOperationsProps} /
|
|
748
|
-
* {@link ICreditAccountsService.assembleCaOperations}.
|
|
749
|
-
*/
|
|
750
|
-
export type AssembleCaUpdateCallsProps = {
|
|
751
|
-
operations: Array<CreditAccountUpdateOperation>;
|
|
752
|
-
/** One group per swap leg (in order), or a single group for the close path. */
|
|
753
|
-
routerCallGroups: Array<Array<MultiCall>>;
|
|
754
|
-
creditFacade: Address;
|
|
755
|
-
withdrawTo: Address;
|
|
756
|
-
creditAccount: {
|
|
757
|
-
debt: bigint;
|
|
758
|
-
assets: Array<Asset>;
|
|
759
|
-
initialQuotas: Record<Address, {
|
|
760
|
-
quota: bigint;
|
|
761
|
-
}>;
|
|
762
|
-
};
|
|
763
|
-
underlyingToken: Address;
|
|
764
|
-
};
|
|
765
711
|
/**
|
|
766
712
|
* An enriched credit-account operation ready for encoding.
|
|
767
713
|
* Each op carries everything needed to build facade / adapter multicalls —
|
|
768
|
-
* swap
|
|
714
|
+
* swap / wrap / unwrap attach concrete `calls` (no external routerCallGroups).
|
|
769
715
|
*
|
|
770
716
|
* Used by {@link ICreditAccountsService.assembleCaOperations}. Does not include
|
|
771
717
|
* close / repay (use dedicated assemblers).
|
|
@@ -790,6 +736,9 @@ export type EncodableCreditAccountOperation = {
|
|
|
790
736
|
} | {
|
|
791
737
|
type: "wrapRwaCollateral";
|
|
792
738
|
calls: Array<MultiCall>;
|
|
739
|
+
} | {
|
|
740
|
+
type: "unwrapRwaCollateral";
|
|
741
|
+
calls: Array<MultiCall>;
|
|
793
742
|
} | {
|
|
794
743
|
type: "changeQuota";
|
|
795
744
|
quotaIncrease: Array<Asset>;
|
|
@@ -1050,15 +999,6 @@ export interface ICreditAccountsService extends Construct {
|
|
|
1050
999
|
* @returns Array of facade / adapter multicall calls (without price feed updates)
|
|
1051
1000
|
*/
|
|
1052
1001
|
assembleCaOperations(props: AssembleCaOperationsProps): Array<MultiCall>;
|
|
1053
|
-
/**
|
|
1054
|
-
* Builds the credit facade multicall calls for a chain of update operations.
|
|
1055
|
-
*
|
|
1056
|
-
* @param props - Operation chain, router call groups and account context
|
|
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.
|
|
1060
|
-
*/
|
|
1061
|
-
assembleCaUpdateCalls(props: AssembleCaUpdateCallsProps): Array<MultiCall>;
|
|
1062
1002
|
/**
|
|
1063
1003
|
* Executes a credit account update: prepends price feed updates and builds the raw
|
|
1064
1004
|
* multicall transaction. Uses the RWA factory when applicable.
|