// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;/**
* @notice Emitted when the account is not a contract
* @param account The account address
*/errorNonContractAddressError(address account);
/**
* @notice Function to check if the account is a contract
* @return The account contract status flag
*/functionisContract(address _account) viewreturns (bool) {
return _account.code.length>0;
}
/**
* @notice Function to require an account to be a contract
*/functionrequireContract(address _account) view{
if (!isContract(_account)) {
revert NonContractAddressError(_account);
}
}
/**
* @notice Function to require an account to be a contract or a zero address
*/functionrequireContractOrZeroAddress(address _account) view{
if (_account !=address(0)) {
requireContract(_account);
}
}
Contract Source Code
File 2 of 17: BalanceManagement.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;import { ITokenBalance } from'./interfaces/ITokenBalance.sol';
import { ManagerRole } from'./roles/ManagerRole.sol';
import'./helpers/TransferHelper.sol'asTransferHelper;
import'./Constants.sol'asConstants;
/**
* @title BalanceManagement
* @notice Base contract for the withdrawal of tokens, except for reserved ones
*/abstractcontractBalanceManagementisManagerRole{
/**
* @notice Emitted when the specified token is reserved
*/errorReservedTokenError();
/**
* @notice Performs the withdrawal of tokens, except for reserved ones
* @dev Use the "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" address for the native token
* @param _tokenAddress The address of the token
* @param _tokenAmount The amount of the token
*/functioncleanup(address _tokenAddress, uint256 _tokenAmount) externalonlyManager{
if (isReservedToken(_tokenAddress)) {
revert ReservedTokenError();
}
if (_tokenAddress == Constants.NATIVE_TOKEN_ADDRESS) {
TransferHelper.safeTransferNative(msg.sender, _tokenAmount);
} else {
TransferHelper.safeTransfer(_tokenAddress, msg.sender, _tokenAmount);
}
}
/**
* @notice Getter of the token balance of the current contract
* @dev Use the "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" address for the native token
* @param _tokenAddress The address of the token
* @return The token balance of the current contract
*/functiontokenBalance(address _tokenAddress) publicviewreturns (uint256) {
if (_tokenAddress == Constants.NATIVE_TOKEN_ADDRESS) {
returnaddress(this).balance;
} else {
return ITokenBalance(_tokenAddress).balanceOf(address(this));
}
}
/**
* @notice Getter of the reserved token flag
* @dev Override to add reserved token addresses
* @param _tokenAddress The address of the token
* @return The reserved token flag
*/functionisReservedToken(address _tokenAddress) publicviewvirtualreturns (bool) {
// The function returns false by default.// The explicit return statement is omitted to avoid the unused parameter warning.// See https://github.com/ethereum/solidity/issues/5295
}
}
Contract Source Code
File 3 of 17: CallerGuard.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;import { ManagerRole } from'./roles/ManagerRole.sol';
import'./helpers/AddressHelper.sol'asAddressHelper;
import'./Constants.sol'asConstants;
import'./DataStructures.sol'asDataStructures;
/**
* @title CallerGuard
* @notice Base contract to control access from other contracts
*/abstractcontractCallerGuardisManagerRole{
/**
* @dev Caller guard mode enumeration
*/enumCallerGuardMode {
ContractForbidden,
ContractList,
ContractAllowed
}
/**
* @dev Caller guard mode value
*/
CallerGuardMode public callerGuardMode = CallerGuardMode.ContractForbidden;
/**
* @dev Registered contract list for "ContractList" mode
*/address[] public listedCallerGuardContractList;
/**
* @dev Registered contract list indices for "ContractList" mode
*/mapping(address/*account*/=> DataStructures.OptionalValue /*index*/)
public listedCallerGuardContractIndexMap;
/**
* @notice Emitted when the caller guard mode is set
* @param callerGuardMode The caller guard mode
*/eventSetCallerGuardMode(CallerGuardMode indexed callerGuardMode);
/**
* @notice Emitted when a registered contract for "ContractList" mode is added or removed
* @param contractAddress The contract address
* @param isListed The registered contract list inclusion flag
*/eventSetListedCallerGuardContract(addressindexed contractAddress, boolindexed isListed);
/**
* @notice Emitted when the caller is not allowed to perform the intended action
*/errorCallerGuardError(address caller);
/**
* @dev Modifier to check if the caller is allowed to perform the intended action
*/modifiercheckCaller() {
if (msg.sender!=tx.origin) {
bool condition = (callerGuardMode == CallerGuardMode.ContractAllowed ||
(callerGuardMode == CallerGuardMode.ContractList &&
isListedCallerGuardContract(msg.sender)));
if (!condition) {
revert CallerGuardError(msg.sender);
}
}
_;
}
/**
* @notice Sets the caller guard mode
* @param _callerGuardMode The caller guard mode
*/functionsetCallerGuardMode(CallerGuardMode _callerGuardMode) externalonlyManager{
callerGuardMode = _callerGuardMode;
emit SetCallerGuardMode(_callerGuardMode);
}
/**
* @notice Updates the list of registered contracts for the "ContractList" mode
* @param _items The addresses and flags for the contracts
*/functionsetListedCallerGuardContracts(
DataStructures.AccountToFlag[] calldata _items
) externalonlyManager{
for (uint256 index; index < _items.length; index++) {
DataStructures.AccountToFlag calldata item = _items[index];
if (item.flag) {
AddressHelper.requireContract(item.account);
}
DataStructures.uniqueAddressListUpdate(
listedCallerGuardContractList,
listedCallerGuardContractIndexMap,
item.account,
item.flag,
Constants.LIST_SIZE_LIMIT_DEFAULT
);
emit SetListedCallerGuardContract(item.account, item.flag);
}
}
/**
* @notice Getter of the registered contract count
* @return The registered contract count
*/functionlistedCallerGuardContractCount() externalviewreturns (uint256) {
return listedCallerGuardContractList.length;
}
/**
* @notice Getter of the complete list of registered contracts
* @return The complete list of registered contracts
*/functionfullListedCallerGuardContractList() externalviewreturns (address[] memory) {
return listedCallerGuardContractList;
}
/**
* @notice Getter of a listed contract flag
* @param _account The contract address
* @return The listed contract flag
*/functionisListedCallerGuardContract(address _account) publicviewreturns (bool) {
return listedCallerGuardContractIndexMap[_account].isSet;
}
}
Contract Source Code
File 4 of 17: Constants.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;/**
* @dev The default token decimals value
*/uint256constant DECIMALS_DEFAULT =18;
/**
* @dev The maximum uint256 value for swap amount limit settings
*/uint256constant INFINITY =type(uint256).max;
/**
* @dev The default limit of account list size
*/uint256constant LIST_SIZE_LIMIT_DEFAULT =100;
/**
* @dev The limit of swap router list size
*/uint256constant LIST_SIZE_LIMIT_ROUTERS =200;
/**
* @dev The factor for percentage settings. Example: 100 is 0.1%
*/uint256constant MILLIPERCENT_FACTOR =100_000;
/**
* @dev The de facto standard address to denote the native token
*/addressconstant NATIVE_TOKEN_ADDRESS =0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
Contract Source Code
File 5 of 17: Context.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)pragmasolidity ^0.8.0;/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Contract Source Code
File 6 of 17: DataStructures.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;/**
* @notice Optional value structure
* @dev Is used in mappings to allow zero values
* @param isSet Value presence flag
* @param value Numeric value
*/structOptionalValue {
bool isSet;
uint256 value;
}
/**
* @notice Key-to-value structure
* @dev Is used as an array parameter item to perform multiple key-value settings
* @param key Numeric key
* @param value Numeric value
*/structKeyToValue {
uint256 key;
uint256 value;
}
/**
* @notice Key-to-value structure for address values
* @dev Is used as an array parameter item to perform multiple key-value settings with address values
* @param key Numeric key
* @param value Address value
*/structKeyToAddressValue {
uint256 key;
address value;
}
/**
* @notice Address-to-flag structure
* @dev Is used as an array parameter item to perform multiple settings
* @param account Account address
* @param flag Flag value
*/structAccountToFlag {
address account;
bool flag;
}
/**
* @notice Emitted when a list exceeds the size limit
*/errorListSizeLimitError();
/**
* @notice Sets or updates a value in a combined map (a mapping with a key list and key index mapping)
* @param _map The mapping reference
* @param _keyList The key list reference
* @param _keyIndexMap The key list index mapping reference
* @param _key The numeric key
* @param _value The address value
* @param _sizeLimit The map and list size limit
* @return isNewKey True if the key was just added, otherwise false
*/functioncombinedMapSet(mapping(uint256 => address) storage _map,
uint256[] storage _keyList,
mapping(uint256 => OptionalValue) storage _keyIndexMap,
uint256 _key,
address _value,
uint256 _sizeLimit
) returns (bool isNewKey) {
isNewKey =!_keyIndexMap[_key].isSet;
if (isNewKey) {
uniqueListAdd(_keyList, _keyIndexMap, _key, _sizeLimit);
}
_map[_key] = _value;
}
/**
* @notice Removes a value from a combined map (a mapping with a key list and key index mapping)
* @param _map The mapping reference
* @param _keyList The key list reference
* @param _keyIndexMap The key list index mapping reference
* @param _key The numeric key
* @return isChanged True if the combined map was changed, otherwise false
*/functioncombinedMapRemove(mapping(uint256 => address) storage _map,
uint256[] storage _keyList,
mapping(uint256 => OptionalValue) storage _keyIndexMap,
uint256 _key
) returns (bool isChanged) {
isChanged = _keyIndexMap[_key].isSet;
if (isChanged) {
delete _map[_key];
uniqueListRemove(_keyList, _keyIndexMap, _key);
}
}
/**
* @notice Adds a value to a unique value list (a list with value index mapping)
* @param _list The list reference
* @param _indexMap The value index mapping reference
* @param _value The numeric value
* @param _sizeLimit The list size limit
* @return isChanged True if the list was changed, otherwise false
*/functionuniqueListAdd(uint256[] storage _list,
mapping(uint256 => OptionalValue) storage _indexMap,
uint256 _value,
uint256 _sizeLimit
) returns (bool isChanged) {
isChanged =!_indexMap[_value].isSet;
if (isChanged) {
if (_list.length>= _sizeLimit) {
revert ListSizeLimitError();
}
_indexMap[_value] = OptionalValue(true, _list.length);
_list.push(_value);
}
}
/**
* @notice Removes a value from a unique value list (a list with value index mapping)
* @param _list The list reference
* @param _indexMap The value index mapping reference
* @param _value The numeric value
* @return isChanged True if the list was changed, otherwise false
*/functionuniqueListRemove(uint256[] storage _list,
mapping(uint256 => OptionalValue) storage _indexMap,
uint256 _value
) returns (bool isChanged) {
OptionalValue storage indexItem = _indexMap[_value];
isChanged = indexItem.isSet;
if (isChanged) {
uint256 itemIndex = indexItem.value;
uint256 lastIndex = _list.length-1;
if (itemIndex != lastIndex) {
uint256 lastValue = _list[lastIndex];
_list[itemIndex] = lastValue;
_indexMap[lastValue].value= itemIndex;
}
_list.pop();
delete _indexMap[_value];
}
}
/**
* @notice Adds a value to a unique address value list (a list with value index mapping)
* @param _list The list reference
* @param _indexMap The value index mapping reference
* @param _value The address value
* @param _sizeLimit The list size limit
* @return isChanged True if the list was changed, otherwise false
*/functionuniqueAddressListAdd(address[] storage _list,
mapping(address => OptionalValue) storage _indexMap,
address _value,
uint256 _sizeLimit
) returns (bool isChanged) {
isChanged =!_indexMap[_value].isSet;
if (isChanged) {
if (_list.length>= _sizeLimit) {
revert ListSizeLimitError();
}
_indexMap[_value] = OptionalValue(true, _list.length);
_list.push(_value);
}
}
/**
* @notice Removes a value from a unique address value list (a list with value index mapping)
* @param _list The list reference
* @param _indexMap The value index mapping reference
* @param _value The address value
* @return isChanged True if the list was changed, otherwise false
*/functionuniqueAddressListRemove(address[] storage _list,
mapping(address => OptionalValue) storage _indexMap,
address _value
) returns (bool isChanged) {
OptionalValue storage indexItem = _indexMap[_value];
isChanged = indexItem.isSet;
if (isChanged) {
uint256 itemIndex = indexItem.value;
uint256 lastIndex = _list.length-1;
if (itemIndex != lastIndex) {
address lastValue = _list[lastIndex];
_list[itemIndex] = lastValue;
_indexMap[lastValue].value= itemIndex;
}
_list.pop();
delete _indexMap[_value];
}
}
/**
* @notice Adds or removes a value to/from a unique address value list (a list with value index mapping)
* @dev The list size limit is checked on items adding only
* @param _list The list reference
* @param _indexMap The value index mapping reference
* @param _value The address value
* @param _flag The value inclusion flag
* @param _sizeLimit The list size limit
* @return isChanged True if the list was changed, otherwise false
*/functionuniqueAddressListUpdate(address[] storage _list,
mapping(address => OptionalValue) storage _indexMap,
address _value,
bool _flag,
uint256 _sizeLimit
) returns (bool isChanged) {
return
_flag
? uniqueAddressListAdd(_list, _indexMap, _value, _sizeLimit)
: uniqueAddressListRemove(_list, _indexMap, _value);
}
Contract Source Code
File 7 of 17: Errors.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;/**
* @notice Emitted when an attempt to burn a token fails
*/errorTokenBurnError();
/**
* @notice Emitted when an attempt to mint a token fails
*/errorTokenMintError();
/**
* @notice Emitted when a zero address is specified where it is not allowed
*/errorZeroAddressError();
Contract Source Code
File 8 of 17: IActionDataStructures.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;/**
* @title IActionDataStructures
* @notice Action data structure declarations
*/interfaceIActionDataStructures{
/**
* @notice Single-chain action data structure
* @param fromTokenAddress The address of the input token
* @param toTokenAddress The address of the output token
* @param swapInfo The data for the single-chain swap
* @param recipient The address of the recipient
*/structLocalAction {
address fromTokenAddress;
address toTokenAddress;
SwapInfo swapInfo;
address recipient;
}
/**
* @notice Cross-chain action data structure
* @param gatewayType The numeric type of the cross-chain gateway
* @param vaultType The numeric type of the vault
* @param sourceTokenAddress The address of the input token on the source chain
* @param sourceSwapInfo The data for the source chain swap
* @param targetChainId The action target chain ID
* @param targetTokenAddress The address of the output token on the destination chain
* @param targetSwapInfoOptions The list of data options for the target chain swap
* @param targetRecipient The address of the recipient on the target chain
* @param gatewaySettings The gateway-specific settings data
*/structAction {
uint256 gatewayType;
uint256 vaultType;
address sourceTokenAddress;
SwapInfo sourceSwapInfo;
uint256 targetChainId;
address targetTokenAddress;
SwapInfo[] targetSwapInfoOptions;
address targetRecipient;
bytes gatewaySettings;
}
/**
* @notice Token swap data structure
* @param fromAmount The quantity of the token
* @param routerType The numeric type of the swap router
* @param routerData The data for the swap router call
*/structSwapInfo {
uint256 fromAmount;
uint256 routerType;
bytes routerData;
}
/**
* @notice Cross-chain message data structure
* @param actionId The unique identifier of the cross-chain action
* @param sourceSender The address of the sender on the source chain
* @param vaultType The numeric type of the vault
* @param targetTokenAddress The address of the output token on the target chain
* @param targetSwapInfo The data for the target chain swap
* @param targetRecipient The address of the recipient on the target chain
*/structTargetMessage {
uint256 actionId;
address sourceSender;
uint256 vaultType;
address targetTokenAddress;
SwapInfo targetSwapInfo;
address targetRecipient;
}
}
Contract Source Code
File 9 of 17: ITokenBalance.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;/**
* @title ITokenBalance
* @notice Token balance interface
*/interfaceITokenBalance{
/**
* @notice Getter of the token balance by the account
* @param _account The account address
* @return Token balance
*/functionbalanceOf(address _account) externalviewreturns (uint256);
}
Contract Source Code
File 10 of 17: LocalActionProxy.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;import { IActionDataStructures } from'../interfaces/IActionDataStructures.sol';
import { BalanceManagement } from'../BalanceManagement.sol';
import { CallerGuard } from'../CallerGuard.sol';
import { Pausable } from'../Pausable.sol';
import { SystemVersionId } from'../SystemVersionId.sol';
import { ZeroAddressError } from'../Errors.sol';
import'../helpers/AddressHelper.sol'asAddressHelper;
import'../helpers/RefundHelper.sol'asRefundHelper;
import'../helpers/TransferHelper.sol'asTransferHelper;
import'../Constants.sol'asConstants;
/**
* @title LocalActionProxy
* @notice Local action proxy contract
*/contractLocalActionProxyisSystemVersionId,
Pausable,
CallerGuard,
BalanceManagement,
IActionDataStructures{
/**
* @dev The address of the action executor contract
*/
ILocalActionExecutor public actionExecutor;
/**
* @dev The address of the fee collector
*/addresspublic feeCollector;
/**
* @notice Emitted when the action executor contract reference is set
* @param actionExecutor The action executor contract address
*/eventSetActionExecutor(addressindexed actionExecutor);
/**
* @notice Emitted when the address of the fee collector is set
* @param feeCollector The address of the fee collector
*/eventSetFeeCollector(addressindexed feeCollector);
/**
* @notice Emitted when the extra balance is refunded
* @param actionId The ID of the action
* @param sender The address of the user
*/eventLocalActionExecuted(uint256indexed actionId, addressindexed sender);
/**
* @notice Emitted when the extra balance is refunded
* @param to The refund receiver's address
* @param extraBalance The extra balance of the native token
*/eventExtraBalanceRefunded(addressindexed to, uint256 extraBalance);
/**
* @notice Emitted when the native token value of the transaction does not correspond to the swap amount
*/errorNativeTokenValueError();
/**
* @notice Initializes the LocalActionProxy contract
* @param _actionExecutor The address of the action executor contract
* @param _feeCollector The address of the fee collector
* @param _owner The address of the initial owner of the contract
* @param _managers The addresses of initial managers of the contract
* @param _addOwnerToManagers The flag to optionally add the owner to the list of managers
*/constructor(
ILocalActionExecutor _actionExecutor,
address _feeCollector,
address _owner,
address[] memory _managers,
bool _addOwnerToManagers
) {
_setActionExecutor(_actionExecutor);
_setFeeCollector(_feeCollector);
_initRoles(_owner, _managers, _addOwnerToManagers);
}
/**
* @notice The standard "receive" function
* @dev Is payable to allow receiving native token funds from the action executor
*/receive() externalpayable{}
/**
* @notice Executes a single-chain action
* @param _localAction The parameters of the action
* @param _processingFee The processing fee value
*/functionexecuteLocal(
LocalAction memory _localAction,
uint256 _processingFee
) externalpayablewhenNotPausedcheckCaller{
uint256 initialBalance =address(this).balance-msg.value;
address fromTokenAddress = _localAction.fromTokenAddress;
uint256 fromAmount = _localAction.swapInfo.fromAmount;
bool fromNative = fromTokenAddress == Constants.NATIVE_TOKEN_ADDRESS;
uint256 requiredNativeTokenValue = fromNative
? fromAmount + _processingFee
: _processingFee;
if (msg.value< requiredNativeTokenValue) {
revert NativeTokenValueError();
}
if (!fromNative) {
TransferHelper.safeTransferFrom(
fromTokenAddress,
msg.sender,
address(this),
fromAmount
);
TransferHelper.safeApprove(fromTokenAddress, address(actionExecutor), fromAmount);
}
if (_localAction.recipient ==address(0)) {
_localAction.recipient =msg.sender;
}
uint256 actionId = actionExecutor.executeLocal{ value: fromNative ? fromAmount : 0 }(
_localAction
);
emit LocalActionExecuted(actionId, msg.sender);
if (!fromNative) {
TransferHelper.safeApprove(fromTokenAddress, address(actionExecutor), 0);
}
TransferHelper.safeTransferNative(feeCollector, _processingFee);
uint256 extraBalance = RefundHelper.refundExtraBalanceWithResult(
address(this),
initialBalance,
payable(msg.sender)
);
if (extraBalance >0) {
emit ExtraBalanceRefunded(msg.sender, extraBalance);
}
}
/**
* @notice Sets the action executor contract reference
* @param _actionExecutor The action executor contract address
*/functionsetActionExecutor(ILocalActionExecutor _actionExecutor) externalonlyManager{
_setActionExecutor(_actionExecutor);
}
/**
* @notice Sets the address of the fee collector
* @param _feeCollector The address of the fee collector
*/functionsetFeeCollector(address _feeCollector) externalonlyManager{
_setFeeCollector(_feeCollector);
}
function_setActionExecutor(ILocalActionExecutor _actionExecutor) private{
AddressHelper.requireContract(address(_actionExecutor));
actionExecutor = _actionExecutor;
emit SetActionExecutor(address(_actionExecutor));
}
function_setFeeCollector(address _feeCollector) private{
if (_feeCollector ==address(0)) {
revert ZeroAddressError();
}
feeCollector = _feeCollector;
emit SetFeeCollector(_feeCollector);
}
}
interfaceILocalActionExecutorisIActionDataStructures{
functionexecuteLocal(
LocalAction calldata _localAction
) externalpayablereturns (uint256 actionId);
}
Contract Source Code
File 11 of 17: ManagerRole.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;import { Ownable } from'@openzeppelin/contracts/access/Ownable.sol';
import { RoleBearers } from'./RoleBearers.sol';
/**
* @title ManagerRole
* @notice Base contract that implements the Manager role.
* The manager role is a high-permission role for core team members only.
* Managers can set vaults and routers addresses, fees, cross-chain protocols,
* and other parameters for Interchain (cross-chain) swaps and single-network swaps.
* Please note, the manager role is unique for every contract,
* hence different addresses may be assigned as managers for different contracts.
*/abstractcontractManagerRoleisOwnable, RoleBearers{
bytes32privateconstant ROLE_KEY =keccak256('Manager');
/**
* @notice Emitted when the Manager role status for the account is updated
* @param account The account address
* @param value The Manager role status flag
*/eventSetManager(addressindexed account, boolindexed value);
/**
* @notice Emitted when the Manager role status for the account is renounced
* @param account The account address
*/eventRenounceManagerRole(addressindexed account);
/**
* @notice Emitted when the caller is not a Manager role bearer
*/errorOnlyManagerError();
/**
* @dev Modifier to check if the caller is a Manager role bearer
*/modifieronlyManager() {
if (!isManager(msg.sender)) {
revert OnlyManagerError();
}
_;
}
/**
* @notice Updates the Manager role status for the account
* @param _account The account address
* @param _value The Manager role status flag
*/functionsetManager(address _account, bool _value) publiconlyOwner{
_setRoleBearer(ROLE_KEY, _account, _value);
emit SetManager(_account, _value);
}
/**
* @notice Renounces the Manager role
*/functionrenounceManagerRole() externalonlyManager{
_setRoleBearer(ROLE_KEY, msg.sender, false);
emit RenounceManagerRole(msg.sender);
}
/**
* @notice Getter of the Manager role bearer count
* @return The Manager role bearer count
*/functionmanagerCount() externalviewreturns (uint256) {
return _roleBearerCount(ROLE_KEY);
}
/**
* @notice Getter of the complete list of the Manager role bearers
* @return The complete list of the Manager role bearers
*/functionfullManagerList() externalviewreturns (address[] memory) {
return _fullRoleBearerList(ROLE_KEY);
}
/**
* @notice Getter of the Manager role bearer status
* @param _account The account address
*/functionisManager(address _account) publicviewreturns (bool) {
return _isRoleBearer(ROLE_KEY, _account);
}
function_initRoles(address _owner,
address[] memory _managers,
bool _addOwnerToManagers
) internal{
address ownerAddress = _owner ==address(0) ? msg.sender : _owner;
for (uint256 index; index < _managers.length; index++) {
setManager(_managers[index], true);
}
if (_addOwnerToManagers &&!isManager(ownerAddress)) {
setManager(ownerAddress, true);
}
if (ownerAddress !=msg.sender) {
transferOwnership(ownerAddress);
}
}
}
Contract Source Code
File 12 of 17: Ownable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)pragmasolidity ^0.8.0;import"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Contract Source Code
File 13 of 17: Pausable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)pragmasolidity ^0.8.0;import"../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/abstractcontractPausableisContext{
/**
* @dev Emitted when the pause is triggered by `account`.
*/eventPaused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/eventUnpaused(address account);
boolprivate _paused;
/**
* @dev Initializes the contract in unpaused state.
*/constructor() {
_paused =false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/modifierwhenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/modifierwhenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/functionpaused() publicviewvirtualreturns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/function_requireNotPaused() internalviewvirtual{
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/function_requirePaused() internalviewvirtual{
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/function_pause() internalvirtualwhenNotPaused{
_paused =true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/function_unpause() internalvirtualwhenPaused{
_paused =false;
emit Unpaused(_msgSender());
}
}
Contract Source Code
File 14 of 17: RefundHelper.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;import'./TransferHelper.sol'asTransferHelper;
/**
* @notice Refunds the extra balance of the native token
* @dev Reverts on subtraction if the actual balance is less than expected
* @param _self The address of the executing contract
* @param _expectedBalance The expected native token balance value
* @param _to The refund receiver's address
*/functionrefundExtraBalance(address _self, uint256 _expectedBalance, addresspayable _to) {
uint256 extraBalance = _self.balance- _expectedBalance;
if (extraBalance >0) {
TransferHelper.safeTransferNative(_to, extraBalance);
}
}
/**
* @notice Refunds the extra balance of the native token
* @dev Reverts on subtraction if the actual balance is less than expected
* @param _self The address of the executing contract
* @param _expectedBalance The expected native token balance value
* @param _to The refund receiver's address
* @return extraBalance The extra balance of the native token
*/functionrefundExtraBalanceWithResult(address _self,
uint256 _expectedBalance,
addresspayable _to
) returns (uint256 extraBalance) {
extraBalance = _self.balance- _expectedBalance;
if (extraBalance >0) {
TransferHelper.safeTransferNative(_to, extraBalance);
}
}
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;/**
* @title SystemVersionId
* @notice Base contract providing the system version identifier
*/abstractcontractSystemVersionId{
/**
* @dev The system version identifier
*/uint256publicconstant SYSTEM_VERSION_ID =uint256(keccak256('Initial'));
}
Contract Source Code
File 17 of 17: TransferHelper.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity 0.8.19;/**
* @notice Emitted when an approval action fails
*/errorSafeApproveError();
/**
* @notice Emitted when a transfer action fails
*/errorSafeTransferError();
/**
* @notice Emitted when a transferFrom action fails
*/errorSafeTransferFromError();
/**
* @notice Emitted when a transfer of the native token fails
*/errorSafeTransferNativeError();
/**
* @notice Safely approve the token to the account
* @param _token The token address
* @param _to The token approval recipient address
* @param _value The token approval amount
*/functionsafeApprove(address _token, address _to, uint256 _value) {
// 0x095ea7b3 is the selector for "approve(address,uint256)"
(bool success, bytesmemory data) = _token.call(
abi.encodeWithSelector(0x095ea7b3, _to, _value)
);
bool condition = success && (data.length==0||abi.decode(data, (bool)));
if (!condition) {
revert SafeApproveError();
}
}
/**
* @notice Safely transfer the token to the account
* @param _token The token address
* @param _to The token transfer recipient address
* @param _value The token transfer amount
*/functionsafeTransfer(address _token, address _to, uint256 _value) {
// 0xa9059cbb is the selector for "transfer(address,uint256)"
(bool success, bytesmemory data) = _token.call(
abi.encodeWithSelector(0xa9059cbb, _to, _value)
);
bool condition = success && (data.length==0||abi.decode(data, (bool)));
if (!condition) {
revert SafeTransferError();
}
}
/**
* @notice Safely transfer the token between the accounts
* @param _token The token address
* @param _from The token transfer source address
* @param _to The token transfer recipient address
* @param _value The token transfer amount
*/functionsafeTransferFrom(address _token, address _from, address _to, uint256 _value) {
// 0x23b872dd is the selector for "transferFrom(address,address,uint256)"
(bool success, bytesmemory data) = _token.call(
abi.encodeWithSelector(0x23b872dd, _from, _to, _value)
);
bool condition = success && (data.length==0||abi.decode(data, (bool)));
if (!condition) {
revert SafeTransferFromError();
}
}
/**
* @notice Safely transfer the native token to the account
* @param _to The native token transfer recipient address
* @param _value The native token transfer amount
*/functionsafeTransferNative(address _to, uint256 _value) {
(bool success, ) = _to.call{ value: _value }(newbytes(0));
if (!success) {
revert SafeTransferNativeError();
}
}