More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 2,014 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Create Reverse S... | 21061042 | 15 hrs ago | IN | 0 ETH | 0.00201187 | ||||
Restake | 21043954 | 3 days ago | IN | 0 ETH | 0.00381036 | ||||
Create Reverse S... | 21030432 | 4 days ago | IN | 0 ETH | 0.00383439 | ||||
Return ETH To Un... | 21024068 | 5 days ago | IN | 0.20199639 ETH | 0.00101908 | ||||
Return ETH To Un... | 21024058 | 5 days ago | IN | 0.02916867 ETH | 0.00100284 | ||||
Return ETH To Un... | 21024053 | 5 days ago | IN | 0.0230082 ETH | 0.00108465 | ||||
Return ETH To Un... | 21024037 | 5 days ago | IN | 0.05758183 ETH | 0.00109684 | ||||
Return ETH To Un... | 21024033 | 5 days ago | IN | 0.04707219 ETH | 0.00120989 | ||||
Create Reverse S... | 21022015 | 6 days ago | IN | 0 ETH | 0.0053963 | ||||
Return ETH To Un... | 21018011 | 6 days ago | IN | 0.01408734 ETH | 0.00104781 | ||||
Return ETH To Un... | 21016897 | 6 days ago | IN | 0.01394987 ETH | 0.00082317 | ||||
Return ETH To Un... | 21016838 | 6 days ago | IN | 0.02048545 ETH | 0.00101551 | ||||
Return ETH To Un... | 21016825 | 6 days ago | IN | 0.055 ETH | 0.00149174 | ||||
Return ETH To Un... | 21016817 | 6 days ago | IN | 0.03460113 ETH | 0.00095882 | ||||
Return ETH To Un... | 21016784 | 6 days ago | IN | 0.03288674 ETH | 0.00100973 | ||||
Return ETH To Un... | 21016737 | 6 days ago | IN | 0.00511867 ETH | 0.0011183 | ||||
Return ETH To Un... | 21016717 | 6 days ago | IN | 0.01985722 ETH | 0.00115604 | ||||
Return ETH To Un... | 21011657 | 7 days ago | IN | 0.1 ETH | 0.00093822 | ||||
Create Reverse S... | 21010368 | 7 days ago | IN | 0 ETH | 0.00262484 | ||||
Create Reverse S... | 21010357 | 7 days ago | IN | 0 ETH | 0.00282123 | ||||
Create Reverse S... | 21009795 | 7 days ago | IN | 0 ETH | 0.00242335 | ||||
Create Reverse S... | 21009571 | 7 days ago | IN | 0 ETH | 0.00254185 | ||||
Create Reverse S... | 21009383 | 7 days ago | IN | 0 ETH | 0.00252991 | ||||
Return ETH To Un... | 20998116 | 9 days ago | IN | 0.035 ETH | 0.00132158 | ||||
Create Reverse S... | 20995615 | 9 days ago | IN | 0 ETH | 0.00283358 |
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
21024068 | 5 days ago | 0.20199639 ETH | ||||
21024058 | 5 days ago | 0.02916867 ETH | ||||
21024053 | 5 days ago | 0.0230082 ETH | ||||
21024037 | 5 days ago | 0.05758183 ETH | ||||
21024033 | 5 days ago | 0.04707219 ETH | ||||
21018011 | 6 days ago | 0.01408734 ETH | ||||
21016897 | 6 days ago | 0.01394987 ETH | ||||
21016838 | 6 days ago | 0.02048545 ETH | ||||
21016825 | 6 days ago | 0.055 ETH | ||||
21016817 | 6 days ago | 0.03460113 ETH | ||||
21016784 | 6 days ago | 0.03288674 ETH | ||||
21016737 | 6 days ago | 0.00511867 ETH | ||||
21016717 | 6 days ago | 0.01985722 ETH | ||||
21011657 | 7 days ago | 0.1 ETH | ||||
20998116 | 9 days ago | 0.035 ETH | ||||
20975892 | 12 days ago | 0.125 ETH | ||||
20952392 | 15 days ago | 0.03255194 ETH | ||||
20952371 | 15 days ago | 0.0158811 ETH | ||||
20952361 | 15 days ago | 0.01202811 ETH | ||||
20936539 | 18 days ago | 1.6 ETH | ||||
20935018 | 18 days ago | 0.00524334 ETH | ||||
20932638 | 18 days ago | 0.03434818 ETH | ||||
20932520 | 18 days ago | 0.22 ETH | ||||
20932471 | 18 days ago | 0.23 ETH | ||||
20923296 | 19 days ago | 0.9 ETH |
Loading...
Loading
Contract Name:
VETHReverseStakingTreasury
Compiler Version
v0.8.18+commit.87f61d96
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.18; import { BackendAgent } from "./access/BackendAgent.sol"; import { VYToken } from "./token/VYToken.sol"; import { VETHP2P } from "./exchange/VETHP2P.sol"; import { VETHRevenueCycleTreasury } from "./exchange/VETHRevenueCycleTreasury.sol"; import { VETHYieldRateTreasury } from "./treasury/VETHYieldRateTreasury.sol"; import { RegistrarClient } from "./RegistrarClient.sol"; import { AdminGovernanceAgent } from "./access/AdminGovernanceAgent.sol"; import { Governable } from "./governance/Governable.sol"; import { RegistrarMigrator } from "./RegistrarMigrator.sol"; import { Registrar } from "./Registrar.sol"; import { Router } from "./Router.sol"; contract VETHReverseStakingTreasury is BackendAgent, RegistrarClient, RegistrarMigrator, AdminGovernanceAgent, Governable { uint256 private constant MINIMUM_REVERSE_STAKE_AUTOCLOSE = 100000000; // 0.1 gwei uint256 private constant MULTIPLIER = 10**18; uint256 private constant DAY_IN_SECONDS = 86400; bytes private constant ROUTE_SELECTOR = abi.encode(bytes4(keccak256("route()"))); uint256 private constant BURNACCRUEDVY_CACHE_DURATION = 6 hours; // We use this to get around stack too deep errors. struct TradeOfferVars { uint256 maxInput; uint256 ethFee; uint256 vyFee; uint256 vyOut; } struct CalcOfferRepayment { uint256 effectiveETHPaidOff; uint256 excessETH; uint256 excessStakedVY; uint256 vyToBurn; bool isPaidOff; } struct RestakeVars { uint256 newReverseStakeVY; uint256 newReverseStakeClaimedYieldETH; uint256 newReverseStakeId; uint256 startAt; uint256 vyToBurn; uint256 processingFeeETH; uint256 yieldPayout; uint256[] reverseStakeIds; uint256 vyYieldRate; } struct MigrateReverseStakeVars { address borrowerAddress; uint256 stakedVY; uint256 originalClaimedYieldETH; uint256 currentClaimedYieldETH; uint256 yieldRate; uint256 startAt; uint256 lastPaidAt; uint256 previousReverseStakeId; uint256 termId; } uint256 public constant ETH_FEE = 20000000000000000; uint256 public constant VY_FEE = 20000000000000000; /// @dev 1.020409; Buffer to account for fee uint256 public constant OFFER_PRICE_YR_RATIO = 1020409000000000000; /// @dev 0.98; 2% left over to account for burn rate over lifespan of offer uint256 public constant OFFER_NET_STAKE_RATIO = 980000000000000000; uint256 public constant EXPIRES_IN = 30 days; uint256 public constant MINIMUM_OFFER_AUTOCLOSE_IN_ETH = 500000000000000; // 0.0005 ETH uint256 public constant MAX_RESTAKE_REVERSE_STAKES = 20; VETHP2P private _vethP2P; VETHRevenueCycleTreasury private _vethRevenueCycleTreasury; VYToken private _vyToken; VETHYieldRateTreasury private _vethYRT; Router private _ethComptroller; address private _migration; uint256 private _reverseStakeTermsNonce = 0; uint256 private _reverseStakesNonce = 0; uint256 private _totalClaimedYieldETH = 0; uint256 private _maxReverseStakes = 20; uint256 private _burnAccruedVYYieldRate; uint256 private _burnAccruedVYTimestamp; // This contains the mutable reverse stake terms struct ReverseStakeTerm { uint256 dailyBurnRate; uint256 minimumReverseStakeETH; uint256 processingFeePercentage; uint256 restakeMinimumPayout; } // This contains reverseStake info per user struct ReverseStake { uint256 termId; uint256 stakedVY; uint256 originalClaimedYieldETH; // No longer used; kept for record-keeping uint256 currentClaimedYieldETH; uint256 yieldRate; // No longer used; kept for record-keeping uint256 startAt; uint256 lastPaidAt; } struct Offer { uint256 unfilledQuantity; uint256 price; uint256 maxClaimedYieldETH; // ClaimedYield at the time offer is created uint256 maxQuantity; // Max quantity at the time offer is created uint256 expiresAt; bool isOpen; } mapping(uint256 => ReverseStakeTerm) private _reverseStakeTerms; mapping(address => mapping(uint256 => ReverseStake)) private _reverseStakes; mapping(address => uint256) private _openReverseStakes; mapping(address => mapping(uint256 => Offer)) private _offers; event CreateReverseStakeTerm( uint256 termId, uint256 dailyBurnRate, uint256 minimumReverseStakeETH, uint256 processingFeePercentage, uint256 restakeMinimumPayout); event CreateReverseStake( address borrower, uint256 reverseStakeId, uint256 termId, uint256 stakedVY, uint256 originalClaimedYieldETH, uint256 currentClaimedYieldETH, uint256 yieldRate, uint256 startAt); event ReturnETHToUnstake( address borrower, uint256 reverseStakeId, uint256 ethAmount, uint256 currentClaimedYieldETH, uint256 stakedVY, uint256 stakedVYReturned, uint256 burnRatePaid, uint256 paidAt ); event MigrateReverseStake( address borrower, uint256 reverseStakeId, uint256 termId, uint256 stakedVY, uint256 originalClaimedYieldETH, uint256 currentClaimedYieldETH, uint256 yieldRate, uint256 startAt, uint256 previousReverseStakeId ); event CloseReverseStake(address borrower, uint256 reverseStakeId, uint256 stakeTransferred); event CreateOffer(address borrower, uint256 reverseStakeId, uint256 quantity, uint256 price, uint256 expiresAt, uint256 timestamp); event TradeOffer( address borrower, uint256 reverseStakeId, address buyer, uint256 sellerQuantity, uint256 buyerQuantity, uint256 unfilledQuantity, uint256 excessETH, uint256 timestamp ); event CloseOffer(address borrower, uint256 reverseStakeId, uint256 timestamp); event Restake( address borrower, uint256 reverseStakeId, uint256 stakedVY, uint256 originalClaimedYieldETH, uint256 currentClaimedYieldETH, uint256 yieldRate, uint256 startAt, uint256 yieldPayout, uint256[] previousReverseStakeIds, uint256 burnRatePaid, uint256 newTermId ); event BurnAccruedVY( address borrower, uint256 reverseStakeId, uint256 stakedVY, uint256 burnRatePaid, uint256 yieldRate ); constructor( address registrarAddress, address ethComptrollerAddress_, address[] memory adminGovAgents, address[] memory backendAdminAgents, address[] memory backendAgents, address[] memory adminAgents ) RegistrarClient(registrarAddress) RegistrarMigrator(registrarAddress, uint(Registrar.Contract.VETHReverseStakingTreasury), adminAgents) AdminGovernanceAgent(adminGovAgents) { require(ethComptrollerAddress_ != address(0), "Invalid address"); _ethComptroller = Router(payable(ethComptrollerAddress_)); _setBackendAdminAgents(backendAdminAgents); _setBackendAgents(backendAgents); } modifier onlyActiveReverseStake(address borrower, uint256 reverseStakeId) { _checkValidReverseStake(_reverseStakes[borrower][reverseStakeId].startAt > 0); _checkActiveReverseStake(isReverseStakeActive(borrower, reverseStakeId)); _; } modifier onlyActiveOffer(address borrower, uint256 reverseStakeId) { require(_offers[borrower][reverseStakeId].isOpen && _offers[borrower][reverseStakeId].expiresAt > block.timestamp, "Invalid offer"); _; } modifier onlyOpenOffer(uint256 id, address borrower) { require(_offers[borrower][id].isOpen, "Offer must be open in order to close"); _; } function setupInitialReverseStakeTerm( uint256 dailyBurnRate, uint256 minimumReverseStakeETH, uint256 processingFeePercentage, uint256 restakeMinimumPayout ) external onlyBackendAdminAgents { require(_reverseStakeTermsNonce == 0, "Reverse stake terms already set up"); _createNewReverseStakeTerm( dailyBurnRate, minimumReverseStakeETH, processingFeePercentage, restakeMinimumPayout ); } function createNewReverseStakeTerm( uint256 dailyBurnRate, uint256 minimumReverseStakeETH, uint256 processingFeePercentage, uint256 restakeMinimumPayout ) external onlyGovernance { _createNewReverseStakeTerm( dailyBurnRate, minimumReverseStakeETH, processingFeePercentage, restakeMinimumPayout ); } /** * @dev Returns total claimed yield in ETH */ function getTotalClaimedYield() external view returns (uint256) { return _totalClaimedYieldETH; } function getReverseStake(address borrower, uint256 reverseStakeId) external view returns (ReverseStake memory) { return _reverseStakes[borrower][reverseStakeId]; } function isReverseStakeActive(address borrower, uint256 reverseStakeId) public view returns (bool) { return _reverseStakes[borrower][reverseStakeId].currentClaimedYieldETH > 0; } function isOfferActive(address borrower, uint256 reverseStakeId) external view returns (bool) { return _offers[borrower][reverseStakeId].isOpen && _offers[borrower][reverseStakeId].expiresAt > block.timestamp; } function getReverseStakeTerm(uint256 termId) external view returns (ReverseStakeTerm memory) { return _reverseStakeTerms[termId]; } function getCurrentReverseStakeTerm() external view returns (ReverseStakeTerm memory) { return _reverseStakeTerms[_reverseStakeTermsNonce]; } function getCurrentReverseStakeTermId() external view returns (uint256) { return _reverseStakeTermsNonce; } function ethToBurn(address borrower, uint256 reverseStakeId) external view returns (uint256) { return _ethToBurn(borrower, reverseStakeId); } function vyToBurn(address borrower, uint256 reverseStakeId) external view returns (uint256) { return _vyToBurn(borrower, reverseStakeId); } function getStakedVYForReverseStakeETH(uint256 ethAmount) external view returns (uint256) { return _getStakedVYForReverseStakeETH(ethAmount); } function getMaxReverseStakes() external view returns (uint256) { return _maxReverseStakes; } function getReverseStakesNonce() external view returns (uint256) { return _reverseStakesNonce; } function getBurnAccruedVYYieldRate() external view returns (uint256) { return _burnAccruedVYYieldRate; } function getBurnAccruedVYTimestamp() external view returns (uint256) { return _burnAccruedVYTimestamp; } function setMaxReverseStakes(uint256 maxReverseStakes_) external onlyBackendAdminAgents { _maxReverseStakes = maxReverseStakes_; } function getMigration() external view returns (address) { return _migration; } function setMigration(address destination) external onlyGovernance { _migration = destination; } function transferMigration(uint256 amount) external onlyAdminGovAgents { require(_migration != address(0), "Migration not set"); _checkSufficientBalance(_vyToken.balanceOf(address(this)) >= amount); _transferVY(_migration, amount); } function createReverseStake(uint256 termId, uint256 ethAmount, uint256 vyAmount) external { require(_vyToken.allowance(_msgSender(), address(this)) >= vyAmount, "Insufficient allowance"); require(_vyToken.balanceOf(_msgSender()) >= vyAmount, "Insufficient balance"); uint256 minStake = _createReverseStakePrerequisite(termId, ethAmount, vyAmount); _createReverseStake(ethAmount, minStake); } function createReverseStake(uint256 termId, uint256 ethAmount, uint256 vyAmount, uint8 v, bytes32 r, bytes32 s) external { uint256 minStake = _createReverseStakePrerequisite(termId, ethAmount, vyAmount); // Call approval _vyToken.permit(_msgSender(), address(this), vyAmount, v, r, s); _createReverseStake(ethAmount, minStake); } function _createReverseStake(uint256 ethAmount, uint256 stakedVY) private { ReverseStakeTerm memory reverseStakeTerm = _reverseStakeTerms[_reverseStakeTermsNonce]; require(ethAmount >= reverseStakeTerm.minimumReverseStakeETH, "Minimum reverse stake ETH not met"); uint256 circulation = _vethRevenueCycleTreasury.getVETHCirculation(); require(_vyToken.balanceOf(address(this)) + stakedVY <= circulation, "Total staked VY cannot exceed circulation"); uint256 reverseStakeId = ++_reverseStakesNonce; uint256 ethComptrollerReceives = ethAmount * reverseStakeTerm.processingFeePercentage / MULTIPLIER; uint256 borrowerReceives = ethAmount - ethComptrollerReceives; uint256 startAt = block.timestamp; uint256 vyYieldRate = _vethRevenueCycleTreasury.getYieldRate(); _reverseStakes[_msgSender()][reverseStakeId] = ReverseStake(_reverseStakeTermsNonce, stakedVY, ethAmount, ethAmount, vyYieldRate, startAt, 0); _openReverseStakes[_msgSender()]++; _totalClaimedYieldETH += ethAmount; _vyToken.transferFrom(_msgSender(), address(this), stakedVY); _vethYRT.reverseStakingTransfer(_msgSender(), borrowerReceives); _vethYRT.reverseStakingRoute(address(_ethComptroller), ethComptrollerReceives, ROUTE_SELECTOR); emit CreateReverseStake(_msgSender(), reverseStakeId, _reverseStakeTermsNonce, stakedVY, ethAmount, ethAmount, vyYieldRate, startAt); } function returnETHToUnstake(uint256 reverseStakeId) external payable onlyActiveReverseStake(_msgSender(), reverseStakeId) { require(msg.value > 0, "Zero ETH amount sent"); _checkActiveOffer(_offers[_msgSender()][reverseStakeId].isOpen); ReverseStake storage reverseStake = _reverseStakes[_msgSender()][reverseStakeId]; uint256 vyToBurn_ = _vyToBurn(_msgSender(), reverseStakeId); require(reverseStake.stakedVY >= vyToBurn_, "Not enough staked VY to burn"); reverseStake.stakedVY -= vyToBurn_; uint256 excessETH = 0; uint256 stakedVYReturned = 0; uint256 ethAmount = msg.value; if (ethAmount > reverseStake.currentClaimedYieldETH) { excessETH = ethAmount - reverseStake.currentClaimedYieldETH; ethAmount = reverseStake.currentClaimedYieldETH; } if (reverseStake.currentClaimedYieldETH == ethAmount) { stakedVYReturned = reverseStake.stakedVY; _decrementOpenReverseStakesAndCloseOffer(_msgSender(), reverseStakeId, 0); } else { stakedVYReturned = reverseStake.stakedVY * ethAmount / reverseStake.currentClaimedYieldETH; } reverseStake.currentClaimedYieldETH -= ethAmount; reverseStake.stakedVY -= stakedVYReturned; reverseStake.lastPaidAt = block.timestamp; _totalClaimedYieldETH -= ethAmount; _transferToRevenueCycleTreasury(vyToBurn_); _transferVY(_msgSender(), stakedVYReturned); _transfer(address(_vethYRT), ethAmount); if (excessETH > 0) { _transfer(_msgSender(), excessETH); } emit ReturnETHToUnstake( _msgSender(), reverseStakeId, ethAmount, reverseStake.currentClaimedYieldETH, reverseStake.stakedVY, stakedVYReturned, vyToBurn_, reverseStake.lastPaidAt ); } function restake(uint256[] memory reverseStakeIds) external { address borrower = _msgSender(); require(reverseStakeIds.length > 0 && reverseStakeIds.length <= MAX_RESTAKE_REVERSE_STAKES, "Invalid number of reverseStakes"); uint256 totalCurrentClaimedYieldETH; RestakeVars memory reverseStakeData = RestakeVars(0, 0, 0, 0, 0, 0, 0, new uint256[](reverseStakeIds.length), 0); // Sum all VYs to burn and principals + close reverseStakes for (uint i = 0; i < reverseStakeIds.length; i++) { uint256 reverseStakeId = reverseStakeIds[i]; reverseStakeData.reverseStakeIds[i] = reverseStakeId; // Requirements _checkValidReverseStake(_reverseStakes[borrower][reverseStakeId].startAt > 0); _checkActiveReverseStake(isReverseStakeActive(borrower, reverseStakeId)); _checkActiveOffer(_offers[borrower][reverseStakeId].isOpen); ReverseStake storage reverseStake = _reverseStakes[borrower][reverseStakeId]; // Sum VY to burn uint256 vyToBurn_ = _vyToBurn(borrower, reverseStakeId); // Calculate VY to burn reverseStakeData.vyToBurn += vyToBurn_; // Sum principal after VY to burn require(reverseStake.stakedVY >= vyToBurn_, "Not enough staked VY to burn"); uint256 newReverseStakeVY = reverseStake.stakedVY - vyToBurn_; reverseStakeData.newReverseStakeVY += newReverseStakeVY; // Close reverseStake totalCurrentClaimedYieldETH += reverseStake.currentClaimedYieldETH; reverseStake.stakedVY = 0; reverseStake.currentClaimedYieldETH = 0; if (_openReverseStakes[borrower] > 0) { _openReverseStakes[borrower]--; } } // Create new reverseStake reverseStakeData.vyYieldRate = _vethRevenueCycleTreasury.getYieldRate(); reverseStakeData.newReverseStakeClaimedYieldETH = reverseStakeData.newReverseStakeVY * MULTIPLIER / reverseStakeData.vyYieldRate; // Calculate new reverseStake principal reverseStakeData.newReverseStakeId = ++_reverseStakesNonce; reverseStakeData.startAt = block.timestamp; _reverseStakes[borrower][reverseStakeData.newReverseStakeId] = ReverseStake( _reverseStakeTermsNonce, // termId reverseStakeData.newReverseStakeVY, // stakedVY reverseStakeData.newReverseStakeClaimedYieldETH, // originalClaimedYieldETH reverseStakeData.newReverseStakeClaimedYieldETH, // currentClaimedYieldETH reverseStakeData.vyYieldRate, // yieldRate reverseStakeData.startAt, // startAt 0); // lastPaidAt _openReverseStakes[borrower]++; // Update totalClaimedYield require(reverseStakeData.newReverseStakeClaimedYieldETH >= totalCurrentClaimedYieldETH, "Restaked reverseStakes must increase in value"); reverseStakeData.yieldPayout = reverseStakeData.newReverseStakeClaimedYieldETH - totalCurrentClaimedYieldETH; _totalClaimedYieldETH += reverseStakeData.yieldPayout; // Processing fee reverseStakeData.processingFeeETH = reverseStakeData.yieldPayout * _reverseStakeTerms[_reverseStakeTermsNonce].processingFeePercentage / MULTIPLIER; // Yield payout require(reverseStakeData.yieldPayout >= _reverseStakeTerms[_reverseStakeTermsNonce].restakeMinimumPayout, "Minimum yield payout not met"); reverseStakeData.yieldPayout -= reverseStakeData.processingFeeETH; // Transfers _vethYRT.reverseStakingTransfer(borrower, reverseStakeData.yieldPayout); _vethYRT.reverseStakingRoute(address(_ethComptroller), reverseStakeData.processingFeeETH, ROUTE_SELECTOR); _transferToRevenueCycleTreasury(reverseStakeData.vyToBurn); emit Restake( borrower, // borrower reverseStakeData.newReverseStakeId, // reverseStakeId reverseStakeData.newReverseStakeVY, // stakedVY reverseStakeData.newReverseStakeClaimedYieldETH, // originalClaimedYieldETH reverseStakeData.newReverseStakeClaimedYieldETH, // currentClaimedYieldETH reverseStakeData.vyYieldRate, // yieldRate reverseStakeData.startAt, // startAt reverseStakeData.yieldPayout, // yieldPayout reverseStakeData.reverseStakeIds, // previousReverseStakeIds reverseStakeData.vyToBurn, // burnRatePaid _reverseStakeTermsNonce // newTermId ); } function burnAccruedVY(address[] memory borrowers, uint256[] memory reverseStakeIds) external onlyBackendAgents { require(borrowers.length == reverseStakeIds.length, "Argument array length mismatch"); if (block.timestamp > _burnAccruedVYTimestamp + BURNACCRUEDVY_CACHE_DURATION) { // Update cache _burnAccruedVYYieldRate = _vethRevenueCycleTreasury.getYieldRate(); _burnAccruedVYTimestamp = block.timestamp; } uint256 totalVYToBurn; for (uint i = 0; i < reverseStakeIds.length; i++) { uint256 reverseStakeId = reverseStakeIds[i]; address borrower = borrowers[i]; ReverseStake storage reverseStake = _reverseStakes[borrower][reverseStakeId]; // Requirements _checkValidReverseStake(reverseStake.startAt > 0); if (!isReverseStakeActive(borrower, reverseStakeId)) { continue; } // Calculate burn using cached yield rate uint256 vyToBurn_ = _vyToBurn(borrower, reverseStakeId, _burnAccruedVYYieldRate); if (vyToBurn_ == 0) { continue; } uint256 burnRatePaid = vyToBurn_; if (reverseStake.stakedVY <= vyToBurn_) { burnRatePaid = reverseStake.stakedVY; // Before closing make sure reverse stake is still open require(reverseStake.stakedVY > 0 && reverseStake.currentClaimedYieldETH > 0, "ReverseStake is already closed"); // Update total claimed yield as part of closing _totalClaimedYieldETH -= reverseStake.currentClaimedYieldETH; // Update reverseStake and offer (if any) upon closing _decrementOpenReverseStakesAndCloseOffer(borrower, reverseStakeId, reverseStake.stakedVY); reverseStake.stakedVY = 0; reverseStake.currentClaimedYieldETH = 0; } else { reverseStake.stakedVY -= vyToBurn_; reverseStake.lastPaidAt = block.timestamp; } totalVYToBurn += burnRatePaid; emit BurnAccruedVY(borrower, reverseStakeId, reverseStake.stakedVY, burnRatePaid, _burnAccruedVYYieldRate); } // Transfer totalVYToBurn outside of loop instead of transferring vyToBurn each time within the for loop. // This is to avoid a yield rate change affecting subsequent vyToBurn calculations within the for loop. _transferToRevenueCycleTreasury(totalVYToBurn); } function createOffer(uint256 reverseStakeId, uint256 quantity, uint256 price) external onlyActiveReverseStake(_msgSender(), reverseStakeId) { _checkValidQuantity(quantity); require(!_offers[_msgSender()][reverseStakeId].isOpen, "Limit one offer per reverseStake"); ReverseStake memory reverseStake = _reverseStakes[_msgSender()][reverseStakeId]; // OFFER_NET_STAKE_RATIO uint256 vyToBurn_ = _vyToBurn(_msgSender(), reverseStakeId); require(reverseStake.stakedVY >= vyToBurn_, "Not enough staked VY"); uint256 maximumQuantity = (reverseStake.stakedVY - vyToBurn_) * OFFER_NET_STAKE_RATIO / MULTIPLIER; require(quantity <= maximumQuantity, "Quantity exceeds limit"); // We're creating a [VY_ETH] offer: // min price = (current claimed yield / (remaining staked VY after burned VY * 0.98)) * 1.020409 uint256 minPrice = reverseStake.currentClaimedYieldETH * OFFER_PRICE_YR_RATIO / maximumQuantity; _checkMinPrice(price >= minPrice); // As yieldRate gets lower, actual "price" gets higher due to inversion // adjustedYieldRate = yield rate / 1.020409 uint256 adjustedYieldRate = _vethRevenueCycleTreasury.getYieldRate() * MULTIPLIER / OFFER_PRICE_YR_RATIO; require((MULTIPLIER * MULTIPLIER / price) <= adjustedYieldRate, "Price too low"); // Set offer expiration uint256 expiresAt = block.timestamp + EXPIRES_IN; // Create offer _offers[_msgSender()][reverseStakeId] = Offer(quantity, price, reverseStake.currentClaimedYieldETH, maximumQuantity, expiresAt, true); emit CreateOffer(_msgSender(), reverseStakeId, quantity, price, expiresAt, block.timestamp); } /** * @dev This is for other members to trade on the offer the borrower created */ function tradeOffer(address borrower, uint256 reverseStakeId) external payable onlyActiveOffer(borrower, reverseStakeId) { _checkValidQuantity(msg.value); Offer storage offer = _offers[borrower][reverseStakeId]; ReverseStake storage reverseStake = _reverseStakes[borrower][reverseStakeId]; TradeOfferVars memory info; info.maxInput = offer.unfilledQuantity * offer.price / MULTIPLIER; _checkEnoughAmountToSell(msg.value <= info.maxInput); info.ethFee = msg.value * ETH_FEE / MULTIPLIER; info.vyFee = msg.value * VY_FEE / offer.price; info.vyOut = msg.value * MULTIPLIER / offer.price; // Calculate and update reverseStake CalcOfferRepayment memory calc = _payReverseStakeVY( borrower, reverseStakeId, info.vyOut, offer.maxClaimedYieldETH, offer.maxQuantity, msg.value - info.ethFee ); // Update offer if (!calc.isPaidOff) { if (info.vyOut > offer.unfilledQuantity) { info.vyOut = offer.unfilledQuantity; } offer.unfilledQuantity -= info.vyOut; // If remaining quantity is low enough, close it out // VY_ETH market - converted selling amount in VY to ETH < MINIMUM_OFFER_AUTOCLOSE_IN_ETH bool takerCloseout = (offer.unfilledQuantity * offer.price / MULTIPLIER) < MINIMUM_OFFER_AUTOCLOSE_IN_ETH; // console.log("unfilledQuantity: %s, takerCloseout: %s, amount: %s", offer.unfilledQuantity, takerCloseout, offer.unfilledQuantity * offer.price / MULTIPLIER); if (takerCloseout) { // Auto-close when selling amount in ETH < MINIMUM_OFFER_AUTOCLOSE_IN_ETH // No need to return VY from offer, since it was reserving // the VY directly from borrower's stakedVY pool. _closeOffer(borrower, reverseStakeId); } } _totalClaimedYieldETH -= calc.effectiveETHPaidOff; // Send out VY fee + VY to burn. // Note that we have 2% VY buffer in the staked VY, as // the offer can only be created with 98% of staked VY max. _transferToRevenueCycleTreasury(info.vyFee + calc.vyToBurn); // Send out VY to buyer _transferVY(_msgSender(), info.vyOut - info.vyFee); // Send out ETH fee _ethComptroller.route{ value: info.ethFee }(); // Send out to VETHYieldRateTreasury _transfer(address(_vethYRT), msg.value - calc.excessETH - info.ethFee); if (calc.excessETH > 0) { // Send excess to borrower _transfer(borrower, calc.excessETH); } if (calc.excessStakedVY > 0) { // Return excess VY to borrower (if any) once reverseStake is repaid in full _transferVY(borrower, calc.excessStakedVY); } emit TradeOffer(borrower, reverseStakeId, _msgSender(), info.vyOut, msg.value, offer.unfilledQuantity, calc.excessETH, reverseStake.lastPaidAt); emit ReturnETHToUnstake( borrower, reverseStakeId, calc.effectiveETHPaidOff, reverseStake.currentClaimedYieldETH, reverseStake.stakedVY, 0, calc.vyToBurn, reverseStake.lastPaidAt ); } /** * @dev This is for the borrower to sell their staked VY to other users */ function tradeStakedVY(uint256 reverseStakeId, uint256 offerId, address seller, uint256 amountVY) external onlyActiveReverseStake(_msgSender(), reverseStakeId) { _tradeStakedVYPrerequisite(reverseStakeId, amountVY); ReverseStake storage reverseStake = _reverseStakes[_msgSender()][reverseStakeId]; // We are trading on a member's [ETH_VY] offer, so their price will be VY/ETH. VETHP2P.Offer memory offer = _vethP2P.getOffer(offerId, seller); require(offer.isOpen == true && offer.quantity > 0, "Offer is closed or has zero quantity"); uint256 vyToBurn_ = _vyToBurn(_msgSender(), reverseStakeId); // min price formula = (current claimed yield / remaining staked VY after burned VY) * 1.020409 // In this case it's actually max price due to inversion. uint256 maxPrice = reverseStake.currentClaimedYieldETH * OFFER_PRICE_YR_RATIO / (reverseStake.stakedVY - vyToBurn_); maxPrice = MULTIPLIER * MULTIPLIER / maxPrice; _checkMinPrice(offer.price <= maxPrice); _vyToken.approve(address(_vethP2P), amountVY); // Calculate (estimate) and update state first VETHP2P.TradeOfferCalcInfo memory calc = _vethP2P.estimateTradeOffer(offerId, seller, amountVY); CalcOfferRepayment memory reverseStakeCalcs = _payReverseStakeVY( _msgSender(), reverseStakeId, amountVY, reverseStake.currentClaimedYieldETH, reverseStake.stakedVY - vyToBurn_, calc.amountOut - calc.takerFee ); // This needs to be updated last (but before transfers) // as this affects the yield rate. _totalClaimedYieldETH -= reverseStakeCalcs.effectiveETHPaidOff; // Execute actual swap VETHP2P.TradeOfferCalcInfo memory realCalc = _vethP2P.tradeOffer(offerId, seller, amountVY); require(calc.amountOut == realCalc.amountOut, "amountOut does not match"); // Send out funds post-swap _transferToRevenueCycleTreasury(reverseStakeCalcs.vyToBurn); _transfer(address(_vethYRT), realCalc.amountOut - reverseStakeCalcs.excessETH - realCalc.takerFee); if (reverseStakeCalcs.excessETH > 0) { // Send excess to borrower _transfer(_msgSender(), reverseStakeCalcs.excessETH); } if (reverseStakeCalcs.excessStakedVY > 0) { // Return excess VY to borrower (if any) once reverseStake is repaid in full _transferVY(_msgSender(), reverseStakeCalcs.excessStakedVY); } emit ReturnETHToUnstake( _msgSender(), reverseStakeId, reverseStakeCalcs.effectiveETHPaidOff, reverseStake.currentClaimedYieldETH, reverseStake.stakedVY, 0, reverseStakeCalcs.vyToBurn, reverseStake.lastPaidAt ); } function closeOffer(uint256 reverseStakeId) external onlyOpenOffer(reverseStakeId, _msgSender()) { _closeOffer(_msgSender(), reverseStakeId); } function closeOffer(address borrower, uint256 reverseStakeId) external onlyOpenOffer(reverseStakeId, borrower) onlyBackendAgents { _closeOffer(borrower, reverseStakeId); } function getOffer(address borrower, uint256 reverseStakeId) external view returns (Offer memory) { return _offers[borrower][reverseStakeId]; } function updateAddresses() external override onlyRegistrar { _vethP2P = VETHP2P(_registrar.getVETHP2P()); _vethRevenueCycleTreasury = VETHRevenueCycleTreasury(_registrar.getVETHRevenueCycleTreasury()); _vyToken = VYToken(_registrar.getVYToken()); _vethYRT = VETHYieldRateTreasury(payable(_registrar.getVETHYieldRateTreasury())); _updateGovernable(_registrar); } function _migrateReverseStake( address borrowerAddress, uint256 stakedVY, uint256 originalClaimedYieldETH, uint256 currentClaimedYieldETH, uint256 yieldRate, uint256 startAt, uint256 lastPaidAt, uint256 previousReverseStakeId, uint256 termId ) private { require(startAt > 0, "Previous reverseStake invalid"); uint256 reverseStakeId = ++_reverseStakesNonce; _reverseStakes[borrowerAddress][reverseStakeId] = ReverseStake(termId, stakedVY, originalClaimedYieldETH, currentClaimedYieldETH, yieldRate, startAt, lastPaidAt); _openReverseStakes[borrowerAddress]++; _totalClaimedYieldETH += currentClaimedYieldETH; emit MigrateReverseStake(borrowerAddress, reverseStakeId, termId, stakedVY, originalClaimedYieldETH, currentClaimedYieldETH, yieldRate, startAt, previousReverseStakeId); } function migrateReverseStakes( MigrateReverseStakeVars[] calldata reverseStakeDataArray ) external onlyBackendAgents onlyUnfinalized { for (uint i = 0; i < reverseStakeDataArray.length; i++) { _migrateReverseStake( reverseStakeDataArray[i].borrowerAddress, reverseStakeDataArray[i].stakedVY, reverseStakeDataArray[i].originalClaimedYieldETH, reverseStakeDataArray[i].currentClaimedYieldETH, reverseStakeDataArray[i].yieldRate, reverseStakeDataArray[i].startAt, reverseStakeDataArray[i].lastPaidAt, reverseStakeDataArray[i].previousReverseStakeId, reverseStakeDataArray[i].termId ); } } function _createNewReverseStakeTerm( uint256 dailyBurnRate, uint256 minimumReverseStakeETH, uint256 processingFeePercentage, uint256 restakeMinimumPayout ) private { _reverseStakeTerms[++_reverseStakeTermsNonce] = ReverseStakeTerm( dailyBurnRate, minimumReverseStakeETH, processingFeePercentage, restakeMinimumPayout ); emit CreateReverseStakeTerm( _reverseStakeTermsNonce, dailyBurnRate, minimumReverseStakeETH, processingFeePercentage, restakeMinimumPayout ); } function _getStakedVYForReverseStakeETH(uint256 ethAmount) private view returns (uint256) { uint256 vyYieldRate = _vethRevenueCycleTreasury.getYieldRate(); return vyYieldRate * ethAmount / MULTIPLIER; } // rounding down basis, meaning for 11.6 days borrower will burn VY for 11 days // we have to account for the case where borrower might pay at 11.6 days and another payment at 20.4 days // because 20.4-11.6 = 8.8 days we cannot calculate directly otherwise 11+8 = 19 days of burn rate instead of 20 // therefore we have to look at the number of days in total minus the number of days borrower has paid function _daysElapsed(uint256 startAt, uint256 lastPaidAt) private view returns (uint256) { uint256 currentTime = block.timestamp; if (lastPaidAt > 0) { uint256 daysTotal = (currentTime - startAt) / DAY_IN_SECONDS; uint256 daysPaid = (lastPaidAt - startAt) / DAY_IN_SECONDS; return daysTotal - daysPaid; } else { return (currentTime - startAt) / DAY_IN_SECONDS; } } function _ethToBurn(address borrower, uint256 reverseStakeId) private view returns (uint256) { ReverseStake memory reverseStake = _reverseStakes[borrower][reverseStakeId]; ReverseStakeTerm memory reverseStakeTerm = _reverseStakeTerms[reverseStake.termId]; uint256 daysElapsed = _daysElapsed(reverseStake.startAt, reverseStake.lastPaidAt); return reverseStake.currentClaimedYieldETH * reverseStakeTerm.dailyBurnRate * daysElapsed / MULTIPLIER; } function _vyToBurn(address borrower, uint256 reverseStakeId) private view returns (uint256) { uint256 ethToBurn_ = _ethToBurn(borrower, reverseStakeId); uint256 vyYieldRate = _vethRevenueCycleTreasury.getYieldRate(); return ethToBurn_ * vyYieldRate / MULTIPLIER; } function _vyToBurn(address borrower, uint256 reverseStakeId, uint256 vyYieldRate) private view returns (uint256) { uint256 ethToBurn_ = _ethToBurn(borrower, reverseStakeId); return ethToBurn_ * vyYieldRate / MULTIPLIER; } /** * @dev Pay off reverseStake by selling staked VY */ function _payReverseStakeVY(address borrower, uint256 reverseStakeId, uint256 vyToTrade, uint256 maxClaimedYieldETH, uint256 maxVY, uint256 amountETH) private returns (CalcOfferRepayment memory) { ReverseStake storage reverseStake = _reverseStakes[borrower][reverseStakeId]; CalcOfferRepayment memory calc; // uint256 percentagePaidOff = vyToTrade * MULTIPLIER / maxVY; // calc.effectiveETHPaidOff = percentagePaidOff * maxClaimedYieldETH / MULTIPLIER; calc.effectiveETHPaidOff = vyToTrade * maxClaimedYieldETH / maxVY; if (amountETH > calc.effectiveETHPaidOff) { calc.excessETH = amountETH - calc.effectiveETHPaidOff; } calc.vyToBurn = _vyToBurn(borrower, reverseStakeId); // console.log("vyToTrade: %s\npercentagePaidOff: %s\neffectiveETHPaidOff: %s", vyToTrade, percentagePaidOff, calc.effectiveETHPaidOff); // console.log("excessETH: %s\nvyToBurn: %s\nstake: %s", calc.excessETH, calc.vyToBurn, reverseStake.stakedVY); // console.log("amountETH: %s", amountETH); // Update reverseStake require(reverseStake.stakedVY >= vyToTrade + calc.vyToBurn, "Not enough staked VY"); reverseStake.stakedVY -= vyToTrade + calc.vyToBurn; // Handle possible precision issues if (calc.effectiveETHPaidOff > reverseStake.currentClaimedYieldETH) { calc.effectiveETHPaidOff = reverseStake.currentClaimedYieldETH; } if (reverseStake.currentClaimedYieldETH > calc.effectiveETHPaidOff && (reverseStake.currentClaimedYieldETH - calc.effectiveETHPaidOff <= MINIMUM_REVERSE_STAKE_AUTOCLOSE)) { calc.effectiveETHPaidOff = reverseStake.currentClaimedYieldETH; } // ReverseStake paid off? if (calc.effectiveETHPaidOff == reverseStake.currentClaimedYieldETH) { calc.isPaidOff = true; _decrementOpenReverseStakesAndCloseOffer(borrower, reverseStakeId, 0); // If there is any remaining staked VY, record that // so we can later return it to borrower. if (reverseStake.stakedVY > 0) { calc.excessStakedVY = reverseStake.stakedVY; reverseStake.stakedVY = 0; } } // Update rest of reverseStake reverseStake.currentClaimedYieldETH -= calc.effectiveETHPaidOff; reverseStake.lastPaidAt = block.timestamp; // console.log("currentClaimedYieldETH: %s, excessStakedVY: %s", reverseStake.currentClaimedYieldETH, calc.excessStakedVY); // console.log("stakedVY: %s", reverseStake.stakedVY); return calc; } function _createReverseStakePrerequisite(uint256 termId, uint256 ethAmount, uint256 vyAmount) private view returns (uint256) { require(termId == _reverseStakeTermsNonce, "Invalid reverse stake term specified"); require(_openReverseStakes[_msgSender()] < _maxReverseStakes, "Maximum reverse stakes reached"); uint256 minStake = _getStakedVYForReverseStakeETH(ethAmount); require(vyAmount >= minStake, "vyAmount too low based on yield rate"); return minStake; } function _tradeStakedVYPrerequisite(uint256 reverseStakeId, uint256 amountVY) private view { _checkValidQuantity(amountVY); Offer memory offer = _offers[_msgSender()][reverseStakeId]; _checkActiveOffer(offer.isOpen); ReverseStake memory reverseStake = _reverseStakes[_msgSender()][reverseStakeId]; uint256 vyToBurn_ = _vyToBurn(_msgSender(), reverseStakeId); require(reverseStake.stakedVY >= vyToBurn_, "Not enough staked VY"); uint256 remainingStake = reverseStake.stakedVY - vyToBurn_; _checkEnoughAmountToSell(amountVY <= remainingStake); } function _transferToRevenueCycleTreasury(uint256 amount) private { _transferVY(address(_vethRevenueCycleTreasury), amount); } function _decrementOpenReverseStakesAndCloseOffer(address borrower, uint256 reverseStakeId, uint256 stakeTransferred) internal { if (_openReverseStakes[borrower] > 0) { _openReverseStakes[borrower]--; } if (_offers[borrower][reverseStakeId].isOpen) { _closeOffer(borrower, reverseStakeId); } emit CloseReverseStake(borrower, reverseStakeId, stakeTransferred); } function _closeOffer(address borrower, uint256 reverseStakeId) internal { delete _offers[borrower][reverseStakeId]; emit CloseOffer(borrower, reverseStakeId, block.timestamp); } function _transferVY(address recipient, uint256 amount) private { if (amount > 0) { _vyToken.transfer(recipient, amount); } } function _checkActiveOffer(bool isOpen) private pure { require(!isOpen, "Active offer found"); } function _checkMinPrice(bool minPriceMet) private pure { require(minPriceMet, "Minimum price not met"); } function _checkValidQuantity(uint256 amount) private pure { require(amount > 0, "Invalid quantity"); } function _checkEnoughAmountToSell(bool isEnough) private pure { require(isEnough, "Not enough to sell"); } function _checkSufficientBalance(bool isufficient) private pure { require(isufficient, "Insufficient balance"); } function _checkValidReverseStake(bool isValid) private pure { require(isValid, "Invalid reverseStake"); } function _checkActiveReverseStake(bool isActive) private pure { require(isActive, "ReverseStake is not active"); } function _transfer(address recipient, uint256 amount) private { (bool sent,) = recipient.call{value: amount}(""); require(sent, "Failed to send Ether"); } receive() external payable {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import { Context } from "../lib/utils/Context.sol"; contract AdminAgent is Context { mapping(address => bool) private _adminAgents; constructor(address[] memory adminAgents_) { for (uint i = 0; i < adminAgents_.length; i++) { require(adminAgents_[i] != address(0), "Invalid address"); _adminAgents[adminAgents_[i]] = true; } } modifier onlyAdminAgents() { require(_adminAgents[_msgSender()], "Unauthorized"); _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import { Context } from "../lib/utils/Context.sol"; contract AdminGovernanceAgent is Context { mapping(address => bool) private _adminGovAgents; constructor(address[] memory adminGovAgents_) { for (uint i = 0; i < adminGovAgents_.length; i++) { require(adminGovAgents_[i] != address(0), "Invalid address"); _adminGovAgents[adminGovAgents_[i]] = true; } } modifier onlyAdminGovAgents() { require(_adminGovAgents[_msgSender()], "Unauthorized"); _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import { Context } from "../lib/utils/Context.sol"; contract BackendAgent is Context { mapping(address => bool) private _backendAdminAgents; mapping(address => bool) private _backendAgents; event SetBackendAgent(address agent); event RevokeBackendAgent(address agent); modifier onlyBackendAdminAgents() { require(_backendAdminAgents[_msgSender()], "Unauthorized"); _; } modifier onlyBackendAgents() { require(_backendAgents[_msgSender()], "Unauthorized"); _; } function _setBackendAgents(address[] memory backendAgents) internal { for (uint i = 0; i < backendAgents.length; i++) { require(backendAgents[i] != address(0), "Invalid address"); _backendAgents[backendAgents[i]] = true; } } function _setBackendAdminAgents(address[] memory backendAdminAgents) internal { for (uint i = 0; i < backendAdminAgents.length; i++) { require(backendAdminAgents[i] != address(0), "Invalid address"); _backendAdminAgents[backendAdminAgents[i]] = true; } } function setBackendAgent(address _agent) external onlyBackendAdminAgents { require(_agent != address(0), "Invalid address"); _backendAgents[_agent] = true; emit SetBackendAgent(_agent); } function revokeBackendAgent(address _agent) external onlyBackendAdminAgents { _backendAgents[_agent] = false; emit RevokeBackendAgent(_agent); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.18; import { VETHRevenueCycleTreasury } from "./VETHRevenueCycleTreasury.sol"; import { ERC20 } from "../lib/token/ERC20/ERC20.sol"; import { VYToken } from "../token/VYToken.sol"; import { BackendAgent } from "../access/BackendAgent.sol"; import { RegistrarClient } from "../RegistrarClient.sol"; import { Router } from "../Router.sol"; contract VETHP2P is BackendAgent, RegistrarClient { uint256 private constant MULTIPLIER = 10**18; struct TradeOfferCalcInfo { uint256 amountOut; uint256 takerReceives; uint256 takerFee; uint256 makerReceives; uint256 makerFee; } uint256 public constant EXPIRES_IN = 30 days; uint256 public constant MINIMUM_AUTOCLOSE_IN_ETH = 500000000000000; // 0.0005 ETH uint256 public constant ETH_FEE = 20000000000000000; uint256 public constant VY_FEE = 20000000000000000; Router private _ethComptroller; VETHRevenueCycleTreasury private _vethRevenueCycleTreasury; uint256 private _nonce = 1; enum TradingPairs { VY_ETH, ETH_VY } struct Offer { uint256 id; TradingPairs tradingPair; uint256 quantity; uint256 price; uint256 expiresAt; bool isOpen; } struct TradingPair { address makerAssetAddress; address takerAssetAddress; address makerTreasuryAddress; address takerTreasuryAddress; uint256 makerFeeRate; uint256 takerFeeRate; } mapping(address => mapping(uint256 => Offer)) private _offers; mapping(TradingPairs => TradingPair) private _tradingPairs; event CreateOffer(uint256 id, address seller, TradingPairs tradingPair, uint256 quantity, uint256 price, uint256 expiresAt, uint256 timestamp); event TradeOffer(uint256 id, address buyer, uint256 sellerQuantity, uint256 buyerQuantity, uint256 unfilledQuantity, uint256 timestamp); event CloseOffer(uint256 id, uint256 timestamp); constructor( address registrarAddress, address ethComptrollerAddress_, address[] memory backendAdminAgents, address[] memory backendAgents ) RegistrarClient(registrarAddress) { require(ethComptrollerAddress_ != address(0), "Invalid address"); _ethComptroller = Router(payable(ethComptrollerAddress_)); _setBackendAdminAgents(backendAdminAgents); _setBackendAgents(backendAgents); } modifier onlyValidCreateOffer(TradingPairs tradingPair, uint256 quantity, uint256 price) { require(_pairExist(tradingPair), "Invalid pair"); require(quantity > 0, "Invalid quantity"); require(price > 0, "Invalid price"); if (tradingPair == TradingPairs.ETH_VY) { require(msg.value == quantity, "Invalid ETH amount sent"); } else { require(msg.value == 0, "Invalid ETH amount sent"); } _; } modifier onlyValidTradeOffer(uint256 id, address seller, uint256 quantity) { require(_isOfferActive(id, seller), "Invalid offer"); require(quantity > 0, "Invalid quantity"); _; } modifier onlyOpenOffer(uint256 id, address seller) { require(_offers[seller][id].isOpen, "Offer must be open in order to close"); _; } function getNonce() external view returns (uint256) { return _nonce; } function getOffer(uint256 id, address seller) external view returns (Offer memory) { return _offers[seller][id]; } function createOffer(TradingPairs tradingPair, uint256 quantity, uint256 price) external payable onlyValidCreateOffer(tradingPair, quantity, price) { _createOffer(tradingPair, quantity, price); } function createOffer(TradingPairs tradingPair, uint256 quantity, uint256 price, uint8 v, bytes32 r, bytes32 s) external payable onlyValidCreateOffer(tradingPair, quantity, price) { // Verify maker asset must be VY require(_tradingPairs[tradingPair].makerAssetAddress == _tradingPairs[TradingPairs.VY_ETH].makerAssetAddress, "Must be [VY_ETH]"); VYToken makerAsset = VYToken(_tradingPairs[tradingPair].makerAssetAddress); // Call approval makerAsset.permit(_msgSender(), address(this), quantity, v, r, s); _createOffer(tradingPair, quantity, price); } function _createOffer(TradingPairs tradingPair, uint256 quantity, uint256 price) private { uint256 yieldRate = _vethRevenueCycleTreasury.getYieldRate(); if (tradingPair == TradingPairs.ETH_VY) { require(price <= yieldRate, "Price must be <= yieldRate"); } else if (tradingPair == TradingPairs.VY_ETH) { require((MULTIPLIER * MULTIPLIER / price) <= yieldRate, "Price reciprocal must be <= yieldRate"); } else { revert("Unsupported pair"); } // Create offer uint256 expiresAt = block.timestamp + EXPIRES_IN; uint256 id = _nonce++; _offers[_msgSender()][id] = Offer(id, tradingPair, quantity, price, expiresAt, true); // Transfer VY to the contract if (tradingPair == TradingPairs.VY_ETH) { ERC20 token = _getSpendingTokenAndCheck(_tradingPairs[tradingPair].makerAssetAddress, quantity); token.transferFrom(_msgSender(), address(this), quantity); } emit CreateOffer(id, _msgSender(), tradingPair, quantity, price, expiresAt, block.timestamp); } function tradeOffer(uint256 id, address seller, uint256 quantity) external payable onlyValidTradeOffer(id, seller, quantity) returns (TradeOfferCalcInfo memory) { _validateTradeOfferETHAmount(id, seller, quantity); return _tradeOffer(id, seller, quantity); } function tradeOffer(uint256 id, address seller, uint256 quantity, uint8 v, bytes32 r, bytes32 s) external payable onlyValidTradeOffer(id, seller, quantity) returns (TradeOfferCalcInfo memory) { _validateTradeOfferETHAmount(id, seller, quantity); // Verify taker asset must be VY TradingPair memory tradingPair = _tradingPairs[_offers[seller][id].tradingPair]; require(tradingPair.takerAssetAddress == _tradingPairs[TradingPairs.ETH_VY].takerAssetAddress, "Must be [ETH_VY]"); VYToken takerAsset = VYToken(tradingPair.takerAssetAddress); // Call approval takerAsset.permit(_msgSender(), address(this), quantity, v, r, s); return _tradeOffer(id, seller, quantity); } function estimateTradeOffer(uint256 id, address seller, uint256 quantity) external view onlyValidTradeOffer(id, seller, quantity) returns (TradeOfferCalcInfo memory) { TradingPair memory tradingPair = _tradingPairs[_offers[seller][id].tradingPair]; uint256 maxInput = _offers[seller][id].quantity * _offers[seller][id].price / MULTIPLIER; require(quantity <= maxInput, "Not enough to sell"); return _calcTradeOffer(tradingPair, quantity, _offers[seller][id].price); } function _tradeOffer(uint256 id, address seller, uint256 quantity) private returns (TradeOfferCalcInfo memory) { TradingPair memory tradingPair = _tradingPairs[_offers[seller][id].tradingPair]; uint256 maxInput = _offers[seller][id].quantity * _offers[seller][id].price / MULTIPLIER; require(quantity <= maxInput, "Not enough to sell"); /// @dev returns maker quantity fulfilled by this trade TradeOfferCalcInfo memory calc = _calcTradeOffer(tradingPair, quantity, _offers[seller][id].price); // Update offer quantity require(_offers[seller][id].quantity >= calc.amountOut, "Bad calculations"); _offers[seller][id].quantity -= calc.amountOut; // VY_ETH trade if (tradingPair.takerAssetAddress == address(0)) { ERC20 makerAsset = ERC20(tradingPair.makerAssetAddress); // Transfer taker ETH _transfer(seller, calc.makerReceives); _ethComptroller.route{ value: calc.makerFee }(); // Transfer maker VY makerAsset.transfer(_msgSender(), calc.takerReceives); makerAsset.transfer(tradingPair.makerTreasuryAddress, calc.takerFee); } else { // ETH_VY trade ERC20 takerAsset = _getSpendingTokenAndCheck(tradingPair.takerAssetAddress, quantity); /** * Transfer taker VY * * @dev the code below transfers makerReceives from taker to contract, then from contract to maker * instead of transferring makerReceives directly from taker to maker, is to avoid user transfer fee * being applied to (See ticket-296 for more info) */ takerAsset.transferFrom(_msgSender(), address(this), calc.makerReceives); takerAsset.transfer(seller, calc.makerReceives); takerAsset.transferFrom(_msgSender(), tradingPair.takerTreasuryAddress, calc.makerFee); // Transfer maker ETH _transfer(_msgSender(), calc.takerReceives); _ethComptroller.route{ value: calc.takerFee }(); } // ETH_VY market - selling amount in ETH < MINIMUM_AUTOCLOSE_IN_ETH bool makerCloseout = (tradingPair.makerAssetAddress == address(0) && _offers[seller][id].quantity < MINIMUM_AUTOCLOSE_IN_ETH); // VY_ETH market - converted selling amount in VY to ETH < MINIMUM_AUTOCLOSE_IN_ETH bool takerCloseout = (tradingPair.takerAssetAddress == address(0) && _offers[seller][id].quantity * _offers[seller][id].price / MULTIPLIER < MINIMUM_AUTOCLOSE_IN_ETH); if (makerCloseout || takerCloseout) { _closeOffer(id, seller); // Auto-close when selling amount in ETH < MINIMUM_AUTOCLOSE_IN_ETH } emit TradeOffer(id, _msgSender(), calc.amountOut, quantity, _offers[seller][id].quantity, block.timestamp); return calc; } function closeOffer(uint256 id) external onlyOpenOffer(id, _msgSender()) { _closeOffer(id, _msgSender()); } function closeOffer(address seller, uint256 id) external onlyOpenOffer(id, seller) onlyBackendAgents { _closeOffer(id, seller); } function _pairExist(TradingPairs tradingPair) private view returns (bool) { return _tradingPairs[tradingPair].makerAssetAddress != address(0) || _tradingPairs[tradingPair].takerAssetAddress != address(0); } function _isOfferActive(uint256 id, address seller) private view returns (bool) { return _offers[seller][id].isOpen && _offers[seller][id].expiresAt > block.timestamp; } function _getSpendingTokenAndCheck(address assetAddress, uint256 quantity) private view returns (ERC20) { ERC20 token = ERC20(assetAddress); require(token.allowance(_msgSender(), address(this)) >= quantity, "Insufficient allowance"); require(token.balanceOf(_msgSender()) >= quantity, "Insufficient balance"); return token; } function _calcTradeOffer(TradingPair memory tradingPair, uint256 quantity, uint256 price) private pure returns (TradeOfferCalcInfo memory) { // Offer is 1,000 VY at 10.0 ETH each (10,000 ETH in total) // Taker want to swap 100 ETH for 10 VY // buyQuantity should be 100 ETH * (10^18 / 10^19) = 10 VY uint256 buyQuantity = quantity * MULTIPLIER / price; TradeOfferCalcInfo memory calc; calc.amountOut = buyQuantity; calc.makerFee = quantity * tradingPair.makerFeeRate / MULTIPLIER; calc.takerFee = buyQuantity * tradingPair.takerFeeRate / MULTIPLIER; calc.makerReceives = quantity - calc.makerFee; calc.takerReceives = buyQuantity - calc.takerFee; return calc; } function _closeOffer(uint256 id, address seller) private { uint256 remainingQuantity = _offers[seller][id].quantity; _offers[seller][id].isOpen = false; if (remainingQuantity > 0) { _offers[seller][id].quantity = 0; address makerAssetAddress = _tradingPairs[_offers[seller][id].tradingPair].makerAssetAddress; if (makerAssetAddress == address(0)) { _transfer(seller, remainingQuantity); } else { ERC20 token = ERC20(makerAssetAddress); token.transfer(seller, remainingQuantity); } } emit CloseOffer(id, block.timestamp); } function updateAddresses() external override onlyRegistrar { _vethRevenueCycleTreasury = VETHRevenueCycleTreasury(_registrar.getVETHRevenueCycleTreasury()); _initTradingPairs(); } function _initTradingPairs() internal { address vethRevenueCycleTreasury = _registrar.getVETHRevenueCycleTreasury(); address vyToken = _registrar.getVYToken(); _tradingPairs[TradingPairs.VY_ETH] = TradingPair(vyToken, address(0), vethRevenueCycleTreasury, address(_ethComptroller), VY_FEE, ETH_FEE); _tradingPairs[TradingPairs.ETH_VY] = TradingPair(address(0), vyToken, address(_ethComptroller), vethRevenueCycleTreasury, ETH_FEE, VY_FEE); } function _transfer(address recipient, uint256 amount) private { (bool sent,) = recipient.call{value: amount}(""); require(sent, "Failed to send Ether"); } function _validateTradeOfferETHAmount(uint256 id, address seller, uint256 quantity) private { if (_offers[seller][id].tradingPair == TradingPairs.VY_ETH) { require(msg.value == quantity, "Invalid ETH amount sent"); } else { require(msg.value == 0, "Invalid ETH amount sent"); } } }
// SPDX-License-Identifier: MIT // // VETHRevenueCycleTreasury [VY_ETH] // pragma solidity 0.8.18; import { BackendAgent } from "../access/BackendAgent.sol"; import { VYToken } from "../token/VYToken.sol"; import { RegistrarClient } from "../RegistrarClient.sol"; import { RegistrarMigrator } from "../RegistrarMigrator.sol"; import { AdminGovernanceAgent } from "../access/AdminGovernanceAgent.sol"; import { Governable } from "../governance/Governable.sol"; import { VETHYieldRateTreasury } from "../treasury/VETHYieldRateTreasury.sol"; import { VYRevenueCycleCirculationTracker } from "./VYRevenueCycleCirculationTracker.sol"; import { Registrar } from "../Registrar.sol"; import { Router } from "../Router.sol"; contract VETHRevenueCycleTreasury is BackendAgent, RegistrarClient, RegistrarMigrator, AdminGovernanceAgent, Governable, VYRevenueCycleCirculationTracker { uint256 private constant MULTIPLIER = 10**18; uint256 public constant ETH_FEE = 20000000000000000; uint256 public constant VY_FEE = 20000000000000000; uint256 public constant CREATE_PRICE_FACTOR = 2000000000000000000; // 2 multiplier uint256 public constant YIELD_RATE_FACTOR = 1030000000000000000; // 1.03 multiplier VYToken internal _vyToken; VETHYieldRateTreasury private _vethYRT; Router private _ethComptroller; address private _migration; uint256 private _nonce = 0; uint256 private _vyAllocatedInOffer = 0; uint256 internal _initialYieldRate = 0; struct Offer { uint256 id; uint256 quantity; uint256 price; bool isOpen; } mapping(uint256 => Offer) private _offers; event CreateOffer(uint256 id, uint256 quantity, uint256 price, uint256 timestamp); event TradeOffer(uint256 id, address buyer, uint256 sellerQuantity, uint256 buyerQuantity, uint256 unfilledQuantity, uint256 timestamp); event CloseOffer(uint256 id, uint256 timestamp); constructor( address registrarAddress, address ethComptrollerAddress_, address[] memory adminAgents, address[] memory backendAdminAgents, address[] memory backendAgents, address[] memory adminGovAgents, uint256 initialYieldRate_, uint256 initialCirculation ) RegistrarClient(registrarAddress) RegistrarMigrator(registrarAddress, uint(Registrar.Contract.VETHRevenueCycleTreasury), adminAgents) AdminGovernanceAgent(adminGovAgents) VYRevenueCycleCirculationTracker(initialCirculation) { require(ethComptrollerAddress_ != address(0), "Invalid address"); _ethComptroller = Router(payable(ethComptrollerAddress_)); _setBackendAdminAgents(backendAdminAgents); _setBackendAgents(backendAgents); _initialYieldRate = initialYieldRate_; } function getNonce() external view returns (uint256) { return _nonce; } function getVYAllocatedInOffer() external view returns (uint256) { return _vyAllocatedInOffer; } function getOffer(uint256 id) external view returns (Offer memory) { return _offers[id]; } function getMigration() external view returns (address) { return _migration; } function getInitialYieldRate() external view returns (uint256) { return _initialYieldRate; } function getYieldRate() external view returns (uint256) { return _getYieldRate(); } function getVETHCirculation() public view returns (uint256) { return _getRevenueCycleCirculation(); } function setMigration(address destination) external onlyGovernance { _migration = destination; } function transferMigration(uint256 amount) external onlyAdminGovAgents { require(_migration != address(0), "Migration not set"); require(_vyToken.balanceOf(address(this)) >= amount, "Insufficient balance"); _vyToken.transfer(_migration, amount); } function createOffer(uint256 quantity) external onlyBackendAgents { require(quantity > 0, "Invalid quantity"); uint256 yieldRate = _getYieldRate(); require(yieldRate > 0, "Yield rate must be greater than zero"); uint256 price = CREATE_PRICE_FACTOR * MULTIPLIER / yieldRate; Offer memory offer = _offers[_nonce]; if (offer.isOpen) { _closeOffer(_nonce); } uint256 _vyBalance = _vyToken.balanceOf(address(this)); uint256 _desiredTotalVY = _vyAllocatedInOffer + quantity; uint256 id = ++_nonce; _offers[id] = Offer(id, quantity, price, true); _vyAllocatedInOffer += quantity; if (_desiredTotalVY > _vyBalance) { uint256 amountToMint = _desiredTotalVY - _vyBalance; _vyToken.mint(amountToMint); } emit CreateOffer(id, quantity, price, block.timestamp); } function tradeOffer(uint256 id) external payable { require(msg.value > 0, "Invalid quantity"); require(_isOfferActive(id), "Invalid offer"); uint256 price = _offers[id].price; uint256 maxInput = _offers[id].quantity * price / MULTIPLIER; require(msg.value <= maxInput, "Not enough to sell"); /// @dev returns maker quantity fulfilled by this trade uint256 buyQuantity = msg.value * MULTIPLIER / price; require(_vyToken.balanceOf(address(this)) >= buyQuantity, "Not enough to sell"); // Add yield rate > 0 check to avoid error dividing by 0 yield rate from the following cases: // 1. VETHYieldRateTreasury contract swap making treasuryValue 0 // 2. Stake supply = 0 and initial yield rate = 0 uint256 yieldRate = _getYieldRate(); if (yieldRate > 0) { uint256 limitYieldRate = YIELD_RATE_FACTOR * MULTIPLIER / yieldRate; // Ensure offer price is still above yield rate to enforce rising yield rate rule require(price >= limitYieldRate, "Price must be >= limitYieldRate"); } // Update offer quantity and total VY allocated require(_offers[id].quantity >= buyQuantity, "Bad calculations"); _offers[id].quantity -= buyQuantity; _vyAllocatedInOffer -= buyQuantity; uint256 makerFee = msg.value * VY_FEE / MULTIPLIER; uint256 takerFee = buyQuantity * ETH_FEE / MULTIPLIER; uint256 makerReceives = msg.value - makerFee; uint256 takerReceives = buyQuantity - takerFee; _transfer(address(_vethYRT), makerReceives); _ethComptroller.route{ value: makerFee }(); _vyToken.transfer(_msgSender(), takerReceives); emit TradeOffer(id, _msgSender(), buyQuantity, msg.value, _offers[id].quantity, block.timestamp); } function closeOffer(uint256 id) external onlyBackendAgents { require(_isOfferActive(id), "Invalid offer"); _closeOffer(id); } function updateAddresses() external override onlyRegistrar { _vyToken = VYToken(_registrar.getVYToken()); _vethYRT = VETHYieldRateTreasury(payable(_registrar.getVETHYieldRateTreasury())); _updateGovernable(_registrar); _updateVYCirculationHelper(_registrar); } function _isOfferActive(uint256 id) private view returns (bool) { return _offers[id].isOpen; } function _getYieldRate() private view returns (uint256) { uint256 circulation = getVETHCirculation(); uint256 treasuryValue = _vethYRT.getYieldRateTreasuryValue(); if (treasuryValue == 0) { return 0; } if (circulation > 0) { return MULTIPLIER * circulation / treasuryValue; } else { return _initialYieldRate; } } function _transfer(address recipient, uint256 amount) private { (bool sent,) = recipient.call{value: amount}(""); require(sent, "Failed to send Ether"); } function _closeOffer(uint256 id) private { _vyAllocatedInOffer -= _offers[id].quantity; _offers[id].isOpen = false; _offers[id].quantity = 0; emit CloseOffer(id, block.timestamp); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.18; import { Registrar } from "../Registrar.sol"; import { Context } from "../lib/utils/Context.sol"; contract VYRevenueCycleCirculationTracker is Context { uint256 private _revenueCycleCirculation; address private _vyTokenAddress; constructor(uint256 initialCirculation) { _revenueCycleCirculation = initialCirculation; } modifier onlyVYToken() { require(_msgSender() == _vyTokenAddress, "Caller must be VYToken"); _; } function increaseRevenueCycleCirculation(uint256 amount) external onlyVYToken { _revenueCycleCirculation += amount; } function decreaseRevenueCycleCirculation(uint256 amount) external onlyVYToken { if (amount > _revenueCycleCirculation) { _revenueCycleCirculation = 0; } else { _revenueCycleCirculation -= amount; } } function _updateVYCirculationHelper(Registrar registrar) internal { _vyTokenAddress = registrar.getVYToken(); } function _getRevenueCycleCirculation() internal view returns (uint256) { return _revenueCycleCirculation; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import { Context } from "../lib/utils/Context.sol"; import { Registrar } from "../Registrar.sol"; contract Governable is Context { address internal _governanceAddress; constructor() {} modifier onlyGovernance() { require(_governanceAddress == _msgSender(), "Unauthorized"); _; } function _updateGovernable(Registrar registrar) internal { _governanceAddress = registrar.getVETHGovernance(); } function getGovernanceAddress() external view returns (address) { return _governanceAddress; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.18; import { AdminGovernanceAgent } from "../access/AdminGovernanceAgent.sol"; import { VETHYieldRateTreasury } from "../treasury/VETHYieldRateTreasury.sol"; import { VYToken } from "../token/VYToken.sol"; import { VETHRevenueCycleTreasury } from "../exchange/VETHRevenueCycleTreasury.sol"; import { VETHReverseStakingTreasury } from "../VETHReverseStakingTreasury.sol"; import { RegistrarClient } from "../RegistrarClient.sol"; contract VETHGovernance is AdminGovernanceAgent, RegistrarClient { enum VoteOptions { YES, NO } enum ProposalType { Migration, Registrar, ReverseStakingTermUpdate } struct MigrationProposal { address yieldRateTreasuryDestination; address revenueCycleTreasuryDestination; address reverseStakingTreasuryDestination; } struct RegistrarProposal { address registrar; // Registrar to add } struct ReverseStakingTermUpdateProposal { uint256 dailyBurnRate; uint256 minimumReverseStakeETH; uint256 processingFeePercentage; uint256 restakeMinimumPayout; } struct Proposal { ProposalType proposalType; uint256 endsAt; bool approved; MigrationProposal migration; RegistrarProposal registrar; ReverseStakingTermUpdateProposal reverseStakingTermUpdate; } event StartMigrationProposal( uint256 proposalId, address yieldRateTreasuryDestination, address revenueCycleTreasuryDestination, address reverseStakingTreasuryDestination, uint256 endsAt ); event StartRegistrarProposal(uint256 proposalId, address registrar, uint256 endsAt); event StartReverseStakingTermUpdateProposal( uint256 proposalId, uint256 dailyBurnRate, uint256 minimumReverseStakeETH, uint256 processingFeePercentage, uint256 restakeMinimumPayout, uint256 endsAt ); VYToken private _vyToken; VETHYieldRateTreasury private _vethYRT; VETHRevenueCycleTreasury private _vethRevenueCycleTreasury; VETHReverseStakingTreasury internal _vethReverseStakingTreasury; mapping(uint256 => mapping(address => uint256)) private _deposits; mapping(uint256 => mapping(VoteOptions => uint256)) private _voteCount; mapping(uint256 => Proposal) private _proposals; uint256 public votingPeriod; // In seconds uint256 private _proposalNonce = 0; event Vote(address account, VoteOptions voteOption, uint256 quantity); constructor( address registrarAddress, uint256 votingPeriod_, address[] memory adminGovAgents ) AdminGovernanceAgent(adminGovAgents) RegistrarClient(registrarAddress) { votingPeriod = votingPeriod_; } modifier hasMigrationAddresses() { require(address(_vethYRT) != address(0), "ETH Treasury address not set"); require(address(_vethRevenueCycleTreasury) != address(0), "VETHRevenueCycleTreasury address not set"); require(address(_vethReverseStakingTreasury) != address(0), "VETHReverseStakingTreasury address not set"); _; } modifier hasProposal() { require(_proposals[_proposalNonce].endsAt > 0, "No proposal"); _; } modifier hasProposalById(uint256 proposalId) { require(_proposals[proposalId].endsAt > 0, "No proposal"); _; } function getCurrentProposal() external view returns (Proposal memory) { return _proposals[_proposalNonce]; } function getProposalById(uint256 proposalId) external view returns (Proposal memory) { return _proposals[proposalId]; } function getCurrentProposalId() external view returns (uint256) { return _proposalNonce; } function getCurrentYesVotes() external view returns (uint256) { return _voteCount[_proposalNonce][VoteOptions.YES]; } function getCurrentNoVotes() external view returns (uint256) { return _voteCount[_proposalNonce][VoteOptions.NO]; } function getYesVotesById(uint256 proposalId) external view returns (uint256) { return _voteCount[proposalId][VoteOptions.YES]; } function getNoVotesById(uint256 proposalId) external view returns (uint256) { return _voteCount[proposalId][VoteOptions.NO]; } function getCurrentDepositedVY(address voter) external view returns (uint256) { return _deposits[_proposalNonce][voter]; } function getDepositedVYById(uint256 proposalId, address voter) external view returns (uint256) { return _deposits[proposalId][voter]; } function hasCurrentProposalEnded() public view hasProposal returns (bool) { return block.timestamp > _proposals[_proposalNonce].endsAt; } function hasProposalEndedById(uint256 proposalId) external view hasProposalById(proposalId) returns (bool) { return block.timestamp > _proposals[proposalId].endsAt; } function voteYes(uint256 quantity) external { _vote(VoteOptions.YES, quantity); } function voteNo(uint256 quantity) external { _vote(VoteOptions.NO, quantity); } function _vote(VoteOptions voteOption, uint256 quantity) private hasProposal { require(block.timestamp < _proposals[_proposalNonce].endsAt, "Proposal already ended"); require(_deposits[_proposalNonce][_msgSender()] == 0, "Already voted"); require(_vyToken.allowance(_msgSender(), address(this)) >= quantity, "Insufficient VY allowance"); require(_vyToken.balanceOf(_msgSender()) >= quantity, "Insufficient VY balance"); _deposits[_proposalNonce][_msgSender()] += quantity; _voteCount[_proposalNonce][voteOption] += quantity; _vyToken.transferFrom(_msgSender(), address(this), quantity); emit Vote(_msgSender(), voteOption, quantity); } function startMigrationProposal( address yieldRateTreasuryDestination, address revenueCycleTreasuryDestination, address reverseStakingTreasuryDestination ) external onlyAdminGovAgents { // Prevent funds locked up in zero address require( yieldRateTreasuryDestination != address(0) && revenueCycleTreasuryDestination != address(0) && reverseStakingTreasuryDestination != address(0), "Invalid address" ); _startMigrationProposal(yieldRateTreasuryDestination, revenueCycleTreasuryDestination, reverseStakingTreasuryDestination); } function executeMigrationProposal() external hasMigrationAddresses hasProposal onlyAdminGovAgents { _checkValidMigrationProposal( _proposals[_proposalNonce].migration.yieldRateTreasuryDestination != address(0), _proposals[_proposalNonce].migration.revenueCycleTreasuryDestination != address(0), _proposals[_proposalNonce].migration.reverseStakingTreasuryDestination != address(0) ); _executeMigrationProposal(); } function startRegistrarProposal(address registrar) external onlyAdminGovAgents { // Prevent funds locked up in zero address require(registrar != address(0), "Invalid address"); // Should only allow starting new proposal after current one is expired // Note: starting first proposal where _proposalNonce is 0 should not require expiration condition require(block.timestamp > _proposals[_proposalNonce].endsAt || _proposalNonce == 0, "Proposal still ongoing"); uint256 endsAt = block.timestamp + votingPeriod; _proposals[++_proposalNonce] = Proposal( ProposalType.Registrar, endsAt, false, MigrationProposal(address(0), address(0), address(0)), RegistrarProposal(registrar), ReverseStakingTermUpdateProposal(0, 0, 0, 0) ); // Emit event emit StartRegistrarProposal( _proposalNonce, registrar, endsAt ); } function executeRegistrarProposal() external hasProposal onlyAdminGovAgents { require(address(_vyToken) != address(0), "VYToken address not set"); require(hasCurrentProposalEnded(), "Proposal still ongoing"); require(_proposals[_proposalNonce].proposalType == ProposalType.Registrar, "Invalid proposal"); require(_voteCount[_proposalNonce][VoteOptions.YES] >= _voteCount[_proposalNonce][VoteOptions.NO], "Proposal not passed"); _proposals[_proposalNonce].approved = true; // Register new Registrar with VYToken _vyToken.setRegistrar(_registrar.getEcosystemId(), _proposalNonce); } function startReverseStakingTermUpdateProposal( uint256 dailyBurnRate, uint256 minimumReverseStakeETH, uint256 processingFeePercentage, uint256 restakeMinimumPayout ) external onlyAdminGovAgents { // Should only allow starting new proposal after current one is expired // Note: starting first proposal where _proposalNonce is 0 should not require expiration condition require(block.timestamp > _proposals[_proposalNonce].endsAt || _proposalNonce == 0, "Proposal still ongoing"); uint256 endsAt = block.timestamp + votingPeriod; _proposals[++_proposalNonce] = Proposal( ProposalType.ReverseStakingTermUpdate, endsAt, false, MigrationProposal(address(0), address(0), address(0)), RegistrarProposal(address(0)), ReverseStakingTermUpdateProposal( dailyBurnRate, minimumReverseStakeETH, processingFeePercentage, restakeMinimumPayout ) ); // Emit event emit StartReverseStakingTermUpdateProposal( _proposalNonce, dailyBurnRate, minimumReverseStakeETH, processingFeePercentage, restakeMinimumPayout, endsAt ); } function executeReverseStakingTermUpdateProposal() external hasProposal onlyAdminGovAgents { require(address(_vethReverseStakingTreasury) != address(0), "VETHReverseStakingTreasury address not set"); require(hasCurrentProposalEnded(), "Proposal still ongoing"); require(_proposals[_proposalNonce].proposalType == ProposalType.ReverseStakingTermUpdate, "Invalid proposal"); require(_voteCount[_proposalNonce][VoteOptions.YES] >= _voteCount[_proposalNonce][VoteOptions.NO], "Proposal not passed"); _proposals[_proposalNonce].approved = true; ReverseStakingTermUpdateProposal memory proposal = _proposals[_proposalNonce].reverseStakingTermUpdate; _vethReverseStakingTreasury.createNewReverseStakeTerm( proposal.dailyBurnRate, proposal.minimumReverseStakeETH, proposal.processingFeePercentage, proposal.restakeMinimumPayout ); } function startYieldRateTreasuryMigration(address yieldRateTreasuryDestination) external onlyAdminGovAgents { // Prevent funds locked up in zero address require(yieldRateTreasuryDestination != address(0), "Invalid address"); _startMigrationProposal(yieldRateTreasuryDestination, address(0), address(0)); } function executeYieldRateTreasuryMigration() external hasProposal onlyAdminGovAgents { require(address(_vethYRT) != address(0), "ETH Treasury address not set"); _checkValidMigrationProposal( _proposals[_proposalNonce].migration.yieldRateTreasuryDestination != address(0), _proposals[_proposalNonce].migration.revenueCycleTreasuryDestination == address(0), _proposals[_proposalNonce].migration.reverseStakingTreasuryDestination == address(0) ); _executeMigrationProposal(); } function startRevenueCycleTreasuryMigration(address revenueCycleTreasuryDestination) external onlyAdminGovAgents { // Prevent funds locked up in zero address require(revenueCycleTreasuryDestination != address(0), "Invalid address"); _startMigrationProposal(address(0), revenueCycleTreasuryDestination, address(0)); } function executeRevenueCycleTreasuryMigration() external hasProposal onlyAdminGovAgents { require(address(_vethRevenueCycleTreasury) != address(0), "VETHRevenueCycleTreasury address not set"); _checkValidMigrationProposal( _proposals[_proposalNonce].migration.yieldRateTreasuryDestination == address(0), _proposals[_proposalNonce].migration.revenueCycleTreasuryDestination != address(0), _proposals[_proposalNonce].migration.reverseStakingTreasuryDestination == address(0) ); _executeMigrationProposal(); } function startReverseStakingTreasuryMigration(address reverseStakingTreasuryDestination) external onlyAdminGovAgents { // Prevent funds locked up in zero address require(reverseStakingTreasuryDestination != address(0), "Invalid address"); _startMigrationProposal(address(0), address(0), reverseStakingTreasuryDestination); } function executeReverseStakingTreasuryMigration() external hasProposal onlyAdminGovAgents { require(address(_vethReverseStakingTreasury) != address(0), "VETHReverseStakingTreasury address not set"); _checkValidMigrationProposal( _proposals[_proposalNonce].migration.yieldRateTreasuryDestination == address(0), _proposals[_proposalNonce].migration.revenueCycleTreasuryDestination == address(0), _proposals[_proposalNonce].migration.reverseStakingTreasuryDestination != address(0) ); _executeMigrationProposal(); } function _executeMigrationProposal() private { require(hasCurrentProposalEnded(), "Proposal still ongoing"); require(_voteCount[_proposalNonce][VoteOptions.YES] >= _voteCount[_proposalNonce][VoteOptions.NO], "Proposal not passed"); _proposals[_proposalNonce].approved = true; // execute VETHYieldRateTreasury migration address yieldRateTreasuryDestination = _proposals[_proposalNonce].migration.yieldRateTreasuryDestination; if (yieldRateTreasuryDestination != address(0)) { _vethYRT.setMigration(yieldRateTreasuryDestination); } // execute VETHRevenueCycleTreasury migration address revenueCycleTreasuryDestination = _proposals[_proposalNonce].migration.revenueCycleTreasuryDestination; if (revenueCycleTreasuryDestination != address(0)) { _vethRevenueCycleTreasury.setMigration(revenueCycleTreasuryDestination); } // execute VETHReverseStakingTreasury migration address reverseStakingTreasuryDestination = _proposals[_proposalNonce].migration.reverseStakingTreasuryDestination; if (reverseStakingTreasuryDestination != address(0)) { _vethReverseStakingTreasury.setMigration(reverseStakingTreasuryDestination); } } function _startMigrationProposal( address yieldRateTreasuryDestination, address revenueCycleTreasuryDestination, address reverseStakingTreasuryDestination ) private { // Should only allow starting new proposal after current one is expired // Note: starting first proposal where _proposalNonce is 0 should not require expiration condition require(block.timestamp > _proposals[_proposalNonce].endsAt || _proposalNonce == 0, "Proposal still ongoing"); uint256 endsAt = block.timestamp + votingPeriod; // Create new proposal and increment nounce _proposals[++_proposalNonce] = Proposal( ProposalType.Migration, endsAt, false, MigrationProposal(yieldRateTreasuryDestination, revenueCycleTreasuryDestination, reverseStakingTreasuryDestination), RegistrarProposal(address(0)), ReverseStakingTermUpdateProposal(0, 0, 0, 0) ); // Emit event emit StartMigrationProposal( _proposalNonce, yieldRateTreasuryDestination, revenueCycleTreasuryDestination, reverseStakingTreasuryDestination, endsAt ); } // Withdraw from current proposal function withdrawDepositedVY() external { _withdraw(_proposalNonce); } // Withdraw by proposal id function withdrawDepositedVYById(uint256 proposalId) external { _withdraw(proposalId); } // Withdraw from all proposals function withdrawAllDepositedVY() external hasProposal { // Check if current proposal is still ongoing - to continue current proposal has to end first require(hasCurrentProposalEnded(), "Proposal still ongoing"); // When _withdraw is called this variable will be false bool nothingToWithdraw = true; // Loop to withdraw proposals that have deposits for (uint proposalId = 1; proposalId <= _proposalNonce; proposalId++) { if (_deposits[proposalId][_msgSender()] > 0) { // Check if there is anything to withdraw nothingToWithdraw = false; _withdraw(proposalId); } } // If nothing to withdraw then warn the user require(!nothingToWithdraw, "Nothing to withdraw"); } function _withdraw(uint256 proposalId) private hasProposalById(proposalId) { require(block.timestamp > _proposals[proposalId].endsAt, "Proposal still ongoing"); require(_deposits[proposalId][_msgSender()] > 0, "Nothing to withdraw"); uint256 quantity = _deposits[proposalId][_msgSender()]; _deposits[proposalId][_msgSender()] = 0; _vyToken.transfer(_msgSender(), quantity); } function updateAddresses() external override onlyRegistrar { _vyToken = VYToken(_registrar.getVYToken()); _vethYRT = VETHYieldRateTreasury(payable(_registrar.getVETHYieldRateTreasury())); _vethRevenueCycleTreasury = VETHRevenueCycleTreasury(_registrar.getVETHRevenueCycleTreasury()); _vethReverseStakingTreasury = VETHReverseStakingTreasury(payable(_registrar.getVETHReverseStakingTreasury())); } function _checkValidMigrationProposal(bool validYRT, bool validRCT, bool validRST) private view { require(_proposals[_proposalNonce].proposalType == ProposalType.Migration, "Invalid proposal"); require(validYRT, "Invalid migration proposal"); require(validRCT, "Invalid migration proposal"); require(validRST, "Invalid migration proposal"); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(account), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _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); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.0; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822ProxiableUpgradeable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallUUPS( address newImplementation, bytes memory data, bool forceCall ) internal { // Upgrades from old implementations will perform a rollback test. This test requires the new // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing // this special case will break upgrade paths from old UUPS implementation to new ones. if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) { _setImplementation(newImplementation); } else { try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) { require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID"); } catch { revert("ERC1967Upgrade: new implementation is not UUPS"); } _upgradeToAndCall(newImplementation, data, forceCall); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.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) || (!AddressUpgradeable.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); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Check that the execution is not being performed through a delegate call. This allows a function to be * callable on the implementing contract but not through proxies. */ modifier notDelegated() { require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall"); _; } /** * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the * implementation. It is used to validate that the this implementation remains valid after an upgrade. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier. */ function proxiableUUID() external view virtual override notDelegated returns (bytes32) { return _IMPLEMENTATION_SLOT; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @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"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(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) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason 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 { // 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; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.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]. * * The default value of {decimals} is 18. To change this, you should override * this function so it returns a different value. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * 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}. * * 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 default value returned by this function, unless * it's overridden. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual 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 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 (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 (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 v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.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) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 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 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; import "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.18; import { AdminAgent } from "./access/AdminAgent.sol"; import { IRegistrarClient } from "./RegistrarClient.sol"; import { VYToken } from "./token/VYToken.sol"; contract Registrar is AdminAgent { bytes32 private constant ECOSYSTEM_ID = keccak256(bytes("VY_ETH")); address[] private _contracts; address[] private _prevContracts; bool private _finalized; event SetContracts(address[] addresses); event SetContractByIndex(uint8 index, address contractAddressTo); event Finalize(address registrarAddress); enum Contract { VYToken, VETHYieldRateTreasury, VETHP2P, VETHRevenueCycleTreasury, VETHGovernance, VETHReverseStakingTreasury } /** * @dev Constructor that setup the owner of this contract. */ constructor(address[] memory adminAgents) AdminAgent(adminAgents) { _prevContracts = new address[](_numbersOfContracts()); } modifier onlyUnfinalized() { require(_finalized == false, "Registrar already finalized"); _; } modifier onlyValidContractIndex(uint256 index) { require(index < _numbersOfContracts(), "Invalid index"); _; } function getEcosystemId() external pure virtual returns (bytes32) { return ECOSYSTEM_ID; } function getContracts() external view returns (address[] memory) { return _contracts; } function getContractByIndex( uint256 index ) external view onlyValidContractIndex(index) returns (address) { return _contracts[index]; } function getPrevContractByIndex( uint256 index ) external view onlyValidContractIndex(index) returns (address) { return _prevContracts[index]; } function setContracts(address[] calldata _addresses) external onlyAdminAgents onlyUnfinalized { require(_validContractsLength(_addresses.length), "Invalid number of addresses"); // Loop through and update _prevContracts entries only if those addresses are new. // For example, assume _prevContracts[0] = 0xABC and contracts[i] = 0xF00 // If _addresses[i] = 0xF00 and we didn't perform the check below, then we would overwrite the old // 0xABC with 0xF00, thereby losing whatever actual previous contract address that was. for (uint i = 0; i < _contracts.length; i++) { if (_addresses[i] != _contracts[i]) { _prevContracts[i] = _contracts[i]; } } _contracts = _addresses; emit SetContracts(_addresses); } function setContractByIndex(uint8 _index, address _address) external onlyAdminAgents onlyUnfinalized { if (_address != _contracts[_index]) { _prevContracts[_index] = _contracts[_index]; } _contracts[_index] = _address; emit SetContractByIndex(_index, _address); } function updateAllClients() external onlyAdminAgents onlyUnfinalized { VYToken(this.getVYToken()).setMinter(); IRegistrarClient(this.getVETHP2P()).updateAddresses(); IRegistrarClient(this.getVETHRevenueCycleTreasury()).updateAddresses(); IRegistrarClient(this.getVETHReverseStakingTreasury()).updateAddresses(); IRegistrarClient(this.getVETHYieldRateTreasury()).updateAddresses(); IRegistrarClient(this.getVETHGovernance()).updateAddresses(); } function getVYToken() external view returns (address) { return _contracts[uint(Contract.VYToken)]; } function getVETHYieldRateTreasury() external view returns (address) { return _contracts[uint(Contract.VETHYieldRateTreasury)]; } function getVETHP2P() external view returns (address) { return _contracts[uint(Contract.VETHP2P)]; } function getVETHRevenueCycleTreasury() external view returns (address) { return _contracts[uint(Contract.VETHRevenueCycleTreasury)]; } function getVETHGovernance() external view returns (address) { return _contracts[uint(Contract.VETHGovernance)]; } function getVETHReverseStakingTreasury() external view returns (address) { return _contracts[uint(Contract.VETHReverseStakingTreasury)]; } function finalize() external onlyAdminAgents onlyUnfinalized { _finalized = true; emit Finalize(address(this)); } function isFinalized() external view returns (bool) { return _finalized; } function _numbersOfContracts() private pure returns (uint256) { return uint(Contract.VETHReverseStakingTreasury) + 1; } function _validContractsLength(uint256 contractsLength) private pure returns (bool) { return contractsLength == _numbersOfContracts(); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import { Context } from "./lib/utils/Context.sol"; import { Registrar } from "./Registrar.sol"; interface IRegistrarClient { function updateAddresses() external; } abstract contract RegistrarClient is Context, IRegistrarClient { Registrar internal _registrar; constructor(address registrarAddress) { require(registrarAddress != address(0), "Invalid address"); _registrar = Registrar(registrarAddress); } modifier onlyRegistrar() { require(_msgSender() == address(_registrar), "Unauthorized, registrar only"); _; } function getRegistrar() external view returns(address) { return address(_registrar); } // All subclasses must implement this function function updateAddresses() external override virtual; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import { Registrar } from "./Registrar.sol"; import { AdminAgent } from "./access/AdminAgent.sol"; import { VYToken } from "./token/VYToken.sol"; abstract contract RegistrarMigrator is AdminAgent { Registrar private _registrar; uint256 private _contractIndex; constructor( address registrarAddress, uint256 contractIndex, address[] memory adminAgents ) AdminAgent(adminAgents) { require(registrarAddress != address(0), "Invalid address"); _registrar = Registrar(registrarAddress); _contractIndex = contractIndex; } modifier onlyUnfinalized() { require(_registrar.isFinalized() == false, "Registrar already finalized"); _; } function registrarMigrateTokens() external onlyAdminAgents onlyUnfinalized { VYToken vyToken = VYToken(_registrar.getVYToken()); vyToken.registrarMigrateTokens(_registrar.getEcosystemId(), _contractIndex); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.18; import { OwnableUpgradeable } from "./lib/openzeppelin-upgradeable/access/OwnableUpgradeable.sol"; import { Initializable } from "./lib/openzeppelin-upgradeable/proxy/utils/Initializable.sol"; import { UUPSUpgradeable } from "./lib/openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; contract Router is Initializable, OwnableUpgradeable, UUPSUpgradeable { address private _primaryStakeholder; event Route(address indexed receiver, uint256 amount); /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } function initialize(address primaryStakeholder_) public initializer { __Ownable_init(); __UUPSUpgradeable_init(); _primaryStakeholder = primaryStakeholder_; } function route() external payable { _routePrimaryStakeholder(msg.value); } function _routePrimaryStakeholder(uint256 amount) private { (bool sent,) = _primaryStakeholder.call{value: amount}(""); require(sent, "Failed to send Ether"); emit Route(_primaryStakeholder, amount); } function _authorizeUpgrade(address newImplementation) internal onlyOwner override {} receive() external payable {} }
// SPDX-License-Identifier: MIT pragma solidity 0.8.18; import { AccessControl } from "../lib/access/AccessControl.sol"; import { ERC20 } from "../lib/token/ERC20/ERC20.sol"; import { AdminAgent } from "../access/AdminAgent.sol"; import { BackendAgent } from "../access/BackendAgent.sol"; import { VYRevenueCycleCirculationTracker } from "../exchange/VYRevenueCycleCirculationTracker.sol"; import { Registrar } from "../Registrar.sol"; import { VETHGovernance } from "../governance/VETHGovernance.sol"; contract VYToken is ERC20, AdminAgent, BackendAgent, AccessControl { uint256 private constant MULTIPLIER = 10**18; // EIP712 Precomputed hashes: // keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)") bytes32 private constant EIP712DOMAINTYPE_HASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f; // keccak256("VYToken") bytes32 private constant NAME_HASH = 0xc8992ef634b020d3849cb749bb94cf703a7071d02872a417a811fadacc5fdcbb; // keccak256("1") bytes32 private constant VERSION_HASH = 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6; // keccak256("VYPermit(address owner,address spender,uint256 amount,uint256 nonce)"); bytes32 private constant TXTYPE_HASH = 0x085abc97e2d328b3816b8248b9e8aa0e35bb8f414343c830d2d375b0d9b3c98f; // solhint-disable-next-line var-name-mixedcase bytes32 public DOMAIN_SEPARATOR; mapping(address => uint) public nonces; bytes32 public constant MAIN_ECOSYSTEM_ID = keccak256(bytes("VY_ETH")); bytes32 private constant OWNER_ROLE = keccak256("OWNER_ROLE"); bytes32 private constant WHITELISTER_ROLE = keccak256("WHITELISTER_ROLE"); uint256 public constant MAX_SUPPLY = 7000000000000000000000000000; // 7 billion hard cap mapping(address => bool) private _agents; mapping(address => bool) private _minters; mapping(bytes32 => address) private _registrars; // Ecosystems uint256 private _vyCirculation = 0; uint256 private _transferFee = 0; // user transfer fee in % event AgentWhitelisted(address recipient); event AgentWhitelistRevoked(address recipient); event SetRegistrar(address registrar, bytes32 ecosystemId); /** * @dev Constructor that setup all the role admins. */ constructor( string memory name, string memory symbol, address registrarAddress, address[] memory adminAgents, address[] memory backendAdminAgents, address[] memory backendAgents, uint256 transferFee_, uint256 initialCirculation ) ERC20(name, symbol) AdminAgent(adminAgents) { // make OWNER_ROLE the admin role for each role (only people with the role of an admin role can manage that role) _setRoleAdmin(WHITELISTER_ROLE, OWNER_ROLE); _setRoleAdmin(OWNER_ROLE, OWNER_ROLE); // setup deployer to be part of OWNER_ROLE which allow deployer to manage all roles _setupRole(OWNER_ROLE, _msgSender()); // Setup backend _setBackendAdminAgents(backendAdminAgents); _setBackendAgents(backendAgents); // Setup registrar _setRegistrar(registrarAddress); // Setup EIP712 DOMAIN_SEPARATOR = keccak256( abi.encode( EIP712DOMAINTYPE_HASH, NAME_HASH, VERSION_HASH, block.chainid, address(this) ) ); _transferFee = transferFee_; _vyCirculation = initialCirculation; } function getVYCirculation() external view returns (uint256) { return _vyCirculation; } function getRegistrarById(bytes32 id) external view returns(address) { return _registrars[id]; } function isMinter(address _address) external view returns (bool) { return _minters[_address]; } function transfer(address recipient, uint256 amount) public override returns (bool) { // Check if fee is not zero then it's user to user transfer - send fee to vethRevenueCycleTreasury uint256 fee = _calculateTransferFee(_msgSender(), recipient, amount); if (fee != 0) { address mainRevenueCycleTreasury = _getMainEcosystemRegistrar().getVETHRevenueCycleTreasury(); _updateCirculationAndSupply(_msgSender(), mainRevenueCycleTreasury, fee); super.transfer(recipient, amount - fee); // transfers amount - fee to recipient return super.transfer(mainRevenueCycleTreasury, fee); // transfers fee to vethRevenueCycleTreasury } _updateCirculationAndSupply(_msgSender(), recipient, amount); return super.transfer(recipient, amount); } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { // Check if fee is not zero then it's user to user transfer - send fee to vethRevenueCycleTreasury uint256 fee = _calculateTransferFee(sender, recipient, amount); if (fee != 0) { address mainRevenueCycleTreasury = _getMainEcosystemRegistrar().getVETHRevenueCycleTreasury(); _updateCirculationAndSupply(sender, mainRevenueCycleTreasury, fee); super.transferFrom(sender, recipient, amount - fee); // transfers amount - fee to recipient return super.transferFrom(sender, mainRevenueCycleTreasury, fee); // transfers fee to vethRevenueCycleTreasury } _updateCirculationAndSupply(sender, recipient, amount); return super.transferFrom(sender, recipient, amount); } function getTransferFee() external view returns (uint256) { return _transferFee; } function setTransferFee(uint256 fee) external onlyAdminAgents { _transferFee = fee; } /* * Register a new ecosystem Registrar with us * * @dev can only be called by VETHGovernance */ function setRegistrar(bytes32 originEcosystemId, uint proposalNonce) external { address registrarAddress = _registrars[originEcosystemId]; require(registrarAddress != address(0), "Invalid originEcosystemId"); // Only VETHGovernance of applicable Registrar may call this function Registrar registrar = Registrar(registrarAddress); VETHGovernance governance = VETHGovernance(registrar.getVETHGovernance()); require(_msgSender() == address(governance), "Caller must be VETHGovernance"); VETHGovernance.Proposal memory proposal = governance.getProposalById(proposalNonce); // Must be valid proposal require(proposal.approved == true && proposal.proposalType == VETHGovernance.ProposalType.Registrar, "Invalid proposal"); _setRegistrar(proposal.registrar.registrar); _setMinter(Registrar(proposal.registrar.registrar)); } /** * @dev 1) Must be called by the outgoing contract (contract to be swapped out) as * the _msgSender must initiate the transfer. * 2) Since the registrar now saves the previous contract, registrarMigrateTokens * can be called post-swap * 3) Registrar must be not finalized */ function registrarMigrateTokens(bytes32 registrarId, uint256 contractIndex) external { // The reason we need this function is to transfer tokens due to a registrar contract // swap without modifying the circulation and supply. // Require valid registrar id address registrarAddress = _registrars[registrarId]; require(registrarAddress != address(0), "Invalid registar id"); // Require that this registrar is not finalized Registrar registrar = Registrar(registrarAddress); _requireRegistrarIsUnfinalized(registrar); address prevContract = registrar.getPrevContractByIndex(contractIndex); address newContract = registrar.getContractByIndex(contractIndex); // Require that _msgSender is prevContract require(_msgSender() == prevContract, "Caller must be prevContract"); // Require newContract should not be the zero address require(newContract != address(0), "newContract is the zero address"); super.transfer(newContract, balanceOf(prevContract)); } function _setRegistrar(address registrar) private { require(registrar != address(0), "Invalid address"); bytes32 ecosystemId = Registrar(registrar).getEcosystemId(); _registrars[ecosystemId] = registrar; emit SetRegistrar(registrar, ecosystemId); } /** * @dev Only whitelisted minters may call this function */ function mint(uint256 amount) public returns (bool) { require(_minters[_msgSender()], "Caller is not an allowed minter"); require(totalSupply() + amount <= MAX_SUPPLY, "Exceeds max supply"); super._mint(_msgSender(), amount); return true; } /** * @dev Can only be called by Registrar, in the case of registrar contract swap update. * Registrar must not be finalized. */ function setMinter() external { Registrar registrar = Registrar(_msgSender()); require(_registrars[registrar.getEcosystemId()] == _msgSender(), "Invalid registar"); _requireRegistrarIsUnfinalized(registrar); _setMinter(registrar); } function _setMinter(Registrar registrar) private { // Unset previous revenueCycleTreasury address prevRevenueCycleTreasury = registrar.getPrevContractByIndex(uint(Registrar.Contract.VETHRevenueCycleTreasury)); _minters[prevRevenueCycleTreasury] = false; // Set current revenueCycleTreasury address revenueCycleTreasury = registrar.getVETHRevenueCycleTreasury(); _minters[revenueCycleTreasury] = true; } /** * @dev Airdrop tokens to holders in case VYToken is migrated. * Can only be done if main ecosystem's registrar is not finalized. */ function airdropTokens(address[] calldata _addresses, uint[] calldata _amounts) external onlyBackendAgents { require(_addresses.length == _amounts.length, "Argument array length mismatch"); _requireRegistrarIsUnfinalized(_getMainEcosystemRegistrar()); // Check main ecosystem for (uint i = 0; i < _addresses.length; i++) { super._mint(_addresses[i], _amounts[i]); } } function grantOwnerRole(address _address) external onlyRole(OWNER_ROLE) { grantRole(OWNER_ROLE, _address); } function grantWhitelisterRole(address _address) external onlyRole(OWNER_ROLE) { grantRole(WHITELISTER_ROLE, _address); } function revokeOwnerRole(address _address) external onlyRole(OWNER_ROLE) { revokeRole(OWNER_ROLE, _address); } function revokeWhitelisterRole(address _address) external onlyRole(OWNER_ROLE) { revokeRole(WHITELISTER_ROLE, _address); } function isWhitelistedAgent(address _address) external view returns (bool) { return _agents[_address]; } function whitelistAgent(address _address) external onlyRole(WHITELISTER_ROLE) { require(_agents[_address] == false, "Already whitelisted"); _agents[_address] = true; emit AgentWhitelisted(_address); } function revokeWhitelistedAgent(address _address) external onlyRole(WHITELISTER_ROLE) { require(_agents[_address] == true, "Not whitelisted"); delete _agents[_address]; emit AgentWhitelistRevoked(_address); } function permit(address owner, address spender, uint256 amount, uint8 v, bytes32 r, bytes32 s) external { // EIP712 scheme: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md bytes32 txInputHash = keccak256(abi.encode(TXTYPE_HASH, owner, spender, amount, nonces[owner])); bytes32 totalHash = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, txInputHash)); address recoveredAddress = ecrecover(totalHash, v, r, s); require(recoveredAddress != address(0) && recoveredAddress == owner, "VYToken: INVALID_SIGNATURE"); nonces[owner] = nonces[owner] + 1; _approve(owner, spender, amount); } function _getMainEcosystemRegistrar() private view returns (Registrar) { address registrarAddress = _registrars[MAIN_ECOSYSTEM_ID]; return Registrar(registrarAddress); } function _updateCirculationAndSupply(address from, address to, uint256 amount) private { if (_minters[to]) { _decreaseCirculationAndSupply(amount, to); } else if (_minters[from]) { _increaseCirculationAndSupply(amount, from); } } function _increaseCirculationAndSupply(uint256 amount, address minter) internal { _vyCirculation += amount; VYRevenueCycleCirculationTracker(minter).increaseRevenueCycleCirculation(amount); } function _decreaseCirculationAndSupply(uint256 amount, address minter) internal { if (amount > _vyCirculation) { _vyCirculation = 0; } else { _vyCirculation -= amount; } VYRevenueCycleCirculationTracker(minter).decreaseRevenueCycleCirculation(amount); } function _calculateTransferFee(address from, address to, uint256 amount) private view returns (uint256) { // Check for user to user transfer if (!_agents[from] && !_agents[to]) { uint256 transferFee = amount * _transferFee / MULTIPLIER; return transferFee; } return 0; } function _requireRegistrarIsUnfinalized(Registrar registrar) private view { require(!registrar.isFinalized(), "Registrar already finalized"); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.18; import { AdminGovernanceAgent } from "../access/AdminGovernanceAgent.sol"; import { Governable } from "../governance/Governable.sol"; import { VETHReverseStakingTreasury } from "../VETHReverseStakingTreasury.sol"; import { RegistrarClient } from "../RegistrarClient.sol"; contract VETHYieldRateTreasury is AdminGovernanceAgent, Governable, RegistrarClient { address private _migration; VETHReverseStakingTreasury private _vethReverseStakingTreasury; event ReverseStakingTransfer(address recipient, uint256 amount); constructor( address registrarAddress, address[] memory adminGovAgents ) AdminGovernanceAgent(adminGovAgents) RegistrarClient(registrarAddress) { } modifier onlyReverseStakingTreasury() { require(address(_vethReverseStakingTreasury) == _msgSender(), "Unauthorized"); _; } function getYieldRateTreasuryValue() external view returns (uint256) { return address(this).balance + _vethReverseStakingTreasury.getTotalClaimedYield(); } function getMigration() external view returns (address) { return _migration; } function setMigration(address destination) external onlyGovernance { _migration = destination; } function transferMigration(uint256 amount) external onlyAdminGovAgents { require(_migration != address(0), "Migration not set"); _transfer(_migration, amount, ""); } function reverseStakingTransfer(address recipient, uint256 amount) external onlyReverseStakingTreasury { _transfer(recipient, amount, ""); emit ReverseStakingTransfer(recipient, amount); } function reverseStakingRoute(address recipient, uint256 amount, bytes memory selector) external onlyReverseStakingTreasury { _transfer(recipient, amount, selector); emit ReverseStakingTransfer(recipient, amount); } function updateAddresses() external override onlyRegistrar { _vethReverseStakingTreasury = VETHReverseStakingTreasury(payable(_registrar.getVETHReverseStakingTreasury())); _updateGovernable(_registrar); } function _transfer(address recipient, uint256 amount, bytes memory payload) private { require(address(this).balance >= amount, "Insufficient balance"); (bool sent,) = recipient.call{value: amount}(payload); require(sent, "Failed to send Ether"); } receive() external payable {} }
{ "optimizer": { "enabled": true, "runs": 1000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"registrarAddress","type":"address"},{"internalType":"address","name":"ethComptrollerAddress_","type":"address"},{"internalType":"address[]","name":"adminGovAgents","type":"address[]"},{"internalType":"address[]","name":"backendAdminAgents","type":"address[]"},{"internalType":"address[]","name":"backendAgents","type":"address[]"},{"internalType":"address[]","name":"adminAgents","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakedVY","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"burnRatePaid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"yieldRate","type":"uint256"}],"name":"BurnAccruedVY","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"CloseOffer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakeTransferred","type":"uint256"}],"name":"CloseReverseStake","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quantity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"expiresAt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"CreateOffer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"termId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakedVY","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"originalClaimedYieldETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"currentClaimedYieldETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"yieldRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startAt","type":"uint256"}],"name":"CreateReverseStake","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"termId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dailyBurnRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minimumReverseStakeETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"processingFeePercentage","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"restakeMinimumPayout","type":"uint256"}],"name":"CreateReverseStakeTerm","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"termId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakedVY","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"originalClaimedYieldETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"currentClaimedYieldETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"yieldRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startAt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"previousReverseStakeId","type":"uint256"}],"name":"MigrateReverseStake","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakedVY","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"originalClaimedYieldETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"currentClaimedYieldETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"yieldRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startAt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"yieldPayout","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"previousReverseStakeIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"burnRatePaid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newTermId","type":"uint256"}],"name":"Restake","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"currentClaimedYieldETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakedVY","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakedVYReturned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"burnRatePaid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"paidAt","type":"uint256"}],"name":"ReturnETHToUnstake","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"agent","type":"address"}],"name":"RevokeBackendAgent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"agent","type":"address"}],"name":"SetBackendAgent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"indexed":false,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"uint256","name":"sellerQuantity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"buyerQuantity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"unfilledQuantity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"excessETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"TradeOffer","type":"event"},{"inputs":[],"name":"ETH_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EXPIRES_IN","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_RESTAKE_REVERSE_STAKES","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINIMUM_OFFER_AUTOCLOSE_IN_ETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OFFER_NET_STAKE_RATIO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OFFER_PRICE_YR_RATIO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VY_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"borrowers","type":"address[]"},{"internalType":"uint256[]","name":"reverseStakeIds","type":"uint256[]"}],"name":"burnAccruedVY","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"closeOffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"closeOffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"dailyBurnRate","type":"uint256"},{"internalType":"uint256","name":"minimumReverseStakeETH","type":"uint256"},{"internalType":"uint256","name":"processingFeePercentage","type":"uint256"},{"internalType":"uint256","name":"restakeMinimumPayout","type":"uint256"}],"name":"createNewReverseStakeTerm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"name":"createOffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"termId","type":"uint256"},{"internalType":"uint256","name":"ethAmount","type":"uint256"},{"internalType":"uint256","name":"vyAmount","type":"uint256"}],"name":"createReverseStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"termId","type":"uint256"},{"internalType":"uint256","name":"ethAmount","type":"uint256"},{"internalType":"uint256","name":"vyAmount","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"createReverseStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"ethToBurn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBurnAccruedVYTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBurnAccruedVYYieldRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentReverseStakeTerm","outputs":[{"components":[{"internalType":"uint256","name":"dailyBurnRate","type":"uint256"},{"internalType":"uint256","name":"minimumReverseStakeETH","type":"uint256"},{"internalType":"uint256","name":"processingFeePercentage","type":"uint256"},{"internalType":"uint256","name":"restakeMinimumPayout","type":"uint256"}],"internalType":"struct VETHReverseStakingTreasury.ReverseStakeTerm","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentReverseStakeTermId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGovernanceAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxReverseStakes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMigration","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"getOffer","outputs":[{"components":[{"internalType":"uint256","name":"unfilledQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"maxClaimedYieldETH","type":"uint256"},{"internalType":"uint256","name":"maxQuantity","type":"uint256"},{"internalType":"uint256","name":"expiresAt","type":"uint256"},{"internalType":"bool","name":"isOpen","type":"bool"}],"internalType":"struct VETHReverseStakingTreasury.Offer","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRegistrar","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"getReverseStake","outputs":[{"components":[{"internalType":"uint256","name":"termId","type":"uint256"},{"internalType":"uint256","name":"stakedVY","type":"uint256"},{"internalType":"uint256","name":"originalClaimedYieldETH","type":"uint256"},{"internalType":"uint256","name":"currentClaimedYieldETH","type":"uint256"},{"internalType":"uint256","name":"yieldRate","type":"uint256"},{"internalType":"uint256","name":"startAt","type":"uint256"},{"internalType":"uint256","name":"lastPaidAt","type":"uint256"}],"internalType":"struct VETHReverseStakingTreasury.ReverseStake","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"termId","type":"uint256"}],"name":"getReverseStakeTerm","outputs":[{"components":[{"internalType":"uint256","name":"dailyBurnRate","type":"uint256"},{"internalType":"uint256","name":"minimumReverseStakeETH","type":"uint256"},{"internalType":"uint256","name":"processingFeePercentage","type":"uint256"},{"internalType":"uint256","name":"restakeMinimumPayout","type":"uint256"}],"internalType":"struct VETHReverseStakingTreasury.ReverseStakeTerm","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReverseStakesNonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"ethAmount","type":"uint256"}],"name":"getStakedVYForReverseStakeETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalClaimedYield","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"isOfferActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"isReverseStakeActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"borrowerAddress","type":"address"},{"internalType":"uint256","name":"stakedVY","type":"uint256"},{"internalType":"uint256","name":"originalClaimedYieldETH","type":"uint256"},{"internalType":"uint256","name":"currentClaimedYieldETH","type":"uint256"},{"internalType":"uint256","name":"yieldRate","type":"uint256"},{"internalType":"uint256","name":"startAt","type":"uint256"},{"internalType":"uint256","name":"lastPaidAt","type":"uint256"},{"internalType":"uint256","name":"previousReverseStakeId","type":"uint256"},{"internalType":"uint256","name":"termId","type":"uint256"}],"internalType":"struct VETHReverseStakingTreasury.MigrateReverseStakeVars[]","name":"reverseStakeDataArray","type":"tuple[]"}],"name":"migrateReverseStakes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"registrarMigrateTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"reverseStakeIds","type":"uint256[]"}],"name":"restake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"returnETHToUnstake","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_agent","type":"address"}],"name":"revokeBackendAgent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_agent","type":"address"}],"name":"setBackendAgent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"maxReverseStakes_","type":"uint256"}],"name":"setMaxReverseStakes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"destination","type":"address"}],"name":"setMigration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"dailyBurnRate","type":"uint256"},{"internalType":"uint256","name":"minimumReverseStakeETH","type":"uint256"},{"internalType":"uint256","name":"processingFeePercentage","type":"uint256"},{"internalType":"uint256","name":"restakeMinimumPayout","type":"uint256"}],"name":"setupInitialReverseStakeTerm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"tradeOffer","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"reverseStakeId","type":"uint256"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"uint256","name":"amountVY","type":"uint256"}],"name":"tradeStakedVY","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferMigration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"reverseStakeId","type":"uint256"}],"name":"vyToBurn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
60806040526000600e556000600f55600060105560146011553480156200002557600080fd5b5060405162005c6838038062005c68833981016040819052620000489162000608565b8386600583808a6001600160a01b0381166200009a5760405162461bcd60e51b815260206004820152600f602482015260008051602062005c4883398151915260448201526064015b60405180910390fd5b600280546001600160a01b0319166001600160a01b039290921691909117905560005b8151811015620001985760006001600160a01b0316828281518110620000e757620000e7620006e6565b60200260200101516001600160a01b031603620001365760405162461bcd60e51b815260206004820152600f602482015260008051602062005c48833981519152604482015260640162000091565b600160036000848481518110620001515762000151620006e6565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055806200018f81620006fc565b915050620000bd565b50506001600160a01b038316620001e15760405162461bcd60e51b815260206004820152600f602482015260008051602062005c48833981519152604482015260640162000091565b50600480546001600160a01b0319166001600160a01b03939093169290921790915560055560005b8151811015620002e45760006001600160a01b0316828281518110620002335762000233620006e6565b60200260200101516001600160a01b031603620002825760405162461bcd60e51b815260206004820152600f602482015260008051602062005c48833981519152604482015260640162000091565b6001600660008484815181106200029d576200029d620006e6565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff191691151591909117905580620002db81620006fc565b91505062000209565b50506001600160a01b0385166200032d5760405162461bcd60e51b815260206004820152600f602482015260008051602062005c48833981519152604482015260640162000091565b600c80546001600160a01b0319166001600160a01b03871617905562000353836200036a565b6200035e826200044b565b50505050505062000724565b60005b8151811015620004475760006001600160a01b0316828281518110620003975762000397620006e6565b60200260200101516001600160a01b031603620003e65760405162461bcd60e51b815260206004820152600f602482015260008051602062005c48833981519152604482015260640162000091565b6001600080848481518110620004005762000400620006e6565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055806200043e81620006fc565b9150506200036d565b5050565b60005b8151811015620004475760006001600160a01b0316828281518110620004785762000478620006e6565b60200260200101516001600160a01b031603620004c75760405162461bcd60e51b815260206004820152600f602482015260008051602062005c48833981519152604482015260640162000091565b6001806000848481518110620004e157620004e1620006e6565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055806200051f81620006fc565b9150506200044e565b80516001600160a01b03811681146200054057600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200056d57600080fd5b815160206001600160401b03808311156200058c576200058c62000545565b8260051b604051601f19603f83011681018181108482111715620005b457620005b462000545565b604052938452858101830193838101925087851115620005d357600080fd5b83870191505b84821015620005fd57620005ed8262000528565b83529183019190830190620005d9565b979650505050505050565b60008060008060008060c087890312156200062257600080fd5b6200062d8762000528565b95506200063d6020880162000528565b60408801519095506001600160401b03808211156200065b57600080fd5b620006698a838b016200055b565b955060608901519150808211156200068057600080fd5b6200068e8a838b016200055b565b94506080890151915080821115620006a557600080fd5b620006b38a838b016200055b565b935060a0890151915080821115620006ca57600080fd5b50620006d989828a016200055b565b9150509295509295509295565b634e487b7160e01b600052603260045260246000fd5b6000600182016200071d57634e487b7160e01b600052601160045260246000fd5b5060010190565b61551480620007346000396000f3fe6080604052600436106102f65760003560e01c806379e5a2951161018f578063b86fd2f2116100e1578063dc35a9001161008a578063e335c8ca11610064578063e335c8ca146108c0578063e5004332146108d5578063e7bdc3f7146108f557600080fd5b8063dc35a90014610878578063dd037b7c14610898578063e26db6fc146108ab57600080fd5b8063c0152062116100bb578063c015206214610821578063cb73f90e14610841578063d3e7af001461085857600080fd5b8063b86fd2f2146107c1578063b930e828146107e1578063baee31e61461080157600080fd5b8063a17e0a1311610143578063ac71045e1161011d578063ac71045e14610733578063b1957e5d146107a1578063b3d6afa11461052657600080fd5b8063a17e0a13146106de578063a4a788cb146106fe578063abcac5eb1461071357600080fd5b80638a12f7ee116101745780638a12f7ee1461069f57806398e449a0146106b45780639ece8f16146106c957600080fd5b806379e5a29514610627578063809867f81461067f57600080fd5b80632c15975c116102485780634afbebee116101fc57806357036316116101d657806357036316146105d45780636f7a5b04146105e9578063732524941461060957600080fd5b80634afbebee146105815780634b09b11c146105a15780634d3f7334146105b657600080fd5b80633bb3bba41161022d5780633bb3bba414610526578063453d734c146105415780634779c77e1461056157600080fd5b80632c15975c146104b857806339c8e3921461050b57600080fd5b80630eeeb41e116102aa578063223eb64011610284578063223eb6401461045557806329256db7146104875780632aaf9d79146104a357600080fd5b80630eeeb41e146104025780630f2ad45214610415578063146699431461043557600080fd5b8063061dab7c116102db578063061dab7c146103a357806308ef74f2146103cd5780630dcfe693146103ed57600080fd5b80630256bf0f1461030257806305477ddf1461038157600080fd5b366102fd57005b600080fd5b34801561030e57600080fd5b5061032261031d366004614e28565b610915565b6040516103789190600060e082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015292915050565b60405180910390f35b34801561038d57600080fd5b506103a161039c366004614e54565b6109ce565b005b3480156103af57600080fd5b506103bf670e293894429c900081565b604051908152602001610378565b3480156103d957600080fd5b506103a16103e8366004614f43565b610a5e565b3480156103f957600080fd5b506012546103bf565b6103a1610410366004614e28565b611202565b34801561042157600080fd5b506103a1610430366004614f78565b6116a6565b34801561044157600080fd5b506103a1610450366004614e54565b611711565b34801561046157600080fd5b50600d546001600160a01b03165b6040516001600160a01b039091168152602001610378565b34801561049357600080fd5b506103bf670d99a8cec7e2000081565b3480156104af57600080fd5b506013546103bf565b3480156104c457600080fd5b506104d86104d3366004614e54565b611764565b60405161037891908151815260208083015190820152604080830151908201526060918201519181019190915260800190565b34801561051757600080fd5b506103bf6601c6bf5263400081565b34801561053257600080fd5b506103bf66470de4df82000081565b34801561054d57600080fd5b506103a161055c366004614f95565b6117d4565b34801561056d57600080fd5b506103a161057c366004614fd4565b611d5a565b34801561058d57600080fd5b506103a161059c366004614f78565b611f13565b3480156105ad57600080fd5b506103a1612013565b3480156105c257600080fd5b506002546001600160a01b031661046f565b3480156105e057600080fd5b50600e546103bf565b3480156105f557600080fd5b506103bf610604366004614e28565b612276565b34801561061557600080fd5b506007546001600160a01b031661046f565b34801561063357600080fd5b5061066f610642366004614e28565b6001600160a01b039190911660009081526015602090815260408083209383529290522060030154151590565b6040519015158152602001610378565b34801561068b57600080fd5b5061066f61069a366004614e28565b612289565b3480156106ab57600080fd5b506104d86122e8565b3480156106c057600080fd5b506103bf601481565b3480156106d557600080fd5b506011546103bf565b3480156106ea57600080fd5b506103a16106f9366004615000565b612360565b34801561070a57600080fd5b50600f546103bf565b34801561071f57600080fd5b506103a161072e366004614f78565b61259d565b34801561073f57600080fd5b5061075361074e366004614e28565b61263c565b6040516103789190600060c082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a0830151151560a083015292915050565b3480156107ad57600080fd5b506103a16107bc366004614e54565b6126ea565b3480156107cd57600080fd5b506103a16107dc366004614e28565b612822565b3480156107ed57600080fd5b506103a16107fc366004615076565b612900565b34801561080d57600080fd5b506103bf61081c366004614e28565b6129b2565b34801561082d57600080fd5b506103a161083c3660046150cf565b6129be565b34801561084d57600080fd5b506103bf62278d0081565b34801561086457600080fd5b506103a16108733660046150cf565b612a8e565b34801561088457600080fd5b506103a1610893366004614fd4565b612ad7565b6103a16108a6366004614e54565b612f5f565b3480156108b757600080fd5b506103a1613241565b3480156108cc57600080fd5b506010546103bf565b3480156108e157600080fd5b506103a16108f0366004615101565b613517565b34801561090157600080fd5b506103bf610910366004614e54565b613881565b6109556040518060e00160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b506001600160a01b0382166000908152601560209081526040808320848452825291829020825160e081018452815481526001820154928101929092526002810154928201929092526003820154606082015260048201546080820152600582015460a082015260069091015460c08201525b92915050565b33600081815260176020908152604080832085845290915290206005015482919060ff16610a4f5760405162461bcd60e51b8152602060048201526024808201527f4f66666572206d757374206265206f70656e20696e206f7264657220746f20636044820152636c6f736560e01b60648201526084015b60405180910390fd5b610a59338461388c565b505050565b8051339015801590610a7257506014825111155b610abe5760405162461bcd60e51b815260206004820152601f60248201527f496e76616c6964206e756d626572206f6620726576657273655374616b6573006044820152606401610a46565b60008060405180610120016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001855167ffffffffffffffff811115610b1857610b18614e6d565b604051908082528060200260200182016040528015610b41578160200160208202803683370190505b5081526020016000815250905060005b8451811015610d71576000858281518110610b6e57610b6e6151c3565b60200260200101519050808360e001518381518110610b8f57610b8f6151c3565b6020908102919091018101919091526001600160a01b03861660009081526015825260408082208483529092522060050154610bcc90151561391a565b6001600160a01b0385166000908152601560209081526040808320848452909152902060030154610bfe901515613967565b6001600160a01b0385166000908152601760209081526040808320848452909152902060050154610c319060ff166139b4565b6001600160a01b0385166000908152601560209081526040808320848452909152812090610c5f8784613a02565b90508085608001818151610c7391906151ef565b9052506001820154811115610cca5760405162461bcd60e51b815260206004820152601c60248201527f4e6f7420656e6f756768207374616b656420565920746f206275726e000000006044820152606401610a46565b6000818360010154610cdc9190615202565b90508086600001818151610cf091906151ef565b9052506003830154610d0290886151ef565b600060018501819055600385018190556001600160a01b038a1681526016602052604090205490975015610d5a576001600160a01b0388166000908152601660205260408120805491610d5483615215565b91905055505b505050508080610d699061522c565b915050610b51565b50600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de99190615245565b61010082018190528151610e0690670de0b6b3a76400009061525e565b610e109190615275565b6020820152600f8054600090610e259061522c565b91829055506040808301918252426060808501918252825160e081018452600e548152855160208083019182528088018051848801908152905194840194855261010089015160808501908152955160a08501908152600060c086018181526001600160a01b038e16808352601586528a83209b5183529a85528982209651875594516001870155915160028601559451600385015594516004840155925160058301555160069091015592815260169092528120805491610ee68361522c565b91905055508181602001511015610f655760405162461bcd60e51b815260206004820152602d60248201527f52657374616b656420726576657273655374616b6573206d75737420696e637260448201527f6561736520696e2076616c7565000000000000000000000000000000000000006064820152608401610a46565b818160200151610f759190615202565b60c0820181905260108054600090610f8e9084906151ef565b9091555050600e5460009081526014602052604090206002015460c0820151670de0b6b3a764000091610fc09161525e565b610fca9190615275565b60a0820152600e5460009081526014602052604090206003015460c082015110156110375760405162461bcd60e51b815260206004820152601c60248201527f4d696e696d756d207969656c64207061796f7574206e6f74206d6574000000006044820152606401610a46565b8060a001518160c00181815161104d9190615202565b905250600b5460c08201516040517f8555d03c0000000000000000000000000000000000000000000000000000000081526001600160a01b0386811660048301526024820192909252911690638555d03c90604401600060405180830381600087803b1580156110bc57600080fd5b505af11580156110d0573d6000803e3d6000fd5b5050600b54600c5460a08501516040805163d96661ef60e01b60208083019190915282518083039091018152818301928390527fd54fb850000000000000000000000000000000000000000000000000000000009092526001600160a01b03948516965063d54fb850955061114b9490931692604401615297565b600060405180830381600087803b15801561116557600080fd5b505af1158015611179573d6000803e3d6000fd5b5050505061118a8160800151613ab2565b7f3e201e2fa049f48369fb4795e1dee18ec57756e4270edc85986f17340ee1a14383826040015183600001518460200151856020015186610100015187606001518860c001518960e001518a60800151600e546040516111f49b9a999897969594939291906152fd565b60405180910390a150505050565b6001600160a01b03821660009081526017602090815260408083208484529091529020600501548290829060ff16801561126157506001600160a01b038216600090815260176020908152604080832084845290915290206004015442105b6112ad5760405162461bcd60e51b815260206004820152600d60248201527f496e76616c6964206f66666572000000000000000000000000000000000000006044820152606401610a46565b6112b634613ac8565b6001600160a01b038416600081815260176020908152604080832087845282528083209383526015825280832087845282528083208151608081018352848152928301849052908201839052606082019290925260018301548354670de0b6b3a7640000916113249161525e565b61132e9190615275565b80825261133d90341115613b18565b670de0b6b3a764000061135766470de4df8200003461525e565b6113619190615275565b6020820152600183015461137c66470de4df8200003461525e565b6113869190615275565b604082015260018301546113a2670de0b6b3a76400003461525e565b6113ac9190615275565b606082018190526002840154600385015460208401516000936113dc938c938c936113d79034615202565b613b65565b9050806080015161145e578354606083015111156113fc57835460608301525b81606001518460000160008282546114149190615202565b9091555050600184015484546000916601c6bf5263400091670de0b6b3a76400009161143f9161525e565b6114499190615275565b109050801561145c5761145c898961388c565b505b805160108054600090611472908490615202565b9091555050606081015160408301516114939161148e916151ef565b613ab2565b6114b033836040015184606001516114ab9190615202565b613d5c565b600c60009054906101000a90046001600160a01b03166001600160a01b031663d96661ef83602001516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561150457600080fd5b505af1158015611518573d6000803e3d6000fd5b5050600b546020808701519086015161155495506001600160a01b03909216935091506115459034615202565b61154f9190615202565b613df6565b60208101511561156c5761156c888260200151613df6565b60408101511561158457611584888260400151613d5c565b7f78c9e8649191f266751e42b82ad73571df372da7b068bb3123c8e2db3fed8bed888833606086810151895460208881015160068c0154604080516001600160a01b039a8b1681529384019890985297909516958101959095529184015234608084015260a083015260c082015260e08101919091526101000160405180910390a17fc3379670bfddf27010499de6ef21c7c372b91252cff56f0ad7821c597d81cf128888836000015186600301548760010154600087606001518a600601546040516116949897969594939291906001600160a01b03989098168852602088019690965260408701949094526060860192909252608085015260a084015260c083015260e08201526101000190565b60405180910390a15050505050505050565b6007546001600160a01b031633146116ef5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b600d80546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526020819052604090205460ff1661175f5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b601155565b61178f6040518060800160405280600081526020016000815260200160008152602001600081525090565b50600090815260146020908152604091829020825160808101845281548152600182015492810192909252600281015492820192909252600390910154606082015290565b33600081815260156020908152604080832088845290915290206005015485906117ff90151561391a565b6001600160a01b0382166000908152601560209081526040808320848452909152902060030154611831901515613967565b61183b8684613e99565b33600090815260156020908152604080832089845290915280822060085482517fb9520ce4000000000000000000000000000000000000000000000000000000008152600481018a90526001600160a01b03898116602483015293519294939091169163b9520ce49160448082019260c0929091908290030181865afa1580156118c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ed91906153ab565b90508060a0015115156001151514801561190b575060008160400151115b61197c5760405162461bcd60e51b8152602060048201526024808201527f4f6666657220697320636c6f736564206f7220686173207a65726f207175616e60448201527f74697479000000000000000000000000000000000000000000000000000000006064820152608401610a46565b6000611988338a613a02565b9050600081846001015461199c9190615202565b670e293894429c900085600301546119b4919061525e565b6119be9190615275565b9050806119d3670de0b6b3a76400008061525e565b6119dd9190615275565b90506119ef8184606001511115613ffd565b600a546008546040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b039182166004820152602481018a905291169063095ea7b3906044016020604051808303816000875af1158015611a5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a819190615436565b506008546040517fe34d5cee000000000000000000000000000000000000000000000000000000008152600481018b90526001600160a01b038a81166024830152604482018a9052600092169063e34d5cee9060640160a060405180830381865afa158015611af4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b189190615451565b90506000611b48338d8b8960030154888b60010154611b379190615202565b604088015188516113d79190615202565b9050806000015160106000828254611b609190615202565b90915550506008546040517f43097b4d000000000000000000000000000000000000000000000000000000008152600481018d90526001600160a01b038c81166024830152604482018c905260009216906343097b4d9060640160a0604051808303816000875af1158015611bd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bfd9190615451565b8051845191925014611c515760405162461bcd60e51b815260206004820152601860248201527f616d6f756e744f757420646f6573206e6f74206d6174636800000000000000006044820152606401610a46565b611c5e8260600151613ab2565b600b54604082015160208401518351611c85936001600160a01b0316929161154591615202565b602082015115611c9d57611c9d338360200151613df6565b604082015115611cb557611cb5338360400151613d5c565b7fc3379670bfddf27010499de6ef21c7c372b91252cff56f0ad7821c597d81cf12338e84600001518a600301548b60010154600088606001518e60060154604051611d439897969594939291906001600160a01b03989098168852602088019690965260408701949094526060860192909252608085015260a084015260c083015260e08201526101000190565b60405180910390a150505050505050505050505050565b600a5481906001600160a01b031663dd62ed3e336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152306024820152604401602060405180830381865afa158015611db8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ddc9190615245565b1015611e2a5760405162461bcd60e51b815260206004820152601660248201527f496e73756666696369656e7420616c6c6f77616e6365000000000000000000006044820152606401610a46565b600a5481906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611e82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ea69190615245565b1015611ef45760405162461bcd60e51b815260206004820152601460248201527f496e73756666696369656e742062616c616e63650000000000000000000000006044820152606401610a46565b6000611f0184848461404a565b9050611f0d83826141ac565b50505050565b3360009081526020819052604090205460ff16611f615760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b6001600160a01b038116611fb75760405162461bcd60e51b815260206004820152600f60248201527f496e76616c6964206164647265737300000000000000000000000000000000006044820152606401610a46565b6001600160a01b038116600081815260016020818152604092839020805460ff191690921790915590519182527fedc5f21c07112257f8f0b205468b4ebd7eef21c5292d6a22f475609077b331fc91015b60405180910390a150565b3360009081526003602052604090205460ff166120615760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b6004805460408051638d4e408360e01b815290516001600160a01b0390921692638d4e40839282820192602092908290030181865afa1580156120a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120cc9190615436565b156121195760405162461bcd60e51b815260206004820152601b60248201527f52656769737472617220616c72656164792066696e616c697a656400000000006044820152606401610a46565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663950304716040518163ffffffff1660e01b8152600401602060405180830381865afa15801561216e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061219291906154c1565b9050806001600160a01b031663259a22c4600460009054906101000a90046001600160a01b03166001600160a01b031663e83d88876040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221a9190615245565b6005546040516001600160e01b031960e085901b16815260048101929092526024820152604401600060405180830381600087803b15801561225b57600080fd5b505af115801561226f573d6000803e3d6000fd5b5050505050565b6000612282838361479a565b9392505050565b6001600160a01b038216600090815260176020908152604080832084845290915281206005015460ff1680156122825750506001600160a01b039190911660009081526017602090815260408083209383529290522060040154421090565b6123136040518060800160405280600081526020016000815260200160008152602001600081525090565b60146000600e548152602001908152602001600020604051806080016040529081600082015481526020016001820154815260200160028201548152602001600382015481525050905090565b3360009081526001602052604090205460ff166123ae5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b6004805460408051638d4e408360e01b815290516001600160a01b0390921692638d4e40839282820192602092908290030181865afa1580156123f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124199190615436565b156124665760405162461bcd60e51b815260206004820152601b60248201527f52656769737472617220616c72656164792066696e616c697a656400000000006044820152606401610a46565b60005b81811015610a595761258b838383818110612486576124866151c3565b61249d926020610120909202019081019150614f78565b8484848181106124af576124af6151c3565b90506101200201602001358585858181106124cc576124cc6151c3565b90506101200201604001358686868181106124e9576124e96151c3565b9050610120020160600135878787818110612506576125066151c3565b9050610120020160800135888888818110612523576125236151c3565b9050610120020160a00135898989818110612540576125406151c3565b9050610120020160c001358a8a8a81811061255d5761255d6151c3565b9050610120020160e001358b8b8b81811061257a5761257a6151c3565b90506101200201610100013561489a565b806125958161522c565b915050612469565b3360009081526020819052604090205460ff166125eb5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b6001600160a01b038116600081815260016020908152604091829020805460ff1916905590519182527fc16c6029d9b12a3ccc0fcf35b497a9f45ac515f76eda84dc53a2eb6cef8ef17b9101612008565b6126776040518060c0016040528060008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b506001600160a01b0382166000908152601760209081526040808320848452825291829020825160c08101845281548152600182015492810192909252600281015492820192909252600382015460608201526004820154608082015260059091015460ff16151560a082015292915050565b3360009081526006602052604090205460ff166127385760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b600d546001600160a01b03166127905760405162461bcd60e51b815260206004820152601160248201527f4d6967726174696f6e206e6f74207365740000000000000000000000000000006044820152606401610a46565b600a546040516370a0823160e01b81523060048201526128099183916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156127de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128029190615245565b1015614a89565b600d5461281f906001600160a01b031682613d5c565b50565b6001600160a01b03821660009081526017602090815260408083208484529091529020600501548190839060ff166128a85760405162461bcd60e51b8152602060048201526024808201527f4f66666572206d757374206265206f70656e20696e206f7264657220746f20636044820152636c6f736560e01b6064820152608401610a46565b3360009081526001602052604090205460ff166128f65760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b611f0d848461388c565b600061290d87878761404a565b600a549091506001600160a01b03166348613c28336040516001600160e01b031960e084901b1681526001600160a01b0390911660048201523060248201526044810188905260ff871660648201526084810186905260a4810185905260c401600060405180830381600087803b15801561298757600080fd5b505af115801561299b573d6000803e3d6000fd5b505050506129a986826141ac565b50505050505050565b60006122828383613a02565b3360009081526020819052604090205460ff16612a0c5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b600e5415612a825760405162461bcd60e51b815260206004820152602260248201527f52657665727365207374616b65207465726d7320616c7265616479207365742060448201527f75700000000000000000000000000000000000000000000000000000000000006064820152608401610a46565b611f0d84848484614ad6565b6007546001600160a01b03163314612a825760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b3360008181526015602090815260408083208784529091529020600501548490612b0290151561391a565b6001600160a01b0382166000908152601560209081526040808320848452909152902060030154612b34901515613967565b612b3d84613ac8565b33600090815260176020908152604080832088845290915290206005015460ff1615612bab5760405162461bcd60e51b815260206004820181905260248201527f4c696d6974206f6e65206f666665722070657220726576657273655374616b656044820152606401610a46565b3360008181526015602090815260408083208984528252808320815160e081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546080830152600581015460a08301526006015460c082015291612c1b9088613a02565b90508082602001511015612c715760405162461bcd60e51b815260206004820152601460248201527f4e6f7420656e6f756768207374616b65642056590000000000000000000000006044820152606401610a46565b6000670de0b6b3a7640000670d99a8cec7e20000838560200151612c959190615202565b612c9f919061525e565b612ca99190615275565b905080871115612cfb5760405162461bcd60e51b815260206004820152601660248201527f5175616e746974792065786365656473206c696d6974000000000000000000006044820152606401610a46565b600081670e293894429c90008560600151612d16919061525e565b612d209190615275565b9050612d2e81881015613ffd565b6000670e293894429c9000670de0b6b3a7640000600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d95573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612db99190615245565b612dc3919061525e565b612dcd9190615275565b90508088612de3670de0b6b3a76400008061525e565b612ded9190615275565b1115612e3b5760405162461bcd60e51b815260206004820152600d60248201527f507269636520746f6f206c6f77000000000000000000000000000000000000006044820152606401610a46565b6000612e4a62278d00426151ef565b90506040518060c001604052808b81526020018a8152602001876060015181526020018581526020018281526020016001151581525060176000612e8b3390565b6001600160a01b03168152602080820192909252604090810160009081208f82528352819020835181559183015160018301558201516002820155606082015160038201556080820151600482015560a0909101516005909101805460ff19169115159190911790557f8e7a928fda5f075156c168b588d71da0a7722cd83503729f3073ed5d67db794433604080516001600160a01b039092168252602082018e905281018c9052606081018b9052608081018390524260a082015260c00160405180910390a15050505050505050505050565b3360008181526015602090815260408083208584529091529020600501548290612f8a90151561391a565b6001600160a01b0382166000908152601560209081526040808320848452909152902060030154612fbc901515613967565b6000341161300c5760405162461bcd60e51b815260206004820152601460248201527f5a65726f2045544820616d6f756e742073656e740000000000000000000000006044820152606401610a46565b3360009081526017602090815260408083208684529091529020600501546130369060ff166139b4565b33600081815260156020908152604080832087845290915281209161305c905b86613a02565b905080826001015410156130b25760405162461bcd60e51b815260206004820152601c60248201527f4e6f7420656e6f756768207374616b656420565920746f206275726e000000006044820152606401610a46565b808260010160008282546130c69190615202565b90915550506003820154600090819034908111156130f75760038501546130ed9082615202565b9250846003015490505b8085600301540361311a576001850154915061311533896000614b8e565b61313c565b846003015481866001015461312f919061525e565b6131399190615275565b91505b808560030160008282546131509190615202565b925050819055508185600101600082825461316b9190615202565b90915550504260068601556010805482919060009061318b908490615202565b9091555061319a905084613ab2565b6131a43383613d5c565b600b546131ba906001600160a01b031682613df6565b82156131ca576131ca3384613df6565b7fc3379670bfddf27010499de6ef21c7c372b91252cff56f0ad7821c597d81cf1233600387015460018801546006890154604080516001600160a01b039095168552602085018e905284018690526060840192909252608083015260a0820185905260c0820187905260e082015261010001611694565b6002546001600160a01b0316336001600160a01b0316146132a45760405162461bcd60e51b815260206004820152601c60248201527f556e617574686f72697a65642c20726567697374726172206f6e6c79000000006044820152606401610a46565b600260009054906101000a90046001600160a01b03166001600160a01b0316631973c38a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156132f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061331b91906154c1565b600880546001600160a01b0319166001600160a01b03928316179055600254604080517fc5ffbbd70000000000000000000000000000000000000000000000000000000081529051919092169163c5ffbbd79160048083019260209291908290030181865afa158015613392573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133b691906154c1565b600980546001600160a01b0319166001600160a01b03928316179055600254604080517f950304710000000000000000000000000000000000000000000000000000000081529051919092169163950304719160048083019260209291908290030181865afa15801561342d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061345191906154c1565b600a80546001600160a01b0319166001600160a01b03928316179055600254604080517f737aad4d0000000000000000000000000000000000000000000000000000000081529051919092169163737aad4d9160048083019260209291908290030181865afa1580156134c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134ec91906154c1565b600b80546001600160a01b0319166001600160a01b039283161790556002546135159116614c5e565b565b3360009081526001602052604090205460ff166135655760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b80518251146135b65760405162461bcd60e51b815260206004820152601e60248201527f417267756d656e74206172726179206c656e677468206d69736d6174636800006044820152606401610a46565b6154606013546135c691906151ef565b42111561364c57600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136449190615245565b601255426013555b6000805b825181101561387757600083828151811061366d5761366d6151c3565b60200260200101519050600085838151811061368b5761368b6151c3565b6020908102919091018101516001600160a01b0381166000908152601583526040808220868352909352919091206005810154919250906136cd90151561391a565b6001600160a01b038216600090815260156020908152604080832086845290915290206003015461370057505050613865565b600061370f8385601254614ce3565b9050806000036137225750505050613865565b6001820154819081106137d3575060018201548015801590613748575060008360030154115b6137945760405162461bcd60e51b815260206004820152601e60248201527f526576657273655374616b6520697320616c726561647920636c6f73656400006044820152606401610a46565b8260030154601060008282546137aa9190615202565b925050819055506137c084868560010154614b8e565b60006001840181905560038401556137f3565b818360010160008282546137e79190615202565b90915550504260068401555b6137fd81886151ef565b6001840154601254604080516001600160a01b0389168152602081018a9052908101929092526060820184905260808201529097507f949a063c91c598bb241108d02c15b43e7f7aabc05c53b9128ee0a8463b0168a29060a00160405180910390a150505050505b8061386f8161522c565b915050613650565b50610a5981613ab2565b60006109c882614d05565b6001600160a01b0382166000818152601760209081526040808320858452825280832083815560018101849055600281018490556003810184905560048101939093556005909201805460ff19169055815192835282018390524282820152517fd38a9ec2a20325c37f49aefc9b3abebb86e05a8770b145a5e0dd57118164082d9181900360600190a15050565b8061281f5760405162461bcd60e51b815260206004820152601460248201527f496e76616c696420726576657273655374616b650000000000000000000000006044820152606401610a46565b8061281f5760405162461bcd60e51b815260206004820152601a60248201527f526576657273655374616b65206973206e6f74206163746976650000000000006044820152606401610a46565b801561281f5760405162461bcd60e51b815260206004820152601260248201527f416374697665206f6666657220666f756e6400000000000000000000000000006044820152606401610a46565b600080613a0f848461479a565b90506000600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613a66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a8a9190615245565b9050670de0b6b3a7640000613a9f828461525e565b613aa99190615275565b95945050505050565b60095461281f906001600160a01b031682613d5c565b6000811161281f5760405162461bcd60e51b815260206004820152601060248201527f496e76616c6964207175616e74697479000000000000000000000000000000006044820152606401610a46565b8061281f5760405162461bcd60e51b815260206004820152601260248201527f4e6f7420656e6f75676820746f2073656c6c00000000000000000000000000006044820152606401610a46565b613b996040518060a00160405280600081526020016000815260200160008152602001600081526020016000151581525090565b6001600160a01b03871660009081526015602090815260408083208984528252808320815160a08101835284815292830184905290820183905260608201839052608082019290925284613bed878961525e565b613bf79190615275565b808252841115613c13578051613c0d9085615202565b60208201525b613c1d8989613a02565b60608201819052613c2e90886151ef565b82600101541015613c815760405162461bcd60e51b815260206004820152601460248201527f4e6f7420656e6f756768207374616b65642056590000000000000000000000006044820152606401610a46565b6060810151613c9090886151ef565b826001016000828254613ca39190615202565b9091555050600382015481511115613cbd57600382015481525b80516003830154118015613ce55750805160038301546305f5e10091613ce291615202565b11155b15613cf257600382015481525b6003820154815103613d2b5760016080820152613d1189896000614b8e565b600182015415613d2b576001820180546040830152600090555b8051600383018054600090613d41908490615202565b90915550504260069092019190915590509695505050505050565b8015613df257600a546040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152602482018490529091169063a9059cbb906044016020604051808303816000875af1158015613dce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a599190615436565b5050565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114613e43576040519150601f19603f3d011682016040523d82523d6000602084013e613e48565b606091505b5050905080610a595760405162461bcd60e51b815260206004820152601460248201527f4661696c656420746f2073656e642045746865720000000000000000000000006044820152606401610a46565b613ea281613ac8565b336000908152601760209081526040808320858452825291829020825160c08101845281548152600182015492810192909252600281015492820192909252600382015460608201526004820154608082015260059091015460ff16151560a08201819052613f10906139b4565b3360008181526015602090815260408083208784528252808320815160e081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546080830152600581015460a08301526006015460c082015291613f7f90613056565b90508082602001511015613fd55760405162461bcd60e51b815260206004820152601460248201527f4e6f7420656e6f756768207374616b65642056590000000000000000000000006044820152606401610a46565b6000818360200151613fe79190615202565b9050613ff581861115613b18565b505050505050565b8061281f5760405162461bcd60e51b815260206004820152601560248201527f4d696e696d756d207072696365206e6f74206d657400000000000000000000006044820152606401610a46565b6000600e5484146140c25760405162461bcd60e51b8152602060048201526024808201527f496e76616c69642072657665727365207374616b65207465726d20737065636960448201527f66696564000000000000000000000000000000000000000000000000000000006064820152608401610a46565b60115433600090815260166020526040902054106141225760405162461bcd60e51b815260206004820152601e60248201527f4d6178696d756d2072657665727365207374616b6573207265616368656400006044820152606401610a46565b600061412d84614d05565b9050808310156141a45760405162461bcd60e51b8152602060048201526024808201527f7679416d6f756e7420746f6f206c6f77206261736564206f6e207969656c642060448201527f72617465000000000000000000000000000000000000000000000000000000006064820152608401610a46565b949350505050565b600e5460009081526014602090815260409182902082516080810184528154815260018201549281018390526002820154938101939093526003015460608301528310156142625760405162461bcd60e51b815260206004820152602160248201527f4d696e696d756d2072657665727365207374616b6520455448206e6f74206d6560448201527f74000000000000000000000000000000000000000000000000000000000000006064820152608401610a46565b600954604080517fd144b2c600000000000000000000000000000000000000000000000000000000815290516000926001600160a01b03169163d144b2c69160048083019260209291908290030181865afa1580156142c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142e99190615245565b600a546040516370a0823160e01b8152306004820152919250829185916001600160a01b0316906370a0823190602401602060405180830381865afa158015614336573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061435a9190615245565b61436491906151ef565b11156143d85760405162461bcd60e51b815260206004820152602960248201527f546f74616c207374616b65642056592063616e6e6f742065786365656420636960448201527f7263756c6174696f6e00000000000000000000000000000000000000000000006064820152608401610a46565b6000600f600081546143e99061522c565b91905081905590506000670de0b6b3a764000084604001518761440c919061525e565b6144169190615275565b905060006144248288615202565b600954604080517ff1009899000000000000000000000000000000000000000000000000000000008152905192935042926000926001600160a01b03169163f10098999160048083019260209291908290030181865afa15801561448c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144b09190615245565b90506040518060e00160405280600e5481526020018981526020018a81526020018a81526020018281526020018381526020016000815250601560006144f33390565b6001600160a01b0316815260208082019290925260409081016000908120898252835281812084518155848401516001820155848301516002820155606085015160038201556080850151600482015560a0850151600582015560c090940151600690940193909355338352601690915281208054916145728361522c565b9190505550886010600082825461458991906151ef565b9091555050600a546001600160a01b03166323b872dd336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152306024820152604481018b90526064016020604051808303816000875af11580156145f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146179190615436565b50600b546001600160a01b0316638555d03c336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101869052604401600060405180830381600087803b15801561467257600080fd5b505af1158015614686573d6000803e3d6000fd5b5050600b54600c546040805163d96661ef60e01b60208201526001600160a01b03938416955063d54fb850945092909116918891016040516020818303038152906040526040518463ffffffff1660e01b81526004016146e893929190615297565b600060405180830381600087803b15801561470257600080fd5b505af1158015614716573d6000803e3d6000fd5b505050507ff57fb4b6d0307d6415f11b10e6bd61dff3223dddb3c4dd23077376677815178d6147423390565b600e54604080516001600160a01b03909316835260208301899052820152606081018a9052608081018b905260a081018b905260c0810183905260e081018490526101000160405180910390a1505050505050505050565b6001600160a01b03821660009081526015602090815260408083208484528252808320815160e081018352815480825260018084015483870152600280850154848701526003808601546060808701919091526004870154608080880191909152600588015460a0880190815260069098015460c08801908152958b5260148a52888b2089519182018a5280548252948501549981019990995291830154968801969096529401549385019390935290519151909291849161485c9190614d9e565b9050670de0b6b3a7640000818360000151856060015161487c919061525e565b614886919061525e565b6148909190615275565b9695505050505050565b600084116148ea5760405162461bcd60e51b815260206004820152601d60248201527f50726576696f757320726576657273655374616b6520696e76616c69640000006044820152606401610a46565b6000600f600081546148fb9061522c565b91905081905590506040518060e001604052808381526020018a815260200189815260200188815260200187815260200186815260200185815250601560008c6001600160a01b03166001600160a01b031681526020019081526020016000206000838152602001908152602001600020600082015181600001556020820151816001015560408201518160020155606082015181600301556080820151816004015560a0820151816005015560c08201518160060155905050601660008b6001600160a01b03166001600160a01b0316815260200190815260200160002060008154809291906149eb9061522c565b91905055508660106000828254614a0291906151ef565b9091555050604080516001600160a01b038c16815260208101839052908101839052606081018a90526080810189905260a0810188905260c0810187905260e0810186905261010081018490527f2ab105565c687bf4a73f575447093ef42398279cdc7f090950777fc994ba2f00906101200160405180910390a150505050505050505050565b8061281f5760405162461bcd60e51b815260206004820152601460248201527f496e73756666696369656e742062616c616e63650000000000000000000000006044820152606401610a46565b60405180608001604052808581526020018481526020018381526020018281525060146000600e60008154614b0a9061522c565b91829055508152602080820192909252604090810160002083518155838301516001820155838201516002820155606093840151600390910155600e5481519081529182018790528101859052908101839052608081018290527fc48c0a6ec3053fcd949fb648264942c827b4fd0a67ecd428e585ad993748fafb9060a0016111f4565b6001600160a01b03831660009081526016602052604090205415614bd6576001600160a01b0383166000908152601660205260408120805491614bd083615215565b91905055505b6001600160a01b038316600090815260176020908152604080832085845290915290206005015460ff1615614c0f57614c0f838361388c565b604080516001600160a01b0385168152602081018490529081018290527f1f34b714276e41860b7d3e67e83ef075ac40dfbcd35e6ac9c8fc83896c3251619060600160405180910390a1505050565b806001600160a01b031663da91d7966040518163ffffffff1660e01b8152600401602060405180830381865afa158015614c9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614cc091906154c1565b600780546001600160a01b0319166001600160a01b039290921691909117905550565b600080614cf0858561479a565b9050670de0b6b3a7640000613a9f848361525e565b600080600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015614d5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d7f9190615245565b9050670de0b6b3a7640000614d94848361525e565b6122829190615275565b6000428215614df357600062015180614db78684615202565b614dc19190615275565b9050600062015180614dd38787615202565b614ddd9190615275565b9050614de98183615202565b93505050506109c8565b62015180614e018583615202565b614e0b9190615275565b9150506109c8565b6001600160a01b038116811461281f57600080fd5b60008060408385031215614e3b57600080fd5b8235614e4681614e13565b946020939093013593505050565b600060208284031215614e6657600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715614eac57614eac614e6d565b604052919050565b600067ffffffffffffffff821115614ece57614ece614e6d565b5060051b60200190565b600082601f830112614ee957600080fd5b81356020614efe614ef983614eb4565b614e83565b82815260059290921b84018101918181019086841115614f1d57600080fd5b8286015b84811015614f385780358352918301918301614f21565b509695505050505050565b600060208284031215614f5557600080fd5b813567ffffffffffffffff811115614f6c57600080fd5b6141a484828501614ed8565b600060208284031215614f8a57600080fd5b813561228281614e13565b60008060008060808587031215614fab57600080fd5b84359350602085013592506040850135614fc481614e13565b9396929550929360600135925050565b600080600060608486031215614fe957600080fd5b505081359360208301359350604090920135919050565b6000806020838503121561501357600080fd5b823567ffffffffffffffff8082111561502b57600080fd5b818501915085601f83011261503f57600080fd5b81358181111561504e57600080fd5b8660206101208302850101111561506457600080fd5b60209290920196919550909350505050565b60008060008060008060c0878903121561508f57600080fd5b863595506020870135945060408701359350606087013560ff811681146150b557600080fd5b9598949750929560808101359460a0909101359350915050565b600080600080608085870312156150e557600080fd5b5050823594602084013594506040840135936060013592509050565b6000806040838503121561511457600080fd5b823567ffffffffffffffff8082111561512c57600080fd5b818501915085601f83011261514057600080fd5b81356020615150614ef983614eb4565b82815260059290921b8401810191818101908984111561516f57600080fd5b948201945b8386101561519657853561518781614e13565b82529482019490820190615174565b965050860135925050808211156151ac57600080fd5b506151b985828601614ed8565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b808201808211156109c8576109c86151d9565b818103818111156109c8576109c86151d9565b600081615224576152246151d9565b506000190190565b60006001820161523e5761523e6151d9565b5060010190565b60006020828403121561525757600080fd5b5051919050565b80820281158282048414176109c8576109c86151d9565b60008261529257634e487b7160e01b600052601260045260246000fd5b500490565b6001600160a01b038416815260006020848184015260606040840152835180606085015260005b818110156152da578581018301518582016080015282016152be565b506000608082860101526080601f19601f83011685010192505050949350505050565b60006101608083016001600160a01b038f16845260208e818601528d60408601528c60608601528b60808601528a60a08601528960c08601528860e086015282610100860152819250875180835261018086019350818901925060005b818110156153765783518552938201939282019260010161535a565b505050506101208301949094525061014001529998505050505050505050565b805180151581146153a657600080fd5b919050565b600060c082840312156153bd57600080fd5b60405160c0810181811067ffffffffffffffff821117156153e0576153e0614e6d565b604052825181526020830151600281106153f957600080fd5b8060208301525060408301516040820152606083015160608201526080830151608082015261542a60a08401615396565b60a08201529392505050565b60006020828403121561544857600080fd5b61228282615396565b600060a0828403121561546357600080fd5b60405160a0810181811067ffffffffffffffff8211171561548657615486614e6d565b806040525082518152602083015160208201526040830151604082015260608301516060820152608083015160808201528091505092915050565b6000602082840312156154d357600080fd5b815161228281614e1356fea26469706673582212207078cd19319f90e7c302ffeb0b8df725a69972857c9362a6d8a67105db59000864736f6c63430008120033496e76616c69642061646472657373000000000000000000000000000000000000000000000000000000000096129af7c0183ef62d7e70b12bcc006d00c3de5f000000000000000000000000890ff89f7ae145e6472c1639517a07b4a2be444200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000093a4e1af91c97561df697c2092c371141b6828c800000000000000000000000000000000000000000000000000000000000000010000000000000000000000004b7f7c13591a69a2c8529b368b411e93a16a399b00000000000000000000000000000000000000000000000000000000000000020000000000000000000000001ef0b97318515c8e6274642746c5822099f1399400000000000000000000000021b1a4ee7581079ddda89908c3625270c3b6e2e300000000000000000000000000000000000000000000000000000000000000010000000000000000000000004b7f7c13591a69a2c8529b368b411e93a16a399b
Deployed Bytecode
0x6080604052600436106102f65760003560e01c806379e5a2951161018f578063b86fd2f2116100e1578063dc35a9001161008a578063e335c8ca11610064578063e335c8ca146108c0578063e5004332146108d5578063e7bdc3f7146108f557600080fd5b8063dc35a90014610878578063dd037b7c14610898578063e26db6fc146108ab57600080fd5b8063c0152062116100bb578063c015206214610821578063cb73f90e14610841578063d3e7af001461085857600080fd5b8063b86fd2f2146107c1578063b930e828146107e1578063baee31e61461080157600080fd5b8063a17e0a1311610143578063ac71045e1161011d578063ac71045e14610733578063b1957e5d146107a1578063b3d6afa11461052657600080fd5b8063a17e0a13146106de578063a4a788cb146106fe578063abcac5eb1461071357600080fd5b80638a12f7ee116101745780638a12f7ee1461069f57806398e449a0146106b45780639ece8f16146106c957600080fd5b806379e5a29514610627578063809867f81461067f57600080fd5b80632c15975c116102485780634afbebee116101fc57806357036316116101d657806357036316146105d45780636f7a5b04146105e9578063732524941461060957600080fd5b80634afbebee146105815780634b09b11c146105a15780634d3f7334146105b657600080fd5b80633bb3bba41161022d5780633bb3bba414610526578063453d734c146105415780634779c77e1461056157600080fd5b80632c15975c146104b857806339c8e3921461050b57600080fd5b80630eeeb41e116102aa578063223eb64011610284578063223eb6401461045557806329256db7146104875780632aaf9d79146104a357600080fd5b80630eeeb41e146104025780630f2ad45214610415578063146699431461043557600080fd5b8063061dab7c116102db578063061dab7c146103a357806308ef74f2146103cd5780630dcfe693146103ed57600080fd5b80630256bf0f1461030257806305477ddf1461038157600080fd5b366102fd57005b600080fd5b34801561030e57600080fd5b5061032261031d366004614e28565b610915565b6040516103789190600060e082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015292915050565b60405180910390f35b34801561038d57600080fd5b506103a161039c366004614e54565b6109ce565b005b3480156103af57600080fd5b506103bf670e293894429c900081565b604051908152602001610378565b3480156103d957600080fd5b506103a16103e8366004614f43565b610a5e565b3480156103f957600080fd5b506012546103bf565b6103a1610410366004614e28565b611202565b34801561042157600080fd5b506103a1610430366004614f78565b6116a6565b34801561044157600080fd5b506103a1610450366004614e54565b611711565b34801561046157600080fd5b50600d546001600160a01b03165b6040516001600160a01b039091168152602001610378565b34801561049357600080fd5b506103bf670d99a8cec7e2000081565b3480156104af57600080fd5b506013546103bf565b3480156104c457600080fd5b506104d86104d3366004614e54565b611764565b60405161037891908151815260208083015190820152604080830151908201526060918201519181019190915260800190565b34801561051757600080fd5b506103bf6601c6bf5263400081565b34801561053257600080fd5b506103bf66470de4df82000081565b34801561054d57600080fd5b506103a161055c366004614f95565b6117d4565b34801561056d57600080fd5b506103a161057c366004614fd4565b611d5a565b34801561058d57600080fd5b506103a161059c366004614f78565b611f13565b3480156105ad57600080fd5b506103a1612013565b3480156105c257600080fd5b506002546001600160a01b031661046f565b3480156105e057600080fd5b50600e546103bf565b3480156105f557600080fd5b506103bf610604366004614e28565b612276565b34801561061557600080fd5b506007546001600160a01b031661046f565b34801561063357600080fd5b5061066f610642366004614e28565b6001600160a01b039190911660009081526015602090815260408083209383529290522060030154151590565b6040519015158152602001610378565b34801561068b57600080fd5b5061066f61069a366004614e28565b612289565b3480156106ab57600080fd5b506104d86122e8565b3480156106c057600080fd5b506103bf601481565b3480156106d557600080fd5b506011546103bf565b3480156106ea57600080fd5b506103a16106f9366004615000565b612360565b34801561070a57600080fd5b50600f546103bf565b34801561071f57600080fd5b506103a161072e366004614f78565b61259d565b34801561073f57600080fd5b5061075361074e366004614e28565b61263c565b6040516103789190600060c082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a0830151151560a083015292915050565b3480156107ad57600080fd5b506103a16107bc366004614e54565b6126ea565b3480156107cd57600080fd5b506103a16107dc366004614e28565b612822565b3480156107ed57600080fd5b506103a16107fc366004615076565b612900565b34801561080d57600080fd5b506103bf61081c366004614e28565b6129b2565b34801561082d57600080fd5b506103a161083c3660046150cf565b6129be565b34801561084d57600080fd5b506103bf62278d0081565b34801561086457600080fd5b506103a16108733660046150cf565b612a8e565b34801561088457600080fd5b506103a1610893366004614fd4565b612ad7565b6103a16108a6366004614e54565b612f5f565b3480156108b757600080fd5b506103a1613241565b3480156108cc57600080fd5b506010546103bf565b3480156108e157600080fd5b506103a16108f0366004615101565b613517565b34801561090157600080fd5b506103bf610910366004614e54565b613881565b6109556040518060e00160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b506001600160a01b0382166000908152601560209081526040808320848452825291829020825160e081018452815481526001820154928101929092526002810154928201929092526003820154606082015260048201546080820152600582015460a082015260069091015460c08201525b92915050565b33600081815260176020908152604080832085845290915290206005015482919060ff16610a4f5760405162461bcd60e51b8152602060048201526024808201527f4f66666572206d757374206265206f70656e20696e206f7264657220746f20636044820152636c6f736560e01b60648201526084015b60405180910390fd5b610a59338461388c565b505050565b8051339015801590610a7257506014825111155b610abe5760405162461bcd60e51b815260206004820152601f60248201527f496e76616c6964206e756d626572206f6620726576657273655374616b6573006044820152606401610a46565b60008060405180610120016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001855167ffffffffffffffff811115610b1857610b18614e6d565b604051908082528060200260200182016040528015610b41578160200160208202803683370190505b5081526020016000815250905060005b8451811015610d71576000858281518110610b6e57610b6e6151c3565b60200260200101519050808360e001518381518110610b8f57610b8f6151c3565b6020908102919091018101919091526001600160a01b03861660009081526015825260408082208483529092522060050154610bcc90151561391a565b6001600160a01b0385166000908152601560209081526040808320848452909152902060030154610bfe901515613967565b6001600160a01b0385166000908152601760209081526040808320848452909152902060050154610c319060ff166139b4565b6001600160a01b0385166000908152601560209081526040808320848452909152812090610c5f8784613a02565b90508085608001818151610c7391906151ef565b9052506001820154811115610cca5760405162461bcd60e51b815260206004820152601c60248201527f4e6f7420656e6f756768207374616b656420565920746f206275726e000000006044820152606401610a46565b6000818360010154610cdc9190615202565b90508086600001818151610cf091906151ef565b9052506003830154610d0290886151ef565b600060018501819055600385018190556001600160a01b038a1681526016602052604090205490975015610d5a576001600160a01b0388166000908152601660205260408120805491610d5483615215565b91905055505b505050508080610d699061522c565b915050610b51565b50600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de99190615245565b61010082018190528151610e0690670de0b6b3a76400009061525e565b610e109190615275565b6020820152600f8054600090610e259061522c565b91829055506040808301918252426060808501918252825160e081018452600e548152855160208083019182528088018051848801908152905194840194855261010089015160808501908152955160a08501908152600060c086018181526001600160a01b038e16808352601586528a83209b5183529a85528982209651875594516001870155915160028601559451600385015594516004840155925160058301555160069091015592815260169092528120805491610ee68361522c565b91905055508181602001511015610f655760405162461bcd60e51b815260206004820152602d60248201527f52657374616b656420726576657273655374616b6573206d75737420696e637260448201527f6561736520696e2076616c7565000000000000000000000000000000000000006064820152608401610a46565b818160200151610f759190615202565b60c0820181905260108054600090610f8e9084906151ef565b9091555050600e5460009081526014602052604090206002015460c0820151670de0b6b3a764000091610fc09161525e565b610fca9190615275565b60a0820152600e5460009081526014602052604090206003015460c082015110156110375760405162461bcd60e51b815260206004820152601c60248201527f4d696e696d756d207969656c64207061796f7574206e6f74206d6574000000006044820152606401610a46565b8060a001518160c00181815161104d9190615202565b905250600b5460c08201516040517f8555d03c0000000000000000000000000000000000000000000000000000000081526001600160a01b0386811660048301526024820192909252911690638555d03c90604401600060405180830381600087803b1580156110bc57600080fd5b505af11580156110d0573d6000803e3d6000fd5b5050600b54600c5460a08501516040805163d96661ef60e01b60208083019190915282518083039091018152818301928390527fd54fb850000000000000000000000000000000000000000000000000000000009092526001600160a01b03948516965063d54fb850955061114b9490931692604401615297565b600060405180830381600087803b15801561116557600080fd5b505af1158015611179573d6000803e3d6000fd5b5050505061118a8160800151613ab2565b7f3e201e2fa049f48369fb4795e1dee18ec57756e4270edc85986f17340ee1a14383826040015183600001518460200151856020015186610100015187606001518860c001518960e001518a60800151600e546040516111f49b9a999897969594939291906152fd565b60405180910390a150505050565b6001600160a01b03821660009081526017602090815260408083208484529091529020600501548290829060ff16801561126157506001600160a01b038216600090815260176020908152604080832084845290915290206004015442105b6112ad5760405162461bcd60e51b815260206004820152600d60248201527f496e76616c6964206f66666572000000000000000000000000000000000000006044820152606401610a46565b6112b634613ac8565b6001600160a01b038416600081815260176020908152604080832087845282528083209383526015825280832087845282528083208151608081018352848152928301849052908201839052606082019290925260018301548354670de0b6b3a7640000916113249161525e565b61132e9190615275565b80825261133d90341115613b18565b670de0b6b3a764000061135766470de4df8200003461525e565b6113619190615275565b6020820152600183015461137c66470de4df8200003461525e565b6113869190615275565b604082015260018301546113a2670de0b6b3a76400003461525e565b6113ac9190615275565b606082018190526002840154600385015460208401516000936113dc938c938c936113d79034615202565b613b65565b9050806080015161145e578354606083015111156113fc57835460608301525b81606001518460000160008282546114149190615202565b9091555050600184015484546000916601c6bf5263400091670de0b6b3a76400009161143f9161525e565b6114499190615275565b109050801561145c5761145c898961388c565b505b805160108054600090611472908490615202565b9091555050606081015160408301516114939161148e916151ef565b613ab2565b6114b033836040015184606001516114ab9190615202565b613d5c565b600c60009054906101000a90046001600160a01b03166001600160a01b031663d96661ef83602001516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561150457600080fd5b505af1158015611518573d6000803e3d6000fd5b5050600b546020808701519086015161155495506001600160a01b03909216935091506115459034615202565b61154f9190615202565b613df6565b60208101511561156c5761156c888260200151613df6565b60408101511561158457611584888260400151613d5c565b7f78c9e8649191f266751e42b82ad73571df372da7b068bb3123c8e2db3fed8bed888833606086810151895460208881015160068c0154604080516001600160a01b039a8b1681529384019890985297909516958101959095529184015234608084015260a083015260c082015260e08101919091526101000160405180910390a17fc3379670bfddf27010499de6ef21c7c372b91252cff56f0ad7821c597d81cf128888836000015186600301548760010154600087606001518a600601546040516116949897969594939291906001600160a01b03989098168852602088019690965260408701949094526060860192909252608085015260a084015260c083015260e08201526101000190565b60405180910390a15050505050505050565b6007546001600160a01b031633146116ef5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b600d80546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526020819052604090205460ff1661175f5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b601155565b61178f6040518060800160405280600081526020016000815260200160008152602001600081525090565b50600090815260146020908152604091829020825160808101845281548152600182015492810192909252600281015492820192909252600390910154606082015290565b33600081815260156020908152604080832088845290915290206005015485906117ff90151561391a565b6001600160a01b0382166000908152601560209081526040808320848452909152902060030154611831901515613967565b61183b8684613e99565b33600090815260156020908152604080832089845290915280822060085482517fb9520ce4000000000000000000000000000000000000000000000000000000008152600481018a90526001600160a01b03898116602483015293519294939091169163b9520ce49160448082019260c0929091908290030181865afa1580156118c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ed91906153ab565b90508060a0015115156001151514801561190b575060008160400151115b61197c5760405162461bcd60e51b8152602060048201526024808201527f4f6666657220697320636c6f736564206f7220686173207a65726f207175616e60448201527f74697479000000000000000000000000000000000000000000000000000000006064820152608401610a46565b6000611988338a613a02565b9050600081846001015461199c9190615202565b670e293894429c900085600301546119b4919061525e565b6119be9190615275565b9050806119d3670de0b6b3a76400008061525e565b6119dd9190615275565b90506119ef8184606001511115613ffd565b600a546008546040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b039182166004820152602481018a905291169063095ea7b3906044016020604051808303816000875af1158015611a5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a819190615436565b506008546040517fe34d5cee000000000000000000000000000000000000000000000000000000008152600481018b90526001600160a01b038a81166024830152604482018a9052600092169063e34d5cee9060640160a060405180830381865afa158015611af4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b189190615451565b90506000611b48338d8b8960030154888b60010154611b379190615202565b604088015188516113d79190615202565b9050806000015160106000828254611b609190615202565b90915550506008546040517f43097b4d000000000000000000000000000000000000000000000000000000008152600481018d90526001600160a01b038c81166024830152604482018c905260009216906343097b4d9060640160a0604051808303816000875af1158015611bd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bfd9190615451565b8051845191925014611c515760405162461bcd60e51b815260206004820152601860248201527f616d6f756e744f757420646f6573206e6f74206d6174636800000000000000006044820152606401610a46565b611c5e8260600151613ab2565b600b54604082015160208401518351611c85936001600160a01b0316929161154591615202565b602082015115611c9d57611c9d338360200151613df6565b604082015115611cb557611cb5338360400151613d5c565b7fc3379670bfddf27010499de6ef21c7c372b91252cff56f0ad7821c597d81cf12338e84600001518a600301548b60010154600088606001518e60060154604051611d439897969594939291906001600160a01b03989098168852602088019690965260408701949094526060860192909252608085015260a084015260c083015260e08201526101000190565b60405180910390a150505050505050505050505050565b600a5481906001600160a01b031663dd62ed3e336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152306024820152604401602060405180830381865afa158015611db8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ddc9190615245565b1015611e2a5760405162461bcd60e51b815260206004820152601660248201527f496e73756666696369656e7420616c6c6f77616e6365000000000000000000006044820152606401610a46565b600a5481906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611e82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ea69190615245565b1015611ef45760405162461bcd60e51b815260206004820152601460248201527f496e73756666696369656e742062616c616e63650000000000000000000000006044820152606401610a46565b6000611f0184848461404a565b9050611f0d83826141ac565b50505050565b3360009081526020819052604090205460ff16611f615760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b6001600160a01b038116611fb75760405162461bcd60e51b815260206004820152600f60248201527f496e76616c6964206164647265737300000000000000000000000000000000006044820152606401610a46565b6001600160a01b038116600081815260016020818152604092839020805460ff191690921790915590519182527fedc5f21c07112257f8f0b205468b4ebd7eef21c5292d6a22f475609077b331fc91015b60405180910390a150565b3360009081526003602052604090205460ff166120615760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b6004805460408051638d4e408360e01b815290516001600160a01b0390921692638d4e40839282820192602092908290030181865afa1580156120a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120cc9190615436565b156121195760405162461bcd60e51b815260206004820152601b60248201527f52656769737472617220616c72656164792066696e616c697a656400000000006044820152606401610a46565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663950304716040518163ffffffff1660e01b8152600401602060405180830381865afa15801561216e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061219291906154c1565b9050806001600160a01b031663259a22c4600460009054906101000a90046001600160a01b03166001600160a01b031663e83d88876040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221a9190615245565b6005546040516001600160e01b031960e085901b16815260048101929092526024820152604401600060405180830381600087803b15801561225b57600080fd5b505af115801561226f573d6000803e3d6000fd5b5050505050565b6000612282838361479a565b9392505050565b6001600160a01b038216600090815260176020908152604080832084845290915281206005015460ff1680156122825750506001600160a01b039190911660009081526017602090815260408083209383529290522060040154421090565b6123136040518060800160405280600081526020016000815260200160008152602001600081525090565b60146000600e548152602001908152602001600020604051806080016040529081600082015481526020016001820154815260200160028201548152602001600382015481525050905090565b3360009081526001602052604090205460ff166123ae5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b6004805460408051638d4e408360e01b815290516001600160a01b0390921692638d4e40839282820192602092908290030181865afa1580156123f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124199190615436565b156124665760405162461bcd60e51b815260206004820152601b60248201527f52656769737472617220616c72656164792066696e616c697a656400000000006044820152606401610a46565b60005b81811015610a595761258b838383818110612486576124866151c3565b61249d926020610120909202019081019150614f78565b8484848181106124af576124af6151c3565b90506101200201602001358585858181106124cc576124cc6151c3565b90506101200201604001358686868181106124e9576124e96151c3565b9050610120020160600135878787818110612506576125066151c3565b9050610120020160800135888888818110612523576125236151c3565b9050610120020160a00135898989818110612540576125406151c3565b9050610120020160c001358a8a8a81811061255d5761255d6151c3565b9050610120020160e001358b8b8b81811061257a5761257a6151c3565b90506101200201610100013561489a565b806125958161522c565b915050612469565b3360009081526020819052604090205460ff166125eb5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b6001600160a01b038116600081815260016020908152604091829020805460ff1916905590519182527fc16c6029d9b12a3ccc0fcf35b497a9f45ac515f76eda84dc53a2eb6cef8ef17b9101612008565b6126776040518060c0016040528060008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b506001600160a01b0382166000908152601760209081526040808320848452825291829020825160c08101845281548152600182015492810192909252600281015492820192909252600382015460608201526004820154608082015260059091015460ff16151560a082015292915050565b3360009081526006602052604090205460ff166127385760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b600d546001600160a01b03166127905760405162461bcd60e51b815260206004820152601160248201527f4d6967726174696f6e206e6f74207365740000000000000000000000000000006044820152606401610a46565b600a546040516370a0823160e01b81523060048201526128099183916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156127de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128029190615245565b1015614a89565b600d5461281f906001600160a01b031682613d5c565b50565b6001600160a01b03821660009081526017602090815260408083208484529091529020600501548190839060ff166128a85760405162461bcd60e51b8152602060048201526024808201527f4f66666572206d757374206265206f70656e20696e206f7264657220746f20636044820152636c6f736560e01b6064820152608401610a46565b3360009081526001602052604090205460ff166128f65760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b611f0d848461388c565b600061290d87878761404a565b600a549091506001600160a01b03166348613c28336040516001600160e01b031960e084901b1681526001600160a01b0390911660048201523060248201526044810188905260ff871660648201526084810186905260a4810185905260c401600060405180830381600087803b15801561298757600080fd5b505af115801561299b573d6000803e3d6000fd5b505050506129a986826141ac565b50505050505050565b60006122828383613a02565b3360009081526020819052604090205460ff16612a0c5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b600e5415612a825760405162461bcd60e51b815260206004820152602260248201527f52657665727365207374616b65207465726d7320616c7265616479207365742060448201527f75700000000000000000000000000000000000000000000000000000000000006064820152608401610a46565b611f0d84848484614ad6565b6007546001600160a01b03163314612a825760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b3360008181526015602090815260408083208784529091529020600501548490612b0290151561391a565b6001600160a01b0382166000908152601560209081526040808320848452909152902060030154612b34901515613967565b612b3d84613ac8565b33600090815260176020908152604080832088845290915290206005015460ff1615612bab5760405162461bcd60e51b815260206004820181905260248201527f4c696d6974206f6e65206f666665722070657220726576657273655374616b656044820152606401610a46565b3360008181526015602090815260408083208984528252808320815160e081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546080830152600581015460a08301526006015460c082015291612c1b9088613a02565b90508082602001511015612c715760405162461bcd60e51b815260206004820152601460248201527f4e6f7420656e6f756768207374616b65642056590000000000000000000000006044820152606401610a46565b6000670de0b6b3a7640000670d99a8cec7e20000838560200151612c959190615202565b612c9f919061525e565b612ca99190615275565b905080871115612cfb5760405162461bcd60e51b815260206004820152601660248201527f5175616e746974792065786365656473206c696d6974000000000000000000006044820152606401610a46565b600081670e293894429c90008560600151612d16919061525e565b612d209190615275565b9050612d2e81881015613ffd565b6000670e293894429c9000670de0b6b3a7640000600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d95573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612db99190615245565b612dc3919061525e565b612dcd9190615275565b90508088612de3670de0b6b3a76400008061525e565b612ded9190615275565b1115612e3b5760405162461bcd60e51b815260206004820152600d60248201527f507269636520746f6f206c6f77000000000000000000000000000000000000006044820152606401610a46565b6000612e4a62278d00426151ef565b90506040518060c001604052808b81526020018a8152602001876060015181526020018581526020018281526020016001151581525060176000612e8b3390565b6001600160a01b03168152602080820192909252604090810160009081208f82528352819020835181559183015160018301558201516002820155606082015160038201556080820151600482015560a0909101516005909101805460ff19169115159190911790557f8e7a928fda5f075156c168b588d71da0a7722cd83503729f3073ed5d67db794433604080516001600160a01b039092168252602082018e905281018c9052606081018b9052608081018390524260a082015260c00160405180910390a15050505050505050505050565b3360008181526015602090815260408083208584529091529020600501548290612f8a90151561391a565b6001600160a01b0382166000908152601560209081526040808320848452909152902060030154612fbc901515613967565b6000341161300c5760405162461bcd60e51b815260206004820152601460248201527f5a65726f2045544820616d6f756e742073656e740000000000000000000000006044820152606401610a46565b3360009081526017602090815260408083208684529091529020600501546130369060ff166139b4565b33600081815260156020908152604080832087845290915281209161305c905b86613a02565b905080826001015410156130b25760405162461bcd60e51b815260206004820152601c60248201527f4e6f7420656e6f756768207374616b656420565920746f206275726e000000006044820152606401610a46565b808260010160008282546130c69190615202565b90915550506003820154600090819034908111156130f75760038501546130ed9082615202565b9250846003015490505b8085600301540361311a576001850154915061311533896000614b8e565b61313c565b846003015481866001015461312f919061525e565b6131399190615275565b91505b808560030160008282546131509190615202565b925050819055508185600101600082825461316b9190615202565b90915550504260068601556010805482919060009061318b908490615202565b9091555061319a905084613ab2565b6131a43383613d5c565b600b546131ba906001600160a01b031682613df6565b82156131ca576131ca3384613df6565b7fc3379670bfddf27010499de6ef21c7c372b91252cff56f0ad7821c597d81cf1233600387015460018801546006890154604080516001600160a01b039095168552602085018e905284018690526060840192909252608083015260a0820185905260c0820187905260e082015261010001611694565b6002546001600160a01b0316336001600160a01b0316146132a45760405162461bcd60e51b815260206004820152601c60248201527f556e617574686f72697a65642c20726567697374726172206f6e6c79000000006044820152606401610a46565b600260009054906101000a90046001600160a01b03166001600160a01b0316631973c38a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156132f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061331b91906154c1565b600880546001600160a01b0319166001600160a01b03928316179055600254604080517fc5ffbbd70000000000000000000000000000000000000000000000000000000081529051919092169163c5ffbbd79160048083019260209291908290030181865afa158015613392573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133b691906154c1565b600980546001600160a01b0319166001600160a01b03928316179055600254604080517f950304710000000000000000000000000000000000000000000000000000000081529051919092169163950304719160048083019260209291908290030181865afa15801561342d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061345191906154c1565b600a80546001600160a01b0319166001600160a01b03928316179055600254604080517f737aad4d0000000000000000000000000000000000000000000000000000000081529051919092169163737aad4d9160048083019260209291908290030181865afa1580156134c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134ec91906154c1565b600b80546001600160a01b0319166001600160a01b039283161790556002546135159116614c5e565b565b3360009081526001602052604090205460ff166135655760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a46565b80518251146135b65760405162461bcd60e51b815260206004820152601e60248201527f417267756d656e74206172726179206c656e677468206d69736d6174636800006044820152606401610a46565b6154606013546135c691906151ef565b42111561364c57600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136449190615245565b601255426013555b6000805b825181101561387757600083828151811061366d5761366d6151c3565b60200260200101519050600085838151811061368b5761368b6151c3565b6020908102919091018101516001600160a01b0381166000908152601583526040808220868352909352919091206005810154919250906136cd90151561391a565b6001600160a01b038216600090815260156020908152604080832086845290915290206003015461370057505050613865565b600061370f8385601254614ce3565b9050806000036137225750505050613865565b6001820154819081106137d3575060018201548015801590613748575060008360030154115b6137945760405162461bcd60e51b815260206004820152601e60248201527f526576657273655374616b6520697320616c726561647920636c6f73656400006044820152606401610a46565b8260030154601060008282546137aa9190615202565b925050819055506137c084868560010154614b8e565b60006001840181905560038401556137f3565b818360010160008282546137e79190615202565b90915550504260068401555b6137fd81886151ef565b6001840154601254604080516001600160a01b0389168152602081018a9052908101929092526060820184905260808201529097507f949a063c91c598bb241108d02c15b43e7f7aabc05c53b9128ee0a8463b0168a29060a00160405180910390a150505050505b8061386f8161522c565b915050613650565b50610a5981613ab2565b60006109c882614d05565b6001600160a01b0382166000818152601760209081526040808320858452825280832083815560018101849055600281018490556003810184905560048101939093556005909201805460ff19169055815192835282018390524282820152517fd38a9ec2a20325c37f49aefc9b3abebb86e05a8770b145a5e0dd57118164082d9181900360600190a15050565b8061281f5760405162461bcd60e51b815260206004820152601460248201527f496e76616c696420726576657273655374616b650000000000000000000000006044820152606401610a46565b8061281f5760405162461bcd60e51b815260206004820152601a60248201527f526576657273655374616b65206973206e6f74206163746976650000000000006044820152606401610a46565b801561281f5760405162461bcd60e51b815260206004820152601260248201527f416374697665206f6666657220666f756e6400000000000000000000000000006044820152606401610a46565b600080613a0f848461479a565b90506000600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613a66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a8a9190615245565b9050670de0b6b3a7640000613a9f828461525e565b613aa99190615275565b95945050505050565b60095461281f906001600160a01b031682613d5c565b6000811161281f5760405162461bcd60e51b815260206004820152601060248201527f496e76616c6964207175616e74697479000000000000000000000000000000006044820152606401610a46565b8061281f5760405162461bcd60e51b815260206004820152601260248201527f4e6f7420656e6f75676820746f2073656c6c00000000000000000000000000006044820152606401610a46565b613b996040518060a00160405280600081526020016000815260200160008152602001600081526020016000151581525090565b6001600160a01b03871660009081526015602090815260408083208984528252808320815160a08101835284815292830184905290820183905260608201839052608082019290925284613bed878961525e565b613bf79190615275565b808252841115613c13578051613c0d9085615202565b60208201525b613c1d8989613a02565b60608201819052613c2e90886151ef565b82600101541015613c815760405162461bcd60e51b815260206004820152601460248201527f4e6f7420656e6f756768207374616b65642056590000000000000000000000006044820152606401610a46565b6060810151613c9090886151ef565b826001016000828254613ca39190615202565b9091555050600382015481511115613cbd57600382015481525b80516003830154118015613ce55750805160038301546305f5e10091613ce291615202565b11155b15613cf257600382015481525b6003820154815103613d2b5760016080820152613d1189896000614b8e565b600182015415613d2b576001820180546040830152600090555b8051600383018054600090613d41908490615202565b90915550504260069092019190915590509695505050505050565b8015613df257600a546040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152602482018490529091169063a9059cbb906044016020604051808303816000875af1158015613dce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a599190615436565b5050565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114613e43576040519150601f19603f3d011682016040523d82523d6000602084013e613e48565b606091505b5050905080610a595760405162461bcd60e51b815260206004820152601460248201527f4661696c656420746f2073656e642045746865720000000000000000000000006044820152606401610a46565b613ea281613ac8565b336000908152601760209081526040808320858452825291829020825160c08101845281548152600182015492810192909252600281015492820192909252600382015460608201526004820154608082015260059091015460ff16151560a08201819052613f10906139b4565b3360008181526015602090815260408083208784528252808320815160e081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546080830152600581015460a08301526006015460c082015291613f7f90613056565b90508082602001511015613fd55760405162461bcd60e51b815260206004820152601460248201527f4e6f7420656e6f756768207374616b65642056590000000000000000000000006044820152606401610a46565b6000818360200151613fe79190615202565b9050613ff581861115613b18565b505050505050565b8061281f5760405162461bcd60e51b815260206004820152601560248201527f4d696e696d756d207072696365206e6f74206d657400000000000000000000006044820152606401610a46565b6000600e5484146140c25760405162461bcd60e51b8152602060048201526024808201527f496e76616c69642072657665727365207374616b65207465726d20737065636960448201527f66696564000000000000000000000000000000000000000000000000000000006064820152608401610a46565b60115433600090815260166020526040902054106141225760405162461bcd60e51b815260206004820152601e60248201527f4d6178696d756d2072657665727365207374616b6573207265616368656400006044820152606401610a46565b600061412d84614d05565b9050808310156141a45760405162461bcd60e51b8152602060048201526024808201527f7679416d6f756e7420746f6f206c6f77206261736564206f6e207969656c642060448201527f72617465000000000000000000000000000000000000000000000000000000006064820152608401610a46565b949350505050565b600e5460009081526014602090815260409182902082516080810184528154815260018201549281018390526002820154938101939093526003015460608301528310156142625760405162461bcd60e51b815260206004820152602160248201527f4d696e696d756d2072657665727365207374616b6520455448206e6f74206d6560448201527f74000000000000000000000000000000000000000000000000000000000000006064820152608401610a46565b600954604080517fd144b2c600000000000000000000000000000000000000000000000000000000815290516000926001600160a01b03169163d144b2c69160048083019260209291908290030181865afa1580156142c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142e99190615245565b600a546040516370a0823160e01b8152306004820152919250829185916001600160a01b0316906370a0823190602401602060405180830381865afa158015614336573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061435a9190615245565b61436491906151ef565b11156143d85760405162461bcd60e51b815260206004820152602960248201527f546f74616c207374616b65642056592063616e6e6f742065786365656420636960448201527f7263756c6174696f6e00000000000000000000000000000000000000000000006064820152608401610a46565b6000600f600081546143e99061522c565b91905081905590506000670de0b6b3a764000084604001518761440c919061525e565b6144169190615275565b905060006144248288615202565b600954604080517ff1009899000000000000000000000000000000000000000000000000000000008152905192935042926000926001600160a01b03169163f10098999160048083019260209291908290030181865afa15801561448c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144b09190615245565b90506040518060e00160405280600e5481526020018981526020018a81526020018a81526020018281526020018381526020016000815250601560006144f33390565b6001600160a01b0316815260208082019290925260409081016000908120898252835281812084518155848401516001820155848301516002820155606085015160038201556080850151600482015560a0850151600582015560c090940151600690940193909355338352601690915281208054916145728361522c565b9190505550886010600082825461458991906151ef565b9091555050600a546001600160a01b03166323b872dd336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152306024820152604481018b90526064016020604051808303816000875af11580156145f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146179190615436565b50600b546001600160a01b0316638555d03c336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101869052604401600060405180830381600087803b15801561467257600080fd5b505af1158015614686573d6000803e3d6000fd5b5050600b54600c546040805163d96661ef60e01b60208201526001600160a01b03938416955063d54fb850945092909116918891016040516020818303038152906040526040518463ffffffff1660e01b81526004016146e893929190615297565b600060405180830381600087803b15801561470257600080fd5b505af1158015614716573d6000803e3d6000fd5b505050507ff57fb4b6d0307d6415f11b10e6bd61dff3223dddb3c4dd23077376677815178d6147423390565b600e54604080516001600160a01b03909316835260208301899052820152606081018a9052608081018b905260a081018b905260c0810183905260e081018490526101000160405180910390a1505050505050505050565b6001600160a01b03821660009081526015602090815260408083208484528252808320815160e081018352815480825260018084015483870152600280850154848701526003808601546060808701919091526004870154608080880191909152600588015460a0880190815260069098015460c08801908152958b5260148a52888b2089519182018a5280548252948501549981019990995291830154968801969096529401549385019390935290519151909291849161485c9190614d9e565b9050670de0b6b3a7640000818360000151856060015161487c919061525e565b614886919061525e565b6148909190615275565b9695505050505050565b600084116148ea5760405162461bcd60e51b815260206004820152601d60248201527f50726576696f757320726576657273655374616b6520696e76616c69640000006044820152606401610a46565b6000600f600081546148fb9061522c565b91905081905590506040518060e001604052808381526020018a815260200189815260200188815260200187815260200186815260200185815250601560008c6001600160a01b03166001600160a01b031681526020019081526020016000206000838152602001908152602001600020600082015181600001556020820151816001015560408201518160020155606082015181600301556080820151816004015560a0820151816005015560c08201518160060155905050601660008b6001600160a01b03166001600160a01b0316815260200190815260200160002060008154809291906149eb9061522c565b91905055508660106000828254614a0291906151ef565b9091555050604080516001600160a01b038c16815260208101839052908101839052606081018a90526080810189905260a0810188905260c0810187905260e0810186905261010081018490527f2ab105565c687bf4a73f575447093ef42398279cdc7f090950777fc994ba2f00906101200160405180910390a150505050505050505050565b8061281f5760405162461bcd60e51b815260206004820152601460248201527f496e73756666696369656e742062616c616e63650000000000000000000000006044820152606401610a46565b60405180608001604052808581526020018481526020018381526020018281525060146000600e60008154614b0a9061522c565b91829055508152602080820192909252604090810160002083518155838301516001820155838201516002820155606093840151600390910155600e5481519081529182018790528101859052908101839052608081018290527fc48c0a6ec3053fcd949fb648264942c827b4fd0a67ecd428e585ad993748fafb9060a0016111f4565b6001600160a01b03831660009081526016602052604090205415614bd6576001600160a01b0383166000908152601660205260408120805491614bd083615215565b91905055505b6001600160a01b038316600090815260176020908152604080832085845290915290206005015460ff1615614c0f57614c0f838361388c565b604080516001600160a01b0385168152602081018490529081018290527f1f34b714276e41860b7d3e67e83ef075ac40dfbcd35e6ac9c8fc83896c3251619060600160405180910390a1505050565b806001600160a01b031663da91d7966040518163ffffffff1660e01b8152600401602060405180830381865afa158015614c9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614cc091906154c1565b600780546001600160a01b0319166001600160a01b039290921691909117905550565b600080614cf0858561479a565b9050670de0b6b3a7640000613a9f848361525e565b600080600960009054906101000a90046001600160a01b03166001600160a01b031663f10098996040518163ffffffff1660e01b8152600401602060405180830381865afa158015614d5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d7f9190615245565b9050670de0b6b3a7640000614d94848361525e565b6122829190615275565b6000428215614df357600062015180614db78684615202565b614dc19190615275565b9050600062015180614dd38787615202565b614ddd9190615275565b9050614de98183615202565b93505050506109c8565b62015180614e018583615202565b614e0b9190615275565b9150506109c8565b6001600160a01b038116811461281f57600080fd5b60008060408385031215614e3b57600080fd5b8235614e4681614e13565b946020939093013593505050565b600060208284031215614e6657600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715614eac57614eac614e6d565b604052919050565b600067ffffffffffffffff821115614ece57614ece614e6d565b5060051b60200190565b600082601f830112614ee957600080fd5b81356020614efe614ef983614eb4565b614e83565b82815260059290921b84018101918181019086841115614f1d57600080fd5b8286015b84811015614f385780358352918301918301614f21565b509695505050505050565b600060208284031215614f5557600080fd5b813567ffffffffffffffff811115614f6c57600080fd5b6141a484828501614ed8565b600060208284031215614f8a57600080fd5b813561228281614e13565b60008060008060808587031215614fab57600080fd5b84359350602085013592506040850135614fc481614e13565b9396929550929360600135925050565b600080600060608486031215614fe957600080fd5b505081359360208301359350604090920135919050565b6000806020838503121561501357600080fd5b823567ffffffffffffffff8082111561502b57600080fd5b818501915085601f83011261503f57600080fd5b81358181111561504e57600080fd5b8660206101208302850101111561506457600080fd5b60209290920196919550909350505050565b60008060008060008060c0878903121561508f57600080fd5b863595506020870135945060408701359350606087013560ff811681146150b557600080fd5b9598949750929560808101359460a0909101359350915050565b600080600080608085870312156150e557600080fd5b5050823594602084013594506040840135936060013592509050565b6000806040838503121561511457600080fd5b823567ffffffffffffffff8082111561512c57600080fd5b818501915085601f83011261514057600080fd5b81356020615150614ef983614eb4565b82815260059290921b8401810191818101908984111561516f57600080fd5b948201945b8386101561519657853561518781614e13565b82529482019490820190615174565b965050860135925050808211156151ac57600080fd5b506151b985828601614ed8565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b808201808211156109c8576109c86151d9565b818103818111156109c8576109c86151d9565b600081615224576152246151d9565b506000190190565b60006001820161523e5761523e6151d9565b5060010190565b60006020828403121561525757600080fd5b5051919050565b80820281158282048414176109c8576109c86151d9565b60008261529257634e487b7160e01b600052601260045260246000fd5b500490565b6001600160a01b038416815260006020848184015260606040840152835180606085015260005b818110156152da578581018301518582016080015282016152be565b506000608082860101526080601f19601f83011685010192505050949350505050565b60006101608083016001600160a01b038f16845260208e818601528d60408601528c60608601528b60808601528a60a08601528960c08601528860e086015282610100860152819250875180835261018086019350818901925060005b818110156153765783518552938201939282019260010161535a565b505050506101208301949094525061014001529998505050505050505050565b805180151581146153a657600080fd5b919050565b600060c082840312156153bd57600080fd5b60405160c0810181811067ffffffffffffffff821117156153e0576153e0614e6d565b604052825181526020830151600281106153f957600080fd5b8060208301525060408301516040820152606083015160608201526080830151608082015261542a60a08401615396565b60a08201529392505050565b60006020828403121561544857600080fd5b61228282615396565b600060a0828403121561546357600080fd5b60405160a0810181811067ffffffffffffffff8211171561548657615486614e6d565b806040525082518152602083015160208201526040830151604082015260608301516060820152608083015160808201528091505092915050565b6000602082840312156154d357600080fd5b815161228281614e1356fea26469706673582212207078cd19319f90e7c302ffeb0b8df725a69972857c9362a6d8a67105db59000864736f6c63430008120033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000096129af7c0183ef62d7e70b12bcc006d00c3de5f000000000000000000000000890ff89f7ae145e6472c1639517a07b4a2be444200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000093a4e1af91c97561df697c2092c371141b6828c800000000000000000000000000000000000000000000000000000000000000010000000000000000000000004b7f7c13591a69a2c8529b368b411e93a16a399b00000000000000000000000000000000000000000000000000000000000000020000000000000000000000001ef0b97318515c8e6274642746c5822099f1399400000000000000000000000021b1a4ee7581079ddda89908c3625270c3b6e2e300000000000000000000000000000000000000000000000000000000000000010000000000000000000000004b7f7c13591a69a2c8529b368b411e93a16a399b
-----Decoded View---------------
Arg [0] : registrarAddress (address): 0x96129aF7C0183ef62D7E70b12bcc006D00C3de5f
Arg [1] : ethComptrollerAddress_ (address): 0x890Ff89f7AE145e6472C1639517A07B4a2be4442
Arg [2] : adminGovAgents (address[]): 0x93a4e1Af91c97561dF697C2092c371141b6828C8
Arg [3] : backendAdminAgents (address[]): 0x4b7f7c13591A69a2C8529b368b411e93A16A399b
Arg [4] : backendAgents (address[]): 0x1eF0B97318515c8E6274642746c5822099f13994,0x21b1a4Ee7581079dDDA89908c3625270c3B6e2E3
Arg [5] : adminAgents (address[]): 0x4b7f7c13591A69a2C8529b368b411e93A16A399b
-----Encoded View---------------
15 Constructor Arguments found :
Arg [0] : 00000000000000000000000096129af7c0183ef62d7e70b12bcc006d00c3de5f
Arg [1] : 000000000000000000000000890ff89f7ae145e6472c1639517a07b4a2be4442
Arg [2] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [5] : 00000000000000000000000000000000000000000000000000000000000001a0
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [7] : 00000000000000000000000093a4e1af91c97561df697c2092c371141b6828c8
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [9] : 0000000000000000000000004b7f7c13591a69a2c8529b368b411e93a16a399b
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [11] : 0000000000000000000000001ef0b97318515c8e6274642746c5822099f13994
Arg [12] : 00000000000000000000000021b1a4ee7581079ddda89908c3625270c3b6e2e3
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [14] : 0000000000000000000000004b7f7c13591a69a2c8529b368b411e93a16a399b
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.