MasterChef V3

Solidity API

MasterChefV3

PoolInfo

struct PoolInfo {
  uint256 allocPoint;
  contract IPancakeV3Pool v3Pool;
  address token0;
  address token1;
  uint24 fee;
  uint256 totalLiquidity;
  uint256 totalBoostLiquidity;
}

UserPositionInfo

struct UserPositionInfo {
  uint128 liquidity;
  uint128 boostLiquidity;
  int24 tickLower;
  int24 tickUpper;
  uint256 rewardGrowthInside;
  uint256 reward;
  address user;
  uint256 pid;
  uint256 boostMultiplier;
}

poolLength

uint256 poolLength

poolInfo

mapping(uint256 => struct MasterChefV3.PoolInfo) poolInfo

Info of each MCV3 pool.

userPositionInfos

mapping(uint256 => struct MasterChefV3.UserPositionInfo) userPositionInfos

userPositionInfos[tokenId] => UserPositionInfo

TokenId is unique, and we can query the pid by tokenId.

v3PoolPid

mapping(address => mapping(address => mapping(uint24 => uint256))) v3PoolPid

v3PoolPid[token0][token1][fee] => pid

v3PoolAddressPid

mapping(address => uint256) v3PoolAddressPid

v3PoolAddressPid[v3PoolAddress] => pid

CAKE

contract IERC20 CAKE

Address of CAKE contract.

WETH

address WETH

Address of WETH contract.

receiver

address receiver

Address of Receiver contract.

nonfungiblePositionManager

contract INonfungiblePositionManager nonfungiblePositionManager

LMPoolDeployer

contract ILMPoolDeployer LMPoolDeployer

Address of liquidity mining pool deployer contract.

FARM_BOOSTER

contract IFarmBooster FARM_BOOSTER

Address of farm booster contract.

emergency

bool emergency

Only use for emergency situations.

totalAllocPoint

uint256 totalAllocPoint

Total allocation points. Must be the sum of all pools' allocation points.

latestPeriodNumber

uint256 latestPeriodNumber

latestPeriodStartTime

uint256 latestPeriodStartTime

latestPeriodEndTime

uint256 latestPeriodEndTime

latestPeriodCakePerSecond

uint256 latestPeriodCakePerSecond

operatorAddress

address operatorAddress

Address of the operator.

PERIOD_DURATION

uint256 PERIOD_DURATION

Default period duration.

MAX_DURATION

uint256 MAX_DURATION

MIN_DURATION

uint256 MIN_DURATION

PRECISION

uint256 PRECISION

BOOST_PRECISION

uint256 BOOST_PRECISION

Basic boost factor, none boosted user's boost factor

MAX_BOOST_PRECISION

uint256 MAX_BOOST_PRECISION

Hard limit for maxmium boost factor, it must greater than BOOST_PRECISION

Q128

uint256 Q128

MAX_U256

uint256 MAX_U256

cakeAmountBelongToMC

uint256 cakeAmountBelongToMC

Record the cake amount belong to MasterChefV3.

ZeroAddress

error ZeroAddress()

NotOwnerOrOperator

error NotOwnerOrOperator()

NoBalance

error NoBalance()

NotPancakeNFT

error NotPancakeNFT()

InvalidNFT

error InvalidNFT()

NotOwner

error NotOwner()

NoLiquidity

error NoLiquidity()

InvalidPeriodDuration

error InvalidPeriodDuration()

NoLMPool

error NoLMPool()

InvalidPid

error InvalidPid()

DuplicatedPool

error DuplicatedPool(uint256 pid)

NotEmpty

error NotEmpty()

WrongReceiver

error WrongReceiver()

InconsistentAmount

error InconsistentAmount()

InsufficientAmount

error InsufficientAmount()

Init

event Init()

AddPool

event AddPool(uint256 pid, uint256 allocPoint, contract IPancakeV3Pool v3Pool, contract ILMPool lmPool)

SetPool

event SetPool(uint256 pid, uint256 allocPoint)

Deposit

event Deposit(address from, uint256 pid, uint256 tokenId, uint256 liquidity, int24 tickLower, int24 tickUpper)

Withdraw

event Withdraw(address from, address to, uint256 pid, uint256 tokenId)

UpdateLiquidity

event UpdateLiquidity(address from, uint256 pid, uint256 tokenId, int128 liquidity, int24 tickLower, int24 tickUpper)

NewOperatorAddress

event NewOperatorAddress(address operator)

NewLMPoolDeployerAddress

event NewLMPoolDeployerAddress(address deployer)

NewReceiver

event NewReceiver(address receiver)

NewPeriodDuration

event NewPeriodDuration(uint256 periodDuration)

Harvest

event Harvest(address sender, address to, uint256 pid, uint256 tokenId, uint256 reward)

NewUpkeepPeriod

event NewUpkeepPeriod(uint256 periodNumber, uint256 startTime, uint256 endTime, uint256 cakePerSecond, uint256 cakeAmount)

UpdateUpkeepPeriod

event UpdateUpkeepPeriod(uint256 periodNumber, uint256 oldEndTime, uint256 newEndTime, uint256 remainingCake)

UpdateFarmBoostContract

event UpdateFarmBoostContract(address farmBoostContract)

SetEmergency

event SetEmergency(bool emergency)

onlyOwnerOrOperator

modifier onlyOwnerOrOperator()

onlyValidPid

modifier onlyValidPid(uint256 _pid)

onlyReceiver

modifier onlyReceiver()

onlyBoostContract

modifier onlyBoostContract()

Throws if caller is not the boost contract.

constructor

constructor(contract IERC20 _CAKE, contract INonfungiblePositionManager _nonfungiblePositionManager, address _WETH) public

Parameters

getLatestPeriodInfoByPid

function getLatestPeriodInfoByPid(uint256 _pid) public view returns (uint256 cakePerSecond, uint256 endTime)

Returns the cake per second , period end time.

Parameters

getLatestPeriodInfo

function getLatestPeriodInfo(address _v3Pool) public view returns (uint256 cakePerSecond, uint256 endTime)

Returns the cake per second , period end time. This is for liquidity mining pool.

Parameters

pendingCake

function pendingCake(uint256 _tokenId) external view returns (uint256 reward)

View function for checking pending CAKE rewards.

The pending cake amount is based on the last state in LMPool. The actual amount will happen whenever liquidity changes or harvest.

Parameters

setEmergency

function setEmergency(bool _emergency) external

For emergency use only.

setReceiver

function setReceiver(address _receiver) external

setLMPoolDeployer

function setLMPoolDeployer(contract ILMPoolDeployer _LMPoolDeployer) external

add

function add(uint256 _allocPoint, contract IPancakeV3Pool _v3Pool, bool _withUpdate) external

Add a new pool. Can only be called by the owner. One v3 pool can only create one pool.

Parameters

set

function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) external

Update the given pool's CAKE allocation point. Can only be called by the owner.

Parameters

DepositCache

struct DepositCache {
  address token0;
  address token1;
  uint24 fee;
  int24 tickLower;
  int24 tickUpper;
  uint128 liquidity;
}

onERC721Received

function onERC721Received(address, address _from, uint256 _tokenId, bytes) external returns (bytes4)

Upon receiving a ERC721

harvest

function harvest(uint256 _tokenId, address _to) external returns (uint256 reward)

harvest cake from pool.

Parameters

harvestOperation

function harvestOperation(struct MasterChefV3.UserPositionInfo positionInfo, uint256 _tokenId, address _to) internal returns (uint256 reward)

withdraw

function withdraw(uint256 _tokenId, address _to) external returns (uint256 reward)

Withdraw LP tokens from pool.

Parameters

updateLiquidity

function updateLiquidity(uint256 _tokenId) external

Update liquidity for the NFT position.

Parameters

updateBoostMultiplier

function updateBoostMultiplier(uint256 _tokenId, uint256 _newMultiplier) external

Update farm boost multiplier for the NFT position.

Parameters

updateLiquidityOperation

function updateLiquidityOperation(struct MasterChefV3.UserPositionInfo positionInfo, uint256 _tokenId, uint256 _newMultiplier) internal

increaseLiquidity

function increaseLiquidity(struct INonfungiblePositionManagerStruct.IncreaseLiquidityParams params) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1)

Increases the amount of liquidity in a position, with tokens paid by the msg.sender

Parameters

Return Values

pay

function pay(address _token, uint256 _amount) internal

Pay.

Parameters

refund

function refund(address _token, uint256 _amount) internal

Refund.

Parameters

decreaseLiquidity

function decreaseLiquidity(struct INonfungiblePositionManagerStruct.DecreaseLiquidityParams params) external returns (uint256 amount0, uint256 amount1)

Decreases the amount of liquidity in a position and accounts it to the position

Parameters

Return Values

collect

function collect(struct INonfungiblePositionManagerStruct.CollectParams params) external returns (uint256 amount0, uint256 amount1)

Collects up to a maximum amount of fees owed to a specific position to the recipient

Warning!!! Please make sure to use multicall to call unwrapWETH9 or sweepToken when set recipient address(0), or you will lose your funds. amount0Max The maximum amount of token0 to collect, amount1Max The maximum amount of token1 to collect

Parameters

Return Values

collectTo

function collectTo(struct INonfungiblePositionManagerStruct.CollectParams params, address to) external returns (uint256 amount0, uint256 amount1)

Collect fees and refund.

transferToken

function transferToken(address _token, address _to) internal

Transfer token from MasterChef V3.

Parameters

unwrapWETH9

function unwrapWETH9(uint256 amountMinimum, address recipient) external

Unwraps the contract's WETH9 balance and sends it to recipient as ETH.

The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.

Parameters

sweepToken

function sweepToken(address token, uint256 amountMinimum, address recipient) external

Transfers the full amount of a token held by this contract to recipient

The amountMinimum parameter prevents malicious contracts from stealing the token from users

Parameters

burn

function burn(uint256 _tokenId) external

Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens must be collected first.

Parameters

upkeep

function upkeep(uint256 _amount, uint256 _duration, bool _withUpdate) external

Upkeep period.

Parameters

massUpdatePools

function massUpdatePools() internal

Update cake reward for all the liquidity mining pool.

updatePools

function updatePools(uint256[] pids) external

Update cake reward for the liquidity mining pool.

Avoid too many pools, and a single transaction cannot be fully executed for all pools.

setOperator

function setOperator(address _operatorAddress) external

Set operator address.

Callable by owner

Parameters

setPeriodDuration

function setPeriodDuration(uint256 _periodDuration) external

Set period duration.

Callable by owner

Parameters

updateFarmBoostContract

function updateFarmBoostContract(address _newFarmBoostContract) external

Update farm boost contract address.

Parameters

safeTransferETH

function safeTransferETH(address to, uint256 value) internal

Transfer ETH in a safe way

Parameters

_safeTransfer

function _safeTransfer(address _to, uint256 _amount) internal

Safe Transfer CAKE.

Parameters

receive

receive() external payable

Last updated