Skip to content

A simple token wallet featuring gasless transfers built for the Monad developers monthly coding challenge

License

Notifications You must be signed in to change notification settings

mgnfy-view/simple-token-wallet-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Simple Token Wallet Challenge

A simple token wallet featuring gasless transfers built for the Monad developers monthly coding challenge
Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Roadmap
  4. Contributing
  5. License
  6. Contact

About The Project

This is a simple token wallet contract that allows you to manage your tokens - depost, withdraw, transfer tokens, use token allowance provided to the wallet, and provide allowance to other addresses. Additionally, it uses EIP712 structured signatures to enable gas sponsorship for token transfers.

Check out the YouTube demo video here.

Some design choices that were made include:

  • Tracking token balances in mapping is gas inefficient. Also, if tokens are directly sent to the wallet without using the deposit() function, there will be a disparity between the actual balance held by the contract and the stored balance in the mapping. Thus, balaces are retrieved by querying the ERC20 token contract.
  • The native gas token is stored in the wrapped form (for example, ETH -> WETH). When native token is sent to the contract, it is automatically wrapped in the receive() function. This choice allows us to use the ERC20 functions for the native token, reducing additional code required for native token handling, and effectively decreasing the contract size (and thus deployment costs).
  • Aside from simple deposits and withdrawals, the wallet also supports transferring tokens out to other addresses, and using token allowance provided to the wallet. This makes the wallet more feature-rich.
  • EIP712 signatures enable gasless transfers. The wallet owner can sign transactions for withdrawals, token transfers, and using allowance, and these can be relayed by anyone to the wallet. This enables gas sponsorship and easier onboarding.
  • Ownership of the wallet is transferrable.

Gas optimizations:

  • Using custom errors instead of require() statements saves gas.
  • Using external functions over public functions saves gas.
  • Token balances are dynamically determined, saving gas (sstore, sload not required).
  • Using immutable and private variables. Getters have been written for private variables separately, saving a bit of gas.

Some security measures that were taken:

  • Critical functions like withdraw(), transferTokens(), transferTokensFrom() are guarded by the onlyOwner modifier.
  • Nonce and deadline values are used for gasless transfers. Nonce prevents replay attacks, and deadline ensures that signatures are valid only for a predefined time interval.
  • Using Openzeppelin's well audited and battle tested contracts for verifying signatures, and handling wallet ownership.

A sample deployment script has also been provided at ./script/DeploySimpleTokenWallet.s.sol.

Built With

  • Solidity
  • Foundry

Getting Started

Prerequisites

Make sure you have git, rust, and foundry installed and configured on your system.

Installation

Clone the repo,

git clone https://github.com/mgnfy-view/simple-token-wallet-challenge.git

cd into the repo, and install the necessary dependencies

cd simple-token-wallet-challenge
forge build

Run tests by executing

forge test

That's it, you are good to go now!

Roadmap

  • Smart contract development
  • Unit tests
  • Write a good README.md

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Reach Out

Here's a gateway to all my socials, don't forget to hit me up!

Linktree

Releases

No releases published

Packages

No packages published