Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/Flash Loan Chat GPT.sol": {
"content": "// SPDX-License-Identifier: MIT\r
pragma solidity ^0.8.20;\r
\r
/*\r
* Minimal educational flash-loan template\r
* (structure only – not profitable or production-ready)\r
*/\r
\r
interface IERC20 {\r
function balanceOf(address) external view returns (uint256);\r
function allowance(address, address) external view returns (uint256);\r
function approve(address, uint256) external returns (bool);\r
}\r
\r
interface IAavePool {\r
function flashLoanSimple(\r
address receiver,\r
address asset,\r
uint256 amount,\r
bytes calldata params,\r
uint16 referralCode\r
) external;\r
}\r
\r
interface IFlashLoanSimpleReceiver {\r
function executeOperation(\r
address asset,\r
uint256 amount,\r
uint256 premium,\r
address initiator,\r
bytes calldata params\r
) external returns (bool);\r
}\r
\r
contract FlashLoanExample is IFlashLoanSimpleReceiver {\r
address public immutable owner;\r
IAavePool public immutable pool;\r
IERC20 public immutable token;\r
\r
modifier onlyOwner() {\r
require(msg.sender == owner, "not owner");\r
_;\r
}\r
\r
constructor(address _pool, address _token) {\r
owner = msg.sender;\r
pool = IAavePool(_pool);\r
token = IERC20(_token);\r
}\r
\r
function initiate(uint256 amount) external onlyOwner {\r
bytes memory params = ""; // no parameters\r
pool.flashLoanSimple(address(this), address(token), amount, params, 0);\r
}\r
\r
function executeOperation(\r
address asset,\r
uint256 amount,\r
uint256 premium,\r
address initiator,\r
bytes calldata /*params*/\r
) external override returns (bool) {\r
require(msg.sender == address(pool), "bad caller");\r
require(initiator == address(this), "bad initiator");\r
require(asset == address(token), "asset mismatch");\r
\r
// your logic here (e.g. trades)\r
\r
// repay the loan + fee\r
uint256 totalOwed = amount + premium;\r
token.approve(address(pool), totalOwed);\r
return true;\r
}\r
}\r
"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-11-04 11:09:42
Comments
Log in to comment.
No comments yet.