Tokemak Vault  -  ERC4626

Tokemak Vault - ERC4626

ERC4626 Tokenized vault implementation to auto-compound Toke LP rewards.

May 22, 2023·

3 min read

A brief on Tokemak LP reactors:

Tokemak acts as a generalized liquidity aggregator for decentralized exchanges (DEXs) and DeFi. The Tokemak protocol is designed to allow users to choose where liquidity is allocated and used, providing a cheaper, more efficient method for liquidity provisioning and sourcing.

The traditional pool 2 liquidity mining incentives attract temporary capital with the goal of extracting short-term value, without concern for the long-term success of a project. Tokemak helps find the right kind of liquidity providers - those that plan on holding your DAOs token long term but may be risk-averse due to impermanent loss when providing liquidity in the traditional 50/50 manner.

ERC4626 Tokenized vault implementation

In this vault example, we intend to automate the process of claiming the toke rewards given by provisioning liquidity to Sushiswap and staking them into the TOKEMAK reactor. The rewards will come in the form of the TOKE token, which gets rewarded on a cycle of 7 days and from transactions made on the token pair TOKE/WETH on Sushiswap.

High-level overview:

The auto compound function of the xTokemakVault contract will claim the rewards available for the total assets staked into TOKE/ETH sushi pool.

It will sell the tokamak in the sushi swap market for more of the Vault's underlying assets. And lastly, it will stake this Sushi lp token into the Tokamak pool for more Toke rewards.

The rewards get harvested every 7 days and in the meantime, each investor holds a certain amount of shares equivalent to the amount provided to the vault initially.

High-level overview:

Github Vault source code...

Funds flow:

  1. The user deposits the sushi lp token "vault underlying token" into the vault.

  2. Vault issues the shares equivalent to the deposit.

  3. Vault stakes user deposit into TOKEMAK SUSHI LP Reactor.

  4. Vault Claims TOKE rewards every 7 days from the TOKEMAK rewards contract.

  5. TOKE rewards are swapped for more sushi lp tokens "vault underlying token".

  6. The cycle of points 4 & 5 repeats every 7 days.

Compounding Rewards

  1. From Sushiswap we get 0.25% of all trades in the TOKE-WETH liquidity pool.

  2. From the TOKEMAK REACTOR contract, we have 16.4% APY in the form of TOKE tokens.

Redeem Vault shares/withdrawals

  1. The user calls "requestWithdrawal(amount)" function with the amount of shares to redeem or withdraw for the underlying token.

  2. The user approves the number of shares to Vault via a wallet or smart contract.

  3. If the shares balance of the user is less o equal to the amount, Tokemak will queue this request on the withdrawals queue to allow the Vault to withdraw.

  4. User shares will be converted to the equivalent underlying token amount and become available to withdraw

Security Considerations

  • To mitigate an inflation attack on the vault, the deployer of this contract will need to deposit a substantial amount of the underlying token and mint initial shares.

  • To mitigate front running on the swapping of the rewards, a minimum amount out is passed to the autoCompound function.

  • It is the responsibility of the deployer to ensure that any off-chain system that calls the auto compound function, calculates the number of rewards against the current price of the TOKE token.


The Tokemak Vault is just another brief example of how composability works on ethereum and how it can enable the matching of APY's and percentages of rewards to create an easy way to generate passive income.

Please check tokemaks website for further details on the reward schedules and its other possibilities as a liquidity provider, or liquidity director.