MCPcopy Create free account
hub / github.com/wevm/viem / assertTransactionCIP42

Function assertTransactionCIP42

src/celo/serializers.ts:82–136  ·  view source on GitHub ↗
(
  transaction: TransactionSerializableCIP42,
)

Source from the content-addressed store, hash-verified

80const MAX_MAX_FEE_PER_GAS = maxUint256
81
82export function assertTransactionCIP42(
83 transaction: TransactionSerializableCIP42,
84) {
85 const {
86 chainId,
87 maxPriorityFeePerGas,
88 gasPrice,
89 maxFeePerGas,
90 to,
91 feeCurrency,
92 gatewayFee,
93 gatewayFeeRecipient,
94 } = transaction
95 if (chainId <= 0) throw new InvalidChainIdError({ chainId })
96 if (to && !isAddress(to)) throw new InvalidAddressError({ address: to })
97 if (gasPrice)
98 throw new BaseError(
99 '`gasPrice` is not a valid CIP-42 Transaction attribute.',
100 )
101
102 if (isPresent(maxFeePerGas) && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
103 throw new FeeCapTooHighError({ maxFeePerGas })
104
105 if (
106 isPresent(maxPriorityFeePerGas) &&
107 isPresent(maxFeePerGas) &&
108 maxPriorityFeePerGas > maxFeePerGas
109 )
110 throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
111
112 if (
113 (isPresent(gatewayFee) && isEmpty(gatewayFeeRecipient)) ||
114 (isPresent(gatewayFeeRecipient) && isEmpty(gatewayFee))
115 ) {
116 throw new BaseError(
117 '`gatewayFee` and `gatewayFeeRecipient` must be provided together.',
118 )
119 }
120
121 if (isPresent(feeCurrency) && !isAddress(feeCurrency)) {
122 throw new BaseError(
123 '`feeCurrency` MUST be a token address for CIP-42 transactions.',
124 )
125 }
126
127 if (isPresent(gatewayFeeRecipient) && !isAddress(gatewayFeeRecipient)) {
128 throw new InvalidAddressError(gatewayFeeRecipient)
129 }
130
131 if (isEmpty(feeCurrency) && isEmpty(gatewayFeeRecipient)) {
132 throw new BaseError(
133 'Either `feeCurrency` or `gatewayFeeRecipient` must be provided for CIP-42 transactions.',
134 )
135 }
136}
137
138export function assertTransactionCIP64(
139 transaction: TransactionSerializableCIP64,

Callers 1

parseTransactionCIP42Function · 0.85

Calls 3

isPresentFunction · 0.85
isEmptyFunction · 0.85
isAddressFunction · 0.50

Tested by

no test coverage detected