@gearbox-protocol/sdk 14.12.0-next.1 → 14.12.0-next.2

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 (80) hide show
  1. package/dist/cjs/abi/iZapper.js +62 -24
  2. package/dist/cjs/preview/parse/errors.js +5 -2
  3. package/dist/cjs/preview/parse/parseOperationCalldata.js +30 -1
  4. package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +10 -2
  5. package/dist/cjs/preview/prerequisites/buildPrerequisites.js +34 -0
  6. package/dist/cjs/preview/simulate/errors.js +0 -7
  7. package/dist/cjs/preview/simulate/index.js +0 -3
  8. package/dist/cjs/preview/simulate/simulatePoolOperation.js +154 -29
  9. package/dist/cjs/sdk/MultichainSDK.js +1 -0
  10. package/dist/cjs/sdk/OnchainSDK.js +7 -3
  11. package/dist/cjs/sdk/market/MarketRegister.js +10 -5
  12. package/dist/cjs/sdk/market/ZapperRegister.js +54 -0
  13. package/dist/cjs/sdk/market/zapper/IERC20ZapperContract.js +3 -38
  14. package/dist/cjs/sdk/market/zapper/IETHZapperContract.js +3 -38
  15. package/dist/cjs/sdk/market/zapper/ZapperContract.js +109 -0
  16. package/dist/cjs/sdk/market/zapper/createZapper.js +12 -4
  17. package/dist/cjs/{preview/simulate/constants.js → sdk/market/zapper/errors.js} +15 -6
  18. package/dist/cjs/sdk/market/zapper/index.js +6 -2
  19. package/dist/cjs/sdk/market/zapper/types.js +16 -0
  20. package/dist/cjs/sdk/options.js +41 -17
  21. package/dist/esm/abi/iZapper.js +62 -24
  22. package/dist/esm/preview/parse/errors.js +3 -1
  23. package/dist/esm/preview/parse/parseOperationCalldata.js +32 -2
  24. package/dist/esm/preview/parse/parsePoolOperationCalldata.js +10 -2
  25. package/dist/esm/preview/prerequisites/buildPrerequisites.js +34 -0
  26. package/dist/esm/preview/simulate/errors.js +0 -6
  27. package/dist/esm/preview/simulate/index.js +0 -2
  28. package/dist/esm/preview/simulate/simulatePoolOperation.js +155 -30
  29. package/dist/esm/sdk/MultichainSDK.js +1 -0
  30. package/dist/esm/sdk/OnchainSDK.js +7 -3
  31. package/dist/esm/sdk/market/MarketRegister.js +10 -5
  32. package/dist/esm/sdk/market/ZapperRegister.js +54 -0
  33. package/dist/esm/sdk/market/zapper/IERC20ZapperContract.js +3 -38
  34. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +3 -38
  35. package/dist/esm/sdk/market/zapper/ZapperContract.js +85 -0
  36. package/dist/esm/sdk/market/zapper/createZapper.js +12 -4
  37. package/dist/esm/sdk/market/zapper/errors.js +13 -0
  38. package/dist/esm/sdk/market/zapper/index.js +3 -1
  39. package/dist/esm/sdk/market/zapper/types.js +0 -0
  40. package/dist/esm/sdk/options.js +39 -15
  41. package/dist/types/abi/iERC20Zapper.d.ts +91 -23
  42. package/dist/types/abi/iETHZapper.d.ts +91 -23
  43. package/dist/types/abi/iZapper.d.ts +91 -23
  44. package/dist/types/preview/parse/errors.d.ts +1 -0
  45. package/dist/types/preview/parse/parseOperationCalldata.d.ts +3 -3
  46. package/dist/types/preview/parse/types-pools.d.ts +61 -1
  47. package/dist/types/preview/simulate/errors.d.ts +6 -12
  48. package/dist/types/preview/simulate/index.d.ts +0 -1
  49. package/dist/types/preview/simulate/simulatePoolOperation.d.ts +22 -4
  50. package/dist/types/preview/simulate/types.d.ts +3 -16
  51. package/dist/types/sdk/MultichainSDK.d.ts +5 -0
  52. package/dist/types/sdk/OnchainSDK.d.ts +4 -0
  53. package/dist/types/sdk/market/MarketRegister.d.ts +15 -6
  54. package/dist/types/sdk/market/ZapperRegister.d.ts +25 -4
  55. package/dist/types/sdk/market/zapper/IERC20ZapperContract.d.ts +93 -39
  56. package/dist/types/sdk/market/zapper/IETHZapperContract.d.ts +93 -39
  57. package/dist/types/sdk/market/zapper/ZapperContract.d.ts +35 -0
  58. package/dist/types/sdk/market/zapper/createZapper.d.ts +2 -4
  59. package/dist/types/sdk/market/zapper/errors.d.ts +10 -0
  60. package/dist/types/sdk/market/zapper/index.d.ts +3 -1
  61. package/dist/types/sdk/market/zapper/types.d.ts +64 -0
  62. package/dist/types/sdk/options.d.ts +10 -5
  63. package/dist/types/sdk/pools/types.d.ts +3 -3
  64. package/dist/types/sdk/types/state-human.d.ts +9 -0
  65. package/dist/types/sdk/types/state.d.ts +7 -0
  66. package/package.json +3 -3
  67. package/dist/cjs/preview/simulate/extractERC20Transfers.js +0 -47
  68. package/dist/cjs/preview/simulate/simulatePoolOpMulticall.js +0 -155
  69. package/dist/cjs/preview/simulate/simulatePoolOpV1.js +0 -106
  70. package/dist/cjs/sdk/market/zapper/Zapper.js +0 -47
  71. package/dist/esm/preview/simulate/constants.js +0 -4
  72. package/dist/esm/preview/simulate/extractERC20Transfers.js +0 -23
  73. package/dist/esm/preview/simulate/simulatePoolOpMulticall.js +0 -130
  74. package/dist/esm/preview/simulate/simulatePoolOpV1.js +0 -82
  75. package/dist/esm/sdk/market/zapper/Zapper.js +0 -23
  76. package/dist/types/preview/simulate/constants.d.ts +0 -6
  77. package/dist/types/preview/simulate/extractERC20Transfers.d.ts +0 -11
  78. package/dist/types/preview/simulate/simulatePoolOpMulticall.d.ts +0 -28
  79. package/dist/types/preview/simulate/simulatePoolOpV1.d.ts +0 -14
  80. package/dist/types/sdk/market/zapper/Zapper.d.ts +0 -13
@@ -1,121 +1,189 @@
1
1
  export declare const iZapperAbi: readonly [{
2
2
  readonly type: "function";
3
+ readonly name: "contractType";
3
4
  readonly inputs: readonly [];
5
+ readonly outputs: readonly [{
6
+ readonly name: "";
7
+ readonly type: "bytes32";
8
+ readonly internalType: "bytes32";
9
+ }];
10
+ readonly stateMutability: "view";
11
+ }, {
12
+ readonly type: "function";
4
13
  readonly name: "pool";
14
+ readonly inputs: readonly [];
5
15
  readonly outputs: readonly [{
6
16
  readonly name: "";
7
- readonly internalType: "address";
8
17
  readonly type: "address";
18
+ readonly internalType: "address";
9
19
  }];
10
20
  readonly stateMutability: "view";
11
21
  }, {
12
22
  readonly type: "function";
23
+ readonly name: "previewDeposit";
13
24
  readonly inputs: readonly [{
14
25
  readonly name: "tokenInAmount";
15
- readonly internalType: "uint256";
16
26
  readonly type: "uint256";
27
+ readonly internalType: "uint256";
17
28
  }];
18
- readonly name: "previewDeposit";
19
29
  readonly outputs: readonly [{
20
30
  readonly name: "tokenOutAmount";
21
- readonly internalType: "uint256";
22
31
  readonly type: "uint256";
32
+ readonly internalType: "uint256";
23
33
  }];
24
34
  readonly stateMutability: "view";
25
35
  }, {
26
36
  readonly type: "function";
37
+ readonly name: "previewRedeem";
27
38
  readonly inputs: readonly [{
28
39
  readonly name: "tokenOutAmount";
29
- readonly internalType: "uint256";
30
40
  readonly type: "uint256";
41
+ readonly internalType: "uint256";
31
42
  }];
32
- readonly name: "previewRedeem";
33
43
  readonly outputs: readonly [{
34
44
  readonly name: "tokenInAmount";
35
- readonly internalType: "uint256";
36
45
  readonly type: "uint256";
46
+ readonly internalType: "uint256";
37
47
  }];
38
48
  readonly stateMutability: "view";
39
49
  }, {
40
50
  readonly type: "function";
51
+ readonly name: "redeem";
41
52
  readonly inputs: readonly [{
42
53
  readonly name: "tokenOutAmount";
43
- readonly internalType: "uint256";
44
54
  readonly type: "uint256";
55
+ readonly internalType: "uint256";
45
56
  }, {
46
57
  readonly name: "receiver";
47
- readonly internalType: "address";
48
58
  readonly type: "address";
59
+ readonly internalType: "address";
49
60
  }];
50
- readonly name: "redeem";
51
61
  readonly outputs: readonly [{
52
62
  readonly name: "tokenInAmount";
53
- readonly internalType: "uint256";
54
63
  readonly type: "uint256";
64
+ readonly internalType: "uint256";
55
65
  }];
56
66
  readonly stateMutability: "nonpayable";
57
67
  }, {
58
68
  readonly type: "function";
69
+ readonly name: "redeemWithPermit";
59
70
  readonly inputs: readonly [{
60
71
  readonly name: "tokenOutAmount";
61
- readonly internalType: "uint256";
62
72
  readonly type: "uint256";
73
+ readonly internalType: "uint256";
63
74
  }, {
64
75
  readonly name: "receiver";
65
- readonly internalType: "address";
66
76
  readonly type: "address";
77
+ readonly internalType: "address";
67
78
  }, {
68
79
  readonly name: "deadline";
69
- readonly internalType: "uint256";
70
80
  readonly type: "uint256";
81
+ readonly internalType: "uint256";
71
82
  }, {
72
83
  readonly name: "v";
73
- readonly internalType: "uint8";
74
84
  readonly type: "uint8";
85
+ readonly internalType: "uint8";
75
86
  }, {
76
87
  readonly name: "r";
77
- readonly internalType: "bytes32";
78
88
  readonly type: "bytes32";
89
+ readonly internalType: "bytes32";
79
90
  }, {
80
91
  readonly name: "s";
81
- readonly internalType: "bytes32";
82
92
  readonly type: "bytes32";
93
+ readonly internalType: "bytes32";
83
94
  }];
84
- readonly name: "redeemWithPermit";
85
95
  readonly outputs: readonly [{
86
96
  readonly name: "tokenInAmount";
97
+ readonly type: "uint256";
87
98
  readonly internalType: "uint256";
99
+ }];
100
+ readonly stateMutability: "nonpayable";
101
+ }, {
102
+ readonly type: "function";
103
+ readonly name: "redeemWithPermitAllowed";
104
+ readonly inputs: readonly [{
105
+ readonly name: "tokenOutAmount";
88
106
  readonly type: "uint256";
107
+ readonly internalType: "uint256";
108
+ }, {
109
+ readonly name: "receiver";
110
+ readonly type: "address";
111
+ readonly internalType: "address";
112
+ }, {
113
+ readonly name: "nonce";
114
+ readonly type: "uint256";
115
+ readonly internalType: "uint256";
116
+ }, {
117
+ readonly name: "expiry";
118
+ readonly type: "uint256";
119
+ readonly internalType: "uint256";
120
+ }, {
121
+ readonly name: "v";
122
+ readonly type: "uint8";
123
+ readonly internalType: "uint8";
124
+ }, {
125
+ readonly name: "r";
126
+ readonly type: "bytes32";
127
+ readonly internalType: "bytes32";
128
+ }, {
129
+ readonly name: "s";
130
+ readonly type: "bytes32";
131
+ readonly internalType: "bytes32";
132
+ }];
133
+ readonly outputs: readonly [{
134
+ readonly name: "tokenInAmount";
135
+ readonly type: "uint256";
136
+ readonly internalType: "uint256";
89
137
  }];
90
138
  readonly stateMutability: "nonpayable";
91
139
  }, {
92
140
  readonly type: "function";
141
+ readonly name: "serialize";
93
142
  readonly inputs: readonly [];
143
+ readonly outputs: readonly [{
144
+ readonly name: "serializedData";
145
+ readonly type: "bytes";
146
+ readonly internalType: "bytes";
147
+ }];
148
+ readonly stateMutability: "view";
149
+ }, {
150
+ readonly type: "function";
94
151
  readonly name: "tokenIn";
152
+ readonly inputs: readonly [];
95
153
  readonly outputs: readonly [{
96
154
  readonly name: "";
97
- readonly internalType: "address";
98
155
  readonly type: "address";
156
+ readonly internalType: "address";
99
157
  }];
100
158
  readonly stateMutability: "view";
101
159
  }, {
102
160
  readonly type: "function";
103
- readonly inputs: readonly [];
104
161
  readonly name: "tokenOut";
162
+ readonly inputs: readonly [];
105
163
  readonly outputs: readonly [{
106
164
  readonly name: "";
107
- readonly internalType: "address";
108
165
  readonly type: "address";
166
+ readonly internalType: "address";
109
167
  }];
110
168
  readonly stateMutability: "view";
111
169
  }, {
112
170
  readonly type: "function";
113
- readonly inputs: readonly [];
114
171
  readonly name: "underlying";
172
+ readonly inputs: readonly [];
115
173
  readonly outputs: readonly [{
116
174
  readonly name: "";
117
- readonly internalType: "address";
118
175
  readonly type: "address";
176
+ readonly internalType: "address";
177
+ }];
178
+ readonly stateMutability: "view";
179
+ }, {
180
+ readonly type: "function";
181
+ readonly name: "version";
182
+ readonly inputs: readonly [];
183
+ readonly outputs: readonly [{
184
+ readonly name: "";
185
+ readonly type: "uint256";
186
+ readonly internalType: "uint256";
119
187
  }];
120
188
  readonly stateMutability: "view";
121
189
  }];
@@ -1,4 +1,5 @@
1
1
  import type { Address } from "viem";
2
+ export { UnsupportedZapperFunctionError } from "../../sdk/index.js";
2
3
  /**
3
4
  * Thrown when the target of a transaction is neither a known Gearbox pool nor a
4
5
  * credit facade.
@@ -12,12 +12,12 @@ export interface ParseOperationCalldataInput<P extends PluginsMap = PluginsMap>
12
12
  calldata: Hex;
13
13
  /** Transaction sender, contextual only. */
14
14
  sender: Address;
15
+ /** Transaction `msg.value`, required for native-token zapper deposits. */
16
+ value?: bigint;
15
17
  }
16
18
  /**
17
19
  * Decodes raw operation calldata into an {@link Operation}.
18
20
  *
19
- * Routes by the resolved contract at `to`: a pool yields a deposit/redeem
20
- * operation, a credit facade yields one facade operation. Anything else throws
21
- * {@link UnsupportedTargetError}.
21
+ * Support parsing of pool operations (including via zappers) and credit facade operations.
22
22
  */
23
23
  export declare function parseOperationCalldata<P extends PluginsMap>(input: ParseOperationCalldataInput<P>): Operation;
@@ -1,14 +1,30 @@
1
1
  import type { Address } from "viem";
2
2
  /**
3
3
  * ERC4626 `deposit` into a Gearbox pool.
4
+ *
5
+ * A deposit can reach the pool directly (an ERC4626 call sent straight to the
6
+ * pool contract) or through a zapper (e.g. RWA-default pools and classic zapper
7
+ * pools). When routed through a zapper, `zapper` is the call target and
8
+ * `tokenIn` is the zapper's input token rather than the pool underlying.
4
9
  */
5
10
  export interface PoolDepositOperation {
11
+ /** ERC4626 operation kind. */
6
12
  operation: "Deposit";
13
+ /** Destination pool the assets are deposited into. */
7
14
  pool: Address;
15
+ /** Address credited with the minted pool shares. */
8
16
  receiver: Address;
9
- /** Underlying assets supplied to the pool. */
17
+ /** Amount of underlying assets supplied to the pool. */
10
18
  assets: bigint;
19
+ /** Underlying token of the destination pool. */
11
20
  underlying: Address;
21
+ /**
22
+ * Token actually supplied by the caller: the pool underlying for direct
23
+ * deposits, or the zapper's input token for zapper-routed deposits.
24
+ */
25
+ tokenIn: Address;
26
+ /** Zapper contract the call is sent to; `undefined` for direct deposits. */
27
+ zapper?: Address;
12
28
  /** Referral code, present only for `depositWithReferral` calls. */
13
29
  referralCode?: bigint;
14
30
  }
@@ -17,12 +33,23 @@ export interface PoolDepositOperation {
17
33
  * amount of shares to mint; the assets pulled are resolved by the pool.
18
34
  */
19
35
  export interface PoolMintOperation {
36
+ /** ERC4626 operation kind. */
20
37
  operation: "Mint";
38
+ /** Destination pool the shares are minted from. */
21
39
  pool: Address;
40
+ /** Address credited with the minted pool shares. */
22
41
  receiver: Address;
23
42
  /** Pool shares (diesel) minted to the receiver. */
24
43
  shares: bigint;
44
+ /** Underlying token of the destination pool. */
25
45
  underlying: Address;
46
+ /**
47
+ * Token actually supplied by the caller: the pool underlying for direct
48
+ * mints, or the zapper's input token for zapper-routed mints.
49
+ */
50
+ tokenIn: Address;
51
+ /** Zapper contract the call is sent to; `undefined` for direct mints. */
52
+ zapper?: Address;
26
53
  /** Referral code, present only for `mintWithReferral` calls. */
27
54
  referralCode?: bigint;
28
55
  }
@@ -32,24 +59,57 @@ export interface PoolMintOperation {
32
59
  * the pool.
33
60
  */
34
61
  export interface PoolWithdrawOperation {
62
+ /** ERC4626 operation kind. */
35
63
  operation: "Withdraw";
64
+ /** Source pool the assets are withdrawn from. */
36
65
  pool: Address;
66
+ /** Address that receives the withdrawn tokens. */
37
67
  receiver: Address;
68
+ /** Address whose pool shares are burned. */
38
69
  owner: Address;
39
70
  /** Underlying assets withdrawn to the receiver. */
40
71
  assets: bigint;
72
+ /** Underlying token of the source pool. */
41
73
  underlying: Address;
74
+ /**
75
+ * Token actually returned to the receiver: the pool underlying for direct
76
+ * withdrawals, or the zapper's output token for zapper-routed withdrawals.
77
+ */
78
+ tokenOut: Address;
79
+ /** Zapper contract the call is sent to; `undefined` for direct withdrawals. */
80
+ zapper?: Address;
42
81
  }
43
82
  /**
44
83
  * ERC4626 `redeem` from a Gearbox pool.
84
+ *
85
+ * A redeem can reach the pool directly or through a zapper. When routed through
86
+ * a zapper, `zapper` is the call target and `tokenOut` is the zapper's output
87
+ * token rather than the pool underlying.
45
88
  */
46
89
  export interface PoolRedeemOperation {
90
+ /** ERC4626 operation kind. */
47
91
  operation: "Redeem";
92
+ /** Source pool the shares are redeemed from. */
48
93
  pool: Address;
94
+ /** Address that receives the redeemed tokens. */
49
95
  receiver: Address;
96
+ /** Address whose pool shares are burned. */
50
97
  owner: Address;
51
98
  /** Pool shares (diesel) burned. */
52
99
  shares: bigint;
100
+ /** Underlying token of the source pool. */
53
101
  underlying: Address;
102
+ /**
103
+ * Token actually returned to the receiver: the pool underlying for direct
104
+ * redeems, or the zapper's output token for zapper-routed redeems.
105
+ */
106
+ tokenOut: Address;
107
+ /** Zapper contract the call is sent to; `undefined` for direct redeems. */
108
+ zapper?: Address;
54
109
  }
110
+ /**
111
+ * ERC4626 pool operations. Each operation may be sent directly to the pool
112
+ * contract or routed through a zapper (indicated by the optional `zapper`
113
+ * field).
114
+ */
55
115
  export type PoolOperation = PoolDepositOperation | PoolMintOperation | PoolWithdrawOperation | PoolRedeemOperation;
@@ -1,17 +1,14 @@
1
1
  import { BaseError, type Hex } from "viem";
2
2
  /** Which simulation flow produced a failure. */
3
- export type SimulationFlowSource = "eth_simulateV1" | "multicall" | "unknown";
3
+ export type SimulationFlowSource = "multicall" | "unknown";
4
4
  /** A single flow failure with its decoded revert detail. */
5
5
  export interface SimulationFlowFailure {
6
6
  source: SimulationFlowSource;
7
7
  detail: SimulationError;
8
8
  }
9
9
  /**
10
- * Error returned by the pool simulation when all attempted flows fail.
11
- *
12
- * On a single-flow failure it wraps that flow's decoded revert reason; when both
13
- * the `eth_simulateV1` and multicall flows fail, it carries the details of both
14
- * (see {@link failures}).
10
+ * Error returned by the pool simulation when it fails. It wraps the flow's
11
+ * decoded revert reason (see {@link failures}).
15
12
  */
16
13
  export declare class PreviewSimulationError extends BaseError {
17
14
  name: string;
@@ -24,8 +21,6 @@ export declare class PreviewSimulationError extends BaseError {
24
21
  * Pass-through when it already is one; otherwise decodes it under `source`.
25
22
  */
26
23
  export declare function asPreviewSimulationError(reason: unknown, source: SimulationFlowSource): PreviewSimulationError;
27
- /** Merges several {@link PreviewSimulationError}s into one carrying all failures. */
28
- export declare function combinePreviewSimulationErrors(...errors: (PreviewSimulationError | undefined)[]): PreviewSimulationError;
29
24
  /** Decoded revert of the simulated transaction. */
30
25
  export interface SimulationError {
31
26
  /** Human-readable revert reason / error name. */
@@ -33,17 +28,16 @@ export interface SimulationError {
33
28
  /** Original error, kept for debugging. */
34
29
  cause?: unknown;
35
30
  }
36
- /** Per-call slice of a `simulateCalls` failure we need to decode. */
31
+ /** Per-call slice of a multicall failure we need to decode. */
37
32
  export interface SimulationRevert {
38
33
  error?: Error;
39
34
  /** Raw revert return data, when present. */
40
35
  data?: Hex;
41
36
  }
42
37
  /**
43
- * Decodes a simulated transaction revert into a {@link SimulationError}.
38
+ * Decodes a simulated call revert into a {@link SimulationError}.
44
39
  *
45
- * The simulated call is raw calldata (no ABI), so viem cannot decode the revert
46
- * itself. We first try to decode the raw return bytes against the SDK's
40
+ * We first try to decode any raw return bytes against the SDK's
47
41
  * {@link errorAbis} (Gearbox protocol exceptions plus standard ERC-20 custom
48
42
  * errors); failing that, we walk viem's error chain for a
49
43
  * {@link ContractFunctionRevertedError} (covers `Error(string)` / `Panic`).
@@ -1,4 +1,3 @@
1
- export { ETH_SIMULATE_V1_NETWORKS } from "./constants.js";
2
1
  export type { SimulationError, SimulationFlowFailure, SimulationFlowSource, } from "./errors.js";
3
2
  export { PreviewSimulationError } from "./errors.js";
4
3
  export type { SimulateFacadeOperationInput } from "./simulateFacadeOperation.js";
@@ -1,8 +1,26 @@
1
- import type { OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput } from "./types.js";
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;
2
6
  /**
3
- * Simulates a pool deposit/mint/withdraw/redeem and returns the resulting
4
- * balance changes (and, when available, ERC-20 transfers), or a decoded failure.
7
+ * Simulates a pool deposit/mint/withdraw/redeem (direct or zapper-routed) and
8
+ * returns the resulting balance changes, or a decoded failure.
5
9
  *
6
- * @throws {@link PreviewSimulationError} when the simulation fails.
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.
16
+ *
17
+ * It does not execute the calldata, so it ignores balance/allowance
18
+ * prerequisites (preview reads succeed regardless).
7
19
  */
8
20
  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[];
@@ -1,7 +1,7 @@
1
1
  import type { Address, Hex } from "viem";
2
2
  import type { OnchainSDK } from "../../sdk/index.js";
3
3
  import type { ILogger } from "../../sdk/types/logger.js";
4
- import type { PoolOperation, TokenTransfer } from "../parse/index.js";
4
+ import type { PoolOperation } from "../parse/index.js";
5
5
  import type { PreviewSimulationError } from "./errors.js";
6
6
  /**
7
7
  * Change in an address's balance of a single token over the simulated call.
@@ -37,12 +37,6 @@ export interface PoolOperationSimulationInput {
37
37
  export interface OperationSimulationOptions {
38
38
  /** Block to simulate at; defaults to latest. */
39
39
  blockNumber?: bigint;
40
- /**
41
- * Whether to run the `eth_simulateV1` flow (preferred, recovers transfers).
42
- * When `undefined`, defaults to whether the SDK's network is in
43
- * {@link ETH_SIMULATE_V1_NETWORKS}.
44
- */
45
- useSimulateV1?: boolean;
46
40
  /**
47
41
  * Optional logger.
48
42
  **/
@@ -50,21 +44,14 @@ export interface OperationSimulationOptions {
50
44
  }
51
45
  /**
52
46
  * Successful simulation of a pool operation: the balance changes grouped by
53
- * watched address and, when available, the wallet-filtered ERC-20 transfers.
54
- * This is the success payload of {@link PoolOperationSimulation} without the
55
- * `status` discriminant.
47
+ * watched address. This is the success payload of
48
+ * {@link PoolOperationSimulation} without the `status` discriminant.
56
49
  */
57
50
  export interface PoolOperationSimulationResult {
58
51
  /**
59
52
  * Balance changes grouped by watched address (wallet, recipient, owner).
60
53
  **/
61
54
  balanceChanges: AddressBalanceChanges[];
62
- /**
63
- * ERC-20 transfers involving the watched addresses.
64
- *
65
- * NOTE: transfers are **not guaranteed** to be returned.
66
- */
67
- transfers?: TokenTransfer[];
68
55
  }
69
56
  /**
70
57
  * Outcome of simulating a pool operation. On success it carries a
@@ -55,6 +55,11 @@ export interface MultichainAttachOptions {
55
55
  * Options for Pyth price-feed updates (shared cache across chains).
56
56
  **/
57
57
  pyth?: PythOptions;
58
+ /**
59
+ * When `true`, automatically load zappers after markets are loaded during
60
+ * attach on every chain.
61
+ **/
62
+ loadZappers?: boolean;
58
63
  }
59
64
  /**
60
65
  * Options for {@link MultichainSDK.hydrate}.
@@ -117,6 +117,10 @@ export interface AttachOptions {
117
117
  * Options for Pyth price-feed updates.
118
118
  **/
119
119
  pyth?: PythOptions;
120
+ /**
121
+ * When `true`, automatically call {@link MarketRegister.loadZappers} during attach.
122
+ **/
123
+ loadZappers?: boolean;
120
124
  }
121
125
  /**
122
126
  * Options accepted by {@link OnchainSDK.hydrate}.
@@ -1,7 +1,7 @@
1
1
  import type { Address } from "viem";
2
2
  import type { MarketData, MarketFilter } from "../base/index.js";
3
3
  import type { OnchainSDK } from "../OnchainSDK.js";
4
- import type { MarketStateHuman } from "../types/index.js";
4
+ import type { MarketStateHuman, ZapperStateHuman } from "../types/index.js";
5
5
  import { AddressMap } from "../utils/index.js";
6
6
  import { type DelegatedMulticall } from "../utils/viem/index.js";
7
7
  import type { CreditSuite } from "./credit/index.js";
@@ -9,7 +9,18 @@ import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
9
9
  import { MarketSuite } from "./MarketSuite.js";
10
10
  import type { IPriceOracleContract } from "./oracle/index.js";
11
11
  import type { PoolSuite } from "./pool/index.js";
12
+ import type { ZapperData } from "./types.js";
12
13
  import { ZapperRegister } from "./ZapperRegister.js";
14
+ /** @internal */
15
+ export interface MarketRegistryState {
16
+ markets: MarketData[];
17
+ zappers?: ZapperData[];
18
+ }
19
+ /** @internal */
20
+ export interface MarketRegistryStateHuman {
21
+ markets: MarketStateHuman[];
22
+ zappers?: ZapperStateHuman[];
23
+ }
13
24
  /**
14
25
  * Central registry of all Gearbox markets on the current chain.
15
26
  *
@@ -29,7 +40,7 @@ export declare class MarketRegister extends ZapperRegister {
29
40
  * bypassing on-chain reads.
30
41
  * @param state - Array of market data snapshots.
31
42
  **/
32
- hydrate(state: MarketData[]): void;
43
+ hydrate({ markets, zappers }: MarketRegistryState): void;
33
44
  /**
34
45
  * @internal
35
46
  * Returns delegated multicalls for loading all markets from the on-chain
@@ -57,14 +68,12 @@ export declare class MarketRegister extends ZapperRegister {
57
68
  /**
58
69
  * Serializable snapshot of all loaded markets, suitable for hydration.
59
70
  **/
60
- get state(): MarketData[];
71
+ get state(): MarketRegistryState;
61
72
  /**
62
73
  * Returns a human-readable snapshot of all markets.
63
74
  * @param raw - When `true`, includes raw/unformatted values.
64
75
  **/
65
- stateHuman(raw?: boolean): {
66
- markets: MarketStateHuman[];
67
- };
76
+ stateHuman(raw?: boolean): MarketRegistryStateHuman;
68
77
  /**
69
78
  * All pool suites across loaded markets.
70
79
  **/
@@ -1,17 +1,38 @@
1
1
  import type { Address } from "viem";
2
2
  import { SDKConstruct } from "../base/index.js";
3
+ import type { ZapperStateHuman } from "../types/index.js";
3
4
  import { AddressMap } from "../utils/index.js";
4
- import { type Zapper } from "./zapper/index.js";
5
+ import type { ZapperData } from "./types.js";
6
+ import { type IZapperContract } from "./zapper/index.js";
5
7
  export declare class ZapperRegister extends SDKConstruct {
6
8
  #private;
7
9
  /**
8
10
  * Load zappers for all pools using periphery compressor, adds hardcoded zappers
9
11
  */
10
12
  loadZappers(force?: boolean): Promise<void>;
11
- get zappers(): AddressMap<Zapper[]>;
12
- poolZappers(pool: Address): Zapper[];
13
+ /**
14
+ * Serializable snapshot of all loaded zappers, suitable for hydration.
15
+ * Returns `undefined` when zappers were never loaded (i.e. `loadZappers` was
16
+ * not called), so the not-loaded state round-trips cleanly.
17
+ **/
18
+ protected get zappersState(): ZapperData[] | undefined;
19
+ /**
20
+ * Restores zapper state from a previously serialized snapshot,
21
+ * bypassing on-chain reads.
22
+ * @param state - Array of zapper data snapshots, or `undefined` when zappers
23
+ * were not loaded in the snapshot (leaves the registry in the not-loaded state).
24
+ **/
25
+ protected hydrateZappers(state?: ZapperData[]): void;
26
+ /**
27
+ * Returns a human-readable snapshot of all loaded zappers.
28
+ * Returns `undefined` when zappers were never loaded.
29
+ * @param raw - When `true`, includes raw/unformatted values.
30
+ **/
31
+ protected zappersStateHuman(_?: boolean): ZapperStateHuman[] | undefined;
32
+ get zappers(): AddressMap<IZapperContract[]>;
33
+ poolZappers(pool: Address): IZapperContract[];
13
34
  /**
14
35
  * Can return multiple zappers if there are multiple zappers for the same tokenIn and tokenOut
15
36
  */
16
- getZapper(pool: Address, tokenIn: Address, tokenOut: Address): Array<Zapper> | undefined;
37
+ getZapper(pool: Address, tokenIn: Address, tokenOut: Address): Array<IZapperContract> | undefined;
17
38
  }