Verified contractExactMIT
v5Pay
Address0x4d50b623db02542bdeaa7eb57675cfed560e55b0
- Balance
0 ETH
- Transactions
6
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 23,926,449
- Creation transaction
- 0xfc69b3fdf3…4260a87b58
2 files
contracts/5_V5Pay.sol
// SPDX-License-Identifier: MIT
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
pragma solidity ^0.8.20;
interface ILido {
function submit(address _referral) external payable returns (uint256);
function balanceOf(address _account) external view returns (uint256);
function transfer(address _to, uint256 _amount) external returns (bool);
}
contract v5Pay is ReentrancyGuard {
ILido public lido;
address public owner;
address public manager;
uint256 public stakingDuration; // 抵押时间(单位:天)
uint256 public APR; // lido年化收益率 (百分比表示, 例如 500 表示 5%)
uint256 public ethToUsdt; //ETH 对应的 USDT 价格
uint256 public dayServicePrice; //每日服务费用 (单位:分USDT)
struct Deposit {
uint256 depositETHAmount;
uint256 shareRecivedAmount;
bool claimed;
uint256 startTimestamp;
uint256 unlockTimestamp;
}
mapping(address => Deposit) public deposits;
uint256 public totalUnClaimETH; //当前所有未提取用户的 stETH 总额
event Deposited(address indexed user, uint256 depositETHAmount, uint256 shareRecivedAmount);
event Claimed(address indexed user, uint256 depositETHAmount, uint256 shareRecivedAmount);
event ParametersUpdatedAPR(uint256 newAPR);
event ParametersUpdatedEthToUsdt(uint256 newEthToUsdt);
event ParametersUpdatedDayServicePrice(uint256 newDayServicePrice);
event ParametersUpdatedStakingDuration(uint256 newStakingDuration);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event ManagerUpdated(address indexed newManager);
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
// ⭐ 新增:仅 manager 才能执行的修饰符
modifier onlyManager() {
require(msg.sender == manager, "Not manager");
_;
}
constructor(
address _lidoAddress,
uint256 _APR,
uint256 _ethToUsdt,
uint256 _dayServicePrice,
uint256 _stakingDuration
) {
lido = ILido(_lidoAddress);
owner = msg.sender;
manager = msg.sender;
APR = _APR;
ethToUsdt = _ethToUsdt;
dayServicePrice = _dayServicePrice;
stakingDuration = _stakingDuration;
}
// -------------------------------------------
// 用户充值
// -------------------------------------------
function deposit() external payable nonReentrant {
require(msg.value > 0, "No ETH sent");
Deposit storage dep = deposits[msg.sender];
require(dep.depositETHAmount == 0 || dep.claimed, "Already deposited and not claimed");
uint256 requiredWei = getRequiredETHToCoverServiceCost();
require(msg.value >= requiredWei, "Insufficient ETH to cover service cost");
uint256 shareRecivedAmount = lido.submit{value: msg.value}(address(this));
uint256 startTimestamp = block.timestamp;
uint256 unlockTimestamp = startTimestamp + stakingDuration * 1 days;
deposits[msg.sender] = Deposit({
depositETHAmount: msg.value,
shareRecivedAmount: shareRecivedAmount,
claimed: false,
startTimestamp: startTimestamp,
unlockTimestamp: unlockTimestamp
});
totalUnClaimETH = totalUnClaimETH + msg.value;
emit Deposited(msg.sender, msg.value, shareRecivedAmount);
}
// -------------------------------------------
// 用户提取
// -------------------------------------------
function claim() external nonReentrant {
Deposit storage dep = deposits[msg.sender];
require(dep.depositETHAmount > 0, "No deposits found");
require(!dep.claimed, "Already claimed");
require(block.timestamp >= dep.unlockTimestamp, "Cannot claim yet");
dep.claimed = true;
bool success = lido.transfer(msg.sender, dep.depositETHAmount);
require(success, "Transfer failed");
totalUnClaimETH = totalUnClaimETH - dep.depositETHAmount;
emit Claimed(msg.sender, dep.depositETHAmount,dep.shareRecivedAmount);
}
// -------------------------------------------
// 参数修改(只有 manager 才能修改)
// -------------------------------------------
function updateAPR(uint256 _APR) external onlyManager {
require(_APR > 0, "APR must be greater than 0");
APR = _APR;
emit ParametersUpdatedAPR(_APR);
}
function updateEthToUsdt(uint256 _ethToUsdt) external onlyManager {
require(_ethToUsdt > 0, "ethToUsdt must be greater than 0");
ethToUsdt = _ethToUsdt;
emit ParametersUpdatedEthToUsdt(_ethToUsdt);
}
function updateDayServicePrice(uint256 _dayServicePrice) external onlyManager {
require(_dayServicePrice > 0, "dayServicePrice must be greater than 0");
dayServicePrice = _dayServicePrice;
emit ParametersUpdatedDayServicePrice(_dayServicePrice);
}
function updateStakingDuration(uint256 _stakingDuration) external onlyManager {
require(_stakingDuration > 0, "stakingDuration must be greater than 0");
stakingDuration = _stakingDuration;
emit ParametersUpdatedStakingDuration(_stakingDuration);
}
// -------------------------------------------
// 工具函数
// -------------------------------------------
function getRequiredETHToCoverServiceCost() public view returns (uint256) {
uint256 requiredWei = (dayServicePrice * 365 * 1e18 * 100) / (APR * ethToUsdt);
return requiredWei;
}
function getDeposit(address user) external view returns (Deposit memory) {
return deposits[user];
}
// -------------------------------------------
// Owner (仅 Owner)
// -------------------------------------------
function setManager(address newManager) external onlyOwner {
require(newManager != address(0), "Manager cannot be zero");
require(newManager != manager, "New manager is the same as the current owner");
manager = newManager;
emit ManagerUpdated(newManager);
}
// -------------------------------------------
// Owner (仅 Owner)
// -------------------------------------------
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "New owner address cannot be zero address");
require(newOwner != owner, "New owner is the same as the current owner");
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
// -------------------------------------------
// 提取收益(仅 Owner)
// -------------------------------------------
function withdrawServiceProfit(address to) external onlyOwner {
uint256 stEthBalance = lido.balanceOf(address(this));
require(stEthBalance > totalUnClaimETH, "No profit to withdraw");
uint256 profit = stEthBalance - totalUnClaimETH;
require(profit > 0, "No profit to withdraw");
require(lido.transfer(to, profit), "Transfer failed");
}
// -------------------------------------------
// 紧急提取(仅 Owner)
// -------------------------------------------
function emergencyWithdraw(address payable to) external onlyOwner nonReentrant {
uint256 stEthBalance = lido.balanceOf(address(this));
require(stEthBalance > 0, "No token can be withdraw");
require(lido.transfer(to, stEthBalance), "Transfer failed");
}
}@openzeppelin/contracts/utils/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.