( transaction: TransactionSerializableCIP42, )
| 80 | const MAX_MAX_FEE_PER_GAS = maxUint256 |
| 81 | |
| 82 | export 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 | |
| 138 | export function assertTransactionCIP64( |
| 139 | transaction: TransactionSerializableCIP64, |
no test coverage detected