Skip to content
/ ic-alloy-dca Public template

A semi-autonomous agent, swapping ERC-20 tokens on Uniswap for you.

License

Notifications You must be signed in to change notification settings

ic-alloy/ic-alloy-dca

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DCA Agent example

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.

Contributors Forks Stargazers Issues MIT License

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.

Setup

There are two main ways to set up the dev environment:

1. Using a VS Code Dev Container

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:

Open locally in Dev Containers

2. Setup manually

Pre-requisites:

Once you have the prerequisites installed, you can clone this repository and run the project.

Running the project

1. Start the Internet Computer

dfx start --background

2. Deploy the evm-rpc canister

dfx deploy evm_rpc

3. Deploy the DCA agent canister

The agent canister is deployed using a script. Edit the deploy script to change the default values.

bash scripts/deploy-agent.sh

Default values:

owner

The principal ID of the agent owner. You can get the principal ID by running:

Default value: $(dfx identity get-principal)

token_in_address

The Ethereum address of the token to swap from. You can get the address from Etherscan.

Default value: 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238

token_in_name

The name of the token to swap from.

Default value: USDC

token_out_address

The Ethereum address of the token to swap to. You can get the address from Etherscan.

Default value: 0xfff9976782d46cc05630d1f6ebab18b2324d6b14

token_out_name

The name of the token to swap to.

Default value: WETH

fee

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

amount_in

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

slippage

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%)

interval

The interval in seconds between each swap.

Default value: 3600 (1 hour)

4. Deploy the frontend

pnpm install
dfx deploy frontend

Usage

Transfer tokens to the agent

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.

Start the agent

bash scripts/start.sh

Stop the agent

bash scripts/stop.sh

Check the agent status

Access the agent status by visiting the frontend canister URL.

Transfer tokens from the agent

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

Develop

During development, you can run the frontend with hot reloading using Vite.

pnpm run dev

Contributors

kristoferlund
Kristofer

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.