编译器
0.8.10+commit.fc410830
文件 1 的 13: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 的 13:ERC721Holder.sol
pragma solidity ^0.8.0;
import "../IERC721Receiver.sol";
contract ERC721Holder is IERC721Receiver {
function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
}
文件 3 的 13:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 4 的 13: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 recipient, 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 sender,
address recipient,
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);
}
文件 5 的 13:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
文件 6 的 13:IERC721Enumerable.sol
pragma solidity ^0.8.0;
import "../IERC721.sol";
interface IERC721Enumerable is IERC721 {
function totalSupply() external view returns (uint256);
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
function tokenByIndex(uint256 index) external view returns (uint256);
}
文件 7 的 13:IERC721Receiver.sol
pragma solidity ^0.8.0;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 8 的 13:Journey.sol
pragma solidity ^0.8.10;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "../shared/interfaces/RealmsToken.sol";
import "../shared/interfaces/LordsToken.sol";
contract Journey is ERC721Holder, Ownable, ReentrancyGuard, Pausable {
event StakeRealms(uint256[] tokenIds, address player);
event UnStakeRealms(uint256[] tokenIds, address player);
mapping(address => uint256) epochClaimed;
mapping(uint256 => address) ownership;
mapping(address => mapping(uint256 => uint256)) public realmsStaked;
LordsToken lordsToken;
RealmsToken realmsToken;
address bridge;
uint256 lordsPerRealm;
uint256 genesis;
uint256 epoch;
uint256 finalAge;
constructor(
uint256 _lordsPerRealm,
uint256 _epoch,
address _realmsAddress,
address _lordsToken
) {
genesis = block.timestamp;
lordsPerRealm = _lordsPerRealm;
epoch = _epoch;
lordsToken = LordsToken(_lordsToken);
realmsToken = RealmsToken(_realmsAddress);
}
function lordsIssuance(uint256 _new) external onlyOwner {
lordsPerRealm = _new * 10**18;
}
function updateRealmsAddress(address _newRealms) external onlyOwner {
realmsToken = RealmsToken(_newRealms);
}
function updateLordsAddress(address _newLords) external onlyOwner {
lordsToken = LordsToken(_newLords);
}
function updateEpochLength(uint256 _newEpoch) external onlyOwner {
epoch = _newEpoch;
}
function setBridge(address _newBridge) external onlyOwner {
bridge = _newBridge;
}
function pause() external onlyOwner {
_pause();
}
function unpause() external onlyOwner {
_unpause();
}
function setFinalAge(uint256 _finalAge) external onlyOwner {
finalAge = _finalAge;
}
function _epochNum() internal view returns (uint256) {
if (finalAge != 0) {
return finalAge;
} else {
return (block.timestamp - genesis) / (epoch * 3600);
}
}
function boardShip(uint256[] memory _tokenIds)
external
whenNotPaused
nonReentrant
{
for (uint256 i = 0; i < _tokenIds.length; i++) {
require(
realmsToken.ownerOf(_tokenIds[i]) == msg.sender,
"NOT_OWNER"
);
ownership[_tokenIds[i]] = msg.sender;
realmsToken.safeTransferFrom(
msg.sender,
address(this),
_tokenIds[i]
);
}
if (getNumberRealms(msg.sender) == 0) {
epochClaimed[msg.sender] = _epochNum();
}
realmsStaked[msg.sender][_epochNum()] += uint256(_tokenIds.length);
emit StakeRealms(_tokenIds, msg.sender);
}
function exitShip(uint256[] memory _tokenIds)
external
whenNotPaused
nonReentrant
{
_exitShip(_tokenIds);
}
function _exitShip(uint256[] memory _tokenIds) internal {
if (lordsAvailable(msg.sender) != 0) {
_claimLords();
}
for (uint256 i = 0; i < _tokenIds.length; i++) {
require(ownership[_tokenIds[i]] == msg.sender, "NOT_OWNER");
ownership[_tokenIds[i]] = address(0);
realmsToken.safeTransferFrom(
address(this),
msg.sender,
_tokenIds[i]
);
}
if (_epochNum() == 0) {
realmsStaked[msg.sender][_epochNum()] -= _tokenIds.length;
} else {
uint256 realmsInPrevious = realmsStaked[msg.sender][
_epochNum() - 1
];
uint256 realmsInCurrent = realmsStaked[msg.sender][_epochNum()];
if (realmsInPrevious > _tokenIds.length) {
realmsStaked[msg.sender][_epochNum() - 1] -= _tokenIds.length;
} else if (realmsInCurrent == _tokenIds.length) {
realmsStaked[msg.sender][_epochNum()] -= _tokenIds.length;
} else if (realmsInPrevious <= _tokenIds.length) {
uint256 oldestFirst = (_tokenIds.length - realmsInPrevious);
realmsStaked[msg.sender][_epochNum() - 1] -= (_tokenIds.length -
oldestFirst);
realmsStaked[msg.sender][_epochNum()] -= oldestFirst;
}
}
emit UnStakeRealms(_tokenIds, msg.sender);
}
function claimLords() external whenNotPaused nonReentrant {
_claimLords();
}
function _claimLords() internal {
uint256 totalClaimable;
uint256 totalRealms;
require(_epochNum() > 1, "GENESIS_epochNum");
for (uint256 i = epochClaimed[msg.sender]; i < _epochNum(); i++) {
totalRealms += realmsStaked[msg.sender][i];
totalClaimable +=
realmsStaked[msg.sender][i] *
((_epochNum() - 1) - i);
}
realmsStaked[msg.sender][_epochNum() - 1] = totalRealms;
epochClaimed[msg.sender] = _epochNum() - 1;
require(totalClaimable > 0, "NOTHING_TO_CLAIM");
uint256 lords = lordsPerRealm * totalClaimable;
lordsToken.approve(address(this), lords);
lordsToken.transferFrom(address(this), msg.sender, lords);
}
function lordsAvailable(address _player)
public
view
returns (uint256 lords)
{
uint256 totalClaimable;
if (_epochNum() > 1) {
for (uint256 i = epochClaimed[_player]; i < _epochNum(); i++) {
totalClaimable +=
realmsStaked[_player][i] *
((_epochNum() - 1) - i);
}
lords = lordsPerRealm * totalClaimable;
} else {
lords = 0;
}
}
function bridgeWithdraw(address _player, uint256[] memory _tokenIds)
public
onlyBridge
{
for (uint256 i = 0; i < _tokenIds.length; i++) {
ownership[_tokenIds[i]] = address(0);
realmsToken.safeTransferFrom(address(this), _player, _tokenIds[i]);
}
emit UnStakeRealms(_tokenIds, _player);
}
function withdrawAllLords(address _destination) public onlyOwner {
uint256 balance = lordsToken.balanceOf(address(this));
lordsToken.approve(address(this), balance);
lordsToken.transferFrom(address(this), _destination, balance);
}
modifier onlyBridge() {
require(msg.sender == bridge, "NOT_THE_BRIDGE");
_;
}
function checkOwner(uint256 _tokenId) public view returns (address) {
return ownership[_tokenId];
}
function getEpoch() public view returns (uint256) {
return _epochNum();
}
function getLordsAddress() public view returns (address) {
return address(lordsToken);
}
function getRealmsAddress() public view returns (address) {
return address(realmsToken);
}
function getEpochLength() public view returns (uint256) {
return epoch;
}
function getLordsIssurance() public view returns (uint256) {
return lordsPerRealm;
}
function getTimeUntilEpoch() public view returns (uint256) {
return (epoch * 3600 * (getEpoch() + 1)) - (block.timestamp - genesis);
}
function getFinalAge() public view returns (uint256) {
return finalAge;
}
function getNumberRealms(address _player) public view returns (uint256) {
uint256 totalRealms;
if (_epochNum() >= 1) {
for (uint256 i = epochClaimed[_player]; i <= _epochNum(); i++) {
totalRealms += realmsStaked[_player][i];
}
return totalRealms;
} else {
return realmsStaked[_player][0];
}
}
}
文件 9 的 13:LordsToken.sol
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface LordsToken is IERC20 {
function mint(address to, uint256 amount) external;
function getAgeDistribution(uint256 _age) external view returns (uint256);
}
文件 10 的 13: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);
}
}
文件 11 的 13:Pausable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Pausable is Context {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor() {
_paused = false;
}
function paused() public view virtual returns (bool) {
return _paused;
}
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
文件 12 的 13:RealmsToken.sol
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
interface RealmsToken is IERC721Enumerable {
}
文件 13 的 13:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
{
"compilationTarget": {
"contracts/pre/Journey.sol": "Journey"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"uint256","name":"_lordsPerRealm","type":"uint256"},{"internalType":"uint256","name":"_epoch","type":"uint256"},{"internalType":"address","name":"_realmsAddress","type":"address"},{"internalType":"address","name":"_lordsToken","type":"address"}],"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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"indexed":false,"internalType":"address","name":"player","type":"address"}],"name":"StakeRealms","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"indexed":false,"internalType":"address","name":"player","type":"address"}],"name":"UnStakeRealms","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"}],"name":"boardShip","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_player","type":"address"},{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"}],"name":"bridgeWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"checkOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimLords","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"}],"name":"exitShip","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEpochLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFinalAge","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLordsAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLordsIssurance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_player","type":"address"}],"name":"getNumberRealms","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRealmsAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTimeUntilEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_player","type":"address"}],"name":"lordsAvailable","outputs":[{"internalType":"uint256","name":"lords","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_new","type":"uint256"}],"name":"lordsIssuance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"realmsStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newBridge","type":"address"}],"name":"setBridge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_finalAge","type":"uint256"}],"name":"setFinalAge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newEpoch","type":"uint256"}],"name":"updateEpochLength","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newLords","type":"address"}],"name":"updateLordsAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newRealms","type":"address"}],"name":"updateRealmsAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_destination","type":"address"}],"name":"withdrawAllLords","outputs":[],"stateMutability":"nonpayable","type":"function"}]