This Dollar Cost Average agent runs on an timer and swaps a fixed amount of in tokens to a variable amount of out tokens every X seconds. The agent runs as a smart contract on the Internet Computer and swaps ERC-20 tokens using Uniswap.
The backend consists of a Rust canister that uses the ic-alloy library to interact with the Ethereum blockchain. The frontend is built with React and Vite.
Tip
This is an example app. Use this repository as a starting point for building your own timer based Ethereum agents on the Internet Computer.
There are two main ways to set up the dev environment:
The dev containers extension lets you use a Docker container as a full-featured development environment. This repository includes a dev container configuration that you can use to open the project with all the necessary tools and dependencies pre-installed.
Pre-requisites:
Once Docker, Visual Studio Code and the Dev Containers Extension are installed, you can open the project in a container by clicking the button below:
Pre-requisites:
Once you have the prerequisites installed, you can clone this repository and run the project.
dfx start --background
dfx deploy evm_rpc
The agent canister is deployed using a script. Edit the deploy script to change the default values.
bash scripts/deploy-agent.sh
Default values:
The principal ID of the agent owner. You can get the principal ID by running:
Default value: $(dfx identity get-principal)
The Ethereum address of the token to swap from. You can get the address from Etherscan.
Default value: 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238
The name of the token to swap from.
Default value: USDC
The Ethereum address of the token to swap to. You can get the address from Etherscan.
Default value: 0xfff9976782d46cc05630d1f6ebab18b2324d6b14
The name of the token to swap to.
Default value: WETH
The fee tier of the Uniswap pool, used to determine the correct pool contract in which to execute the swap. Uniswap v3 protocol has the 1%, 0.3%, 0.05%, and 0.01% fee tiers.
Allowed values: 10000
, 3000
, 500
, 100
The amount of tokens to swap from. For the USDC token, the default amount represents 0.1 USDC. USDC uses fewer decimals than most tokens, so the amount is lower than for other tokens.
Default value: 100000
The maximum slippage percentage allowed for the swap. If the slippage is higher than the allowed percentage, the swap is reverted.
Default value: 5
(5%)
The interval in seconds between each swap.
Default value: 3600
(1 hour)
pnpm install
dfx deploy frontend
Before you start the agent, you need to transfer some tokens to the agent canister, both the "in" token and some of the base chain token to pay for the gas fees. The agent Ethereum address is displayed in the frontend.
bash scripts/start.sh
bash scripts/stop.sh
Access the agent status by visiting the frontend canister URL.
At any point, you can transfer the remaining tokens from the agent canister back to your wallet.
bash scripts/transfer-in-token.sh
bash scripts/transfer-out-token.sh
bash scripts/transfer-base-token.sh
During development, you can run the frontend with hot reloading using Vite.
pnpm run dev
Kristofer |
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.