Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions contracts/contracts/HederaTokenManagerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {IHederaTokenManager, RolesStruct} from './Interfaces/IHederaTokenManager
import {_HEDERA_TOKEN_MANAGER_RESOLVER_KEY} from './constants/resolverKeys.sol';
import {SupplierAdminStorageWrapper} from './extensions/SupplierAdminStorageWrapper.sol';
import {ReserveStorageWrapper} from './extensions/ReserveStorageWrapper.sol';
import {IRoles} from './extensions/Interfaces/IRoles.sol';
// solhint-disable-next-line max-line-length
import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol';
import {KeysLib} from './library/KeysLib.sol';
// solhint-disable-next-line max-line-length
import {IERC20MetadataUpgradeable} from '@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol';
import {HederaTokenManagerStorageWrapper} from './HederaTokenManagerStorageWrapper.sol';
import {IStaticFunctionSelectors} from './resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {ADMIN_ROLE} from './constants/roles.sol';

contract HederaTokenManagerFacet is
IStaticFunctionSelectors,
Expand Down Expand Up @@ -129,12 +129,7 @@ contract HederaTokenManagerFacet is
*/
function updateToken(
UpdateTokenStruct calldata updatedToken
)
external
override(IHederaTokenManager)
lessThan100(updatedToken.tokenMetadataURI)
onlyRole(_getRoleId(IRoles.RoleName.ADMIN))
{
) external override(IHederaTokenManager) lessThan100(updatedToken.tokenMetadataURI) onlyRole(ADMIN_ROLE) {
_setMetadata(updatedToken.tokenMetadataURI);

address currentTokenAddress = _getTokenAddress();
Expand Down Expand Up @@ -207,7 +202,7 @@ contract HederaTokenManagerFacet is
}

// granting admin role, always to the SC creator
_grantRole(_getRoleId(IRoles.RoleName.ADMIN), originalSender);
_grantRole(ADMIN_ROLE, originalSender);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/extensions/BurnableFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pragma solidity 0.8.18;
// solhint-disable-next-line max-line-length
import {HoldManagementStorageWrapper} from './HoldManagementStorageWrapper.sol';
import {IBurnable} from './Interfaces/IBurnable.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {SafeCast} from '@openzeppelin/contracts/utils/math/SafeCast.sol';
import {_BURNABLE_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {RolesStorageWrapper} from './RolesStorageWrapper.sol';
import {TokenOwnerStorageWrapper} from './TokenOwnerStorageWrapper.sol';
import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_BURN_ROLE} from '../constants/roles.sol';

contract BurnableFacet is
IBurnable,
Expand All @@ -37,7 +37,7 @@ contract BurnableFacet is
)
external
override(IBurnable)
onlyRole(_getRoleId(IRoles.RoleName.BURN))
onlyRole(_BURN_ROLE)
amountIsNotNegative(amount, false)
checkBurnAmount(amount)
returns (bool)
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/extensions/CashInFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
pragma solidity 0.8.18;

import {ICashIn} from './Interfaces/ICashIn.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {SupplierAdminStorageWrapper} from './SupplierAdminStorageWrapper.sol';
// solhint-disable-next-line max-line-length
import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol';
import {ReserveStorageWrapper} from './ReserveStorageWrapper.sol';
import {SafeCast} from '@openzeppelin/contracts/utils/math/SafeCast.sol';
import {_CASH_IN_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_CASHIN_ROLE} from '../constants/roles.sol';

contract CashInFacet is ICashIn, IStaticFunctionSelectors, SupplierAdminStorageWrapper, ReserveStorageWrapper {
/**
Expand All @@ -25,7 +25,7 @@ contract CashInFacet is ICashIn, IStaticFunctionSelectors, SupplierAdminStorageW
)
external
override(ICashIn)
onlyRole(_getRoleId(IRoles.RoleName.CASHIN))
onlyRole(_CASHIN_ROLE)
checkReserveIncrease(SafeCast.toUint256(amount))
addressIsNotZero(account)
amountIsNotNegative(amount, false)
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/extensions/CustomFeesFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {RolesStorageWrapper} from './RolesStorageWrapper.sol';
// solhint-disable-next-line max-line-length
import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol';
import {_CUSTOM_FEES_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_CUSTOM_FEES_ROLE} from '../constants/roles.sol';

contract CustomFeesFacet is ICustomFees, IStaticFunctionSelectors, TokenOwnerStorageWrapper, RolesStorageWrapper {
/**
Expand All @@ -20,7 +20,7 @@ contract CustomFeesFacet is ICustomFees, IStaticFunctionSelectors, TokenOwnerSto
function updateTokenCustomFees(
IHederaTokenService.FixedFee[] calldata fixedFees,
IHederaTokenService.FractionalFee[] calldata fractionalFees
) external override(ICustomFees) onlyRole(_getRoleId(IRoles.RoleName.CUSTOM_FEES)) returns (bool) {
) external override(ICustomFees) onlyRole(_CUSTOM_FEES_ROLE) returns (bool) {
address currentTokenAddress = _getTokenAddress();

int64 responseCode = IHederaTokenService(_PRECOMPILED_ADDRESS).updateFungibleTokenCustomFees(
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/extensions/DeletableFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {RolesStorageWrapper} from './RolesStorageWrapper.sol';
import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol';
import {IDeletable} from './Interfaces/IDeletable.sol';
import {_DELETABLE_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_DELETE_ROLE} from '../constants/roles.sol';

contract DeletableFacet is IDeletable, IStaticFunctionSelectors, TokenOwnerStorageWrapper, RolesStorageWrapper {
/**
* @dev Deletes the token
*
*/
function deleteToken() external override(IDeletable) onlyRole(_getRoleId(IRoles.RoleName.DELETE)) returns (bool) {
function deleteToken() external override(IDeletable) onlyRole(_DELETE_ROLE) returns (bool) {
address currentTokenAddress = _getTokenAddress();

int64 responseCode = IHederaTokenService(_PRECOMPILED_ADDRESS).deleteToken(currentTokenAddress);
Expand Down
18 changes: 3 additions & 15 deletions contracts/contracts/extensions/FreezableFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {RolesStorageWrapper} from './RolesStorageWrapper.sol';
import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol';
import {IFreezable} from './Interfaces/IFreezable.sol';
import {_FREEZABLE_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_FREEZE_ROLE} from '../constants/roles.sol';

contract FreezableFacet is IFreezable, IStaticFunctionSelectors, TokenOwnerStorageWrapper, RolesStorageWrapper {
/**
Expand All @@ -18,13 +18,7 @@ contract FreezableFacet is IFreezable, IStaticFunctionSelectors, TokenOwnerStora
*/
function freeze(
address account
)
external
override(IFreezable)
onlyRole(_getRoleId(IRoles.RoleName.FREEZE))
addressIsNotZero(account)
returns (bool)
{
) external override(IFreezable) onlyRole(_FREEZE_ROLE) addressIsNotZero(account) returns (bool) {
address currentTokenAddress = _getTokenAddress();

int64 responseCode = IHederaTokenService(_PRECOMPILED_ADDRESS).freezeToken(currentTokenAddress, account);
Expand All @@ -43,13 +37,7 @@ contract FreezableFacet is IFreezable, IStaticFunctionSelectors, TokenOwnerStora
*/
function unfreeze(
address account
)
external
override(IFreezable)
onlyRole(_getRoleId(IRoles.RoleName.FREEZE))
addressIsNotZero(account)
returns (bool)
{
) external override(IFreezable) onlyRole(_FREEZE_ROLE) addressIsNotZero(account) returns (bool) {
address currentTokenAddress = _getTokenAddress();

int64 responseCode = IHederaTokenService(_PRECOMPILED_ADDRESS).unfreezeToken(currentTokenAddress, account);
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/extensions/HoldManagementFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {RolesStorageWrapper} from './RolesStorageWrapper.sol';
import {TokenOwnerStorageWrapper} from './TokenOwnerStorageWrapper.sol';
import {HoldManagementStorageWrapper} from './HoldManagementStorageWrapper.sol';
import {_HOLD_MANAGEMENT_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_HOLD_CREATOR_ROLE} from '../constants/roles.sol';

// solhint-enable max-line-length

Expand Down Expand Up @@ -156,7 +156,7 @@ contract HoldManagementFacet is
validExpiration(_hold.expirationTimestamp)
addressIsNotZero(_hold.escrow)
addressIsNotZero(_from)
onlyRole(_getRoleId(IRoles.RoleName.HOLD_CREATOR))
onlyRole(_HOLD_CREATOR_ROLE)
amountIsNotNegative(_hold.amount, false)
returns (bool success_, uint256 holdId_)
{
Expand Down
32 changes: 9 additions & 23 deletions contracts/contracts/extensions/Interfaces/IRoles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
pragma solidity 0.8.18;

interface IRoles {
enum RoleName {
ADMIN,
CASHIN,
BURN,
WIPE,
RESCUE,
PAUSE,
FREEZE,
DELETE,
KYC,
CUSTOM_FEES,
HOLD_CREATOR,
DEFAULT_ADMIN_ROLE
}

/**
* @dev Emitted when the provided account is not granted the role
*
Expand All @@ -27,18 +12,19 @@ interface IRoles {
error AccountHasNoRole(address account, bytes32 role);

/**
* @dev Returns an array of roles the account currently has
* @dev Emitted when trying to remove a role from the role list passing an out of bound position
*
* @param length The roles list length
* @param position The 0 based index we are trying to access in the role list
*
* @param account The account address
* @return bytes32[] The array containing the roles
*/
function getRoles(address account) external view returns (bytes32[] memory);
error RolePositionOutOfBounds(uint256 length, uint256 position);

/**
* @dev Returns a role bytes32 representation
* @dev Returns an array of roles the account currently has
*
* @param role The role we want to retrieve the bytes32 for
* @return bytes32 The bytes32 of the role
* @param account The account address
* @return bytes32[] The array containing the roles
*/
function getRoleId(RoleName role) external view returns (bytes32);
function getRoles(address account) external view returns (bytes32[] memory);
}
8 changes: 3 additions & 5 deletions contracts/contracts/extensions/KYCFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {RolesStorageWrapper} from './RolesStorageWrapper.sol';
import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol';
import {IKYC} from './Interfaces/IKYC.sol';
import {_KYC_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_KYC_ROLE} from '../constants/roles.sol';

contract KYCFacet is IKYC, IStaticFunctionSelectors, TokenOwnerStorageWrapper, RolesStorageWrapper {
/**
Expand All @@ -18,7 +18,7 @@ contract KYCFacet is IKYC, IStaticFunctionSelectors, TokenOwnerStorageWrapper, R
*/
function grantKyc(
address account
) external override(IKYC) onlyRole(_getRoleId(IRoles.RoleName.KYC)) addressIsNotZero(account) returns (bool) {
) external override(IKYC) onlyRole(_KYC_ROLE) addressIsNotZero(account) returns (bool) {
address currentTokenAddress = _getTokenAddress();

int64 responseCode = IHederaTokenService(_PRECOMPILED_ADDRESS).grantTokenKyc(currentTokenAddress, account);
Expand All @@ -35,9 +35,7 @@ contract KYCFacet is IKYC, IStaticFunctionSelectors, TokenOwnerStorageWrapper, R
*
* @param account The account to which the KYC will be revoked
*/
function revokeKyc(
address account
) external onlyRole(_getRoleId(IRoles.RoleName.KYC)) addressIsNotZero(account) returns (bool) {
function revokeKyc(address account) external onlyRole(_KYC_ROLE) addressIsNotZero(account) returns (bool) {
address currentTokenAddress = _getTokenAddress();

int64 responseCode = IHederaTokenService(_PRECOMPILED_ADDRESS).revokeTokenKyc(currentTokenAddress, account);
Expand Down
6 changes: 3 additions & 3 deletions contracts/contracts/extensions/PausableFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {IPausable} from './Interfaces/IPausable.sol';
// solhint-disable-next-line max-line-length
import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol';
import {_PAUSABLE_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_PAUSE_ROLE} from '../constants/roles.sol';

contract PausableFacet is IPausable, IStaticFunctionSelectors, TokenOwnerStorageWrapper, RolesStorageWrapper {
/**
* @dev Pauses the token in order to prevent it from being involved in any kind of operation
*
*/
function pause() external override(IPausable) onlyRole(_getRoleId(IRoles.RoleName.PAUSE)) returns (bool) {
function pause() external override(IPausable) onlyRole(_PAUSE_ROLE) returns (bool) {
address currentTokenAddress = _getTokenAddress();

int64 responseCode = IHederaTokenService(_PRECOMPILED_ADDRESS).pauseToken(currentTokenAddress);
Expand All @@ -31,7 +31,7 @@ contract PausableFacet is IPausable, IStaticFunctionSelectors, TokenOwnerStorage
* @dev Unpauses the token in order to allow it to be involved in any kind of operation
*
*/
function unpause() external override(IPausable) onlyRole(_getRoleId(IRoles.RoleName.PAUSE)) returns (bool) {
function unpause() external override(IPausable) onlyRole(_PAUSE_ROLE) returns (bool) {
address currentTokenAddress = _getTokenAddress();

int64 responseCode = IHederaTokenService(_PRECOMPILED_ADDRESS).unpauseToken(currentTokenAddress);
Expand Down
6 changes: 3 additions & 3 deletions contracts/contracts/extensions/RescuableFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {IHederaTokenService} from '@hashgraph/smart-contracts/contracts/system-c
import {ReentrancyGuard} from '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import {SafeCast} from '@openzeppelin/contracts/utils/math/SafeCast.sol';
import {_RESCUABLE_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {_RESCUE_ROLE} from '../constants/roles.sol';

contract RescuableFacet is
ReentrancyGuard,
Expand All @@ -31,7 +31,7 @@ contract RescuableFacet is
)
external
override(IRescuable)
onlyRole(_getRoleId(IRoles.RoleName.RESCUE))
onlyRole(_RESCUE_ROLE)
amountIsNotNegative(amount, false)
valueIsNotGreaterThan(SafeCast.toUint256(amount), _balanceOf(address(this)), true)
returns (bool)
Expand Down Expand Up @@ -64,7 +64,7 @@ contract RescuableFacet is
)
external
override(IRescuable)
onlyRole(_getRoleId(IRoles.RoleName.RESCUE))
onlyRole(_RESCUE_ROLE)
valueIsNotGreaterThan(amount, address(this).balance, true)
nonReentrant
returns (bool)
Expand Down
6 changes: 2 additions & 4 deletions contracts/contracts/extensions/ReserveFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity 0.8.18;

import {IReserve} from './Interfaces/IReserve.sol';
import {IRoles} from './Interfaces/IRoles.sol';
import {ReserveStorageWrapper} from './ReserveStorageWrapper.sol';
import {_RESERVE_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {ADMIN_ROLE} from '../constants/roles.sol';

contract ReserveFacet is IReserve, IStaticFunctionSelectors, ReserveStorageWrapper {
/**
Expand All @@ -21,9 +21,7 @@ contract ReserveFacet is IReserve, IStaticFunctionSelectors, ReserveStorageWrapp
*
* @param newAddress The new reserve address. Can be set to 0.0.0 (zero address) to disable the reserve.
*/
function updateReserveAddress(
address newAddress
) external override(IReserve) onlyRole(_getRoleId(IRoles.RoleName.ADMIN)) {
function updateReserveAddress(address newAddress) external override(IReserve) onlyRole(ADMIN_ROLE) {
address previous = _reserveStorage().reserveAddress;
_reserveStorage().reserveAddress = newAddress;
emit ReserveAddressChanged(previous, newAddress);
Expand Down
14 changes: 5 additions & 9 deletions contracts/contracts/extensions/RoleManagementFacet.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

import {IRoles} from './Interfaces/IRoles.sol';
import {IRoleManagement} from './Interfaces/IRoleManagement.sol';
import {SupplierAdminStorageWrapper} from './SupplierAdminStorageWrapper.sol';
import {_ROLE_MANAGEMENT_RESOLVER_KEY} from '../constants/resolverKeys.sol';
import {IStaticFunctionSelectors} from '../resolver/interfaces/resolverProxy/IStaticFunctionSelectors.sol';
import {ADMIN_ROLE, _CASHIN_ROLE} from '../constants/roles.sol';

contract RoleManagementFacet is IRoleManagement, IStaticFunctionSelectors, SupplierAdminStorageWrapper {
/**
Expand All @@ -19,11 +19,9 @@ contract RoleManagementFacet is IRoleManagement, IStaticFunctionSelectors, Suppl
bytes32[] calldata roles,
address[] calldata accounts,
uint256[] calldata amounts
) external override(IRoleManagement) onlyRole(_getRoleId(IRoles.RoleName.ADMIN)) addressesAreNotZero(accounts) {
bytes32 cashInRole = _getRoleId(IRoles.RoleName.CASHIN);

) external override(IRoleManagement) onlyRole(ADMIN_ROLE) addressesAreNotZero(accounts) {
for (uint256 i = 0; i < roles.length; i++) {
if (roles[i] == cashInRole) {
if (roles[i] == _CASHIN_ROLE) {
if (accounts.length != amounts.length) revert ArraysLengthNotEqual(accounts.length, amounts.length);
for (uint256 j = 0; j < accounts.length; j++) {
if (amounts[j] != 0) _grantSupplierRole(accounts[j], amounts[j]);
Expand All @@ -46,11 +44,9 @@ contract RoleManagementFacet is IRoleManagement, IStaticFunctionSelectors, Suppl
function revokeRoles(
bytes32[] calldata roles,
address[] calldata accounts
) external override(IRoleManagement) onlyRole(_getRoleId(IRoles.RoleName.ADMIN)) {
bytes32 cashInRole = _getRoleId(IRoles.RoleName.CASHIN);

) external override(IRoleManagement) onlyRole(ADMIN_ROLE) {
for (uint256 i = 0; i < roles.length; i++) {
if (roles[i] == cashInRole) {
if (roles[i] == _CASHIN_ROLE) {
for (uint256 j = 0; j < accounts.length; j++) {
_revokeSupplierRole(accounts[j]);
}
Expand Down
Loading
Loading