Description:
Smart contract deployed on Ethereum with Factory, Oracle features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/EIP7702Delegate.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}
/**
* @title EIP7702Delegate
* @dev Contract code that EOAs can delegate to via EIP-7702 for gasless transactions
* This contract allows paying gas fees with ERC20 tokens (like USDC)
*/
contract EIP7702Delegate {
// Events
event GaslessTransfer(
address indexed from,
address indexed to,
uint256 amount,
address token,
uint256 gasPaid
);
// State variables for gas payment configuration
mapping(address => bool) public authorizedRelayers;
mapping(address => uint256) public tokenGasPrice; // Gas price in token units
address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; // Mainnet USDC
modifier onlyRelayer() {
require(
authorizedRelayers[msg.sender],
"Not authorized relayer"
);
_;
}
/**
* @dev Execute a gasless token transfer
* The EOA delegating to this contract will have their USDC used for gas payment
*/
function executeGaslessTransfer(
address token,
address to,
uint256 amount,
uint256 maxGasPayment
) external returns (bool) {
// Calculate actual gas cost in USDC
uint256 gasUsed = gasleft();
uint256 gasPayment = calculateGasPayment(
gasUsed
);
require(
gasPayment <= maxGasPayment,
"Gas payment exceeds maximum"
);
// Transfer the tokens
require(
IERC20(token).transfer(to, amount),
"Token transfer failed"
);
// Pay for gas in USDC to the relayer
require(
IERC20(USDC).transfer(
tx.origin,
gasPayment
),
"Gas payment failed"
);
emit GaslessTransfer(
address(this),
to,
amount,
token,
gasPayment
);
return true;
}
/**
* @dev Execute any call with gas paid in USDC
*/
function executeWithGasPayment(
address target,
bytes calldata data,
uint256 maxGasPayment
)
external
returns (bytes memory)
{
uint256 gasStart = gasleft();
// Execute the call
(bool success, bytes memory result) = target.call(data);
require(success, "Call failed");
// Calculate and pay for gas
uint256 gasUsed = gasStart - gasleft();
uint256 gasPayment = calculateGasPayment(gasUsed);
require(gasPayment <= maxGasPayment, "Gas payment exceeds maximum");
// Pay for gas in USDC
require(IERC20(USDC).transfer(tx.origin, gasPayment), "Gas payment failed");
return result;
}
/**
* @dev Calculate gas payment in USDC based on current rates
*/
function calculateGasPayment(
uint256 gasUsed
)
public
pure
returns (uint256)
{
// In production, this would use an oracle for accurate ETH/USDC pricing
// For demo: assume 1 ETH = 2000 USDC, gas price = 30 gwei
uint256 gasPrice = 30 * 10**9; // 30 gwei
uint256 gasCostInWei = gasUsed * gasPrice;
uint256 ethToUsdc = 2000; // $2000 per ETH
// Convert to USDC (6 decimals)
uint256 gasCostInUsdc = (gasCostInWei * ethToUsdc * 10**6) / 10**18;
// Add 10% relayer fee
return gasCostInUsdc * 110 / 100;
}
/**
* @dev Allows the delegating EOA to execute any action
*/
fallback()
external
payable
{
// This allows the EOA to retain full functionality
// while also having access to gasless features
}
receive()
external
payable {}
}"
}
},
"settings": {
"remappings": [
"@balancer-labs/v3-interfaces/=lib/balancer-v3-monorepo/pkg/interfaces/",
"@balancer-labs/v3-vault/=lib/balancer-v3-monorepo/pkg/vault/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"permit2/=lib/permit2/",
"@ensdomains/=node_modules/@ensdomains/",
"@ethereum-waffle/=node_modules/@ethereum-waffle/",
"balancer-v3-monorepo/=lib/balancer-v3-monorepo/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"eth-gas-reporter/=node_modules/eth-gas-reporter/",
"forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=node_modules/hardhat/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solmate/=lib/permit2/lib/solmate/"
],
"optimizer": {
"enabled": true,
"runs": 999999
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "shanghai",
"viaIR": false
}
}}
Submitted on: 2025-09-22 12:23:23
Comments
Log in to comment.
No comments yet.