@gearbox-protocol/sdk 17.13.0-next.2 → 17.13.0-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/cjs/model/errors/index.js +3 -0
  2. package/dist/cjs/model/errors/operation-errors.js +27 -0
  3. package/dist/cjs/model/index.js +3 -0
  4. package/dist/cjs/onchain/accounts/intents/index.js +1 -0
  5. package/dist/cjs/onchain/accounts/intents/operations.js +1 -1
  6. package/dist/cjs/onchain/accounts/intents/plan.js +21 -0
  7. package/dist/cjs/onchain/accounts/intents/realize.js +29 -7
  8. package/dist/cjs/onchain/accounts/intents/resolveQuotaUpdate.js +146 -0
  9. package/dist/cjs/onchain/accounts/intents/tests/update-quota.fixtures.js +102 -0
  10. package/dist/cjs/onchain/accounts/intents/utils/index.js +1 -0
  11. package/dist/cjs/onchain/accounts/intents/utils/quotas-for-update.js +28 -10
  12. package/dist/cjs/onchain/constants/index.js +1 -0
  13. package/dist/cjs/onchain/constants/math.js +6 -0
  14. package/dist/cjs/onchain/index.js +9 -0
  15. package/dist/cjs/onchain/positions/calcHealthFactor.js +1 -1
  16. package/dist/cjs/onchain/preview/preview/CreditAccountState.js +4 -2
  17. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +2 -0
  18. package/dist/cjs/onchain/validation/bundles/checkQuotaUpdates.js +45 -0
  19. package/dist/cjs/onchain/validation/bundles/index.js +2 -0
  20. package/dist/cjs/onchain/validation/checks/checkMaxQuota.js +18 -0
  21. package/dist/cjs/onchain/validation/checks/checkQuotaActive.js +10 -0
  22. package/dist/cjs/onchain/validation/checks/checkQuotaChange.js +18 -0
  23. package/dist/cjs/onchain/validation/checks/index.js +6 -0
  24. package/dist/cjs/onchain/validation/index.js +8 -0
  25. package/dist/cjs/sdk/prepare/PrepareApi.js +10 -0
  26. package/dist/esm/dev/AccountOpener.js +1 -1
  27. package/dist/esm/dev/withdrawalUtils.js +1 -1
  28. package/dist/esm/history/trace/extractTransfers.js +1 -1
  29. package/dist/esm/model/errors/index.js +2 -2
  30. package/dist/esm/model/errors/operation-errors.js +25 -1
  31. package/dist/esm/model/index.js +2 -2
  32. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  33. package/dist/esm/onchain/accounts/intents/index.js +2 -1
  34. package/dist/esm/onchain/accounts/intents/operations.js +1 -1
  35. package/dist/esm/onchain/accounts/intents/plan.js +22 -2
  36. package/dist/esm/onchain/accounts/intents/realize.js +29 -7
  37. package/dist/esm/onchain/accounts/intents/resolveQuotaUpdate.js +145 -0
  38. package/dist/esm/onchain/accounts/intents/tests/update-quota.fixtures.js +92 -0
  39. package/dist/esm/onchain/accounts/intents/utils/index.js +2 -2
  40. package/dist/esm/onchain/accounts/intents/utils/quotas-for-update.js +28 -11
  41. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  42. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  43. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  44. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  45. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  46. package/dist/esm/onchain/base/TokensMeta.js +3 -3
  47. package/dist/esm/onchain/constants/index.js +2 -2
  48. package/dist/esm/onchain/constants/math.js +6 -1
  49. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  50. package/dist/esm/onchain/index.js +6 -2
  51. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  52. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  53. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  54. package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
  55. package/dist/esm/onchain/market/rwa/createDegenNFT.js +1 -1
  56. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  57. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  58. package/dist/esm/onchain/positions/calcHealthFactor.js +1 -1
  59. package/dist/esm/onchain/preview/preview/CreditAccountState.js +4 -2
  60. package/dist/esm/onchain/preview/preview/previewPoolPositionOperation.js +2 -2
  61. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  62. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +2 -0
  63. package/dist/esm/onchain/validation/bundles/checkQuotaUpdates.js +44 -0
  64. package/dist/esm/onchain/validation/bundles/index.js +2 -1
  65. package/dist/esm/onchain/validation/checks/checkMaxQuota.js +17 -0
  66. package/dist/esm/onchain/validation/checks/checkQuotaActive.js +9 -0
  67. package/dist/esm/onchain/validation/checks/checkQuotaChange.js +17 -0
  68. package/dist/esm/onchain/validation/checks/index.js +4 -1
  69. package/dist/esm/onchain/validation/index.js +5 -1
  70. package/dist/esm/sdk/prepare/PrepareApi.js +10 -0
  71. package/dist/types/model/errors/index.d.ts +2 -2
  72. package/dist/types/model/errors/operation-errors.d.ts +39 -1
  73. package/dist/types/model/index.d.ts +2 -2
  74. package/dist/types/onchain/accounts/index.d.ts +2 -2
  75. package/dist/types/onchain/accounts/intents/index.d.ts +2 -2
  76. package/dist/types/onchain/accounts/intents/operations.d.ts +9 -3
  77. package/dist/types/onchain/accounts/intents/plan.d.ts +19 -2
  78. package/dist/types/onchain/accounts/intents/resolveQuotaUpdate.d.ts +34 -0
  79. package/dist/types/onchain/accounts/intents/tests/update-quota.fixtures.d.ts +49 -0
  80. package/dist/types/onchain/accounts/intents/types.d.ts +19 -2
  81. package/dist/types/onchain/accounts/intents/utils/index.d.ts +2 -2
  82. package/dist/types/onchain/accounts/intents/utils/quotas-for-update.d.ts +23 -5
  83. package/dist/types/onchain/constants/index.d.ts +2 -2
  84. package/dist/types/onchain/constants/math.d.ts +6 -1
  85. package/dist/types/onchain/index.d.ts +7 -3
  86. package/dist/types/onchain/preview/preview/CreditAccountState.d.ts +2 -1
  87. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +2 -2
  88. package/dist/types/onchain/validation/bundles/checkQuotaUpdates.d.ts +16 -0
  89. package/dist/types/onchain/validation/bundles/index.d.ts +2 -1
  90. package/dist/types/onchain/validation/checks/checkMaxQuota.d.ts +16 -0
  91. package/dist/types/onchain/validation/checks/checkQuotaActive.d.ts +13 -0
  92. package/dist/types/onchain/validation/checks/checkQuotaChange.d.ts +17 -0
  93. package/dist/types/onchain/validation/checks/index.d.ts +4 -1
  94. package/dist/types/onchain/validation/index.d.ts +5 -1
  95. package/dist/types/onchain/validation/raise.d.ts +2 -2
  96. package/dist/types/sdk/execute/types.d.ts +1 -1
  97. package/dist/types/sdk/index.d.ts +2 -2
  98. package/dist/types/sdk/prepare/PrepareApi.d.ts +6 -2
  99. package/dist/types/sdk/prepare/index.d.ts +2 -2
  100. package/dist/types/sdk/prepare/types.d.ts +22 -2
  101. package/package.json +1 -1
@@ -0,0 +1,92 @@
1
+ import { MIN_INT96 } from "../../../constants/math.js";
2
+ import { ANY, buildFixtureCreditAccount, buildMarketSdk, caToken, valueInUnd } from "../testing/market.js";
3
+ //#region src/onchain/accounts/intents/tests/update-quota.fixtures.ts
4
+ /**
5
+ * Start update-quota fixtures.
6
+ *
7
+ * The account holds 1000 UND and 2000 ANY (another 1000 UND) against 500 UND of
8
+ * debt. Nothing moves, so every case is a single `changeQuota` and the totals
9
+ * stand still.
10
+ */
11
+ const BASE_UND = 100000000000n;
12
+ const BALANCE_ANY = 2000000000000000000000n;
13
+ const DEBT = 50000000000n;
14
+ /** What 2000 ANY is sized to: 1000 UND × 92%. */
15
+ const SIZED_ANY = 92000000000n;
16
+ const TOTAL_VALUE = BASE_UND + valueInUnd(BALANCE_ANY, ANY);
17
+ /** Omitted quota on an unquoted balance: bought at balance × LT. */
18
+ const case_auto_increase = {
19
+ intent: {
20
+ type: "UPDATE_QUOTA",
21
+ token: ANY
22
+ },
23
+ current: 0n,
24
+ ops: [{
25
+ type: "changeQuota",
26
+ quotaIncrease: [{
27
+ token: ANY,
28
+ balance: SIZED_ANY
29
+ }],
30
+ quotaDecrease: [],
31
+ desiredQuota: {}
32
+ }],
33
+ quotaAfter: SIZED_ANY,
34
+ minQuota: 10000n
35
+ };
36
+ /** A lower target: the quota drops to exactly it. */
37
+ const case_target_decrease = {
38
+ intent: {
39
+ type: "UPDATE_QUOTA",
40
+ token: ANY,
41
+ quota: 40000000000n
42
+ },
43
+ current: SIZED_ANY,
44
+ ops: [{
45
+ type: "changeQuota",
46
+ quotaIncrease: [],
47
+ quotaDecrease: [{
48
+ token: ANY,
49
+ balance: 40000000000n - SIZED_ANY
50
+ }],
51
+ desiredQuota: {}
52
+ }],
53
+ quotaAfter: 40000000000n,
54
+ minQuota: 40000000000n
55
+ };
56
+ /** Target 0: the quota is reset with the sentinel. */
57
+ const case_target_disable = {
58
+ intent: {
59
+ type: "UPDATE_QUOTA",
60
+ token: ANY,
61
+ quota: 0n
62
+ },
63
+ current: SIZED_ANY,
64
+ ops: [{
65
+ type: "changeQuota",
66
+ quotaIncrease: [],
67
+ quotaDecrease: [{
68
+ token: ANY,
69
+ balance: MIN_INT96
70
+ }],
71
+ desiredQuota: {}
72
+ }],
73
+ quotaAfter: 0n,
74
+ minQuota: 0n
75
+ };
76
+ function buildUpdateQuotaSdk(c) {
77
+ return buildMarketSdk(c.extras);
78
+ }
79
+ function buildUpdateQuotaProps(c, sdk) {
80
+ return {
81
+ intent: c.intent,
82
+ creditAccount: buildFixtureCreditAccount({
83
+ totalDebt: c.totalDebt ?? 50000000000n,
84
+ tokens: [...c.others ?? [caToken("0x3333333333333333333333333333333333333333", 100000000000n)], caToken(ANY, BALANCE_ANY, c.current)]
85
+ }),
86
+ sdk,
87
+ quotaReserve: void 0,
88
+ slippage: void 0
89
+ };
90
+ }
91
+ //#endregion
92
+ export { BALANCE_ANY, BASE_UND, DEBT, SIZED_ANY, TOTAL_VALUE, buildUpdateQuotaProps, buildUpdateQuotaSdk, case_auto_increase, case_target_decrease, case_target_disable };
@@ -6,6 +6,6 @@ import { calcBorrowedAmountPlusInterestAndFees } from "./borrowed-amount-plus-in
6
6
  import { fetchCreditAccountSlice, toCreditAccountSlice, unopenedAccountSlice } from "./credit-account-slice.js";
7
7
  import { OperationLedger } from "./ledger.js";
8
8
  import { collectPriceImpact, lossRate, startProbe } from "./price-impact.js";
9
- import { clearedQuotas, getQuotasForUpdate, quotaIncreaseLimit, quotasAfterUpdate, withDirectTransferQuota } from "./quotas-for-update.js";
9
+ import { clearedQuotas, getQuotasForUpdate, quotaIncreaseLimit, quotasAfterUpdate, resizedQuota, withDirectTransferQuota } from "./quotas-for-update.js";
10
10
  import { createOraclePaths, createRouterPaths } from "./router-path.js";
11
- export { OperationLedger, adjustStateToSnapshot, assembleOperationCalls, calcBorrowedAmountPlusInterestAndFees, clearedQuotas, collectPriceImpact, createOraclePaths, createRouterPaths, eq, fetchCreditAccountSlice, getQuotasForUpdate, isPhantomToken, isRedemptionPhantomToken, lossRate, pickFattestNonPhantomToken, quotaIncreaseLimit, quotasAfterUpdate, rankAccountTokens, resolveCreditManager, startProbe, toCreditAccountSlice, toRouterCaSlice, toTargetDecimals, unopenedAccountSlice, withDirectTransferQuota };
11
+ export { OperationLedger, adjustStateToSnapshot, assembleOperationCalls, calcBorrowedAmountPlusInterestAndFees, clearedQuotas, collectPriceImpact, createOraclePaths, createRouterPaths, eq, fetchCreditAccountSlice, getQuotasForUpdate, isPhantomToken, isRedemptionPhantomToken, lossRate, pickFattestNonPhantomToken, quotaIncreaseLimit, quotasAfterUpdate, rankAccountTokens, resizedQuota, resolveCreditManager, startProbe, toCreditAccountSlice, toRouterCaSlice, toTargetDecimals, unopenedAccountSlice, withDirectTransferQuota };
@@ -4,17 +4,28 @@ import { TypedObjectUtils } from "../../../utils/mappers.js";
4
4
  import "../../../constants/index.js";
5
5
  import { DIRECT_TRANSFERS_QUOTA, calcQuotaUpdate, maxAmountForQuota, roundUpQuota } from "../../quota-utils.js";
6
6
  //#region src/onchain/accounts/intents/utils/quotas-for-update.ts
7
- function getQuotasForUpdate({ assetsBefore, assetsAfter, initialQuotas, quotaReserve = 0, liquidationThresholds: liquidationThresholdsMap, quotas: quotasMap, maxDebt, underlyingToken, convert }) {
7
+ function getQuotasForUpdate(props) {
8
+ const assetsAfterLc = lowercased(props.assetsAfter);
9
+ const { spend, obtain } = collectQuotaChange(lowercased(props.assetsBefore), assetsAfterLc);
10
+ return sizeQuotas(assetsAfterLc, spend, obtain, props);
11
+ }
12
+ /**
13
+ * The update that sizes one token's quota to the balance the account holds of
14
+ * it, whatever moved.
15
+ *
16
+ * Sits beside {@link getQuotasForUpdate} because that one only resizes what an
17
+ * operation spent or obtained, and an operation that changes a quota alone
18
+ * moves no balance at all.
19
+ */
20
+ function resizedQuota(props) {
21
+ const entry = [{
22
+ token: props.token.toLowerCase(),
23
+ balance: 0n
24
+ }];
25
+ return sizeQuotas(lowercased(props.assets), entry, entry, props);
26
+ }
27
+ function sizeQuotas(assetsAfterLc, spend, obtain, { initialQuotas, quotaReserve = 0, liquidationThresholds: liquidationThresholdsMap, quotas: quotasMap, maxDebt, underlyingToken, convert }) {
8
28
  const underlyingTokenLc = underlyingToken.toLowerCase();
9
- const assetsBeforeLc = assetsBefore.map((a) => ({
10
- ...a,
11
- token: a.token.toLowerCase()
12
- }));
13
- const assetsAfterLc = assetsAfter.map((a) => ({
14
- ...a,
15
- token: a.token.toLowerCase()
16
- }));
17
- const { spend, obtain } = collectQuotaChange(assetsBeforeLc, assetsAfterLc);
18
29
  const initialQuotasLc = initialQuotas.map((a) => {
19
30
  const tokenLc = a.token.toLowerCase();
20
31
  return [tokenLc, {
@@ -130,6 +141,12 @@ function quotasAfterUpdate(initialQuotas, desiredQuota) {
130
141
  else delete after[token];
131
142
  return after;
132
143
  }
144
+ function lowercased(assets) {
145
+ return assets.map((a) => ({
146
+ ...a,
147
+ token: a.token.toLowerCase()
148
+ }));
149
+ }
133
150
  function collectQuotaChange(assetsBefore, assetsAfter) {
134
151
  const before = new Map(assetsBefore.map((a) => [a.token, a.balance]));
135
152
  const after = new Map(assetsAfter.map((a) => [a.token, a.balance]));
@@ -233,4 +250,4 @@ function quotaIncreaseLimit({ suite, token, balance, initialQuotas, quotaReserve
233
250
  return { value: increaseResult.value - (purchaseValue.value >= excessTokenIncrease ? 1n : 0n) };
234
251
  }
235
252
  //#endregion
236
- export { clearedQuotas, getQuotasForUpdate, quotaIncreaseLimit, quotasAfterUpdate, withDirectTransferQuota };
253
+ export { clearedQuotas, getQuotasForUpdate, quotaIncreaseLimit, quotasAfterUpdate, resizedQuota, withDirectTransferQuota };
@@ -1,3 +1,4 @@
1
+ import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
1
2
  import { AddressSet } from "../../utils/AddressSet.js";
2
3
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
3
4
  import { ADDRESS_0X0 } from "../../constants/addresses.js";
@@ -19,7 +20,6 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
19
20
  import "../../market/rwa/securitize/index.js";
20
21
  import "../../market/index.js";
21
22
  import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
22
- import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
23
23
  import { optimalPartialLiquidation, partialLiquidationParams } from "./partialLiquidation.js";
24
24
  import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
25
25
  //#region src/onchain/accounts/liquidations/LiquidationsService.ts
@@ -1,9 +1,9 @@
1
+ import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
1
2
  import { BaseContract } from "../../base/BaseContract.js";
2
3
  import "../../base/index.js";
3
4
  import { sdkErr, sdkOk } from "../../../model/result.js";
4
5
  import "../../../model/index.js";
5
6
  import { decodeDelayedIntent } from "./intent-codec.js";
6
- import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
7
7
  //#region src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
8
8
  const abi = iRedemptionLoggerV310Abi;
9
9
  /**
@@ -1,5 +1,5 @@
1
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
1
  import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
2
+ import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
3
3
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
4
4
  const abi = iWithdrawalCompressorV310Abi;
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
1
  import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
2
+ import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
3
3
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
4
4
  const abi = iWithdrawalCompressorV311Abi;
5
5
  /**
@@ -1,6 +1,6 @@
1
+ import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
1
2
  import { encodeDelayedIntent } from "./intent-codec.js";
2
3
  import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
3
- import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
4
4
  import { toWithdrawalStatus } from "./types.js";
5
5
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
6
6
  const abi = iWithdrawalCompressorV313Abi;
@@ -1,12 +1,12 @@
1
+ import { iExpirableAbi } from "../../abi/iExpirable.js";
2
+ import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
3
+ import { iVersionAbi } from "../../abi/iVersion.js";
1
4
  import { AddressMap } from "../utils/AddressMap.js";
2
5
  import { AddressSet } from "../utils/AddressSet.js";
3
6
  import { bytes32ToString } from "../utils/bytes32ToString.js";
4
7
  import { getAssetType } from "../chain/chains.js";
5
8
  import { formatBN } from "../utils/formatter.js";
6
9
  import "../utils/index.js";
7
- import { iExpirableAbi } from "../../abi/iExpirable.js";
8
- import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
9
- import { iVersionAbi } from "../../abi/iVersion.js";
10
10
  import { SdkRWADataNotLoadedError } from "../core/errors.js";
11
11
  import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
12
12
  //#region src/onchain/base/TokensMeta.ts
@@ -1,8 +1,8 @@
1
1
  import { ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, NO_VERSION } from "./address-provider.js";
2
2
  import { ADDRESS_0X0, MULTICALL_ADDRESS, NATIVE_ADDRESS, NOT_DEPLOYED } from "./addresses.js";
3
3
  import { BotPermissions, botPermissionsToString } from "./bot-permissions.js";
4
- import { DUST_THRESHOLD, LEVERAGE_DECIMALS, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PRICE_DECIMALS, PRICE_DECIMALS_POW, RAY, RAY_DECIMALS_POW, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, WAD, WAD_DECIMALS_POW, halfRAY, isZeroBalance } from "./math.js";
4
+ import { DUST_THRESHOLD, LEVERAGE_DECIMALS, MAX_INT, MAX_QUOTA_MULTIPLIER, MAX_UINT16, MAX_UINT256, MIN_INT96, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PRICE_DECIMALS, PRICE_DECIMALS_POW, RAY, RAY_DECIMALS_POW, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, WAD, WAD_DECIMALS_POW, halfRAY, isZeroBalance } from "./math.js";
5
5
  import { BLOCKS_PER_WEEK_BY_NETWORK, RAMP_DURATION_BY_NETWORK } from "./networks.js";
6
6
  import { PERIPHERY_CONTRACTS } from "./periphery.js";
7
7
  import { VERSION_RANGE_310, isV310, isVersionRange } from "./versions.js";
8
- export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, BLOCKS_PER_WEEK_BY_NETWORK, BotPermissions, DUST_THRESHOLD, LEVERAGE_DECIMALS, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, NATIVE_ADDRESS, NOT_DEPLOYED, NO_VERSION, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PRICE_DECIMALS, PRICE_DECIMALS_POW, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, VERSION_RANGE_310, WAD, WAD_DECIMALS_POW, botPermissionsToString, halfRAY, isV310, isVersionRange, isZeroBalance };
8
+ export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, BLOCKS_PER_WEEK_BY_NETWORK, BotPermissions, DUST_THRESHOLD, LEVERAGE_DECIMALS, MAX_INT, MAX_QUOTA_MULTIPLIER, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, NATIVE_ADDRESS, NOT_DEPLOYED, NO_VERSION, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PRICE_DECIMALS, PRICE_DECIMALS_POW, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, VERSION_RANGE_310, WAD, WAD_DECIMALS_POW, botPermissionsToString, halfRAY, isV310, isVersionRange, isZeroBalance };
@@ -17,6 +17,11 @@ const PERCENTAGE_FACTOR_1KK = PERCENTAGE_FACTOR * PERCENTAGE_DECIMALS;
17
17
  const LEVERAGE_DECIMALS = 100n;
18
18
  const SLIPPAGE_DECIMALS = 100n;
19
19
  /**
20
+ * The facade's `maxQuotaMultiplier`: a token's quota may not exceed this many
21
+ * times `maxDebt`. A constant on-chain, so it is not read.
22
+ **/
23
+ const MAX_QUOTA_MULTIPLIER = 2n;
24
+ /**
20
25
  * Token balances at or below this threshold are treated as dust and ignored.
21
26
  **/
22
27
  const DUST_THRESHOLD = 10n;
@@ -31,4 +36,4 @@ function isZeroBalance(balance) {
31
36
  return (balance ?? 0n) <= DUST_THRESHOLD;
32
37
  }
33
38
  //#endregion
34
- export { DUST_THRESHOLD, LEVERAGE_DECIMALS, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PRICE_DECIMALS, PRICE_DECIMALS_POW, RAY, RAY_DECIMALS_POW, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, WAD, WAD_DECIMALS_POW, halfRAY, isZeroBalance };
39
+ export { DUST_THRESHOLD, LEVERAGE_DECIMALS, MAX_INT, MAX_QUOTA_MULTIPLIER, MAX_UINT16, MAX_UINT256, MIN_INT96, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PRICE_DECIMALS, PRICE_DECIMALS_POW, RAY, RAY_DECIMALS_POW, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, WAD, WAD_DECIMALS_POW, halfRAY, isZeroBalance };
@@ -1,8 +1,8 @@
1
+ import { iVersionAbi } from "../../abi/iVersion.js";
1
2
  import "../constants/address-provider.js";
2
3
  import { isV310 } from "../constants/versions.js";
3
4
  import "../constants/index.js";
4
5
  import { hexEq } from "../utils/hex.js";
5
- import { iVersionAbi } from "../../abi/iVersion.js";
6
6
  import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
7
7
  //#region src/onchain/core/createAddressProvider.ts
8
8
  const OVERRIDE_ADDRESSES = {};
@@ -14,7 +14,7 @@ import { etherscanApiUrl, etherscanUrl } from "./utils/etherscan.js";
14
14
  import { ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, NO_VERSION } from "./constants/address-provider.js";
15
15
  import { ADDRESS_0X0, MULTICALL_ADDRESS, NATIVE_ADDRESS, NOT_DEPLOYED } from "./constants/addresses.js";
16
16
  import { BotPermissions, botPermissionsToString } from "./constants/bot-permissions.js";
17
- import { DUST_THRESHOLD, LEVERAGE_DECIMALS, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PRICE_DECIMALS, PRICE_DECIMALS_POW, RAY, RAY_DECIMALS_POW, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, WAD, WAD_DECIMALS_POW, halfRAY, isZeroBalance } from "./constants/math.js";
17
+ import { DUST_THRESHOLD, LEVERAGE_DECIMALS, MAX_INT, MAX_QUOTA_MULTIPLIER, MAX_UINT16, MAX_UINT256, MIN_INT96, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PRICE_DECIMALS, PRICE_DECIMALS_POW, RAY, RAY_DECIMALS_POW, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, WAD, WAD_DECIMALS_POW, halfRAY, isZeroBalance } from "./constants/math.js";
18
18
  import { TypedObjectUtils } from "./utils/mappers.js";
19
19
  import { BLOCKS_PER_WEEK_BY_NETWORK, RAMP_DURATION_BY_NETWORK } from "./constants/networks.js";
20
20
  import { PERIPHERY_CONTRACTS } from "./constants/periphery.js";
@@ -211,9 +211,12 @@ import { checkForbiddenToken } from "./validation/checks/checkForbiddenToken.js"
211
211
  import { checkLeverage } from "./validation/checks/checkLeverage.js";
212
212
  import { checkLiquidatorEligible } from "./validation/checks/checkLiquidatorEligible.js";
213
213
  import { checkMarketExpired } from "./validation/checks/checkMarketExpired.js";
214
+ import { checkMaxQuota } from "./validation/checks/checkMaxQuota.js";
214
215
  import { checkPoolLiquidity } from "./validation/checks/checkPoolLiquidity.js";
215
216
  import { checkPoolPaused } from "./validation/checks/checkPoolPaused.js";
216
217
  import { checkPoolSunset } from "./validation/checks/checkPoolSunset.js";
218
+ import { checkQuotaActive } from "./validation/checks/checkQuotaActive.js";
219
+ import { checkQuotaChange } from "./validation/checks/checkQuotaChange.js";
217
220
  import { checkQuotaCount } from "./validation/checks/checkQuotaCount.js";
218
221
  import { checkQuotaLimit } from "./validation/checks/checkQuotaLimit.js";
219
222
  import { checkReservePriceLimited } from "./validation/checks/checkReservePriceLimited.js";
@@ -226,6 +229,7 @@ import { checkIncreaseDebt } from "./validation/bundles/checkIncreaseDebt.js";
226
229
  import { checkIncreaseQuota } from "./validation/bundles/checkIncreaseQuota.js";
227
230
  import { checkMarket } from "./validation/bundles/checkMarket.js";
228
231
  import { checkObtained } from "./validation/bundles/checkObtained.js";
232
+ import { checkQuotaUpdates } from "./validation/bundles/checkQuotaUpdates.js";
229
233
  import { checkMidasAccountGreenlist } from "./validation/bundles/checkMidasAccountGreenlist.js";
230
234
  import { checkRWAOpenRequirements } from "./validation/bundles/checkRWAOpenRequirements.js";
231
235
  import { checkRWAOpening } from "./validation/bundles/checkRWAOpening.js";
@@ -306,4 +310,4 @@ import { replayMulticall } from "./preview/preview/replayMulticall.js";
306
310
  import { previewOperation } from "./preview/preview/previewOperation.js";
307
311
  import "./preview/index.js";
308
312
  import "./types/index.js";
309
- export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractAdapterContract, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AccountBotsService, AccountMigratorAdapterContract, AdapterType, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerV3PoolStatus, BalancerV3RouterAdapterContract, BalancerV3WrapperAdapterContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, CamelotV3AdapterContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, ConstantPriceFeedContract, Construct, ContractParseError, ConvexV1BaseRewardPoolAdapterContract, ConvexV1BoosterAdapterContract, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountState, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CreditSuiteStrategy, Curve2AssetsAdapterContract, Curve3AssetsAdapterContract, Curve4AssetsAdapterContract, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, CurveV1AdapterStETHContract, CurveV1StableNGAdapterContract, DEFAULT_QUOTA_BUFFER_BPS, DEGEN_NFT_MIDAS, DEGEN_NFT_SECURITIZE, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DIRECT_TRANSFERS_QUOTA, DUST_THRESHOLD, DaiUsdsAdapterContract, ERC4626AdapterContract, ERC4626ReferralAdapterContract, EXECUTE_BYTES_SELECTOR, Erc4626PriceFeedContract, ExternalPriceFeedContract, FluidDexAdapterContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InfinifiGatewayAdapterContract, InfinifiUnwindingGatewayAdapterContract, KelpLRTDepositPoolAdapterContract, KelpLRTWithdrawalManagerAdapterContract, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LidoV1AdapterContract, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_LEVERAGE_BUFFER_BPS, MAX_UINT16, MAX_UINT256, MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_INT96, MIN_SAFE_HEALTH_FACTOR_FORM, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowClaimerAdapterContract, MellowDVVAdapterContract, MellowERC4626VaultAdapterContract, MellowLRTPriceFeedContract, MellowWrapperAdapterContract, MidasDegenNFT, MidasGatewayAdapterContract, MidasIssuanceVaultAdapterContract, MidasLiquidatorContract, MidasRedemptionVaultAdapterContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, NON_STRATEGY_PHANTOM_TOKEN_TYPES, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendlePairStatus, PendleRouterAdapterContract, PendleTWAPPTPriceFeed, PendleTokenType, PeripheryCompressorV310Contract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegistry, PriceOracleV310Contract, PriceUpdatesCache, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_COMPRESSOR_ADDRESS, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkRWADataNotLoadedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeDegenNFT, SecuritizeLiquidatorContract, SecuritizeOnRampAdapterContract, SecuritizeRWAFactory, SecuritizeRedemptionGatewayAdapterContract, SimulateWithPriceUpdatesError, SimulationError, StakingRewardsAdapterContract, TokensMeta, TraderJoePoolVersion, TraderJoeRouterAdapterContract, TypedObjectUtils, UniswapV2AdapterContract, UniswapV3AdapterContract, UniswapV4AdapterContract, UpdatablePriceFeedRegistry, UpshiftVaultAdapterContract, VERSION_RANGE_310, VelodromeV2RouterAdapterContract, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, WstETHV1AdapterContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodBigInt, ZodHex, accountSnapshotFromCreditAccountData, adapterActionAbi, adapterActionSelectors, adapterActionSignatures, adapterConstructorAbi, allTransfersAsTokenAmounts, amountOf, assetsMap, attachOptionsSchema, botPermissionsToString, bpsToRay, buildDelayedStrategyPositionOperationPreview, bytes32ToString, calcBorrowApy, calcBorrowRate, calcDefaultQuota, calcEffectiveBorrowApy, calcHealthFactor, calcLiquidationPrice, calcLiquidationPriceForTarget, calcMaxLeverage, calcNetStrategyApy, calcPositionLeverage, calcQuotaRate, calcQuotaUpdate, calcRecommendedQuota, calcTimeToLiquidationMs, calcUtilization, calcUtilizationRaw, chains, checkAccountQuotas, checkBorrowLimit, checkCollateralFunding, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkCreditOperation, checkDebtLimits, checkEmergencyLiquidator, checkForbiddenToken, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLeverage, checkLiquidation, checkLiquidationEligibility, checkLiquidationFunding, checkLiquidatorEligible, checkMarket, checkMarketExpired, checkMidasAccountGreenlist, checkObtained, checkOperation, checkPoolFunding, checkPoolLiquidity, checkPoolOperation, checkPoolPaused, checkPoolSunset, checkQuotaCount, checkQuotaLimit, checkRWAOpenRequirements, checkRWAOpening, checkReservePriceLimited, checkSimulation, checkWallet, checkWalletAllowance, checkWalletBalance, childLogger, classifyCloseOrRepay, classifyCurveOperation, classifyInnerOperations, collateralPriceInUnderlying, collectTraces, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, curveAddLiquidityFromTransfers, curveRemoveLiquidityFromTransfers, decodeDelayedIntent, detectDelayedClaim, detectDelayedOperation, detectNetwork, dominantCollateral, encodeDelayedIntent, erc4626ReferralAdapterAbi, estimateClaimableAt, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, executeMulticallBatches, expectedBalanceDeltas, fetchCreditAccountSlice, filterDust, filterDustUSD, findCallTo, findCallWithInput, findCuratorMarketConfigurator, findExecuteBytes, fmtBinaryMask, fnSigToName, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAccountTargetCollateral, getAdapterActionAbi, getAdapterDeployParamsAbi, getAdapterType, getAssetType, getCastTraceArgs, getChain, getCuratorName, getDirectTransferToken, getFunctionSignature, getLegacyStrategyTarget, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, hasAdapterDeployParamsAbi, healthFactorBps, hexEq, hydrateAddressProvider, iBalancerV3RouterAbi, iBalancerV3RouterAdapterAbi, iBalancerV3WrapperAbi, iBalancerV3WrapperAdapterAbi, iBaseOnRampAbi, iBaseRewardPoolAbi, iBoosterAbi, iCamelotV3AdapterAbi, iCamelotV3RouterAbi, iConvexV1BaseRewardPoolAdapterAbi, iConvexV1BoosterAdapterAbi, iCreditAccountAbi, iCurvePoolAbi, iCurvePoolStableNGAbi, iCurvePool_2Abi, iCurvePool_3Abi, iCurvePool_4Abi, iCurveV1StableNgAdapterAbi, iCurveV1_2AssetsAdapterAbi, iCurveV1_3AssetsAdapterAbi, iCurveV1_4AssetsAdapterAbi, iDaiUsdsAbi, iDaiUsdsAdapterAbi, iERC4626Abi, iERC4626ReferralAbi, iFluidDexAbi, iFluidDexAdapterAbi, iInfinifiGatewayAbi, iInfinifiGatewayAdapterAbi, iInfinifiUnwindingGatewayAbi, iInfinifiUnwindingGatewayAdapterAbi, iKelpLRTDepositPoolGatewayAbi, iKelpLRTWithdrawalManagerGatewayAbi, iKelpLrtDepositPoolAdapterAbi, iKelpLrtDepositPoolGatewayAbi, iKelpLrtWithdrawalManagerAdapterAbi, iKelpLrtWithdrawalManagerGatewayAbi, iLidoV1AdapterAbi, iMellow4626VaultAdapterAbi, iMellowClaimerAbi, iMellowClaimerAdapterAbi, iMellowWrapperAbi, iMellowWrapperAdapterAbi, iMidasGatewayAdapterV311Abi, iMidasGatewayV311Abi, iMidasIssuanceVaultAdapterV310Abi, iMidasIssuanceVaultV310Abi, iMidasRedemptionVaultAdapterV310Abi, iMidasRedemptionVaultGatewayV310Abi, iPendleRouterAbi, iPendleRouterAdapterAbi, iSecuritizeOnRampAbi, iSecuritizeOnRampAdapterV310Abi, iSecuritizeRedemptionGatewayAdapterV311Abi, iSecuritizeRedemptionGatewayV311Abi, iStakingRewardsAbi, iStakingRewardsAdapterAbi, iTraderJoeRouterAbi, iTraderJoeRouterAdapterAbi, iUniswapV2AdapterAbi, iUniswapV2Router02Abi, iUniswapV3Abi, iUniswapV3AdapterAbi, iUniswapV4AdapterAbi, iUniswapV4GatewayAbi, iUpshiftVaultAdapterAbi, iUpshiftVaultGatewayAbi, iVelodromeV2RouterAbi, iVelodromeV2RouterAdapterAbi, isCloseOrRepay, isDust, isLPPriceFeed, isPhantomToken, isPoolOperation, isPublicNetwork, isRWAFactory, isRWAOperation, isRWAToken, isStrategyCollateral, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, isZeroBalance, iwstETHAbi, iwstEthv1AdapterAbi, json_parse, json_stringify, lidoV1_WETHGatewayAbi, makeReplayState, maxAmountForQuota, mellowDvvAdapterAbi, midasGreenlistsAccount, minSeizedAmount, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalPartialLiquidation, optimalPartialLiquidationAmounts, parseAdapterAction, parseAdapterDeployParams, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parsePosNegAmount, parseRWAFactoryOperationCalldata, partialLiquidationParams, percentFmt, pickStrategyTargetCollateral, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, raise, rayToBps, rayToNumber, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent, resolveProtocolCall, retry, rewardsFromTransfers, roundUpQuota, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, soleNonUnderlyingCollateral, strategyName, swapFromTransfers, toAddress, toBN, toBigInt, toChainIds, toClaimableWithdrawal, toCreditAccountSlice, toNetTransfers, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toToken, toTokenAmount, toWithdrawalStatus, updatableDependencies, usdToNumber, watchBlocksAsync };
313
+ export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractAdapterContract, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AccountBotsService, AccountMigratorAdapterContract, AdapterType, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerV3PoolStatus, BalancerV3RouterAdapterContract, BalancerV3WrapperAdapterContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, CamelotV3AdapterContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, ConstantPriceFeedContract, Construct, ContractParseError, ConvexV1BaseRewardPoolAdapterContract, ConvexV1BoosterAdapterContract, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountState, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CreditSuiteStrategy, Curve2AssetsAdapterContract, Curve3AssetsAdapterContract, Curve4AssetsAdapterContract, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, CurveV1AdapterStETHContract, CurveV1StableNGAdapterContract, DEFAULT_QUOTA_BUFFER_BPS, DEGEN_NFT_MIDAS, DEGEN_NFT_SECURITIZE, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DIRECT_TRANSFERS_QUOTA, DUST_THRESHOLD, DaiUsdsAdapterContract, ERC4626AdapterContract, ERC4626ReferralAdapterContract, EXECUTE_BYTES_SELECTOR, Erc4626PriceFeedContract, ExternalPriceFeedContract, FluidDexAdapterContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InfinifiGatewayAdapterContract, InfinifiUnwindingGatewayAdapterContract, KelpLRTDepositPoolAdapterContract, KelpLRTWithdrawalManagerAdapterContract, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LidoV1AdapterContract, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_LEVERAGE_BUFFER_BPS, MAX_QUOTA_MULTIPLIER, MAX_UINT16, MAX_UINT256, MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_INT96, MIN_SAFE_HEALTH_FACTOR_FORM, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowClaimerAdapterContract, MellowDVVAdapterContract, MellowERC4626VaultAdapterContract, MellowLRTPriceFeedContract, MellowWrapperAdapterContract, MidasDegenNFT, MidasGatewayAdapterContract, MidasIssuanceVaultAdapterContract, MidasLiquidatorContract, MidasRedemptionVaultAdapterContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, NON_STRATEGY_PHANTOM_TOKEN_TYPES, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendlePairStatus, PendleRouterAdapterContract, PendleTWAPPTPriceFeed, PendleTokenType, PeripheryCompressorV310Contract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegistry, PriceOracleV310Contract, PriceUpdatesCache, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_COMPRESSOR_ADDRESS, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkRWADataNotLoadedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeDegenNFT, SecuritizeLiquidatorContract, SecuritizeOnRampAdapterContract, SecuritizeRWAFactory, SecuritizeRedemptionGatewayAdapterContract, SimulateWithPriceUpdatesError, SimulationError, StakingRewardsAdapterContract, TokensMeta, TraderJoePoolVersion, TraderJoeRouterAdapterContract, TypedObjectUtils, UniswapV2AdapterContract, UniswapV3AdapterContract, UniswapV4AdapterContract, UpdatablePriceFeedRegistry, UpshiftVaultAdapterContract, VERSION_RANGE_310, VelodromeV2RouterAdapterContract, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, WstETHV1AdapterContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodBigInt, ZodHex, accountSnapshotFromCreditAccountData, adapterActionAbi, adapterActionSelectors, adapterActionSignatures, adapterConstructorAbi, allTransfersAsTokenAmounts, amountOf, assetsMap, attachOptionsSchema, botPermissionsToString, bpsToRay, buildDelayedStrategyPositionOperationPreview, bytes32ToString, calcBorrowApy, calcBorrowRate, calcDefaultQuota, calcEffectiveBorrowApy, calcHealthFactor, calcLiquidationPrice, calcLiquidationPriceForTarget, calcMaxLeverage, calcNetStrategyApy, calcPositionLeverage, calcQuotaRate, calcQuotaUpdate, calcRecommendedQuota, calcTimeToLiquidationMs, calcUtilization, calcUtilizationRaw, chains, checkAccountQuotas, checkBorrowLimit, checkCollateralFunding, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkCreditOperation, checkDebtLimits, checkEmergencyLiquidator, checkForbiddenToken, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLeverage, checkLiquidation, checkLiquidationEligibility, checkLiquidationFunding, checkLiquidatorEligible, checkMarket, checkMarketExpired, checkMaxQuota, checkMidasAccountGreenlist, checkObtained, checkOperation, checkPoolFunding, checkPoolLiquidity, checkPoolOperation, checkPoolPaused, checkPoolSunset, checkQuotaActive, checkQuotaChange, checkQuotaCount, checkQuotaLimit, checkQuotaUpdates, checkRWAOpenRequirements, checkRWAOpening, checkReservePriceLimited, checkSimulation, checkWallet, checkWalletAllowance, checkWalletBalance, childLogger, classifyCloseOrRepay, classifyCurveOperation, classifyInnerOperations, collateralPriceInUnderlying, collectTraces, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, curveAddLiquidityFromTransfers, curveRemoveLiquidityFromTransfers, decodeDelayedIntent, detectDelayedClaim, detectDelayedOperation, detectNetwork, dominantCollateral, encodeDelayedIntent, erc4626ReferralAdapterAbi, estimateClaimableAt, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, executeMulticallBatches, expectedBalanceDeltas, fetchCreditAccountSlice, filterDust, filterDustUSD, findCallTo, findCallWithInput, findCuratorMarketConfigurator, findExecuteBytes, fmtBinaryMask, fnSigToName, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAccountTargetCollateral, getAdapterActionAbi, getAdapterDeployParamsAbi, getAdapterType, getAssetType, getCastTraceArgs, getChain, getCuratorName, getDirectTransferToken, getFunctionSignature, getLegacyStrategyTarget, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, hasAdapterDeployParamsAbi, healthFactorBps, hexEq, hydrateAddressProvider, iBalancerV3RouterAbi, iBalancerV3RouterAdapterAbi, iBalancerV3WrapperAbi, iBalancerV3WrapperAdapterAbi, iBaseOnRampAbi, iBaseRewardPoolAbi, iBoosterAbi, iCamelotV3AdapterAbi, iCamelotV3RouterAbi, iConvexV1BaseRewardPoolAdapterAbi, iConvexV1BoosterAdapterAbi, iCreditAccountAbi, iCurvePoolAbi, iCurvePoolStableNGAbi, iCurvePool_2Abi, iCurvePool_3Abi, iCurvePool_4Abi, iCurveV1StableNgAdapterAbi, iCurveV1_2AssetsAdapterAbi, iCurveV1_3AssetsAdapterAbi, iCurveV1_4AssetsAdapterAbi, iDaiUsdsAbi, iDaiUsdsAdapterAbi, iERC4626Abi, iERC4626ReferralAbi, iFluidDexAbi, iFluidDexAdapterAbi, iInfinifiGatewayAbi, iInfinifiGatewayAdapterAbi, iInfinifiUnwindingGatewayAbi, iInfinifiUnwindingGatewayAdapterAbi, iKelpLRTDepositPoolGatewayAbi, iKelpLRTWithdrawalManagerGatewayAbi, iKelpLrtDepositPoolAdapterAbi, iKelpLrtDepositPoolGatewayAbi, iKelpLrtWithdrawalManagerAdapterAbi, iKelpLrtWithdrawalManagerGatewayAbi, iLidoV1AdapterAbi, iMellow4626VaultAdapterAbi, iMellowClaimerAbi, iMellowClaimerAdapterAbi, iMellowWrapperAbi, iMellowWrapperAdapterAbi, iMidasGatewayAdapterV311Abi, iMidasGatewayV311Abi, iMidasIssuanceVaultAdapterV310Abi, iMidasIssuanceVaultV310Abi, iMidasRedemptionVaultAdapterV310Abi, iMidasRedemptionVaultGatewayV310Abi, iPendleRouterAbi, iPendleRouterAdapterAbi, iSecuritizeOnRampAbi, iSecuritizeOnRampAdapterV310Abi, iSecuritizeRedemptionGatewayAdapterV311Abi, iSecuritizeRedemptionGatewayV311Abi, iStakingRewardsAbi, iStakingRewardsAdapterAbi, iTraderJoeRouterAbi, iTraderJoeRouterAdapterAbi, iUniswapV2AdapterAbi, iUniswapV2Router02Abi, iUniswapV3Abi, iUniswapV3AdapterAbi, iUniswapV4AdapterAbi, iUniswapV4GatewayAbi, iUpshiftVaultAdapterAbi, iUpshiftVaultGatewayAbi, iVelodromeV2RouterAbi, iVelodromeV2RouterAdapterAbi, isCloseOrRepay, isDust, isLPPriceFeed, isPhantomToken, isPoolOperation, isPublicNetwork, isRWAFactory, isRWAOperation, isRWAToken, isStrategyCollateral, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, isZeroBalance, iwstETHAbi, iwstEthv1AdapterAbi, json_parse, json_stringify, lidoV1_WETHGatewayAbi, makeReplayState, maxAmountForQuota, mellowDvvAdapterAbi, midasGreenlistsAccount, minSeizedAmount, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalPartialLiquidation, optimalPartialLiquidationAmounts, parseAdapterAction, parseAdapterDeployParams, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parsePosNegAmount, parseRWAFactoryOperationCalldata, partialLiquidationParams, percentFmt, pickStrategyTargetCollateral, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, raise, rayToBps, rayToNumber, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent, resolveProtocolCall, retry, rewardsFromTransfers, roundUpQuota, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, soleNonUnderlyingCollateral, strategyName, swapFromTransfers, toAddress, toBN, toBigInt, toChainIds, toClaimableWithdrawal, toCreditAccountSlice, toNetTransfers, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toToken, toTokenAmount, toWithdrawalStatus, updatableDependencies, usdToNumber, watchBlocksAsync };
@@ -1,5 +1,5 @@
1
- import { AbstractAdapterContract } from "./AbstractAdapter.js";
2
1
  import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
2
+ import { AbstractAdapterContract } from "./AbstractAdapter.js";
3
3
  //#region src/onchain/market/adapters/contracts/AccountMigratorAdapterContract.ts
4
4
  const abi = accountMigratorAbi;
5
5
  const protocolAbi = accountMigratorAbi;
@@ -1,6 +1,6 @@
1
+ import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
1
2
  import { MissingSerializedParamsError } from "../../../base/errors.js";
2
3
  import "../../../base/index.js";
3
- import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
4
4
  import { iERC4626Abi } from "../abi/targetContractAbi.js";
5
5
  import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
6
6
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
@@ -1,7 +1,7 @@
1
+ import { iPausableAbi } from "../../../abi/iPausable.js";
1
2
  import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
2
3
  import { BaseContract } from "../../base/BaseContract.js";
3
4
  import "../../base/index.js";
4
- import { iPausableAbi } from "../../../abi/iPausable.js";
5
5
  //#region src/onchain/market/credit/CreditFacadeV310BaseContract.ts
6
6
  const abi = [
7
7
  ...iCreditFacadeV310Abi,
@@ -1,3 +1,4 @@
1
+ import { iPausableAbi } from "../../../abi/iPausable.js";
1
2
  import { iPoolV310Abi } from "../../../abi/310/generated.js";
2
3
  import { AddressMap } from "../../utils/AddressMap.js";
3
4
  import { RAY } from "../../constants/math.js";
@@ -7,7 +8,6 @@ import "../../utils/index.js";
7
8
  import { SdkRWADataNotLoadedError } from "../../core/errors.js";
8
9
  import { BaseContract } from "../../base/BaseContract.js";
9
10
  import "../../base/index.js";
10
- import { iPausableAbi } from "../../../abi/iPausable.js";
11
11
  //#region src/onchain/market/pool/PoolV310Contract.ts
12
12
  const abi = [...iPoolV310Abi, ...iPausableAbi];
13
13
  var PoolV310Contract = class extends BaseContract {
@@ -1,6 +1,6 @@
1
+ import { iVersionAbi } from "../../../abi/iVersion.js";
1
2
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
2
3
  import "../../utils/index.js";
3
- import { iVersionAbi } from "../../../abi/iVersion.js";
4
4
  import { iMidasDegenNFTAbi } from "../../../abi/rwa/iMidasDegenNFT.js";
5
5
  import { DEGEN_NFT_MIDAS } from "./midas/constants.js";
6
6
  import { MidasDegenNFT } from "./midas/MidasDegenNFT.js";
@@ -1,5 +1,5 @@
1
- import { ZapperContract } from "./ZapperContract.js";
2
1
  import { iethZapperAbi } from "../../../abi/iETHZapper.js";
2
+ import { ZapperContract } from "./ZapperContract.js";
3
3
  //#region src/onchain/market/zapper/IETHZapperContract.ts
4
4
  const abi = iethZapperAbi;
5
5
  var IETHZapperContract = class extends ZapperContract {
@@ -1,8 +1,8 @@
1
+ import { iZapperAbi } from "../../../abi/iZapper.js";
1
2
  import { BaseContract } from "../../base/BaseContract.js";
2
3
  import "../../base/index.js";
3
4
  import { sdkErr, sdkOk } from "../../../model/result.js";
4
5
  import "../../../model/index.js";
5
- import { iZapperAbi } from "../../../abi/iZapper.js";
6
6
  //#region src/onchain/market/zapper/ZapperContract.ts
7
7
  /**
8
8
  * Base contract for every Gearbox zapper. Specialized zappers (e.g.
@@ -42,7 +42,7 @@ function calcHealthFactor(props) {
42
42
  const quota = snapshot.quotas.find((q) => isAddressEqual(q.token, token));
43
43
  const quotaBalance = quota && (active.get(token) ?? false) ? quota.balance : 0n;
44
44
  const quotaWeighted = (convertToUSD(underlying, quotaBalance) ?? 0n) * PERCENTAGE_FACTOR;
45
- return acc + (quota ? BigIntMath.min(quotaWeighted, tokenLtWeighted) : tokenLtWeighted);
45
+ return acc + (quota || active.get(token) ? BigIntMath.min(quotaWeighted, tokenLtWeighted) : tokenLtWeighted);
46
46
  }, 0n);
47
47
  const borrowedValue = convertToUSD(underlying, snapshot.totalDebt) ?? 0n;
48
48
  const hf = borrowedValue > 0n ? assetValue / borrowedValue : 0n;
@@ -1,5 +1,6 @@
1
1
  import { AssetsMap } from "../../utils/AssetsMap.js";
2
2
  import { DUST_THRESHOLD } from "../../constants/math.js";
3
+ import { roundUpQuota } from "../../accounts/quota-utils.js";
3
4
  import { zeroAddress } from "viem";
4
5
  //#region src/onchain/preview/preview/CreditAccountState.ts
5
6
  /**
@@ -129,7 +130,8 @@ var CreditAccountState = class CreditAccountState {
129
130
  /**
130
131
  * Applies a relative `updateQuota` change to the token's quota:
131
132
  * `MIN_INT96` is the facade "disable quota" sentinel and zeroes it, other
132
- * changes are added with the result clamped at zero (quotas cannot go
133
+ * changes are rounded toward zero to a `PERCENTAGE_FACTOR` step, as the
134
+ * facade does, and added with the result clamped at zero (quotas cannot go
133
135
  * negative on-chain).
134
136
  */
135
137
  updateQuota(token, change) {
@@ -137,7 +139,7 @@ var CreditAccountState = class CreditAccountState {
137
139
  this.quotas.upsert(token, 0n);
138
140
  return;
139
141
  }
140
- const next = this.quotas.getOrZero(token) + change;
142
+ const next = this.quotas.getOrZero(token) + roundUpQuota(change);
141
143
  this.quotas.upsert(token, next > 0n ? next : 0n);
142
144
  }
143
145
  };
@@ -1,8 +1,8 @@
1
- import { iPoolV310Abi } from "../../../abi/310/generated.js";
2
1
  import { ierc20Abi } from "../../../abi/iERC20.js";
2
+ import { iZapperAbi } from "../../../abi/iZapper.js";
3
+ import { iPoolV310Abi } from "../../../abi/310/generated.js";
3
4
  import { sdkErr, sdkOk } from "../../../model/result.js";
4
5
  import "../../../model/index.js";
5
- import { iZapperAbi } from "../../../abi/iZapper.js";
6
6
  //#region src/onchain/preview/preview/previewPoolPositionOperation.ts
7
7
  function previewRead(operation) {
8
8
  switch (operation.operation) {
@@ -1,6 +1,6 @@
1
1
  import { errorAbis } from "../../../abi/errors.js";
2
- import { generateCastTraceCall } from "./cast.js";
3
2
  import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
3
+ import { generateCastTraceCall } from "./cast.js";
4
4
  import { simulateMulticall } from "./simulateMulticall.js";
5
5
  import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
6
6
  import { getAction, parseAccount } from "viem/utils";
@@ -9,6 +9,7 @@ import { checkIncreaseDebt } from "./checkIncreaseDebt.js";
9
9
  import { checkIncreaseQuota } from "./checkIncreaseQuota.js";
10
10
  import { checkMarket } from "./checkMarket.js";
11
11
  import { checkObtained } from "./checkObtained.js";
12
+ import { checkQuotaUpdates } from "./checkQuotaUpdates.js";
12
13
  import { checkRWAOpening } from "./checkRWAOpening.js";
13
14
  //#region src/onchain/validation/bundles/checkCreditOperation.ts
14
15
  /**
@@ -40,6 +41,7 @@ async function checkCreditOperation(args) {
40
41
  ...checkIncreaseDebt(suite, preview, underlying),
41
42
  ...checkObtained(suite, preview),
42
43
  ...checkAccountQuotas(suite, preview),
44
+ ...checkQuotaUpdates(suite, preview, underlying),
43
45
  ...checkIncreaseQuota(market, preview, underlying),
44
46
  ...checkHealthFactors({
45
47
  totalDebt: preview.totalDebt,
@@ -0,0 +1,44 @@
1
+ import { MAX_QUOTA_MULTIPLIER } from "../../constants/math.js";
2
+ import { debtOutOfRange } from "../../../model/errors/operation-errors.js";
3
+ import "../../../model/index.js";
4
+ import { amountOf } from "../helpers/amount.js";
5
+ import "../helpers/index.js";
6
+ import { checkForbiddenToken } from "../checks/checkForbiddenToken.js";
7
+ import { checkMaxQuota } from "../checks/checkMaxQuota.js";
8
+ import "../checks/index.js";
9
+ import { isAddressEqual } from "viem";
10
+ //#region src/onchain/validation/bundles/checkQuotaUpdates.ts
11
+ /**
12
+ * What the facade reverts on in each quota the operation touches: an increase
13
+ * on a forbidden token, an increase on an account that ends with zero debt, and
14
+ * a resulting quota above `MAX_QUOTA_MULTIPLIER × maxDebt`.
15
+ */
16
+ function checkQuotaUpdates(suite, preview, underlying) {
17
+ const isAdjust = preview.operation === "AdjustCreditAccount";
18
+ const changes = (isAdjust ? preview.quotasChange : preview.quotas).filter((q) => q.value !== 0n);
19
+ const increases = changes.filter((q) => q.value > 0n);
20
+ const { minDebt, maxDebt } = suite.creditFacade;
21
+ const maxQuota = MAX_QUOTA_MULTIPLIER * maxDebt;
22
+ const forbidden = increases.flatMap((q) => checkForbiddenToken({
23
+ token: q.token,
24
+ isForbidden: suite.isForbidden(q.token.address)
25
+ }));
26
+ const isZeroDebt = isAdjust && increases.length > 0 && preview.totalDebt.value === 0n ? [debtOutOfRange({
27
+ requested: amountOf(underlying, 0n),
28
+ minDebt: amountOf(underlying, minDebt),
29
+ maxDebt: amountOf(underlying, maxDebt)
30
+ })] : [];
31
+ const aboveMax = changes.flatMap((q) => checkMaxQuota({
32
+ token: q.token,
33
+ requested: preview.quotas.find((r) => isAddressEqual(r.token.address, q.token.address))?.value ?? 0n,
34
+ maxQuota,
35
+ underlying
36
+ }));
37
+ return [
38
+ ...forbidden,
39
+ ...isZeroDebt,
40
+ ...aboveMax
41
+ ];
42
+ }
43
+ //#endregion
44
+ export { checkQuotaUpdates };
@@ -7,6 +7,7 @@ import { checkIncreaseDebt } from "./checkIncreaseDebt.js";
7
7
  import { checkIncreaseQuota } from "./checkIncreaseQuota.js";
8
8
  import { checkMarket } from "./checkMarket.js";
9
9
  import { checkObtained } from "./checkObtained.js";
10
+ import { checkQuotaUpdates } from "./checkQuotaUpdates.js";
10
11
  import { checkMidasAccountGreenlist } from "./checkMidasAccountGreenlist.js";
11
12
  import { checkRWAOpenRequirements } from "./checkRWAOpenRequirements.js";
12
13
  import { checkRWAOpening } from "./checkRWAOpening.js";
@@ -16,4 +17,4 @@ import { checkLiquidationFunding } from "./checkLiquidationFunding.js";
16
17
  import { checkWallet } from "./checkWallet.js";
17
18
  import { checkPoolFunding } from "./checkPoolFunding.js";
18
19
  import { checkPoolOperation } from "./checkPoolOperation.js";
19
- export { checkAccountQuotas, checkCollateralFunding, checkCreditOperation, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLiquidationEligibility, checkLiquidationFunding, checkMarket, checkMidasAccountGreenlist, checkObtained, checkPoolFunding, checkPoolOperation, checkRWAOpenRequirements, checkRWAOpening, checkWallet, checkWalletAllowance, checkWalletBalance };
20
+ export { checkAccountQuotas, checkCollateralFunding, checkCreditOperation, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLiquidationEligibility, checkLiquidationFunding, checkMarket, checkMidasAccountGreenlist, checkObtained, checkPoolFunding, checkPoolOperation, checkQuotaUpdates, checkRWAOpenRequirements, checkRWAOpening, checkWallet, checkWalletAllowance, checkWalletBalance };
@@ -0,0 +1,17 @@
1
+ import { quotaAboveMax } from "../../../model/errors/operation-errors.js";
2
+ import "../../../model/index.js";
3
+ import { amountOf } from "../helpers/amount.js";
4
+ import "../helpers/index.js";
5
+ //#region src/onchain/validation/checks/checkMaxQuota.ts
6
+ /** The facade's per-token quota ceiling. */
7
+ function checkMaxQuota(args) {
8
+ const { token, requested, maxQuota, underlying } = args;
9
+ if (requested <= maxQuota) return [];
10
+ return [quotaAboveMax({
11
+ token,
12
+ requested: amountOf(underlying, requested),
13
+ maxQuota: amountOf(underlying, maxQuota)
14
+ })];
15
+ }
16
+ //#endregion
17
+ export { checkMaxQuota };
@@ -0,0 +1,9 @@
1
+ import { quotaInactive } from "../../../model/errors/operation-errors.js";
2
+ import "../../../model/index.js";
3
+ //#region src/onchain/validation/checks/checkQuotaActive.ts
4
+ /** A token whose quota the keeper does not manage at all. */
5
+ function checkQuotaActive(args) {
6
+ return args.isActive ? [] : [quotaInactive(args.token)];
7
+ }
8
+ //#endregion
9
+ export { checkQuotaActive };
@@ -0,0 +1,17 @@
1
+ import { quotaUnchanged } from "../../../model/errors/operation-errors.js";
2
+ import "../../../model/index.js";
3
+ import { amountOf } from "../helpers/amount.js";
4
+ import "../helpers/index.js";
5
+ //#region src/onchain/validation/checks/checkQuotaChange.ts
6
+ /** A quota update that rounds to nothing. */
7
+ function checkQuotaChange(args) {
8
+ const { token, current, requested, change, underlying } = args;
9
+ if (change !== 0n) return [];
10
+ return [quotaUnchanged({
11
+ token,
12
+ current: amountOf(underlying, current),
13
+ requested: amountOf(underlying, requested)
14
+ })];
15
+ }
16
+ //#endregion
17
+ export { checkQuotaChange };