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
: AnIERC20Upgradeable
variable that represents the address of the legacy ICHI token.ICHI
: AnIIchiV2
variable that represents the address of the ICHI v2 token.ichiFarm
: AnIIchiFarm
variable that represents the address of the ICHI farming contract.
Functions
initialize
This function initializes the contract's state variables with the provided ICHI v1, ICHI v2, and ICHI farming contract addresses.
Parameters:
Name | Type | Description |
---|---|---|
| address | Address of the ICHI v2 token contract |
| address | Address of the ICHI v1 token address |
| address | Address of the ICHI farming contract |
encodeId
This function encodes the pool ID and ICHI per share into an ERC-1155 token ID.
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | Pool ID |
| uint256 | ICHI reward per share multiplied by 10e18 |
decodeId
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 |
---|---|---|
| uint256 | The pool ID extracted from the first 16 bits fo the |
| uint256 | The value of ichiPerShare extracted from the last 240 bits of the |
getUnderlyingToken
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
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 |
---|---|---|
| uint256 | The ERC1155 token ID to encode |
| uint | The amount of share |
Returns:
Name | Type | Description |
---|---|---|
| array | An array containing the address of the reward token ( specifically ICHI) |
| uint256 | An array containing the amount of ICHI rewards |
mint
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 |
---|---|---|
| uint256 | The ID of the pool to deposit the LP tokens |
| uint256 | The amount of LP tokens to deposit |
Returns:
uint256
: The token ID that was minted.
burn
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 |
---|---|---|
| uint256 | The ERC1155 token ID to burn |
| uint256 | The amount of tokens to burn |
Returns:
uint256
: The pool ID that you will receive LP tokens back.
_ensureApprove
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 |
---|---|---|
| address | The address of the token to check |
| address | The address of the spender to check |
| uint256 | The amount of allowance to ensure |
Last updated