Verified contractPartialMIT
WBTCPool
Address0xa4f02fa811a7a08850f2e6a00a04a4890cbea40b
- Balance
0 ETH
- Transactions
54
- Compiler
solc 0.8.27
- Same code
Only this contract
Details
- Compiler
- solc 0.8.27+commit.40a35a09
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- shanghai
- License
- MIT
- Match
- Partialcreation code: no, runtime code: yes
- Verified on Sourcify
- Created in block
- 21,752,762
- Creation transaction
- 0x33c2fb1e1f…d7ad369b67
- Libraries
- src/utils/Time.sol:Time0x5dcd…d133d3
99 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/pools/WBTCPool.solmain7.72 KB
- lib/chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol382 B
- lib/chainlink/contracts/src/v0.8/shared/access/ConfirmedOwnerWithProposal.sol2.11 KB
- lib/chainlink/contracts/src/v0.8/shared/interfaces/IOwnable.sol226 B
- lib/chainlink/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol8.33 KB
- lib/chainlink/contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2Plus.sol2.13 KB
- lib/chainlink/contracts/src/v0.8/vrf/dev/interfaces/IVRFMigratableConsumerV2Plus.sol554 B
- lib/chainlink/contracts/src/v0.8/vrf/dev/interfaces/IVRFSubscriptionV2Plus.sol3.93 KB
- lib/chainlink/contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol641 B
- lib/devtools/packages/oapp-evm/contracts/oapp/OApp.sol1.53 KB
- lib/devtools/packages/oapp-evm/contracts/oapp/OAppCore.sol3.36 KB
- lib/devtools/packages/oapp-evm/contracts/oapp/OAppReceiver.sol5.41 KB
- lib/devtools/packages/oapp-evm/contracts/oapp/OAppSender.sol5.63 KB
- lib/devtools/packages/oapp-evm/contracts/oapp/interfaces/IOAppCore.sol1.86 KB
- lib/devtools/packages/oapp-evm/contracts/oapp/interfaces/IOAppMsgInspector.sol909 B
- lib/devtools/packages/oapp-evm/contracts/oapp/interfaces/IOAppOptionsType3.sol1.44 KB
- lib/devtools/packages/oapp-evm/contracts/oapp/interfaces/IOAppReceiver.sol1.08 KB
- lib/devtools/packages/oapp-evm/contracts/oapp/libs/OAppOptionsType3.sol4.9 KB
- lib/devtools/packages/oapp-evm/contracts/precrime/OAppPreCrimeSimulator.sol5.36 KB
- lib/devtools/packages/oapp-evm/contracts/precrime/interfaces/IOAppPreCrimeSimulator.sol1.92 KB
- lib/devtools/packages/oapp-evm/contracts/precrime/interfaces/IPreCrime.sol1.11 KB
- lib/devtools/packages/oapp-evm/contracts/precrime/libs/Packet.sol2.47 KB
- lib/devtools/packages/oft-evm/contracts/OFT.sol3.4 KB
- lib/devtools/packages/oft-evm/contracts/OFTCore.sol20.36 KB
- lib/devtools/packages/oft-evm/contracts/interfaces/IOFT.sol6.24 KB
- lib/devtools/packages/oft-evm/contracts/libs/OFTComposeMsgCodec.sol2.99 KB
- lib/devtools/packages/oft-evm/contracts/libs/OFTMsgCodec.sol2.91 KB
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol2.59 KB
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/interfaces/ILayerZeroReceiver.sol519 B
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/interfaces/IMessageLib.sol805 B
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/interfaces/IMessageLibManager.sol2.76 KB
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/interfaces/IMessagingChannel.sol1.54 KB
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/interfaces/IMessagingComposer.sol1.03 KB
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/interfaces/IMessagingContext.sol239 B
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/interfaces/ISendLib.sol923 B
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/libs/AddressCast.sol1.47 KB
- lib/layerzero-v2/packages/layerzero-v2/evm/protocol/contracts/messagelib/libs/PacketV1Codec.sol3.67 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol2.48 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol192 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol181 B
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10.9 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Burnable.sol1.18 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol9.44 KB
- lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol16.46 KB
- lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol4.93 KB
- lib/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol997 B
- lib/openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Enumerable.sol1.04 KB
- lib/openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol792 B
- lib/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Utils.sol1.91 KB
- lib/openzeppelin-contracts/contracts/utils/Address.sol6.03 KB
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- lib/openzeppelin-contracts/contracts/utils/Strings.sol3.93 KB
- lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol912 B
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol870 B
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol28.31 KB
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol2.61 KB
- lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol12.89 KB
- lib/v3-core/contracts/interfaces/IUniswapV3Pool.sol1.09 KB
- lib/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol1.29 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolActions.sol6.3 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol2.6 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolErrors.sol390 B
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolEvents.sol5.96 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol1.81 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol1.19 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol6.67 KB
- lib/v3-core/contracts/libraries/TickMath.sol9.42 KB
- lib/v3-periphery/contracts/interfaces/IERC721Permit.sol1.46 KB
- lib/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol8.63 KB
- lib/v3-periphery/contracts/interfaces/IPeripheryImmutableState.sol419 B
- lib/v3-periphery/contracts/interfaces/IPeripheryPayments.sol1.42 KB
- lib/v3-periphery/contracts/interfaces/IPoolInitializer.sol1.16 KB
- lib/v3-periphery/contracts/interfaces/IQuoter.sol2.79 KB
- lib/v3-periphery/contracts/interfaces/ISwapRouter.sol2.72 KB
- lib/v3-periphery/contracts/libraries/PoolAddress.sol1.9 KB
- src/BuyAndBurn.sol10.61 KB
- src/LotusEdenBnBFeeder.sol10.39 KB
- src/Mining.sol20.7 KB
- src/Shaolin.sol3.81 KB
- src/Staking.sol15.19 KB
- src/WBTCPoolFeeder.sol9.99 KB
- src/actions/SwapActions.sol7.08 KB
- src/const/Constants.sol2.36 KB
- src/interfaces/ILotusEdenBnB.sol151 B
- src/interfaces/IWETH9.sol376 B
- src/libs/OracleLibrary.sol7.29 KB
- src/libs/PoolAddress.sol1.87 KB
- src/pools/LamboPool.sol13.67 KB
- src/utils/Errors.sol2.42 KB
- src/utils/Math.sol17.95 KB
- src/utils/Time.sol3.57 KB
src/pools/WBTCPool.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;
import "@const/Constants.sol";
import {Time} from "@utils/Time.sol";
import {Errors} from "@utils/Errors.sol";
import {wdiv, wmul} from "@utils/Math.sol";
import {ShaolinMining} from "@core/Mining.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
struct CycleState {
uint256 totalShares; //< Total shares in the cycle.
uint256 available; //< Rewards per share for the cycle.
mapping(address user => uint256 shares) sharesOf; //< Shares of a user for a cycle
}
/**
* @title WBTCPool
* @dev Manages rewards distribution for WBTC staking cycles.
*/
contract WBTCPool is Errors {
using SafeERC20 for IERC20;
/// @notice Duration of each rewards cycle in days.
uint32 constant DURATION_PER_CYCLE = 28;
/// @notice Reference to the ShaolinMining contract.
ShaolinMining immutable mining;
/// @notice Reference to the WBTC ERC20 token contract.
IERC20 public immutable wbtc;
/// @notice The start timestamp of the contract.
uint32 public immutable startTimestamp;
/// @dev Mapping of cycle numbers to their respective cycle states.
mapping(uint32 cycle => CycleState) cycles;
/// @dev Tracks pending shares for users in specific cycles.
mapping(uint32 cycle => mapping(address _user => uint256)) public pendingShares;
/// @notice Emitted when shares are added for a user.
/// @param _user The address of the user.
/// @param _cycle The cycle for which the user deposited
/// @param additionalAmount The amount of shares added.
event SharesAdded(address indexed _user, uint32 indexed _cycle, uint256 indexed additionalAmount);
/// @notice Emitted when shares are added for a user.
/// @param _user The address of the user.
/// @param _cycle The cycle for which the user deposited
/// @param _claimed The amount of WBTC claimed.
event RewardClaimed(address indexed _user, uint32 indexed _cycle, uint256 indexed _claimed);
/// @notice Thrown when a function is called by an address other than the mining contract.
error WBTCPool__OnlyMining();
/// @notice Thrown when there are no rewards available to claim.
error WBTCPool__NothingToClaim();
error WBTCPool__CycleNotOver();
/**
* @dev Initializes the contract with the given parameters.
* @param _startTimestamp The timestamp when the contract starts.
* @param _wbtc The address of the WBTC token.
* @param _mining The address of the ShaolinMining contract.
*/
constructor(uint32 _startTimestamp, address _wbtc, address _mining) {
mining = ShaolinMining(payable(_mining));
wbtc = IERC20(_wbtc);
startTimestamp = _startTimestamp;
}
/// @dev Modifier to restrict access to the mining contract.
modifier onlyMining() {
_onlyMining();
_;
}
/**
* @notice Adds shares to a user for the current cycle.
* @param _user The address of the user.
* @param _amount The amount of shares to add.
*/
function addToShares(address _user, uint256 _amount) public onlyMining {
uint32 _currCycle = getCurrentCycle();
CycleState storage _cycle = cycles[_currCycle];
uint256 shares = _cycle.sharesOf[_user];
if (shares > 0) {
emit SharesAdded(_user, _currCycle, _amount);
_cycle.totalShares += _amount;
_cycle.sharesOf[_user] += _amount;
} else {
pendingShares[_currCycle][_user] += _amount;
uint256 total = pendingShares[_currCycle][_user];
if (total < MIN_SHAO_FOR_WBTC_POOL) return;
emit SharesAdded(_user, _currCycle, _amount);
_cycle.totalShares += total;
_cycle.sharesOf[_user] += total;
pendingShares[_currCycle][_user] = 0;
}
}
/**
* @notice Calculates the claimable rewards for a user in a specific cycle.
* @param _user The address of the user.
* @param _cycle The cycle number.
* @return The claimable rewards amount.
*/
function claimableAmount(address _user, uint32 _cycle) public view returns (uint256) {
CycleState storage _cycleState = cycles[_cycle];
uint256 shares = _cycleState.sharesOf[_user];
uint256 available;
if (_cycleState.totalShares == 0) return 0;
if (_cycle < getCurrentCycle()) available = _cycleState.available;
return (((shares * available) * WAD) / _cycleState.totalShares) / WAD;
}
/**
* @notice Calculates the total claimable rewards for a user across multiple cycles.
* @param _user The address of the user.
* @param _cycles The array of cycle numbers.
* @return total The total claimable rewards.
*/
function batchClaimableAmount(address _user, uint32[] calldata _cycles) external view returns (uint256 total) {
for (uint32 i; i < _cycles.length; i++) {
total += claimableAmount(_user, _cycles[i]);
}
}
/**
* @notice Claims rewards for a user across multiple cycles.
* @param _receiver The address to send the rewards to.
* @param _cycles The array of cycle numbers.
*/
function batchClaim(address _receiver, uint32[] calldata _cycles) external {
for (uint32 i; i < _cycles.length; i++) {
claim(_receiver, _cycles[i]);
}
}
/**
* @notice Claims rewards for a specific cycle and sends them to the receiver.
* @param _receiver The address to send the rewards to.
* @param _cycle The cycle number for which to claim rewards.
*/
function claim(address _receiver, uint32 _cycle) public notAddress0(_receiver) {
require(_cycle < getCurrentCycle(), WBTCPool__CycleNotOver());
CycleState storage _cycleState = cycles[_cycle];
uint256 amountToClaim = claimableAmount(msg.sender, _cycle);
require(amountToClaim > 0, WBTCPool__NothingToClaim());
_cycleState.sharesOf[msg.sender] = 0;
emit RewardClaimed(msg.sender, _cycle, amountToClaim);
wbtc.transfer(_receiver, amountToClaim);
}
/**
* @notice Distributes rewards to the current cycle.
* @param amount The amount of rewards to distribute.
*/
function distribute(uint256 amount) external notAmount0(amount) {
cycles[getCurrentCycle()].available += amount;
wbtc.safeTransferFrom(msg.sender, address(this), amount);
}
/**
* @dev Returns the current cycle number based on the current day.
* @return cycle The current cycle number.
*/
function getCurrentCycle() public view returns (uint32 cycle) {
uint32 currentDay = _getCurrentDay();
cycle = (currentDay / DURATION_PER_CYCLE) + 1;
}
function getAvailableForCycle(uint32 _cycle) external view returns (uint256 available) {
return cycles[_cycle].available;
}
function getShareOfUserForCycle(uint32 _cycle, address _user) public view returns (uint256 shares) {
return cycles[_cycle].sharesOf[_user];
}
/**
* @dev Returns the current day since the contract started.
* @return currentDay The current day.
*/
function _getCurrentDay() internal view returns (uint32 currentDay) {
if (startTimestamp > Time.blockTs()) return 1;
currentDay = Time.dayGap(startTimestamp, Time.blockTs()) + 1;
}
/**
* @dev Ensures that the caller is the mining contract.
*/
function _onlyMining() internal view {
require(msg.sender == address(mining), WBTCPool__OnlyMining());
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {
"src/utils/Time.sol": {
"Time": "0x5dcd2315a462f0046641b2118e106fbb47d133d3"
}
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "shanghai",
"remappings": [
":@actions/=src/actions/",
":@chainlink/=lib/chainlink/",
":@const/=src/const/",
":@core/=src/",
":@interfaces/=src/interfaces/",
":@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/protocol/",
":@layerzerolabs/oapp-evm/=lib/devtools/packages/oapp-evm/",
":@layerzerolabs/oft-evm/=lib/devtools/packages/oft-evm/",
":@libs/=src/libs/",
":@murky/=lib/murky/src/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@script/=script/",
":@uniswap/v2-core/=lib/v2-core/",
":@uniswap/v2-periphery/=lib/v2-periphery/",
":@uniswap/v3-core/=lib/v3-core/",
":@uniswap/v3-periphery/=lib/v3-periphery/",
":@utils/=src/utils/",
":chainlink/=lib/chainlink/",
":devtools/=lib/devtools/packages/toolbox-foundry/src/",
":ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
":layerzero-v2/=lib/layerzero-v2/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":v3-core/=lib/v3-core/contracts/",
":v3-periphery/=lib/v3-periphery/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.