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

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 (165) hide show
  1. package/dist/cjs/abi/rwa/iSecuritizeRWAFactory.js +15 -0
  2. package/dist/cjs/model/errors/index.js +1 -0
  3. package/dist/cjs/model/errors/operation-errors.js +9 -0
  4. package/dist/cjs/model/index.js +1 -0
  5. package/dist/cjs/onchain/accounts/bots/AccountBotsService.js +29 -0
  6. package/dist/cjs/onchain/accounts/bots/PeripheryCompressorV310Contract.js +2 -1
  7. package/dist/cjs/onchain/accounts/index.js +1 -1
  8. package/dist/cjs/onchain/accounts/intents/index.js +33 -1
  9. package/dist/cjs/onchain/accounts/intents/operations.js +13 -13
  10. package/dist/cjs/onchain/accounts/intents/plan.js +45 -23
  11. package/dist/cjs/onchain/accounts/intents/readAaveHoldings.js +56 -0
  12. package/dist/cjs/onchain/accounts/intents/realize.js +61 -23
  13. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -1
  14. package/dist/cjs/onchain/accounts/intents/utils/ledger.js +6 -6
  15. package/dist/cjs/onchain/chain/chains.js +1 -0
  16. package/dist/cjs/onchain/index.js +13 -1
  17. package/dist/cjs/onchain/market/ZapperRegister.js +1 -1
  18. package/dist/cjs/onchain/market/adapters/abi/aave/iAaveOracle.js +20 -0
  19. package/dist/cjs/onchain/market/adapters/abi/aave/iAaveV3Pool.js +166 -0
  20. package/dist/cjs/onchain/market/adapters/abi/aave/iPoolAddressesProvider.js +11 -0
  21. package/dist/cjs/onchain/market/adapters/abi/aave/iVariableDebtToken.js +17 -0
  22. package/dist/cjs/onchain/market/adapters/abi/aave/index.js +6 -0
  23. package/dist/cjs/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.js +27 -0
  24. package/dist/cjs/onchain/market/adapters/abi/index.js +8 -0
  25. package/dist/cjs/onchain/market/adapters/abi/securitize/iSecuritizeNAVProvider.js +15 -0
  26. package/dist/cjs/onchain/market/adapters/abi/securitize/index.js +2 -0
  27. package/dist/cjs/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.js +100 -12
  28. package/dist/cjs/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.js +19 -11
  29. package/dist/cjs/onchain/market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.js +42 -5
  30. package/dist/cjs/onchain/market/adapters/index.js +8 -0
  31. package/dist/cjs/onchain/market/index.js +8 -0
  32. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +9 -0
  33. package/dist/cjs/onchain/positions/MultichainPositionsService.js +15 -0
  34. package/dist/cjs/onchain/positions/PositionsService.js +31 -0
  35. package/dist/cjs/onchain/positions/aaveMoveCalls.js +45 -0
  36. package/dist/cjs/onchain/positions/projectAavePosition.js +164 -26
  37. package/dist/cjs/onchain/positions/readAavePosition.js +152 -0
  38. package/dist/cjs/onchain/preview/index.js +2 -0
  39. package/dist/cjs/onchain/preview/preview/aaveBridgeBorrows.js +24 -0
  40. package/dist/cjs/onchain/preview/preview/aaveMoveStart.js +27 -0
  41. package/dist/cjs/onchain/preview/preview/index.js +2 -0
  42. package/dist/cjs/onchain/preview/preview/previewAdjustStrategyPosition.js +3 -0
  43. package/dist/cjs/onchain/preview/preview/previewExitOrRepayStrategyPosition.js +5 -2
  44. package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +4 -1
  45. package/dist/cjs/onchain/preview/preview/previewOperation.js +31 -8
  46. package/dist/cjs/onchain/validation/bundles/checkAaveDelegation.js +54 -0
  47. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +36 -11
  48. package/dist/cjs/onchain/validation/bundles/index.js +2 -0
  49. package/dist/cjs/onchain/validation/checkOperation.js +16 -4
  50. package/dist/cjs/onchain/validation/index.js +2 -0
  51. package/dist/cjs/sdk/execute/ExecuteApi.js +1 -0
  52. package/dist/cjs/sdk/positions/PositionsNamespace.js +6 -0
  53. package/dist/cjs/sdk/prepare/PrepareApi.js +68 -9
  54. package/dist/cjs/sdk/preview/PreviewNamespace.js +11 -2
  55. package/dist/esm/abi/rwa/iSecuritizeRWAFactory.js +15 -0
  56. package/dist/esm/model/errors/index.js +2 -2
  57. package/dist/esm/model/errors/operation-errors.js +9 -1
  58. package/dist/esm/model/index.js +2 -2
  59. package/dist/esm/onchain/accounts/bots/AccountBotsService.js +29 -0
  60. package/dist/esm/onchain/accounts/bots/PeripheryCompressorV310Contract.js +1 -1
  61. package/dist/esm/onchain/accounts/index.js +1 -1
  62. package/dist/esm/onchain/accounts/intents/index.js +34 -2
  63. package/dist/esm/onchain/accounts/intents/operations.js +12 -12
  64. package/dist/esm/onchain/accounts/intents/plan.js +46 -24
  65. package/dist/esm/onchain/accounts/intents/readAaveHoldings.js +55 -0
  66. package/dist/esm/onchain/accounts/intents/realize.js +62 -24
  67. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -1
  68. package/dist/esm/onchain/accounts/intents/utils/ledger.js +6 -6
  69. package/dist/esm/onchain/chain/chains.js +1 -0
  70. package/dist/esm/onchain/index.js +8 -2
  71. package/dist/esm/onchain/market/ZapperRegister.js +1 -1
  72. package/dist/esm/onchain/market/adapters/abi/aave/iAaveOracle.js +19 -0
  73. package/dist/esm/onchain/market/adapters/abi/aave/iAaveV3Pool.js +166 -0
  74. package/dist/esm/onchain/market/adapters/abi/aave/iPoolAddressesProvider.js +10 -0
  75. package/dist/esm/onchain/market/adapters/abi/aave/iVariableDebtToken.js +16 -0
  76. package/dist/esm/onchain/market/adapters/abi/aave/index.js +4 -1
  77. package/dist/esm/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.js +27 -0
  78. package/dist/esm/onchain/market/adapters/abi/index.js +5 -1
  79. package/dist/esm/onchain/market/adapters/abi/securitize/iSecuritizeNAVProvider.js +14 -0
  80. package/dist/esm/onchain/market/adapters/abi/securitize/index.js +2 -1
  81. package/dist/esm/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.js +101 -13
  82. package/dist/esm/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.js +20 -12
  83. package/dist/esm/onchain/market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.js +43 -6
  84. package/dist/esm/onchain/market/adapters/index.js +5 -1
  85. package/dist/esm/onchain/market/index.js +5 -1
  86. package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +9 -0
  87. package/dist/esm/onchain/positions/MultichainPositionsService.js +15 -0
  88. package/dist/esm/onchain/positions/PositionsService.js +31 -0
  89. package/dist/esm/onchain/positions/aaveMoveCalls.js +44 -0
  90. package/dist/esm/onchain/positions/projectAavePosition.js +165 -27
  91. package/dist/esm/onchain/positions/readAavePosition.js +151 -0
  92. package/dist/esm/onchain/preview/index.js +2 -1
  93. package/dist/esm/onchain/preview/preview/aaveBridgeBorrows.js +23 -0
  94. package/dist/esm/onchain/preview/preview/aaveMoveStart.js +26 -0
  95. package/dist/esm/onchain/preview/preview/index.js +2 -1
  96. package/dist/esm/onchain/preview/preview/previewAdjustStrategyPosition.js +3 -0
  97. package/dist/esm/onchain/preview/preview/previewExitOrRepayStrategyPosition.js +5 -2
  98. package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +4 -1
  99. package/dist/esm/onchain/preview/preview/previewOperation.js +31 -8
  100. package/dist/esm/onchain/validation/bundles/checkAaveDelegation.js +53 -0
  101. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +36 -11
  102. package/dist/esm/onchain/validation/bundles/index.js +2 -1
  103. package/dist/esm/onchain/validation/checkOperation.js +16 -4
  104. package/dist/esm/onchain/validation/index.js +2 -1
  105. package/dist/esm/sdk/execute/ExecuteApi.js +1 -0
  106. package/dist/esm/sdk/positions/PositionsNamespace.js +6 -0
  107. package/dist/esm/sdk/prepare/PrepareApi.js +69 -10
  108. package/dist/esm/sdk/preview/PreviewNamespace.js +11 -2
  109. package/dist/types/abi/rwa/iSecuritizeRWAFactory.d.ts +14 -0
  110. package/dist/types/model/aave.d.ts +60 -3
  111. package/dist/types/model/errors/index.d.ts +2 -2
  112. package/dist/types/model/errors/operation-errors.d.ts +19 -0
  113. package/dist/types/model/index.d.ts +5 -5
  114. package/dist/types/model/opportunities.d.ts +1 -1
  115. package/dist/types/model/previews.d.ts +18 -2
  116. package/dist/types/onchain/accounts/bots/AccountBotsService.d.ts +11 -1
  117. package/dist/types/onchain/accounts/bots/index.d.ts +2 -2
  118. package/dist/types/onchain/accounts/bots/types.d.ts +7 -1
  119. package/dist/types/onchain/accounts/index.d.ts +3 -3
  120. package/dist/types/onchain/accounts/intents/index.d.ts +21 -3
  121. package/dist/types/onchain/accounts/intents/operations.d.ts +27 -23
  122. package/dist/types/onchain/accounts/intents/plan.d.ts +23 -19
  123. package/dist/types/onchain/accounts/intents/readAaveHoldings.d.ts +16 -0
  124. package/dist/types/onchain/accounts/intents/types.d.ts +37 -14
  125. package/dist/types/onchain/index.d.ts +10 -4
  126. package/dist/types/onchain/market/adapters/abi/aave/iAaveOracle.d.ts +22 -0
  127. package/dist/types/onchain/market/adapters/abi/aave/iAaveV3Pool.d.ts +139 -0
  128. package/dist/types/onchain/market/adapters/abi/aave/iPoolAddressesProvider.d.ts +11 -0
  129. package/dist/types/onchain/market/adapters/abi/aave/iVariableDebtToken.d.ts +17 -0
  130. package/dist/types/onchain/market/adapters/abi/aave/index.d.ts +4 -1
  131. package/dist/types/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.d.ts +21 -0
  132. package/dist/types/onchain/market/adapters/abi/index.d.ts +5 -1
  133. package/dist/types/onchain/market/adapters/abi/securitize/iSecuritizeNAVProvider.d.ts +13 -0
  134. package/dist/types/onchain/market/adapters/abi/securitize/index.d.ts +2 -1
  135. package/dist/types/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.d.ts +59 -10
  136. package/dist/types/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.d.ts +147 -4
  137. package/dist/types/onchain/market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.d.ts +19 -4
  138. package/dist/types/onchain/market/adapters/index.d.ts +5 -1
  139. package/dist/types/onchain/market/index.d.ts +5 -1
  140. package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +20 -0
  141. package/dist/types/onchain/market/rwa/types.d.ts +6 -0
  142. package/dist/types/onchain/positions/MultichainPositionsService.d.ts +7 -1
  143. package/dist/types/onchain/positions/PositionsService.d.ts +16 -2
  144. package/dist/types/onchain/positions/aaveMoveCalls.d.ts +30 -0
  145. package/dist/types/onchain/positions/index.d.ts +2 -2
  146. package/dist/types/onchain/positions/projectAavePosition.d.ts +34 -4
  147. package/dist/types/onchain/positions/readAavePosition.d.ts +22 -0
  148. package/dist/types/onchain/positions/types.d.ts +25 -0
  149. package/dist/types/onchain/preview/index.d.ts +2 -1
  150. package/dist/types/onchain/preview/preview/aaveBridgeBorrows.d.ts +15 -0
  151. package/dist/types/onchain/preview/preview/aaveMoveStart.d.ts +18 -0
  152. package/dist/types/onchain/preview/preview/index.d.ts +2 -1
  153. package/dist/types/onchain/validation/bundles/checkAaveDelegation.d.ts +21 -0
  154. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +2 -2
  155. package/dist/types/onchain/validation/bundles/index.d.ts +2 -1
  156. package/dist/types/onchain/validation/index.d.ts +2 -1
  157. package/dist/types/sdk/execute/types.d.ts +7 -5
  158. package/dist/types/sdk/index.d.ts +2 -2
  159. package/dist/types/sdk/positions/PositionsNamespace.d.ts +6 -1
  160. package/dist/types/sdk/positions/types.d.ts +9 -1
  161. package/dist/types/sdk/prepare/PrepareApi.d.ts +4 -4
  162. package/dist/types/sdk/prepare/index.d.ts +2 -2
  163. package/dist/types/sdk/prepare/types.d.ts +88 -28
  164. package/dist/types/sdk/preview/types.d.ts +4 -2
  165. package/package.json +1 -1
@@ -79,6 +79,21 @@ const iSecuritizeRWAFactoryAbi = [
79
79
  }],
80
80
  stateMutability: "view"
81
81
  },
82
+ {
83
+ type: "function",
84
+ name: "isAllowedBot",
85
+ inputs: [{
86
+ name: "bot",
87
+ type: "address",
88
+ internalType: "address"
89
+ }],
90
+ outputs: [{
91
+ name: "",
92
+ type: "bool",
93
+ internalType: "bool"
94
+ }],
95
+ stateMutability: "view"
96
+ },
82
97
  {
83
98
  type: "function",
84
99
  name: "isCreditAccount",
@@ -14,6 +14,7 @@ exports.debtOutOfRange = require_model_errors_operation_errors.debtOutOfRange;
14
14
  exports.forbiddenToken = require_model_errors_operation_errors.forbiddenToken;
15
15
  exports.insufficientAllowance = require_model_errors_operation_errors.insufficientAllowance;
16
16
  exports.insufficientBalance = require_model_errors_operation_errors.insufficientBalance;
17
+ exports.insufficientBorrowAllowance = require_model_errors_operation_errors.insufficientBorrowAllowance;
17
18
  exports.insufficientCollateral = require_model_errors_operation_errors.insufficientCollateral;
18
19
  exports.insufficientPoolLiquidity = require_model_errors_operation_errors.insufficientPoolLiquidity;
19
20
  exports.leverageOutOfRange = require_model_errors_operation_errors.leverageOutOfRange;
@@ -142,6 +142,14 @@ function insufficientAllowance(args) {
142
142
  ...args
143
143
  };
144
144
  }
145
+ /** {@inheritDoc InsufficientBorrowAllowanceError} */
146
+ function insufficientBorrowAllowance(args) {
147
+ return {
148
+ code: "insufficientBorrowAllowance",
149
+ message: `${args.required.value} of ${args.required.token.symbol} borrowing must be delegated to ${args.spender} on ${args.debtToken}, ${args.allowed.value} is.`,
150
+ ...args
151
+ };
152
+ }
145
153
  /** {@inheritDoc RWAOpenRequirementsError} */
146
154
  function rwaOpenRequirementsNotMet(args) {
147
155
  return {
@@ -165,6 +173,7 @@ exports.debtOutOfRange = debtOutOfRange;
165
173
  exports.forbiddenToken = forbiddenToken;
166
174
  exports.insufficientAllowance = insufficientAllowance;
167
175
  exports.insufficientBalance = insufficientBalance;
176
+ exports.insufficientBorrowAllowance = insufficientBorrowAllowance;
168
177
  exports.insufficientCollateral = insufficientCollateral;
169
178
  exports.insufficientPoolLiquidity = insufficientPoolLiquidity;
170
179
  exports.leverageOutOfRange = leverageOutOfRange;
@@ -105,6 +105,7 @@ exports.forbiddenToken = require_model_errors_operation_errors.forbiddenToken;
105
105
  exports.instantReceivedAssetSchema = require_model_liquidations_schema.instantReceivedAssetSchema;
106
106
  exports.insufficientAllowance = require_model_errors_operation_errors.insufficientAllowance;
107
107
  exports.insufficientBalance = require_model_errors_operation_errors.insufficientBalance;
108
+ exports.insufficientBorrowAllowance = require_model_errors_operation_errors.insufficientBorrowAllowance;
108
109
  exports.insufficientCollateral = require_model_errors_operation_errors.insufficientCollateral;
109
110
  exports.insufficientPoolLiquidity = require_model_errors_operation_errors.insufficientPoolLiquidity;
110
111
  exports.isFilterSet = require_model_filters.isFilterSet;
@@ -1,8 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_abi_310_generated = require("../../../abi/310/generated.js");
3
+ const require_abi_compressors_peripheryCompressor = require("../../../abi/compressors/peripheryCompressor.js");
4
+ const require_onchain_utils_AddressMap = require("../../utils/AddressMap.js");
3
5
  const require_onchain_constants_address_provider = require("../../constants/address-provider.js");
4
6
  const require_onchain_constants_versions = require("../../constants/versions.js");
5
7
  require("../../constants/index.js");
8
+ require("../../utils/index.js");
6
9
  const require_onchain_base_SDKConstruct = require("../../base/SDKConstruct.js");
7
10
  require("../../base/index.js");
8
11
  const require_onchain_accounts_bots_abi = require("./abi.js");
@@ -15,6 +18,32 @@ const require_onchain_accounts_bots_PeripheryCompressorV310Contract = require(".
15
18
  * and builds the transactions that connect or disconnect one.
16
19
  **/
17
20
  var AccountBotsService = class extends require_onchain_base_SDKConstruct.SDKConstruct {
21
+ #marketBots = new require_onchain_utils_AddressMap.AddressMap(void 0, "marketBots");
22
+ /**
23
+ * The bots a market configurator lists among its periphery contracts.
24
+ *
25
+ * Read once per configurator and kept for the service's lifetime: the list
26
+ * changes only when the curator adds or removes a bot. A failed read is not
27
+ * kept, so the next call tries again.
28
+ *
29
+ * @param marketConfigurator - Configurator to list the bots of.
30
+ **/
31
+ getMarketBots(marketConfigurator) {
32
+ let bots = this.#marketBots.get(marketConfigurator);
33
+ if (!bots) {
34
+ bots = this.client.readContract({
35
+ address: this.#compressor.address,
36
+ abi: require_abi_compressors_peripheryCompressor.peripheryCompressorAbi,
37
+ functionName: "getBots",
38
+ args: [marketConfigurator]
39
+ }).catch((e) => {
40
+ this.#marketBots.delete(marketConfigurator);
41
+ throw e;
42
+ });
43
+ this.#marketBots.upsert(marketConfigurator, bots);
44
+ }
45
+ return bots;
46
+ }
18
47
  /**
19
48
  * Reads the bots connected to each of the given credit accounts.
20
49
  *
@@ -1,8 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_abi_compressors_peripheryCompressor = require("../../../abi/compressors/peripheryCompressor.js");
2
3
  const require_onchain_base_BaseContract = require("../../base/BaseContract.js");
3
4
  require("../../base/index.js");
4
5
  //#region src/onchain/accounts/bots/PeripheryCompressorV310Contract.ts
5
- const abi = require("../../../abi/compressors/peripheryCompressor.js").peripheryCompressorAbi;
6
+ const abi = require_abi_compressors_peripheryCompressor.peripheryCompressorAbi;
6
7
  var PeripheryCompressorV310Contract = class extends require_onchain_base_BaseContract.BaseContract {
7
8
  constructor(sdk, address) {
8
9
  super(sdk, {
@@ -9,6 +9,7 @@ const require_onchain_accounts_CreditAccountsServiceV310 = require("./CreditAcco
9
9
  const require_onchain_accounts_intents_utils_pick_token = require("./intents/utils/pick-token.js");
10
10
  const require_onchain_accounts_intents_utils_credit_account_slice = require("./intents/utils/credit-account-slice.js");
11
11
  const require_onchain_accounts_quota_utils = require("./quota-utils.js");
12
+ const require_onchain_accounts_withdrawal_compressor_intent_codec = require("./withdrawal-compressor/intent-codec.js");
12
13
  const require_onchain_accounts_intents_index = require("./intents/index.js");
13
14
  const require_onchain_accounts_liquidations_constants = require("./liquidations/constants.js");
14
15
  const require_onchain_accounts_liquidations_partialLiquidation = require("./liquidations/partialLiquidation.js");
@@ -16,7 +17,6 @@ const require_onchain_accounts_liquidations_LiquidationsService = require("./liq
16
17
  const require_onchain_accounts_liquidations_MultichainLiquidationsService = require("./liquidations/MultichainLiquidationsService.js");
17
18
  require("./liquidations/index.js");
18
19
  require("./types.js");
19
- const require_onchain_accounts_withdrawal_compressor_intent_codec = require("./withdrawal-compressor/intent-codec.js");
20
20
  const require_onchain_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract = require("./withdrawal-compressor/AbstractWithdrawalCompressorContract.js");
21
21
  const require_onchain_accounts_withdrawal_compressor_addresses = require("./withdrawal-compressor/addresses.js");
22
22
  const require_onchain_accounts_withdrawal_compressor_RedemptionLoggerV310Contract = require("./withdrawal-compressor/RedemptionLoggerV310Contract.js");
@@ -19,6 +19,7 @@ const require_onchain_accounts_intents_maxBorrowAndWithdraw = require("./maxBorr
19
19
  const require_onchain_accounts_intents_maxWithdrawCollateral = require("./maxWithdrawCollateral.js");
20
20
  const require_onchain_accounts_intents_open_strategy = require("./open-strategy.js");
21
21
  const require_onchain_accounts_intents_plan = require("./plan.js");
22
+ const require_onchain_accounts_intents_readAaveHoldings = require("./readAaveHoldings.js");
22
23
  const require_onchain_accounts_intents_withdraw_limits = require("./withdraw-limits.js");
23
24
  const require_onchain_accounts_intents_realize = require("./realize.js");
24
25
  const require_onchain_accounts_intents_tail = require("./tail.js");
@@ -66,7 +67,6 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
66
67
  case "ADJUST_LEVERAGE": return require_onchain_accounts_intents_plan.planAdjustLeverage(intent, view);
67
68
  case "DEPOSIT": return require_onchain_accounts_intents_plan.planDeposit(intent, view);
68
69
  case "REPAY": return require_onchain_accounts_intents_plan.planRepay(intent, view);
69
- case "MOVE_TO_AAVE": return require_onchain_accounts_intents_plan.planMoveToAave(intent, view);
70
70
  case "WITHDRAW": return require_onchain_accounts_intents_plan.planWithdraw(intent, view);
71
71
  case "UPDATE_QUOTA": return require_onchain_accounts_intents_plan.planUpdateQuota(intent, view);
72
72
  default: throw new Error(`${intent.type} - not implemented`);
@@ -240,6 +240,7 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
240
240
  switch (intent.type) {
241
241
  case "ADJUST_LEVERAGE": return require_onchain_accounts_intents_plan.planAdjustLeverageDelayed(intent, view);
242
242
  case "WITHDRAW": return require_onchain_accounts_intents_plan.planWithdrawDelayed(intent, view);
243
+ case "CLOSE_AAVE_POSITION": return require_onchain_accounts_intents_plan.planCloseAavePosition(intent, view);
243
244
  default: throw new Error(`${intent.type} - cannot be delayed`);
244
245
  }
245
246
  }, limits);
@@ -274,6 +275,37 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
274
275
  }
275
276
  }
276
277
  /**
278
+ * Previews leaving `owner`'s Aave Horizon position in `token` in one
279
+ * transaction, see {@link CloseAavePositionIntent}.
280
+ *
281
+ * What the owner holds and owes on Aave is read here, at the block the SDK
282
+ * stands at; the rest is {@link startDelayedIntent}, tail included.
283
+ *
284
+ * @param props - Account slice, quota reserve and slippage, the RWA, the
285
+ * wallet the exit pays, and the owner the bridge resolves for the account:
286
+ * the investor of an RWA factory account, the borrower otherwise
287
+ * @returns The request transaction, the state the exit ends in and what it
288
+ * recorded for the tail, or `{ ok: false, error }`
289
+ */
290
+ async closeAavePositionIntent(props) {
291
+ const { token, to, owner, ...rest } = props;
292
+ let holdings;
293
+ try {
294
+ holdings = await require_onchain_accounts_intents_readAaveHoldings.readAaveHoldings(rest.sdk, rest.creditAccount.creditManager, owner, token);
295
+ } catch (e) {
296
+ return asRefused(e, rest.draft ?? {});
297
+ }
298
+ return this.startDelayedIntent({
299
+ ...rest,
300
+ intent: {
301
+ type: "CLOSE_AAVE_POSITION",
302
+ token,
303
+ to,
304
+ holdings
305
+ }
306
+ });
307
+ }
308
+ /**
277
309
  * Previews a delayable intent both ways at once: settled by the router now,
278
310
  * and started as a redemption that finishes days later.
279
311
  *
@@ -135,23 +135,23 @@ function buildClaimDelayedWithdrawalOperation(input) {
135
135
  })
136
136
  };
137
137
  }
138
- function buildAaveSupplyOperation(input) {
138
+ function buildAaveClosePositionOperation(input) {
139
139
  return {
140
- type: "aaveSupply",
141
- token: input.token,
140
+ type: "aaveClosePosition",
142
141
  aToken: input.aToken,
143
- amount: input.amount,
144
- calls: [input.adapter.supplyCall(input.token, input.amount)]
142
+ aTokenAmount: input.aTokenAmount,
143
+ debtToken: input.debtToken,
144
+ repayAmount: input.repayAmount,
145
+ calls: [input.adapter.closePositionCall(input.aToken, input.debtToken, input.repayAmount, input.aTokenAmount)]
145
146
  };
146
147
  }
147
- function buildAaveOpenPositionOperation(input) {
148
+ function buildAaveWithdrawOperation(input) {
148
149
  return {
149
- type: "aaveOpenPosition",
150
+ type: "aaveWithdraw",
151
+ token: input.token,
150
152
  aToken: input.aToken,
151
- aTokenAmount: input.aTokenAmount,
152
- debtToken: input.debtToken,
153
- borrowAmount: input.borrowAmount,
154
- calls: [input.adapter.openPositionCall(input.aToken, input.debtToken, input.aTokenAmount, input.borrowAmount)]
153
+ amount: input.amount,
154
+ calls: [input.adapter.withdrawDiffCall(input.token, 0n)]
155
155
  };
156
156
  }
157
157
  /**
@@ -169,8 +169,8 @@ function instantOutput(outputs, token) {
169
169
  }
170
170
  }
171
171
  //#endregion
172
- exports.buildAaveOpenPositionOperation = buildAaveOpenPositionOperation;
173
- exports.buildAaveSupplyOperation = buildAaveSupplyOperation;
172
+ exports.buildAaveClosePositionOperation = buildAaveClosePositionOperation;
173
+ exports.buildAaveWithdrawOperation = buildAaveWithdrawOperation;
174
174
  exports.buildAddCollateralOperation = buildAddCollateralOperation;
175
175
  exports.buildClaimDelayedWithdrawalOperation = buildClaimDelayedWithdrawalOperation;
176
176
  exports.buildCloseSwapOperation = buildCloseSwapOperation;
@@ -105,35 +105,50 @@ function planRepay(intent, view) {
105
105
  ];
106
106
  }
107
107
  /**
108
- * The position leaves for Aave Horizon: the RWA is supplied to the Aave pool,
109
- * its aTokens go to the owner with a loan against them, and that loan settles
110
- * the account's own.
108
+ * The owner's Aave position comes back and leaves: the account borrows what
109
+ * the owner owes on Aave, the bridge repays it and returns the aTokens, the
110
+ * pool turns them back into the RWA, and the RWA is requested for redemption
111
+ * with an exit recorded for the tail — all in one transaction.
111
112
  *
112
- * Aave lends the debt plus the {@link SETTLE_MARGIN} headroom, since the facade
113
- * is told to repay everything outstanding by the time the transaction lands;
114
- * what it does not take stays on the account.
113
+ * The repayment is the debt plus {@link CLOSE_AAVE_WINDOW} of interest at the
114
+ * current rate, see {@link CloseAavePositionIntent}.
115
115
  */
116
- function planMoveToAave(intent, view) {
117
- const amount = view.balanceOf(intent.token);
118
- if (require_onchain_accounts_intents_utils_common.eq(intent.token, view.underlying) || require_onchain_constants_math.isZeroBalance(amount)) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(view.sdk, intent.token)), `moveToAave: ${intent.token} is the underlying or not held by the account`);
119
- if (view.debt <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.debtOutOfRange({
120
- requested: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, view.underlying, view.debt),
121
- minDebt: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, view.underlying, view.debtLimits.minDebt),
122
- maxDebt: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, view.underlying, view.debtLimits.maxDebt)
123
- }), "moveToAave: the account owes nothing");
116
+ function planCloseAavePosition(intent, view) {
117
+ const { token, holdings } = intent;
118
+ const U = view.underlying;
119
+ if (require_onchain_accounts_intents_utils_common.eq(token, U) || require_onchain_constants_math.isZeroBalance(holdings.supplied)) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(view.sdk, token)), `closeAavePosition: the owner holds no aToken of ${token} on Aave`);
120
+ if (holdings.owed <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.debtOutOfRange({
121
+ requested: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, 0n),
122
+ minDebt: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, view.debtLimits.minDebt),
123
+ maxDebt: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, view.debtLimits.maxDebt)
124
+ }), "closeAavePosition: the owner owes nothing on Aave");
125
+ const repay = holdings.owed + ceilDiv(holdings.owed * holdings.borrowRate * CLOSE_AAVE_WINDOW, require_onchain_constants_math.RAY * BigInt(require_onchain_constants_math.SECONDS_PER_YEAR));
126
+ let borrowed = require_onchain_accounts_intents_utils_common.toTargetDecimals(repay, holdings.debtToken, U, view.sdk);
127
+ if (require_onchain_accounts_intents_utils_common.toTargetDecimals(borrowed, U, holdings.debtToken, view.sdk) < repay) borrowed += 1n;
128
+ require_onchain_accounts_intents_math.assertDebtLimits(view.sdk, view.debt + borrowed, view.debtLimits, U, view.limits);
124
129
  return [
130
+ borrow(borrowed),
131
+ ...require_onchain_accounts_intents_utils_common.eq(holdings.debtToken, U) ? [] : [convert(U, holdings.debtToken, borrowed)],
125
132
  {
126
- kind: "aaveSupply",
127
- token: intent.token,
128
- amount
133
+ kind: "aaveClosePosition",
134
+ token,
135
+ repay,
136
+ aTokenAmount: holdings.supplied
129
137
  },
130
138
  {
131
- kind: "aaveOpenPosition",
132
- token: intent.token,
133
- borrow: withMargin(view.debt)
139
+ kind: "aaveWithdraw",
140
+ token
134
141
  },
135
- clearQuotas(),
136
- repay(view.debt)
142
+ {
143
+ kind: "request",
144
+ token,
145
+ amount: view.balanceOf(token) + holdings.supplied,
146
+ reserve: 0n,
147
+ record: {
148
+ type: "CLOSE_ACCOUNT",
149
+ to: intent.to
150
+ }
151
+ }
137
152
  ];
138
153
  }
139
154
  /**
@@ -439,6 +454,13 @@ const clearQuotas = () => ({ kind: "clearQuotas" });
439
454
  */
440
455
  const SETTLE_MARGIN = 10n;
441
456
  const withMargin = (debt) => debt + debt * SETTLE_MARGIN / require_onchain_constants_math.PERCENTAGE_FACTOR;
457
+ /**
458
+ * Seconds of Aave interest a closing repays on top of the debt it read: the
459
+ * bridge keeps whatever Aave does not take, so this is paid for, unlike
460
+ * {@link SETTLE_MARGIN}, and an hour costs a fraction of a basis point.
461
+ */
462
+ const CLOSE_AAVE_WINDOW = 3600n;
463
+ const ceilDiv = (a, b) => (a + b - 1n) / b;
442
464
  /** The amount that asks for all of it, whatever "all" turns out to be. */
443
465
  const everything = (amount) => amount >= require_onchain_constants_math.MAX_UINT256;
444
466
  const min = (a, b) => a < b ? a : b;
@@ -483,12 +505,12 @@ exports.planAddCollateral = planAddCollateral;
483
505
  exports.planAdjustLeverage = planAdjustLeverage;
484
506
  exports.planAdjustLeverageDelayed = planAdjustLeverageDelayed;
485
507
  exports.planBorrowAndWithdraw = planBorrowAndWithdraw;
508
+ exports.planCloseAavePosition = planCloseAavePosition;
486
509
  exports.planDeposit = planDeposit;
487
510
  exports.planFinishClaimOnly = planFinishClaimOnly;
488
511
  exports.planFinishCloseAccount = planFinishCloseAccount;
489
512
  exports.planFinishDecreaseLeverage = planFinishDecreaseLeverage;
490
513
  exports.planFinishWithdraw = planFinishWithdraw;
491
- exports.planMoveToAave = planMoveToAave;
492
514
  exports.planRepay = planRepay;
493
515
  exports.planUpdateQuota = planUpdateQuota;
494
516
  exports.planWithdraw = planWithdraw;
@@ -0,0 +1,56 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_market_adapters_abi_aave_iAaveV3Pool = require("../../market/adapters/abi/aave/iAaveV3Pool.js");
3
+ require("../../market/adapters/abi/aave/index.js");
4
+ const require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract = require("../../market/adapters/contracts/AaveV3PoolAdapterContract.js");
5
+ const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
6
+ require("../../../model/index.js");
7
+ const require_onchain_validation_helpers_token = require("../../validation/helpers/token.js");
8
+ const require_onchain_validation_raise = require("../../validation/raise.js");
9
+ let viem = require("viem");
10
+ //#region src/onchain/accounts/intents/readAaveHoldings.ts
11
+ /**
12
+ * What `owner` holds and owes on the Aave pool the credit manager supplies
13
+ * `token` to: its aTokens of `token`, and its variable debt in the asset the
14
+ * Horizon bridge lends there — the underlying, or the asset an RWA underlying
15
+ * wraps.
16
+ *
17
+ * Refused with `unsupportedCollateralToken` when no Aave pool adapter of the
18
+ * credit manager lists `token`.
19
+ */
20
+ async function readAaveHoldings(sdk, creditManager, owner, token) {
21
+ const suite = sdk.marketRegister.findCreditManager(creditManager);
22
+ const adapter = suite.creditManager.adapters.values().find((a) => a instanceof require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract.AaveV3PoolAdapterContract && a.isAssetAllowed(token));
23
+ if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, token)), `readAaveHoldings: no Aave pool adapter lists ${token}`);
24
+ const underlying = suite.underlying;
25
+ const debtToken = sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset ?? underlying;
26
+ const [aToken, reserve] = await Promise.all([adapter.aToken(token), sdk.client.readContract({
27
+ address: adapter.pool,
28
+ abi: require_onchain_market_adapters_abi_aave_iAaveV3Pool.iAaveV3PoolAbi,
29
+ functionName: "getReserveData",
30
+ args: [debtToken]
31
+ })]);
32
+ const [supplied, owed] = await sdk.client.multicall({
33
+ contracts: [{
34
+ address: aToken,
35
+ abi: viem.erc20Abi,
36
+ functionName: "balanceOf",
37
+ args: [owner]
38
+ }, {
39
+ address: reserve.variableDebtTokenAddress,
40
+ abi: viem.erc20Abi,
41
+ functionName: "balanceOf",
42
+ args: [owner]
43
+ }],
44
+ allowFailure: false,
45
+ batchSize: 0
46
+ });
47
+ return {
48
+ aToken,
49
+ debtToken,
50
+ supplied,
51
+ owed,
52
+ borrowRate: reserve.currentVariableBorrowRate
53
+ };
54
+ }
55
+ //#endregion
56
+ exports.readAaveHoldings = readAaveHoldings;
@@ -3,6 +3,7 @@ const require_onchain_chain_chains = require("../../chain/chains.js");
3
3
  const require_onchain_constants_math = require("../../constants/math.js");
4
4
  const require_onchain_market_adapters_contracts_AaveHorizonBridgeAdapterContract = require("../../market/adapters/contracts/AaveHorizonBridgeAdapterContract.js");
5
5
  const require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract = require("../../market/adapters/contracts/AaveV3PoolAdapterContract.js");
6
+ const require_onchain_market_adapters_contracts_SecuritizeRedemptionGatewayAdapterContract = require("../../market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.js");
6
7
  const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
7
8
  const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
8
9
  require("../../../model/index.js");
@@ -15,6 +16,7 @@ const require_onchain_accounts_intents_utils_ledger = require("./utils/ledger.js
15
16
  const require_onchain_accounts_intents_utils_price_impact = require("./utils/price-impact.js");
16
17
  const require_onchain_accounts_intents_utils_quotas_for_update = require("./utils/quotas-for-update.js");
17
18
  const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
19
+ const require_onchain_accounts_withdrawal_compressor_intent_codec = require("../withdrawal-compressor/intent-codec.js");
18
20
  const require_onchain_accounts_intents_operations = require("./operations.js");
19
21
  const require_onchain_accounts_intents_resolveQuotaUpdate = require("./resolveQuotaUpdate.js");
20
22
  const require_onchain_accounts_intents_withdraw_limits = require("./withdraw-limits.js");
@@ -288,12 +290,19 @@ async function realize(steps, props) {
288
290
  if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.withdrawalInProgress(require_onchain_validation_helpers_token.toTokenAmount(sdk, asset.withdrawalPhantomToken, ledger.balanceOf(asset.withdrawalPhantomToken))), `request: ${asset.withdrawalPhantomToken} already holds a pending withdrawal`);
289
291
  assertHolds(step.token, step.amount + step.reserve, "request");
290
292
  if (step.record.type !== "CLOSE_ACCOUNT") directTransfer ??= require_onchain_chain_chains.getDirectTransferToken(step.token, sdk.networkType);
291
- const preview = await sdk.accounts.previewDelayedWithdrawal({
293
+ const preview = (creditAccount.tokens.find((t) => require_onchain_accounts_intents_utils_common.eq(t.token, step.token))?.balance ?? 0n) >= step.amount ? await sdk.accounts.previewDelayedWithdrawal({
292
294
  creditAccount: creditAccount.creditAccount,
293
295
  token: step.token,
294
296
  amount: step.amount,
295
297
  withdrawalPhantomToken: asset.withdrawalPhantomToken,
296
298
  intent: step.record
299
+ }) : await arrivingRedemption({
300
+ sdk,
301
+ suite,
302
+ asset,
303
+ amount: step.amount,
304
+ leftover: ledger.balanceOf(step.token) - step.amount,
305
+ record: step.record
297
306
  });
298
307
  push(require_onchain_accounts_intents_operations.buildStartDelayedWithdrawalOperation({
299
308
  preview,
@@ -330,8 +339,9 @@ async function realize(steps, props) {
330
339
  break;
331
340
  case "sweep": {
332
341
  withdrawsCollateral = true;
342
+ const swept = (token) => !step.token || require_onchain_accounts_intents_utils_common.eq(token, step.token) || rwaAsset !== void 0 && require_onchain_accounts_intents_utils_common.eq(step.token, underlying) && require_onchain_accounts_intents_utils_common.eq(token, rwaAsset);
333
343
  const wrapped = ledger.balanceOf(underlying);
334
- if (rwaAsset && wrapped > 0n) push(await require_onchain_accounts_intents_operations.buildUnwrapRwaCollateralOperation({
344
+ if (rwaAsset && wrapped > 0n && swept(underlying)) push(await require_onchain_accounts_intents_operations.buildUnwrapRwaCollateralOperation({
335
345
  tokenIn: underlying,
336
346
  all: true,
337
347
  amountIn: wrapped,
@@ -341,6 +351,7 @@ async function realize(steps, props) {
341
351
  sdk
342
352
  }));
343
353
  for (const { token, balance } of ledger.snapshot().assets) {
354
+ if (!swept(token)) continue;
344
355
  const withdrawal = require_onchain_accounts_intents_operations.buildWithdrawCollateralOperation({
345
356
  token,
346
357
  amount: balance,
@@ -356,33 +367,36 @@ async function realize(steps, props) {
356
367
  }
357
368
  break;
358
369
  }
359
- case "aaveSupply": {
360
- assertHolds(step.token, step.amount, "aaveSupply");
361
- const adapter = aavePoolAdapter(sdk, suite, step.token);
362
- push(require_onchain_accounts_intents_operations.buildAaveSupplyOperation({
363
- adapter,
364
- token: step.token,
365
- aToken: await adapter.aToken(step.token),
366
- amount: step.amount
367
- }));
368
- break;
369
- }
370
- case "aaveOpenPosition": {
370
+ case "aaveClosePosition": {
371
371
  const aToken = await aavePoolAdapter(sdk, suite, step.token).aToken(step.token);
372
- const aTokenAmount = ledger.balanceOf(aToken);
373
- assertHolds(aToken, aTokenAmount, "aaveOpenPosition");
374
- push(require_onchain_accounts_intents_operations.buildAaveOpenPositionOperation({
372
+ const debtToken = rwaAsset ?? underlying;
373
+ assertHolds(debtToken, step.repay, "aaveClosePosition");
374
+ push(require_onchain_accounts_intents_operations.buildAaveClosePositionOperation({
375
375
  adapter: aaveBridgeAdapter(sdk, suite, step.token, {
376
376
  aToken,
377
- debtToken: underlying
377
+ debtToken
378
378
  }),
379
379
  aToken,
380
- aTokenAmount,
381
- debtToken: underlying,
382
- borrowAmount: step.borrow
380
+ aTokenAmount: step.aTokenAmount,
381
+ debtToken,
382
+ repayAmount: step.repay
383
383
  }));
384
384
  break;
385
385
  }
386
+ case "aaveWithdraw": {
387
+ const adapter = aavePoolAdapter(sdk, suite, step.token);
388
+ const aToken = await adapter.aToken(step.token);
389
+ const amount = ledger.balanceOf(aToken);
390
+ assertHolds(aToken, amount, "aaveWithdraw");
391
+ push(require_onchain_accounts_intents_operations.buildAaveWithdrawOperation({
392
+ adapter,
393
+ token: step.token,
394
+ aToken,
395
+ amount
396
+ }));
397
+ raised = amount;
398
+ break;
399
+ }
386
400
  }
387
401
  const floor = ledger.snapshot();
388
402
  const { assets, debt } = floor;
@@ -505,10 +519,34 @@ async function delayedConfig(sdk, creditAccount, token) {
505
519
  if (assets.length > 1) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.multipleDelayedWithdrawals(require_onchain_validation_helpers_token.toToken(sdk, token), assets.length), `request: ${token} has ${assets.length} delayed withdrawal configs`);
506
520
  return assets[0];
507
521
  }
522
+ /**
523
+ * The request for a redemption of a balance an earlier call of the same
524
+ * multicall brings in. The withdrawal compressor caps what it quotes at the
525
+ * balance the account holds before the transaction, so the request is built
526
+ * here instead: a diff call that names no amount, its phantom valued the way
527
+ * the gateway values it. Only a Securitize redemption gateway redeems that
528
+ * way; any other redemption is refused with `noDelayedRoute`.
529
+ */
530
+ async function arrivingRedemption(input) {
531
+ const { sdk, suite, asset, amount } = input;
532
+ const adapter = suite.creditManager.adapters.values().find((a) => a instanceof require_onchain_market_adapters_contracts_SecuritizeRedemptionGatewayAdapterContract.SecuritizeRedemptionGatewayAdapterContract && require_onchain_accounts_intents_utils_common.eq(a.dsToken, asset.token) && require_onchain_accounts_intents_utils_common.eq(a.redemptionPhantomToken, asset.withdrawalPhantomToken));
533
+ if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noDelayedRoute(require_onchain_validation_helpers_token.toToken(sdk, asset.token)), `request: ${asset.token} arrives in this transaction, and only a Securitize gateway redeems it without a quote`);
534
+ return {
535
+ token: asset.token,
536
+ amountIn: amount,
537
+ outputs: [{
538
+ token: asset.withdrawalPhantomToken,
539
+ isDelayed: true,
540
+ amount: await adapter.redemptionValue(amount)
541
+ }],
542
+ requestCalls: [adapter.redeemDiffCall(input.leftover, require_onchain_accounts_withdrawal_compressor_intent_codec.encodeDelayedIntent(input.record))],
543
+ claimableAt: sdk.timestamp + asset.withdrawalLength
544
+ };
545
+ }
508
546
  /** The credit manager's Aave pool adapter that lists `token`. */
509
547
  function aavePoolAdapter(sdk, suite, token) {
510
548
  const adapter = suite.creditManager.adapters.values().find((a) => a instanceof require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract.AaveV3PoolAdapterContract && a.isAssetAllowed(token));
511
- if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, token)), `aaveSupply: no Aave pool adapter lists ${token}`);
549
+ if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, token)), `aave: no Aave pool adapter lists ${token}`);
512
550
  return adapter;
513
551
  }
514
552
  /**
@@ -517,7 +555,7 @@ function aavePoolAdapter(sdk, suite, token) {
517
555
  */
518
556
  function aaveBridgeAdapter(sdk, suite, token, pair) {
519
557
  const adapter = suite.creditManager.adapters.values().find((a) => a instanceof require_onchain_market_adapters_contracts_AaveHorizonBridgeAdapterContract.AaveHorizonBridgeAdapterContract && a.isATokenAllowed(pair.aToken) && a.isDebtTokenAllowed(pair.debtToken));
520
- if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, token)), `aaveOpenPosition: no Horizon bridge adapter takes ${pair.aToken} against ${pair.debtToken}`);
558
+ if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, token)), `aaveClosePosition: no Horizon bridge adapter takes ${pair.aToken} against ${pair.debtToken}`);
521
559
  return adapter;
522
560
  }
523
561
  const callsOf = (operations) => operations.flatMap((op) => op.calls);
@@ -326,7 +326,7 @@ function buildMockSdk(args) {
326
326
  chainId: 1,
327
327
  networkType: "Mainnet",
328
328
  currentBlock: 1n,
329
- timestamp: args.timestamp ?? 0,
329
+ timestamp: BigInt(args.timestamp ?? 0),
330
330
  withdrawalCompressor,
331
331
  tokensMeta: {
332
332
  get: (token) => ({
@@ -81,13 +81,13 @@ var OperationLedger = class {
81
81
  this.#add(op.withdrawalPhantomToken, -op.withdrawalTokenSpent);
82
82
  for (const out of op.outputs) this.#add(out.token, out.amount);
83
83
  break;
84
- case "aaveSupply":
85
- this.#add(op.token, -op.amount);
86
- this.#add(op.aToken, op.amount);
84
+ case "aaveClosePosition":
85
+ this.#add(op.debtToken, -op.repayAmount);
86
+ this.#add(op.aToken, op.aTokenAmount);
87
87
  break;
88
- case "aaveOpenPosition":
89
- this.#add(op.aToken, -op.aTokenAmount);
90
- this.#add(op.debtToken, op.borrowAmount);
88
+ case "aaveWithdraw":
89
+ this.#add(op.aToken, -op.amount);
90
+ this.#add(op.token, op.amount);
91
91
  }
92
92
  return this;
93
93
  }
@@ -128,6 +128,7 @@ const chains = {
128
128
  symbol: "USDC"
129
129
  },
130
130
  tokenPrettyNames: require_onchain_utils_AddressMap.AddressMap.fromRecord({
131
+ "0x225e61a55b6ef8cc2ae94e85d0a95f9e2cd96a88": "VBILL → RLUSD",
131
132
  "0xab7d50fc2486a1ac06516e2ece9dadc95ba8cd20": "wstETH redemption from cp0xLRT",
132
133
  "0x6252467c2fefb61cb55180282943139baeea36c5": "wstETH redemption from rstETH",
133
134
  "0xd412ca00d177eba2843348f9c50dd17bfce32c40": "wstETH redemption from pzETH",