This repository contains an automated market maker (AMM) strategy that implements a yield optimizer with arbitrage detection for the NEAR blockchain ecosystem. The strategy focuses on buying CRANS tokens using NEAR while detecting and exploiting arbitrage opportunities across different liquidity pool routes.
- Direction: Buys CRANS tokens using NEAR
- Method: Multi-path arbitrage detection across various LP pairs
- Optimization: Yield maximization through route comparison and selection
The main yield optimization engine that:
- Manages the complete trading cycle from NEAR to CRANS
- Handles circular arbitrage routes for maximum yield
- Coordinates with Ref Finance DEX
- Implements safety mechanisms and cooldown periods
- Tracks and reports profit/loss
The arbitrage detection system that:
- Simulates multiple trading routes in real-time
- Compares expected returns across different LP paths
- Identifies the most profitable route for NEAR → CRANS conversion
- Validates arbitrage opportunities before execution
The system evaluates multiple routes for NEAR to CRANS conversion:
Primary Routes:
- NEAR → CRANS (direct)
- NEAR → SHITZU → CRANS
- NEAR → BD → CRANS
- NEAR → SIN → CRANS
- NEAR → PUMP → CRANS
Complex Multi-hop Routes:
- NEAR → SHITZU → BD → CRANS
- NEAR → BD → SHITZU → CRANS
Circular Arbitrage Routes:
- NEAR → CRANS → SHITZU → CRANS
- NEAR → CRANS → BD → CRANS
- NEAR → CRANS → SIN → CRANS
- NEAR → CRANS → PUMP → CRANS
- Base Amount: 0.3 NEAR per trade
- Cooldown: 1-3 minutes between cycles
- Safety Margin: 99.9% slippage protection
- Gas Limit: 300 TGas
- Minimum Threshold: 3 CRANS minimum output
- React
- NEAR
- Ref Finance SDK
- Big.js
- TypeScript
- NEAR wallet with NEAR tokens
- Ref Finance deposit for gas optimization
- Private key configuration
import { ArbitrageSupervisor } from './yieldOptimizer';
import { CransArbitrage } from './arbitrageDetector';
// Initialize yield optimizer
<ArbitrageSupervisor
isEnabled={true}
onProfit={(profit) => console.log('Profit:', profit)}
onRouteFound={(route) => console.log('Best route:', route)}
/>The system provides real-time monitoring of:
- NEAR to CRANS conversion efficiency
- Profit/loss tracking on circular routes
- Route performance comparison
- Gas usage optimization
- Market conditions analysis
- Balance Check: Verify NEAR token availability on Ref Finance
- Route Simulation: Test all possible NEAR → CRANS paths
- Arbitrage Detection: Identify most profitable route
- Circular Route Execution: Execute multi-step arbitrage cycles
- Profit Calculation: Track and report returns
- Withdrawal & Transfer: Move profits and manage liquidity
- Cooldown: Wait before next cycle
The strategy implements sophisticated circular arbitrage:
- NEAR Deposit: Ensures sufficient NEAR on Ref Finance
- Multi-step Swaps: Executes circular paths like NEAR → CRANS → Token → CRANS
- Profit Extraction: Withdraws accumulated CRANS tokens
- Balance Management: Maintains optimal liquidity ratios
Comprehensive logging system with:
- Detailed transaction logs with [ARB_LOG] prefix
- Route comparison data
- Balance tracking
- Error tracking and reporting
- Performance metrics
- Market condition alerts