viem 0.0.0-main.20231026T220458 → 0.0.0-main.20231027T032213
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/_cjs/chains/celo/formatters.js +34 -5
- package/_cjs/chains/celo/formatters.js.map +1 -1
- package/_cjs/chains/celo/parsers.js +55 -0
- package/_cjs/chains/celo/parsers.js.map +1 -1
- package/_cjs/chains/celo/serializers.js +70 -6
- package/_cjs/chains/celo/serializers.js.map +1 -1
- package/_cjs/chains/utils/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_esm/chains/celo/formatters.js +34 -5
- package/_esm/chains/celo/formatters.js.map +1 -1
- package/_esm/chains/celo/parsers.js +56 -1
- package/_esm/chains/celo/parsers.js.map +1 -1
- package/_esm/chains/celo/serializers.js +73 -7
- package/_esm/chains/celo/serializers.js.map +1 -1
- package/_esm/chains/utils/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_types/chains/celo/formatters.d.ts +126 -0
- package/_types/chains/celo/formatters.d.ts.map +1 -1
- package/_types/chains/celo/parsers.d.ts.map +1 -1
- package/_types/chains/celo/serializers.d.ts +3 -1
- package/_types/chains/celo/serializers.d.ts.map +1 -1
- package/_types/chains/celo/types.d.ts +39 -7
- package/_types/chains/celo/types.d.ts.map +1 -1
- package/_types/chains/definitions/celo.d.ts +126 -0
- package/_types/chains/definitions/celo.d.ts.map +1 -1
- package/_types/chains/definitions/celoAlfajores.d.ts +126 -0
- package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
- package/_types/chains/definitions/celoCannoli.d.ts +126 -0
- package/_types/chains/definitions/celoCannoli.d.ts.map +1 -1
- package/_types/chains/utils/index.d.ts +1 -1
- package/_types/chains/utils/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/chains/celo/formatters.ts +39 -5
- package/chains/celo/parsers.ts +82 -1
- package/chains/celo/serializers.ts +121 -9
- package/chains/celo/types.ts +60 -2
- package/chains/utils/index.ts +6 -0
- package/errors/version.ts +1 -1
- package/package.json +1 -1
@@ -18,21 +18,27 @@ import {
|
|
18
18
|
import type {
|
19
19
|
CeloTransactionSerializable,
|
20
20
|
TransactionSerializableCIP42,
|
21
|
+
TransactionSerializableCIP64,
|
21
22
|
TransactionSerializedCIP42,
|
23
|
+
TransactionSerializedCIP64,
|
22
24
|
} from './types.js'
|
23
25
|
|
24
26
|
export const serializeTransactionCelo: SerializeTransactionFn<
|
25
27
|
CeloTransactionSerializable
|
26
28
|
> = (tx, signature) => {
|
27
|
-
|
28
|
-
|
29
|
+
if (isCIP64(tx)) {
|
30
|
+
return serializeTransactionCIP64(
|
31
|
+
tx as TransactionSerializableCIP64,
|
32
|
+
signature,
|
33
|
+
)
|
34
|
+
} else if (isCIP42(tx)) {
|
29
35
|
return serializeTransactionCIP42(
|
30
36
|
tx as TransactionSerializableCIP42,
|
31
37
|
signature,
|
32
38
|
)
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
} else {
|
40
|
+
return serializeTransaction(tx as TransactionSerializable, signature)
|
41
|
+
}
|
36
42
|
}
|
37
43
|
|
38
44
|
export const serializersCelo = {
|
@@ -43,6 +49,7 @@ export const serializersCelo = {
|
|
43
49
|
// Serializers
|
44
50
|
|
45
51
|
export type SerializeTransactionCIP42ReturnType = TransactionSerializedCIP42
|
52
|
+
export type SerializeTransactionCIP64ReturnType = TransactionSerializedCIP64
|
46
53
|
|
47
54
|
// There shall be a typed transaction with the code 0x7c that has the following format:
|
48
55
|
// 0x7c || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, feecurrency, gatewayFeeRecipient, gatewayfee, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s]).
|
@@ -96,20 +103,83 @@ function serializeTransactionCIP42(
|
|
96
103
|
]) as SerializeTransactionCIP42ReturnType
|
97
104
|
}
|
98
105
|
|
106
|
+
function serializeTransactionCIP64(
|
107
|
+
transaction: TransactionSerializableCIP64,
|
108
|
+
signature?: Signature,
|
109
|
+
): SerializeTransactionCIP64ReturnType {
|
110
|
+
assertTransactionCIP64(transaction)
|
111
|
+
const {
|
112
|
+
chainId,
|
113
|
+
gas,
|
114
|
+
nonce,
|
115
|
+
to,
|
116
|
+
value,
|
117
|
+
maxFeePerGas,
|
118
|
+
maxPriorityFeePerGas,
|
119
|
+
accessList,
|
120
|
+
feeCurrency,
|
121
|
+
data,
|
122
|
+
} = transaction
|
123
|
+
|
124
|
+
const serializedTransaction = [
|
125
|
+
toHex(chainId),
|
126
|
+
nonce ? toHex(nonce) : '0x',
|
127
|
+
maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x',
|
128
|
+
maxFeePerGas ? toHex(maxFeePerGas) : '0x',
|
129
|
+
gas ? toHex(gas) : '0x',
|
130
|
+
to ?? '0x',
|
131
|
+
value ? toHex(value) : '0x',
|
132
|
+
data ?? '0x',
|
133
|
+
serializeAccessList(accessList),
|
134
|
+
feeCurrency ?? '0x',
|
135
|
+
]
|
136
|
+
|
137
|
+
if (signature) {
|
138
|
+
serializedTransaction.push(
|
139
|
+
signature.v === 27n ? '0x' : toHex(1), // yParity
|
140
|
+
trim(signature.r),
|
141
|
+
trim(signature.s),
|
142
|
+
)
|
143
|
+
}
|
144
|
+
|
145
|
+
return concatHex([
|
146
|
+
'0x7b',
|
147
|
+
toRlp(serializedTransaction),
|
148
|
+
]) as SerializeTransactionCIP64ReturnType
|
149
|
+
}
|
150
|
+
|
99
151
|
//////////////////////////////////////////////////////////////////////////////
|
100
152
|
// Utilities
|
101
153
|
|
102
154
|
// process as CIP42 if any of these fields are present. realistically gatewayfee is not used but is part of spec
|
103
|
-
function isCIP42(transaction: CeloTransactionSerializable) {
|
104
|
-
if (
|
155
|
+
function isCIP42(transaction: CeloTransactionSerializable): boolean {
|
156
|
+
if (transaction.type === 'cip42') return true
|
157
|
+
// if the type is defined as anything else, assume it is *not* cip42
|
158
|
+
if (transaction.type) return false
|
159
|
+
|
160
|
+
// if the type is undefined, check if the fields match the expectations for cip42
|
161
|
+
return (
|
105
162
|
'maxFeePerGas' in transaction &&
|
106
163
|
'maxPriorityFeePerGas' in transaction &&
|
107
164
|
('feeCurrency' in transaction ||
|
108
165
|
'gatewayFee' in transaction ||
|
109
166
|
'gatewayFeeRecipient' in transaction)
|
110
167
|
)
|
111
|
-
|
112
|
-
|
168
|
+
}
|
169
|
+
|
170
|
+
function isCIP64(transaction: CeloTransactionSerializable): boolean {
|
171
|
+
if (transaction.type === 'cip64') return true
|
172
|
+
// if the type is defined as anything else, assume it is *not* cip64
|
173
|
+
if (transaction.type) return false
|
174
|
+
|
175
|
+
// if the type is undefined, check if the fields match the expectations for cip64
|
176
|
+
return (
|
177
|
+
'maxFeePerGas' in transaction &&
|
178
|
+
'maxPriorityFeePerGas' in transaction &&
|
179
|
+
'feeCurrency' in transaction &&
|
180
|
+
!('gatewayFee' in transaction) &&
|
181
|
+
!('gatewayFeeRecipient' in transaction)
|
182
|
+
)
|
113
183
|
}
|
114
184
|
|
115
185
|
// maxFeePerGas must be less than 2^256 - 1: however writing like that caused exceptions to be raised
|
@@ -167,3 +237,45 @@ export function assertTransactionCIP42(
|
|
167
237
|
)
|
168
238
|
}
|
169
239
|
}
|
240
|
+
|
241
|
+
export function assertTransactionCIP64(
|
242
|
+
transaction: TransactionSerializableCIP64,
|
243
|
+
) {
|
244
|
+
const {
|
245
|
+
chainId,
|
246
|
+
maxPriorityFeePerGas,
|
247
|
+
gasPrice,
|
248
|
+
maxFeePerGas,
|
249
|
+
to,
|
250
|
+
feeCurrency,
|
251
|
+
} = transaction
|
252
|
+
|
253
|
+
if (chainId <= 0) throw new InvalidChainIdError({ chainId })
|
254
|
+
if (to && !isAddress(to)) throw new InvalidAddressError({ address: to })
|
255
|
+
|
256
|
+
if (gasPrice)
|
257
|
+
throw new BaseError(
|
258
|
+
'`gasPrice` is not a valid CIP-64 Transaction attribute.',
|
259
|
+
)
|
260
|
+
|
261
|
+
if (maxFeePerGas && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
|
262
|
+
throw new FeeCapTooHighError({ maxFeePerGas })
|
263
|
+
if (
|
264
|
+
maxPriorityFeePerGas &&
|
265
|
+
maxFeePerGas &&
|
266
|
+
maxPriorityFeePerGas > maxFeePerGas
|
267
|
+
)
|
268
|
+
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
|
269
|
+
|
270
|
+
if (feeCurrency && !feeCurrency?.startsWith('0x')) {
|
271
|
+
throw new BaseError(
|
272
|
+
'`feeCurrency` MUST be a token address for CIP-64 transactions.',
|
273
|
+
)
|
274
|
+
}
|
275
|
+
|
276
|
+
if (!feeCurrency) {
|
277
|
+
throw new BaseError(
|
278
|
+
'`feeCurrency` must be provided for CIP-64 transactions.',
|
279
|
+
)
|
280
|
+
}
|
281
|
+
}
|
package/chains/celo/types.ts
CHANGED
@@ -75,6 +75,7 @@ export type CeloRpcBlock<
|
|
75
75
|
export type CeloRpcTransaction<TPending extends boolean = boolean> =
|
76
76
|
| RpcTransaction<TPending>
|
77
77
|
| RpcTransactionCIP42<TPending>
|
78
|
+
| RpcTransactionCIP64<TPending>
|
78
79
|
|
79
80
|
export type CeloRpcTransactionReceiptOverrides = {
|
80
81
|
feeCurrency: Address | null
|
@@ -87,10 +88,12 @@ export type CeloRpcTransactionReceipt = RpcTransactionReceipt &
|
|
87
88
|
export type CeloRpcTransactionRequest =
|
88
89
|
| RpcTransactionRequest
|
89
90
|
| RpcTransactionRequestCIP42
|
91
|
+
| RpcTransactionRequestCIP64
|
90
92
|
|
91
93
|
export type CeloTransaction<TPending extends boolean = boolean> =
|
92
94
|
| Transaction<TPending>
|
93
95
|
| TransactionCIP42<TPending>
|
96
|
+
| TransactionCIP64<TPending>
|
94
97
|
|
95
98
|
export type CeloTransactionReceiptOverrides = {
|
96
99
|
feeCurrency: Address | null
|
@@ -103,16 +106,21 @@ export type CeloTransactionReceipt = TransactionReceipt &
|
|
103
106
|
export type CeloTransactionRequest =
|
104
107
|
| TransactionRequest
|
105
108
|
| TransactionRequestCIP42
|
109
|
+
| TransactionRequestCIP64
|
106
110
|
|
107
111
|
export type CeloTransactionSerializable =
|
108
112
|
| TransactionSerializableCIP42
|
113
|
+
| TransactionSerializableCIP64
|
109
114
|
| TransactionSerializable
|
110
115
|
|
111
116
|
export type CeloTransactionSerialized<
|
112
117
|
TType extends CeloTransactionType = 'legacy',
|
113
|
-
> =
|
118
|
+
> =
|
119
|
+
| TransactionSerialized<TType>
|
120
|
+
| TransactionSerializedCIP42
|
121
|
+
| TransactionSerializedCIP64
|
114
122
|
|
115
|
-
export type CeloTransactionType = TransactionType | 'cip42'
|
123
|
+
export type CeloTransactionType = TransactionType | 'cip42' | 'cip64'
|
116
124
|
|
117
125
|
type RpcTransaction<TPending extends boolean = boolean> =
|
118
126
|
RpcTransaction_<TPending> & {
|
@@ -136,6 +144,13 @@ export type RpcTransactionCIP42<TPending extends boolean = boolean> =
|
|
136
144
|
type: '0x7c'
|
137
145
|
}
|
138
146
|
|
147
|
+
export type RpcTransactionCIP64<TPending extends boolean = boolean> =
|
148
|
+
TransactionBase<Quantity, Index, TPending> &
|
149
|
+
FeeValuesEIP1559<Quantity> & {
|
150
|
+
feeCurrency: Address | null
|
151
|
+
type: '0x7b'
|
152
|
+
}
|
153
|
+
|
139
154
|
export type RpcTransactionRequestCIP42 = TransactionRequestBase<
|
140
155
|
Quantity,
|
141
156
|
Index
|
@@ -148,6 +163,18 @@ export type RpcTransactionRequestCIP42 = TransactionRequestBase<
|
|
148
163
|
type?: '0x7c'
|
149
164
|
}
|
150
165
|
|
166
|
+
export type RpcTransactionRequestCIP64 = TransactionRequestBase<
|
167
|
+
Quantity,
|
168
|
+
Index
|
169
|
+
> &
|
170
|
+
Partial<FeeValuesEIP1559<Quantity>> & {
|
171
|
+
accessList?: AccessList
|
172
|
+
feeCurrency?: Address
|
173
|
+
gatewayFee?: undefined
|
174
|
+
gatewayFeeRecipient?: undefined
|
175
|
+
type?: '0x7b'
|
176
|
+
}
|
177
|
+
|
151
178
|
type Transaction<TPending extends boolean = boolean> = Transaction_<
|
152
179
|
bigint,
|
153
180
|
number,
|
@@ -167,6 +194,15 @@ export type TransactionCIP42<TPending extends boolean = boolean> =
|
|
167
194
|
type: 'cip42'
|
168
195
|
}
|
169
196
|
|
197
|
+
export type TransactionCIP64<TPending extends boolean = boolean> =
|
198
|
+
TransactionBase<bigint, number, TPending> &
|
199
|
+
FeeValuesEIP1559 & {
|
200
|
+
feeCurrency: Address | null
|
201
|
+
gatewayFee?: undefined
|
202
|
+
gatewayFeeRecipient?: undefined
|
203
|
+
type: 'cip64'
|
204
|
+
}
|
205
|
+
|
170
206
|
type TransactionRequest = TransactionRequest_ & {
|
171
207
|
feeCurrency?: Address
|
172
208
|
gatewayFee?: bigint
|
@@ -182,6 +218,15 @@ export type TransactionRequestCIP42 = TransactionRequestBase &
|
|
182
218
|
type?: 'cip42'
|
183
219
|
}
|
184
220
|
|
221
|
+
export type TransactionRequestCIP64 = TransactionRequestBase &
|
222
|
+
Partial<FeeValuesEIP1559> & {
|
223
|
+
accessList?: AccessList
|
224
|
+
feeCurrency?: Address
|
225
|
+
gatewayFee?: undefined
|
226
|
+
gatewayFeeRecipient?: undefined
|
227
|
+
type?: 'cip64'
|
228
|
+
}
|
229
|
+
|
185
230
|
export type TransactionSerializableCIP42<
|
186
231
|
TQuantity = bigint,
|
187
232
|
TIndex = number,
|
@@ -196,4 +241,17 @@ export type TransactionSerializableCIP42<
|
|
196
241
|
type?: 'cip42'
|
197
242
|
}
|
198
243
|
|
244
|
+
export type TransactionSerializableCIP64<
|
245
|
+
TQuantity = bigint,
|
246
|
+
TIndex = number,
|
247
|
+
> = TransactionSerializableBase<TQuantity, TIndex> &
|
248
|
+
FeeValuesEIP1559<TQuantity> & {
|
249
|
+
accessList?: AccessList
|
250
|
+
gasPrice?: never
|
251
|
+
feeCurrency?: Address
|
252
|
+
chainId: number
|
253
|
+
type?: 'cip64'
|
254
|
+
}
|
255
|
+
|
199
256
|
export type TransactionSerializedCIP42 = `0x7c${string}`
|
257
|
+
export type TransactionSerializedCIP64 = `0x7b${string}`
|
package/chains/utils/index.ts
CHANGED
@@ -21,11 +21,17 @@ export type {
|
|
21
21
|
CeloTransactionSerialized,
|
22
22
|
CeloTransactionType,
|
23
23
|
RpcTransactionCIP42,
|
24
|
+
RpcTransactionCIP64,
|
24
25
|
RpcTransactionRequestCIP42,
|
26
|
+
RpcTransactionRequestCIP64,
|
25
27
|
TransactionCIP42,
|
28
|
+
TransactionCIP64,
|
26
29
|
TransactionRequestCIP42,
|
30
|
+
TransactionRequestCIP64,
|
27
31
|
TransactionSerializableCIP42,
|
32
|
+
TransactionSerializableCIP64,
|
28
33
|
TransactionSerializedCIP42,
|
34
|
+
TransactionSerializedCIP64,
|
29
35
|
} from '../celo/types.js'
|
30
36
|
|
31
37
|
export { formattersOptimism } from '../optimism/formatters.js'
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.0.0-main.
|
1
|
+
export const version = '0.0.0-main.20231027T032213'
|
package/package.json
CHANGED