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:
Name
Type
Description
_ichi
address
Address of the ICHI v2 token contract
_ichiv1
address
Address of the ICHI v1 token address
_ichiFarm
address
Address of the ICHI farming contract

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:
Name
Type
Description
pid
uint256
Pool ID
ichiPerShare
uint256
ICHI reward per share multiplied by 10e18

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:
Name
Type
Description
pid
uint256
The pool ID extracted from the first 16 bits fo the id
ichiPerShare
uint256
The value of ichiPerShare extracted from the last 240 bits of the id

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:
Name
Type
Description
tokenId
uint256
The ERC1155 token ID to encode
amount
uint
The amount of share
Returns:
Name
Type
Description
tokens
array
An array containing the address of the reward token ( specifically ICHI)
rewards
uint256
An array containing the amount of ICHI rewards

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:
Name
Type
Description
pid
uint256
The ID of the pool to deposit the LP tokens
amount
uint256
The amount of LP tokens to deposit
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:
Name
Type
Description
id
uint256
The ERC1155 token ID to burn
amount
uint256
The amount of tokens to burn
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:
Name
Type
Description
token
address
The address of the token to check
spender
address
The address of the spender to check
amount
uint256
The amount of allowance to ensure