编译器
0.8.20+commit.a1b79de6
文件 1 的 11:AnimaStakingRewardsEmitter.sol
pragma solidity ^0.8.17;
import "../ERC20/ITokenMinter.sol";
import "./IAnimaChamberData.sol";
import "./IAnimaStakerStorage.sol";
import "../Manager/ManagerModifier.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "./IAnimaStakingRewardsStorage.sol";
import "./IAnimaStakingRewardsEmitter.sol";
contract AnimaStakingRewardsEmitter is
ManagerModifier,
IAnimaStakingRewardsEmitter
{
ITokenMinter public TOKEN_MINTER;
IAnimaChamberData public CHAMBER_DATA;
IAnimaStakingRewardsStorage public REWARDS_STORAGE;
IAnimaStakerStorage public STAKER_STORAGE;
IERC721 public CHAMBER;
IERC721 public REALM;
constructor(
address _manager,
address _tokenMinter,
address _chamberData,
address _stakerStorage,
address _rewardsStorage,
address _chamber,
address _realm
) ManagerModifier(_manager) {
TOKEN_MINTER = ITokenMinter(_tokenMinter);
CHAMBER_DATA = IAnimaChamberData(_chamberData);
REWARDS_STORAGE = IAnimaStakingRewardsStorage(_rewardsStorage);
STAKER_STORAGE = IAnimaStakerStorage(_stakerStorage);
CHAMBER = IERC721(_chamber);
REALM = IERC721(_realm);
}
function emitStakerRewards(
uint _tokenId,
uint _rewardsAmount,
bool _compound
) external onlyTokenEmitter {
uint currentStake = CHAMBER_DATA.stakedAnima(_tokenId);
address owner = CHAMBER.ownerOf(_tokenId);
address target = owner;
if (_compound) {
target = address(STAKER_STORAGE);
currentStake += _rewardsAmount;
CHAMBER_DATA.getAndResetStakedAnima(_tokenId);
CHAMBER_DATA.setStakedAnima(_tokenId, currentStake);
REWARDS_STORAGE.registerChamberCompound(_tokenId, _rewardsAmount);
STAKER_STORAGE.changeDelta(int(_rewardsAmount));
}
emit StakerRewardsEmitted(
_tokenId,
_rewardsAmount,
owner,
_compound,
currentStake
);
TOKEN_MINTER.mint(target, _rewardsAmount, MINTER_STAKER_BUCKET);
}
function emitRealmerRewards(
uint _tokenId,
uint _realmId,
uint _rewardsAmount
) external onlyTokenEmitter {
address realmOwner = REALM.ownerOf(_realmId);
TOKEN_MINTER.mint(realmOwner, _rewardsAmount, MINTER_REALM_BUCKET);
emit RealmerRewardsEmitted(_tokenId, _realmId, _rewardsAmount, realmOwner);
}
}
文件 2 的 11:IAnimaChamberData.sol
pragma solidity ^0.8.17;
interface IAnimaChamberData {
function stakedAnima(uint256 _tokenId) external view returns (uint256);
function mintedAt(uint256 _tokenId) external view returns (uint256);
function stakedAnimaBatch(
uint256[] calldata _tokenId
) external view returns (uint256[] memory result);
function setStakedAnima(uint256 _tokenId, uint256 _amount) external;
function getAndResetStakedAnima(
uint _tokenId
) external returns (uint256 result);
}
文件 3 的 11:IAnimaStakerStorage.sol
pragma solidity ^0.8.17;
interface IAnimaStakerStorage {
function unstakeAndChangeDelta(address _for, uint256 _amount) external;
function getTotal() external view returns (uint);
function getEpochChanges(uint _epoch) external view returns (int);
function getEpochChangesBatch(
uint startEpoch,
uint endEpoch
) external view returns (int[] memory result);
function changeDelta(int _delta) external;
}
文件 4 的 11:IAnimaStakingRewardsEmitter.sol
pragma solidity ^0.8.17;
interface IAnimaStakingRewardsEmitter {
event StakerRewardsEmitted(
uint _tokenId,
uint _amount,
address _receiver,
bool _compounded,
uint _totalAnimaStaked
);
event RealmerRewardsEmitted(
uint _tokenId,
uint _realmId,
uint _amount,
address _receiver
);
function emitStakerRewards(
uint _tokenId,
uint _rewardsAmount,
bool _compound
) external;
function emitRealmerRewards(
uint _tokenId,
uint _realmId,
uint _rewardsAmount
) external;
}
文件 5 的 11:IAnimaStakingRewardsStorage.sol
pragma solidity ^0.8.17;
struct ChamberRewardsStorage {
uint32 realmId;
uint32 mintedAt;
uint32 stakedAt;
uint32 chamberStakedIndex;
uint32 lastRealmerCollectedAt;
uint32 lastStakerCollectedAt;
}
struct RealmRewardsStorage {
uint32 lastCapacityAdjustedAt;
uint lastCapacityUsed;
}
error ChamberAlreadyStaked(uint _realmId, uint _chamberId);
error ChamberNotStaked(uint _realmId, uint _chamberId);
interface IAnimaStakingRewardsStorage {
function realmChamberIds(uint _realmId) external view returns (uint[] memory);
function loadChamberInfo(
uint256 _chamberId
) external view returns (ChamberRewardsStorage memory);
function loadRealmInfo(
uint256 _realmId
) external view returns (RealmRewardsStorage memory);
function updateStakingRewards(
uint256 _chamberId,
bool _updateStakerTimestamp,
bool _updateRealmerTimestamp,
uint256 _lastUsedCapacity
) external;
function stakedAmountWithDeltas(
uint _realmId,
uint _startEpoch,
uint _endEpoch
) external view returns (uint current, int[] memory deltas);
function checkStaked(
uint256 _chamberId
) external view returns (bool, uint256);
function registerChamberStaked(uint256 _chamberId, uint256 _realmId) external;
function registerChamberCompound(
uint256 _chamberId,
uint _rewardsAmount
) external;
function unregisterChamberStaked(
uint256 _chamberId,
uint256 _realmId
) external;
}
文件 6 的 11:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 7 的 11: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,
bytes calldata data
) external;
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 setApprovalForAll(address operator, bool _approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
文件 8 的 11:IEpochConfigurable.sol
pragma solidity ^0.8.17;
interface IEpochConfigurable {
function currentEpoch() external view returns (uint);
function epochAtTimestamp(uint _timestamp) external view returns (uint);
}
文件 9 的 11:IManager.sol
pragma solidity ^0.8.4;
interface IManager {
function isAdmin(address _addr) external view returns (bool);
function isManager(address _addr, uint256 _type) external view returns (bool);
function addManager(address _addr, uint256 _type) external;
function removeManager(address _addr, uint256 _type) external;
function addAdmin(address _addr) external;
function removeAdmin(address _addr) external;
}
文件 10 的 11:ITokenMinter.sol
pragma solidity ^0.8.17;
import "../Utils/IEpochConfigurable.sol";
uint constant MINTER_ADVENTURER_BUCKET = 1;
uint constant MINTER_REALM_BUCKET = 2;
uint constant MINTER_STAKER_BUCKET = 3;
interface ITokenMinter is IEpochConfigurable {
function getEpochValue(uint _epoch) external view returns (uint);
function getEpochValueBatch(
uint startEpoch,
uint endEpoch
) external view returns (uint[] memory result);
function getBucketEpochValueBatch(
uint _startEpoch,
uint _endEpoch,
uint _bucket
) external view returns (uint[] memory result);
function getEpochValueBatchTotal(
uint startEpoch,
uint endEpoch
) external view returns (uint result);
function getBucketEpochValueBatchTotal(
uint _startEpoch,
uint _endEpoch,
uint _bucket
) external view returns (uint result);
function mint(address _owner, uint _amount, uint _bucket) external;
}
文件 11 的 11:ManagerModifier.sol
pragma solidity ^0.8.4;
import "../Manager/IManager.sol";
abstract contract ManagerModifier {
IManager public immutable MANAGER;
constructor(address _manager) {
MANAGER = IManager(_manager);
}
modifier onlyAdmin() {
require(MANAGER.isAdmin(msg.sender), "Manager: Not an Admin");
_;
}
modifier onlyManager() {
require(MANAGER.isManager(msg.sender, 0), "Manager: Not manager");
_;
}
modifier onlyMinter() {
require(MANAGER.isManager(msg.sender, 1), "Manager: Not minter");
_;
}
modifier onlyTokenMinter() {
require(MANAGER.isManager(msg.sender, 2), "Manager: Not token minter");
_;
}
modifier onlyBinder() {
require(MANAGER.isManager(msg.sender, 3), "Manager: Not binder");
_;
}
modifier onlyConfigManager() {
require(MANAGER.isManager(msg.sender, 4), "Manager: Not config manager");
_;
}
modifier onlyTokenSpender() {
require(MANAGER.isManager(msg.sender, 5), "Manager: Not token spender");
_;
}
modifier onlyTokenEmitter() {
require(MANAGER.isManager(msg.sender, 6), "Manager: Not token emitter");
_;
}
modifier onlyPauser() {
require(
MANAGER.isAdmin(msg.sender) || MANAGER.isManager(msg.sender, 6),
"Manager: Not pauser"
);
_;
}
}
{
"compilationTarget": {
"contracts/AnimaStaking/AnimaStakingRewardsEmitter.sol": "AnimaStakingRewardsEmitter"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_manager","type":"address"},{"internalType":"address","name":"_tokenMinter","type":"address"},{"internalType":"address","name":"_chamberData","type":"address"},{"internalType":"address","name":"_stakerStorage","type":"address"},{"internalType":"address","name":"_rewardsStorage","type":"address"},{"internalType":"address","name":"_chamber","type":"address"},{"internalType":"address","name":"_realm","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_realmId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"_receiver","type":"address"}],"name":"RealmerRewardsEmitted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"_receiver","type":"address"},{"indexed":false,"internalType":"bool","name":"_compounded","type":"bool"},{"indexed":false,"internalType":"uint256","name":"_totalAnimaStaked","type":"uint256"}],"name":"StakerRewardsEmitted","type":"event"},{"inputs":[],"name":"CHAMBER","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CHAMBER_DATA","outputs":[{"internalType":"contract IAnimaChamberData","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MANAGER","outputs":[{"internalType":"contract IManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REALM","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REWARDS_STORAGE","outputs":[{"internalType":"contract IAnimaStakingRewardsStorage","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STAKER_STORAGE","outputs":[{"internalType":"contract IAnimaStakerStorage","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_MINTER","outputs":[{"internalType":"contract ITokenMinter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_realmId","type":"uint256"},{"internalType":"uint256","name":"_rewardsAmount","type":"uint256"}],"name":"emitRealmerRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_rewardsAmount","type":"uint256"},{"internalType":"bool","name":"_compound","type":"bool"}],"name":"emitStakerRewards","outputs":[],"stateMutability":"nonpayable","type":"function"}]