Crypto MasterChef V3
npm install @cryptoswapdex/masterchef-v3solidity
struct PoolInfo {
uint256 allocPoint;
ICryptoV3Pool v3Pool;
address token0;
address token1;
uint24 fee;
uint256 totalLiquidity;
uint256 totalBoostLiquidity;
}
`
$3
`solidity
struct UserPositionInfo {
uint128 liquidity;
uint128 boostLiquidity;
int24 tickLower;
int24 tickUpper;
uint256 rewardGrowthInside;
uint256 reward;
address user;
uint256 pid;
uint256 boostMultiplier;
}
`
$3
`solidity
uint256 poolLength
`
$3
`solidity
mapping(uint256 => PoolInfo) poolInfo
`
Info of each MCV3 pool.
$3
`solidity
mapping(uint256 => UserPositionInfo) userPositionInfos
`
userPositionInfos[tokenId] => UserPositionInfo
_TokenId is unique, and we can query the pid by tokenId._
$3
`solidity
mapping(address => mapping(address => mapping(uint24 => uint256))) v3PoolPid
`
v3PoolPid[token0][token1][fee] => pid
$3
`solidity
mapping(address => uint256) v3PoolAddressPid
`
v3PoolAddressPid[v3PoolAddress] => pid
$3
`solidity
IERC20 CST
`
Address of CST contract.
$3
`solidity
address WETH
`
Address of WETH contract.
$3
`solidity
address receiver
`
Address of Receiver contract.
$3
`solidity
INonfungiblePositionManager nonfungiblePositionManager
`
$3
`solidity
ILMPoolDeployer LMPoolDeployer
`
Address of liquidity mining pool deployer contract.
$3
`solidity
IFarmBooster FARM_BOOSTER
`
Address of farm booster contract.
$3
`solidity
bool emergency
`
Only use for emergency situations.
$3
`solidity
uint256 totalAllocPoint
`
Total allocation points. Must be the sum of all pools' allocation points.
$3
`solidity
uint256 latestPeriodNumber
`
$3
`solidity
uint256 latestPeriodStartTime
`
$3
`solidity
uint256 latestPeriodEndTime
`
$3
`solidity
uint256 latestPeriodcryptoPerSecond
`
$3
`solidity
address operatorAddress
`
Address of the operator.
$3
`solidity
uint256 PERIOD_DURATION
`
Default period duration.
$3
`solidity
uint256 MAX_DURATION
`
$3
`solidity
uint256 MIN_DURATION
`
$3
`solidity
uint256 PRECISION
`
$3
`solidity
uint256 BOOST_PRECISION
`
Basic boost factor, none boosted user's boost factor
$3
`solidity
uint256 MAX_BOOST_PRECISION
`
Hard limit for maxmium boost factor, it must greater than BOOST_PRECISION
$3
`solidity
uint256 Q128
`
$3
`solidity
uint256 MAX_U256
`
$3
`solidity
uint256 cryptoAmountBelongToMC
`
Record the CST amount belong to
$3
`solidity
constructor(IERC20 _crypto, INonfungiblePositionManager _nonfungiblePositionManager, address _WETH) public
`
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _crypto | IERC20 | The CST token contract address. |
| _nonfungiblePositionManager | INonfungiblePositionManager | the NFT position manager contract address. |
| _WETH | address | |
$3
`solidity
function getLatestPeriodInfoByPid(uint256 _pid) public view returns (uint256 cryptoPerSecond, uint256 endTime)
`
Returns the CST per second , period end time.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _pid | uint256 | The pool pid. |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| cryptoPerSecond | uint256 | CST reward per second. |
| endTime | uint256 | Period end time. |
$3
`solidity
function getLatestPeriodInfo(address _v3Pool) public view returns (uint256 cryptoPerSecond, uint256 endTime)
`
Returns the CST per second , period end time. This is for liquidity mining pool.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _v3Pool | address | Address of the V3 pool. |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| cryptoPerSecond | uint256 | CST reward per second. |
| endTime | uint256 | Period end time. |
$3
`solidity
function pendingcrypto(uint256 _tokenId) external view returns (uint256 reward)
`
View function for checking pending CST rewards.
_The pending CST amount is based on the last state in LMPool. The actual amount will happen whenever liquidity changes or harvest._
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _tokenId | uint256 | Token Id of NFT. |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| reward | uint256 | Pending reward. |
$3
`solidity
function setEmergency(bool _emergency) external
`
For emergency use only.
$3
`solidity
function setReceiver(address _receiver) external
`
$3
`solidity
function setLMPoolDeployer(ILMPoolDeployer _LMPoolDeployer) external
`
$3
`solidity
function add(uint256 _allocPoint, ICryptoV3Pool _v3Pool, bool _withUpdate) external
`
Add a new pool. Can only be called by the owner.
One v3 pool can only create one pool.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _allocPoint | uint256 | Number of allocation points for the new pool. |
| _v3Pool | ICryptoV3Pool | Address of the V3 pool. |
| _withUpdate | bool | Whether call "massUpdatePools" operation. |
$3
`solidity
function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) external
`
Update the given pool's CST allocation point. Can only be called by the owner.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _pid | uint256 | The id of the pool. See poolInfo. |
| _allocPoint | uint256 | New number of allocation points for the pool. |
| _withUpdate | bool | Whether call "massUpdatePools" operation. |
$3
`solidity
function onERC721Received(address, address _from, uint256 _tokenId, bytes) external returns (bytes4)
`
Upon receiving a ERC721
$3
`solidity
function harvest(uint256 _tokenId, address _to) external returns (uint256 reward)
`
harvest CST from pool.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _tokenId | uint256 | Token Id of NFT. |
| _to | address | Address to. |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| reward | uint256 | CST reward. |
$3
`solidity
function withdraw(uint256 _tokenId, address _to) external returns (uint256 reward)
`
Withdraw LP tokens from pool.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _tokenId | uint256 | Token Id of NFT to deposit. |
| _to | address | Address to which NFT token to withdraw. |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| reward | uint256 | CST reward. |
$3
`solidity
function updateLiquidity(uint256 _tokenId) external
`
Update liquidity for the NFT position.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _tokenId | uint256 | Token Id of NFT to update. |
$3
`solidity
function updateBoostMultiplier(uint256 _tokenId, uint256 _newMultiplier) external
`
Update farm boost multiplier for the NFT position.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _tokenId | uint256 | Token Id of NFT to update. |
| _newMultiplier | uint256 | New boost multiplier. |
$3
`solidity
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
`
$3
`solidity
function increaseLiquidity(struct 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
| Name | Type | Description |
| ---- | ---- | ----------- |
| params | struct IncreaseLiquidityParams | tokenId The ID of the token for which liquidity is being increased, amount0Desired The desired amount of token0 to be spent, amount1Desired The desired amount of token1 to be spent, amount0Min The minimum amount of token0 to spend, which serves as a slippage check, amount1Min The minimum amount of token1 to spend, which serves as a slippage check, deadline The time by which the transaction must be included to effect the change |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| liquidity | uint128 | The new liquidity amount as a result of the increase |
| amount0 | uint256 | The amount of token0 to acheive resulting liquidity |
| amount1 | uint256 | The amount of token1 to acheive resulting liquidity |
$3
`solidity
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
`
$3
`solidity
function decreaseLiquidity(struct DecreaseLiquidityParams params) external returns (uint256 amount0, uint256 amount1)
`
Decreases the amount of liquidity in a position and accounts it to the position
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| params | struct DecreaseLiquidityParams | tokenId The ID of the token for which liquidity is being decreased, amount The amount by which liquidity will be decreased, amount0Min The minimum amount of token0 that should be accounted for the burned liquidity, amount1Min The minimum amount of token1 that should be accounted for the burned liquidity, deadline The time by which the transaction must be included to effect the change |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| amount0 | uint256 | The amount of token0 accounted to the position's tokens owed |
| amount1 | uint256 | The amount of token1 accounted to the position's tokens owed |
$3
`solidity
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
`
$3
`solidity
function collect(struct 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
| Name | Type | Description |
| ---- | ---- | ----------- |
| params | struct CollectParams | tokenId The ID of the NFT for which tokens are being collected, recipient The account that should receive the tokens, |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| amount0 | uint256 | The amount of fees collected in token0 |
| amount1 | uint256 | The amount of fees collected in token1 |
$3
`solidity
function collectTo(struct CollectParams params, address to) external returns (uint256 amount0, uint256 amount1)
`
Collects up to a maximum amount of fees owed to a specific position to the recipient, then refund.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| params | struct CollectParams | CollectParams. |
| to | address | Refund recipient. |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| amount0 | uint256 | The amount of fees collected in token0 |
| amount1 | uint256 | The amount of fees collected in token1 |
$3
`solidity
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
| Name | Type | Description |
| ---- | ---- | ----------- |
| amountMinimum | uint256 | The minimum amount of WETH9 to unwrap |
| recipient | address | The address receiving ETH |
$3
`solidity
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
| Name | Type | Description |
| ---- | ---- | ----------- |
| token | address | The contract address of the token which will be transferred to recipient |
| amountMinimum | uint256 | The minimum amount of token required for a transfer |
| recipient | address | The destination address of the token |
$3
`solidity
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
| Name | Type | Description |
| ---- | ---- | ----------- |
| _tokenId | uint256 | The ID of the token that is being burned |
$3
`solidity
function upkeep(uint256 _amount, uint256 _duration, bool _withUpdate) external
`
Upkeep period.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _amount | uint256 | The amount of CST injected. |
| _duration | uint256 | The period duration. |
| _withUpdate | bool | Whether call "massUpdatePools" operation. |
$3
`solidity
function updatePools(uint256[] pids) external
`
Update CST reward for the liquidity mining pool.
_Avoid too many pools, and a single transaction cannot be fully executed for all pools._
$3
`solidity
function setOperator(address _operatorAddress) external
`
Set operator address.
_Callable by owner_
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _operatorAddress | address | New operator address. |
$3
`solidity
function setPeriodDuration(uint256 _periodDuration) external
`
Set period duration.
_Callable by owner_
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _periodDuration | uint256 | New period duration. |
$3
`solidity
function updateFarmBoostContract(address _newFarmBoostContract) external
`
Update farm boost contract address.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _newFarmBoostContract | address | The new farm booster address. |
$3
`solidity
error ZeroAddress()
`
$3
`solidity
error NotOwnerOrOperator()
`
$3
`solidity
error NoBalance()
`
$3
`solidity
error NotCryptoNFT()
`
$3
`solidity
error InvalidNFT()
`
$3
`solidity
error NotOwner()
`
$3
`solidity
error NoLiquidity()
`
$3
`solidity
error InvalidPeriodDuration()
`
$3
`solidity
error NoLMPool()
`
$3
`solidity
error InvalidPid()
`
$3
`solidity
error DuplicatedPool(uint256 pid)
`
$3
`solidity
error NotEmpty()
`
$3
`solidity
error WrongReceiver()
`
$3
`solidity
error InconsistentAmount()
`
$3
`solidity
error InsufficientAmount()
`
$3
`solidity
event Init()
`
$3
`solidity
event AddPool(uint256 pid, uint256 allocPoint, ICryptoV3Pool v3Pool, ILMPool lmPool)
`
$3
`solidity
event SetPool(uint256 pid, uint256 allocPoint)
`
$3
`solidity
event Deposit(address from, uint256 pid, uint256 tokenId, uint256 liquidity, int24 tickLower, int24 tickUpper)
`
$3
`solidity
event Withdraw(address from, address to, uint256 pid, uint256 tokenId)
`
$3
`solidity
event UpdateLiquidity(address from, uint256 pid, uint256 tokenId, int128 liquidity, int24 tickLower, int24 tickUpper)
`
$3
`solidity
event NewOperatorAddress(address operator)
`
$3
`solidity
event NewLMPoolDeployerAddress(address deployer)
`
$3
`solidity
event NewReceiver(address receiver)
`
$3
`solidity
event NewPeriodDuration(uint256 periodDuration)
`
$3
`solidity
event Harvest(address sender, address to, uint256 pid, uint256 tokenId, uint256 reward)
`
$3
`solidity
event NewUpkeepPeriod(uint256 periodNumber, uint256 startTime, uint256 endTime, uint256 cryptoPerSecond, uint256 cryptoAmount)
`
$3
`solidity
event UpdateUpkeepPeriod(uint256 periodNumber, uint256 oldEndTime, uint256 newEndTime, uint256 remainingcrypto)
`
$3
`solidity
event UpdateFarmBoostContract(address farmBoostContract)
`
$3
`solidity
event SetEmergency(bool emergency)
``