@gearbox-protocol/sdk 14.11.0-next.6 → 14.11.0-next.8
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.
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +21 -6
- package/dist/cjs/preview/parse/types.js +1 -1
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +46 -0
- package/dist/cjs/preview/simulate/constants.js +28 -0
- package/dist/cjs/preview/simulate/{decodeSimulationError.js → errors.js} +37 -3
- package/dist/cjs/preview/simulate/holders.js +45 -0
- package/dist/cjs/preview/simulate/index.js +21 -13
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +1 -1
- package/dist/cjs/preview/simulate/simulateOperation.js +3 -3
- package/dist/cjs/preview/simulate/simulatePoolOpMulticall.js +155 -0
- package/dist/cjs/preview/simulate/simulatePoolOpV1.js +106 -0
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +30 -62
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +21 -6
- package/dist/esm/preview/parse/types.js +1 -1
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +46 -0
- package/dist/esm/preview/simulate/constants.js +4 -0
- package/dist/esm/preview/simulate/{decodeSimulationError.js → errors.js} +31 -0
- package/dist/esm/preview/simulate/holders.js +21 -0
- package/dist/esm/preview/simulate/index.js +12 -6
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +1 -1
- package/dist/esm/preview/simulate/simulateOperation.js +3 -3
- package/dist/esm/preview/simulate/simulatePoolOpMulticall.js +130 -0
- package/dist/esm/preview/simulate/simulatePoolOpV1.js +82 -0
- package/dist/esm/preview/simulate/simulatePoolOperation.js +33 -62
- package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +4 -2
- package/dist/types/preview/parse/types-pools.d.ts +29 -16
- package/dist/types/preview/parse/types.d.ts +3 -3
- package/dist/types/preview/simulate/constants.d.ts +6 -0
- package/dist/types/preview/simulate/errors.d.ts +51 -0
- package/dist/types/preview/simulate/holders.d.ts +7 -0
- package/dist/types/preview/simulate/index.d.ts +9 -6
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +3 -5
- package/dist/types/preview/simulate/simulateOperation.d.ts +5 -11
- package/dist/types/preview/simulate/simulatePoolOpMulticall.d.ts +28 -0
- package/dist/types/preview/simulate/simulatePoolOpV1.d.ts +14 -0
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +5 -27
- package/dist/types/preview/simulate/types.d.ts +54 -18
- package/package.json +1 -1
- package/dist/types/preview/simulate/decodeSimulationError.d.ts +0 -18
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type { TokenTransfer } from "./types-adapters.js";
|
|
3
2
|
/**
|
|
4
3
|
* ERC4626 `deposit` into a Gearbox pool.
|
|
5
|
-
* Token metadata (symbol/decimals) is intentionally omitted: consumers resolve
|
|
6
|
-
* it from `sdk.tokensMeta` using the token addresses below.
|
|
7
4
|
*/
|
|
8
5
|
export interface PoolDepositOperation {
|
|
9
6
|
operation: "Deposit";
|
|
@@ -14,16 +11,37 @@ export interface PoolDepositOperation {
|
|
|
14
11
|
underlying: Address;
|
|
15
12
|
/** Referral code, present only for `depositWithReferral` calls. */
|
|
16
13
|
referralCode?: bigint;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* ERC4626 `mint` into a Gearbox pool. Unlike `deposit`, the caller specifies the
|
|
17
|
+
* amount of shares to mint; the assets pulled are resolved by the pool.
|
|
18
|
+
*/
|
|
19
|
+
export interface PoolMintOperation {
|
|
20
|
+
operation: "Mint";
|
|
21
|
+
pool: Address;
|
|
22
|
+
receiver: Address;
|
|
23
|
+
/** Pool shares (diesel) minted to the receiver. */
|
|
24
|
+
shares: bigint;
|
|
25
|
+
underlying: Address;
|
|
26
|
+
/** Referral code, present only for `mintWithReferral` calls. */
|
|
27
|
+
referralCode?: bigint;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* ERC4626 `withdraw` from a Gearbox pool. Unlike `redeem`, the caller specifies
|
|
31
|
+
* the amount of underlying assets to withdraw; the shares burned are resolved by
|
|
32
|
+
* the pool.
|
|
33
|
+
*/
|
|
34
|
+
export interface PoolWithdrawOperation {
|
|
35
|
+
operation: "Withdraw";
|
|
36
|
+
pool: Address;
|
|
37
|
+
receiver: Address;
|
|
38
|
+
owner: Address;
|
|
39
|
+
/** Underlying assets withdrawn to the receiver. */
|
|
40
|
+
assets: bigint;
|
|
41
|
+
underlying: Address;
|
|
22
42
|
}
|
|
23
43
|
/**
|
|
24
44
|
* ERC4626 `redeem` from a Gearbox pool.
|
|
25
|
-
* Token metadata (symbol/decimals) is intentionally omitted: consumers resolve
|
|
26
|
-
* it from `sdk.tokensMeta` using the token addresses below.
|
|
27
45
|
*/
|
|
28
46
|
export interface PoolRedeemOperation {
|
|
29
47
|
operation: "Redeem";
|
|
@@ -33,10 +51,5 @@ export interface PoolRedeemOperation {
|
|
|
33
51
|
/** Pool shares (diesel) burned. */
|
|
34
52
|
shares: bigint;
|
|
35
53
|
underlying: Address;
|
|
36
|
-
/**
|
|
37
|
-
* ERC-20 transfers involving the wallet, recovered by simulating the call.
|
|
38
|
-
* Empty for the calldata-only parse; populated by the simulation stage.
|
|
39
|
-
*/
|
|
40
|
-
transfers: TokenTransfer[];
|
|
41
54
|
}
|
|
42
|
-
export type PoolOperation = PoolDepositOperation | PoolRedeemOperation;
|
|
55
|
+
export type PoolOperation = PoolDepositOperation | PoolMintOperation | PoolWithdrawOperation | PoolRedeemOperation;
|
|
@@ -37,8 +37,8 @@ export type SdkWithAdapters<P extends PluginsMap = PluginsMap> = OnchainSDK<P> &
|
|
|
37
37
|
*/
|
|
38
38
|
export type Operation = PoolOperation | OuterFacadeOperation;
|
|
39
39
|
/**
|
|
40
|
-
* Narrows an {@link Operation} to a {@link PoolOperation} (deposit
|
|
41
|
-
* Used by the UI to decide whether a custom view exists for
|
|
42
|
-
* everything else falls back to the raw JSON view.
|
|
40
|
+
* Narrows an {@link Operation} to a {@link PoolOperation} (deposit, mint,
|
|
41
|
+
* withdraw or redeem). Used by the UI to decide whether a custom view exists for
|
|
42
|
+
* the parsed result; everything else falls back to the raw JSON view.
|
|
43
43
|
*/
|
|
44
44
|
export declare function isPoolOperation(tx: Operation): tx is PoolOperation;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { NetworkType } from "../../sdk/chain/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Networks where the `eth_simulateV1` JSON-RPC method is available and usable
|
|
4
|
+
* for pool or credit account operation simulation.
|
|
5
|
+
**/
|
|
6
|
+
export declare const ETH_SIMULATE_V1_NETWORKS: ReadonlySet<NetworkType>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BaseError, type Hex } from "viem";
|
|
2
|
+
/** Which simulation flow produced a failure. */
|
|
3
|
+
export type SimulationFlowSource = "eth_simulateV1" | "multicall" | "unknown";
|
|
4
|
+
/** A single flow failure with its decoded revert detail. */
|
|
5
|
+
export interface SimulationFlowFailure {
|
|
6
|
+
source: SimulationFlowSource;
|
|
7
|
+
detail: SimulationError;
|
|
8
|
+
}
|
|
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}).
|
|
15
|
+
*/
|
|
16
|
+
export declare class PreviewSimulationError extends BaseError {
|
|
17
|
+
name: string;
|
|
18
|
+
/** Per-flow decoded failures behind this error. */
|
|
19
|
+
readonly failures: SimulationFlowFailure[];
|
|
20
|
+
constructor(failures: SimulationFlowFailure[]);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Normalises an unknown rejection reason into a {@link PreviewSimulationError}.
|
|
24
|
+
* Pass-through when it already is one; otherwise decodes it under `source`.
|
|
25
|
+
*/
|
|
26
|
+
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
|
+
/** Decoded revert of the simulated transaction. */
|
|
30
|
+
export interface SimulationError {
|
|
31
|
+
/** Human-readable revert reason / error name. */
|
|
32
|
+
reason: string;
|
|
33
|
+
/** Original error, kept for debugging. */
|
|
34
|
+
cause?: unknown;
|
|
35
|
+
}
|
|
36
|
+
/** Per-call slice of a `simulateCalls` failure we need to decode. */
|
|
37
|
+
export interface SimulationRevert {
|
|
38
|
+
error?: Error;
|
|
39
|
+
/** Raw revert return data, when present. */
|
|
40
|
+
data?: Hex;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Decodes a simulated transaction revert into a {@link SimulationError}.
|
|
44
|
+
*
|
|
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
|
|
47
|
+
* {@link errorAbis} (Gearbox protocol exceptions plus standard ERC-20 custom
|
|
48
|
+
* errors); failing that, we walk viem's error chain for a
|
|
49
|
+
* {@link ContractFunctionRevertedError} (covers `Error(string)` / `Panic`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function decodeSimulationError(revert: SimulationRevert): SimulationError;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { PoolOperation } from "../parse/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Distinct addresses whose balances change during the operation: the funds
|
|
5
|
+
* source (payer or share owner) and the receiver.
|
|
6
|
+
*/
|
|
7
|
+
export declare function watchedHolders(operation: PoolOperation, wallet: Address): Address[];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
1
|
+
export { ETH_SIMULATE_V1_NETWORKS } from "./constants.js";
|
|
2
|
+
export type { SimulationError, SimulationFlowFailure, SimulationFlowSource, } from "./errors.js";
|
|
3
|
+
export { PreviewSimulationError } from "./errors.js";
|
|
4
|
+
export type { SimulateFacadeOperationInput } from "./simulateFacadeOperation.js";
|
|
5
|
+
export { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
6
|
+
export type { SimulateOperationInput } from "./simulateOperation.js";
|
|
7
|
+
export { simulateOperation } from "./simulateOperation.js";
|
|
8
|
+
export { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
9
|
+
export type { AddressBalanceChanges, OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput, PoolOperationSimulationResult, TokenBalanceChange, } from "./types.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Address, Hex } from "viem";
|
|
2
2
|
import type { OnchainSDK } from "../../sdk/index.js";
|
|
3
3
|
import type { OuterFacadeOperation } from "../parse/index.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { OperationSimulationOptions, PoolOperationSimulation } from "./types.js";
|
|
5
5
|
export interface SimulateFacadeOperationInput {
|
|
6
|
-
/** Only `client`
|
|
6
|
+
/** Only `client`/`networkType` are used, so any OnchainSDK works. */
|
|
7
7
|
sdk: OnchainSDK;
|
|
8
8
|
/** Parsed credit-facade operation to simulate. */
|
|
9
9
|
operation: OuterFacadeOperation;
|
|
@@ -13,8 +13,6 @@ export interface SimulateFacadeOperationInput {
|
|
|
13
13
|
calldata: Hex;
|
|
14
14
|
/** Wallet whose balance changes and transfers we track. */
|
|
15
15
|
wallet: Address;
|
|
16
|
-
/** Block to simulate at; defaults to latest. Only set for testnet forks. */
|
|
17
|
-
blockNumber?: bigint;
|
|
18
16
|
}
|
|
19
17
|
/**
|
|
20
18
|
* Simulates a credit-facade operation.
|
|
@@ -24,4 +22,4 @@ export interface SimulateFacadeOperationInput {
|
|
|
24
22
|
* signature mirrors {@link simulatePoolOperation} so the
|
|
25
23
|
* {@link simulateOperation} wrapper can delegate uniformly once implemented.
|
|
26
24
|
*/
|
|
27
|
-
export declare function simulateFacadeOperation(_input: SimulateFacadeOperationInput): Promise<
|
|
25
|
+
export declare function simulateFacadeOperation(_input: SimulateFacadeOperationInput, _options?: OperationSimulationOptions): Promise<PoolOperationSimulation>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Address, Hex } from "viem";
|
|
2
2
|
import type { OnchainSDK } from "../../sdk/index.js";
|
|
3
3
|
import { type Operation } from "../parse/index.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { OperationSimulationOptions, PoolOperationSimulation } from "./types.js";
|
|
5
5
|
export interface SimulateOperationInput {
|
|
6
|
-
/**
|
|
6
|
+
/** Gearbox SDK instance. */
|
|
7
7
|
sdk: OnchainSDK;
|
|
8
|
-
/** Parsed
|
|
8
|
+
/** Parsed pool or credit account operation */
|
|
9
9
|
operation: Operation;
|
|
10
10
|
/** Target contract the calldata is sent to. */
|
|
11
11
|
to: Address;
|
|
@@ -13,14 +13,8 @@ export interface SimulateOperationInput {
|
|
|
13
13
|
calldata: Hex;
|
|
14
14
|
/** Wallet whose balance changes and transfers we track. */
|
|
15
15
|
wallet: Address;
|
|
16
|
-
/** Block to simulate at; defaults to latest. Only set for testnet forks. */
|
|
17
|
-
blockNumber?: bigint;
|
|
18
16
|
}
|
|
19
17
|
/**
|
|
20
|
-
* Simulates a parsed {@link Operation}
|
|
21
|
-
* pool deposit/redeem operations go to {@link simulatePoolOperation}, and
|
|
22
|
-
* credit-facade operations go to {@link simulateFacadeOperation} (currently a
|
|
23
|
-
* stub). Returns the recovered transfers, balance changes and gas on success,
|
|
24
|
-
* or a decoded revert on failure.
|
|
18
|
+
* Simulates a parsed pool or credit account operation {@link Operation}
|
|
25
19
|
*/
|
|
26
|
-
export declare function simulateOperation(input: SimulateOperationInput): Promise<
|
|
20
|
+
export declare function simulateOperation(input: SimulateOperationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulation>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { PoolOperation } from "../parse/index.js";
|
|
3
|
+
import type { AddressBalanceChanges, OperationSimulationOptions, PoolOperationSimulationInput, PoolOperationSimulationResult } from "./types.js";
|
|
4
|
+
/** Reads a watched holder's "before" balance of a token. */
|
|
5
|
+
export type BalanceLookup = (token: Address, holder: Address) => bigint;
|
|
6
|
+
/**
|
|
7
|
+
* Multicall pool-operation flow, used where `eth_simulateV1` is unavailable or
|
|
8
|
+
* as a fallback alongside it.
|
|
9
|
+
*
|
|
10
|
+
* Reads the watched holders' "before" balances together with the matching
|
|
11
|
+
* ERC4626 preview (`previewDeposit`/`previewMint`/`previewWithdraw`/
|
|
12
|
+
* `previewRedeem`) in a single multicall, then computes the theoretical balance
|
|
13
|
+
* changes via {@link computePoolOpBalanceChanges}.
|
|
14
|
+
*
|
|
15
|
+
* Unlike the `eth_simulateV1` flow it does not execute the calldata, so it
|
|
16
|
+
* cannot recover ERC-20 transfers (`transfers` is always `undefined`) and it
|
|
17
|
+
* ignores balance/allowance prerequisites (preview reads succeed regardless).
|
|
18
|
+
*
|
|
19
|
+
* @throws {@link PreviewSimulationError} when the multicall round-trip throws or
|
|
20
|
+
* any call (a balance read or the preview read) reverts.
|
|
21
|
+
*/
|
|
22
|
+
export declare function simulatePoolOpMulticall(input: PoolOperationSimulationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulationResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Pure computation of {@link AddressBalanceChanges} for a pool operation from
|
|
25
|
+
* its ERC4626 preview result and the watched holders' "before" balances. Legs
|
|
26
|
+
* sharing the same address are grouped together.
|
|
27
|
+
*/
|
|
28
|
+
export declare function computePoolOpBalanceChanges(operation: PoolOperation, wallet: Address, previewAmount: bigint, before: BalanceLookup): AddressBalanceChanges[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OperationSimulationOptions, PoolOperationSimulationInput, PoolOperationSimulationResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* `eth_simulateV1` pool-operation flow.
|
|
4
|
+
*
|
|
5
|
+
* Sandwiches the raw calldata between `balanceOf` reads of the underlying and
|
|
6
|
+
* pool (share) tokens for every watched holder, then derives the balance changes
|
|
7
|
+
* from the before/after diff and the wallet-relevant ERC-20 transfers from the
|
|
8
|
+
* emitted logs. Simulation runs against real chain state (no overrides), so an
|
|
9
|
+
* unmet prerequisite surfaces here as a revert.
|
|
10
|
+
*
|
|
11
|
+
* @throws {@link PreviewSimulationError} when the round-trip throws or the
|
|
12
|
+
* simulated transaction reverts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function simulatePoolOpV1(input: PoolOperationSimulationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulationResult>;
|
|
@@ -1,30 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { OnchainSDK } from "../../sdk/index.js";
|
|
3
|
-
import type { PoolOperation } from "../parse/index.js";
|
|
4
|
-
import type { PoolSimulationResult } from "./types.js";
|
|
5
|
-
export interface SimulatePoolOperationInput {
|
|
6
|
-
/** Only `client` is used, so any OnchainSDK works. */
|
|
7
|
-
sdk: OnchainSDK;
|
|
8
|
-
/** Parsed operation, used to resolve the underlying and pool tokens. */
|
|
9
|
-
operation: PoolOperation;
|
|
10
|
-
/** Target contract the calldata is sent to (the pool). */
|
|
11
|
-
to: Address;
|
|
12
|
-
/** Raw deposit/redeem calldata to simulate. */
|
|
13
|
-
calldata: Hex;
|
|
14
|
-
/** Wallet whose balance changes and transfers we track. */
|
|
15
|
-
wallet: Address;
|
|
16
|
-
/** Block to simulate at; defaults to latest. Only set for testnet forks. */
|
|
17
|
-
blockNumber?: bigint;
|
|
18
|
-
}
|
|
1
|
+
import type { OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput } from "./types.js";
|
|
19
2
|
/**
|
|
20
|
-
* Simulates a pool deposit/redeem
|
|
21
|
-
*
|
|
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.
|
|
22
5
|
*
|
|
23
|
-
*
|
|
24
|
-
* wallet or the operation recipient (for merging into the parsed operation) and
|
|
25
|
-
* the balance changes grouped by watched address (wallet, plus the recipient
|
|
26
|
-
* when distinct); on revert, returns the decoded reason. Simulation runs against
|
|
27
|
-
* real chain state (no overrides), so an unmet prerequisite surfaces here as a
|
|
28
|
-
* failure.
|
|
6
|
+
* @throws {@link PreviewSimulationError} when the simulation fails.
|
|
29
7
|
*/
|
|
30
|
-
export declare function simulatePoolOperation(input:
|
|
8
|
+
export declare function simulatePoolOperation(input: PoolOperationSimulationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulation>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import type {
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { OnchainSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { ILogger } from "../../sdk/types/logger.js";
|
|
4
|
+
import type { PoolOperation, TokenTransfer } from "../parse/index.js";
|
|
5
|
+
import type { PreviewSimulationError } from "./errors.js";
|
|
3
6
|
/**
|
|
4
7
|
* Change in an address's balance of a single token over the simulated call.
|
|
5
8
|
* `delta` is `after - before` (negative when the address spent the token).
|
|
@@ -19,25 +22,58 @@ export interface AddressBalanceChanges {
|
|
|
19
22
|
address: Address;
|
|
20
23
|
changes: TokenBalanceChange[];
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
export interface PoolOperationSimulationInput {
|
|
26
|
+
/** Only `client`/`networkType` are used, so any OnchainSDK works. */
|
|
27
|
+
sdk: OnchainSDK;
|
|
28
|
+
/** Parsed operation, used to resolve the underlying and pool tokens. */
|
|
29
|
+
operation: PoolOperation;
|
|
30
|
+
/** Target contract the calldata is sent to (the pool). */
|
|
31
|
+
to: Address;
|
|
32
|
+
/** Raw deposit/mint/withdraw/redeem calldata to simulate. */
|
|
33
|
+
calldata: Hex;
|
|
34
|
+
/** Wallet whose balance changes and transfers we track. */
|
|
35
|
+
wallet: Address;
|
|
36
|
+
}
|
|
37
|
+
export interface OperationSimulationOptions {
|
|
38
|
+
/** Block to simulate at; defaults to latest. */
|
|
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
|
+
/**
|
|
47
|
+
* Optional logger.
|
|
48
|
+
**/
|
|
49
|
+
logger?: ILogger;
|
|
28
50
|
}
|
|
29
51
|
/**
|
|
30
|
-
*
|
|
31
|
-
* wallet-filtered ERC-20 transfers
|
|
32
|
-
*
|
|
33
|
-
*
|
|
52
|
+
* 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.
|
|
34
56
|
*/
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
57
|
+
export interface PoolOperationSimulationResult {
|
|
58
|
+
/**
|
|
59
|
+
* Balance changes grouped by watched address (wallet, recipient, owner).
|
|
60
|
+
**/
|
|
38
61
|
balanceChanges: AddressBalanceChanges[];
|
|
39
|
-
|
|
40
|
-
|
|
62
|
+
/**
|
|
63
|
+
* ERC-20 transfers involving the watched addresses.
|
|
64
|
+
*
|
|
65
|
+
* NOTE: transfers are **not guaranteed** to be returned.
|
|
66
|
+
*/
|
|
67
|
+
transfers?: TokenTransfer[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Outcome of simulating a pool operation. On success it carries a
|
|
71
|
+
* {@link PoolOperationSimulationResult}; on failure it carries a
|
|
72
|
+
* {@link PreviewSimulationError}.
|
|
73
|
+
*/
|
|
74
|
+
export type PoolOperationSimulation = ({
|
|
75
|
+
status: "success";
|
|
76
|
+
} & PoolOperationSimulationResult) | {
|
|
41
77
|
status: "failure";
|
|
42
|
-
error:
|
|
78
|
+
error: PreviewSimulationError;
|
|
43
79
|
};
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type Hex } from "viem";
|
|
2
|
-
import type { SimulationError } from "./types.js";
|
|
3
|
-
/** Per-call slice of a `simulateCalls` failure we need to decode. */
|
|
4
|
-
export interface SimulationRevert {
|
|
5
|
-
error?: Error;
|
|
6
|
-
/** Raw revert return data, when present. */
|
|
7
|
-
data?: Hex;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Decodes a simulated transaction revert into a {@link SimulationError}.
|
|
11
|
-
*
|
|
12
|
-
* The simulated call is raw calldata (no ABI), so viem cannot decode the revert
|
|
13
|
-
* itself. We first try to decode the raw return bytes against the SDK's
|
|
14
|
-
* {@link errorAbis} (Gearbox protocol exceptions plus standard ERC-20 custom
|
|
15
|
-
* errors); failing that, we walk viem's error chain for a
|
|
16
|
-
* {@link ContractFunctionRevertedError} (covers `Error(string)` / `Panic`).
|
|
17
|
-
*/
|
|
18
|
-
export declare function decodeSimulationError(revert: SimulationRevert): SimulationError;
|