Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 165 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Distribute Token... | 21084285 | 82 days ago | IN | 0 ETH | 0.00332801 | ||||
Distribute Token... | 21084089 | 82 days ago | IN | 0 ETH | 0.0027775 | ||||
Distribute Token... | 21084080 | 82 days ago | IN | 0 ETH | 0.00298902 | ||||
Distribute Token... | 21084070 | 82 days ago | IN | 0 ETH | 0.0027197 | ||||
Distribute Token... | 21084041 | 82 days ago | IN | 0 ETH | 0.00219872 | ||||
Distribute Token... | 21084030 | 82 days ago | IN | 0 ETH | 0.00239992 | ||||
Distribute Token... | 21084026 | 82 days ago | IN | 0 ETH | 0.00231351 | ||||
Distribute Token... | 21084022 | 82 days ago | IN | 0 ETH | 0.0024481 | ||||
Distribute Token... | 20077044 | 223 days ago | IN | 0 ETH | 0.0073496 | ||||
Distribute Token... | 20077042 | 223 days ago | IN | 0 ETH | 0.00736232 | ||||
Distribute Token... | 20077038 | 223 days ago | IN | 0 ETH | 0.00739147 | ||||
Distribute Token... | 20077033 | 223 days ago | IN | 0 ETH | 0.00694685 | ||||
Distribute Token... | 20077029 | 223 days ago | IN | 0 ETH | 0.00743968 | ||||
Distribute Token... | 20077024 | 223 days ago | IN | 0 ETH | 0.00679895 | ||||
Distribute Token... | 20077020 | 223 days ago | IN | 0 ETH | 0.007986 | ||||
Distribute Token... | 20077017 | 223 days ago | IN | 0 ETH | 0.00762981 | ||||
Distribute Token... | 20077012 | 223 days ago | IN | 0 ETH | 0.00776002 | ||||
Distribute Token... | 19926162 | 244 days ago | IN | 0 ETH | 0.00539519 | ||||
Distribute Token... | 19790275 | 263 days ago | IN | 0 ETH | 0.00312776 | ||||
Distribute Token... | 19790272 | 263 days ago | IN | 0 ETH | 0.00322947 | ||||
Distribute Token... | 19790269 | 263 days ago | IN | 0 ETH | 0.00323188 | ||||
Distribute Token... | 19790266 | 263 days ago | IN | 0 ETH | 0.00322124 | ||||
Distribute Token... | 19555460 | 296 days ago | IN | 0 ETH | 0.00673985 | ||||
Distribute Token... | 19538100 | 298 days ago | IN | 0 ETH | 0.00881834 | ||||
Distribute Token... | 19310888 | 330 days ago | IN | 0 ETH | 0.01318477 |
Latest 25 internal transactions (View All)
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
TokenDistributor
Compiler Version
v0.8.10+commit.fc410830
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.10; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; import {PERCENTAGE_FACTOR} from "./helpers/Constants.sol"; import {IAddressProvider} from "./interfaces/IAddressProvider.sol"; import {IGearToken} from "./interfaces/IGearToken.sol"; import {StepVesting} from "./Vesting.sol"; import {IStepVesting} from "./interfaces/IStepVesting.sol"; import {ITokenDistributorOld, VestingContract, VotingPower} from "./interfaces/ITokenDistributorOld.sol"; import {ITokenDistributor, TokenAllocationOpts} from "./interfaces/ITokenDistributor.sol"; contract TokenDistributor is ITokenDistributor { using EnumerableSet for EnumerableSet.AddressSet; /// @dev Address of the treasury address public immutable treasury; /// @dev Address responsible for managing vesting contracts address public distributionController; /// @dev GEAR token IGearToken public immutable gearToken; /// @dev Address of master contract to clone address public immutable masterVestingContract; /// @dev Mapping from contributor addresses to their active vesting contracts mapping(address => EnumerableSet.AddressSet) internal vestingContracts; /// @dev Mapping from vesting contracts to their voting power categories mapping(address => string) public vestingContractVotingCategory; /// @dev Mapping from voting categories to corresponding voting power multipliers mapping(string => uint16) public votingCategoryMultipliers; /// @dev Mapping from existing voting categories mapping(string => bool) public votingCategoryExists; /// @dev Set of all known contributors EnumerableSet.AddressSet private contributorsSet; /// @param addressProvider address of Address provider /// @param tokenDistributorOld Address of the previous token distributor constructor(IAddressProvider addressProvider, ITokenDistributorOld tokenDistributorOld) { masterVestingContract = tokenDistributorOld.masterVestingContract(); gearToken = IGearToken(addressProvider.getGearToken()); // T:[TD-1] treasury = addressProvider.getTreasuryContract(); distributionController = addressProvider.getTreasuryContract(); uint16 weightA = uint16(tokenDistributorOld.weightA()); uint16 weightB = uint16(tokenDistributorOld.weightB()); _updateVotingCategoryMultiplier("TYPE_A", weightA); _updateVotingCategoryMultiplier("TYPE_B", weightB); _updateVotingCategoryMultiplier("TYPE_ZERO", 0); address[] memory oldContributors = tokenDistributorOld.contributorsList(); uint256 numOldContributors = oldContributors.length; for (uint256 i = 0; i < numOldContributors; ++i) { VestingContract memory vc = tokenDistributorOld.vestingContracts(oldContributors[i]); address receiver = StepVesting(vc.contractAddress).receiver(); _addVestingContractForContributor(vc.contractAddress, receiver); string memory votingCategory = vc.votingPower == VotingPower.A ? "TYPE_A" : vc.votingPower == VotingPower.B ? "TYPE_B" : "TYPE_ZERO"; vestingContractVotingCategory[vc.contractAddress] = votingCategory; emit VestingContractAdded( receiver, vc.contractAddress, gearToken.balanceOf(vc.contractAddress), votingCategory ); } } modifier distributionControllerOnly() { if (msg.sender != distributionController) { revert NotDistributionControllerException(); } _; } modifier treasuryOnly() { if (msg.sender != treasury) { revert NotTreasuryException(); } _; } /// @dev Returns the total GEAR balance of holder, including vested balances weighted with their respective /// voting category multipliers. Used in snapshot voting. /// @param holder Address to calculate the weighted balance for function balanceOf(address holder) external view returns (uint256 vestedBalanceWeighted) { uint256 numVestingContracts = vestingContracts[holder].length(); for (uint256 i = 0; i < numVestingContracts; ++i) { address vc = vestingContracts[holder].at(i); address receiver = IStepVesting(vc).receiver(); if (receiver == holder) { vestedBalanceWeighted += ( gearToken.balanceOf(vc) * votingCategoryMultipliers[vestingContractVotingCategory[vc]] ) / PERCENTAGE_FACTOR; } } vestedBalanceWeighted += gearToken.balanceOf(holder); } // // VESTING CONTRACT CONTROLS // /// @dev Creates a batch of new GEAR vesting contracts with passed parameters /// @param recipient Address to set as the vesting contract receiver /// @param votingCategory The voting category used to determine the vested GEARs' voting weight /// @param cliffDuration Time until first payout /// @param cliffAmount Size of first payout /// @param vestingDuration Time until all tokens are unlocked, starting from cliff /// @param vestingNumSteps Number of ticks at which tokens are unlocked /// @param vestingAmount Total number of tokens unlocked during the vesting period (excluding cliff) function distributeTokens( address recipient, string calldata votingCategory, uint256 cliffDuration, uint256 cliffAmount, uint256 vestingDuration, uint256 vestingNumSteps, uint256 vestingAmount ) external distributionControllerOnly { TokenAllocationOpts memory opts = TokenAllocationOpts({ recipient: recipient, votingCategory: votingCategory, cliffDuration: cliffDuration, cliffAmount: cliffAmount, vestingDuration: vestingDuration, vestingNumSteps: vestingNumSteps, vestingAmount: vestingAmount }); _deployVestingContract(opts); } // // CONTRIBUTOR HOUSEKEEPING // /// @dev Updates the receiver on the passed contributor's VCs, if needed function updateContributor(address contributor) external { _updateContributor(contributor, false); } /// @dev Updates the receiver on the passed contributor's VCs and cleans up spent contracts function cleanupContributor(address contributor) external distributionControllerOnly { _updateContributor(contributor, true); } function _updateContributor(address contributor, bool removeZeroBalance) internal { if (!contributorsSet.contains(contributor)) { revert ContributorNotRegisteredException(contributor); } _cleanupContributor(contributor, removeZeroBalance); } /// @dev Aligns the receiver between this contract /// and vesting contracts, for all recorded contributors function updateContributors() external { _updateContributors(false); } /// @dev Cleans up exhausted vesting contracts and aligns the receiver between this contract /// and vesting contracts, for all recorded contributors function cleanupContributors() external distributionControllerOnly { _updateContributors(true); } function _updateContributors(bool removeZeroBalance) internal { address[] memory contributorsArray = contributorsSet.values(); uint256 numContributors = contributorsArray.length; for (uint256 i = 0; i < numContributors; i++) { _cleanupContributor(contributorsArray[i], removeZeroBalance); } } // // CONFIGURATION // /// @dev Updates the voting weight for a particular voting category /// @param category The name of the category to update the multiplier for /// @param multiplier The voting power weight for all vested GEAR belonging to the category function updateVotingCategoryMultiplier(string calldata category, uint16 multiplier) external treasuryOnly { _updateVotingCategoryMultiplier(category, multiplier); } function _updateVotingCategoryMultiplier(string memory category, uint16 multiplier) internal { if (multiplier > PERCENTAGE_FACTOR) { revert MultiplierValueIncorrect(); } votingCategoryMultipliers[category] = multiplier; votingCategoryExists[category] = true; emit NewVotingMultiplier(category, multiplier); } /// @dev Changes the distribution controller /// @param newController Address of the new distribution controller function setDistributionController(address newController) external treasuryOnly { distributionController = newController; emit NewDistrubtionController(newController); } // // GETTERS // /// @dev Returns the number of recorded contributors function countContributors() external view returns (uint256) { return contributorsSet.length(); } /// @dev Returns the full list of recorded contributors function contributorsList() external view returns (address[] memory) { address[] memory result = new address[](contributorsSet.length()); for (uint256 i = 0; i < contributorsSet.length(); i++) { result[i] = contributorsSet.at(i); } return result; } /// @dev Returns the active vesting contracts for a particular contributor function contributorVestingContracts(address contributor) external view returns (address[] memory) { return vestingContracts[contributor].values(); } // // INTERNAL FUNCTIONS // /// @dev Deploys a vesting contract for a new allocation function _deployVestingContract( TokenAllocationOpts memory opts ) internal { if (!votingCategoryExists[opts.votingCategory]) { revert VotingCategoryDoesntExist(); } address vc = Clones.clone(address(masterVestingContract)); IStepVesting(vc).initialize( gearToken, block.timestamp, opts.cliffDuration, opts.vestingDuration / opts.vestingNumSteps, opts.cliffAmount, opts.vestingAmount / opts.vestingNumSteps, opts.vestingNumSteps, opts.recipient ); _addVestingContractForContributor(vc, opts.recipient); vestingContractVotingCategory[vc] = opts.votingCategory; emit VestingContractAdded(opts.recipient, vc, opts.cliffAmount + opts.vestingAmount, opts.votingCategory); } /// @dev Cleans up all vesting contracts currently belonging to a contributor /// If there are no more active vesting contracts after cleanup, removes /// the contributor from the list function _cleanupContributor(address contributor, bool removeZeroBalance) internal { address[] memory vcs = vestingContracts[contributor].values(); uint256 numVestingContracts = vcs.length; for (uint256 i = 0; i < numVestingContracts;) { address vc = vcs[i]; _cleanupVestingContract(contributor, vc, removeZeroBalance); unchecked { ++i; } } if (vestingContracts[contributor].length() == 0) { contributorsSet.remove(contributor); } } /// @dev Removes the contract from the list if it was exhausted, or /// updates the associated contributor if the receiver was changed function _cleanupVestingContract(address contributor, address vc, bool removeZeroBalance) internal { address receiver = IStepVesting(vc).receiver(); if (gearToken.balanceOf(vc) == 0 && removeZeroBalance) { vestingContracts[contributor].remove(vc); } else if (receiver != contributor) { vestingContracts[contributor].remove(vc); _addVestingContractForContributor(vc, receiver); emit VestingContractReceiverUpdated(vc, contributor, receiver); } } /// @dev Associates a vesting contract with a contributor, and adds a contributor /// to the list, if it did not exist before function _addVestingContractForContributor(address vc, address receiver) internal { if (!contributorsSet.contains(receiver)) { contributorsSet.add(receiver); } vestingContracts[receiver].add(vc); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.10; import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {IGearToken} from "./interfaces/IGearToken.sol"; // Based on https://github.com/1inch/governance-contracts/blob/master/contracts/StepVesting.sol contract StepVesting is Initializable { using SafeMath for uint256; using SafeERC20 for IGearToken; error ZeroAddressException(); event ReceiverChanged(address oldWallet, address newWallet); uint256 public started; IGearToken public token; uint256 public cliffDuration; uint256 public stepDuration; uint256 public cliffAmount; uint256 public stepAmount; uint256 public numOfSteps; address public receiver; uint256 public claimed; modifier onlyReceiver() { require(msg.sender == receiver, "access denied"); _; } function initialize( IGearToken _token, uint256 _started, uint256 _cliffDuration, uint256 _stepDuration, uint256 _cliffAmount, uint256 _stepAmount, uint256 _numOfSteps, address _receiver ) external initializer { if (address(_token) == address(0) && _receiver == address(0)) { revert ZeroAddressException(); } token = _token; started = _started; cliffDuration = _cliffDuration; stepDuration = _stepDuration; cliffAmount = _cliffAmount; stepAmount = _stepAmount; numOfSteps = _numOfSteps; receiver = _receiver; } function available() public view returns (uint256) { return claimable().sub(claimed); } function claimable() public view returns (uint256) { if (block.timestamp < started.add(cliffDuration)) { return 0; } uint256 passedSinceCliff = block.timestamp.sub(started.add(cliffDuration)); uint256 stepsPassed = Math.min(numOfSteps, passedSinceCliff.div(stepDuration)); return cliffAmount.add(stepsPassed.mul(stepAmount)); } function setReceiver(address _receiver) public onlyReceiver { if (_receiver == address(0)) revert ZeroAddressException(); emit ReceiverChanged(receiver, _receiver); receiver = _receiver; } function delegate(address delegatee) external onlyReceiver { if (delegatee == address(0)) revert ZeroAddressException(); token.delegate(delegatee); } function claim() external onlyReceiver { uint256 amount = available(); claimed = claimed.add(amount); token.safeTransfer(msg.sender, amount); } }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.10; uint256 constant PERCENTAGE_FACTOR = 10000;
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.10; /// @title Optimised for front-end Address Provider interface interface IAddressProvider { /// @return Address of ACL contract function getACL() external view returns (address); /// @return Address of ContractsRegister function getContractsRegister() external view returns (address); /// @return Address of AccountFactory function getAccountFactory() external view returns (address); /// @return Address of DataCompressor function getDataCompressor() external view returns (address); /// @return Address of GEAR token function getGearToken() external view returns (address); /// @return Address of WETH token function getWethToken() external view returns (address); /// @return Address of WETH Gateway function getWETHGateway() external view returns (address); /// @return Address of PriceOracle function getPriceOracle() external view returns (address); /// @return Address of DAO Treasury Multisig function getTreasuryContract() external view returns (address); /// @return Address of PathFinder function getLeveragedActions() external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.10; pragma abicoder v2; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IGearToken is IERC20 { /** * @dev Approves token spending by signature * @param owner The address to approve from * @param spender The address to be approved * @param rawAmount The number of tokens that are approved (type(uint256).max sets allowance to infinite) * @param deadline The time at which to expire the signature * @param v The recovery byte of the signature * @param r Half of the ECDSA signature pair * @param s Half of the ECDSA signature pair */ function permit(address owner, address spender, uint256 rawAmount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; /** * @notice Delegate votes from `msg.sender` to `delegatee` * @param delegatee The address to delegate votes to */ function delegate(address delegatee) external; /** * @notice Delegate votes by signature * @param delegatee The address to delegate votes to * @param nonce The contract state required to match the signature * @param expiry The time at which to expire the signature * @param v The recovery byte of the signature * @param r Half of the ECDSA signature pair * @param s Half of the ECDSA signature pair */ function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external; /** * @notice Returns the current total votes for `account` * @param account The address to get voting power for * @return The number of current votes for `account` */ function getCurrentVotes(address account) external view returns (uint96); /** * @notice Determine the number of votes for an account as of a prior block number * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. * @param account The address of the account to check * @param blockNumber The block number to get the vote balance at * @return The number of votes the account had as of the given block */ function getPriorVotes(address account, uint256 blockNumber) external view returns (uint96); function setMiner(address) external; }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.10; import {IGearToken} from "./IGearToken.sol"; interface IStepVesting { function receiver() external view returns (address); function initialize( IGearToken _token, uint256 _started, uint256 _cliffDuration, uint256 _stepDuration, uint256 _cliffAmount, uint256 _stepAmount, uint256 _numOfSteps, address _receiver ) external; function setReceiver(address) external; function cliffDuration() external view returns (uint256); function stepDuration() external view returns (uint256); function cliffAmount() external view returns (uint256); function stepAmount() external view returns (uint256); function numOfSteps() external view returns (uint256); function claimed() external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.10; /// @dev Struct containing parameters to initialize a new vesting contract struct TokenAllocationOpts { address recipient; string votingCategory; uint256 cliffDuration; uint256 cliffAmount; uint256 vestingDuration; uint256 vestingNumSteps; uint256 vestingAmount; } interface ITokenDistributorExceptions { /// @dev Thrown if there is leftover GEAR in the contract after distribution error NonZeroBalanceAfterDistributionException(uint256 amount); /// @dev Thrown if attempting to do an action for an address that is not a contributor error ContributorNotRegisteredException(address user); /// @dev Thrown if an access-restricted function is called by other than the treasury multisig error NotTreasuryException(); /// @dev Thrown if an access-restricted function is called by other than the distribution controller error NotDistributionControllerException(); /// @dev Thrown if a voting multiplier value does not pass sanity checks error MultiplierValueIncorrect(); /// @dev Thrown if voting category doesn't exist error VotingCategoryDoesntExist(); } interface ITokenDistributorEvents { /// @dev Emits when a multiplier for a voting category is updated event NewVotingMultiplier(string indexed category, uint16 multiplier); /// @dev Emits when a new distribution controller is set event NewDistrubtionController(address newController); /// @dev Emits when a new vesting contract is added event VestingContractAdded( address indexed holder, address indexed vestingContract, uint256 amount, string votingPowerCategory ); /// @dev Emits when the contributor associated with a vesting contract is changed event VestingContractReceiverUpdated( address indexed vestingContract, address indexed prevReceiver, address indexed newReceiver ); } interface ITokenDistributor is ITokenDistributorExceptions, ITokenDistributorEvents { function distributeTokens( address recipient, string calldata votingCategory, uint256 cliffDuration, uint256 cliffAmount, uint256 vestingDuration, uint256 vestingNumSteps, uint256 vestingAmount ) external; function updateContributor(address contributor) external; function updateContributors() external; function updateVotingCategoryMultiplier(string calldata category, uint16 multiplier) external; function balanceOf(address holder) external view returns (uint256 vestedBalanceWeighted); function countContributors() external view returns (uint256); function contributorsList() external view returns (address[] memory); function contributorVestingContracts(address contributor) external view returns (address[] memory); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.10; enum VotingPower { A, B, ZERO_VOTING_POWER } struct VestingContract { address contractAddress; // vesting contract address VotingPower votingPower; // enum for voting power(0 means "A", 1 means "B" and 2 means "ZERO VOTING") } interface ITokenDistributorOld { function masterVestingContract() external view returns (address); function vestingContracts(address contributor) external view returns (VestingContract memory); function weightA() external view returns (uint256); function weightB() external view returns (uint256); function contributorsList() external view returns (address[] memory); function countContributors() external view returns (uint256); function balanceOf(address) external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ 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 { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ 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 { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/Clones.sol) pragma solidity ^0.8.0; /** * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for * deploying minimal proxy contracts, also known as "clones". * * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies * > a minimal bytecode implementation that delegates all calls to a known, fixed address. * * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the * deterministic method. * * _Available since v3.4._ */ library Clones { /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create opcode, which should never revert. */ function clone(address implementation) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes // of the `implementation` address with the bytecode before the address. mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000)) // Packs the remaining 17 bytes of `implementation` with the bytecode after the address. mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3)) instance := create(0, 0x09, 0x37) } require(instance != address(0), "ERC1167: create failed"); } /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create2 opcode and a `salt` to deterministically deploy * the clone. Using the same `implementation` and `salt` multiple time will revert, since * the clones cannot be deployed twice at the same address. */ function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes // of the `implementation` address with the bytecode before the address. mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000)) // Packs the remaining 17 bytes of `implementation` with the bytecode after the address. mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3)) instance := create2(0, 0x09, 0x37, salt) } require(instance != address(0), "ERC1167: create2 failed"); } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress( address implementation, bytes32 salt, address deployer ) internal pure returns (address predicted) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(add(ptr, 0x38), deployer) mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff) mstore(add(ptr, 0x14), implementation) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73) mstore(add(ptr, 0x58), salt) mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37)) predicted := keccak256(add(ptr, 0x43), 0x55) } } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress(address implementation, bytes32 salt) internal view returns (address predicted) { return predictDeterministicAddress(implementation, salt, address(this)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/Address.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ``` * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original * initialization step. This is essential to configure modules that are added through upgrades and that require * initialization. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Internal function that returns the initialized version. Returns `_initialized` */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Internal function that returns the initialized version. Returns `_initializing` */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.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}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * 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]. * * 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. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * 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 override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override 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 value {ERC20} uses, unless this function is * 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 override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override 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 `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` 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 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); 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 `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `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. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; } emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; unchecked { // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. _balances[account] += amount; } emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; // Overflow not possible: amount <= accountBalance <= totalSupply. _totalSupply -= amount; } emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` 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. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @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 amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @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 `amount` 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 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` 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 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ 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 v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @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. */ 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]. */ 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 v4.7.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../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; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @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, it is bubbled up by this * function (like regular Solidity function calls). * * 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. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @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`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @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 up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (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; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 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. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); 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 (rounding == Rounding.Up && 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 down. * * 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * 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 + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * 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 10, 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 + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ 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. * * _Available since v3.4._ */ 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. * * _Available since v3.4._ */ 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. * * _Available since v3.4._ */ 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. * * _Available since v3.4._ */ 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 addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
{ "remappings": [ "@openzeppelin/=lib/openzeppelin-contracts/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract IAddressProvider","name":"addressProvider","type":"address"},{"internalType":"contract ITokenDistributorOld","name":"tokenDistributorOld","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"ContributorNotRegisteredException","type":"error"},{"inputs":[],"name":"MultiplierValueIncorrect","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"NonZeroBalanceAfterDistributionException","type":"error"},{"inputs":[],"name":"NotDistributionControllerException","type":"error"},{"inputs":[],"name":"NotTreasuryException","type":"error"},{"inputs":[],"name":"VotingCategoryDoesntExist","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newController","type":"address"}],"name":"NewDistrubtionController","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"string","name":"category","type":"string"},{"indexed":false,"internalType":"uint16","name":"multiplier","type":"uint16"}],"name":"NewVotingMultiplier","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"holder","type":"address"},{"indexed":true,"internalType":"address","name":"vestingContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"string","name":"votingPowerCategory","type":"string"}],"name":"VestingContractAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vestingContract","type":"address"},{"indexed":true,"internalType":"address","name":"prevReceiver","type":"address"},{"indexed":true,"internalType":"address","name":"newReceiver","type":"address"}],"name":"VestingContractReceiverUpdated","type":"event"},{"inputs":[{"internalType":"address","name":"holder","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"vestedBalanceWeighted","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contributor","type":"address"}],"name":"cleanupContributor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cleanupContributors","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contributor","type":"address"}],"name":"contributorVestingContracts","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"contributorsList","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"countContributors","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"string","name":"votingCategory","type":"string"},{"internalType":"uint256","name":"cliffDuration","type":"uint256"},{"internalType":"uint256","name":"cliffAmount","type":"uint256"},{"internalType":"uint256","name":"vestingDuration","type":"uint256"},{"internalType":"uint256","name":"vestingNumSteps","type":"uint256"},{"internalType":"uint256","name":"vestingAmount","type":"uint256"}],"name":"distributeTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"distributionController","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gearToken","outputs":[{"internalType":"contract IGearToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"masterVestingContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newController","type":"address"}],"name":"setDistributionController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contributor","type":"address"}],"name":"updateContributor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateContributors","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"category","type":"string"},{"internalType":"uint16","name":"multiplier","type":"uint16"}],"name":"updateVotingCategoryMultiplier","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vestingContractVotingCategory","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"votingCategoryExists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"votingCategoryMultipliers","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60e06040523480156200001157600080fd5b506040516200253138038062002531833981016040819052620000349162000984565b806001600160a01b031663bc5432a86040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000073573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000999190620009c3565b6001600160a01b031660c0816001600160a01b031681525050816001600160a01b031663affd92436040518163ffffffff1660e01b8152600401602060405180830381865afa158015620000f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001179190620009c3565b6001600160a01b031660a0816001600160a01b031681525050816001600160a01b03166326c74fc36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200016f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001959190620009c3565b6001600160a01b03166080816001600160a01b031681525050816001600160a01b03166326c74fc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015620001ed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002139190620009c3565b6000806101000a8154816001600160a01b0302191690836001600160a01b031602179055506000816001600160a01b03166399c1a8ec6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000279573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200029f9190620009ea565b90506000826001600160a01b031663f42b68bb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620002e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003089190620009ea565b90506200033a60405180604001604052806006815260200165545950455f4160d01b81525083620006e160201b60201c565b6040805180820190915260068152652a2ca822afa160d11b6020820152620003639082620006e1565b604080518082019091526009815268545950455f5a45524f60b81b602082015262000390906000620006e1565b6000836001600160a01b03166345f02a5b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015620003d1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052620003fb919081019062000a4d565b805190915060005b81811015620006d4576000866001600160a01b0316633791587485848151811062000432576200043262000b0b565b60200260200101516040518263ffffffff1660e01b81526004016200046691906001600160a01b0391909116815260200190565b6040805180830381865afa15801562000483573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620004a9919062000b21565b9050600081600001516001600160a01b031663f7260d3e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620004f0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620005169190620009c3565b8251909150620005279082620007c8565b6000808360200151600281111562000543576200054362000b8a565b14620005b75760018360200151600281111562000564576200056462000b8a565b14620005925760405180604001604052806009815260200168545950455f5a45524f60b81b815250620005d7565b604051806040016040528060068152602001652a2ca822afa160d11b815250620005d7565b60405180604001604052806006815260200165545950455f4160d01b8152505b83516001600160a01b03166000908152600260209081526040909120825192935062000608929091840190620008c5565b50825160a0516040516370a0823160e01b81526001600160a01b039283166004820181905292858116927f1e6bc1d88248bc568e10637edab81732ad3df3df4dfd94854872871921098278929116906370a0823190602401602060405180830381865afa1580156200067e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620006a49190620009ea565b84604051620006b592919062000bd3565b60405180910390a350505080620006cc9062000c0f565b905062000403565b5050505050505062000c94565b6127108161ffff1611156200070957604051631223f46760e21b815260040160405180910390fd5b806003836040516200071c919062000c39565b908152602001604051809103902060006101000a81548161ffff021916908361ffff160217905550600160048360405162000758919062000c39565b908152604051908190036020018120805492151560ff19909316929092179091556200078690839062000c39565b60405190819003812061ffff83168252907fade552231733058b4fe6a2f5bf548d53c217ef8dbaeb29338afc87bcd0c547269060200160405180910390a25050565b620007e38160056200083b60201b620009921790919060201c565b6200080557620008038160056200086260201b620009b31790919060201c565b505b6001600160a01b038116600090815260016020908152604090912062000836918490620009b362000862821b17901c565b505050565b6001600160a01b038116600090815260018301602052604081205415155b90505b92915050565b600062000859836001600160a01b0384166000818152600183016020526040812054620008bc575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556200085c565b5060006200085c565b828054620008d39062000c57565b90600052602060002090601f016020900481019282620008f7576000855562000942565b82601f106200091257805160ff191683800117855562000942565b8280016001018555821562000942579182015b828111156200094257825182559160200191906001019062000925565b506200095092915062000954565b5090565b5b8082111562000950576000815560010162000955565b6001600160a01b03811681146200098157600080fd5b50565b600080604083850312156200099857600080fd5b8251620009a5816200096b565b6020840151909250620009b8816200096b565b809150509250929050565b600060208284031215620009d657600080fd5b8151620009e3816200096b565b9392505050565b600060208284031215620009fd57600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171562000a455762000a4562000a04565b604052919050565b6000602080838503121562000a6157600080fd5b82516001600160401b038082111562000a7957600080fd5b818501915085601f83011262000a8e57600080fd5b81518181111562000aa35762000aa362000a04565b8060051b915062000ab684830162000a1a565b818152918301840191848101908884111562000ad157600080fd5b938501935b8385101562000aff578451925062000aee836200096b565b828252938501939085019062000ad6565b98975050505050505050565b634e487b7160e01b600052603260045260246000fd5b60006040828403121562000b3457600080fd5b604080519081016001600160401b038111828210171562000b595762000b5962000a04565b604052825162000b69816200096b565b815260208301516003811062000b7e57600080fd5b60208201529392505050565b634e487b7160e01b600052602160045260246000fd5b60005b8381101562000bbd57818101518382015260200162000ba3565b8381111562000bcd576000848401525b50505050565b828152604060208201526000825180604084015262000bfa81606085016020870162000ba0565b601f01601f1916919091016060019392505050565b600060001982141562000c3257634e487b7160e01b600052601160045260246000fd5b5060010190565b6000825162000c4d81846020870162000ba0565b9190910192915050565b600181811c9082168062000c6c57607f821691505b6020821081141562000c8e57634e487b7160e01b600052602260045260246000fd5b50919050565b60805160a05160c05161183c62000cf5600039600081816102d20152610a130152600081816101ed015281816107370152818161081001528181610a4a015261104701526000818161023f015281816103f601526108d8015261183c6000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c806361d027b3116100a2578063b179aefd11610071578063b179aefd146102ba578063bc5432a8146102cd578063ca2f8c21146102f4578063e48a8b09146102fc578063f7d752bc1461030f57600080fd5b806361d027b31461023a57806370a08231146102615780637e50a31b146102745780637ec72cc9146102b257600080fd5b80633ed76d9b116100e95780633ed76d9b146101a057806345f02a5b146101c057806348c1de87146101d557806349a3218d146101e85780634e5e580f1461022757600080fd5b806301a4f1141461011b5780630bb0ffeb1461013057806314720c0d1461014b57806335b7dc351461018d575b600080fd5b61012e61012936600461137b565b610322565b005b6101386103da565b6040519081526020015b60405180910390f35b61017a610159366004611411565b805160208183018101805160038252928201919093012091525461ffff1681565b60405161ffff9091168152602001610142565b61012e61019b3660046114c2565b6103eb565b6101b36101ae3660046114c2565b610488565b6040516101429190611537565b6101c8610522565b604051610142919061154a565b6101c86101e33660046114c2565b6105d5565b61020f7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610142565b61012e6102353660046114c2565b6105ff565b61020f7f000000000000000000000000000000000000000000000000000000000000000081565b61013861026f3660046114c2565b61060d565b6102a2610282366004611411565b805160208183018101805160048252928201919093012091525460ff1681565b6040519015158152602001610142565b61012e61088c565b60005461020f906001600160a01b031681565b61020f7f000000000000000000000000000000000000000000000000000000000000000081565b61012e6108c3565b61012e61030a366004611597565b6108cd565b61012e61031d3660046114c2565b61095c565b6000546001600160a01b0316331461034d5760405163067197b760e41b815260040160405180910390fd5b60006040518060e001604052808a6001600160a01b0316815260200189898080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050908252506020810188905260408101879052606081018690526080810185905260a00183905290506103cf816109c8565b505050505050505050565b60006103e66005610bd9565b905090565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610434576040516396f1dadb60e01b815260040160405180910390fd5b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527fe66352ed6ebf1f1d5cd08cd8ffe838aa3e8be818c14de670da2f54f4c5cb51529060200160405180910390a150565b600260205260009081526040902080546104a1906115f5565b80601f01602080910402602001604051908101604052809291908181526020018280546104cd906115f5565b801561051a5780601f106104ef5761010080835404028352916020019161051a565b820191906000526020600020905b8154815290600101906020018083116104fd57829003601f168201915b505050505081565b606060006105306005610bd9565b67ffffffffffffffff811115610548576105486113fb565b604051908082528060200260200182016040528015610571578160200160208202803683370190505b50905060005b6105816005610bd9565b8110156105cf57610593600582610be3565b8282815181106105a5576105a561162a565b6001600160a01b0390921660209283029190910190910152806105c781611656565b915050610577565b50919050565b6001600160a01b03811660009081526001602052604090206060906105f990610bef565b92915050565b61060a816000610bfc565b50565b6001600160a01b0381166000908152600160205260408120819061063090610bd9565b905060005b818110156107f0576001600160a01b038416600090815260016020526040812061065f9083610be3565b90506000816001600160a01b031663f7260d3e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106c59190611671565b9050856001600160a01b0316816001600160a01b031614156107dd576001600160a01b0382166000908152600260205260409081902090516127109160039161070e919061168e565b908152604051908190036020018120546370a0823160e01b825261ffff16906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a082319061077b9087906004016001600160a01b0391909116815260200190565b602060405180830381865afa158015610798573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107bc919061172a565b6107c69190611743565b6107d09190611762565b6107da9086611784565b94505b5050806107e990611656565b9050610635565b506040516370a0823160e01b81526001600160a01b0384811660048301527f000000000000000000000000000000000000000000000000000000000000000016906370a0823190602401602060405180830381865afa158015610857573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061087b919061172a565b6108859083611784565b9392505050565b6000546001600160a01b031633146108b75760405163067197b760e41b815260040160405180910390fd5b6108c16001610c42565b565b6108c16000610c42565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610916576040516396f1dadb60e01b815260040160405180910390fd5b61095783838080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250859250610c99915050565b505050565b6000546001600160a01b031633146109875760405163067197b760e41b815260040160405180910390fd5b61060a816001610bfc565b6001600160a01b031660009081526001919091016020526040902054151590565b6000610885836001600160a01b038416610d79565b600481602001516040516109dc919061179c565b9081526040519081900360200190205460ff16610a0c57604051631132e8a960e31b815260040160405180910390fd5b6000610a377f0000000000000000000000000000000000000000000000000000000000000000610dc8565b9050806001600160a01b031663848ff6847f00000000000000000000000000000000000000000000000000000000000000004285604001518660a001518760800151610a839190611762565b87606001518860a001518960c00151610a9c9190611762565b60a08a01518a5160405160e08a901b6001600160e01b03191681526001600160a01b039889166004820152602481019790975260448701959095526064860193909352608485019190915260a484015260c48301529190911660e482015261010401600060405180830381600087803b158015610b1857600080fd5b505af1158015610b2c573d6000803e3d6000fd5b50505050610b3e818360000151610e62565b6020808301516001600160a01b038316600090815260028352604090208151610b6c93919290910190611284565b50806001600160a01b031682600001516001600160a01b03167f1e6bc1d88248bc568e10637edab81732ad3df3df4dfd948548728719210982788460c001518560600151610bba9190611784565b8560200151604051610bcd9291906117b8565b60405180910390a35050565b60006105f9825490565b60006108858383610ea0565b6060600061088583610eca565b610c07600583610992565b610c34576040516358b539b960e01b81526001600160a01b03831660048201526024015b60405180910390fd5b610c3e8282610f26565b5050565b6000610c4e6005610bef565b805190915060005b81811015610c9357610c81838281518110610c7357610c7361162a565b602002602001015185610f26565b80610c8b81611656565b915050610c56565b50505050565b6127108161ffff161115610cc057604051631223f46760e21b815260040160405180910390fd5b80600383604051610cd1919061179c565b908152602001604051809103902060006101000a81548161ffff021916908361ffff1602179055506001600483604051610d0b919061179c565b908152604051908190036020018120805492151560ff1990931692909217909155610d3790839061179c565b60405190819003812061ffff83168252907fade552231733058b4fe6a2f5bf548d53c217ef8dbaeb29338afc87bcd0c547269060200160405180910390a25050565b6000818152600183016020526040812054610dc0575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105f9565b5060006105f9565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008260601b60e81c176000526e5af43d82803e903d91602b57fd5bf38260781b17602052603760096000f090506001600160a01b038116610e5d5760405162461bcd60e51b8152602060048201526016602482015275115490cc4c4d8dce8818dc99585d194819985a5b195960521b6044820152606401610c2b565b919050565b610e6d600582610992565b610e7e57610e7c6005826109b3565b505b6001600160a01b038116600090815260016020526040902061095790836109b3565b6000826000018281548110610eb757610eb761162a565b9060005260206000200154905092915050565b606081600001805480602002602001604051908101604052809291908181526020018280548015610f1a57602002820191906000526020600020905b815481526020019060010190808311610f06575b50505050509050919050565b6001600160a01b0382166000908152600160205260408120610f4790610bef565b805190915060005b81811015610f89576000838281518110610f6b57610f6b61162a565b60200260200101519050610f80868287610fc1565b50600101610f4f565b506001600160a01b0384166000908152600160205260409020610fab90610bd9565b610c9357610fba600585611181565b5050505050565b6000826001600160a01b031663f7260d3e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611001573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110259190611671565b6040516370a0823160e01b81526001600160a01b0385811660048301529192507f0000000000000000000000000000000000000000000000000000000000000000909116906370a0823190602401602060405180830381865afa158015611090573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b4919061172a565b1580156110be5750815b156110eb576001600160a01b03841660009081526001602052604090206110e59084611181565b50610c93565b836001600160a01b0316816001600160a01b031614610c93576001600160a01b03841660009081526001602052604090206111269084611181565b506111318382610e62565b806001600160a01b0316846001600160a01b0316846001600160a01b03167f742efd9b0e7d4712efe4a0ff6cbd5d63f2454fbe42347384ef5ca1cc08560cec60405160405180910390a450505050565b6000610885836001600160a01b0384166000818152600183016020526040812054801561127a5760006111b56001836117d9565b85549091506000906111c9906001906117d9565b905081811461122e5760008660000182815481106111e9576111e961162a565b906000526020600020015490508087600001848154811061120c5761120c61162a565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061123f5761123f6117f0565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105f9565b60009150506105f9565b828054611290906115f5565b90600052602060002090601f0160209004810192826112b257600085556112f8565b82601f106112cb57805160ff19168380011785556112f8565b828001600101855582156112f8579182015b828111156112f85782518255916020019190600101906112dd565b50611304929150611308565b5090565b5b808211156113045760008155600101611309565b6001600160a01b038116811461060a57600080fd5b60008083601f84011261134457600080fd5b50813567ffffffffffffffff81111561135c57600080fd5b60208301915083602082850101111561137457600080fd5b9250929050565b60008060008060008060008060e0898b03121561139757600080fd5b88356113a28161131d565b9750602089013567ffffffffffffffff8111156113be57600080fd5b6113ca8b828c01611332565b999c909b509899604081013599606082013599506080820135985060a0820135975060c09091013595509350505050565b634e487b7160e01b600052604160045260246000fd5b60006020828403121561142357600080fd5b813567ffffffffffffffff8082111561143b57600080fd5b818401915084601f83011261144f57600080fd5b813581811115611461576114616113fb565b604051601f8201601f19908116603f01168101908382118183101715611489576114896113fb565b816040528281528760208487010111156114a257600080fd5b826020860160208301376000928101602001929092525095945050505050565b6000602082840312156114d457600080fd5b81356108858161131d565b60005b838110156114fa5781810151838201526020016114e2565b83811115610c935750506000910152565b600081518084526115238160208601602086016114df565b601f01601f19169290920160200192915050565b602081526000610885602083018461150b565b6020808252825182820181905260009190848201906040850190845b8181101561158b5783516001600160a01b031683529284019291840191600101611566565b50909695505050505050565b6000806000604084860312156115ac57600080fd5b833567ffffffffffffffff8111156115c357600080fd5b6115cf86828701611332565b909450925050602084013561ffff811681146115ea57600080fd5b809150509250925092565b600181811c9082168061160957607f821691505b602082108114156105cf57634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060001982141561166a5761166a611640565b5060010190565b60006020828403121561168357600080fd5b81516108858161131d565b600080835481600182811c9150808316806116aa57607f831692505b60208084108214156116ca57634e487b7160e01b86526022600452602486fd5b8180156116de57600181146116ef5761171c565b60ff1986168952848901965061171c565b60008a81526020902060005b868110156117145781548b8201529085019083016116fb565b505084890196505b509498975050505050505050565b60006020828403121561173c57600080fd5b5051919050565b600081600019048311821515161561175d5761175d611640565b500290565b60008261177f57634e487b7160e01b600052601260045260246000fd5b500490565b6000821982111561179757611797611640565b500190565b600082516117ae8184602087016114df565b9190910192915050565b8281526040602082015260006117d1604083018461150b565b949350505050565b6000828210156117eb576117eb611640565b500390565b634e487b7160e01b600052603160045260246000fdfea264697066735822122071d70ee063981b257f7c33abb57b9b06e15a3bf0d003a4ba2d26eb48e284039e64736f6c634300080a0033000000000000000000000000cf64698aff7e5f27a11dff868af228653ba53be0000000000000000000000000bf57539473913685688d224ad4e262684b23dd4c
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101165760003560e01c806361d027b3116100a2578063b179aefd11610071578063b179aefd146102ba578063bc5432a8146102cd578063ca2f8c21146102f4578063e48a8b09146102fc578063f7d752bc1461030f57600080fd5b806361d027b31461023a57806370a08231146102615780637e50a31b146102745780637ec72cc9146102b257600080fd5b80633ed76d9b116100e95780633ed76d9b146101a057806345f02a5b146101c057806348c1de87146101d557806349a3218d146101e85780634e5e580f1461022757600080fd5b806301a4f1141461011b5780630bb0ffeb1461013057806314720c0d1461014b57806335b7dc351461018d575b600080fd5b61012e61012936600461137b565b610322565b005b6101386103da565b6040519081526020015b60405180910390f35b61017a610159366004611411565b805160208183018101805160038252928201919093012091525461ffff1681565b60405161ffff9091168152602001610142565b61012e61019b3660046114c2565b6103eb565b6101b36101ae3660046114c2565b610488565b6040516101429190611537565b6101c8610522565b604051610142919061154a565b6101c86101e33660046114c2565b6105d5565b61020f7f000000000000000000000000ba3335588d9403515223f109edc4eb7269a9ab5d81565b6040516001600160a01b039091168152602001610142565b61012e6102353660046114c2565b6105ff565b61020f7f0000000000000000000000007b065fcb0760df0cea8cfd144e08554f3cea73d181565b61013861026f3660046114c2565b61060d565b6102a2610282366004611411565b805160208183018101805160048252928201919093012091525460ff1681565b6040519015158152602001610142565b61012e61088c565b60005461020f906001600160a01b031681565b61020f7f000000000000000000000000ef686707193af7406f40cbd7a39ba309da5ad4ec81565b61012e6108c3565b61012e61030a366004611597565b6108cd565b61012e61031d3660046114c2565b61095c565b6000546001600160a01b0316331461034d5760405163067197b760e41b815260040160405180910390fd5b60006040518060e001604052808a6001600160a01b0316815260200189898080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050908252506020810188905260408101879052606081018690526080810185905260a00183905290506103cf816109c8565b505050505050505050565b60006103e66005610bd9565b905090565b336001600160a01b037f0000000000000000000000007b065fcb0760df0cea8cfd144e08554f3cea73d11614610434576040516396f1dadb60e01b815260040160405180910390fd5b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527fe66352ed6ebf1f1d5cd08cd8ffe838aa3e8be818c14de670da2f54f4c5cb51529060200160405180910390a150565b600260205260009081526040902080546104a1906115f5565b80601f01602080910402602001604051908101604052809291908181526020018280546104cd906115f5565b801561051a5780601f106104ef5761010080835404028352916020019161051a565b820191906000526020600020905b8154815290600101906020018083116104fd57829003601f168201915b505050505081565b606060006105306005610bd9565b67ffffffffffffffff811115610548576105486113fb565b604051908082528060200260200182016040528015610571578160200160208202803683370190505b50905060005b6105816005610bd9565b8110156105cf57610593600582610be3565b8282815181106105a5576105a561162a565b6001600160a01b0390921660209283029190910190910152806105c781611656565b915050610577565b50919050565b6001600160a01b03811660009081526001602052604090206060906105f990610bef565b92915050565b61060a816000610bfc565b50565b6001600160a01b0381166000908152600160205260408120819061063090610bd9565b905060005b818110156107f0576001600160a01b038416600090815260016020526040812061065f9083610be3565b90506000816001600160a01b031663f7260d3e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106c59190611671565b9050856001600160a01b0316816001600160a01b031614156107dd576001600160a01b0382166000908152600260205260409081902090516127109160039161070e919061168e565b908152604051908190036020018120546370a0823160e01b825261ffff16906001600160a01b037f000000000000000000000000ba3335588d9403515223f109edc4eb7269a9ab5d16906370a082319061077b9087906004016001600160a01b0391909116815260200190565b602060405180830381865afa158015610798573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107bc919061172a565b6107c69190611743565b6107d09190611762565b6107da9086611784565b94505b5050806107e990611656565b9050610635565b506040516370a0823160e01b81526001600160a01b0384811660048301527f000000000000000000000000ba3335588d9403515223f109edc4eb7269a9ab5d16906370a0823190602401602060405180830381865afa158015610857573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061087b919061172a565b6108859083611784565b9392505050565b6000546001600160a01b031633146108b75760405163067197b760e41b815260040160405180910390fd5b6108c16001610c42565b565b6108c16000610c42565b336001600160a01b037f0000000000000000000000007b065fcb0760df0cea8cfd144e08554f3cea73d11614610916576040516396f1dadb60e01b815260040160405180910390fd5b61095783838080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250859250610c99915050565b505050565b6000546001600160a01b031633146109875760405163067197b760e41b815260040160405180910390fd5b61060a816001610bfc565b6001600160a01b031660009081526001919091016020526040902054151590565b6000610885836001600160a01b038416610d79565b600481602001516040516109dc919061179c565b9081526040519081900360200190205460ff16610a0c57604051631132e8a960e31b815260040160405180910390fd5b6000610a377f000000000000000000000000ef686707193af7406f40cbd7a39ba309da5ad4ec610dc8565b9050806001600160a01b031663848ff6847f000000000000000000000000ba3335588d9403515223f109edc4eb7269a9ab5d4285604001518660a001518760800151610a839190611762565b87606001518860a001518960c00151610a9c9190611762565b60a08a01518a5160405160e08a901b6001600160e01b03191681526001600160a01b039889166004820152602481019790975260448701959095526064860193909352608485019190915260a484015260c48301529190911660e482015261010401600060405180830381600087803b158015610b1857600080fd5b505af1158015610b2c573d6000803e3d6000fd5b50505050610b3e818360000151610e62565b6020808301516001600160a01b038316600090815260028352604090208151610b6c93919290910190611284565b50806001600160a01b031682600001516001600160a01b03167f1e6bc1d88248bc568e10637edab81732ad3df3df4dfd948548728719210982788460c001518560600151610bba9190611784565b8560200151604051610bcd9291906117b8565b60405180910390a35050565b60006105f9825490565b60006108858383610ea0565b6060600061088583610eca565b610c07600583610992565b610c34576040516358b539b960e01b81526001600160a01b03831660048201526024015b60405180910390fd5b610c3e8282610f26565b5050565b6000610c4e6005610bef565b805190915060005b81811015610c9357610c81838281518110610c7357610c7361162a565b602002602001015185610f26565b80610c8b81611656565b915050610c56565b50505050565b6127108161ffff161115610cc057604051631223f46760e21b815260040160405180910390fd5b80600383604051610cd1919061179c565b908152602001604051809103902060006101000a81548161ffff021916908361ffff1602179055506001600483604051610d0b919061179c565b908152604051908190036020018120805492151560ff1990931692909217909155610d3790839061179c565b60405190819003812061ffff83168252907fade552231733058b4fe6a2f5bf548d53c217ef8dbaeb29338afc87bcd0c547269060200160405180910390a25050565b6000818152600183016020526040812054610dc0575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105f9565b5060006105f9565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008260601b60e81c176000526e5af43d82803e903d91602b57fd5bf38260781b17602052603760096000f090506001600160a01b038116610e5d5760405162461bcd60e51b8152602060048201526016602482015275115490cc4c4d8dce8818dc99585d194819985a5b195960521b6044820152606401610c2b565b919050565b610e6d600582610992565b610e7e57610e7c6005826109b3565b505b6001600160a01b038116600090815260016020526040902061095790836109b3565b6000826000018281548110610eb757610eb761162a565b9060005260206000200154905092915050565b606081600001805480602002602001604051908101604052809291908181526020018280548015610f1a57602002820191906000526020600020905b815481526020019060010190808311610f06575b50505050509050919050565b6001600160a01b0382166000908152600160205260408120610f4790610bef565b805190915060005b81811015610f89576000838281518110610f6b57610f6b61162a565b60200260200101519050610f80868287610fc1565b50600101610f4f565b506001600160a01b0384166000908152600160205260409020610fab90610bd9565b610c9357610fba600585611181565b5050505050565b6000826001600160a01b031663f7260d3e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611001573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110259190611671565b6040516370a0823160e01b81526001600160a01b0385811660048301529192507f000000000000000000000000ba3335588d9403515223f109edc4eb7269a9ab5d909116906370a0823190602401602060405180830381865afa158015611090573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b4919061172a565b1580156110be5750815b156110eb576001600160a01b03841660009081526001602052604090206110e59084611181565b50610c93565b836001600160a01b0316816001600160a01b031614610c93576001600160a01b03841660009081526001602052604090206111269084611181565b506111318382610e62565b806001600160a01b0316846001600160a01b0316846001600160a01b03167f742efd9b0e7d4712efe4a0ff6cbd5d63f2454fbe42347384ef5ca1cc08560cec60405160405180910390a450505050565b6000610885836001600160a01b0384166000818152600183016020526040812054801561127a5760006111b56001836117d9565b85549091506000906111c9906001906117d9565b905081811461122e5760008660000182815481106111e9576111e961162a565b906000526020600020015490508087600001848154811061120c5761120c61162a565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061123f5761123f6117f0565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105f9565b60009150506105f9565b828054611290906115f5565b90600052602060002090601f0160209004810192826112b257600085556112f8565b82601f106112cb57805160ff19168380011785556112f8565b828001600101855582156112f8579182015b828111156112f85782518255916020019190600101906112dd565b50611304929150611308565b5090565b5b808211156113045760008155600101611309565b6001600160a01b038116811461060a57600080fd5b60008083601f84011261134457600080fd5b50813567ffffffffffffffff81111561135c57600080fd5b60208301915083602082850101111561137457600080fd5b9250929050565b60008060008060008060008060e0898b03121561139757600080fd5b88356113a28161131d565b9750602089013567ffffffffffffffff8111156113be57600080fd5b6113ca8b828c01611332565b999c909b509899604081013599606082013599506080820135985060a0820135975060c09091013595509350505050565b634e487b7160e01b600052604160045260246000fd5b60006020828403121561142357600080fd5b813567ffffffffffffffff8082111561143b57600080fd5b818401915084601f83011261144f57600080fd5b813581811115611461576114616113fb565b604051601f8201601f19908116603f01168101908382118183101715611489576114896113fb565b816040528281528760208487010111156114a257600080fd5b826020860160208301376000928101602001929092525095945050505050565b6000602082840312156114d457600080fd5b81356108858161131d565b60005b838110156114fa5781810151838201526020016114e2565b83811115610c935750506000910152565b600081518084526115238160208601602086016114df565b601f01601f19169290920160200192915050565b602081526000610885602083018461150b565b6020808252825182820181905260009190848201906040850190845b8181101561158b5783516001600160a01b031683529284019291840191600101611566565b50909695505050505050565b6000806000604084860312156115ac57600080fd5b833567ffffffffffffffff8111156115c357600080fd5b6115cf86828701611332565b909450925050602084013561ffff811681146115ea57600080fd5b809150509250925092565b600181811c9082168061160957607f821691505b602082108114156105cf57634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060001982141561166a5761166a611640565b5060010190565b60006020828403121561168357600080fd5b81516108858161131d565b600080835481600182811c9150808316806116aa57607f831692505b60208084108214156116ca57634e487b7160e01b86526022600452602486fd5b8180156116de57600181146116ef5761171c565b60ff1986168952848901965061171c565b60008a81526020902060005b868110156117145781548b8201529085019083016116fb565b505084890196505b509498975050505050505050565b60006020828403121561173c57600080fd5b5051919050565b600081600019048311821515161561175d5761175d611640565b500290565b60008261177f57634e487b7160e01b600052601260045260246000fd5b500490565b6000821982111561179757611797611640565b500190565b600082516117ae8184602087016114df565b9190910192915050565b8281526040602082015260006117d1604083018461150b565b949350505050565b6000828210156117eb576117eb611640565b500390565b634e487b7160e01b600052603160045260246000fdfea264697066735822122071d70ee063981b257f7c33abb57b9b06e15a3bf0d003a4ba2d26eb48e284039e64736f6c634300080a0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000cf64698aff7e5f27a11dff868af228653ba53be0000000000000000000000000bf57539473913685688d224ad4e262684b23dd4c
-----Decoded View---------------
Arg [0] : addressProvider (address): 0xcF64698AFF7E5f27A11dff868AF228653ba53be0
Arg [1] : tokenDistributorOld (address): 0xBF57539473913685688d224ad4E262684B23dD4c
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000cf64698aff7e5f27a11dff868af228653ba53be0
Arg [1] : 000000000000000000000000bf57539473913685688d224ad4e262684b23dd4c
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
[ 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.