ox 0.9.7 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ import type * as Hex from '../core/Hex.js';
2
+ import * as Calls from './Calls.js';
3
+ export type Batch = {
4
+ calls: readonly Call[];
5
+ opData?: Hex.Hex | undefined;
6
+ };
7
+ export type Call = Calls.Call;
8
+ export declare const abiFunction: {
9
+ type: "function";
10
+ name: string;
11
+ inputs: ({
12
+ name: string;
13
+ type: "bytes32";
14
+ internalType: string;
15
+ } | {
16
+ name: string;
17
+ type: "bytes";
18
+ internalType: string;
19
+ })[];
20
+ outputs: never[];
21
+ stateMutability: "payable";
22
+ };
23
+ export declare const mode: {
24
+ readonly default: "0x0100000000000000000000000000000000000000000000000000000000000000";
25
+ readonly opData: "0x0100000000007821000100000000000000000000000000000000000000000000";
26
+ readonly batchOfBatches: "0x0100000000007821000200000000000000000000000000000000000000000000";
27
+ };
28
+ /**
29
+ * Decodes calls from ERC-7821 `execute` function data.
30
+ *
31
+ * @example
32
+ * ```ts twoslash
33
+ * import { Execute } from 'ox/erc7821'
34
+ *
35
+ * const { calls } = Execute.decodeData('0x...')
36
+ * ```
37
+ *
38
+ * @param data - The encoded data.
39
+ * @returns The decoded calls and optional opData.
40
+ */
41
+ export declare function decodeData(data: Hex.Hex): decodeData.ReturnType;
42
+ export declare namespace decodeData {
43
+ type ReturnType = {
44
+ calls: Call[];
45
+ opData?: Hex.Hex | undefined;
46
+ };
47
+ }
48
+ /**
49
+ * Decodes batches from ERC-7821 `execute` function data in "batch of batches" mode.
50
+ *
51
+ * @example
52
+ * ```ts twoslash
53
+ * import { Execute } from 'ox/erc7821'
54
+ *
55
+ * const batches = Execute.decodeBatchOfBatchesData('0x...')
56
+ * ```
57
+ *
58
+ * @param data - The encoded data.
59
+ * @returns The decoded batches.
60
+ */
61
+ export declare function decodeBatchOfBatchesData(data: Hex.Hex): decodeBatchOfBatchesData.ReturnType;
62
+ export declare namespace decodeBatchOfBatchesData {
63
+ type ReturnType = Batch[];
64
+ }
65
+ /**
66
+ * Encodes calls for the ERC-7821 `execute` function with "batch of batches" mode.
67
+ *
68
+ * @example
69
+ * ```ts twoslash
70
+ * import { Execute } from 'ox/erc7821'
71
+ *
72
+ * const data = Execute.encodeBatchOfBatchesData([
73
+ * {
74
+ * calls: [
75
+ * {
76
+ * data: '0xcafebabe',
77
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
78
+ * value: 1n,
79
+ * }
80
+ * ]
81
+ * },
82
+ * {
83
+ * calls: [
84
+ * {
85
+ * data: '0xdeadbeef',
86
+ * to: '0xcafebabecafebabecafebabecafebabecafebabe',
87
+ * value: 2n,
88
+ * }
89
+ * ],
90
+ * opData: '0xcafebabe',
91
+ * }
92
+ * ])
93
+ * ```
94
+ *
95
+ * @param calls - The calls to encode.
96
+ * @param options - The options.
97
+ * @returns The encoded data.
98
+ */
99
+ export declare function encodeBatchOfBatchesData(batches: readonly Batch[]): `0x${string}`;
100
+ /**
101
+ * Encodes calls for the ERC-7821 `execute` function.
102
+ *
103
+ * @example
104
+ * ```ts twoslash
105
+ * import { Execute } from 'ox/erc7821'
106
+ *
107
+ * const data = Execute.encodeData([
108
+ * {
109
+ * data: '0xcafebabe',
110
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
111
+ * value: 1n,
112
+ * }
113
+ * ])
114
+ * ```
115
+ *
116
+ * @param calls - The calls to encode.
117
+ * @param options - The options.
118
+ * @returns The encoded data.
119
+ */
120
+ export declare function encodeData(calls: readonly Call[], options?: encodeData.Options): `0x${string}`;
121
+ export declare namespace encodeData {
122
+ type Options = {
123
+ opData?: Hex.Hex | undefined;
124
+ };
125
+ }
126
+ //# sourceMappingURL=Execute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Execute.d.ts","sourceRoot":"","sources":["../../erc7821/Execute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAE1C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE,SAAS,IAAI,EAAE,CAAA;IACtB,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,SAAS,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;AAE7B,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CAiBW,CAAA;AAEnC,eAAO,MAAM,IAAI;;;;CAKP,CAAA;AAEV;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,GAAG,UAAU,CAAC,UAAU,CAM/D;AAED,MAAM,CAAC,OAAO,WAAW,UAAU,CAAC;IAClC,KAAK,UAAU,GAAG;QAChB,KAAK,EAAE,IAAI,EAAE,CAAA;QACb,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,SAAS,CAAA;KAC7B,CAAA;CACF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,GAAG,CAAC,GAAG,GACZ,wBAAwB,CAAC,UAAU,CA6BrC;AAED,MAAM,CAAC,OAAO,WAAW,wBAAwB,CAAC;IAChD,KAAK,UAAU,GAAG,KAAK,EAAE,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,iBAUjE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,OAAO,GAAE,UAAU,CAAC,OAAY,iBAMjC;AAED,MAAM,CAAC,OAAO,WAAW,UAAU,CAAC;IAClC,KAAK,OAAO,GAAG;QACb,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,SAAS,CAAA;KAC7B,CAAA;CACF"}
@@ -0,0 +1,71 @@
1
+ /** @entrypointCategory ERCs */
2
+ export type {};
3
+ /**
4
+ * Utility functions for encoding and decoding [ERC-7821](https://eips.ethereum.org/EIPS/eip-7821) calls.
5
+ *
6
+ * @example
7
+ * ### Encoding calls
8
+ *
9
+ * Calls can be encoded using `Calls.encode`.
10
+ *
11
+ * ```ts twoslash
12
+ * import { Calls } from 'ox/erc7821'
13
+ *
14
+ * const calls = Calls.encode([
15
+ * {
16
+ * data: '0xcafebabe',
17
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
18
+ * value: 1n,
19
+ * }
20
+ * ])
21
+ * ```
22
+ *
23
+ * @example
24
+ * ### Decoding calls
25
+ *
26
+ * Calls can be decoded using `Calls.decode`.
27
+ *
28
+ * ```ts twoslash
29
+ * import { Calls } from 'ox/erc7821'
30
+ *
31
+ * const { calls } = Calls.decode('0x...')
32
+ * ```
33
+ *
34
+ * @category ERC-7821
35
+ */
36
+ export * as Calls from './Calls.js';
37
+ /**
38
+ * Utility functions for encoding and decoding [ERC-7821](https://eips.ethereum.org/EIPS/eip-7821) `execute` function data.
39
+ *
40
+ * @example
41
+ * ### Encoding `execute` Function Data
42
+ *
43
+ * The `execute` function data can be encoded using `Execute.encodeData`.
44
+ *
45
+ * ```ts twoslash
46
+ * import { Execute } from 'ox/erc7821'
47
+ *
48
+ * const data = Execute.encodeData([
49
+ * {
50
+ * data: '0xcafebabe',
51
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
52
+ * value: 1n,
53
+ * }
54
+ * ])
55
+ * ```
56
+ *
57
+ * @example
58
+ * ### Decoding `execute` Function Data
59
+ *
60
+ * The `execute` function data can be decoded using `Execute.decodeData`.
61
+ *
62
+ * ```ts twoslash
63
+ * import { Execute } from 'ox/erc7821'
64
+ *
65
+ * const { calls } = Execute.decodeData('0xe9ae5c53...')
66
+ * ```
67
+ *
68
+ * @category ERC-7821
69
+ */
70
+ export * as Execute from './Execute.js';
71
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../erc7821/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,YAAY,EAAE,CAAA;AAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA"}
@@ -2,5 +2,6 @@
2
2
  export * from './index.js';
3
3
  export * from './erc4337/index.js';
4
4
  export * from './erc6492/index.js';
5
+ export * from './erc7821/index.js';
5
6
  export * from './erc8010/index.js';
6
7
  //# sourceMappingURL=index.docs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../index.docs.ts"],"names":[],"mappings":"AACA,2FAA2F;AAE3F,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../index.docs.ts"],"names":[],"mappings":"AACA,2FAA2F;AAE3F,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
@@ -1,3 +1,3 @@
1
1
  /** @internal */
2
- export declare const version = "0.9.7";
2
+ export declare const version = "0.9.8";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc7821/Calls.d.ts",
4
+ "main": "../../_cjs/erc7821/Calls.js",
5
+ "module": "../../_esm/erc7821/Calls.js"
6
+ }
@@ -0,0 +1,148 @@
1
+ import * as AbiParameters from '../core/AbiParameters.js'
2
+ import type * as Address from '../core/Address.js'
3
+ import type * as Hex from '../core/Hex.js'
4
+
5
+ export type Call<bigintType = bigint> = {
6
+ data?: Hex.Hex | undefined
7
+ to: Address.Address
8
+ value?: bigintType | undefined
9
+ }
10
+
11
+ /**
12
+ * Encodes a set of ERC-7821 calls.
13
+ *
14
+ * @example
15
+ * ```ts twoslash
16
+ * import { Calls } from 'ox/erc7821'
17
+ *
18
+ * const calls = Calls.encode([
19
+ * {
20
+ * data: '0xdeadbeef',
21
+ * to: '0xcafebabecafebabecafebabecafebabecafebabe',
22
+ * value: 1n,
23
+ * },
24
+ * {
25
+ * data: '0xcafebabe',
26
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
27
+ * value: 2n,
28
+ * },
29
+ * ])
30
+ * // @log: '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000cafebabecafebabecafebabecafebabecafebabe0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000deadbeef000000000000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeef0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cafebabe'
31
+ * ```
32
+ *
33
+ * @param calls - Calls to encode.
34
+ * @param options - Options for the encoding.
35
+ * @returns The encoded calls.
36
+ */
37
+ export function encode(calls: readonly Call[], options: encode.Options = {}) {
38
+ const { opData } = options
39
+ return AbiParameters.encode(getAbiParameters({ opData: !!opData }), [
40
+ calls.map((call) => ({
41
+ target: call.to,
42
+ value: call.value ?? 0n,
43
+ data: call.data ?? '0x',
44
+ })),
45
+ ...(opData ? [opData] : []),
46
+ ] as any)
47
+ }
48
+
49
+ export declare namespace encode {
50
+ type Options = {
51
+ /** Additional data to include for execution. */
52
+ opData?: Hex.Hex | undefined
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Gets the ABI parameters for the ERC-7821 calls.
58
+ *
59
+ * @example
60
+ * ```ts twoslash
61
+ * import { Calls } from 'ox/erc7821'
62
+ *
63
+ * const abiParameters = Calls.getAbiParameters({ opData: true })
64
+ * ```
65
+ *
66
+ * @param options - Options.
67
+ * @returns The ABI parameters.
68
+ */
69
+ export function getAbiParameters(options: getAbiParameters.Options = {}) {
70
+ const { opData } = options
71
+ return AbiParameters.from([
72
+ 'struct Call { address target; uint256 value; bytes data; }',
73
+ 'Call[] calls',
74
+ ...(opData ? ['bytes opData'] : []),
75
+ ])
76
+ }
77
+
78
+ export declare namespace getAbiParameters {
79
+ type Options = {
80
+ opData?: boolean | undefined
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Decodes a set of ERC-7821 calls from encoded data.
86
+ *
87
+ * @example
88
+ * ```ts twoslash
89
+ * import { Calls } from 'ox/erc7821'
90
+ *
91
+ * const data = Calls.decode('0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000cafebabecafebabecafebabecafebabecafebabe000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000000000000000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeef000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004cafebabe00000000000000000000000000000000000000000000000000000000')
92
+ * // @log: {
93
+ * // @log: calls: [
94
+ * // @log: {
95
+ * // @log: data: '0xdeadbeef',
96
+ * // @log: to: '0xcafebabecafebabecafebabecafebabecafebabe',
97
+ * // @log: value: 1n,
98
+ * // @log: },
99
+ * // @log: {
100
+ * // @log: data: '0xcafebabe',
101
+ * // @log: to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
102
+ * // @log: value: 2n,
103
+ * // @log: },
104
+ * // @log: ]
105
+ * // @log: }
106
+ * ```
107
+ *
108
+ * @param data - The encoded calls data.
109
+ * @param options - Options for decoding.
110
+ * @returns The decoded calls and optional opData.
111
+ */
112
+ export function decode(
113
+ data: Hex.Hex,
114
+ options: decode.Options = {},
115
+ ): decode.ReturnType {
116
+ const { opData: withOpData = false } = options
117
+
118
+ const decoded = AbiParameters.decode(
119
+ getAbiParameters({ opData: withOpData }),
120
+ data,
121
+ ) as readonly unknown[]
122
+ const [encodedCalls, opData] = decoded as readonly [
123
+ { target: Address.Address; value: bigint; data: Hex.Hex }[],
124
+ Hex.Hex?,
125
+ ]
126
+
127
+ const calls = encodedCalls.map((call) => ({
128
+ to: call.target,
129
+ value: call.value,
130
+ data: call.data,
131
+ }))
132
+
133
+ return withOpData
134
+ ? { calls, opData: opData === '0x' ? undefined : opData }
135
+ : { calls }
136
+ }
137
+
138
+ export declare namespace decode {
139
+ type Options = {
140
+ /** Whether to decode opData if present. */
141
+ opData?: boolean | undefined
142
+ }
143
+
144
+ type ReturnType = {
145
+ calls: Call[]
146
+ opData?: Hex.Hex | undefined
147
+ }
148
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc7821/Execute.d.ts",
4
+ "main": "../../_cjs/erc7821/Execute.js",
5
+ "module": "../../_esm/erc7821/Execute.js"
6
+ }
@@ -0,0 +1,197 @@
1
+ import * as AbiFunction from '../core/AbiFunction.js'
2
+ import type * as Hex from '../core/Hex.js'
3
+ import { AbiParameters } from '../index.js'
4
+ import * as Calls from './Calls.js'
5
+
6
+ export type Batch = {
7
+ calls: readonly Call[]
8
+ opData?: Hex.Hex | undefined
9
+ }
10
+
11
+ export type Call = Calls.Call
12
+
13
+ export const abiFunction = {
14
+ type: 'function',
15
+ name: 'execute',
16
+ inputs: [
17
+ {
18
+ name: 'mode',
19
+ type: 'bytes32',
20
+ internalType: 'bytes32',
21
+ },
22
+ {
23
+ name: 'executionData',
24
+ type: 'bytes',
25
+ internalType: 'bytes',
26
+ },
27
+ ],
28
+ outputs: [],
29
+ stateMutability: 'payable',
30
+ } satisfies AbiFunction.AbiFunction
31
+
32
+ export const mode = {
33
+ default: '0x0100000000000000000000000000000000000000000000000000000000000000',
34
+ opData: '0x0100000000007821000100000000000000000000000000000000000000000000',
35
+ batchOfBatches:
36
+ '0x0100000000007821000200000000000000000000000000000000000000000000',
37
+ } as const
38
+
39
+ /**
40
+ * Decodes calls from ERC-7821 `execute` function data.
41
+ *
42
+ * @example
43
+ * ```ts twoslash
44
+ * import { Execute } from 'ox/erc7821'
45
+ *
46
+ * const { calls } = Execute.decodeData('0x...')
47
+ * ```
48
+ *
49
+ * @param data - The encoded data.
50
+ * @returns The decoded calls and optional opData.
51
+ */
52
+ export function decodeData(data: Hex.Hex): decodeData.ReturnType {
53
+ const [m, executionData] = AbiFunction.decodeData(abiFunction, data) as [
54
+ Hex.Hex,
55
+ Hex.Hex,
56
+ ]
57
+ return Calls.decode(executionData, { opData: m !== mode.default })
58
+ }
59
+
60
+ export declare namespace decodeData {
61
+ type ReturnType = {
62
+ calls: Call[]
63
+ opData?: Hex.Hex | undefined
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Decodes batches from ERC-7821 `execute` function data in "batch of batches" mode.
69
+ *
70
+ * @example
71
+ * ```ts twoslash
72
+ * import { Execute } from 'ox/erc7821'
73
+ *
74
+ * const batches = Execute.decodeBatchOfBatchesData('0x...')
75
+ * ```
76
+ *
77
+ * @param data - The encoded data.
78
+ * @returns The decoded batches.
79
+ */
80
+ export function decodeBatchOfBatchesData(
81
+ data: Hex.Hex,
82
+ ): decodeBatchOfBatchesData.ReturnType {
83
+ const [, executionData] = AbiFunction.decodeData(abiFunction, data) as [
84
+ Hex.Hex,
85
+ Hex.Hex,
86
+ ]
87
+
88
+ const [encodedBatches] = AbiParameters.decode(
89
+ AbiParameters.from('bytes[]'),
90
+ executionData,
91
+ ) as readonly [Hex.Hex[]]
92
+
93
+ return encodedBatches.map((encodedBatch) => {
94
+ // Try decoding with opData first
95
+ try {
96
+ const decoded = Calls.decode(encodedBatch, { opData: true })
97
+ if (decoded.opData) {
98
+ return {
99
+ calls: decoded.calls,
100
+ opData: decoded.opData,
101
+ }
102
+ }
103
+ // If opData is undefined, return without it
104
+ return { calls: decoded.calls }
105
+ } catch {
106
+ // If decoding with opData fails, decode without it
107
+ const decoded = Calls.decode(encodedBatch, { opData: false })
108
+ return { calls: decoded.calls }
109
+ }
110
+ })
111
+ }
112
+
113
+ export declare namespace decodeBatchOfBatchesData {
114
+ type ReturnType = Batch[]
115
+ }
116
+
117
+ /**
118
+ * Encodes calls for the ERC-7821 `execute` function with "batch of batches" mode.
119
+ *
120
+ * @example
121
+ * ```ts twoslash
122
+ * import { Execute } from 'ox/erc7821'
123
+ *
124
+ * const data = Execute.encodeBatchOfBatchesData([
125
+ * {
126
+ * calls: [
127
+ * {
128
+ * data: '0xcafebabe',
129
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
130
+ * value: 1n,
131
+ * }
132
+ * ]
133
+ * },
134
+ * {
135
+ * calls: [
136
+ * {
137
+ * data: '0xdeadbeef',
138
+ * to: '0xcafebabecafebabecafebabecafebabecafebabe',
139
+ * value: 2n,
140
+ * }
141
+ * ],
142
+ * opData: '0xcafebabe',
143
+ * }
144
+ * ])
145
+ * ```
146
+ *
147
+ * @param calls - The calls to encode.
148
+ * @param options - The options.
149
+ * @returns The encoded data.
150
+ */
151
+ export function encodeBatchOfBatchesData(batches: readonly Batch[]) {
152
+ const b = AbiParameters.encode(AbiParameters.from('bytes[]'), [
153
+ batches.map((b) => {
154
+ const batch = b as Batch
155
+ return Calls.encode(batch.calls, {
156
+ opData: batch.opData,
157
+ })
158
+ }),
159
+ ])
160
+ return AbiFunction.encodeData(abiFunction, [mode.batchOfBatches, b])
161
+ }
162
+
163
+ /**
164
+ * Encodes calls for the ERC-7821 `execute` function.
165
+ *
166
+ * @example
167
+ * ```ts twoslash
168
+ * import { Execute } from 'ox/erc7821'
169
+ *
170
+ * const data = Execute.encodeData([
171
+ * {
172
+ * data: '0xcafebabe',
173
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
174
+ * value: 1n,
175
+ * }
176
+ * ])
177
+ * ```
178
+ *
179
+ * @param calls - The calls to encode.
180
+ * @param options - The options.
181
+ * @returns The encoded data.
182
+ */
183
+ export function encodeData(
184
+ calls: readonly Call[],
185
+ options: encodeData.Options = {},
186
+ ) {
187
+ const { opData } = options
188
+ const c = Calls.encode(calls, { opData })
189
+ const m = opData ? mode.opData : mode.default
190
+ return AbiFunction.encodeData(abiFunction, [m, c])
191
+ }
192
+
193
+ export declare namespace encodeData {
194
+ type Options = {
195
+ opData?: Hex.Hex | undefined
196
+ }
197
+ }
@@ -0,0 +1,73 @@
1
+ /** @entrypointCategory ERCs */
2
+ // biome-ignore lint/complexity/noUselessEmptyExport: tsdoc
3
+ export type {}
4
+
5
+ /**
6
+ * Utility functions for encoding and decoding [ERC-7821](https://eips.ethereum.org/EIPS/eip-7821) calls.
7
+ *
8
+ * @example
9
+ * ### Encoding calls
10
+ *
11
+ * Calls can be encoded using `Calls.encode`.
12
+ *
13
+ * ```ts twoslash
14
+ * import { Calls } from 'ox/erc7821'
15
+ *
16
+ * const calls = Calls.encode([
17
+ * {
18
+ * data: '0xcafebabe',
19
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
20
+ * value: 1n,
21
+ * }
22
+ * ])
23
+ * ```
24
+ *
25
+ * @example
26
+ * ### Decoding calls
27
+ *
28
+ * Calls can be decoded using `Calls.decode`.
29
+ *
30
+ * ```ts twoslash
31
+ * import { Calls } from 'ox/erc7821'
32
+ *
33
+ * const { calls } = Calls.decode('0x...')
34
+ * ```
35
+ *
36
+ * @category ERC-7821
37
+ */
38
+ export * as Calls from './Calls.js'
39
+
40
+ /**
41
+ * Utility functions for encoding and decoding [ERC-7821](https://eips.ethereum.org/EIPS/eip-7821) `execute` function data.
42
+ *
43
+ * @example
44
+ * ### Encoding `execute` Function Data
45
+ *
46
+ * The `execute` function data can be encoded using `Execute.encodeData`.
47
+ *
48
+ * ```ts twoslash
49
+ * import { Execute } from 'ox/erc7821'
50
+ *
51
+ * const data = Execute.encodeData([
52
+ * {
53
+ * data: '0xcafebabe',
54
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
55
+ * value: 1n,
56
+ * }
57
+ * ])
58
+ * ```
59
+ *
60
+ * @example
61
+ * ### Decoding `execute` Function Data
62
+ *
63
+ * The `execute` function data can be decoded using `Execute.decodeData`.
64
+ *
65
+ * ```ts twoslash
66
+ * import { Execute } from 'ox/erc7821'
67
+ *
68
+ * const { calls } = Execute.decodeData('0xe9ae5c53...')
69
+ * ```
70
+ *
71
+ * @category ERC-7821
72
+ */
73
+ export * as Execute from './Execute.js'
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/erc7821/index.d.ts",
4
+ "main": "../_cjs/erc7821/index.js",
5
+ "module": "../_esm/erc7821/index.js"
6
+ }
package/index.docs.ts CHANGED
@@ -4,4 +4,5 @@
4
4
  export * from './index.js'
5
5
  export * from './erc4337/index.js'
6
6
  export * from './erc6492/index.js'
7
+ export * from './erc7821/index.js'
7
8
  export * from './erc8010/index.js'