编译器
0.8.13+commit.abaa5c0e
文件 1 的 6: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;
}
}
文件 2 的 6:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
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);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 3 的 6:ILandAuction.sol
pragma solidity ^0.8.13;
interface ILandAuction {
function winningsBidsOf(address user) external view returns (uint256);
}
文件 4 的 6:ILockLeash.sol
pragma solidity ^0.8.13;
interface ILockLeash {
function lockInfoOf(address user)
external
view
returns (
uint256 amount,
uint256 startTime,
uint256 numDays,
address ogUser
);
function weightOf(address user) external view returns (uint256);
function extraLeashNeeded(address user, uint256 targetWeight)
external
view
returns (uint256);
function extraDaysNeeded(address user, uint256 targetWeight)
external
view
returns (uint256);
function isWinner(address user) external view returns (bool);
function unlockAt(address user) external view returns (uint256);
}
文件 5 的 6:LockLeash.sol
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/ILockLeash.sol";
import "./interfaces/ILandAuction.sol";
contract LockLeash is ILockLeash, Ownable {
uint256 public immutable AMOUNT_MIN;
uint256 public immutable AMOUNT_MAX;
uint256 public immutable DAYS_MIN;
uint256 public immutable DAYS_MAX;
IERC20 public immutable LEASH;
IERC20 public immutable BONE;
ILandAuction public landAuction;
bool public isLockEnabled;
uint256 public totalWeight;
uint256 public totalBoneRewards;
struct Lock {
uint256 amount;
uint256 startTime;
uint256 numDays;
address ogUser;
}
mapping(address => Lock) private _lockOf;
constructor(
address _leash,
address _bone,
uint256 amountMin,
uint256 amountMax,
uint256 daysMin,
uint256 daysMax
) {
LEASH = IERC20(_leash);
BONE = IERC20(_bone);
AMOUNT_MIN = amountMin;
AMOUNT_MAX = amountMax;
DAYS_MIN = daysMin;
DAYS_MAX = daysMax;
}
function lockInfoOf(address user)
public
view
returns (
uint256 amount,
uint256 startTime,
uint256 numDays,
address ogUser
)
{
return (
_lockOf[user].amount,
_lockOf[user].startTime,
_lockOf[user].numDays,
_lockOf[user].ogUser
);
}
function weightOf(address user) public view returns (uint256) {
return _lockOf[user].amount * _lockOf[user].numDays;
}
function extraLeashNeeded(address user, uint256 targetWeight)
external
view
returns (uint256)
{
uint256 currentWeight = weightOf(user);
if (currentWeight >= targetWeight) {
return 0;
}
return (targetWeight - currentWeight) / _lockOf[user].numDays;
}
function extraDaysNeeded(address user, uint256 targetWeight)
external
view
returns (uint256)
{
uint256 currentWeight = weightOf(user);
if (currentWeight >= targetWeight) {
return 0;
}
return (targetWeight - currentWeight) / _lockOf[user].amount;
}
function isWinner(address user) public view returns (bool) {
return landAuction.winningsBidsOf(user) > 0;
}
function unlockAt(address user) public view returns (uint256) {
Lock memory s = _lockOf[user];
if (isWinner(user)) {
return s.startTime + s.numDays * 1 days;
}
return s.startTime + 15 days + (s.numDays * 1 days) / 3;
}
function setLandAuction(address sale) external onlyOwner {
landAuction = ILandAuction(sale);
}
function addBoneRewards(uint256 rewardAmount) external onlyOwner {
totalBoneRewards += rewardAmount;
BONE.transferFrom(msg.sender, address(this), rewardAmount);
}
function toggleLockEnabled() external onlyOwner {
isLockEnabled = !isLockEnabled;
}
function lock(uint256 amount, uint256 numDaysToAdd) external {
require(isLockEnabled, "Locking not enabled");
Lock storage s = _lockOf[msg.sender];
uint256 oldWeight = s.amount * s.numDays;
s.amount += amount;
require(
AMOUNT_MIN <= s.amount && s.amount <= AMOUNT_MAX,
"LEASH amount outside of limits"
);
if (s.numDays == 0) {
s.startTime = block.timestamp;
s.ogUser = msg.sender;
}
if (numDaysToAdd > 0) {
s.numDays += numDaysToAdd;
}
uint256 numDays = s.numDays;
require(
DAYS_MIN <= numDays && numDays <= DAYS_MAX,
"Days outside of limits"
);
totalWeight += s.amount * s.numDays - oldWeight;
LEASH.transferFrom(msg.sender, address(this), amount);
}
function unlock() external {
Lock storage s = _lockOf[msg.sender];
uint256 amount = s.amount;
uint256 numDays = s.numDays;
require(amount > 0, "No LEASH locked");
require(unlockAt(msg.sender) <= block.timestamp, "Not unlocked yet");
delete _lockOf[msg.sender];
LEASH.transfer(msg.sender, amount);
BONE.transfer(
msg.sender,
(totalBoneRewards * amount * numDays) / totalWeight
);
}
function transferLock(address newOwner) external {
require(_lockOf[msg.sender].numDays != 0, "Lock does not exist");
require(_lockOf[newOwner].numDays == 0, "New owner already has a lock");
_lockOf[newOwner] = _lockOf[msg.sender];
delete _lockOf[msg.sender];
}
}
文件 6 的 6: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());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
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);
}
}
{
"compilationTarget": {
"contracts/LockLeash.sol": "LockLeash"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_leash","type":"address"},{"internalType":"address","name":"_bone","type":"address"},{"internalType":"uint256","name":"amountMin","type":"uint256"},{"internalType":"uint256","name":"amountMax","type":"uint256"},{"internalType":"uint256","name":"daysMin","type":"uint256"},{"internalType":"uint256","name":"daysMax","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"AMOUNT_MAX","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"AMOUNT_MIN","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BONE","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DAYS_MAX","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DAYS_MIN","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LEASH","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"name":"addBoneRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"targetWeight","type":"uint256"}],"name":"extraDaysNeeded","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"targetWeight","type":"uint256"}],"name":"extraLeashNeeded","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isLockEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isWinner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"landAuction","outputs":[{"internalType":"contract ILandAuction","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"numDaysToAdd","type":"uint256"}],"name":"lock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"lockInfoOf","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"numDays","type":"uint256"},{"internalType":"address","name":"ogUser","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sale","type":"address"}],"name":"setLandAuction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"toggleLockEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalBoneRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"unlockAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"weightOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]