HypernativeFirewallProtected

Git Source

Title: HypernativeFirewallProtected

Author: Merge Layers Inc.

Abstract contract that provides firewall protection for the contract.

Inherited from Hypernative and refactored it for our needs, but without changing the core logic.

State Variables

HYPERNATIVE_ORACLE_STORAGE_SLOT

Storage slot for the firewall address

bytes32 private constant HYPERNATIVE_ORACLE_STORAGE_SLOT =
    bytes32(uint256(keccak256("eip1967.hypernative.firewall")) - 1)

HYPERNATIVE_ADMIN_STORAGE_SLOT

Storage slot for the firewall admin address

bytes32 private constant HYPERNATIVE_ADMIN_STORAGE_SLOT =
    bytes32(uint256(keccak256("eip1967.hypernative.admin")) - 1)

HYPERNATIVE_MODE_STORAGE_SLOT

Storage slot for the firewall strict mode

bytes32 private constant HYPERNATIVE_MODE_STORAGE_SLOT =
    bytes32(uint256(keccak256("eip1967.hypernative.is_strict_mode")) - 1)

Functions

onlyFirewallApproved

Modifier to restrict access to only approved firewall addresses

modifier onlyFirewallApproved() ;

onlyFirewallApprovedAllowEOA

Modifier to restrict access to only approved firewall addresses and EOAs

modifier onlyFirewallApprovedAllowEOA() ;

onlyNotBlacklistedEOA

Modifier to restrict access to only not blacklisted EOAs

modifier onlyNotBlacklistedEOA() ;

onlyFirewallAdmin

Modifier to restrict access to only the firewall admin

modifier onlyFirewallAdmin() ;

firewallRegister

Function to register an account with the firewall

function firewallRegister(address _account) public virtual;

Parameters

NameTypeDescription
_accountaddressThe account to register

setFirewall

Function to set the firewall

Admin only function, sets new firewall admin. set to address(0) to revoke firewall

function setFirewall(address _firewall) public onlyFirewallAdmin;

Parameters

NameTypeDescription
_firewalladdressThe new firewall address

setIsStrictMode

Function to set the strict mode

function setIsStrictMode(bool _mode) public onlyFirewallAdmin;

Parameters

NameTypeDescription
_modeboolThe strict mode

changeFirewallAdmin

Function to change the firewall admin

function changeFirewallAdmin(address _newAdmin) public onlyFirewallAdmin;

Parameters

NameTypeDescription
_newAdminaddressThe new firewall admin address

hypernativeFirewallAdmin

Function to get the firewall admin

function hypernativeFirewallAdmin() public view returns (address);

Returns

NameTypeDescription
<none>addressThe firewall admin address

_initHypernativeFirewall

Internal function to initialize the firewall

function _initHypernativeFirewall(address _firewall, address _admin) internal;

Parameters

NameTypeDescription
_firewalladdressThe firewall address
_adminaddressThe firewall admin address

_changeFirewallAdmin

Internal function to change the firewall admin

function _changeFirewallAdmin(address _newAdmin) internal;

Parameters

NameTypeDescription
_newAdminaddressThe new firewall admin address

_setAddressBySlot

Internal function to set the address in the slot

function _setAddressBySlot(bytes32 slot, address newAddress) internal;

Parameters

NameTypeDescription
slotbytes32The slot to set the address in
newAddressaddressThe address to set in the slot

_setValueBySlot

Internal function to set the value in the slot

function _setValueBySlot(bytes32 _slot, uint256 _value) internal;

Parameters

NameTypeDescription
_slotbytes32The slot to set the value in
_valueuint256The value to set in the slot

_getAddressBySlot

Internal function to get the address from the slot

function _getAddressBySlot(bytes32 slot) internal view returns (address addr);

Parameters

NameTypeDescription
slotbytes32The slot to get the address from

Returns

NameTypeDescription
addraddressThe address from the slot

_getValueBySlot

Internal function to get the value from the slot

function _getValueBySlot(bytes32 _slot) internal view returns (uint256 value);

Parameters

NameTypeDescription
_slotbytes32The slot to get the value from

Returns

NameTypeDescription
valueuint256The value from the slot

_hypernativeFirewallIsStrictMode

Internal function to get the strict mode

function _hypernativeFirewallIsStrictMode() private view returns (bool);

Returns

NameTypeDescription
<none>boolThe strict mode

_hypernativeFirewall

Internal function to get the firewall address

function _hypernativeFirewall() private view returns (address);

Returns

NameTypeDescription
<none>addressThe firewall address

Events

FirewallAdminChanged

Emitted when the firewall admin is changed

event FirewallAdminChanged(address indexed previousAdmin, address indexed newAdmin);

Parameters

NameTypeDescription
previousAdminaddressThe previous firewall admin address
newAdminaddressThe new firewall admin address

FirewallAddressChanged

Emitted when the firewall address is changed

event FirewallAddressChanged(address indexed previousFirewall, address indexed newFirewall);

Parameters

NameTypeDescription
previousFirewalladdressThe previous firewall address
newFirewalladdressThe new firewall address

Errors

HypernativeFirewallProtected_CallerNotEOA

Thrown when the caller is not an EOA

error HypernativeFirewallProtected_CallerNotEOA();

HypernativeFirewallProtected_CallerNotFirewallAdmin

Thrown when the caller is not the firewall admin

error HypernativeFirewallProtected_CallerNotFirewallAdmin();

HypernativeFirewallProtected_AddressNotValid

Thrown when the address is not valid

error HypernativeFirewallProtected_AddressNotValid();