Skip to content
Verified contractExactMIT

VeOrnPausable

Address0xa003f9c86f95ce154de709819ad735b2c8fd90ff
Balance

0 ETH

 

Transactions

3

 

Compiler

solc 0.8.19

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.19+commit.7dd6d404
Language
solidity
Optimization
Yes, 200 runs
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
22,694,441
Creation transaction
0x89b3ccbc73…b6205d4a89

contracts/legacy/governance/VeORNPausable.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import {ReentrancyGuard} from "../../governance/libraries/ReentrancyGuard.sol";
import "./libraries/TransferHelper.sol";
import "./libraries/Math.sol";
import "./base/Staking.sol";
import "./base/StakingPoints.sol";
import "./base/TWBalance.sol";
import "./veORNStorage.sol";

import "./interfaces/IERC20Minimal.sol";

import "./interfaces/IveORN.sol";
import "./interfaces/IOrionVoting.sol";

import "../../governance/libraries/PausableLib.sol";

/**
 * @title veORN now VeLumia! We moved your locks to the new VeLumia contract on the new Lumia chain.
 * @author https://lumia.org/
 * @notice Checkout: https://token.lumia.org/governance
 */
contract VeOrnPausable is TWBalance, Staking, veORNStorage, StakingPoints, Pausable, ReentrancyGuard {
	using Math for uint128;
	using Math for uint256;

	uint256 public constant START_TIME = 1690848000; //Aug 01 2023 00:00:00 UTC
	uint128 constant DAY = 86400;
	uint128 constant WEEK = 7 * 86400;
	uint128 constant YEAR = 365 * 86400;
	uint256 constant MAXTIME = 2 * YEAR;
	uint256 constant MINTIME = WEEK;

	uint128 public constant ALPHA7 = 0x268e511cc4915e0000; //ALPHA=730/(30-Math.sqrt(730/7))**(1/3)/7;

	uint8 public immutable decimals;

	address public immutable ORN;
	address public immutable smartOwner;

	event Deposit(address indexed provider, uint256 value, uint256 indexed locktime, int128 mode, uint256 ts); //old

	event Withdraw(address indexed provider, uint256 value, uint256 ts);
	event UpdateDeposit(
		address indexed provider,
		uint48 time_lock,
		uint128 balance,
		uint128 amount_token,
		uint256 value,
		uint256 totalSupplyT0,
		uint256 ts
	);

	event AirdropStateUpdated();

	modifier onlyOwner() {
		require(msg.sender == smartOwner, "Caller is not the owner");
		_;
	}

	modifier onlyAdmin() {
		require(msg.sender == admin, "Caller is not the admin");
		_;
	}

	constructor(address ORN_) {
		ORN = ORN_;
		decimals = IERC20Minimal(ORN).decimals();
		smartOwner = msg.sender;
	}

	function pause(uint256 timestamp) public override onlyOwner {
		_pause(timestamp);
	}

	function unpause() public override onlyOwner {
		_unpause();
	}

	//erc20
	function name() external pure returns (string memory) {
		return "veORN";
	}

	function symbol() external pure returns (string memory) {
		return "veORN";
	}

	function setSmartVote(address addrVote) external onlyOwner {
		smartVote = addrVote;
	}

	//--------------------------------------Staking support

	function setAdmin(address _admin) external onlyOwner {
		admin = _admin;
	}

	function setRewards(uint64 rewards, uint64 duration) external onlyAdmin {
		_setRewards(rewards, duration);
	}

	function setPointsRewards(uint64 rewards, uint64 duration) external onlyAdmin {
		_setPointsRewards(rewards, duration);
	}

	function claimReward() external whenNotPaused nonReentrant {
		_claimReward();
	}

	//--------------------------------------Exp Balance support

	//util

	function getK(uint256 time) public pure returns (uint128) {
		if (time < START_TIME) time = START_TIME;
		uint128 deltaYears = (time - START_TIME).from_uint() / YEAR;
		return Math.exp_2(deltaYears * 2);
	}

	function amountAt(uint256 amount, uint256 time) public pure override returns (uint256) {
		return amount.div256(getK(time));
	}

	function amountByTokenAt(uint128 amount_token, uint256 time_lock) public view returns (uint128 balance) {
		uint128 K1 = getK(block.timestamp);

		uint128 deltaWeeks = (time_lock - block.timestamp).from_uint() / WEEK;
		//balance=amount_token.mul(Math.sqrt(deltaWeeks)).mul(K1);

		uint128 MultiplicatorSQRT = Math.sqrt(deltaWeeks);
		uint128 Multiplicator1 = deltaWeeks.div(ALPHA7);
		uint128 Multiplicator2 = Multiplicator1.mul(Multiplicator1);
		uint128 Multiplicator3 = Multiplicator2.mul(Multiplicator1);

		balance = amount_token.mul(MultiplicatorSQRT + Multiplicator3).mul(K1);
	}

	//view

	function totalSupply0() public view override returns (uint256) {
		return totalSupplyT0;
	}

	function balanceOf0(address account) public view override returns (uint256) {
		return tokenMap[account].balance;
	}

	function balanceTokenOf(address account) public view returns (uint256) {
		return tokenMap[account].amount_token;
	}

	function totalSupply() public view override returns (uint256) {
		return amountAt(totalSupply0(), block.timestamp);
	}

	function balanceOf(address account) public view override returns (uint256) {
		return amountAt(balanceOf0(account), block.timestamp);
	}

	function totalSupply(uint256 time) external view returns (uint256) {
		return amountAt(totalSupply0(), time);
	}

	function balanceOf(address account, uint256 time) external view returns (uint256) {
		return amountAt(balanceOf0(account), time);
	}

	function lockTime(address account) external view returns (uint48) {
		return tokenMap[account].time_lock;
	}

	//external

	function create_lock(uint256 _value, uint256 unlock_time) public whenNotPaused {
		_create_lock(_value, unlock_time);
	}

	function increase_amount(uint256 _value) external whenNotPaused {
		IveORN.UserInfo memory item = tokenMap[msg.sender];

		require(_value > 0, "need non-zero value");
		require(item.amount_token > 0, "No existing lock found");
		require(item.time_lock > block.timestamp, "Cannot add to expired lock");

		_deposit_for(msg.sender, _value, 0);
	}

	function increase_unlock_time(uint256 unlock_time) public whenNotPaused {
		IveORN.UserInfo memory item = tokenMap[msg.sender];
		require(item.amount_token > 0, "No existing lock found");

		require(unlock_time > item.time_lock, "Can only increase lock duration");
		require(unlock_time <= block.timestamp + MAXTIME, "Voting lock can be 2 years max");
		require(unlock_time >= block.timestamp + MINTIME, "Voting lock can be 1 week min");

		_deposit_for(msg.sender, 0, unlock_time);
	}

	function increase_unlock_period(uint256 unlock_period) external whenNotPaused {
		increase_unlock_time(block.timestamp + unlock_period);
	}

	function create_lock_period(uint256 _value, uint256 unlock_period) external whenNotPaused {
		create_lock(_value, block.timestamp + unlock_period);
	}

	function create_lock_period(uint256 _value, uint256 unlock_period, bool isDropLock) external whenNotPaused {
		create_lock(_value, block.timestamp + unlock_period);
	}

	function withdraw() external whenNotPaused nonReentrant {
		writeTWBalances(msg.sender);

		IveORN.UserInfo memory item = tokenMap[msg.sender];
		require(block.timestamp >= item.time_lock, "The lock didn't expire");

		//automatic removal of all votes
		if (smartVote != address(0)) IOrionVoting(smartVote).unvoteAll(msg.sender);

		//staking
		_claimReward();
		_unstake(msg.sender, item.balance);

		uint256 balance = item.amount_token;
		totalSupplyT0 -= item.balance;
		delete tokenMap[msg.sender];

		TransferHelper.safeTransfer(ORN, msg.sender, balance);

		emit Withdraw(msg.sender, balance, block.timestamp);
	}

	function updateAirdropState() external onlyOwner whenNotPaused {
		isAirdropPassed = true;

		_setEndTime(block.timestamp);

		emit AirdropStateUpdated();
	}

	/**
	 * @notice Move ORN tokens to Admin, that MUST bridge them to the Lumia chain
	 * @dev This function can only be called by the admin when the contract is paused
	 */
	function moveORNToVeLumia() external onlyAdmin whenPaused {
		uint256 ornBalance = IERC20Minimal(ORN).balanceOf(address(this));
		TransferHelper.safeTransfer(ORN, msg.sender, ornBalance);
	}

	//internal

	function _claimReward() internal {
		uint256 amount = getReward(msg.sender);
		if (amount > 0) {
			super._claimReward(msg.sender, amount);

			TransferHelper.safeTransfer(ORN, msg.sender, amount);
		}
	}

	function _create_lock(uint256 _value, uint256 unlock_time) internal {
		IveORN.UserInfo memory item = tokenMap[msg.sender];

		require(_value > 0, "need non-zero value");
		require(item.amount_token == 0, "Withdraw old tokens first");
		require(unlock_time > block.timestamp, "Can only lock until time in the future");
		require(unlock_time <= block.timestamp + MAXTIME, "Voting lock can be 2 years max");
		require(unlock_time >= block.timestamp + MINTIME, "Voting lock can be 1 week min");

		_deposit_for(msg.sender, _value, unlock_time);
	}

	function _deposit_for(address account, uint256 value, uint256 unlock_time) internal nonReentrant {
		writeTWBalances(account);

		IveORN.UserInfo storage item = tokenMap[account];

		uint128 delta;

		if (unlock_time > 0) {
			item.time_lock = uint48(unlock_time);
			item.amount_token += uint128(value);
			uint128 balance = amountByTokenAt(item.amount_token, item.time_lock);

			require(balance > item.balance, "_deposit_for: Only increase amount");

			delta = balance - item.balance;
		} else {
			item.amount_token += uint128(value);
			delta = amountByTokenAt(uint128(value), item.time_lock);
		}

		//staking
		_stake(account, delta);

		item.balance += delta;
		totalSupplyT0 += delta;

		if (value > 0) {
			TransferHelper.safeTransferFrom(ORN, msg.sender, address(this), value);
		}

		emit UpdateDeposit(
			account,
			item.time_lock,
			item.balance,
			item.amount_token,
			value,
			totalSupplyT0,
			block.timestamp
		);
	}
}

@openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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);
}

contracts/governance/libraries/PausableLib.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

library PausableLib {
	// Storage slot for pause state to avoid storage collision
	bytes32 private constant PAUSE_SLOT = bytes32(uint256(keccak256("orion.pausable.state")) - 1);

	error PauseShouldBeInTheFuture(uint256 timestamp);
	error AlreadyPaused(uint256 timestamp);
	error AlreadyUnpaused();

	struct PauseState {
		uint256 pausedTimestamp;
	}

	function getPauseState() internal pure returns (PauseState storage state) {
		bytes32 slot = PAUSE_SLOT;
		assembly {
			state.slot := slot
		}
	}

	function pause(uint256 timestamp) internal {
		PauseState storage state = getPauseState();
		if (state.pausedTimestamp != 0) revert AlreadyPaused(state.pausedTimestamp);
		if (timestamp == 0) timestamp = block.timestamp;
		else if (timestamp < block.timestamp) revert PauseShouldBeInTheFuture(timestamp);
		state.pausedTimestamp = timestamp;
	}

	function unpause() internal {
		PauseState storage state = getPauseState();
		if (state.pausedTimestamp == 0) revert AlreadyUnpaused();
		delete state.pausedTimestamp;
	}

	function isPaused() internal view returns (bool) {
		uint256 pausedTimestamp = getPauseState().pausedTimestamp;
		return pausedTimestamp != 0 && block.timestamp > pausedTimestamp;
	}

	function requireNotPaused() internal view {
		if (isPaused()) revert AlreadyPaused(getPauseState().pausedTimestamp);
	}

	function requirePaused() internal view {
		if (!isPaused()) revert AlreadyUnpaused();
	}
}

abstract contract Pausable {
	// Events
	event Paused(address account);
	event Unpaused(address account);

	// Modifiers
	modifier whenNotPaused() {
		PausableLib.requireNotPaused();
		_;
	}

	modifier whenPaused() {
		PausableLib.requirePaused();
		_;
	}

	/**
	 * @notice Returns the pause state of the contract.
	 * @return A boolean indicating whether the contract is paused.
	 */
	function isPaused() public view returns (bool) {
		return PausableLib.isPaused();
	}

	/**
	 * @notice Pauses the contract.
	 * @dev SHOULD BE REPLACED BY INHERITING CONTRACTS
	 * @param timestamp The timestamp at which the contract should be paused.
	 */
	function pause(uint256 timestamp) public virtual {}

	/**
	 * @notice Unpauses the contract.
	 * @dev SHOULD BE REPLACED BY INHERITING CONTRACTS
	 */
	function unpause() public virtual {}

	/**
	 * @notice Internal function to pause the contract.
	 * @param timestamp The timestamp at which the contract should be paused.
	 */
	function _pause(uint256 timestamp) internal whenNotPaused {
		PausableLib.pause(timestamp);
		emit Paused(msg.sender);
	}

	/**
	 * @notice Internal function to unpause the contract.
	 * @dev SHOULD BE REPLACED BY INHERITING CONTRACTS
	 */
	function _unpause() internal whenPaused {
		PausableLib.unpause();
		emit Unpaused(msg.sender);
	}
}

contracts/governance/libraries/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

library LibReentrancyGuardStorage {
	bytes32 internal constant STORAGE_POSITION = keccak256("orion.reentrancy.guard.storage");
	uint256 internal constant _NOT_ENTERED = 0;
	uint256 internal constant _ENTERED = 1;

	struct ReentrancyGuardStorage {
		uint256 status;
	}

	function reentrancyGuardStorage() internal pure returns (ReentrancyGuardStorage storage rgs) {
		bytes32 position = STORAGE_POSITION;
		assembly {
			rgs.slot := position
		}
	}
}

abstract contract ReentrancyGuard {
	error ReentrantCall();
	/**
	 * @notice Modifier that prevents reentrant calls to a function
	 * @dev This modifier uses a reentrancy guard to ensure that a function cannot be called
	 * while it is already being executed, protecting against reentrancy attacks.
	 */
	modifier nonReentrant() {
		LibReentrancyGuardStorage.ReentrancyGuardStorage storage rgs = LibReentrancyGuardStorage
			.reentrancyGuardStorage();

		if (rgs.status == LibReentrancyGuardStorage._ENTERED) {
			revert ReentrantCall();
		}

		rgs.status = LibReentrancyGuardStorage._ENTERED;

		_;

		rgs.status = LibReentrancyGuardStorage._NOT_ENTERED;
	}
}

contracts/legacy/governance/base/Staking.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

abstract contract Staking {
	uint256 internal constant RATE_PRECISION = 1e40;

	uint256 public rewardRate; //скорость наград, например 1 ORN в секунду на всех (точность 10**48)

	struct UserState {
		uint256 stake;
		uint256 rateCumulative;
		uint256 reward;
		uint256 rewardWithdraw;
	}

	uint256 public allStake; //сумма всех стейков
	mapping(address => UserState) public poolStake; //стейки по пользователям

	uint256 public rateCumulative;
	uint256 public rateTime;
	uint256 private rewardCumulativeTotal; //сумма всех наград

	event SetRewards(
		uint64 rewards,
		uint64 duration,
		uint256 rewardCumulativeTotal,
		uint256 rateCumulative,
		uint256 timestamp
	);
	event Stake(
		address indexed account,
		uint256 amount,
		uint256 rewardCumulativeTotal,
		uint256 rateCumulative,
		uint256 reward,
		uint256 timestamp
	);
	event Unstake(
		address indexed account,
		uint256 amount,
		uint256 rewardCumulativeTotal,
		uint256 rateCumulative,
		uint256 reward,
		uint256 timestamp
	);
	event ClaimReward(
		address indexed account,
		uint256 amount,
		uint256 rewardCumulativeTotal,
		uint256 rateCumulative,
		uint256 reward,
		uint256 timestamp
	);

	//  Set the overall reward
	function _setRewards(uint64 rewards, uint64 duration) internal {
		require(duration > 0, "_setRewards: zero duration");

		_writeCumulative();

		//  ORN / sec
		rewardRate = (RATE_PRECISION * rewards) / duration;

		emit SetRewards(rewards, duration, rewardCumulativeTotal, rateCumulative, block.timestamp);
	}

	//Расчет нового курса награды
	function calcNewRate() public view virtual returns (uint256) {
		uint256 Rate = 0;
		if (allStake > 0) {
			Rate = rewardRate / allStake;
		}

		return Rate * (block.timestamp - rateTime);
	}

	function _writeCumulative() internal virtual {
		uint256 newRate = calcNewRate();

		rewardCumulativeTotal += (newRate * allStake) / RATE_PRECISION;
		rateCumulative += newRate;
		rateTime = block.timestamp;
	}

	function _stake(address account, uint256 amount) internal {
		require(amount > 0, "_stake: zero stake amount");

		_writeCumulative();

		UserState memory item = poolStake[account];
		item.reward = _calcReward(item, rateCumulative);
		item.stake += amount;
		item.rateCumulative = rateCumulative;
		poolStake[account] = item;

		allStake += amount;

		emit Stake(account, amount, rewardCumulativeTotal, rateCumulative, item.reward, block.timestamp);
	}

	function _claimReward(address account, uint256 amount) internal {
		_writeCumulative();

		UserState memory item = poolStake[account];

		item.reward = _calcReward(item, rateCumulative);
		require(item.reward - item.rewardWithdraw >= amount, "Error claim amount");
		item.rewardWithdraw += amount;
		item.rateCumulative = rateCumulative;
		poolStake[account] = item;

		emit ClaimReward(account, amount, rewardCumulativeTotal, rateCumulative, item.reward, block.timestamp);
	}

	function _unstake(address account, uint256 amount) internal {
		_writeCumulative();

		UserState memory item = poolStake[account];
		require(item.stake >= amount, "Error unstake amount");

		item.reward = _calcReward(item, rateCumulative);
		item.stake -= amount;
		item.rateCumulative = rateCumulative;
		poolStake[account] = item;

		allStake -= amount;

		emit Unstake(account, amount, rewardCumulativeTotal, rateCumulative, item.reward, block.timestamp);
	}

	function _calcReward(UserState memory item, uint256 _rateCumulative) internal pure returns (uint256) {
		return item.reward + ((_rateCumulative - item.rateCumulative) * item.stake) / RATE_PRECISION;
	}

	function getReward(address account) public view virtual returns (uint256) {
		UserState memory item = poolStake[account];
		uint256 _rateCumulative = rateCumulative + calcNewRate();
		return _calcReward(item, _rateCumulative) - item.rewardWithdraw;
	}

	function getStake(address account) public view returns (uint256) {
		return poolStake[account].stake;
	}

	function getRewardWithdraw(address account) external view returns (uint256) {
		return poolStake[account].rewardWithdraw;
	}

	function getRewardCumulative(address account) external view returns (uint256) {
		return getReward(account) + poolStake[account].rewardWithdraw;
	}

	function getRewardCumulativeAll() public view returns (uint256) {
		uint256 newRate = calcNewRate();
		return rewardCumulativeTotal + (newRate * allStake) / RATE_PRECISION;
	}
}

contracts/legacy/governance/base/StakingPoints.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

abstract contract StakingPoints {
	uint256 internal constant RATE_PRECISION_POINTS = 1e40;

	uint256 public rewardPointsRate; //скорость наград, например 1 ORN в секунду на всех (точность 10**48)

	struct UserStatePoints {
		uint256 stake;
		uint256 rateCumulativePoints;
		uint256 reward;
		uint256 rewardWithdraw;
	}

	uint256 public allStakePoints; //сумма всех стейков
	mapping(address => UserStatePoints) public poolStakePoints; //стейки по пользователям

	uint256 public rateCumulativePoints;
	uint256 public rateTimePoints;
	uint256 private rewardCumulativePointsTotal; //сумма всех наград
	uint256 public endCumulativePointsTime;

	event SetPointsRewards(
		uint64 rewards,
		uint64 duration,
		uint256 rewardCumulativePointsTotal,
		uint256 rateCumulativePoints,
		uint256 timestamp
	);
	event StakePoints(
		address indexed account,
		uint256 amount,
		uint256 rewardCumulativePointsTotal,
		uint256 rateCumulativePoints,
		uint256 reward,
		uint256 timestamp
	);
	event UnstakePoints(
		address indexed account,
		uint256 amount,
		uint256 rewardCumulativePointsTotal,
		uint256 rateCumulativePoints,
		uint256 reward,
		uint256 timestamp
	);
	event ClaimRewardPoints(
		address indexed account,
		uint256 amount,
		uint256 rewardCumulativePointsTotal,
		uint256 rateCumulativePoints,
		uint256 reward,
		uint256 timestamp
	);

	function _setEndTime(uint256 endTime) internal {
		endCumulativePointsTime = endTime;
	}

	//  Set the overall reward
	function _setPointsRewards(uint64 rewards, uint64 duration) internal {
		require(duration > 0, "_setRewards: zero duration");

		_writeCumulativePoints();

		//  ORN / sec
		rewardPointsRate = (RATE_PRECISION_POINTS * rewards) / duration;

		emit SetPointsRewards(rewards, duration, rewardCumulativePointsTotal, rateCumulativePoints, block.timestamp);
	}

	//Расчет нового курса награды
	function calcPointsNewRate() public view virtual returns (uint256) {
		uint256 Rate = 0;
		if (allStakePoints > 0) {
			Rate = rewardPointsRate / allStakePoints;
		}

		if (endCumulativePointsTime != 0) {
			return Rate * (endCumulativePointsTime - rateTimePoints);
		}

		return Rate * (block.timestamp - rateTimePoints);
	}

	function _writeCumulativePoints() internal virtual {
		uint256 newRate = calcPointsNewRate();

		rewardCumulativePointsTotal += (newRate * allStakePoints) / RATE_PRECISION_POINTS;
		rateCumulativePoints += newRate;
		rateTimePoints = block.timestamp;
	}

	function _stakePoints(address account, uint256 amount) internal {
		require(amount > 0, "_stake: zero stake amount");

		_writeCumulativePoints();

		UserStatePoints memory item = poolStakePoints[account];
		item.reward = _calcPointsReward(item, rateCumulativePoints);
		item.stake += amount;
		item.rateCumulativePoints = rateCumulativePoints;
		poolStakePoints[account] = item;

		allStakePoints += amount;

		emit StakePoints(
			account,
			amount,
			rewardCumulativePointsTotal,
			rateCumulativePoints,
			item.reward,
			block.timestamp
		);
	}

	function _calcPointsReward(
		UserStatePoints memory item,
		uint256 _rateCumulativePoints
	) internal pure returns (uint256) {
		return item.reward + ((_rateCumulativePoints - item.rateCumulativePoints) * item.stake) / RATE_PRECISION_POINTS;
	}

	function getPointsReward(address account) public view virtual returns (uint256) {
		UserStatePoints memory item = poolStakePoints[account];
		uint256 _rateCumulativePoints = rateCumulativePoints + calcPointsNewRate();
		return _calcPointsReward(item, _rateCumulativePoints) - item.rewardWithdraw;
	}

	function getPointsStake(address account) public view returns (uint256) {
		return poolStakePoints[account].stake;
	}

	function getPointsRewardWithdraw(address account) external view returns (uint256) {
		return poolStakePoints[account].rewardWithdraw;
	}

	function getPointsRewardCumulative(address account) external view returns (uint256) {
		return getPointsReward(account) + poolStakePoints[account].rewardWithdraw;
	}

	function getPointsRewardCumulativeAll() public view returns (uint256) {
		uint256 newRate = calcPointsNewRate();
		return rewardCumulativePointsTotal + (newRate * allStakePoints) / RATE_PRECISION_POINTS;
	}
}

contracts/legacy/governance/base/TWBalance.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import "../interfaces/ITWBalance.sol";

abstract contract TWBalance is ITWBalance {
	mapping(address => TWItem) private twapUserMap;
	TWItem private twapTotalSupply;

	//view
	function balanceOfTW(address user) public view returns (TWItem memory) {
		uint256 currentAmount = balanceOf0(user);
		return calcNewTW(twapUserMap[user], uint160(currentAmount));
	}

	function balanceOfAvg(address user, TWItem memory itemStart) public view returns (uint256) {
		TWItem memory itemNew = balanceOfTW(user);
		return avgAmount(itemStart, itemNew);
	}

	function totalSupplyTW() public view returns (TWItem memory) {
		uint256 currentAmount = totalSupply0();
		return calcNewTW(twapTotalSupply, uint160(currentAmount));
	}

	function totalSupplyAvg(TWItem memory itemStart) public view returns (uint256) {
		TWItem memory itemNew = totalSupplyTW();
		return avgAmount(itemStart, itemNew);
	}

	//internal
	function writeTWBalances(address user) internal {
		twapUserMap[user] = balanceOfTW(user);
		twapTotalSupply = totalSupplyTW();
	}

	function calcNewTW(TWItem memory itemOld, uint160 amount) internal view returns (TWItem memory itemNew) {
		uint48 blockTimestamp = uint48(block.timestamp);
		uint48 timeElapsed = blockTimestamp - itemOld.timestamp;
		itemNew.amountTW = itemOld.amountTW + uint208(timeElapsed) * uint208(amount);
		itemNew.timestamp = blockTimestamp;
	}

	function avgAmount(TWItem memory itemStart, TWItem memory itemNew) internal pure returns (uint256) {
		uint256 timeElapsed = uint256(itemNew.timestamp) - uint256(itemStart.timestamp);
		if (timeElapsed > 0) {
			uint256 deltaTW = itemNew.amountTW - itemStart.amountTW;
			//return deltaTW/timeElapsed;//balance0
			return amountAt(deltaTW / timeElapsed, itemStart.timestamp + timeElapsed / 2); //баланс приводится по времени на середину отрезка
		} else {
			return 0;
		}
	}

	//virtual
	function balanceOf(address account) public view virtual returns (uint256);

	function totalSupply() public view virtual returns (uint256);

	function balanceOf0(address account) public view virtual returns (uint256);

	function totalSupply0() public view virtual returns (uint256);

	function amountAt(uint256 amount, uint256 time) public pure virtual returns (uint256);
}

contracts/legacy/governance/interfaces/IERC20Minimal.sol

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Minimal ERC20 interface for Uniswap
/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3
interface IERC20Minimal {
	/**
	 * @dev Returns the amount of tokens in existence.
	 */
	function totalSupply() external view returns (uint256);

	/// @notice Returns the balance of a token
	/// @param account The account for which to look up the number of tokens it has, i.e. its balance
	/// @return The number of tokens held by the account
	function balanceOf(address account) external view returns (uint256);

	/// @notice Returns the number of decimals used to get its user representation.
	function decimals() external view returns (uint8);

	/// @notice Transfers the amount of token from the `msg.sender` to the recipient
	/// @param recipient The account that will receive the amount transferred
	/// @param amount The number of tokens to send from the sender to the recipient
	/// @return Returns true for a successful transfer, false for an unsuccessful transfer
	function transfer(address recipient, uint256 amount) external returns (bool);

	/// @notice Returns the current allowance given to a spender by an owner
	/// @param owner The account of the token owner
	/// @param spender The account of the token spender
	/// @return The current allowance granted by `owner` to `spender`
	function allowance(address owner, address spender) external view returns (uint256);

	/// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`
	/// @param spender The account which will be allowed to spend a given amount of the owners tokens
	/// @param amount The amount of tokens allowed to be used by `spender`
	/// @return Returns true for a successful approval, false for unsuccessful
	function approve(address spender, uint256 amount) external returns (bool);

	/// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`
	/// @param sender The account from which the transfer will be initiated
	/// @param recipient The recipient of the transfer
	/// @param amount The amount of the transfer
	/// @return Returns true for a successful transfer, false for unsuccessful
	function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

	/// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.
	/// @param from The account from which the tokens were sent, i.e. the balance decreased
	/// @param to The account to which the tokens were sent, i.e. the balance increased
	/// @param value The amount of tokens that were transferred
	event Transfer(address indexed from, address indexed to, uint256 value);

	/// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.
	/// @param owner The account that approved spending of its tokens
	/// @param spender The account for which the spending allowance was modified
	/// @param value The new allowance from the owner to the spender
	event Approval(address indexed owner, address indexed spender, uint256 value);
}

contracts/legacy/governance/interfaces/IOrionVoting.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import "./IStaking.sol";

interface IOrionVoting is IStaking {
	//admin
	function setSmart(address addr, bool bUse) external;
	function setRewards(uint64 rewards, uint64 duration) external;
	function addPool(address pool) external;
	function deletePool(address pool) external;

	//user
	function vote(address pool, uint256 amount) external;
	function voteArr(address[] calldata pools, uint256[] calldata amounts) external;
	function unvote(address pool, uint256 amount) external;
	function unvoteAll(address account) external;

	//smart
	function claimReward(address pool, address to, uint256 amount) external;

	//vew
	function countPool() external view returns (uint256); //number of pools
	function poolList(uint256) external view returns (address); //list of pools
	function poolIndex(address pool) external view returns (uint256); //whether there is a pool in the list (index numbers starting from 1)
	function users(address user) external view returns (uint256); //user votes across all pools
	function usersPool(address user, address pool) external view returns (uint256); //user votes by pool
	function smarts(address smart) external view returns (bool); //white list of trusted farm contracts

	function veORN() external view returns (address);
	function ORN() external view returns (address);

	function havePool(address account) external view returns (bool);
}

contracts/legacy/governance/interfaces/IStaking.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

interface IStaking {
	//staking
	function getReward(address account) external view returns (uint256);
	function getStake(address account) external view returns (uint256);
	function allStake() external view returns (uint256);
	function rewardRate() external view returns (uint256);
	function rateCumulative() external view returns (uint256);
	function rateTime() external view returns (uint256);

	function getRewardWithdraw(address account) external view returns (uint256);
	function getRewardCumulative(address account) external view returns (uint256);
	function getRewardCumulativeAll() external view returns (uint256);
}

contracts/legacy/governance/interfaces/ITWBalance.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

interface ITWBalance {
	struct TWItem {
		// the block timestamp
		uint48 timestamp;
		// the amount accumulator, i.e. amount * time elapsed
		uint208 amountTW;
	}

	/// @notice Returns the time weight (TW) amount of tokens in existence.
	function totalSupplyTW() external view returns (TWItem memory);

	/// @notice Calculates the average aamount of tokens in existence from the specified TW period
	function totalSupplyAvg(TWItem memory itemStart) external view returns (uint256);

	/// @notice Returns the time weight (TW) balance of a token
	/// @param user The account for which to look up the number of tokens it has, i.e. its balance
	/// @return The number of tokens held by the account
	function balanceOfTW(address user) external view returns (TWItem memory);

	/// @notice Calculates the average address balance from the specified TW period
	function balanceOfAvg(address user, TWItem memory itemStart) external view returns (uint256);
}

contracts/legacy/governance/interfaces/IveORN.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import "./ITWBalance.sol";
import "./IStaking.sol";

interface IveORN is ITWBalance, IStaking {
	struct UserInfo {
		uint48 time_lock;
		uint128 balance;
		uint128 amount_token;
	}
	/**
	 * @dev Returns the amount of tokens in existence.
	 */
	function totalSupply() external view returns (uint256);
	function totalSupply(uint256 ts) external view returns (uint256);
	function totalSupply0() external view returns (uint256); //balance on start timestamp

	/// @notice Returns the balance of a token
	/// @param account The account for which to look up the number of tokens it has, i.e. its balance
	/// @return The number of tokens held by the account
	function balanceOf(address account) external view returns (uint256);
	function balanceOf(address account, uint256 ts) external view returns (uint256);
	function balanceOf0(address account) external view returns (uint256); //balance on start timestamp

	function balanceTokenOf(address account) external view returns (uint256);

	/// @notice Returns the number of decimals used to get its user representation.
	function decimals() external view returns (uint8);

	function name() external pure returns (string memory);
	function symbol() external pure returns (string memory);

	function ORN() external view returns (address);

	function lockTime(address account) external view returns (uint48);

	//staking ORN
	function create_lock(uint256 _value, uint256 _unlock_time) external;
	//function deposit_for(address _addr, uint256 _value) external;
	function increase_amount(uint256 _value) external;
	function increase_unlock_time(uint256 _unlock_time) external;
	function increase_unlock_period(uint256 unlock_period) external;
	function create_lock_period(uint256 _value, uint256 unlock_period) external;

	function withdraw() external;
	function claimReward() external;

	function tokenMap(address user) external returns (UserInfo memory);
}

contracts/legacy/governance/libraries/Math.sol

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.19;

library Math {
	uint128 private constant MAX_64x64 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
	uint128 private constant MAX_U64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

	/// @notice Cast a int128 to a uint128, revert on overflow
	/// @param y The int128 to be casted
	/// @return z The casted integer, now type uint128
	function toUint128(int128 y) internal pure returns (uint128 z) {
		unchecked {
			require(y >= 0);
			z = uint128(y);
		}
	}

	/// @notice Cast a uint128 to a int128, revert on overflow
	/// @param y The uint128 to be casted
	/// @return z The casted integer, now type int128
	function toInt128(uint128 y) internal pure returns (int128 z) {
		unchecked {
			require(y <= MAX_U64x64);
			z = int128(y);
		}
	}

	//precision 64.0 -> 64.64
	function from_uint(uint256 x) internal pure returns (uint128) {
		unchecked {
			require(x <= 0x7FFFFFFFFFFFFFFF);
			return uint128(x << 64);
		}
	}

	function div18(uint128 x, uint128 y) internal pure returns (uint128) {
		unchecked {
			require(y != 0);
			uint256 result = (uint256(x) * 10 ** 18) / y;
			require(result <= MAX_64x64);
			return uint128(result);
		}
	}

	/**
	 * Calculate x / y rounding towards zero.  Revert on overflow or when y is
	 * zero.
	 *
	 * @param x unsigned 64.64-bit fixed point number
	 * @param y unsigned 64.64-bit fixed point number
	 * @return unsigned 64.64-bit fixed point number
	 */
	function div256(uint256 x, uint128 y) internal pure returns (uint128) {
		unchecked {
			require(y != 0);
			uint256 result = ((x) << 64) / y;
			require(result <= MAX_64x64);
			return uint128(result);
		}
	}

	/**
	 * Calculate x * y rounding down.  Revert on overflow.
	 *
	 * @param x unsigned 64.64-bit fixed point number
	 * @param y unsigned 64.64-bit fixed point number
	 * @return unsigned 64.64-bit fixed point number
	 */
	function mul256(uint256 x, uint128 y) internal pure returns (uint128) {
		unchecked {
			uint256 result = ((x) * y) >> 64;
			require(result <= MAX_64x64);
			return uint128(result);
		}
	}

	/**
	 * Calculate x / y rounding towards zero.  Revert on overflow or when y is
	 * zero.
	 *
	 * @param x unsigned 64.64-bit fixed point number
	 * @param y unsigned 64.64-bit fixed point number
	 * @return unsigned 64.64-bit fixed point number
	 */
	function div(uint128 x, uint128 y) internal pure returns (uint128) {
		unchecked {
			require(y != 0);
			uint256 result = (uint256(x) << 64) / y;
			require(result <= MAX_64x64);
			return uint128(result);
		}
	}

	/**
	 * Calculate x * y rounding down.  Revert on overflow.
	 *
	 * @param x unsigned 64.64-bit fixed point number
	 * @param y unsigned 64.64-bit fixed point number
	 * @return unsigned 64.64-bit fixed point number
	 */
	function mul(uint128 x, uint128 y) internal pure returns (uint128) {
		unchecked {
			uint256 result = (uint256(x) * y) >> 64;
			require(result <= MAX_64x64);
			return uint128(result);
		}
	}

	function exp_2(uint128 x) internal pure returns (uint128) {
		return toUint128(exp_2(toInt128(x)));
	}

	function sqrt(uint128 x) internal pure returns (uint128) {
		return sqrtu(uint256(x) << 64);
	}

	//lib

	/// @notice Calculates the binary exponent of x using the binary fraction method.
	//  src from https://github.com/PaulRBerg/prb-math
	/// @param x0 The exponent as an unsigned 64.64-bit fixed-point number.
	/// @return result The result as an unsigned 64.64-bit  fixed-point number.
	/// @custom:smtchecker abstract-function-nondet
	function exp_2(int128 x0) internal pure returns (int128) {
		unchecked {
			require(x0 < 0x400000000000000000); // Overflow
			require(x0 >= 0);
			uint256 x = uint128(x0);

			// Start from 0.5 in the 192.64-bit fixed-point format.
			uint256 result = 0x800000000000000000000000000000000000000000000000;

			// The following logic multiplies the result by $\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
			//
			// 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
			// 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
			// a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
			// we know that `x & 0xFF` is also 1.
			if (x & 0xFF00000000000000 > 0) {
				if (x & 0x8000000000000000 > 0) {
					result = (result * 0x16A09E667F3BCC909) >> 64;
				}
				if (x & 0x4000000000000000 > 0) {
					result = (result * 0x1306FE0A31B7152DF) >> 64;
				}
				if (x & 0x2000000000000000 > 0) {
					result = (result * 0x1172B83C7D517ADCE) >> 64;
				}
				if (x & 0x1000000000000000 > 0) {
					result = (result * 0x10B5586CF9890F62A) >> 64;
				}
				if (x & 0x800000000000000 > 0) {
					result = (result * 0x1059B0D31585743AE) >> 64;
				}
				if (x & 0x400000000000000 > 0) {
					result = (result * 0x102C9A3E778060EE7) >> 64;
				}
				if (x & 0x200000000000000 > 0) {
					result = (result * 0x10163DA9FB33356D8) >> 64;
				}
				if (x & 0x100000000000000 > 0) {
					result = (result * 0x100B1AFA5ABCBED61) >> 64;
				}
			}

			if (x & 0xFF000000000000 > 0) {
				if (x & 0x80000000000000 > 0) {
					result = (result * 0x10058C86DA1C09EA2) >> 64;
				}
				if (x & 0x40000000000000 > 0) {
					result = (result * 0x1002C605E2E8CEC50) >> 64;
				}
				if (x & 0x20000000000000 > 0) {
					result = (result * 0x100162F3904051FA1) >> 64;
				}
				if (x & 0x10000000000000 > 0) {
					result = (result * 0x1000B175EFFDC76BA) >> 64;
				}
				if (x & 0x8000000000000 > 0) {
					result = (result * 0x100058BA01FB9F96D) >> 64;
				}
				if (x & 0x4000000000000 > 0) {
					result = (result * 0x10002C5CC37DA9492) >> 64;
				}
				if (x & 0x2000000000000 > 0) {
					result = (result * 0x1000162E525EE0547) >> 64;
				}
				if (x & 0x1000000000000 > 0) {
					result = (result * 0x10000B17255775C04) >> 64;
				}
			}

			if (x & 0xFF0000000000 > 0) {
				if (x & 0x800000000000 > 0) {
					result = (result * 0x1000058B91B5BC9AE) >> 64;
				}
				if (x & 0x400000000000 > 0) {
					result = (result * 0x100002C5C89D5EC6D) >> 64;
				}
				if (x & 0x200000000000 > 0) {
					result = (result * 0x10000162E43F4F831) >> 64;
				}
				if (x & 0x100000000000 > 0) {
					result = (result * 0x100000B1721BCFC9A) >> 64;
				}
				if (x & 0x80000000000 > 0) {
					result = (result * 0x10000058B90CF1E6E) >> 64;
				}
				if (x & 0x40000000000 > 0) {
					result = (result * 0x1000002C5C863B73F) >> 64;
				}
				if (x & 0x20000000000 > 0) {
					result = (result * 0x100000162E430E5A2) >> 64;
				}
				if (x & 0x10000000000 > 0) {
					result = (result * 0x1000000B172183551) >> 64;
				}
			}

			if (x & 0xFF00000000 > 0) {
				if (x & 0x8000000000 > 0) {
					result = (result * 0x100000058B90C0B49) >> 64;
				}
				if (x & 0x4000000000 > 0) {
					result = (result * 0x10000002C5C8601CC) >> 64;
				}
				if (x & 0x2000000000 > 0) {
					result = (result * 0x1000000162E42FFF0) >> 64;
				}
				if (x & 0x1000000000 > 0) {
					result = (result * 0x10000000B17217FBB) >> 64;
				}
				if (x & 0x800000000 > 0) {
					result = (result * 0x1000000058B90BFCE) >> 64;
				}
				if (x & 0x400000000 > 0) {
					result = (result * 0x100000002C5C85FE3) >> 64;
				}
				if (x & 0x200000000 > 0) {
					result = (result * 0x10000000162E42FF1) >> 64;
				}
				if (x & 0x100000000 > 0) {
					result = (result * 0x100000000B17217F8) >> 64;
				}
			}

			if (x & 0xFF000000 > 0) {
				if (x & 0x80000000 > 0) {
					result = (result * 0x10000000058B90BFC) >> 64;
				}
				if (x & 0x40000000 > 0) {
					result = (result * 0x1000000002C5C85FE) >> 64;
				}
				if (x & 0x20000000 > 0) {
					result = (result * 0x100000000162E42FF) >> 64;
				}
				if (x & 0x10000000 > 0) {
					result = (result * 0x1000000000B17217F) >> 64;
				}
				if (x & 0x8000000 > 0) {
					result = (result * 0x100000000058B90C0) >> 64;
				}
				if (x & 0x4000000 > 0) {
					result = (result * 0x10000000002C5C860) >> 64;
				}
				if (x & 0x2000000 > 0) {
					result = (result * 0x1000000000162E430) >> 64;
				}
				if (x & 0x1000000 > 0) {
					result = (result * 0x10000000000B17218) >> 64;
				}
			}

			if (x & 0xFF0000 > 0) {
				if (x & 0x800000 > 0) {
					result = (result * 0x1000000000058B90C) >> 64;
				}
				if (x & 0x400000 > 0) {
					result = (result * 0x100000000002C5C86) >> 64;
				}
				if (x & 0x200000 > 0) {
					result = (result * 0x10000000000162E43) >> 64;
				}
				if (x & 0x100000 > 0) {
					result = (result * 0x100000000000B1721) >> 64;
				}
				if (x & 0x80000 > 0) {
					result = (result * 0x10000000000058B91) >> 64;
				}
				if (x & 0x40000 > 0) {
					result = (result * 0x1000000000002C5C8) >> 64;
				}
				if (x & 0x20000 > 0) {
					result = (result * 0x100000000000162E4) >> 64;
				}
				if (x & 0x10000 > 0) {
					result = (result * 0x1000000000000B172) >> 64;
				}
			}

			if (x & 0xFF00 > 0) {
				if (x & 0x8000 > 0) {
					result = (result * 0x100000000000058B9) >> 64;
				}
				if (x & 0x4000 > 0) {
					result = (result * 0x10000000000002C5D) >> 64;
				}
				if (x & 0x2000 > 0) {
					result = (result * 0x1000000000000162E) >> 64;
				}
				if (x & 0x1000 > 0) {
					result = (result * 0x10000000000000B17) >> 64;
				}
				if (x & 0x800 > 0) {
					result = (result * 0x1000000000000058C) >> 64;
				}
				if (x & 0x400 > 0) {
					result = (result * 0x100000000000002C6) >> 64;
				}
				if (x & 0x200 > 0) {
					result = (result * 0x10000000000000163) >> 64;
				}
				if (x & 0x100 > 0) {
					result = (result * 0x100000000000000B1) >> 64;
				}
			}

			if (x & 0xFF > 0) {
				if (x & 0x80 > 0) {
					result = (result * 0x10000000000000059) >> 64;
				}
				if (x & 0x40 > 0) {
					result = (result * 0x1000000000000002C) >> 64;
				}
				if (x & 0x20 > 0) {
					result = (result * 0x10000000000000016) >> 64;
				}
				if (x & 0x10 > 0) {
					result = (result * 0x1000000000000000B) >> 64;
				}
				if (x & 0x8 > 0) {
					result = (result * 0x10000000000000006) >> 64;
				}
				if (x & 0x4 > 0) {
					result = (result * 0x10000000000000003) >> 64;
				}
				if (x & 0x2 > 0) {
					result = (result * 0x10000000000000001) >> 64;
				}
				if (x & 0x1 > 0) {
					result = (result * 0x10000000000000001) >> 64;
				}
			}

			result >>= 127 - (x >> 64);

			require(result <= uint256(int256(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));

			return int128(int256(result));
		}
	}

	/**
	 * Calculate sqrt (x) rounding down.  Revert if x < 0.
	 *
	 * @param x signed 64.64-bit fixed point number
	 * @return signed 64.64-bit fixed point number
	 */
	function sqrt0(int128 x) internal pure returns (int128) {
		unchecked {
			require(x >= 0);
			return int128(sqrtu(uint256(int256(x)) << 64));
		}
	}

	/**
	 * Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer
	 * number.
	 *
	 * @param x unsigned 256-bit integer number
	 * @return unsigned 128-bit integer number
	 */
	function sqrtu(uint256 x) private pure returns (uint128) {
		unchecked {
			if (x == 0) return 0;
			else {
				uint256 xx = x;
				uint256 r = 1;
				if (xx >= 0x100000000000000000000000000000000) {
					xx >>= 128;
					r <<= 64;
				}
				if (xx >= 0x10000000000000000) {
					xx >>= 64;
					r <<= 32;
				}
				if (xx >= 0x100000000) {
					xx >>= 32;
					r <<= 16;
				}
				if (xx >= 0x10000) {
					xx >>= 16;
					r <<= 8;
				}
				if (xx >= 0x100) {
					xx >>= 8;
					r <<= 4;
				}
				if (xx >= 0x10) {
					xx >>= 4;
					r <<= 2;
				}
				if (xx >= 0x4) {
					r <<= 1;
				}
				r = (r + x / r) >> 1;
				r = (r + x / r) >> 1;
				r = (r + x / r) >> 1;
				r = (r + x / r) >> 1;
				r = (r + x / r) >> 1;
				r = (r + x / r) >> 1;
				r = (r + x / r) >> 1; // Seven iterations should be enough
				uint256 r1 = x / r;
				return uint128(r < r1 ? r : r1);
			}
		}
	}
}

contracts/legacy/governance/libraries/TransferHelper.sol

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.19;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

library TransferHelper {
	/// @notice Transfers tokens from the targeted address to the given destination
	/// @notice Errors with 'STF' if transfer fails
	/// @param token The contract address of the token to be transferred
	/// @param from The originating address from which the tokens will be transferred
	/// @param to The destination address of the transfer
	/// @param value The amount to be transferred
	function safeTransferFrom(address token, address from, address to, uint256 value) internal {
		(bool success, bytes memory data) = token.call(
			abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value)
		);
		require(success && (data.length == 0 || abi.decode(data, (bool))), "STF");
	}

	/// @notice Transfers tokens from msg.sender to a recipient
	/// @dev Errors with ST if transfer fails
	/// @param token The contract address of the token which will be transferred
	/// @param to The recipient of the transfer
	/// @param value The value of the transfer
	function safeTransfer(address token, address to, uint256 value) internal {
		(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
		require(success && (data.length == 0 || abi.decode(data, (bool))), "ST");
	}

	/// @notice Approves the stipulated contract to spend the given allowance in the given token
	/// @dev Errors with 'SA' if transfer fails
	/// @param token The contract address of the token to be approved
	/// @param to The target of the approval
	/// @param value The amount of the given token the target will be allowed to spend
	function safeApprove(address token, address to, uint256 value) internal {
		(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
		require(success && (data.length == 0 || abi.decode(data, (bool))), "SA");
	}

	/// @notice Transfers ETH to the recipient address
	/// @dev Fails with `STE`
	/// @param to The destination of the transfer
	/// @param value The value to be transferred
	function safeTransferETH(address to, uint256 value) internal {
		(bool success, ) = to.call{value: value}(new bytes(0));
		require(success, "STE");
	}
}

contracts/legacy/governance/veORNStorage.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import "./interfaces/IveORN.sol";

contract veORNStorage {
	uint256 internal totalSupplyT0;
	address public smartVote;

	mapping(address => IveORN.UserInfo) public tokenMap;

	bool public isAirdropPassed;
	mapping(address => bool) public dropLockUsers;
	uint256 internal totalSupplyDropLockUsersT0;

	address public admin;

	uint256[50] private __gap;
}
Compiler settingsShow
{
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.