### Example ERC20 Fee Conversion Calculation Source: https://docs.morph.network/docs/about-morph/altfeetx Demonstrates the calculation of ERC-20 token amount for a given ETH amount, using specific price, decimal, and scale parameters. Shows the intermediate tokenRate calculation and the final tokenAmount. ```solidity tokenRate = 1*(1/4000)*1e12 = 250000000 If ethAmount = 0.00000001 ETH (10 gwei): tokenAmount = (1e10 * 1) / 250000000 = 40 (USDC smallest units) ``` -------------------------------- ### AltFeeTx Go Struct Definition Source: https://docs.morph.network/docs/about-morph/altfeetx Defines the Go struct for an AltFeeTx, detailing all fields including standard transaction parameters and the new FeeTokenID and FeeLimit for alternative fee payments. ```go type AltFeeTx struct { ChainID *big.Int // Chain ID for replay protection Nonce uint64 // Sender's nonce GasTipCap *big.Int // Max priority fee per gas (in ETH units) GasFeeCap *big.Int // Max fee per gas (in ETH units) Gas uint64 // Gas limit To *common.Address // Recipient (nil for contract creation) Value *big.Int // ETH value to transfer Data []byte // Transaction data AccessList AccessList // EIP-2930 access list // AltFeeTx-specific fields FeeTokenID uint16 // ERC20 token ID for fee payment (0 = ETH) FeeLimit *big.Int // Maximum fee in token units (optional) // Signature values V *big.Int R *big.Int S *big.Int } ``` -------------------------------- ### Calculate Gas Refund in Tokens Source: https://docs.morph.network/docs/about-morph/altfeetx Calculates the refund for unused gas and converts it into the equivalent amount of the selected token. Ensures users are only charged for the gas actually consumed during transaction execution. ```solidity remaining = remainingGas * effectiveGasPrice remainingToken = ⌈(remaining × tokenScale) / tokenRate⌉ ``` -------------------------------- ### Convert ETH Fee to ERC20 Tokens Source: https://docs.morph.network/docs/about-morph/altfeetx Converts the total ETH fee into the equivalent amount of a selected ERC-20 token. Uses a ceiling function to round up, preventing precision loss and ensuring sufficient token amount. Requires token scale and rate for conversion. ```solidity tokenAmount = ⌈(ethAmount × tokenScale) / tokenRate⌉ ``` -------------------------------- ### RLP Encoding for Transactions Source: https://docs.morph.network/docs/about-morph/altfeetx Serializes transaction data into a space-efficient RLP format for network transmission. Includes all relevant transaction parameters. ```Solidity rlp([chainID, nonce, gasTipCap, gasFeeCap, gas, to, value, data, accessList, feeTokenID, feeLimit, v, r, s]) ``` -------------------------------- ### Empty Code Hash Source: https://docs.morph.network/docs/about-morph/eip7702 If the delegation marker points to the zero address, the account's code is cleared by resetting the code hash to the empty code hash. ```solidity 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 ``` -------------------------------- ### TokenInfo Structure for Token Registry Source: https://docs.morph.network/docs/about-morph/altfeetx Defines the structure for storing essential information about ERC-20 tokens eligible for gas payments. Includes token address, balance slot, activity status, decimals, and conversion scale. ```solidity struct TokenInfo { address tokenAddress; // ERC20 token contract address bytes32 balanceSlot; // Storage slot for balances bool isActive; // Whether token is enabled for fee payment uint8 decimals; // Token decimals uint256 scale; // Conversion scale factor } ``` -------------------------------- ### Calculate ETH Fee (EIP-1559) Source: https://docs.morph.network/docs/about-morph/altfeetx Calculates the total ETH fee for an L2 transaction using the EIP-1559 model, including L2 gas and L1 data fees. Ensure gas, tip cap, fee cap, and base fee are correctly provided. ```solidity effectiveGasPrice = min(GasTipCap, GasFeeCap - baseFee) + baseFee l2Fee = Gas * effectiveGasPrice l1DataFee = calculateL1DataFee(data) totalFeeETH = l2Fee + l1DataFee ``` -------------------------------- ### AltFeeTx RLP Encoding Structure Source: https://docs.morph.network/docs/about-morph/altfeetx This represents the RLP-encoded structure of an AltFeeTx, including standard transaction fields and the new FeeTokenID and FeeLimit fields. ```go rlp([chainID, nonce, gasTipCap, gasFeeCap, gas, to, value, data, accessList, feeTokenID, feeLimit, v, r, s]) ``` -------------------------------- ### EIP-7702 Authorization Entry Field Constraints Source: https://docs.morph.network/docs/about-morph/eip7702 Details the constraints and expected data types for each field within an authorization entry in the authorization_list for EIP-7702 transactions. ```python assert auth.chain_id < 2**256 assert auth.nonce < 2**64 assert len(auth.address) == 20 assert auth.y_parity < 2**8 assert auth.r < 2**256 assert auth.s < 2**256 ``` -------------------------------- ### Delegation Marker Byte Source: https://docs.morph.network/docs/about-morph/eip7702 The delegation marker is a reserved opcode (0xef) followed by the address of the delegated code. This marker is used to indicate that an account's code should be treated differently. ```solidity 0xef0100 || address ``` -------------------------------- ### Transaction Signature Hash Calculation Source: https://docs.morph.network/docs/about-morph/altfeetx Calculates the Keccak-256 hash of the RLP-encoded transaction data, excluding signature components, for signature verification purposes. ```Solidity sigHash = keccak256(0x7F || rlp([ chainID, nonce, gasTipCap, gasFeeCap, gas, to, value, data, accessList, feeTokenID, feeLimit ])) ``` -------------------------------- ### Additional Gas Cost for Authorizations Source: https://docs.morph.network/docs/about-morph/eip7702 This snippet shows the additional gas cost incurred per authorization when using delegation markers. ```plaintext + PER_EMPTY_ACCOUNT_COST * number_of_authorizations ``` -------------------------------- ### Direct Slot Update for ERC20 Balance Source: https://docs.morph.network/docs/about-morph/altfeetx Updates ERC-20 token balances directly in storage when the balance slot is known and non-zero. This method is more efficient than EVM calls, offering deterministic gas costs and avoiding external contract execution. ```solidity senderSlot = keccak256(abi.encode(senderAddress, balanceSlot)) recipientSlot = keccak256(abi.encode(recipientAddress, balanceSlot)) senderBalance = stateDB.GetState(tokenAddress, senderSlot) require(senderBalance >= amount) stateDB.SetState(tokenAddress, senderSlot, senderBalance - amount) stateDB.SetState(tokenAddress, recipientSlot, recipientBalance + amount) ``` -------------------------------- ### ERC-20 Token Transfer with EVM Call Source: https://docs.morph.network/docs/about-morph/altfeetx Handles ERC-20 token transfers, ensuring compatibility and verifying balances before and after the operation. Requires sender balance to be sufficient. ```Solidity // Get balance before transfer balanceBefore = IERC20(token).balanceOf(sender) require(balanceBefore >= amount) // Execute transfer bool success = IERC20(token).transfer(recipient, amount) if success.exist(){ require(success) } // Verify balance after transfer balanceAfter = IERC20(token).balanceOf(sender) require(balanceAfter == balanceBefore - amount) ``` -------------------------------- ### Calculate Token Rate Source: https://docs.morph.network/docs/about-morph/altfeetx Calculates the scaled token-to-ETH rate, adjusting for differences in token and ETH decimal precision. This formula is used by trusted Oracle services to synchronize rates to the system contract. ```solidity tokenRate = tokenScale * (tokenPrice / ethPrice) × 10^(ethDecimals - tokenDecimals) ``` -------------------------------- ### EIP-2930 Gas Calculation Source: https://docs.morph.network/docs/about-morph/eip7702 This snippet outlines the intrinsic gas costs for transactions following EIP-2930 rules, including base costs, calldata costs, and access list costs. ```plaintext 21000 + 16 * nonzero calldata byte + 4 * zero calldata byte + 1900 * per storage key in the access list + 2400 * per address in the access list ``` -------------------------------- ### EIP-7702 Receipt Payload Structure Source: https://docs.morph.network/docs/about-morph/eip7702 Specifies the structure of the EIP-2718 receipt payload for the Set Code Transaction type, including status, cumulative gas used, logs bloom, and logs. ```rlp rlp([status, cumulative_transaction_gas_used, logs_bloom, logs]). ``` -------------------------------- ### EIP-7702 Transaction Format: Set Code Transaction Source: https://docs.morph.network/docs/about-morph/eip7702 Defines the RLP encoding structure for a new EIP-2718 typed transaction (SET_CODE_TX_TYPE) used for delegated execution. Includes standard fields, destination, value, data, access list, and an authorization list. ```rlp rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, value, data, access_list, authorization_list, signature_y_parity, signature_r, signature_s]) authorization_list = [[chain_id, address, nonce, y_parity, r, s], ...] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.