@gearbox-protocol/sdk 18.4.1-aave.1 → 18.4.1-aave.3

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.
Files changed (105) hide show
  1. package/dist/cjs/model/errors/index.js +1 -0
  2. package/dist/cjs/model/errors/operation-errors.js +9 -0
  3. package/dist/cjs/model/index.js +1 -0
  4. package/dist/cjs/onchain/accounts/bots/AccountBotsService.js +29 -0
  5. package/dist/cjs/onchain/accounts/bots/PeripheryCompressorV310Contract.js +2 -1
  6. package/dist/cjs/onchain/accounts/intents/operations.js +2 -2
  7. package/dist/cjs/onchain/accounts/intents/plan.js +6 -1
  8. package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
  9. package/dist/cjs/onchain/index.js +10 -0
  10. package/dist/cjs/onchain/market/ZapperRegister.js +1 -1
  11. package/dist/cjs/onchain/market/adapters/abi/aave/iAaveOracle.js +20 -0
  12. package/dist/cjs/onchain/market/adapters/abi/aave/iAaveV3Pool.js +166 -0
  13. package/dist/cjs/onchain/market/adapters/abi/aave/iPoolAddressesProvider.js +11 -0
  14. package/dist/cjs/onchain/market/adapters/abi/aave/iVariableDebtToken.js +17 -0
  15. package/dist/cjs/onchain/market/adapters/abi/aave/index.js +6 -0
  16. package/dist/cjs/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.js +27 -0
  17. package/dist/cjs/onchain/market/adapters/abi/index.js +6 -0
  18. package/dist/cjs/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.js +71 -12
  19. package/dist/cjs/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.js +5 -11
  20. package/dist/cjs/onchain/market/adapters/index.js +6 -0
  21. package/dist/cjs/onchain/market/index.js +6 -0
  22. package/dist/cjs/onchain/positions/projectAavePosition.js +163 -26
  23. package/dist/cjs/onchain/preview/index.js +2 -0
  24. package/dist/cjs/onchain/preview/preview/aaveBridgeBorrows.js +24 -0
  25. package/dist/cjs/onchain/preview/preview/index.js +2 -0
  26. package/dist/cjs/onchain/preview/preview/previewAdjustStrategyPosition.js +3 -0
  27. package/dist/cjs/onchain/preview/preview/previewExitOrRepayStrategyPosition.js +3 -0
  28. package/dist/cjs/onchain/validation/bundles/checkAaveDelegation.js +54 -0
  29. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +34 -11
  30. package/dist/cjs/onchain/validation/bundles/index.js +2 -0
  31. package/dist/cjs/onchain/validation/checkOperation.js +16 -4
  32. package/dist/cjs/onchain/validation/index.js +2 -0
  33. package/dist/cjs/sdk/prepare/PrepareApi.js +21 -3
  34. package/dist/cjs/sdk/preview/PreviewNamespace.js +11 -2
  35. package/dist/esm/model/errors/index.js +2 -2
  36. package/dist/esm/model/errors/operation-errors.js +9 -1
  37. package/dist/esm/model/index.js +2 -2
  38. package/dist/esm/onchain/accounts/bots/AccountBotsService.js +29 -0
  39. package/dist/esm/onchain/accounts/bots/PeripheryCompressorV310Contract.js +1 -1
  40. package/dist/esm/onchain/accounts/intents/operations.js +2 -2
  41. package/dist/esm/onchain/accounts/intents/plan.js +6 -1
  42. package/dist/esm/onchain/accounts/intents/tail.js +1 -1
  43. package/dist/esm/onchain/index.js +6 -1
  44. package/dist/esm/onchain/market/ZapperRegister.js +1 -1
  45. package/dist/esm/onchain/market/adapters/abi/aave/iAaveOracle.js +19 -0
  46. package/dist/esm/onchain/market/adapters/abi/aave/iAaveV3Pool.js +166 -0
  47. package/dist/esm/onchain/market/adapters/abi/aave/iPoolAddressesProvider.js +10 -0
  48. package/dist/esm/onchain/market/adapters/abi/aave/iVariableDebtToken.js +16 -0
  49. package/dist/esm/onchain/market/adapters/abi/aave/index.js +4 -1
  50. package/dist/esm/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.js +27 -0
  51. package/dist/esm/onchain/market/adapters/abi/index.js +4 -1
  52. package/dist/esm/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.js +72 -13
  53. package/dist/esm/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.js +6 -12
  54. package/dist/esm/onchain/market/adapters/index.js +4 -1
  55. package/dist/esm/onchain/market/index.js +4 -1
  56. package/dist/esm/onchain/positions/projectAavePosition.js +164 -27
  57. package/dist/esm/onchain/preview/index.js +2 -1
  58. package/dist/esm/onchain/preview/preview/aaveBridgeBorrows.js +23 -0
  59. package/dist/esm/onchain/preview/preview/index.js +2 -1
  60. package/dist/esm/onchain/preview/preview/previewAdjustStrategyPosition.js +3 -0
  61. package/dist/esm/onchain/preview/preview/previewExitOrRepayStrategyPosition.js +3 -0
  62. package/dist/esm/onchain/validation/bundles/checkAaveDelegation.js +53 -0
  63. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +34 -11
  64. package/dist/esm/onchain/validation/bundles/index.js +2 -1
  65. package/dist/esm/onchain/validation/checkOperation.js +16 -4
  66. package/dist/esm/onchain/validation/index.js +2 -1
  67. package/dist/esm/sdk/prepare/PrepareApi.js +22 -4
  68. package/dist/esm/sdk/preview/PreviewNamespace.js +11 -2
  69. package/dist/types/model/aave.d.ts +20 -3
  70. package/dist/types/model/errors/index.d.ts +2 -2
  71. package/dist/types/model/errors/operation-errors.d.ts +19 -0
  72. package/dist/types/model/index.d.ts +3 -3
  73. package/dist/types/model/previews.d.ts +11 -1
  74. package/dist/types/onchain/accounts/bots/AccountBotsService.d.ts +11 -1
  75. package/dist/types/onchain/accounts/bots/index.d.ts +2 -2
  76. package/dist/types/onchain/accounts/bots/types.d.ts +7 -1
  77. package/dist/types/onchain/accounts/index.d.ts +2 -2
  78. package/dist/types/onchain/accounts/intents/operations.d.ts +9 -3
  79. package/dist/types/onchain/accounts/intents/types.d.ts +5 -0
  80. package/dist/types/onchain/index.d.ts +7 -2
  81. package/dist/types/onchain/market/adapters/abi/aave/iAaveOracle.d.ts +22 -0
  82. package/dist/types/onchain/market/adapters/abi/aave/iAaveV3Pool.d.ts +139 -0
  83. package/dist/types/onchain/market/adapters/abi/aave/iPoolAddressesProvider.d.ts +11 -0
  84. package/dist/types/onchain/market/adapters/abi/aave/iVariableDebtToken.d.ts +17 -0
  85. package/dist/types/onchain/market/adapters/abi/aave/index.d.ts +4 -1
  86. package/dist/types/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.d.ts +21 -0
  87. package/dist/types/onchain/market/adapters/abi/index.d.ts +4 -1
  88. package/dist/types/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.d.ts +47 -10
  89. package/dist/types/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.d.ts +142 -4
  90. package/dist/types/onchain/market/adapters/index.d.ts +4 -1
  91. package/dist/types/onchain/market/index.d.ts +4 -1
  92. package/dist/types/onchain/positions/projectAavePosition.d.ts +33 -4
  93. package/dist/types/onchain/preview/index.d.ts +2 -1
  94. package/dist/types/onchain/preview/preview/aaveBridgeBorrows.d.ts +15 -0
  95. package/dist/types/onchain/preview/preview/index.d.ts +2 -1
  96. package/dist/types/onchain/validation/bundles/checkAaveDelegation.d.ts +21 -0
  97. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +2 -2
  98. package/dist/types/onchain/validation/bundles/index.d.ts +2 -1
  99. package/dist/types/onchain/validation/index.d.ts +2 -1
  100. package/dist/types/sdk/index.d.ts +2 -2
  101. package/dist/types/sdk/prepare/PrepareApi.d.ts +2 -2
  102. package/dist/types/sdk/prepare/index.d.ts +2 -2
  103. package/dist/types/sdk/prepare/types.d.ts +49 -11
  104. package/dist/types/sdk/preview/types.d.ts +4 -2
  105. package/package.json +1 -1
@@ -1,39 +1,176 @@
1
- import { PERCENTAGE_FACTOR, SECONDS_PER_YEAR } from "../constants/math.js";
1
+ import { MAX_UINT16, PERCENTAGE_FACTOR, PRICE_DECIMALS, RAY, SECONDS_PER_YEAR } from "../constants/math.js";
2
+ import { iAaveOracleAbi } from "../market/adapters/abi/aave/iAaveOracle.js";
3
+ import { iAaveV3PoolAbi } from "../market/adapters/abi/aave/iAaveV3Pool.js";
4
+ import { iPoolAddressesProviderAbi } from "../market/adapters/abi/aave/iPoolAddressesProvider.js";
5
+ import "../market/adapters/abi/aave/index.js";
6
+ import { AaveHorizonBridgeAdapterContract } from "../market/adapters/contracts/AaveHorizonBridgeAdapterContract.js";
7
+ import { AaveV3PoolAdapterContract } from "../market/adapters/contracts/AaveV3PoolAdapterContract.js";
8
+ import { calcPositionLeverage } from "../market/math.js";
9
+ import { isAddressEqual } from "viem";
2
10
  //#region src/onchain/positions/projectAavePosition.ts
3
11
  /**
4
- * Mint settlement period, until each RWA token reports its own.
5
- **/
6
- const MINT_DURATION = 432e3;
7
- /**
8
12
  * Where an opening lands once it has moved to Aave Horizon, from the snapshot
9
13
  * of the credit account it is built in.
10
14
  *
11
- * Placeholder until the Aave Horizon contracts ship: the mint is assumed to
12
- * take {@link MINT_DURATION} and to mint the account's balances one for one,
13
- * and the Aave side is weighed by the credit manager's own projection.
15
+ * The finalizer bot supplies the account's RWA to the pool and borrows the
16
+ * Gearbox debt against it on the owner's behalf, so the Aave side is read off
17
+ * the pool for `owner`: the reserve's LTV and liquidation threshold (its eMode
18
+ * category's, where the owner is in one that lists it), the Aave oracle's
19
+ * prices, the variable borrow rate of the underlying, and whatever the owner
20
+ * already holds and owes there. `healthFactor` and `liquidationPrice` are of
21
+ * that whole position; the values describe this opening alone.
22
+ *
23
+ * The RWA is either on the account already, and the position is on Aave at
24
+ * once (the bot's move is the next block), or still being minted: then the
25
+ * account holds the withdrawal phantom token of a delayed operation the
26
+ * withdrawal compressor lists for the credit manager, the mint takes that
27
+ * operation's `withdrawalLength` and is assumed to come out one for one, and
28
+ * the Gearbox debt accrues interest at the credit manager's rate meanwhile.
29
+ *
30
+ * `undefined` when the credit manager cannot move the account to Aave: no
31
+ * pool adapter lists an asset of the account or the RWA it is being minted
32
+ * into, or no bridge adapter takes its aToken against the underlying.
14
33
  **/
15
- function projectAavePosition(sdk, snapshot) {
34
+ async function projectAavePosition(sdk, snapshot, owner) {
35
+ const suite = sdk.marketRegister.findCreditManager(snapshot.creditManager);
16
36
  const market = sdk.marketRegister.findByCreditManager(snapshot.creditManager);
17
- const pool = { availableLiquidityChange: -snapshot.totalDebt };
18
- const rate = sdk.positions.metrics(snapshot, pool).borrowRate.totalOnDebt;
19
- const interest = snapshot.totalDebt * BigInt(rate) * BigInt(MINT_DURATION) / (PERCENTAGE_FACTOR * BigInt(SECONDS_PER_YEAR));
20
- const { totalValue, totalDebt, netValue, assets, healthFactor, liquidationPrice, borrowRate, leverage } = sdk.positions.projection({
21
- ...snapshot,
22
- totalDebt: snapshot.totalDebt + interest
23
- }, pool);
37
+ const { underlying } = market;
38
+ const adapters = suite.creditManager.adapters.values();
39
+ const poolAdapters = adapters.filter((p) => p instanceof AaveV3PoolAdapterContract);
40
+ const compressor = sdk.withdrawalCompressor;
41
+ const delayed = compressor?.state ? compressor.getWithdrawableAssets(snapshot.creditManager) : [];
42
+ let collateral;
43
+ let mintDuration = 0;
44
+ let poolAdapter;
45
+ for (const a of snapshot.assets) {
46
+ if (a.balance <= 10n || isAddressEqual(a.token, underlying)) continue;
47
+ const mint = delayed.find((d) => isAddressEqual(d.withdrawalPhantomToken, a.token));
48
+ const token = mint ? mint.underlying : a.token;
49
+ poolAdapter = poolAdapters.find((p) => p.isAssetAllowed(token));
50
+ if (poolAdapter) {
51
+ collateral = {
52
+ token,
53
+ balance: a.balance
54
+ };
55
+ mintDuration = mint ? Number(mint.withdrawalLength) : 0;
56
+ break;
57
+ }
58
+ }
59
+ if (!collateral || !poolAdapter) return;
60
+ const pool = poolAdapter.targetContract;
61
+ const [rwaReserve, debtReserve, account, eMode, provider] = await sdk.client.multicall({
62
+ contracts: [
63
+ {
64
+ address: pool,
65
+ abi: iAaveV3PoolAbi,
66
+ functionName: "getReserveData",
67
+ args: [collateral.token]
68
+ },
69
+ {
70
+ address: pool,
71
+ abi: iAaveV3PoolAbi,
72
+ functionName: "getReserveData",
73
+ args: [underlying]
74
+ },
75
+ {
76
+ address: pool,
77
+ abi: iAaveV3PoolAbi,
78
+ functionName: "getUserAccountData",
79
+ args: [owner]
80
+ },
81
+ {
82
+ address: pool,
83
+ abi: iAaveV3PoolAbi,
84
+ functionName: "getUserEMode",
85
+ args: [owner]
86
+ },
87
+ {
88
+ address: pool,
89
+ abi: iAaveV3PoolAbi,
90
+ functionName: "ADDRESSES_PROVIDER"
91
+ }
92
+ ],
93
+ allowFailure: false,
94
+ batchSize: 0
95
+ });
96
+ const bridgeAdapter = adapters.find((b) => b instanceof AaveHorizonBridgeAdapterContract && b.isATokenAllowed(rwaReserve.aTokenAddress) && b.isDebtTokenAllowed(underlying));
97
+ if (!bridgeAdapter) return;
98
+ const oracle = await sdk.client.readContract({
99
+ address: provider,
100
+ abi: iPoolAddressesProviderAbi,
101
+ functionName: "getPriceOracle"
102
+ });
103
+ const [[rwaPrice, underlyingPrice], categoryParams] = await Promise.all([sdk.client.readContract({
104
+ address: oracle,
105
+ abi: iAaveOracleAbi,
106
+ functionName: "getAssetsPrices",
107
+ args: [[collateral.token, underlying]]
108
+ }), eMode > 0n ? sdk.client.multicall({
109
+ contracts: [{
110
+ address: pool,
111
+ abi: iAaveV3PoolAbi,
112
+ functionName: "getEModeCategoryCollateralConfig",
113
+ args: [Number(eMode)]
114
+ }, {
115
+ address: pool,
116
+ abi: iAaveV3PoolAbi,
117
+ functionName: "getEModeCategoryCollateralBitmap",
118
+ args: [Number(eMode)]
119
+ }],
120
+ allowFailure: false,
121
+ batchSize: 0
122
+ }) : void 0]);
123
+ const rwaConfig = rwaReserve.configuration.data;
124
+ let ltv = rwaConfig & 65535n;
125
+ let liquidationThreshold = rwaConfig >> 16n & 65535n;
126
+ const [category, bitmap] = categoryParams ?? [];
127
+ if (category && bitmap && bitmap >> BigInt(rwaReserve.id) & 1n) {
128
+ ltv = BigInt(category.ltv);
129
+ liquidationThreshold = BigInt(category.liquidationThreshold);
130
+ }
131
+ const rwaScale = 10n ** (rwaConfig >> 48n & 255n);
132
+ const underlyingScale = 10n ** (debtReserve.configuration.data >> 48n & 255n);
133
+ const collateralBase = account[0];
134
+ const debtBase = account[1];
135
+ const currentLiquidationThreshold = account[3];
136
+ const currentLtv = account[4];
137
+ const gearboxPool = { availableLiquidityChange: -snapshot.totalDebt };
138
+ const gearboxRate = sdk.positions.metrics(snapshot, gearboxPool).borrowRate.totalOnDebt;
139
+ const interest = snapshot.totalDebt * BigInt(gearboxRate) * BigInt(mintDuration) / (PERCENTAGE_FACTOR * BigInt(SECONDS_PER_YEAR));
140
+ const totalDebt = snapshot.totalDebt + interest;
141
+ const suppliedBase = collateral.balance * rwaPrice / rwaScale;
142
+ const owedBase = debtBase + ceilDiv(totalDebt * underlyingPrice, underlyingScale);
143
+ const weightedLiquidation = collateralBase * currentLiquidationThreshold + suppliedBase * liquidationThreshold;
144
+ const borrowableBase = (collateralBase * currentLtv + suppliedBase * ltv) / PERCENTAGE_FACTOR;
145
+ const totalValue = collateral.balance * rwaPrice * underlyingScale / (rwaScale * underlyingPrice);
146
+ const rate = Number(debtReserve.currentVariableBorrowRate * PERCENTAGE_FACTOR / RAY);
147
+ const uncovered = owedBase * PERCENTAGE_FACTOR - collateralBase * currentLiquidationThreshold;
148
+ const liquidationPrice = liquidationThreshold === 0n ? null : uncovered <= 0n ? 0n : uncovered * rwaScale * PRICE_DECIMALS / (collateral.balance * liquidationThreshold * underlyingPrice);
24
149
  return {
25
- totalValue,
26
- totalDebt,
27
- netValue,
28
- assets,
29
- healthFactor,
30
- liquidationPrice,
31
- borrowRate,
32
- leverage,
33
- mintPeriodInterest: market.toUnderlyingAmount(interest),
34
- mintDuration: MINT_DURATION,
35
- estLiveAt: Number(sdk.timestamp) + MINT_DURATION
150
+ aave: {
151
+ totalValue: market.toUnderlyingAmount(totalValue),
152
+ totalDebt: market.toUnderlyingAmount(totalDebt),
153
+ netValue: market.toUnderlyingAmount(totalValue - totalDebt),
154
+ assets: [market.priceOracle.toTokenAmount(collateral.token, collateral.balance)],
155
+ healthFactor: Number(owedBase > 0n ? weightedLiquidation / owedBase : MAX_UINT16),
156
+ liquidationPrice,
157
+ borrowRate: {
158
+ total: totalValue > 0n ? Number(BigInt(rate) * totalDebt / totalValue) : 0,
159
+ totalOnDebt: rate,
160
+ base: rate,
161
+ quotas: []
162
+ },
163
+ leverage: calcPositionLeverage(totalValue, totalDebt),
164
+ mintPeriodInterest: market.toUnderlyingAmount(interest),
165
+ mintDuration,
166
+ estLiveAt: Number(sdk.timestamp) + mintDuration,
167
+ bridge: bridgeAdapter.bridge
168
+ },
169
+ maxDebt: borrowableBase > debtBase ? (borrowableBase - debtBase) * underlyingScale / underlyingPrice : 0n
36
170
  };
37
171
  }
172
+ function ceilDiv(a, b) {
173
+ return (a + b - 1n) / b;
174
+ }
38
175
  //#endregion
39
176
  export { projectAavePosition };
@@ -5,6 +5,7 @@ import { parseRWAFactoryOperationCalldata } from "./parse/parseRWAFactoryOperati
5
5
  import { parseOperationCalldata } from "./parse/parseOperationCalldata.js";
6
6
  import { isPoolOperation, isRWAOperation } from "./parse/types.js";
7
7
  import "./parse/index.js";
8
+ import { aaveBridgeBorrows } from "./preview/aaveBridgeBorrows.js";
8
9
  import { buildDelayedStrategyPositionOperationPreview } from "./preview/buildDelayedStrategyPositionOperationPreview.js";
9
10
  import { CreditAccountState } from "./preview/CreditAccountState.js";
10
11
  import { classifyCloseOrRepay, isCloseOrRepay } from "./preview/detectCloseOrRepay.js";
@@ -18,4 +19,4 @@ import { makeReplayState, replayInnerOperations } from "./preview/replayInnerOpe
18
19
  import { replayMulticall } from "./preview/replayMulticall.js";
19
20
  import { previewOperation } from "./preview/previewOperation.js";
20
21
  import "./preview/index.js";
21
- export { CreditAccountState, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, classifyInnerOperations, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, isCloseOrRepay, isPoolOperation, isRWAOperation, makeReplayState, midasGreenlistsAccount, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
22
+ export { CreditAccountState, aaveBridgeBorrows, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, classifyInnerOperations, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, isCloseOrRepay, isPoolOperation, isRWAOperation, makeReplayState, midasGreenlistsAccount, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
@@ -0,0 +1,23 @@
1
+ import { AaveHorizonBridgeAdapterContract } from "../../market/adapters/contracts/AaveHorizonBridgeAdapterContract.js";
2
+ //#region src/onchain/preview/preview/aaveBridgeBorrows.ts
3
+ /**
4
+ * The loans the multicall's Horizon bridge calls take as the account owner,
5
+ * at the amounts the calldata names.
6
+ */
7
+ function aaveBridgeBorrows(sdk, creditManager, multicall) {
8
+ const { priceOracle } = sdk.marketRegister.findByCreditManager(creditManager);
9
+ const borrows = [];
10
+ for (const op of multicall) {
11
+ if (op.operation !== "Execute") continue;
12
+ const adapter = sdk.getContract(op.adapter);
13
+ if (!(adapter instanceof AaveHorizonBridgeAdapterContract)) continue;
14
+ const borrow = adapter.parseBorrow(op.calldata);
15
+ if (borrow) borrows.push({
16
+ bridge: adapter.bridge,
17
+ amount: priceOracle.toTokenAmount(borrow.debtToken, borrow.amount)
18
+ });
19
+ }
20
+ return borrows;
21
+ }
22
+ //#endregion
23
+ export { aaveBridgeBorrows };
@@ -1,3 +1,4 @@
1
+ import { aaveBridgeBorrows } from "./aaveBridgeBorrows.js";
1
2
  import { buildDelayedStrategyPositionOperationPreview } from "./buildDelayedStrategyPositionOperationPreview.js";
2
3
  import { CreditAccountState } from "./CreditAccountState.js";
3
4
  import { classifyCloseOrRepay, isCloseOrRepay } from "./detectCloseOrRepay.js";
@@ -10,4 +11,4 @@ import { previewExitOrRepayStrategyPosition } from "./previewExitOrRepayStrategy
10
11
  import { makeReplayState, replayInnerOperations } from "./replayInnerOperations.js";
11
12
  import { replayMulticall } from "./replayMulticall.js";
12
13
  import { previewOperation } from "./previewOperation.js";
13
- export { CreditAccountState, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, isCloseOrRepay, makeReplayState, midasGreenlistsAccount, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
14
+ export { CreditAccountState, aaveBridgeBorrows, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, isCloseOrRepay, makeReplayState, midasGreenlistsAccount, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
@@ -3,6 +3,7 @@ import { DUST_THRESHOLD } from "../../constants/math.js";
3
3
  import { asEstimated } from "../../../model/previews.js";
4
4
  import { sdkOk } from "../../../model/result.js";
5
5
  import "../../../model/index.js";
6
+ import { aaveBridgeBorrows } from "./aaveBridgeBorrows.js";
6
7
  import { unwrapNativeCollateral } from "./unwrapNativeCollateral.js";
7
8
  //#region src/onchain/preview/preview/previewAdjustStrategyPosition.ts
8
9
  /**
@@ -23,6 +24,7 @@ function previewAdjustStrategyPosition(sdk, input, operation, replay) {
23
24
  const assetsChange = account.balances.difference(before.balances).toAssets(DUST_THRESHOLD);
24
25
  const priced = oracle.safeConvertAssets(account.balances.toAssets(), market.underlying);
25
26
  const snap = account.toSnapshot(priced.value);
27
+ const aaveBorrows = aaveBridgeBorrows(sdk, operation.creditManager, operation.multicall);
26
28
  return sdkOk({
27
29
  operation: "AdjustCreditAccount",
28
30
  ...asEstimated(sdk.positions.projection(snap, { availableLiquidityChange: before.totalDebt - account.totalDebt })),
@@ -37,6 +39,7 @@ function previewAdjustStrategyPosition(sdk, input, operation, replay) {
37
39
  ...oracle.toAmount(market.underlying, q.balance)
38
40
  })),
39
41
  assetsChange: assetsChange.map((a) => oracle.toTokenAmount(a.token, a.balance)),
42
+ ...aaveBorrows.length > 0 ? { aaveBorrows } : {},
40
43
  warning: priced.error
41
44
  });
42
45
  }
@@ -3,6 +3,7 @@ import "../../constants/math.js";
3
3
  import { asEstimated } from "../../../model/previews.js";
4
4
  import { sdkOk } from "../../../model/result.js";
5
5
  import "../../../model/index.js";
6
+ import { aaveBridgeBorrows } from "./aaveBridgeBorrows.js";
6
7
  import { classifyCloseOrRepay } from "./detectCloseOrRepay.js";
7
8
  import { unwrapNativeCollateral } from "./unwrapNativeCollateral.js";
8
9
  //#region src/onchain/preview/preview/previewExitOrRepayStrategyPosition.ts
@@ -55,6 +56,7 @@ function previewRepayCreditAccount(sdk, input, operation, permanent, replay) {
55
56
  const collateralAdded = unwrapped.data;
56
57
  const priced = market.priceOracle.safeConvertAssets(account.balances.toAssets(), market.underlying);
57
58
  const suite = sdk.marketRegister.findCreditManager(operation.creditManager);
59
+ const aaveBorrows = aaveBridgeBorrows(sdk, operation.creditManager, operation.multicall);
58
60
  return sdkOk({
59
61
  operation: "RepayCreditAccount",
60
62
  permanent,
@@ -65,6 +67,7 @@ function previewRepayCreditAccount(sdk, input, operation, permanent, replay) {
65
67
  collateralAdded: collateralAdded.map((a) => market.priceOracle.toTokenAmount(a.token, a.balance)),
66
68
  debtRepaid: market.toUnderlyingAmount(before.totalDebt - account.totalDebt),
67
69
  collateralWithdrawn: after.collateralWithdrawn.toAssets().map((a) => market.priceOracle.toTokenAmount(a.token, a.balance)),
70
+ ...aaveBorrows.length > 0 ? { aaveBorrows } : {},
68
71
  warning: priced.error
69
72
  });
70
73
  }
@@ -0,0 +1,53 @@
1
+ import { iAaveHorizonBridgeAbi } from "../../market/adapters/abi/aave/iAaveHorizonBridge.js";
2
+ import { iAaveV3PoolAbi } from "../../market/adapters/abi/aave/iAaveV3Pool.js";
3
+ import { iVariableDebtTokenAbi } from "../../market/adapters/abi/aave/iVariableDebtToken.js";
4
+ import "../../market/adapters/abi/aave/index.js";
5
+ import { insufficientBorrowAllowance } from "../../../model/errors/operation-errors.js";
6
+ import { unexpectedFailure } from "../../../model/errors/prepare-errors.js";
7
+ import "../../../model/index.js";
8
+ import { toTokenAmount } from "../helpers/token.js";
9
+ import "../helpers/index.js";
10
+ //#region src/onchain/validation/bundles/checkAaveDelegation.ts
11
+ /**
12
+ * `owner` has delegated the bridge at least the borrowed amount on the
13
+ * variable debt token of the borrowed token, in the pool the bridge borrows
14
+ * from.
15
+ */
16
+ async function checkAaveDelegation(input) {
17
+ const { sdk, owner, borrow, blockNumber } = input;
18
+ const { bridge, amount } = borrow;
19
+ const token = amount.token.address;
20
+ try {
21
+ const pool = await sdk.client.readContract({
22
+ address: bridge,
23
+ abi: iAaveHorizonBridgeAbi,
24
+ functionName: "pool",
25
+ blockNumber
26
+ });
27
+ const { variableDebtTokenAddress } = await sdk.client.readContract({
28
+ address: pool,
29
+ abi: iAaveV3PoolAbi,
30
+ functionName: "getReserveData",
31
+ args: [token],
32
+ blockNumber
33
+ });
34
+ const allowed = await sdk.client.readContract({
35
+ address: variableDebtTokenAddress,
36
+ abi: iVariableDebtTokenAbi,
37
+ functionName: "borrowAllowance",
38
+ args: [owner, bridge],
39
+ blockNumber
40
+ });
41
+ return allowed >= amount.value ? [] : [insufficientBorrowAllowance({
42
+ owner,
43
+ spender: bridge,
44
+ debtToken: variableDebtTokenAddress,
45
+ required: amount,
46
+ allowed: toTokenAmount(sdk, token, allowed)
47
+ })];
48
+ } catch (cause) {
49
+ return [unexpectedFailure(cause, `read the ${amount.token.symbol} borrow delegation`)];
50
+ }
51
+ }
52
+ //#endregion
53
+ export { checkAaveDelegation };
@@ -1,5 +1,6 @@
1
1
  import { toToken } from "../helpers/token.js";
2
2
  import "../helpers/index.js";
3
+ import { checkAaveDelegation } from "./checkAaveDelegation.js";
3
4
  import { checkDebtLimits } from "../checks/checkDebtLimits.js";
4
5
  import "../checks/index.js";
5
6
  import { checkAccountQuotas } from "./checkAccountQuotas.js";
@@ -49,21 +50,43 @@ async function checkCreditOperation(args) {
49
50
  safeHealthFactor: preview.estSafeHealthFactor
50
51
  }, thresholds)
51
52
  ];
52
- const [funding, rwa] = await Promise.all([checkCollateralFunding({
53
- sdk,
54
- preview,
55
- sender,
56
- blockNumber
57
- }), isOpening ? checkRWAOpening({
58
- sdk,
59
- preview,
60
- sender
61
- }) : []]);
53
+ const [funding, rwa, ...delegations] = await Promise.all([
54
+ checkCollateralFunding({
55
+ sdk,
56
+ preview,
57
+ sender,
58
+ blockNumber
59
+ }),
60
+ isOpening ? checkRWAOpening({
61
+ sdk,
62
+ preview,
63
+ sender
64
+ }) : [],
65
+ ...aaveBorrows(preview).map((borrow) => checkAaveDelegation({
66
+ sdk,
67
+ owner: sender,
68
+ borrow,
69
+ blockNumber
70
+ }))
71
+ ]);
62
72
  return [
63
73
  ...protocol,
64
74
  ...funding,
65
- ...rwa
75
+ ...rwa,
76
+ ...delegations.flat()
66
77
  ];
67
78
  }
79
+ /**
80
+ * What the Horizon bridge borrows as the owner: the whole debt when an Aave
81
+ * opening moves, or the loans an adjustment takes itself.
82
+ */
83
+ function aaveBorrows(preview) {
84
+ if (isAaveOpening(preview)) return [{
85
+ bridge: preview.aave.bridge,
86
+ amount: preview.aave.totalDebt
87
+ }];
88
+ return preview.operation === "AdjustCreditAccount" ? preview.aaveBorrows ?? [] : [];
89
+ }
90
+ const isAaveOpening = (preview) => "aave" in preview;
68
91
  //#endregion
69
92
  export { checkCreditOperation };
@@ -1,3 +1,4 @@
1
+ import { checkAaveDelegation } from "./checkAaveDelegation.js";
1
2
  import { checkAccountQuotas } from "./checkAccountQuotas.js";
2
3
  import { checkWalletAllowance } from "./checkWalletAllowance.js";
3
4
  import { checkWalletBalance } from "./checkWalletBalance.js";
@@ -17,4 +18,4 @@ import { checkLiquidationFunding } from "./checkLiquidationFunding.js";
17
18
  import { checkWallet } from "./checkWallet.js";
18
19
  import { checkPoolFunding } from "./checkPoolFunding.js";
19
20
  import { checkPoolOperation } from "./checkPoolOperation.js";
20
- export { checkAccountQuotas, checkCollateralFunding, checkCreditOperation, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLiquidationEligibility, checkLiquidationFunding, checkMarket, checkMidasAccountGreenlist, checkObtained, checkPoolFunding, checkPoolOperation, checkQuotaUpdates, checkRWAOpenRequirements, checkRWAOpening, checkWallet, checkWalletAllowance, checkWalletBalance };
21
+ export { checkAaveDelegation, checkAccountQuotas, checkCollateralFunding, checkCreditOperation, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLiquidationEligibility, checkLiquidationFunding, checkMarket, checkMidasAccountGreenlist, checkObtained, checkPoolFunding, checkPoolOperation, checkQuotaUpdates, checkRWAOpenRequirements, checkRWAOpening, checkWallet, checkWalletAllowance, checkWalletBalance };
@@ -1,3 +1,4 @@
1
+ import { checkAaveDelegation } from "./bundles/checkAaveDelegation.js";
1
2
  import { checkCollateralFunding } from "./bundles/checkCollateralFunding.js";
2
3
  import { checkMarket } from "./bundles/checkMarket.js";
3
4
  import { checkCreditOperation } from "./bundles/checkCreditOperation.js";
@@ -49,10 +50,21 @@ async function checkOperation(input, options = {}) {
49
50
  blockNumber,
50
51
  ...thresholds
51
52
  });
52
- case "RepayCreditAccount": return [...checkMarket(sdk.marketRegister.findCreditManager(preview.creditManager)), ...await checkCollateralFunding({
53
- ...wallet,
54
- preview
55
- })];
53
+ case "RepayCreditAccount": {
54
+ const [funding, ...delegations] = await Promise.all([checkCollateralFunding({
55
+ ...wallet,
56
+ preview
57
+ }), ...(preview.aaveBorrows ?? []).map((borrow) => checkAaveDelegation({
58
+ ...wallet,
59
+ owner: sender,
60
+ borrow
61
+ }))]);
62
+ return [
63
+ ...checkMarket(sdk.marketRegister.findCreditManager(preview.creditManager)),
64
+ ...funding,
65
+ ...delegations.flat()
66
+ ];
67
+ }
56
68
  case "CloseCreditAccount": return checkMarket(sdk.marketRegister.findCreditManager(preview.creditManager));
57
69
  }
58
70
  }
@@ -2,6 +2,7 @@ import { amountOf } from "./helpers/amount.js";
2
2
  import { MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM } from "./helpers/health-factor-limits.js";
3
3
  import { toToken, toTokenAmount } from "./helpers/token.js";
4
4
  import "./helpers/index.js";
5
+ import { checkAaveDelegation } from "./bundles/checkAaveDelegation.js";
5
6
  import { checkBorrowLimit } from "./checks/checkBorrowLimit.js";
6
7
  import { checkCollateralised } from "./checks/checkCollateralised.js";
7
8
  import { checkCreditAccountFrozen } from "./checks/checkCreditAccountFrozen.js";
@@ -47,4 +48,4 @@ import { checkLiquidation } from "./checkLiquidation.js";
47
48
  import { checkOperation } from "./checkOperation.js";
48
49
  import { checkSimulation } from "./checkSimulation.js";
49
50
  import { raise } from "./raise.js";
50
- export { MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM, amountOf, checkAccountQuotas, checkBorrowLimit, checkCollateralFunding, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkCreditOperation, checkDebtLimits, checkEmergencyLiquidator, checkForbiddenToken, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLeverage, checkLiquidation, checkLiquidationEligibility, checkLiquidationFunding, checkLiquidatorEligible, checkMarket, checkMarketExpired, checkMaxQuota, checkMidasAccountGreenlist, checkObtained, checkOperation, checkPartiallyLiquidatable, checkPoolFunding, checkPoolLiquidity, checkPoolOperation, checkPoolPaused, checkPoolSunset, checkQuotaActive, checkQuotaChange, checkQuotaCount, checkQuotaLimit, checkQuotaUpdates, checkRWAOpenRequirements, checkRWAOpening, checkReservePriceLimited, checkSimulation, checkWallet, checkWalletAllowance, checkWalletBalance, raise, toToken, toTokenAmount };
51
+ export { MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM, amountOf, checkAaveDelegation, checkAccountQuotas, checkBorrowLimit, checkCollateralFunding, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkCreditOperation, checkDebtLimits, checkEmergencyLiquidator, checkForbiddenToken, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLeverage, checkLiquidation, checkLiquidationEligibility, checkLiquidationFunding, checkLiquidatorEligible, checkMarket, checkMarketExpired, checkMaxQuota, checkMidasAccountGreenlist, checkObtained, checkOperation, checkPartiallyLiquidatable, checkPoolFunding, checkPoolLiquidity, checkPoolOperation, checkPoolPaused, checkPoolSunset, checkQuotaActive, checkQuotaChange, checkQuotaCount, checkQuotaLimit, checkQuotaUpdates, checkRWAOpenRequirements, checkRWAOpening, checkReservePriceLimited, checkSimulation, checkWallet, checkWalletAllowance, checkWalletBalance, raise, toToken, toTokenAmount };
@@ -2,7 +2,8 @@ import { PERCENTAGE_FACTOR } from "../../onchain/constants/math.js";
2
2
  import { hexEq } from "../../onchain/utils/hex.js";
3
3
  import { MultichainConstruct } from "../../onchain/base/MultichainConstruct.js";
4
4
  import "../../onchain/market/math.js";
5
- import { creditAccountNotEmpty, creditAccountNotFound, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedTokenPair } from "../../model/errors/prepare-errors.js";
5
+ import { debtOutOfRange } from "../../model/errors/operation-errors.js";
6
+ import { creditAccountNotEmpty, creditAccountNotFound, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedCollateralToken, unsupportedTokenPair } from "../../model/errors/prepare-errors.js";
6
7
  import { sdkErr, sdkOk } from "../../model/result.js";
7
8
  import "../../model/index.js";
8
9
  import { toToken } from "../../onchain/validation/helpers/token.js";
@@ -265,7 +266,8 @@ var PrepareApi = class extends MultichainConstruct {
265
266
  if (!opened.ok) return opened;
266
267
  const { state } = opened.data;
267
268
  try {
268
- const aave = projectAavePosition(this.sdk.chain(strategy.chainId), {
269
+ const sdk = this.sdk.chain(strategy.chainId);
270
+ const projected = await projectAavePosition(sdk, {
269
271
  creditManager: state.creditManager,
270
272
  assets: state.averageAssets.map((a) => ({
271
273
  token: a.token.address,
@@ -274,7 +276,22 @@ var PrepareApi = class extends MultichainConstruct {
274
276
  quotas: state.averageQuota,
275
277
  totalDebt: state.totalDebt.value,
276
278
  totalValue: state.totalValue.value
277
- });
279
+ }, params.wallet);
280
+ const suite = sdk.marketRegister.findCreditManager(strategy.creditManager);
281
+ if (!projected) {
282
+ const target = params.targetToken ?? suite.strategy?.targetCollateral;
283
+ return refused(target ? unsupportedCollateralToken(toToken(sdk, target)) : noStrategyTargetCollateral(strategy.creditManager), state);
284
+ }
285
+ const { aave, maxDebt } = projected;
286
+ if (aave.totalDebt.value > maxDebt) {
287
+ const market = sdk.marketRegister.findByCreditManager(strategy.creditManager);
288
+ const { creditFacade } = suite;
289
+ return refused(debtOutOfRange({
290
+ requested: aave.totalDebt,
291
+ minDebt: market.toUnderlyingAmount(creditFacade.minDebt),
292
+ maxDebt: market.toUnderlyingAmount(maxDebt)
293
+ }), state);
294
+ }
278
295
  return sdkOk({
279
296
  ...opened.data,
280
297
  state: {
@@ -379,7 +396,8 @@ var PrepareApi = class extends MultichainConstruct {
379
396
  async moveToAave(position, params) {
380
397
  return this.#startIntent(position, {}, {
381
398
  type: "MOVE_TO_AAVE",
382
- token: params.token
399
+ token: params.token,
400
+ claimable: params.claimable && toClaimableWithdrawal(params.claimable)
383
401
  });
384
402
  }
385
403
  /**
@@ -2,6 +2,7 @@ import { sdkErr, sdkOk } from "../../model/result.js";
2
2
  import "../../model/index.js";
3
3
  import { checkOperation } from "../../onchain/validation/checkOperation.js";
4
4
  import { checkSimulation } from "../../onchain/validation/checkSimulation.js";
5
+ import { parseOperationCalldata } from "../../onchain/preview/parse/parseOperationCalldata.js";
5
6
  import { previewOperation } from "../../onchain/preview/preview/previewOperation.js";
6
7
  import "../../onchain/index.js";
7
8
  import { projectAavePosition } from "../../onchain/positions/projectAavePosition.js";
@@ -36,7 +37,10 @@ var PreviewNamespace = class {
36
37
  message: `operation "${preview.operation}" is not an Aave position opening`,
37
38
  operation: preview.operation
38
39
  });
39
- const aave = projectAavePosition(this.#onchain.chain(input.chainId), {
40
+ const sdk = this.#onchain.chain(input.chainId);
41
+ const parsed = parseOperationCalldata(sdk, input);
42
+ const owner = parsed.ok && parsed.data.operation === "OpenCreditAccount" ? parsed.data.onBehalfOf : input.sender;
43
+ const projected = await projectAavePosition(sdk, {
40
44
  creditManager: preview.creditManager,
41
45
  assets: preview.estAssets.map((a) => ({
42
46
  token: a.token.address,
@@ -48,10 +52,15 @@ var PreviewNamespace = class {
48
52
  })),
49
53
  totalDebt: preview.totalDebt.value,
50
54
  totalValue: preview.estTotalValue.value
55
+ }, owner);
56
+ if (!projected) return sdkErr({
57
+ code: "unsupportedOperation",
58
+ message: `credit manager ${preview.creditManager} cannot move this opening to Aave`,
59
+ operation: preview.operation
51
60
  });
52
61
  return sdkOk({
53
62
  ...preview,
54
- aave
63
+ aave: projected.aave
55
64
  });
56
65
  }
57
66
  /**
@@ -1,10 +1,20 @@
1
1
  import { Timestamp, TokenAmount } from "./primitives.js";
2
2
  import { AccountProjection } from "./previews.js";
3
+ import { Address } from "viem";
3
4
  //#region src/model/aave.d.ts
5
+ /**
6
+ * A loan the Horizon bridge takes on Aave as the credit account owner. Aave
7
+ * lends it only up to what the owner delegated to the bridge on the variable
8
+ * debt token of the borrowed token (`approveDelegation`).
9
+ **/
10
+ export interface AaveBridgeBorrow {
11
+ bridge: Address;
12
+ amount: TokenAmount;
13
+ }
4
14
  /**
5
15
  * Where an opening lands once it has moved to Aave Horizon.
6
16
  *
7
- * An RWA collateral is minted asynchronously, so the leverage is built in a
17
+ * An RWA collateral may be minted asynchronously, so the leverage is built in a
8
18
  * Gearbox credit account first; once the mint settles, the minted collateral is
9
19
  * supplied to Aave, the Gearbox debt is refinanced there with the interest it
10
20
  * accrued in the meantime, and the credit account closes. This is that second
@@ -21,12 +31,19 @@ export interface AavePositionProjection extends Pick<AccountProjection, "totalVa
21
31
  **/
22
32
  mintPeriodInterest: TokenAmount;
23
33
  /**
24
- * How long the mint takes to settle, in seconds.
34
+ * How long the mint takes to settle, in seconds: the `withdrawalLength` of
35
+ * the RWA's delayed operation, `0` where the opening mints it outright.
25
36
  **/
26
37
  mintDuration: number;
27
38
  /**
28
- * Estimated unix seconds at which the position is live on Aave.
39
+ * Estimated unix seconds at which the position is live on Aave. The
40
+ * finalizer bot moves it a block after the mint settles at the earliest.
29
41
  **/
30
42
  estLiveAt: Timestamp;
43
+ /**
44
+ * Horizon bridge that borrows `totalDebt` as the owner when the position
45
+ * moves, see {@link AaveBridgeBorrow}.
46
+ **/
47
+ bridge: Address;
31
48
  }
32
49
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { IGearboxError } from "./base.js";
2
2
  import { CreditAccountFrozenError, LiquidatorNotEligibleError, NotEmergencyLiquidatorError, PartialLiquidationImpossibleError, creditAccountFrozen, liquidatorNotEligible, notEmergencyLiquidator, partialLiquidationImpossible } from "./liquidation-errors.js";
3
- import { AccountNotMidasGreenlistedError, BorrowLimitCause, CollateralLimits, CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientAllowanceError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageLimits, LeverageOutOfRangeError, MarketExpiredError, OperationLimitOptions, PoolPausedError, PoolSunsetError, QuotaAboveMaxError, QuotaCountExceededError, QuotaInactiveError, QuotaInputLimits, QuotaLimitReachedError, QuotaUnchangedError, RWAOpenRequirementsError, ReservePriceLimitedError, accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet } from "./operation-errors.js";
3
+ import { AccountNotMidasGreenlistedError, BorrowLimitCause, CollateralLimits, CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientAllowanceError, InsufficientBalanceError, InsufficientBorrowAllowanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageLimits, LeverageOutOfRangeError, MarketExpiredError, OperationLimitOptions, PoolPausedError, PoolSunsetError, QuotaAboveMaxError, QuotaCountExceededError, QuotaInactiveError, QuotaInputLimits, QuotaLimitReachedError, QuotaUnchangedError, RWAOpenRequirementsError, ReservePriceLimitedError, accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientBorrowAllowance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet } from "./operation-errors.js";
4
4
  import { UnpriceableTokenError, unpriceableTokenError } from "./oracle-errors.js";
5
5
  import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress } from "./prepare-errors.js";
6
6
  import { InvalidDelayedIntentError, MalformedTransactionError, PoolOperationPreviewError, UnsupportedOperationError, UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedZapperFunctionError, malformedTransaction } from "./preview-errors.js";
7
- export { AccountNotMidasGreenlistedError, BorrowLimitCause, CollateralLimits, CreditAccountFrozenError, CreditAccountNotEmptyError, CreditAccountNotFoundError, CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, IGearboxError, InsufficientAllowanceError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, InvalidDelayedIntentError, LeverageLimits, LeverageOutOfRangeError, LiquidatorNotEligibleError, MalformedTransactionError, MarketExpiredError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, NotEmergencyLiquidatorError, OperationLimitOptions, PartialLiquidationImpossibleError, PoolOperationPreviewError, PoolPausedError, PoolSunsetError, QuotaAboveMaxError, QuotaCountExceededError, QuotaInactiveError, QuotaInputLimits, QuotaLimitReachedError, QuotaUnchangedError, RWAOpenRequirementsError, ReservePriceLimitedError, UnexpectedFailureError, UnpriceableTokenError, UnsupportedCollateralTokenError, UnsupportedOperationError, UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedTokenPairError, UnsupportedZapperFunctionError, WithdrawalInProgressError, accountNotMidasGreenlisted, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, liquidatorNotEligible, malformedTransaction, marketExpired, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, partialLiquidationImpossible, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress };
7
+ export { AccountNotMidasGreenlistedError, BorrowLimitCause, CollateralLimits, CreditAccountFrozenError, CreditAccountNotEmptyError, CreditAccountNotFoundError, CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, IGearboxError, InsufficientAllowanceError, InsufficientBalanceError, InsufficientBorrowAllowanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, InvalidDelayedIntentError, LeverageLimits, LeverageOutOfRangeError, LiquidatorNotEligibleError, MalformedTransactionError, MarketExpiredError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, NotEmergencyLiquidatorError, OperationLimitOptions, PartialLiquidationImpossibleError, PoolOperationPreviewError, PoolPausedError, PoolSunsetError, QuotaAboveMaxError, QuotaCountExceededError, QuotaInactiveError, QuotaInputLimits, QuotaLimitReachedError, QuotaUnchangedError, RWAOpenRequirementsError, ReservePriceLimitedError, UnexpectedFailureError, UnpriceableTokenError, UnsupportedCollateralTokenError, UnsupportedOperationError, UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedTokenPairError, UnsupportedZapperFunctionError, WithdrawalInProgressError, accountNotMidasGreenlisted, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientBorrowAllowance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, liquidatorNotEligible, malformedTransaction, marketExpired, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, partialLiquidationImpossible, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress };