This project implements a Compound Interest Farming strategy using the Compound protocol. The script automates the process of depositing DAI into the cDAI market, claiming COMP rewards, and reinvesting those rewards back into the cDAI market to compound interest.
- Fetches user assets and interest rates from the Compound protocol.
- Approves token transfers for DAI and COMP.
- Deposits DAI into the cDAI market.
- Claims COMP rewards.
- Reinvests COMP rewards back into the cDAI market.
- Schedules reinvestment to run daily at midnight.
- Node.js and npm installed on your machine.
- An Ethereum wallet with some DAI and COMP tokens.
- An Infura project ID for connecting to the Ethereum mainnet.
-
Clone the Repository:
git clone https://github.com/yllvar/compound-interest-farming.git cd compound-interest-farming -
Install Dependencies:
npm install
-
Set Up Environment Variables:
-
Create a
.envfile in the root directory of the project. -
Add the following environment variables to the
.envfile:INFURA_PROJECT_ID=your_infura_project_id ACCOUNT_ADDRESS=your_wallet_address PRIVATE_KEY=your_private_key -
Replace
your_infura_project_id,your_wallet_address, andyour_private_keywith your actual Infura project ID, wallet address, and private key.
-
-
Validate Private Key:
- Ensure that the private key is 64 hexadecimal characters (32 bytes), optionally starting with
0x.
- Ensure that the private key is 64 hexadecimal characters (32 bytes), optionally starting with
-
Run the Script:
node index.js
-
Initial Setup:
- The script will:
- Fetch user assets and interest rates.
- Approve token transfer for DAI.
- Deposit 100 DAI into the cDAI market.
- Claim COMP rewards.
- Reinvest COMP rewards back into the cDAI market.
- The script will:
-
Scheduled Reinvestment:
- The script schedules reinvestment to run daily at midnight. You can modify the schedule in the
schedule.scheduleJobfunction inindex.js.
- The script schedules reinvestment to run daily at midnight. You can modify the schedule in the
-
Change Deposit Amount:
- Modify the
amountToDepositvariable in theindex.jsfile to change the initial deposit amount.
const amountToDeposit = web3.utils.toWei('100', 'ether'); // Example: 100 DAI
- Modify the
-
Modify Reinvestment Schedule:
- Modify the cron expression in the
schedule.scheduleJobfunction to change the reinvestment schedule.
schedule.scheduleJob('0 0 * * *', async () => { // Daily at midnight await reinvestInterest(); });
- Modify the cron expression in the