Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/KUSD.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.30;
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { AllowlistRegistry } from "src/AllowlistRegistry.sol";
import { IKUSD, Redemption } from "src/interfaces/IKUSD.sol";
import { KredConfigRoleChecker } from "src/KredConfigRoleChecker.sol";
/**
* @title KUSD
* @notice Kred USD - An upgradeable stablecoin backed by other stablecoins (USDT, USDC, etc.)
* @dev Uses UUPS proxy pattern for upgradeability and KredConfig for role-based access control
*/
contract KUSD is
IKUSD,
Initializable,
ERC20Upgradeable,
PausableUpgradeable,
ReentrancyGuardUpgradeable,
UUPSUpgradeable,
KredConfigRoleChecker
{
using SafeERC20 for IERC20;
// ============ Constants ============
/// @notice Decimals for KUSD (18)
uint8 private constant KUSD_DECIMALS = 18;
// ============ State Variables ============
/// @notice Minimum deposit amount in KUSD decimals (18)
/// @dev 0 means no minimum deposit amount is enforced
uint256 public minDepositAmount;
/// @notice Minimum redemption amount in KUSD decimals (18)
/// @dev 0 means no minimum redemption amount is enforced
uint256 public minRedemptionAmount;
/// @notice Redemption delay in seconds
uint256 public redemptionDelay;
/// @notice Maximum number of open redemptions allowed per user at any given point in time
uint256 public maxOpenRedemptionsPerUser;
/// @notice Minimum redemption delay in seconds
/// @dev A min delay of 0 means no floor for the redemptionDelay value
uint256 public minRedemptionDelay;
/// @notice Maximum redemption delay in seconds
/// @dev A max delay of 0 means no ceiling for the redemptionDelay value
uint256 public maxRedemptionDelay;
/// @notice Registry contract that manages the allowlist
AllowlistRegistry public allowlistRegistry;
/// @notice Global deposit limit across all accepted stablecoins (in KUSD decimals - 18)
/// @dev A limit of 0 means no deposits allowed. Use type(uint256).max for unlimited deposits.
uint256 public globalDepositLimit;
/// @notice Total amount deposited globally across all stablecoins (in KUSD decimals - 18)
uint256 public totalDepositedGlobal;
/// @notice Mapping of deposit limits per stablecoin (in KUSD decimals - 18)
/// @dev A limit of 0 means no deposits allowed. Use type(uint256).max for unlimited deposits.
mapping(address stablecoin => uint256 limit) public depositLimits;
/// @notice Mapping to track total deposits per stablecoin (in KUSD decimals - 18)
mapping(address stablecoin => uint256 totalDeposited) public totalDepositedPerStablecoin;
/// @notice Mapping of stablecoins that can be used for deposits/redemptions
mapping(address stablecoin => bool accepted) public acceptedStablecoins;
/// @notice Mapping from user => redemptionId => Redemption
mapping(address user => mapping(uint256 redemptionId => Redemption)) public redemptions;
/// @notice Counter for redemptions per user
mapping(address user => uint256 count) public redemptionCounter;
/// @notice Mapping to track the number of open redemptions per user
/// @dev Set to 0 to disable the limit on open redemptions
mapping(address => uint256) public openRedemptionCount;
/// @notice Address that receives stablecoins when moveAssetsToCustody is called
address public custodyAddress;
// ============ Modifiers ============
/// @notice Modifier to restrict access to only allowlisted (i.e. whitelisted) addresses
modifier onlyAllowlisted() {
_onlyAllowlisted(msg.sender);
_;
}
/// @notice Modifier to restrict access to non-forbidden (i.e. non-blacklisted) addresses
modifier notForbidden(address account) {
_notForbidden(account);
_;
}
/// @notice Modifier to limit the action to only supported stablecoins
modifier onlySupportedStablecoin(address stablecoin) {
_onlySupportedStablecoin(stablecoin);
_;
}
// ============ Constructor ============
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
// ============ Initializer ============
/**
* @notice Initialize the contract
* @param _kredConfig The address of the KredConfig contract
* @param _allowlistRegistry The address of the allowlist registry
*/
function initialize(address _kredConfig, address _allowlistRegistry) external initializer {
if (_kredConfig == address(0)) {
revert ZeroAddressNotAllowed();
}
if (_allowlistRegistry == address(0)) {
revert ZeroAddressNotAllowed();
}
__ERC20_init("Kred USD", "KUSD");
__Pausable_init();
__ReentrancyGuard_init();
__UUPSUpgradeable_init();
__KredConfigRoleChecker_init(_kredConfig);
allowlistRegistry = AllowlistRegistry(_allowlistRegistry);
}
// ============ Pause Management ============
/**
* @notice Pause the contract
* @dev Only callable by addresses with PAUSER_ROLE
*/
function pause() external onlyPauser {
_pause();
}
/**
* @notice Unpause the contract
* @dev Only callable by addresses with DEFAULT_ADMIN_ROLE
*/
function unpause() external onlyAdmin {
_unpause();
}
// ============ Stablecoin Management ============
/**
* @notice Set the minimum deposit amount
* @param newMinDepositAmount The new minimum deposit amount in KUSD decimals (18)
*/
function setMinDepositAmount(uint256 newMinDepositAmount) external onlyManager {
minDepositAmount = newMinDepositAmount;
emit MinDepositAmountUpdated(newMinDepositAmount);
}
/**
* @notice Set the global deposit limit across all stablecoins
* @param newLimit The new global deposit limit (in KUSD decimals - 18).
* Set to 0 to prevent all deposits. Set to type(uint256).max for unlimited deposits.
*/
function setGlobalDepositLimit(uint256 newLimit) external onlyManager {
globalDepositLimit = newLimit; // use type(uint256).max for “no cap”
emit GlobalDepositLimitUpdated(newLimit);
}
/**
* @notice Set the deposit limit for a specific stablecoin
* @param stablecoin The address of the stablecoin
* @param limit The maximum amount of KUSD that can be minted from this stablecoin (18 decimals).
* Set to 0 to prevent all deposits. Set to type(uint256).max for unlimited deposits.
*/
function setDepositLimit(
address stablecoin,
uint256 limit
)
external
onlyManager
onlySupportedStablecoin(stablecoin)
{
depositLimits[stablecoin] = limit;
emit DepositLimitUpdated(stablecoin, limit);
}
/**
* @notice Set whether a stablecoin is accepted for deposits/redemptions
* @param stablecoin The address of the stablecoin
* @param accepted Whether the stablecoin is accepted
*/
function setStablecoinAccepted(address stablecoin, bool accepted) external onlyManager {
if (stablecoin == address(0)) {
revert ZeroAddressNotAllowed();
}
acceptedStablecoins[stablecoin] = accepted;
emit StablecoinAccepted(stablecoin, accepted);
}
/**
* @notice Set the custody address that receives stablecoins when moveAssetsToCustody is called
* @dev Only callable by addresses with DEFAULT_ADMIN_ROLE
* @param newCustodyAddress The new custody address
*/
function setCustodyAddress(address newCustodyAddress) external onlyAdmin {
if (newCustodyAddress == address(0)) {
revert ZeroAddressNotAllowed();
}
custodyAddress = newCustodyAddress;
emit CustodyAddressUpdated(newCustodyAddress);
}
/**
* @notice Move stablecoins from the contract to the custody address
* @dev Only callable by addresses with MANAGER_ROLE
* @param stablecoin The address of the stablecoin to move
* @param amount The amount of stablecoin to move (in stablecoin's decimals)
*/
function moveAssetsToCustody(
address stablecoin,
uint256 amount
)
external
onlyManager
onlySupportedStablecoin(stablecoin)
{
if (custodyAddress == address(0)) {
revert ZeroAddressNotAllowed();
}
if (amount == 0) {
revert ZeroAmount();
}
// Check contract has enough stablecoin
uint256 contractBalance = IERC20(stablecoin).balanceOf(address(this));
if (contractBalance < amount) {
revert InsufficientStablecoinBalance(stablecoin, amount, contractBalance);
}
// Transfer stablecoin to custody address
IERC20(stablecoin).safeTransfer(custodyAddress, amount);
emit AssetsMovedToCustody(stablecoin, custodyAddress, amount);
}
// ============ Redemption Settings Management ============
/**
* @notice Set the minimum redemption amount
* @param newMinRedemptionAmount The new minimum redemption amount in KUSD decimals (18)
*/
function setMinRedemptionAmount(uint256 newMinRedemptionAmount) external onlyManager {
minRedemptionAmount = newMinRedemptionAmount;
emit MinRedemptionAmountUpdated(newMinRedemptionAmount);
}
/**
* @notice Set the redemption delay
* @dev The new delay must be within the min and max bounds (if set)
* @param newDelay The new redemption delay in seconds
*/
function setRedemptionDelay(uint256 newDelay) external onlyManager {
if (newDelay < minRedemptionDelay || (maxRedemptionDelay != 0 && newDelay > maxRedemptionDelay)) {
revert RedemptionDelayOutOfBounds(minRedemptionDelay, maxRedemptionDelay, newDelay);
}
redemptionDelay = newDelay;
emit RedemptionDelayUpdated(newDelay);
}
/**
* @notice Set the redemption delay bounds
* @dev If ceiling is desired, set newMaxDelay >= newMinDelay, else set newMaxDelay = 0 to remove ceiling
* @param newMinDelay The new minimum redemption delay in seconds
* @param newMaxDelay The new maximum redemption delay in seconds
*/
function setRedemptionDelayBounds(uint256 newMinDelay, uint256 newMaxDelay) external onlyManager {
if (newMaxDelay != 0 && newMaxDelay < newMinDelay) {
revert InvalidRedemptionDelayBounds(newMinDelay, newMaxDelay);
}
// Auto-clamp current redemptionDelay to fit within the new bounds
if (redemptionDelay < newMinDelay) redemptionDelay = newMinDelay;
if (newMaxDelay != 0 && redemptionDelay > newMaxDelay) redemptionDelay = newMaxDelay;
// Set the new bounds
minRedemptionDelay = newMinDelay;
maxRedemptionDelay = newMaxDelay;
emit RedemptionDelayBoundsUpdated(newMinDelay, newMaxDelay);
}
/**
* @notice Set the maximum number of open redemptions allowed per user
* @param newMax The new maximum number of open redemptions
*/
function setMaxOpenRedemptionsPerUser(uint256 newMax) external onlyManager {
maxOpenRedemptionsPerUser = newMax;
emit MaxOpenRedemptionsPerUserUpdated(newMax);
}
// ============ Deposit Functions ============
/**
* @notice Deposit stablecoins to mint KUSD
* @param stablecoin The address of the stablecoin to deposit
* @param amount The amount of stablecoin to deposit (in that stablecoin's decimals)
* @param referralId Referral ID for tracking purposes
*/
function deposit(
address stablecoin,
uint256 amount,
string calldata referralId
)
external
whenNotPaused
nonReentrant
onlyAllowlisted
notForbidden(msg.sender)
onlySupportedStablecoin(stablecoin)
{
if (amount == 0) {
revert ZeroAmount();
}
// Calculate KUSD amount (convert to KUSD decimals - 18)
uint256 kusdAmount = _convertToKUSD(stablecoin, amount);
if (minDepositAmount != 0 && kusdAmount < minDepositAmount) {
revert BelowMinDeposit(minDepositAmount);
}
// Check global deposit limit (0 means no deposits allowed, type(uint256).max means unlimited)
if (globalDepositLimit != type(uint256).max) {
uint256 newGlobal = totalDepositedGlobal + kusdAmount;
if (newGlobal > globalDepositLimit) {
revert GlobalDepositLimitExceeded(globalDepositLimit, totalDepositedGlobal, kusdAmount);
}
totalDepositedGlobal = newGlobal;
}
// Check per-stablecoin deposit limit (0 means no deposits allowed, type(uint256).max means unlimited)
uint256 limit = depositLimits[stablecoin];
if (limit != type(uint256).max) {
uint256 currentTotal = totalDepositedPerStablecoin[stablecoin];
uint256 newTotal = currentTotal + kusdAmount;
if (newTotal > limit) {
revert DepositLimitExceeded(stablecoin, limit, currentTotal, kusdAmount);
}
totalDepositedPerStablecoin[stablecoin] = newTotal;
}
// Transfer stablecoin from user
IERC20(stablecoin).safeTransferFrom(msg.sender, address(this), amount);
// Mint KUSD to user
_mint(msg.sender, kusdAmount);
emit Deposit(msg.sender, stablecoin, amount, kusdAmount, referralId);
}
// ============ Redemption Functions ============
/**
* @notice Initiate a redemption of KUSD for stablecoins (step 1)
* @param kusdAmount The amount of KUSD to redeem (18 decimals)
* @param stablecoin The stablecoin to receive
* @return redemptionId The ID of the redemption
*/
function initiateRedemption(
uint256 kusdAmount,
address stablecoin
)
external
whenNotPaused
nonReentrant
onlyAllowlisted
notForbidden(msg.sender)
onlySupportedStablecoin(stablecoin)
returns (uint256 redemptionId)
{
if (kusdAmount == 0) {
revert ZeroAmount();
}
if (minRedemptionAmount != 0 && kusdAmount < minRedemptionAmount) {
revert BelowMinRedemption(minRedemptionAmount);
}
if (maxOpenRedemptionsPerUser != 0) {
uint256 currentCount = openRedemptionCount[msg.sender];
if (currentCount >= maxOpenRedemptionsPerUser) {
revert TooManyOpenRedemptions(currentCount, maxOpenRedemptionsPerUser);
}
}
// Transfer KUSD from user to the contract
_transfer(msg.sender, address(this), kusdAmount);
// Create redemption record
redemptionId = redemptionCounter[msg.sender]++;
uint256 unlockTime = block.timestamp + redemptionDelay;
redemptions[msg.sender][redemptionId] =
Redemption({ amount: kusdAmount, stablecoin: stablecoin, completed: false, unlockTime: unlockTime });
// Increment open redemption count
openRedemptionCount[msg.sender]++;
emit RedemptionInitiated(msg.sender, redemptionId, kusdAmount, stablecoin, unlockTime);
}
/**
* @notice Complete a redemption (step 2)
* @param redemptionId The ID of the redemption
*/
function completeRedemption(uint256 redemptionId) external whenNotPaused nonReentrant notForbidden(msg.sender) {
_completeRedemption(msg.sender, redemptionId);
}
/**
* @notice Complete a redemption as a manager
* @param user The user who initiated the redemption
* @param redemptionId The ID of the redemption
*/
function completeRedemptionAsManager(
address user,
uint256 redemptionId
)
external
nonReentrant
onlyManager
notForbidden(user)
{
_completeRedemption(user, redemptionId);
}
/**
* @notice Cancel a redemption and return KUSD to user
* @param redemptionId The ID of the redemption to cancel
*/
function cancelRedemption(uint256 redemptionId) external nonReentrant whenNotPaused notForbidden(msg.sender) {
Redemption storage redemption = redemptions[msg.sender][redemptionId];
if (redemption.completed) {
revert RedemptionAlreadyCompleted(redemptionId);
}
if (redemption.amount == 0) {
revert InvalidRedemption(redemptionId);
}
uint256 kusdAmount = redemption.amount;
// Mark as completed (cancelled)
redemption.completed = true;
// Return KUSD to user
_transfer(address(this), msg.sender, kusdAmount);
// Decrement open redemption count
if (openRedemptionCount[msg.sender] != 0) openRedemptionCount[msg.sender] -= 1;
emit RedemptionCancelled(msg.sender, redemptionId);
}
// ============ Limits View Functions ============
/**
* @notice Gets the remaining global capacity available for new deposits (in KUSD decimals - 18)
* @return The remaining global capacity
*/
function remainingGlobalCapacity() public view returns (uint256) {
uint256 limit = globalDepositLimit;
// Unlimited cap
if (limit == type(uint256).max) return type(uint256).max;
// Hard block or fully used
if (limit == 0 || totalDepositedGlobal >= limit) return 0;
return limit - totalDepositedGlobal;
}
/**
* @notice Gets the remaining capacity for a specific stablecoin (in KUSD decimals - 18)
* @param stablecoin The address of the stablecoin
* @return The remaining capacity for the stablecoin
*/
function remainingPerAssetCapacity(address stablecoin)
public
view
onlySupportedStablecoin(stablecoin)
returns (uint256)
{
uint256 limit = depositLimits[stablecoin];
// Unlimited per-asset cap
if (limit == type(uint256).max) return type(uint256).max;
// Hard block or fully used
uint256 usedCapacity = totalDepositedPerStablecoin[stablecoin];
if (limit == 0 || usedCapacity >= limit) return 0;
return limit - usedCapacity;
}
/**
* @notice Gets the effective remaining capacity for a specific asset as min(global, per-asset cap)
* @param stablecoin The address of the stablecoin
* @return The effective remaining capacity for the stablecoin
*/
function effectivePerAssetCapacity(address stablecoin)
external
view
onlySupportedStablecoin(stablecoin)
returns (uint256)
{
uint256 remainingGlobal = remainingGlobalCapacity();
uint256 remainingPerAsset = remainingPerAssetCapacity(stablecoin);
return remainingGlobal < remainingPerAsset ? remainingGlobal : remainingPerAsset;
}
// ============ ERC20 Overrides ============
/**
* @notice Override transfer to check forbidden list and pause status
*/
function transfer(
address to,
uint256 value
)
public
override
whenNotPaused
notForbidden(msg.sender)
notForbidden(to)
returns (bool)
{
return super.transfer(to, value);
}
/**
* @notice Override transferFrom to check forbidden list and pause status
*/
function transferFrom(
address from,
address to,
uint256 value
)
public
override
whenNotPaused
notForbidden(from)
notForbidden(to)
returns (bool)
{
return super.transferFrom(from, to, value);
}
// ============ Internal Helper Functions ============
/**
* @notice Convert stablecoin amount to KUSD amount
* @param stablecoin The address of the stablecoin
* @param amount The amount in stablecoin decimals
* @return The amount in KUSD decimals (18)
*/
function _convertToKUSD(address stablecoin, uint256 amount) internal view returns (uint256) {
uint8 stablecoinDecimals = IERC20Metadata(stablecoin).decimals();
if (stablecoinDecimals == KUSD_DECIMALS) {
return amount;
} else if (stablecoinDecimals < KUSD_DECIMALS) {
return amount * (10 ** (KUSD_DECIMALS - stablecoinDecimals));
} else {
return amount / (10 ** (stablecoinDecimals - KUSD_DECIMALS));
}
}
/**
* @notice Convert KUSD amount to stablecoin amount
* @param stablecoin The address of the stablecoin
* @param kusdAmount The amount in KUSD decimals (18)
* @return The amount in stablecoin decimals
*/
function _convertFromKUSD(address stablecoin, uint256 kusdAmount) internal view returns (uint256) {
uint8 stablecoinDecimals = IERC20Metadata(stablecoin).decimals();
if (stablecoinDecimals == KUSD_DECIMALS) {
return kusdAmount;
} else if (stablecoinDecimals < KUSD_DECIMALS) {
return kusdAmount / (10 ** (KUSD_DECIMALS - stablecoinDecimals));
} else {
return kusdAmount * (10 ** (stablecoinDecimals - KUSD_DECIMALS));
}
}
/**
* @notice Internal function to complete a redemption
* @param user The user who initiated the redemption
* @param redemptionId The ID of the redemption
*/
function _completeRedemption(address user, uint256 redemptionId) internal {
Redemption storage redemption = redemptions[user][redemptionId];
if (redemption.completed) {
revert RedemptionAlreadyCompleted(redemptionId);
}
if (redemption.amount == 0) {
revert InvalidRedemption(redemptionId);
}
if (block.timestamp < redemption.unlockTime) {
revert RedemptionNotReady();
}
// Calculate stablecoin amount (convert from KUSD decimals to stablecoin decimals)
uint256 stablecoinAmount = _convertFromKUSD(redemption.stablecoin, redemption.amount);
if (stablecoinAmount == 0) {
revert AmountTooSmall();
}
// Check contract has enough stablecoin
uint256 contractBalance = IERC20(redemption.stablecoin).balanceOf(address(this));
if (contractBalance < stablecoinAmount) {
revert InsufficientStablecoinBalance(redemption.stablecoin, stablecoinAmount, contractBalance);
}
// Mark as completed
redemption.completed = true;
// Burn escrowed KUSD
_burn(address(this), redemption.amount);
// Transfer stablecoin to user
IERC20(redemption.stablecoin).safeTransfer(user, stablecoinAmount);
// Decrement open redemption count
if (openRedemptionCount[user] != 0) openRedemptionCount[user] -= 1;
emit RedemptionCompleted(user, redemptionId, redemption.stablecoin, stablecoinAmount);
}
/// @notice Internal function to check if an address is allowlisted
function _onlyAllowlisted(address account) internal view {
if (!allowlistRegistry.isAllowed(account)) {
revert NotAllowlisted();
}
}
/// @notice Internal function to check if an address is not forbidden
function _notForbidden(address account) internal view {
if (allowlistRegistry.isForbidden(account)) {
revert AddressOnForbiddenList(account);
}
}
/// @notice Internal function to check if a stablecoin is supported
function _onlySupportedStablecoin(address stablecoin) internal view {
if (!acceptedStablecoins[stablecoin]) {
revert StablecoinNotAccepted(stablecoin);
}
}
// ============ Upgradeability ============
/**
* @notice Authorize an upgrade to a new implementation
* @param newImplementation The address of the new implementation
*/
function _authorizeUpgrade(address newImplementation) internal override onlyAdmin { }
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ContextUpgradeable} from "../../utils/ContextUpgradeable.sol";
import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20, IERC20Metadata, IERC20Errors {
/// @custom:storage-location erc7201:openzeppelin.storage.ERC20
struct ERC20Storage {
mapping(address account => uint256) _balances;
mapping(address account => mapping(address spender => uint256)) _allowances;
uint256 _totalSupply;
string _name;
string _symbol;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;
function _getERC20Storage() private pure returns (ERC20Storage storage $) {
assembly {
$.slot := ERC20StorageLocation
}
}
/**
* @dev Sets the values for {name} and {symbol}.
*
* Both values are immutable: they can only be set once during construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
ERC20Storage storage $ = _getERC20Storage();
$._name = name_;
$._symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/// @inheritdoc IERC20
function totalSupply() public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._totalSupply;
}
/// @inheritdoc IERC20
function balanceOf(address account) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/// @inheritdoc IERC20
function allowance(address owner, address spender) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
$._totalSupply += value;
} else {
uint256 fromBalance = $._balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
$._balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
$._totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
$._balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
$._allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner`'s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reinitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/utils/PausableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.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.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Pausable
struct PausableStorage {
bool _paused;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;
function _getPausableStorage() private pure returns (PausableStorage storage $) {
assembly {
$.slot := PausableStorageLocation
}
}
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
function __Pausable_init() internal onlyInitializing {
}
function __Pausable_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
PausableStorage storage $ = _getPausableStorage();
return $._paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = false;
emit Unpaused(_msgSender());
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* 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 ReentrancyGuardUpgradeable is Initializable {
// 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;
/// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
struct ReentrancyGuardStorage {
uint256 _status;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
assembly {
$.slot := ReentrancyGuardStorageLocation
}
}
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
$._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 {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// On the first call to nonReentrant, _status will be NOT_ENTERED
if ($._status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
$._status = ENTERED;
}
function _nonReentrantAfter() private {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// 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) {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
return $._status == ENTERED;
}
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowanc
Submitted on: 2025-11-04 13:02:34
Comments
Log in to comment.
No comments yet.