@gearbox-protocol/sdk 16.3.2 → 16.4.0-next.10

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 (139) hide show
  1. package/dist/cjs/dev/index.js +3 -2
  2. package/dist/cjs/dev/kycUtils.js +18 -35
  3. package/dist/cjs/dev/midasUtils.js +40 -11
  4. package/dist/cjs/dev/securitizeUtils.js +14 -10
  5. package/dist/cjs/dev/withdrawalUtils.js +3 -6
  6. package/dist/cjs/model/errors/index.js +2 -0
  7. package/dist/cjs/model/errors/operation-errors.js +18 -0
  8. package/dist/cjs/model/index.js +2 -0
  9. package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +0 -1
  10. package/dist/cjs/onchain/accounts/intents/borrow.js +139 -0
  11. package/dist/cjs/onchain/accounts/intents/collateral-valuation.js +41 -0
  12. package/dist/cjs/onchain/accounts/intents/guards.js +15 -3
  13. package/dist/cjs/onchain/accounts/intents/index.js +107 -20
  14. package/dist/cjs/onchain/accounts/intents/leverage-band.js +2 -12
  15. package/dist/cjs/onchain/accounts/intents/maxBorrow.js +89 -0
  16. package/dist/cjs/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
  17. package/dist/cjs/onchain/accounts/intents/open-strategy.js +6 -45
  18. package/dist/cjs/onchain/accounts/intents/realize.js +54 -2
  19. package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
  20. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  21. package/dist/cjs/onchain/accounts/intents/utils/common.js +19 -0
  22. package/dist/cjs/onchain/accounts/intents/utils/credit-account-slice.js +21 -0
  23. package/dist/cjs/onchain/accounts/intents/utils/index.js +2 -0
  24. package/dist/cjs/onchain/accounts/intents/utils/price-impact.js +3 -3
  25. package/dist/cjs/onchain/accounts/intents/withdraw-limits.js +97 -0
  26. package/dist/cjs/onchain/core/createAddressProvider.js +2 -5
  27. package/dist/cjs/onchain/index.js +6 -0
  28. package/dist/cjs/onchain/market/adapters/abi/conctructorAbi.js +1 -1
  29. package/dist/cjs/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +11 -3
  30. package/dist/cjs/onchain/positions/calcHealthFactor.js +3 -3
  31. package/dist/cjs/onchain/preview/index.js +2 -0
  32. package/dist/cjs/onchain/preview/preview/index.js +2 -0
  33. package/dist/cjs/onchain/preview/preview/midasGreenlistsAccount.js +17 -0
  34. package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +13 -16
  35. package/dist/cjs/onchain/preview/preview/previewOperation.js +19 -11
  36. package/dist/cjs/onchain/preview/preview/replayMulticall.js +4 -3
  37. package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  38. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +4 -3
  39. package/dist/cjs/onchain/validation/bundles/checkMidasAccountGreenlist.js +44 -0
  40. package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +16 -7
  41. package/dist/cjs/onchain/validation/bundles/index.js +2 -0
  42. package/dist/cjs/onchain/validation/checkOperation.js +0 -1
  43. package/dist/cjs/onchain/validation/checks/checkReservePriceLimited.js +30 -0
  44. package/dist/cjs/onchain/validation/checks/index.js +2 -0
  45. package/dist/cjs/onchain/validation/index.js +4 -0
  46. package/dist/cjs/sdk/execute/ExecuteApi.js +65 -5
  47. package/dist/cjs/sdk/prepare/PrepareApi.js +89 -14
  48. package/dist/esm/dev/index.js +3 -3
  49. package/dist/esm/dev/kycUtils.js +17 -33
  50. package/dist/esm/dev/midasUtils.js +39 -12
  51. package/dist/esm/dev/securitizeUtils.js +15 -11
  52. package/dist/esm/dev/withdrawalUtils.js +3 -6
  53. package/dist/esm/model/errors/index.js +2 -2
  54. package/dist/esm/model/errors/operation-errors.js +17 -1
  55. package/dist/esm/model/index.js +2 -2
  56. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +0 -1
  57. package/dist/esm/onchain/accounts/intents/borrow.js +137 -0
  58. package/dist/esm/onchain/accounts/intents/collateral-valuation.js +40 -0
  59. package/dist/esm/onchain/accounts/intents/guards.js +15 -3
  60. package/dist/esm/onchain/accounts/intents/index.js +107 -20
  61. package/dist/esm/onchain/accounts/intents/leverage-band.js +2 -12
  62. package/dist/esm/onchain/accounts/intents/maxBorrow.js +87 -0
  63. package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
  64. package/dist/esm/onchain/accounts/intents/open-strategy.js +6 -45
  65. package/dist/esm/onchain/accounts/intents/realize.js +54 -2
  66. package/dist/esm/onchain/accounts/intents/tail.js +1 -1
  67. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  68. package/dist/esm/onchain/accounts/intents/utils/common.js +19 -1
  69. package/dist/esm/onchain/accounts/intents/utils/credit-account-slice.js +21 -1
  70. package/dist/esm/onchain/accounts/intents/utils/index.js +3 -3
  71. package/dist/esm/onchain/accounts/intents/utils/price-impact.js +3 -3
  72. package/dist/esm/onchain/accounts/intents/withdraw-limits.js +95 -0
  73. package/dist/esm/onchain/core/createAddressProvider.js +2 -5
  74. package/dist/esm/onchain/index.js +4 -1
  75. package/dist/esm/onchain/market/adapters/abi/conctructorAbi.js +1 -1
  76. package/dist/esm/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +11 -3
  77. package/dist/esm/onchain/positions/calcHealthFactor.js +3 -3
  78. package/dist/esm/onchain/preview/index.js +2 -1
  79. package/dist/esm/onchain/preview/preview/index.js +2 -1
  80. package/dist/esm/onchain/preview/preview/midasGreenlistsAccount.js +16 -0
  81. package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +14 -17
  82. package/dist/esm/onchain/preview/preview/previewOperation.js +19 -11
  83. package/dist/esm/onchain/preview/preview/replayMulticall.js +4 -3
  84. package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  85. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +4 -3
  86. package/dist/esm/onchain/validation/bundles/checkMidasAccountGreenlist.js +43 -0
  87. package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +16 -7
  88. package/dist/esm/onchain/validation/bundles/index.js +2 -1
  89. package/dist/esm/onchain/validation/checkOperation.js +0 -1
  90. package/dist/esm/onchain/validation/checks/checkReservePriceLimited.js +29 -0
  91. package/dist/esm/onchain/validation/checks/index.js +2 -1
  92. package/dist/esm/onchain/validation/index.js +3 -1
  93. package/dist/esm/sdk/execute/ExecuteApi.js +65 -5
  94. package/dist/esm/sdk/prepare/PrepareApi.js +89 -14
  95. package/dist/types/dev/index.d.ts +3 -3
  96. package/dist/types/dev/kycUtils.d.ts +1 -5
  97. package/dist/types/dev/midasUtils.d.ts +11 -1
  98. package/dist/types/model/errors/index.d.ts +2 -2
  99. package/dist/types/model/errors/operation-errors.d.ts +54 -1
  100. package/dist/types/model/index.d.ts +3 -3
  101. package/dist/types/model/previews.d.ts +25 -19
  102. package/dist/types/onchain/accounts/index.d.ts +4 -3
  103. package/dist/types/onchain/accounts/intents/borrow.d.ts +141 -0
  104. package/dist/types/onchain/accounts/intents/collateral-valuation.d.ts +42 -0
  105. package/dist/types/onchain/accounts/intents/guards.d.ts +18 -2
  106. package/dist/types/onchain/accounts/intents/index.d.ts +102 -14
  107. package/dist/types/onchain/accounts/intents/maxBorrow.d.ts +54 -0
  108. package/dist/types/onchain/accounts/intents/maxWithdrawCollateral.d.ts +3 -8
  109. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -17
  110. package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +2 -0
  111. package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
  112. package/dist/types/onchain/accounts/intents/types.d.ts +41 -5
  113. package/dist/types/onchain/accounts/intents/utils/common.d.ts +15 -1
  114. package/dist/types/onchain/accounts/intents/utils/credit-account-slice.d.ts +14 -1
  115. package/dist/types/onchain/accounts/intents/utils/index.d.ts +3 -3
  116. package/dist/types/onchain/accounts/intents/withdraw-limits.d.ts +80 -0
  117. package/dist/types/onchain/index.d.ts +8 -4
  118. package/dist/types/onchain/market/adapters/contracts/MidasGatewayAdapterContract.d.ts +8 -2
  119. package/dist/types/onchain/preview/index.d.ts +2 -1
  120. package/dist/types/onchain/preview/preview/index.d.ts +2 -1
  121. package/dist/types/onchain/preview/preview/midasGreenlistsAccount.d.ts +13 -0
  122. package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +5 -3
  123. package/dist/types/onchain/preview/preview/replayMulticall.d.ts +8 -7
  124. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +2 -2
  125. package/dist/types/onchain/validation/bundles/checkMidasAccountGreenlist.d.ts +22 -0
  126. package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +6 -4
  127. package/dist/types/onchain/validation/bundles/index.d.ts +3 -2
  128. package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +2 -2
  129. package/dist/types/onchain/validation/checks/checkReservePriceLimited.d.ts +31 -0
  130. package/dist/types/onchain/validation/checks/index.d.ts +2 -1
  131. package/dist/types/onchain/validation/index.d.ts +4 -2
  132. package/dist/types/onchain/validation/raise.d.ts +2 -2
  133. package/dist/types/sdk/execute/index.d.ts +2 -2
  134. package/dist/types/sdk/execute/types.d.ts +48 -6
  135. package/dist/types/sdk/index.d.ts +5 -4
  136. package/dist/types/sdk/prepare/PrepareApi.d.ts +16 -4
  137. package/dist/types/sdk/prepare/index.d.ts +4 -3
  138. package/dist/types/sdk/prepare/types.d.ts +199 -65
  139. package/package.json +1 -1
@@ -14,10 +14,10 @@ const require_dev_detectChain = require("./detectChain.js");
14
14
  const require_dev_isOutOfSyncError = require("./isOutOfSyncError.js");
15
15
  const require_dev_isRateLimitError = require("./isRateLimitError.js");
16
16
  const require_dev_isTransientError = require("./isTransientError.js");
17
+ const require_dev_midasUtils = require("./midasUtils.js");
17
18
  const require_dev_kycUtils = require("./kycUtils.js");
18
19
  const require_dev_logSplitterTransport = require("./logSplitterTransport.js");
19
20
  const require_dev_ltUtils = require("./ltUtils.js");
20
- const require_dev_midasUtils = require("./midasUtils.js");
21
21
  const require_dev_migrateFaucet = require("./migrateFaucet.js");
22
22
  const require_dev_providers = require("./providers.js");
23
23
  const require_dev_replaceStorage = require("./replaceStorage.js");
@@ -42,6 +42,8 @@ exports.calcLiquidatableLTs = require_dev_calcLiquidatableLTs.calcLiquidatableLT
42
42
  exports.claimDSToken = require_dev_securitizeUtils.claimDSToken;
43
43
  exports.claimDSTokens = require_dev_securitizeUtils.claimDSTokens;
44
44
  exports.claimFromFaucet = require_dev_claimFromFaucet.claimFromFaucet;
45
+ exports.collectMidasGateways = require_dev_midasUtils.collectMidasGateways;
46
+ exports.collectMidasMTokens = require_dev_midasUtils.collectMidasMTokens;
45
47
  exports.createAnvilClient = require_dev_createAnvilClient.createAnvilClient;
46
48
  exports.createMinter = require_dev_mint_factory.createMinter;
47
49
  exports.deployUsingPublicCreate2 = require_dev_create2.deployUsingPublicCreate2;
@@ -86,4 +88,3 @@ exports.setLTZero = require_dev_ltUtils.setLTZero;
86
88
  exports.setLTs = require_dev_ltUtils.setLTs;
87
89
  exports.unpauseMidasIssuanceVault = require_dev_midasUtils.unpauseMidasIssuanceVault;
88
90
  exports.verifyTestnet = require_dev_verifyTestnet.verifyTestnet;
89
- exports.writeAndWait = require_dev_kycUtils.writeAndWait;
@@ -5,23 +5,12 @@ const require_onchain_OnchainSDK = require("../onchain/OnchainSDK.js");
5
5
  require("../onchain/index.js");
6
6
  const require_abi_rwa_iDSRegistryService = require("../abi/rwa/iDSRegistryService.js");
7
7
  const require_abi_rwa_iDSToken = require("../abi/rwa/iDSToken.js");
8
+ const require_dev_midasUtils = require("./midasUtils.js");
8
9
  const require_dev_withdrawalAbi = require("./withdrawalAbi.js");
9
10
  let viem = require("viem");
10
11
  let viem_accounts = require("viem/accounts");
11
12
  //#region src/dev/kycUtils.ts
12
13
  /**
13
- * Writes to a contract, mines a block and waits for the receipt
14
- */
15
- async function writeAndWait(anvil, params) {
16
- const hash = await anvil.writeContract(params);
17
- await anvil.mine({ blocks: 1 });
18
- await anvil.waitForTransactionReceipt({
19
- hash,
20
- pollingInterval: 100
21
- });
22
- return hash;
23
- }
24
- /**
25
14
  * Resolves the account that performs the DS registry writes: either the admin
26
15
  * private key, or the admin address impersonated on the fork
27
16
  */
@@ -99,36 +88,39 @@ async function registerSecuritizeInvestor(props) {
99
88
  const { account, release } = await useSecuritizeAdmin(props);
100
89
  try {
101
90
  if (!investorExists) {
102
- await writeAndWait(anvil, {
91
+ await anvil.writeContractSync({
103
92
  account,
104
93
  chain: anvil.chain,
105
94
  address: registryService,
106
95
  abi: require_abi_rwa_iDSRegistryService.iDSRegistryServiceAbi,
107
96
  functionName: "registerInvestor",
108
- args: [investorId, investorId]
97
+ args: [investorId, investorId],
98
+ throwOnReceiptRevert: true
109
99
  });
110
100
  logger?.debug(`Registered investor "${investorId}"`);
111
101
  }
112
- await writeAndWait(anvil, {
102
+ await anvil.writeContractSync({
113
103
  account,
114
104
  chain: anvil.chain,
115
105
  address: registryService,
116
106
  abi: require_abi_rwa_iDSRegistryService.iDSRegistryServiceAbi,
117
107
  functionName: "addWallet",
118
- args: [investor, investorId]
108
+ args: [investor, investorId],
109
+ throwOnReceiptRevert: true
119
110
  });
120
111
  logger?.debug(`Added wallet ${investor} for investor "${investorId}"`);
121
112
  try {
122
- await writeAndWait(anvil, {
113
+ await anvil.writeContractSync({
123
114
  account,
124
115
  chain: anvil.chain,
125
116
  address: registryService,
126
117
  abi: require_abi_rwa_iDSRegistryService.iDSRegistryServiceAbi,
127
118
  functionName: "setCountry",
128
- args: [investorId, "US"]
119
+ args: [investorId, "US"],
120
+ throwOnReceiptRevert: true
129
121
  });
130
122
  logger?.debug(`Set country for investor "${investorId}" to "US"`);
131
- await writeAndWait(anvil, {
123
+ await anvil.writeContractSync({
132
124
  account,
133
125
  chain: anvil.chain,
134
126
  address: registryService,
@@ -140,7 +132,8 @@ async function registerSecuritizeInvestor(props) {
140
132
  BigInt(APPROVED),
141
133
  require_onchain_constants_math.MAX_UINT256,
142
134
  "fake proof"
143
- ]
135
+ ],
136
+ throwOnReceiptRevert: true
144
137
  });
145
138
  logger?.debug(`Set attributes for investor "${investorId}"`);
146
139
  } catch (e) {
@@ -242,13 +235,14 @@ async function greenlistMidasGateway(props) {
242
235
  logger?.debug(`midas: ${account} already has role ${role}`);
243
236
  continue;
244
237
  }
245
- await writeAndWait(anvil, {
238
+ await anvil.writeContractSync({
246
239
  account: admin,
247
240
  chain: anvil.chain,
248
241
  address: accessControl,
249
242
  abi: iMidasAccessControlAbi,
250
243
  functionName: "grantRole",
251
- args: [role, account]
244
+ args: [role, account],
245
+ throwOnReceiptRevert: true
252
246
  });
253
247
  logger?.debug(`midas: granted role ${role} to ${account}`);
254
248
  }
@@ -280,7 +274,7 @@ async function findMidasGateway(props) {
280
274
  });
281
275
  await sdk.attach({ marketConfigurators });
282
276
  }
283
- const candidates = collectMidasGateways(sdk);
277
+ const candidates = require_dev_midasUtils.collectMidasGateways(sdk);
284
278
  if (candidates.length === 0) throw new Error("no midas gateway adapters found in loaded markets");
285
279
  const index = (await anvil.multicall({
286
280
  allowFailure: false,
@@ -295,16 +289,6 @@ async function findMidasGateway(props) {
295
289
  return candidates[index];
296
290
  }
297
291
  /**
298
- * Collects the target contracts of all Midas gateway adapters of the loaded
299
- * credit managers, same as the foundry tests do with
300
- * `ICreditConfiguratorV3.allowedAdapters`
301
- */
302
- function collectMidasGateways(sdk) {
303
- const gateways = new require_onchain_utils_AddressSet.AddressSet();
304
- for (const cm of sdk.marketRegister.creditManagers) for (const adapter of cm.creditManager.adapters.values()) if (adapter.contractType === "ADAPTER::MIDAS_GATEWAY") gateways.add(adapter.targetContract);
305
- return gateways.asArray();
306
- }
307
- /**
308
292
  * Registers a wallet as an investor (fake KYC) in every Securitize DSToken and
309
293
  * every Midas gateway of the markets loaded by `sdk`.
310
294
  *
@@ -336,7 +320,7 @@ async function registerRWAInvestor(props) {
336
320
  });
337
321
  }
338
322
  else if (dsTokens.size > 0) logger?.warn(`securitize: no registry admin, skipping ${dsTokens.size} DSToken(s)`);
339
- const gateways = collectMidasGateways(sdk);
323
+ const gateways = require_dev_midasUtils.collectMidasGateways(sdk);
340
324
  for (const gateway of gateways) try {
341
325
  await greenlistMidasGateway({
342
326
  anvil,
@@ -366,4 +350,3 @@ exports.greenlistMidasGateway = greenlistMidasGateway;
366
350
  exports.registerMidasInvestor = registerMidasInvestor;
367
351
  exports.registerRWAInvestor = registerRWAInvestor;
368
352
  exports.registerSecuritizeInvestor = registerSecuritizeInvestor;
369
- exports.writeAndWait = writeAndWait;
@@ -1,5 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_dev_kycUtils = require("./kycUtils.js");
2
+ const require_onchain_utils_AddressSet = require("../onchain/utils/AddressSet.js");
3
+ const require_onchain_market_adapters_contracts_MidasGatewayAdapterContract = require("../onchain/market/adapters/contracts/MidasGatewayAdapterContract.js");
4
+ require("../onchain/index.js");
3
5
  let viem = require("viem");
4
6
  //#region src/dev/midasUtils.ts
5
7
  /**
@@ -78,30 +80,33 @@ async function unpauseMidasIssuanceVault(props) {
78
80
  value: (0, viem.parseEther)("100")
79
81
  });
80
82
  if (!isPauseAdmin) {
81
- await require_dev_kycUtils.writeAndWait(anvil, {
83
+ await anvil.writeContractSync({
82
84
  account: admin,
83
85
  chain: anvil.chain,
84
86
  address: accessControl,
85
87
  abi: iMidasAccessControlAbi,
86
88
  functionName: "grantRole",
87
- args: [pauseAdminRole, admin]
89
+ args: [pauseAdminRole, admin],
90
+ throwOnReceiptRevert: true
88
91
  });
89
92
  logger?.debug(`midas: granted pause admin role to ${admin}`);
90
93
  }
91
- if (paused) await require_dev_kycUtils.writeAndWait(anvil, {
94
+ if (paused) await anvil.writeContractSync({
92
95
  account: admin,
93
96
  chain: anvil.chain,
94
97
  address: vault,
95
98
  abi: iMidasPausableVaultAbi,
96
- functionName: "unpause"
99
+ functionName: "unpause",
100
+ throwOnReceiptRevert: true
97
101
  });
98
- if (depositInstantPaused) await require_dev_kycUtils.writeAndWait(anvil, {
102
+ if (depositInstantPaused) await anvil.writeContractSync({
99
103
  account: admin,
100
104
  chain: anvil.chain,
101
105
  address: vault,
102
106
  abi: iMidasPausableVaultAbi,
103
107
  functionName: "unpauseFn",
104
- args: [DEPOSIT_INSTANT_SELECTOR]
108
+ args: [DEPOSIT_INSTANT_SELECTOR],
109
+ throwOnReceiptRevert: true
105
110
  });
106
111
  } finally {
107
112
  await anvil.stopImpersonatingAccount({ address: admin });
@@ -117,20 +122,22 @@ async function unpauseMidasIssuanceVault(props) {
117
122
  address: admin,
118
123
  value: (0, viem.parseEther)("100")
119
124
  });
120
- if (paused) await require_dev_kycUtils.writeAndWait(anvil, {
125
+ if (paused) await anvil.writeContractSync({
121
126
  account: admin,
122
127
  chain: anvil.chain,
123
128
  address: vault,
124
129
  abi: iMidasPausableVaultAbi,
125
- functionName: "pause"
130
+ functionName: "pause",
131
+ throwOnReceiptRevert: true
126
132
  });
127
- if (depositInstantPaused) await require_dev_kycUtils.writeAndWait(anvil, {
133
+ if (depositInstantPaused) await anvil.writeContractSync({
128
134
  account: admin,
129
135
  chain: anvil.chain,
130
136
  address: vault,
131
137
  abi: iMidasPausableVaultAbi,
132
138
  functionName: "pauseFn",
133
- args: [DEPOSIT_INSTANT_SELECTOR]
139
+ args: [DEPOSIT_INSTANT_SELECTOR],
140
+ throwOnReceiptRevert: true
134
141
  });
135
142
  } catch (e) {
136
143
  logger?.warn(`midas: failed to pause issuance vault ${vault} back: ${e}`);
@@ -139,5 +146,27 @@ async function unpauseMidasIssuanceVault(props) {
139
146
  }
140
147
  };
141
148
  }
149
+ function* midasGatewayAdapters(sdk) {
150
+ for (const cm of sdk.marketRegister.creditManagers) for (const adapter of cm.creditManager.adapters.values()) if (adapter instanceof require_onchain_market_adapters_contracts_MidasGatewayAdapterContract.MidasGatewayAdapterContract) yield adapter;
151
+ }
152
+ /**
153
+ * Target contracts of all Midas gateway adapters of the loaded credit managers,
154
+ * same as the foundry tests do with `ICreditConfiguratorV3.allowedAdapters`
155
+ */
156
+ function collectMidasGateways(sdk) {
157
+ const gateways = new require_onchain_utils_AddressSet.AddressSet();
158
+ for (const adapter of midasGatewayAdapters(sdk)) gateways.add(adapter.targetContract);
159
+ return gateways.asArray();
160
+ }
161
+ /**
162
+ * mTokens of all Midas gateway adapters of the loaded credit managers
163
+ */
164
+ function collectMidasMTokens(sdk) {
165
+ const mTokens = new require_onchain_utils_AddressSet.AddressSet();
166
+ for (const adapter of midasGatewayAdapters(sdk)) mTokens.add(adapter.mToken);
167
+ return mTokens.asArray();
168
+ }
142
169
  //#endregion
170
+ exports.collectMidasGateways = collectMidasGateways;
171
+ exports.collectMidasMTokens = collectMidasMTokens;
143
172
  exports.unpauseMidasIssuanceVault = unpauseMidasIssuanceVault;
@@ -65,7 +65,7 @@ async function issueDSTokens(props) {
65
65
  const { timestamp } = await anvil.getBlock();
66
66
  const issuanceTime = timestamp - lockPeriod - 1n;
67
67
  try {
68
- const hash = await require_dev_kycUtils.writeAndWait(anvil, {
68
+ const receipt = await anvil.writeContractSync({
69
69
  account,
70
70
  chain: anvil.chain,
71
71
  address: token,
@@ -78,14 +78,15 @@ async function issueDSTokens(props) {
78
78
  0n,
79
79
  "",
80
80
  0n
81
- ]
81
+ ],
82
+ throwOnReceiptRevert: true
82
83
  });
83
84
  logger?.debug({
84
85
  issuanceTime,
85
86
  investor,
86
87
  amount
87
88
  }, "issueTokensCustom successful");
88
- return hash;
89
+ return receipt.transactionHash;
89
90
  } catch (e) {
90
91
  logger?.debug(`issueTokensCustom failed: ${e}`);
91
92
  }
@@ -94,14 +95,15 @@ async function issueDSTokens(props) {
94
95
  investor,
95
96
  amount
96
97
  }, "Falling back to issueTokens");
97
- return require_dev_kycUtils.writeAndWait(anvil, {
98
+ return (await anvil.writeContractSync({
98
99
  account,
99
100
  chain: anvil.chain,
100
101
  address: token,
101
102
  abi: require_abi_rwa_iDSToken.iDSTokenAbi,
102
103
  functionName: "issueTokens",
103
- args: [investor, amount]
104
- });
104
+ args: [investor, amount],
105
+ throwOnReceiptRevert: true
106
+ })).transactionHash;
105
107
  }
106
108
  /**
107
109
  * Resolves unique compliance configuration services of `tokens`: several
@@ -161,13 +163,14 @@ async function enableDSTokenBackDating(props) {
161
163
  continue;
162
164
  }
163
165
  logger?.info(`Allowing back-dating on ${service}`);
164
- await require_dev_kycUtils.writeAndWait(anvil, {
166
+ await anvil.writeContractSync({
165
167
  account,
166
168
  chain: anvil.chain,
167
169
  address: service,
168
170
  abi: iDSComplianceConfigurationServiceAbi,
169
171
  functionName: "setDisallowBackDating",
170
- args: [false]
172
+ args: [false],
173
+ throwOnReceiptRevert: true
171
174
  });
172
175
  toRestore.push(service);
173
176
  }
@@ -177,13 +180,14 @@ async function enableDSTokenBackDating(props) {
177
180
  for (const service of services) {
178
181
  logger?.info(`Disallowing back-dating on ${service}`);
179
182
  try {
180
- await require_dev_kycUtils.writeAndWait(anvil, {
183
+ await anvil.writeContractSync({
181
184
  account,
182
185
  chain: anvil.chain,
183
186
  address: service,
184
187
  abi: iDSComplianceConfigurationServiceAbi,
185
188
  functionName: "setDisallowBackDating",
186
- args: [true]
189
+ args: [true],
190
+ throwOnReceiptRevert: true
187
191
  });
188
192
  } catch (e) {
189
193
  logger?.warn(`Failed to restore disallowBackDating on ${service}: ${e}`);
@@ -205,18 +205,15 @@ async function fulfillMidasRedeemer(anvil, redeemer, logger) {
205
205
  address: MIDAS_VAULT_ADMIN,
206
206
  value: (0, viem.parseEther)("100")
207
207
  });
208
- const hash = await anvil.writeContract({
208
+ await anvil.writeContractSync({
209
209
  chain: anvil.chain,
210
210
  address: midasRedemptionVault,
211
211
  account: MIDAS_VAULT_ADMIN,
212
212
  abi: iMidasRedemptionVaultExtAbi,
213
213
  functionName: "safeApproveRequest",
214
- args: [requestId, mTokenRate]
214
+ args: [requestId, mTokenRate],
215
+ throwOnReceiptRevert: true
215
216
  });
216
- if ((await anvil.waitForTransactionReceipt({
217
- hash,
218
- pollingInterval: 100
219
- })).status !== "success") throw new Error(`midas: safeApproveRequest tx ${hash} reverted`);
220
217
  await anvil.stopImpersonatingAccount({ address: MIDAS_VAULT_ADMIN });
221
218
  }
222
219
  /**
@@ -5,6 +5,7 @@ const require_model_errors_operation_errors = require("./operation-errors.js");
5
5
  const require_model_errors_oracle_errors = require("./oracle-errors.js");
6
6
  const require_model_errors_prepare_errors = require("./prepare-errors.js");
7
7
  const require_model_errors_preview_errors = require("./preview-errors.js");
8
+ exports.accountNotMidasGreenlisted = require_model_errors_operation_errors.accountNotMidasGreenlisted;
8
9
  exports.creditAccountFrozen = require_model_errors_liquidation_errors.creditAccountFrozen;
9
10
  exports.creditAccountNotEmpty = require_model_errors_prepare_errors.creditAccountNotEmpty;
10
11
  exports.creditAccountNotFound = require_model_errors_prepare_errors.creditAccountNotFound;
@@ -28,6 +29,7 @@ exports.poolPaused = require_model_errors_operation_errors.poolPaused;
28
29
  exports.poolSunset = require_model_errors_operation_errors.poolSunset;
29
30
  exports.quotaCountExceeded = require_model_errors_operation_errors.quotaCountExceeded;
30
31
  exports.quotaLimitReached = require_model_errors_operation_errors.quotaLimitReached;
32
+ exports.reservePriceLimited = require_model_errors_operation_errors.reservePriceLimited;
31
33
  exports.rwaOpenRequirementsNotMet = require_model_errors_operation_errors.rwaOpenRequirementsNotMet;
32
34
  exports.unexpectedFailure = require_model_errors_prepare_errors.unexpectedFailure;
33
35
  exports.unpriceableTokenError = require_model_errors_oracle_errors.unpriceableTokenError;
@@ -67,6 +67,14 @@ function insufficientCollateral(args) {
67
67
  ...args
68
68
  };
69
69
  }
70
+ /** {@inheritDoc ReservePriceLimitedError} */
71
+ function reservePriceLimited(args) {
72
+ return {
73
+ code: "reservePriceLimited",
74
+ message: `The reserve price feed values this collateral below what the operation pays out: the account covers its debt at ${args.atMainPrices} on the main feed and only ${args.healthFactor} at the reserve one, below ${args.healthFactorThreshold}.`,
75
+ ...args
76
+ };
77
+ }
70
78
  /** {@inheritDoc ForbiddenTokenError} */
71
79
  function forbiddenToken(token) {
72
80
  return {
@@ -118,7 +126,16 @@ function rwaOpenRequirementsNotMet(args) {
118
126
  ...args
119
127
  };
120
128
  }
129
+ /** {@inheritDoc AccountNotMidasGreenlistedError} */
130
+ function accountNotMidasGreenlisted(args) {
131
+ return {
132
+ code: "accountNotMidasGreenlisted",
133
+ message: `The credit account is not Midas-greenlisted for ${args.token.symbol}.`,
134
+ ...args
135
+ };
136
+ }
121
137
  //#endregion
138
+ exports.accountNotMidasGreenlisted = accountNotMidasGreenlisted;
122
139
  exports.creditManagerPaused = creditManagerPaused;
123
140
  exports.debtOutOfRange = debtOutOfRange;
124
141
  exports.forbiddenToken = forbiddenToken;
@@ -132,4 +149,5 @@ exports.poolPaused = poolPaused;
132
149
  exports.poolSunset = poolSunset;
133
150
  exports.quotaCountExceeded = quotaCountExceeded;
134
151
  exports.quotaLimitReached = quotaLimitReached;
152
+ exports.reservePriceLimited = reservePriceLimited;
135
153
  exports.rwaOpenRequirementsNotMet = rwaOpenRequirementsNotMet;
@@ -50,6 +50,7 @@ exports.SECURITIZE_REGISTER_VAULT_TYPES = require_model_rwa.SECURITIZE_REGISTER_
50
50
  exports.STRATEGY_OPPORTUNITY_CHART_METRICS = require_model_charts.STRATEGY_OPPORTUNITY_CHART_METRICS;
51
51
  exports.STRATEGY_POSITION_CHART_METRICS = require_model_charts.STRATEGY_POSITION_CHART_METRICS;
52
52
  exports.STRATEGY_POSITION_COLLATERAL_ERROR = require_model_positions.STRATEGY_POSITION_COLLATERAL_ERROR;
53
+ exports.accountNotMidasGreenlisted = require_model_errors_operation_errors.accountNotMidasGreenlisted;
53
54
  exports.amountSchema = require_model_primitives_schema.amountSchema;
54
55
  exports.analyticsChartQueryOptionsSchema = require_model_analytics_schema.analyticsChartQueryOptionsSchema;
55
56
  exports.analyticsChartQueryParamsSchema = require_model_analytics_schema.analyticsChartQueryParamsSchema;
@@ -175,6 +176,7 @@ exports.quotaLimitReached = require_model_errors_operation_errors.quotaLimitReac
175
176
  exports.rateCurvePointSchema = require_model_opportunities_schema.rateCurvePointSchema;
176
177
  exports.rateCurveSchema = require_model_opportunities_schema.rateCurveSchema;
177
178
  exports.receivedAssetSchema = require_model_liquidations_schema.receivedAssetSchema;
179
+ exports.reservePriceLimited = require_model_errors_operation_errors.reservePriceLimited;
178
180
  exports.responseMetadataSchema = require_model_response_schema.responseMetadataSchema;
179
181
  exports.responseSchema = require_model_response_schema.responseSchema;
180
182
  exports.rewardsPnLSchema = require_model_positions_schema.rewardsPnLSchema;
@@ -213,7 +213,6 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
213
213
  }),
214
214
  ...callsAfter ?? []
215
215
  ];
216
- calls = await this.#prependMidasReceiveGreenlist(cm.address, calls);
217
216
  calls = await this.prependPriceUpdates(cm.address, calls);
218
217
  const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
219
218
  tx.value = ethAmount.toString(10);
@@ -0,0 +1,139 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
3
+ const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
4
+ require("../../../model/index.js");
5
+ const require_onchain_validation_helpers_token = require("../../validation/helpers/token.js");
6
+ const require_onchain_validation_raise = require("../../validation/raise.js");
7
+ require("../../validation/index.js");
8
+ const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
9
+ const require_onchain_accounts_intents_guards = require("./guards.js");
10
+ const require_onchain_accounts_intents_math = require("./math.js");
11
+ const require_onchain_accounts_intents_utils_credit_account_slice = require("./utils/credit-account-slice.js");
12
+ const require_onchain_accounts_intents_utils_price_impact = require("./utils/price-impact.js");
13
+ const require_onchain_accounts_intents_utils_quotas_for_update = require("./utils/quotas-for-update.js");
14
+ const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
15
+ require("./utils/index.js");
16
+ //#region src/onchain/accounts/intents/borrow.ts
17
+ /**
18
+ * Builds the state a borrow would leave behind.
19
+ *
20
+ * The debt is named rather than derived: a borrow asks for an amount, where an
21
+ * opening asks for a leverage and lets the collateral decide. Everything the
22
+ * loan pays out leaves the account, so the collateral alone backs it — which
23
+ * is what makes the health factor here a straight function of the two amounts.
24
+ *
25
+ * Produces no operation list, as opening never does: the caller hands the
26
+ * numbers and the calls to `sdk.accounts.openCA`, with `withdrawToken` set to
27
+ * the payout.
28
+ */
29
+ async function buildBorrowState(props) {
30
+ const { sdk, creditManager, collateralAmount, borrowAmount, slippage = 0, quotaReserve, creditAccount: existing } = props;
31
+ const suite = sdk.marketRegister.findCreditManager(creditManager);
32
+ const market = sdk.marketRegister.findByCreditManager(creditManager);
33
+ require_onchain_accounts_intents_guards.assertMarketOperable(suite);
34
+ const underlying = market.pool.underlying.toLowerCase();
35
+ const collateralToken = props.collateralToken.toLowerCase();
36
+ const borrowToken = props.borrowToken.toLowerCase();
37
+ const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
38
+ if (require_onchain_accounts_intents_utils_common.eq(collateralToken, borrowToken)) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, collateralToken)), "borrow: the payout token cannot also be the collateral");
39
+ const rwaAsset = sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset?.toLowerCase();
40
+ const unwrapsPayout = !!rwaAsset && require_onchain_accounts_intents_utils_common.eq(borrowToken, rwaAsset);
41
+ if (rwaAsset && require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying)) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, borrowToken)), `borrow: ${underlying} cannot leave the account, ask for the payout in ${rwaAsset}`);
42
+ if (collateralAmount <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "borrow: no collateral supplied");
43
+ if (borrowAmount <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "borrow: nothing to borrow");
44
+ const margin = convert(collateralToken, underlying, collateralAmount);
45
+ if (margin <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "borrow: collateral is worth nothing in underlying");
46
+ const debt = require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying) ? borrowAmount : unwrapsPayout ? require_onchain_accounts_intents_utils_common.toTargetDecimals(borrowAmount, borrowToken, underlying, sdk) : convert(borrowToken, underlying, borrowAmount);
47
+ require_onchain_accounts_intents_math.assertDebtLimits(sdk, debt, suite.creditFacade, underlying);
48
+ require_onchain_accounts_intents_guards.assertCanBorrow(sdk, suite, debt);
49
+ const account = existing ?? require_onchain_accounts_intents_utils_credit_account_slice.unopenedAccountSlice({
50
+ creditManager,
51
+ creditFacade: suite.creditFacade.address,
52
+ underlying
53
+ });
54
+ const leg = require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying) || unwrapsPayout ? void 0 : await require_onchain_accounts_intents_utils_router_path.createRouterPaths({
55
+ sdk,
56
+ creditAccount: account,
57
+ slippage
58
+ }).swap({
59
+ tokenIn: underlying,
60
+ tokenOut: borrowToken,
61
+ amount: debt,
62
+ keep: require_onchain_accounts_intents_utils_common.eq(collateralToken, underlying) ? collateralAmount : 0n
63
+ });
64
+ const unwrap = unwrapsPayout ? await sdk.accounts.assembleRWAUnwrapCalls(debt, creditManager) : void 0;
65
+ if (unwrapsPayout && !unwrap) throw new Error(`borrow: no unwrap calls found for ${borrowToken}`);
66
+ const assets = [{
67
+ token: collateralToken,
68
+ balance: collateralAmount
69
+ }];
70
+ const quotaIncrease = borrowCollateralQuota({
71
+ sdk,
72
+ creditManager,
73
+ assets,
74
+ quotaReserve
75
+ });
76
+ require_onchain_accounts_intents_guards.assertGrowthAllowed({
77
+ sdk,
78
+ suite,
79
+ market,
80
+ before: [],
81
+ after: assets
82
+ });
83
+ require_onchain_accounts_intents_guards.assertQuotaAvailable(sdk, market, quotaIncrease);
84
+ const snapshot = {
85
+ creditManager,
86
+ assets,
87
+ quotas: quotaIncrease,
88
+ totalDebt: debt,
89
+ totalValue: margin
90
+ };
91
+ const projection = sdk.positions.projection(snapshot, { availableLiquidityChange: -debt });
92
+ require_onchain_accounts_intents_guards.assertCollateralised(projection.safeHealthFactor, true);
93
+ const priced = (token, balance) => market.priceOracle.toTokenAmount(token, balance);
94
+ const payout = unwrapsPayout ? require_onchain_accounts_intents_utils_common.toTargetDecimals(debt, underlying, borrowToken, sdk) : leg ? leg.amount : debt;
95
+ return {
96
+ ...projection,
97
+ currentPrice: sdk.positions.currentPrice(snapshot),
98
+ executionCost: void 0,
99
+ priceImpact: await require_onchain_accounts_intents_utils_price_impact.collectPriceImpact(leg?.probe ? [leg.probe] : [], {
100
+ totalValue: margin,
101
+ netValue: margin - debt,
102
+ toUnderlying: (from, amount) => convert(from, underlying, amount)
103
+ }),
104
+ collateral: priced(collateralToken, collateralAmount),
105
+ borrowed: priced(borrowToken, payout),
106
+ minBorrowed: priced(borrowToken, leg ? leg.minAmount : payout),
107
+ slippage,
108
+ quotaIncrease,
109
+ calls: leg ? [...leg.calls] : unwrap ?? [],
110
+ creditAccount: existing?.creditAccount
111
+ };
112
+ }
113
+ /**
114
+ * Quota a borrow buys for its collateral on an account that holds none yet.
115
+ *
116
+ * Shared with `maxBorrow`, because a quota short of the collateral's weighted
117
+ * value is what caps the loan: the two have to read the same number or the
118
+ * ceiling one offers is one the other refuses.
119
+ *
120
+ * @param props - {@link BorrowCollateralQuotaProps}
121
+ **/
122
+ function borrowCollateralQuota({ sdk, creditManager, assets, quotaReserve }) {
123
+ const suite = sdk.marketRegister.findCreditManager(creditManager);
124
+ const market = sdk.marketRegister.findByCreditManager(creditManager);
125
+ return require_onchain_accounts_intents_utils_quotas_for_update.getQuotasForUpdate({
126
+ assetsBefore: [],
127
+ assetsAfter: assets,
128
+ initialQuotas: [],
129
+ quotaReserve,
130
+ underlyingToken: market.pool.underlying,
131
+ liquidationThresholds: suite.creditManager.liquidationThresholds,
132
+ quotas: market.pool.pqk.quotas,
133
+ maxDebt: suite.creditFacade.maxDebt,
134
+ convert: (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value
135
+ }).quotaIncrease;
136
+ }
137
+ //#endregion
138
+ exports.borrowCollateralQuota = borrowCollateralQuota;
139
+ exports.buildBorrowState = buildBorrowState;
@@ -0,0 +1,41 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_utils_bigint_math = require("../../utils/bigint-math.js");
3
+ const require_onchain_constants_math = require("../../constants/math.js");
4
+ require("../../utils/index.js");
5
+ const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
6
+ //#region src/onchain/accounts/intents/collateral-valuation.ts
7
+ /** {@inheritDoc CollateralValuation} */
8
+ function collateralValuation(creditAccount, sdk) {
9
+ const { market, creditManager } = sdk.marketRegister.findCreditManager(creditAccount.creditManager);
10
+ const { priceOracle } = market;
11
+ const { pqk } = market.pool;
12
+ const underlying = market.pool.underlying;
13
+ const masked = creditAccount.enabledTokensMask !== 0n;
14
+ const mainUsd = (token, amount) => {
15
+ try {
16
+ return priceOracle.convertToUSD(token, amount);
17
+ } catch {
18
+ return;
19
+ }
20
+ };
21
+ const lt = (token) => BigInt(creditManager.liquidationThresholds.get(token) ?? 0);
22
+ const checkedUsd = (holding) => require_onchain_accounts_intents_utils_common.eq(holding.token, underlying) ? mainUsd(holding.token, holding.balance) ?? 0n : priceOracle.safeConvertMinUSD(holding.token, holding.balance).value;
23
+ /** A quota is underlying-denominated, and a closed market backs nothing. */
24
+ const quotaValue = (holding) => pqk.hasActiveQuota(holding.token) ? (mainUsd(underlying, holding.quota) ?? 0n) * require_onchain_constants_math.PERCENTAGE_FACTOR : 0n;
25
+ const weigh = (holding) => {
26
+ const weighted = checkedUsd(holding) * lt(holding.token);
27
+ if (holding.quota === 0n) return weighted;
28
+ return require_onchain_utils_bigint_math.BigIntMath.min(quotaValue(holding), weighted);
29
+ };
30
+ return {
31
+ underlying,
32
+ counts: (holding) => holding.balance > 10n && (!masked || (holding.mask & creditAccount.enabledTokensMask) !== 0n),
33
+ weigh,
34
+ quotaValue,
35
+ mainUsd,
36
+ checkedUsd,
37
+ lt
38
+ };
39
+ }
40
+ //#endregion
41
+ exports.collateralValuation = collateralValuation;
@@ -7,6 +7,7 @@ const require_onchain_validation_checks_checkCreditManagerPaused = require("../.
7
7
  const require_onchain_validation_checks_checkForbiddenToken = require("../../validation/checks/checkForbiddenToken.js");
8
8
  const require_onchain_validation_checks_checkMarketExpired = require("../../validation/checks/checkMarketExpired.js");
9
9
  const require_onchain_validation_checks_checkQuotaLimit = require("../../validation/checks/checkQuotaLimit.js");
10
+ const require_onchain_validation_checks_checkReservePriceLimited = require("../../validation/checks/checkReservePriceLimited.js");
10
11
  const require_onchain_validation_raise = require("../../validation/raise.js");
11
12
  require("../../validation/index.js");
12
13
  const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
@@ -112,13 +113,24 @@ function assertGrowthAllowed(args) {
112
113
  * whose reserve feed the SDK cannot read keeps its main price, so a plan can
113
114
  * still be refused on-chain after passing here.
114
115
  */
115
- function assertCollateralised(healthFactorBps, safePrices) {
116
+ function assertCollateralised(healthFactorBps, safePrices, atSafePrices) {
116
117
  const healthFactorThreshold = require_onchain_validation_helpers_health_factor_limits.MIN_HEALTH_FACTOR_FACADE;
117
- require_onchain_validation_raise.raise(require_onchain_validation_checks_checkCollateralised.checkCollateralised({
118
+ const errors = require_onchain_validation_checks_checkCollateralised.checkCollateralised({
118
119
  healthFactor: healthFactorBps,
119
120
  healthFactorThreshold,
120
121
  safePrices
121
- }), `the account would end at a health factor of ${healthFactorBps}, below ${healthFactorThreshold}`);
122
+ });
123
+ if (errors.length === 0) return;
124
+ if (safePrices && atSafePrices) {
125
+ const { atMainPrices, withdrawable } = atSafePrices();
126
+ require_onchain_validation_raise.raise(require_onchain_validation_checks_checkReservePriceLimited.checkReservePriceLimited({
127
+ healthFactor: healthFactorBps,
128
+ atMainPrices,
129
+ healthFactorThreshold,
130
+ withdrawable
131
+ }), `the account covers its debt at ${atMainPrices} on the main feed and only ${healthFactorBps} at the reserve one, below ${healthFactorThreshold}`);
132
+ }
133
+ require_onchain_validation_raise.raise(errors, `the account would end at a health factor of ${healthFactorBps}, below ${healthFactorThreshold}`);
122
134
  }
123
135
  /**
124
136
  * A quota can only be raised as far as the market still has room for: past the