This project implements an algorithmic trading strategy using Ethereum smart contracts. The strategy involves:
- Converting ETH to WETH.
- Swapping WETH for USDC on Uniswap.
- Supplying USDC,WETH to the Aave protocol to earn interest.
- Withdrawing USDC,WETH from the Aave protocol.
The smart contract is designed to allow users to interact with it and execute this strategy seamlessly in a decentralized manner.
- ETH to WETH Conversion: Wraps ETH into WETH for ERC-20 compatibility.
- Uniswap Integration: Swaps WETH for USDC using Uniswap's V3 router.
- Aave Integration: Supplies USDC to Aave's lending pool to earn interest.
- Balance Tracking: Allows users to check their WETH, USDC, and aUSDC balances.
- Modular Design: Each step of the strategy is implemented as a separate function for flexibility.
- Solidity (v0.8.20): Smart contract programming language.
- Uniswap V3: Decentralized exchange for token swaps.
- Aave V3: Lending and borrowing protocol for earning interest on deposits.
- Foundry: Development framework for testing and deploying smart contracts.
AlgoTrading.sol
:- Core contract implementing the trading strategy.
InteractAlgoTrading.sol
:- Script for interacting with the deployed
AlgoTrading
contract.
- Script for interacting with the deployed
Wraps ETH into WETH using the WETH contract.
Swaps a specified amount of WETH for USDC using Uniswap V3.
Supplies USDC to Aave's lending pool and mints aUSDC tokens for the user.
Fetches the user's aUSDC balance from Aave, confirming successful deposits.
Returns the user's WETH and USDC balances.
- Node.js and npm installed
- Foundry installed (
forge
andanvil
) - An Ethereum RPC URL (e.g., Infura or Alchemy)
-
Clone the repository:
-
Install dependencies:
-
Set up environment variables:
- Create a
.env
file with the following variables:RPC_URL=<your_rpc_url> PRIVATE_KEY=<your_private_key>
-
Compile the contracts:
-
Run tests:
-
Start an Anvil fork of Ethereum Mainnet: anvil --fork-url <RPC_URL> --hardfork shanghai
-
Deploy the smart contract: forge script script/Deploy.s.sol --broadcast --rpc-url <RPC_URL> --private-key .env.PRIVATE_KEY
-
Note down the deployed contract address from the terminal output.
Use the provided script (InteractAlgoTrading.sol
) to interact with your deployed contract:
-
Check initial balances:
-
Execute the trading strategy step-by-step:
- Convert ETH to WETH.
- Swap WETH for USDC.
- Supply USDC to Aave.
- Withdraw assets from Aave.
- Verify balances after each step using the console logs
- Deposit 1 ETH into the contract:
- Call
swapEthForWeth()
with 1 ETH sent as value.
- Swap WETH for USDC:
- Call
swapWethForUsdc()
with the desired amount of WETH.
- Supply USDC,WETH to Aave:
- Call
supply
functions.
- Withdraw USDC,WETH from Aave:
- Call
withdraw
functions.
Contract | Address (Mainnet) |
---|---|
WETH | 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 |
USDC | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
Uniswap Router V3 | 0xE592427A0AEce92De3Edee1F18E0157C05861564 |
Aave Pool | 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 |
Aave Data Provider | 0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d |
- Add support for multiple trading strategies.
- Implement stop-loss, take-profit,rebalancing mechanisms.
- Integrate additional DeFi protocols like Compound or Curve.
- Support gas optimization techniques like batch transactions.
This project is licensed under MIT License.