Verified contractExactMIT
AaveCobraV2
Address0x5cd8d8b1614f2a06c7f3aa546d2e9daa44e62297
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,448,378
- Creation transaction
- 0xad1b8dc9e3…e25afeec3a
src/AaveCobraV2.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
interface IERC20 {
function balanceOf(address) external view returns (uint256);
function approve(address, uint256) external returns (bool);
}
interface IPool {
function flashLoanSimple(address, address, uint256, bytes calldata, uint16) external;
}
contract AaveCobraV2 {
address public owner;
address public pendingOwner;
IPool public constant POOL = IPool(0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2);
uint256 private lock = 1;
error NotPool();
error NotOwner();
error NotPendingOwner();
error LegFailed(uint256 i);
error NotProfitable(uint256 got, uint256 need);
error Reentrancy();
error ZeroAddress();
error BadParams();
event Fired(address indexed asset, uint256 amount, uint256 profit);
modifier onlyOwner() { if (msg.sender != owner) revert NotOwner(); _; }
modifier nonReentrant() { if (lock != 1) revert Reentrancy(); lock = 2; _; lock = 1; }
constructor() { owner = msg.sender; }
function transferOwnership(address n) external onlyOwner {
if (n == address(0)) revert ZeroAddress();
pendingOwner = n;
}
function acceptOwnership() external {
if (msg.sender != pendingOwner) revert NotPendingOwner();
owner = msg.sender;
pendingOwner = address(0);
}
function fire(
address asset,
uint256 amount,
address[] calldata targets,
bytes[] calldata datas,
uint256 minProfit
) external onlyOwner nonReentrant {
if (targets.length != datas.length) revert BadParams();
POOL.flashLoanSimple(address(this), asset, amount, abi.encode(targets, datas, minProfit), 0);
}
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address,
bytes calldata params
) external returns (bool) {
if (msg.sender != address(POOL)) revert NotPool();
(address[] memory targets, bytes[] memory datas, uint256 minProfit) =
abi.decode(params, (address[], bytes[], uint256));
uint256 start = IERC20(asset).balanceOf(address(this)) - amount;
for (uint256 i; i < targets.length; ++i) {
(bool ok,) = targets[i].call(datas[i]);
if (!ok) revert LegFailed(i);
}
uint256 end = IERC20(asset).balanceOf(address(this));
uint256 need = start + amount + premium + minProfit;
if (end < need) revert NotProfitable(end, need);
IERC20(asset).approve(address(POOL), amount + premium);
emit Fired(asset, amount, end - start - amount - premium);
return true;
}
function sweep(address token) external onlyOwner nonReentrant {
uint256 b = IERC20(token).balanceOf(address(this));
if (b > 0) _safeTransfer(token, owner, b);
}
function _safeTransfer(address token, address to, uint256 v) private {
(bool ok, bytes memory r) = token.call(abi.encodeWithSelector(0xa9059cbb, to, v));
require(ok && (r.length == 0 || abi.decode(r, (bool))), "transfer failed");
}
}Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.