Arbitrage Strategies
Arbitrage strategies exploit price differences between decentralized exchanges. These opportunities arise due to market inefficiencies, liquidity fragmentation, and delayed price updates across different platforms.
Cross-Exchange Arbitrage
Multi-DEX Monitoring
Simultaneously track prices across Uniswap, SushiSwap, PancakeSwap, and others
Profit Calculation
Account for gas costs, slippage, and MEV competition in profit estimates
Rapid Execution
Execute buy and sell orders simultaneously to lock in profits
class ArbitrageBot {
constructor(provider, apiKey) {
this.provider = provider;
this.poipoe = new PoIPoE({ apiKey });
}
async findArbitrageOpportunities() {
const assets = ['ETH', 'BTC', 'LINK', 'UNI'];
const opportunities = [];
for (const asset of assets) {
const prices = await this.getDexPrices(asset);
const maxPrice = Math.max(...prices);
const minPrice = Math.min(...prices);
const spread = maxPrice - minPrice;
if (spread > this.minProfitThreshold) {
opportunities.push({
asset,
buyDex: prices.indexOf(minPrice),
sellDex: prices.indexOf(maxPrice),
spread,
profit: this.calculateProfit(spread)
});
}
}
return opportunities;
}
async executeArbitrage(opportunity) {
const { buyDex, sellDex, asset, amount } = opportunity;
// Simultaneous execution
const [buyTx, sellTx] = await Promise.all([
this.buyOnDex(buyDex, asset, amount),
this.sellOnDex(sellDex, asset, amount)
]);
return { buyTx, sellTx };
}
}
Triangular Arbitrage
Exploit price discrepancies within a single DEX by trading through three assets in a cycle. For example: ETH → USDC → DAI → ETH, profiting from rounding errors and market inefficiencies.
Market Conditions
Best in volatile markets with high trading volume and fragmented liquidity
Capital Requirements
Minimum $10K-50K for consistent opportunities, higher for better execution
Expected Returns
0.1-2% per opportunity, 5-20% monthly returns in optimal conditions
Liquidation Strategies
Liquidation strategies monitor lending protocols for undercollateralized positions and compete to liquidate them first, earning liquidation bonuses and protocol rewards.
Protocol Monitoring
Monitor Health Factors
Continuously track borrowing positions across Aave, Compound, and other protocols
Predict Liquidations
Use price feeds and volatility models to predict when positions will be liquidatable
Compete for Execution
Submit liquidation transactions with optimal gas pricing to win the race
Claim Rewards
Receive liquidation bonuses plus seized collateral at discounted prices
class LiquidationBot {
constructor(provider, protocols) {
this.provider = provider;
this.protocols = protocols;
this.gasOptimizer = new GasOptimizer();
}
async findLiquidations() {
const liquidations = [];
for (const protocol of this.protocols) {
const positions = await protocol.getRiskyPositions();
for (const position of positions) {
const healthFactor = await this.calculateHealthFactor(position);
if (healthFactor < 1.0) {
const profit = await this.estimateLiquidationProfit(position);
const gasCost = await this.estimateGasCost(position);
if (profit > gasCost * 2) {
liquidations.push({
protocol: protocol.name,
position,
healthFactor,
profit,
gasCost
});
}
}
}
}
return liquidations.sort((a, b) => (b.profit - b.gasCost) - (a.profit - a.gasCost));
}
async executeLiquidation(liquidation) {
// Submit with optimized gas price
const gasPrice = await this.gasOptimizer.getOptimalGasPrice();
return await this.protocols[liquidation.protocol].liquidate(
liquidation.position,
{ gasPrice }
);
}
}
Sandwich Attack Strategies
Sandwich attacks manipulate the price impact of target trades by placing orders before and after them, extracting value from the victim's slippage tolerance.
Attack Pattern
Target Selection
Identify large trades with significant price impact and generous slippage
Price Manipulation
Execute buy order to pump price, wait for victim trade, then sell for profit
Timing Critical
All three transactions must be included in the same block to succeed
class SandwichAttack {
constructor(provider, targetTx) {
this.provider = provider;
this.targetTx = targetTx;
this.gasMultiplier = 1.2; // Beat competitor gas prices
}
async analyzeTarget() {
const trade = this.targetTx;
// Calculate expected price impact
const priceImpact = await this.calculatePriceImpact(trade);
const slippage = trade.slippage || 0.05; // 5% default
if (priceImpact > slippage) {
const profit = await this.estimateSandwichProfit(trade);
return { viable: profit > 0, profit, priceImpact };
}
return { viable: false, reason: 'Insufficient price impact' };
}
async executeSandwich() {
// 1. Pre-trade: Buy to pump price
const preTradeTx = await this.createBuyOrder();
// 2. Wait for target transaction
await this.waitForTargetTransaction();
// 3. Post-trade: Sell to capture profit
const postTradeTx = await this.createSellOrder();
// Bundle all transactions
return await this.bundleTransactions([preTradeTx, postTradeTx]);
}
}
Risk Profile
High risk due to price prediction accuracy and MEV competition
Execution Speed
Requires sub-second response times and optimal gas pricing
Ethical Considerations
These attacks are controversial and may be considered exploitative
Backrunning Strategies
Backrunning involves placing transactions immediately after profitable events to capture residual value. Unlike sandwich attacks, backrunning doesn't manipulate prices but exploits naturally occurring opportunities.
Common Backrun Types
Oracle Updates
Trade on price discrepancies after oracle updates before markets adjust
Token Unlocks
Execute trades immediately after token unlock events create price movements
Failed Transactions
Capitalize on failed large transactions that created temporary price impact
NFT MEV Strategies
NFT MEV focuses on capturing value from NFT minting, trading, and listing events. This includes mint sniping, floor sweeping, and rarity-based arbitrage opportunities.
NFT Strategy Types
Mint Sniping
Automatically mint newly released NFTs at the lowest possible gas price
Floor Sweeping
Buy NFTs below floor price and immediately relist to profit from spreads
Rarity Arbitrage
Identify undervalued rare traits and profit from market inefficiencies
Flashloan Arbitrage
Flashloan arbitrage uses uncollateralized loans from protocols like Aave to execute complex arbitrage strategies in a single transaction, eliminating capital requirements.
// Flashloan Arbitrage Contract
contract FlashLoanArbitrage {
IERC20 public token0;
IERC20 public token1;
IUniswapV2Router public router;
IAavePool public aavePool;
function executeFlashLoan(uint256 amount) external {
// 1. Borrow flashloan
aavePool.flashLoan(
address(this),
address(token0),
amount,
address(this),
0,
new bytes(0)
);
}
// Aave callback
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address initiator,
bytes calldata params
) external override returns (bool) {
// 2. Execute arbitrage strategy
uint256 profit = performArbitrage(amount);
// 3. Repay flashloan + premium
uint256 repayment = amount + premium;
require(profit > repayment, "No profit");
token0.transfer(address(aavePool), repayment);
// 4. Keep the difference
uint256 keptProfit = profit - repayment;
token0.transfer(msg.sender, keptProfit);
return true;
}
}