@gearbox-protocol/sdk 14.12.0-next.76 → 14.12.0-next.78

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 (90) hide show
  1. package/dist/cjs/model/curators.js +1 -0
  2. package/dist/cjs/model/curators.schema.js +38 -0
  3. package/dist/cjs/model/index.js +4 -1
  4. package/dist/cjs/model/opportunities.schema.js +3 -1
  5. package/dist/cjs/model/primitives.schema.js +5 -13
  6. package/dist/cjs/preview/index.js +0 -1
  7. package/dist/cjs/preview/preview/buildDelayedPreview.js +4 -3
  8. package/dist/cjs/preview/preview/index.js +0 -1
  9. package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +3 -2
  10. package/dist/cjs/preview/preview/types.js +0 -16
  11. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +12 -38
  12. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +1 -1
  13. package/dist/cjs/sdk/chain/chains.js +1 -1
  14. package/dist/cjs/sdk/index.js +3 -0
  15. package/dist/cjs/sdk/market/MarketConfiguratorContract.js +2 -14
  16. package/dist/cjs/sdk/market/MarketSuite.js +1 -0
  17. package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +10 -0
  18. package/dist/cjs/sdk/market/credit/expectedBalanceDeltas.js +25 -0
  19. package/dist/cjs/sdk/market/credit/index.js +2 -0
  20. package/dist/cjs/sdk/market/index.js +2 -0
  21. package/dist/cjs/sdk/utils/index.js +1 -0
  22. package/dist/cjs/sdk/utils/zod.js +36 -14
  23. package/dist/esm/model/curators.js +1 -0
  24. package/dist/esm/model/curators.schema.js +36 -0
  25. package/dist/esm/model/index.js +4 -2
  26. package/dist/esm/model/opportunities.schema.js +3 -1
  27. package/dist/esm/model/primitives.schema.js +7 -14
  28. package/dist/esm/preview/index.js +2 -2
  29. package/dist/esm/preview/preview/buildDelayedPreview.js +5 -4
  30. package/dist/esm/preview/preview/index.js +2 -2
  31. package/dist/esm/preview/preview/previewAdjustCreditAccount.js +4 -3
  32. package/dist/esm/preview/preview/types.js +1 -16
  33. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +12 -38
  34. package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +1 -1
  35. package/dist/esm/sdk/chain/chains.js +1 -1
  36. package/dist/esm/sdk/index.js +3 -2
  37. package/dist/esm/sdk/market/MarketConfiguratorContract.js +2 -14
  38. package/dist/esm/sdk/market/MarketSuite.js +1 -0
  39. package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +10 -0
  40. package/dist/esm/sdk/market/credit/expectedBalanceDeltas.js +24 -0
  41. package/dist/esm/sdk/market/credit/index.js +2 -1
  42. package/dist/esm/sdk/market/index.js +2 -1
  43. package/dist/esm/sdk/utils/index.js +2 -2
  44. package/dist/esm/sdk/utils/zod.js +36 -15
  45. package/dist/types/dev/AccountOpener.d.ts +1 -1
  46. package/dist/types/model/curators.d.ts +33 -0
  47. package/dist/types/model/curators.schema.d.ts +50 -0
  48. package/dist/types/model/history.schema.d.ts +6 -6
  49. package/dist/types/model/index.d.ts +5 -3
  50. package/dist/types/model/liquidations.schema.d.ts +47 -47
  51. package/dist/types/model/opportunities.d.ts +6 -1
  52. package/dist/types/model/opportunities.schema.d.ts +257 -106
  53. package/dist/types/model/positions.schema.d.ts +92 -92
  54. package/dist/types/model/primitives.d.ts +2 -25
  55. package/dist/types/model/primitives.schema.d.ts +10 -17
  56. package/dist/types/preview/index.d.ts +2 -2
  57. package/dist/types/preview/preview/index.d.ts +2 -2
  58. package/dist/types/preview/preview/types.d.ts +1 -16
  59. package/dist/types/sdk/OnchainSDK.d.ts +3 -3
  60. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +8 -7
  61. package/dist/types/sdk/accounts/bots/types.d.ts +1 -1
  62. package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +1 -1
  63. package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressorV310Contract.d.ts +1 -1
  64. package/dist/types/sdk/accounts/index.d.ts +2 -2
  65. package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +1 -2
  66. package/dist/types/sdk/accounts/types.d.ts +8 -78
  67. package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.d.ts +1 -1
  68. package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.d.ts +1 -1
  69. package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +1 -1
  70. package/dist/types/sdk/base/index.d.ts +2 -2
  71. package/dist/types/sdk/base/types.d.ts +42 -1
  72. package/dist/types/sdk/chain/chains.d.ts +7 -11
  73. package/dist/types/sdk/chain/index.d.ts +2 -2
  74. package/dist/types/sdk/index.d.ts +26 -25
  75. package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +2 -7
  76. package/dist/types/sdk/market/MarketSuite.d.ts +2 -1
  77. package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +6 -3
  78. package/dist/types/sdk/market/credit/CreditSuite.d.ts +2 -2
  79. package/dist/types/sdk/market/credit/expectedBalanceDeltas.d.ts +39 -0
  80. package/dist/types/sdk/market/credit/index.d.ts +3 -2
  81. package/dist/types/sdk/market/credit/types.d.ts +26 -3
  82. package/dist/types/sdk/market/index.d.ts +4 -3
  83. package/dist/types/sdk/market/rwa/index.d.ts +2 -2
  84. package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +1 -2
  85. package/dist/types/sdk/market/rwa/types.d.ts +11 -2
  86. package/dist/types/sdk/options.d.ts +4 -4
  87. package/dist/types/sdk/pools/types.d.ts +1 -12
  88. package/dist/types/sdk/utils/index.d.ts +2 -2
  89. package/dist/types/sdk/utils/zod.d.ts +7 -3
  90. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { ZodAddress, ZodHex } from "../sdk/utils/zod.js";
1
+ import { ZodAddress, ZodBigInt, ZodHex } from "../sdk/utils/zod.js";
2
2
  import { z } from "zod/v4";
3
3
  //#region src/model/primitives.schema.ts
4
4
  /**
@@ -30,14 +30,15 @@ const assetTypeSchema = z.union([
30
30
  z.literal("BTC")
31
31
  ]);
32
32
  /**
33
- * {@link Leverage}
33
+ * {@link Leverage}. Nonnegative rather than positive: `0` is the backend's
34
+ * encoding of "leverage unavailable".
34
35
  **/
35
- const leverageSchema = z.number().positive();
36
+ const leverageSchema = z.number().nonnegative();
36
37
  /**
37
38
  * {@link Amount}
38
39
  **/
39
40
  const amountSchema = z.object({
40
- value: z.bigint(),
41
+ value: ZodBigInt(),
41
42
  valueUsd: z.number().nullable()
42
43
  });
43
44
  /**
@@ -61,15 +62,7 @@ const tokenAmountSchema = amountSchema.extend({ token: tokenSchema });
61
62
  const txCallSchema = z.object({
62
63
  to: ZodAddress(),
63
64
  callData: ZodHex(),
64
- value: z.bigint().optional()
65
- });
66
- /**
67
- * {@link Curator}
68
- **/
69
- const curatorSchema = z.object({
70
- address: ZodAddress(),
71
- name: z.string(),
72
- url: z.string().nullable()
65
+ value: ZodBigInt().optional()
73
66
  });
74
67
  //#endregion
75
- export { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema };
68
+ export { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema };
@@ -18,7 +18,7 @@ import { BalancePrerequisite } from "./prerequisites/BalancePrerequisite.js";
18
18
  import { RWAOpenRequirementsPrerequisite } from "./prerequisites/RWAOpenRequirementsPrerequisite.js";
19
19
  import { checkPrerequisites } from "./prerequisites/checkPrerequisites.js";
20
20
  import "./prerequisites/index.js";
21
- import { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, PREVIEW_DUST } from "./preview/types.js";
21
+ import { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN } from "./preview/types.js";
22
22
  import { buildDelayedPreview } from "./preview/buildDelayedPreview.js";
23
23
  import { CreditAccountState } from "./preview/CreditAccountState.js";
24
24
  import { classifyCloseOrRepay, isCloseOrRepay } from "./preview/detectCloseOrRepay.js";
@@ -32,4 +32,4 @@ import { previewCloseOrRepayCreditAccount } from "./preview/previewCloseOrRepayC
32
32
  import { previewOperation } from "./preview/previewOperation.js";
33
33
  import "./preview/index.js";
34
34
  import "./types.js";
35
- export { AllowancePrerequisite, BalancePrerequisite, CreditAccountState, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, PREVIEW_DUST, Prerequisite, RWAOpenRequirementsPrerequisite, TransferAlignmentError, UnexpectedFacadeEventOrderError, UnknownAdapterError, UnknownFacadeCallError, UnsupportedOperationError, UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedZapperFunctionError, WithdrawCollateralAlignmentError, buildDelayedPreview, checkPrerequisites, classifyCloseOrRepay, classifyInnerOperations, detectDelayedClaim, detectDelayedOperation, extractAdapterCallTraces, extractTransfers, findFacadeCalls, isCloseOrRepay, isPoolOperation, isRWAOperation, makeReplayState, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata, previewAdjustCreditAccount, previewCloseOrRepayCreditAccount, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
35
+ export { AllowancePrerequisite, BalancePrerequisite, CreditAccountState, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, Prerequisite, RWAOpenRequirementsPrerequisite, TransferAlignmentError, UnexpectedFacadeEventOrderError, UnknownAdapterError, UnknownFacadeCallError, UnsupportedOperationError, UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedZapperFunctionError, WithdrawCollateralAlignmentError, buildDelayedPreview, checkPrerequisites, classifyCloseOrRepay, classifyInnerOperations, detectDelayedClaim, detectDelayedOperation, extractAdapterCallTraces, extractTransfers, findFacadeCalls, isCloseOrRepay, isPoolOperation, isRWAOperation, makeReplayState, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata, previewAdjustCreditAccount, previewCloseOrRepayCreditAccount, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
@@ -1,8 +1,9 @@
1
1
  import { AssetsMap } from "../../sdk/utils/AssetsMap.js";
2
2
  import { BigIntMath } from "../../sdk/utils/bigint-math.js";
3
+ import { DUST_THRESHOLD } from "../../sdk/constants/math.js";
3
4
  import "../../sdk/index.js";
4
5
  import "../../common-utils/index.js";
5
- import { ERROR_UNPRICEABLE_TOKEN, PREVIEW_DUST } from "./types.js";
6
+ import { ERROR_UNPRICEABLE_TOKEN } from "./types.js";
6
7
  import { isAddressEqual } from "viem";
7
8
  //#region src/preview/preview/buildDelayedPreview.ts
8
9
  /**
@@ -171,7 +172,7 @@ function buildClosePreview(post, converter, receivedToken) {
171
172
  };
172
173
  }
173
174
  function buildAdjustPreview(post, before, collateralWithdrawn, converter) {
174
- const totalValue = totalValueInUnderlying(post, converter.convert, PREVIEW_DUST);
175
+ const totalValue = totalValueInUnderlying(post, converter.convert, DUST_THRESHOLD);
175
176
  return {
176
177
  operation: "AdjustCreditAccount",
177
178
  creditManager: post.creditManager,
@@ -183,8 +184,8 @@ function buildAdjustPreview(post, before, collateralWithdrawn, converter) {
183
184
  debtChange: post.debt - before.debt,
184
185
  quotas: post.quotas.toAssets(0n),
185
186
  quotasChange: post.quotas.difference(before.quotas).toAssets(),
186
- assets: post.balances.toAssets(PREVIEW_DUST),
187
- assetsChange: post.balances.difference(before.balances).toAssets(PREVIEW_DUST),
187
+ assets: post.balances.toAssets(DUST_THRESHOLD),
188
+ assetsChange: post.balances.difference(before.balances).toAssets(DUST_THRESHOLD),
188
189
  error: converter.error
189
190
  };
190
191
  }
@@ -1,4 +1,4 @@
1
- import { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, PREVIEW_DUST } from "./types.js";
1
+ import { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN } from "./types.js";
2
2
  import { buildDelayedPreview } from "./buildDelayedPreview.js";
3
3
  import { CreditAccountState } from "./CreditAccountState.js";
4
4
  import { classifyCloseOrRepay, isCloseOrRepay } from "./detectCloseOrRepay.js";
@@ -10,4 +10,4 @@ import { replayMulticall } from "./replayMulticall.js";
10
10
  import { previewAdjustCreditAccount } from "./previewAdjustCreditAccount.js";
11
11
  import { previewCloseOrRepayCreditAccount } from "./previewCloseOrRepayCreditAccount.js";
12
12
  import { previewOperation } from "./previewOperation.js";
13
- export { CreditAccountState, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, PREVIEW_DUST, UnsupportedOperationError, buildDelayedPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, isCloseOrRepay, makeReplayState, previewAdjustCreditAccount, previewCloseOrRepayCreditAccount, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
13
+ export { CreditAccountState, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, UnsupportedOperationError, buildDelayedPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, isCloseOrRepay, makeReplayState, previewAdjustCreditAccount, previewCloseOrRepayCreditAccount, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
@@ -1,6 +1,7 @@
1
1
  import { AP_WETH_TOKEN } from "../../sdk/constants/address-provider.js";
2
+ import { DUST_THRESHOLD } from "../../sdk/constants/math.js";
2
3
  import "../../sdk/index.js";
3
- import { ERROR_UNPRICEABLE_TOKEN, PREVIEW_DUST } from "./types.js";
4
+ import { ERROR_UNPRICEABLE_TOKEN } from "./types.js";
4
5
  import { replayMulticall } from "./replayMulticall.js";
5
6
  import { unwrapNativeCollateral } from "./unwrapNativeCollateral.js";
6
7
  //#region src/preview/preview/previewAdjustCreditAccount.ts
@@ -19,8 +20,8 @@ async function previewAdjustCreditAccount(input, operation, options) {
19
20
  let error = replayError;
20
21
  const { assets: collateralAdded, error: unwrapError } = unwrapNativeCollateral(after.collateralAdded.toAssets(), value, sdk.addressProvider.getAddress(AP_WETH_TOKEN, 0));
21
22
  error ??= unwrapError;
22
- const assets = account.balances.toAssets(PREVIEW_DUST);
23
- const assetsChange = account.balances.difference(before.balances).toAssets(PREVIEW_DUST);
23
+ const assets = account.balances.toAssets(DUST_THRESHOLD);
24
+ const assetsChange = account.balances.difference(before.balances).toAssets(DUST_THRESHOLD);
24
25
  const totalValue = assets.reduce((acc, { token, balance }) => {
25
26
  try {
26
27
  return acc + market.priceOracle.convert(token, market.underlying, balance);
@@ -31,20 +31,5 @@ const ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP = 1005;
31
31
  const ERROR_INVALID_TRANSACTION_VALUE = 1006;
32
32
  /** A token in the preview could not be priced by the oracle */
33
33
  const ERROR_UNPRICEABLE_TOKEN = 2001;
34
- /**
35
- * Dust threshold for replayed preview balances and balance changes.
36
- *
37
- * Multicalls assembled by `CreditAccountsServiceV310` subtract a 10-unit
38
- * safety buffer from every expected output token in their
39
- * `storeExpectedBalances` deltas (`amount - 10n` in
40
- * `assembleStartDelayedWithdrawalCalls`/`assembleClaimDelayedCalls`), while
41
- * subsequent calls in the same multicall spend exact on-chain amounts. A
42
- * replay that credits only the min-guarantee can therefore be off by up to
43
- * 10 units per token, including small negative residues that are impossible
44
- * on-chain. Amounts within this threshold (in absolute value) are filtered
45
- * from preview outputs; anything beyond it is a genuine discrepancy and is
46
- * reported.
47
- */
48
- const PREVIEW_DUST = 10n;
49
34
  //#endregion
50
- export { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, PREVIEW_DUST };
35
+ export { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN };
@@ -10,6 +10,8 @@ import "../base/index.js";
10
10
  import { AccountBotsService } from "./bots/AccountBotsService.js";
11
11
  import "./bots/index.js";
12
12
  import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
13
+ import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
14
+ import "../market/index.js";
13
15
  import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
14
16
  import "./credit-account-compressor/index.js";
15
17
  import { extractPriceUpdates, extractQuotaTokens, mergePriceUpdates } from "./multicall-utils.js";
@@ -173,49 +175,21 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
173
175
  * {@inheritDoc ICreditAccountsService.assembleStartDelayedWithdrawalCalls}
174
176
  **/
175
177
  assembleStartDelayedWithdrawalCalls({ creditFacade, preview }) {
176
- const record = preview.outputs.reduce((acc, o) => {
177
- const token = o.token.toLowerCase();
178
- acc[token] = (acc[token] || 0n) + o.amount;
179
- return acc;
180
- }, {});
181
- const deltas = Object.entries(record).filter(([, a]) => a > 10n).map(([token, amount]) => ({
182
- token,
183
- amount: amount > 10n ? amount - 10n : 0n
184
- }));
185
- if (preview.amountIn > 0n) deltas.push({
186
- token: preview.token,
187
- amount: -preview.amountIn
188
- });
189
- const facade = this.sdk.marketRegister.findCreditFacade(creditFacade);
190
- return [
191
- facade.prepareStoreExpectedBalances(deltas),
192
- ...preview.requestCalls,
193
- facade.prepareCompareBalances()
194
- ];
178
+ return this.sdk.marketRegister.findCreditFacade(creditFacade).prepareWithBalanceCheck(expectedBalanceDeltas({
179
+ outputs: preview.outputs,
180
+ spentToken: preview.token,
181
+ spentAmount: preview.amountIn
182
+ }), preview.requestCalls);
195
183
  }
196
184
  /**
197
185
  * {@inheritDoc ICreditAccountsService.assembleClaimDelayedCalls}
198
186
  **/
199
187
  assembleClaimDelayedCalls({ creditFacade, claimableNow }) {
200
- const record = claimableNow.outputs.reduce((acc, o) => {
201
- const token = o.token.toLowerCase();
202
- acc[token] = (acc[token] || 0n) + o.amount;
203
- return acc;
204
- }, {});
205
- const deltas = Object.entries(record).filter(([, a]) => a > 10n).map(([token, amount]) => ({
206
- token,
207
- amount: amount > 10n ? amount - 10n : 0n
208
- }));
209
- if (claimableNow.withdrawalTokenSpent > 0n) deltas.push({
210
- token: claimableNow.withdrawalPhantomToken,
211
- amount: -claimableNow.withdrawalTokenSpent
212
- });
213
- const facade = this.sdk.marketRegister.findCreditFacade(creditFacade);
214
- return [
215
- facade.prepareStoreExpectedBalances(deltas),
216
- ...claimableNow.claimCalls,
217
- facade.prepareCompareBalances()
218
- ];
188
+ return this.sdk.marketRegister.findCreditFacade(creditFacade).prepareWithBalanceCheck(expectedBalanceDeltas({
189
+ outputs: claimableNow.outputs,
190
+ spentToken: claimableNow.withdrawalPhantomToken,
191
+ spentAmount: claimableNow.withdrawalTokenSpent
192
+ }), claimableNow.claimCalls);
219
193
  }
220
194
  /**
221
195
  * {@inheritDoc ICreditAccountsService.getApprovalAddress}
@@ -9,12 +9,12 @@ import { hexEq } from "../../utils/hex.js";
9
9
  import "../../utils/index.js";
10
10
  import { SDKConstruct } from "../../base/SDKConstruct.js";
11
11
  import "../../base/index.js";
12
- import { iRWAFactoryAbi } from "../../../abi/rwa/iRWAFactory.js";
13
12
  import { borrowApyBps, healthFactorBps, positionLeverage, usdToNumber } from "../../market/math.js";
14
13
  import { dominantCollateral } from "../../market/credit/dominantCollateral.js";
15
14
  import { simulateWithPriceUpdates } from "../../utils/viem/simulateWithPriceUpdates.js";
16
15
  import "../../utils/viem/index.js";
17
16
  import "../../market/index.js";
17
+ import { iRWAFactoryAbi } from "../../../abi/rwa/iRWAFactory.js";
18
18
  import { CreditAccountCompressorV310Contract } from "./CreditAccountCompressorV310Contract.js";
19
19
  //#region src/sdk/accounts/credit-account-compressor/CreditAccountCompressor.ts
20
20
  /**
@@ -374,7 +374,7 @@ function isPublicNetwork(networkOrChainId) {
374
374
  });
375
375
  }
376
376
  /**
377
- * Looks up the {@link Curator} name for a market configurator address.
377
+ * Looks up the {@link CuratorName} name for a market configurator address.
378
378
  *
379
379
  * Searches default and test market configurators across all chains, or
380
380
  * a single network if provided.
@@ -26,7 +26,7 @@ import { fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage,
26
26
  import { hexEq } from "./utils/hex.js";
27
27
  import { retry } from "./utils/retry.js";
28
28
  import { toAddress } from "./utils/toAddress.js";
29
- import { ZodAddress, ZodHex } from "./utils/zod.js";
29
+ import { ZodAddress, ZodBigInt, ZodHex } from "./utils/zod.js";
30
30
  import "./utils/index.js";
31
31
  import { generateCastTraceCall, getCastTraceArgs } from "./utils/viem/cast.js";
32
32
  import { SimulationError, simulateCall } from "./utils/viem/simulateCall.js";
@@ -53,6 +53,7 @@ import { PARTIAL_LIQUIDATION_BUFFER_BPS, additionalBorrowApyBps, borrowApyBps, h
53
53
  import { CreditManagerV310Contract } from "./market/credit/CreditManagerV310Contract.js";
54
54
  import { dominantCollateral, mustGetDominantCollateral } from "./market/credit/dominantCollateral.js";
55
55
  import { CreditSuite } from "./market/credit/CreditSuite.js";
56
+ import { expectedBalanceDeltas } from "./market/credit/expectedBalanceDeltas.js";
56
57
  import { simulateMulticall } from "./utils/viem/simulateMulticall.js";
57
58
  import { SimulateWithPriceUpdatesError, getSimulateWithPriceUpdatesError, simulateWithPriceUpdates } from "./utils/viem/simulateWithPriceUpdates.js";
58
59
  import { executeDelegatedMulticalls } from "./utils/viem/executeDelegatedMulticalls.js";
@@ -147,4 +148,4 @@ import { OnchainSDK, STATE_VERSION } from "./OnchainSDK.js";
147
148
  import { MultichainSDK } from "./MultichainSDK.js";
148
149
  import { attachOptionsSchema, onchainSDKOptionsSchema } from "./options.js";
149
150
  import "./types/index.js";
150
- 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_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AccountBotsService, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, 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, PendleTWAPPTPriceFeed, PeripheryCompressorV310Contract, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, 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, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodHex, additionalBorrowApyBps, assetsMap, attachOptionsSchema, borrowApyBps, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, dominantCollateral, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, fetchPythPayloads, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAssetType, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, healthFactorBps, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, maxLeverage, minSeizedAmount, mustGetDominantCollateral, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalRepaidAmount, percentFmt, positionLeverage, primaryInstantOutput, rayToBps, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toWithdrawalStatus, usdToNumber, utilizationBps, watchBlocksAsync };
151
+ 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_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AccountBotsService, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, 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, PendleTWAPPTPriceFeed, PeripheryCompressorV310Contract, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, 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, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodBigInt, ZodHex, additionalBorrowApyBps, assetsMap, attachOptionsSchema, borrowApyBps, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, dominantCollateral, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, expectedBalanceDeltas, fetchPythPayloads, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAssetType, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, healthFactorBps, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, maxLeverage, minSeizedAmount, mustGetDominantCollateral, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalRepaidAmount, percentFmt, positionLeverage, primaryInstantOutput, rayToBps, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toWithdrawalStatus, usdToNumber, utilizationBps, watchBlocksAsync };
@@ -8,7 +8,6 @@ import { stringToHex } from "viem";
8
8
  //#region src/sdk/market/MarketConfiguratorContract.ts
9
9
  const abi = iMarketConfiguratorV310Abi;
10
10
  var MarketConfiguratorContract = class extends BaseContract {
11
- #curatorName;
12
11
  constructor(options, address) {
13
12
  super(options, {
14
13
  abi,
@@ -17,24 +16,13 @@ var MarketConfiguratorContract = class extends BaseContract {
17
16
  version: 0
18
17
  });
19
18
  }
20
- async loadCuratorName() {
21
- this.#curatorName = await this.client.readContract({
22
- address: this.address,
23
- abi: this.abi,
24
- functionName: "curatorName"
25
- });
26
- this.register.setAddressLabel(this.address, `Market configurator ${this.#curatorName}`);
27
- }
28
19
  /**
29
- * The entity operating this configurator, as the shared read model describes
30
- * it. The curated per-chain table wins over the name the contract reports,
31
- * because the two sources must agree across services and only the table is
32
- * shared with the backend.
20
+ * The entity operating this configurator
33
21
  */
34
22
  get curator() {
35
23
  return {
36
24
  address: this.address,
37
- name: getCuratorName(this.address, this.networkType) ?? this.#curatorName ?? "Unknown",
25
+ name: getCuratorName(this.address, this.networkType),
38
26
  url: null
39
27
  };
40
28
  }
@@ -222,6 +222,7 @@ var MarketSuite = class extends SDKConstruct {
222
222
  curator: this.curator,
223
223
  underlyingToken: this.underlyingToken,
224
224
  totalSupply: oracle.toAmount(pool.underlying, pool.totalAssets),
225
+ availableLiquidity: oracle.toAmount(pool.underlying, pool.availableLiquidity),
225
226
  totalBorrow: oracle.toAmount(pool.underlying, pool.totalBorrowed),
226
227
  utilization: pool.utilization,
227
228
  supplyApy: { organicApy: rayToBps(pool.supplyRate) },
@@ -288,6 +288,16 @@ var CreditFacadeV310Contract = class extends CreditFacadeV310BaseContract {
288
288
  })
289
289
  };
290
290
  }
291
+ /**
292
+ * {@inheritDoc ICreditFacadeContract.prepareWithBalanceCheck}
293
+ */
294
+ prepareWithBalanceCheck(deltas, calls) {
295
+ return [
296
+ this.prepareStoreExpectedBalances(deltas),
297
+ ...calls,
298
+ this.prepareCompareBalances()
299
+ ];
300
+ }
291
301
  };
292
302
  //#endregion
293
303
  export { CreditFacadeV310Contract };
@@ -0,0 +1,24 @@
1
+ import { AssetsMap } from "../../utils/AssetsMap.js";
2
+ import { DUST_THRESHOLD } from "../../constants/math.js";
3
+ import "../../constants/index.js";
4
+ import "../../utils/index.js";
5
+ //#region src/sdk/market/credit/expectedBalanceDeltas.ts
6
+ /**
7
+ * Builds the `storeExpectedBalances` deltas of a multicall from the amounts it
8
+ * is expected to produce and the token it spends.
9
+ */
10
+ function expectedBalanceDeltas({ outputs, spentToken, spentAmount }) {
11
+ const sums = new AssetsMap();
12
+ for (const { token, amount } of outputs) sums.inc(token, amount);
13
+ const deltas = sums.entries().filter(([, amount]) => amount > DUST_THRESHOLD).map(([token, amount]) => ({
14
+ token,
15
+ amount: amount - DUST_THRESHOLD
16
+ }));
17
+ if (spentAmount > 0n) deltas.push({
18
+ token: spentToken,
19
+ amount: -spentAmount
20
+ });
21
+ return deltas;
22
+ }
23
+ //#endregion
24
+ export { expectedBalanceDeltas };
@@ -4,5 +4,6 @@ import { CreditFacadeV310Contract } from "./CreditFacadeV310Contract.js";
4
4
  import { CreditManagerV310Contract } from "./CreditManagerV310Contract.js";
5
5
  import { dominantCollateral, mustGetDominantCollateral } from "./dominantCollateral.js";
6
6
  import { CreditSuite } from "./CreditSuite.js";
7
+ import { expectedBalanceDeltas } from "./expectedBalanceDeltas.js";
7
8
  import "./types.js";
8
- export { CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, abi as creditFacadeV310Abi, dominantCollateral, mustGetDominantCollateral };
9
+ export { CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, abi as creditFacadeV310Abi, dominantCollateral, expectedBalanceDeltas, mustGetDominantCollateral };
@@ -7,6 +7,7 @@ import { CreditFacadeV310Contract } from "./credit/CreditFacadeV310Contract.js";
7
7
  import { CreditManagerV310Contract } from "./credit/CreditManagerV310Contract.js";
8
8
  import { dominantCollateral, mustGetDominantCollateral } from "./credit/dominantCollateral.js";
9
9
  import { CreditSuite } from "./credit/CreditSuite.js";
10
+ import { expectedBalanceDeltas } from "./credit/expectedBalanceDeltas.js";
10
11
  import "./credit/index.js";
11
12
  import { isUpdatablePriceFeed } from "./pricefeeds/isUpdatablePriceFeed.js";
12
13
  import { PriceFeedRef } from "./pricefeeds/PriceFeedRef.js";
@@ -59,4 +60,4 @@ import { RWARegistry } from "./rwa/RWARegistry.js";
59
60
  import { RWA_FACTORY_TYPES, isRWAFactory } from "./rwa/types.js";
60
61
  import "./rwa/index.js";
61
62
  import "./types.js";
62
- export { AbstractLPPriceFeedContract, AbstractPriceFeedContract, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CompositePriceFeedContract, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, LinearInterestRateModelContract, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PoolSuite, PoolV310Contract, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RedstonePriceFeedContract, SECURITIZE_REGISTER_VAULT_TYPES, SecuritizeLiquidatorContract, SecuritizeRWAFactory, UnsupportedZapperFunctionError, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, createAdapter, createPriceOracle, createZapper, abi as creditFacadeV310Abi, dominantCollateral, fetchPythPayloads, fetchRedstonePayloads, getRawPriceUpdates, isLPPriceFeed, isRWAFactory, isUpdatablePriceFeed, mustGetDominantCollateral };
63
+ export { AbstractLPPriceFeedContract, AbstractPriceFeedContract, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CompositePriceFeedContract, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, LinearInterestRateModelContract, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PoolSuite, PoolV310Contract, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RedstonePriceFeedContract, SECURITIZE_REGISTER_VAULT_TYPES, SecuritizeLiquidatorContract, SecuritizeRWAFactory, UnsupportedZapperFunctionError, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, createAdapter, createPriceOracle, createZapper, abi as creditFacadeV310Abi, dominantCollateral, expectedBalanceDeltas, fetchPythPayloads, fetchRedstonePayloads, getRawPriceUpdates, isLPPriceFeed, isRWAFactory, isUpdatablePriceFeed, mustGetDominantCollateral };
@@ -16,5 +16,5 @@ import { hexEq } from "./hex.js";
16
16
  import { retry } from "./retry.js";
17
17
  import { toAddress } from "./toAddress.js";
18
18
  import "./type-utils.js";
19
- import { ZodAddress, ZodHex } from "./zod.js";
20
- export { AddressMap, AddressSet, AssetsMap, BigIntMath, TypedObjectUtils, ZodAddress, ZodHex, bytes32ToString, childLogger, createRawTx, etherscanApiUrl, etherscanUrl, filterDust, filterDustUSD, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, getFunctionSignature, hexEq, isDust, json_parse, json_stringify, numberWithCommas, percentFmt, rayToNumber, retry, shortAddress, shortHash, toAddress, toBN, toBigInt, toSignificant };
19
+ import { ZodAddress, ZodBigInt, ZodHex } from "./zod.js";
20
+ export { AddressMap, AddressSet, AssetsMap, BigIntMath, TypedObjectUtils, ZodAddress, ZodBigInt, ZodHex, bytes32ToString, childLogger, createRawTx, etherscanApiUrl, etherscanUrl, filterDust, filterDustUSD, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, getFunctionSignature, hexEq, isDust, json_parse, json_stringify, numberWithCommas, percentFmt, rayToNumber, retry, shortAddress, shortHash, toAddress, toBN, toBigInt, toSignificant };
@@ -2,26 +2,47 @@ import { getAddress, isAddress, isHex } from "viem";
2
2
  import { z } from "zod/v4";
3
3
  //#region src/sdk/utils/zod.ts
4
4
  /**
5
+ * A `bigint` codec that serializes into string, deserializes into bigint.
6
+ */
7
+ const ZodBigInt = () => z.codec(z.union([z.string().regex(z.regexes.integer), z.bigint()]), z.bigint(), {
8
+ decode: (value) => typeof value === "bigint" ? value : BigInt(value),
9
+ encode: (value) => value.toString()
10
+ });
11
+ const addressOut = z.custom((val) => typeof val === "string" && isAddress(val, { strict: false }));
12
+ /**
5
13
  * Like Address from abitype/zod, but converts an address into an address that is checksum encoded.
6
14
  */
7
- const ZodAddress = () => z.string().transform((val, ctx) => {
8
- if (!isAddress(val)) ctx.issues.push({
9
- code: "custom",
10
- message: `invalid address ${val}`,
11
- input: ctx.value
12
- });
13
- return getAddress(val);
15
+ const ZodAddress = () => z.codec(z.string(), addressOut, {
16
+ decode: (val, ctx) => {
17
+ if (!isAddress(val, { strict: false })) {
18
+ ctx.issues.push({
19
+ code: "custom",
20
+ message: `invalid address ${val}`,
21
+ input: val
22
+ });
23
+ return z.NEVER;
24
+ }
25
+ return getAddress(val);
26
+ },
27
+ encode: (address) => address
14
28
  });
29
+ const hexOut = z.custom((val) => typeof val === "string" && isHex(val));
15
30
  /**
16
31
  * A `0x`-prefixed hex string, as viem's Hex.
17
32
  */
18
- const ZodHex = () => z.string().transform((val, ctx) => {
19
- if (!isHex(val)) ctx.issues.push({
20
- code: "custom",
21
- message: `invalid hex string ${val}`,
22
- input: ctx.value
23
- });
24
- return val;
33
+ const ZodHex = () => z.codec(z.string(), hexOut, {
34
+ decode: (val, ctx) => {
35
+ if (!isHex(val)) {
36
+ ctx.issues.push({
37
+ code: "custom",
38
+ message: `invalid hex string ${val}`,
39
+ input: val
40
+ });
41
+ return z.NEVER;
42
+ }
43
+ return val;
44
+ },
45
+ encode: (hex) => hex
25
46
  });
26
47
  //#endregion
27
- export { ZodAddress, ZodHex };
48
+ export { ZodAddress, ZodBigInt, ZodHex };
@@ -1,7 +1,7 @@
1
1
  import { Asset, CreditAccountData } from "../sdk/base/types.js";
2
- import { ICreditAccountsService } from "../sdk/accounts/types.js";
3
2
  import { RawTx } from "../sdk/types/transactions.js";
4
3
  import { SDKConstruct } from "../sdk/base/SDKConstruct.js";
4
+ import { ICreditAccountsService } from "../sdk/accounts/types.js";
5
5
  import "../sdk/index.js";
6
6
  import { Address, BaseError, Hash, Hex, PrivateKeyAccount } from "viem";
7
7
  //#region src/dev/AccountOpener.d.ts
@@ -0,0 +1,33 @@
1
+ import { Address } from "viem";
2
+ //#region src/model/curators.d.ts
3
+ /**
4
+ * Known curator names that manage Gearbox markets.
5
+ **/
6
+ type CuratorName = "Chaos Labs" | "K3" | "cp0x" | "Re7" | "Invariant Group" | "Tulipa" | "M11 Credit" | "KPK" | "Hyperithm" | "UltraYield" | "TelosC" | "Gami Labs" | "Securitize" | "Testnet Curator";
7
+ /**
8
+ * The entity that curates a market: sets risk parameters, picks collateral and
9
+ * operates the market configurator.
10
+ **/
11
+ interface Curator {
12
+ /**
13
+ * Address of the market configurator the curator operates. This is the
14
+ * on-chain identity of a curator, not a personal wallet.
15
+ **/
16
+ address: Address;
17
+ /**
18
+ * Display name from the curated per-chain table, or `undefined` when the
19
+ * market configurator is not a well-known curator.
20
+ *
21
+ * @example `"Chaos Labs"`
22
+ **/
23
+ name?: CuratorName;
24
+ /**
25
+ * Link to the curator's page, or `null` when unknown. The chain knows no
26
+ * URLs, so this is `null` for anything served from the on-chain source.
27
+ *
28
+ * @mode offchain
29
+ **/
30
+ url: string | null;
31
+ }
32
+ //#endregion
33
+ export { Curator, CuratorName };
@@ -0,0 +1,50 @@
1
+ import { z } from "zod/v4";
2
+ //#region src/model/curators.schema.d.ts
3
+ /**
4
+ * Runtime schemas for {@link ./curators.js}, see the note in
5
+ * `primitives.schema.ts` on why they are written by hand.
6
+ **/
7
+ /**
8
+ * {@link CuratorName}
9
+ **/
10
+ declare const curatorNameSchema: z.ZodEnum<{
11
+ "Chaos Labs": "Chaos Labs";
12
+ "Gami Labs": "Gami Labs";
13
+ Hyperithm: "Hyperithm";
14
+ "Invariant Group": "Invariant Group";
15
+ K3: "K3";
16
+ KPK: "KPK";
17
+ "M11 Credit": "M11 Credit";
18
+ Re7: "Re7";
19
+ Securitize: "Securitize";
20
+ TelosC: "TelosC";
21
+ "Testnet Curator": "Testnet Curator";
22
+ Tulipa: "Tulipa";
23
+ UltraYield: "UltraYield";
24
+ cp0x: "cp0x";
25
+ }>;
26
+ /**
27
+ * {@link Curator}
28
+ **/
29
+ declare const curatorSchema: z.ZodObject<{
30
+ address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
31
+ name: z.ZodOptional<z.ZodEnum<{
32
+ "Chaos Labs": "Chaos Labs";
33
+ "Gami Labs": "Gami Labs";
34
+ Hyperithm: "Hyperithm";
35
+ "Invariant Group": "Invariant Group";
36
+ K3: "K3";
37
+ KPK: "KPK";
38
+ "M11 Credit": "M11 Credit";
39
+ Re7: "Re7";
40
+ Securitize: "Securitize";
41
+ TelosC: "TelosC";
42
+ "Testnet Curator": "Testnet Curator";
43
+ Tulipa: "Tulipa";
44
+ UltraYield: "UltraYield";
45
+ cp0x: "cp0x";
46
+ }>>;
47
+ url: z.ZodNullable<z.ZodString>;
48
+ }, z.core.$strip>;
49
+ //#endregion
50
+ export { curatorNameSchema, curatorSchema };
@@ -63,12 +63,12 @@ declare const historySeriesSchema: z.ZodObject<{
63
63
  declare const opportunityHistoryQuerySchema: z.ZodObject<{
64
64
  opportunity: z.ZodDiscriminatedUnion<[z.ZodObject<{
65
65
  chainId: z.ZodNumber;
66
- pool: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
66
+ pool: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
67
67
  kind: z.ZodLiteral<"pool">;
68
68
  }, z.core.$strip>, z.ZodObject<{
69
69
  chainId: z.ZodNumber;
70
- creditManager: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
71
- targetCollateral: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
70
+ creditManager: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
71
+ targetCollateral: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
72
72
  kind: z.ZodLiteral<"strategy">;
73
73
  }, z.core.$strip>], "kind">;
74
74
  range: z.ZodUnion<readonly [z.ZodLiteral<"1d">, z.ZodLiteral<"1w">, z.ZodLiteral<"1m">, z.ZodLiteral<"1y">, z.ZodLiteral<"max">]>;
@@ -80,12 +80,12 @@ declare const opportunityHistoryQuerySchema: z.ZodObject<{
80
80
  declare const positionHistoryQuerySchema: z.ZodObject<{
81
81
  position: z.ZodDiscriminatedUnion<[z.ZodObject<{
82
82
  chainId: z.ZodNumber;
83
- pool: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
84
- wallet: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
83
+ pool: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
84
+ wallet: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
85
85
  kind: z.ZodLiteral<"pool">;
86
86
  }, z.core.$strip>, z.ZodObject<{
87
87
  chainId: z.ZodNumber;
88
- creditAccount: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
88
+ creditAccount: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
89
89
  kind: z.ZodLiteral<"strategy">;
90
90
  }, z.core.$strip>], "kind">;
91
91
  range: z.ZodUnion<readonly [z.ZodLiteral<"1d">, z.ZodLiteral<"1w">, z.ZodLiteral<"1m">, z.ZodLiteral<"1y">, z.ZodLiteral<"max">]>;