@gearbox-protocol/sdk 16.0.0-next.18 → 16.0.0-next.19

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 (186) hide show
  1. package/dist/cjs/common-utils/index.js +3 -21
  2. package/dist/cjs/common-utils/test-utils/index.js +4 -3
  3. package/dist/cjs/common-utils/utils/index.js +3 -22
  4. package/dist/cjs/common-utils/utils/strategies/index.js +3 -0
  5. package/dist/cjs/common-utils/utils/strategies/strategy-info/cm-availability-condition.js +5 -5
  6. package/dist/cjs/common-utils/utils/strategies/strategy-info/credit-manager-issues.js +135 -0
  7. package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +12 -23
  8. package/dist/cjs/common-utils/utils/strategies/strategy-info/index.js +3 -0
  9. package/dist/cjs/onchain/accounts/index.js +2 -3
  10. package/dist/cjs/onchain/accounts/intents/guards.js +55 -50
  11. package/dist/cjs/onchain/accounts/intents/index.js +7 -8
  12. package/dist/cjs/onchain/accounts/intents/math.js +15 -22
  13. package/dist/cjs/onchain/accounts/intents/open-strategy.js +5 -5
  14. package/dist/cjs/onchain/accounts/intents/plan.js +27 -41
  15. package/dist/cjs/onchain/accounts/intents/realize.js +14 -21
  16. package/dist/cjs/onchain/accounts/intents/tail.js +2 -2
  17. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  18. package/dist/cjs/onchain/accounts/intents/view.js +1 -0
  19. package/dist/cjs/onchain/constants/index.js +1 -0
  20. package/dist/cjs/onchain/constants/math.js +11 -0
  21. package/dist/cjs/onchain/index.js +32 -3
  22. package/dist/cjs/onchain/validation/checks.js +250 -0
  23. package/dist/cjs/onchain/validation/index.js +29 -0
  24. package/dist/cjs/onchain/{accounts/intents → validation}/refusal.js +12 -1
  25. package/dist/cjs/onchain/validation/token.js +29 -0
  26. package/dist/cjs/preview/index.js +10 -0
  27. package/dist/cjs/preview/preview/buildDelayedPreview.js +1 -0
  28. package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +1 -0
  29. package/dist/cjs/preview/preview/previewOpenCreditAccount.js +1 -0
  30. package/dist/cjs/preview/validate/checkOperation.js +173 -0
  31. package/dist/cjs/preview/validate/checkSimulation.js +52 -0
  32. package/dist/cjs/preview/validate/index.js +6 -0
  33. package/dist/cjs/sdk/index.js +4 -0
  34. package/dist/cjs/sdk/prepare/PrepareApi.js +17 -13
  35. package/dist/cjs/sdk/prepare/index.js +4 -0
  36. package/dist/cjs/sdk/prepare/types.js +4 -0
  37. package/dist/esm/common-utils/index.js +2 -11
  38. package/dist/esm/common-utils/test-utils/index.js +4 -3
  39. package/dist/esm/common-utils/utils/index.js +2 -12
  40. package/dist/esm/common-utils/utils/strategies/index.js +2 -1
  41. package/dist/esm/common-utils/utils/strategies/strategy-info/cm-availability-condition.js +5 -5
  42. package/dist/esm/common-utils/utils/strategies/strategy-info/credit-manager-issues.js +133 -0
  43. package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +12 -23
  44. package/dist/esm/common-utils/utils/strategies/strategy-info/index.js +2 -1
  45. package/dist/esm/dev/AccountOpener.js +1 -1
  46. package/dist/esm/dev/withdrawalUtils.js +1 -1
  47. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  48. package/dist/esm/onchain/accounts/index.js +2 -2
  49. package/dist/esm/onchain/accounts/intents/guards.js +55 -50
  50. package/dist/esm/onchain/accounts/intents/index.js +5 -5
  51. package/dist/esm/onchain/accounts/intents/math.js +14 -21
  52. package/dist/esm/onchain/accounts/intents/open-strategy.js +4 -4
  53. package/dist/esm/onchain/accounts/intents/plan.js +15 -29
  54. package/dist/esm/onchain/accounts/intents/realize.js +12 -19
  55. package/dist/esm/onchain/accounts/intents/tail.js +1 -1
  56. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  57. package/dist/esm/onchain/accounts/intents/view.js +1 -0
  58. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  59. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  60. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  61. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  62. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  63. package/dist/esm/onchain/base/TokensMeta.js +3 -3
  64. package/dist/esm/onchain/chain/detectNetwork.js +1 -1
  65. package/dist/esm/onchain/constants/index.js +2 -2
  66. package/dist/esm/onchain/constants/math.js +11 -1
  67. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  68. package/dist/esm/onchain/index.js +7 -3
  69. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  70. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  71. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  72. package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
  73. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  74. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  75. package/dist/esm/onchain/pools/PoolService.js +1 -1
  76. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  77. package/dist/esm/onchain/validation/checks.js +230 -0
  78. package/dist/esm/onchain/validation/index.js +4 -0
  79. package/dist/esm/onchain/{accounts/intents → validation}/refusal.js +12 -2
  80. package/dist/esm/onchain/validation/token.js +27 -0
  81. package/dist/esm/preview/index.js +5 -1
  82. package/dist/esm/preview/preview/buildDelayedPreview.js +1 -0
  83. package/dist/esm/preview/preview/previewAdjustCreditAccount.js +1 -0
  84. package/dist/esm/preview/preview/previewOpenCreditAccount.js +1 -0
  85. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  86. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  87. package/dist/esm/preview/validate/checkOperation.js +171 -0
  88. package/dist/esm/preview/validate/checkSimulation.js +51 -0
  89. package/dist/esm/preview/validate/index.js +3 -0
  90. package/dist/esm/sdk/index.js +2 -1
  91. package/dist/esm/sdk/prepare/PrepareApi.js +15 -11
  92. package/dist/esm/sdk/prepare/index.js +2 -1
  93. package/dist/esm/sdk/prepare/types.js +2 -1
  94. package/dist/types/common-utils/index.d.ts +2 -12
  95. package/dist/types/common-utils/utils/index.d.ts +2 -13
  96. package/dist/types/common-utils/utils/strategies/index.d.ts +2 -1
  97. package/dist/types/common-utils/utils/strategies/strategy-info/credit-manager-issues.d.ts +34 -0
  98. package/dist/types/common-utils/utils/strategies/strategy-info/index.d.ts +2 -1
  99. package/dist/types/model/previews.d.ts +22 -0
  100. package/dist/types/onchain/accounts/index.d.ts +2 -2
  101. package/dist/types/onchain/accounts/intents/guards.d.ts +8 -4
  102. package/dist/types/onchain/accounts/intents/index.d.ts +4 -3
  103. package/dist/types/onchain/accounts/intents/math.d.ts +2 -1
  104. package/dist/types/onchain/accounts/intents/plan.d.ts +3 -0
  105. package/dist/types/onchain/accounts/intents/types.d.ts +7 -1
  106. package/dist/types/onchain/constants/index.d.ts +2 -2
  107. package/dist/types/onchain/constants/math.d.ts +9 -1
  108. package/dist/types/onchain/index.d.ts +7 -3
  109. package/dist/types/onchain/validation/checks.d.ts +167 -0
  110. package/dist/types/onchain/validation/index.d.ts +4 -0
  111. package/dist/types/onchain/{accounts/intents → validation}/refusal.d.ts +100 -31
  112. package/dist/types/onchain/validation/token.d.ts +17 -0
  113. package/dist/types/preview/index.d.ts +5 -1
  114. package/dist/types/preview/validate/checkOperation.d.ts +46 -0
  115. package/dist/types/preview/validate/checkSimulation.d.ts +34 -0
  116. package/dist/types/preview/validate/index.d.ts +3 -0
  117. package/dist/types/sdk/index.d.ts +2 -2
  118. package/dist/types/sdk/prepare/index.d.ts +2 -2
  119. package/dist/types/sdk/prepare/types.d.ts +2 -2
  120. package/package.json +1 -1
  121. package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.js +0 -267
  122. package/dist/cjs/common-utils/utils/validation/index.js +0 -23
  123. package/dist/cjs/common-utils/utils/validation/is-zero-balance.js +0 -7
  124. package/dist/cjs/common-utils/utils/validation/validate-balance.js +0 -22
  125. package/dist/cjs/common-utils/utils/validation/validate-balance.spec.js +0 -54
  126. package/dist/cjs/common-utils/utils/validation/validate-balances.js +0 -17
  127. package/dist/cjs/common-utils/utils/validation/validate-balances.spec.js +0 -45
  128. package/dist/cjs/common-utils/utils/validation/validate-credit-manager.js +0 -8
  129. package/dist/cjs/common-utils/utils/validation/validate-credit-manager.spec.js +0 -36
  130. package/dist/cjs/common-utils/utils/validation/validate-hf.js +0 -10
  131. package/dist/cjs/common-utils/utils/validation/validate-hf.spec.js +0 -26
  132. package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.js +0 -14
  133. package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js +0 -29
  134. package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +0 -37
  135. package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.spec.js +0 -98
  136. package/dist/cjs/common-utils/utils/validation/validate-open-account.js +0 -18
  137. package/dist/cjs/common-utils/utils/validation/validate-open-account.spec.js +0 -56
  138. package/dist/cjs/common-utils/utils/validation/validate-quota.js +0 -23
  139. package/dist/cjs/common-utils/utils/validation/validate-quota.spec.js +0 -88
  140. package/dist/cjs/common-utils/utils/validation/validate-token-to-obtain.js +0 -18
  141. package/dist/cjs/common-utils/utils/validation/validate-token-to-obtain.spec.js +0 -36
  142. package/dist/cjs/common-utils/utils/validation/validation-types.js +0 -1
  143. package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.js +0 -264
  144. package/dist/esm/common-utils/utils/validation/index.js +0 -12
  145. package/dist/esm/common-utils/utils/validation/is-zero-balance.js +0 -6
  146. package/dist/esm/common-utils/utils/validation/validate-balance.js +0 -21
  147. package/dist/esm/common-utils/utils/validation/validate-balance.spec.js +0 -54
  148. package/dist/esm/common-utils/utils/validation/validate-balances.js +0 -16
  149. package/dist/esm/common-utils/utils/validation/validate-balances.spec.js +0 -45
  150. package/dist/esm/common-utils/utils/validation/validate-credit-manager.js +0 -7
  151. package/dist/esm/common-utils/utils/validation/validate-credit-manager.spec.js +0 -36
  152. package/dist/esm/common-utils/utils/validation/validate-hf.js +0 -8
  153. package/dist/esm/common-utils/utils/validation/validate-hf.spec.js +0 -26
  154. package/dist/esm/common-utils/utils/validation/validate-open-account-pool-quota-status.js +0 -13
  155. package/dist/esm/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js +0 -29
  156. package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +0 -36
  157. package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.spec.js +0 -98
  158. package/dist/esm/common-utils/utils/validation/validate-open-account.js +0 -17
  159. package/dist/esm/common-utils/utils/validation/validate-open-account.spec.js +0 -56
  160. package/dist/esm/common-utils/utils/validation/validate-quota.js +0 -22
  161. package/dist/esm/common-utils/utils/validation/validate-quota.spec.js +0 -88
  162. package/dist/esm/common-utils/utils/validation/validate-token-to-obtain.js +0 -17
  163. package/dist/esm/common-utils/utils/validation/validate-token-to-obtain.spec.js +0 -36
  164. package/dist/esm/common-utils/utils/validation/validation-types.js +0 -1
  165. package/dist/types/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.d.ts +0 -1
  166. package/dist/types/common-utils/utils/validation/index.d.ts +0 -12
  167. package/dist/types/common-utils/utils/validation/is-zero-balance.d.ts +0 -4
  168. package/dist/types/common-utils/utils/validation/validate-balance.d.ts +0 -25
  169. package/dist/types/common-utils/utils/validation/validate-balance.spec.d.ts +0 -1
  170. package/dist/types/common-utils/utils/validation/validate-balances.d.ts +0 -13
  171. package/dist/types/common-utils/utils/validation/validate-balances.spec.d.ts +0 -1
  172. package/dist/types/common-utils/utils/validation/validate-credit-manager.d.ts +0 -13
  173. package/dist/types/common-utils/utils/validation/validate-credit-manager.spec.d.ts +0 -1
  174. package/dist/types/common-utils/utils/validation/validate-hf.d.ts +0 -12
  175. package/dist/types/common-utils/utils/validation/validate-hf.spec.d.ts +0 -1
  176. package/dist/types/common-utils/utils/validation/validate-open-account-pool-quota-status.d.ts +0 -10
  177. package/dist/types/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.d.ts +0 -1
  178. package/dist/types/common-utils/utils/validation/validate-open-account-pool-status.d.ts +0 -26
  179. package/dist/types/common-utils/utils/validation/validate-open-account-pool-status.spec.d.ts +0 -1
  180. package/dist/types/common-utils/utils/validation/validate-open-account.d.ts +0 -25
  181. package/dist/types/common-utils/utils/validation/validate-open-account.spec.d.ts +0 -1
  182. package/dist/types/common-utils/utils/validation/validate-quota.d.ts +0 -24
  183. package/dist/types/common-utils/utils/validation/validate-quota.spec.d.ts +0 -1
  184. package/dist/types/common-utils/utils/validation/validate-token-to-obtain.d.ts +0 -17
  185. package/dist/types/common-utils/utils/validation/validate-token-to-obtain.spec.d.ts +0 -1
  186. package/dist/types/common-utils/utils/validation/validation-types.d.ts +0 -10
@@ -0,0 +1,173 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_validation_checks = require("../../onchain/validation/checks.js");
3
+ const require_onchain_validation_token = require("../../onchain/validation/token.js");
4
+ const require_onchain_accounts_intents_guards = require("../../onchain/accounts/intents/guards.js");
5
+ require("../../onchain/index.js");
6
+ let viem = require("viem");
7
+ //#region src/preview/validate/checkOperation.ts
8
+ /**
9
+ * Whether a parsed operation may be signed at all — the protocol state that
10
+ * `checkPrerequisites` leaves out, since that one covers only what the sender
11
+ * can fix themselves.
12
+ *
13
+ * Synchronous: the preview carries the numbers and the market is attached.
14
+ * Reports the most fundamental issue it finds and stops there, which is the one
15
+ * a caller acts on.
16
+ */
17
+ function checkOperation(input, options = {}) {
18
+ const { sdk, preview } = input;
19
+ const malformed = require_onchain_validation_checks.checkPreviewError("error" in preview ? preview.error : void 0);
20
+ if (malformed) return malformed;
21
+ switch (preview.operation) {
22
+ case "Deposit":
23
+ case "Mint": return poolIssues(sdk, preview, options, true);
24
+ case "Withdraw":
25
+ case "Redeem": return poolIssues(sdk, preview, options, false);
26
+ case "DelayedCreditAccountOperation": return checkOperation({
27
+ sdk,
28
+ preview: preview.instantPreview
29
+ }, options);
30
+ case "OpenCreditAccount":
31
+ case "RWAOpenCreditAccount":
32
+ case "AdjustCreditAccount": return creditIssues(sdk, preview, options);
33
+ case "CloseCreditAccount":
34
+ case "RepayCreditAccount": return marketIssues(sdk, preview.creditManager);
35
+ }
36
+ }
37
+ function poolIssues(sdk, preview, options, isDeposit) {
38
+ const market = sdk.marketRegister.findByPool(preview.pool);
39
+ return require_onchain_validation_checks.checkPoolPaused({
40
+ isPaused: market.pool.pool.isPaused,
41
+ pool: preview.pool
42
+ }) || require_onchain_validation_checks.checkPoolSunset({
43
+ isSunset: market.sunset,
44
+ isDeposit,
45
+ pool: preview.pool
46
+ }) || (isDeposit ? null : require_onchain_validation_checks.checkPoolPayout({
47
+ requested: preview.tokenOut.value,
48
+ available: market.pool.pool.availableLiquidity,
49
+ underlying: preview.tokenOut.token
50
+ })) || fundingIssue(options, [preview.tokenIn]);
51
+ }
52
+ /** What the market itself refuses, whatever the operation does. */
53
+ function marketIssues(sdk, creditManager) {
54
+ const suite = sdk.marketRegister.findCreditManager(creditManager);
55
+ return require_onchain_validation_checks.checkCreditManagerPaused({
56
+ isPaused: suite.isPaused,
57
+ creditManager
58
+ }) || require_onchain_validation_checks.checkMarketExpired({
59
+ isExpired: suite.isExpired,
60
+ creditManager,
61
+ expirationDate: suite.creditFacade.expirationDate
62
+ });
63
+ }
64
+ function creditIssues(sdk, preview, options) {
65
+ const suite = sdk.marketRegister.findCreditManager(preview.creditManager);
66
+ const market = suite.market;
67
+ const underlying = require_onchain_validation_token.toToken(sdk, market.pool.underlying);
68
+ const isOpening = preview.operation === "OpenCreditAccount" || preview.operation === "RWAOpenCreditAccount";
69
+ return marketIssues(sdk, preview.creditManager) || require_onchain_validation_checks.checkDebtInBand({
70
+ debt: preview.debt,
71
+ minDebt: suite.creditFacade.minDebt,
72
+ maxDebt: suite.creditFacade.maxDebt,
73
+ underlying,
74
+ allowZero: !isOpening
75
+ }) || borrowIssue(suite, preview, underlying) || forbiddenIssue(suite, preview) || require_onchain_validation_checks.checkQuotaCount({
76
+ count: preview.quotas.filter((q) => q.value > 0n).length,
77
+ max: suite.creditManager.maxEnabledTokens
78
+ }) || quotaIssue(market, preview, underlying) || (preview.debt === 0n ? null : collateralIssue(preview, options)) || fundingIssue(options, collateralOf(preview));
79
+ }
80
+ /**
81
+ * What the transaction draws, against what the market can lend right now.
82
+ *
83
+ * Only a draw is weighed: repaying, or leaving the debt alone, can never exceed
84
+ * a ceiling. Opening borrows the whole debt; adjusting borrows `debtChange`.
85
+ *
86
+ * The engine holds every simulation to this already (`assertCanBorrow`), so
87
+ * this is here for the transactions it never saw — a pasted calldata reaches
88
+ * the confirm screen with nothing else standing between it and a revert.
89
+ */
90
+ function borrowIssue(suite, preview, underlying) {
91
+ const drawn = preview.operation === "AdjustCreditAccount" ? preview.debtChange : preview.debt;
92
+ if (drawn <= 0n) return null;
93
+ const { limit, binding } = require_onchain_accounts_intents_guards.borrowable(suite);
94
+ return require_onchain_validation_checks.checkBorrowLimit({
95
+ requested: drawn,
96
+ available: limit,
97
+ binding,
98
+ underlying
99
+ });
100
+ }
101
+ /** The account against whichever bars the caller holds it to. */
102
+ function collateralIssue(preview, options) {
103
+ return collateralIssuesOf({
104
+ healthFactor: preview.healthFactor,
105
+ safeHealthFactor: preview.safeHealthFactor
106
+ }, options);
107
+ }
108
+ /** The wallet's side of the operation, against the balances it was given. */
109
+ function fundingIssue(options, puts) {
110
+ const { balances } = options;
111
+ if (!balances) return null;
112
+ for (const { token, value } of puts) {
113
+ const issue = require_onchain_validation_checks.checkFunding({
114
+ token,
115
+ required: value,
116
+ held: balances.get(token.address) ?? 0n
117
+ });
118
+ if (issue) return issue;
119
+ }
120
+ return null;
121
+ }
122
+ /** What the wallet puts in, which is what its balances have to cover. */
123
+ function collateralOf(preview) {
124
+ if ("collateral" in preview) return preview.collateral;
125
+ if ("collateralAdded" in preview) return preview.collateralAdded;
126
+ return [];
127
+ }
128
+ function forbiddenIssue(suite, preview) {
129
+ const obtained = preview.operation === "AdjustCreditAccount" ? preview.assetsChange : preview.assets;
130
+ const forbidden = suite.forbiddenTokens;
131
+ for (const asset of obtained) {
132
+ if (asset.value <= 0n) continue;
133
+ const issue = require_onchain_validation_checks.checkForbiddenToken({
134
+ token: asset.token,
135
+ isForbidden: forbidden.some((f) => (0, viem.isAddressEqual)(f, asset.token.address))
136
+ });
137
+ if (issue) return issue;
138
+ }
139
+ return null;
140
+ }
141
+ function quotaIssue(market, preview, underlying) {
142
+ const increases = preview.operation === "AdjustCreditAccount" ? preview.quotasChange : preview.quotas;
143
+ const { pqk } = market.pool;
144
+ for (const q of increases) {
145
+ if (q.value <= 0n) continue;
146
+ const quota = pqk.hasActiveQuota(q.token.address) ? pqk.quotas.get(q.token.address) : void 0;
147
+ const issue = require_onchain_validation_checks.checkQuotaLimit({
148
+ token: q.token,
149
+ requested: quota ? q.value : void 0,
150
+ available: (quota?.limit ?? 0n) - (quota?.totalQuoted ?? 0n),
151
+ underlying
152
+ });
153
+ if (issue) return issue;
154
+ }
155
+ return null;
156
+ }
157
+ /** The two collateral bars, shared by the preview and the simulation paths. */
158
+ function collateralIssuesOf(factors, options) {
159
+ const { minHealthFactor, minSafeHealthFactor, currentHealthFactor } = options;
160
+ return (minHealthFactor === void 0 ? null : require_onchain_validation_checks.checkCollateralised({
161
+ healthFactor: factors.healthFactor,
162
+ required: minHealthFactor,
163
+ safePrices: false,
164
+ improvesFrom: currentHealthFactor
165
+ })) || (minSafeHealthFactor === void 0 || factors.safeHealthFactor === void 0 ? null : require_onchain_validation_checks.checkCollateralised({
166
+ healthFactor: factors.safeHealthFactor,
167
+ required: minSafeHealthFactor,
168
+ safePrices: true
169
+ }));
170
+ }
171
+ //#endregion
172
+ exports.checkOperation = checkOperation;
173
+ exports.collateralIssuesOf = collateralIssuesOf;
@@ -0,0 +1,52 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_validation_checks = require("../../onchain/validation/checks.js");
3
+ const require_onchain_validation_token = require("../../onchain/validation/token.js");
4
+ require("../../onchain/index.js");
5
+ const require_preview_validate_checkOperation = require("./checkOperation.js");
6
+ //#region src/preview/validate/checkSimulation.ts
7
+ /**
8
+ * Whether a simulated operation clears the caller's own bars.
9
+ *
10
+ * The engine holds an account to the facade's `1.0`, because its guards answer
11
+ * "would this revert". A form is wiser to ask for more, and the engine's own
12
+ * note says so — a caller wanting the stricter bar applies it itself. This is
13
+ * that second opinion, over the numbers the engine already reported.
14
+ *
15
+ * Three of the checks below the engine does not make at all: both health-factor
16
+ * bars are its own `1.0`, and the quota count it never weighs. The other two run
17
+ * against the same numbers the engine used, and are here so that a change in the
18
+ * engine cannot pass silently.
19
+ *
20
+ * What is deliberately absent: the forbidden-token, quota-limit and funding
21
+ * checks all need the *delta* an operation applies, and `OperationState` reports
22
+ * only the state after it. Weighing them against absolutes would refuse a
23
+ * forbidden token the account merely holds, or a quota the operation never
24
+ * touched. The engine performed all three during the walk, so a simulation that
25
+ * came back `ok` has already passed them.
26
+ */
27
+ function checkSimulation(input, options = {}) {
28
+ const { sdk, state, creditManager } = input;
29
+ const suite = sdk.marketRegister.findCreditManager(creditManager);
30
+ return require_onchain_validation_checks.checkCreditManagerPaused({
31
+ isPaused: suite.isPaused,
32
+ creditManager
33
+ }) || require_onchain_validation_checks.checkMarketExpired({
34
+ isExpired: suite.isExpired,
35
+ creditManager,
36
+ expirationDate: suite.creditFacade.expirationDate
37
+ }) || require_onchain_validation_checks.checkDebtInBand({
38
+ debt: state.accountDebt,
39
+ minDebt: suite.creditFacade.minDebt,
40
+ maxDebt: suite.creditFacade.maxDebt,
41
+ underlying: require_onchain_validation_token.toToken(sdk, suite.market.pool.underlying),
42
+ allowZero: true
43
+ }) || require_onchain_validation_checks.checkQuotaCount({
44
+ count: Object.values(state.quotas).filter((q) => q.balance > 0n).length,
45
+ max: suite.creditManager.maxEnabledTokens
46
+ }) || (state.accountDebt === 0n ? null : require_preview_validate_checkOperation.collateralIssuesOf({
47
+ healthFactor: state.healthFactor,
48
+ safeHealthFactor: state.safeHealthFactor
49
+ }, options));
50
+ }
51
+ //#endregion
52
+ exports.checkSimulation = checkSimulation;
@@ -0,0 +1,6 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_preview_validate_checkOperation = require("./checkOperation.js");
3
+ const require_preview_validate_checkSimulation = require("./checkSimulation.js");
4
+ exports.checkOperation = require_preview_validate_checkOperation.checkOperation;
5
+ exports.checkSimulation = require_preview_validate_checkSimulation.checkSimulation;
6
+ exports.collateralIssuesOf = require_preview_validate_checkOperation.collateralIssuesOf;
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_validation_refusal = require("../onchain/validation/refusal.js");
2
3
  const require_sdk_errors_AllSourcesFailedError = require("./errors/AllSourcesFailedError.js");
3
4
  const require_sdk_errors_SourceChainMismatchError = require("./errors/SourceChainMismatchError.js");
4
5
  const require_sdk_errors_assertSameChains = require("./errors/assertSameChains.js");
@@ -31,6 +32,7 @@ exports.DEFAULT_MAX_OFFCHAIN_LAG = require_sdk_utils_mergeChains.DEFAULT_MAX_OFF
31
32
  exports.DEFAULT_MAX_STATE_AGE = require_sdk_GearboxSDK.DEFAULT_MAX_STATE_AGE;
32
33
  exports.ExecuteApi = require_sdk_execute_ExecuteApi.ExecuteApi;
33
34
  exports.GearboxSDK = require_sdk_GearboxSDK.GearboxSDK;
35
+ exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
34
36
  exports.LiquidationsNamespace = require_sdk_liquidations_LiquidationsNamespace.LiquidationsNamespace;
35
37
  exports.MissingSourceError = require_sdk_errors_MissingSourceError.MissingSourceError;
36
38
  exports.NoSourceServedError = require_sdk_errors_NoSourceServedError.NoSourceServedError;
@@ -45,3 +47,5 @@ exports.everyChainFailed = require_sdk_errors_everyChainFailed.everyChainFailed;
45
47
  exports.filterResponse = require_sdk_utils_filterResponse.filterResponse;
46
48
  exports.mergeChainList = require_sdk_utils_mergeChains.mergeChainList;
47
49
  exports.mergeChainOne = require_sdk_utils_mergeChains.mergeChainOne;
50
+ exports.raise = require_onchain_validation_refusal.raise;
51
+ exports.refuse = require_onchain_validation_refusal.refuse;
@@ -1,7 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_onchain_utils_hex = require("../../onchain/utils/hex.js");
3
3
  const require_onchain_base_MultichainConstruct = require("../../onchain/base/MultichainConstruct.js");
4
- const require_onchain_accounts_intents_refusal = require("../../onchain/accounts/intents/refusal.js");
4
+ const require_onchain_validation_refusal = require("../../onchain/validation/refusal.js");
5
+ const require_onchain_validation_token = require("../../onchain/validation/token.js");
5
6
  const require_onchain_accounts_intents_utils_credit_account_slice = require("../../onchain/accounts/intents/utils/credit-account-slice.js");
6
7
  const require_onchain_accounts_intents_index = require("../../onchain/accounts/intents/index.js");
7
8
  require("../../onchain/index.js");
@@ -37,7 +38,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
37
38
  network: position.chainId,
38
39
  run: async (sdk) => {
39
40
  const intent = resumable(params.intent ?? params.claimable.intent);
40
- if (!intent) return require_onchain_accounts_intents_refusal.refuse("noRecordedIntent", void 0);
41
+ if (!intent) return require_onchain_validation_refusal.refuse("noRecordedIntent", void 0);
41
42
  return service(sdk).finishIntent({
42
43
  intent,
43
44
  claimable: params.claimable,
@@ -53,10 +54,11 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
53
54
  * {@inheritDoc OpportunitiesPrepare.deposit}
54
55
  **/
55
56
  deposit(pool, params) {
56
- const { marketRegister, pools } = this.sdk.chain(pool.chainId);
57
+ const chain = this.sdk.chain(pool.chainId);
58
+ const { marketRegister, pools } = chain;
57
59
  const tokenIn = params.tokenIn ?? marketRegister.findByPool(pool.pool).pool.underlying;
58
60
  const tokenOut = lpRoute(params.tokenOut, () => pools.getDepositTokensOut(pool.pool, tokenIn));
59
- if (!tokenOut) return unroutable(tokenIn, void 0);
61
+ if (!tokenOut) return unroutable(chain, tokenIn, void 0);
60
62
  const preview = pools.simulateDeposit({
61
63
  pool: pool.pool,
62
64
  amount: params.amount,
@@ -69,7 +71,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
69
71
  wallet: params.wallet,
70
72
  meta: pools.getDepositMetadata(pool.pool, tokenIn, tokenOut)
71
73
  });
72
- if (!call) return unroutable(tokenIn, tokenOut);
74
+ if (!call) return unroutable(chain, tokenIn, tokenOut);
73
75
  return {
74
76
  ok: true,
75
77
  operations: [],
@@ -81,10 +83,11 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
81
83
  * {@inheritDoc OpportunitiesPrepare.withdraw}
82
84
  **/
83
85
  withdraw(pool, params) {
84
- const { pools } = this.sdk.chain(pool.chainId);
86
+ const chain = this.sdk.chain(pool.chainId);
87
+ const { pools } = chain;
85
88
  const tokenIn = params.tokenIn ?? pool.pool;
86
89
  const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
87
- if (!tokenOut) return unroutable(tokenIn, void 0);
90
+ if (!tokenOut) return unroutable(chain, tokenIn, void 0);
88
91
  const preview = pools.simulateWithdraw({
89
92
  pool: pool.pool,
90
93
  amount: params.amount,
@@ -110,10 +113,11 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
110
113
  * {@inheritDoc OpportunitiesPrepare.redeem}
111
114
  **/
112
115
  redeem(pool, params) {
113
- const { pools } = this.sdk.chain(pool.chainId);
116
+ const chain = this.sdk.chain(pool.chainId);
117
+ const { pools } = chain;
114
118
  const tokenIn = params.tokenIn ?? pool.pool;
115
119
  const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
116
- if (!tokenOut) return unroutable(tokenIn, void 0);
120
+ if (!tokenOut) return unroutable(chain, tokenIn, void 0);
117
121
  const preview = pools.simulateRedeem({
118
122
  pool: pool.pool,
119
123
  amount: params.amount,
@@ -333,10 +337,10 @@ function resumable(intent) {
333
337
  * is the usual way of it; both are present where a pair exists but nothing of
334
338
  * ours implements it.
335
339
  **/
336
- function unroutable(from, to) {
337
- return require_onchain_accounts_intents_refusal.refuse("unsupportedTokenPair", {
338
- from,
339
- to
340
+ function unroutable(sdk, from, to) {
341
+ return require_onchain_validation_refusal.refuse("unsupportedTokenPair", {
342
+ from: require_onchain_validation_token.toToken(sdk, from),
343
+ to: to === void 0 ? void 0 : require_onchain_validation_token.toToken(sdk, to)
340
344
  });
341
345
  }
342
346
  /**
@@ -1,4 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_validation_refusal = require("../../onchain/validation/refusal.js");
2
3
  const require_sdk_prepare_PrepareApi = require("./PrepareApi.js");
3
4
  require("./types.js");
5
+ exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
4
6
  exports.PrepareApi = require_sdk_prepare_PrepareApi.PrepareApi;
7
+ exports.raise = require_onchain_validation_refusal.raise;
8
+ exports.refuse = require_onchain_validation_refusal.refuse;
@@ -1 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_validation_refusal = require("../../onchain/validation/refusal.js");
3
+ exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
4
+ exports.raise = require_onchain_validation_refusal.raise;
5
+ exports.refuse = require_onchain_validation_refusal.refuse;
@@ -2,7 +2,6 @@ import { AxiosCache } from "./axios-cache/AxiosCache.js";
2
2
  import "./axios-cache/index.js";
3
3
  import { BigIntMath } from "../onchain/utils/bigint-math.js";
4
4
  import { EXECUTE_BYTES_SELECTOR, collectTraces, findCallTo, findCallWithInput, findExecuteBytes, resolveProtocolCall } from "./utils/trace.js";
5
- import { MIN_HF_LIMITED, validateHF } from "./utils/validation/validate-hf.js";
6
5
  import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./utils/creditAccount/quota-utils.js";
7
6
  import { ChartsCreditManagerData } from "./charts/credit-manager.js";
8
7
  import { CREDIT_SESSION_ID_BY_STATUS, CREDIT_SESSION_STATUS_BY_ID, CreditSession, CreditSessionFiltered, UserCreditSessionsBuilder } from "./charts/credit-session.js";
@@ -74,23 +73,15 @@ import { getComplexPointsList } from "./utils/strategies/points/get-complex-poin
74
73
  import { getPointsInfo } from "./utils/strategies/points/get-points-info.js";
75
74
  import { getPointsRates } from "./utils/strategies/points/get-points-rates.js";
76
75
  import { getStrategyPoints } from "./utils/strategies/points/get-strategy-points.js";
77
- import { validateOpenAccountPoolQuotaStatus } from "./utils/validation/validate-open-account-pool-quota-status.js";
78
- import { validateOpenAccountPoolStatus } from "./utils/validation/validate-open-account-pool-status.js";
76
+ import { checkCreditManagerUsable, checkOpenAccountCeilings } from "./utils/strategies/strategy-info/credit-manager-issues.js";
79
77
  import { cmAvailabilityCondition } from "./utils/strategies/strategy-info/cm-availability-condition.js";
80
78
  import { getStrategyMaxAPY } from "./utils/strategies/strategy-info/get-strategy-max-apy.js";
81
79
  import { sortStrategyCMsByAvailability } from "./utils/strategies/sort-strategy-cms-by-availability/sort-strategy-cms-by-availability.js";
82
80
  import { calculateTotalAPY } from "./utils/strategies/strategy-info/calculate-total-apy.js";
83
81
  import { calculateTotalPoints } from "./utils/strategies/strategy-info/calculate-total-points.js";
84
- import { isZeroBalance } from "./utils/validation/is-zero-balance.js";
85
- import { validateBalance } from "./utils/validation/validate-balance.js";
86
- import { validateBalances } from "./utils/validation/validate-balances.js";
87
- import { validateCreditManager } from "./utils/validation/validate-credit-manager.js";
88
- import { validateQuota } from "./utils/validation/validate-quota.js";
89
- import { validateOpenAccount } from "./utils/validation/validate-open-account.js";
90
- import { validateTokenToObtain } from "./utils/validation/validate-token-to-obtain.js";
91
82
  import { getCMYouCanEarn } from "./utils/strategies/strategy-info/get-cm-you-can-earn.js";
92
83
  import { getStrategyInfoCore } from "./utils/strategies/strategy-info/get-strategy-info-core.js";
93
84
  import { getStrategyInfo } from "./utils/strategies/strategy-info/get-strategy-info.js";
94
85
  import { getStrategyYouCanEarn } from "./utils/strategies/strategy-info/get-strategy-you-can-earn.js";
95
86
  import "./utils/index.js";
96
- export { AssetUtils, AxiosCache, BONUS_APY_FROM_POINTS, BigIntMath, CREDIT_SESSION_ID_BY_STATUS, CREDIT_SESSION_STATUS_BY_ID, ChartsCreditManagerData, ChartsPoolData, CreditSession, CreditSessionFiltered, EMPTY_ADDRESS, EMPTY_ARRAY, EMPTY_OBJECT, EXECUTE_BYTES_SELECTOR, MIN_HF_LIMITED, PriceUtils, RST_ETH_ADDRESS, TokenData, UserCreditSessionsBuilder, UserPoolData, addAmountInTarget, amountAbcComparator, assetComparator, calcDefaultQuota, calcHealthFactor, calcMaxDebtIncrease, calcMaxLendingDebt, calcOverallAPY, calcQuotaBorrowRate, calcQuotaUpdate, calcRecommendedQuota, calcRelativeBaseBorrowRate, calculateBorrowRateFromUtilization, calculateEarnings, calculateEffectiveBorrowRate, calculateLossCoefficient, calculateMaxLeverageFactor, calculateMaxStrategyDebt, calculateSafeBorrowRate, calculateTotalAPY, calculateTotalPoints, checkBoolean, checkDegenNFT, cmAvailabilityCondition, collectTraces, createLegacyStrategyDataSource, findCallTo, findCallWithInput, findExecuteBytes, getAvailableAndDisabledStrategies, getCMAllowedCollaterals, getCMYouCanEarn, getChainPhantomTokens, getCollateralByDebt, getComplexAPYList, getComplexPointsList, getDefaultAsset, getFactorFromLeverage, getLeverageFromFactor, getListWithAmountInTarget, getNativeTokenAddress, getPointsInfo, getPointsRates, getRateWithFee, getRecommendedDebt, getRecommendedLeverageFactor, getReleasedStrategiesList, getReleasedStrategiesListCore, getSafeBaseBorrowRate, getSingleQuotaBorrowRate, getStrategyCreditManagers, getStrategyCreditManagersList, getStrategyCreditManagersListCore, getStrategyInfo, getStrategyInfoCore, getStrategyMaxAPY, getStrategyPoints, getStrategyYouCanEarn, getTimeToLiquidation, getWalletBalancesAllowedOnCM, isActivatedToken, isApyWithPointsException, isCollateralToken, isCreditManagerUsable, isForbiddenToken, isObtainableToken, isStrategyCMDisabled, isStrategyDisabled, isStrategyEligible, isStrategyReleased, isUsableToken, isValidExtraCollateralToken, isZeroBalance, liquidationPrice, maxAPYFormula, maxLeverage, maxLeverageThreshold, resolveProtocolCall, roundUpQuota, sortAssets, sortBalances, sortStrategyCMsByAvailability, tokensAbcComparator, validateBalance, validateBalances, validateCreditManager, validateHF, validateOpenAccount, validateOpenAccountPoolQuotaStatus, validateOpenAccountPoolStatus, validateQuota, validateTokenToObtain, wrapTokenAddress };
87
+ export { AssetUtils, AxiosCache, BONUS_APY_FROM_POINTS, BigIntMath, CREDIT_SESSION_ID_BY_STATUS, CREDIT_SESSION_STATUS_BY_ID, ChartsCreditManagerData, ChartsPoolData, CreditSession, CreditSessionFiltered, EMPTY_ADDRESS, EMPTY_ARRAY, EMPTY_OBJECT, EXECUTE_BYTES_SELECTOR, PriceUtils, RST_ETH_ADDRESS, TokenData, UserCreditSessionsBuilder, UserPoolData, addAmountInTarget, amountAbcComparator, assetComparator, calcDefaultQuota, calcHealthFactor, calcMaxDebtIncrease, calcMaxLendingDebt, calcOverallAPY, calcQuotaBorrowRate, calcQuotaUpdate, calcRecommendedQuota, calcRelativeBaseBorrowRate, calculateBorrowRateFromUtilization, calculateEarnings, calculateEffectiveBorrowRate, calculateLossCoefficient, calculateMaxLeverageFactor, calculateMaxStrategyDebt, calculateSafeBorrowRate, calculateTotalAPY, calculateTotalPoints, checkBoolean, checkCreditManagerUsable, checkDegenNFT, checkOpenAccountCeilings, cmAvailabilityCondition, collectTraces, createLegacyStrategyDataSource, findCallTo, findCallWithInput, findExecuteBytes, getAvailableAndDisabledStrategies, getCMAllowedCollaterals, getCMYouCanEarn, getChainPhantomTokens, getCollateralByDebt, getComplexAPYList, getComplexPointsList, getDefaultAsset, getFactorFromLeverage, getLeverageFromFactor, getListWithAmountInTarget, getNativeTokenAddress, getPointsInfo, getPointsRates, getRateWithFee, getRecommendedDebt, getRecommendedLeverageFactor, getReleasedStrategiesList, getReleasedStrategiesListCore, getSafeBaseBorrowRate, getSingleQuotaBorrowRate, getStrategyCreditManagers, getStrategyCreditManagersList, getStrategyCreditManagersListCore, getStrategyInfo, getStrategyInfoCore, getStrategyMaxAPY, getStrategyPoints, getStrategyYouCanEarn, getTimeToLiquidation, getWalletBalancesAllowedOnCM, isActivatedToken, isApyWithPointsException, isCollateralToken, isCreditManagerUsable, isForbiddenToken, isObtainableToken, isStrategyCMDisabled, isStrategyDisabled, isStrategyEligible, isStrategyReleased, isUsableToken, isValidExtraCollateralToken, liquidationPrice, maxAPYFormula, maxLeverage, maxLeverageThreshold, resolveProtocolCall, roundUpQuota, sortAssets, sortBalances, sortStrategyCMsByAvailability, tokensAbcComparator, wrapTokenAddress };
@@ -42,6 +42,7 @@ function buildCreditManager(overrides = {}) {
42
42
  const pool = overrides.pool ?? "0xcccccccccccccccccccccccccccccccccccccccc";
43
43
  const underlyingToken = overrides.underlyingToken ?? "0x9999999999999999999999999999999999999999";
44
44
  const quotas = overrides.quotas ?? {};
45
+ const forbiddenTokens = overrides.forbiddenTokens ?? {};
45
46
  return {
46
47
  address,
47
48
  name: overrides.name ?? "",
@@ -49,7 +50,6 @@ function buildCreditManager(overrides = {}) {
49
50
  pool,
50
51
  isPaused: overrides.isPaused ?? false,
51
52
  collateralTokens: overrides.collateralTokens ?? [],
52
- forbiddenTokens: overrides.forbiddenTokens ?? {},
53
53
  supportedTokens: overrides.supportedTokens ?? {},
54
54
  quotas,
55
55
  liquidationThresholds: overrides.liquidationThresholds ?? {},
@@ -65,8 +65,9 @@ function buildCreditManager(overrides = {}) {
65
65
  isDegenMode: overrides.isDegenMode ?? false,
66
66
  degenNFT: overrides.degenNFT ?? "0x0000000000000000000000000000000000000000",
67
67
  isQuoted: overrides.isQuoted ?? (() => false),
68
- isForbidden: overrides.isForbidden ?? (() => false),
69
- ...overrides
68
+ ...overrides,
69
+ forbiddenTokens,
70
+ isForbidden: overrides.isForbidden ?? ((token) => !!forbiddenTokens[token])
70
71
  };
71
72
  }
72
73
  function buildTokenData(address, symbol, decimals = 18, isPhantom = false) {
@@ -1,6 +1,5 @@
1
1
  import { BigIntMath } from "../../onchain/utils/bigint-math.js";
2
2
  import { EXECUTE_BYTES_SELECTOR, collectTraces, findCallTo, findCallWithInput, findExecuteBytes, resolveProtocolCall } from "./trace.js";
3
- import { MIN_HF_LIMITED, validateHF } from "./validation/validate-hf.js";
4
3
  import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./creditAccount/quota-utils.js";
5
4
  import { BONUS_APY_FROM_POINTS } from "./apy/bonus-apy-from-points.js";
6
5
  import { calculateBorrowRateFromUtilization } from "./apy/calculate-borrow-rate-from-utilization.js";
@@ -68,24 +67,15 @@ import { getComplexPointsList } from "./strategies/points/get-complex-points-lis
68
67
  import { getPointsInfo } from "./strategies/points/get-points-info.js";
69
68
  import { getPointsRates } from "./strategies/points/get-points-rates.js";
70
69
  import { getStrategyPoints } from "./strategies/points/get-strategy-points.js";
71
- import { validateOpenAccountPoolQuotaStatus } from "./validation/validate-open-account-pool-quota-status.js";
72
- import { validateOpenAccountPoolStatus } from "./validation/validate-open-account-pool-status.js";
70
+ import { checkCreditManagerUsable, checkOpenAccountCeilings } from "./strategies/strategy-info/credit-manager-issues.js";
73
71
  import { cmAvailabilityCondition } from "./strategies/strategy-info/cm-availability-condition.js";
74
72
  import { getStrategyMaxAPY } from "./strategies/strategy-info/get-strategy-max-apy.js";
75
73
  import { sortStrategyCMsByAvailability } from "./strategies/sort-strategy-cms-by-availability/sort-strategy-cms-by-availability.js";
76
74
  import { calculateTotalAPY } from "./strategies/strategy-info/calculate-total-apy.js";
77
75
  import { calculateTotalPoints } from "./strategies/strategy-info/calculate-total-points.js";
78
- import { isZeroBalance } from "./validation/is-zero-balance.js";
79
- import { validateBalance } from "./validation/validate-balance.js";
80
- import { validateBalances } from "./validation/validate-balances.js";
81
- import { validateCreditManager } from "./validation/validate-credit-manager.js";
82
- import { validateQuota } from "./validation/validate-quota.js";
83
- import { validateOpenAccount } from "./validation/validate-open-account.js";
84
- import { validateTokenToObtain } from "./validation/validate-token-to-obtain.js";
85
76
  import { getCMYouCanEarn } from "./strategies/strategy-info/get-cm-you-can-earn.js";
86
77
  import { getStrategyInfoCore } from "./strategies/strategy-info/get-strategy-info-core.js";
87
78
  import { getStrategyInfo } from "./strategies/strategy-info/get-strategy-info.js";
88
79
  import { getStrategyYouCanEarn } from "./strategies/strategy-info/get-strategy-you-can-earn.js";
89
80
  import "./strategies/index.js";
90
- import "./validation/index.js";
91
- export { AssetUtils, BONUS_APY_FROM_POINTS, BigIntMath, EMPTY_ADDRESS, EMPTY_ARRAY, EMPTY_OBJECT, EXECUTE_BYTES_SELECTOR, MIN_HF_LIMITED, PriceUtils, RST_ETH_ADDRESS, addAmountInTarget, amountAbcComparator, assetComparator, calcDefaultQuota, calcHealthFactor, calcMaxDebtIncrease, calcMaxLendingDebt, calcOverallAPY, calcQuotaBorrowRate, calcQuotaUpdate, calcRecommendedQuota, calcRelativeBaseBorrowRate, calculateBorrowRateFromUtilization, calculateEarnings, calculateEffectiveBorrowRate, calculateLossCoefficient, calculateMaxLeverageFactor, calculateMaxStrategyDebt, calculateSafeBorrowRate, calculateTotalAPY, calculateTotalPoints, checkBoolean, checkDegenNFT, cmAvailabilityCondition, collectTraces, createLegacyStrategyDataSource, findCallTo, findCallWithInput, findExecuteBytes, getAvailableAndDisabledStrategies, getCMAllowedCollaterals, getCMYouCanEarn, getChainPhantomTokens, getCollateralByDebt, getComplexAPYList, getComplexPointsList, getDefaultAsset, getFactorFromLeverage, getLeverageFromFactor, getListWithAmountInTarget, getNativeTokenAddress, getPointsInfo, getPointsRates, getRateWithFee, getRecommendedDebt, getRecommendedLeverageFactor, getReleasedStrategiesList, getReleasedStrategiesListCore, getSafeBaseBorrowRate, getSingleQuotaBorrowRate, getStrategyCreditManagers, getStrategyCreditManagersList, getStrategyCreditManagersListCore, getStrategyInfo, getStrategyInfoCore, getStrategyMaxAPY, getStrategyPoints, getStrategyYouCanEarn, getTimeToLiquidation, getWalletBalancesAllowedOnCM, isActivatedToken, isApyWithPointsException, isCollateralToken, isCreditManagerUsable, isForbiddenToken, isObtainableToken, isStrategyCMDisabled, isStrategyDisabled, isStrategyEligible, isStrategyReleased, isUsableToken, isValidExtraCollateralToken, isZeroBalance, liquidationPrice, maxAPYFormula, maxLeverage, maxLeverageThreshold, resolveProtocolCall, roundUpQuota, sortAssets, sortBalances, sortStrategyCMsByAvailability, tokensAbcComparator, validateBalance, validateBalances, validateCreditManager, validateHF, validateOpenAccount, validateOpenAccountPoolQuotaStatus, validateOpenAccountPoolStatus, validateQuota, validateTokenToObtain, wrapTokenAddress };
81
+ export { AssetUtils, BONUS_APY_FROM_POINTS, BigIntMath, EMPTY_ADDRESS, EMPTY_ARRAY, EMPTY_OBJECT, EXECUTE_BYTES_SELECTOR, PriceUtils, RST_ETH_ADDRESS, addAmountInTarget, amountAbcComparator, assetComparator, calcDefaultQuota, calcHealthFactor, calcMaxDebtIncrease, calcMaxLendingDebt, calcOverallAPY, calcQuotaBorrowRate, calcQuotaUpdate, calcRecommendedQuota, calcRelativeBaseBorrowRate, calculateBorrowRateFromUtilization, calculateEarnings, calculateEffectiveBorrowRate, calculateLossCoefficient, calculateMaxLeverageFactor, calculateMaxStrategyDebt, calculateSafeBorrowRate, calculateTotalAPY, calculateTotalPoints, checkBoolean, checkCreditManagerUsable, checkDegenNFT, checkOpenAccountCeilings, cmAvailabilityCondition, collectTraces, createLegacyStrategyDataSource, findCallTo, findCallWithInput, findExecuteBytes, getAvailableAndDisabledStrategies, getCMAllowedCollaterals, getCMYouCanEarn, getChainPhantomTokens, getCollateralByDebt, getComplexAPYList, getComplexPointsList, getDefaultAsset, getFactorFromLeverage, getLeverageFromFactor, getListWithAmountInTarget, getNativeTokenAddress, getPointsInfo, getPointsRates, getRateWithFee, getRecommendedDebt, getRecommendedLeverageFactor, getReleasedStrategiesList, getReleasedStrategiesListCore, getSafeBaseBorrowRate, getSingleQuotaBorrowRate, getStrategyCreditManagers, getStrategyCreditManagersList, getStrategyCreditManagersListCore, getStrategyInfo, getStrategyInfoCore, getStrategyMaxAPY, getStrategyPoints, getStrategyYouCanEarn, getTimeToLiquidation, getWalletBalancesAllowedOnCM, isActivatedToken, isApyWithPointsException, isCollateralToken, isCreditManagerUsable, isForbiddenToken, isObtainableToken, isStrategyCMDisabled, isStrategyDisabled, isStrategyEligible, isStrategyReleased, isUsableToken, isValidExtraCollateralToken, liquidationPrice, maxAPYFormula, maxLeverage, maxLeverageThreshold, resolveProtocolCall, roundUpQuota, sortAssets, sortBalances, sortStrategyCMsByAvailability, tokensAbcComparator, wrapTokenAddress };
@@ -50,6 +50,7 @@ import { getPointsInfo } from "./points/get-points-info.js";
50
50
  import { getPointsRates } from "./points/get-points-rates.js";
51
51
  import { getStrategyPoints } from "./points/get-strategy-points.js";
52
52
  import "./points/index.js";
53
+ import { checkCreditManagerUsable, checkOpenAccountCeilings } from "./strategy-info/credit-manager-issues.js";
53
54
  import { cmAvailabilityCondition } from "./strategy-info/cm-availability-condition.js";
54
55
  import { getStrategyMaxAPY } from "./strategy-info/get-strategy-max-apy.js";
55
56
  import { sortStrategyCMsByAvailability } from "./sort-strategy-cms-by-availability/sort-strategy-cms-by-availability.js";
@@ -62,4 +63,4 @@ import { getStrategyInfo } from "./strategy-info/get-strategy-info.js";
62
63
  import { getStrategyYouCanEarn } from "./strategy-info/get-strategy-you-can-earn.js";
63
64
  import "./strategy-info/index.js";
64
65
  import "./strategy-state/index.js";
65
- export { RST_ETH_ADDRESS, addAmountInTarget, calculateLossCoefficient, calculateMaxLeverageFactor, calculateMaxStrategyDebt, calculateTotalAPY, calculateTotalPoints, checkBoolean, checkDegenNFT, cmAvailabilityCondition, createLegacyStrategyDataSource, getAvailableAndDisabledStrategies, getCMAllowedCollaterals, getCMYouCanEarn, getChainPhantomTokens, getCollateralByDebt, getComplexPointsList, getDefaultAsset, getFactorFromLeverage, getLeverageFromFactor, getListWithAmountInTarget, getNativeTokenAddress, getPointsInfo, getPointsRates, getRecommendedDebt, getRecommendedLeverageFactor, getReleasedStrategiesList, getReleasedStrategiesListCore, getStrategyCreditManagers, getStrategyCreditManagersList, getStrategyCreditManagersListCore, getStrategyInfo, getStrategyInfoCore, getStrategyMaxAPY, getStrategyPoints, getStrategyYouCanEarn, getWalletBalancesAllowedOnCM, isActivatedToken, isApyWithPointsException, isCollateralToken, isCreditManagerUsable, isForbiddenToken, isObtainableToken, isStrategyCMDisabled, isStrategyDisabled, isStrategyEligible, isStrategyReleased, isUsableToken, isValidExtraCollateralToken, maxLeverage, maxLeverageThreshold, sortStrategyCMsByAvailability, wrapTokenAddress };
66
+ export { RST_ETH_ADDRESS, addAmountInTarget, calculateLossCoefficient, calculateMaxLeverageFactor, calculateMaxStrategyDebt, calculateTotalAPY, calculateTotalPoints, checkBoolean, checkCreditManagerUsable, checkDegenNFT, checkOpenAccountCeilings, cmAvailabilityCondition, createLegacyStrategyDataSource, getAvailableAndDisabledStrategies, getCMAllowedCollaterals, getCMYouCanEarn, getChainPhantomTokens, getCollateralByDebt, getComplexPointsList, getDefaultAsset, getFactorFromLeverage, getLeverageFromFactor, getListWithAmountInTarget, getNativeTokenAddress, getPointsInfo, getPointsRates, getRecommendedDebt, getRecommendedLeverageFactor, getReleasedStrategiesList, getReleasedStrategiesListCore, getStrategyCreditManagers, getStrategyCreditManagersList, getStrategyCreditManagersListCore, getStrategyInfo, getStrategyInfoCore, getStrategyMaxAPY, getStrategyPoints, getStrategyYouCanEarn, getWalletBalancesAllowedOnCM, isActivatedToken, isApyWithPointsException, isCollateralToken, isCreditManagerUsable, isForbiddenToken, isObtainableToken, isStrategyCMDisabled, isStrategyDisabled, isStrategyEligible, isStrategyReleased, isUsableToken, isValidExtraCollateralToken, maxLeverage, maxLeverageThreshold, sortStrategyCMsByAvailability, wrapTokenAddress };
@@ -1,16 +1,16 @@
1
1
  import { checkBoolean } from "../availability/check-boolean.js";
2
2
  import { checkDegenNFT } from "../availability/check-degen-nft.js";
3
3
  import "../availability/index.js";
4
- import { validateOpenAccountPoolStatus } from "../../validation/validate-open-account-pool-status.js";
4
+ import { checkOpenAccountCeilings } from "./credit-manager-issues.js";
5
5
  //#region src/common-utils/utils/strategies/strategy-info/cm-availability-condition.ts
6
6
  function cmAvailabilityCondition(targetToken, cmA, cmB, pools) {
7
- const aHasMinError = validateOpenAccountPoolStatus({
7
+ const aHasMinError = checkOpenAccountCeilings({
8
8
  pool: pools?.[cmA.pool],
9
9
  debt: cmA.minDebt,
10
10
  creditManager: cmA,
11
11
  targetToken
12
12
  });
13
- const bHasMinError = validateOpenAccountPoolStatus({
13
+ const bHasMinError = checkOpenAccountCeilings({
14
14
  pool: pools?.[cmB.pool],
15
15
  debt: cmB.minDebt,
16
16
  creditManager: cmB,
@@ -22,13 +22,13 @@ function cmAvailabilityCondition(targetToken, cmA, cmB, pools) {
22
22
  const { freeOfNFT: bFreeOfNFT } = checkDegenNFT(cmB);
23
23
  const nftSort = checkBoolean(aFreeOfNFT, bFreeOfNFT);
24
24
  if (nftSort !== 0) return nftSort;
25
- const aHasMaxError = validateOpenAccountPoolStatus({
25
+ const aHasMaxError = checkOpenAccountCeilings({
26
26
  pool: pools?.[cmA.pool],
27
27
  debt: cmA.maxDebt,
28
28
  creditManager: cmA,
29
29
  targetToken
30
30
  });
31
- const bHasMaxError = validateOpenAccountPoolStatus({
31
+ const bHasMaxError = checkOpenAccountCeilings({
32
32
  pool: pools?.[cmB.pool],
33
33
  debt: cmB.maxDebt,
34
34
  creditManager: cmB,