ox 0.9.6 → 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.
- package/CHANGELOG.md +14 -0
- package/_cjs/core/Bytes.js +1 -1
- package/_cjs/core/Bytes.js.map +1 -1
- package/_cjs/core/Hex.js +1 -1
- package/_cjs/core/Hex.js.map +1 -1
- package/_cjs/core/Rlp.js +4 -4
- package/_cjs/core/Rlp.js.map +1 -1
- package/_cjs/core/TransactionRequest.js +3 -1
- package/_cjs/core/TransactionRequest.js.map +1 -1
- package/_cjs/erc7821/Calls.js +39 -0
- package/_cjs/erc7821/Calls.js.map +1 -0
- package/_cjs/erc7821/Execute.js +75 -0
- package/_cjs/erc7821/Execute.js.map +1 -0
- package/_cjs/erc7821/index.js +6 -0
- package/_cjs/erc7821/index.js.map +1 -0
- package/_cjs/index.docs.js +1 -0
- package/_cjs/index.docs.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/core/Bytes.js +1 -1
- package/_esm/core/Bytes.js.map +1 -1
- package/_esm/core/Hex.js +1 -1
- package/_esm/core/Hex.js.map +1 -1
- package/_esm/core/Rlp.js +4 -4
- package/_esm/core/Rlp.js.map +1 -1
- package/_esm/core/TransactionRequest.js +3 -1
- package/_esm/core/TransactionRequest.js.map +1 -1
- package/_esm/erc7821/Calls.js +101 -0
- package/_esm/erc7821/Calls.js.map +1 -0
- package/_esm/erc7821/Execute.js +151 -0
- package/_esm/erc7821/Execute.js.map +1 -0
- package/_esm/erc7821/index.js +69 -0
- package/_esm/erc7821/index.js.map +1 -0
- package/_esm/index.docs.js +1 -0
- package/_esm/index.docs.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/core/TransactionRequest.d.ts.map +1 -1
- package/_types/erc7821/Calls.d.ts +102 -0
- package/_types/erc7821/Calls.d.ts.map +1 -0
- package/_types/erc7821/Execute.d.ts +126 -0
- package/_types/erc7821/Execute.d.ts.map +1 -0
- package/_types/erc7821/index.d.ts +71 -0
- package/_types/erc7821/index.d.ts.map +1 -0
- package/_types/index.docs.d.ts +1 -0
- package/_types/index.docs.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/core/Bytes.ts +1 -1
- package/core/Hex.ts +1 -1
- package/core/Rlp.ts +4 -4
- package/core/TransactionRequest.ts +6 -1
- package/erc7821/Calls/package.json +6 -0
- package/erc7821/Calls.ts +148 -0
- package/erc7821/Execute/package.json +6 -0
- package/erc7821/Execute.ts +197 -0
- package/erc7821/index.ts +73 -0
- package/erc7821/package.json +6 -0
- package/index.docs.ts +1 -0
- package/package.json +16 -1
- package/version.ts +1 -1
|
@@ -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"}
|
package/_types/index.docs.d.ts
CHANGED
|
@@ -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"}
|
package/_types/version.d.ts
CHANGED
package/core/Bytes.ts
CHANGED
|
@@ -231,7 +231,7 @@ export function fromHex(value: Hex.Hex, options: fromHex.Options = {}): Bytes {
|
|
|
231
231
|
`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`,
|
|
232
232
|
)
|
|
233
233
|
}
|
|
234
|
-
bytes[index] = nibbleLeft
|
|
234
|
+
bytes[index] = (nibbleLeft << 4) | nibbleRight
|
|
235
235
|
}
|
|
236
236
|
return bytes
|
|
237
237
|
}
|
package/core/Hex.ts
CHANGED
|
@@ -256,7 +256,7 @@ export function fromNumber(
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
const stringValue = (
|
|
259
|
-
signed && value_ < 0 ?
|
|
259
|
+
signed && value_ < 0 ? BigInt.asUintN(size * 8, BigInt(value_)) : value_
|
|
260
260
|
).toString(16)
|
|
261
261
|
|
|
262
262
|
const hex = `0x${stringValue}` as Hex
|
package/core/Rlp.ts
CHANGED
|
@@ -359,9 +359,9 @@ function getEncodableBytes(bytesOrHex: Bytes.Bytes | Hex.Hex): Encodable {
|
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
function getSizeOfLength(length: number) {
|
|
362
|
-
if (length
|
|
363
|
-
if (length
|
|
364
|
-
if (length
|
|
365
|
-
if (length
|
|
362
|
+
if (length <= 0xff) return 1
|
|
363
|
+
if (length <= 0xff_ff) return 2
|
|
364
|
+
if (length <= 0xff_ff_ff) return 3
|
|
365
|
+
if (length <= 0xff_ff_ff_ff) return 4
|
|
366
366
|
throw new Errors.BaseError('Length is too large.')
|
|
367
367
|
}
|
|
@@ -4,6 +4,7 @@ import * as Authorization from './Authorization.js'
|
|
|
4
4
|
import type * as Errors from './Errors.js'
|
|
5
5
|
import * as Hex from './Hex.js'
|
|
6
6
|
import type { Compute } from './internal/types.js'
|
|
7
|
+
import * as Transaction from './Transaction.js'
|
|
7
8
|
|
|
8
9
|
/** A Transaction Request that is generic to all transaction types, as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/4aca1d7a3e5aab24c8f6437131289ad386944eaa/src/schemas/transaction.yaml#L358-L423). */
|
|
9
10
|
export type TransactionRequest<
|
|
@@ -132,7 +133,11 @@ export function toRpc(request: TransactionRequest): Rpc {
|
|
|
132
133
|
if (typeof request.nonce !== 'undefined')
|
|
133
134
|
request_rpc.nonce = Hex.fromNumber(request.nonce)
|
|
134
135
|
if (typeof request.to !== 'undefined') request_rpc.to = request.to
|
|
135
|
-
if (typeof request.type !== 'undefined')
|
|
136
|
+
if (typeof request.type !== 'undefined')
|
|
137
|
+
request_rpc.type =
|
|
138
|
+
Transaction.toRpcType[
|
|
139
|
+
request.type as keyof typeof Transaction.toRpcType
|
|
140
|
+
] || request.type
|
|
136
141
|
if (typeof request.value !== 'undefined')
|
|
137
142
|
request_rpc.value = Hex.fromNumber(request.value)
|
|
138
143
|
|
package/erc7821/Calls.ts
ADDED
|
@@ -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,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
|
+
}
|
package/erc7821/index.ts
ADDED
|
@@ -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'
|
package/index.docs.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ox",
|
|
3
3
|
"description": "Ethereum Standard Library",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.8",
|
|
5
5
|
"main": "./_cjs/index.js",
|
|
6
6
|
"module": "./_esm/index.js",
|
|
7
7
|
"types": "./_types/index.d.ts",
|
|
@@ -428,6 +428,21 @@
|
|
|
428
428
|
"import": "./_esm/erc6492/index.js",
|
|
429
429
|
"default": "./_cjs/erc6492/index.js"
|
|
430
430
|
},
|
|
431
|
+
"./erc7821/Calls": {
|
|
432
|
+
"types": "./_types/erc7821/Calls.d.ts",
|
|
433
|
+
"import": "./_esm/erc7821/Calls.js",
|
|
434
|
+
"default": "./_cjs/erc7821/Calls.js"
|
|
435
|
+
},
|
|
436
|
+
"./erc7821/Execute": {
|
|
437
|
+
"types": "./_types/erc7821/Execute.d.ts",
|
|
438
|
+
"import": "./_esm/erc7821/Execute.js",
|
|
439
|
+
"default": "./_cjs/erc7821/Execute.js"
|
|
440
|
+
},
|
|
441
|
+
"./erc7821": {
|
|
442
|
+
"types": "./_types/erc7821/index.d.ts",
|
|
443
|
+
"import": "./_esm/erc7821/index.js",
|
|
444
|
+
"default": "./_cjs/erc7821/index.js"
|
|
445
|
+
},
|
|
431
446
|
"./erc8010/SignatureErc8010": {
|
|
432
447
|
"types": "./_types/erc8010/SignatureErc8010.d.ts",
|
|
433
448
|
"import": "./_esm/erc8010/SignatureErc8010.js",
|
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.9.
|
|
2
|
+
export const version = '0.9.8'
|