Verified contractExactMIT
TokenBridge
Address0x2201ec99df36cd50ad928f6f9ec6a3da5541cb36
- Balance
0 ETH
- Transactions
113
- Compiler
solc 0.8.19
- Same code
Only this contract
Details
- Compiler
- solc 0.8.19+commit.7dd6d404
- Language
- solidity
- Optimization
- No
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 17,981,524
- Creation transaction
- 0xd6b4ac8183…b0f8f5935b
project:/contracts/TokenBridge.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// import "../node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol";
// import "../node_modules/@openzeppelin/contracts/access/AccessControlEnumerable.sol";
// import "../node_modules/@openzeppelin/contracts/security/Pausable.sol";
import "../node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol";
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20BurnMint {
/**
* @dev Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `amount`.
*/
function burnFrom(address account, uint256 amount) external;
/**
* @dev Creates `amount` new tokens for `to`.
*
* See {ERC20-_mint}.
*
* Requirements:
*
* - the caller must have the `MINTER_ROLE`.
*/
function mint(address to, uint256 amount) external;
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
}
/**
* @title TokenBridge
* @dev TokenBridge contract is AccessControlEnumerable
**/
// contract TokenBridge is AccessControlEnumerable {
contract TokenBridge is ReentrancyGuard {
// ####################### Roles ############################
// bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
// bytes32 public constant FEE_ROLE = keccak256("FEE_ROLE");
// bytes32 public constant ALLOW_ROLE = keccak256("ALLOW_ROLE");
// bytes32 public constant RELAYER_ROLE = keccak256("RELAYER_ROLE");
// bytes32 public constant MAKER_ROLE = keccak256("MAKER_ROLE");
// ####################### Instantiate Interfaces ############################
// ####################### Helpers ############################
// function getBridgeTokenBalance(address _tokenAddress) public view returns(uint256) {
// return IERC20BurnMint(_tokenAddress).balanceOf(address(this));
// }
// ####################### Enums ############################
// ####################### Constants ############################
uint256 private constant _CREATED = 1;
uint256 private constant _UPDATED = 2;
uint256 private constant _EDITED = 3;
// ####################### Structs ############################
struct TokenBridging{
address tokenAddressFrom;
uint256 fromChain;
address tokenAddressTo;
uint256 toChain;
// uint256 bridgingRelayFee;
bool bridgingAllowed;
}
// struct PendingBridgeFromChain{
// address tokenAddress;
// uint256 amount;
// uint256 fromChain;
// uint256 toChain;
// }
// struct PendingBridgeToChain{
// address owner;
// address tokenAddress;
// uint256 amount;
// uint256 fromChain;
// uint256 toChain;
// uint256 blockTimestamp;
// uint256 feePaid;
// bool pendingBridge;
// }
// ####################### Mappings ############################
mapping (address => mapping (uint256 => mapping (address => mapping (uint256 => bool)))) public bridgingAllowedMapping; // maps from token address -> from chain -> to token address -> to chain => bridging allowed boolean
// mapping (address => mapping (uint256 => mapping (address => mapping (uint256 => uint256)))) internal bridgingRelayFeeMapping; // maps token address -> from chain -> to token address -> to chain => bridging fee
// mapping (address => uint256) internal tokenBalanceOfBridgeMapping; // total
mapping (address => uint256) internal totalToClaimMapping; // maps token address to amount to be claimed by users
mapping (address => mapping (address => mapping (uint256 => mapping (address => mapping (uint256 => mapping (uint256 => uint256)))))) internal bridgeMapping; // maps to receiving address -> token address -> from chain -> to token address -> to chain -> block timestamp => to amount to send out from bridge
mapping (address => mapping (address => mapping (uint256 => mapping (address => mapping (uint256 => mapping (uint256 => mapping (uint256 => mapping (uint256 => uint256)))))))) internal claimMapping; // maps to receiving address -> token address -> from chain -> to token address -> to chain -> block timestamp -> bridge fee -> amount => to whether 0 = not exist, 1 = exist and to be sent, 2 = bridge has been sent and completed successfully
// ####################### Initial Variables ############################
TokenBridging[] public tokenBridgingStructArray;
uint256 public totalTokenBridgeRoutes = 0;
uint256 public bridgingTime = 30 minutes;
bool public paused = false;
uint256 public thisChainId;
address private owner;
address private relayer;
// PendingBridgeToChain internal defaultPendingBridgeToChainStruct = PendingBridgeToChain(address(0), address(0), 0, 0, 0, 0, 0, false);
// PendingBridgeFromChain internal defaultPendingBridgeFromChainStruct = PendingBridgeFromChain(address(0), 0, 0, 0);
// uint256 public bridgingRelayFeeMultiplier = 200; // need to divide by 100, so for eg. 200 multi = x 2 the fee paid by relayer
// bool useZRO = false;
// ####################### Events ############################
event ClaimTokens(address indexed to, address tokenAddressFrom, uint256 fromChain, address tokenAddressTo, uint256 toChain, uint256 blockTime, uint256 bridgingRelayFee, uint256 amount, uint256 code);
event BridgeTokens(address indexed to, address tokenAddressFrom, uint256 fromChain, address tokenAddressTo, uint256 toChain, uint256 blockTime, uint256 amount);
event BridgeDetails(address tokenAddressFrom, uint256 fromChain, address tokenAddressTo, uint256 toChain, bool bridgingAllowed, uint256 code);
// ####################### modifiers ############################
modifier onlyRelayer {
require(msg.sender == relayer || msg.sender == owner, "Only relayer or owner can execute this function");
_;
}
modifier onlyOwner {
require(msg.sender == owner, "Only owner can execute this function");
_;
}
modifier whenNotPaused() {
require(!paused, "Bridging paused");
_;
}
// modifier isPauser() {
// require(hasRole(PAUSER_ROLE, _msgSender()),"Error Pause: You must have pauser role to pause/unpause");
// _;
// }
// modifier isFee() {
// require(hasRole(FEE_ROLE, msg.sender),"Error Fee: You must have fee role to edit bridging routes fees");
// _;
// }
// modifier isAllower() {
// require(hasRole(ALLOW_ROLE, msg.sender),"Error Allow: You must have allow role to edit allow bridging routes");
// _;
// }
// modifier isMaker() {
// require(hasRole(MAKER_ROLE, msg.sender),"Error Bridge: You must have maker role to add or edit bridging routes");
// _;
// }
// modifier isRelayer() {
// require(hasRole(RELAYER_ROLE, msg.sender),"Error Relayer: You must have relayer role to relay bridging to the blockchain");
// _;
// }
modifier tokenBridgingAllowed(address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _toChain) {
require(bridgingAllowedMapping[_tokenAddressFrom][_fromChain][_tokenAddressTo][_toChain] == true, "Error: Bridging not allowed for this token and/or route");
_;
}
// ####################### Constructor ############################
/**
* @dev contract constructor
**/
constructor(address _owner, address _relayer, uint256 _thisChainId) {
owner = _owner;
relayer = _relayer;
thisChainId = _thisChainId;
// _setupRole(PAUSER_ROLE, _admin);
// _setupRole(FEE_ROLE, _admin);
// _setupRole(ALLOW_ROLE, _admin);
// _setupRole(RELAYER_ROLE, _admin);
// _setupRole(MAKER_ROLE, _admin);
}
// ####################### Admin Functions ############################
// pause public functions
function pauseAdmin() external onlyOwner {
paused = true;
}
// unpause public functions
function unpauseAdmin() external onlyOwner {
paused = false;
}
function getOwnerAdmin() external onlyOwner view returns(address) {
return owner;
}
function getRelayerAdmin() external onlyRelayer view returns(address) {
return relayer;
}
function setOwnerAdmin(address _newOwner) external onlyOwner {
owner = _newOwner;
}
function setRelayerAdmin(address _newRelayer) external onlyOwner {
relayer = _newRelayer;
}
// add bridge route
function addBridgeRouteAdmin(address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _toChain, bool _bridgingAllowed) external onlyOwner {
require(_tokenAddressFrom != address(0),"Error Adding Route: Token address from cannot be 0.");
require(_tokenAddressTo != address(0),"Error Adding Route: Token address to cannot be 0.");
require(_fromChain != 0,"Error Adding Route: From chain cannot be 0.");
require(_toChain != 0,"Error Adding Route: To chain cannot be 0.");
require(_toChain != _fromChain,"Error Adding Route: From chain cannot be the same as To chain.");
bridgingAllowedMapping[_tokenAddressFrom][_fromChain][_tokenAddressTo][_toChain] = _bridgingAllowed;
// bridgingRelayFeeMapping[_tokenAddressFrom][_fromChain][_tokenAddressTo][_toChain] = _bridgingRelayFee;
// TokenBridging memory tokenBridge = TokenBridging(_tokenAddressFrom, _fromChain, _tokenAddressTo, _toChain, _bridgingAllowed);
tokenBridgingStructArray.push(TokenBridging(_tokenAddressFrom, _fromChain, _tokenAddressTo, _toChain, _bridgingAllowed));
totalTokenBridgeRoutes ++;
emit BridgeDetails(_tokenAddressFrom, _fromChain, _tokenAddressTo, _toChain, _bridgingAllowed, _CREATED);
}
// edit bridge route
function editBridgeRouteAdmin(uint256 _index, address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _toChain, bool _bridgingAllowed) external onlyOwner {
require(tokenBridgingStructArray[_index].tokenAddressFrom != address(0),"Error Edit Route: TokenBridging struct doesn't exist, try using addBridgeRouteAdmin");
require(_tokenAddressFrom != address(0),"Error Editing Route: Token address from cannot be 0.");
require(_tokenAddressTo != address(0),"Error Editing Route: Token address to cannot be 0.");
require(_fromChain != 0,"Error Editing Route: From chain cannot be 0.");
require(_toChain != 0,"Error Editing Route: To chain cannot be 0.");
require(_toChain != _fromChain,"Error Editing Route: From chain cannot be the same as To chain.");
bridgingAllowedMapping[_tokenAddressFrom][_fromChain][_tokenAddressTo][_toChain] = _bridgingAllowed;
// bridgingRelayFeeMapping[_tokenAddressFrom][_fromChain][_tokenAddressTo][_toChain] = _bridgingRelayFee;
tokenBridgingStructArray[_index] = TokenBridging(_tokenAddressFrom, _fromChain, _tokenAddressTo, _toChain, _bridgingAllowed);
emit BridgeDetails(_tokenAddressFrom, _fromChain, _tokenAddressTo, _toChain, _bridgingAllowed, _UPDATED);
}
// edit bridge route allowed. in case a certain route needs to be paused for a certain token
function editBridgeRouteAllowedAdmin(uint256 _index, bool _bridgingAllowed) external onlyOwner {
require(tokenBridgingStructArray[_index].tokenAddressFrom != address(0),"Error Edit Route Allowed: TokenBridging struct doesn't exist");
bridgingAllowedMapping[tokenBridgingStructArray[_index].tokenAddressFrom][tokenBridgingStructArray[_index].fromChain][tokenBridgingStructArray[_index].tokenAddressTo][tokenBridgingStructArray[_index].toChain] = _bridgingAllowed;
tokenBridgingStructArray[_index].bridgingAllowed = _bridgingAllowed;
emit BridgeDetails(tokenBridgingStructArray[_index].tokenAddressFrom, tokenBridgingStructArray[_index].fromChain, tokenBridgingStructArray[_index].tokenAddressTo, tokenBridgingStructArray[_index].toChain, _bridgingAllowed, _EDITED);
}
//
// function editBridgeRouteFeeAdmin(uint256 _index, uint256 _bridgingRelayFee) external isFee {
// require(tokenBridgingStructArray[_index].tokenAddressFrom != address(0),"Error Edit Route Fee: TokenBridging struct doesn't exist");
// bridgingRelayFeeMapping[tokenBridgingStructArray[_index].tokenAddressFrom][tokenBridgingStructArray[_index].fromChain][tokenBridgingStructArray[_index].tokenAddressTo][tokenBridgingStructArray[_index].toChain] = _bridgingRelayFee;
// tokenBridgingStructArray[_index].bridgingRelayFee = _bridgingRelayFee;
// emit BridgeDetails(tokenBridgingStructArray[_index].tokenAddressFrom, tokenBridgingStructArray[_index].fromChain, tokenBridgingStructArray[_index].tokenAddressTo, tokenBridgingStructArray[_index].toChain, _bridgingRelayFee, tokenBridgingStructArray[_index].bridgingAllowed, 3);
// }
// this function is mainly for verifying a bridge actually occured on the chain
function getBridgeMappingAdmin(address _to, address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _toChain, uint256 _blockTimestamp) external onlyRelayer view returns(uint256) {
return bridgeMapping[_to][_tokenAddressFrom][_fromChain][_tokenAddressTo][_toChain][_blockTimestamp];
}
// function getBridgingFeeAdmin(address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _toChain) external onlyRelayer view returns(uint256) {
// return bridgingRelayFeeMapping[_tokenAddressFrom][_fromChain][_tokenAddressTo][_toChain];
// }
// input must be in seconds
function setBridgingTime(uint256 _bridgingTime) external onlyOwner {
bridgingTime = _bridgingTime;
}
function getTotalToClaimAdmin(address _tokenAddressTo) external onlyRelayer view returns(uint256) {
return totalToClaimMapping[_tokenAddressTo];
}
function setTotalToClaimAdmin(address _tokenAddressTo, uint256 _amount, uint256 _code) external onlyOwner {
if (_code == 0) {
totalToClaimMapping[_tokenAddressTo] = _amount;
} else if (_code == 1) {
totalToClaimMapping[_tokenAddressTo] += _amount;
} else if (_code == 2) {
totalToClaimMapping[_tokenAddressTo] -= _amount;
}
}
function getToClaimAdmin(address _to, uint256 _amount, address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _toChain, uint256 _blockTimestamp, uint256 _bridgingRelayFee) external onlyRelayer view returns(uint256) {
return claimMapping[_to][_tokenAddressFrom][_fromChain][_tokenAddressTo][_toChain][_blockTimestamp][_bridgingRelayFee][_amount];
}
// this function is set automatically by the relay server and sets all the parameters that the user will need to input exactly to be able to claim their tokens
function setToClaimAdmin(address _to, address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _blockTimestamp, uint256 _bridgingRelayFee, uint256 _amountToClaim) external onlyRelayer tokenBridgingAllowed(_tokenAddressFrom, _fromChain, _tokenAddressTo, thisChainId) {
require(_amountToClaim > 0, "Error Set Claim: Claim amount cannot be 0.");
require(claimMapping[_to][_tokenAddressFrom][_fromChain][_tokenAddressTo][thisChainId][_blockTimestamp][_bridgingRelayFee][_amountToClaim] == 0, "Error Set Claim: Token bridging already exists or has been claimed already.");
claimMapping[_to][_tokenAddressFrom][_fromChain][_tokenAddressTo][thisChainId][_blockTimestamp][_bridgingRelayFee][_amountToClaim] = _CREATED;
totalToClaimMapping[_tokenAddressTo] += _amountToClaim;
emit ClaimTokens(_to, _tokenAddressFrom, _fromChain, _tokenAddressTo, thisChainId, _blockTimestamp, _bridgingRelayFee, _amountToClaim, _CREATED);
}
// this function is used in emergencies only to stop a claim from occuring in case of malicious activity. set _code to anything > 2 such as 3, 4, etc.... If everything ok then set _code back to what it was before
function editToClaimAdmin(address _to, address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _blockTimestamp, uint256 _bridgingRelayFee, uint256 _amountToClaim, uint256 _code) external onlyOwner tokenBridgingAllowed(_tokenAddressFrom, _fromChain, _tokenAddressTo, thisChainId) {
require(_amountToClaim > 0, "Error Set Claim: Claim amount cannot be 0.");
require(claimMapping[_to][_tokenAddressFrom][_fromChain][_tokenAddressTo][thisChainId][_blockTimestamp][_bridgingRelayFee][_amountToClaim] != 0, "Error Edit Claim: Token bridging doesn't exists. Double check your inputs.");
claimMapping[_to][_tokenAddressFrom][_fromChain][_tokenAddressTo][thisChainId][_blockTimestamp][_bridgingRelayFee][_amountToClaim] = _code;
emit ClaimTokens(_to, _tokenAddressFrom, _fromChain, _tokenAddressTo, thisChainId, _blockTimestamp, _bridgingRelayFee, _amountToClaim, _code);
}
// ####################### Private Functions ############################
// ####################### Public Functions ############################
// this function is called by the user from the chain they are bridging FROM. it burns the users tokens and adds the bridge to a mapping and emits an event for the relayer
function bridgeTokens(address _tokenAddressFrom, address _tokenAddressTo, uint256 _toChain, uint256 _amountToBridge) external nonReentrant whenNotPaused tokenBridgingAllowed(_tokenAddressFrom, thisChainId, _tokenAddressTo, _toChain) {
require(bridgeMapping[msg.sender][_tokenAddressFrom][thisChainId][_tokenAddressTo][_toChain][block.timestamp] == 0, "Error Bridging: You already have an existing pending bridge for these inputs");
require(_amountToBridge > 0, "Error Bridging: Bridge amount cannot be 0.");
// require(_tokenAddressFrom != address(0), "Error Bridging: Cannot bridge from 0 address token from.");
// require(_tokenAddressTo != address(0), "Error Bridging: Cannot bridge from 0 address token to.");
// require(thisChainId != 0,"Error Bridging: From chain cannot be 0.");
// require(_toChain != 0,"Error Bridging: To chain cannot be 0.");
// require(_toChain != thisChainId,"Error Bridging: From chain cannot be the same as To chain.");
IERC20BurnMint(_tokenAddressFrom).burnFrom(msg.sender, _amountToBridge);
bridgeMapping[msg.sender][_tokenAddressFrom][thisChainId][_tokenAddressTo][_toChain][block.timestamp] = _amountToBridge;
emit BridgeTokens(msg.sender, _tokenAddressFrom, thisChainId, _tokenAddressTo, _toChain, block.timestamp, _amountToBridge);
}
// this function is called by the user from the chain they are claiming TO. it mints mints tokens based on the mapping set by the bridge relay server and emits an event for the relayer
function claimTokens(address _tokenAddressFrom, uint256 _fromChain, address _tokenAddressTo, uint256 _blockTimestamp, uint256 _bridgingRelayFee, uint256 _amountToClaim) external payable nonReentrant whenNotPaused tokenBridgingAllowed(_tokenAddressFrom, _fromChain, _tokenAddressTo, thisChainId) {
require(claimMapping[msg.sender][_tokenAddressFrom][_fromChain][_tokenAddressTo][thisChainId][_blockTimestamp][_bridgingRelayFee][_amountToClaim] == _CREATED, "Error Claiming: Token bridging doesnt exist for these inputs, or has been bridged already.");
require(msg.value == _bridgingRelayFee, "Error Claiming: message value not equal to bridging relay fee.");
require(block.timestamp >= (_blockTimestamp + bridgingTime), "Error Claiming: Need to wait for bridgingTime before bridge can complete.");
require(_amountToClaim <= totalToClaimMapping[_tokenAddressTo], "Error Claiming: Claim amount exceeds total claimable via the bridge.");
payable(relayer).transfer(msg.value);
claimMapping[msg.sender][_tokenAddressFrom][_fromChain][_tokenAddressTo][thisChainId][_blockTimestamp][_bridgingRelayFee][_amountToClaim] = _UPDATED;
totalToClaimMapping[_tokenAddressTo] -= _amountToClaim;
IERC20BurnMint(_tokenAddressTo).mint(msg.sender, _amountToClaim);
emit ClaimTokens(msg.sender, _tokenAddressFrom, _fromChain, _tokenAddressTo, thisChainId, _blockTimestamp, _bridgingRelayFee, _amountToClaim, _UPDATED);
}
// function getEncode(address _add, uint256 _value) pure public returns(bytes memory){
// return abi.encode(_add, _value);
// }
// function getEncodePacked(address _add, uint256 _value) pure public returns(bytes memory){
// return abi.encodePacked(_add, _value);
// }
// function getEncodeWithSelector(address _add,uint256 _value) pure public returns(bytes memory){
// bytes4 selector = bytes4(keccak256(bytes("transfer(address,uint)")));
// bytes memory data = abi.encodeWithSelector(selector,_add,_value );
// return data;
// }
// function getEncodeWithSignature(address _add, uint256 _value) pure public returns(bytes memory){
// bytes memory data = abi.encodeWithSignature("transfer(address,uint)",_add,_value);
// return data;
// }
// function decodeData(bytes memory data) pure public returns(address, uint256){
// (address add, uint256 value) = abi.decode(data, (address,uint256));
// return (add,value);
// }
// ####################### Must Haves ############################
event ReceivedNativeToken(address from, uint256 amount);
/**
* isAdmin
* @dev ensures that msg.sender is admin
**/
// modifier isAdmin() {
// require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender),"Error: You must have admin role to use this function.");
// _;
// }
/**
* destroy
* @dev Terminate contract and refund native tokens to owner
**/
// function destroy() public isAdmin {
// selfdestruct(payable(msg.sender));
// }
/**
* transferNative
* @dev to transfer any native tokens out of the contract
**/
function transferNative(address _to, uint256 _amount) public onlyOwner {
payable(_to).transfer(_amount);
}
/**
* transferToken
* @dev to transfer any tokens out of the contract
**/
function transferToken(address _tokenAddress, address _to, uint256 _amount) public onlyOwner {
IERC20BurnMint(_tokenAddress).transfer(_to, _amount);
}
/**
* @dev Fallback function if native token is sent to address
**/
fallback() external payable {
emit ReceivedNativeToken(msg.sender, msg.value);
}
/**
* @dev Fallback function if native token is sent to address
**/
receive() external payable {
emit ReceivedNativeToken(msg.sender, msg.value);
}
}project:/node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "paris",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.