Address Contract Verified
Address
0x83e225353Fafc848bC5AF132A3ebC2f8f66d95C8
Balance
0 ETH
Nonce
1
Code Size
3579 bytes
Creator
0xFEB26AAB...9C6B at tx 0x2e2c35d9...79447d
Indexed Transactions
0 (1 on-chain, 1.3% indexed)
Contract Bytecode
3579 bytes
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c80638426b9681161008c578063a7fdd04711610066578063a7fdd047146101d6578063cc5b7450146101e9578063daba7ef7146101fc578063e7e5db4f1461020f57600080fd5b80638426b968146101be57806399e80f3b146101c65780639aa9019e146101ce57600080fd5b80634c6c848f116100c85780634c6c848f1461014c5780634ee8f8581461015f5780635c60da1b146101725780636160b05e1461018357600080fd5b8063021a5fe5146100ef5780630900f010146101175780633c2311661461012c575b600080fd5b6101026100fd366004610b5c565b610217565b60405190151581526020015b60405180910390f35b61012a610125366004610b7e565b610282565b005b6101346103ab565b6040516001600160a01b03909116815260200161010e565b61012a61015a366004610b7e565b6103e4565b61012a61016d366004610b7e565b6104e6565b6000546001600160a01b0316610134565b610196610191366004610b5c565b6105de565b604080516001600160a01b03948516815293909216602084015215159082015260600161010e565b61012a610613565b610134610720565b61013461073e565b61012a6101e4366004610bbd565b61076e565b61012a6101f7366004610bbd565b61082a565b61012a61020a366004610b7e565b6108e6565b6101346109dd565b6000808261024660017f9a7afc584486ebd3e91191a9ac2c2e986b3aaa4084656fc915fe0843ff009c6b610c98565b6040516001600160e01b03199092166020830152602482015260440160408051601f198184030181529190528051602090910120549392505050565b7f000000000000000000000000feb26aab75638440b3cefe8b10de6118972f9c6b6001600160a01b031633146102ff5760405162461bcd60e51b815260206004820152601960248201527f50726f7879426561636f6e3a206e6f7420616e206f776e65720000000000000060448201526064015b60405180910390fd5b6001600160a01b0381163b6103565760405162461bcd60e51b815260206004820152601b60248201527f50726f7879426561636f6e3a206e6f74206120636f6e7472616374000000000060448201526064016102f6565b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b906020015b60405180910390a150565b60006103df6103db60017f1777adabd324f814e2b0e28f6edf876dce01d7d66358c9acfe87b1b5f38338d6610c98565b5490565b905090565b6104006103db6001600080516020610d86833981519152610c98565b6001600160a01b0316336001600160a01b0316146104305760405162461bcd60e51b81526004016102f690610cb1565b610439816109fb565b60006104696103db60017f1777adabd324f814e2b0e28f6edf876dce01d7d66358c9acfe87b1b5f38338d6610c98565b905061049e61049960017f1777adabd324f814e2b0e28f6edf876dce01d7d66358c9acfe87b1b5f38338d6610c98565b839055565b604080516001600160a01b038084168252841660208201527ff33499cccaa0611882086224cc48cd82ef54b66a4d2edf4ed67108dd516896d591015b60405180910390a15050565b6105026103db6001600080516020610da6833981519152610c98565b6001600160a01b0316336001600160a01b0316146105625760405162461bcd60e51b815260206004820152601d60248201527f53706865726558206572726f723a2061646d696e20726571756972656400000060448201526064016102f6565b60006105806103db6001600080516020610d86833981519152610c98565b905061059e6104996001600080516020610d86833981519152610c98565b604080516001600160a01b038084168252841660208201527f2ac55ae7ba47db34b5334622acafeb34a65daf143b47019273185d64c73a35a591016104da565b60008060006105f56000546001600160a01b031690565b6105fd6103ab565b61060686610217565b9250925092509193909250565b3361061c61073e565b6001600160a01b0316146106815760405162461bcd60e51b815260206004820152602660248201527f53706865726558206572726f723a206e6f74207468652070656e64696e67206160448201526518d8dbdd5b9d60d21b60648201526084016102f6565b600061068b610720565b90506106ae6106a96001600080516020610da6833981519152610c98565b339055565b6106e26106dc60017f3a517dd736309b905c692160a21b5439bdc56db1dc77d6982b66d44814e3fa97610c98565b60009055565b604080516001600160a01b03831681523360208201527f67ebaebcd2ca5a91a404e898110f221747e8d15567f2388a34794aab151cf3e691016103a0565b60006103df6103db6001600080516020610da6833981519152610c98565b60006103df6103db60017f3a517dd736309b905c692160a21b5439bdc56db1dc77d6982b66d44814e3fa97610c98565b61078a6103db6001600080516020610d86833981519152610c98565b6001600160a01b0316336001600160a01b0316146107ba5760405162461bcd60e51b81526004016102f690610cb1565b60005b81518110156107fa576107ea8282815181106107db576107db610ce6565b60200260200101516000610ad5565b6107f381610cfc565b90506107bd565b507f754b9f3148ad4cf227ecdf9a64810fa2d0b8682a2de15dfad5310a12b7281a5f816040516103a09190610d15565b6108466103db6001600080516020610d86833981519152610c98565b6001600160a01b0316336001600160a01b0316146108765760405162461bcd60e51b81526004016102f690610cb1565b60005b81518110156108b6576108a682828151811061089757610897610ce6565b60200260200101516001610ad5565b6108af81610cfc565b9050610879565b507f45fc6a4de33dfc2fa6f40e48f353bf7ff006086db3ecf80c077f788082cc7d5a816040516103a09190610d15565b6109026103db6001600080516020610da6833981519152610c98565b6001600160a01b0316336001600160a01b0316146109625760405162461bcd60e51b815260206004820152601d60248201527f53706865726558206572726f723a2061646d696e20726571756972656400000060448201526064016102f6565b61099561099060017f3a517dd736309b905c692160a21b5439bdc56db1dc77d6982b66d44814e3fa97610c98565b829055565b7f5778f1547abbbb86090a43c32aec38334b31df4beeb6f8f3fa063f593b53a5266109be610720565b604080516001600160a01b0392831681529184166020830152016103a0565b60006103df6103db6001600080516020610d86833981519152610c98565b6001600160a01b0381161580610a7b57506040516301ffc9a760e01b81526329f20dd560e11b60048201526001600160a01b038216906301ffc9a790602401602060405180830381865afa158015610a57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a7b9190610d63565b610ad25760405162461bcd60e51b815260206004820152602260248201527f53706865726558206572726f723a206e6f7420612053706865726558456e67696044820152616e6560f01b60648201526084016102f6565b50565b600082610b0360017f9a7afc584486ebd3e91191a9ac2c2e986b3aaa4084656fc915fe0843ff009c6b610c98565b6040516001600160e01b031990921660208301526024820152604401604051602081830303815290604052805190602001209050818155505050565b80356001600160e01b031981168114610b5757600080fd5b919050565b600060208284031215610b6e57600080fd5b610b7782610b3f565b9392505050565b600060208284031215610b9057600080fd5b81356001600160a01b0381168114610b7757600080fd5b634e487b7160e01b600052604160045260246000fd5b60006020808385031215610bd057600080fd5b823567ffffffffffffffff80821115610be857600080fd5b818501915085601f830112610bfc57600080fd5b813581811115610c0e57610c0e610ba7565b8060051b604051601f19603f83011681018181108582111715610c3357610c33610ba7565b604052918252848201925083810185019188831115610c5157600080fd5b938501935b82851015610c7657610c6785610b3f565b84529385019392850192610c56565b98975050505050505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610cab57610cab610c82565b92915050565b6020808252818101527f53706865726558206572726f723a206f70657261746f72207265717569726564604082015260600190565b634e487b7160e01b600052603260045260246000fd5b600060018201610d0e57610d0e610c82565b5060010190565b6020808252825182820181905260009190848201906040850190845b81811015610d575783516001600160e01b03191683529284019291840191600101610d31565b50909695505050505050565b600060208284031215610d7557600080fd5b81518015158114610b7757600080fdfeadf90d75f0f2d657d5a22fa0f6e4dabb83c4598b77158eb4119cb38f1d864463ca334bf49ef20e9cbff039feda3bc1c2a853aff17b1b5187e4aa1380ec55829da2646970667358221220e3a8ae8b144f8d5f1dd5766405b6b30bca020f96d1366696f3add7bdffc7c18b64736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
EVM: paris
Optimization: Yes (200 runs)
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
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");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
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");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
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);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
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);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
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);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
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 {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
ProxyBeacon.sol 41 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {IBeacon} from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
/**
* @notice The PoolContractsRegistry module
*
* This is a utility lightweighted ProxyBeacon contract this is used as a beacon that BeaconProxies point to.
*/
contract ProxyBeacon is IBeacon {
using Address for address;
address private immutable _OWNER;
address private _implementation;
event Upgraded(address implementation);
modifier onlyOwner() {
require(_OWNER == msg.sender, "ProxyBeacon: not an owner");
_;
}
constructor() {
_OWNER = msg.sender;
}
function upgrade(address newImplementation_) external onlyOwner {
require(newImplementation_.isContract(), "ProxyBeacon: not a contract");
_implementation = newImplementation_;
emit Upgraded(newImplementation_);
}
function implementation() public view override returns (address) {
return _implementation;
}
}
ISphereXEngine.sol 52 lines
// SPDX-License-Identifier: UNLICENSED
// (c) SphereX 2023 Terms&Conditions
pragma solidity ^0.8.0;
/**
* @title Interface for SphereXEngine - definitions of core functionality
* @author SphereX Technologies ltd
* @notice This interface is imported by SphereXProtected, so that SphereXProtected can call functions from SphereXEngine
* @dev Full docs of these functions can be found in SphereXEngine
*/
interface ISphereXEngine {
function sphereXValidatePre(int256 num, address sender, bytes calldata data) external returns (bytes32[] memory);
function sphereXValidatePost(
int256 num,
uint256 gas,
bytes32[] calldata valuesBefore,
bytes32[] calldata valuesAfter
) external;
function sphereXValidateInternalPre(int256 num) external returns (bytes32[] memory);
function sphereXValidateInternalPost(
int256 num,
uint256 gas,
bytes32[] calldata valuesBefore,
bytes32[] calldata valuesAfter
) external;
function addAllowedSenderOnChain(address sender) external;
/**
* This function is taken as is from OZ IERC165, we don't inherit from OZ
* to avoid collisions with the customer OZ version.
*
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
/**
* @dev this struct is used to reduce the stack usage of the modifiers.
*/
struct ModifierLocals {
bytes32[] storageSlots;
bytes32[] valuesBefore;
uint256 gas;
}
ISphereXBeacon.sol 14 lines
// SPDX-License-Identifier: UNLICENSED
// (c) SphereX 2023 Terms&Conditions
pragma solidity ^0.8.0;
import {ISphereXEngine} from "../ISphereXEngine.sol";
/**
* @title Interface for a spherex beacon to be used by spherex's beacon proxy.
*/
interface ISphereXBeacon {
function protectedImplementation(bytes4 func_sig) external view returns (address, address, bool);
}
SphereXProtectedBase.sol 329 lines
// SPDX-License-Identifier: UNLICENSED
// (c) SphereX 2023 Terms&Conditions
pragma solidity ^0.8.0;
import {ISphereXEngine, ModifierLocals} from "./ISphereXEngine.sol";
/**
* @title SphereX base Customer contract template
*/
abstract contract SphereXProtectedBase {
/**
* @dev we would like to avoid occupying storage slots
* @dev to easily incorporate with existing contracts
*/
bytes32 private constant SPHEREX_ADMIN_STORAGE_SLOT = bytes32(uint256(keccak256("eip1967.spherex.spherex")) - 1);
bytes32 private constant SPHEREX_PENDING_ADMIN_STORAGE_SLOT =
bytes32(uint256(keccak256("eip1967.spherex.pending")) - 1);
bytes32 private constant SPHEREX_OPERATOR_STORAGE_SLOT = bytes32(uint256(keccak256("eip1967.spherex.operator")) - 1);
bytes32 private constant SPHEREX_ENGINE_STORAGE_SLOT =
bytes32(uint256(keccak256("eip1967.spherex.spherex_engine")) - 1);
event ChangedSpherexOperator(address oldSphereXAdmin, address newSphereXAdmin);
event ChangedSpherexEngineAddress(address oldEngineAddress, address newEngineAddress);
event SpherexAdminTransferStarted(address currentAdmin, address pendingAdmin);
event SpherexAdminTransferCompleted(address oldAdmin, address newAdmin);
/**
* @dev used when the client doesn't use a proxy
* @notice constructor visibility is required to support all compiler versions
*/
constructor(address admin, address operator, address engine) {
__SphereXProtectedBase_init(admin, operator, engine);
}
/**
* @dev used when the client uses a proxy - should be called by the inhereter initialization
*/
function __SphereXProtectedBase_init(address admin, address operator, address engine) internal virtual {
_setAddress(SPHEREX_ADMIN_STORAGE_SLOT, admin);
emit SpherexAdminTransferCompleted(address(0), admin);
_setAddress(SPHEREX_OPERATOR_STORAGE_SLOT, operator);
emit ChangedSpherexOperator(address(0), operator);
_checkSphereXEngine(engine);
_setAddress(SPHEREX_ENGINE_STORAGE_SLOT, engine);
emit ChangedSpherexEngineAddress(address(0), engine);
}
// ============ Helper functions ============
function _sphereXEngine() private view returns (ISphereXEngine) {
return ISphereXEngine(_getAddress(SPHEREX_ENGINE_STORAGE_SLOT));
}
/**
* Stores a new address in an arbitrary slot
* @param slot where to store the address
* @param newAddress address to store in given slot
*/
function _setAddress(bytes32 slot, address newAddress) internal {
// solhint-disable-next-line no-inline-assembly
// slither-disable-next-line assembly
assembly {
sstore(slot, newAddress)
}
}
/**
* Returns an address from an arbitrary slot.
* @param slot to read an address from
*/
function _getAddress(bytes32 slot) internal view returns (address addr) {
// solhint-disable-next-line no-inline-assembly
// slither-disable-next-line assembly
assembly {
addr := sload(slot)
}
}
// ============ Local modifiers ============
modifier onlySphereXAdmin() {
require(msg.sender == _getAddress(SPHEREX_ADMIN_STORAGE_SLOT), "SphereX error: admin required");
_;
}
modifier spherexOnlyOperator() {
require(msg.sender == _getAddress(SPHEREX_OPERATOR_STORAGE_SLOT), "SphereX error: operator required");
_;
}
modifier returnsIfNotActivated() {
if (address(_sphereXEngine()) == address(0)) {
return;
}
_;
}
// ============ Management ============
/**
* Returns the currently pending admin address, the one that can call acceptSphereXAdminRole to become the admin.
* @dev Could not use OZ Ownable2Step because the client's contract might use it.
*/
function pendingSphereXAdmin() public view returns (address) {
return _getAddress(SPHEREX_PENDING_ADMIN_STORAGE_SLOT);
}
/**
* Returns the current admin address, the one that can call acceptSphereXAdminRole to become the admin.
* @dev Could not use OZ Ownable2Step because the client's contract might use it.
*/
function sphereXAdmin() public view returns (address) {
return _getAddress(SPHEREX_ADMIN_STORAGE_SLOT);
}
/**
* Returns the current operator address.
*/
function sphereXOperator() public view returns (address) {
return _getAddress(SPHEREX_OPERATOR_STORAGE_SLOT);
}
/**
* Returns the current engine address.
*/
function sphereXEngine() public view returns (address) {
return _getAddress(SPHEREX_ENGINE_STORAGE_SLOT);
}
/**
* Setting the address of the next admin. this address will have to accept the role to become the new admin.
* @dev Could not use OZ Ownable2Step because the client's contract might use it.
*/
function transferSphereXAdminRole(address newAdmin) public virtual onlySphereXAdmin {
_setAddress(SPHEREX_PENDING_ADMIN_STORAGE_SLOT, newAdmin);
emit SpherexAdminTransferStarted(sphereXAdmin(), newAdmin);
}
/**
* Accepting the admin role and completing the transfer.
* @dev Could not use OZ Ownable2Step because the client's contract might use it.
*/
function acceptSphereXAdminRole() public virtual {
require(pendingSphereXAdmin() == msg.sender, "SphereX error: not the pending account");
address oldAdmin = sphereXAdmin();
_setAddress(SPHEREX_ADMIN_STORAGE_SLOT, msg.sender);
_setAddress(SPHEREX_PENDING_ADMIN_STORAGE_SLOT, address(0));
emit SpherexAdminTransferCompleted(oldAdmin, msg.sender);
}
/**
*
* @param newSphereXOperator new address of the new operator account
*/
function changeSphereXOperator(address newSphereXOperator) external onlySphereXAdmin {
address oldSphereXOperator = _getAddress(SPHEREX_OPERATOR_STORAGE_SLOT);
_setAddress(SPHEREX_OPERATOR_STORAGE_SLOT, newSphereXOperator);
emit ChangedSpherexOperator(oldSphereXOperator, newSphereXOperator);
}
/**
* Checks the given address implements ISphereXEngine or is address(0)
* @param newSphereXEngine new address of the spherex engine
*/
function _checkSphereXEngine(address newSphereXEngine) private view {
require(
newSphereXEngine == address(0)
|| ISphereXEngine(newSphereXEngine).supportsInterface(type(ISphereXEngine).interfaceId),
"SphereX error: not a SphereXEngine"
);
}
/**
*
* @param newSphereXEngine new address of the spherex engine
* @dev this is also used to actually enable the defense
* (because as long is this address is 0, the protection is disabled).
*/
function changeSphereXEngine(address newSphereXEngine) external spherexOnlyOperator {
_checkSphereXEngine(newSphereXEngine);
address oldEngine = _getAddress(SPHEREX_ENGINE_STORAGE_SLOT);
_setAddress(SPHEREX_ENGINE_STORAGE_SLOT, newSphereXEngine);
emit ChangedSpherexEngineAddress(oldEngine, newSphereXEngine);
}
// ============ Engine interaction ============
function _addAllowedSenderOnChain(address newSender) internal {
ISphereXEngine engine = _sphereXEngine();
if (address(engine) != address(0)) {
engine.addAllowedSenderOnChain(newSender);
}
}
// ============ Hooks ============
/**
* @dev internal function for engine communication. We use it to reduce contract size.
* Should be called before the code of a function.
* @param num function identifier
* @param isExternalCall set to true if this was called externally
* or a 'public' function from another address
*/
function _sphereXValidatePre(int256 num, bool isExternalCall)
private
returnsIfNotActivated
returns (ModifierLocals memory locals)
{
ISphereXEngine sphereXEngine = _sphereXEngine();
if (isExternalCall) {
locals.storageSlots = sphereXEngine.sphereXValidatePre(num, msg.sender, msg.data);
} else {
locals.storageSlots = sphereXEngine.sphereXValidateInternalPre(num);
}
locals.valuesBefore = _readStorage(locals.storageSlots);
locals.gas = gasleft();
return locals;
}
/**
* @dev internal function for engine communication. We use it to reduce contract size.
* Should be called after the code of a function.
* @param num function identifier
* @param isExternalCall set to true if this was called externally
* or a 'public' function from another address
*/
function _sphereXValidatePost(int256 num, bool isExternalCall, ModifierLocals memory locals)
private
returnsIfNotActivated
{
uint256 gas = locals.gas - gasleft();
ISphereXEngine sphereXEngine = _sphereXEngine();
bytes32[] memory valuesAfter;
valuesAfter = _readStorage(locals.storageSlots);
if (isExternalCall) {
sphereXEngine.sphereXValidatePost(num, gas, locals.valuesBefore, valuesAfter);
} else {
sphereXEngine.sphereXValidateInternalPost(num, gas, locals.valuesBefore, valuesAfter);
}
}
/**
* @dev internal function for engine communication. We use it to reduce contract size.
* Should be called before the code of a function.
* @param num function identifier
* @return locals ModifierLocals
*/
function _sphereXValidateInternalPre(int256 num)
internal
returnsIfNotActivated
returns (ModifierLocals memory locals)
{
locals.storageSlots = _sphereXEngine().sphereXValidateInternalPre(num);
locals.valuesBefore = _readStorage(locals.storageSlots);
locals.gas = gasleft();
return locals;
}
/**
* @dev internal function for engine communication. We use it to reduce contract size.
* Should be called after the code of a function.
* @param num function identifier
* @param locals ModifierLocals
*/
function _sphereXValidateInternalPost(int256 num, ModifierLocals memory locals) internal returnsIfNotActivated {
bytes32[] memory valuesAfter;
valuesAfter = _readStorage(locals.storageSlots);
_sphereXEngine().sphereXValidateInternalPost(num, locals.gas - gasleft(), locals.valuesBefore, valuesAfter);
}
/**
* @dev Modifier to be incorporated in all internal protected non-view functions
*/
modifier sphereXGuardInternal(int256 num) {
ModifierLocals memory locals = _sphereXValidateInternalPre(num);
_;
_sphereXValidateInternalPost(-num, locals);
}
/**
* @dev Modifier to be incorporated in all external protected non-view functions
*/
modifier sphereXGuardExternal(int256 num) {
ModifierLocals memory locals = _sphereXValidatePre(num, true);
_;
_sphereXValidatePost(-num, true, locals);
}
/**
* @dev Modifier to be incorporated in all public protected non-view functions
*/
modifier sphereXGuardPublic(int256 num, bytes4 selector) {
ModifierLocals memory locals = _sphereXValidatePre(num, msg.sig == selector);
_;
_sphereXValidatePost(-num, msg.sig == selector, locals);
}
// ============ Internal Storage logic ============
/**
* Internal function that reads values from given storage slots and returns them
* @param storageSlots list of storage slots to read
* @return list of values read from the various storage slots
*/
function _readStorage(bytes32[] memory storageSlots) internal view returns (bytes32[] memory) {
uint256 arrayLength = storageSlots.length;
bytes32[] memory values = new bytes32[](arrayLength);
// create the return array data
for (uint256 i = 0; i < arrayLength; i++) {
bytes32 slot = storageSlots[i];
bytes32 temp_value;
// solhint-disable-next-line no-inline-assembly
// slither-disable-next-line assembly
assembly {
temp_value := sload(slot)
}
values[i] = temp_value;
}
return values;
}
}
SphereXProxyBase.sol 65 lines
// SPDX-License-Identifier: UNLICENSED
// (c) SphereX 2023 Terms&Conditions
pragma solidity ^0.8.0;
import {SphereXProtectedBase} from "./SphereXProtectedBase.sol";
contract SphereXProxyBase is SphereXProtectedBase {
constructor(address admin, address operator, address engine) SphereXProtectedBase(admin, operator, engine) {}
event AddedProtectedFuncSigs(bytes4[] patterns);
event RemovedProtectedFuncSigs(bytes4[] patterns);
/**
* @dev As we dont want to conflict with the imp's storage we implenment the protected
* @dev functions map in an arbitrary slot.
*/
bytes32 private constant PROTECTED_FUNC_SIG_BASE_POSITION =
bytes32(uint256(keccak256("eip1967.spherex.protection_sig_base")) - 1);
/**
* Sets the value of a functions signature in the protected functions map stored in an arbitrary slot
* @param func_sig of the wanted function
* @param value bool value to set for the given function signature
*/
function _setProtectedFuncSig(bytes4 func_sig, bool value) internal {
bytes32 position = keccak256(abi.encodePacked(func_sig, PROTECTED_FUNC_SIG_BASE_POSITION));
assembly {
sstore(position, value)
}
}
/**
* Adds several functions' signature to the protected functions map stored in an arbitrary slot
* @param keys of the functions added to the protected map
*/
function addProtectedFuncSigs(bytes4[] memory keys) public spherexOnlyOperator {
for (uint256 i = 0; i < keys.length; ++i) {
_setProtectedFuncSig(keys[i], true);
}
emit AddedProtectedFuncSigs(keys);
}
/**
* Removes given functions' signature from the protected functions map
* @param keys of the functions removed from the protected map
*/
function removeProtectedFuncSigs(bytes4[] memory keys) public spherexOnlyOperator {
for (uint256 i = 0; i < keys.length; ++i) {
_setProtectedFuncSig(keys[i], false);
}
emit RemovedProtectedFuncSigs(keys);
}
/**
* Getter for a specific function signature in the protected map
* @param func_sig of the wanted function
*/
function isProtectedFuncSig(bytes4 func_sig) public view virtual returns (bool value) {
bytes32 position = keccak256(abi.encodePacked(func_sig, PROTECTED_FUNC_SIG_BASE_POSITION));
assembly {
value := sload(position)
}
}
}
PoolBeacon.sol 21 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@spherex-xyz/contracts/src/SphereXProxyBase.sol";
import "@spherex-xyz/contracts/src/ProtectedProxies/ISphereXBeacon.sol";
import "@solarity/solidity-lib/contracts-registry/pools/proxy/ProxyBeacon.sol";
contract PoolBeacon is ISphereXBeacon, SphereXProxyBase, ProxyBeacon {
constructor(
address sphereXAdmin,
address sphereXOperator,
address sphereXEngine
) SphereXProxyBase(sphereXAdmin, sphereXOperator, sphereXEngine) {}
function protectedImplementation(
bytes4 selector
) external view returns (address, address, bool) {
return (implementation(), sphereXEngine(), isProtectedFuncSig(selector));
}
}
Read Contract
implementation 0x5c60da1b → address
isProtectedFuncSig 0x021a5fe5 → bool
pendingSphereXAdmin 0x9aa9019e → address
protectedImplementation 0x6160b05e → address, address, bool
sphereXAdmin 0x99e80f3b → address
sphereXEngine 0x3c231166 → address
sphereXOperator 0xe7e5db4f → address
Write Contract 7 functions
These functions modify contract state and require a wallet transaction to execute.
acceptSphereXAdminRole 0x8426b968
No parameters
addProtectedFuncSigs 0xcc5b7450
bytes4[] keys
changeSphereXEngine 0x4c6c848f
address newSphereXEngine
changeSphereXOperator 0x4ee8f858
address newSphereXOperator
removeProtectedFuncSigs 0xa7fdd047
bytes4[] keys
transferSphereXAdminRole 0xdaba7ef7
address newAdmin
upgrade 0x0900f010
address newImplementation_
Recent Transactions
This address has 1 on-chain transactions, but only 1.3% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →