编译器
0.8.16+commit.07a7930e
文件 1 的 15:AccessControl.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 2 的 15:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 15:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 4 的 15:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
文件 5 的 15:IAccessControl.sol
pragma solidity ^0.8.0;
interface IAccessControl {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
文件 6 的 15:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 7 的 15:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
文件 8 的 15:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 9 的 15:ILNDX.sol
pragma solidity 0.8.16;
interface ILNDX {
function feeToDistribute(uint256 amount) external;
}
文件 10 的 15:IveLNDX.sol
pragma solidity 0.8.16;
interface IveLNDX {
function mint(address account, uint256 amount) external;
function burn(address account, uint256 amount) external;
}
文件 11 的 15:LNDX.sol
pragma solidity 0.8.16;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "./interfaces/IveLNDX.sol";
import "./interfaces/ILNDX.sol";
contract LNDX is ILNDX, ERC20, Ownable, AccessControl {
enum StakePeriods {
MONTHS_3,
MONTHS_12,
MONTHS_48
}
struct Grant {
uint256 createdTime;
uint256 startTime;
uint256 amount;
uint256 vestingDuration;
uint256 daysClaimed;
uint256 totalClaimed;
address recipient;
uint256 veLndxClaimed;
uint256 remainingVeLndx;
uint256 remainingRewards;
uint256 remainingFee;
}
struct Stake {
address staker;
uint256 amount;
uint256 startTime;
uint256 endTime;
uint256 veLndxClaimed;
bool unstaked;
}
struct RewardVesting {
uint256 amountVested;
uint256 vestingStartedAt;
uint256 lastVestedAt;
uint256 daysClaimed;
}
bytes32 public constant FEE_DISTRIBUTOR = keccak256("FEE_DISTRIBUTOR");
uint256 public constant MAX_MINTABLE_AMOUNT = 80000000000000;
uint256 public constant MAX_REWARD_AMOUNT = 15600000000000;
uint256 public totalGranted = 0;
address usdc;
address veLNDX;
mapping(StakePeriods => uint8) public coefficients;
mapping(uint256 => Stake) public stakes;
uint256 public stakesCount;
mapping(address => Grant) public grants;
mapping(address => uint256) public feePerGrant;
mapping(address => uint256) public rewardsPerGrant;
mapping(uint256 => uint256) public feePerStake;
mapping(uint256 => uint256) public rewardsPerStake;
uint256 public feeSharesPerToken;
uint256 public feeNotDistributed;
uint256 public rewardSharesPerToken;
uint256 public rewardNotDistributed;
uint256 public totalStaked;
uint256 public totalLocked;
mapping (address => uint256[2]) public stakerClaimed;
mapping (address => uint256) public staked;
uint16 public rewardVestingDuration;
RewardVesting public rewardVested;
event GrantAdded(address recipient, uint256 amount, uint256 cliffEndAt, uint256 vestingEndAt);
event GrantTokensClaimed(address recipient, uint256 amountClaimed);
event Staked(address user, uint256 amount, uint256 stakeId, uint256 endAt);
event Unstaked(address user, uint256 amount, uint256 stakeId);
constructor(
address _usdc,
address _veLNDX,
uint16 _rewardVestingDuration
) ERC20("LandX Governance Token", "LNDX") {
require(_usdc != address(0), "zero address is not allowed");
require(_veLNDX != address(0), "zero address is not allowed");
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
usdc = _usdc;
veLNDX = _veLNDX;
coefficients[StakePeriods.MONTHS_3] = 25;
coefficients[StakePeriods.MONTHS_12] = 50;
coefficients[StakePeriods.MONTHS_48] = 100;
if (_rewardVestingDuration == 0) {
rewardVestingDuration = 1825;
} else {
rewardVestingDuration = _rewardVestingDuration;
}
}
function grantLNDX(
address recipient,
uint256 amount,
uint256 cliffInMonths,
uint256 vestingDurationInMonths
) external onlyOwner {
_rewardsToDistribute();
require(
(totalGranted + amount) <= (MAX_MINTABLE_AMOUNT - MAX_REWARD_AMOUNT),
"Mint limit amount exceeded"
);
if (cliffInMonths == 0 && vestingDurationInMonths == 0) {
_mint(recipient, amount);
totalGranted += amount;
return;
}
require(grants[recipient].amount == 0, "grant already exists");
require(cliffInMonths <= 60, "cliff greater than 5 year");
require(vestingDurationInMonths <= 60, "duration greater than 5 years");
uint256 totalPeriod = cliffInMonths + vestingDurationInMonths;
uint8 coefficient;
if (totalPeriod >= 48) {
coefficient = coefficients[StakePeriods.MONTHS_48];
}
else if (totalPeriod >= 12) {
coefficient = coefficients[StakePeriods.MONTHS_12];
} else {
coefficient = coefficients[StakePeriods.MONTHS_3];
}
_mint(address(this), amount);
totalGranted += amount;
totalLocked += amount;
uint256 veLNDXAmount = (amount * coefficient) / 100;
IveLNDX(veLNDX).mint(recipient, veLNDXAmount);
rewardsPerGrant[recipient] = rewardSharesPerToken * veLNDXAmount / 1e6;
feePerGrant[recipient] = feeSharesPerToken * veLNDXAmount / 1e6;
uint256 startTime = block.timestamp +
(30 days * uint256(cliffInMonths));
Grant memory grant = Grant({
createdTime: block.timestamp,
startTime: startTime,
amount: amount,
vestingDuration: vestingDurationInMonths * 30,
daysClaimed: 0,
totalClaimed: 0,
recipient: recipient,
veLndxClaimed: veLNDXAmount,
remainingVeLndx: veLNDXAmount,
remainingRewards: 0,
remainingFee: 0
});
grants[recipient] = grant;
emit GrantAdded(recipient, amount, startTime, startTime + vestingDurationInMonths * 30 * 1 days);
}
function claimVestedTokens() external {
uint256 daysVested;
uint256 amountVested;
(daysVested, amountVested) = calculateGrantClaim(msg.sender);
require(amountVested > 0, "wait one day or vested is 0");
_rewardsToDistribute();
Grant storage grant = grants[msg.sender];
grant.daysClaimed += daysVested;
grant.totalClaimed += amountVested;
uint256 veLNDXAmount = (amountVested * grant.veLndxClaimed) /
grant.amount;
if (grant.totalClaimed == grant.amount) {
veLNDXAmount = grant.remainingVeLndx;
}
IveLNDX(veLNDX).burn(msg.sender, veLNDXAmount);
totalLocked -= amountVested;
uint256 totalFee = computeGrantFee(msg.sender);
uint256 fee = (grant.totalClaimed * totalFee) / grant.amount;
uint256 totalRewards = computeGrantReward(msg.sender);
uint256 rewards = (grant.totalClaimed * totalRewards) / grant.amount;
grant.remainingVeLndx -= veLNDXAmount;
grant.remainingRewards = totalRewards - rewards;
grant.remainingFee = totalFee - fee;
rewardsPerGrant[msg.sender] = grant.remainingVeLndx * rewardSharesPerToken / 1e6;
feePerGrant[msg.sender] = grant.remainingVeLndx * feeSharesPerToken / 1e6;
IERC20(usdc).transfer(msg.sender, fee);
_transfer(address(this), grant.recipient, amountVested + rewards);
emit GrantTokensClaimed(grant.recipient, amountVested);
}
function computeGrantReward(address recipient)
public
view
returns (uint256)
{
Grant storage grant = grants[recipient];
return
(grant.remainingVeLndx * rewardSharesPerToken) /
1e6 -
rewardsPerGrant[recipient] + grant.remainingRewards;
}
function computeGrantFee(address recipient) public view returns (uint256) {
Grant storage grant = grants[recipient];
return
(grant.remainingVeLndx * feeSharesPerToken) /
1e6 -
feePerGrant[recipient] + grant.remainingFee;
}
function _rewardsToDistribute() internal {
if (rewardVested.amountVested >= MAX_REWARD_AMOUNT) {
return;
}
if (rewardVested.vestingStartedAt == 0) {
rewardVested.vestingStartedAt = block.timestamp;
}
if (rewardVested.lastVestedAt == 0) {
rewardVested.lastVestedAt = block.timestamp;
}
uint256 elapsedDays = (block.timestamp - rewardVested.lastVestedAt) / 1 days;
uint256 amountVested = 0;
if (elapsedDays > 0) {
uint256 amountVestedPerDay = MAX_REWARD_AMOUNT / uint256(rewardVestingDuration);
amountVested = amountVestedPerDay * elapsedDays;
if ((amountVested + rewardVested.amountVested) > MAX_REWARD_AMOUNT) {
amountVested = MAX_REWARD_AMOUNT - rewardVested.amountVested;
elapsedDays = rewardVestingDuration - rewardVested.daysClaimed;
}
rewardVested.daysClaimed += elapsedDays;
rewardVested.amountVested += amountVested;
rewardVested.lastVestedAt = block.timestamp;
_mint(address(this), amountVested);
uint256 tokensCount = IERC20(veLNDX).totalSupply();
if (tokensCount == 0) {
rewardNotDistributed += amountVested;
return;
}
rewardSharesPerToken +=
(1e6 * (amountVested + rewardNotDistributed)) /
tokensCount;
rewardNotDistributed = 0;
}
}
function calculateGrantClaim(address _recipient) public view returns (uint256, uint256) {
Grant storage grant = grants[_recipient];
require(grant.totalClaimed < grant.amount, "grant fully claimed");
if (block.timestamp < grant.startTime) {
return (0, 0);
}
uint256 elapsedDays = (block.timestamp - grant.startTime) / 1 days;
if (elapsedDays >= grant.vestingDuration) {
uint256 remainingGrant = grant.amount - grant.totalClaimed;
return (grant.vestingDuration - grant.daysClaimed, remainingGrant);
} else {
uint256 daysVested = elapsedDays - grant.daysClaimed;
uint256 amountVestedPerDay = grant.amount / grant.vestingDuration;
uint256 amountVested = daysVested * amountVestedPerDay;
return (daysVested, amountVested);
}
}
function feeToDistribute(uint256 amount)
external
onlyRole(FEE_DISTRIBUTOR)
{
uint256 tokensCount = IERC20(veLNDX).totalSupply();
if (tokensCount == 0) {
feeNotDistributed += amount;
return;
}
feeSharesPerToken += (1e6 * (amount + feeNotDistributed)) / tokensCount;
feeNotDistributed = 0;
}
function stakeLNDX(uint256 amount, StakePeriods period) external {
require(coefficients[period] != 0, "wrong period");
_transfer(msg.sender, address(this), amount);
uint256 mintAmount = (amount * coefficients[period]) / 100;
IveLNDX(veLNDX).mint(msg.sender, mintAmount);
_rewardsToDistribute();
Stake memory stake = Stake({
staker: msg.sender,
amount: amount,
startTime: block.timestamp,
endTime: _calculateEndDate(period),
unstaked: false,
veLndxClaimed: mintAmount
});
stakesCount++;
stakes[stakesCount] = stake;
totalStaked += amount;
staked[msg.sender] += amount;
feePerStake[stakesCount] += (feeSharesPerToken * mintAmount) / 1e6;
rewardsPerStake[stakesCount] +=
(rewardSharesPerToken * mintAmount) /
1e6;
emit Staked(msg.sender, amount, stakesCount, stake.endTime);
}
function unstake(uint256 stakeID) external {
require(stakes[stakeID].staker == msg.sender, "not staker");
require(stakes[stakeID].unstaked == false, "already unstaked");
require(stakes[stakeID].endTime <= block.timestamp, "too early");
Stake storage s = stakes[stakeID];
totalStaked -= s.amount;
staked[msg.sender] -= s.amount;
_rewardsToDistribute();
uint256 rewards = computeStakeReward(stakeID);
uint256 fee = computeStakeFee(stakeID);
stakerClaimed[s.staker][0] += fee;
stakerClaimed[s.staker][1] += rewards;
s.unstaked = true;
rewardsPerStake[stakeID] = 0;
feePerStake[stakeID] = 0;
_transfer(address(this), msg.sender, s.amount + rewards);
IveLNDX(veLNDX).burn(msg.sender, s.veLndxClaimed);
IERC20(usdc).transfer(msg.sender, fee);
emit Unstaked(msg.sender, s.amount, stakeID);
}
function _rewardsToDistributePreview() internal view returns (uint256){
if (rewardVested.amountVested >= MAX_REWARD_AMOUNT) {
return 0;
}
uint256 vestingStartedAt = rewardVested.vestingStartedAt;
uint256 lastVestedAt = rewardVested.lastVestedAt;
if (vestingStartedAt == 0) {
vestingStartedAt = block.timestamp;
}
if (lastVestedAt == 0) {
lastVestedAt = block.timestamp;
}
uint256 elapsedDays = (block.timestamp - lastVestedAt) / 1 days;
uint256 amountVested = 0;
if (elapsedDays > 0) {
uint256 amountVestedPerDay = MAX_REWARD_AMOUNT / uint256(rewardVestingDuration);
amountVested = amountVestedPerDay * elapsedDays;
if ((amountVested + rewardVested.amountVested) > MAX_REWARD_AMOUNT) {
amountVested = MAX_REWARD_AMOUNT - rewardVested.amountVested;
elapsedDays = rewardVestingDuration - rewardVested.daysClaimed;
}
uint256 tokensCount = IERC20(veLNDX).totalSupply();
uint256 _rewardNotDistributed = rewardNotDistributed;
if (tokensCount == 0) {
_rewardNotDistributed += amountVested;
return 0;
}
return (rewardSharesPerToken +
(1e6 * (amountVested + _rewardNotDistributed)) /
tokensCount);
}
return rewardSharesPerToken;
}
function unstakePreview(uint256 stakeID)
external
view
returns (
uint256,
uint256,
uint256
)
{
require(stakes[stakeID].unstaked == false, "already unstaked");
Stake storage s = stakes[stakeID];
uint256 _rewardSharesPerToken = _rewardsToDistributePreview();
uint256 rewards = (s.veLndxClaimed * _rewardSharesPerToken) / 1e6 - rewardsPerStake[stakeID];
uint256 fee = computeStakeFee(stakeID);
return (s.amount, fee, rewards);
}
function computeStakeReward(uint256 stakeID) public view returns (uint256) {
Stake storage stake = stakes[stakeID];
return
(stake.veLndxClaimed * rewardSharesPerToken) /
1e6 -
rewardsPerStake[stakeID];
}
function computeStakeFee(uint256 stakeID) public view returns (uint256) {
Stake storage stake = stakes[stakeID];
return
(stake.veLndxClaimed * feeSharesPerToken) /
1e6 -
feePerStake[stakeID];
}
function _calculateEndDate(StakePeriods period)
internal
view
returns (uint256)
{
if (period == StakePeriods.MONTHS_3) {
return (block.timestamp + 90 days);
}
if (period == StakePeriods.MONTHS_12) {
return (block.timestamp + 365 days);
}
if (period == StakePeriods.MONTHS_48) {
return (block.timestamp + 4 * 365 days);
}
return 0;
}
function decimals() public pure override returns (uint8) {
return 6;
}
function renounceOwnership() public view override onlyOwner {
revert ("can 't renounceOwnership here");
}
}
文件 12 的 15:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1, "Math: mulDiv overflow");
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
文件 13 的 15:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 14 的 15:SignedMath.sol
pragma solidity ^0.8.0;
library SignedMath {
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
function average(int256 a, int256 b) internal pure returns (int256) {
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
function abs(int256 n) internal pure returns (uint256) {
unchecked {
return uint256(n >= 0 ? n : -n);
}
}
}
文件 15 的 15:Strings.sol
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
{
"compilationTarget": {
"contracts/LNDX.sol": "LNDX"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_usdc","type":"address"},{"internalType":"address","name":"_veLNDX","type":"address"},{"internalType":"uint16","name":"_rewardVestingDuration","type":"uint16"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cliffEndAt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"vestingEndAt","type":"uint256"}],"name":"GrantAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountClaimed","type":"uint256"}],"name":"GrantTokensClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endAt","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakeId","type":"uint256"}],"name":"Unstaked","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_DISTRIBUTOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_MINTABLE_AMOUNT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_REWARD_AMOUNT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"calculateGrantClaim","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimVestedTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum LNDX.StakePeriods","name":"","type":"uint8"}],"name":"coefficients","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"computeGrantFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"computeGrantReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"stakeID","type":"uint256"}],"name":"computeStakeFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"stakeID","type":"uint256"}],"name":"computeStakeReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeNotDistributed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"feePerGrant","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"feePerStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeSharesPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"feeToDistribute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"cliffInMonths","type":"uint256"},{"internalType":"uint256","name":"vestingDurationInMonths","type":"uint256"}],"name":"grantLNDX","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"grants","outputs":[{"internalType":"uint256","name":"createdTime","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"vestingDuration","type":"uint256"},{"internalType":"uint256","name":"daysClaimed","type":"uint256"},{"internalType":"uint256","name":"totalClaimed","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"veLndxClaimed","type":"uint256"},{"internalType":"uint256","name":"remainingVeLndx","type":"uint256"},{"internalType":"uint256","name":"remainingRewards","type":"uint256"},{"internalType":"uint256","name":"remainingFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardNotDistributed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardSharesPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardVested","outputs":[{"internalType":"uint256","name":"amountVested","type":"uint256"},{"internalType":"uint256","name":"vestingStartedAt","type":"uint256"},{"internalType":"uint256","name":"lastVestedAt","type":"uint256"},{"internalType":"uint256","name":"daysClaimed","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardVestingDuration","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardsPerGrant","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardsPerStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum LNDX.StakePeriods","name":"period","type":"uint8"}],"name":"stakeLNDX","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"staked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"stakerClaimed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"stakes","outputs":[{"internalType":"address","name":"staker","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"uint256","name":"veLndxClaimed","type":"uint256"},{"internalType":"bool","name":"unstaked","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakesCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalGranted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLocked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"stakeID","type":"uint256"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"stakeID","type":"uint256"}],"name":"unstakePreview","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]