Verified contractPartialUNLICENSED
StrategyExecutor
Address0x68d3a973e7272eb388022a5c6518d9b2a2e66fbf
- Balance
0 ETH
- Transactions
1,731,910
- 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
- paris
- License
- UNLICENSED
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 20,168,374
- Creation transaction
- 0xe3a084c73d…2f8bc8ffa3
9 files
- StrategyExecutor.solmain641 B
- Admin.sol1.7 KB
- Arbitrage.sol4.2 KB
- Callbacks.sol1.35 KB
- Interfaces.sol1.62 KB
- Roles.sol851 B
- Storage.sol2.05 KB
- Swaps.sol4.11 KB
- UnknownSelectors.sol844 B
StrategyExecutor.sol
// Rebuilt by the imd.fun swarm
// ◇ IMD · an onchain AI agent workforce · $IMD 0xD34a99Bc0f67aE1bbd63C660e6d0b0dd03E263B7
// Seat #783 · explorer.imd.fun/goals/550d462b-2dac-4e06-981a-d844034ddc92
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "./Roles.sol";
import "./Admin.sol";
import "./Swaps.sol";
import "./Arbitrage.sol";
import "./Callbacks.sol";
import "./UnknownSelectors.sol";
contract StrategyExecutor is Roles, Admin, Swaps, Arbitrage, Callbacks, UnknownSelectors {
constructor() {
owner = msg.sender;
swapState.pool = address(this);
}
receive() external payable {}
}
Admin.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "./Storage.sol";
import "./Interfaces.sol";
abstract contract Admin is StrategyStorage {
address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
function addToken_8zSNM7(address token) external onlyOwner {
_addToken(token);
}
function wrap_62lZAo() external payable {
IStrategyWETH(WETH).deposit{value: msg.value}();
}
function wrapETH_8tbLBk(uint256 amount) external {
require(imd_0000000006aa7afa[msg.sender], ";");
IStrategyWETH(WETH).deposit{value: amount}();
}
function withdraw() external onlyOwner {
(bool ok,) = payable(owner).call{value: address(this).balance}("");
require(ok, "f");
}
function withdrawETH_94X0gZ(address recipient, uint256 amount) external onlyRebalancerRecipient(recipient) {
IStrategyWETH(WETH).withdraw(amount);
(bool ok,) = payable(recipient).call{value: amount}("");
require(ok, "f");
}
function withdrawToken_61riqI(address recipient, address token, uint256 amount) external onlyRebalancerRecipient(recipient) {
IStrategyToken(token).transfer(recipient, amount);
}
function fundTraders(address[] calldata accounts, uint256[] calldata amounts) external onlyOwner {
require(accounts.length == amounts.length);
uint256 total;
for (uint256 i; i < amounts.length; ++i) total += amounts[i];
IStrategyWETH(WETH).withdraw(total);
for (uint256 i; i < amounts.length; ++i) {
(bool ok,) = payable(accounts[i]).call{value: amounts[i]}("");
require(ok, "f");
}
}
}
Arbitrage.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "./Storage.sol";
import "./Interfaces.sol";
abstract contract Arbitrage is StrategyStorage {
function arbV2b_0y21qv(
address pair,
bool oneForZero,
uint256 amountIn,
uint256 maxReserveIn,
address tokenIn,
uint256 gasCost,
uint256 priceIn,
uint256 priceOut,
uint256 bribeBps,
uint256 kLast,
address coinbase
) external payable correctBlock onlyTrader(pair) {
require(block.coinbase == coinbase, "C");
require(int256(gasCost) > 0, "G");
require(bribeBps < 10000, "B");
(uint256 spent, uint256 received) = _arbV2Swap(pair, oneForZero, amountIn, maxReserveIn, tokenIn, kLast);
int256 gain = (int256(received) * int256(priceOut) - int256(spent) * int256(priceIn)) / int256(1 ether) - int256(gasCost);
require(gain > 0, "L");
uint256 bribe = uint256(gain) * bribeBps / 10000;
if (bribe > address(this).balance) {
(bool ok,) = payable(block.coinbase).call{value: address(this).balance}("");
require(ok);
} else {
(bool ok,) = payable(block.coinbase).call{value: bribe}("");
require(ok);
}
}
function _arbV2Swap(
address pair,
bool oneForZero,
uint256 amountIn,
uint256 maxReserveIn,
address tokenIn,
uint256 kLast
) internal returns (uint256 spent, uint256 received) {
IStrategyV2Pair p = IStrategyV2Pair(pair);
require(kLast == p.kLast(), "k");
(uint112 reserve0, uint112 reserve1,) = p.getReserves();
if (oneForZero) {
require(maxReserveIn > reserve1, "s");
spent = (maxReserveIn - reserve1) * 1000 / 997;
if (amountIn < spent) spent = amountIn;
received = _getAmountOut(spent, reserve1, reserve0);
} else {
require(maxReserveIn > reserve0, "S");
spent = (maxReserveIn - reserve0) * 1000 / 997;
if (amountIn < spent) spent = amountIn;
received = _getAmountOut(spent, reserve0, reserve1);
}
IStrategyToken token = IStrategyToken(tokenIn);
token.transfer(pair, spent);
if (oneForZero) {
p.swap(received, 0, address(this), bytes(""));
} else {
p.swap(0, received, address(this), bytes(""));
}
}
function arbV3b_0ye3FH(
address pool,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
address tokenIn,
uint256 gasCost,
uint256 price0,
uint256 price1,
uint256 bribeBps,
address coinbase
) external payable correctBlock onlyTrader(pool) {
require(block.coinbase == coinbase, "C");
require(int256(gasCost) > 0, "G");
require(bribeBps < 10000, "B");
(int256 amount0, int256 amount1) = _arbV3Swap(swapState, pool, zeroForOne, amountSpecified, sqrtPriceLimitX96, tokenIn);
int256 gain = ((-amount0) * int256(price0) - amount1 * int256(price1)) / int256(1 ether) - int256(gasCost);
require(gain > 0, "L");
uint256 bribe = uint256(gain) * bribeBps / 10000;
if (bribe > address(this).balance) {
(bool ok,) = payable(block.coinbase).call{value: address(this).balance}("");
require(ok);
} else {
(bool ok,) = payable(block.coinbase).call{value: bribe}("");
require(ok);
}
}
function _arbV3Swap(
SwapState storage state,
address pool,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
address tokenIn
) internal returns (int256 amount0, int256 amount1) {
state.pool = pool;
state.amount = uint256(amountSpecified);
IStrategyV3Pool p = IStrategyV3Pool(pool);
(amount0, amount1) = p.swap(
address(this), zeroForOne, amountSpecified, sqrtPriceLimitX96, abi.encode(tokenIn, zeroForOne)
);
require(state.pool == address(this), "x");
require(state.amount == 0, "y");
}
}
Callbacks.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "./Storage.sol";
import "./Interfaces.sol";
abstract contract Callbacks is StrategyStorage {
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external {
_swapCallback(swapState, amount0Delta, amount1Delta, data);
}
function pancakeV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external {
_swapCallback(swapState, amount0Delta, amount1Delta, data);
}
function _swapCallback(SwapState storage state, int256 amount0Delta, int256 amount1Delta, bytes calldata data) internal {
require(msg.sender == state.pool, "wtf");
state.pool = address(this);
(address token, bool zeroForOne) = abi.decode(data, (address, bool));
if (zeroForOne) {
require(amount0Delta <= int256(state.amount), "o");
state.amount = 0;
IStrategyToken tokenContract = IStrategyToken(token);
tokenContract.transfer(msg.sender, uint256(amount0Delta));
} else {
require(amount1Delta <= int256(state.amount), "o");
state.amount = 0;
IStrategyToken tokenContract = IStrategyToken(token);
tokenContract.transfer(msg.sender, uint256(amount1Delta));
}
}
}
Interfaces.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
interface IStrategyToken {
function approve(address spender, uint256 amount) external;
function transfer(address recipient, uint256 amount) external;
}
interface IStrategyWETH {
function deposit() external payable;
function withdraw(uint256 amount) external;
}
interface IStrategyV3Pool {
function swap(address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data) external returns (int256 amount0, int256 amount1);
}
interface IStrategyBalancerPool {
function swapExactAmountIn(address tokenIn, uint256 amountIn, address tokenOut, uint256 minAmountOut, uint256 maxPrice) external;
}
interface IStrategyV2Pair {
function kLast() external view returns (uint256);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 timestampLast);
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
}
interface IStrategyAsset {}
interface IStrategyBalancerVault {
enum SwapKind { GIVEN_IN, GIVEN_OUT }
struct SingleSwap {
bytes32 poolId;
SwapKind kind;
IStrategyAsset assetIn;
IStrategyAsset assetOut;
uint256 amount;
bytes userData;
}
struct FundManagement {
address sender;
bool fromInternalBalance;
address payable recipient;
bool toInternalBalance;
}
function swap(SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline) external payable returns (uint256);
}
Roles.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "./Storage.sol";
abstract contract Roles is StrategyStorage {
function grantRebalancerRole(address account) external onlyOwner {
_grantRebalancer(account);
}
function revokeRebalancerRole(address account) external onlyOwner {
imd_0000000006aa7afa[account] = false;
}
function grantTraderRole(address account) external onlyOwner {
_grantTrader(account);
}
function revokeTraderRole(address account) external onlyOwner {
imd_000000008ccdb524[account] = false;
}
function grantRecipientRole_1rGXXA(address account) external onlyOwner {
_grantRecipient(account);
}
function revokeRecipientRole_19Gx2g(address account) external onlyOwner {
imd_0000000015096b66[account] = false;
}
}
Storage.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "./Interfaces.sol";
abstract contract StrategyStorage {
address internal owner; // slot 0
mapping(address => bool) public imd_000000008ccdb524; // slot 1
mapping(address => bool) public imd_0000000006aa7afa; // slot 2
mapping(address => bool) public imd_000000024e34972c; // slot 3
mapping(address => bool) public imd_0000000015096b66; // slot 4
struct SwapState {
uint256 amount;
address pool;
}
SwapState internal swapState; // slots 5 and 6
modifier onlyOwner() {
require(msg.sender == owner, "!");
_;
}
modifier correctBlock() {
require(block.number == msg.value, "b");
_;
}
modifier onlyTrader(address pool) {
require(imd_000000008ccdb524[msg.sender], "?");
require(imd_000000024e34972c[pool], "a");
_;
}
modifier onlyRebalancerRecipient(address recipient) {
require(imd_0000000006aa7afa[msg.sender], ";");
require(imd_0000000015096b66[recipient], "t");
_;
}
function _getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) internal pure returns (uint256) {
uint256 amountInWithFee = amountIn * 997;
uint256 numerator = amountInWithFee * reserveOut;
uint256 denominator = reserveIn * 1000 + amountInWithFee;
return numerator / denominator;
}
function _addToken(address token) internal {
IStrategyToken(token).approve(owner, type(uint256).max);
}
function _grantTrader(address account) internal {
imd_000000008ccdb524[account] = true;
}
function _grantOperator(address account) internal {
imd_000000024e34972c[account] = true;
}
function _grantRecipient(address account) internal {
imd_0000000015096b66[account] = true;
}
function _grantRebalancer(address account) internal {
imd_0000000006aa7afa[account] = true;
}
}
Swaps.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "./Storage.sol";
import "./Interfaces.sol";
abstract contract Swaps is StrategyStorage {
address internal constant BALANCER_VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
function swapBalancerV2_63j4UQ(bytes32 poolId, address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut) external payable correctBlock onlyTrader(address(bytes20(poolId))) {
_swapBalancerVault(poolId, tokenIn, tokenOut, amountIn, minAmountOut);
}
function _swapBalancerVault(bytes32 poolId, address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut) internal {
IStrategyToken(tokenIn).approve(BALANCER_VAULT, amountIn + 1);
IStrategyBalancerVault(BALANCER_VAULT).swap(
IStrategyBalancerVault.SingleSwap({
poolId: poolId,
kind: IStrategyBalancerVault.SwapKind.GIVEN_IN,
assetIn: IStrategyAsset(tokenIn),
assetOut: IStrategyAsset(tokenOut),
amount: amountIn,
userData: ""
}),
IStrategyBalancerVault.FundManagement({
sender: address(this),
fromInternalBalance: false,
recipient: payable(address(this)),
toInternalBalance: false
}),
minAmountOut,
block.timestamp
);
}
function imd_00000000b519b5ed(address pair, bool oneForZero, uint256 amountIn, uint256 minAmountOut, address tokenIn) external payable correctBlock onlyTrader(pair) {
_swapV2(pair, oneForZero, amountIn, minAmountOut, tokenIn);
}
function _swapV2(address pair, bool oneForZero, uint256 amountIn, uint256 minAmountOut, address tokenIn) internal {
uint256 amountOut;
IStrategyV2Pair p = IStrategyV2Pair(pair);
(uint112 reserve0, uint112 reserve1,) = p.getReserves();
if (oneForZero) {
amountOut = _getAmountOut(amountIn, reserve1, reserve0);
} else {
amountOut = _getAmountOut(amountIn, reserve0, reserve1);
}
require(amountOut >= minAmountOut, "n");
IStrategyToken token = IStrategyToken(tokenIn);
token.transfer(pair, amountIn);
if (oneForZero) {
p.swap(amountOut, 0, address(this), bytes(""));
} else {
p.swap(0, amountOut, address(this), bytes(""));
}
}
function swapV3b_2lJInn(address pool, bool zeroForOne, int256 amountSpecified, uint256 minAmountOut, address tokenIn) external payable correctBlock onlyTrader(pool) {
_swapV3(swapState, pool, zeroForOne, amountSpecified, minAmountOut, tokenIn);
}
function _swapV3(SwapState storage state, address pool, bool zeroForOne, int256 amountSpecified, uint256 minAmountOut, address tokenIn) internal {
state.pool = pool;
state.amount = uint256(amountSpecified);
IStrategyV3Pool p = IStrategyV3Pool(pool);
(int256 amount0, int256 amount1) = p.swap(
address(this), zeroForOne, amountSpecified,
zeroForOne ? uint160(4295128740) : uint160(1461446703485210103287273052203988822378723970341),
abi.encode(tokenIn, zeroForOne)
);
require(state.pool == address(this), "x");
require(state.amount == 0, "y");
if (zeroForOne) {
require(-amount1 >= int256(minAmountOut), "m");
} else {
require(-amount0 >= int256(minAmountOut), "M");
}
}
function swapBalancerV1_FQbkQe(address pool, address tokenIn, uint256 amountIn, address tokenOut, uint256 minAmountOut) external payable correctBlock onlyTrader(pool) {
_swapBalancer(pool, tokenIn, amountIn, tokenOut, minAmountOut);
}
function _swapBalancer(address pool, address tokenIn, uint256 amountIn, address tokenOut, uint256 minAmountOut) internal {
IStrategyToken(tokenIn).approve(pool, amountIn + 1);
IStrategyBalancerPool(pool).swapExactAmountIn(tokenIn, amountIn, tokenOut, minAmountOut, type(uint256).max);
}
}
UnknownSelectors.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "./Storage.sol";
abstract contract UnknownSelectors is StrategyStorage {
// Alternate names preserve the selectors when the original names are unavailable.
function imd_00000000423df052(address account) external onlyOwner {
_grantOperator(account);
}
function imd_000000000f3f485f(address account) external onlyOwner {
imd_000000024e34972c[account] = false;
}
function imd_000000014534d0e4(address[] calldata tokens, address[] calldata accounts, address[] calldata traders_) external onlyOwner {
for (uint256 i; i < tokens.length; ++i) _addToken(tokens[i]);
for (uint256 i; i < accounts.length; ++i) _grantOperator(accounts[i]);
for (uint256 i; i < traders_.length; ++i) _grantTrader(traders_[i]);
}
}
Compiler settingsShow
{
"viaIR": false,
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.