viem 0.0.0-main.20231105T204204 → 0.0.0-main.20231105T211250
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 +23 -35
- package/_cjs/chains/celo/formatters.js.map +1 -1
- package/_cjs/chains/celo/serializers.js +20 -38
- package/_cjs/chains/celo/serializers.js.map +1 -1
- package/_cjs/chains/celo/utils.js +44 -0
- package/_cjs/chains/celo/utils.js.map +1 -0
- package/_cjs/errors/node.js +11 -11
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/rpc.js +18 -18
- package/_cjs/errors/rpc.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_esm/chains/celo/formatters.js +23 -35
- package/_esm/chains/celo/formatters.js.map +1 -1
- package/_esm/chains/celo/serializers.js +19 -44
- package/_esm/chains/celo/serializers.js.map +1 -1
- package/_esm/chains/celo/utils.js +39 -0
- package/_esm/chains/celo/utils.js.map +1 -0
- package/_esm/errors/node.js +11 -22
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/rpc.js +18 -36
- package/_esm/errors/rpc.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_types/chains/celo/formatters.d.ts +6 -6
- package/_types/chains/celo/formatters.d.ts.map +1 -1
- package/_types/chains/celo/serializers.d.ts +3 -2
- package/_types/chains/celo/serializers.d.ts.map +1 -1
- package/_types/chains/celo/types.d.ts +12 -7
- package/_types/chains/celo/types.d.ts.map +1 -1
- package/_types/chains/celo/utils.d.ts +7 -0
- package/_types/chains/celo/utils.d.ts.map +1 -0
- package/_types/chains/definitions/celo.d.ts +6 -6
- package/_types/chains/definitions/celoAlfajores.d.ts +6 -6
- package/_types/chains/definitions/celoCannoli.d.ts +6 -6
- package/_types/errors/version.d.ts +1 -1
- package/chains/celo/formatters.ts +24 -37
- package/chains/celo/serializers.ts +23 -59
- package/chains/celo/types.ts +29 -19
- package/chains/celo/utils.ts +68 -0
- package/errors/version.ts +1 -1
- package/package.json +1 -1
@@ -84,12 +84,12 @@ export declare const celoAlfajores: import("../../types/utils.js").Assign<{
|
|
84
84
|
feeCurrency: `0x${string}` | null;
|
85
85
|
gatewayFee: `0x${string}` | null;
|
86
86
|
gatewayFeeRecipient: `0x${string}` | null;
|
87
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
87
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
88
88
|
feeCurrency: `0x${string}` | null;
|
89
89
|
gatewayFee: `0x${string}` | null;
|
90
90
|
gatewayFeeRecipient: `0x${string}` | null;
|
91
91
|
type: "0x7c";
|
92
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
92
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
93
93
|
feeCurrency: `0x${string}` | null;
|
94
94
|
type: "0x7b";
|
95
95
|
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex"> & {
|
@@ -104,12 +104,12 @@ export declare const celoAlfajores: import("../../types/utils.js").Assign<{
|
|
104
104
|
feeCurrency: `0x${string}` | null;
|
105
105
|
gatewayFee: `0x${string}` | null;
|
106
106
|
gatewayFeeRecipient: `0x${string}` | null;
|
107
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
107
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
108
108
|
feeCurrency: `0x${string}` | null;
|
109
109
|
gatewayFee: `0x${string}` | null;
|
110
110
|
gatewayFeeRecipient: `0x${string}` | null;
|
111
111
|
type: "0x7c";
|
112
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
112
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
113
113
|
feeCurrency: `0x${string}` | null;
|
114
114
|
type: "0x7b";
|
115
115
|
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex"> & {
|
@@ -124,12 +124,12 @@ export declare const celoAlfajores: import("../../types/utils.js").Assign<{
|
|
124
124
|
feeCurrency: `0x${string}` | null;
|
125
125
|
gatewayFee: `0x${string}` | null;
|
126
126
|
gatewayFeeRecipient: `0x${string}` | null;
|
127
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
127
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
128
128
|
feeCurrency: `0x${string}` | null;
|
129
129
|
gatewayFee: `0x${string}` | null;
|
130
130
|
gatewayFeeRecipient: `0x${string}` | null;
|
131
131
|
type: "0x7c";
|
132
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
132
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
133
133
|
feeCurrency: `0x${string}` | null;
|
134
134
|
type: "0x7b";
|
135
135
|
})) => ({
|
@@ -77,12 +77,12 @@ export declare const celoCannoli: import("../../types/utils.js").Assign<{
|
|
77
77
|
feeCurrency: `0x${string}` | null;
|
78
78
|
gatewayFee: `0x${string}` | null;
|
79
79
|
gatewayFeeRecipient: `0x${string}` | null;
|
80
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
80
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
81
81
|
feeCurrency: `0x${string}` | null;
|
82
82
|
gatewayFee: `0x${string}` | null;
|
83
83
|
gatewayFeeRecipient: `0x${string}` | null;
|
84
84
|
type: "0x7c";
|
85
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
85
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
86
86
|
feeCurrency: `0x${string}` | null;
|
87
87
|
type: "0x7b";
|
88
88
|
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex"> & {
|
@@ -97,12 +97,12 @@ export declare const celoCannoli: import("../../types/utils.js").Assign<{
|
|
97
97
|
feeCurrency: `0x${string}` | null;
|
98
98
|
gatewayFee: `0x${string}` | null;
|
99
99
|
gatewayFeeRecipient: `0x${string}` | null;
|
100
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
100
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
101
101
|
feeCurrency: `0x${string}` | null;
|
102
102
|
gatewayFee: `0x${string}` | null;
|
103
103
|
gatewayFeeRecipient: `0x${string}` | null;
|
104
104
|
type: "0x7c";
|
105
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
105
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP2930<`0x${string}`, `0x${string}`, boolean, "0x1">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
106
106
|
feeCurrency: `0x${string}` | null;
|
107
107
|
type: "0x7b";
|
108
108
|
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionLegacy<`0x${string}`, `0x${string}`, boolean, "0x0">, "typeHex"> & {
|
@@ -117,12 +117,12 @@ export declare const celoCannoli: import("../../types/utils.js").Assign<{
|
|
117
117
|
feeCurrency: `0x${string}` | null;
|
118
118
|
gatewayFee: `0x${string}` | null;
|
119
119
|
gatewayFeeRecipient: `0x${string}` | null;
|
120
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
120
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
121
121
|
feeCurrency: `0x${string}` | null;
|
122
122
|
gatewayFee: `0x${string}` | null;
|
123
123
|
gatewayFeeRecipient: `0x${string}` | null;
|
124
124
|
type: "0x7c";
|
125
|
-
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
125
|
+
}) | (import("../../types/utils.js").Assign_<Partial<Omit<import("../../index.js").TransactionEIP1559<`0x${string}`, `0x${string}`, boolean, "0x2">, "typeHex">>, import("../celo/types.js").CeloRpcTransaction> & Omit<import("../../index.js").TransactionBase<`0x${string}`, `0x${string}`, boolean>, "typeHex"> & import("../../index.js").FeeValuesEIP1559<`0x${string}`> & {
|
126
126
|
feeCurrency: `0x${string}` | null;
|
127
127
|
type: "0x7b";
|
128
128
|
})) => ({
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const version = "0.0.0-main.
|
1
|
+
export declare const version = "0.0.0-main.20231105T211250";
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
@@ -19,22 +19,7 @@ import type {
|
|
19
19
|
CeloTransactionReceiptOverrides,
|
20
20
|
CeloTransactionRequest,
|
21
21
|
} from './types.js'
|
22
|
-
|
23
|
-
function isTransactionRequestCIP64(args: CeloTransactionRequest): boolean {
|
24
|
-
if (args.type === 'cip64') return true
|
25
|
-
if (args.type) return false
|
26
|
-
return (
|
27
|
-
'feeCurrency' in args &&
|
28
|
-
args.gatewayFee === undefined &&
|
29
|
-
args.gatewayFeeRecipient === undefined
|
30
|
-
)
|
31
|
-
}
|
32
|
-
|
33
|
-
function isTransactionRequestCIP42(args: CeloTransactionRequest): boolean {
|
34
|
-
if (args.type === 'cip42') return true
|
35
|
-
if (args.type) return false
|
36
|
-
return args.gatewayFee !== undefined || args.gatewayFeeRecipient !== undefined
|
37
|
-
}
|
22
|
+
import { isCIP42, isCIP64 } from './utils.js'
|
38
23
|
|
39
24
|
export const formattersCelo = {
|
40
25
|
block: /*#__PURE__*/ defineBlock({
|
@@ -70,15 +55,19 @@ export const formattersCelo = {
|
|
70
55
|
}),
|
71
56
|
transaction: /*#__PURE__*/ defineTransaction({
|
72
57
|
format(args: CeloRpcTransaction): CeloTransaction {
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
58
|
+
const transaction = { feeCurrency: args.feeCurrency } as CeloTransaction
|
59
|
+
|
60
|
+
if (args.type === '0x7b') transaction.type = 'cip64'
|
61
|
+
else {
|
62
|
+
if (args.type === '0x7c') transaction.type = 'cip42'
|
63
|
+
|
64
|
+
transaction.gatewayFee = args.gatewayFee
|
65
|
+
? hexToBigInt(args.gatewayFee)
|
66
|
+
: null
|
67
|
+
transaction.gatewayFeeRecipient = args.gatewayFeeRecipient
|
68
|
+
}
|
69
|
+
|
70
|
+
return transaction
|
82
71
|
},
|
83
72
|
}),
|
84
73
|
transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({
|
@@ -95,22 +84,20 @@ export const formattersCelo = {
|
|
95
84
|
|
96
85
|
transactionRequest: /*#__PURE__*/ defineTransactionRequest({
|
97
86
|
format(args: CeloTransactionRequest): CeloRpcTransactionRequest {
|
98
|
-
if (isTransactionRequestCIP64(args))
|
99
|
-
return {
|
100
|
-
type: '0x7b',
|
101
|
-
feeCurrency: args.feeCurrency,
|
102
|
-
} as CeloRpcTransactionRequest
|
103
|
-
|
104
87
|
const request = {
|
105
88
|
feeCurrency: args.feeCurrency,
|
106
|
-
gatewayFee:
|
107
|
-
typeof args.gatewayFee !== 'undefined'
|
108
|
-
? numberToHex(args.gatewayFee)
|
109
|
-
: undefined,
|
110
|
-
gatewayFeeRecipient: args.gatewayFeeRecipient,
|
111
89
|
} as CeloRpcTransactionRequest
|
112
90
|
|
113
|
-
if (
|
91
|
+
if (isCIP64(args)) request.type = '0x7b'
|
92
|
+
else {
|
93
|
+
if (isCIP42(args)) request.type = '0x7c'
|
94
|
+
|
95
|
+
request.gatewayFee =
|
96
|
+
typeof args.gatewayFee !== 'undefined'
|
97
|
+
? numberToHex(args.gatewayFee)
|
98
|
+
: undefined
|
99
|
+
request.gatewayFeeRecipient = args.gatewayFeeRecipient
|
100
|
+
}
|
114
101
|
|
115
102
|
return request
|
116
103
|
},
|
@@ -22,20 +22,15 @@ import type {
|
|
22
22
|
TransactionSerializedCIP42,
|
23
23
|
TransactionSerializedCIP64,
|
24
24
|
} from './types.js'
|
25
|
+
import { isCIP42, isCIP64, isEmpty, isPresent } from './utils.js'
|
25
26
|
|
26
27
|
export const serializeTransactionCelo: SerializeTransactionFn<
|
27
|
-
CeloTransactionSerializable
|
28
|
+
CeloTransactionSerializable | TransactionSerializable
|
28
29
|
> = (tx, signature) => {
|
29
30
|
if (isCIP64(tx)) {
|
30
|
-
return serializeTransactionCIP64(
|
31
|
-
tx as TransactionSerializableCIP64,
|
32
|
-
signature,
|
33
|
-
)
|
31
|
+
return serializeTransactionCIP64(tx, signature)
|
34
32
|
} else if (isCIP42(tx)) {
|
35
|
-
return serializeTransactionCIP42(
|
36
|
-
tx as TransactionSerializableCIP42,
|
37
|
-
signature,
|
38
|
-
)
|
33
|
+
return serializeTransactionCIP42(tx, signature)
|
39
34
|
} else {
|
40
35
|
return serializeTransaction(tx as TransactionSerializable, signature)
|
41
36
|
}
|
@@ -131,7 +126,7 @@ function serializeTransactionCIP64(
|
|
131
126
|
value ? toHex(value) : '0x',
|
132
127
|
data ?? '0x',
|
133
128
|
serializeAccessList(accessList),
|
134
|
-
feeCurrency
|
129
|
+
feeCurrency!,
|
135
130
|
]
|
136
131
|
|
137
132
|
if (signature) {
|
@@ -148,43 +143,8 @@ function serializeTransactionCIP64(
|
|
148
143
|
]) as SerializeTransactionCIP64ReturnType
|
149
144
|
}
|
150
145
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
// process as CIP42 if any of these fields are present. realistically gatewayfee is not used but is part of spec
|
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 (
|
162
|
-
'maxFeePerGas' in transaction &&
|
163
|
-
'maxPriorityFeePerGas' in transaction &&
|
164
|
-
('feeCurrency' in transaction ||
|
165
|
-
'gatewayFee' in transaction ||
|
166
|
-
'gatewayFeeRecipient' in transaction)
|
167
|
-
)
|
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
|
-
)
|
183
|
-
}
|
184
|
-
|
185
|
-
// maxFeePerGas must be less than 2^256 - 1: however writing like that caused exceptions to be raised
|
186
|
-
const MAX_MAX_FEE_PER_GAS =
|
187
|
-
115792089237316195423570985008687907853269984665640564039457584007913129639935n
|
146
|
+
// maxFeePerGas must be less than 2^256 - 1
|
147
|
+
const MAX_MAX_FEE_PER_GAS = 2n ** 256n - 1n
|
188
148
|
|
189
149
|
export function assertTransactionCIP42(
|
190
150
|
transaction: TransactionSerializableCIP42,
|
@@ -206,32 +166,36 @@ export function assertTransactionCIP42(
|
|
206
166
|
'`gasPrice` is not a valid CIP-42 Transaction attribute.',
|
207
167
|
)
|
208
168
|
|
209
|
-
if (maxFeePerGas && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
|
169
|
+
if (isPresent(maxFeePerGas) && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
|
210
170
|
throw new FeeCapTooHighError({ maxFeePerGas })
|
211
171
|
|
212
172
|
if (
|
213
|
-
maxPriorityFeePerGas &&
|
214
|
-
maxFeePerGas &&
|
173
|
+
isPresent(maxPriorityFeePerGas) &&
|
174
|
+
isPresent(maxFeePerGas) &&
|
215
175
|
maxPriorityFeePerGas > maxFeePerGas
|
216
176
|
)
|
217
177
|
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
|
218
178
|
|
219
179
|
if (
|
220
|
-
(gatewayFee &&
|
221
|
-
(gatewayFeeRecipient &&
|
180
|
+
(isPresent(gatewayFee) && isEmpty(gatewayFeeRecipient)) ||
|
181
|
+
(isPresent(gatewayFeeRecipient) && isEmpty(gatewayFee))
|
222
182
|
) {
|
223
183
|
throw new BaseError(
|
224
184
|
'`gatewayFee` and `gatewayFeeRecipient` must be provided together.',
|
225
185
|
)
|
226
186
|
}
|
227
187
|
|
228
|
-
if (feeCurrency && !feeCurrency
|
188
|
+
if (isPresent(feeCurrency) && !isAddress(feeCurrency)) {
|
229
189
|
throw new BaseError(
|
230
190
|
'`feeCurrency` MUST be a token address for CIP-42 transactions.',
|
231
191
|
)
|
232
192
|
}
|
233
193
|
|
234
|
-
if (
|
194
|
+
if (isPresent(gatewayFeeRecipient) && !isAddress(gatewayFeeRecipient)) {
|
195
|
+
throw new InvalidAddressError(gatewayFeeRecipient)
|
196
|
+
}
|
197
|
+
|
198
|
+
if (isEmpty(feeCurrency) && isEmpty(gatewayFeeRecipient)) {
|
235
199
|
throw new BaseError(
|
236
200
|
'Either `feeCurrency` or `gatewayFeeRecipient` must be provided for CIP-42 transactions.',
|
237
201
|
)
|
@@ -258,22 +222,22 @@ export function assertTransactionCIP64(
|
|
258
222
|
'`gasPrice` is not a valid CIP-64 Transaction attribute.',
|
259
223
|
)
|
260
224
|
|
261
|
-
if (maxFeePerGas && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
|
225
|
+
if (isPresent(maxFeePerGas) && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
|
262
226
|
throw new FeeCapTooHighError({ maxFeePerGas })
|
263
227
|
if (
|
264
|
-
maxPriorityFeePerGas &&
|
265
|
-
maxFeePerGas &&
|
228
|
+
isPresent(maxPriorityFeePerGas) &&
|
229
|
+
isPresent(maxFeePerGas) &&
|
266
230
|
maxPriorityFeePerGas > maxFeePerGas
|
267
231
|
)
|
268
232
|
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
|
269
233
|
|
270
|
-
if (feeCurrency && !feeCurrency?.startsWith('0x')) {
|
234
|
+
if (isPresent(feeCurrency) && !feeCurrency?.startsWith('0x')) {
|
271
235
|
throw new BaseError(
|
272
236
|
'`feeCurrency` MUST be a token address for CIP-64 transactions.',
|
273
237
|
)
|
274
238
|
}
|
275
239
|
|
276
|
-
if (
|
240
|
+
if (isEmpty(feeCurrency)) {
|
277
241
|
throw new BaseError(
|
278
242
|
'`feeCurrency` must be provided for CIP-64 transactions.',
|
279
243
|
)
|
package/chains/celo/types.ts
CHANGED
@@ -111,7 +111,7 @@ export type CeloTransactionRequest =
|
|
111
111
|
export type CeloTransactionSerializable =
|
112
112
|
| TransactionSerializableCIP42
|
113
113
|
| TransactionSerializableCIP64
|
114
|
-
|
|
114
|
+
| CeloTransactionSerializableBase
|
115
115
|
|
116
116
|
export type CeloTransactionSerialized<
|
117
117
|
TType extends CeloTransactionType = 'legacy',
|
@@ -135,21 +135,25 @@ type RpcTransactionRequest = RpcTransactionRequest_ & {
|
|
135
135
|
gatewayFeeRecipient?: Address
|
136
136
|
}
|
137
137
|
|
138
|
-
export type RpcTransactionCIP42<TPending extends boolean = boolean> =
|
139
|
-
TransactionBase<Quantity, Index, TPending
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
138
|
+
export type RpcTransactionCIP42<TPending extends boolean = boolean> = Omit<
|
139
|
+
TransactionBase<Quantity, Index, TPending>,
|
140
|
+
'typeHex'
|
141
|
+
> &
|
142
|
+
FeeValuesEIP1559<Quantity> & {
|
143
|
+
feeCurrency: Address | null
|
144
|
+
gatewayFee: Hex | null
|
145
|
+
gatewayFeeRecipient: Address | null
|
146
|
+
type: '0x7c'
|
147
|
+
}
|
146
148
|
|
147
|
-
export type RpcTransactionCIP64<TPending extends boolean = boolean> =
|
148
|
-
TransactionBase<Quantity, Index, TPending
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
149
|
+
export type RpcTransactionCIP64<TPending extends boolean = boolean> = Omit<
|
150
|
+
TransactionBase<Quantity, Index, TPending>,
|
151
|
+
'typeHex'
|
152
|
+
> &
|
153
|
+
FeeValuesEIP1559<Quantity> & {
|
154
|
+
feeCurrency: Address | null
|
155
|
+
type: '0x7b'
|
156
|
+
}
|
153
157
|
|
154
158
|
export type RpcTransactionRequestCIP42 = TransactionRequestBase<
|
155
159
|
Quantity,
|
@@ -231,9 +235,8 @@ export type TransactionSerializableCIP42<
|
|
231
235
|
TQuantity = bigint,
|
232
236
|
TIndex = number,
|
233
237
|
> = TransactionSerializableBase<TQuantity, TIndex> &
|
234
|
-
FeeValuesEIP1559<TQuantity
|
238
|
+
Partial<FeeValuesEIP1559<TQuantity>> & {
|
235
239
|
accessList?: AccessList
|
236
|
-
gasPrice?: never
|
237
240
|
feeCurrency?: Address
|
238
241
|
gatewayFeeRecipient?: Address
|
239
242
|
gatewayFee?: TQuantity
|
@@ -245,13 +248,20 @@ export type TransactionSerializableCIP64<
|
|
245
248
|
TQuantity = bigint,
|
246
249
|
TIndex = number,
|
247
250
|
> = TransactionSerializableBase<TQuantity, TIndex> &
|
248
|
-
FeeValuesEIP1559<TQuantity
|
251
|
+
Partial<FeeValuesEIP1559<TQuantity>> & {
|
249
252
|
accessList?: AccessList
|
250
|
-
gasPrice?: never
|
251
253
|
feeCurrency?: Address
|
254
|
+
gatewayFee?: undefined
|
255
|
+
gatewayFeeRecipient?: undefined
|
252
256
|
chainId: number
|
253
257
|
type?: 'cip64'
|
254
258
|
}
|
255
259
|
|
260
|
+
export type CeloTransactionSerializableBase = TransactionSerializable & {
|
261
|
+
feeCurrency?: undefined
|
262
|
+
gatewayFee?: undefined
|
263
|
+
gatewayFeeRecipient?: undefined
|
264
|
+
}
|
265
|
+
|
256
266
|
export type TransactionSerializedCIP42 = `0x7c${string}`
|
257
267
|
export type TransactionSerializedCIP64 = `0x7b${string}`
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import { trim } from '../../utils/data/trim.js'
|
3
|
+
import type {
|
4
|
+
CeloTransactionRequest,
|
5
|
+
CeloTransactionSerializable,
|
6
|
+
TransactionSerializableCIP42,
|
7
|
+
TransactionSerializableCIP64,
|
8
|
+
} from './types.js'
|
9
|
+
|
10
|
+
export function isEmpty(
|
11
|
+
value: string | undefined | number | BigInt,
|
12
|
+
): value is undefined {
|
13
|
+
return (
|
14
|
+
value === 0 ||
|
15
|
+
value === 0n ||
|
16
|
+
value === undefined ||
|
17
|
+
value === null ||
|
18
|
+
value === '0' ||
|
19
|
+
value === '' ||
|
20
|
+
(typeof value === 'string' &&
|
21
|
+
(trim(value as Address).toLowerCase() === '0x' ||
|
22
|
+
trim(value as Address).toLowerCase() === '0x00'))
|
23
|
+
)
|
24
|
+
}
|
25
|
+
|
26
|
+
export function isPresent(
|
27
|
+
value: string | undefined | number | BigInt,
|
28
|
+
): value is string | number | BigInt {
|
29
|
+
return !isEmpty(value)
|
30
|
+
}
|
31
|
+
|
32
|
+
export function isEIP1559(
|
33
|
+
transaction: CeloTransactionSerializable | CeloTransactionRequest,
|
34
|
+
): boolean {
|
35
|
+
return (
|
36
|
+
isPresent(transaction.maxFeePerGas) &&
|
37
|
+
isPresent(transaction.maxPriorityFeePerGas)
|
38
|
+
)
|
39
|
+
}
|
40
|
+
|
41
|
+
// process as CIP42 if any of these fields are present. realistically gatewayfee is not used but is part of spec
|
42
|
+
export function isCIP42(
|
43
|
+
transaction: CeloTransactionSerializable | CeloTransactionRequest,
|
44
|
+
): transaction is TransactionSerializableCIP42 {
|
45
|
+
// Enable end-user to force the tx to be considered as a cip42
|
46
|
+
if (transaction.type) return transaction.type === 'cip42'
|
47
|
+
|
48
|
+
return (
|
49
|
+
isEIP1559(transaction) &&
|
50
|
+
(isPresent(transaction.feeCurrency) ||
|
51
|
+
isPresent(transaction.gatewayFeeRecipient) ||
|
52
|
+
isPresent(transaction.gatewayFee))
|
53
|
+
)
|
54
|
+
}
|
55
|
+
|
56
|
+
export function isCIP64(
|
57
|
+
transaction: CeloTransactionSerializable | CeloTransactionRequest,
|
58
|
+
): transaction is TransactionSerializableCIP64 {
|
59
|
+
// Enable end-user to force the tx to be considered as a cip64
|
60
|
+
if (transaction.type) return transaction.type === 'cip64'
|
61
|
+
|
62
|
+
return (
|
63
|
+
isEIP1559(transaction) &&
|
64
|
+
isPresent(transaction.feeCurrency) &&
|
65
|
+
isEmpty(transaction.gatewayFee) &&
|
66
|
+
isEmpty(transaction.gatewayFeeRecipient)
|
67
|
+
)
|
68
|
+
}
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.0.0-main.
|
1
|
+
export const version = '0.0.0-main.20231105T211250'
|
package/package.json
CHANGED