@gearbox-protocol/sdk 14.12.0-next.3 → 14.12.0-next.5

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 (87) hide show
  1. package/dist/cjs/preview/index.js +2 -4
  2. package/dist/cjs/preview/parse/index.js +0 -2
  3. package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +5 -12
  4. package/dist/cjs/preview/parse/parseOperationCalldata.js +6 -4
  5. package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +4 -0
  6. package/dist/cjs/preview/parse/parseRWAFactoryOperationCalldata.js +22 -10
  7. package/dist/cjs/preview/parse/types-rwa.js +16 -0
  8. package/dist/cjs/preview/parse/types.js +9 -2
  9. package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +13 -13
  10. package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +32 -14
  11. package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +66 -0
  12. package/dist/cjs/preview/prerequisites/buildPrerequisites.js +95 -27
  13. package/dist/cjs/preview/prerequisites/index.js +2 -0
  14. package/dist/cjs/preview/{simulate/holders.js → preview/errors.js} +12 -21
  15. package/dist/cjs/preview/{parse → preview}/extractExpectedBalanceChanges.js +1 -1
  16. package/dist/cjs/preview/preview/index.js +26 -0
  17. package/dist/cjs/preview/preview/previewOpenCreditAccount.js +99 -0
  18. package/dist/cjs/preview/preview/previewOperation.js +41 -0
  19. package/dist/cjs/preview/preview/previewPoolOperation.js +75 -0
  20. package/dist/cjs/preview/preview/types.js +16 -0
  21. package/dist/cjs/preview/simulate/index.js +5 -2
  22. package/dist/cjs/preview/simulate/simulateOperation.js +4 -0
  23. package/dist/cjs/preview/simulate/simulatePoolOperation.js +20 -116
  24. package/dist/cjs/preview/simulate/simulateRWAOperation.js +30 -0
  25. package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +14 -4
  26. package/dist/cjs/sdk/market/rwa/types.js +5 -2
  27. package/dist/cjs/sdk/market/zapper/ZapperContract.js +0 -3
  28. package/dist/esm/preview/index.js +1 -2
  29. package/dist/esm/preview/parse/index.js +0 -1
  30. package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +5 -12
  31. package/dist/esm/preview/parse/parseOperationCalldata.js +7 -5
  32. package/dist/esm/preview/parse/parsePoolOperationCalldata.js +4 -0
  33. package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +25 -11
  34. package/dist/esm/preview/parse/types-rwa.js +0 -0
  35. package/dist/esm/preview/parse/types.js +6 -1
  36. package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +13 -13
  37. package/dist/esm/preview/prerequisites/BalancePrerequisite.js +32 -14
  38. package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +42 -0
  39. package/dist/esm/preview/prerequisites/buildPrerequisites.js +100 -27
  40. package/dist/esm/preview/prerequisites/index.js +1 -0
  41. package/dist/esm/preview/preview/errors.js +12 -0
  42. package/dist/esm/preview/{parse → preview}/extractExpectedBalanceChanges.js +1 -1
  43. package/dist/esm/preview/preview/index.js +3 -0
  44. package/dist/esm/preview/preview/previewOpenCreditAccount.js +77 -0
  45. package/dist/esm/preview/preview/previewOperation.js +17 -0
  46. package/dist/esm/preview/preview/previewPoolOperation.js +53 -0
  47. package/dist/esm/preview/preview/types.js +0 -0
  48. package/dist/esm/preview/simulate/index.js +3 -1
  49. package/dist/esm/preview/simulate/simulateOperation.js +8 -1
  50. package/dist/esm/preview/simulate/simulatePoolOperation.js +21 -120
  51. package/dist/esm/preview/simulate/simulateRWAOperation.js +6 -0
  52. package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +14 -4
  53. package/dist/esm/sdk/market/rwa/types.js +5 -2
  54. package/dist/esm/sdk/market/zapper/ZapperContract.js +0 -3
  55. package/dist/types/history/types.d.ts +4 -4
  56. package/dist/types/preview/index.d.ts +1 -2
  57. package/dist/types/preview/parse/index.d.ts +0 -1
  58. package/dist/types/preview/parse/parseRWAFactoryOperationCalldata.d.ts +10 -11
  59. package/dist/types/preview/parse/types-facades.d.ts +0 -33
  60. package/dist/types/preview/parse/types-pools.d.ts +29 -1
  61. package/dist/types/preview/parse/types-rwa.d.ts +48 -0
  62. package/dist/types/preview/parse/types.d.ts +11 -6
  63. package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +1 -3
  64. package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +9 -6
  65. package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +36 -0
  66. package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +15 -6
  67. package/dist/types/preview/prerequisites/index.d.ts +1 -0
  68. package/dist/types/preview/prerequisites/types.d.ts +10 -8
  69. package/dist/types/preview/preview/errors.d.ts +9 -0
  70. package/dist/types/preview/{parse → preview}/extractExpectedBalanceChanges.d.ts +4 -5
  71. package/dist/types/preview/preview/index.d.ts +3 -0
  72. package/dist/types/preview/preview/previewOpenCreditAccount.d.ts +4 -0
  73. package/dist/types/preview/preview/previewOperation.d.ts +8 -0
  74. package/dist/types/preview/preview/previewPoolOperation.d.ts +5 -0
  75. package/dist/types/preview/preview/types.d.ts +103 -0
  76. package/dist/types/preview/simulate/index.d.ts +3 -1
  77. package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -2
  78. package/dist/types/preview/simulate/simulateOperation.d.ts +0 -2
  79. package/dist/types/preview/simulate/simulatePoolOperation.d.ts +6 -18
  80. package/dist/types/preview/simulate/simulateRWAOperation.d.ts +23 -0
  81. package/dist/types/preview/simulate/types.d.ts +12 -26
  82. package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +4 -0
  83. package/dist/types/sdk/market/rwa/types.d.ts +13 -5
  84. package/dist/types/sdk/market/zapper/types.d.ts +6 -6
  85. package/package.json +1 -1
  86. package/dist/esm/preview/simulate/holders.js +0 -21
  87. package/dist/types/preview/simulate/holders.d.ts +0 -7
@@ -0,0 +1,48 @@
1
+ import type { Address } from "viem";
2
+ import type { SecuritizeRegisterMessage } from "../../sdk/index.js";
3
+ import type { InnerOperation } from "./types-facades.js";
4
+ /**
5
+ * Metadata shared by all RWA factory operations. RWA credit accounts are
6
+ * opened and managed through the market's RWA factory rather than the credit
7
+ * facade, but the inner `calls` still target the facade/adapters, so the
8
+ * credit suite is known.
9
+ */
10
+ export interface RWAOperationMetadata {
11
+ /** RWA factory contract the transaction is sent to. */
12
+ factory: Address;
13
+ creditManager: Address;
14
+ creditFacade: Address;
15
+ }
16
+ export interface SecuritizeOpenCreditAccountOperation<Ext extends object = {}> extends RWAOperationMetadata {
17
+ operation: "SecuritizeOpenCreditAccount";
18
+ multicall: InnerOperation<Ext>[];
19
+ /**
20
+ * DSToken addresses to register, decoded from calldata. Empty in the
21
+ * template flow, where the real value comes from the factory's open-account
22
+ * requirements.
23
+ */
24
+ tokensToRegister: Address[];
25
+ /**
26
+ * EIP-712 registration signatures to store on-chain, decoded from calldata.
27
+ * Empty in the template flow.
28
+ */
29
+ signaturesToCache: SecuritizeRegisterMessage[];
30
+ }
31
+ /**
32
+ * `SecuritizeRWAFactory.multicall` call: like the facade's `multicall`, plus
33
+ * the factory-specific registration args.
34
+ */
35
+ export interface SecuritizeMulticallOperation<Ext extends object = {}> extends RWAOperationMetadata {
36
+ operation: "SecuritizeMulticall";
37
+ creditAccount: Address;
38
+ multicall: InnerOperation<Ext>[];
39
+ /** DSToken addresses to register, decoded from calldata. */
40
+ tokensToRegister: Address[];
41
+ /** EIP-712 registration signatures to store on-chain, decoded from calldata. */
42
+ signaturesToCache: SecuritizeRegisterMessage[];
43
+ }
44
+ /**
45
+ * Discriminated union of all RWA factory operation types. Extend it when
46
+ * adding support for a new RWA factory type.
47
+ */
48
+ export type RWAOperation<Ext extends object = {}> = SecuritizeOpenCreditAccountOperation<Ext> | SecuritizeMulticallOperation<Ext>;
@@ -2,9 +2,11 @@ import type { AdaptersPlugin } from "../../plugins/adapters/index.js";
2
2
  import type { OnchainSDK, PluginsMap } from "../../sdk/index.js";
3
3
  import type { OuterFacadeOperation } from "./types-facades.js";
4
4
  import type { PoolOperation } from "./types-pools.js";
5
+ import type { RWAOperation } from "./types-rwa.js";
5
6
  export * from "./types-adapters.js";
6
7
  export * from "./types-facades.js";
7
8
  export * from "./types-pools.js";
9
+ export * from "./types-rwa.js";
8
10
  /**
9
11
  * True when the plugin map `P` contains the {@link AdaptersPlugin} under any
10
12
  * key. Matched nominally (the plugin's private fields make it non-structural),
@@ -29,16 +31,19 @@ export type RequireAdaptersPlugin<P extends PluginsMap> = HasAdaptersPlugin<P> e
29
31
  */
30
32
  export type SdkWithAdapters<P extends PluginsMap = PluginsMap> = OnchainSDK<P> & RequireAdaptersPlugin<P>;
31
33
  /**
32
- * Result of decoding a single raw operation calldata: either a pool
33
- * deposit/redeem or one of the credit-facade operations.
34
- *
35
- * Calldata-only parse produces base (descriptor) adapter operations, so the
36
- * facade operations are used with the default `Ext = {}`.
34
+ * Result of decoding a single raw operation calldata: a pool deposit/redeem,
35
+ * one of the credit-facade operations, or an RWA-factory operation.
37
36
  */
38
- export type Operation = PoolOperation | OuterFacadeOperation;
37
+ export type Operation = PoolOperation | OuterFacadeOperation | RWAOperation;
39
38
  /**
40
39
  * Narrows an {@link Operation} to a {@link PoolOperation} (deposit, mint,
41
40
  * withdraw or redeem). Used by the UI to decide whether a custom view exists for
42
41
  * the parsed result; everything else falls back to the raw JSON view.
43
42
  */
44
43
  export declare function isPoolOperation(tx: Operation): tx is PoolOperation;
44
+ /**
45
+ * Narrows an {@link Operation} to an {@link RWAOperation} (an RWA-factory
46
+ * open-account or multicall). Used to route parsed operations to the
47
+ * RWA-specific simulation path.
48
+ */
49
+ export declare function isRWAOperation(tx: Operation): tx is RWAOperation;
@@ -11,9 +11,7 @@ export interface AllowancePrerequisiteProps {
11
11
  }
12
12
  /** Checks that `owner` granted `spender` an ERC-20 allowance >= `required`. */
13
13
  export declare class AllowancePrerequisite extends Prerequisite<"allowance"> {
14
- private readonly _id;
15
- private readonly _title;
16
- private readonly _detail;
14
+ #private;
17
15
  constructor(props: AllowancePrerequisiteProps);
18
16
  get id(): string;
19
17
  get kind(): "allowance";
@@ -1,6 +1,6 @@
1
1
  import { type Address, type ContractFunctionParameters } from "viem";
2
2
  import { type MulticallCallResult, Prerequisite } from "./Prerequisite.js";
3
- import type { PrerequisiteDetail, PrerequisiteResult } from "./types.js";
3
+ import type { PrerequisiteContext, PrerequisiteDetail, PrerequisiteResult } from "./types.js";
4
4
  export interface BalancePrerequisiteProps {
5
5
  token: Address;
6
6
  owner: Address;
@@ -8,16 +8,19 @@ export interface BalancePrerequisiteProps {
8
8
  title?: string;
9
9
  id?: string;
10
10
  }
11
- /** Checks that `owner` holds an ERC-20 balance >= `required`. */
11
+ /**
12
+ * Checks that `owner` holds a token balance >= `required`. The token is read
13
+ * as an ERC-20, except for the native pseudo-address ({@link NATIVE_ADDRESS},
14
+ * e.g. ETH-zapper deposits) whose balance is read via multicall3's
15
+ * `getEthBalance`.
16
+ */
12
17
  export declare class BalancePrerequisite extends Prerequisite<"balance"> {
13
- private readonly _id;
14
- private readonly _title;
15
- private readonly _detail;
18
+ #private;
16
19
  constructor(props: BalancePrerequisiteProps);
17
20
  get id(): string;
18
21
  get kind(): "balance";
19
22
  get title(): string;
20
23
  get detail(): PrerequisiteDetail<"balance">;
21
- calls(): ContractFunctionParameters[];
24
+ calls(ctx: PrerequisiteContext): ContractFunctionParameters[];
22
25
  resolve(slice: MulticallCallResult[]): PrerequisiteResult<"balance">;
23
26
  }
@@ -0,0 +1,36 @@
1
+ import type { Address, ContractFunctionParameters } from "viem";
2
+ import type { RWAOpenAccountRequirements } from "../../sdk/index.js";
3
+ import { Prerequisite } from "./Prerequisite.js";
4
+ import type { PrerequisiteDetail, PrerequisiteResult } from "./types.js";
5
+ export interface RWAOpenRequirementsPrerequisiteProps {
6
+ /** Requirements already resolved via `sdk.accounts.getOpenAccountRequirements`. */
7
+ requirements: RWAOpenAccountRequirements;
8
+ /** RWA token (e.g. Securitize DSToken) the requirements were computed for. */
9
+ token: Address;
10
+ /** RWA factory that produced the requirements. */
11
+ factory: Address;
12
+ title?: string;
13
+ id?: string;
14
+ }
15
+ /**
16
+ * Checks that the borrower has fulfilled the RWA factory's open-account
17
+ * requirements (issuer-side token registration, EIP-712 signatures).
18
+ *
19
+ * Unlike `allowance`/`balance`, the requirements cannot be derived from plain
20
+ * ERC-20 multicall reads: they come from an async compressor read performed by
21
+ * `sdk.accounts.getOpenAccountRequirements`. The prerequisite is therefore
22
+ * *pre-resolved*: it is constructed with the requirements already computed,
23
+ * contributes no calls to the verification multicall, and `resolve` only
24
+ * interprets the stored payload.
25
+ */
26
+ export declare class RWAOpenRequirementsPrerequisite extends Prerequisite<"rwaOpenRequirements"> {
27
+ #private;
28
+ constructor(props: RWAOpenRequirementsPrerequisiteProps);
29
+ get id(): string;
30
+ get kind(): "rwaOpenRequirements";
31
+ get title(): string;
32
+ get detail(): PrerequisiteDetail<"rwaOpenRequirements">;
33
+ /** Pre-resolved: no on-chain reads to contribute. */
34
+ calls(): ContractFunctionParameters[];
35
+ resolve(): PrerequisiteResult<"rwaOpenRequirements">;
36
+ }
@@ -1,10 +1,19 @@
1
- import type { Operation } from "../parse/index.js";
1
+ import { type PluginsMap } from "../../sdk/index.js";
2
+ import { type ParseOperationCalldataInput } from "../parse/parseOperationCalldata.js";
2
3
  import type { AnyPrerequisite } from "./Prerequisite.js";
3
- import type { PrerequisiteContext } from "./types.js";
4
4
  /**
5
- * Derives the on-chain prerequisites for a parsed operation: the conditions
6
- * that must hold for the call not to revert and that we can verify with the
7
- * SDK (token approvals, wallet balances).
5
+ * Input of {@link buildPrerequisites}: the same raw-calldata input as the
6
+ * internal calldata parser, plus an optional block to read at.
7
+ */
8
+ export type BuildPrerequisitesInput<P extends PluginsMap = PluginsMap> = ParseOperationCalldataInput<P> & {
9
+ /** Block to read at; defaults to latest. Only set for testnet forks. */
10
+ blockNumber?: bigint;
11
+ };
12
+ /**
13
+ * Derives the on-chain prerequisites for an operation given its raw calldata:
14
+ * the conditions that must hold for the call not to revert and that we can
15
+ * verify with the SDK (token approvals, wallet balances). The calldata is
16
+ * decoded internally via `parseOperationCalldata`.
8
17
  *
9
18
  * Only *sender-actionable* prerequisites belong here: conditions the LP
10
19
  * provider or borrower can fix themselves before retrying (e.g. approve a
@@ -13,4 +22,4 @@ import type { PrerequisiteContext } from "./types.js";
13
22
  * bot permissions) is intentionally out of scope, since the user cannot
14
23
  * resolve it. New {@link AnyPrerequisite} subclasses must follow the same rule.
15
24
  */
16
- export declare function buildPrerequisites(tx: Operation, ctx: PrerequisiteContext): Promise<AnyPrerequisite[]>;
25
+ export declare function buildPrerequisites<P extends PluginsMap>(input: BuildPrerequisitesInput<P>): Promise<AnyPrerequisite[]>;
@@ -3,5 +3,6 @@ export * from "./BalancePrerequisite.js";
3
3
  export * from "./buildPrerequisites.js";
4
4
  export * from "./Prerequisite.js";
5
5
  export * from "./prepareAction.js";
6
+ export * from "./RWAOpenRequirementsPrerequisite.js";
6
7
  export * from "./runPrerequisites.js";
7
8
  export * from "./types.js";
@@ -1,18 +1,14 @@
1
1
  import type { Address } from "viem";
2
- import type { OnchainSDK } from "../../sdk/index.js";
2
+ import type { OnchainSDK, RWAOpenAccountRequirements } from "../../sdk/index.js";
3
3
  /**
4
4
  * Extension point that ties each prerequisite kind to its detail payload.
5
5
  *
6
- * Adding a new prerequisite kind only requires a new entry here: the generic
7
- * machinery below and the UI renderer registry both key off this map, so TS
8
- * forces every consumer to handle the new kind.
9
- *
10
6
  * IMPORTANT: only add prerequisites that are *actionable by the transaction
11
7
  * sender* (the LP provider or borrower). A valid prerequisite is one the user
12
8
  * can resolve themselves before retrying, e.g. approve a token (`allowance`)
13
- * or acquire/free up funds (`balance`). Do NOT add protocol- or admin-level
14
- * state the user cannot change, such as pool pause status or available pool
15
- * liquidity; those are not actionable and must not be listed as prerequisites.
9
+ * or perform offchain KYC verification.
10
+ *
11
+ * Do NOT add protocol- or admin-level state the user cannot change.
16
12
  */
17
13
  export interface PrerequisiteDetailMap {
18
14
  /** ERC-20 allowance from `owner` to `spender` must cover `required`. */
@@ -32,6 +28,12 @@ export interface PrerequisiteDetailMap {
32
28
  /** On-chain balance read; only present when the read succeeded. */
33
29
  actual?: bigint;
34
30
  };
31
+ /**
32
+ * RWA (e.g. Securitize) open-account requirements: off-chain token
33
+ * registration and/or EIP-712 signatures the borrower must provide before
34
+ * opening a credit account in an RWA market.
35
+ */
36
+ rwaOpenRequirements: RWAOpenAccountRequirements;
35
37
  }
36
38
  export type PrerequisiteKind = keyof PrerequisiteDetailMap;
37
39
  export type PrerequisiteDetail<K extends PrerequisiteKind = PrerequisiteKind> = PrerequisiteDetailMap[K];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Thrown by `previewOperation` for parsed operations it cannot preview yet.
3
+ * Currently only pool operations and credit account opening are supported.
4
+ */
5
+ export declare class UnsupportedOperationError extends Error {
6
+ /** The parsed operation kind (the `operation` discriminant). */
7
+ readonly operation: string;
8
+ constructor(operation: string);
9
+ }
@@ -1,5 +1,4 @@
1
- import type { ParsedCallV2 } from "../../sdk/index.js";
2
- import type { ExpectedBalanceChange } from "./types.js";
1
+ import type { Asset, ParsedCallV2 } from "../../sdk/index.js";
3
2
  /**
4
3
  * Recovers the potential balance changes declared by a router-generated
5
4
  * `storeExpectedBalances`/`compareBalances` pair inside a credit-facade
@@ -13,10 +12,10 @@ import type { ExpectedBalanceChange } from "./types.js";
13
12
  *
14
13
  * When the multicall does not match this shape, `undefined` is returned. On a
15
14
  * match, the `BalanceDelta[]` argument of `storeExpectedBalances` is decoded
16
- * into {@link ExpectedBalanceChange}[] (the `amount` is the signed `int256`
17
- * delta and may be negative).
15
+ * into {@link Asset}[] (the `balance` is the signed `int256` delta and may be
16
+ * negative).
18
17
  *
19
18
  * @param innerCalls - Raw (already-decoded) inner multicall calls.
20
19
  * @returns The declared balance changes, or `undefined` when not router-shaped.
21
20
  */
22
- export declare function extractExpectedBalanceChanges(innerCalls: ParsedCallV2[]): ExpectedBalanceChange[] | undefined;
21
+ export declare function extractExpectedBalanceChanges(innerCalls: ParsedCallV2[]): Asset[] | undefined;
@@ -0,0 +1,3 @@
1
+ export * from "./errors.js";
2
+ export * from "./previewOperation.js";
3
+ export * from "./types.js";
@@ -0,0 +1,4 @@
1
+ import { type PluginsMap } from "../../sdk/index.js";
2
+ import type { OpenCreditAccountOperation, SecuritizeOpenCreditAccountOperation } from "../parse/index.js";
3
+ import type { OpenCreditAccountPreview, PreviewOperationInput } from "./types.js";
4
+ export declare function previewOpenCreditAccount<P extends PluginsMap>(input: PreviewOperationInput<P>, operation: OpenCreditAccountOperation | SecuritizeOpenCreditAccountOperation): OpenCreditAccountPreview;
@@ -0,0 +1,8 @@
1
+ import type { PluginsMap } from "../../sdk/index.js";
2
+ import type { OperationSimulationOptions } from "../simulate/index.js";
3
+ import type { OperationPreview, PreviewOperationInput } from "./types.js";
4
+ /**
5
+ * Previews a raw operation calldata: decodes it into a typed operation and
6
+ * assembles an operation-specific, human-displayable preview.
7
+ */
8
+ export declare function previewOperation<P extends PluginsMap = PluginsMap>(input: PreviewOperationInput<P>, options?: OperationSimulationOptions): Promise<OperationPreview>;
@@ -0,0 +1,5 @@
1
+ import type { PluginsMap } from "../../sdk/index.js";
2
+ import type { PoolOperation } from "../parse/index.js";
3
+ import { type OperationSimulationOptions } from "../simulate/index.js";
4
+ import type { PoolOperationPreview, PreviewOperationInput } from "./types.js";
5
+ export declare function previewPoolOperation<P extends PluginsMap>(input: PreviewOperationInput<P>, operation: PoolOperation, options?: OperationSimulationOptions): Promise<PoolOperationPreview>;
@@ -0,0 +1,103 @@
1
+ import type { Address, Hex } from "viem";
2
+ import type { Asset, PluginsMap } from "../../sdk/index.js";
3
+ import type { PoolOperationType, SdkWithAdapters } from "../parse/index.js";
4
+ /**
5
+ * Input of {@link previewOperation}: the raw operation calldata plus the
6
+ * already-attached SDK
7
+ */
8
+ export interface PreviewOperationInput<P extends PluginsMap = PluginsMap> {
9
+ /**
10
+ * Already-attached SDK; chain, RPC and block are baked in at attach time.
11
+ * Must be created with the adapters plugin (enforced at compile time) so
12
+ * adapter contracts resolve during multicall classification.
13
+ */
14
+ sdk: SdkWithAdapters<P>;
15
+ /**
16
+ * Contract address that was called
17
+ */
18
+ to: Address;
19
+ /**
20
+ * Raw calldata of the operation
21
+ */
22
+ calldata: Hex;
23
+ /**
24
+ * Transaction sender
25
+ */
26
+ sender: Address;
27
+ /**
28
+ * Transaction `msg.value`
29
+ **/
30
+ value?: bigint;
31
+ }
32
+ /**
33
+ * A token amount that may require an additional async call (e.g. an ERC4626
34
+ * preview read) to determine. When that call fails, only the token address and
35
+ * the error are returned.
36
+ */
37
+ export type PreviewedAsset = Asset | {
38
+ token: Address;
39
+ error: Error;
40
+ };
41
+ export interface PoolOperationPreview {
42
+ operation: PoolOperationType;
43
+ /**
44
+ * Pool address
45
+ */
46
+ pool: Address;
47
+ /**
48
+ * Token that goes from user to pool
49
+ * In case of deposit, underlying for direct deposit, zapper input for zapper-routed deposit
50
+ * In case of withdraw, pool shares (diesel token) for direct withdraw or zapper token out
51
+ *
52
+ * For mint/withdraw the amount of tokenIn cannot be determined from
53
+ * transaction calldata alone and requires an additional async call
54
+ * (previewMint/previewWithdraw). In case of error only the token address is
55
+ * returned.
56
+ */
57
+ tokenIn: PreviewedAsset;
58
+ /**
59
+ * Token that goes from pool to user
60
+ * In case of deposit, pool shares (diesel token) for direct deposit or zapper token out
61
+ * In case of withdraw, underlying for direct withdraw or zapper token in
62
+ *
63
+ * For deposit/redeem the amount of tokenOut cannot be determined from
64
+ * transaction calldata alone and requires an additional async call
65
+ * (previewDeposit/previewRedeem). In case of error only the token address is
66
+ * returned.
67
+ */
68
+ tokenOut: PreviewedAsset;
69
+ }
70
+ export interface OpenCreditAccountPreview {
71
+ operation: "OpenCreditAccount" | "SecuritizeOpenCreditAccount";
72
+ /**
73
+ * Target token of strategy: the first quoted token, with its balance taken
74
+ * from `assets`. Undefined when nothing is quoted.
75
+ */
76
+ target?: Asset;
77
+ /**
78
+ * Tokens that were added as collateral during account opening
79
+ */
80
+ collateral: Asset[];
81
+ /**
82
+ * Sum of collateral tokens in underlying
83
+ */
84
+ collateralValue: bigint;
85
+ /**
86
+ * Borrowed amount in underlying
87
+ */
88
+ debt: bigint;
89
+ /**
90
+ * Desired quotas
91
+ */
92
+ quotas: Asset[];
93
+ /**
94
+ * Minimum amount of assets on credit account after it's opened,
95
+ * as estimated by router
96
+ */
97
+ assets: Asset[];
98
+ }
99
+ /**
100
+ * Result of previewing a raw operation calldata: currently pool operations and
101
+ * credit account opening are supported.
102
+ */
103
+ export type OperationPreview = PoolOperationPreview | OpenCreditAccountPreview;
@@ -5,4 +5,6 @@ export { simulateFacadeOperation } from "./simulateFacadeOperation.js";
5
5
  export type { SimulateOperationInput } from "./simulateOperation.js";
6
6
  export { simulateOperation } from "./simulateOperation.js";
7
7
  export { simulatePoolOperation } from "./simulatePoolOperation.js";
8
- export type { AddressBalanceChanges, OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput, PoolOperationSimulationResult, TokenBalanceChange, } from "./types.js";
8
+ export type { SimulateRWAOperationInput } from "./simulateRWAOperation.js";
9
+ export { simulateRWAOperation } from "./simulateRWAOperation.js";
10
+ export type { OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput, PoolOperationSimulationResult, } from "./types.js";
@@ -11,8 +11,6 @@ export interface SimulateFacadeOperationInput {
11
11
  to: Address;
12
12
  /** Raw credit-facade calldata to simulate. */
13
13
  calldata: Hex;
14
- /** Wallet whose balance changes and transfers we track. */
15
- wallet: Address;
16
14
  }
17
15
  /**
18
16
  * Simulates a credit-facade operation.
@@ -11,8 +11,6 @@ export interface SimulateOperationInput {
11
11
  to: Address;
12
12
  /** Raw operation calldata to simulate. */
13
13
  calldata: Hex;
14
- /** Wallet whose balance changes and transfers we track. */
15
- wallet: Address;
16
14
  }
17
15
  /**
18
16
  * Simulates a parsed pool or credit account operation {@link Operation}
@@ -1,26 +1,14 @@
1
- import type { Address } from "viem";
2
- import type { PoolOperation } from "../parse/index.js";
3
- import type { AddressBalanceChanges, OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput } from "./types.js";
4
- /** Reads a watched holder's "before" balance of a token. */
5
- export type BalanceLookup = (token: Address, holder: Address) => bigint;
1
+ import type { OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput } from "./types.js";
6
2
  /**
7
3
  * Simulates a pool deposit/mint/withdraw/redeem (direct or zapper-routed) and
8
- * returns the resulting balance changes, or a decoded failure.
4
+ * returns the resulting token amounts going in and out, or a decoded failure.
9
5
  *
10
- * Reads the watched holders' "before" balances together with the matching
11
- * preview (the pool's ERC4626 `previewDeposit`/`previewMint`/`previewWithdraw`/
12
- * `previewRedeem`, or the zapper's `previewDeposit`/`previewRedeem`) in a single
13
- * multicall, then computes the theoretical balance changes via
14
- * {@link computePoolOpBalanceChanges}. It works on every network the SDK
15
- * supports.
6
+ * Performs the matching preview read (the pool's ERC4626
7
+ * `previewDeposit`/`previewMint`/`previewWithdraw`/`previewRedeem`, or the
8
+ * zapper's `previewDeposit`/`previewRedeem`) to convert the calldata-known
9
+ * amount into its counterpart. It works on every network the SDK supports.
16
10
  *
17
11
  * It does not execute the calldata, so it ignores balance/allowance
18
12
  * prerequisites (preview reads succeed regardless).
19
13
  */
20
14
  export declare function simulatePoolOperation(input: PoolOperationSimulationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulation>;
21
- /**
22
- * Pure computation of {@link AddressBalanceChanges} for a pool operation from
23
- * its preview result and the watched holders' "before" balances. Legs sharing
24
- * the same address are grouped together.
25
- */
26
- export declare function computePoolOpBalanceChanges(operation: PoolOperation, wallet: Address, previewAmount: bigint, before: BalanceLookup): AddressBalanceChanges[];
@@ -0,0 +1,23 @@
1
+ import type { Address, Hex } from "viem";
2
+ import type { OnchainSDK } from "../../sdk/index.js";
3
+ import type { RWAOperation } from "../parse/index.js";
4
+ import type { OperationSimulationOptions, PoolOperationSimulation } from "./types.js";
5
+ export interface SimulateRWAOperationInput {
6
+ /** Only `client`/`networkType` are used, so any OnchainSDK works. */
7
+ sdk: OnchainSDK;
8
+ /** Parsed RWA-factory operation to simulate. */
9
+ operation: RWAOperation;
10
+ /** Target contract the calldata is sent to (the RWA factory). */
11
+ to: Address;
12
+ /** Raw RWA-factory calldata to simulate. */
13
+ calldata: Hex;
14
+ }
15
+ /**
16
+ * Simulates an RWA-factory operation.
17
+ *
18
+ * Not yet implemented: like credit-facade simulation, it requires
19
+ * multicall-aware balance/transfer accounting that the pool simulation does
20
+ * not cover. The signature mirrors {@link simulatePoolOperation} so the
21
+ * {@link simulateOperation} wrapper can delegate uniformly once implemented.
22
+ */
23
+ export declare function simulateRWAOperation(_input: SimulateRWAOperationInput, _options?: OperationSimulationOptions): Promise<PoolOperationSimulation>;
@@ -3,25 +3,6 @@ import type { OnchainSDK } from "../../sdk/index.js";
3
3
  import type { ILogger } from "../../sdk/types/logger.js";
4
4
  import type { PoolOperation } from "../parse/index.js";
5
5
  import type { PreviewSimulationError } from "./errors.js";
6
- /**
7
- * Change in an address's balance of a single token over the simulated call.
8
- * `delta` is `after - before` (negative when the address spent the token).
9
- */
10
- export interface TokenBalanceChange {
11
- token: Address;
12
- before: bigint;
13
- after: bigint;
14
- delta: bigint;
15
- }
16
- /**
17
- * Balance changes for a single watched address (e.g. the wallet or the
18
- * operation recipient). Keyed purely by address; UI labeling is resolved
19
- * separately by the presentation layer.
20
- */
21
- export interface AddressBalanceChanges {
22
- address: Address;
23
- changes: TokenBalanceChange[];
24
- }
25
6
  export interface PoolOperationSimulationInput {
26
7
  /** Only `client`/`networkType` are used, so any OnchainSDK works. */
27
8
  sdk: OnchainSDK;
@@ -31,8 +12,6 @@ export interface PoolOperationSimulationInput {
31
12
  to: Address;
32
13
  /** Raw deposit/mint/withdraw/redeem calldata to simulate. */
33
14
  calldata: Hex;
34
- /** Wallet whose balance changes and transfers we track. */
35
- wallet: Address;
36
15
  }
37
16
  export interface OperationSimulationOptions {
38
17
  /** Block to simulate at; defaults to latest. */
@@ -43,15 +22,22 @@ export interface OperationSimulationOptions {
43
22
  logger?: ILogger;
44
23
  }
45
24
  /**
46
- * Successful simulation of a pool operation: the balance changes grouped by
47
- * watched address. This is the success payload of
48
- * {@link PoolOperationSimulation} without the `status` discriminant.
25
+ * Successful simulation of a pool operation: the amounts of tokens going in
26
+ * and out. One side comes from calldata, the other from the matching ERC4626
27
+ * preview read. This is the success payload of {@link PoolOperationSimulation}
28
+ * without the `status` discriminant.
49
29
  */
50
30
  export interface PoolOperationSimulationResult {
51
31
  /**
52
- * Balance changes grouped by watched address (wallet, recipient, owner).
32
+ * Amount of tokens going from the user to the pool (underlying or zapper
33
+ * input token for deposit/mint, pool shares for withdraw/redeem).
34
+ **/
35
+ amountIn: bigint;
36
+ /**
37
+ * Amount of tokens going from the pool to the user (pool shares or zapper
38
+ * output token for deposit/mint, underlying for withdraw/redeem).
53
39
  **/
54
- balanceChanges: AddressBalanceChanges[];
40
+ amountOut: bigint;
55
41
  }
56
42
  /**
57
43
  * Outcome of simulating a pool operation. On success it carries a
@@ -468,6 +468,10 @@ export declare class SecuritizeRWAFactory extends BaseContract<abi> implements I
468
468
  * {@inheritDoc IRWAFactory.decodeInvestorData}
469
469
  */
470
470
  decodeInvestorData(data: RWACompressorInvestorData): SecuritizeInvestorData;
471
+ /**
472
+ * {@inheritDoc IRWAFactory.getTokens}
473
+ */
474
+ getTokens(): Address[];
471
475
  /**
472
476
  * {@inheritDoc IRWAFactory.getInvestor}
473
477
  */
@@ -102,6 +102,12 @@ export interface IRWAFactory<T extends RWAFactoryType = RWAFactoryType> extends
102
102
  * @param data - raw RWACompressor InvestorData
103
103
  **/
104
104
  decodeInvestorData(data: RWACompressorInvestorData): RWAInvestorData<T>;
105
+ /**
106
+ * Returns the RWA token addresses this factory can register/gate
107
+ * (e.g. Securitize DSTokens). Named for parity with the Solidity
108
+ * `IRWAFactory` contract.
109
+ **/
110
+ getTokens(): Address[];
105
111
  /**
106
112
  * Returns the investor address for a credit account.
107
113
  * @param creditAccount - credit account address
@@ -161,11 +167,13 @@ export interface IRWAFactory<T extends RWAFactoryType = RWAFactoryType> extends
161
167
  openCreditAccount(creditManager: Address, calls: MultiCall[], options?: RWAOperationParams<T>): RawTx;
162
168
  }
163
169
  /**
164
- * Narrows an {@link IRWAFactory} to a specific factory type.
170
+ * Narrows any contract to an {@link IRWAFactory}.
165
171
  *
166
- * @param factory - factory instance to check
167
- * @param type - expected factory type literal
168
- * @returns `true` if `factory.factoryType === type`
172
+ * @param contract - contract instance to check
173
+ * @param type - optional expected factory type literal. When provided, narrows
174
+ * to the concrete `IRWAFactory<T>`; when omitted, narrows to the
175
+ * generalized {@link IRWAFactory}
176
+ * @returns `true` if the contract is an RWA factory (of the given type, if provided)
169
177
  **/
170
- export declare function isRWAFactory<T extends RWAFactoryType>(factory: IRWAFactory, type: T): factory is IRWAFactory<T>;
178
+ export declare function isRWAFactory<T extends RWAFactoryType = RWAFactoryType>(contract: IBaseContract, type?: T): contract is IRWAFactory<T>;
171
179
  export {};
@@ -12,10 +12,8 @@ export interface ParsedZapperDeposit {
12
12
  /** Zapper contract the call is sent to. */
13
13
  zapper: Address;
14
14
  receiver: Address;
15
- /** Amount of `token` supplied to the zapper. */
15
+ /** Amount of `tokenIn` supplied to the zapper. */
16
16
  assets: bigint;
17
- /** Token actually deposited into the zapper (the zapper's `tokenIn`). */
18
- token: Address;
19
17
  /** Underlying token of the destination pool. */
20
18
  underlying: Address;
21
19
  /** Referral code, present only for `depositWithReferral(...)` calls. */
@@ -32,10 +30,12 @@ export interface ParsedZapperRedeem {
32
30
  /** Zapper contract the call is sent to. */
33
31
  zapper: Address;
34
32
  receiver: Address;
35
- /** Pool shares (diesel) burned. */
33
+ /**
34
+ * Amount of the zapper's `tokenOut` burned. This is the pool's diesel token
35
+ * only when the zapper's `tokenOut` is the pool itself; for farmed/staked
36
+ * wrappers it's denominated in the wrapper token.
37
+ */
36
38
  shares: bigint;
37
- /** Token returned to the receiver (the zapper's `tokenIn`). */
38
- token: Address;
39
39
  /** Underlying token of the source pool. */
40
40
  underlying: Address;
41
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.12.0-next.3",
3
+ "version": "14.12.0-next.5",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {