Contract Name:
PeerToPlayDefaultImplementation
Contract Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Variables} from "../variables.sol";
/**
* @title Index Interface
* @dev Interface to retrieve the list address from the PeerToPlayFactory.
*/
interface IndexInterface {
/**
* @dev Returns the address of the list contract.
*/
function list() external view returns (address);
}
/**
* @title List Interface
* @dev Interface for adding and removing authorized users in PeerToPlay.
*/
interface ListInterface {
/**
* @dev Adds authorization for a user.
* @param user Address of the user.
*/
function addAuth(address user) external;
/**
* @dev Removes authorization for a user.
* @param user Address of the user.
*/
function removeAuth(address user) external;
}
/**
* @title Constants
* @dev Defines constants and immutable variables used in the PeerToPlay contract.
*/
contract Constants is Variables {
uint256 public constant implementationVersion = 1;
// PeerToPlayFactory Address.
address public immutable peerToPlayFactory;
// The Account Module Version.
uint256 public constant version = 1;
constructor(address _peerToPlayFactory) {
peerToPlayFactory = _peerToPlayFactory;
}
}
/**
* @title Record
* @dev Provides functionality to enable and disable user authorization, and token receiver functions.
*/
contract Record is Constants {
constructor(address _peerToPlayFactory) Constants(_peerToPlayFactory) {}
event LogEnableUser(address indexed user);
event LogDisableUser(address indexed user);
/**
* @dev Checks if a user is authorized.
* @param user Address of the user.
* @return bool True if authorized, otherwise false.
*/
function isAuth(address user) public view returns (bool) {
return _auth[user];
}
/**
* @dev Enables a new user by adding them to the authorized list.
* @param user Address of the user to enable.
*/
function enable(address user) public {
require(
msg.sender == address(this) || msg.sender == peerToPlayFactory,
"not-self-index"
);
require(user != address(0), "not-valid");
require(!_auth[user], "already-enabled");
_auth[user] = true;
ListInterface(IndexInterface(peerToPlayFactory).list()).addAuth(user);
emit LogEnableUser(user);
}
/**
* @dev Disables a user by removing them from the authorized list.
* @param user Address of the user to disable.
*/
function disable(address user) public {
require(msg.sender == address(this), "not-self");
require(user != address(0), "not-valid");
require(_auth[user], "already-disabled");
delete _auth[user];
ListInterface(IndexInterface(peerToPlayFactory).list()).removeAuth(
user
);
emit LogDisableUser(user);
}
/**
* @dev ERC721 token receiver function to handle the receipt of ERC721 tokens.
* @return bytes4 Function selector for ERC721 token receipt.
*/
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external returns (bytes4) {
return 0x150b7a02; // bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))
}
/**
* @dev ERC1155 token receiver function to handle the receipt of single ERC1155 tokens.
* @return bytes4 Function selector for single ERC1155 token receipt.
*/
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) external returns (bytes4) {
return 0xf23a6e61; // bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))
}
/**
* @dev ERC1155 batch token receiver function to handle the receipt of multiple ERC1155 tokens.
* @return bytes4 Function selector for batch ERC1155 token receipt.
*/
function onERC1155BatchReceived(
address,
address,
uint256[] calldata,
uint256[] calldata,
bytes calldata
) external returns (bytes4) {
return 0xbc197c81; // bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))
}
}
/**
* @title PeerToPlayDefaultImplementation
* @dev Main contract for PeerToPlay default implementation, inherits Record functionalities.
*/
contract PeerToPlayDefaultImplementation is Record {
constructor(address _peerToPlayFactory) Record(_peerToPlayFactory) {}
/**
* @dev Fallback function to receive Ether directly.
*/
receive() external payable {}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title Variables
* @dev This contract manages the authorization settings for the platform.
*/
contract Variables {
/// @dev Mapping of address to boolean indicating authorization status.
mapping (address => bool) internal _auth;
}