WIchiFarm

This contract wraps the ICHI MasterChef farming contract by holding ICHI LP tokens in the BlueberryBank, while the underlying LP tokens are deposited into the ICHI farming pool to generate additional yields The LP tokens are identified by token IDs encoded from the LP token address and accPerShare of the deposited time.

Variables

The WIchiFarm contract has the following state variables:

  • ICHIv1: An IERC20Upgradeable variable that represents the address of the legacy ICHI token.

  • ICHI: An IIchiV2 variable that represents the address of the ICHI v2 token.

  • ichiFarm: An IIchiFarm variable that represents the address of the ICHI farming contract.

Functions

initialize

function initialize(address _ichi, address _ichiv1, address _ichiFarm) external initializer

This function initializes the contract's state variables with the provided ICHI v1, ICHI v2, and ICHI farming contract addresses.

Parameters:

encodeId

function encodeId(uint256 pid, uint256 ichiPerShare) public pure returns (uint256 id)

This function encodes the pool ID and ICHI per share into an ERC-1155 token ID.

Parameters:

decodeId

function decodeId(uint256 id) public pure returns (uint256 pid, uint256 ichiPerShare)

This function decodes the ERC-1155 token ID into the pool ID and ICHI per share.The pid is the first 16 bits of the token id, and ichiPerShare is the last 240 bits of the token id.

Parameters:

  • id (uint256): ERC-1155 token ID

Returns:

getUnderlyingToken

function getUnderlyingToken(uint256 id) external view override returns (address)

This function returns the underlying ERC-20 token for a given ERC1155 token id. It calls decodeId to extract the pid from the token id and then looks up the corresponding LP token address from the ICHI farming pool.

Parameters:

  • id(uint256): The ERC1155 token ID to decode

Returns:

  • address: The address of the underlying ERC-20 token

pendingRewards

function pendingRewards(uint256 tokenId, uint amount) public view override returns (address[] memory tokens, uint256[] memory rewards)

This function returns the pending ICHI rewards for a given ERC1155 token id and amount of LP tokens. It calls decodeId to extract the pid and stIchiPerShare values from the token id, looks up the current enIchiPerShare value from the ICHI farming pool, and calculates the difference in ICHI rewards based on the change in ichiPerShare values.

Parameters:

Returns:

mint

function mint(uint256 pid, uint256 amount) external nonReentrant returns (uint256)

This function mints new ERC1155 tokens by wrapping a user's LP tokens in the ICHI farming pool. It first transfers the LP tokens from the user to the ERC1155 contract, approves the ICHI farming pool to spend the LP tokens, deposits the LP tokens into the ICHI farming pool, and then mints new ERC1155 tokens with the pid and current ichiPerShare values.

Parameters:

Returns:

  • uint256: The token ID that was minted.

burn

function burn(uint256 id, uint256 amount) external nonReentrant returns (uint256)

This function burns existing ERC1155 tokens to redeem a user's LP tokens from the ICHI farming pool and claim any pending ICHI rewards. It first decodes the token id to extract the pid, then burns the ERC1155 tokens from the user's account. It then calls the harvest and withdraw functions of the ICHI farming pool to claim the user's LP tokens and ICHI rewards, respectively. If the user has any pending ICHI rewards in the legacy ICHI contract, this function converts them to ICHI v2 tokens. Finally, the user's LP tokens and ICHI rewards are transferred to the user's account.

Parameters:

Returns:

  • uint256: The pool ID that you will receive LP tokens back.

_ensureApprove

function _ensureApprove(address token, address spender, uint256 amount) internal

This internal function ensures that a user has approved the spender to spend at least the given amount of the given token. If the current allowance is less than the required amount, it approves the spender to spend the token up to the required amount.

Parameters:

Last updated