/abstract-accounts

A playground for ERC-4337 Account Abstraction

Primary LanguageSolidityMIT LicenseMIT

Playground for Abstracted Wallets

WARNING: The contracts in this repository are experimental, not audited and should not be used in production.

General

Installation

Clone and compile this repository:

git clone git@github.com:naddison36/abstract-accounts.git
yarn
yarn compile

Hardhat Tasks

Hardhat Tasks are used to execute different transactions.

To see a list of available tasks run:

yarn task

The URL of the Ethereum node provider is set with the NODE_URL environment variable. For example:

export NODE_URL=https://eth-goerli.g.alchemy.com/v2/your-project-id

If deploying contracts, the ETHERSCAN_KEY environment variable is required so the contracts can be verified on Etherscan. You need to login to Etherscan and generate an API key at https://etherscan.io/myapikey

export ETHERSCAN_KEY=your-api-key

To see the log output, export the DEBUG environment variable:

export DEBUG=aa:*

Signers

In order to send transactions or sign user operations for the abstract wallet, a signer is required. This is an eternally owned account that uses a private key to cryptographically sign data. From this private key, the account address can be derived.

The following signers are supported:

  • A private key by setting the PRIVATE_KEY environment variable.
  • A mnemonic by setting the MNEMONIC environment variable.
  • Impersonating an account if working against a local Hardhat or Anvil node by setting the IMPERSONATE environment variable to the account or contract address.
  • Using Defender Relay from Open Zeppelin by generating an API key and setting the DEFENDER_API_KEY and DEFENDER_API_SECRET environment variables.

SimpleAccount

Uses the SimpleAccount contract from the Core Ethereum's eth-infinitism/account-abstraction repository. The Core contracts have been copied into this repo as typechain can't import the contracts from the @account-abstraction/contracts package. See typechain issue #816 for details.

The following Hardhat tasks work with the SimpleAccount contract:

AVAILABLE TASKS:
  account-address               Gets the abstract account for the signer
  account-create                Deploys a new SimpleAccount using the factory
  account-factory-deploy        Deploys a SimpleAccountFactory
  account-transfers             Transfers native currency (eg ETH) or tokens from the abstract account to one or more accounts by directly calling the EntryPoint contract

To create your own simple abstract wallet, run the following after setting up your signer:

yarn task account-create --network goerli

To deploy a new SimpleAccountFactory contract, run the following:

yarn task account-factory-deploy --network goerli

DexWallet

Run a Decentralized Exchange (DEX) in your wallet with DexWallet. No fees, approvals, deposits/withdrawals, impairment loss or slippage. Publish a signed order of what you want to exchange and let a market maker trade directly with your wallet.

Features:

  • Whole swaps between two tokens.
  • Buying or selling tokens at a fixed rate but to the available liquidity in the wallet.
  • Buying or selling a batch of NFTs for a fixed token unit price.
  • No approvals by either party.
  • Expiry of orders.
  • Canceling orders.
  • Cross-chain replay protection.

Processes

Token Swap

Token Swap

Tasks

To deploy a new DexWalletFactory contract, run the following:

yarn task account-factory-deploy --network goerli --factory DexWalletFactory

To verify the newly deployed DexWallet implementation contract

yarn task account-verify --network goerli --type DexWallet --address 0x7EdC734891a04750B7fc26cE7FdBCf771e96563C

To create your own dex wallet, run the following after setting up your signer:

yarn task account-create --network goerli --type DexWallet