Production-grade arbitrage executor with flash loans (Morpho, Balancer) and a Node.js strategy bot leveraging 0x Swap API.
contracts: SolidityExecutorwith OpenZeppelin security (Ownable2Step, Pausable, ReentrancyGuard, SafeERC20).bot: Typescript bot scanning pairs, sizing, quoting with 0x, and submitting private txs.ops: Systemd service example.
- Foundry (forge 1.2+), Node.js 20+
- Mainnet RPC and 0x API key (optional but recommended)
cd contracts
forge build
export PRIVATE_KEY=0x...
export PAYOUT_WALLET=0xYourTreasury
export BOT_EXECUTOR=0xYourBotEOA
forge script script/Deploy.s.sol:Deploy --rpc-url $RPC_URL --broadcast -vvvv
Create bot/.env:
RPC_URL=...
PROTECT_RPC=https://protect.flashbots.net
BOT_PRIVATE_KEY=0x...
EXECUTOR=0xDeployedExecutor
ZRX_API=https://api.0x.org/swap/v1/quote
ZRX_ORDERBOOK=https://api.0x.org/orderbook/v1
ZRX_API_KEY=your_key_optional
USDC=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
WETH=0xC02aaA39b223FE8D0a0e5C4F27eAD9083C756Cc2
MIN_PROFIT_USD=100000000
MAX_FLASH_USD=100000000000
GAS_BUFFER_USD=2000000
FLASH_SOURCE=morpho
Build and run:
cd bot
npm i
npm run build
node dist/index.js
- Executor whitelists 0x
ExchangeProxyandAllowanceTargetand restrictsexecuteto configured bot EOAs. - Balancer flash loan is repaid explicitly; Morpho pull is approved once via
forceApprove. - Profits are enforced in USDC and swept to
payoutWalleteach run. - Use private transactions to avoid frontrunning.