编译器
0.8.20+commit.a1b79de6
文件 1 的 28:AbstractDurabilityEnabledArmoryAdapter.sol
pragma solidity ^0.8.17;
import "./IDurabilityEnabledAdapter.sol";
import "../lib/FloatingPointConstants.sol";
abstract contract AbstractDurabilityEnabledArmoryAdapter is
ManagerModifier,
IDurabilityEnabledAdapter
{
error DurabilityNotSupported();
IBrokenTokenHandler public BREAK_HANDLER;
bool public immutable SUPPORTS_DURABILITY;
error TokenNotAvailable(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId
);
error InsufficientDurability(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId,
uint durabilityLoss
);
struct DurabilityReductionRequest {
address _ownerAddress;
uint _ownerTokenId;
address _entityAddress;
uint _entityTokenId;
uint _durabilityLoss;
bool startNewTokenIfUndamaged;
bool ignoreAvailability;
}
struct ProcessingMemory {
DurabilityReductionRequest request;
bool anyBroken;
uint[] brokenAmounts;
uint[][] nestedBrokenAmounts;
}
constructor(
address _manager,
address _breakHandler,
bool _supportsDurability
) ManagerModifier(_manager) {
BREAK_HANDLER = IBrokenTokenHandler(_breakHandler);
SUPPORTS_DURABILITY = _supportsDurability;
}
event EntityDurabilityChanged(
address adventurerAddress,
uint adventurerTokenId,
address entityAddress,
uint entityTokenId,
uint durability
);
event EntityBroken(
address adventurerAddress,
uint adventurerTokenId,
address entityAddress,
uint entityTokenId
);
mapping(address => mapping(uint => mapping(address => mapping(uint => uint32))))
public currentDurabilityStorage;
function _burnOnBreak(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId
) internal virtual;
function _isNextAvailable(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId
) internal view virtual returns (bool);
function _damagedEntityCount(
mapping(uint => uint32) storage _durabilityMapping,
uint _tokenId
) internal view returns (uint) {
return _durabilityMapping[_tokenId] > 0 ? 1 : 0;
}
function _damagedEntityCount(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId
) internal view returns (uint) {
return
currentDurabilityStorage[_ownerAddress][_ownerTokenId][_entityAddress][_entityTokenId] > 0
? 1
: 0;
}
function _maximumTokenDurability(
address _entityAddress,
uint _entityTokenId
) internal virtual returns (uint32) {
return uint32(ONE_HUNDRED);
}
function _maximumTokenDurabilityView(
address _entityAddress,
uint _entityTokenId
) internal view virtual returns (uint32) {
return uint32(ONE_HUNDRED);
}
function _ownedEntityDurabilityMapping(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress
) internal view returns (mapping(uint => uint32) storage) {
return currentDurabilityStorage[_ownerAddress][_ownerTokenId][_entityAddress];
}
function _break(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId
) internal {
currentDurabilityStorage[_ownerAddress][_ownerTokenId][_entityAddress][_entityTokenId] = 0;
_burnOnBreak(_ownerAddress, _ownerTokenId, _entityAddress, _entityTokenId);
emit EntityBroken(_ownerAddress, _ownerTokenId, _entityAddress, _entityTokenId);
}
function currentDurabilityBatch(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityId
) public view returns (uint[] memory result) {
mapping(uint => uint32) storage durabilities = currentDurabilityStorage[_ownerAddress][
_ownerId
][_entityAddress];
result = new uint[](_entityId.length);
for (uint i = 0; i < _entityId.length; i++) {
result[i] = uint(durabilities[_entityId[i]]);
}
}
function currentDurability(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256 _entityId
) public view returns (uint) {
return uint(currentDurabilityStorage[_ownerAddress][_ownerId][_entityAddress][_entityId]);
}
function currentDurabilityBatch(
address[] calldata _ownerAddresses,
uint256[] calldata _ownerIds,
address _entityAddress,
uint256[][] calldata _entityId
) external view returns (uint[][] memory result) {
result = new uint[][](_ownerAddresses.length);
for (uint i = 0; i < _ownerAddresses.length; i++) {
result[i] = currentDurabilityBatch(
_ownerAddresses[i],
_ownerIds[i],
_entityAddress,
_entityId[i]
);
}
}
function currentDurabilityPercentage(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256 _entityId
) public view returns (uint result) {
result =
(ONE_HUNDRED *
uint(currentDurabilityStorage[_ownerAddress][_ownerId][_entityAddress][_entityId])) /
_maximumTokenDurabilityView(_entityAddress, _entityId);
if (result == 0 && _isNextAvailable(_ownerAddress, _ownerId, _entityAddress, _entityId)) {
result = ONE_HUNDRED;
}
}
function currentDurabilityBatchPercentage(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityIds
) public view returns (uint[] memory result) {
mapping(uint => uint32) storage durabilities = currentDurabilityStorage[_ownerAddress][
_ownerId
][_entityAddress];
result = new uint[](_entityIds.length);
for (uint i = 0; i < _entityIds.length; i++) {
result[i] =
(ONE_HUNDRED * uint(durabilities[_entityIds[i]])) /
_maximumTokenDurabilityView(_entityAddress, _entityIds[i]);
if (
result[i] == 0 && _isNextAvailable(_ownerAddress, _ownerId, _entityAddress, _entityIds[i])
) {
result[i] = ONE_HUNDRED;
}
}
}
function currentDurabilityBatchPercentage(
address[] calldata _ownerAddresses,
uint256[] calldata _ownerIds,
address _entityAddress,
uint256[][] calldata _entityId
) external view returns (uint[][] memory result) {
result = new uint[][](_ownerAddresses.length);
for (uint i = 0; i < _ownerAddresses.length; i++) {
result[i] = currentDurabilityBatchPercentage(
_ownerAddresses[i],
_ownerIds[i],
_entityAddress,
_entityId[i]
);
}
}
function reduceDurability(
address _reducer,
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId,
uint _durabilityLoss,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external onlyManager {
if (!SUPPORTS_DURABILITY) {
revert DurabilityNotSupported();
}
mapping(uint => uint32) storage _ownerEntityTokensDurability = currentDurabilityStorage[
_ownerAddress
][_ownerTokenId][_entityAddress];
if (
_reduceDurabilityInternal(
_ownerEntityTokensDurability,
DurabilityReductionRequest(
_ownerAddress,
_ownerTokenId,
_entityAddress,
_entityTokenId,
_durabilityLoss,
_startNewTokenIfNeeded,
_ignoreAvailability
)
) && address(BREAK_HANDLER) != address(0)
) {
BREAK_HANDLER.handleBrokenToken(
_reducer,
_ownerAddress,
_ownerTokenId,
_entityAddress,
_entityTokenId,
1
);
}
}
function reduceDurabilityBatch(
address _reducer,
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint[] calldata _entityTokenIds,
uint[] calldata _durabilityLosses,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external onlyManager {
if (!SUPPORTS_DURABILITY) {
revert DurabilityNotSupported();
}
ProcessingMemory memory mem;
mem.request._ownerAddress = _ownerAddress;
mem.request._ownerTokenId = _ownerTokenId;
mem.request._entityAddress = _entityAddress;
mem.request.startNewTokenIfUndamaged = _startNewTokenIfNeeded;
mem.request.ignoreAvailability = _ignoreAvailability;
mem.brokenAmounts = new uint[](_entityTokenIds.length);
mapping(uint => uint32) storage _ownerEntityTokensDurability = currentDurabilityStorage[
_ownerAddress
][_ownerTokenId][_entityAddress];
for (uint i = 0; i < _entityTokenIds.length; i++) {
mem.request._entityTokenId = _entityTokenIds[i];
mem.request._durabilityLoss = _durabilityLosses[i];
if (_reduceDurabilityInternal(_ownerEntityTokensDurability, mem.request)) {
mem.anyBroken = true;
mem.brokenAmounts[i] = 1;
}
}
if (mem.anyBroken && address(BREAK_HANDLER) != address(0)) {
BREAK_HANDLER.handleBrokenTokenBatch(
_reducer,
_ownerAddress,
_ownerTokenId,
_entityAddress,
_entityTokenIds,
mem.brokenAmounts
);
}
}
function reduceDurabilityBatch(
address _reducer,
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint[] calldata _entityTokenIds,
uint _durabilityLoss,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external onlyManager {
if (!SUPPORTS_DURABILITY) {
revert DurabilityNotSupported();
}
uint[] memory brokenAmounts = new uint[](_entityTokenIds.length);
mapping(uint => uint32) storage _ownerEntityTokensDurability = currentDurabilityStorage[
_ownerAddress
][_ownerTokenId][_entityAddress];
bool anyBroken = false;
for (uint i = 0; i < _entityTokenIds.length; i++) {
DurabilityReductionRequest memory request = DurabilityReductionRequest(
_ownerAddress,
_ownerTokenId,
_entityAddress,
_entityTokenIds[i],
_durabilityLoss,
_startNewTokenIfNeeded,
_ignoreAvailability
);
if (_reduceDurabilityInternal(_ownerEntityTokensDurability, request)) {
anyBroken = true;
brokenAmounts[i] = 1;
}
}
if (anyBroken && address(BREAK_HANDLER) != address(0)) {
BREAK_HANDLER.handleBrokenTokenBatch(
_reducer,
_ownerAddress,
_ownerTokenId,
_entityAddress,
_entityTokenIds,
brokenAmounts
);
}
}
function reduceDurabilityBatch(
address _reducer,
address[] calldata _ownerAddresses,
uint[] calldata _ownerTokenIds,
address _entityAddress,
uint[][] calldata _entityTokenIds,
uint _durabilityLoss,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external onlyManager {
if (!SUPPORTS_DURABILITY) {
revert DurabilityNotSupported();
}
uint[][] memory brokenAmounts = new uint[][](_entityTokenIds.length);
ProcessingMemory memory mem;
mem.request._durabilityLoss = _durabilityLoss;
mem.request.startNewTokenIfUndamaged = _startNewTokenIfNeeded;
mem.request.ignoreAvailability = _ignoreAvailability;
mem.request._entityAddress = _entityAddress;
mem.nestedBrokenAmounts = new uint[][](_entityTokenIds.length);
mem.anyBroken = false;
for (uint i = 0; i < _entityTokenIds.length; i++) {
mapping(uint => uint32) storage _ownerEntityTokensDurability = currentDurabilityStorage[
_ownerAddresses[i]
][_ownerTokenIds[i]][_entityAddress];
mem.request._ownerAddress = _ownerAddresses[i];
mem.request._ownerTokenId = _ownerTokenIds[i];
mem.nestedBrokenAmounts[i] = new uint[](_entityTokenIds[i].length);
for (uint j = 0; j < _entityTokenIds[i].length; j++) {
mem.request._entityTokenId = _entityTokenIds[i][j];
if (_reduceDurabilityInternal(_ownerEntityTokensDurability, mem.request)) {
mem.anyBroken = true;
mem.nestedBrokenAmounts[i][j] = 1;
}
}
}
if (mem.anyBroken && address(BREAK_HANDLER) != address(0)) {
BREAK_HANDLER.handleBrokenTokenBatch(
_reducer,
_ownerAddresses,
_ownerTokenIds,
_entityAddress,
_entityTokenIds,
mem.nestedBrokenAmounts
);
}
}
function reduceDurabilityBatch(
address _reducer,
address[] calldata _ownerAddresses,
uint[] calldata _ownerTokenIds,
address _entityAddress,
uint[][] calldata _entityTokenIds,
uint[][] calldata _durabilityLosses,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external onlyManager {
if (!SUPPORTS_DURABILITY) {
revert DurabilityNotSupported();
}
ProcessingMemory memory mem;
mem.nestedBrokenAmounts = new uint[][](_entityTokenIds.length);
mem.request._entityAddress = _entityAddress;
mem.request.startNewTokenIfUndamaged = _startNewTokenIfNeeded;
mem.request.ignoreAvailability = _ignoreAvailability;
for (uint i = 0; i < _entityTokenIds.length; i++) {
mapping(uint => uint32) storage _ownerEntityTokensDurability = currentDurabilityStorage[
_ownerAddresses[i]
][_ownerTokenIds[i]][_entityAddress];
mem.nestedBrokenAmounts[i] = new uint[](_entityTokenIds[i].length);
mem.request._ownerAddress = _ownerAddresses[i];
mem.request._ownerTokenId = _ownerTokenIds[i];
for (uint j = 0; j < _entityTokenIds[i].length; j++) {
mem.request._durabilityLoss = _durabilityLosses[i][j];
mem.request._entityTokenId = _entityTokenIds[i][j];
if (_reduceDurabilityInternal(_ownerEntityTokensDurability, mem.request)) {
mem.anyBroken = true;
mem.nestedBrokenAmounts[i][j] = 1;
}
}
}
if (mem.anyBroken && address(BREAK_HANDLER) != address(0)) {
BREAK_HANDLER.handleBrokenTokenBatch(
_reducer,
_ownerAddresses,
_ownerTokenIds,
_entityAddress,
_entityTokenIds,
mem.nestedBrokenAmounts
);
}
}
function _reduceDurabilityInternal(
mapping(uint => uint32) storage _ownerEntityTokensDurability,
DurabilityReductionRequest memory _request
) internal virtual returns (bool) {
uint32 durability = _ownerEntityTokensDurability[_request._entityTokenId];
if (durability == 0) {
if (_request.startNewTokenIfUndamaged) {
if (
_isNextAvailable(
_request._ownerAddress,
_request._ownerTokenId,
_request._entityAddress,
_request._entityTokenId
)
) {
durability = _maximumTokenDurability(_request._entityAddress, _request._entityTokenId);
} else if (_request.ignoreAvailability) {
return false;
} else {
revert InsufficientDurability(
_request._ownerAddress,
_request._ownerTokenId,
_request._entityAddress,
_request._entityTokenId,
_request._durabilityLoss
);
}
} else {
return false;
}
}
if (_request._durabilityLoss >= durability) {
_break(
_request._ownerAddress,
_request._ownerTokenId,
_request._entityAddress,
_request._entityTokenId
);
return true;
}
durability -= uint32(_request._durabilityLoss);
_ownerEntityTokensDurability[_request._entityTokenId] = durability;
emit EntityDurabilityChanged(
_request._ownerAddress,
_request._ownerTokenId,
_request._entityAddress,
_request._entityTokenId,
durability
);
return false;
}
function updateBreakHandler(address _handler) external onlyAdmin {
require(SUPPORTS_DURABILITY);
BREAK_HANDLER = IBrokenTokenHandler(_handler);
}
}
文件 2 的 28:Actions.sol
pragma solidity ^0.8.17;
uint64 constant DAILY_EPOCH_DURATION = 1 days;
uint64 constant DAILY_EPOCH_OFFSET = 0 hours;
uint64 constant HOURLY_EPOCH_DURATION = 1 hours;
uint64 constant NO_OFFSET = 0 hours;
uint256 constant ACTION_LOCK = 101;
uint256 constant ACTION_ADVENTURER_HOMAGE = 1001;
uint256 constant ACTION_ADVENTURER_BATTLE_V3 = 1002;
uint256 constant ACTION_ADVENTURER_COLLECT_EPOCH_REWARDS = 1003;
uint256 constant ACTION_ADVENTURER_VOID_CRAFTING = 1004;
uint256 constant ACTION_ADVENTURER_REALM_CRAFTING = 1005;
uint256 constant ACTION_ADVENTURER_ANIMA_REGENERATION = 1006;
uint256 constant ACTION_ADVENTURER_BATTLE_V3_OPPONENT = 1007;
uint256 constant ACTION_ADVENTURER_TRAINING = 1008;
uint256 constant ACTION_ADVENTURER_TRANSCENDENCE = 1009;
uint256 constant ACTION_ARMORY_STAKE_RARITY_ITEM = 2001;
uint256 constant ACTION_ARMORY_UNSTAKE_RARITY_ITEM = 2002;
uint256 constant ACTION_ARMORY_STAKE_RARITY_ITEM_SHARD = 2011;
uint256 constant ACTION_ARMORY_UNSTAKE_RARITY_ITEM_SHARD = 2012;
uint256 constant ACTION_ARMORY_STAKE_MATERIAL_SHARD = 2021;
uint256 constant ACTION_ARMORY_UNSTAKE_MATERIAL_SHARD = 2022;
uint256 constant ACTION_ARMORY_STAKE_LAB = 2031;
uint256 constant ACTION_ARMORY_UNSTAKE_LAB = 2032;
uint256 constant ACTION_ARMORY_STAKE_COLLECTIBLE = 2041;
uint256 constant ACTION_ARMORY_UNSTAKE_COLLECTIBLE = 2042;
uint256 constant ACTION_ARMORY_STAKE_MATERIAL = 2051;
uint256 constant ACTION_ARMORY_UNSTAKE_MATERIAL = 2052;
uint256 constant ACTION_ARMORY_STAKE_CITY = 2061;
uint256 constant ACTION_ARMORY_UNSTAKE_CITY = 2062;
uint256 constant ACTION_ARMORY_STAKE_MONUMENT = 2061;
uint256 constant ACTION_ARMORY_UNSTAKE_MONUMENT = 2062;
uint256 constant ACTION_REALM_COLLECT_COLLECTIBLES = 4001;
uint256 constant ACTION_REALM_BUILD_LAB = 4011;
文件 3 的 28:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 4 的 28:ArmoryConstants.sol
pragma solidity ^0.8.17;
uint constant ARMORY_ENTITY_DISABLED = 0;
uint constant ARMORY_ENTITY_ERC20 = 1;
uint constant ARMORY_ENTITY_ERC721 = 2;
uint constant ARMORY_ENTITY_ERC1155 = 3;
uint constant ARMORY_ENTITY_DATA = 4;
文件 5 的 28:BurnMintERC1155ArmoryAdapter.sol
pragma solidity ^0.8.17;
import "./SingleERC1155ArmoryAdapter.sol";
abstract contract BurnMintERC1155ArmoryAdapter is SingleERC1155ArmoryAdapter {
constructor(
address _manager,
address _actionPermit,
address _collectionAddress,
uint _requiredStakeActionPermission,
uint _requiredUnstakeActionPermission,
bool _supportsDurability,
address _breakHandler
)
SingleERC1155ArmoryAdapter(
_manager,
_actionPermit,
_collectionAddress,
_requiredStakeActionPermission,
_requiredUnstakeActionPermission,
_supportsDurability,
_breakHandler
)
{}
function _burnFrom(address _from, uint256 _id, uint256 _amount) internal virtual;
function _burnBatchFrom(
address _from,
uint256[] calldata _id,
uint256[] calldata _amount
) internal virtual;
function _burnBatchFrom(
address _from,
uint256[][] calldata _id,
uint256[][] calldata _amount
) internal virtual;
function _mintFor(address _for, uint256 _id, uint256 _amount) internal virtual;
function _mintBatchFor(
address _for,
uint256[] calldata _id,
uint256[] calldata _amount
) internal virtual;
function _mintBatchFor(
address _for,
uint256[][] calldata _id,
uint256[][] calldata _amount
) internal virtual;
function _doStake(address _staker, uint256 _ids, uint256 _amount) internal override {
if (_amount == 0) {
return;
}
_burnFrom(_staker, _ids, _amount);
}
function _doStakeBatch(
address _staker,
uint256[] calldata _ids,
uint256[] calldata _amounts
) internal override {
_burnBatchFrom(_staker, _ids, _amounts);
}
function _doStakeBatch(
address _staker,
uint256[][] calldata _ids,
uint256[][] calldata _amounts
) internal override {
_burnBatchFrom(_staker, _ids, _amounts);
}
function _doUnstake(address _staker, uint256 _id, uint256 _amount) internal override {
if (_amount == 0) {
return;
}
_mintFor(_staker, _id, _amount);
}
function _doUnstakeBatch(
address _staker,
uint256[] calldata _ids,
uint256[] calldata _amounts
) internal override {
_mintBatchFor(_staker, _ids, _amounts);
}
function _doUnstakeBatch(
address _staker,
uint256[][] calldata _ids,
uint256[][] calldata _amounts
) internal override {
_mintBatchFor(_staker, _ids, _amounts);
}
function _doBurn(uint256 _id, uint256 _amount) internal override {}
function _doBurnBatch(uint256[] calldata _ids, uint256[] calldata _amounts) internal override {}
function _doBurnBatch(
uint256[][] calldata _ids,
uint256[][] calldata _amounts
) internal override {}
function _doMint(uint256 _id, uint256 _amount) internal override {}
function _doMintBatch(uint256[] calldata _ids, uint256[] calldata _amounts) internal override {}
function _doMintBatch(
uint256[][] calldata _ids,
uint256[][] calldata _amounts
) internal override {}
}
文件 6 的 28: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;
}
}
文件 7 的 28:ERC1155.sol
pragma solidity ^0.8.0;
import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
mapping(uint256 => mapping(address => uint256)) private _balances;
mapping(address => mapping(address => bool)) private _operatorApprovals;
string private _uri;
constructor(string memory uri_) {
_setURI(uri_);
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
function uri(uint256) public view virtual override returns (string memory) {
return _uri;
}
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: address zero is not a valid owner");
return _balances[id][account];
}
function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
function _mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
function _burn(
address from,
uint256 id,
uint256 amount
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
function _burnBatch(
address from,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _afterTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
文件 8 的 28:ERC1155Holder.sol
pragma solidity ^0.8.0;
import "./ERC1155Receiver.sol";
contract ERC1155Holder is ERC1155Receiver {
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
文件 9 的 28:ERC1155Receiver.sol
pragma solidity ^0.8.0;
import "../IERC1155Receiver.sol";
import "../../../utils/introspection/ERC165.sol";
abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
}
文件 10 的 28: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;
}
}
文件 11 的 28:FloatingPointConstants.sol
pragma solidity ^0.8.17;
uint256 constant DECIMAL_POINT = 10 ** 3;
int256 constant SIGNED_DECIMAL_POINT = int256(DECIMAL_POINT);
uint256 constant ONE_HUNDRED = 100 * DECIMAL_POINT;
uint256 constant ONE_HUNDRED_SQUARE = ONE_HUNDRED * ONE_HUNDRED;
int256 constant SIGNED_ONE_HUNDRED = 100 * SIGNED_DECIMAL_POINT;
int256 constant SIGNED_ONE_HUNDRED_SQUARE = SIGNED_ONE_HUNDRED * SIGNED_ONE_HUNDRED;
int256 constant SIGNED_ZERO = 0;
文件 12 的 28:IActionPermit.sol
pragma solidity ^0.8.17;
error Unauthorized(address _tokenAddr, uint256 _tokenId);
error EntityLocked(address _tokenAddr, uint256 _tokenId, uint _lockedUntil);
error MinEpochsTooLow(uint256 _minEpochs);
error InsufficientEpochSpan(
uint256 _minEpochs,
uint256 _epochs,
address _tokenAddr,
uint256 _tokenId
);
error DuplicateActionAttempt(address _tokenAddr, uint256 _tokenId);
interface IActionPermit {
function checkAndMarkActionComplete(
address _sender,
address _tokenAddr,
uint256 _tokenId,
bytes32[] calldata _proof,
uint256 _action,
uint256 _minEpochs,
uint128 _epochConfig
) external;
function checkAndMarkActionCompleteMany(
address _sender,
address[] calldata _tokenAddrs,
uint256[] calldata _tokenIds,
bytes32[][] calldata _proofs,
uint256 _action,
uint256 _minEpochs,
uint128 _epochConfig
) external;
function checkAndMarkActionCompleteMany(
address _sender,
address[] calldata _tokenAddrs,
uint256[] calldata _tokenIds,
bytes32[][] calldata _proofs,
uint256 _action,
uint256[] calldata _minEpochs,
uint128 _epochConfig
) external;
function forceMarkActionComplete(address _tokenAddr, uint256 _tokenId, uint256 _action) external;
function checkPermissions(
address _sender,
address _tokenAddr,
uint256 _tokenId,
bytes32[] calldata _proof,
uint256 _action
) external view;
function checkOwner(
address _tokenAddr,
uint256 _tokenId,
bytes32[] calldata _proof
) external view returns (address);
function checkPermissionsMany(
address _sender,
address[] calldata _tokenAddr,
uint256[] calldata _tokenId,
bytes32[][] calldata _proofs,
uint256 _action
) external view;
function checkPermissionsMany(
address _sender,
address _tokenAddr,
uint256[] calldata _tokenId,
bytes32[][] calldata _proofs,
uint256 _action
) external view;
function checkOwnerBatch(
address[] calldata _tokenAddrs,
uint256[] calldata _tokenIds,
bytes32[][] calldata _proofs
) external view returns (address[] memory);
function checkIfEnoughEpochsElapsed(
address _tokenAddr,
uint256 _tokenId,
uint256 _action,
uint256 _minEpochs,
uint128 _epochConfig
) external view;
function checkIfEnoughEpochsElapsedBatch(
address[] calldata _tokenAddrs,
uint256[] calldata _tokenIds,
uint256 _action,
uint256 _minEpochs,
uint128 _epochConfig
) external view;
function checkIfEnoughEpochsElapsedBatch(
address[] calldata _tokenAddrs,
uint256[] calldata _tokenIds,
uint256 _action,
uint256[] calldata _minEpochs,
uint128 _epochConfig
) external view;
function getElapsedEpochs(
address[] calldata _tokenAddrs,
uint256[] calldata _tokenIds,
uint256 _action,
uint128 _epochConfig
) external view returns (uint[] memory result);
}
文件 13 的 28:IArmoryEntityStorageAdapter.sol
pragma solidity ^0.8.17;
interface IArmoryEntityStorageAdapter {
error Unauthorized(address _staker, address _ownerAddress, uint _ownerId);
error UnsupportedOperation(address _entityAddress, string operation);
error UnsupportedEntity(address _entityAddress);
error InsufficientAmountStaked(
address _ownerAddress,
uint _ownerId,
address _entityAddress,
uint _tokenIds,
uint _tokenAmounts
);
function entityType() external pure returns (uint);
function stake(
address _staker,
address _ownerAddress,
uint256 _ownerId,
bytes32[] calldata _proof,
address _entityAddress,
uint256 _entityTokenId,
uint256 _entityAmount
) external;
function stakeBatch(
address _staker,
address _ownerAddresses,
uint256 _ownerIds,
bytes32[] calldata _proof,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) external;
function stakeBatch(
address _staker,
address[] calldata _ownerAddresses,
uint256[] calldata _ownerIds,
bytes32[][] calldata _proofs,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external;
function unstake(
address _staker,
address _ownerAddress,
uint256 _ownerId,
bytes32[] calldata _proof,
address _entityAddress,
uint256 _entityTokenId,
uint256 _entityAmount
) external;
function unstakeBatch(
address _staker,
address _ownerAddresses,
uint256 _ownerIds,
bytes32[] calldata _proof,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) external;
function unstakeBatch(
address _staker,
address[] calldata _ownerAddresses,
uint256[] calldata _ownerIds,
bytes32[][] calldata _proofs,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external;
function burn(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256 _entityTokenId,
uint256 _entityAmount
) external;
function burnBatch(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) external;
function burnBatch(
address[] calldata _ownerAddress,
uint256[] calldata _ownerId,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external;
function mint(
address _ownerAddresses,
uint256 _ownerIds,
address _entityAddress,
uint256 _entityTokenId,
uint256 _entityAmount
) external;
function mintBatch(
address _ownerAddresses,
uint256 _ownerIds,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) external;
function mintBatch(
address[] calldata _ownerAddresses,
uint256[] calldata _ownerIds,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external;
function batchCheckAmounts(
address[] calldata _ownerAddresses,
uint256[] calldata _ownerIds,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external view;
function batchCheckAmounts(
address _ownerAddresses,
uint256 _ownerIds,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) external view;
function batchCheckAmounts(
address _ownerAddresses,
uint256 _ownerIds,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256 _entityAmounts
) external view;
function balanceOf(
address _ownerAddress,
uint _ownerIds,
address _entityAddress,
uint _entityTokenId
) external view returns (uint);
function balanceOfBatch(
address _ownerAddress,
uint _ownerIds,
address _entityAddress,
uint[] calldata _entityTokenIds
) external view returns (uint[] memory);
}
文件 14 的 28:IBrokenEquipmentHandler.sol
pragma solidity ^0.8.17;
interface IBrokenTokenHandler {
function handleBrokenToken(
address _breakerContract,
address _ownerAddress,
uint _ownerTokenId,
address _brokenEntityAddress,
uint _brokenEntityTokenId,
uint _brokenAmount
) external;
function handleBrokenTokenBatch(
address _breakerContract,
address _ownerAddress,
uint _ownerTokenId,
address _brokenEntityAddress,
uint[] calldata _brokenEntityTokenIds,
uint[] calldata _brokenAmounts
) external;
function handleBrokenTokenBatch(
address _breakerContract,
address[] calldata _ownerAddresses,
uint[] calldata _ownerTokenIds,
address _brokenEntityAddress,
uint[][] calldata _brokenEntityTokenIds,
uint[][] calldata _brokenAmounts
) external;
}
文件 15 的 28:IDurabilityEnabledAdapter.sol
pragma solidity ^0.8.17;
import "../Manager/ManagerModifier.sol";
import "../AdventurerEquipment/IBrokenEquipmentHandler.sol";
import "./IArmoryEntityStorageAdapter.sol";
interface IDurabilityEnabledAdapter {
function currentDurability(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256 _entityId
) external view returns (uint);
function currentDurabilityBatch(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityId
) external view returns (uint[] memory);
function currentDurabilityBatch(
address[] calldata _ownerAddress,
uint256[] calldata _ownerId,
address _entityAddress,
uint256[][] calldata _entityId
) external view returns (uint[][] memory);
function currentDurabilityPercentage(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256 _entityId
) external view returns (uint);
function currentDurabilityBatchPercentage(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityId
) external view returns (uint[] memory);
function currentDurabilityBatchPercentage(
address[] calldata _ownerAddress,
uint256[] calldata _ownerId,
address _entityAddress,
uint256[][] calldata _entityId
) external view returns (uint[][] memory);
function reduceDurability(
address _reducer,
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId,
uint _durabilityLoss,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external;
function reduceDurabilityBatch(
address _reducer,
address _ownerAddress,
uint _ownerTokenIds,
address _entityAddress,
uint[] calldata _entityTokenIds,
uint _durabilityLoss,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external;
function reduceDurabilityBatch(
address _reducer,
address _ownerAddress,
uint _ownerTokenIds,
address _entityAddress,
uint[] calldata _entityTokenIds,
uint[] calldata _durabilityLosses,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external;
function reduceDurabilityBatch(
address _reducer,
address[] calldata _ownerAddress,
uint[] calldata _ownerTokenIds,
address _entityAddress,
uint[][] calldata _entityTokenIds,
uint _durabilityLoss,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external;
function reduceDurabilityBatch(
address _reducer,
address[] calldata _ownerAddress,
uint[] calldata _ownerTokenIds,
address _entityAddress,
uint[][] calldata _entityTokenIds,
uint[][] calldata _durabilityLoss,
bool _startNewTokenIfNeeded,
bool _ignoreAvailability
) external;
}
文件 16 的 28:IERC1155.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
文件 17 的 28:IERC1155MetadataURI.sol
pragma solidity ^0.8.0;
import "../IERC1155.sol";
interface IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}
文件 18 的 28:IERC1155Receiver.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155Receiver is IERC165 {
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
文件 19 的 28:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 20 的 28:IItemMetadata.sol
pragma solidity ^0.8.17;
interface IItemMetadata {
function getMetadata(uint256 _tokenId) external view returns (string memory);
function isBound(uint256 _tokenId) external view returns (bool);
function name(uint256 _tokenId) external view returns (string memory);
}
文件 21 的 28: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;
}
文件 22 的 28:IMaximumDurabilitySource.sol
pragma solidity ^0.8.17;
interface IMaximumDurabilitySource {
function getMaximumDurability(address _address, uint _token) external view returns (uint32);
}
文件 23 的 28:IRarityItemMetadata.sol
pragma solidity ^0.8.17;
import "./IItemMetadata.sol";
interface IRarityItemMetadata is IItemMetadata {}
文件 24 的 28: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");
_;
}
}
文件 25 的 28:RarityItem.sol
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "../Manager/ManagerModifier.sol";
import "./IRarityItemMetadata.sol";
contract RarityItem is ERC1155, ReentrancyGuard, ManagerModifier {
IRarityItemMetadata public metadata;
constructor(
address _manager,
address _metadata
) ERC1155("") ManagerModifier(_manager) {
metadata = IRarityItemMetadata(_metadata);
}
function mintFor(
address _for,
uint256 _id,
uint256 _amount
) external nonReentrant onlyMinter {
_mint(_for, _id, _amount, "");
}
function mintBatchFor(
address _for,
uint256[] memory _ids,
uint256[] memory _amounts
) external nonReentrant onlyMinter {
_mintBatch(_for, _ids, _amounts, "");
}
function burn(uint256 _id, uint256 _amount) external nonReentrant {
_burn(msg.sender, _id, _amount);
}
function burnBatch(
uint256[] memory ids,
uint256[] memory amounts
) external nonReentrant {
_burnBatch(msg.sender, ids, amounts);
}
function uri(uint256 _tokenId) public view override returns (string memory) {
return metadata.getMetadata(_tokenId);
}
function updateMetadata(address _addr) external onlyAdmin {
metadata = IRarityItemMetadata(_addr);
}
}
文件 26 的 28:RarityItemArmoryAdapter.sol
pragma solidity ^0.8.17;
import "../Item/RarityItem.sol";
import "../Action/Actions.sol";
import "./IMaximumDurabilitySource.sol";
import "../Armory/BurnMintERC1155ArmoryAdapter.sol";
contract RarityItemArmoryAdapter is BurnMintERC1155ArmoryAdapter {
RarityItem public immutable TOKEN;
IMaximumDurabilitySource public maximumDurabilitySource;
constructor(
address _manager,
address _actionPermit,
address _rarityItem,
address _breakHandler,
address _maxDurabilitySource
)
BurnMintERC1155ArmoryAdapter(
_manager,
_actionPermit,
_rarityItem,
ACTION_ARMORY_STAKE_RARITY_ITEM,
ACTION_ARMORY_UNSTAKE_RARITY_ITEM,
true,
_breakHandler
)
{
TOKEN = RarityItem(_rarityItem);
maximumDurabilitySource = IMaximumDurabilitySource(_maxDurabilitySource);
}
mapping(uint => uint32) maxRarityItemDurability;
function _burnFrom(address _from, uint256 _id, uint256 _amount) internal override {
TOKEN.safeTransferFrom(_from, address(this), _id, _amount, "");
TOKEN.burn(_id, _amount);
}
function _burnBatchFrom(
address _staker,
uint256[] calldata _ids,
uint256[] calldata _amounts
) internal override {
TOKEN.safeBatchTransferFrom(_staker, address(this), _ids, _amounts, "");
TOKEN.burnBatch(_ids, _amounts);
}
function _burnBatchFrom(
address _staker,
uint256[][] calldata _ids,
uint256[][] calldata _amounts
) internal override {
for (uint i = 0; i < _ids.length; i++) {
TOKEN.safeBatchTransferFrom(_staker, address(this), _ids[i], _amounts[i], "");
TOKEN.burnBatch(_ids[i], _amounts[i]);
}
}
function _mintFor(address _for, uint256 _id, uint256 _amount) internal override {
TOKEN.mintFor(_for, _id, _amount);
}
function _mintBatchFor(
address _staker,
uint256[] calldata _ids,
uint256[] calldata _amounts
) internal override {
TOKEN.mintBatchFor(_staker, _ids, _amounts);
}
function _mintBatchFor(
address _staker,
uint256[][] calldata _ids,
uint256[][] calldata _amounts
) internal override {
for (uint i = 0; i < _ids.length; i++) {
TOKEN.mintBatchFor(_staker, _ids[i], _amounts[i]);
}
}
function _maximumTokenDurability(
address _entityAddress,
uint _entityTokenId
) internal override returns (uint32 result) {
require(COLLECTION_ADDRESS == _entityAddress);
result = maxRarityItemDurability[_entityTokenId];
if (result == 0) {
result = maximumDurabilitySource.getMaximumDurability(_entityAddress, _entityTokenId);
maxRarityItemDurability[_entityTokenId] = result;
}
}
function _maximumTokenDurabilityView(
address _entityAddress,
uint _entityTokenId
) internal view override returns (uint32 result) {
require(COLLECTION_ADDRESS == _entityAddress);
return maximumDurabilitySource.getMaximumDurability(_entityAddress, _entityTokenId);
}
function _verifyBalance(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
mapping(uint256 => uint256) storage _ownedEntities,
uint _tokenId,
uint _requiredAmount
) internal view override {
if (_tokenId == 0) {
return;
}
super._verifyBalance(
_ownerAddress,
_ownerId,
_entityAddress,
_ownedEntities,
_tokenId,
_requiredAmount
);
}
function _reduceDurabilityInternal(
mapping(uint => uint32) storage _ownerEntityTokensDurability,
DurabilityReductionRequest memory _request
) internal override returns (bool) {
if (_request._entityTokenId == 0) {
return false;
}
return super._reduceDurabilityInternal(_ownerEntityTokensDurability, _request);
}
function clearDurabilityCache(uint256[] calldata _tokenIds) external onlyAdmin {
for (uint i = 0; i < _tokenIds.length; i++) {
maxRarityItemDurability[i] = 0;
}
}
function updateDurabilitySource(address _durabilitySource) external onlyAdmin {
maximumDurabilitySource = IMaximumDurabilitySource(_durabilitySource);
}
}
文件 27 的 28: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() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
}
function _nonReentrantAfter() private {
_status = _NOT_ENTERED;
}
}
文件 28 的 28:SingleERC1155ArmoryAdapter.sol
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "../Armory/IArmoryEntityStorageAdapter.sol";
import "../Armory/ArmoryConstants.sol";
import "../Action/IActionPermit.sol";
import "../Manager/ManagerModifier.sol";
import "./AbstractDurabilityEnabledArmoryAdapter.sol";
abstract contract SingleERC1155ArmoryAdapter is
ERC1155Holder,
ReentrancyGuard,
ManagerModifier,
IArmoryEntityStorageAdapter,
AbstractDurabilityEnabledArmoryAdapter
{
mapping(address => mapping(uint256 => mapping(uint256 => uint256))) public stakerBalances;
IActionPermit public ACTION_PERMIT;
address immutable COLLECTION_ADDRESS;
uint immutable REQUIRED_STAKE_ACTION_PERMISSION;
uint immutable REQUIRED_UNSTAKE_ACTION_PERMISSION;
constructor(
address _manager,
address _actionPermit,
address _collectionAddress,
uint _requiredStakeActionPermission,
uint _requiredUnstakeActionPermission,
bool _supportsDurability,
address _breakHandler
) AbstractDurabilityEnabledArmoryAdapter(_manager, _breakHandler, _supportsDurability) {
ACTION_PERMIT = IActionPermit(_actionPermit);
COLLECTION_ADDRESS = _collectionAddress;
REQUIRED_STAKE_ACTION_PERMISSION = _requiredStakeActionPermission;
REQUIRED_UNSTAKE_ACTION_PERMISSION = _requiredUnstakeActionPermission;
}
function _doStake(address _staker, uint256 _ids, uint256 _amounts) internal virtual;
function _doStakeBatch(
address _staker,
uint256[] calldata _ids,
uint256[] calldata _amounts
) internal virtual;
function _doStakeBatch(
address _staker,
uint256[][] calldata _ids,
uint256[][] calldata _amounts
) internal virtual;
function _doUnstake(address _staker, uint256 _ids, uint256 _amounts) internal virtual;
function _doUnstakeBatch(
address _staker,
uint256[] calldata _ids,
uint256[] calldata _amounts
) internal virtual;
function _doUnstakeBatch(
address _staker,
uint256[][] calldata _ids,
uint256[][] calldata _amounts
) internal virtual;
function _doBurn(uint256 _id, uint256 _amount) internal virtual;
function _doBurnBatch(uint256[] calldata _ids, uint256[] calldata _amounts) internal virtual;
function _doBurnBatch(uint256[][] calldata _ids, uint256[][] calldata _amounts) internal virtual;
function _doMint(uint256 _id, uint256 _amount) internal virtual;
function _doMintBatch(uint256[] calldata _ids, uint256[] calldata _amounts) internal virtual;
function _doMintBatch(uint256[][] calldata _ids, uint256[][] calldata _amounts) internal virtual;
function entityType() external pure returns (uint) {
return ARMORY_ENTITY_ERC1155;
}
function stake(
address _staker,
address _ownerAddress,
uint256 _ownerId,
bytes32[] calldata _proof,
address _entityAddress,
uint256 _entityTokenId,
uint256 _entityAmount
) public onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
ACTION_PERMIT.checkPermissions(
_staker,
_ownerAddress,
_ownerId,
_proof,
REQUIRED_STAKE_ACTION_PERMISSION
);
_doStake(_staker, _entityTokenId, _entityAmount);
stakerBalances[_ownerAddress][_ownerId][_entityTokenId] += _entityAmount;
}
function stakeBatch(
address _staker,
address _ownerAddress,
uint256 _ownerId,
bytes32[] calldata _proof,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) public onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
ACTION_PERMIT.checkPermissions(
_staker,
_ownerAddress,
_ownerId,
_proof,
REQUIRED_STAKE_ACTION_PERMISSION
);
_doStakeBatch(_staker, _entityTokenIds, _entityAmounts);
mapping(uint256 => uint256) storage memoryBalances = stakerBalances[_ownerAddress][_ownerId];
for (uint i = 0; i < _entityTokenIds.length; i++) {
memoryBalances[_entityTokenIds[i]] += _entityAmounts[i];
}
}
function stakeBatch(
address _staker,
address[] calldata _ownerAddress,
uint256[] calldata _ownerId,
bytes32[][] calldata _proofs,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
ACTION_PERMIT.checkPermissionsMany(
_staker,
_ownerAddress,
_ownerId,
_proofs,
REQUIRED_STAKE_ACTION_PERMISSION
);
_doStakeBatch(_staker, _entityTokenIds, _entityAmounts);
for (uint i = 0; i < _entityTokenIds.length; i++) {
mapping(uint256 => uint256) storage balance = stakerBalances[_ownerAddress[i]][_ownerId[i]];
for (uint j = 0; j < _entityTokenIds[i].length; j++) {
balance[_entityTokenIds[i][j]] += _entityAmounts[i][j];
}
}
}
function unstake(
address _staker,
address _ownerAddress,
uint256 _ownerId,
bytes32[] calldata _proofs,
address _entityAddress,
uint256 _entityTokenId,
uint256 _entityAmount
) public onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
ACTION_PERMIT.checkPermissions(
_staker,
_ownerAddress,
_ownerId,
_proofs,
REQUIRED_UNSTAKE_ACTION_PERMISSION
);
_checkAndDecreaseAmountInternal(_ownerAddress, _ownerId, _entityTokenId, _entityAmount);
_doUnstake(_staker, _entityTokenId, _entityAmount);
}
function unstakeBatch(
address _staker,
address _ownerAddress,
uint256 _ownerId,
bytes32[] calldata _proof,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) external onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
ACTION_PERMIT.checkPermissions(
_staker,
_ownerAddress,
_ownerId,
_proof,
REQUIRED_UNSTAKE_ACTION_PERMISSION
);
_checkAndDecreaseAmountsInternal(_ownerAddress, _ownerId, _entityTokenIds, _entityAmounts);
_doUnstakeBatch(_staker, _entityTokenIds, _entityAmounts);
}
function unstakeBatch(
address _staker,
address[] calldata _ownerAddress,
uint256[] calldata _ownerId,
bytes32[][] calldata _proofs,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
ACTION_PERMIT.checkPermissionsMany(
_staker,
_ownerAddress,
_ownerId,
_proofs,
REQUIRED_UNSTAKE_ACTION_PERMISSION
);
_checkAndDecreaseAmountsInternal(_ownerAddress, _ownerId, _entityTokenIds, _entityAmounts);
_doUnstakeBatch(_staker, _entityTokenIds, _entityAmounts);
}
function burnBatch(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) external onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
mapping(uint256 => uint256) storage ownedEntities = stakerBalances[_ownerAddress][_ownerId];
mapping(uint256 => uint32) storage ownedEntityDurabilities = _ownedEntityDurabilityMapping(
_ownerAddress,
_ownerId,
_entityAddress
);
_checkAndDecreaseAmountsInternal(_ownerAddress, _ownerId, _entityTokenIds, _entityAmounts);
_doBurnBatch(_entityTokenIds, _entityAmounts);
}
function burnBatch(
address[] calldata _ownerAddress,
uint256[] calldata _ownerId,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
_checkAndDecreaseAmountsInternal(_ownerAddress, _ownerId, _entityTokenIds, _entityAmounts);
_doBurnBatch(_entityTokenIds, _entityAmounts);
}
function burn(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256 _entityTokenId,
uint256 _entityAmount
) public onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
_checkAndDecreaseAmountInternal(_ownerAddress, _ownerId, _entityTokenId, _entityAmount);
_doBurn(_entityTokenId, _entityAmount);
}
function mintBatch(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) external onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
_doMintBatch(_entityTokenIds, _entityAmounts);
mapping(uint256 => uint256) storage ownedEntities = stakerBalances[_ownerAddress][_ownerId];
for (uint i = 0; i < _entityTokenIds.length; i++) {
ownedEntities[_entityTokenIds[i]] += _entityAmounts[i];
}
}
function mintBatch(
address[] calldata _ownerAddress,
uint256[] calldata _ownerId,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
_doMintBatch(_entityTokenIds, _entityAmounts);
for (uint i = 0; i < _entityTokenIds.length; i++) {
mapping(uint256 => uint256) storage memoryBalances = stakerBalances[_ownerAddress[i]][
_ownerId[i]
];
for (uint j = 0; j < _entityTokenIds[i].length; j++) {
memoryBalances[_entityTokenIds[i][j]] += _entityAmounts[i][j];
}
}
}
function mint(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256 _entityTokenId,
uint256 _entityAmount
) external onlyManager nonReentrant {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
_doMint(_entityTokenId, _entityAmount);
if (_entityAmount == 0) {
return;
}
stakerBalances[_ownerAddress][_ownerId][_entityTokenId] += _entityAmount;
}
function batchCheckAmounts(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) public view {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
mapping(uint256 => uint256) storage ownedEntities = stakerBalances[_ownerAddress][_ownerId];
for (uint i = 0; i < _entityTokenIds.length; i++) {
_verifyBalance(
_ownerAddress,
_ownerId,
_entityAddress,
ownedEntities,
_entityTokenIds[i],
_entityAmounts[i]
);
}
}
function batchCheckAmounts(
address[] calldata _ownerAddresses,
uint256[] calldata _ownerIds,
address _entityAddress,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) external view {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
for (uint i = 0; i < _entityTokenIds.length; i++) {
batchCheckAmounts(
_ownerAddresses[i],
_ownerIds[i],
_entityAddress,
_entityTokenIds[i],
_entityAmounts[i]
);
}
}
function batchCheckAmounts(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
uint256[] calldata _entityTokenIds,
uint256 _entityAmounts
) external view {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
mapping(uint256 => uint256) storage ownedEntities = stakerBalances[_ownerAddress][_ownerId];
for (uint i = 0; i < _entityTokenIds.length; i++) {
_verifyBalance(
_ownerAddress,
_ownerId,
_entityAddress,
ownedEntities,
_entityTokenIds[i],
_entityAmounts
);
}
}
function balanceOf(
address _ownerAddress,
uint _ownerId,
address _entityAddress,
uint _entityTokenId
) external view returns (uint) {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
return stakerBalances[_ownerAddress][_ownerId][_entityTokenId];
}
function balanceOfBatch(
address _ownerAddress,
uint _ownerId,
address _entityAddress,
uint[] calldata _entityTokenIds
) external view returns (uint[] memory result) {
if (_entityAddress != COLLECTION_ADDRESS) {
revert UnsupportedEntity(_entityAddress);
}
mapping(uint256 => uint256) storage ownedEntities = stakerBalances[_ownerAddress][_ownerId];
result = new uint[](_entityTokenIds.length);
for (uint i = 0; i < result.length; i++) {
result[i] = ownedEntities[_entityTokenIds[i]];
}
}
function _verifyBalance(
address _ownerAddress,
uint256 _ownerId,
address _entityAddress,
mapping(uint256 => uint256) storage _ownedEntities,
uint _tokenId,
uint _requiredAmount
) internal view virtual {
if (_ownedEntities[_tokenId] < _requiredAmount) {
revert InsufficientAmountStaked(
_ownerAddress,
_ownerId,
_entityAddress,
_tokenId,
_requiredAmount
);
}
}
function _checkAndDecreaseAmountInternal(
address _ownerAddress,
uint256 _ownerId,
uint256 _entityTokenId,
uint256 _entityAmount
) internal {
mapping(uint256 => uint256) storage ownedEntities = stakerBalances[_ownerAddress][_ownerId];
uint damagedEntityCount;
if (SUPPORTS_DURABILITY) {
damagedEntityCount = _damagedEntityCount(
_ownerAddress,
_ownerId,
COLLECTION_ADDRESS,
_entityTokenId
);
}
if (
ownedEntities[_entityTokenId] >= damagedEntityCount &&
ownedEntities[_entityTokenId] - damagedEntityCount >= _entityAmount
) {
ownedEntities[_entityTokenId] -= _entityAmount;
} else {
revert InsufficientAmountStaked(
_ownerAddress,
_ownerId,
COLLECTION_ADDRESS,
_entityTokenId,
_entityAmount
);
}
}
function _checkAndDecreaseAmountsInternal(
address _ownerAddress,
uint256 _ownerId,
uint256[] calldata _entityTokenIds,
uint256[] calldata _entityAmounts
) internal {
mapping(uint256 => uint256) storage ownedEntities = stakerBalances[_ownerAddress][_ownerId];
mapping(uint256 => uint32) storage ownedEntityDurabilities = _ownedEntityDurabilityMapping(
_ownerAddress,
_ownerId,
COLLECTION_ADDRESS
);
uint damagedEntityCount;
for (uint i = 0; i < _entityTokenIds.length; i++) {
if (SUPPORTS_DURABILITY) {
damagedEntityCount = _damagedEntityCount(ownedEntityDurabilities, _entityTokenIds[i]);
}
if (
ownedEntities[_entityTokenIds[i]] >= damagedEntityCount &&
ownedEntities[_entityTokenIds[i]] - damagedEntityCount >= _entityAmounts[i]
) {
ownedEntities[_entityTokenIds[i]] -= _entityAmounts[i];
} else {
revert InsufficientAmountStaked(
_ownerAddress,
_ownerId,
COLLECTION_ADDRESS,
_entityTokenIds[i],
_entityAmounts[i]
);
}
}
}
function _checkAndDecreaseAmountsInternal(
address[] calldata _ownerAddresses,
uint256[] calldata _ownerIds,
uint256[][] calldata _entityTokenIds,
uint256[][] calldata _entityAmounts
) internal {
for (uint i = 0; i < _ownerAddresses.length; i++) {
_checkAndDecreaseAmountsInternal(
_ownerAddresses[i],
_ownerIds[i],
_entityTokenIds[i],
_entityAmounts[i]
);
}
}
function _burnOnBreak(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId
) internal override {
burn(_ownerAddress, _ownerTokenId, _entityAddress, _entityTokenId, 1);
}
function _isNextAvailable(
address _ownerAddress,
uint _ownerTokenId,
address _entityAddress,
uint _entityTokenId
) internal view override returns (bool) {
require(_entityAddress == COLLECTION_ADDRESS);
return stakerBalances[_ownerAddress][_ownerTokenId][_entityTokenId] > 0;
}
function updatePermit(address _actionPermit) external onlyAdmin {
ACTION_PERMIT = IActionPermit(_actionPermit);
}
}
{
"compilationTarget": {
"contracts/AdventurerArmory/RarityItemArmoryAdapter.sol": "RarityItemArmoryAdapter"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_manager","type":"address"},{"internalType":"address","name":"_actionPermit","type":"address"},{"internalType":"address","name":"_rarityItem","type":"address"},{"internalType":"address","name":"_breakHandler","type":"address"},{"internalType":"address","name":"_maxDurabilitySource","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DurabilityNotSupported","type":"error"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_tokenIds","type":"uint256"},{"internalType":"uint256","name":"_tokenAmounts","type":"uint256"}],"name":"InsufficientAmountStaked","type":"error"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerTokenId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityTokenId","type":"uint256"},{"internalType":"uint256","name":"durabilityLoss","type":"uint256"}],"name":"InsufficientDurability","type":"error"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerTokenId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityTokenId","type":"uint256"}],"name":"TokenNotAvailable","type":"error"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"},{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"}],"name":"Unauthorized","type":"error"},{"inputs":[{"internalType":"address","name":"_entityAddress","type":"address"}],"name":"UnsupportedEntity","type":"error"},{"inputs":[{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"string","name":"operation","type":"string"}],"name":"UnsupportedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"adventurerAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"adventurerTokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"entityAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"entityTokenId","type":"uint256"}],"name":"EntityBroken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"adventurerAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"adventurerTokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"entityAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"entityTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"durability","type":"uint256"}],"name":"EntityDurabilityChanged","type":"event"},{"inputs":[],"name":"ACTION_PERMIT","outputs":[{"internalType":"contract IActionPermit","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BREAK_HANDLER","outputs":[{"internalType":"contract IBrokenTokenHandler","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MANAGER","outputs":[{"internalType":"contract IManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SUPPORTS_DURABILITY","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN","outputs":[{"internalType":"contract RarityItem","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityTokenId","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"result","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_entityAmounts","type":"uint256[]"}],"name":"batchCheckAmounts","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_ownerAddresses","type":"address[]"},{"internalType":"uint256[]","name":"_ownerIds","type":"uint256[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityTokenIds","type":"uint256[][]"},{"internalType":"uint256[][]","name":"_entityAmounts","type":"uint256[][]"}],"name":"batchCheckAmounts","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"},{"internalType":"uint256","name":"_entityAmounts","type":"uint256"}],"name":"batchCheckAmounts","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityTokenId","type":"uint256"},{"internalType":"uint256","name":"_entityAmount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_entityAmounts","type":"uint256[]"}],"name":"burnBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_ownerAddress","type":"address[]"},{"internalType":"uint256[]","name":"_ownerId","type":"uint256[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityTokenIds","type":"uint256[][]"},{"internalType":"uint256[][]","name":"_entityAmounts","type":"uint256[][]"}],"name":"burnBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"}],"name":"clearDurabilityCache","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityId","type":"uint256"}],"name":"currentDurability","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityId","type":"uint256[]"}],"name":"currentDurabilityBatch","outputs":[{"internalType":"uint256[]","name":"result","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_ownerAddresses","type":"address[]"},{"internalType":"uint256[]","name":"_ownerIds","type":"uint256[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityId","type":"uint256[][]"}],"name":"currentDurabilityBatch","outputs":[{"internalType":"uint256[][]","name":"result","type":"uint256[][]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_ownerAddresses","type":"address[]"},{"internalType":"uint256[]","name":"_ownerIds","type":"uint256[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityId","type":"uint256[][]"}],"name":"currentDurabilityBatchPercentage","outputs":[{"internalType":"uint256[][]","name":"result","type":"uint256[][]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityIds","type":"uint256[]"}],"name":"currentDurabilityBatchPercentage","outputs":[{"internalType":"uint256[]","name":"result","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityId","type":"uint256"}],"name":"currentDurabilityPercentage","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"currentDurabilityStorage","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entityType","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"maximumDurabilitySource","outputs":[{"internalType":"contract IMaximumDurabilitySource","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityTokenId","type":"uint256"},{"internalType":"uint256","name":"_entityAmount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_entityAmounts","type":"uint256[]"}],"name":"mintBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_ownerAddress","type":"address[]"},{"internalType":"uint256[]","name":"_ownerId","type":"uint256[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityTokenIds","type":"uint256[][]"},{"internalType":"uint256[][]","name":"_entityAmounts","type":"uint256[][]"}],"name":"mintBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_reducer","type":"address"},{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerTokenId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityTokenId","type":"uint256"},{"internalType":"uint256","name":"_durabilityLoss","type":"uint256"},{"internalType":"bool","name":"_startNewTokenIfNeeded","type":"bool"},{"internalType":"bool","name":"_ignoreAvailability","type":"bool"}],"name":"reduceDurability","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_reducer","type":"address"},{"internalType":"address[]","name":"_ownerAddresses","type":"address[]"},{"internalType":"uint256[]","name":"_ownerTokenIds","type":"uint256[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityTokenIds","type":"uint256[][]"},{"internalType":"uint256","name":"_durabilityLoss","type":"uint256"},{"internalType":"bool","name":"_startNewTokenIfNeeded","type":"bool"},{"internalType":"bool","name":"_ignoreAvailability","type":"bool"}],"name":"reduceDurabilityBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_reducer","type":"address"},{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerTokenId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_durabilityLosses","type":"uint256[]"},{"internalType":"bool","name":"_startNewTokenIfNeeded","type":"bool"},{"internalType":"bool","name":"_ignoreAvailability","type":"bool"}],"name":"reduceDurabilityBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_reducer","type":"address"},{"internalType":"address[]","name":"_ownerAddresses","type":"address[]"},{"internalType":"uint256[]","name":"_ownerTokenIds","type":"uint256[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityTokenIds","type":"uint256[][]"},{"internalType":"uint256[][]","name":"_durabilityLosses","type":"uint256[][]"},{"internalType":"bool","name":"_startNewTokenIfNeeded","type":"bool"},{"internalType":"bool","name":"_ignoreAvailability","type":"bool"}],"name":"reduceDurabilityBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_reducer","type":"address"},{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerTokenId","type":"uint256"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"},{"internalType":"uint256","name":"_durabilityLoss","type":"uint256"},{"internalType":"bool","name":"_startNewTokenIfNeeded","type":"bool"},{"internalType":"bool","name":"_ignoreAvailability","type":"bool"}],"name":"reduceDurabilityBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"},{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"bytes32[]","name":"_proof","type":"bytes32[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityTokenId","type":"uint256"},{"internalType":"uint256","name":"_entityAmount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"},{"internalType":"address[]","name":"_ownerAddress","type":"address[]"},{"internalType":"uint256[]","name":"_ownerId","type":"uint256[]"},{"internalType":"bytes32[][]","name":"_proofs","type":"bytes32[][]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityTokenIds","type":"uint256[][]"},{"internalType":"uint256[][]","name":"_entityAmounts","type":"uint256[][]"}],"name":"stakeBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"},{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"bytes32[]","name":"_proof","type":"bytes32[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_entityAmounts","type":"uint256[]"}],"name":"stakeBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"stakerBalances","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":[{"internalType":"address","name":"_staker","type":"address"},{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"bytes32[]","name":"_proofs","type":"bytes32[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256","name":"_entityTokenId","type":"uint256"},{"internalType":"uint256","name":"_entityAmount","type":"uint256"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"},{"internalType":"address[]","name":"_ownerAddress","type":"address[]"},{"internalType":"uint256[]","name":"_ownerId","type":"uint256[]"},{"internalType":"bytes32[][]","name":"_proofs","type":"bytes32[][]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[][]","name":"_entityTokenIds","type":"uint256[][]"},{"internalType":"uint256[][]","name":"_entityAmounts","type":"uint256[][]"}],"name":"unstakeBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"},{"internalType":"address","name":"_ownerAddress","type":"address"},{"internalType":"uint256","name":"_ownerId","type":"uint256"},{"internalType":"bytes32[]","name":"_proof","type":"bytes32[]"},{"internalType":"address","name":"_entityAddress","type":"address"},{"internalType":"uint256[]","name":"_entityTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_entityAmounts","type":"uint256[]"}],"name":"unstakeBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_handler","type":"address"}],"name":"updateBreakHandler","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_durabilitySource","type":"address"}],"name":"updateDurabilitySource","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_actionPermit","type":"address"}],"name":"updatePermit","outputs":[],"stateMutability":"nonpayable","type":"function"}]