viem-tx-sim 0.1.0 → 0.2.0
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/README.md +103 -34
- package/contracts/TxSimulator.sol +83 -20
- package/dist/generated/txSimulatorBytecode.d.ts +1 -1
- package/dist/generated/txSimulatorBytecode.d.ts.map +1 -1
- package/dist/generated/txSimulatorBytecode.js +1 -1
- package/dist/generated/txSimulatorBytecode.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/queryDiscovery.d.ts +8 -0
- package/dist/internal/queryDiscovery.d.ts.map +1 -0
- package/dist/internal/queryDiscovery.js +38 -0
- package/dist/internal/queryDiscovery.js.map +1 -0
- package/dist/internal/requirements.d.ts +2 -1
- package/dist/internal/requirements.d.ts.map +1 -1
- package/dist/internal/requirements.js +2 -1
- package/dist/internal/requirements.js.map +1 -1
- package/dist/internal/simulator.d.ts +19 -3
- package/dist/internal/simulator.d.ts.map +1 -1
- package/dist/internal/simulator.js +12 -16
- package/dist/internal/simulator.js.map +1 -1
- package/dist/internal/slots.d.ts +4 -2
- package/dist/internal/slots.d.ts.map +1 -1
- package/dist/internal/slots.js +4 -2
- package/dist/internal/slots.js.map +1 -1
- package/dist/txSimulator.d.ts +64 -40
- package/dist/txSimulator.d.ts.map +1 -1
- package/dist/txSimulator.js +64 -16
- package/dist/txSimulator.js.map +1 -1
- package/dist/types.d.ts +47 -16
- package/dist/types.d.ts.map +1 -1
- package/package.json +17 -28
- package/src/generated/txSimulatorBytecode.ts +1 -1
- package/src/index.ts +3 -1
- package/src/internal/queryDiscovery.ts +49 -0
- package/src/internal/requirements.ts +3 -1
- package/src/internal/simulator.ts +28 -24
- package/src/internal/slots.ts +5 -2
- package/src/txSimulator.ts +160 -63
- package/src/types.ts +50 -17
package/dist/types.d.ts
CHANGED
|
@@ -8,6 +8,28 @@ export type SimulatedCall = {
|
|
|
8
8
|
/** Native value to send with this call; omitted means zero. */
|
|
9
9
|
value?: bigint;
|
|
10
10
|
};
|
|
11
|
+
/** One balance to observe during simulation. `asset` is `"native"` or an ERC-20 address. */
|
|
12
|
+
export type BalanceQuery = {
|
|
13
|
+
asset: "native" | Address;
|
|
14
|
+
/** Account whose balance is observed; this can be any address, not just `from`. */
|
|
15
|
+
account: Address;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Balance observation for one query. `before` is after `tokenSlotOverrides` are applied, so deltas
|
|
19
|
+
* describe simulated changes under the supplied state assumptions.
|
|
20
|
+
*/
|
|
21
|
+
export type BalanceDelta = {
|
|
22
|
+
asset: "native" | Address;
|
|
23
|
+
account: Address;
|
|
24
|
+
before: bigint;
|
|
25
|
+
after: bigint;
|
|
26
|
+
delta: bigint;
|
|
27
|
+
/**
|
|
28
|
+
* Signed change per call, index-aligned with `calls`. Sums to `delta`; on a
|
|
29
|
+
* revert, entries from the failing call onward are 0n.
|
|
30
|
+
*/
|
|
31
|
+
byCall: readonly bigint[];
|
|
32
|
+
};
|
|
11
33
|
/** Structured event emitted before and after each RPC call when debug logging is enabled. */
|
|
12
34
|
export type SimulationDebugEvent = {
|
|
13
35
|
/** Lifecycle phase for the RPC operation. */
|
|
@@ -45,7 +67,7 @@ type SimulationOptions = {
|
|
|
45
67
|
export type TokenSlotOverride = {
|
|
46
68
|
/** Token contract whose storage should be overridden. */
|
|
47
69
|
token: Address;
|
|
48
|
-
/** Storage slot to write. Usually prepared by `
|
|
70
|
+
/** Storage slot to write. Usually prepared by `tokenOverrides.forBalances` or `tokenOverrides.forAllowances`. */
|
|
49
71
|
slot: Hex;
|
|
50
72
|
/** Value written to the slot. Must be below uint256 max. */
|
|
51
73
|
amount: bigint;
|
|
@@ -88,26 +110,38 @@ export type SimulateArgs = SimulationOptions & {
|
|
|
88
110
|
from: Address;
|
|
89
111
|
/** One call or an ERC-5792-style sequential batch. Must contain at least one call. */
|
|
90
112
|
calls: readonly SimulatedCall[];
|
|
91
|
-
/**
|
|
113
|
+
/** Balances to observe. Use `[]` to execute without balance observations. */
|
|
114
|
+
balanceQueries: readonly BalanceQuery[];
|
|
115
|
+
/**
|
|
116
|
+
* Storage-slot overrides applied before simulating. Query the tokens you forge if you want to
|
|
117
|
+
* observe them.
|
|
118
|
+
*/
|
|
92
119
|
tokenSlotOverrides?: readonly TokenSlotOverride[];
|
|
93
120
|
/** Additional error definitions for decoding this call's reverts; merged after the bound errorAbi. */
|
|
94
121
|
errorAbi?: Abi;
|
|
95
122
|
};
|
|
96
|
-
/** Arguments for `TxSimulator.
|
|
123
|
+
/** Arguments for `TxSimulator.balanceQueries.forUser`. */
|
|
124
|
+
export type ForUserBalanceQueriesArgs = SimulationOptions & {
|
|
125
|
+
/** Account whose wallet-style balance queries should be discovered. */
|
|
126
|
+
from: Address;
|
|
127
|
+
/** Calls whose access lists should be searched for token candidates. */
|
|
128
|
+
calls: readonly SimulatedCall[];
|
|
129
|
+
};
|
|
130
|
+
/** Arguments for `TxSimulator.tokenOverrides.forBalances`. */
|
|
97
131
|
export type PrepareBalanceOverridesArgs = SimulationOptions & {
|
|
98
132
|
/** Account whose token balance overrides should be prepared. */
|
|
99
133
|
from: Address;
|
|
100
134
|
/** Tokens to prepare ERC-20-style balance overrides for. */
|
|
101
135
|
tokens: readonly Address[];
|
|
102
136
|
};
|
|
103
|
-
/** Arguments for `TxSimulator.
|
|
137
|
+
/** Arguments for `TxSimulator.tokenOverrides.forAllowances`. */
|
|
104
138
|
export type PrepareAllowanceOverridesArgs = SimulationOptions & {
|
|
105
139
|
/** Account whose allowance overrides should be prepared. */
|
|
106
140
|
from: Address;
|
|
107
141
|
/** Token/spender allowance pairs to prepare overrides for. */
|
|
108
142
|
pairs: readonly AllowanceSlotPair[];
|
|
109
143
|
};
|
|
110
|
-
/** Arguments for `TxSimulator.
|
|
144
|
+
/** Arguments for `TxSimulator.tokenOverrides.estimateRequirements`. */
|
|
111
145
|
export type EstimateAssetRequirementsArgs = SimulationOptions & {
|
|
112
146
|
/** Account whose balance and approval needs should be estimated. */
|
|
113
147
|
from: Address;
|
|
@@ -179,24 +213,21 @@ export type EstimatedAssetRequirementsReverted = EstimatedAssetRequirementsBase
|
|
|
179
213
|
};
|
|
180
214
|
/** Asset-requirement estimate result; check `status` before reading revert fields. */
|
|
181
215
|
export type EstimatedAssetRequirements = EstimatedAssetRequirementsSuccess | EstimatedAssetRequirementsReverted;
|
|
182
|
-
/** Raw balance delta for native ETH or an ERC-20-style `balanceOf(address)` asset. */
|
|
183
|
-
export type AssetBalanceDelta = {
|
|
184
|
-
/** `"native"` for ETH, otherwise the token contract address. */
|
|
185
|
-
asset: "native" | Address;
|
|
186
|
-
/** Signed raw-unit balance change for `from`; negative means the account lost assets. */
|
|
187
|
-
delta: bigint;
|
|
188
|
-
};
|
|
189
216
|
/** Successful simulation result. */
|
|
190
217
|
export type SimulationSuccess = {
|
|
191
218
|
status: "success";
|
|
192
|
-
/**
|
|
193
|
-
|
|
219
|
+
/** Balance observations mirrored 1:1 from successful queries, including zero deltas. */
|
|
220
|
+
balanceDeltas: BalanceDelta[];
|
|
221
|
+
/** Queries that could not be read, usually because an ERC-20 `balanceOf` staticcall failed. */
|
|
222
|
+
unresolved: BalanceQuery[];
|
|
194
223
|
};
|
|
195
224
|
/** Simulation result for a transaction revert; infrastructure failures throw typed errors instead. */
|
|
196
225
|
export type SimulationReverted = {
|
|
197
226
|
status: "reverted";
|
|
198
|
-
/**
|
|
199
|
-
|
|
227
|
+
/** Balance observations mirrored 1:1 from successful queries, including zero deltas. */
|
|
228
|
+
balanceDeltas: BalanceDelta[];
|
|
229
|
+
/** Queries that could not be read, usually because an ERC-20 `balanceOf` staticcall failed. */
|
|
230
|
+
unresolved: BalanceQuery[];
|
|
200
231
|
/** Raw EVM revert data from the failing simulated call. */
|
|
201
232
|
revertData: Hex;
|
|
202
233
|
/** Human-readable decoded revert; present when revertData decodes via supplied error definitions or as built-in Error/Panic. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1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AAC,EAAE,MAAM,CAAC;IACtB,gGAAgG;IAChG,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,mFAAmF;IACnF,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,sFAAsF;AACtF,MAAM,MAAM,0BAA0B,GAClC,iCAAiC,GACjC,kCAAkC,CAAC;AAEvC,oCAAoC;AACpC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,SAAS,CAAC;IAClB,wFAAwF;IACxF,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,+FAA+F;IAC/F,UAAU,EAAE,YAAY,EAAE,CAAC;CAC5B,CAAC;AAEF,sGAAsG;AACtG,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,UAAU,CAAC;IACnB,wFAAwF;IACxF,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,+FAA+F;IAC/F,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,2DAA2D;IAC3D,UAAU,EAAE,GAAG,CAAC;IAChB,gIAAgI;IAChI,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gGAAgG;IAChG,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,mFAAmF;IACnF,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,gGAAgG;AAChG,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viem-tx-sim",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "RPC-only transaction simulation helpers for viem applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eth_call",
|
|
@@ -35,24 +35,6 @@
|
|
|
35
35
|
"default": "./dist/index.js"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "pnpm build:contracts && pnpm build:ts",
|
|
40
|
-
"build:contracts": "forge build && node scripts/generate-txsim-bytecode.mjs",
|
|
41
|
-
"build:ts": "tsc -p tsconfig.build.json",
|
|
42
|
-
"changeset": "changeset",
|
|
43
|
-
"fmt": "oxfmt package.json .oxlintrc.json .oxfmtrc.json tsconfig.json tsconfig.build.json vitest.config.ts src test scripts",
|
|
44
|
-
"fmt:check": "oxfmt --check package.json .oxlintrc.json .oxfmtrc.json tsconfig.json tsconfig.build.json vitest.config.ts src test scripts",
|
|
45
|
-
"lint": "oxlint && oxfmt --check package.json .oxlintrc.json .oxfmtrc.json tsconfig.json tsconfig.build.json vitest.config.ts src test scripts",
|
|
46
|
-
"lint:fix": "oxlint --fix && oxfmt package.json .oxlintrc.json .oxfmtrc.json tsconfig.json tsconfig.build.json vitest.config.ts src test scripts",
|
|
47
|
-
"prepare": "pnpm build:ts",
|
|
48
|
-
"prepublishOnly": "pnpm build:ts",
|
|
49
|
-
"release": "pnpm verify && pnpm changeset publish",
|
|
50
|
-
"test": "pnpm build:contracts && vitest run",
|
|
51
|
-
"test:debug": "VIEM_TX_SIM_DEBUG_RPC=1 pnpm test",
|
|
52
|
-
"test:mainnet": "pnpm build:contracts && vitest run test/mainnet.test.ts",
|
|
53
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
54
|
-
"verify": "pnpm lint && pnpm typecheck && pnpm build && pnpm test"
|
|
55
|
-
},
|
|
56
38
|
"devDependencies": {
|
|
57
39
|
"@arethetypeswrong/cli": "^0.18.4",
|
|
58
40
|
"@changesets/changelog-github": "^0.7.0",
|
|
@@ -70,13 +52,20 @@
|
|
|
70
52
|
"engines": {
|
|
71
53
|
"node": ">=20"
|
|
72
54
|
},
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "pnpm build:contracts && pnpm build:ts",
|
|
57
|
+
"build:contracts": "forge build && node scripts/generate-txsim-bytecode.mjs",
|
|
58
|
+
"build:ts": "tsc -p tsconfig.build.json",
|
|
59
|
+
"changeset": "changeset",
|
|
60
|
+
"fmt": "oxfmt package.json .oxlintrc.json .oxfmtrc.json tsconfig.json tsconfig.build.json vitest.config.ts src test scripts",
|
|
61
|
+
"fmt:check": "oxfmt --check package.json .oxlintrc.json .oxfmtrc.json tsconfig.json tsconfig.build.json vitest.config.ts src test scripts",
|
|
62
|
+
"lint": "oxlint && oxfmt --check package.json .oxlintrc.json .oxfmtrc.json tsconfig.json tsconfig.build.json vitest.config.ts src test scripts",
|
|
63
|
+
"lint:fix": "oxlint --fix && oxfmt package.json .oxlintrc.json .oxfmtrc.json tsconfig.json tsconfig.build.json vitest.config.ts src test scripts",
|
|
64
|
+
"release": "pnpm verify && pnpm changeset publish",
|
|
65
|
+
"test": "pnpm build:contracts && vitest run",
|
|
66
|
+
"test:debug": "VIEM_TX_SIM_DEBUG_RPC=1 pnpm test",
|
|
67
|
+
"test:mainnet": "pnpm build:contracts && vitest run test/mainnet.test.ts",
|
|
68
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
69
|
+
"verify": "pnpm lint && pnpm typecheck && pnpm build && pnpm test"
|
|
81
70
|
}
|
|
82
|
-
}
|
|
71
|
+
}
|
|
@@ -2,4 +2,4 @@ import type { Hex } from "viem";
|
|
|
2
2
|
|
|
3
3
|
// Generated by scripts/generate-txsim-bytecode.mjs.
|
|
4
4
|
export const txSimulatorRuntimeBytecode =
|
|
5
|
-
"0x60806040526004361061004c575f3560e01c8063150b7a02146100575780631626ba7e146100a0578063bc197c81146100bf578063cb8935e9146100ed578063f23a6e6114610119575f80fd5b3661005357005b5f80fd5b348015610062575f80fd5b506100826100713660046110ac565b630a85bd0160e11b95945050505050565b6040516001600160e01b031990911681526020015b60405180910390f35b3480156100ab575f80fd5b506100826100ba366004611115565b610145565b3480156100ca575f80fd5b506100826100d936600461119c565b63bc197c8160e01b98975050505050505050565b3480156100f8575f80fd5b5061010c61010736600461124e565b610181565b60405161009791906113cb565b348015610124575f80fd5b506100826101333660046114b9565b63f23a6e6160e01b9695505050505050565b5f30610152858585610300565b6001600160a01b03161461016e576001600160e01b0319610177565b630b135d3f60e11b5b90505b9392505050565b6101d56040518061014001604052805f151581526020015f8152602001606081526020015f8152602001606081526020016060815260200160608152602001606081526020015f8152602001606081525090565b475f6101e18787610456565b90506101ee88600161153f565b6101f89085611552565b6001600160401b0381111561020f5761020f611569565b604051908082528060200260200182016040528015610238578160200160208202803683370190505b50610120840190815260408051608081018252838201518152602080850151908201529151908201525f90606081016102728b600161153f565b905290505f6102878b8b8b8b8b8b888b6106d5565b60408901919091526020880191909152901515865290506102a847856107cd565b8560600181815250506102c383606001518460800151610844565b6080860152808410156102d6575f6102e0565b6102e0818561157d565b6101008601526102f2898985886108e0565b505050509695505050505050565b5f60418290036103bb578235602084013560408501355f1a601b81101561032f5761032c601b82611590565b90505b8060ff16601b1415801561034757508060ff16601c14155b15610357575f935050505061017a565b604080515f81526020810180835289905260ff831691810191909152606081018490526080810183905260019060a0016020604051602081039080840390855afa1580156103a7573d5f803e3d5ffd5b50505060206040510351935050505061017a565b604082900361044d57823560208401356001600160ff1b0381165f6103e560ff84901c601b61153f565b604080515f8152602081018083528b905260ff831691810191909152606081018690526080810184905290915060019060a0016020604051602081039080840390855afa158015610438573d5f803e3d5ffd5b5050506020604051035194505050505061017a565b505f9392505050565b6104876040518060a00160405280606081526020016060815260200160608152602001606081526020015f81525090565b816001600160401b0381111561049f5761049f611569565b6040519080825280602002602001820160405280156104c8578160200160208202803683370190505b508152816001600160401b038111156104e3576104e3611569565b60405190808252806020026020018201604052801561050c578160200160208202803683370190505b506020820152816001600160401b0381111561052a5761052a611569565b604051908082528060200260200182016040528015610553578160200160208202803683370190505b506040820152816001600160401b0381111561057157610571611569565b60405190808252806020026020018201604052801561059a578160200160208202803683370190505b5060608201525f5b828110156106ce575f806105dc8686858181106105c1576105c16115a9565b90506020020160208101906105d691906115bd565b30610b97565b9150915081156106c4576001846040015184815181106105fe576105fe6115a9565b60200260200101901515908115158152505080845f01518481518110610626576106266115a9565b6020026020010181815250508084602001518481518110610649576106496115a9565b602002602001018181525050858584818110610667576106676115a9565b905060200201602081019061067c91906115bd565b606085015160808601805190610691826115d6565b9052815181106106a3576106a36115a9565b60200260200101906001600160a01b031690816001600160a01b0316815250505b50506001016105a2565b5092915050565b60015f1960608386156106f7576106f7888888606001515f8a60400151610c6f565b5f5b8b8110156107bd575f8061072f8f8f85818110610718576107186115a9565b905060200281019061072a91906115ee565b610d2a565b9150915081610768575f96509194509092508390838915610761576107618b8b90508a60600151858c60400151610dac565b50506107bd565b4784811015610775578094505b6107888e8e8c5f01518d60200151610e4b565b8a156107af576107af8c8c8c606001518760016107a5919061153f565b8e60400151610c6f565b5050508060010190506106f9565b5098509850985098945050505050565b5f818310610808575f6107e0838561157d565b90506001600160ff1b03811115610801576001600160ff1b0391505061083e565b905061083e565b5f610813848461157d565b90506001600160ff1b0381111561083157600160ff1b91505061083e565b61083a8161160c565b9150505b92915050565b6060816001600160401b0381111561085e5761085e611569565b604051908082528060200260200182016040528015610887578160200160208202803683370190505b5090505f5b828110156106ce578381815181106108a6576108a66115a9565b60200260200101518282815181106108c0576108c06115a9565b6001600160a01b039092166020928302919091019091015260010161088c565b826001600160401b038111156108f8576108f8611569565b604051908082528060200260200182016040528015610921578160200160208202803683370190505b5060e08201525f836001600160401b0381111561094057610940611569565b604051908082528060200260200182016040528015610969578160200160208202803683370190505b5090505f846001600160401b0381111561098557610985611569565b6040519080825280602002602001820160405280156109ae578160200160208202803683370190505b5090505f805b86811015610b6c57856040015181815181106109d2576109d26115a9565b602002602001015115610b6457856020015181815181106109f5576109f56115a9565b6020026020010151865f01518281518110610a1257610a126115a9565b602002602001015110610a875785602001518181518110610a3557610a356115a9565b6020026020010151865f01518281518110610a5257610a526115a9565b6020026020010151610a64919061157d565b8560e001518281518110610a7a57610a7a6115a9565b6020026020010181815250505b5f80610a9e8a8a858181106105c1576105c16115a9565b9150915081610aae575050610b64565b5f610ad5828a5f01518681518110610ac857610ac86115a9565b60200260200101516107cd565b90508015610b60578a8a85818110610aef57610aef6115a9565b9050602002016020810190610b0491906115bd565b878681518110610b1657610b166115a9565b60200260200101906001600160a01b031690816001600160a01b03168152505080868681518110610b4957610b496115a9565b6020908102919091010152610b5d856115d6565b94505b5050505b6001016109b4565b50610b778382610844565b60a0850152610b868282610ee4565b8460c0018190525050505050505050565b604080516001600160a01b0383811660248084019190915283518084039091018152604490920183526020820180516001600160e01b03166370a0823160e01b17905291515f92839283928392881691610bf091611626565b5f60405180830381855afa9150503d805f8114610c28576040519150601f19603f3d011682016040523d82523d5f602084013e610c2d565b606091505b5091509150811580610c40575060208151105b15610c4c575050610c68565b81935080806020019051810190610c639190611637565b925050505b9250929050565b5f5b84811015610d22575f80610cd6888885818110610c9057610c906115a9565b610ca692602060409092020190810191506115bd565b308a8a87818110610cb957610cb96115a9565b9050604002016020016020810190610cd191906115bd565b610f73565b9150915081610ce5575f610ce7565b805b8486610cf38987611552565b610cfd919061153f565b81518110610d0d57610d0d6115a9565b60209081029190910101525050600101610c71565b505050505050565b5f6060610d3a60208401846115bd565b6001600160a01b03166020840135610d55604086018661164e565b604051610d63929190611690565b5f6040518083038185875af1925050503d805f8114610d9d576040519150601f19603f3d011682016040523d82523d5f602084013e610da2565b606091505b5091509150915091565b5f5b84811015610e44575f8284610dc38785611552565b610dcd919061153f565b81518110610ddd57610ddd6115a9565b602002602001015190505f846001610df5919061153f565b90505b85811015610e3a57818482610e0d8987611552565b610e17919061153f565b81518110610e2757610e276115a9565b6020908102919091010152600101610df8565b5050600101610dae565b5050505050565b5f5b83811015610e4457828181518110610e6757610e676115a9565b602002602001015115610edc575f80610e8b8787858181106105c1576105c16115a9565b91509150818015610eb45750838381518110610ea957610ea96115a9565b602002602001015181105b15610ed95780848481518110610ecc57610ecc6115a9565b6020026020010181815250505b50505b600101610e4d565b6060816001600160401b03811115610efe57610efe611569565b604051908082528060200260200182016040528015610f27578160200160208202803683370190505b5090505f5b828110156106ce57838181518110610f4657610f466115a9565b6020026020010151828281518110610f6057610f606115a9565b6020908102919091010152600101610f2c565b604080516001600160a01b03848116602483015283811660448084019190915283518084039091018152606490920183526020820180516001600160e01b0316636eb1769f60e11b17905291515f92839283928392891691610fd491611626565b5f60405180830381855afa9150503d805f811461100c576040519150601f19603f3d011682016040523d82523d5f602084013e611011565b606091505b5091509150811580611024575060208151105b1561103057505061104c565b819350808060200190518101906110479190611637565b925050505b935093915050565b80356001600160a01b038116811461106a575f80fd5b919050565b5f8083601f84011261107f575f80fd5b5081356001600160401b03811115611095575f80fd5b602083019150836020828501011115610c68575f80fd5b5f805f805f608086880312156110c0575f80fd5b6110c986611054565b94506110d760208701611054565b93506040860135925060608601356001600160401b038111156110f8575f80fd5b6111048882890161106f565b969995985093965092949392505050565b5f805f60408486031215611127575f80fd5b8335925060208401356001600160401b03811115611143575f80fd5b61114f8682870161106f565b9497909650939450505050565b5f8083601f84011261116c575f80fd5b5081356001600160401b03811115611182575f80fd5b6020830191508360208260051b8501011115610c68575f80fd5b5f805f805f805f8060a0898b0312156111b3575f80fd5b6111bc89611054565b97506111ca60208a01611054565b965060408901356001600160401b03808211156111e5575f80fd5b6111f18c838d0161115c565b909850965060608b0135915080821115611209575f80fd5b6112158c838d0161115c565b909650945060808b013591508082111561122d575f80fd5b5061123a8b828c0161106f565b999c989b5096995094979396929594505050565b5f805f805f8060608789031215611263575f80fd5b86356001600160401b0380821115611279575f80fd5b6112858a838b0161115c565b9098509650602089013591508082111561129d575f80fd5b6112a98a838b0161115c565b909650945060408901359150808211156112c1575f80fd5b818901915089601f8301126112d4575f80fd5b8135818111156112e2575f80fd5b8a60208260061b85010111156112f6575f80fd5b6020830194508093505050509295509295509295565b5f5b8381101561132657818101518382015260200161130e565b50505f910152565b5f815180845261134581602086016020860161130c565b601f01601f19169290920160200192915050565b5f815180845260208085019450602084015f5b838110156113915781516001600160a01b03168752958201959082019060010161136c565b509495945050505050565b5f815180845260208085019450602084015f5b83811015611391578151875295820195908201906001016113af565b602081526113de60208201835115159052565b602082015160408201525f604083015161014080606085015261140561016085018361132e565b9150606085015160808501526080850151601f19808685030160a087015261142d8483611359565b935060a08701519150808685030160c087015261144a8483611359565b935060c08701519150808685030160e0870152611467848361139c565b935060e08701519150610100818786030181880152611486858461139c565b908801516101208881019190915288015187820390920184880152935090506114af838261139c565b9695505050505050565b5f805f805f8060a087890312156114ce575f80fd5b6114d787611054565b95506114e560208801611054565b9450604087013593506060870135925060808701356001600160401b0381111561150d575f80fd5b61151989828a0161106f565b979a9699509497509295939492505050565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561083e5761083e61152b565b808202811582820484141761083e5761083e61152b565b634e487b7160e01b5f52604160045260245ffd5b8181038181111561083e5761083e61152b565b60ff818116838216019081111561083e5761083e61152b565b634e487b7160e01b5f52603260045260245ffd5b5f602082840312156115cd575f80fd5b61017a82611054565b5f600182016115e7576115e761152b565b5060010190565b5f8235605e19833603018112611602575f80fd5b9190910192915050565b5f600160ff1b82016116205761162061152b565b505f0390565b5f825161160281846020870161130c565b5f60208284031215611647575f80fd5b5051919050565b5f808335601e19843603018112611663575f80fd5b8301803591506001600160401b0382111561167c575f80fd5b602001915036819003821315610c68575f80fd5b818382375f910190815291905056fea2646970667358221220c9adb57984fec989769acf8df499b49fd3aadd781fd0b128ec026480393cb0a764736f6c63430008180033" as const satisfies Hex;
|
|
5
|
+
"0x60806040526004361061004c575f3560e01c8063150b7a02146100575780631626ba7e146100a05780639b093492146100bf578063bc197c81146100eb578063f23a6e6114610119575f80fd5b3661005357005b5f80fd5b348015610062575f80fd5b50610082610071366004611316565b630a85bd0160e11b95945050505050565b6040516001600160e01b031990911681526020015b60405180910390f35b3480156100ab575f80fd5b506100826100ba36600461137f565b610145565b3480156100ca575f80fd5b506100de6100d9366004611446565b610181565b60405161009791906115f0565b3480156100f6575f80fd5b5061008261010536600461171e565b63bc197c8160e01b98975050505050505050565b348015610124575f80fd5b506100826101333660046117bc565b63f23a6e6160e01b9695505050505050565b5f306101528585856103b6565b6001600160a01b03161461016e576001600160e01b0319610177565b630b135d3f60e11b5b90505b9392505050565b6101e36040518061018001604052805f151581526020015f8152602001606081526020015f8152602001606081526020016060815260200160608152602001606081526020015f81526020016060815260200160608152602001606081525090565b475f6101ef898961050c565b90505f6101fd8b6001611842565b90506102098186611855565b6001600160401b038111156102205761022061186c565b604051908082528060200260200182016040528015610249578160200160208202803683370190505b50610140850152846001600160401b038111156102685761026861186c565b604051908082528060200260200182016040528015610291578160200160208202803683370190505b506101608501526102a28188611855565b6001600160401b038111156102b9576102b961186c565b6040519080825280602002602001820160405280156102e2578160200160208202803683370190505b5061012085019081526040805160c081018252848201518152602080860151908201529151908201526101408501516060820152610160850151608082015260a081018290525f61033a8e8e8e8e8e8e8e8e8a61078b565b60408a019190915260208901919091529015158752905061035b47866108dc565b86606001818152505061037684606001518560800151610953565b608087015280851015610389575f610393565b6103938186611880565b6101008701526103a58c8c86896109ef565b505050505098975050505050505050565b5f6041829003610471578235602084013560408501355f1a601b8110156103e5576103e2601b82611893565b90505b8060ff16601b141580156103fd57508060ff16601c14155b1561040d575f935050505061017a565b604080515f81526020810180835289905260ff831691810191909152606081018490526080810183905260019060a0016020604051602081039080840390855afa15801561045d573d5f803e3d5ffd5b50505060206040510351935050505061017a565b604082900361050357823560208401356001600160ff1b0381165f61049b60ff84901c601b611842565b604080515f8152602081018083528b905260ff831691810191909152606081018690526080810184905290915060019060a0016020604051602081039080840390855afa1580156104ee573d5f803e3d5ffd5b5050506020604051035194505050505061017a565b505f9392505050565b61053d6040518060a00160405280606081526020016060815260200160608152602001606081526020015f81525090565b816001600160401b038111156105555761055561186c565b60405190808252806020026020018201604052801561057e578160200160208202803683370190505b508152816001600160401b038111156105995761059961186c565b6040519080825280602002602001820160405280156105c2578160200160208202803683370190505b506020820152816001600160401b038111156105e0576105e061186c565b604051908082528060200260200182016040528015610609578160200160208202803683370190505b506040820152816001600160401b038111156106275761062761186c565b604051908082528060200260200182016040528015610650578160200160208202803683370190505b5060608201525f5b82811015610784575f80610692868685818110610677576106776118ac565b905060200201602081019061068c91906118c0565b30610ca6565b91509150811561077a576001846040015184815181106106b4576106b46118ac565b60200260200101901515908115158152505080845f015184815181106106dc576106dc6118ac565b60200260200101818152505080846020015184815181106106ff576106ff6118ac565b60200260200101818152505085858481811061071d5761071d6118ac565b905060200201602081019061073291906118c0565b606085015160808601805190610747826118d9565b905281518110610759576107596118ac565b60200260200101906001600160a01b031690816001600160a01b0316815250505b5050600101610658565b5092915050565b60015f1960604787156107ad576107ad89898760a001515f8960400151610d7e565b85156107cd576107cd87878760a001515f89606001518a60800151610e39565b5f5b8c8110156108cb576108038e8e838181106107ec576107ec6118ac565b90506020028101906107fe91906118f1565b610f0c565b90955092508461084f57925082881561082d5761082d8a8a90508760a00151838960400151610fa5565b861561084a5761084a888890508760a00151838960600151610fa5565b6108cb565b478281101561085c578092505b61086f8d8d895f01518a60200151611044565b8915610896576108968b8b8960a0015185600161088c9190611842565b8b60400151610d7e565b87156108c2576108c289898960a001518560016108b39190611842565b8b606001518c60800151610e39565b506001016107cf565b509950995099509995505050505050565b5f818310610917575f6108ef8385611880565b90506001600160ff1b03811115610910576001600160ff1b0391505061094d565b905061094d565b5f6109228484611880565b90506001600160ff1b0381111561094057600160ff1b91505061094d565b6109498161190f565b9150505b92915050565b6060816001600160401b0381111561096d5761096d61186c565b604051908082528060200260200182016040528015610996578160200160208202803683370190505b5090505f5b82811015610784578381815181106109b5576109b56118ac565b60200260200101518282815181106109cf576109cf6118ac565b6001600160a01b039092166020928302919091019091015260010161099b565b826001600160401b03811115610a0757610a0761186c565b604051908082528060200260200182016040528015610a30578160200160208202803683370190505b5060e08201525f836001600160401b03811115610a4f57610a4f61186c565b604051908082528060200260200182016040528015610a78578160200160208202803683370190505b5090505f846001600160401b03811115610a9457610a9461186c565b604051908082528060200260200182016040528015610abd578160200160208202803683370190505b5090505f805b86811015610c7b5785604001518181518110610ae157610ae16118ac565b602002602001015115610c735785602001518181518110610b0457610b046118ac565b6020026020010151865f01518281518110610b2157610b216118ac565b602002602001015110610b965785602001518181518110610b4457610b446118ac565b6020026020010151865f01518281518110610b6157610b616118ac565b6020026020010151610b739190611880565b8560e001518281518110610b8957610b896118ac565b6020026020010181815250505b5f80610bad8a8a85818110610677576106776118ac565b9150915081610bbd575050610c73565b5f610be4828a5f01518681518110610bd757610bd76118ac565b60200260200101516108dc565b90508015610c6f578a8a85818110610bfe57610bfe6118ac565b9050602002016020810190610c1391906118c0565b878681518110610c2557610c256118ac565b60200260200101906001600160a01b031690816001600160a01b03168152505080868681518110610c5857610c586118ac565b6020908102919091010152610c6c856118d9565b94505b5050505b600101610ac3565b50610c868382610953565b60a0850152610c9582826110dd565b8460c0018190525050505050505050565b604080516001600160a01b0383811660248084019190915283518084039091018152604490920183526020820180516001600160e01b03166370a0823160e01b17905291515f92839283928392881691610cff91611929565b5f60405180830381855afa9150503d805f8114610d37576040519150601f19603f3d011682016040523d82523d5f602084013e610d3c565b606091505b5091509150811580610d4f575060208151105b15610d5b575050610d77565b81935080806020019051810190610d72919061193a565b925050505b9250929050565b5f5b84811015610e31575f80610de5888885818110610d9f57610d9f6118ac565b610db592602060409092020190810191506118c0565b308a8a87818110610dc857610dc86118ac565b9050604002016020016020810190610de091906118c0565b61116c565b9150915081610df4575f610df6565b805b8486610e028987611855565b610e0c9190611842565b81518110610e1c57610e1c6118ac565b60209081029190910101525050600101610d80565b505050505050565b5f5b85811015610f03575f80610e65898985818110610e5a57610e5a6118ac565b90506040020161124d565b9150915081610e74575f610e76565b805b8587610e828a87611855565b610e8c9190611842565b81518110610e9c57610e9c6118ac565b60209081029190910101528515610ed557838381518110610ebf57610ebf6118ac565b60200260200101518015610ed05750815b610ed7565b815b848481518110610ee957610ee96118ac565b911515602092830291909101909101525050600101610e3b565b50505050505050565b5f6060610f1c60208401846118c0565b6001600160a01b03166020840135610f376040860186611951565b604051610f45929190611993565b5f6040518083038185875af1925050503d805f8114610f7f576040519150601f19603f3d011682016040523d82523d5f602084013e610f84565b606091505b5090925090508115610fa0575060408051602081019091525f81525b915091565b5f5b8481101561103d575f8284610fbc8785611855565b610fc69190611842565b81518110610fd657610fd66118ac565b602002602001015190505f846001610fee9190611842565b90505b85811015611033578184826110068987611855565b6110109190611842565b81518110611020576110206118ac565b6020908102919091010152600101610ff1565b5050600101610fa7565b5050505050565b5f5b8381101561103d57828181518110611060576110606118ac565b6020026020010151156110d5575f80611084878785818110610677576106776118ac565b915091508180156110ad57508383815181106110a2576110a26118ac565b602002602001015181105b156110d257808484815181106110c5576110c56118ac565b6020026020010181815250505b50505b600101611046565b6060816001600160401b038111156110f7576110f761186c565b604051908082528060200260200182016040528015611120578160200160208202803683370190505b5090505f5b828110156107845783818151811061113f5761113f6118ac565b6020026020010151828281518110611159576111596118ac565b6020908102919091010152600101611125565b604080516001600160a01b03848116602483015283811660448084019190915283518084039091018152606490920183526020820180516001600160e01b0316636eb1769f60e11b17905291515f928392839283928916916111cd91611929565b5f60405180830381855afa9150503d805f8114611205576040519150601f19603f3d011682016040523d82523d5f602084013e61120a565b606091505b509150915081158061121d575060208151105b15611229575050611245565b81935080806020019051810190611240919061193a565b925050505b935093915050565b5f808061125d60208501856118c0565b6001600160a01b031603611290576001915061127f60408401602085016118c0565b6001600160a01b0316319050915091565b6112b56112a060208501856118c0565b6112b060408601602087016118c0565b610ca6565b91509150915091565b80356001600160a01b03811681146112d4575f80fd5b919050565b5f8083601f8401126112e9575f80fd5b5081356001600160401b038111156112ff575f80fd5b602083019150836020828501011115610d77575f80fd5b5f805f805f6080868803121561132a575f80fd5b611333866112be565b9450611341602087016112be565b93506040860135925060608601356001600160401b03811115611362575f80fd5b61136e888289016112d9565b969995985093965092949392505050565b5f805f60408486031215611391575f80fd5b8335925060208401356001600160401b038111156113ad575f80fd5b6113b9868287016112d9565b9497909650939450505050565b5f8083601f8401126113d6575f80fd5b5081356001600160401b038111156113ec575f80fd5b6020830191508360208260051b8501011115610d77575f80fd5b5f8083601f840112611416575f80fd5b5081356001600160401b0381111561142c575f80fd5b6020830191508360208260061b8501011115610d77575f80fd5b5f805f805f805f806080898b03121561145d575f80fd5b88356001600160401b0380821115611473575f80fd5b61147f8c838d016113c6565b909a50985060208b0135915080821115611497575f80fd5b6114a38c838d016113c6565b909850965060408b01359150808211156114bb575f80fd5b6114c78c838d01611406565b909650945060608b01359150808211156114df575f80fd5b506114ec8b828c01611406565b999c989b5096995094979396929594505050565b5f5b8381101561151a578181015183820152602001611502565b50505f910152565b5f8151808452611539816020860160208601611500565b601f01601f19169290920160200192915050565b5f815180845260208085019450602084015f5b838110156115855781516001600160a01b031687529582019590820190600101611560565b509495945050505050565b5f815180845260208085019450602084015f5b83811015611585578151875295820195908201906001016115a3565b5f815180845260208085019450602084015f5b838110156115855781511515875295820195908201906001016115d2565b6020815261160360208201835115159052565b602082015160408201525f604083015161018080606085015261162a6101a0850183611522565b9150606085015160808501526080850151601f19808685030160a0870152611652848361154d565b935060a08701519150808685030160c087015261166f848361154d565b935060c08701519150808685030160e087015261168c8483611590565b935060e087015191506101008187860301818801526116ab8584611590565b9450808801519250506101208281880152808801519250506101408187860301818801526116d98584611590565b9450808801519250506101608187860301818801526116f88584611590565b90880151878203909201848801529350905061171483826115bf565b9695505050505050565b5f805f805f805f8060a0898b031215611735575f80fd5b61173e896112be565b975061174c60208a016112be565b965060408901356001600160401b0380821115611767575f80fd5b6117738c838d016113c6565b909850965060608b013591508082111561178b575f80fd5b6117978c838d016113c6565b909650945060808b01359150808211156117af575f80fd5b506114ec8b828c016112d9565b5f805f805f8060a087890312156117d1575f80fd5b6117da876112be565b95506117e8602088016112be565b9450604087013593506060870135925060808701356001600160401b03811115611810575f80fd5b61181c89828a016112d9565b979a9699509497509295939492505050565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561094d5761094d61182e565b808202811582820484141761094d5761094d61182e565b634e487b7160e01b5f52604160045260245ffd5b8181038181111561094d5761094d61182e565b60ff818116838216019081111561094d5761094d61182e565b634e487b7160e01b5f52603260045260245ffd5b5f602082840312156118d0575f80fd5b61017a826112be565b5f600182016118ea576118ea61182e565b5060010190565b5f8235605e19833603018112611905575f80fd5b9190910192915050565b5f600160ff1b82016119235761192361182e565b505f0390565b5f8251611905818460208701611500565b5f6020828403121561194a575f80fd5b5051919050565b5f808335601e19843603018112611966575f80fd5b8301803591506001600160401b0382111561197f575f80fd5b602001915036819003821315610d77575f80fd5b818382375f910190815291905056fea26469706673582212204c77b0c567d34ad97024dab0976d2c9adabfbedde5c906937beb807267751de464736f6c63430008180033" as const satisfies Hex;
|
package/src/index.ts
CHANGED
|
@@ -8,10 +8,12 @@ export {
|
|
|
8
8
|
} from "./errors.js";
|
|
9
9
|
export type {
|
|
10
10
|
AllowanceSlot,
|
|
11
|
+
BalanceDelta,
|
|
12
|
+
BalanceQuery,
|
|
11
13
|
PreparedAllowanceOverrides,
|
|
12
14
|
AllowanceSlotPair,
|
|
13
|
-
AssetBalanceDelta,
|
|
14
15
|
PreparedBalanceOverrides,
|
|
16
|
+
ForUserBalanceQueriesArgs,
|
|
15
17
|
PrepareAllowanceOverridesArgs,
|
|
16
18
|
PrepareBalanceOverridesArgs,
|
|
17
19
|
EstimatedAssetRequirements,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
|
|
3
|
+
import type { BalanceQuery, ForUserBalanceQueriesArgs, SimulatedCall } from "../types.js";
|
|
4
|
+
import type { ClientArgs } from "./rpc.js";
|
|
5
|
+
import { blockOptionsSpread } from "./rpc.js";
|
|
6
|
+
import { discoverCandidateAddresses, runSimulator } from "./simulator.js";
|
|
7
|
+
|
|
8
|
+
/** @internal Implements {@link TxSimulator.balanceQueries.forUser}. Prefer the instance API from the package root. */
|
|
9
|
+
export async function forUserBalanceQueries(
|
|
10
|
+
args: ForUserBalanceQueriesArgs & ClientArgs,
|
|
11
|
+
): Promise<BalanceQuery[]> {
|
|
12
|
+
const tokens = await discoverErc20s(args);
|
|
13
|
+
|
|
14
|
+
return [
|
|
15
|
+
{ asset: "native", account: args.from },
|
|
16
|
+
...tokens.map((asset) => ({ asset, account: args.from })),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @internal Implements {@link TxSimulator.balanceQueries.discoverErc20s}. Prefer the instance API from the package root. */
|
|
21
|
+
export async function discoverErc20s(
|
|
22
|
+
args: ForUserBalanceQueriesArgs & ClientArgs,
|
|
23
|
+
): Promise<Address[]> {
|
|
24
|
+
const calls = args.calls.map((call) => ({
|
|
25
|
+
to: call.to,
|
|
26
|
+
data: call.data,
|
|
27
|
+
value: call.value ?? 0n,
|
|
28
|
+
})) satisfies SimulatedCall[];
|
|
29
|
+
const candidates = await discoverCandidateAddresses({
|
|
30
|
+
client: args.client,
|
|
31
|
+
from: args.from,
|
|
32
|
+
calls,
|
|
33
|
+
gas: args.gas,
|
|
34
|
+
debug: args.debug,
|
|
35
|
+
...blockOptionsSpread(args),
|
|
36
|
+
});
|
|
37
|
+
const result = await runSimulator({
|
|
38
|
+
client: args.client,
|
|
39
|
+
from: args.from,
|
|
40
|
+
calls: [],
|
|
41
|
+
candidates,
|
|
42
|
+
debug: args.debug,
|
|
43
|
+
debugStep: "balanceQueries.tokenFilter",
|
|
44
|
+
gas: args.gas,
|
|
45
|
+
...blockOptionsSpread(args),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return result.probeData.observedTokens;
|
|
49
|
+
}
|
|
@@ -24,7 +24,7 @@ type AllowanceProbe = {
|
|
|
24
24
|
spender: Address;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
/** @internal Implements {@link TxSimulator.
|
|
27
|
+
/** @internal Implements {@link TxSimulator.tokenOverrides.estimateRequirements}. Prefer the instance API from the package root. */
|
|
28
28
|
export async function estimateAssetRequirements(
|
|
29
29
|
args: EstimateAssetRequirementsArgs & ClientArgs,
|
|
30
30
|
): Promise<EstimatedAssetRequirements> {
|
|
@@ -138,6 +138,8 @@ export async function estimateAssetRequirements(
|
|
|
138
138
|
return { status: "success", ...shared };
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
export const estimateTokenOverrideRequirements = estimateAssetRequirements;
|
|
142
|
+
|
|
141
143
|
function allowancePairs(
|
|
142
144
|
tokens: readonly Address[],
|
|
143
145
|
spenders: readonly Address[],
|
|
@@ -6,14 +6,10 @@ import {
|
|
|
6
6
|
parseAbi,
|
|
7
7
|
slice,
|
|
8
8
|
size,
|
|
9
|
+
zeroAddress,
|
|
9
10
|
} from "viem";
|
|
10
11
|
|
|
11
|
-
import type {
|
|
12
|
-
AssetBalanceDelta,
|
|
13
|
-
SimulatedCall,
|
|
14
|
-
SimulationResult,
|
|
15
|
-
TokenSlotOverride,
|
|
16
|
-
} from "../types.js";
|
|
12
|
+
import type { RevertError, SimulatedCall, TokenSlotOverride } from "../types.js";
|
|
17
13
|
import { InvalidSimulationInputError, StateOverrideUnsupportedError } from "../errors.js";
|
|
18
14
|
import { txSimulatorRuntimeBytecode } from "../generated/txSimulatorBytecode.js";
|
|
19
15
|
import {
|
|
@@ -39,17 +35,31 @@ type ProbeData = {
|
|
|
39
35
|
maxTokenOutflows: readonly bigint[];
|
|
40
36
|
maxNativeOutflow: bigint;
|
|
41
37
|
allowanceCheckpoints: readonly bigint[];
|
|
38
|
+
balanceCheckpoints: readonly bigint[];
|
|
39
|
+
balanceProbeOk: readonly boolean[];
|
|
42
40
|
};
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
type SimulatorBase = {
|
|
45
43
|
probeData: ProbeData;
|
|
46
44
|
};
|
|
47
45
|
|
|
46
|
+
export type SimulatorResult =
|
|
47
|
+
| (SimulatorBase & { status: "success" })
|
|
48
|
+
| (SimulatorBase & {
|
|
49
|
+
status: "reverted";
|
|
50
|
+
revertData: Hex;
|
|
51
|
+
revertReason?: string;
|
|
52
|
+
revertError?: RevertError;
|
|
53
|
+
revertSelector?: Hex;
|
|
54
|
+
failingCallIndex: number;
|
|
55
|
+
});
|
|
56
|
+
|
|
48
57
|
const txSimulatorAbi = parseAbi([
|
|
49
58
|
"struct SimulatedCall { address to; uint256 value; bytes data; }",
|
|
50
59
|
"struct AllowanceProbe { address token; address spender; }",
|
|
51
|
-
"struct
|
|
52
|
-
"
|
|
60
|
+
"struct BalanceProbe { address token; address account; }",
|
|
61
|
+
"struct SimulationResult { bool success; uint256 failingCallIndex; bytes revertData; int256 nativeDelta; address[] observedTokens; address[] deltaTokens; int256[] tokenDeltas; uint256[] maxTokenOutflows; uint256 maxNativeOutflow; uint256[] allowanceCheckpoints; uint256[] balanceCheckpoints; bool[] balanceProbeOk; }",
|
|
62
|
+
"function simulate(SimulatedCall[] calls, address[] candidates, AllowanceProbe[] probes, BalanceProbe[] balanceProbes) returns (SimulationResult)",
|
|
53
63
|
"function isValidSignature(bytes32 hash, bytes signature) view returns (bytes4)",
|
|
54
64
|
]);
|
|
55
65
|
|
|
@@ -61,11 +71,16 @@ export async function runSimulator(
|
|
|
61
71
|
tokenSlotOverrides?: readonly TokenSlotOverride[];
|
|
62
72
|
extraStateOverrides?: readonly StateOverrideEntry[];
|
|
63
73
|
allowanceProbes?: readonly { token: Address; spender: Address }[];
|
|
74
|
+
balanceProbes?: readonly { token: Address | "native"; account: Address }[];
|
|
64
75
|
debugStep?: string;
|
|
65
76
|
errorAbi?: Abi;
|
|
66
77
|
},
|
|
67
78
|
): Promise<SimulatorResult> {
|
|
68
79
|
const candidates = uniqueAddresses(args.candidates);
|
|
80
|
+
const balanceProbes = (args.balanceProbes ?? []).map((probe) => ({
|
|
81
|
+
token: probe.token === "native" ? zeroAddress : probe.token,
|
|
82
|
+
account: probe.account,
|
|
83
|
+
}));
|
|
69
84
|
const data = encodeFunctionData({
|
|
70
85
|
abi: txSimulatorAbi,
|
|
71
86
|
functionName: "simulate",
|
|
@@ -77,6 +92,7 @@ export async function runSimulator(
|
|
|
77
92
|
})),
|
|
78
93
|
candidates,
|
|
79
94
|
args.allowanceProbes ?? [],
|
|
95
|
+
balanceProbes,
|
|
80
96
|
],
|
|
81
97
|
});
|
|
82
98
|
|
|
@@ -97,6 +113,7 @@ export async function runSimulator(
|
|
|
97
113
|
from: args.from,
|
|
98
114
|
calls: args.calls.length,
|
|
99
115
|
candidates: candidates.length,
|
|
116
|
+
balanceProbes: balanceProbes.length,
|
|
100
117
|
storageOverrides: args.tokenSlotOverrides?.length ?? 0,
|
|
101
118
|
stateOverrideAccounts: stateOverride.length,
|
|
102
119
|
},
|
|
@@ -133,32 +150,20 @@ export async function runSimulator(
|
|
|
133
150
|
);
|
|
134
151
|
}
|
|
135
152
|
|
|
136
|
-
const assetBalanceDeltas: AssetBalanceDelta[] = [];
|
|
137
|
-
if (result.nativeDelta !== 0n) {
|
|
138
|
-
assetBalanceDeltas.push({ asset: "native", delta: result.nativeDelta });
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
for (let i = 0; i < result.deltaTokens.length; ++i) {
|
|
142
|
-
const token = result.deltaTokens[i];
|
|
143
|
-
const delta = result.tokenDeltas[i];
|
|
144
|
-
if (token && delta !== undefined && delta !== 0n) {
|
|
145
|
-
assetBalanceDeltas.push({ asset: token, delta });
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
153
|
const probeData = {
|
|
150
154
|
observedTokens: uniqueAddresses(result.observedTokens),
|
|
151
155
|
candidates,
|
|
152
156
|
maxTokenOutflows: result.maxTokenOutflows,
|
|
153
157
|
maxNativeOutflow: result.maxNativeOutflow,
|
|
154
158
|
allowanceCheckpoints: result.allowanceCheckpoints,
|
|
159
|
+
balanceCheckpoints: result.balanceCheckpoints,
|
|
160
|
+
balanceProbeOk: result.balanceProbeOk,
|
|
155
161
|
};
|
|
156
162
|
|
|
157
163
|
if (!result.success) {
|
|
158
164
|
const decodedRevert = decodeRevert(result.revertData, args.errorAbi);
|
|
159
165
|
return {
|
|
160
166
|
status: "reverted",
|
|
161
|
-
assetBalanceDeltas,
|
|
162
167
|
revertData: result.revertData,
|
|
163
168
|
...(decodedRevert.revertReason !== undefined
|
|
164
169
|
? { revertReason: decodedRevert.revertReason }
|
|
@@ -176,7 +181,6 @@ export async function runSimulator(
|
|
|
176
181
|
|
|
177
182
|
return {
|
|
178
183
|
status: "success",
|
|
179
|
-
assetBalanceDeltas,
|
|
180
184
|
probeData,
|
|
181
185
|
};
|
|
182
186
|
}
|
package/src/internal/slots.ts
CHANGED
|
@@ -24,7 +24,7 @@ type AllowanceSlotFact = SlotFact & {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// Orchestration
|
|
27
|
-
/** @internal Implements `TxSimulator.
|
|
27
|
+
/** @internal Implements `TxSimulator.tokenOverrides.forBalances`. Prefer the instance API from the package root. */
|
|
28
28
|
export async function prepareBalanceOverrides(
|
|
29
29
|
args: PrepareBalanceOverridesArgs & ClientArgs,
|
|
30
30
|
): Promise<PreparedBalanceOverrides> {
|
|
@@ -47,7 +47,7 @@ export async function prepareBalanceOverrides(
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/** @internal Implements `TxSimulator.
|
|
50
|
+
/** @internal Implements `TxSimulator.tokenOverrides.forAllowances`. Prefer the instance API from the package root. */
|
|
51
51
|
export async function prepareAllowanceOverrides(
|
|
52
52
|
args: PrepareAllowanceOverridesArgs & ClientArgs,
|
|
53
53
|
): Promise<PreparedAllowanceOverrides> {
|
|
@@ -194,6 +194,9 @@ function mappingSlot(key: Address, baseSlot: Hex | bigint): Hex {
|
|
|
194
194
|
);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
export const prepareBalanceTokenOverrides = prepareBalanceOverrides;
|
|
198
|
+
export const prepareAllowanceTokenOverrides = prepareAllowanceOverrides;
|
|
199
|
+
|
|
197
200
|
function allowanceSlotFor(owner: Address, spender: Address, base: bigint): Hex {
|
|
198
201
|
return mappingSlot(spender, mappingSlot(owner, base));
|
|
199
202
|
}
|