You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/abicalldata/README.md
+33-2Lines changed: 33 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# ABI calldata
2
2
3
-
Helpers for **Ethereum ABI-encoded calldata**: head layout, static argument words, and dynamic `bytes`/`string` tails. Also defines **`ByteRange`**and **`Selector`** for locating byte spans inside a v3 **`CallsPayload`**.
3
+
Helpers for **Ethereum ABI-encoded calldata**: head layout, static argument words, and dynamic `bytes`/`string` tails. Also defines **`ByteRange`**, **`Selector`**, and a fluent **`Path`** for locating byte spans inside a v3 **`CallsPayload`**.
4
4
5
5
## Calldata layout
6
6
@@ -33,4 +33,35 @@ sel := abicalldata.NewRangeSelector(0, 0x24, 32)
33
33
ranges, err:= sel.Resolve(payload)
34
34
```
35
35
36
-
**`Selector`** is implemented by types in other packages that walk `CallsPayload` and nested calldata; they typically use the functions above to turn `abi.Method` + argument index into `ByteRange` updates. **`NewRangeSelector`** is the built-in implementation for a fixed call index, offset, and length.
36
+
## Path builder (`NewPath`)
37
+
38
+
**`*Path`** is a **`Selector`**: chain steps to walk from a top-level call into nested packed calls and ABI argument slots, then call **`.AsSelector()`** for APIs that take a **`Selector`**.
39
+
40
+
Typical steps:
41
+
42
+
-**`.CallData(i)`** — start from `payload.Calls[i].Data`.
43
+
-**`.ABI(contractABI, method)`** — bind the current range to that method (checks the 4-byte selector).
44
+
-**`.ArgSlot(name)`** / **`.ArgSlotIndex(i)`** — static argument word(s) in the current frame.
45
+
-**`.ArgBytesData(name)`** / **`.ArgBytesDataIndex(i)`** — inner payload of a `bytes`/`string` argument (clears ABI context; rebind with `.ABI` before further arg steps).
46
+
-**`.ArgBytesEncoded(name)`** — full ABI-encoded tail for that dynamic argument.
47
+
-**`.EncodedCallsPayload()`** — treat the active range as v3 packed calls; clear ABI context.
48
+
-**`.EncodedCallData(j)`** — select packed call `j`’s calldata within that layout.
49
+
-**`.Slice(offset, size)`** — byte slice within the active range.
50
+
51
+
```go
52
+
sel:= abicalldata.NewPath().
53
+
CallData(0).
54
+
ABI(&outerABI, "hydrateExecute").
55
+
ArgBytesData("payload").
56
+
EncodedCallsPayload().
57
+
EncodedCallData(0).
58
+
ABI(&tokenABI, "permit").
59
+
ArgSlot("value").
60
+
AsSelector()
61
+
```
62
+
63
+
After any step that narrows the range or switches to a new byte frame (including **`.Slice`**, **`.ArgBytesData`**, **`.ArgBytesDataIndex`**, **`.ArgBytesEncoded`**, **`.EncodedCallsPayload`**, **`.EncodedCallData`**), ABI context is cleared. Call **`.ABI(...)`** again before **`.ArgSlot`**, **`.ArgSlotIndex`**, **`.ArgBytesData`**, **`.ArgBytesDataIndex`**, or **`.ArgBytesEncoded`** on the new frame.
64
+
65
+
## Packed calls layout
66
+
67
+
**`ParsePackedCalls(packed []byte)`** returns a **`PackedCallsLayout`** describing where each call’s calldata sits inside the encoded packed-calls blob (as produced by `CallsPayload.Encode`). **`CallData`** entries use **`Span`** (`Start`, `Len`; `Start == -1` when that call has no calldata). The path step **`.EncodedCallData(i)`** uses this parser internally.
Copy file name to clipboardExpand all lines: lib/hydrate/README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,15 @@
2
2
3
3
Build `hydratePayload` bytes for **HydrateProxy** (`hydrateExecute` / `hydrateExecuteAndSweep` in trails-contracts) by resolving patch targets with [`abicalldata`](https://github.com/0xsequence/go-sequence/tree/master/lib/abicalldata)**`Selector`** and **`ByteRange`** instead of hand-counting calldata offsets.
4
4
5
-
`hydrate`depends only on `abicalldata` for selector types. The example below builds an `abicalldata.Selector` using `Path` from `lib/sapient/malleable`; fixed offsets can use `abicalldata.NewRangeSelector` instead.
5
+
This package depends on **`abicalldata`** for selector types and for building selectors with **`abicalldata.NewPath()`** (or **`abicalldata.NewRangeSelector`** for fixed offsets).
6
6
7
7
## Usage
8
8
9
9
```go
10
10
payload:= v3.NewCallsPayload(...)
11
11
12
12
// Selector must resolve to exactly one range on the target call (same index as ForCall).
If ABI parameters are unnamed, use index-based steps such as `ArgSlotIndex` / `ArgBytesDataIndex` when your path builder provides them.
50
+
If ABI parameters are unnamed, use index-based steps such as **`ArgSlotIndex`** / **`ArgBytesDataIndex`** on **`abicalldata.NewPath()`** (see the abicalldata README).
0 commit comments