Overview
S Balance
S Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 8 from a total of 8 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Edit Giveaway Ti... | 5391777 | 20 days ago | IN | 0 S | 0.00272018 | ||||
Edit Giveaway Ti... | 5381368 | 21 days ago | IN | 0 S | 0.00277853 | ||||
0x09c56431 | 5277444 | 22 days ago | IN | 0 S | 0.00171279 | ||||
Edit Giveaway Ti... | 5275500 | 22 days ago | IN | 0 S | 0.00173248 | ||||
Edit Giveaway Ti... | 5275426 | 22 days ago | IN | 0 S | 0.00277786 | ||||
Start Sync Givea... | 5275016 | 22 days ago | IN | 0 S | 0.00444425 | ||||
Edit Giveaway Ti... | 5274933 | 22 days ago | IN | 0 S | 0.00271952 | ||||
Edit Silver Fees | 5274855 | 22 days ago | IN | 0 S | 0.00272134 |
Loading...
Loading
Contract Name:
SilverFeesGiveaway
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 10 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.20; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/access/Ownable2Step.sol"; import {GelatoVRFConsumerBase} from "contracts/Integrations/Gelato/VRF/GelatoVRFConsumerBase.sol"; import 'contracts/SilverFees/SilverFees.sol'; // User's tickets struct UserTickets { uint256 tickets; uint256 timestamp; } // User's tickets data struct GiveawayTicketsData { mapping(address => UserTickets) userTickets; uint256 lastExecution; } // Weekly giveaway struct GiveawayData { address[] giveawayParticipants; uint256 numberOfParticipants; bool participationEnded; uint256 giveawayEndTime; } // Giveaway settings struct GiveawaySettings { bool isGiveawayActive; uint256 ticketPrice; uint256 giveawayTime; bool editedActive; uint256 editedTicketPrice; uint256 editedGiveawayTime; } // Gelato VRF Data struct RandomnessRequest { bool requestSent; bool fulfilled; uint256 pendingRequestId; uint256 latestRandomness; uint256 latestRequestId; } /// @title SilverFeesGiveaway /// @author github.com/SifexPro /// @notice This contract take care of the weekly giveaway contract SilverFeesGiveaway is Ownable2Step, GelatoVRFConsumerBase { SilverFees public silverFees; GiveawayData public giveawayData; GiveawayTicketsData public giveawayTicketsData; GiveawaySettings public giveawaySettings; RandomnessRequest public randomnessRequest; address private immutable _operatorAddr; // Events for giveaway event GiveawaySyncStarted(uint256 ticketPrice, uint256 giveawayEndTime); event GiveawaySynced(); event GiveawayExecuted(bool isGiveawayActive, uint256 weeklyGiveawayAmount); event BuyTickets(address indexed account, uint256 amount, uint256 tickets); event DrawWinner(address indexed winner, uint256 amount, uint256 randomIndex); // Event for randomness request event RequestSent(uint256 requestId); event RequestFulfilled(uint256 requestId, uint256 randomness); // Events for misc event EditedSilverFees(address silverFees); event EditedGiveawayTicketPrice(uint256 ticketPrice); event EditedGiveawayTime(uint256 giveawayTime); event EditedGiveawayActive(bool isGiveawayActive); event StartedGiveaway(uint256 ticketPrice, uint256 giveawayEndTime); event StoppedGiveaway(); event WithdrawnToken(address indexed token, address to, uint256 amount); // Constructor constructor(address operator) Ownable(msg.sender) { _operatorAddr = operator; giveawaySettings = GiveawaySettings(true, 1 ether, 1 weeks, false, 0, 0); } // Fees management /** * @dev Check if the giveaway can be executed * @notice Will return true : if the giveaway is over and s_request is fulfilled, or if the giveaway is not active */ function checkExecuteGiveaway() external onlySilverFees view returns (bool) { return ((giveawayData.participationEnded && randomnessRequest.fulfilled) || !giveawaySettings.isGiveawayActive); } /** * @dev Execute the giveaway * @param isSwapToWrappedToken If the giveaway is in wrapped native token * @param weeklyGiveawayAmount Amount to giveaway * @notice Will draw a winner if the giveaway is active, otherwise will transfer the amount to the contract */ function executeGiveaway(bool isSwapToWrappedToken, uint256 weeklyGiveawayAmount) external onlySilverFees { if (giveawaySettings.isGiveawayActive && randomnessRequest.fulfilled) drawWinner(isSwapToWrappedToken, weeklyGiveawayAmount); else if (!giveawaySettings.isGiveawayActive) { bool success; if (isSwapToWrappedToken) success = silverFees.wrappedToken().transferFrom(address(silverFees), address(this), weeklyGiveawayAmount); else success = silverFees.silverToken().transferFrom(address(silverFees), address(this), weeklyGiveawayAmount); require(success, "Transfer failed"); } applyEditedSettings(); emit GiveawayExecuted(giveawaySettings.isGiveawayActive, weeklyGiveawayAmount); } // Sync Fees Management /** * @dev Start the giveaway sync */ function startSyncGiveaway() public onlySilverFeesOrOwner { applyEditedSettings(); giveawayData = GiveawayData(new address[](0), 0, false, silverFees.syncFeesLastSync() + giveawaySettings.giveawayTime); emit GiveawaySyncStarted(giveawaySettings.ticketPrice, giveawayData.giveawayEndTime); } /** * @dev Sync the giveaway */ function syncGiveaway() external onlySilverFees { if (!giveawaySettings.isGiveawayActive) return; uint256 syncTime = silverFees.syncFeesTime(); uint256 giveawayTime = giveawaySettings.giveawayTime; bool giveawayTimeCheck = block.timestamp + (syncTime / 2) >= giveawayData.giveawayEndTime; if (giveawayTimeCheck && giveawayData.numberOfParticipants > 0 && !randomnessRequest.requestSent) { // Check if the giveaway is over and no request is sent requestRandomness(); giveawayData.participationEnded = true; } else if (giveawayTimeCheck && giveawayData.numberOfParticipants == 0) { // Check if the giveaway is over and no participants giveawaySettings.editedGiveawayTime = giveawayTime; applyEditedSettings(); } else if (giveawayTimeCheck && giveawayData.participationEnded && block.timestamp > giveawayData.giveawayEndTime + (2 * syncTime)) { // Check if the giveaway is over and still not executed after 2 sync clearRequest(); giveawayData.participationEnded = false; giveawaySettings.editedGiveawayTime = giveawayTime; applyEditedSettings(); } emit GiveawaySynced(); } // Weekly giveaway /** * @dev Buy tickets for the giveaway * @param _amount Amount of tokens to buy tickets * @param user Address of the user * @notice Will buy tickets for the user if the giveaway is active and not ended */ function buyTickets(uint256 _amount, address user) external onlySilverFees { require(giveawaySettings.isGiveawayActive, "Giveaway not active"); require(!giveawayData.participationEnded, "Ended"); require(_amount >= giveawaySettings.ticketPrice, "Price too low"); uint256 amount = _amount; uint256 tokenAmountIn = _amount / giveawaySettings.ticketPrice; if (_amount > giveawaySettings.ticketPrice) { amount = tokenAmountIn * giveawaySettings.ticketPrice; } uint256 balance = silverFees.silverToken().balanceOf(user); require(balance >= amount, "Not enough balance"); uint256 allowance = silverFees.silverToken().allowance(user, address(silverFees)); require(allowance >= amount, 'Not enough allowance'); silverFees.buyTicketsBurn(user, amount); for (uint256 i = 0; i < tokenAmountIn; i++) giveawayData.giveawayParticipants.push(user); giveawayData.numberOfParticipants = giveawayData.giveawayParticipants.length; giveawayTicketsData.userTickets[user] = UserTickets(userTickets(user) + tokenAmountIn, block.timestamp); emit BuyTickets(user, amount, tokenAmountIn); } /** * @dev Draw a winner for the giveaway * @param isSwapToWrappedToken If the giveaway is in wrapped native token * @param weeklyGiveawayAmount Amount to giveaway * @notice Will draw a winner if the giveaway is active and ended */ function drawWinner(bool isSwapToWrappedToken, uint256 weeklyGiveawayAmount) private { require(giveawayData.participationEnded, "Too early"); require(giveawayData.numberOfParticipants > 0, "0 participants"); uint256 winnerIndex = getRandomIndex(giveawayData.numberOfParticipants); address winner = giveawayData.giveawayParticipants[winnerIndex]; uint256 giveawayAmount = weeklyGiveawayAmount; bool success; if (isSwapToWrappedToken) success = silverFees.wrappedToken().transferFrom(address(silverFees), winner, giveawayAmount); else success = silverFees.silverToken().transferFrom(address(silverFees), winner, giveawayAmount); require(success, "Transfer failed"); // Reset giveaway giveawayData.participationEnded = false; giveawayData.giveawayEndTime = silverFees.syncFeesLastSync() + giveawaySettings.giveawayTime; giveawayData.giveawayParticipants = new address[](0); giveawayData.numberOfParticipants = 0; clearRequest(); giveawayTicketsData.lastExecution = block.timestamp; emit DrawWinner(winner, giveawayAmount, winnerIndex); } function getRandomIndex(uint256 lenght) private view returns (uint256 _randomIndex) { uint256 randomIndex = (uint256(keccak256(abi.encodePacked(randomnessRequest.latestRandomness))) % lenght); return (randomIndex); } // User tickets /** * @dev Get the user's tickets * @param user Address of the user * @return Number of tickets */ function userTickets(address user) public view returns (uint256) { if (giveawayTicketsData.userTickets[user].timestamp > giveawayTicketsData.lastExecution && giveawaySettings.isGiveawayActive) return giveawayTicketsData.userTickets[user].tickets; return 0; } // Internal functions function withdrawToken(address _token, address _to) public onlyOwner { IERC20 token = IERC20(_token); uint256 balance = token.balanceOf(address(this)); SafeERC20.safeTransfer(token, _to, balance); emit WithdrawnToken(_token, _to, balance); } function applyEditedSettings() private { if (giveawaySettings.editedTicketPrice != 0) { giveawaySettings.ticketPrice = giveawaySettings.editedTicketPrice; giveawaySettings.editedTicketPrice = 0; } if (giveawaySettings.editedGiveawayTime != 0) { giveawayData.giveawayEndTime = silverFees.syncFeesLastSync() + giveawaySettings.editedGiveawayTime; giveawaySettings.giveawayTime = giveawaySettings.editedGiveawayTime; giveawaySettings.editedGiveawayTime = 0; } if (giveawaySettings.editedActive) { giveawaySettings.isGiveawayActive = !giveawaySettings.isGiveawayActive; giveawaySettings.editedActive = false; if (giveawaySettings.isGiveawayActive) { giveawayData.giveawayEndTime = silverFees.syncFeesLastSync() + giveawaySettings.giveawayTime; emit StartedGiveaway(giveawaySettings.ticketPrice, giveawayData.giveawayEndTime); } else emit StoppedGiveaway(); } } function editSilverFees(address _silverFees) public onlyOwner { silverFees = SilverFees(payable(_silverFees)); emit EditedSilverFees(_silverFees); } function editGiveawayTicketPrice(uint256 _ticketPrice) public onlyOwner { giveawaySettings.editedTicketPrice = _ticketPrice; emit EditedGiveawayTicketPrice(_ticketPrice); } function editGiveawayTime(uint256 _giveawayTime) public onlyOwner { giveawaySettings.editedGiveawayTime = _giveawayTime; emit EditedGiveawayTime(_giveawayTime); } function setActiveGiveaway(bool _giveawayActive) public onlyOwner { if (giveawaySettings.isGiveawayActive == _giveawayActive) giveawaySettings.editedActive = false; else giveawaySettings.editedActive = true; emit EditedGiveawayActive(_giveawayActive); } // Gelato VRF function requestRandomness() private { require(randomnessRequest.requestSent == false, "Request already sent"); randomnessRequest.requestSent = true; randomnessRequest.pendingRequestId = _requestRandomness(abi.encode(0)); emit RequestSent(randomnessRequest.pendingRequestId); } function _fulfillRandomness( uint256 randomness, uint256 requestId, bytes memory ) internal override { require(randomnessRequest.requestSent == true, "Request not sent"); require(randomnessRequest.pendingRequestId == requestId, "requestId not valid"); randomnessRequest.fulfilled = true; randomnessRequest.latestRandomness = randomness; randomnessRequest.latestRequestId = requestId; emit RequestFulfilled(requestId, randomness); } function clearRequest() private { randomnessRequest.requestSent = false; randomnessRequest.fulfilled = false; randomnessRequest.pendingRequestId = 0; randomnessRequest.latestRandomness = 0; randomnessRequest.latestRequestId = 0; } function getRandomnessRequest() public view returns (RandomnessRequest memory) { return randomnessRequest; } function _operator() internal view override returns (address) { return _operatorAddr; } // Modifiers modifier onlySilverFeesOrOwner() { require(msg.sender == owner() || msg.sender == address(silverFees), 'Only SilverFees/Owner'); _; } modifier onlySilverFees() { require(msg.sender == address(silverFees), 'Only SilverFees'); _; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol) pragma solidity ^0.8.20; import {Context} from "../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. * * The initial owner is set to the address provided by the deployer. 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. */ abstract contract Ownable is Context { address private _owner; /** * @dev The caller account is not authorized to perform an operation. */ error OwnableUnauthorizedAccount(address account); /** * @dev The owner is not a valid owner account. (eg. `address(0)`) */ error OwnableInvalidOwner(address owner); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the address provided by the deployer as the initial owner. */ constructor(address initialOwner) { if (initialOwner == address(0)) { revert OwnableInvalidOwner(address(0)); } _transferOwnership(initialOwner); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { if (owner() != _msgSender()) { revert OwnableUnauthorizedAccount(_msgSender()); } } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { if (newOwner == address(0)) { revert OwnableInvalidOwner(address(0)); } _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol) pragma solidity ^0.8.20; import {Ownable} from "./Ownable.sol"; /** * @dev Contract module which provides access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * The initial owner is specified at deployment time in the constructor for `Ownable`. This * can later be changed with {transferOwnership} and {acceptOwnership}. * * This module is used through inheritance. It will make available all functions * from parent (Ownable). */ abstract contract Ownable2Step is Ownable { address private _pendingOwner; event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner); /** * @dev Returns the address of the pending owner. */ function pendingOwner() public view virtual returns (address) { return _pendingOwner; } /** * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual override onlyOwner { _pendingOwner = newOwner; emit OwnershipTransferStarted(owner(), newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner. * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual override { delete _pendingOwner; super._transferOwnership(newOwner); } /** * @dev The new owner accepts the ownership transfer. */ function acceptOwnership() public virtual { address sender = _msgSender(); if (pendingOwner() != sender) { revert OwnableUnauthorizedAccount(sender); } _transferOwnership(sender); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol) pragma solidity ^0.8.20; /** * @dev Standard ERC20 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens. */ interface IERC20Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC20InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC20InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. * @param spender Address that may be allowed to operate on tokens without being their owner. * @param allowance Amount of tokens a `spender` is allowed to operate with. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC20InvalidApprover(address approver); /** * @dev Indicates a failure with the `spender` to be approved. Used in approvals. * @param spender Address that may be allowed to operate on tokens without being their owner. */ error ERC20InvalidSpender(address spender); } /** * @dev Standard ERC721 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens. */ interface IERC721Errors { /** * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20. * Used in balance queries. * @param owner Address of the current owner of a token. */ error ERC721InvalidOwner(address owner); /** * @dev Indicates a `tokenId` whose `owner` is the zero address. * @param tokenId Identifier number of a token. */ error ERC721NonexistentToken(uint256 tokenId); /** * @dev Indicates an error related to the ownership over a particular token. Used in transfers. * @param sender Address whose tokens are being transferred. * @param tokenId Identifier number of a token. * @param owner Address of the current owner of a token. */ error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC721InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC721InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param tokenId Identifier number of a token. */ error ERC721InsufficientApproval(address operator, uint256 tokenId); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC721InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC721InvalidOperator(address operator); } /** * @dev Standard ERC1155 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens. */ interface IERC1155Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. * @param tokenId Identifier number of a token. */ error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC1155InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC1155InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param owner Address of the current owner of a token. */ error ERC1155MissingApprovalForAll(address operator, address owner); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC1155InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC1155InvalidOperator(address operator); /** * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. * Used in batch transfers. * @param idsLength Length of the array of token identifiers * @param valuesLength Length of the array of token amounts */ error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "./IERC20.sol"; import {IERC20Metadata} from "./extensions/IERC20Metadata.sol"; import {Context} from "../../utils/Context.sol"; import {IERC20Errors} from "../../interfaces/draft-IERC6093.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 ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. */ abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors { mapping(address account => uint256) private _balances; mapping(address account => mapping(address spender => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { 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; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual returns (uint256) { 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; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual returns (uint256) { 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}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * 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 { 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: * ``` * 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 { 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); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. * * CAUTION: See Security Considerations above. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ 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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; import {IERC20Permit} from "../extensions/IERC20Permit.sol"; import {Address} from "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 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 { using Address for address; /** * @dev An operation with an ERC20 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 Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ 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. */ 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. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data); if (returndata.length != 0 && !abi.decode(returndata, (bool))) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol) pragma solidity ^0.8.20; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev The ETH balance of the account is not enough to perform the operation. */ error AddressInsufficientBalance(address account); /** * @dev There's no code at `target` (it is not a contract). */ error AddressEmptyCode(address target); /** * @dev A call to an address target failed. The target may have reverted. */ error FailedInnerCall(); /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { if (address(this).balance < amount) { revert AddressInsufficientBalance(address(this)); } (bool success, ) = recipient.call{value: amount}(""); if (!success) { revert FailedInnerCall(); } } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason or custom error, it is bubbled * up by this function (like regular Solidity function calls). However, if * the call reverted with no returned reason, this function reverts with a * {FailedInnerCall} error. * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { if (address(this).balance < value) { revert AddressInsufficientBalance(address(this)); } (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an * unsuccessful call. */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata ) internal view returns (bytes memory) { if (!success) { _revert(returndata); } else { // only check if target is a contract if the call was successful and the return data is empty // otherwise we already know that it was a contract if (returndata.length == 0 && target.code.length == 0) { revert AddressEmptyCode(target); } return returndata; } } /** * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the * revert reason or with a default {FailedInnerCall} error. */ function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) { if (!success) { _revert(returndata); } else { return returndata; } } /** * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}. */ function _revert(bytes memory returndata) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert FailedInnerCall(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; /** * @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. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol) pragma solidity ^0.8.20; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Muldiv operation overflow. */ error MathOverflowedMulDiv(); enum Rounding { Floor, // Toward negative infinity Ceil, // Toward positive infinity Trunc, // Toward zero Expand // Away from zero } /** * @dev Returns the addition of two unsigned integers, with an overflow flag. */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds towards infinity instead * of rounding towards zero. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { if (b == 0) { // Guarantee the same behavior as in a regular Solidity division. return a / b; } // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or * denominator == 0. * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by * Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0 = x * y; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. if (denominator <= prod1) { revert MathOverflowedMulDiv(); } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. // Always >= 1. See https://cs.stackexchange.com/q/138556/92363. uint256 twos = denominator & (0 - denominator); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also // works in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded * towards zero. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256 of a positive value rounded towards zero. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0); } } /** * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers. */ function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) { return uint8(rounding) % 2 == 1; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.20; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol) pragma solidity ^0.8.20; import {Math} from "./math/Math.sol"; import {SignedMath} from "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant HEX_DIGITS = "0123456789abcdef"; uint8 private constant ADDRESS_LENGTH = 20; /** * @dev The `value` string doesn't fit in the specified `length`. */ error StringsInsufficientHexLength(uint256 value, uint256 length); /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), HEX_DIGITS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toStringSigned(int256 value) internal pure returns (string memory) { return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { uint256 localValue = value; bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = HEX_DIGITS[localValue & 0xf]; localValue >>= 4; } if (localValue != 0) { revert StringsInsufficientHexLength(value, length); } return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal * representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b)); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.14; import "./Types.sol"; abstract contract AutomateModuleHelper { function _resolverModuleArg( address _resolverAddress, bytes memory _resolverData ) internal pure returns (bytes memory) { return abi.encode(_resolverAddress, _resolverData); } function _proxyModuleArg() internal pure returns (bytes memory) { return bytes(""); } function _singleExecModuleArg() internal pure returns (bytes memory) { return bytes(""); } function _web3FunctionModuleArg( string memory _web3FunctionHash, bytes memory _web3FunctionArgsHex ) internal pure returns (bytes memory) { return abi.encode(_web3FunctionHash, _web3FunctionArgsHex); } function _timeTriggerModuleArg(uint128 _start, uint128 _interval) internal pure returns (bytes memory) { bytes memory triggerConfig = abi.encode(_start, _interval); return abi.encode(TriggerType.TIME, triggerConfig); } function _cronTriggerModuleArg(string memory _expression) internal pure returns (bytes memory) { bytes memory triggerConfig = abi.encode(_expression); return abi.encode(TriggerType.CRON, triggerConfig); } function _eventTriggerModuleArg( address _address, bytes32[][] memory _topics, uint256 _blockConfirmations ) internal pure returns (bytes memory) { bytes memory triggerConfig = abi.encode( _address, _topics, _blockConfirmations ); return abi.encode(TriggerType.EVENT, triggerConfig); } function _blockTriggerModuleArg() internal pure returns (bytes memory) { bytes memory triggerConfig = abi.encode(bytes("")); return abi.encode(TriggerType.BLOCK, triggerConfig); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.14; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "./Types.sol"; /** * @dev Inherit this contract to allow your smart contract to * - Make synchronous fee payments. * - Have call restrictions for functions to be automated. */ // solhint-disable private-vars-leading-underscore abstract contract AutomateReady { IAutomate public immutable automate; address public immutable dedicatedMsgSender; address private immutable feeCollector; address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; /** * @dev * Only tasks created by _taskCreator defined in constructor can call * the functions with this modifier. */ modifier onlyDedicatedMsgSender() { require(msg.sender == dedicatedMsgSender, "Only dedicated msg.sender"); _; } /** * @dev * _taskCreator is the address which will create tasks for this contract. */ constructor(address _automate, address _taskCreator) { automate = IAutomate(_automate); IGelato gelato = IGelato(IAutomate(_automate).gelato()); feeCollector = gelato.feeCollector(); address proxyModuleAddress = IAutomate(_automate).taskModuleAddresses( Module.PROXY ); address opsProxyFactoryAddress = IProxyModule(proxyModuleAddress) .opsProxyFactory(); (dedicatedMsgSender, ) = IOpsProxyFactory(opsProxyFactoryAddress) .getProxyOf(_taskCreator); } /** * @dev * Transfers fee to gelato for synchronous fee payments. * * _fee & _feeToken should be queried from IAutomate.getFeeDetails() */ function _transfer(uint256 _fee, address _feeToken) internal { if (_feeToken == ETH) { (bool success, ) = feeCollector.call{value: _fee}(""); require(success, "_transfer: ETH transfer failed"); } else { SafeERC20.safeTransfer(IERC20(_feeToken), feeCollector, _fee); } } function _getFeeDetails() internal view returns (uint256 fee, address feeToken) { (fee, feeToken) = automate.getFeeDetails(); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.14; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./AutomateReady.sol"; import {AutomateModuleHelper} from "./AutomateModuleHelper.sol"; /** * @dev Inherit this contract to allow your smart contract * to be a task creator and create tasks. */ //solhint-disable const-name-snakecase //solhint-disable no-empty-blocks abstract contract AutomateTaskCreator is AutomateModuleHelper, AutomateReady { using SafeERC20 for IERC20; IGelato1Balance public constant gelato1Balance = IGelato1Balance(0x7506C12a824d73D9b08564d5Afc22c949434755e); constructor(address _automate) AutomateReady(_automate, address(this)) {} function _depositFunds1Balance( uint256 _amount, address _token, address _sponsor ) internal { if (_token == ETH) { ///@dev Only deposit ETH on goerli for now. require(block.chainid == 5, "Only deposit ETH on goerli"); gelato1Balance.depositNative{value: _amount}(_sponsor); } else { ///@dev Only deposit USDC on polygon for now. require( block.chainid == 137 && _token == address(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174), "Only deposit USDC on polygon" ); IERC20(_token).approve(address(gelato1Balance), _amount); gelato1Balance.depositToken(_sponsor, _token, _amount); } } function _createTask( address _execAddress, bytes memory _execDataOrSelector, ModuleData memory _moduleData, address _feeToken ) internal returns (bytes32) { return automate.createTask( _execAddress, _execDataOrSelector, _moduleData, _feeToken ); } function _cancelTask(bytes32 _taskId) internal { automate.cancelTask(_taskId); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.12; enum Module { RESOLVER, DEPRECATED_TIME, PROXY, SINGLE_EXEC, WEB3_FUNCTION, TRIGGER } enum TriggerType { TIME, CRON, EVENT, BLOCK } struct ModuleData { Module[] modules; bytes[] args; } interface IAutomate { function createTask( address execAddress, bytes calldata execDataOrSelector, ModuleData calldata moduleData, address feeToken ) external returns (bytes32 taskId); function cancelTask(bytes32 taskId) external; function getFeeDetails() external view returns (uint256, address); function gelato() external view returns (address payable); function taskModuleAddresses(Module) external view returns (address); } interface IProxyModule { function opsProxyFactory() external view returns (address); } interface IOpsProxyFactory { function getProxyOf(address account) external view returns (address, bool); } interface IGelato1Balance { function depositNative(address _sponsor) external payable; function depositToken( address _sponsor, address _token, uint256 _amount ) external; } interface IGelato { function feeCollector() external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {IGelatoVRFConsumer} from "./IGelatoVRFConsumer.sol"; /// @title GelatoVRFConsumerBase /// @dev This contract can be inherit by upgradeable smart contracts as well. /// @dev This contract handles domain separation between consecutive randomness requests /// The contract has to be implemented by contracts willing to use the gelato VRF system. /// This base contract enhances the GelatoVRFConsumer by introducing request IDs and /// ensuring unique random values. /// for different request IDs by hashing them with the random number provided by drand. /// For security considerations, refer to the Gelato documentation. abstract contract GelatoVRFConsumerBase is IGelatoVRFConsumer { uint256 private constant _PERIOD = 3; uint256 private constant _GENESIS = 1692803367; bool[] public requestPending; mapping(uint256 => bytes32) public requestedHash; /// @notice Returns the address of the dedicated msg.sender. /// @dev The operator can be found on the Gelato dashboard after a VRF is deployed. /// @return Address of the operator. function _operator() internal view virtual returns (address); /// @notice User logic to handle the random value received. /// @param randomness The random number generated by Gelato VRF. /// @param requestId The ID for the randomness request. /// @param extraData Additional data from the randomness request. function _fulfillRandomness( uint256 randomness, uint256 requestId, bytes memory extraData ) internal virtual; /// @notice Requests randomness from the Gelato VRF. /// @dev The extraData parameter allows for additional data to be passed to /// the VRF, which is then forwarded to the callback. This is useful for /// request tracking purposes if requestId is not enough. /// @param extraData Additional data for the randomness request. /// @return requestId The ID for the randomness request. function _requestRandomness( bytes memory extraData ) internal returns (uint256 requestId) { requestId = uint256(requestPending.length); requestPending.push(); requestPending[requestId] = true; bytes memory data = abi.encode(requestId, extraData); uint256 round = _round(); bytes memory dataWithRound = abi.encode(round, data); bytes32 requestHash = keccak256(dataWithRound); requestedHash[requestId] = requestHash; emit RequestedRandomness(round, data); } /// @notice Callback function used by Gelato VRF to return the random number. /// The randomness is derived by hashing the provided randomness with the request ID. /// @param randomness The random number generated by Gelato VRF. /// @param dataWithRound Additional data provided by Gelato VRF containing request details. function fulfillRandomness( uint256 randomness, bytes calldata dataWithRound ) external { require(msg.sender == _operator(), "only operator"); (, bytes memory data) = abi.decode(dataWithRound, (uint256, bytes)); (uint256 requestId, bytes memory extraData) = abi.decode( data, (uint256, bytes) ); bytes32 requestHash = keccak256(dataWithRound); bool isValidRequestHash = requestHash == requestedHash[requestId]; require(requestPending[requestId], "request fulfilled or missing"); if (isValidRequestHash) { randomness = uint( keccak256( abi.encode( randomness, address(this), block.chainid, requestId ) ) ); _fulfillRandomness(randomness, requestId, extraData); requestPending[requestId] = false; delete requestedHash[requestId]; } delete requestedHash[requestId]; } /// @notice Computes and returns the round number of drand to request randomness from. function _round() private view returns (uint256 round) { // solhint-disable-next-line not-rely-on-time uint256 elapsedFromGenesis = block.timestamp - _GENESIS; uint256 currentRound = (elapsedFromGenesis / _PERIOD) + 1; round = block.chainid == 1 ? currentRound + 4 : currentRound + 1; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title IGelatoVRFConsumer /// @dev Interface for consuming random number provided by Drand. /// @notice This interface allows contracts to receive a random number provided by Gelato VRF. interface IGelatoVRFConsumer { /// @notice Event emitted when a randomness request is made. /// @param data The round of randomness to request. /// @param data Additional data associated with the request. event RequestedRandomness(uint256 round, bytes data); /// @notice Callback function used by Gelato to return the random number. /// @dev The random number is fetched from one among many drand endpoints /// and passed back to this function like in a Gelato Web3 Function. /// @param randomness The random number generated by drand. /// @param data Additional data provided by Gelato VRF or the user, typically unused. function fulfillRandomness( uint256 randomness, bytes calldata data ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.6.0; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; /// @dev Credit to Uniswap Labs under GPL-2.0-or-later license: /// https://github.com/Uniswap/v3-periphery library TransferHelper { /// @notice Transfers tokens from the targeted address to the given destination /// @notice Errors with 'STF' if transfer fails /// @param token The contract address of the token to be transferred /// @param from The originating address from which the tokens will be transferred /// @param to The destination address of the transfer /// @param value The amount to be transferred function safeTransferFrom( address token, address from, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call( abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value) ); require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF'); } /// @notice Transfers tokens from msg.sender to a recipient /// @dev Errors with ST if transfer fails /// @param token The contract address of the token which will be transferred /// @param to The recipient of the transfer /// @param value The value of the transfer function safeTransfer( address token, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST'); } /// @notice Approves the stipulated contract to spend the given allowance in the given token /// @dev Errors with 'SA' if transfer fails /// @param token The contract address of the token to be approved /// @param to The target of the approval /// @param value The amount of the given token the target will be allowed to spend function safeApprove( address token, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA'); } /// @notice Transfers NativeToken to the recipient address /// @dev Fails with `STE` /// @param to The destination of the transfer /// @param value The value to be transferred function safeTransferNative(address to, uint256 value) internal { (bool success, ) = to.call{value: value}(new bytes(0)); require(success, 'STE'); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.20; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/access/Ownable2Step.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "contracts/Libraries/TransferHelper.sol"; import "contracts/Integrations/Gelato/AutomateTaskCreator.sol"; import "contracts/SilverFees/SilverFeesGiveaway.sol"; struct ExactInputParams { bytes path; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; } interface IAlgebraSwapRouter { function exactInput(ExactInputParams memory data) external payable returns (uint256); } interface IAlgebraCommunityVault { function withdraw(address token, uint256 amount) external; function algebraFee() external view returns (uint16); } interface IAlgebraPool { function communityVault() external view returns (address); } interface IAlgebraNFTPositionManager { function balanceOf(address owner) external view returns (uint256); } // Fees redistribution data struct FeesRedistributionData { uint256 agWeeklyGiveawayAmount; uint256 wrappedTokenWeeklyGiveawayAmount; uint256 agFlareAmount; uint256 wrappedTokenFlareAmount; uint256 agSnatchAmount; uint256 wrappedTokenSnatchAmount; } // Fees management struct FeesManagementData { uint256 teamFees; uint256 weeklyGiveawayFees; uint256 buybackFees; FeesRedistributionData redistributionData; mapping (address => bool) flareWhitelistedTokens; address[] flareTokenToUnwhitelist; uint256 flareProgramPercentage; address bannedFlareUser; bool flareEnded; bool snatchEnded; string flareCID; string snatchCID; bool swapChanged; bool swapToWrappedToken; uint256 firstExecution; uint256 lastExecution; bytes32 taskId; } // Sync fees management struct SyncFeesManagementData { uint256 time; uint256 lastSync; uint256 nextSync; bytes32 taskId; } // Fees converter struct FeesTokenData { mapping(address => bytes32) taskId; string scriptCID; } // Bid data struct BidData { uint256 amount; uint256 timestamp; } // Flare datas struct FlareData { address user; uint256 bidAmount; address buybackToken; mapping (address=>BidData) lastBid; bytes32 taskId; } // Snatch datas struct SnatchPerPoolData { address user; uint256 bidAmount; } struct SnatchData { SnatchPerPoolData perPoolData; mapping (address=>BidData) lastBid; uint256 lastExecution; address bannedUser; bytes32 taskId; } /// @title SilverFees /// @author github.com/SifexPro /// @notice Contract for the fees management of Silver contract SilverFees is AutomateTaskCreator, Ownable2Step { SilverFeesGiveaway public silverFeesGiveaway; // Utils variables IERC20 public silverToken; IERC20 public wrappedToken; address public burnAddress; address public flareProgramAddress; address public teamMultisig; IAlgebraSwapRouter public swapRouter; IAlgebraCommunityVault public communityVault; IAlgebraNFTPositionManager public nftPositionManager; // All datas structures FeesManagementData public feesManagementData; SyncFeesManagementData public syncFeesManagementData; FeesTokenData public feesTokenData; FlareData public flareData; mapping (address => SnatchData) public snatchData; mapping(address => bool) public snatchIsPoolBided; address[] public snatchPoolsBids; // Events event FeesManagementExecuted(uint256 forTeam, uint256 forWeeklyGiveaway, uint256 forBuyback); event SyncFeesStarted(); event SyncFeesManagement(uint256 indexed timestamp); event TokensBurned(uint256 amount); event FeesTokenAdded(address indexed token, bytes32 taskId); event FeesTokenRemoved(address indexed token); event FeesTokenSwapped(address indexed token, uint256 amountIn, uint256 amountOut); event FlareAuction(address indexed user, uint256 auctionAmount); event FlareExecution(address indexed user, uint256 buybackAmount, uint256 programAmount); event FlareBuyback(address indexed token, uint256 amount); event SnatchAuction(address indexed user, address indexed poolToSteal, uint256 auctionAmount); event SnatchExecution(address indexed user, address indexed poolToSteal); event SnatchSteal(address indexed user, address indexed rewardsPool, address rewardsToken, uint256 rewardsAmount); // Events for misc event SwapToWrappedToken(bool swapToWrappedToken); event SwapTypeChanged(); event WithdrawnNative(address indexed to, uint256 amount); event WithdrawnToken(address indexed token, address to, uint256 amount); event EditedTeamMultisig(address indexed teamMultisig); event EditedFees(uint256 teamFees, uint256 weeklyGiveawayFees, uint256 buybackFees); // Gelato events event GelatoTaskCreated(bytes32 id); event GelatoTaskCanceled(bytes32 id); event GelatoTaskCancelFailed(bytes32 id); event GelatoFeesCheck(uint256 fees, address token); // Constructor constructor(address _silver, address _silverFeesGiveaway, address _burnAddress, address _flareProgramAddress, address _swapRouter, address _nftPositionManager, address _communityVault, address _teamMultisig, address _automate, address _wrappedToken, string memory _flareCID, string memory _snatchCID, string memory _feesTokenCID) AutomateTaskCreator(_automate) Ownable(msg.sender) { silverToken = IERC20(payable(_silver)); wrappedToken = IERC20(payable(_wrappedToken)); burnAddress = _burnAddress; flareProgramAddress = _flareProgramAddress; teamMultisig = _teamMultisig; swapRouter = IAlgebraSwapRouter(payable(_swapRouter)); communityVault = IAlgebraCommunityVault(payable(_communityVault)); nftPositionManager = IAlgebraNFTPositionManager(payable(_nftPositionManager)); silverFeesGiveaway = SilverFeesGiveaway(payable(_silverFeesGiveaway)); feesManagementData.teamFees = 12; // 12% for team feesManagementData.weeklyGiveawayFees = 3; // 3% for weekly giveaway feesManagementData.buybackFees = 85; // 85% for buyback feesManagementData.flareProgramPercentage = 0; feesManagementData.flareCID = _flareCID; feesManagementData.snatchCID = _snatchCID; feesManagementData.swapToWrappedToken = true; feesTokenData.scriptCID = _feesTokenCID; } // Fees management /** * @dev Main function (to manage the fees) scheduled with Gelato by the sync system (10 min after the last sync) */ function executeFeesManagement() public onlyDedicatedMsgSender { require(block.timestamp >= feesManagementData.lastExecution + syncFeesManagementData.time - 5 minutes, "Too early"); // Balance uint256 balance; if (feesManagementData.swapToWrappedToken) balance = tokenAmount(address(wrappedToken)) - feesManagementData.redistributionData.wrappedTokenWeeklyGiveawayAmount - feesManagementData.redistributionData.wrappedTokenFlareAmount - feesManagementData.redistributionData.wrappedTokenSnatchAmount; else balance = tokenAmount(address(silverToken)) - feesManagementData.redistributionData.agWeeklyGiveawayAmount - feesManagementData.redistributionData.agFlareAmount - feesManagementData.redistributionData.agSnatchAmount; // Fees uint256 teamFees = (balance * feesManagementData.teamFees) / 100; uint256 weeklyGiveawayFees = (balance * feesManagementData.weeklyGiveawayFees) / 100; uint256 buybackFees = balance - teamFees - weeklyGiveawayFees; uint256 flareFees = buybackFees / 2; uint256 snatchFees = buybackFees - flareFees; // Redistribution if (feesManagementData.swapToWrappedToken) { SafeERC20.safeTransfer(wrappedToken, teamMultisig, teamFees); feesManagementData.redistributionData.wrappedTokenWeeklyGiveawayAmount += weeklyGiveawayFees; feesManagementData.redistributionData.wrappedTokenFlareAmount += flareFees; feesManagementData.redistributionData.wrappedTokenSnatchAmount += snatchFees; } else { SafeERC20.safeTransfer(silverToken, teamMultisig, teamFees); feesManagementData.redistributionData.agWeeklyGiveawayAmount += weeklyGiveawayFees; feesManagementData.redistributionData.agFlareAmount += flareFees; feesManagementData.redistributionData.agSnatchAmount += snatchFees; } // Giveaway if (silverFeesGiveaway.checkExecuteGiveaway()) drawWinner(); // Flare if (feesManagementData.flareEnded && flareData.user != address(0)) executeFlare(); feesManagementData.flareEnded = false; // Snatch if (feesManagementData.snatchEnded && snatchPoolsBids.length > 0) { for (uint256 i = 0; i < snatchPoolsBids.length; i++) { executeSnatch(snatchPoolsBids[i]); snatchIsPoolBided[snatchPoolsBids[i]] = false; } delete snatchPoolsBids; } feesManagementData.snatchEnded = false; // Fees management data update if (feesManagementData.swapChanged) { feesManagementData.swapChanged = false; feesManagementData.swapToWrappedToken = !feesManagementData.swapToWrappedToken; emit SwapToWrappedToken(feesManagementData.swapToWrappedToken); } feesManagementData.lastExecution = block.timestamp; // Gelato fees (uint256 fee, address feeToken) = _getFeeDetails(); _transfer(fee, feeToken); emit GelatoFeesCheck(fee, feeToken); feesManagementData.taskId = bytes32(""); emit FeesManagementExecuted(teamFees, weeklyGiveawayFees, buybackFees); } // Sync fees management /** * @dev Sync the fees management */ function syncFeesManagement() public onlyDedicatedMsgSender { silverFeesGiveaway.syncGiveaway(); // Sync the giveaway if (flareData.user != address(0)) feesManagementData.flareEnded = true; // End the flare auction if (snatchPoolsBids.length > 0) feesManagementData.snatchEnded = true; // End the snatch auction syncFeesManagementData.lastSync = block.timestamp; syncFeesManagementData.nextSync = block.timestamp + syncFeesManagementData.time; createTaskFeesManagement(); // Create the task for executeFeesManagement() (10 min) // Gelato fees (uint256 fee, address feeToken) = _getFeeDetails(); _transfer(fee, feeToken); emit GelatoFeesCheck(fee, feeToken); emit SyncFeesManagement(block.timestamp); } /** * @dev Start the sync system * @param time Time between each sync * @notice The sync system will execute the syncFeesManagement() function every time seconds (12 hours by default) */ function startSyncSystem(uint256 time) public onlyOwner { require(time == 0 || time >= 1200, "Time too low"); syncFeesManagementData.time = time; syncFeesManagementData.lastSync = block.timestamp; syncFeesManagementData.nextSync = block.timestamp + time; feesManagementData.firstExecution = block.timestamp; feesManagementData.lastExecution = block.timestamp; cancelTask(flareData.taskId); cancelTask(feesManagementData.taskId); cancelTask(syncFeesManagementData.taskId); delete flareData; for (uint256 i = 0; i < snatchPoolsBids.length; i++) { cancelTaskSnatch(snatchPoolsBids[i]); delete snatchData[snatchPoolsBids[i]].perPoolData; snatchData[snatchPoolsBids[i]].lastExecution = 0; snatchIsPoolBided[snatchPoolsBids[i]] = false; } delete snatchPoolsBids; feesManagementData.flareEnded = false; feesManagementData.snatchEnded = false; if (time != 0) { silverFeesGiveaway.startSyncGiveaway(); createTaskSyncSystem(); } emit SyncFeesStarted(); } function syncFeesTime() public view returns (uint256) { return syncFeesManagementData.time; } function syncFeesLastSync() public view returns (uint256) { return syncFeesManagementData.lastSync; } // Tokens fees converter /** * @dev Swap the fees token to WrappedToken or $AG * @param tokenAddress Token to swap * @param swapArgs Swap arguments * @notice Executed by a gelato task when SyncFeesManagement event is emitted */ function swapFeesToken(address tokenAddress, ExactInputParams memory swapArgs) public onlyDedicatedMsgSender { uint256 amountIn; uint256 amountOut; uint256 balanceBefore; uint256 balanceAfter; if (feesManagementData.swapToWrappedToken) balanceBefore = tokenAmount(address(wrappedToken)); else balanceBefore = tokenAmount(address(silverToken)); communityVault.withdraw(tokenAddress, swapArgs.amountIn); if (!(feesManagementData.swapToWrappedToken && tokenAddress == address(wrappedToken) || !feesManagementData.swapToWrappedToken && tokenAddress == address(silverToken))) { swapArgs.recipient = payable(address(this)); swapArgs.amountIn = tokenAmount(tokenAddress); TransferHelper.safeApprove(address(tokenAddress), address(swapRouter), swapArgs.amountIn); swapRouter.exactInput(swapArgs); } if (feesManagementData.swapToWrappedToken) balanceAfter = tokenAmount(address(wrappedToken)); else balanceAfter = tokenAmount(address(silverToken)); amountIn = swapArgs.amountIn; amountOut = balanceAfter - balanceBefore; // Gelato fees (uint256 fee, address feeToken) = _getFeeDetails(); _transfer(fee, feeToken); emit GelatoFeesCheck(fee, feeToken); emit FeesTokenSwapped(tokenAddress, amountIn, amountOut); } /** * @dev Add a token to the fees converter system * @param tokenAddress Token to add * @notice The token must be in the community vault */ function addFeesToken(address tokenAddress) public onlyOwner { require(feesTokenData.taskId[tokenAddress] == bytes32(""), "Already added"); createTaskFeesToken(tokenAddress); bytes32 taskId = feesTokenData.taskId[tokenAddress]; emit FeesTokenAdded(tokenAddress, taskId); } function removeFeesToken(address tokenAddress) public onlyOwner { require(feesTokenData.taskId[tokenAddress] != bytes32(""), "Not added"); _cancelTask(feesTokenData.taskId[tokenAddress]); feesTokenData.taskId[tokenAddress] = bytes32(""); emit FeesTokenRemoved(tokenAddress); } function tokenAmountVault(address tokenAddress) public view returns (uint256) { IERC20 token = IERC20(tokenAddress); uint256 balance = token.balanceOf(address(communityVault)); return (balance); } function tokenAmount(address tokenAddress) public view returns (uint256) { IERC20 token = IERC20(tokenAddress); uint256 balance = token.balanceOf(address(this)); return (balance); } function isSwapToWrappedToken() public view returns (bool) { return (feesManagementData.swapToWrappedToken); } function feesTokenTaskId(address tokenAddress) public view returns (bytes32) { return feesTokenData.taskId[tokenAddress]; } // Weekly giveaway /** * @dev Buy tickets for the weekly giveaway * @param _amount Amount in $AG of tickets to buy, by default 1 ticket = 1 $AG */ function buyTickets(uint256 _amount) public onlyLpUser { silverFeesGiveaway.buyTickets(_amount, msg.sender); } /** * @dev Draw the winner of the weekly giveaway * @notice The winner will receive the weekly giveaway amount */ function drawWinner() public onlyDedicatedMsgSender { bool _isSwapToWrappedToken = feesManagementData.swapToWrappedToken; uint256 weeklyGiveawayAmount; if (_isSwapToWrappedToken) { weeklyGiveawayAmount = feesManagementData.redistributionData.wrappedTokenWeeklyGiveawayAmount; feesManagementData.redistributionData.wrappedTokenWeeklyGiveawayAmount = 0; TransferHelper.safeApprove(address(wrappedToken), address(silverFeesGiveaway), weeklyGiveawayAmount); } else { weeklyGiveawayAmount = feesManagementData.redistributionData.agWeeklyGiveawayAmount; feesManagementData.redistributionData.agWeeklyGiveawayAmount = 0; TransferHelper.safeApprove(address(silverToken), address(silverFeesGiveaway), weeklyGiveawayAmount); } silverFeesGiveaway.executeGiveaway(_isSwapToWrappedToken, weeklyGiveawayAmount); } function buyTicketsBurn(address _user, uint256 _amount) external { require(msg.sender == address(silverFeesGiveaway), "Only FeesGiveaway"); bool success = silverToken.transferFrom(_user, address(this), _amount); require(success, "Transfer failed"); burnTokens(_amount); } // Flare /** * @dev Flare auction * @param _amountToBurn Amount of $AG to burn * @param buybackToken Token to buyback */ function flare(uint256 _amountToBurn, address buybackToken) public onlyLpUser { require(!feesManagementData.flareEnded, "Ended"); require(feesManagementData.bannedFlareUser != msg.sender, "Banned"); require(flareIsWhitelistedToken(buybackToken), "Not whitelisted token"); uint256 rounding = 1 ether / 10; uint256 roundAmount = _amountToBurn / rounding; uint256 amountToBurn = roundAmount * rounding; require(amountToBurn > flareData.bidAmount, "Bid too low"); require(amountToBurn >= rounding, "< 0.1 $AG"); uint256 balance = silverToken.balanceOf(msg.sender); require(balance >= amountToBurn, "Not enough balance"); uint256 allowance = silverToken.allowance(msg.sender, address(this)); require(allowance >= amountToBurn, "Not enough allowance"); flareData.user = msg.sender; flareData.bidAmount = amountToBurn; flareData.buybackToken = buybackToken; flareData.lastBid[msg.sender] = BidData(amountToBurn, block.timestamp); emit FlareAuction(msg.sender, amountToBurn); } /** * @dev Flare's execute function */ function executeFlare() public onlyDedicatedMsgSender { require(feesManagementData.flareEnded, "Too early"); address user = flareData.user; uint256 amountToBurn = flareData.bidAmount; uint256 balance = silverToken.balanceOf(user); uint256 allowance = silverToken.allowance(user, address(this)); if (balance < amountToBurn || allowance < amountToBurn) { feesManagementData.bannedFlareUser = user; delete flareData; return; } bool success = silverToken.transferFrom(user, address(this), amountToBurn); require(success, "Transfer failed"); burnTokens(amountToBurn); uint256 flareAmountBuyback; uint256 flareAmountProgram; if (feesManagementData.swapToWrappedToken) { flareAmountProgram = (feesManagementData.redistributionData.wrappedTokenFlareAmount * feesManagementData.flareProgramPercentage) / 100; flareAmountBuyback = feesManagementData.redistributionData.wrappedTokenFlareAmount - flareAmountProgram; feesManagementData.redistributionData.wrappedTokenFlareAmount = 0; if (flareAmountProgram > 0) SafeERC20.safeTransfer(wrappedToken, flareProgramAddress, flareAmountProgram); } else { flareAmountProgram = (feesManagementData.redistributionData.agFlareAmount * feesManagementData.flareProgramPercentage) / 100; flareAmountBuyback = feesManagementData.redistributionData.agFlareAmount - flareAmountProgram; feesManagementData.redistributionData.agFlareAmount = 0; if (flareAmountProgram > 0) SafeERC20.safeTransfer(silverToken, flareProgramAddress, flareAmountProgram); } feesManagementData.bannedFlareUser = address(0); address buybackToken = flareData.buybackToken; delete flareData; createTaskFlareBuyback(buybackToken, flareAmountBuyback); emit FlareExecution(user, flareAmountBuyback, flareAmountProgram); } /** * @dev Flare's buyback function (after the auction when executeFeeManagement is called) * @param tokenToSwap Token to swap * @param swapArgs Swap arguments */ function flareBuyback(address tokenToSwap, address tokenAddress, ExactInputParams memory swapArgs) public onlyDedicatedMsgSender { if (swapArgs.amountIn != 0 && tokenToSwap != tokenAddress && flareIsWhitelistedToken(tokenAddress)) { swapArgs.recipient = payable(teamMultisig); TransferHelper.safeApprove(address(tokenToSwap), address(swapRouter), swapArgs.amountIn); swapRouter.exactInput(swapArgs); } else if (swapArgs.amountIn != 0 && tokenToSwap == tokenAddress && flareIsWhitelistedToken(tokenAddress)) { bool success = IERC20(tokenToSwap).transfer(teamMultisig, swapArgs.amountIn); require(success, "Transfer failed"); } for (uint256 i = 0; i < feesManagementData.flareTokenToUnwhitelist.length && i < 10; i++) feesManagementData.flareWhitelistedTokens[feesManagementData.flareTokenToUnwhitelist[i]] = false; delete feesManagementData.flareTokenToUnwhitelist; // Gelato fees (uint256 fee, address feeToken) = _getFeeDetails(); _transfer(fee, feeToken); emit GelatoFeesCheck(fee, feeToken); flareData.taskId = bytes32(""); emit FlareBuyback(tokenToSwap, swapArgs.amountIn); } function flareAddWhitelistedToken(address token) public onlyOwner { require(!flareIsWhitelistedToken(token), "Already whitelisted"); feesManagementData.flareWhitelistedTokens[token] = true; } function flareRemoveWhitelistedToken(address token) public onlyOwner { require(flareIsWhitelistedToken(token), "Not whitelisted"); if (flareData.buybackToken == token) feesManagementData.flareTokenToUnwhitelist.push(token); else feesManagementData.flareWhitelistedTokens[token] = false; } function flareIsWhitelistedToken(address token) public view returns (bool) { return feesManagementData.flareWhitelistedTokens[token]; } function flareLastBid(address user) public view returns (uint256) { if (flareData.lastBid[user].timestamp > feesManagementData.lastExecution) return flareData.lastBid[user].amount; return 0; } // Snatch /** * @dev Snatch auction * @param _amountToBurn Amount of $AG to burn * @param poolToSteal Pool to steal 50% of swap fees */ function snatch(uint256 _amountToBurn, address poolToSteal) public onlyLpUser { require(!feesManagementData.snatchEnded, "Ended"); require(snatchData[poolToSteal].bannedUser != msg.sender, "Banned"); require(IAlgebraPool(poolToSteal).communityVault() == address(communityVault), "Invalid pool"); uint256 rounding = 1 ether / 10; uint256 roundAmount = _amountToBurn / rounding; uint256 amountToBurn = roundAmount * rounding; require(amountToBurn > snatchData[poolToSteal].perPoolData.bidAmount, "Bid too low"); require(amountToBurn >= rounding, "< 0.1 $AG"); uint256 balance = silverToken.balanceOf(msg.sender); require(balance >= amountToBurn, "Not enough balance"); uint256 allowance = silverToken.allowance(msg.sender, address(this)); require(allowance >= amountToBurn, "Not enough allowance"); if (!snatchIsPoolBided[poolToSteal]) { snatchPoolsBids.push(poolToSteal); snatchIsPoolBided[poolToSteal] = true; } if (snatchData[poolToSteal].lastExecution == 0) snatchData[poolToSteal].lastExecution = feesManagementData.firstExecution; snatchData[poolToSteal].perPoolData.user = msg.sender; snatchData[poolToSteal].perPoolData.bidAmount = amountToBurn; snatchData[poolToSteal].lastBid[msg.sender] = BidData(amountToBurn, block.timestamp); emit SnatchAuction(msg.sender, poolToSteal, amountToBurn); } /** * @dev Snatch's execute function */ function executeSnatch(address poolToSteal) public onlyDedicatedMsgSender { require(feesManagementData.snatchEnded, "Too early"); address user = snatchData[poolToSteal].perPoolData.user; uint256 amountToBurn = snatchData[poolToSteal].perPoolData.bidAmount; uint256 balance = silverToken.balanceOf(user); uint256 allowance = silverToken.allowance(user, address(this)); if (balance < amountToBurn || allowance < amountToBurn) { snatchData[poolToSteal].bannedUser = user; delete snatchData[poolToSteal].perPoolData; return; } bool success = silverToken.transferFrom(user, address(this), amountToBurn); require(success, "Transfer failed"); burnTokens(amountToBurn); snatchData[poolToSteal].bannedUser = address(0); delete snatchData[poolToSteal].perPoolData; createTaskSnatchSteal(user, poolToSteal); emit SnatchExecution(user, poolToSteal); } /** * @dev Snatch's steal function (after the auction when executeFeeManagement is called) * @param user User to send the rewards * @param rewardsPool Pool to steal * @param rewardsToken Token to send * @param rewardsAmount Amount to send */ function snatchSteal(address user, address rewardsPool, address rewardsToken, uint256 rewardsAmount) public onlyDedicatedMsgSender { if (rewardsToken == address(wrappedToken)) { require(wrappedToken.transfer(user, rewardsAmount), "Transfer failed"); if (rewardsAmount > feesManagementData.redistributionData.wrappedTokenSnatchAmount) feesManagementData.redistributionData.wrappedTokenSnatchAmount = 0; else feesManagementData.redistributionData.wrappedTokenSnatchAmount -= rewardsAmount; } else if (rewardsToken == address(silverToken)) { require(silverToken.transfer(user, rewardsAmount), "Transfer failed"); if (rewardsAmount > feesManagementData.redistributionData.agSnatchAmount) feesManagementData.redistributionData.agSnatchAmount = 0; else feesManagementData.redistributionData.agSnatchAmount -= rewardsAmount; } snatchData[rewardsPool].lastExecution = block.timestamp; snatchData[rewardsPool].taskId = bytes32(""); // Gelato fees (uint256 fee, address feeToken) = _getFeeDetails(); _transfer(fee, feeToken); emit GelatoFeesCheck(fee, feeToken); emit SnatchSteal(user, rewardsPool, rewardsToken, rewardsAmount); } function snatchLastBid(address user, address pool) public view returns (uint256) { if (snatchData[pool].lastBid[user].timestamp > feesManagementData.lastExecution) return snatchData[pool].lastBid[user].amount; return 0; } // Get allowance /** * @dev Get all bids of a user * @param user User to check * @return totalBids Total bids of the user * @notice Include Flare and Snatch bids */ function getAllBids(address user) public view returns (uint256) { uint256 totalBids; totalBids += flareLastBid(user); for (uint256 i = 0; i < snatchPoolsBids.length; i++) totalBids += snatchLastBid(user, snatchPoolsBids[i]); return totalBids; } // Burn function /** * @dev Burn the Silver tokens (send to burn contract) * @param _amount Amount of $AG to burn */ function burnTokens(uint256 _amount) private { require(silverToken.transfer(burnAddress, _amount), "Burn failed"); emit TokensBurned(_amount); } // Gelato functions /** * @dev Create a task for the sync system * @notice The task will be executed every syncFeesManagementData.time seconds */ function createTaskSyncSystem() private { bytes memory execData = abi.encodeCall(this.syncFeesManagement, ()); ModuleData memory moduleData = ModuleData({ modules: new Module[](2), args: new bytes[](2) }); moduleData.modules[0] = Module.PROXY; moduleData.modules[1] = Module.TRIGGER; moduleData.args[0] = _proxyModuleArg(); moduleData.args[1] = _timeTriggerModuleArg( uint128(syncFeesManagementData.nextSync) * 1000, uint128(syncFeesManagementData.time) * 1000 ); bytes32 taskId = _createTask(address(this), execData, moduleData, ETH); syncFeesManagementData.taskId = taskId; emit GelatoTaskCreated(taskId); } /** * @dev Create task for executeFeesManagement function (SINGLE_EXEC) * @notice Created by the sync system * @notice The task will be executed 10 min after the last sync */ function createTaskFeesManagement() private { uint256 execTime = 10 minutes; bytes memory execData = abi.encodeCall(this.executeFeesManagement, ()); ModuleData memory moduleData = ModuleData({ modules: new Module[](3), args: new bytes[](3) }); moduleData.modules[0] = Module.PROXY; moduleData.modules[1] = Module.SINGLE_EXEC; moduleData.modules[2] = Module.TRIGGER; moduleData.args[0] = _proxyModuleArg(); moduleData.args[1] = _singleExecModuleArg(); moduleData.args[2] = _timeTriggerModuleArg( uint128(syncFeesManagementData.lastSync + execTime) * 1000, uint128(execTime) * 1000 ); bytes32 taskId = _createTask(address(this), execData, moduleData, ETH); feesManagementData.taskId = taskId; emit GelatoTaskCreated(taskId); } /** * @dev Create task for convert fees token to WrappedToken or $AG * @param tokenAddress Token to convert * @notice Executed by a gelato task when SyncFeesManagement event is emitted */ function createTaskFeesToken(address tokenAddress) private { bytes memory execData = abi.encode( Strings.toHexString(uint256(uint160(address(this))), 20), // contract address Strings.toHexString(uint256(uint160(tokenAddress)), 20), // tokenAddress Strings.toString(ERC20(tokenAddress).decimals()), // tokenDecimals Strings.toHexString(uint256(uint160(address(silverToken))), 20), // agAddress Strings.toHexString(uint256(uint160(address(wrappedToken))), 20), // wrappedTokenAddress Strings.toString(block.chainid) // network ); ModuleData memory moduleData = ModuleData({ modules: new Module[](3), args: new bytes[](3) }); moduleData.modules[0] = Module.PROXY; moduleData.modules[1] = Module.WEB3_FUNCTION; moduleData.modules[2] = Module.TRIGGER; moduleData.args[0] = _proxyModuleArg(); moduleData.args[1] = _web3FunctionModuleArg( feesTokenData.scriptCID, execData ); bytes32[][] memory topics = new bytes32[][](1); topics[0] = new bytes32[](1); topics[0][0] = keccak256("SyncFeesManagement(uint256)"); moduleData.args[2] = _eventTriggerModuleArg( address(this), topics, 7 ); bytes32 taskId = _createTask(address(this), execData, moduleData, ETH); feesTokenData.taskId[tokenAddress] = taskId; emit GelatoTaskCreated(taskId); } /** * @dev Create task for buyback function (after the auction) * @param tokenAddress Token to swap * @param buybackAmount Amount to buyback * @notice Task created when executeFlare is called and executed right after */ function createTaskFlareBuyback(address tokenAddress, uint256 buybackAmount) private { address addressToSwap; if (feesManagementData.swapToWrappedToken) addressToSwap = address(wrappedToken); else addressToSwap = address(silverToken); bytes memory execData = abi.encode( Strings.toHexString(uint256(uint160(address(this))), 20), // contract address Strings.toHexString((uint256(uint160(teamMultisig))), 20), // teamMultisig Strings.toHexString((uint256(uint160(tokenAddress))), 20), // tokenAddress Strings.toString(ERC20(tokenAddress).decimals()), // tokenDecimals Strings.toString(buybackAmount), // buybackAmount Strings.toHexString(uint256(uint160(address(addressToSwap))), 20), // addressToSwap Strings.toString(block.chainid) // network ); ModuleData memory moduleData = ModuleData({ modules: new Module[](3), args: new bytes[](3) }); moduleData.modules[0] = Module.PROXY; moduleData.modules[1] = Module.SINGLE_EXEC; moduleData.modules[2] = Module.WEB3_FUNCTION; moduleData.args[0] = _proxyModuleArg(); moduleData.args[1] = _singleExecModuleArg(); moduleData.args[2] = _web3FunctionModuleArg( feesManagementData.flareCID, execData ); bytes32 taskId = _createTask(address(this), execData, moduleData, ETH); flareData.taskId = taskId; emit GelatoTaskCreated(taskId); } /** * @dev Create task for snatchSteal function (after the auction) * @param user User that steal the fees * @param poolToSteal Pool from which to steal 50% of swap fees * @notice Task is executed right after creation */ function createTaskSnatchSteal(address user, address poolToSteal) private { address rewardsToken; uint256 timeToSteal = block.timestamp - snatchData[poolToSteal].lastExecution; if (feesManagementData.swapToWrappedToken) rewardsToken = address(wrappedToken); else rewardsToken = address(silverToken); bytes memory execData = abi.encode( Strings.toHexString(uint256(uint160(address(this))), 20), // contract address Strings.toHexString((uint256(uint160(user))), 20), // userAddress Strings.toString(timeToSteal), // timeToSteal Strings.toHexString((uint256(uint160(poolToSteal))), 20), // poolToSteal Strings.toHexString(uint256(uint160(address(rewardsToken))), 20), // rewardsToken Strings.toString(block.chainid) // network ); ModuleData memory moduleData = ModuleData({ modules: new Module[](3), args: new bytes[](3) }); moduleData.modules[0] = Module.PROXY; moduleData.modules[1] = Module.SINGLE_EXEC; moduleData.modules[2] = Module.WEB3_FUNCTION; moduleData.args[0] = _proxyModuleArg(); moduleData.args[1] = _singleExecModuleArg(); moduleData.args[2] = _web3FunctionModuleArg( feesManagementData.snatchCID, execData ); bytes32 taskId = _createTask(address(this), execData, moduleData, ETH); snatchData[poolToSteal].taskId = taskId; emit GelatoTaskCreated(taskId); } function cancelTaskCall(bytes32 taskId) public { require(msg.sender == address(this)); _cancelTask(taskId); } /** * @dev Cancel a gelato task * @param taskId Task id to cancel */ function cancelTask(bytes32 taskId) public onlyOwner { if (taskId == bytes32("")) return; (bool success, ) = address(this).call( abi.encodeWithSignature("cancelTaskCall(bytes32)", taskId) ); if (success) emit GelatoTaskCanceled(taskId); else emit GelatoTaskCancelFailed(taskId); if (taskId == syncFeesManagementData.taskId) syncFeesManagementData.taskId = bytes32(""); else if (taskId == feesManagementData.taskId) feesManagementData.taskId = bytes32(""); else if (taskId == flareData.taskId) flareData.taskId = bytes32(""); } /** * @dev Cancel a gelato task * @param pool Pool to cancel */ function cancelTaskSnatch(address pool) public onlyOwner { bytes32 taskId = snatchData[pool].taskId; if (taskId == bytes32("")) return; (bool success, ) = address(this).call( abi.encodeWithSignature("cancelTaskCall(bytes32)", taskId) ); if (success) emit GelatoTaskCanceled(taskId); else emit GelatoTaskCancelFailed(taskId); snatchData[pool].taskId = bytes32(""); } // Internal functions /** * @dev Change the swap fees to WrappedToken or $AG * @param swapToWrappedToken True if swap to WrappedToken, false if swap to $AG * @notice The change is not immediate, it will be applied at the next fees management */ function setSwapToWrappedToken(bool swapToWrappedToken) public onlyOwner { if (feesManagementData.swapToWrappedToken == swapToWrappedToken) feesManagementData.swapChanged = false; else feesManagementData.swapChanged = true; emit SwapTypeChanged(); } function withdrawNative(address _to) public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "No Native to withdraw"); address payable _tresory = payable(_to); (bool success, ) = _tresory.call{value:balance}(""); require(success, "Transaction failed"); emit WithdrawnNative(_tresory, balance); } function withdrawToken(address _token, address _to) public onlyOwner { IERC20 token = IERC20(_token); uint256 balance = token.balanceOf(address(this)); SafeERC20.safeTransfer(token, _to, balance); emit WithdrawnToken(_token, _to, balance); } function editMultisig(address _teamMultisig) public onlyMultisig { teamMultisig = _teamMultisig; emit EditedTeamMultisig(_teamMultisig); } function editSilver(address _silver) public onlyOwner { silverToken = IERC20(payable(_silver)); } function editSilverFeesGiveaway(address _silverFeesGiveaway) public onlyOwner { silverFeesGiveaway = SilverFeesGiveaway(payable(_silverFeesGiveaway)); } function editwrappedToken(address _wrappedToken) public onlyOwner { wrappedToken = IERC20(payable(_wrappedToken)); } function editFlareProgramAddress(address _flareProgramAddress) public onlyOwner { flareProgramAddress = _flareProgramAddress; } function editAlgebraSwapRouter(address _swapRouter) public onlyOwner { swapRouter = IAlgebraSwapRouter(payable(_swapRouter)); } function editCommunityVault(address _communityVault) public onlyOwner { communityVault = IAlgebraCommunityVault(payable(_communityVault)); } function editNftPositionManager(address _nftPositionManager) public onlyOwner { nftPositionManager = IAlgebraNFTPositionManager(payable(_nftPositionManager)); } function editFees(uint256 teamFees, uint256 weeklyGiveawayFees, uint256 buybackFees) public onlyOwner { require(teamFees + weeklyGiveawayFees + buybackFees == 100, "Invalid fees"); feesManagementData.teamFees = teamFees; feesManagementData.weeklyGiveawayFees = weeklyGiveawayFees; feesManagementData.buybackFees = buybackFees; emit EditedFees(teamFees, weeklyGiveawayFees, buybackFees); } function editFlareProgramPercentage(uint256 flareProgramPercentage) public onlyOwner { require(flareProgramPercentage <= 100); feesManagementData.flareProgramPercentage = flareProgramPercentage; } function editFlareCID(string memory flareCID) public onlyOwner { feesManagementData.flareCID = flareCID; } function editSnatchCID(string memory snatchCID) public onlyOwner { feesManagementData.snatchCID = snatchCID; } function editFeesTokenCID(string memory scriptCID) public onlyOwner { feesTokenData.scriptCID = scriptCID; } // Modifiers modifier onlyLpUser() { require(nftPositionManager.balanceOf(msg.sender) > 0, "Not LP user"); _; } modifier onlyMultisig() { require(msg.sender == teamMultisig, "Not authorized"); _; } // Receive function (to receive Native) receive() external payable {} }
{ "evmVersion": "paris", "optimizer": { "enabled": true, "runs": 10 }, "metadata": { "bytecodeHash": "none" }, "viaIR": true, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tickets","type":"uint256"}],"name":"BuyTickets","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"winner","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"randomIndex","type":"uint256"}],"name":"DrawWinner","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isGiveawayActive","type":"bool"}],"name":"EditedGiveawayActive","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"ticketPrice","type":"uint256"}],"name":"EditedGiveawayTicketPrice","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"giveawayTime","type":"uint256"}],"name":"EditedGiveawayTime","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"silverFees","type":"address"}],"name":"EditedSilverFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isGiveawayActive","type":"bool"},{"indexed":false,"internalType":"uint256","name":"weeklyGiveawayAmount","type":"uint256"}],"name":"GiveawayExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"ticketPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"giveawayEndTime","type":"uint256"}],"name":"GiveawaySyncStarted","type":"event"},{"anonymous":false,"inputs":[],"name":"GiveawaySynced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"randomness","type":"uint256"}],"name":"RequestFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"requestId","type":"uint256"}],"name":"RequestSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"RequestedRandomness","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"ticketPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"giveawayEndTime","type":"uint256"}],"name":"StartedGiveaway","type":"event"},{"anonymous":false,"inputs":[],"name":"StoppedGiveaway","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawnToken","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"user","type":"address"}],"name":"buyTickets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"checkExecuteGiveaway","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_ticketPrice","type":"uint256"}],"name":"editGiveawayTicketPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_giveawayTime","type":"uint256"}],"name":"editGiveawayTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_silverFees","type":"address"}],"name":"editSilverFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"isSwapToWrappedToken","type":"bool"},{"internalType":"uint256","name":"weeklyGiveawayAmount","type":"uint256"}],"name":"executeGiveaway","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"randomness","type":"uint256"},{"internalType":"bytes","name":"dataWithRound","type":"bytes"}],"name":"fulfillRandomness","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getRandomnessRequest","outputs":[{"components":[{"internalType":"bool","name":"requestSent","type":"bool"},{"internalType":"bool","name":"fulfilled","type":"bool"},{"internalType":"uint256","name":"pendingRequestId","type":"uint256"},{"internalType":"uint256","name":"latestRandomness","type":"uint256"},{"internalType":"uint256","name":"latestRequestId","type":"uint256"}],"internalType":"struct RandomnessRequest","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"giveawayData","outputs":[{"internalType":"uint256","name":"numberOfParticipants","type":"uint256"},{"internalType":"bool","name":"participationEnded","type":"bool"},{"internalType":"uint256","name":"giveawayEndTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"giveawaySettings","outputs":[{"internalType":"bool","name":"isGiveawayActive","type":"bool"},{"internalType":"uint256","name":"ticketPrice","type":"uint256"},{"internalType":"uint256","name":"giveawayTime","type":"uint256"},{"internalType":"bool","name":"editedActive","type":"bool"},{"internalType":"uint256","name":"editedTicketPrice","type":"uint256"},{"internalType":"uint256","name":"editedGiveawayTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"giveawayTicketsData","outputs":[{"internalType":"uint256","name":"lastExecution","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"randomnessRequest","outputs":[{"internalType":"bool","name":"requestSent","type":"bool"},{"internalType":"bool","name":"fulfilled","type":"bool"},{"internalType":"uint256","name":"pendingRequestId","type":"uint256"},{"internalType":"uint256","name":"latestRandomness","type":"uint256"},{"internalType":"uint256","name":"latestRequestId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requestPending","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requestedHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_giveawayActive","type":"bool"}],"name":"setActiveGiveaway","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"silverFees","outputs":[{"internalType":"contract SilverFees","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"startSyncGiveaway","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"syncGiveaway","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"userTickets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_to","type":"address"}],"name":"withdrawToken","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60a03461014f57601f6200227338819003918201601f19168301926001600160401b039290918385118386101761015457816020928492604097885283398101031261014f57516001600160a01b039190828116810361014f5733156101375760018060a01b03198060015416600155600093845491339083161785553391167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08580a360805282519060c082019081118282101761012357835260018152670de0b6b3a7640000908160208201528260a062093a80928387820152826060820152826080820152015260ff1991600183600b541617600b55600c55600d55600e5416600e5580600f556010555161210890816200016b8239608051816108140152f35b634e487b7160e01b83526041600452602483fd5b8351631e4fbdf760e01b815260006004820152602490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe60806040908082526004908136101561001757600080fd5b600090813560e01c908163149d8b8e1461151a5750806332b7083b146114e55780633aeac4e11461135b5780633e16d3dd146112dc57806340b226831461126e578063711332dc14610dd7578063715018a614610d8457806375ce7fff14610d4557806379ba509714610cd55780637a42d1c514610c3857806380017f4e14610c0b5780638942fc3114610bd95780638da5cb5b14610bb157806393b886c114610b62578063a48debd114610afd578063a527913e14610ad4578063b3f6b99a146107c5578063b6ec155b14610771578063b9c5a97814610722578063c4f8f27b146106f5578063e02ae8ce146106ab578063e30c397814610682578063e8177b861461065f578063f2fde38b146105f25763fdad3a5f1461013857600080fd5b346105ef57826003193601126105ef5781359261015361174a565b83546001600160a01b039590861661016c3382146118ee565b60ff600b5416156105b65760ff6007541661058b57600c5492838310610558578293801561054557808085049411610518575b50845163c34fe1dd60e01b815297602092838a8a81845afa998a1561050e57848a9b84928b9c9b916104f1575b5060248a51809481936370a0823160e01b8352818a169e8f90840152165afa908115610451579087918b916104c0575b501061048857865163c34fe1dd60e01b815284818c81855afa908115610451578a9161045b575b50848960448d868c519586948593636eb1769f60e11b8552840152876024840152165afa908115610451579087918b9161041c575b50106103e257803b156103de5788866102889285838e8c5196879586948593639e28bdcf60e01b85528401611d9d565b03925af180156103d4576103a7575b508390885b8281106103385750506102b76102bc92600554600655611dd3565b6119c3565b8451908186016001600160401b03811183821017610323577feb94184f338c573d1df2cb195ce1a83fc8fc5ffcc64d03de272232fb7aa183cf97989950865281526001828201428152888a5260098452868a2092518355519101558351928352820152a280f35b60418a634e487b7160e01b6000525260246000fd5b9091506005805490600160401b8210156103945760018201905561035b90611db8565b81549060031b90848b831b921b191617905560001981146103815760010190849161029c565b634e487b7160e01b895260118a52602489fd5b634e487b7160e01b8b5260418c5260248bfd5b9097906001600160401b0381116103c15786529638610297565b634e487b7160e01b825260418a52602482fd5b87513d8b823e3d90fd5b8880fd5b865162461bcd60e51b8152808b0185905260146024820152734e6f7420656e6f75676820616c6c6f77616e636560601b6044820152606490fd5b809250868092503d831161044a575b6104358183611856565b810103126104465786905138610258565b8980fd5b503d61042b565b88513d8c823e3d90fd5b61047b9150853d8711610481575b6104738183611856565b81019061192c565b38610223565b503d610469565b865162461bcd60e51b8152808b0185905260126024820152714e6f7420656e6f7567682062616c616e636560701b6044820152606490fd5b809250868092503d83116104ea575b6104d98183611856565b8101031261044657869051386101fc565b503d6104cf565b6105089150823d8411610481576104738183611856565b386101cc565b87513d8a823e3d90fd5b80919450830290838204148315171561053257923861019f565b634e487b7160e01b865260118752602486fd5b634e487b7160e01b875260128852602487fd5b845162461bcd60e51b8152602081890152600d60248201526c507269636520746f6f206c6f7760981b6044820152606490fd5b835162461bcd60e51b81526020818801526005602482015264115b99195960da1b6044820152606490fd5b835162461bcd60e51b815260208188015260136024820152724769766561776179206e6f742061637469766560681b6044820152606490fd5b80fd5b50346105ef5760203660031901126105ef5761060c61172f565b6106146117c3565b600180546001600160a01b0319166001600160a01b0392831690811790915582549091167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e227008380a380f35b50823461067e578160031936011261067e57602090600a549051908152f35b5080fd5b50823461067e578160031936011261067e5760015490516001600160a01b039091168152602090f35b50823461067e578160031936011261067e5760a09060115490601254601354906014549260ff8151958181161515875260081c161515602086015284015260608301526080820152f35b5091903461071e57602036600319011261071e5760209282913581526003845220549051908152f35b8280fd5b5091903461071e57602036600319011261071e577f68bff35e46d3206e18452a58ab63d15ddf725d0b38dfb1df3d4dab8e77f5d5659160209135906107656117c3565b8160105551908152a180f35b50823461067e578160031936011261067e5760c09060ff600b541690600c5490600d5460ff600e541690600f54926010549481519615158752602087015285015215156060840152608083015260a0820152f35b50823461067e578060031936011261067e576001600160401b0392602480359190858311610ad05736602384011215610ad0578282013592868411610acc5783810182810190368211610a92577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163303610a9a578287910312610a96576044820135888111610a9257820181604382011215610a925790816044856108769401359101611894565b938451850160209887878b84019303126103de57898701519688810151918211610446570181603f820112156103de5789810151916108b483611879565b906108c18a519283611856565b83825289848401011161044657916108e391898c6108ec9796950191016118cb565b83369201611894565b86815191012083865260038752848620541460ff6109098561176f565b90549060031b1c1615610a515761092b575b5050829360039184525281205580f35b83518681019083358252308682015246606082015284608082015260808152610953816117ef565b5190209160115491600160ff8416151503610a1c5784601254036109e4575050917f5c69e7026b653d8606b5613bb00fd8c4b0504b1cbe8db600c406faac180924d58486979361010060039661ff00191617601155806013558360145581519084825285820152a16109c48161176f565b60ff825491861b1b1916905580855282825284848120559181955061091b565b855162461bcd60e51b8152918201889052601390820152721c995c5d595cdd1259081b9bdd081d985b1a59606a1b6044820152606490fd5b855162461bcd60e51b81529182018890526010908201526f14995c5d595cdd081b9bdd081cd95b9d60821b6044820152606490fd5b845162461bcd60e51b8152808401889052601c818401527b726571756573742066756c66696c6c6564206f72206d697373696e6760201b6044820152606490fd5b8780fd5b8680fd5b865162461bcd60e51b8152602081870152600d818601526c37b7363c9037b832b930ba37b960991b6044820152606490fd5b8580fd5b8480fd5b5091903461071e578260031936011261071e575490516001600160a01b03909116815260209150f35b508290346105ef57806003193601126105ef5750610b2860209260018060a01b0390541633146118ee565b60ff600754169081610b52575b8115610b44575b519015158152f35b600b5460ff16159150610b3c565b60115460081c60ff169150610b35565b5091903461071e57602036600319011261071e577ff56ae34a736154a570ed8935e3feb13fc99a990bfd5c7ad6486f4cb126859f96916020913590610ba56117c3565b81600f5551908152a180f35b50823461067e578160031936011261067e57905490516001600160a01b039091168152602090f35b50903461067e578160031936011261067e5754610c00906001600160a01b031633146118ee565b610c086119e6565b80f35b50823461067e57602036600319011261067e57602090610c31610c2c61172f565b611dd3565b9051908152f35b50823461067e578160031936011261067e5760a09160808251610c5a816117ef565b828152826020820152828482015282606082015201528051610c7b816117ef565b60115460ff811615159283835260ff602084019260081c1615158252601254818401908152601354926060850193845260806014549501948552825195865251151560208601525190840152516060830152516080820152f35b50913461071e578260031936011261071e57600154916001600160a01b03913383851603610d2e5750506001600160a01b031991821660015582543392811683178455166000805160206120dc8339815191528380a380f35b60249250519063118cdaa760e01b82523390820152fd5b5091903461071e57602036600319011261071e5735916002548310156105ef575060ff610d7360209361176f565b92905490519260031b1c1615158152f35b50346105ef57806003193601126105ef57610d9d6117c3565b600180546001600160a01b03199081169091558154908116825581906001600160a01b03166000805160206120dc8339815191528280a380f35b50823461067e578060031936011261067e57610df1611760565b835460243591906001600160a01b03908116610e0e3382146118ee565b600b5460ff16808061125f575b1561110b57505060ff60075416156110dc576006549586156110a85760135496855197602098898101918252898152610e538161183b565b519020069180610e6284611db8565b90549060031b1c169360001461105c578154865163996c6cc360e01b815290821689828581845afa91821561105257610ebf92878b868e958c958395611033575b508d516323b872dd60e01b8152978896879586938d8501611963565b0393165af190811561050e57899291610edf918a91611006575b50611985565b60ff1960075416600755825416865192838092631e14e34360e31b82525afa8015610ffc578690610fcd575b610f199150600d54906119c3565b600855848451610f2881611820565b526005548560055580610fa9575b508385967f826bbd0fbc2baeb2244f7b5226338393b58c345e7dac64b39391b4e3b9b3813992600560008051602061207c833981519152985288600655610f7b61205f565b42600a55825191868352820152a25b610f92611e76565b60ff600b541690825191151582526020820152a180f35b60058652868620908101905b818110610fc25750610f36565b868155600101610fb5565b508681813d8311610ff5575b610fe38183611856565b81010312610acc57610f199051610f0b565b503d610fd9565b85513d88823e3d90fd5b6110269150843d861161102c575b61101e8183611856565b81019061194b565b8b610ed9565b503d611014565b61104b919550873d8911610481576104738183611856565b9338610ea3565b88513d8b823e3d90fd5b8154865163c34fe1dd60e01b815290821689828581845afa91821561105257610ebf92878b868e958c95839561103357508d516323b872dd60e01b8152978896879586938d8501611963565b606490602086519162461bcd60e51b8352820152600e60248201526d30207061727469636970616e747360901b6044820152fd5b835162461bcd60e51b81526020818801526009602482015268546f6f206561726c7960b81b6044820152606490fd5b9695969290919215611131575b50505060008051602061207c8339815191529250610f8a565b15611211575080845416938584519263996c6cc360e01b845260209687858581845afa948515611207579261118a9592899592889583956111e8575b5089516323b872dd60e01b81529788968795869330918501611963565b0393165af19384156111de57936111b99160008051602061207c8339815191529587926111c1575b5050611985565b848080611118565b6111d79250803d1061102c5761101e8183611856565b86806111b2565b83513d87823e3d90fd5b611200919550873d8911610481576104738183611856565b938c61116d565b87513d85823e3d90fd5b938584519263c34fe1dd60e01b845260209687858581845afa948515611207579261118a9592899592889583956111e8575089516323b872dd60e01b81529788968795869330918501611963565b5060ff60115460081c16610e1b565b50913461071e57602036600319011261071e577f1647043f27b6ab91a262baccf5e4b2dd4085e0ecea7e9885b6f6d329a0a6851a916020916112ae61172f565b6112b66117c3565b82546001600160a01b0319166001600160a01b039190911690811790925551908152a180f35b50823461067e57602036600319011261067e5760207fd1eac0a1c82fb301a1760f4bbacb6db64acaf2e4eebb26b7b1d11d267498a88c9161131b611760565b906113246117c3565b600b549115159160ff16151582036113495760ff19600e5416600e555b51908152a180f35b600160ff19600e541617600e55611341565b50903461067e578260031936011261067e5761137561172f565b9061137e61174a565b916113876117c3565b84516370a0823160e01b815230838201526001600160a01b039190911692909160208084602481885afa9384156114db5786946114ac575b50611428868089518481019063a9059cbb60e01b82526113f5816113e78b8b60248401611d9d565b03601f198101835282611856565b5190828a5af13d156114a4573d9061140c82611879565b916114198b519384611856565b82523d898584013e5b87611e13565b805191821515928361148b575b505050611474575061146e7f11dd463c4f2edd676b85f050130c7ab2f5832f52becb5444b09a92404aa1498a9394955192839283611d9d565b0390a280f35b8551635274afe760e01b8152908101849052602490fd5b61149b935082018101910161194b565b15388080611435565b606090611422565b9080945081813d83116114d4575b6114c48183611856565b81010312610acc575192386113bf565b503d6114ba565b87513d88823e3d90fd5b50823461067e578160031936011261067e576060906006549060ff600754169060085491815193845215156020840152820152f35b8285853461071e578260031936011261071e5782546001600160a01b039490851633148015611723575b156116eb5750611552611e76565b81519061155e82611820565b838252848154169183518093631e14e34360e31b8252818460209687935afa8015610ffc5786906116bc575b6115989150600d54906119c3565b8451909290916001600160401b039060808401828111858210176116a9578752808452858401928884526060888601958a875201958652815192831161169657600160401b8311611696575085906005548360055580841061166d575b500160058852858820885b83811061165957505050507fc848b8758eef2575b37a79281d279c80506ed2e7fdfc9d6a1d61da8b60e9c68d9596505160065551151560ff8019600754169116176007555180600855600c54918351928352820152a180f35b82518b168282015591870191600101611600565b60058a5283838b2091820191015b81811061168857506115f5565b8a815588935060010161167b565b634e487b7160e01b895260419052602488fd5b634e487b7160e01b895260418452602489fd5b508381813d83116116e4575b6116d28183611856565b81010312610acc57611598905161158a565b503d6116c8565b602060649262461bcd60e51b8352820152601560248201527427b7363c9029b4b63b32b92332b2b997a7bbb732b960591b6044820152fd5b50848254163314611544565b600435906001600160a01b038216820361174557565b600080fd5b602435906001600160a01b038216820361174557565b60043590811515820361174557565b906002548210156117ad576002600052600582901c7f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0191601f1690565b634e487b7160e01b600052603260045260246000fd5b6000546001600160a01b031633036117d757565b60405163118cdaa760e01b8152336004820152602490fd5b60a081019081106001600160401b0382111761180a57604052565b634e487b7160e01b600052604160045260246000fd5b602081019081106001600160401b0382111761180a57604052565b604081019081106001600160401b0382111761180a57604052565b601f909101601f19168101906001600160401b0382119082101761180a57604052565b6001600160401b03811161180a57601f01601f191660200190565b9291926118a082611879565b916118ae6040519384611856565b829481845281830111611745578281602093846000960137010152565b60005b8381106118de5750506000910152565b81810151838201526020016118ce565b156118f557565b60405162461bcd60e51b815260206004820152600f60248201526e4f6e6c792053696c7665724665657360881b6044820152606490fd5b9081602091031261174557516001600160a01b03811681036117455790565b90816020910312611745575180151581036117455790565b6001600160a01b03918216815291166020820152604081019190915260600190565b1561198c57565b60405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606490fd5b919082018092116119d057565b634e487b7160e01b600052601160045260246000fd5b60ff600b541615611d9b57600480546040805163179bbedf60e21b81529290916020919082908590839082906001600160a01b03165afa938415611d9057600094611d61575b50600d54600194611a3f81871c426119c3565b6008548091101591828093611d56575b80611d49575b15611c86575050505060119283549360ff8516611c4d5760ff1994851686178155815160008582015284815292611a8b8461183b565b60025493600160401b851015611c385790611adc9291888601600255611ab08661176f565b5050611abb8661176f565b81549060031b9060ff8c831b921b191617905584519384918789840161202c565b0391611af0601f1993848101865285611856565b6364e62126194201428111611c2457600390049089820192838311611bca57600092468c03611bdc5760059192935001809311611bca5750509160008051602061209c833981519152916000805160206120bc83398151915296959493905b8451611b708882019282611b6487878761202c565b03908101835282611856565b51902085600052600387528460002055611b8e84519283928361202c565b0390a18160125551908152a160075416176007555b7fa82b306739f8d9062e2a6cb231e2b2b6010520832cf162c722a1c45c01ee3ce0600080a1565b634e487b7160e01b6000525260246000fd5b600201809411611c13575050509160008051602061209c833981519152916000805160206120bc8339815191529695949390611b4f565b634e487b7160e01b83525260249150fd5b5090634e487b7160e01b6000525260246000fd5b604182634e487b7160e01b6000525260246000fd5b5091606492519162461bcd60e51b8352820152601460248201527314995c5d595cdd08185b1c9958591e481cd95b9d60621b6044820152fd5b92969195509293508480611d3f575b15611caf575050505050601055611caa611e76565b611ba3565b84611d32575b84611ced575b50505050611cca575b50611ba3565b611cd261205f565b60ff1960075416600755601055611ce7611e76565b38611cc4565b929594935090916001600160ff1b0382168203611d1d57611d12939495501b906119c3565b421138808080611cbb565b601186634e487b7160e01b6000525260246000fd5b60075460ff169450611cb5565b5060065415611c95565b5060ff6011541615611a55565b506006541515611a4f565b90938282813d8311611d89575b611d788183611856565b810103126105ef5750519238611a2c565b503d611d6e565b83513d6000823e3d90fd5b565b6001600160a01b039091168152602081019190915260400190565b6005548110156117ad57600560005260206000200190600090565b6001600160a01b031660009081526009602052604090206001810154600a541080611e07575b611e035750600090565b5490565b5060ff600b5416611df9565b90611e3a5750805115611e2857805190602001fd5b604051630a12f52160e11b8152600490fd5b81511580611e6d575b611e4b575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b15611e43565b600f548061201e575b5060105480611f98575b50600e5460ff8116611e985750565b600b5460ff8082161516918260ff1980931617600b5516600e55600014611f715760048054604051631e14e34360e31b81529160209183919082906001600160a01b03165afa908115611f6557600091611f33575b506040611f1e7ff630826129f37a41796127d038cfae85fe120359ddd6f9b0da24ee9e8ea8d8ac92600d54906119c3565b80600855600c549082519182526020820152a1565b906020823d8211611f5d575b81611f4c60209383611856565b810103126105ef5750516040611eed565b3d9150611f3f565b6040513d6000823e3d90fd5b7f6f233cde5f47c07fa0d9895c54d2d2a3ab36f565c605df426bdd460a5bf3ea59600080a1565b60048054604051631e14e34360e31b81529160209183919082906001600160a01b03165afa8015611f65578290600090611fe8575b611fd792506119c3565b600855600d55600060105538611e89565b90506020823d8211612016575b8161200260209383611856565b810103126105ef575081611fd79151611fcd565b3d9150611ff5565b600c556000600f5538611e7f565b909160609282526040602083015261205381518092816040860152602086860191016118cb565b601f01601f1916010190565b61ffff196011541660115560006012556000601355600060145556fef311bc4329e14d73a88accc37c5045c49a8f9a4e7d84c49c2f657b6fc13e5e34d91fc3685b930310b008ec37d2334870cab88a023ed8cc628a2e2ccd4e55d2020cd21a41891ff04ecd9a8754bec97e2fb85d2a4e7694329d4dc364c796f23d068be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0a164736f6c6343000814000a0000000000000000000000007fece6ab0d1473b7e6abe52a3b155269c0f8e4f9
Deployed Bytecode
0x60806040908082526004908136101561001757600080fd5b600090813560e01c908163149d8b8e1461151a5750806332b7083b146114e55780633aeac4e11461135b5780633e16d3dd146112dc57806340b226831461126e578063711332dc14610dd7578063715018a614610d8457806375ce7fff14610d4557806379ba509714610cd55780637a42d1c514610c3857806380017f4e14610c0b5780638942fc3114610bd95780638da5cb5b14610bb157806393b886c114610b62578063a48debd114610afd578063a527913e14610ad4578063b3f6b99a146107c5578063b6ec155b14610771578063b9c5a97814610722578063c4f8f27b146106f5578063e02ae8ce146106ab578063e30c397814610682578063e8177b861461065f578063f2fde38b146105f25763fdad3a5f1461013857600080fd5b346105ef57826003193601126105ef5781359261015361174a565b83546001600160a01b039590861661016c3382146118ee565b60ff600b5416156105b65760ff6007541661058b57600c5492838310610558578293801561054557808085049411610518575b50845163c34fe1dd60e01b815297602092838a8a81845afa998a1561050e57848a9b84928b9c9b916104f1575b5060248a51809481936370a0823160e01b8352818a169e8f90840152165afa908115610451579087918b916104c0575b501061048857865163c34fe1dd60e01b815284818c81855afa908115610451578a9161045b575b50848960448d868c519586948593636eb1769f60e11b8552840152876024840152165afa908115610451579087918b9161041c575b50106103e257803b156103de5788866102889285838e8c5196879586948593639e28bdcf60e01b85528401611d9d565b03925af180156103d4576103a7575b508390885b8281106103385750506102b76102bc92600554600655611dd3565b6119c3565b8451908186016001600160401b03811183821017610323577feb94184f338c573d1df2cb195ce1a83fc8fc5ffcc64d03de272232fb7aa183cf97989950865281526001828201428152888a5260098452868a2092518355519101558351928352820152a280f35b60418a634e487b7160e01b6000525260246000fd5b9091506005805490600160401b8210156103945760018201905561035b90611db8565b81549060031b90848b831b921b191617905560001981146103815760010190849161029c565b634e487b7160e01b895260118a52602489fd5b634e487b7160e01b8b5260418c5260248bfd5b9097906001600160401b0381116103c15786529638610297565b634e487b7160e01b825260418a52602482fd5b87513d8b823e3d90fd5b8880fd5b865162461bcd60e51b8152808b0185905260146024820152734e6f7420656e6f75676820616c6c6f77616e636560601b6044820152606490fd5b809250868092503d831161044a575b6104358183611856565b810103126104465786905138610258565b8980fd5b503d61042b565b88513d8c823e3d90fd5b61047b9150853d8711610481575b6104738183611856565b81019061192c565b38610223565b503d610469565b865162461bcd60e51b8152808b0185905260126024820152714e6f7420656e6f7567682062616c616e636560701b6044820152606490fd5b809250868092503d83116104ea575b6104d98183611856565b8101031261044657869051386101fc565b503d6104cf565b6105089150823d8411610481576104738183611856565b386101cc565b87513d8a823e3d90fd5b80919450830290838204148315171561053257923861019f565b634e487b7160e01b865260118752602486fd5b634e487b7160e01b875260128852602487fd5b845162461bcd60e51b8152602081890152600d60248201526c507269636520746f6f206c6f7760981b6044820152606490fd5b835162461bcd60e51b81526020818801526005602482015264115b99195960da1b6044820152606490fd5b835162461bcd60e51b815260208188015260136024820152724769766561776179206e6f742061637469766560681b6044820152606490fd5b80fd5b50346105ef5760203660031901126105ef5761060c61172f565b6106146117c3565b600180546001600160a01b0319166001600160a01b0392831690811790915582549091167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e227008380a380f35b50823461067e578160031936011261067e57602090600a549051908152f35b5080fd5b50823461067e578160031936011261067e5760015490516001600160a01b039091168152602090f35b50823461067e578160031936011261067e5760a09060115490601254601354906014549260ff8151958181161515875260081c161515602086015284015260608301526080820152f35b5091903461071e57602036600319011261071e5760209282913581526003845220549051908152f35b8280fd5b5091903461071e57602036600319011261071e577f68bff35e46d3206e18452a58ab63d15ddf725d0b38dfb1df3d4dab8e77f5d5659160209135906107656117c3565b8160105551908152a180f35b50823461067e578160031936011261067e5760c09060ff600b541690600c5490600d5460ff600e541690600f54926010549481519615158752602087015285015215156060840152608083015260a0820152f35b50823461067e578060031936011261067e576001600160401b0392602480359190858311610ad05736602384011215610ad0578282013592868411610acc5783810182810190368211610a92577f0000000000000000000000007fece6ab0d1473b7e6abe52a3b155269c0f8e4f96001600160a01b03163303610a9a578287910312610a96576044820135888111610a9257820181604382011215610a925790816044856108769401359101611894565b938451850160209887878b84019303126103de57898701519688810151918211610446570181603f820112156103de5789810151916108b483611879565b906108c18a519283611856565b83825289848401011161044657916108e391898c6108ec9796950191016118cb565b83369201611894565b86815191012083865260038752848620541460ff6109098561176f565b90549060031b1c1615610a515761092b575b5050829360039184525281205580f35b83518681019083358252308682015246606082015284608082015260808152610953816117ef565b5190209160115491600160ff8416151503610a1c5784601254036109e4575050917f5c69e7026b653d8606b5613bb00fd8c4b0504b1cbe8db600c406faac180924d58486979361010060039661ff00191617601155806013558360145581519084825285820152a16109c48161176f565b60ff825491861b1b1916905580855282825284848120559181955061091b565b855162461bcd60e51b8152918201889052601390820152721c995c5d595cdd1259081b9bdd081d985b1a59606a1b6044820152606490fd5b855162461bcd60e51b81529182018890526010908201526f14995c5d595cdd081b9bdd081cd95b9d60821b6044820152606490fd5b845162461bcd60e51b8152808401889052601c818401527b726571756573742066756c66696c6c6564206f72206d697373696e6760201b6044820152606490fd5b8780fd5b8680fd5b865162461bcd60e51b8152602081870152600d818601526c37b7363c9037b832b930ba37b960991b6044820152606490fd5b8580fd5b8480fd5b5091903461071e578260031936011261071e575490516001600160a01b03909116815260209150f35b508290346105ef57806003193601126105ef5750610b2860209260018060a01b0390541633146118ee565b60ff600754169081610b52575b8115610b44575b519015158152f35b600b5460ff16159150610b3c565b60115460081c60ff169150610b35565b5091903461071e57602036600319011261071e577ff56ae34a736154a570ed8935e3feb13fc99a990bfd5c7ad6486f4cb126859f96916020913590610ba56117c3565b81600f5551908152a180f35b50823461067e578160031936011261067e57905490516001600160a01b039091168152602090f35b50903461067e578160031936011261067e5754610c00906001600160a01b031633146118ee565b610c086119e6565b80f35b50823461067e57602036600319011261067e57602090610c31610c2c61172f565b611dd3565b9051908152f35b50823461067e578160031936011261067e5760a09160808251610c5a816117ef565b828152826020820152828482015282606082015201528051610c7b816117ef565b60115460ff811615159283835260ff602084019260081c1615158252601254818401908152601354926060850193845260806014549501948552825195865251151560208601525190840152516060830152516080820152f35b50913461071e578260031936011261071e57600154916001600160a01b03913383851603610d2e5750506001600160a01b031991821660015582543392811683178455166000805160206120dc8339815191528380a380f35b60249250519063118cdaa760e01b82523390820152fd5b5091903461071e57602036600319011261071e5735916002548310156105ef575060ff610d7360209361176f565b92905490519260031b1c1615158152f35b50346105ef57806003193601126105ef57610d9d6117c3565b600180546001600160a01b03199081169091558154908116825581906001600160a01b03166000805160206120dc8339815191528280a380f35b50823461067e578060031936011261067e57610df1611760565b835460243591906001600160a01b03908116610e0e3382146118ee565b600b5460ff16808061125f575b1561110b57505060ff60075416156110dc576006549586156110a85760135496855197602098898101918252898152610e538161183b565b519020069180610e6284611db8565b90549060031b1c169360001461105c578154865163996c6cc360e01b815290821689828581845afa91821561105257610ebf92878b868e958c958395611033575b508d516323b872dd60e01b8152978896879586938d8501611963565b0393165af190811561050e57899291610edf918a91611006575b50611985565b60ff1960075416600755825416865192838092631e14e34360e31b82525afa8015610ffc578690610fcd575b610f199150600d54906119c3565b600855848451610f2881611820565b526005548560055580610fa9575b508385967f826bbd0fbc2baeb2244f7b5226338393b58c345e7dac64b39391b4e3b9b3813992600560008051602061207c833981519152985288600655610f7b61205f565b42600a55825191868352820152a25b610f92611e76565b60ff600b541690825191151582526020820152a180f35b60058652868620908101905b818110610fc25750610f36565b868155600101610fb5565b508681813d8311610ff5575b610fe38183611856565b81010312610acc57610f199051610f0b565b503d610fd9565b85513d88823e3d90fd5b6110269150843d861161102c575b61101e8183611856565b81019061194b565b8b610ed9565b503d611014565b61104b919550873d8911610481576104738183611856565b9338610ea3565b88513d8b823e3d90fd5b8154865163c34fe1dd60e01b815290821689828581845afa91821561105257610ebf92878b868e958c95839561103357508d516323b872dd60e01b8152978896879586938d8501611963565b606490602086519162461bcd60e51b8352820152600e60248201526d30207061727469636970616e747360901b6044820152fd5b835162461bcd60e51b81526020818801526009602482015268546f6f206561726c7960b81b6044820152606490fd5b9695969290919215611131575b50505060008051602061207c8339815191529250610f8a565b15611211575080845416938584519263996c6cc360e01b845260209687858581845afa948515611207579261118a9592899592889583956111e8575b5089516323b872dd60e01b81529788968795869330918501611963565b0393165af19384156111de57936111b99160008051602061207c8339815191529587926111c1575b5050611985565b848080611118565b6111d79250803d1061102c5761101e8183611856565b86806111b2565b83513d87823e3d90fd5b611200919550873d8911610481576104738183611856565b938c61116d565b87513d85823e3d90fd5b938584519263c34fe1dd60e01b845260209687858581845afa948515611207579261118a9592899592889583956111e8575089516323b872dd60e01b81529788968795869330918501611963565b5060ff60115460081c16610e1b565b50913461071e57602036600319011261071e577f1647043f27b6ab91a262baccf5e4b2dd4085e0ecea7e9885b6f6d329a0a6851a916020916112ae61172f565b6112b66117c3565b82546001600160a01b0319166001600160a01b039190911690811790925551908152a180f35b50823461067e57602036600319011261067e5760207fd1eac0a1c82fb301a1760f4bbacb6db64acaf2e4eebb26b7b1d11d267498a88c9161131b611760565b906113246117c3565b600b549115159160ff16151582036113495760ff19600e5416600e555b51908152a180f35b600160ff19600e541617600e55611341565b50903461067e578260031936011261067e5761137561172f565b9061137e61174a565b916113876117c3565b84516370a0823160e01b815230838201526001600160a01b039190911692909160208084602481885afa9384156114db5786946114ac575b50611428868089518481019063a9059cbb60e01b82526113f5816113e78b8b60248401611d9d565b03601f198101835282611856565b5190828a5af13d156114a4573d9061140c82611879565b916114198b519384611856565b82523d898584013e5b87611e13565b805191821515928361148b575b505050611474575061146e7f11dd463c4f2edd676b85f050130c7ab2f5832f52becb5444b09a92404aa1498a9394955192839283611d9d565b0390a280f35b8551635274afe760e01b8152908101849052602490fd5b61149b935082018101910161194b565b15388080611435565b606090611422565b9080945081813d83116114d4575b6114c48183611856565b81010312610acc575192386113bf565b503d6114ba565b87513d88823e3d90fd5b50823461067e578160031936011261067e576060906006549060ff600754169060085491815193845215156020840152820152f35b8285853461071e578260031936011261071e5782546001600160a01b039490851633148015611723575b156116eb5750611552611e76565b81519061155e82611820565b838252848154169183518093631e14e34360e31b8252818460209687935afa8015610ffc5786906116bc575b6115989150600d54906119c3565b8451909290916001600160401b039060808401828111858210176116a9578752808452858401928884526060888601958a875201958652815192831161169657600160401b8311611696575085906005548360055580841061166d575b500160058852858820885b83811061165957505050507fc848b8758eef2575b37a79281d279c80506ed2e7fdfc9d6a1d61da8b60e9c68d9596505160065551151560ff8019600754169116176007555180600855600c54918351928352820152a180f35b82518b168282015591870191600101611600565b60058a5283838b2091820191015b81811061168857506115f5565b8a815588935060010161167b565b634e487b7160e01b895260419052602488fd5b634e487b7160e01b895260418452602489fd5b508381813d83116116e4575b6116d28183611856565b81010312610acc57611598905161158a565b503d6116c8565b602060649262461bcd60e51b8352820152601560248201527427b7363c9029b4b63b32b92332b2b997a7bbb732b960591b6044820152fd5b50848254163314611544565b600435906001600160a01b038216820361174557565b600080fd5b602435906001600160a01b038216820361174557565b60043590811515820361174557565b906002548210156117ad576002600052600582901c7f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0191601f1690565b634e487b7160e01b600052603260045260246000fd5b6000546001600160a01b031633036117d757565b60405163118cdaa760e01b8152336004820152602490fd5b60a081019081106001600160401b0382111761180a57604052565b634e487b7160e01b600052604160045260246000fd5b602081019081106001600160401b0382111761180a57604052565b604081019081106001600160401b0382111761180a57604052565b601f909101601f19168101906001600160401b0382119082101761180a57604052565b6001600160401b03811161180a57601f01601f191660200190565b9291926118a082611879565b916118ae6040519384611856565b829481845281830111611745578281602093846000960137010152565b60005b8381106118de5750506000910152565b81810151838201526020016118ce565b156118f557565b60405162461bcd60e51b815260206004820152600f60248201526e4f6e6c792053696c7665724665657360881b6044820152606490fd5b9081602091031261174557516001600160a01b03811681036117455790565b90816020910312611745575180151581036117455790565b6001600160a01b03918216815291166020820152604081019190915260600190565b1561198c57565b60405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606490fd5b919082018092116119d057565b634e487b7160e01b600052601160045260246000fd5b60ff600b541615611d9b57600480546040805163179bbedf60e21b81529290916020919082908590839082906001600160a01b03165afa938415611d9057600094611d61575b50600d54600194611a3f81871c426119c3565b6008548091101591828093611d56575b80611d49575b15611c86575050505060119283549360ff8516611c4d5760ff1994851686178155815160008582015284815292611a8b8461183b565b60025493600160401b851015611c385790611adc9291888601600255611ab08661176f565b5050611abb8661176f565b81549060031b9060ff8c831b921b191617905584519384918789840161202c565b0391611af0601f1993848101865285611856565b6364e62126194201428111611c2457600390049089820192838311611bca57600092468c03611bdc5760059192935001809311611bca5750509160008051602061209c833981519152916000805160206120bc83398151915296959493905b8451611b708882019282611b6487878761202c565b03908101835282611856565b51902085600052600387528460002055611b8e84519283928361202c565b0390a18160125551908152a160075416176007555b7fa82b306739f8d9062e2a6cb231e2b2b6010520832cf162c722a1c45c01ee3ce0600080a1565b634e487b7160e01b6000525260246000fd5b600201809411611c13575050509160008051602061209c833981519152916000805160206120bc8339815191529695949390611b4f565b634e487b7160e01b83525260249150fd5b5090634e487b7160e01b6000525260246000fd5b604182634e487b7160e01b6000525260246000fd5b5091606492519162461bcd60e51b8352820152601460248201527314995c5d595cdd08185b1c9958591e481cd95b9d60621b6044820152fd5b92969195509293508480611d3f575b15611caf575050505050601055611caa611e76565b611ba3565b84611d32575b84611ced575b50505050611cca575b50611ba3565b611cd261205f565b60ff1960075416600755601055611ce7611e76565b38611cc4565b929594935090916001600160ff1b0382168203611d1d57611d12939495501b906119c3565b421138808080611cbb565b601186634e487b7160e01b6000525260246000fd5b60075460ff169450611cb5565b5060065415611c95565b5060ff6011541615611a55565b506006541515611a4f565b90938282813d8311611d89575b611d788183611856565b810103126105ef5750519238611a2c565b503d611d6e565b83513d6000823e3d90fd5b565b6001600160a01b039091168152602081019190915260400190565b6005548110156117ad57600560005260206000200190600090565b6001600160a01b031660009081526009602052604090206001810154600a541080611e07575b611e035750600090565b5490565b5060ff600b5416611df9565b90611e3a5750805115611e2857805190602001fd5b604051630a12f52160e11b8152600490fd5b81511580611e6d575b611e4b575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b15611e43565b600f548061201e575b5060105480611f98575b50600e5460ff8116611e985750565b600b5460ff8082161516918260ff1980931617600b5516600e55600014611f715760048054604051631e14e34360e31b81529160209183919082906001600160a01b03165afa908115611f6557600091611f33575b506040611f1e7ff630826129f37a41796127d038cfae85fe120359ddd6f9b0da24ee9e8ea8d8ac92600d54906119c3565b80600855600c549082519182526020820152a1565b906020823d8211611f5d575b81611f4c60209383611856565b810103126105ef5750516040611eed565b3d9150611f3f565b6040513d6000823e3d90fd5b7f6f233cde5f47c07fa0d9895c54d2d2a3ab36f565c605df426bdd460a5bf3ea59600080a1565b60048054604051631e14e34360e31b81529160209183919082906001600160a01b03165afa8015611f65578290600090611fe8575b611fd792506119c3565b600855600d55600060105538611e89565b90506020823d8211612016575b8161200260209383611856565b810103126105ef575081611fd79151611fcd565b3d9150611ff5565b600c556000600f5538611e7f565b909160609282526040602083015261205381518092816040860152602086860191016118cb565b601f01601f1916010190565b61ffff196011541660115560006012556000601355600060145556fef311bc4329e14d73a88accc37c5045c49a8f9a4e7d84c49c2f657b6fc13e5e34d91fc3685b930310b008ec37d2334870cab88a023ed8cc628a2e2ccd4e55d2020cd21a41891ff04ecd9a8754bec97e2fb85d2a4e7694329d4dc364c796f23d068be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0a164736f6c6343000814000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000007fece6ab0d1473b7e6abe52a3b155269c0f8e4f9
-----Decoded View---------------
Arg [0] : operator (address): 0x7FECe6AB0d1473b7E6ABe52a3B155269C0F8e4F9
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000007fece6ab0d1473b7e6abe52a3b155269c0f8e4f9
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.