Source Code
Latest 17 from a total of 17 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Increase Lock Po... | 9051928 | 385 days ago | IN | 0 GLMR | 0.037149 | ||||
| Withdraw | 8806728 | 403 days ago | IN | 0 GLMR | 0.02199 | ||||
| Increase Lock Po... | 8461513 | 428 days ago | IN | 0 GLMR | 0.031842 | ||||
| Increase Lock Po... | 7875940 | 469 days ago | IN | 0 GLMR | 0.037149 | ||||
| Increase Lock Po... | 7618198 | 487 days ago | IN | 0 GLMR | 0.024272 | ||||
| Increase Lock Po... | 7447300 | 499 days ago | IN | 0 GLMR | 0.031842 | ||||
| Increase Lock Po... | 6732117 | 550 days ago | IN | 0 GLMR | 0.0254736 | ||||
| Increase Lock Po... | 6732109 | 550 days ago | IN | 0 GLMR | 0.0382104 | ||||
| Increase Lock Po... | 6662346 | 554 days ago | IN | 0 GLMR | 0.01038109 | ||||
| Increase Lock Po... | 6653331 | 555 days ago | IN | 0 GLMR | 0.02139782 | ||||
| Increase Lock Po... | 6652493 | 555 days ago | IN | 0 GLMR | 0.031842 | ||||
| Increase Lock Po... | 6527387 | 569 days ago | IN | 0 GLMR | 0.021228 | ||||
| Increase Lock Po... | 6515245 | 570 days ago | IN | 0 GLMR | 0.02685342 | ||||
| Increase Lock Po... | 6510046 | 571 days ago | IN | 0 GLMR | 0.026535 | ||||
| Claim Ownership | 6479334 | 575 days ago | IN | 0 GLMR | 0.00411787 | ||||
| Increase Lock Po... | 6464236 | 578 days ago | IN | 0 GLMR | 0.037149 | ||||
| Transfer Ownersh... | 6458993 | 578 days ago | IN | 0 GLMR | 0.00364975 |
View more zero value Internal Transactions in Advanced View mode
Cross-Chain Transactions
Loading...
Loading
Contract Name:
VotingEscrowZenlinkMainchain
Compiler Version
v0.8.24+commit.e11b9ed9
Optimization Enabled:
Yes with 800 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import {Checkpoints, Checkpoint} from "../libraries/VeHistoryLib.sol";
import {VeBalanceLib, VeBalance, LockedPosition} from "../libraries/VeBalanceLib.sol";
import {WeekMath} from "../libraries/WeekMath.sol";
import {MiniHelpers} from "../../core/libraries/MiniHelpers.sol";
import {Errors} from "../../core/libraries/Errors.sol";
import {VotingEscrowTokenBase} from "./VotingEscrowTokenBase.sol";
import {BoringOwnableUpgradeable} from "../../core/libraries/BoringOwnableUpgradeable.sol";
import {IPVotingEscrowMainchain} from "../../interfaces/IPVotingEscrowMainchain.sol";
import {IPVeToken} from "../../interfaces/IPVeToken.sol";
contract VotingEscrowZenlinkMainchain is VotingEscrowTokenBase, IPVotingEscrowMainchain, BoringOwnableUpgradeable {
using SafeERC20 for IERC20;
using VeBalanceLib for VeBalance;
using VeBalanceLib for LockedPosition;
using Checkpoints for Checkpoints.History;
using EnumerableMap for EnumerableMap.UintToAddressMap;
bytes private constant EMPTY_BYTES = abi.encode();
bytes private constant SAMPLE_SUPPLY_UPDATE_MESSAGE = abi.encode(0, VeBalance(0, 0), EMPTY_BYTES);
bytes private constant SAMPLE_POSITION_UPDATE_MESSAGE =
abi.encode(0, VeBalance(0, 0), abi.encode(address(0), LockedPosition(0, 0)));
IERC20 public immutable ZLK;
uint128 public lastSlopeChangeAppliedAt;
// [wTime] => slopeChanges
mapping(uint128 => uint128) public slopeChanges;
// Saving totalSupply checkpoint for each week, later can be used for reward accounting
// [wTime] => totalSupply
mapping(uint128 => uint128) public totalSupplyAt;
// Saving VeBalance checkpoint for users of each week, can later use binary search
// to ask for their veZLK balance at any wTime
mapping(address => Checkpoints.History) internal userHistory;
constructor(IERC20 _ZLK) initializer {
ZLK = _ZLK;
lastSlopeChangeAppliedAt = WeekMath.getCurrentWeekStart();
__BoringOwnable_init();
}
/**
* @notice increases the lock position of a user (amount and/or expiry). Applicable even when
* user has no position or the current position has expired.
* @param additionalAmountToLock zlk amount to be pulled in from user to lock.
* @param newExpiry new lock expiry. Must be a valid week beginning, and resulting lock
* duration (since `block.timestamp`) must be within the allowed range.
* @dev Will revert if resulting position has zero lock amount.
* @dev See `_increasePosition()` for details on inner workings.
* @dev Sidechain broadcasting is not bundled since it can be done anytime after.
*/
function increaseLockPosition(uint128 additionalAmountToLock, uint128 newExpiry)
public
returns (uint128 newVeBalance)
{
address user = msg.sender;
if (!WeekMath.isValidWTime(newExpiry)) revert Errors.InvalidWTime(newExpiry);
if (MiniHelpers.isTimeInThePast(newExpiry)) revert Errors.ExpiryInThePast(newExpiry);
if (newExpiry < positionData[user].expiry) revert Errors.VENotAllowedReduceExpiry();
if (newExpiry > block.timestamp + MAX_LOCK_TIME) revert Errors.VEExceededMaxLockTime();
if (newExpiry < block.timestamp + MIN_LOCK_TIME) revert Errors.VEInsufficientLockTime();
uint128 newTotalAmountLocked = additionalAmountToLock + positionData[user].amount;
if (newTotalAmountLocked == 0) revert Errors.VEZeroAmountLocked();
uint128 additionalDurationToLock = newExpiry - positionData[user].expiry;
if (additionalAmountToLock > 0) {
ZLK.safeTransferFrom(user, address(this), additionalAmountToLock);
}
newVeBalance = _increasePosition(user, additionalAmountToLock, additionalDurationToLock);
emit NewLockPosition(user, newTotalAmountLocked, newExpiry);
}
/**
* @notice Withdraws an expired lock position, returns locked ZLK back to user
* @dev reverts if position is not expired, or if no locked ZLK to withdraw
* @dev broadcast is not bundled since it can be done anytime after
*/
function withdraw() external returns (uint128 amount) {
address user = msg.sender;
if (!_isPositionExpired(user)) revert Errors.VEPositionNotExpired();
amount = positionData[user].amount;
if (amount == 0) revert Errors.VEZeroPosition();
delete positionData[user];
ZLK.safeTransfer(user, amount);
emit Withdraw(user, amount);
}
/**
* @notice update & return the current totalSupply, but does not broadcast info to other chains
* @dev See `broadcastTotalSupply()` and `broadcastUserPosition()` for broadcasting
*/
function totalSupplyCurrent() public virtual override(IPVeToken, VotingEscrowTokenBase) returns (uint128) {
(VeBalance memory supply,) = _applySlopeChange();
return supply.getCurrentValue();
}
function getUserHistoryLength(address user) external view returns (uint256) {
return userHistory[user].length();
}
function getUserHistoryAt(address user, uint256 index) external view returns (Checkpoint memory) {
return userHistory[user].get(index);
}
/**
* @notice increase the locking position of the user
* @dev works by simply removing the old position from all relevant data (as if the user has
* never locked) and then add in the new position
*/
function _increasePosition(address user, uint128 amountToIncrease, uint128 durationToIncrease)
internal
returns (uint128)
{
LockedPosition memory oldPosition = positionData[user];
(VeBalance memory newSupply,) = _applySlopeChange();
if (!MiniHelpers.isCurrentlyExpired(oldPosition.expiry)) {
// remove old position not yet expired
VeBalance memory oldBalance = oldPosition.convertToVeBalance();
newSupply = newSupply.sub(oldBalance);
slopeChanges[oldPosition.expiry] -= oldBalance.slope;
}
LockedPosition memory newPosition =
LockedPosition(oldPosition.amount + amountToIncrease, oldPosition.expiry + durationToIncrease);
VeBalance memory newBalance = newPosition.convertToVeBalance();
// add new position
newSupply = newSupply.add(newBalance);
slopeChanges[newPosition.expiry] += newBalance.slope;
_totalSupply = newSupply;
positionData[user] = newPosition;
userHistory[user].push(newBalance);
return newBalance.getCurrentValue();
}
/**
* @notice updates the totalSupply, processing all slope changes of past weeks. At the same time,
* set the finalized totalSupplyAt
*/
function _applySlopeChange() internal returns (VeBalance memory, uint128) {
VeBalance memory supply = _totalSupply;
uint128 wTime = lastSlopeChangeAppliedAt;
uint128 currentWeekStart = WeekMath.getCurrentWeekStart();
if (wTime >= currentWeekStart) {
return (supply, wTime);
}
while (wTime < currentWeekStart) {
wTime += WEEK;
supply = supply.sub(slopeChanges[wTime], wTime);
totalSupplyAt[wTime] = supply.getValueAt(wTime);
}
_totalSupply = supply;
lastSlopeChangeAppliedAt = wTime;
return (supply, wTime);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableMap.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableMap.js.
pragma solidity ^0.8.0;
import "./EnumerableSet.sol";
/**
* @dev Library for managing an enumerable variant of Solidity's
* https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
* type.
*
* Maps have the following properties:
*
* - Entries are added, removed, and checked for existence in constant time
* (O(1)).
* - Entries are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableMap for EnumerableMap.UintToAddressMap;
*
* // Declare a set state variable
* EnumerableMap.UintToAddressMap private myMap;
* }
* ```
*
* The following map types are supported:
*
* - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
* - `address -> uint256` (`AddressToUintMap`) since v4.6.0
* - `bytes32 -> bytes32` (`Bytes32ToBytes32Map`) since v4.6.0
* - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0
* - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableMap.
* ====
*/
library EnumerableMap {
using EnumerableSet for EnumerableSet.Bytes32Set;
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Map type with
// bytes32 keys and values.
// The Map implementation uses private functions, and user-facing
// implementations (such as Uint256ToAddressMap) are just wrappers around
// the underlying Map.
// This means that we can only create new EnumerableMaps for types that fit
// in bytes32.
struct Bytes32ToBytes32Map {
// Storage of keys
EnumerableSet.Bytes32Set _keys;
mapping(bytes32 => bytes32) _values;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(Bytes32ToBytes32Map storage map, bytes32 key, bytes32 value) internal returns (bool) {
map._values[key] = value;
return map._keys.add(key);
}
/**
* @dev Removes a key-value pair from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {
delete map._values[key];
return map._keys.remove(key);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {
return map._keys.contains(key);
}
/**
* @dev Returns the number of key-value pairs in the map. O(1).
*/
function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {
return map._keys.length();
}
/**
* @dev Returns the key-value pair stored at position `index` in the map. O(1).
*
* Note that there are no guarantees on the ordering of entries inside the
* array, and it may change when more entries are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32, bytes32) {
bytes32 key = map._keys.at(index);
return (key, map._values[key]);
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool, bytes32) {
bytes32 value = map._values[key];
if (value == bytes32(0)) {
return (contains(map, key), bytes32(0));
} else {
return (true, value);
}
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {
bytes32 value = map._values[key];
require(value != 0 || contains(map, key), "EnumerableMap: nonexistent key");
return value;
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
Bytes32ToBytes32Map storage map,
bytes32 key,
string memory errorMessage
) internal view returns (bytes32) {
bytes32 value = map._values[key];
require(value != 0 || contains(map, key), errorMessage);
return value;
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(Bytes32ToBytes32Map storage map) internal view returns (bytes32[] memory) {
return map._keys.values();
}
// UintToUintMap
struct UintToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToUintMap storage map, uint256 key, uint256 value) internal returns (bool) {
return set(map._inner, bytes32(key), bytes32(value));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToUintMap storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToUintMap storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToUintMap storage map, uint256 index) internal view returns (uint256, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (uint256(key), uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(key)));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(UintToUintMap storage map, uint256 key, string memory errorMessage) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(key), errorMessage));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(UintToUintMap storage map) internal view returns (uint256[] memory) {
bytes32[] memory store = keys(map._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintToAddressMap
struct UintToAddressMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToAddressMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (uint256(key), address(uint160(uint256(value))));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
return (success, address(uint160(uint256(value))));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
return address(uint160(uint256(get(map._inner, bytes32(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
UintToAddressMap storage map,
uint256 key,
string memory errorMessage
) internal view returns (address) {
return address(uint160(uint256(get(map._inner, bytes32(key), errorMessage))));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(UintToAddressMap storage map) internal view returns (uint256[] memory) {
bytes32[] memory store = keys(map._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressToUintMap
struct AddressToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(AddressToUintMap storage map, address key, uint256 value) internal returns (bool) {
return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(AddressToUintMap storage map, address key) internal returns (bool) {
return remove(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(AddressToUintMap storage map, address key) internal view returns (bool) {
return contains(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(AddressToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressToUintMap storage map, uint256 index) internal view returns (address, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (address(uint160(uint256(key))), uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(AddressToUintMap storage map, address key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(uint256(uint160(key))));
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(uint256(uint160(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
AddressToUintMap storage map,
address key,
string memory errorMessage
) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(uint256(uint160(key))), errorMessage));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(AddressToUintMap storage map) internal view returns (address[] memory) {
bytes32[] memory store = keys(map._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// Bytes32ToUintMap
struct Bytes32ToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(Bytes32ToUintMap storage map, bytes32 key, uint256 value) internal returns (bool) {
return set(map._inner, key, bytes32(value));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(Bytes32ToUintMap storage map, bytes32 key) internal returns (bool) {
return remove(map._inner, key);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool) {
return contains(map._inner, key);
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(Bytes32ToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32ToUintMap storage map, uint256 index) internal view returns (bytes32, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (key, uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, key);
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(Bytes32ToUintMap storage map, bytes32 key) internal view returns (uint256) {
return uint256(get(map._inner, key));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
Bytes32ToUintMap storage map,
bytes32 key,
string memory errorMessage
) internal view returns (uint256) {
return uint256(get(map._inner, key, errorMessage));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(Bytes32ToUintMap storage map) internal view returns (bytes32[] memory) {
bytes32[] memory store = keys(map._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
// Forked from OpenZeppelin (v4.5.0) (utils/Checkpoints.sol)
pragma solidity ^0.8.24;
import {PMath} from "../../core/libraries/math/PMath.sol";
import {VeBalance} from "./VeBalanceLib.sol";
import {WeekMath} from "./WeekMath.sol";
struct Checkpoint {
uint128 timestamp;
VeBalance value;
}
library CheckpointHelper {
function assignWith(Checkpoint memory a, Checkpoint memory b) internal pure {
a.timestamp = b.timestamp;
a.value = b.value;
}
}
library Checkpoints {
struct History {
Checkpoint[] _checkpoints;
}
function length(History storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
function get(History storage self, uint256 index) internal view returns (Checkpoint memory) {
return self._checkpoints[index];
}
function push(History storage self, VeBalance memory value) internal {
uint256 pos = self._checkpoints.length;
if (pos > 0 && self._checkpoints[pos - 1].timestamp == WeekMath.getCurrentWeekStart()) {
self._checkpoints[pos - 1].value = value;
} else {
self._checkpoints.push(Checkpoint({timestamp: WeekMath.getCurrentWeekStart(), value: value}));
}
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
import {PMath} from "../../core/libraries/math/PMath.sol";
import {Errors} from "../../core/libraries/Errors.sol";
struct VeBalance {
uint128 bias;
uint128 slope;
}
struct LockedPosition {
uint128 amount;
uint128 expiry;
}
library VeBalanceLib {
using PMath for uint256;
uint128 internal constant MAX_LOCK_TIME = 104 weeks;
uint256 internal constant USER_VOTE_MAX_WEIGHT = 10 ** 18;
function add(VeBalance memory a, VeBalance memory b) internal pure returns (VeBalance memory res) {
res.bias = a.bias + b.bias;
res.slope = a.slope + b.slope;
}
function sub(VeBalance memory a, VeBalance memory b) internal pure returns (VeBalance memory res) {
res.bias = a.bias - b.bias;
res.slope = a.slope - b.slope;
}
function sub(VeBalance memory a, uint128 slope, uint128 expiry) internal pure returns (VeBalance memory res) {
res.slope = a.slope - slope;
res.bias = a.bias - slope * expiry;
}
function isExpired(VeBalance memory a) internal view returns (bool) {
return a.slope * uint128(block.timestamp) >= a.bias;
}
function getCurrentValue(VeBalance memory a) internal view returns (uint128) {
if (isExpired(a)) return 0;
return getValueAt(a, uint128(block.timestamp));
}
function getValueAt(VeBalance memory a, uint128 t) internal pure returns (uint128) {
if (a.slope * t > a.bias) {
return 0;
}
return a.bias - a.slope * t;
}
function getExpiry(VeBalance memory a) internal pure returns (uint128) {
if (a.slope == 0) revert Errors.VEZeroSlope(a.bias, a.slope);
return a.bias / a.slope;
}
function convertToVeBalance(LockedPosition memory position) internal pure returns (VeBalance memory res) {
res.slope = position.amount / MAX_LOCK_TIME;
res.bias = res.slope * position.expiry;
}
function convertToVeBalance(LockedPosition memory position, uint256 weight)
internal
pure
returns (VeBalance memory res)
{
res.slope = ((position.amount * weight) / MAX_LOCK_TIME / USER_VOTE_MAX_WEIGHT).Uint128();
res.bias = res.slope * position.expiry;
}
function convertToVeBalance(uint128 amount, uint128 expiry) internal pure returns (uint128, uint128) {
VeBalance memory balance = convertToVeBalance(LockedPosition(amount, expiry));
return (balance.bias, balance.slope);
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
library WeekMath {
uint128 internal constant WEEK = 7 days;
function getWeekStartTimestamp(uint128 timestamp) internal pure returns (uint128) {
return (timestamp / WEEK) * WEEK;
}
function getCurrentWeekStart() internal view returns (uint128) {
return getWeekStartTimestamp(uint128(block.timestamp));
}
function isValidWTime(uint256 time) internal pure returns (bool) {
return time % WEEK == 0;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
library MiniHelpers {
function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {
return (expiry <= block.timestamp);
}
function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {
return (expiry <= blockTime);
}
function isTimeInThePast(uint256 timestamp) internal view returns (bool) {
return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
library Errors {
// BulkSeller
error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);
error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);
error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);
error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);
error BulkNotMaintainer();
error BulkNotAdmin();
error BulkSellerAlreadyExisted(address token, address SY, address bulk);
error BulkSellerInvalidToken(address token, address SY);
error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);
error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);
// APPROX
error ApproxFail();
error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);
error ApproxBinarySearchInputInvalid(
uint256 approxGuessMin, uint256 approxGuessMax, uint256 minGuessMin, uint256 maxGuessMax
);
// MARKET + MARKET MATH CORE
error MarketExpired();
error MarketZeroAmountsInput();
error MarketZeroAmountsOutput();
error MarketZeroLnImpliedRate();
error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);
error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);
error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);
error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);
error MarketExchangeRateBelowOne(int256 exchangeRate);
error MarketProportionMustNotEqualOne();
error MarketRateScalarBelowZero(int256 rateScalar);
error MarketScalarRootBelowZero(int256 scalarRoot);
error MarketProportionTooHigh(int256 proportion, int256 maxProportion);
error OracleUninitialized();
error OracleTargetTooOld(uint32 target, uint32 oldest);
error OracleZeroCardinality();
error MarketFactoryExpiredPt();
error MarketFactoryInvalidPt();
error MarketFactoryMarketExists();
error MarketFactoryGaugeControllerExists();
error MarketFactoryGaugeControllerNotSet();
error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);
error MarketFactoryOverriddenFeeTooHigh(uint80 overriddenFee, uint256 marketLnFeeRateRoot);
error MarketFactoryReserveFeePercentTooHigh(uint8 reserveFeePercent, uint8 maxReserveFeePercent);
error MarketFactoryZeroTreasury();
error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);
error MFNotZenlinkMarket(address addr);
// ROUTER
error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);
error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);
error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);
error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);
error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);
error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);
error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);
error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);
error RouterTimeRangeZero();
error RouterCallbackNotZenlinkMarket(address caller);
error RouterInvalidAction(bytes4 selector);
error RouterInvalidFacet(address facet);
error RouterKyberSwapDataZero();
error SimulationResults(bool success, bytes res);
// YIELD CONTRACT
error YCExpired();
error YCNotExpired();
error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);
error YCNothingToRedeem();
error YCPostExpiryDataNotSet();
error YCNoFloatingSy();
// YieldFactory
error YCFactoryInvalidExpiry();
error YCFactoryYieldContractExisted();
error YCFactoryZeroExpiryDivisor();
error YCFactoryZeroTreasury();
error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);
error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);
// SY
error SYInvalidTokenIn(address token);
error SYInvalidTokenOut(address token);
error SYZeroDeposit();
error SYZeroRedeem();
error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);
error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
// SY-specific
error SYQiTokenMintFailed(uint256 errCode);
error SYQiTokenRedeemFailed(uint256 errCode);
error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);
error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);
error SYCurveInvalidPid();
error SYCurve3crvPoolNotFound();
error SYApeDepositAmountTooSmall(uint256 amountDeposited);
error SYBalancerInvalidPid();
error SYInvalidRewardToken(address token);
error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);
error SYBalancerReentrancy();
error NotFromTrustedRemote(uint16 srcChainId, bytes path);
error ApxETHNotEnoughBuffer();
// Liquidity Mining
error VCInactivePool(address pool);
error VCPoolAlreadyActive(address pool);
error VCZeroVeZenlink(address user);
error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);
error VCEpochNotFinalized(uint256 wTime);
error VCPoolAlreadyAddAndRemoved(address pool);
error VEInvalidNewExpiry(uint256 newExpiry);
error VEExceededMaxLockTime();
error VEInsufficientLockTime();
error VENotAllowedReduceExpiry();
error VEZeroAmountLocked();
error VEPositionNotExpired();
error VEZeroPosition();
error VEZeroSlope(uint128 bias, uint128 slope);
error VEReceiveOldSupply(uint256 msgTime);
error GCNotZenlinkMarket(address caller);
error GCNotVotingController(address caller);
error InvalidWTime(uint256 wTime);
error ExpiryInThePast(uint256 expiry);
error ChainNotSupported(uint256 chainId);
error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);
error FDEpochLengthMismatch();
error FDInvalidPool(address pool);
error FDPoolAlreadyExists(address pool);
error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);
error FDInvalidStartEpoch(uint256 startEpoch);
error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);
error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);
error BDInvalidEpoch(uint256 epoch, uint256 startTime);
// Cross-Chain
error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);
error MsgNotFromReceiveEndpoint(address sender);
error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);
error ApproxDstExecutionGasNotSet();
error InvalidRetryData();
// GENERIC MSG
error ArrayLengthMismatch();
error ArrayEmpty();
error ArrayOutOfBounds();
error ZeroAddress();
error FailedToSendEther();
error InvalidMerkleProof();
error OnlyLayerZeroEndpoint();
error OnlyYT();
error OnlyYCFactory();
error OnlyWhitelisted();
// Swap Aggregator
error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);
error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
import {MiniHelpers} from "../../core/libraries/MiniHelpers.sol";
import {VeBalanceLib, VeBalance, LockedPosition} from "../libraries/VeBalanceLib.sol";
import {WeekMath} from "../libraries/WeekMath.sol";
import {IPVeToken} from "../../interfaces/IPVeToken.sol";
/**
* @dev this contract is an abstract for its mainchain and sidechain variant
* PRINCIPLE:
* - All functions implemented in this contract should be either view or pure
* to ensure that no writing logic is inherited by sidechain version
* - Mainchain version will handle the logic which are:
* + Deposit, withdraw, increase lock, increase amount
* + Mainchain logic will be ensured to have _totalSupply = linear sum of
* all users' veBalance such that their locks are not yet expired
* + Mainchain contract reserves 100% the right to write on sidechain
* + No other transaction is allowed to write on sidechain storage
*/
abstract contract VotingEscrowTokenBase is IPVeToken {
using VeBalanceLib for VeBalance;
using VeBalanceLib for LockedPosition;
uint128 public constant WEEK = 1 weeks;
uint128 public constant MAX_LOCK_TIME = 104 weeks;
uint128 public constant MIN_LOCK_TIME = 1 weeks;
VeBalance internal _totalSupply;
mapping(address => LockedPosition) public positionData;
constructor() {}
function balanceOf(address user) public view virtual returns (uint128) {
return positionData[user].convertToVeBalance().getCurrentValue();
}
function totalSupplyStored() public view virtual returns (uint128) {
return _totalSupply.getCurrentValue();
}
function totalSupplyCurrent() public virtual returns (uint128);
function _isPositionExpired(address user) internal view returns (bool) {
return MiniHelpers.isCurrentlyExpired(positionData[user].expiry);
}
function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128) {
return (totalSupplyCurrent(), balanceOf(user));
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
import {Initializable} from "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol";
contract BoringOwnableUpgradeableData {
address public owner;
address public pendingOwner;
}
abstract contract BoringOwnableUpgradeable is BoringOwnableUpgradeableData, Initializable {
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function __BoringOwnable_init() internal onlyInitializing {
owner = msg.sender;
}
/// @notice Transfers ownership to `newOwner`. Either directly or claimable by the new pending owner.
/// Can only be invoked by the current `owner`.
/// @param newOwner Address of the new owner.
/// @param direct True if `newOwner` should be set immediately. False if `newOwner` needs to use `claimOwnership`.
/// @param renounce Allows the `newOwner` to be `address(0)` if `direct` and `renounce` is True. Has no effect otherwise.
function transferOwnership(address newOwner, bool direct, bool renounce) public onlyOwner {
if (direct) {
// Checks
require(newOwner != address(0) || renounce, "Ownable: zero address");
// Effects
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
pendingOwner = address(0);
} else {
// Effects
pendingOwner = newOwner;
}
}
/// @notice Needs to be called by `pendingOwner` to claim ownership.
function claimOwnership() public {
address _pendingOwner = pendingOwner;
// Checks
require(msg.sender == _pendingOwner, "Ownable: caller != pending owner");
// Effects
emit OwnershipTransferred(owner, _pendingOwner);
owner = _pendingOwner;
pendingOwner = address(0);
}
/// @notice Only allows the `owner` to execute the function.
modifier onlyOwner() {
require(msg.sender == owner, "Ownable: caller is not the owner");
_;
}
uint256[48] private __gap;
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
import {IPVeToken} from "./IPVeToken.sol";
import {VeBalance} from "../LiquidityMining/libraries/VeBalanceLib.sol";
import {Checkpoint} from "../LiquidityMining/libraries/VeHistoryLib.sol";
interface IPVotingEscrowMainchain is IPVeToken {
event NewLockPosition(address indexed user, uint128 amount, uint128 expiry);
event Withdraw(address indexed user, uint128 amount);
event BroadcastTotalSupply(VeBalance newTotalSupply, uint256[] chainIds);
event BroadcastUserPosition(address indexed user, uint256[] chainIds);
// ============= ACTIONS =============
function increaseLockPosition(uint128 additionalAmountToLock, uint128 expiry) external returns (uint128);
function withdraw() external returns (uint128);
function totalSupplyAt(uint128 timestamp) external view returns (uint128);
function getUserHistoryLength(address user) external view returns (uint256);
function getUserHistoryAt(address user, uint256 index) external view returns (Checkpoint memory);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
interface IPVeToken {
// ============= USER INFO =============
function balanceOf(address user) external view returns (uint128);
function positionData(address user) external view returns (uint128 amount, uint128 expiry);
// ============= META DATA =============
function totalSupplyStored() external view returns (uint128);
function totalSupplyCurrent() external returns (uint128);
function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.8.24;
library PMath {
uint256 internal constant ONE = 1e18; // 18 decimal places
int256 internal constant IONE = 1e18; // 18 decimal places
function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
return (a >= b ? a - b : 0);
}
}
function subNoNeg(int256 a, int256 b) internal pure returns (int256) {
require(a >= b, "negative");
return a - b; // no unchecked since if b is very negative, a - b might overflow
}
function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 product = a * b;
unchecked {
return product / ONE;
}
}
function mulDown(int256 a, int256 b) internal pure returns (int256) {
int256 product = a * b;
unchecked {
return product / IONE;
}
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 aInflated = a * ONE;
unchecked {
return aInflated / b;
}
}
function divDown(int256 a, int256 b) internal pure returns (int256) {
int256 aInflated = a * IONE;
unchecked {
return aInflated / b;
}
}
function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
return (a + b - 1) / b;
}
// @author Uniswap
function sqrt(uint256 y) internal pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
function square(uint256 x) internal pure returns (uint256) {
return x * x;
}
function squareDown(uint256 x) internal pure returns (uint256) {
return mulDown(x, x);
}
function abs(int256 x) internal pure returns (uint256) {
return uint256(x > 0 ? x : -x);
}
function neg(int256 x) internal pure returns (int256) {
return x * (-1);
}
function neg(uint256 x) internal pure returns (int256) {
return Int(x) * (-1);
}
function max(uint256 x, uint256 y) internal pure returns (uint256) {
return (x > y ? x : y);
}
function max(int256 x, int256 y) internal pure returns (int256) {
return (x > y ? x : y);
}
function min(uint256 x, uint256 y) internal pure returns (uint256) {
return (x < y ? x : y);
}
function min(int256 x, int256 y) internal pure returns (int256) {
return (x < y ? x : y);
}
/*///////////////////////////////////////////////////////////////
SIGNED CASTS
//////////////////////////////////////////////////////////////*/
function Int(uint256 x) internal pure returns (int256) {
require(x <= uint256(type(int256).max));
return int256(x);
}
function Int128(int256 x) internal pure returns (int128) {
require(type(int128).min <= x && x <= type(int128).max);
return int128(x);
}
function Int128(uint256 x) internal pure returns (int128) {
return Int128(Int(x));
}
/*///////////////////////////////////////////////////////////////
UNSIGNED CASTS
//////////////////////////////////////////////////////////////*/
function Uint(int256 x) internal pure returns (uint256) {
require(x >= 0);
return uint256(x);
}
function Uint32(uint256 x) internal pure returns (uint32) {
require(x <= type(uint32).max);
return uint32(x);
}
function Uint64(uint256 x) internal pure returns (uint64) {
require(x <= type(uint64).max);
return uint64(x);
}
function Uint112(uint256 x) internal pure returns (uint112) {
require(x <= type(uint112).max);
return uint112(x);
}
function Uint96(uint256 x) internal pure returns (uint96) {
require(x <= type(uint96).max);
return uint96(x);
}
function Uint128(uint256 x) internal pure returns (uint128) {
require(x <= type(uint128).max);
return uint128(x);
}
function Uint192(uint256 x) internal pure returns (uint192) {
require(x <= type(uint192).max);
return uint192(x);
}
function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);
}
function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return a >= b && a <= mulDown(b, ONE + eps);
}
function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return a <= b && a >= mulDown(b, ONE - eps);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev 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.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
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.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
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.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}{
"remappings": [
"@openzeppelin/=lib/openzeppelin-contracts/",
"@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/"
],
"optimizer": {
"enabled": true,
"runs": 800
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": true,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IERC20","name":"_ZLK","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"expiry","type":"uint256"}],"name":"ExpiryInThePast","type":"error"},{"inputs":[{"internalType":"uint256","name":"wTime","type":"uint256"}],"name":"InvalidWTime","type":"error"},{"inputs":[],"name":"VEExceededMaxLockTime","type":"error"},{"inputs":[],"name":"VEInsufficientLockTime","type":"error"},{"inputs":[],"name":"VENotAllowedReduceExpiry","type":"error"},{"inputs":[],"name":"VEPositionNotExpired","type":"error"},{"inputs":[],"name":"VEZeroAmountLocked","type":"error"},{"inputs":[],"name":"VEZeroPosition","type":"error"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint128","name":"bias","type":"uint128"},{"internalType":"uint128","name":"slope","type":"uint128"}],"indexed":false,"internalType":"struct VeBalance","name":"newTotalSupply","type":"tuple"},{"indexed":false,"internalType":"uint256[]","name":"chainIds","type":"uint256[]"}],"name":"BroadcastTotalSupply","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"chainIds","type":"uint256[]"}],"name":"BroadcastUserPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"expiry","type":"uint128"}],"name":"NewLockPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"MAX_LOCK_TIME","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_LOCK_TIME","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WEEK","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ZLK","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getUserHistoryAt","outputs":[{"components":[{"internalType":"uint128","name":"timestamp","type":"uint128"},{"components":[{"internalType":"uint128","name":"bias","type":"uint128"},{"internalType":"uint128","name":"slope","type":"uint128"}],"internalType":"struct VeBalance","name":"value","type":"tuple"}],"internalType":"struct Checkpoint","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserHistoryLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"additionalAmountToLock","type":"uint128"},{"internalType":"uint128","name":"newExpiry","type":"uint128"}],"name":"increaseLockPosition","outputs":[{"internalType":"uint128","name":"newVeBalance","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastSlopeChangeAppliedAt","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"positionData","outputs":[{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"expiry","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"","type":"uint128"}],"name":"slopeChanges","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalSupplyAndBalanceCurrent","outputs":[{"internalType":"uint128","name":"","type":"uint128"},{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"","type":"uint128"}],"name":"totalSupplyAt","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupplyCurrent","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalSupplyStored","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"},{"internalType":"bool","name":"direct","type":"bool"},{"internalType":"bool","name":"renounce","type":"bool"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[{"internalType":"uint128","name":"amount","type":"uint128"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60a0346200026557601f6200168138819003918201601f19168301916001600160401b038311848410176200026a578084926020946040528339810103126200026557516001600160a01b038116810362000265576003549060ff8260a81c16159182809362000254575b801562000238575b15620001dc5760ff60a01b198116600160a01b1760035582620001c3575b5060805262093a806001600160801b034281168290048116909102908116908103620001ad5760018060801b031960345416176034556003549060ff8260a81c16156200015457600280546001600160a01b0319163317905562000116575b60405161140090816200028182396080518181816107c601528181610ac20152610b790152f35b60ff60a81b1916600355604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602090a138620000ef565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b634e487b7160e01b600052601160045260246000fd5b61ffff60a01b191661010160a01b176003553862000090565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b50303b158015620000725750600160ff8260a01c161462000072565b50600160ff8260a01c16106200006a565b600080fd5b634e487b7160e01b600052604160045260246000fdfe608060408181526004918236101561001657600080fd5b600092833560e01c918263078dfbe714610c245750816330d981af14610bfc5781633ccfd60b14610ae65781633ff03207146101585781634502495014610aa25781634e71e0c8146109df57816370a082311461099a5781637c386c7114610903578163814b2cac146108db5781638da5cb5b146108b3578163947975d914610879578163c8121ec2146102c757508063cb6b4f3c14610270578063d88e92a914610237578063e268b3a4146101b8578063e30c397814610191578063ef1c243a1461015d578063f4359ce514610158578063fa78668f1461013a5763fc367c611461010157600080fd5b3461013657602036600319011261013657806020926001600160a01b03610126610d9e565b1681526037845220549051908152f35b5080fd5b5034610136578160031936011261013657602090516303bfc4008152f35b610db9565b50346101365781600319360112610136576020906001600160801b03610189610184610e1f565b61103e565b915191168152f35b50346101365781600319360112610136576020906001600160a01b03600354169051908152f35b5090346102345760203660031901126102345761023061020e610184610209856101e0610d9e565b956001600160a01b036101fa6101f4610ee2565b5061103e565b97168152600160205220610e45565b6110b5565b92516001600160801b0392831681529190921660208201529081906040820190565b0390f35b80fd5b503461013657602036600319011261013657602091816001600160801b03918261025f610dd7565b168152603585522054169051908152f35b50346101365760203660031901126101365780610230926001600160a01b03610297610d9e565b168152600160209081529190205491516001600160801b038316815260809290921c908201529081906040820190565b905082346102345782600319360112610234576102e2610dd7565b926024938435936001600160801b0393848616968787036101365762093a8091828906610864574289111561084f57338152600193602099858b528783205460801c8110610840576303bfc400420180421161081f578111610831578442019081421161081f571061081157338252848a5261036388888420541687610e98565b9588871615610802579187959493918b9333835286855261038a8884205460801c8d610ec9565b8b821680610771575b503384528786528b6103a68a8620610e45565b916103af610ee2565b50938493898d8183019742878a5116116106d8575b505050908380925116906103d791610e98565b945116906103e491610e98565b96818b51946103f286610ded565b1684528301961686528d8c80610407856110b5565b809c519461041486610ded565b88865282858181808a01948d865282808251168189511661043491610e98565b168b520151169301928184511661044a91610e98565b16905251169751168552603590528a84208c8154978189169061046c91610e98565b166001600160801b03198098161790556104a4906001600160801b038151169060206001600160801b031991015160801b1617600055565b338352868d52898320815160209092015160801b6fffffffffffffffffffffffffffffffff19166001600160801b039290921691909117905560378c528882209384549586151580610695575b156105b057505060001985019485116105a05750505092610184816105969461053e610572957fb1a3371956c54dc1d83695b4a006b051c8313ee986e533b6b964e77c9066fc2c986110fc565b50825160209093015160801b6fffffffffffffffffffffffffffffffff19166001600160801b039390931692909217910155565b84516001600160801b03948516815293909616602084015233929081906040820190565b0390a25191168152f35b634e487b7160e01b825260119052fd5b6105c4908c9897949295939842160461107a565b928b8b51946105d286610ded565b1684528d8401958987526801000000000000000082101561068357906105fc9188820181556110fc565b979097610674575050905185549092169189169190911784555051805160209091015160801b6fffffffffffffffffffffffffffffffff19166001600160801b0391909116179101557fb1a3371956c54dc1d83695b4a006b051c8313ee986e533b6b964e77c9066fc2c90610596906105729061103e565b634e487b7160e01b8252819052fd5b5050634e487b7160e01b815260418752fd5b5060001987018781116106c5576106ad8d91886110fc565b5054168c6106be838242160461107a565b16146104f1565b5050634e487b7160e01b83525060119052fd5b829750908684928c8280989796816106f081996110b5565b9d8e958289519761070089610ded565b878952838901978852818084511691511661071a91610ec9565b1687520151169c019b818d511661073091610ec9565b169052985116908d848b51168d52603590528b2090838254918183169061075691610ec9565b16906001600160801b03191617905591925050898d386103c4565b91939550919395969751908d6323b872dd60e01b90830152338783015230604483015260648201526064815260a0810181811067ffffffffffffffff8211176107f057916107ea8e9694928c9a999896948b527f0000000000000000000000000000000000000000000000000000000000000000611175565b8e610393565b634e487b7160e01b8652604185528686fd5b5086516323fbc14f60e11b8152fd5b8651630def6af560e21b8152fd5b5050634e487b7160e01b825260119052fd5b508651632739a01960e11b8152fd5b508651631f8b0c5960e21b8152fd5b50845163d928003560e01b8152808401899052fd5b508451637bf16ce960e11b8152808401899052fd5b50503461013657602036600319011261013657602091816001600160801b0391826108a2610dd7565b168152603685522054169051908152f35b5050346101365781600319360112610136576020906001600160a01b03600254169051908152f35b5050346101365781600319360112610136576020906001600160801b03603454169051908152f35b505034610136578060031936011261013657610950816060936001600160a01b0361092c610d9e565b610934610e6a565b50168152603760205220610946610e6a565b50602435906110fc565b509080519161095e83610ded565b602061097a60016001600160801b039384815416875201610e45565b818501908152828451955116855251828151168286015201511690820152f35b505034610136576020366003190112610136576001600160801b03610189610184610209846020966001600160a01b036109d2610d9e565b1681526001885220610e45565b91905034610a9e5782600319360112610a9e57600354906001600160a01b039283831691823303610a5b575050806002549384167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08680a373ffffffffffffffffffffffffffffffffffffffff19809316176002551660035580f35b906020606492519162461bcd60e51b8352820152602060248201527f4f776e61626c653a2063616c6c657220213d2070656e64696e67206f776e65726044820152fd5b8280fd5b505034610136578160031936011261013657602090516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b91905034610a9e5782600319360112610a9e573383526020926001845281812054429060801c11610bee57338152600184526001600160801b038282205416928315610be05733825260018552818381205582519163a9059cbb60e01b8684015233602484015284604484015260448352608083019183831067ffffffffffffffff841117610bcd5750508252610b9d907f0000000000000000000000000000000000000000000000000000000000000000611175565b80518281527f0e1bb0545c1ebb9fb680bde73514e572831de93b479c087ec1ef6c35c3a19fd6843392a251908152f35b634e487b7160e01b825260419052602490fd5b8251631e95654360e11b8152fd5b50516339ba104360e01b8152fd5b5050346101365781600319360112610136576020906001600160801b036101896101f4610ee2565b92915034610d9a576060366003190112610d9a57610c40610d9e565b91602435928315158403610d9657604435938415158503610d92576001600160a01b039586600254163303610d51575085919015610d2a571692831590811591610d22575b5015610cdf575050806002549283167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08580a373ffffffffffffffffffffffffffffffffffffffff19809216176002556003541660035580f35b906020606492519162461bcd60e51b8352820152601560248201527f4f776e61626c653a207a65726f206164647265737300000000000000000000006044820152fd5b905038610c85565b93505050501673ffffffffffffffffffffffffffffffffffffffff19600354161760035580f35b62461bcd60e51b8152602085820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606490fd5b8680fd5b8580fd5b8380fd5b600435906001600160a01b0382168203610db457565b600080fd5b34610db4576000366003190112610db457602060405162093a808152f35b600435906001600160801b0382168203610db457565b6040810190811067ffffffffffffffff821117610e0957604052565b634e487b7160e01b600052604160045260246000fd5b60405190610e2c82610ded565b6000546001600160801b038116835260801c6020830152565b90604051610e5281610ded565b91546001600160801b038116835260801c6020830152565b60405190610e7782610ded565b60008252604051602083610e8a83610ded565b600083526000828401520152565b9190916001600160801b0380809416911601918211610eb357565b634e487b7160e01b600052601160045260246000fd5b6001600160801b039182169082160391908211610eb357565b60409060405191610ef283610ded565b600080845280602080950152610f06610e1f565b936001600160801b039384603454169062093a809186610f29848242160461107a565b1691828210156110335797905b8781169083821015610fea5750830197878911610fd6578685898b818082978c8280861698898352603589528181842054169586915199610f768b610ded565b848b52808b019485528501511690610f8d91610ec9565b169052511691610f9c91611097565b610fa591610ec9565b168152809a610fb39161112e565b908752603686528888882091166001600160801b03198254161790559790610f36565b634e487b7160e01b86526011600452602486fd5b9897955050945050505061101c826001600160801b038151169060206001600160801b031991015160801b1617600055565b83166001600160801b031960345416176034559190565b909650945050505050565b6001600160801b03806020830151169061105b8142168093611097565b8351821691161015611073576110709161112e565b90565b5050600090565b9062093a806001600160801b0380931602918216918203610eb357565b9190916001600160801b0380809416911602918216918203610eb357565b906040516110c281610ded565b6000815260206110f78183016000815283956001600160801b039381856303bfc4008180955116041680945201511690611097565b169052565b80548210156111185760005260206000209060011b0190600090565b634e487b7160e01b600052603260045260246000fd5b602081016001600160801b039283928361114b8382865116611097565b915116938491161161116c5761107093611166925116611097565b90610ec9565b50505050600090565b6040516001600160a01b0391909116929161118f82610ded565b6020918281527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564838201526000808385829551910182895af13d156112ea573d9067ffffffffffffffff968783116112d657601f199260405193603f81601f8401160116840198848a10908a11176112c2576112199596979860405283528286883d92013e6112f6565b80519182159184831561129e575b5050509050156112345750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b91938180945001031261013657820151908115158203610234575080388084611227565b634e487b7160e01b86526041600452602486fd5b634e487b7160e01b85526041600452602485fd5b94611219929394956060915b91929015611358575081511561130a575090565b3b156113135790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561136b5750805190602001fd5b6040519062461bcd60e51b82528160208060048301528251908160248401526000935b8285106113b1575050604492506000838284010152601f80199101168101030190fd5b848101820151868601604401529381019385935061138e56fea26469706673582212201a532afa6fe9dcb635e7b872de693b1bd3d5a70ca9482603efa9ecb14d74a7ac64736f6c634300081800330000000000000000000000003fd9b6c9a24e09f67b7b706d72864aebb439100c
Deployed Bytecode
0x608060408181526004918236101561001657600080fd5b600092833560e01c918263078dfbe714610c245750816330d981af14610bfc5781633ccfd60b14610ae65781633ff03207146101585781634502495014610aa25781634e71e0c8146109df57816370a082311461099a5781637c386c7114610903578163814b2cac146108db5781638da5cb5b146108b3578163947975d914610879578163c8121ec2146102c757508063cb6b4f3c14610270578063d88e92a914610237578063e268b3a4146101b8578063e30c397814610191578063ef1c243a1461015d578063f4359ce514610158578063fa78668f1461013a5763fc367c611461010157600080fd5b3461013657602036600319011261013657806020926001600160a01b03610126610d9e565b1681526037845220549051908152f35b5080fd5b5034610136578160031936011261013657602090516303bfc4008152f35b610db9565b50346101365781600319360112610136576020906001600160801b03610189610184610e1f565b61103e565b915191168152f35b50346101365781600319360112610136576020906001600160a01b03600354169051908152f35b5090346102345760203660031901126102345761023061020e610184610209856101e0610d9e565b956001600160a01b036101fa6101f4610ee2565b5061103e565b97168152600160205220610e45565b6110b5565b92516001600160801b0392831681529190921660208201529081906040820190565b0390f35b80fd5b503461013657602036600319011261013657602091816001600160801b03918261025f610dd7565b168152603585522054169051908152f35b50346101365760203660031901126101365780610230926001600160a01b03610297610d9e565b168152600160209081529190205491516001600160801b038316815260809290921c908201529081906040820190565b905082346102345782600319360112610234576102e2610dd7565b926024938435936001600160801b0393848616968787036101365762093a8091828906610864574289111561084f57338152600193602099858b528783205460801c8110610840576303bfc400420180421161081f578111610831578442019081421161081f571061081157338252848a5261036388888420541687610e98565b9588871615610802579187959493918b9333835286855261038a8884205460801c8d610ec9565b8b821680610771575b503384528786528b6103a68a8620610e45565b916103af610ee2565b50938493898d8183019742878a5116116106d8575b505050908380925116906103d791610e98565b945116906103e491610e98565b96818b51946103f286610ded565b1684528301961686528d8c80610407856110b5565b809c519461041486610ded565b88865282858181808a01948d865282808251168189511661043491610e98565b168b520151169301928184511661044a91610e98565b16905251169751168552603590528a84208c8154978189169061046c91610e98565b166001600160801b03198098161790556104a4906001600160801b038151169060206001600160801b031991015160801b1617600055565b338352868d52898320815160209092015160801b6fffffffffffffffffffffffffffffffff19166001600160801b039290921691909117905560378c528882209384549586151580610695575b156105b057505060001985019485116105a05750505092610184816105969461053e610572957fb1a3371956c54dc1d83695b4a006b051c8313ee986e533b6b964e77c9066fc2c986110fc565b50825160209093015160801b6fffffffffffffffffffffffffffffffff19166001600160801b039390931692909217910155565b84516001600160801b03948516815293909616602084015233929081906040820190565b0390a25191168152f35b634e487b7160e01b825260119052fd5b6105c4908c9897949295939842160461107a565b928b8b51946105d286610ded565b1684528d8401958987526801000000000000000082101561068357906105fc9188820181556110fc565b979097610674575050905185549092169189169190911784555051805160209091015160801b6fffffffffffffffffffffffffffffffff19166001600160801b0391909116179101557fb1a3371956c54dc1d83695b4a006b051c8313ee986e533b6b964e77c9066fc2c90610596906105729061103e565b634e487b7160e01b8252819052fd5b5050634e487b7160e01b815260418752fd5b5060001987018781116106c5576106ad8d91886110fc565b5054168c6106be838242160461107a565b16146104f1565b5050634e487b7160e01b83525060119052fd5b829750908684928c8280989796816106f081996110b5565b9d8e958289519761070089610ded565b878952838901978852818084511691511661071a91610ec9565b1687520151169c019b818d511661073091610ec9565b169052985116908d848b51168d52603590528b2090838254918183169061075691610ec9565b16906001600160801b03191617905591925050898d386103c4565b91939550919395969751908d6323b872dd60e01b90830152338783015230604483015260648201526064815260a0810181811067ffffffffffffffff8211176107f057916107ea8e9694928c9a999896948b527f0000000000000000000000003fd9b6c9a24e09f67b7b706d72864aebb439100c611175565b8e610393565b634e487b7160e01b8652604185528686fd5b5086516323fbc14f60e11b8152fd5b8651630def6af560e21b8152fd5b5050634e487b7160e01b825260119052fd5b508651632739a01960e11b8152fd5b508651631f8b0c5960e21b8152fd5b50845163d928003560e01b8152808401899052fd5b508451637bf16ce960e11b8152808401899052fd5b50503461013657602036600319011261013657602091816001600160801b0391826108a2610dd7565b168152603685522054169051908152f35b5050346101365781600319360112610136576020906001600160a01b03600254169051908152f35b5050346101365781600319360112610136576020906001600160801b03603454169051908152f35b505034610136578060031936011261013657610950816060936001600160a01b0361092c610d9e565b610934610e6a565b50168152603760205220610946610e6a565b50602435906110fc565b509080519161095e83610ded565b602061097a60016001600160801b039384815416875201610e45565b818501908152828451955116855251828151168286015201511690820152f35b505034610136576020366003190112610136576001600160801b03610189610184610209846020966001600160a01b036109d2610d9e565b1681526001885220610e45565b91905034610a9e5782600319360112610a9e57600354906001600160a01b039283831691823303610a5b575050806002549384167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08680a373ffffffffffffffffffffffffffffffffffffffff19809316176002551660035580f35b906020606492519162461bcd60e51b8352820152602060248201527f4f776e61626c653a2063616c6c657220213d2070656e64696e67206f776e65726044820152fd5b8280fd5b505034610136578160031936011261013657602090516001600160a01b037f0000000000000000000000003fd9b6c9a24e09f67b7b706d72864aebb439100c168152f35b91905034610a9e5782600319360112610a9e573383526020926001845281812054429060801c11610bee57338152600184526001600160801b038282205416928315610be05733825260018552818381205582519163a9059cbb60e01b8684015233602484015284604484015260448352608083019183831067ffffffffffffffff841117610bcd5750508252610b9d907f0000000000000000000000003fd9b6c9a24e09f67b7b706d72864aebb439100c611175565b80518281527f0e1bb0545c1ebb9fb680bde73514e572831de93b479c087ec1ef6c35c3a19fd6843392a251908152f35b634e487b7160e01b825260419052602490fd5b8251631e95654360e11b8152fd5b50516339ba104360e01b8152fd5b5050346101365781600319360112610136576020906001600160801b036101896101f4610ee2565b92915034610d9a576060366003190112610d9a57610c40610d9e565b91602435928315158403610d9657604435938415158503610d92576001600160a01b039586600254163303610d51575085919015610d2a571692831590811591610d22575b5015610cdf575050806002549283167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08580a373ffffffffffffffffffffffffffffffffffffffff19809216176002556003541660035580f35b906020606492519162461bcd60e51b8352820152601560248201527f4f776e61626c653a207a65726f206164647265737300000000000000000000006044820152fd5b905038610c85565b93505050501673ffffffffffffffffffffffffffffffffffffffff19600354161760035580f35b62461bcd60e51b8152602085820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606490fd5b8680fd5b8580fd5b8380fd5b600435906001600160a01b0382168203610db457565b600080fd5b34610db4576000366003190112610db457602060405162093a808152f35b600435906001600160801b0382168203610db457565b6040810190811067ffffffffffffffff821117610e0957604052565b634e487b7160e01b600052604160045260246000fd5b60405190610e2c82610ded565b6000546001600160801b038116835260801c6020830152565b90604051610e5281610ded565b91546001600160801b038116835260801c6020830152565b60405190610e7782610ded565b60008252604051602083610e8a83610ded565b600083526000828401520152565b9190916001600160801b0380809416911601918211610eb357565b634e487b7160e01b600052601160045260246000fd5b6001600160801b039182169082160391908211610eb357565b60409060405191610ef283610ded565b600080845280602080950152610f06610e1f565b936001600160801b039384603454169062093a809186610f29848242160461107a565b1691828210156110335797905b8781169083821015610fea5750830197878911610fd6578685898b818082978c8280861698898352603589528181842054169586915199610f768b610ded565b848b52808b019485528501511690610f8d91610ec9565b169052511691610f9c91611097565b610fa591610ec9565b168152809a610fb39161112e565b908752603686528888882091166001600160801b03198254161790559790610f36565b634e487b7160e01b86526011600452602486fd5b9897955050945050505061101c826001600160801b038151169060206001600160801b031991015160801b1617600055565b83166001600160801b031960345416176034559190565b909650945050505050565b6001600160801b03806020830151169061105b8142168093611097565b8351821691161015611073576110709161112e565b90565b5050600090565b9062093a806001600160801b0380931602918216918203610eb357565b9190916001600160801b0380809416911602918216918203610eb357565b906040516110c281610ded565b6000815260206110f78183016000815283956001600160801b039381856303bfc4008180955116041680945201511690611097565b169052565b80548210156111185760005260206000209060011b0190600090565b634e487b7160e01b600052603260045260246000fd5b602081016001600160801b039283928361114b8382865116611097565b915116938491161161116c5761107093611166925116611097565b90610ec9565b50505050600090565b6040516001600160a01b0391909116929161118f82610ded565b6020918281527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564838201526000808385829551910182895af13d156112ea573d9067ffffffffffffffff968783116112d657601f199260405193603f81601f8401160116840198848a10908a11176112c2576112199596979860405283528286883d92013e6112f6565b80519182159184831561129e575b5050509050156112345750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b91938180945001031261013657820151908115158203610234575080388084611227565b634e487b7160e01b86526041600452602486fd5b634e487b7160e01b85526041600452602485fd5b94611219929394956060915b91929015611358575081511561130a575090565b3b156113135790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561136b5750805190602001fd5b6040519062461bcd60e51b82528160208060048301528251908160248401526000935b8285106113b1575050604492506000838284010152601f80199101168101030190fd5b848101820151868601604401529381019385935061138e56fea26469706673582212201a532afa6fe9dcb635e7b872de693b1bd3d5a70ca9482603efa9ecb14d74a7ac64736f6c63430008180033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000003fd9b6c9a24e09f67b7b706d72864aebb439100c
-----Decoded View---------------
Arg [0] : _ZLK (address): 0x3Fd9b6C9A24E09F67b7b706d72864aEbb439100C
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000003fd9b6c9a24e09f67b7b706d72864aebb439100c
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$102.27
Net Worth in GLMR
Token Allocations
ZLK
100.00%
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|---|---|---|---|---|
| GLMR | 100.00% | $0.00117 | 87,425.4645 | $102.27 |
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ 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.