/auto-hold

Primary LanguageSolidity

Auto HODL

Auto HODL is a consumer DeFi framework for automatically saving a small amount of tokens as users perform their normal on-chain activity. In other words, Auto HODL is an on-chain equivalent of Acorns and other round-up savings tools.

ETH Denver 2024 presentation

Architecture

Terminology

  • Consumer dApp: dApp UI that the end user wants to interact with. This might be uniswap.com, the Metamask interface for transferring ERC20, or any other UI that talks to the blockchain.
  • Savings Contract: The on-chain contract that all the user's transactions passes through.
  • Target Contract: The on-chain component of the Consumer dApp.
  • Unlock Date: The user defined date after which savings can be withdrawn.

User flow

  1. Alice sets up a Savings Contract and defines how much she wants to put in to savings for every transaction and what the Lockup Period will be.
  2. Alice wants to do a swap on the Target Contract, 1inch, for 100 USDC to ETH
  3. Auto HODL intercepts Alice's transaction and asks for a small amount of additional token before Alice signs the transaction.
  4. The transaction is sent to the Savings Contract which deposits the extra amount into savings.
  5. The Savings Contract forwards the swap request to the Target Contract (1inch) which processes the transaction normally.
  6. After the Unlock Date, Alice can withdraw all her savings.

Diagram

This code currently implements v1 in the diagram below. In the future, we plan on streamlining by integrating with Metamask snaps and 4337 account abstraction.

Auto HODL design

Getting started

1. Deploy contracts

$ cd backend
$ forge build
$ HODL_DEPLOY_KEY='XXX'

# Deploy Savings Contract
$ forge create src/Factory.sol:Factory \
    --private-key $HODL_DEPLOY_KEY \
    --rpc-url https://example.com

# Deploy sample Target Contract
$ forge create src/Counter.sol:Counter \
    --private-key $HODL_DEPLOY_KEY \
    --rpc-url https://example.com

2. Run sample dApp

$ cd interface
$ yarn
$ yarn dev

Deployed Savings Contracts

Network Environment Address
Base Mainnet 0xf312F04DF2885Ec7C44cde77bAC8BB8B1FB4Aa20
Inco Testnet 0xF6c8EED3bE03a482Fe5d43c4EFC330d14dB7cfA4
Fhenix Testnet 0xF6c8EED3bE03a482Fe5d43c4EFC330d14dB7cfA4
Arbitrum Testnet 0xF6c8EED3bE03a482Fe5d43c4EFC330d14dB7cfA4
Linea Mainnet 0xF6c8EED3bE03a482Fe5d43c4EFC330d14dB7cfA4
XDC Testnet 0xF6c8EED3bE03a482Fe5d43c4EFC330d14dB7cfA4
Injective Testnet 0xa52b8D81C2A8673C704a35557E6a8B8791fC3506

Deployed Target Contracts

Network Environment Address
Base Mainnet 0x94789011AcF3c7411d1db9Abe8337f4BA7589D9f
Inco Testnet 0xf312F04DF2885Ec7C44cde77bAC8BB8B1FB4Aa20
Fhenix Testnet 0x94789011AcF3c7411d1db9Abe8337f4BA7589D9f
Arbitrum Testnet 0xf312F04DF2885Ec7C44cde77bAC8BB8B1FB4Aa20
Linea Mainnet 0xf312F04DF2885Ec7C44cde77bAC8BB8B1FB4Aa20
XDC Testnet 0x94789011AcF3c7411d1db9Abe8337f4BA7589D9f
Injective Testnet 0x144E52b74F837F5529b0c41e900BB5c61d30afb4