@gearbox-protocol/sdk 14.11.3 → 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.
- package/dist/cjs/abi/iZapper.js +62 -24
- package/dist/cjs/common-utils/utils/index.js +2 -0
- package/dist/cjs/{history/trace-utils.js → common-utils/utils/trace.js} +62 -5
- package/dist/cjs/dev/index.js +3 -1
- package/dist/cjs/dev/verifyTestnet.js +52 -0
- package/dist/cjs/history/assembleOperations.js +6 -6
- package/dist/cjs/history/classifyMulticallOperations.js +31 -25
- package/dist/cjs/history/index.js +0 -2
- package/dist/cjs/history/parseCreditAccountTransaction.js +5 -6
- package/dist/cjs/history/toLegacyOperation.js +5 -1
- package/dist/cjs/plugins/adapters/contracts/AbstractAdapter.js +25 -37
- package/dist/cjs/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
- package/dist/cjs/{history/internal-types.js → plugins/adapters/transfers.js} +2 -2
- package/dist/cjs/preview/index.js +28 -0
- package/dist/cjs/preview/package.json +1 -0
- package/dist/cjs/preview/parse/classifyInnerOperations.js +92 -0
- package/dist/cjs/preview/parse/errors.js +50 -0
- package/dist/cjs/preview/parse/extractExpectedBalanceChanges.js +48 -0
- package/dist/cjs/preview/parse/index.js +34 -0
- package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +115 -0
- package/dist/cjs/preview/parse/parseOperationCalldata.js +75 -0
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +85 -0
- package/dist/cjs/{history/inner-operations.js → preview/parse/types-adapters.js} +2 -2
- package/dist/cjs/preview/parse/types-facades.js +16 -0
- package/dist/cjs/preview/parse/types-pools.js +16 -0
- package/dist/cjs/preview/parse/types.js +37 -0
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +78 -0
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +77 -0
- package/dist/cjs/preview/prerequisites/Prerequisite.js +85 -0
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +221 -0
- package/dist/cjs/preview/prerequisites/index.js +34 -0
- package/dist/cjs/preview/prerequisites/prepareAction.js +48 -0
- package/dist/cjs/preview/prerequisites/runPrerequisites.js +71 -0
- package/dist/cjs/preview/prerequisites/types.js +16 -0
- package/dist/cjs/preview/simulate/errors.js +91 -0
- package/dist/cjs/{sdk/market/zapper/Zapper.js → preview/simulate/holders.js} +21 -23
- package/dist/cjs/preview/simulate/index.js +37 -0
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +30 -0
- package/dist/cjs/preview/simulate/simulateOperation.js +37 -0
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +187 -0
- package/dist/cjs/preview/simulate/types.js +16 -0
- package/dist/cjs/{history → preview/trace}/errors.js +0 -26
- package/dist/cjs/preview/trace/extractAdapterCallTraces.js +58 -0
- package/dist/cjs/{history → preview/trace}/extractTransfers.js +9 -12
- package/dist/cjs/{history → preview/trace}/findFacadeCalls.js +3 -3
- package/dist/cjs/preview/trace/index.js +30 -0
- package/dist/cjs/preview/trace/types.js +16 -0
- package/dist/cjs/sdk/MultichainSDK.js +1 -0
- package/dist/cjs/sdk/OnchainSDK.js +7 -3
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +154 -0
- package/dist/cjs/sdk/market/MarketRegister.js +10 -5
- package/dist/cjs/sdk/market/ZapperRegister.js +54 -0
- package/dist/cjs/sdk/market/zapper/IERC20ZapperContract.js +3 -38
- package/dist/cjs/sdk/market/zapper/IETHZapperContract.js +3 -38
- package/dist/cjs/sdk/market/zapper/ZapperContract.js +109 -0
- package/dist/cjs/sdk/market/zapper/createZapper.js +12 -4
- package/dist/cjs/sdk/market/zapper/errors.js +37 -0
- package/dist/cjs/sdk/market/zapper/index.js +6 -2
- package/dist/cjs/sdk/market/zapper/types.js +16 -0
- package/dist/cjs/sdk/options.js +41 -17
- package/dist/esm/abi/iZapper.js +62 -24
- package/dist/esm/common-utils/utils/index.js +1 -0
- package/dist/esm/common-utils/utils/trace.js +93 -0
- package/dist/esm/dev/index.js +1 -0
- package/dist/esm/dev/verifyTestnet.js +27 -0
- package/dist/esm/history/assembleOperations.js +8 -6
- package/dist/esm/history/classifyMulticallOperations.js +29 -23
- package/dist/esm/history/index.js +0 -1
- package/dist/esm/history/parseCreditAccountTransaction.js +3 -4
- package/dist/esm/history/toLegacyOperation.js +5 -1
- package/dist/esm/plugins/adapters/contracts/AbstractAdapter.js +28 -38
- package/dist/esm/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
- package/dist/esm/preview/index.js +4 -0
- package/dist/esm/preview/package.json +1 -0
- package/dist/esm/preview/parse/classifyInnerOperations.js +68 -0
- package/dist/esm/preview/parse/errors.js +24 -0
- package/dist/esm/preview/parse/extractExpectedBalanceChanges.js +24 -0
- package/dist/esm/preview/parse/index.js +7 -0
- package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +91 -0
- package/dist/esm/preview/parse/parseOperationCalldata.js +55 -0
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +61 -0
- package/dist/esm/preview/parse/types-facades.js +0 -0
- package/dist/esm/preview/parse/types-pools.js +0 -0
- package/dist/esm/preview/parse/types.js +9 -0
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +57 -0
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +56 -0
- package/dist/esm/preview/prerequisites/Prerequisite.js +63 -0
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +197 -0
- package/dist/esm/preview/prerequisites/index.js +7 -0
- package/dist/esm/preview/prerequisites/prepareAction.js +23 -0
- package/dist/esm/preview/prerequisites/runPrerequisites.js +47 -0
- package/dist/esm/preview/prerequisites/types.js +0 -0
- package/dist/esm/preview/simulate/errors.js +69 -0
- package/dist/esm/preview/simulate/holders.js +21 -0
- package/dist/esm/preview/simulate/index.js +10 -0
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +6 -0
- package/dist/esm/preview/simulate/simulateOperation.js +13 -0
- package/dist/esm/preview/simulate/simulatePoolOperation.js +166 -0
- package/dist/esm/preview/simulate/types.js +0 -0
- package/dist/esm/{history → preview/trace}/errors.js +0 -24
- package/dist/esm/preview/trace/extractAdapterCallTraces.js +40 -0
- package/dist/esm/{history → preview/trace}/extractTransfers.js +9 -12
- package/dist/esm/{history → preview/trace}/findFacadeCalls.js +4 -2
- package/dist/esm/preview/trace/index.js +5 -0
- package/dist/esm/preview/trace/types.js +0 -0
- package/dist/esm/sdk/MultichainSDK.js +1 -0
- package/dist/esm/sdk/OnchainSDK.js +7 -3
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +154 -0
- package/dist/esm/sdk/market/MarketRegister.js +10 -5
- package/dist/esm/sdk/market/ZapperRegister.js +54 -0
- package/dist/esm/sdk/market/zapper/IERC20ZapperContract.js +3 -38
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +3 -38
- package/dist/esm/sdk/market/zapper/ZapperContract.js +85 -0
- package/dist/esm/sdk/market/zapper/createZapper.js +12 -4
- package/dist/esm/sdk/market/zapper/errors.js +13 -0
- package/dist/esm/sdk/market/zapper/index.js +3 -1
- package/dist/esm/sdk/market/zapper/types.js +0 -0
- package/dist/esm/sdk/options.js +39 -15
- package/dist/types/abi/iERC20Zapper.d.ts +91 -23
- package/dist/types/abi/iETHZapper.d.ts +91 -23
- package/dist/types/abi/iZapper.d.ts +91 -23
- package/dist/types/common-utils/utils/index.d.ts +1 -0
- package/dist/types/common-utils/utils/trace.d.ts +73 -0
- package/dist/types/dev/index.d.ts +1 -0
- package/dist/types/dev/verifyTestnet.d.ts +24 -0
- package/dist/types/history/assembleOperations.d.ts +11 -6
- package/dist/types/history/classifyMulticallOperations.d.ts +21 -9
- package/dist/types/history/index.d.ts +0 -1
- package/dist/types/history/mapOperations.d.ts +7 -9
- package/dist/types/history/types.d.ts +22 -71
- package/dist/types/plugins/adapters/contracts/AbstractAdapter.d.ts +16 -17
- package/dist/types/plugins/adapters/contracts/AccountMigratorAdapterContract.d.ts +10 -1
- package/dist/types/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve2AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve3AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve4AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterDeposit.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterStETHContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1StableNGAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/DaiUsdsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ERC4626AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ERC4626ReferralAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/LidoV1AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/MellowDVVAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/UniswapV2AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/UniswapV4AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/WstETHV1AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/transferHelpers.d.ts +1 -1
- package/dist/types/plugins/adapters/transfers.d.ts +17 -0
- package/dist/types/plugins/adapters/types.d.ts +8 -46
- package/dist/types/preview/index.d.ts +4 -0
- package/dist/types/preview/parse/classifyInnerOperations.d.ts +21 -0
- package/dist/types/preview/parse/errors.d.ts +18 -0
- package/dist/types/preview/parse/extractExpectedBalanceChanges.d.ts +22 -0
- package/dist/types/preview/parse/index.d.ts +7 -0
- package/dist/types/preview/parse/parseFacadeOperationCalldata.d.ts +19 -0
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +23 -0
- package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +17 -0
- package/dist/types/preview/parse/types-adapters.d.ts +69 -0
- package/dist/types/preview/parse/types-facades.d.ts +158 -0
- package/dist/types/preview/parse/types-pools.d.ts +115 -0
- package/dist/types/preview/parse/types.d.ts +44 -0
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +24 -0
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +23 -0
- package/dist/types/preview/prerequisites/Prerequisite.d.ts +60 -0
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +16 -0
- package/dist/types/preview/prerequisites/index.d.ts +7 -0
- package/dist/types/preview/prerequisites/prepareAction.d.ts +52 -0
- package/dist/types/preview/prerequisites/runPrerequisites.d.ts +12 -0
- package/dist/types/preview/prerequisites/types.d.ts +78 -0
- package/dist/types/preview/simulate/errors.d.ts +45 -0
- package/dist/types/preview/simulate/holders.d.ts +7 -0
- package/dist/types/preview/simulate/index.d.ts +8 -0
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +25 -0
- package/dist/types/preview/simulate/simulateOperation.d.ts +20 -0
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +26 -0
- package/dist/types/preview/simulate/types.d.ts +66 -0
- package/dist/types/{history → preview/trace}/errors.d.ts +0 -10
- package/dist/types/preview/trace/extractAdapterCallTraces.d.ts +23 -0
- package/dist/types/{history → preview/trace}/extractTransfers.d.ts +14 -5
- package/dist/types/{history → preview/trace}/findFacadeCalls.d.ts +3 -2
- package/dist/types/preview/trace/index.d.ts +5 -0
- package/dist/types/preview/trace/types.d.ts +21 -0
- package/dist/types/sdk/MultichainSDK.d.ts +5 -0
- package/dist/types/sdk/OnchainSDK.d.ts +4 -0
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +21 -1
- package/dist/types/sdk/accounts/types.d.ts +82 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +15 -6
- package/dist/types/sdk/market/ZapperRegister.d.ts +25 -4
- package/dist/types/sdk/market/zapper/IERC20ZapperContract.d.ts +93 -39
- package/dist/types/sdk/market/zapper/IETHZapperContract.d.ts +93 -39
- package/dist/types/sdk/market/zapper/ZapperContract.d.ts +35 -0
- package/dist/types/sdk/market/zapper/createZapper.d.ts +2 -4
- package/dist/types/sdk/market/zapper/errors.d.ts +10 -0
- package/dist/types/sdk/market/zapper/index.d.ts +3 -1
- package/dist/types/sdk/market/zapper/types.d.ts +64 -0
- package/dist/types/sdk/options.d.ts +10 -5
- package/dist/types/sdk/pools/types.d.ts +3 -3
- package/dist/types/sdk/types/state-human.d.ts +9 -0
- package/dist/types/sdk/types/state.d.ts +7 -0
- package/package.json +8 -3
- package/dist/cjs/history/extractProtocolCalls.js +0 -53
- package/dist/esm/history/extractProtocolCalls.js +0 -32
- package/dist/esm/history/trace-utils.js +0 -36
- package/dist/esm/sdk/market/zapper/Zapper.js +0 -23
- package/dist/types/history/extractProtocolCalls.d.ts +0 -8
- package/dist/types/history/inner-operations.d.ts +0 -57
- package/dist/types/history/internal-types.d.ts +0 -47
- package/dist/types/history/trace-utils.d.ts +0 -12
- package/dist/types/sdk/market/zapper/Zapper.d.ts +0 -13
- /package/dist/esm/{history/inner-operations.js → plugins/adapters/transfers.js} +0 -0
- /package/dist/esm/{history/internal-types.js → preview/parse/types-adapters.js} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
/**
|
|
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.
|
|
9
|
+
*/
|
|
10
|
+
export interface PoolDepositOperation {
|
|
11
|
+
/** ERC4626 operation kind. */
|
|
12
|
+
operation: "Deposit";
|
|
13
|
+
/** Destination pool the assets are deposited into. */
|
|
14
|
+
pool: Address;
|
|
15
|
+
/** Address credited with the minted pool shares. */
|
|
16
|
+
receiver: Address;
|
|
17
|
+
/** Amount of underlying assets supplied to the pool. */
|
|
18
|
+
assets: bigint;
|
|
19
|
+
/** Underlying token of the destination pool. */
|
|
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;
|
|
28
|
+
/** Referral code, present only for `depositWithReferral` calls. */
|
|
29
|
+
referralCode?: bigint;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* ERC4626 `mint` into a Gearbox pool. Unlike `deposit`, the caller specifies the
|
|
33
|
+
* amount of shares to mint; the assets pulled are resolved by the pool.
|
|
34
|
+
*/
|
|
35
|
+
export interface PoolMintOperation {
|
|
36
|
+
/** ERC4626 operation kind. */
|
|
37
|
+
operation: "Mint";
|
|
38
|
+
/** Destination pool the shares are minted from. */
|
|
39
|
+
pool: Address;
|
|
40
|
+
/** Address credited with the minted pool shares. */
|
|
41
|
+
receiver: Address;
|
|
42
|
+
/** Pool shares (diesel) minted to the receiver. */
|
|
43
|
+
shares: bigint;
|
|
44
|
+
/** Underlying token of the destination pool. */
|
|
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;
|
|
53
|
+
/** Referral code, present only for `mintWithReferral` calls. */
|
|
54
|
+
referralCode?: bigint;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* ERC4626 `withdraw` from a Gearbox pool. Unlike `redeem`, the caller specifies
|
|
58
|
+
* the amount of underlying assets to withdraw; the shares burned are resolved by
|
|
59
|
+
* the pool.
|
|
60
|
+
*/
|
|
61
|
+
export interface PoolWithdrawOperation {
|
|
62
|
+
/** ERC4626 operation kind. */
|
|
63
|
+
operation: "Withdraw";
|
|
64
|
+
/** Source pool the assets are withdrawn from. */
|
|
65
|
+
pool: Address;
|
|
66
|
+
/** Address that receives the withdrawn tokens. */
|
|
67
|
+
receiver: Address;
|
|
68
|
+
/** Address whose pool shares are burned. */
|
|
69
|
+
owner: Address;
|
|
70
|
+
/** Underlying assets withdrawn to the receiver. */
|
|
71
|
+
assets: bigint;
|
|
72
|
+
/** Underlying token of the source pool. */
|
|
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;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
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.
|
|
88
|
+
*/
|
|
89
|
+
export interface PoolRedeemOperation {
|
|
90
|
+
/** ERC4626 operation kind. */
|
|
91
|
+
operation: "Redeem";
|
|
92
|
+
/** Source pool the shares are redeemed from. */
|
|
93
|
+
pool: Address;
|
|
94
|
+
/** Address that receives the redeemed tokens. */
|
|
95
|
+
receiver: Address;
|
|
96
|
+
/** Address whose pool shares are burned. */
|
|
97
|
+
owner: Address;
|
|
98
|
+
/** Pool shares (diesel) burned. */
|
|
99
|
+
shares: bigint;
|
|
100
|
+
/** Underlying token of the source pool. */
|
|
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;
|
|
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
|
+
*/
|
|
115
|
+
export type PoolOperation = PoolDepositOperation | PoolMintOperation | PoolWithdrawOperation | PoolRedeemOperation;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AdaptersPlugin } from "../../plugins/adapters/index.js";
|
|
2
|
+
import type { OnchainSDK, PluginsMap } from "../../sdk/index.js";
|
|
3
|
+
import type { OuterFacadeOperation } from "./types-facades.js";
|
|
4
|
+
import type { PoolOperation } from "./types-pools.js";
|
|
5
|
+
export * from "./types-adapters.js";
|
|
6
|
+
export * from "./types-facades.js";
|
|
7
|
+
export * from "./types-pools.js";
|
|
8
|
+
/**
|
|
9
|
+
* True when the plugin map `P` contains the {@link AdaptersPlugin} under any
|
|
10
|
+
* key. Matched nominally (the plugin's private fields make it non-structural),
|
|
11
|
+
* so unrelated plugins never satisfy it.
|
|
12
|
+
*/
|
|
13
|
+
export type HasAdaptersPlugin<P extends PluginsMap> = Extract<P[keyof P], AdaptersPlugin> extends never ? false : true;
|
|
14
|
+
/**
|
|
15
|
+
* Compile-time guard for the adapters plugin. Resolves to a no-op (`unknown`)
|
|
16
|
+
* when `P` includes the {@link AdaptersPlugin}, otherwise to an error-shaped
|
|
17
|
+
* type that makes the surrounding call fail to type-check.
|
|
18
|
+
*
|
|
19
|
+
* Intended to be intersected with a function argument so callers must pass an
|
|
20
|
+
* SDK whose adapter contracts are registered (required for multicall
|
|
21
|
+
* classification).
|
|
22
|
+
*/
|
|
23
|
+
export type RequireAdaptersPlugin<P extends PluginsMap> = HasAdaptersPlugin<P> extends true ? unknown : {
|
|
24
|
+
"OnchainSDK must be created with the AdaptersPlugin": never;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* {@link OnchainSDK} whose plugin map is guaranteed at compile time to include
|
|
28
|
+
* the {@link AdaptersPlugin}.
|
|
29
|
+
*/
|
|
30
|
+
export type SdkWithAdapters<P extends PluginsMap = PluginsMap> = OnchainSDK<P> & RequireAdaptersPlugin<P>;
|
|
31
|
+
/**
|
|
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 = {}`.
|
|
37
|
+
*/
|
|
38
|
+
export type Operation = PoolOperation | OuterFacadeOperation;
|
|
39
|
+
/**
|
|
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
|
+
*/
|
|
44
|
+
export declare function isPoolOperation(tx: Operation): tx is PoolOperation;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Address, type ContractFunctionParameters } from "viem";
|
|
2
|
+
import { type MulticallCallResult, Prerequisite } from "./Prerequisite.js";
|
|
3
|
+
import type { PrerequisiteDetail, PrerequisiteResult } from "./types.js";
|
|
4
|
+
export interface AllowancePrerequisiteProps {
|
|
5
|
+
token: Address;
|
|
6
|
+
owner: Address;
|
|
7
|
+
spender: Address;
|
|
8
|
+
required: bigint;
|
|
9
|
+
title?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Checks that `owner` granted `spender` an ERC-20 allowance >= `required`. */
|
|
13
|
+
export declare class AllowancePrerequisite extends Prerequisite<"allowance"> {
|
|
14
|
+
private readonly _id;
|
|
15
|
+
private readonly _title;
|
|
16
|
+
private readonly _detail;
|
|
17
|
+
constructor(props: AllowancePrerequisiteProps);
|
|
18
|
+
get id(): string;
|
|
19
|
+
get kind(): "allowance";
|
|
20
|
+
get title(): string;
|
|
21
|
+
get detail(): PrerequisiteDetail<"allowance">;
|
|
22
|
+
calls(): ContractFunctionParameters[];
|
|
23
|
+
resolve(slice: MulticallCallResult[]): PrerequisiteResult<"allowance">;
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Address, type ContractFunctionParameters } from "viem";
|
|
2
|
+
import { type MulticallCallResult, Prerequisite } from "./Prerequisite.js";
|
|
3
|
+
import type { PrerequisiteDetail, PrerequisiteResult } from "./types.js";
|
|
4
|
+
export interface BalancePrerequisiteProps {
|
|
5
|
+
token: Address;
|
|
6
|
+
owner: Address;
|
|
7
|
+
required: bigint;
|
|
8
|
+
title?: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Checks that `owner` holds an ERC-20 balance >= `required`. */
|
|
12
|
+
export declare class BalancePrerequisite extends Prerequisite<"balance"> {
|
|
13
|
+
private readonly _id;
|
|
14
|
+
private readonly _title;
|
|
15
|
+
private readonly _detail;
|
|
16
|
+
constructor(props: BalancePrerequisiteProps);
|
|
17
|
+
get id(): string;
|
|
18
|
+
get kind(): "balance";
|
|
19
|
+
get title(): string;
|
|
20
|
+
get detail(): PrerequisiteDetail<"balance">;
|
|
21
|
+
calls(): ContractFunctionParameters[];
|
|
22
|
+
resolve(slice: MulticallCallResult[]): PrerequisiteResult<"balance">;
|
|
23
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type ContractFunctionParameters } from "viem";
|
|
2
|
+
import type { PrerequisiteContext, PrerequisiteDetail, PrerequisiteError, PrerequisiteKind, PrerequisiteResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* One entry of a viem `multicall({ allowFailure: true })` response: either a
|
|
5
|
+
* decoded `result` or the `error` that the call reverted with.
|
|
6
|
+
*/
|
|
7
|
+
export type MulticallCallResult = {
|
|
8
|
+
status: "success";
|
|
9
|
+
result: unknown;
|
|
10
|
+
error?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
status: "failure";
|
|
13
|
+
result?: undefined;
|
|
14
|
+
error: Error;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Decodes an unknown error into a {@link PrerequisiteError} with a
|
|
18
|
+
* human-readable revert reason. Mirrors the SDK's `extractCallError`: walk the
|
|
19
|
+
* viem error chain for a {@link ContractFunctionRevertedError} and use its
|
|
20
|
+
* `errorName`, otherwise fall back to the error's short message / name.
|
|
21
|
+
*/
|
|
22
|
+
export declare function toPrerequisiteError(cause: unknown): PrerequisiteError;
|
|
23
|
+
/**
|
|
24
|
+
* A single verifiable prerequisite for a transaction. Subclasses describe the
|
|
25
|
+
* on-chain reads they need ({@link calls}) and how to turn the multicall slice
|
|
26
|
+
* into a {@link PrerequisiteResult} ({@link resolve}).
|
|
27
|
+
*
|
|
28
|
+
* Identity (`id`, `kind`, `title`) and build-time `detail` are exposed as
|
|
29
|
+
* read-only accessors; subclasses back them with private fields. The shared
|
|
30
|
+
* {@link satisfiedResult}/{@link errorResult} helpers are `protected` so each
|
|
31
|
+
* subclass builds results consistently.
|
|
32
|
+
*
|
|
33
|
+
* The same instance can be verified standalone via {@link verify} or batched
|
|
34
|
+
* together with others by `verifyPrerequisites`.
|
|
35
|
+
*/
|
|
36
|
+
export declare abstract class Prerequisite<K extends PrerequisiteKind> {
|
|
37
|
+
/** Stable identifier, used as a React key and for deduplication. */
|
|
38
|
+
abstract get id(): string;
|
|
39
|
+
/** Discriminant tying this check to its detail payload. */
|
|
40
|
+
abstract get kind(): K;
|
|
41
|
+
/** Human-readable label shown in the UI. */
|
|
42
|
+
abstract get title(): string;
|
|
43
|
+
/** Inputs known before reading the chain (no `actual` yet). */
|
|
44
|
+
abstract get detail(): PrerequisiteDetail<K>;
|
|
45
|
+
/** Contract reads this check needs (usually one). */
|
|
46
|
+
abstract calls(ctx: PrerequisiteContext): ContractFunctionParameters[];
|
|
47
|
+
/** Maps this check's slice of the multicall response into a result. */
|
|
48
|
+
abstract resolve(slice: MulticallCallResult[]): PrerequisiteResult<K>;
|
|
49
|
+
/**
|
|
50
|
+
* Verifies this prerequisite on its own using an `allowFailure` multicall.
|
|
51
|
+
* Prefer `verifyPrerequisites` to batch several checks into one round-trip.
|
|
52
|
+
*/
|
|
53
|
+
verify(ctx: PrerequisiteContext): Promise<PrerequisiteResult<K>>;
|
|
54
|
+
/** Builds a successful result; `detail` carries the on-chain `actual`. */
|
|
55
|
+
protected satisfiedResult(satisfied: boolean, detail: PrerequisiteDetail<K>): PrerequisiteResult<K>;
|
|
56
|
+
/** Builds a failed result from a decoded read error. */
|
|
57
|
+
protected errorResult(error: PrerequisiteError): PrerequisiteResult<K>;
|
|
58
|
+
}
|
|
59
|
+
/** Any prerequisite regardless of its kind, used for heterogeneous lists. */
|
|
60
|
+
export type AnyPrerequisite = Prerequisite<PrerequisiteKind>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Operation } from "../parse/index.js";
|
|
2
|
+
import type { AnyPrerequisite } from "./Prerequisite.js";
|
|
3
|
+
import type { PrerequisiteContext } from "./types.js";
|
|
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).
|
|
8
|
+
*
|
|
9
|
+
* Only *sender-actionable* prerequisites belong here: conditions the LP
|
|
10
|
+
* provider or borrower can fix themselves before retrying (e.g. approve a
|
|
11
|
+
* token, top up a balance). Non-actionable protocol/admin state (pool pause,
|
|
12
|
+
* available pool liquidity, health factor, liquidatability, degen NFT gating,
|
|
13
|
+
* bot permissions) is intentionally out of scope, since the user cannot
|
|
14
|
+
* resolve it. New {@link AnyPrerequisite} subclasses must follow the same rule.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildPrerequisites(tx: Operation, ctx: PrerequisiteContext): AnyPrerequisite[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./AllowancePrerequisite.js";
|
|
2
|
+
export * from "./BalancePrerequisite.js";
|
|
3
|
+
export * from "./buildPrerequisites.js";
|
|
4
|
+
export * from "./Prerequisite.js";
|
|
5
|
+
export * from "./prepareAction.js";
|
|
6
|
+
export * from "./runPrerequisites.js";
|
|
7
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import type { AnyPrerequisiteResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A single transaction that satisfies a sender-actionable prerequisite.
|
|
5
|
+
*
|
|
6
|
+
* The shape is intentionally minimal (`to`/`data`/optional `value`) so it maps
|
|
7
|
+
* directly onto wallet send primitives (e.g. viem `sendTransaction`, wagmi
|
|
8
|
+
* `useSendTransaction`/`useWriteContract`). It is deliberately *not* the heavier
|
|
9
|
+
* {@link import("../../sdk/types/transactions.js").RawTx} used for Safe batches.
|
|
10
|
+
*
|
|
11
|
+
* The `kind` mirrors the prerequisite kind it remediates, so consumers can label
|
|
12
|
+
* the action (e.g. "Approve") without re-deriving it.
|
|
13
|
+
*/
|
|
14
|
+
export interface PrerequisiteAction {
|
|
15
|
+
/** Prerequisite kind this action remediates. */
|
|
16
|
+
kind: "allowance";
|
|
17
|
+
/** Contract the transaction is sent to (the ERC-20 token for allowances). */
|
|
18
|
+
to: Address;
|
|
19
|
+
/** Encoded calldata (e.g. `approve(spender, required)`). */
|
|
20
|
+
data: Hex;
|
|
21
|
+
/** Native value to send; omitted (treated as 0) for ERC-20 approvals. */
|
|
22
|
+
value?: bigint;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Builds the transaction that resolves an unsatisfied, sender-actionable
|
|
26
|
+
* prerequisite, or returns `null` when the prerequisite cannot be fixed with a
|
|
27
|
+
* single wallet transaction.
|
|
28
|
+
*
|
|
29
|
+
* Currently only `allowance` is actionable: it returns an ERC-20
|
|
30
|
+
* `approve(spender, required)` for the exact required amount. `balance`
|
|
31
|
+
* shortfalls (the user must acquire/free up funds) and errored reads are not
|
|
32
|
+
* actionable and return `null`. New actionable kinds (permits, native unwrap,
|
|
33
|
+
* approve-reset-to-zero for non-standard tokens, ...) should be encoded here so
|
|
34
|
+
* consumers do not have to special-case them.
|
|
35
|
+
*
|
|
36
|
+
* Operates on the serializable {@link AnyPrerequisiteResult} produced by
|
|
37
|
+
* `verifyPrerequisites` (not on {@link import("./Prerequisite.js").Prerequisite}
|
|
38
|
+
* instances), so it works against cached/persisted results.
|
|
39
|
+
*
|
|
40
|
+
* @param result - A verified prerequisite result.
|
|
41
|
+
* @returns The remediation transaction, or `null` if not auto-actionable.
|
|
42
|
+
*/
|
|
43
|
+
export declare function preparePrerequisiteAction(result: AnyPrerequisiteResult): PrerequisiteAction | null;
|
|
44
|
+
/**
|
|
45
|
+
* Whether a prerequisite result represents something the sender can fix with a
|
|
46
|
+
* single wallet transaction (i.e. {@link preparePrerequisiteAction} returns a
|
|
47
|
+
* transaction for it).
|
|
48
|
+
*
|
|
49
|
+
* Useful for UIs that distinguish "approve to continue" (actionable) from hard
|
|
50
|
+
* blocks like an insufficient balance (not actionable).
|
|
51
|
+
*/
|
|
52
|
+
export declare function isActionablePrerequisite(result: AnyPrerequisiteResult): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AnyPrerequisite } from "./Prerequisite.js";
|
|
2
|
+
import type { AnyPrerequisiteResult, PrerequisiteContext } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Verifies all prerequisites in a single resilient multicall.
|
|
5
|
+
*
|
|
6
|
+
* Every prereq contributes its reads to one `multicall({ allowFailure: true })`
|
|
7
|
+
* batch, then resolves its own slice of the response. A read that reverts
|
|
8
|
+
* isolates to that prerequisite (an `error` result) without affecting the
|
|
9
|
+
* others; if the whole round-trip fails (RPC/network), every prerequisite
|
|
10
|
+
* resolves to an `error` carrying that reason.
|
|
11
|
+
*/
|
|
12
|
+
export declare function verifyPrerequisites(prereqs: AnyPrerequisite[], ctx: PrerequisiteContext): Promise<AnyPrerequisiteResult[]>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { OnchainSDK } from "../../sdk/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extension point that ties each prerequisite kind to its detail payload.
|
|
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
|
+
* IMPORTANT: only add prerequisites that are *actionable by the transaction
|
|
11
|
+
* sender* (the LP provider or borrower). A valid prerequisite is one the user
|
|
12
|
+
* 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.
|
|
16
|
+
*/
|
|
17
|
+
export interface PrerequisiteDetailMap {
|
|
18
|
+
/** ERC-20 allowance from `owner` to `spender` must cover `required`. */
|
|
19
|
+
allowance: {
|
|
20
|
+
token: Address;
|
|
21
|
+
owner: Address;
|
|
22
|
+
spender: Address;
|
|
23
|
+
required: bigint;
|
|
24
|
+
/** On-chain allowance read; only present when the read succeeded. */
|
|
25
|
+
actual?: bigint;
|
|
26
|
+
};
|
|
27
|
+
/** ERC-20 balance of `owner` must cover `required`. */
|
|
28
|
+
balance: {
|
|
29
|
+
token: Address;
|
|
30
|
+
owner: Address;
|
|
31
|
+
required: bigint;
|
|
32
|
+
/** On-chain balance read; only present when the read succeeded. */
|
|
33
|
+
actual?: bigint;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export type PrerequisiteKind = keyof PrerequisiteDetailMap;
|
|
37
|
+
export type PrerequisiteDetail<K extends PrerequisiteKind = PrerequisiteKind> = PrerequisiteDetailMap[K];
|
|
38
|
+
/** Failure of the underlying on-chain read (revert, decode error, RPC error). */
|
|
39
|
+
export interface PrerequisiteError {
|
|
40
|
+
/** Decoded revert reason / error name, human-readable. */
|
|
41
|
+
reason: string;
|
|
42
|
+
/** Original error, kept for debugging. */
|
|
43
|
+
cause?: unknown;
|
|
44
|
+
}
|
|
45
|
+
export interface PrerequisiteBase<K extends PrerequisiteKind> {
|
|
46
|
+
id: string;
|
|
47
|
+
kind: K;
|
|
48
|
+
title: string;
|
|
49
|
+
detail: PrerequisiteDetail<K>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Outcome of verifying a single prerequisite: either the read succeeded (a
|
|
53
|
+
* `satisfied` boolean) or it reverted/failed (an `error` with the revert
|
|
54
|
+
* reason). The two variants are mutually exclusive.
|
|
55
|
+
*/
|
|
56
|
+
export type PrerequisiteResult<K extends PrerequisiteKind = PrerequisiteKind> = PrerequisiteBase<K> & ({
|
|
57
|
+
satisfied: boolean;
|
|
58
|
+
error?: undefined;
|
|
59
|
+
} | {
|
|
60
|
+
satisfied?: undefined;
|
|
61
|
+
error: PrerequisiteError;
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Discriminated union over every prerequisite kind. Switching on `kind`
|
|
65
|
+
* narrows `detail` to the matching payload, so React components can render
|
|
66
|
+
* kind-specific details with full type safety.
|
|
67
|
+
*/
|
|
68
|
+
export type AnyPrerequisiteResult = {
|
|
69
|
+
[K in PrerequisiteKind]: PrerequisiteResult<K>;
|
|
70
|
+
}[PrerequisiteKind];
|
|
71
|
+
/** Shared inputs for building and verifying prerequisites. */
|
|
72
|
+
export interface PrerequisiteContext {
|
|
73
|
+
sdk: OnchainSDK;
|
|
74
|
+
/** Address whose balances/allowances are checked (the tx sender). */
|
|
75
|
+
wallet: Address;
|
|
76
|
+
/** Block to read at; defaults to latest. Only set for testnet forks. */
|
|
77
|
+
blockNumber?: bigint;
|
|
78
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BaseError, type Hex } from "viem";
|
|
2
|
+
/** Which simulation flow produced a failure. */
|
|
3
|
+
export type SimulationFlowSource = "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 it fails. It wraps the flow's
|
|
11
|
+
* decoded revert reason (see {@link failures}).
|
|
12
|
+
*/
|
|
13
|
+
export declare class PreviewSimulationError extends BaseError {
|
|
14
|
+
name: string;
|
|
15
|
+
/** Per-flow decoded failures behind this error. */
|
|
16
|
+
readonly failures: SimulationFlowFailure[];
|
|
17
|
+
constructor(failures: SimulationFlowFailure[]);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Normalises an unknown rejection reason into a {@link PreviewSimulationError}.
|
|
21
|
+
* Pass-through when it already is one; otherwise decodes it under `source`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function asPreviewSimulationError(reason: unknown, source: SimulationFlowSource): PreviewSimulationError;
|
|
24
|
+
/** Decoded revert of the simulated transaction. */
|
|
25
|
+
export interface SimulationError {
|
|
26
|
+
/** Human-readable revert reason / error name. */
|
|
27
|
+
reason: string;
|
|
28
|
+
/** Original error, kept for debugging. */
|
|
29
|
+
cause?: unknown;
|
|
30
|
+
}
|
|
31
|
+
/** Per-call slice of a multicall failure we need to decode. */
|
|
32
|
+
export interface SimulationRevert {
|
|
33
|
+
error?: Error;
|
|
34
|
+
/** Raw revert return data, when present. */
|
|
35
|
+
data?: Hex;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Decodes a simulated call revert into a {@link SimulationError}.
|
|
39
|
+
*
|
|
40
|
+
* We first try to decode any raw return bytes against the SDK's
|
|
41
|
+
* {@link errorAbis} (Gearbox protocol exceptions plus standard ERC-20 custom
|
|
42
|
+
* errors); failing that, we walk viem's error chain for a
|
|
43
|
+
* {@link ContractFunctionRevertedError} (covers `Error(string)` / `Panic`).
|
|
44
|
+
*/
|
|
45
|
+
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[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { SimulationError, SimulationFlowFailure, SimulationFlowSource, } from "./errors.js";
|
|
2
|
+
export { PreviewSimulationError } from "./errors.js";
|
|
3
|
+
export type { SimulateFacadeOperationInput } from "./simulateFacadeOperation.js";
|
|
4
|
+
export { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
5
|
+
export type { SimulateOperationInput } from "./simulateOperation.js";
|
|
6
|
+
export { simulateOperation } from "./simulateOperation.js";
|
|
7
|
+
export { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
8
|
+
export type { AddressBalanceChanges, OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput, PoolOperationSimulationResult, TokenBalanceChange, } from "./types.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { OnchainSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { OuterFacadeOperation } from "../parse/index.js";
|
|
4
|
+
import type { OperationSimulationOptions, PoolOperationSimulation } from "./types.js";
|
|
5
|
+
export interface SimulateFacadeOperationInput {
|
|
6
|
+
/** Only `client`/`networkType` are used, so any OnchainSDK works. */
|
|
7
|
+
sdk: OnchainSDK;
|
|
8
|
+
/** Parsed credit-facade operation to simulate. */
|
|
9
|
+
operation: OuterFacadeOperation;
|
|
10
|
+
/** Target contract the calldata is sent to (the credit facade). */
|
|
11
|
+
to: Address;
|
|
12
|
+
/** Raw credit-facade calldata to simulate. */
|
|
13
|
+
calldata: Hex;
|
|
14
|
+
/** Wallet whose balance changes and transfers we track. */
|
|
15
|
+
wallet: Address;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Simulates a credit-facade operation.
|
|
19
|
+
*
|
|
20
|
+
* Not yet implemented: credit-facade simulation requires multicall-aware
|
|
21
|
+
* balance/transfer accounting that the pool simulation does not cover. The
|
|
22
|
+
* signature mirrors {@link simulatePoolOperation} so the
|
|
23
|
+
* {@link simulateOperation} wrapper can delegate uniformly once implemented.
|
|
24
|
+
*/
|
|
25
|
+
export declare function simulateFacadeOperation(_input: SimulateFacadeOperationInput, _options?: OperationSimulationOptions): Promise<PoolOperationSimulation>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { OnchainSDK } from "../../sdk/index.js";
|
|
3
|
+
import { type Operation } from "../parse/index.js";
|
|
4
|
+
import type { OperationSimulationOptions, PoolOperationSimulation } from "./types.js";
|
|
5
|
+
export interface SimulateOperationInput {
|
|
6
|
+
/** Gearbox SDK instance. */
|
|
7
|
+
sdk: OnchainSDK;
|
|
8
|
+
/** Parsed pool or credit account operation */
|
|
9
|
+
operation: Operation;
|
|
10
|
+
/** Target contract the calldata is sent to. */
|
|
11
|
+
to: Address;
|
|
12
|
+
/** Raw operation calldata to simulate. */
|
|
13
|
+
calldata: Hex;
|
|
14
|
+
/** Wallet whose balance changes and transfers we track. */
|
|
15
|
+
wallet: Address;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Simulates a parsed pool or credit account operation {@link Operation}
|
|
19
|
+
*/
|
|
20
|
+
export declare function simulateOperation(input: SimulateOperationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulation>;
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
6
|
+
/**
|
|
7
|
+
* Simulates a pool deposit/mint/withdraw/redeem (direct or zapper-routed) and
|
|
8
|
+
* returns the resulting balance changes, or a decoded failure.
|
|
9
|
+
*
|
|
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).
|
|
19
|
+
*/
|
|
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[];
|
|
@@ -0,0 +1,66 @@
|
|
|
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 } from "../parse/index.js";
|
|
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
|
+
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
|
+
* Optional logger.
|
|
42
|
+
**/
|
|
43
|
+
logger?: ILogger;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
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.
|
|
49
|
+
*/
|
|
50
|
+
export interface PoolOperationSimulationResult {
|
|
51
|
+
/**
|
|
52
|
+
* Balance changes grouped by watched address (wallet, recipient, owner).
|
|
53
|
+
**/
|
|
54
|
+
balanceChanges: AddressBalanceChanges[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Outcome of simulating a pool operation. On success it carries a
|
|
58
|
+
* {@link PoolOperationSimulationResult}; on failure it carries a
|
|
59
|
+
* {@link PreviewSimulationError}.
|
|
60
|
+
*/
|
|
61
|
+
export type PoolOperationSimulation = ({
|
|
62
|
+
status: "success";
|
|
63
|
+
} & PoolOperationSimulationResult) | {
|
|
64
|
+
status: "failure";
|
|
65
|
+
error: PreviewSimulationError;
|
|
66
|
+
};
|