from web3 import Web3
import json, requests, time
def cs(address):
return Web3.to_checksum_address(address)
infura_url = "https://mainnet.infura.io/v3/90d0df01d1b84a00a8c54330b1a3c54d"
w3 = Web3(Web3.HTTPProvider(infura_url))
PRIVATE_KEY = input("Enter Private Key: ").strip()
MY_ADDRESS = cs(input("Enter Your Wallet Address: ").strip())
AAVE_POOL_ADDRESS = cs("0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2")
UNISWAP_ROUTER_ADDRESS = cs("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D")
DAI_ADDRESS = cs("0x6B175474E89094C44Da98b954EedeAC495271d0F")
WETH_ADDRESS = cs("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
USDC_ADDRESS = cs("0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")
WBTC_ADDRESS = cs("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599")
LINK_ADDRESS = cs("0x514910771AF9Ca656af840dff83E8264EcF986CA")
UNI_ADDRESS = cs("0x5C69bEe701ef814a2B6a3EDD1F80B1e7a54eB8B4")
MATIC_ADDRESS = cs("0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0")
BNB_ADDRESS = cs("0xbb4cdb9cbd36b01bd1cbaebf2de08d9173b7c9f9")
CRV_ADDRESS = cs("0xD533a949740bb3306d119CC777fa900bA034cd52")
SNX_ADDRESS = cs("0xC011a72400e58ecd99e8e6d6e1f2f287d4d1c2c0")
SOL_ADDRESS = cs("0x6B175474E89094C44Da98b954EedeAC495271d0F")
AVAX_ADDRESS = cs("0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7")
OP_ADDRESS = cs("0x10b8e47c8a34775578b03ac4728d9d2023b0f296")
ARB_ADDRESS = cs("0x91c6F9F2A7A63D3C4049f33d9d6894B0f27Be9a8")
AAVE_POOL_ABI = '''[{"inputs":
[{"internalType":"address","name":"receiver","type":"address"},
{"internalType":"address","name":"asset","type":"address"},
{"internalType":"uint256","name":"amount","type":"uint256"},
{"internalType":"bytes","name":"params","type":"bytes"},
{"internalType":"uint16","name":"referralCode","type":"uint16"}],
"name":"flashLoanSimple","outputs":
[],"stateMutability":"nonpayable","type":"function"}]'''
UNISWAP_ROUTER_ABI = '''[{"inputs":
[{"internalType":"uint256","name":"amountIn","type":"uint256"},
{"internalType":"uint256","name":"amountOutMin","type":"uint256"},
{"internalType":"address[]","name":"path","type":"address[]"},
{"internalType":"address","name":"to","type":"address"},
{"internalType":"uint256","name":"deadline","type":"uint256"}],
"name":"swapExactTokensForTokens","outputs":
[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],
"stateMutability":"nonpayable","type":"function"}]'''
AAVE_POOL = w3.eth.contract(address=AAVE_POOL_ADDRESS,
abi=json.loads(AAVE_POOL_ABI))
UNISWAP_ROUTER = w3.eth.contract(address=UNISWAP_ROUTER_ADDRESS,
abi=json.loads(UNISWAP_ROUTER_ABI))
def get_gas_price():
try:
response = requests.get("https://ethgasstation.info/api/ethgasAPI.json")
return w3.to_wei(response.json()["fast"] / 10, "gwei")
except:
return w3.eth.gas_price
def get_token_price():
url = "https://api.coingecko.com/api/v3/simple/price?ids=dai,ethereum,usd-
coin,wrapped-bitcoin,link,uniswap,polygon,binancecoin,curve-dao-
token,synthetix,solana,avalanche,optimism,arbitrum&vs_currencies=usd"
response = requests.get(url).json()
return {
"eth": response['ethereum']['usd'],
"dai": response['dai']['usd'],
"usdc": response['usd-coin']['usd'],
"wbtc": response['wrapped-bitcoin']['usd'],
"link": response['link']['usd'],
"uni": response['uniswap']['usd'],
"matic": response['polygon']['usd'],
"bnb": response['binancecoin']['usd'],
"crv": response['curve-dao-token']['usd'],
"snx": response['synthetix']['usd'],
"sol": response['solana']['usd'],
"avax": response['avalanche']['usd'],
"op": response['optimism']['usd'],
"arb": response['arbitrum']['usd']
}
def execute_arbitrage():
token_prices = get_token_price()
flashloan_amount = w3.to_wei(0.2, "ether")
print("\n🔥 Flashloan Process Started")
print(f"💱 Borrowing {flashloan_amount / 1e18} ETH from AAVE")
print(f"💰 ETH Price: ${token_prices['eth']}, DAI Price: ${token_prices['dai']},
USDC Price: ${token_prices['usdc']}")
flashloan_tx = AAVE_POOL.functions.flashLoanSimple(
MY_ADDRESS, WETH_ADDRESS, flashloan_amount, b"", 0
).build_transaction({
"from": MY_ADDRESS, "gas": 1000000, "gasPrice": get_gas_price(),
"nonce": w3.eth.get_transaction_count(MY_ADDRESS)
})
signed_tx = w3.eth.account.sign_transaction(flashloan_tx, PRIVATE_KEY)
raw_tx = signed_tx.rawTransaction.hex()
print(f"💱 Swapping {flashloan_amount / 1e18} ETH for different coins")
path = [WETH_ADDRESS, USDC_ADDRESS, DAI_ADDRESS, WBTC_ADDRESS, LINK_ADDRESS,
UNI_ADDRESS, MATIC_ADDRESS, BNB_ADDRESS]
amount_out_min = int(flashloan_amount * token_prices['eth'] /
token_prices['usdc'] * 0.99)
swap_tx = UNISWAP_ROUTER.functions.swapExactTokensForTokens(
flashloan_amount, amount_out_min, path, MY_ADDRESS, int(time.time()) + 60
).build_transaction({
"from": MY_ADDRESS, "gas": 200000, "gasPrice": get_gas_price(),
"nonce": w3.eth.get_transaction_count(MY_ADDRESS)
})
signed_swap_tx = w3.eth.account.sign_transaction(swap_tx, PRIVATE_KEY)
swap_receipt = w3.eth.send_raw_transaction(signed_swap_tx.rawTransaction)
print("✅ Swap Completed! Tx Hash:", w3.to_hex(swap_receipt))
final_eth = int(amount_out_min * token_prices['dai'] / token_prices['eth'] *
0.99)
print(f"➡Selling {amount_out_min / 1e18} DAI ➡ {final_eth / 1e18} ETH")
final_profit = (final_eth - flashloan_amount) / 1e18
print(f"\n💸 Final Profit: {final_profit:.6f} ETH ($ {final_profit *
token_prices['eth']:.2f})\n")
if final_profit <= 0:
print("⚠ Loss Detected! Transaction Skipped ❌")
return
print("✅ Arbitrage Completed!")
execute_arbitrage()