Tokenizing farming positions into ERC-1155

Tokenizing Farming Positions

Alpha Homora V2 tokenizes farming positions into ERC-1155 tokens to efficiently and accurately calculate the rewards. Why not ERC-20?
ERC-1155 is a multi-token standard. In other words, ERC-1155 is one type of NFT tokens. It can be treated as a class of ERC-20 tokens, grouped by ids. For example, token A with id 1 will behave mostly like an ERC-20 token and will have its logic separated from token B with id 2 (while both token A and token B are both inside a single ERC-1155 contract). This provides a gas-efficient way to have a class of ERC-20 tokens without having to deploy a separate contract for each new one.
NOTE: now displays ERC-1155 token transfers!
In Alpha Homora V2, rewards are no longer sold and reinvested into your position.
The reward amounts for farming positions actually depend on 2 factors:
  1. 1.
    LP Shares – How much LP is staked by the user. The more staked, the more the rewards.
  2. 2.
    Stake Time – The earlier the user stakes, the higher the reward.
This means that the amount of yield farmed tokens user A and B receive will be different even though they have the same LP shares (as rewards are distributed based on LP shares). This scenario occurs when user A and B open their leveraged yield farming position at different times, resulting in users starting to stake LP tokens to accrue farmed tokens at different times. Because of this, we cannot simply tokenize positions into regular ERC-20 tokens.
If two users stake at the exact same time, their reward split will simply be proportional to their LP shares. Thus, positions with the same stake-time are the same and are fungible (up to LP share amount, which can be reflected in token balance).

Alpha Homora V2's ERC-1155 Wrappers

Alpha Homora V2 wraps ERC-20 LP tokens and mints ERC-1155 tokens for putting as collateral in the HomoraBank, while the actual LP tokens can be staked at the corresponding staking contracts to earn yield farming rewards.
Each wrapper encodes LP tokens and other necessary data (e.g. pool id) into the ERC-1155 token id, so that tokens with the same id implies the same amount of reward. As an example, let's look at WMasterChef, a Sushiswap LP token wrapper for staking to Sushiswap's MasterChef.
WMasterChef's id encodes:
  • pid – MasterChef pool id for the LP token. This determines which pool and ERC-20 LP token you're actually wrapping.
  • rewardPerShare – An accumulated SUSHI reward amount per share (at the time of position adjustment).
The number of tokens a user holds corresponds to how many LP tokens are wrapped. When the user closes the position, the total amount of reward can then be calculated from:
shareBalance * (WMasterChef'scurrentRewardPerShare - token's rewardPerShare)
This calculation is similar to how Sushiswap implements SUSHI token distribution logic by leveraging the difference between the initial rewardPerShare and the currentRewardPerShare, which is only updated globally at every action to MasterChef.
Other Alpha Homora V2 token wrappers include:
  • WERC20 – simple wrap for Uniswap and Balancer ERC-20 LP tokens without staking logic
  • WLiquidityGauge – wrapper for Curve ERC-20 LP tokens for staking to Curve's Liquidity Gauge
  • WStakingRewards – wrapper for LP tokens that can be stake to staking contracts with Synthetix's IStakingRewards interface.
NOTE: Each of these wrappers may have different encodings due to different interactions with different protocols.
Last modified 6mo ago
Copy link