Skip to content

Aphyla/token-migrator

Repository files navigation

Token Migrator

A modular and secure system for migrating to a new ERC20 tokens.

Contracts

A pausable, ownable contract that enables users to migrate their tokens from a source ERC20 to a target ERC20 in a 1:1 manner. The owner can deposit and withdraw tokens, while users can atomically exchange their tokens through the migrate function. All migrations are tracked on-chain. This contract does not support transfer tax tokens, or any tokens whose balance may fluctuate without any transfer in/out (e.g. rebasing tokens, transfer tax tokens).

  • constructor: Initializes the migrator with the source and target tokens and sets the initial owner.
  • getSourceToken: Returns the source token being migrated from.
  • getTargetToken: Returns the target token being migrated to.
  • getTotalMigrated: Returns the total amount of tokens migrated so far.
  • migrate: Migrates a specified amount of source tokens to target tokens for the caller. Checks balances, allowances, and contract state.
  • depositTargetToken: Allows the owner to deposit target tokens for future migrations.
  • withdrawToken: Allows the owner to withdraw any ERC20 token from the contract.
  • pause / unpause: Owner can pause or unpause migrations.

A factory contract that deploys new TokenMigrator contracts for specific ERC20 token pairs. Each migrator is owned by the creator and configured for a unique migration campaign.

  • createTokenMigrator: Deploys a new TokenMigrator for a given source and target token, setting the caller as the owner.

Usage

This repository uses yarn for package management and foundry for smart contract development.

Documentation

Environment Setup

First, copy the .env.example file to .env.

$ cp .env.example .env

Then, update the .env file with the appropriate values.

Note that the default CELO RPC doesn't use an archive node, so you may need to use a different RPC when running the integration tests.

Build

$ yarn build

Test

$ yarn test

Deploy

$ yarn deploy ./script/DeployTokenMigratorFactory.s.sol --broadcast --rpc-url <rpc-url> --verify

If the deployment fails, you can resume from the last failed transaction:

$ yarn deploy <path-to-script> --resume

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published