Verified contractPartialUNLICENSED
WBTCPoolFeeder
Address0x7acc8d23ce290f0af3fce3ad7a3f7ebb3e8a1d5d
- Balance
0 ETH
- Transactions
423
- 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
- UNLICENSED
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 21,752,762
- Creation transaction
- 0x62a3854d52…88d58be1be
- 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/WBTCPoolFeeder.solmain9.99 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/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/pools/WBTCPool.sol7.72 KB
- src/utils/Errors.sol2.42 KB
- src/utils/Math.sol17.95 KB
- src/utils/Time.sol3.57 KB
src/WBTCPoolFeeder.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.27;
import "@actions/SwapActions.sol";
import {wmul} from "@utils/Math.sol";
import {Time} from "@utils/Time.sol";
import {WBTCPool} from "@core/pools/WBTCPool.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
contract WBTCPoolFeeder is SwapActions {
using SafeERC20 for *;
//=============STRUCTS============//
/// @notice Struct to represent intervals for burning
struct Interval {
uint256 amountAllocated;
uint256 amountBurned;
}
//===========IMMUTABLE===========//
///@notice The startTimestamp
uint32 public immutable startTimeStamp;
IERC20 immutable weth;
WBTCPool immutable wbtcPool;
IERC20 immutable wbtc;
//===========STATE===========//
/// @notice Timestamp of the last burn call
uint32 public lastBurnedIntervalStartTimestamp;
/// @notice Last interval number
uint32 public lastIntervalNumber;
/// @notice Last burned interval
uint32 public lastBurnedInterval;
/// @notice That last snapshot timestamp
uint32 public lastSnapshot;
///@notice WETH Swap cap
uint256 public swapCap;
/// @notice Mapping from interval number to Interval struct
mapping(uint32 interval => Interval) public intervals;
/// @notice Total WETH tokens distributed
uint256 public totalWETHDistributed;
uint256 public toDistribute;
//===========EVENTS===========//
/// @notice Event emitted when tokens are bought and burnt
event BuyAndBurn(uint256 indexed wbtcAmount, uint256 indexed vyperReceived, address indexed caller);
//===========ERRORS===========//
/// @notice Error when the contract has not started yet
error NotStartedYet();
/// @notice Error when interval has already been burned
error IntervalAlreadyBurned();
error MustStartAt5PMUTC();
error BuyAndBurn__OnlyEOA();
//========CONSTRUCTOR========//
/// @notice Constructor initializes the contract
constructor(
uint32 _startTimestamp,
address _weth,
address _wbtc,
address _wbtcPool,
SwapActionParams memory _params
) SwapActions(_params) {
swapCap = type(uint256).max;
wbtcPool = WBTCPool(_wbtcPool);
weth = IERC20(_weth);
wbtc = IERC20(_wbtc);
startTimeStamp = _startTimestamp;
}
//========MODIFIERS=======//
/// @notice Updates the contract state for intervals
modifier intervalUpdate() {
_intervalUpdate();
_;
}
//==========================//
//==========PUBLIC==========//
//==========================//
function changeSwapCap(uint256 _newSwapCap) external onlySlippageAdminOrOwner {
swapCap = _newSwapCap == 0 ? type(uint256).max : _newSwapCap;
}
/**
* @notice Swaps WETH for WBTC and sends to WBTC Pools
* @param _deadline The deadline for which the passes should pass
*/
function swapWETHToWBTCAndDistribute(uint32 _deadline) external intervalUpdate {
if (msg.sender != tx.origin) revert BuyAndBurn__OnlyEOA();
Interval storage currInterval = intervals[lastIntervalNumber];
if (currInterval.amountBurned != 0) revert IntervalAlreadyBurned();
_updateSnapshot();
if (currInterval.amountAllocated > swapCap) {
uint256 difference = currInterval.amountAllocated - swapCap;
//@note - Add the difference for the next day
toDistribute += difference;
currInterval.amountAllocated = swapCap;
}
uint256 incentive = wmul(currInterval.amountAllocated, INCENTIVE_FEE);
currInterval.amountBurned = currInterval.amountAllocated;
uint256 wbtcAmount =
swapExactInput(address(weth), address(wbtc), currInterval.amountAllocated - incentive, 0, 500, _deadline);
weth.safeTransfer(msg.sender, incentive);
wbtc.approve(address(wbtcPool), wbtcAmount);
wbtcPool.distribute(wbtcAmount);
lastBurnedInterval = lastIntervalNumber;
emit BuyAndBurn(currInterval.amountAllocated - incentive, wbtcAmount, msg.sender);
}
/**
* @notice Distributes WETH tokens for burning
* @param _amount The amount of WETH tokens
*/
function distributeWETH(uint256 _amount) external notAmount0(_amount) {
///@dev - If there are some missed intervals update the accumulated allocation before depositing new WETH
if (Time.blockTs() > startTimeStamp && Time.blockTs() - lastBurnedIntervalStartTimestamp > INTERVAL_TIME) {
_intervalUpdate();
}
weth.safeTransferFrom(msg.sender, address(this), _amount);
_updateSnapshot();
toDistribute += _amount;
}
//==========================//
//=========INTERNAL=========//
//==========================//
function _calculateIntervals(uint256 timeElapsedSince)
internal
view
returns (uint32 _lastIntervalNumber, uint256 _totalAmountForInterval, uint32 missedIntervals)
{
missedIntervals = _calculateMissedIntervals(timeElapsedSince);
_lastIntervalNumber = lastIntervalNumber + missedIntervals + 1;
uint32 currentDay = Time.dayCountByT(uint32(block.timestamp));
uint32 _lastBurnedIntervalTimestamp = lastBurnedIntervalStartTimestamp;
uint32 dayOfLastInterval =
_lastBurnedIntervalTimestamp == 0 ? currentDay : Time.dayCountByT(_lastBurnedIntervalTimestamp);
uint256 _totalWETHDistributed = totalWETHDistributed;
if (currentDay == dayOfLastInterval) {
_totalAmountForInterval = (_totalWETHDistributed * (missedIntervals + 1)) / INTERVALS_PER_DAY;
} else {
uint32 _lastBurnedIntervalStartTimestamp = _lastBurnedIntervalTimestamp;
uint32 theEndOfTheDay = Time.getDayEnd(_lastBurnedIntervalStartTimestamp);
uint32 accumulatedIntervalsForTheDay = (theEndOfTheDay - _lastBurnedIntervalStartTimestamp) / INTERVAL_TIME;
//@note - Calculate the remaining intervals from the last one's day
_totalAmountForInterval +=
uint256(_totalWETHDistributed * accumulatedIntervalsForTheDay) / INTERVALS_PER_DAY;
//@note - Calculate the upcoming intervals with the to distribute shares
uint256 _intervalsForNewDay = missedIntervals >= accumulatedIntervalsForTheDay
? (missedIntervals - accumulatedIntervalsForTheDay) + 1
: 0;
_totalAmountForInterval += (_intervalsForNewDay > INTERVALS_PER_DAY)
? uint256(toDistribute)
: uint256(toDistribute * _intervalsForNewDay) / INTERVALS_PER_DAY;
}
Interval memory prevInt = intervals[lastIntervalNumber];
//@note - If the last interval was only updated, but not burned add its allocation to the next one.
uint256 additional = prevInt.amountBurned == 0 && prevInt.amountAllocated != 0 ? prevInt.amountAllocated : 0;
if (_totalAmountForInterval + additional > weth.balanceOf(address(this))) {
_totalAmountForInterval = uint256(weth.balanceOf(address(this)));
} else {
_totalAmountForInterval += additional;
}
}
function _calculateMissedIntervals(uint256 timeElapsedSince) internal view returns (uint32 _missedIntervals) {
_missedIntervals = uint32(timeElapsedSince / INTERVAL_TIME);
if (lastBurnedIntervalStartTimestamp != 0) _missedIntervals--;
}
function _updateSnapshot() internal {
if (Time.blockTs() < startTimeStamp || lastSnapshot + 24 hours > Time.blockTs()) return;
if (lastSnapshot != 0 && lastSnapshot + 48 hours <= Time.blockTs()) {
// If we have missed entire snapshot of interacting with the contract
toDistribute = 0;
}
totalWETHDistributed = toDistribute;
toDistribute = 0;
uint32 timeElapsed = Time.blockTs() - startTimeStamp;
uint32 snapshots = timeElapsed / 24 hours;
lastSnapshot = startTimeStamp + (snapshots * 24 hours);
}
/// @notice Updates the contract state for intervals
function _intervalUpdate() private {
if (Time.blockTs() < startTimeStamp) revert NotStartedYet();
if (lastSnapshot == 0) _updateSnapshot();
(
uint32 _lastInterval,
uint256 _amountAllocated,
uint32 _missedIntervals,
uint32 _lastIntervalStartTimestamp,
bool updated
) = getCurrentInterval();
if (updated) {
lastBurnedIntervalStartTimestamp = _lastIntervalStartTimestamp + (uint32(_missedIntervals) * INTERVAL_TIME);
intervals[_lastInterval] = Interval({amountAllocated: _amountAllocated, amountBurned: 0});
lastIntervalNumber = _lastInterval;
}
}
function getCurrentInterval()
public
view
returns (
uint32 _lastInterval,
uint256 _amountAllocated,
uint32 _missedIntervals,
uint32 _lastIntervalStartTimestamp,
bool updated
)
{
if (startTimeStamp > Time.blockTs()) return (0, 0, 0, 0, false);
uint32 startPoint = lastBurnedIntervalStartTimestamp == 0 ? startTimeStamp : lastBurnedIntervalStartTimestamp;
uint32 timeElapseSinceLastBurn = Time.blockTs() - startPoint;
if (lastBurnedIntervalStartTimestamp == 0 || timeElapseSinceLastBurn > INTERVAL_TIME) {
(_lastInterval, _amountAllocated, _missedIntervals) = _calculateIntervals(timeElapseSinceLastBurn);
_lastIntervalStartTimestamp = startPoint;
_missedIntervals += timeElapseSinceLastBurn > INTERVAL_TIME && lastBurnedIntervalStartTimestamp != 0 ? 1 : 0;
updated = true;
}
}
}
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.