Source Code
Overview
ETH Balance
ETH Value
$0.00Latest 1 from a total of 1 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Query | 409460 | 865 days ago | IN | 0 ETH | 0.00011175 |
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 26797057 | 39 days ago | 0 ETH | ||||
| 26229217 | 55 days ago | 0 ETH | ||||
| 26229217 | 55 days ago | 0 ETH | ||||
| 26229217 | 55 days ago | 0 ETH | ||||
| 26229160 | 55 days ago | 0 ETH | ||||
| 26229160 | 55 days ago | 0 ETH | ||||
| 26229160 | 55 days ago | 0 ETH | ||||
| 26229160 | 55 days ago | 0 ETH | ||||
| 26229160 | 55 days ago | 0 ETH | ||||
| 26229160 | 55 days ago | 0 ETH | ||||
| 26143432 | 57 days ago | 0 ETH | ||||
| 26143410 | 57 days ago | 0 ETH | ||||
| 26143394 | 57 days ago | 0 ETH | ||||
| 26087853 | 59 days ago | 0 ETH | ||||
| 26050285 | 60 days ago | 0 ETH | ||||
| 26050285 | 60 days ago | 0 ETH | ||||
| 26050285 | 60 days ago | 0 ETH | ||||
| 26050285 | 60 days ago | 0 ETH | ||||
| 26050285 | 60 days ago | 0 ETH | ||||
| 25870999 | 65 days ago | 0 ETH | ||||
| 25870999 | 65 days ago | 0 ETH | ||||
| 25854537 | 66 days ago | 0 ETH | ||||
| 25854537 | 66 days ago | 0 ETH | ||||
| 25851609 | 66 days ago | 0 ETH | ||||
| 25850470 | 66 days ago | 0 ETH |
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
SwapFacet
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 50 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/lib/Token.sol";
import "src/lib/PoolBalanceLib.sol";
import "src/interfaces/IPool.sol";
import "src/interfaces/ISwap.sol";
import "src/interfaces/IConverter.sol";
import "src/interfaces/IVC.sol";
import "src/interfaces/IVault.sol";
import "src/interfaces/IFacet.sol";
import "src/VaultStorage.sol";
import "openzeppelin-contracts/contracts/utils/math/SafeCast.sol";
import "openzeppelin-contracts/contracts/utils/math/Math.sol";
uint256 constant GAUGE_FLAG_KILLED = 1;
/**
* @dev a Facet for handling swap, stake and vote logic.
*
*
* please refer to the tech docs below for its intended behavior.
* https://velocore.gitbook.io/velocore-v2/technical-docs/exchanging-tokens-with-vault
*
*
*/
contract SwapFacet is VaultStorage, IFacet {
using PoolBalanceLib for PoolBalance;
using TokenLib for Token;
using UncheckedMemory for Token[];
using UncheckedMemory for int128[];
using UncheckedMemory for bytes32[];
using UncheckedMemory for uint256[];
using SafeCast for uint256;
using SafeCast for int256;
using EnumerableSet for EnumerableSet.AddressSet;
IVC immutable vc;
Token immutable ballot; // veVC
address immutable thisImplementation;
constructor(IVC vc_, Token ballot_) {
vc = vc_;
ballot = ballot_;
thisImplementation = address(this);
}
/**
* @dev called by AdminFacet.admin_addFacet().
* doesnt get added to the routing table, hence the lack of access control.
*/
function initializeFacet() external {
_setFunction(SwapFacet.execute.selector, thisImplementation);
// set as viewer; meaning its state alteration will not last.
// This allows query() to make actually perform swaps without any security consequences.
_setViewer(SwapFacet.query.selector, thisImplementation);
_setViewer(SwapFacet.balanceDelta.selector, thisImplementation);
}
/**
* @dev the primary function for exchanging tokens.
* @param tokenRef list of unique tokens involved in the operations. preferrably sorted.
* @param deposit list of amounts, in the same order as tokenRef, that will be transferFrom()'ed before execution.
* allows selling of tax tokens.
* @param ops please refer to the tech docs.
*/
function execute(Token[] memory tokenRef, int128[] memory deposit, VelocoreOperation[] memory ops)
external
payable
nonReentrant
returns (int128[] memory)
{
uint256 tokenRefLength = tokenRef.length;
require(tokenRefLength == deposit.length && tokenRefLength < 256, "malformed array");
/**
* to gurantee uniqueness and binary-searchability, tokenRef and VelocoreOperation.tokenInformation must be sorted first.
* We perform insertion sort to allow sorting off-chain to save gas.
*/
(bool orderChanged,, uint256[] memory toNewIdx) = _sort(tokenRef, deposit, ops);
/**
* transfer (deposit[]) amount of tokens from the user and credit them.
* we are using deposit[] to track internal balance here.
*/
unchecked {
for (uint256 i = 0; i < tokenRefLength; ++i) {
int128 d = deposit.u(i);
require(d >= 0);
if (d > 0) {
deposit.u(
i,
int128(
uint128(tokenRef.u(i).meteredTransferFrom(msg.sender, address(this), uint256(int256(d))))
)
);
}
}
}
/**
* credit msg.value to the internal balance.
* we are using deposit[] to track internal balance here.
*/
if (msg.value > 0) {
deposit.u(_binarySearchM(tokenRef, NATIVE_TOKEN), msg.value.toInt256().toInt128());
}
/**
* actually calculate exchange. deposit[] will be modified in-place to represent the user's internal balance.
*/
_execute(msg.sender, tokenRef, deposit, ops);
/**
* transfer the internal balance back to the user.
*/
unchecked {
for (uint256 i = 0; i < tokenRefLength; ++i) {
int128 d = deposit.u(i);
if (d == 0) {
continue;
} else if (d > 0) {
tokenRef.u(i).transferFrom(address(this), msg.sender, uint256(int256(d)));
} else {
tokenRef.u(i).safeTransferFrom(msg.sender, address(this), uint256(int256(-d)));
}
}
}
if (orderChanged) {
int128[] memory ret = new int128[](tokenRef.length);
for (uint256 i = 0; i < ret.length; i++) {
ret[i] = deposit[toNewIdx[i]];
}
return ret;
} else {
return deposit;
}
}
/**
* @dev actually perform operations and return their result.
* this function modifies states
* this function is not intended to be added as a viewer function. see initializeFacet() above for explanation.
*/
function query(address user, Token[] memory tokenRef, int128[] memory deposit, VelocoreOperation[] memory ops)
external
nonReentrant
returns (int128[] memory)
{
require(tokenRef.length == deposit.length && tokenRef.length < 256, "malformed input");
(bool orderChanged,, uint256[] memory toNewIdx) = _sort(tokenRef, deposit, ops);
_execute(user, tokenRef, deposit, ops);
if (orderChanged) {
int128[] memory ret = new int128[](tokenRef.length);
for (uint256 i = 0; i < ret.length; i++) {
ret[i] = deposit[toNewIdx[i]];
}
return ret;
} else {
return deposit;
}
}
/**
* the core logic, called from query() and execute()
* using cumDelta as internal balance.
*/
function _execute(address user, Token[] memory tokenRef, int128[] memory cumDelta, VelocoreOperation[] memory ops)
internal
{
bool vcDispensed = false;
for (uint256 i = 0; i < ops.length; i++) {
VelocoreOperation memory op = ops[i];
bytes32[] memory opTokenInformations = op.tokenInformations;
uint256 opTokenLength = opTokenInformations.length;
Token[] memory opTokens = new Token[](opTokenLength);
int128[] memory opAmounts = new int128[](opTokenLength);
unchecked {
for (uint256 j = 0; j < opTokenLength; j++) {
bytes32 tokInfo = opTokenInformations.u(j);
uint8 tokenIndex = uint8(tokInfo[0]);
uint8 amountType = uint8(tokInfo[1]);
opTokens.u(j, tokenRef.u(tokenIndex));
if (amountType == 0) {
// equals
opAmounts.u(j, int128(uint128(uint256(tokInfo))));
} else if (amountType == 1) {
// at most
opAmounts.u(j, type(int128).max);
} else if (amountType == 2) {
// consume all
opAmounts.u(j, cumDelta.u(tokenIndex));
} else if (amountType == 3) {
// everything
opAmounts.u(
j,
int128(
int256(
Math.min(
opTokens.u(j).balanceOf(address(this)), uint256(int256(type(int128).max)) - 1
)
)
)
);
}
}
}
uint8 opType = uint8(op.poolId[0]);
address opDst = address(uint160(uint256(op.poolId)));
if (opType == 0) {
// swap
(int128[] memory deltaGauge, int128[] memory deltaPool) =
ISwap(opDst).velocore__execute(user, opTokens, opAmounts, op.data);
require(deltaGauge.length == opTokenLength && deltaPool.length == opTokenLength);
_verifyAndApplyDelta(cumDelta, IPool(opDst), opTokens, opTokenInformations, deltaGauge, deltaPool);
unchecked {
for (uint256 j = 0; j < opTokenLength; j++) {
deltaGauge.u(j, deltaPool.u(j) + deltaGauge.u(j));
}
}
emit Swap(ISwap(opDst), user, opTokens, deltaGauge);
} else if (opType == 1) {
// stake
if (!vcDispensed) {
_dispenseVC();
vcDispensed = true;
}
_sendEmission(IGauge(opDst));
(int128[] memory deltaGauge, int128[] memory deltaPool) =
IGauge(opDst).velocore__gauge(user, opTokens, opAmounts, op.data);
require(deltaGauge.length == opTokenLength && deltaPool.length == opTokenLength);
_verifyAndApplyDelta(cumDelta, IPool(opDst), opTokens, opTokenInformations, deltaGauge, deltaPool);
unchecked {
for (uint256 j = 0; j < opTokenLength; j++) {
deltaGauge.u(j, deltaPool.u(j) + deltaGauge.u(j));
}
}
emit Gauge(IGauge(opDst), user, opTokens, deltaGauge);
} else if (opType == 2) {
// convert
uint256[] memory balances = new uint256[](opTokenLength);
for (uint256 j = 0; j < opTokenLength; j++) {
balances.u(j, opTokens.u(j).balanceOf(address(this)));
if (opAmounts.u(j) <= 0 || opAmounts.u(j) == type(int128).max) continue;
opTokens.u(j).transferFrom(address(this), opDst, uint128(uint256(int256(opAmounts.u(j)))));
}
IConverter(opDst).velocore__convert(user, opTokens, opAmounts, op.data);
int128[] memory deltas = SwapFacet(address(this)).balanceDelta(opTokens, balances);
for (uint256 j = 0; j < opTokenLength; j++) {
require(-deltas.u(j) <= int128(uint128(uint256(opTokenInformations.u(j)))));
cumDelta[uint8(uint256(opTokenInformations.u(j) >> (256 - 8)))] += deltas.u(j);
deltas.u(j, -deltas.u(j));
}
emit Convert(IConverter(opDst), user, opTokens, deltas);
} else if (opType == 3) {
// vote
if (!vcDispensed) {
_dispenseVC();
vcDispensed = true;
}
_sendEmission(IGauge(opDst));
GaugeInformation storage gauge = _e().gauges[IGauge(opDst)];
if (gauge.lastBribeUpdate == 0) gauge.lastBribeUpdate = uint32(block.timestamp);
if (gauge.lastBribeUpdate > 1) {
uint256 elapsed = block.timestamp - gauge.lastBribeUpdate;
if (elapsed > 0) {
uint256 len = gauge.bribes.length();
for (uint256 j = 0; j < len; j++) {
bytes memory extortCalldata = abi.encodeWithSelector(
SwapFacet.extort.selector, j, tokenRef, cumDelta, IGauge(opDst), elapsed, user
);
address thisImpl = thisImplementation;
bool success;
assembly ("memory-safe") {
success :=
delegatecall(gas(), thisImpl, add(extortCalldata, 32), mload(extortCalldata), 0, 0)
if success { returndatacopy(add(cumDelta, 32), 0, mul(32, mload(cumDelta))) }
}
}
}
gauge.lastBribeUpdate = uint32(block.timestamp);
}
uint256 ballotIndex = _binarySearchM(opTokens, ballot);
int128 deltaVote;
if (ballotIndex != type(uint256).max) {
deltaVote = opAmounts.u(ballotIndex);
if (deltaVote != type(int128).max) {
gauge.totalVotes = (int256(uint256(gauge.totalVotes)) + deltaVote).toUint256().toUint112();
_e().totalVotes = (int256(uint256(_e().totalVotes)) + deltaVote).toUint256().toUint128();
gauge.userVotes[user] =
(int256(uint256(gauge.userVotes[user])) + deltaVote).toUint256().toUint128();
cumDelta[_binarySearchM(tokenRef, ballot)] -= deltaVote;
} else {
deltaVote = 0;
}
}
emit Vote(IGauge(opDst), user, deltaVote);
} else if (opType == 4) {
bool isUser = user == opDst;
for (uint256 j = 0; j < opTokenLength; j++) {
require(isUser || opAmounts[j] >= 0, "you can't withdraw other's balance");
_userBalances()[opDst][opTokens[j]] =
(int256(_userBalances()[opDst][opTokens[j]]) + opAmounts[j]).toUint256();
cumDelta[uint8(uint256(opTokenInformations.u(j) >> (256 - 8)))] -= opAmounts[j];
}
emit UserBalance(opDst, user, opTokens, opAmounts);
} else if (opType == 5) {
unchecked {
for (uint256 j = 0; j < opTokenLength; j++) {
require(
int128(uint128(uint256(opTokenInformations.u(j))))
>= -cumDelta[uint8(uint256(opTokenInformations.u(j) >> (256 - 8)))],
"sippage"
);
}
}
} else {
revert();
}
}
}
function balanceDelta(Token[] memory tokens, uint256[] memory balancesBefore)
external
returns (int128[] memory delta)
{
delta = new int128[](tokens.length);
for (uint256 i = 0; i < tokens.length; i++) {
int128 diff = (tokens.u(i).balanceOf(address(this)).toInt256() - balancesBefore.u(i).toInt256()).toInt128();
delta.u(i, diff);
if (diff > 0) {
tokens.u(i).transferFrom(address(this), address(0xDEADBEEF), uint256(int256(diff)));
}
}
}
function extort(
uint256 bribeIndex,
Token[] calldata tokenRef,
int128[] memory cumDelta,
IGauge gauge,
uint256 elapsed,
address user
) external payable {
IBribe briber = IBribe(_e().gauges[gauge].bribes.at(bribeIndex));
(
Token[] memory bribeTokens,
int128[] memory deltaGauge,
int128[] memory deltaPool,
int128[] memory deltaExternal
) = briber.velocore__bribe(gauge, elapsed);
require(
bribeTokens.length == deltaGauge.length && bribeTokens.length == deltaPool.length
&& bribeTokens.length == deltaExternal.length
);
for (uint256 j = 0; j < bribeTokens.length; j++) {
uint256 netDelta = (-(int256(deltaGauge.u(j)) + deltaPool.u(j) + deltaExternal.u(j))).toUint256();
Token token = bribeTokens.u(j);
require(deltaExternal[j] <= 0);
_modifyPoolBalance(briber, token, deltaGauge.u(j), deltaPool.u(j), deltaExternal.u(j));
GaugeInformation storage g = _e().gauges[gauge];
Rewards storage r = g.rewards[briber][token];
if (g.totalVotes > 0) {
r.current += netDelta * 1e18 / g.totalVotes;
} else {
unchecked {
_userBalances()[StorageSlot.getAddressSlot(SSLOT_HYPERCORE_TREASURY).value][token] += netDelta;
}
}
uint256 userClaimed = (r.current - r.snapshots[user]) * uint256(g.userVotes[user]) / 1e18;
uint256 index = _binarySearch(tokenRef, token);
r.snapshots[user] = r.current;
if (index != type(uint256).max) {
cumDelta[index] += userClaimed.toInt256().toInt128();
} else {
_userBalances()[user][token] += userClaimed;
}
}
assembly ("memory-safe") {
return(add(cumDelta, 32), mul(32, mload(cumDelta)))
}
}
/**
* @dev in-place sort for execute() inputs.
*
* To gurantee uniqueness and binary-searchability, tokenRef and VelocoreOperation.tokenInformation must be sorted first.
* We perform insertion sort to allow sorting off-chain to save gas.
*
* @return orderChanged wether the orignal input was already sorted
* @return toOldIdx mapping(new index => old index)
* @return toNewIdx mapping(old index => new index); valid only when orderChanged == true;
*/
function _sort(Token[] memory tokens, int128[] memory amounts, VelocoreOperation[] memory ops)
internal
returns (bool orderChanged, uint256[] memory toOldIdx, uint256[] memory toNewIdx)
{
toOldIdx = new uint256[](tokens.length);
toNewIdx = new uint256[](tokens.length);
orderChanged = false;
uint256 tokenRefLength = tokens.length;
uint256 opsLength = ops.length;
unchecked {
/**
* Perform insertion sort on tokenRef first
*/
for (uint256 i = 1; i < tokenRefLength; ++i) {
toOldIdx.u(i, i);
Token key = tokens.u(i);
// using (<=) instead of (<) to include cases with duplicated tokens
if (key <= tokens.u(i - 1)) {
int128 amt = amounts.u(i);
uint256 j = i;
orderChanged = true;
while (j >= 1 && key <= tokens.u(j - 1)) {
--j;
tokens.u(j + 1, tokens.u(j));
toOldIdx.u(j + 1, toOldIdx.u(j));
amounts.u(j + 1, amounts.u(j));
}
require(tokenRefLength - 1 == j || tokens.u(j + 1) != key, "duplicated token");
tokens.u(j, key);
toOldIdx.u(j, i);
amounts.u(j, amt);
}
}
/**
* compute toNewIdx only when orderChanged
*/
if (orderChanged) {
for (uint256 i = 0; i < tokenRefLength; ++i) {
toNewIdx.u(toOldIdx.u(i), i);
}
}
/**
* perform insertion sort on VelocoreOperation[].tokenInforamtion
*/
for (uint256 i = 0; i < opsLength; ++i) {
bytes32[] memory arr = ops[i].tokenInformations;
uint256 tokenInformationLength = arr.length;
for (uint256 j = 0; j < tokenInformationLength; ++j) {
bytes32 key;
if (orderChanged) {
uint8 oldIdx = uint8(arr.u(j)[0]);
// toNewIdx.length could be lower than oldIdx; using boundedness check here.
key = (
(arr.u(j) & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
| bytes32(bytes1(uint8(toNewIdx[oldIdx])))
);
arr.u(j, key);
} else {
key = arr.u(j);
}
uint256 k = j;
if (k >= 1 && key[0] <= arr.u(k - 1)[0]) {
while (k >= 1 && key[0] <= arr.u(k - 1)[0]) {
--k;
arr.u(k + 1, arr.u(k));
}
require(
arr.length - 1 == k || arr.u(k + 1)[0] != key[0], "duplicated token in VelocoreOperation"
);
arr.u(k, key);
}
}
require(
tokenInformationLength == 0 || uint8(arr.u(tokenInformationLength - 1)[0]) < tokenRefLength,
"token not in tokenRef"
);
}
}
}
function _modifyPoolBalance(IPool pool, Token tok, int128 dGauge, int128 dPool, int128 dExternal) internal {
_poolBalances()[pool][tok] = _poolBalances()[pool][tok].credit(dGauge, dPool);
if (dExternal < 0) {
tok.safeTransferFrom(address(pool), address(this), uint256(int256(-dExternal)));
}
// we don't implement (dExternal > 0), as such cases will not happen.
}
function _dispenseVC() internal {
if (_e().totalVotes > 0) {
uint256 dispensed = vc.dispense();
if (dispensed > 0) {
_e().perVote = _e().perVote + (uint256(1e9) * dispensed / _e().totalVotes).toUint128();
}
}
}
function _sendEmission(IGauge gauge) internal {
uint256 newEmissions;
if (_e().gauges[gauge].lastBribeUpdate == 1) {
newEmissions = 0;
} else {
newEmissions = uint256(_e().perVote - _e().gauges[gauge].perVoteAtLastEmissionUpdate)
* _e().gauges[gauge].totalVotes / 1e9;
// overflow should not happen, as (perVote / 1e9) should be much lower than 200 according to the tokenmics.
// log2(1e18 * 1e9 * 1e3) = 99.7 < 112
_e().gauges[gauge].perVoteAtLastEmissionUpdate = uint112(_e().perVote);
}
_poolBalances()[gauge][toToken(vc)] = _poolBalances()[gauge][toToken(vc)].credit(int256(newEmissions), 0);
gauge.velocore__emission(newEmissions);
}
function _verifyAndApplyDelta(
int128[] memory cumDelta,
IPool pool,
Token[] memory opTokens,
bytes32[] memory tokenInformations,
int128[] memory deltaGauge,
int128[] memory deltaPool
) internal {
uint256 opTokenLength = opTokens.length;
for (uint256 j = 0; j < opTokenLength; j++) {
int128 dg = deltaGauge.u(j);
int128 dp = deltaPool.u(j);
int128 d = dg + dp;
require(d <= int128(uint128(uint256(tokenInformations.u(j)))), "token result above max");
Token token = opTokens.u(j);
_modifyPoolBalance(pool, token, dg, dp, 0);
cumDelta[uint8(tokenInformations.u(j)[0])] -= d;
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "src/lib/UncheckedMemory.sol";
import "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import "openzeppelin-contracts/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol";
// a library for abstracting tokens
// provides a common interface for ERC20, ERC1155, and ERC721 tokens.
bytes32 constant TOKEN_MASK = 0x000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
bytes32 constant ID_MASK = 0x00FFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000;
uint256 constant ID_SHIFT = 160;
bytes32 constant TOKENSPEC_MASK = 0xFF00000000000000000000000000000000000000000000000000000000000000;
string constant NATIVE_TOKEN_SYMBOL = "ETH";
type Token is bytes32;
type TokenSpecType is bytes32;
using {TokenSpec_equals as ==} for TokenSpecType global;
using {Token_equals as ==} for Token global;
using {Token_lt as <} for Token global;
using {Token_lte as <=} for Token global;
using {Token_ne as !=} for Token global;
using UncheckedMemory for Token[];
Token constant NATIVE_TOKEN = Token.wrap(0xEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE);
function TokenSpec_equals(TokenSpecType a, TokenSpecType b) pure returns (bool) {
return TokenSpecType.unwrap(a) == TokenSpecType.unwrap(b);
}
function Token_equals(Token a, Token b) pure returns (bool) {
return Token.unwrap(a) == Token.unwrap(b);
}
function Token_ne(Token a, Token b) pure returns (bool) {
return Token.unwrap(a) != Token.unwrap(b);
}
function Token_lt(Token a, Token b) pure returns (bool) {
return Token.unwrap(a) < Token.unwrap(b);
}
function Token_lte(Token a, Token b) pure returns (bool) {
return Token.unwrap(a) <= Token.unwrap(b);
}
library TokenSpec {
TokenSpecType constant ERC20 =
TokenSpecType.wrap(0x0000000000000000000000000000000000000000000000000000000000000000);
TokenSpecType constant ERC721 =
TokenSpecType.wrap(0x0100000000000000000000000000000000000000000000000000000000000000);
TokenSpecType constant ERC1155 =
TokenSpecType.wrap(0x0200000000000000000000000000000000000000000000000000000000000000);
TokenSpecType constant NATIVE =
TokenSpecType.wrap(0xEE00000000000000000000000000000000000000000000000000000000000000);
}
function toToken(IERC20 tok) pure returns (Token) {
return Token.wrap(bytes32(uint256(uint160(address(tok)))));
}
function toToken(TokenSpecType spec_, uint88 id_, address addr_) pure returns (Token) {
return Token.wrap(
TokenSpecType.unwrap(spec_) | bytes32((bytes32(uint256(id_)) << ID_SHIFT) & ID_MASK)
| bytes32(uint256(uint160(addr_)))
);
}
// binary search on sorted arrays
function _binarySearch(Token[] calldata arr, Token token) view returns (uint256) {
if (arr.length == 0) return type(uint256).max;
uint256 start = 0;
uint256 end = arr.length - 1;
unchecked {
while (start <= end) {
uint256 mid = start + (end - start) / 2;
if (arr.uc(mid) == token) {
return mid;
} else if (arr.uc(mid) < token) {
start = mid + 1;
} else {
if (mid == 0) return type(uint256).max;
end = mid - 1;
}
}
}
return type(uint256).max;
}
// binary search on sorted arrays, memory array version
function _binarySearchM(Token[] memory arr, Token token) view returns (uint256) {
if (arr.length == 0) return type(uint256).max;
uint256 start = 0;
uint256 end = arr.length - 1;
unchecked {
while (start <= end) {
uint256 mid = start + (end - start) / 2;
if (arr.u(mid) == token) {
return mid;
} else if (arr.u(mid) < token) {
start = mid + 1;
} else {
if (mid == 0) return type(uint256).max;
end = mid - 1;
}
}
}
return type(uint256).max;
}
library TokenLib {
using TokenLib for Token;
using TokenLib for bytes32;
using SafeERC20 for IERC20;
using SafeERC20 for IERC20Metadata;
function wrap(bytes32 data) internal pure returns (Token) {
return Token.wrap(data);
}
function unwrap(Token tok) internal pure returns (bytes32) {
return Token.unwrap(tok);
}
function addr(Token tok) internal pure returns (address) {
return address(uint160(uint256(tok.unwrap() & TOKEN_MASK)));
}
function id(Token tok) internal pure returns (uint256) {
return uint256((tok.unwrap() & ID_MASK) >> ID_SHIFT);
}
function spec(Token tok) internal pure returns (TokenSpecType) {
return TokenSpecType.wrap(tok.unwrap() & TOKENSPEC_MASK);
}
function toIERC20(Token tok) internal pure returns (IERC20Metadata) {
return IERC20Metadata(tok.addr());
}
function toIERC1155(Token tok) internal pure returns (IERC1155) {
return IERC1155(tok.addr());
}
function toIERC721(Token tok) internal pure returns (IERC721Metadata) {
return IERC721Metadata(tok.addr());
}
function balanceOf(Token tok, address user) internal view returns (uint256) {
if (tok.spec() == TokenSpec.ERC20) {
require(tok.id() == 0);
return tok.toIERC20().balanceOf(user); // ERC721 balanceOf() has the same signature
} else if (tok.spec() == TokenSpec.ERC1155) {
return tok.toIERC1155().balanceOf(user, tok.id());
} else if (tok.spec() == TokenSpec.ERC721) {
return tok.toIERC721().ownerOf(tok.id()) == user ? 1 : 0;
} else if (tok == NATIVE_TOKEN) {
return user.balance;
}
revert("invalid token");
}
function totalSupply(Token tok) internal view returns (uint256) {
if (tok.spec() == TokenSpec.ERC20) {
require(tok.id() == 0);
return tok.toIERC20().totalSupply(); // ERC721 balanceOf() has the same signature
} else if (tok.spec() == TokenSpec.ERC1155) {
return ERC1155Supply(tok.addr()).totalSupply(tok.id());
} else if (tok.spec() == TokenSpec.ERC721) {
return 1;
} else if (tok == NATIVE_TOKEN) {
revert("ETH total supply unknown");
}
revert("invalid token");
}
function symbol(Token tok) internal view returns (string memory) {
if (tok.spec() == TokenSpec.ERC20) {
require(tok.id() == 0);
return tok.toIERC20().symbol(); // ERC721 balanceOf() has the same signature
} else if (tok.spec() == TokenSpec.ERC1155) {
return "";
} else if (tok.spec() == TokenSpec.ERC721) {
return tok.toIERC721().symbol();
} else if (tok == NATIVE_TOKEN) {
return NATIVE_TOKEN_SYMBOL;
}
revert("invalid token");
}
function decimals(Token tok) internal view returns (uint8) {
if (tok.spec() == TokenSpec.ERC20) {
require(tok.id() == 0);
return IERC20Metadata(tok.addr()).decimals();
} else if (tok == NATIVE_TOKEN) {
return 18;
}
return 0;
}
function transferFrom(Token tok, address from, address to, uint256 amount) internal {
if (tok.spec() == TokenSpec.ERC20) {
require(tok.id() == 0);
if (from == address(this)) {
tok.toIERC20().safeTransfer(to, amount);
} else {
tok.toIERC20().safeTransferFrom(from, to, amount);
}
} else if (tok == NATIVE_TOKEN) {
require(from == address(this), "native token transferFrom is not supported");
assembly {
let success := call(gas(), to, amount, 0, 0, 0, 0)
if iszero(success) { revert(0, 0) }
}
} else if (tok.spec() == TokenSpec.ERC721) {
require(amount == 1, "invalid amount");
tok.toIERC721().safeTransferFrom(from, to, tok.id());
} else if (tok.spec() == TokenSpec.ERC1155) {
tok.toIERC1155().safeTransferFrom(from, to, tok.id(), amount, "");
} else {
revert("invalid token");
}
}
function meteredTransferFrom(Token tok, address from, address to, uint256 amount) internal returns (uint256) {
uint256 balBefore = tok.balanceOf(to);
tok.transferFrom(from, to, amount);
return tok.balanceOf(to) - balBefore;
}
function safeTransferFrom(Token tok, address from, address to, uint256 amount) internal {
require(tok.meteredTransferFrom(from, to, amount) >= amount);
}
}// SPDX-License-Identifier: AUNLICENSED
pragma solidity ^0.8.0;
import "openzeppelin-contracts/contracts/utils/math/SafeCast.sol";
// a pool's balances are stored as two uint128;
// the only difference between them is that new emissions are credited into the gauge balance.
// the pool can use them in any way they want.
type PoolBalance is bytes32;
library PoolBalanceLib {
using PoolBalanceLib for PoolBalance;
using SafeCast for uint256;
using SafeCast for int256;
function gaugeHalf(PoolBalance self) internal pure returns (uint256) {
return uint128(bytes16(PoolBalance.unwrap(self)));
}
function poolHalf(PoolBalance self) internal pure returns (uint256) {
return uint128(uint256(PoolBalance.unwrap(self)));
}
function pack(uint256 a, uint256 b) internal pure returns (PoolBalance) {
uint128 a_ = uint128(a);
uint128 b_ = uint128(b);
require(b == b_ && a == a_, "overflow");
return PoolBalance.wrap(bytes32(bytes16(a_)) | bytes32(uint256(b_)));
}
function credit(PoolBalance self, int256 dGauge, int256 dPool) internal pure returns (PoolBalance) {
return pack(
(int256(uint256(self.gaugeHalf())) + dGauge).toUint256(),
(int256(uint256(self.poolHalf())) + dPool).toUint256()
);
}
function credit(PoolBalance self, int256 dPool) internal pure returns (PoolBalance) {
return pack(self.gaugeHalf(), (int256(uint256(self.poolHalf())) + dPool).toUint256());
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/lib/Token.sol";
interface IPool {
function poolParams() external view returns (bytes memory);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/lib/Token.sol";
import "./IPool.sol";
interface ISwap is IPool {
/**
* @param user the user that requested swap
* @param tokens sorted, unique list of tokens that user asked to swap
* @param amounts same order as tokens, requested change of token balance, positive when pool receives, negative when pool gives. type(int128).max for unknown values, for which the pool should decide.
* @param data auxillary data for pool-specific uses.
* @return deltaGauge same order as tokens, the desired change of gauge balance
* @return deltaPool same order as bribeTokens, the desired change of pool balance
*/
function velocore__execute(address user, Token[] calldata tokens, int128[] memory amounts, bytes calldata data)
external
returns (int128[] memory, int128[] memory);
function swapType() external view returns (string memory);
function listedTokens() external view returns (Token[] memory);
function lpTokens() external view returns (Token[] memory);
function underlyingTokens(Token lp) external view returns (Token[] memory);
//function spotPrice(Token token, Token base) external view returns (uint256);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/lib/Token.sol";
interface IConverter {
/**
* @dev This method is called by Vault.execute().
* Vault will transfer any positively specified amounts directly to the IConverter before calling velocore__convert.
*
* Instead of returning balance delta numbers, IConverter is expected to directly transfer outputs back to vault.
* Vault will measure the difference, and credit the user.
*/
function velocore__convert(address user, Token[] calldata tokens, int128[] memory amounts, bytes calldata data)
external;
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/lib/Token.sol";
interface IVC is IERC20 {
function notifyMigration(uint128 n) external;
function dispense() external returns (uint256);
function emissionRate() external view returns (uint256);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/interfaces/IAuthorizer.sol";
import "src/interfaces/IFacet.sol";
import "src/interfaces/IGauge.sol";
import "src/interfaces/IConverter.sol";
import "src/interfaces/IBribe.sol";
import "src/interfaces/ISwap.sol";
import "src/lib/Token.sol";
bytes32 constant SSLOT_HYPERCORE_TREASURY = bytes32(uint256(keccak256("hypercore.treasury")) - 1);
bytes32 constant SSLOT_HYPERCORE_AUTHORIZER = bytes32(uint256(keccak256("hypercore.authorizer")) - 1);
bytes32 constant SSLOT_HYPERCORE_ROUTINGTABLE = bytes32(uint256(keccak256("hypercore.routingTable")) - 1);
bytes32 constant SSLOT_HYPERCORE_POOLBALANCES = bytes32(uint256(keccak256("hypercore.poolBalances")) - 1);
bytes32 constant SSLOT_HYPERCORE_USERBALANCES = bytes32(uint256(keccak256("hypercore.userBalances")) - 1);
bytes32 constant SSLOT_HYPERCORE_EMISSIONINFORMATION = bytes32(uint256(keccak256("hypercore.emissionInformation")) - 1);
bytes32 constant SSLOT_REENTRACNYGUARD_LOCKED = bytes32(uint256(keccak256("ReentrancyGuard.locked")) - 1);
bytes32 constant SSLOT_PAUSABLE_PAUSED = bytes32(uint256(keccak256("Pausable.paused")) - 1);
struct VelocoreOperation {
bytes32 poolId;
bytes32[] tokenInformations;
bytes data;
}
interface IVault {
struct Facet {
address facetAddress;
bytes4[] functionSelectors;
}
enum FacetCutAction {
Add,
Replace,
Remove
}
// Add=0, Replace=1, Remove=2
struct FacetCut {
address facetAddress;
FacetCutAction action;
bytes4[] functionSelectors;
}
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);
event Swap(ISwap indexed pool, address indexed user, Token[] tokenRef, int128[] delta);
event Gauge(IGauge indexed pool, address indexed user, Token[] tokenRef, int128[] delta);
event Convert(IConverter indexed pool, address indexed user, Token[] tokenRef, int128[] delta);
event Vote(IGauge indexed pool, address indexed user, int256 voteDelta);
event UserBalance(address indexed to, address indexed from, Token[] tokenRef, int128[] delta);
event BribeAttached(IGauge indexed gauge, IBribe indexed bribe);
event BribeKilled(IGauge indexed gauge, IBribe indexed bribe);
event GaugeKilled(IGauge indexed gauge, bool killed);
function notifyInitialSupply(Token, uint128, uint128) external;
function attachBribe(IGauge gauge, IBribe bribe) external;
function killBribe(IGauge gauge, IBribe bribe) external;
function killGauge(IGauge gauge, bool t) external;
function ballotToken() external returns (Token);
function emissionToken() external returns (Token);
function execute(Token[] calldata tokenRef, int128[] memory deposit, VelocoreOperation[] calldata ops)
external
payable;
function facets() external view returns (Facet[] memory facets_);
function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetFunctionSelectors_);
function facetAddresses() external view returns (address[] memory facetAddresses_);
function facetAddress(bytes4 _functionSelector) external view returns (address facetAddress_);
function query(address user, Token[] calldata tokenRef, int128[] memory deposit, VelocoreOperation[] calldata ops)
external
returns (int128[] memory);
function admin_setFunctions(address implementation, bytes4[] calldata sigs) external;
function admin_addFacet(IFacet implementation) external;
function admin_setAuthorizer(IAuthorizer auth_) external;
function admin_pause(bool t) external;
function admin_setTreasury(address treasury) external;
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function getAmountsOut(uint256 amountIn, address[] calldata path) external returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path) external returns (uint256[] memory amounts);
function execute1(address pool, uint8 method, address t1, uint8 m1, int128 a1, bytes memory data)
external
payable
returns (int128[] memory);
function query1(address pool, uint8 method, address t1, uint8 m1, int128 a1, bytes memory data)
external
returns (int128[] memory);
function execute2(
address pool,
uint8 method,
address t1,
uint8 m1,
int128 a1,
address t2,
uint8 m2,
int128 a2,
bytes memory data
) external payable returns (int128[] memory);
function query2(
address pool,
uint8 method,
address t1,
uint8 m1,
int128 a1,
address t2,
uint8 m2,
int128 a2,
bytes memory data
) external returns (int128[] memory);
function execute3(
address pool,
uint8 method,
address t1,
uint8 m1,
int128 a1,
address t2,
uint8 m2,
int128 a2,
address t3,
uint8 m3,
int128 a3,
bytes memory data
) external payable returns (int128[] memory);
function query3(
address pool,
uint8 method,
address t1,
uint8 m1,
int128 a1,
address t2,
uint8 m2,
int128 a2,
address t3,
uint8 m3,
int128 a3,
bytes memory data
) external returns (int128[] memory);
function getPair(address t0, address t1) external view returns (address);
function allPairs(uint256 i) external view returns (address);
function allPairsLength() external view returns (uint256);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
interface IFacet {
function initializeFacet() external;
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/lib/Token.sol";
import "src/interfaces/IVault.sol";
import "src/interfaces/IGauge.sol";
import "src/lib/PoolBalanceLib.sol";
import "src/interfaces/IGauge.sol";
import "src/interfaces/IBribe.sol";
import "src/interfaces/IAuthorizer.sol";
import "openzeppelin-contracts/contracts/utils/structs/BitMaps.sol";
import "openzeppelin-contracts/contracts/utils/StorageSlot.sol";
import "openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol";
// A base contract inherited by every facet.
// Vault stores everything on named slots, in order to:
// - prevent storage collision
// - make information access cheaper. (see Diamond.yul)
// The downside of doing that is that storage access becomes exteremely verbose;
// We define large singleton structs to mitigate that.
struct EmissionInformation {
// a singleton struct for emission-related global data
// accessed as `_e()`
uint128 perVote; // (number of VC tokens ever emitted, per vote) * 1e9; monotonically increasing.
uint128 totalVotes; // the current sum of votes on all pool
mapping(IGauge => GaugeInformation) gauges; // per-guage informations
}
struct GaugeInformation {
// we use `lastBribeUpdate == 1` as a special value indicating a killed gauge
// note that this is updated with bribe calculation, not emission calculation, unlike perVoteAtLastEmissionUpdate
uint32 lastBribeUpdate;
uint112 perVoteAtLastEmissionUpdate;
//
// total vote on this gauge
uint112 totalVotes;
//
mapping(address => uint256) userVotes;
//
// bribes are contracts; we call them to extort bribes on demand
EnumerableSet.AddressSet bribes;
//
// for storing extorted bribes.
// we track (accumulated reward / vote), per bribe contract, per token
// we separately track rewards from different bribes, to contain bad-behaving bribe contracts
mapping(IBribe => mapping(Token => Rewards)) rewards;
}
// tracks the distribution of a single token
struct Rewards {
// accumulated rewards per vote * 1e9
uint256 current;
// `accumulated rewards per vote * 1e9` at the moment of last claim of the user
mapping(address => uint256) snapshots;
}
struct RoutingTable {
EnumerableSet.Bytes32Set sigs;
mapping(address => EnumerableSet.Bytes32Set) sigsByImplementation;
}
contract VaultStorage {
using EnumerableSet for EnumerableSet.Bytes32Set;
event Swap(ISwap indexed pool, address indexed user, Token[] tokenRef, int128[] delta);
event Gauge(IGauge indexed pool, address indexed user, Token[] tokenRef, int128[] delta);
event Convert(IConverter indexed pool, address indexed user, Token[] tokenRef, int128[] delta);
event Vote(IGauge indexed pool, address indexed user, int256 voteDelta);
event UserBalance(address indexed to, address indexed from, Token[] tokenRef, int128[] delta);
event BribeAttached(IGauge indexed gauge, IBribe indexed bribe);
event BribeKilled(IGauge indexed gauge, IBribe indexed bribe);
event GaugeKilled(IGauge indexed gauge, bool killed);
enum FacetCutAction {
Add,
Replace,
Remove
}
// Add=0, Replace=1, Remove=2
struct FacetCut {
address facetAddress;
FacetCutAction action;
bytes4[] functionSelectors;
}
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);
function _getImplementation(bytes4 sig) internal view returns (address impl, bool readonly) {
assembly ("memory-safe") {
impl := sload(not(shr(0xe0, sig)))
if iszero(lt(impl, 0x10000000000000000000000000000000000000000)) {
readonly := 1
impl := not(impl)
}
}
}
function _setFunction(bytes4 sig, address implementation) internal {
(address oldImplementation,) = _getImplementation(sig);
FacetCut[] memory a = new FacetCut[](1);
a[0].facetAddress = implementation;
a[0].action = FacetCutAction.Add;
a[0].functionSelectors = new bytes4[](1);
a[0].functionSelectors[0] = sig;
if (oldImplementation != address(0)) a[0].action = FacetCutAction.Replace;
if (implementation == address(0)) a[0].action = FacetCutAction.Remove;
emit DiamondCut(a, implementation, "");
assembly ("memory-safe") {
sstore(not(shr(0xe0, sig)), implementation)
}
if (oldImplementation != address(0)) {
_routingTable().sigsByImplementation[oldImplementation].remove(sig);
}
if (implementation == address(0)) {
_routingTable().sigs.remove(sig);
} else {
_routingTable().sigs.add(sig);
_routingTable().sigsByImplementation[implementation].add(sig);
}
}
// viewer implementations are stored as `not(implementation)`. please refer to Diamond.yul for more information
function _setViewer(bytes4 sig, address implementation) internal {
(address oldImplementation,) = _getImplementation(sig);
FacetCut[] memory a = new FacetCut[](1);
a[0].facetAddress = implementation;
a[0].action = FacetCutAction.Add;
a[0].functionSelectors = new bytes4[](1);
a[0].functionSelectors[0] = sig;
if (oldImplementation != address(0)) a[0].action = FacetCutAction.Replace;
if (implementation == address(0)) a[0].action = FacetCutAction.Remove;
emit DiamondCut(a, implementation, "");
assembly ("memory-safe") {
sstore(not(shr(0xe0, sig)), not(implementation))
}
if (oldImplementation != address(0)) {
_routingTable().sigsByImplementation[oldImplementation].remove(sig);
}
if (implementation == address(0)) {
_routingTable().sigs.remove(sig);
} else {
_routingTable().sigs.add(sig);
_routingTable().sigsByImplementation[implementation].add(sig);
}
}
function _routingTable() internal pure returns (RoutingTable storage ret) {
bytes32 slot = SSLOT_HYPERCORE_ROUTINGTABLE;
assembly ("memory-safe") {
ret.slot := slot
}
}
// each pool has two accounts of balance: gauge balance and pool balance; both are uint128.
// they are stored in a wrapped bytes32, PoolBalance
// the only difference between them is that new emissions are credited into the gauge balance.
// the pool can use them in any way they want.
function _poolBalances() internal pure returns (mapping(IPool => mapping(Token => PoolBalance)) storage ret) {
bytes32 slot = SSLOT_HYPERCORE_POOLBALANCES;
assembly ("memory-safe") {
ret.slot := slot
}
}
function _e() internal pure returns (EmissionInformation storage ret) {
bytes32 slot = SSLOT_HYPERCORE_EMISSIONINFORMATION;
assembly ("memory-safe") {
ret.slot := slot
}
}
// users can also store tokens directly in the vault; their balances are tracked separately.
function _userBalances() internal pure returns (mapping(address => mapping(Token => uint256)) storage ret) {
bytes32 slot = SSLOT_HYPERCORE_USERBALANCES;
assembly ("memory-safe") {
ret.slot := slot
}
}
modifier nonReentrant() {
require(StorageSlot.getUint256Slot(SSLOT_REENTRACNYGUARD_LOCKED).value < 2, "REENTRANCY");
StorageSlot.getUint256Slot(SSLOT_REENTRACNYGUARD_LOCKED).value = 2;
_;
StorageSlot.getUint256Slot(SSLOT_REENTRACNYGUARD_LOCKED).value = 1;
}
modifier whenNotPaused() {
require(StorageSlot.getUint256Slot(SSLOT_PAUSABLE_PAUSED).value == 0, "PAUSED");
_;
}
// this contract delegates access control to another contract, IAuthenticator.
// this design was inspired by Balancer.
// actionId is a function of method signature and contract address
modifier authenticate() {
authenticateCaller();
_;
}
function authenticateCaller() internal {
bytes32 actionId = keccak256(abi.encodePacked(bytes32(uint256(uint160(address(this)))), msg.sig));
require(
IAuthorizer(StorageSlot.getAddressSlot(SSLOT_HYPERCORE_AUTHORIZER).value).canPerform(
actionId, msg.sender, address(this)
),
"unauthorized"
);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: AUNLICENSED
pragma solidity ^0.8.0;
import {Token} from "src/lib/Token.sol";
// solidity by default perform bound check for every array access.
// we define functions for unchecked access here
library UncheckedMemory {
function u(bytes32[] memory self, uint256 i) internal view returns (bytes32 ret) {
assembly ("memory-safe") {
ret := mload(add(self, mul(32, add(i, 1))))
}
}
function u(bytes32[] memory self, uint256 i, bytes32 v) internal view {
assembly ("memory-safe") {
mstore(add(self, mul(32, add(i, 1))), v)
}
}
function u(uint256[] memory self, uint256 i) internal view returns (uint256 ret) {
assembly ("memory-safe") {
ret := mload(add(self, mul(32, add(i, 1))))
}
}
function u(uint256[] memory self, uint256 i, uint256 v) internal view {
assembly ("memory-safe") {
mstore(add(self, mul(32, add(i, 1))), v)
}
}
function u(int128[] memory self, uint256 i) internal view returns (int128 ret) {
assembly ("memory-safe") {
ret := mload(add(self, mul(32, add(i, 1))))
}
}
function u(int128[] memory self, uint256 i, int128 v) internal view {
assembly ("memory-safe") {
mstore(add(self, mul(32, add(i, 1))), v)
}
}
// uc instead u for calldata array; as solidity does not support type-location overloading.
function uc(Token[] calldata self, uint256 i) internal view returns (Token ret) {
assembly ("memory-safe") {
ret := calldataload(add(self.offset, mul(32, i)))
}
}
function u(Token[] memory self, uint256 i) internal view returns (Token ret) {
assembly ("memory-safe") {
ret := mload(add(self, mul(32, add(i, 1))))
}
}
function u(Token[] memory self, uint256 i, Token v) internal view {
assembly ("memory-safe") {
mstore(add(self, mul(32, add(i, 1))), v)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC1155/extensions/ERC1155Supply.sol)
pragma solidity ^0.8.0;
import "../ERC1155.sol";
/**
* @dev Extension of ERC1155 that adds tracking of total supply per id.
*
* Useful for scenarios where Fungible and Non-fungible tokens have to be
* clearly identified. Note: While a totalSupply of 1 might mean the
* corresponding is an NFT, there is no guarantees that no other token with the
* same id are not going to be minted.
*/
abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 => uint256) private _totalSupply;
/**
* @dev Total amount of tokens in with a given id.
*/
function totalSupply(uint256 id) public view virtual returns (uint256) {
return _totalSupply[id];
}
/**
* @dev Indicates whether any token exist with a given id, or not.
*/
function exists(uint256 id) public view virtual returns (bool) {
return ERC1155Supply.totalSupply(id) > 0;
}
/**
* @dev See {ERC1155-_beforeTokenTransfer}.
*/
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i];
}
}
if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 supply = _totalSupply[id];
require(supply >= amount, "ERC1155: burn amount exceeds totalSupply");
unchecked {
_totalSupply[id] = supply - amount;
}
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: UNLICENSED
// 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.0;
interface IAuthorizer {
/**
* @dev Returns true if `account` can perform the action described by `actionId` in the contract `where`.
*/
function canPerform(bytes32 actionId, address account, address where) external view returns (bool);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/lib/Token.sol";
import "src/interfaces/IPool.sol";
/**
* Gauges are just pools.
* instead of velocore__execute, they interact with velocore__gauge.
* (un)staking is done by putting/extracting staking token (usually LP token) from/into the pool with velocore__gauge.
* harvesting is done by setting the staking amount to zero.
*/
interface IGauge is IPool {
/**
* @dev This method is called by Vault.execute().
* the parameters and return values are the same as velocore__execute.
* The only difference is that the vault will call velocore__emission before calling velocore__gauge.
*/
function velocore__gauge(address user, Token[] calldata tokens, int128[] memory amounts, bytes calldata data)
external
returns (int128[] memory deltaGauge, int128[] memory deltaPool);
/**
* @dev This method is called by Vault.execute() before calling velocore__emission or changing votes.
*
* The vault will credit emitted VC into the gauge balance.
* IGauge is expected to update its internal ledger.
* @param newEmissions newly emitted VCs since last emission
*/
function velocore__emission(uint256 newEmissions) external;
function stakeableTokens() external view returns (Token[] memory);
function stakedTokens(address user) external view returns (uint256[] memory);
function stakedTokens() external view returns (uint256[] memory);
function emissionShare(address user) external view returns (uint256);
function naturalBribes() external view returns (Token[] memory);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "src/lib/Token.sol";
import "./IGauge.sol";
import "./IPool.sol";
interface IBribe is IPool {
/**
* @dev This method is called when someone vote/harvest from/to a @param gauge,
* and when this IBribe happens to be attached to the gauge.
*
* Attachment can happen without IBribe's permission. Implementations must verify that @param gauge is correct.
*
* Returns balance deltas; their net differences are credited as bribe.
* deltaExternal must be zero or negative; Vault will take specified amounts from the contract's balance
*
* @param gauge the gauge to bribe for.
* @param elapsed elapsed time after last call; can be used to save gas.
* @return bribeTokens list of tokens to bribe
* @return deltaGauge same order as bribeTokens, the desired change of gauge balance
* @return deltaPool same order as bribeTokens, the desired change of pool balance
* @return deltaExternal same order as bribeTokens, the vault will pull this amount out from the bribe contract with transferFrom()
*/
function velocore__bribe(IGauge gauge, uint256 elapsed)
external
returns (
Token[] memory bribeTokens,
int128[] memory deltaGauge,
int128[] memory deltaPool,
int128[] memory deltaExternal
);
function bribeTokens(IGauge gauge) external view returns (Token[] memory);
function bribeRates(IGauge gauge) external view returns (uint256[] memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/BitMaps.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential.
* Largely inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].
*/
library BitMaps {
struct BitMap {
mapping(uint256 => uint256) _data;
}
/**
* @dev Returns whether the bit at `index` is set.
*/
function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
return bitmap._data[bucket] & mask != 0;
}
/**
* @dev Sets the bit at `index` to the boolean `value`.
*/
function setTo(
BitMap storage bitmap,
uint256 index,
bool value
) internal {
if (value) {
set(bitmap, index);
} else {
unset(bitmap, index);
}
}
/**
* @dev Sets the bit at `index`.
*/
function set(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] |= mask;
}
/**
* @dev Unsets the bit at `index`.
*/
function unset(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] &= ~mask;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC1155/ERC1155.sol)
pragma solidity ^0.8.0;
import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of the basic standard multi-token.
* See https://eips.ethereum.org/EIPS/eip-1155
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
*
* _Available since v3.1._
*/
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
// Mapping from token ID to account balances
mapping(uint256 => mapping(address => uint256)) private _balances;
// Mapping from account to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri;
/**
* @dev See {_setURI}.
*/
constructor(string memory uri_) {
_setURI(uri_);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256) public view virtual override returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: address zero is not a valid owner");
return _balances[id][account];
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
/**
* @dev Sets a new URI for all token types, by relying on the token type ID
* substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* By this mechanism, any occurrence of the `\{id\}` substring in either the
* URI or any of the amounts in the JSON file at said URI will be replaced by
* clients with the token type ID.
*
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
* interpreted by clients as
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
* for token type ID 0x4cce0.
*
* See {uri}.
*
* Because these URIs cannot be meaningfully represented by the {URI} event,
* this function emits no events.
*/
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
/**
* @dev Creates `amount` tokens of token type `id`, and assigns them to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
/**
* @dev Destroys `amount` tokens of token type `id` from `from`
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `amount` tokens of token type `id`.
*/
function _burn(
address from,
uint256 id,
uint256 amount
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
*/
function _burnBatch(
address from,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `ids` and `amounts` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `id` and `amount` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev _Available since v3.1._
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)
pragma solidity ^0.8.0;
import "../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*
* _Available since v3.1._
*/
interface IERC1155MetadataURI is IERC1155 {
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}{
"remappings": [
"@prb/test/=lib/prb-math/lib/prb-test/src/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"prb-math/=lib/prb-math/src/",
"prb-test/=lib/prb-math/lib/prb-test/src/",
"solmate/=lib/solmate/src/",
"lib/forge-std:ds-test/=lib/forge-std/lib/ds-test/src/",
"lib/openzeppelin-contracts-upgradeable:ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
"lib/openzeppelin-contracts-upgradeable:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"lib/openzeppelin-contracts-upgradeable:forge-std/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/src/",
"lib/openzeppelin-contracts-upgradeable:openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
"lib/prb-math:@prb/test/=lib/prb-math/lib/prb-test/src/",
"lib/prb-math:ds-test/=lib/prb-math/lib/forge-std/lib/ds-test/src/",
"lib/prb-math:forge-std/=lib/prb-math/lib/forge-std/src/",
"lib/prb-math:prb-test/=lib/prb-math/lib/prb-test/src/",
"lib/solmate:ds-test/=lib/solmate/lib/ds-test/src/"
],
"optimizer": {
"enabled": true,
"runs": 50
},
"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 IVC","name":"vc_","type":"address"},{"internalType":"Token","name":"ballot_","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IGauge","name":"gauge","type":"address"},{"indexed":true,"internalType":"contract IBribe","name":"bribe","type":"address"}],"name":"BribeAttached","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IGauge","name":"gauge","type":"address"},{"indexed":true,"internalType":"contract IBribe","name":"bribe","type":"address"}],"name":"BribeKilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IConverter","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"Token[]","name":"tokenRef","type":"bytes32[]"},{"indexed":false,"internalType":"int128[]","name":"delta","type":"int128[]"}],"name":"Convert","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"facetAddress","type":"address"},{"internalType":"enum VaultStorage.FacetCutAction","name":"action","type":"uint8"},{"internalType":"bytes4[]","name":"functionSelectors","type":"bytes4[]"}],"indexed":false,"internalType":"struct VaultStorage.FacetCut[]","name":"_diamondCut","type":"tuple[]"},{"indexed":false,"internalType":"address","name":"_init","type":"address"},{"indexed":false,"internalType":"bytes","name":"_calldata","type":"bytes"}],"name":"DiamondCut","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IGauge","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"Token[]","name":"tokenRef","type":"bytes32[]"},{"indexed":false,"internalType":"int128[]","name":"delta","type":"int128[]"}],"name":"Gauge","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IGauge","name":"gauge","type":"address"},{"indexed":false,"internalType":"bool","name":"killed","type":"bool"}],"name":"GaugeKilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract ISwap","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"Token[]","name":"tokenRef","type":"bytes32[]"},{"indexed":false,"internalType":"int128[]","name":"delta","type":"int128[]"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"Token[]","name":"tokenRef","type":"bytes32[]"},{"indexed":false,"internalType":"int128[]","name":"delta","type":"int128[]"}],"name":"UserBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IGauge","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"int256","name":"voteDelta","type":"int256"}],"name":"Vote","type":"event"},{"inputs":[{"internalType":"Token[]","name":"tokens","type":"bytes32[]"},{"internalType":"uint256[]","name":"balancesBefore","type":"uint256[]"}],"name":"balanceDelta","outputs":[{"internalType":"int128[]","name":"delta","type":"int128[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Token[]","name":"tokenRef","type":"bytes32[]"},{"internalType":"int128[]","name":"deposit","type":"int128[]"},{"components":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"bytes32[]","name":"tokenInformations","type":"bytes32[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct VelocoreOperation[]","name":"ops","type":"tuple[]"}],"name":"execute","outputs":[{"internalType":"int128[]","name":"","type":"int128[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"bribeIndex","type":"uint256"},{"internalType":"Token[]","name":"tokenRef","type":"bytes32[]"},{"internalType":"int128[]","name":"cumDelta","type":"int128[]"},{"internalType":"contract IGauge","name":"gauge","type":"address"},{"internalType":"uint256","name":"elapsed","type":"uint256"},{"internalType":"address","name":"user","type":"address"}],"name":"extort","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"initializeFacet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"Token[]","name":"tokenRef","type":"bytes32[]"},{"internalType":"int128[]","name":"deposit","type":"int128[]"},{"components":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"bytes32[]","name":"tokenInformations","type":"bytes32[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct VelocoreOperation[]","name":"ops","type":"tuple[]"}],"name":"query","outputs":[{"internalType":"int128[]","name":"","type":"int128[]"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60e0346200009d57601f6200439938819003918201601f19168301916001600160401b03831184841017620000a25780849260409485528339810103126200009d578051906001600160a01b03821682036200009d57602001519060805260a0523060c0526040516142e09081620000b982396080518181816128020152612933015260a05181611639015260c05181818161065d01526118b30152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604052600436101561001257600080fd5b6000803560e01c908163669a9d9d1461006a575080637a97f8cf14610065578063d3115a8a14610060578063ea8f29c81461005b5763fe8886651461005657600080fd5b610646565b610597565b6104eb565b610460565b60c03660031901126100e9576024356001600160401b038082116100ec57366023830112156100ec578160040135928184116100e9573660248560051b850101116100e9576044359182116100e957506100c890369060040161019c565b6100d0610215565b906100d9610224565b9360246084359401600435611ecb565b80fd5b8280fd5b634e487b7160e01b600052604160045260246000fd5b606081019081106001600160401b0382111761012157604052565b6100f0565b6001600160401b03811161012157604052565b604081019081106001600160401b0382111761012157604052565b90601f801991011681019081106001600160401b0382111761012157604052565b6001600160401b0381116101215760051b60200190565b80600f0b0361019757565b600080fd5b81601f82011215610197578035916101b383610175565b926101c16040519485610154565b808452602092838086019260051b820101928311610197578301905b8282106101eb575050505090565b83809183356101f98161018c565b8152019101906101dd565b6001600160a01b0381160361019757565b6064359061022282610204565b565b60a4359061022282610204565b81601f820112156101975780359161024883610175565b926102566040519485610154565b808452602092838086019260051b820101928311610197578301905b828210610280575050505090565b81358152908301908301610272565b6001600160401b03811161012157601f01601f191660200190565b81601f82011215610197578035906102c18261028f565b926102cf6040519485610154565b8284526020838301011161019757816000926020809301838601378301015290565b81601f820112156101975780359061030882610175565b92604061031781519586610154565b8385526020938486019185600592831b8601019484861161019757868101935b86851061034957505050505050505090565b6001600160401b03853581811161019757830191606080601f19858b0301126101975785519061037882610106565b8b8501358252868501358481116101975785018a603f8201121561019757808d80920135896103a682610175565b936103b382519586610154565b8285528401918c1b830101918d8311610197578f908b01915b8383106104045750915050830152840135928311610197576103f5898c809695819601016102aa565b86820152815201940193610337565b819083358152019101908f906103cc565b90815180825260208080930193019160005b828110610435575050505090565b8351600f0b85529381019392810192600101610427565b90602061045d928181520190610415565b90565b346101975760803660031901126101975760043561047d81610204565b6001600160401b036024358181116101975761049d903690600401610231565b91604435828111610197576104b690369060040161019c565b606435928311610197576104e7936104d56104db9436906004016102f1565b92610ba3565b6040519182918261044c565b0390f35b6060366003190112610197576001600160401b0360043581811161019757610517903690600401610231565b6024358281116101975761052f90369060040161019c565b604435928311610197576105896001916105506104e79536906004016102f1565b907f079bb613b46d8aca7a0fbe9d391ceb5913593f8825aa19f06db6024aa331ac7594610580600287541061080a565b60028655610905565b91556040519182918261044c565b34610197576040366003190112610197576001600160401b03600435818111610197576105c8903690600401610231565b60243591821161019757366023830112156101975781600401356105eb81610175565b926105f96040519485610154565b81845260209160248386019160051b8301019136831161019757602401905b82821061062c576104e76104db8787611cbf565b81358152908301908301610618565b600091031261019757565b34610197576000806003193601126100e9576107627f00000000000000000000000000000000000000000000000000000000000000006106846133f3565b5061068d612b43565b906106ab8361069b846108df565b516001600160a01b039091169052565b8460206106b7846108df565b5101526106c2612b98565b60406106cd846108df565b5101526106f56106e960406106e1856108df565b5101516108df565b636988ad4560e11b9052565b6001600160a01b038181161515906000805160206141eb833981519152908590836107b8575b811615948561079d575b61073460405192839283612bb2565b0390a18363d3115a8a1955610785575b501561076557610752612fb2565b505b61075d81613447565b613563565b80f35b61076d612cc1565b5061077f61077a82610d21565b612d47565b50610754565b61079161079691610d21565b6130c1565b5038610744565b6107b360206107ab836108df565b510160029052565b610725565b6107ce60206107c6886108df565b510160019052565b61071b565b634e487b7160e01b600052601160045260246000fd5b6000198101919082116107f857565b6107d3565b919082039182116107f857565b1561081157565b60405162461bcd60e51b815260206004820152600a6024820152695245454e5452414e435960b01b6044820152606490fd5b1561084a57565b60405162461bcd60e51b815260206004820152600f60248201526e6d616c666f726d656420617272617960881b6044820152606490fd5b1561019757565b9061089282610175565b61089f6040519182610154565b82815280926108b0601f1991610175565b0190602036910137565b60001981146107f85760010190565b634e487b7160e01b600052603260045260246000fd5b8051156108ec5760200190565b6108c9565b80518210156108ec5760209160051b010190565b8051928251841480610ac5575b61091b90610843565b61092681848461230f565b959192905060005b828110610a4e57506109489034610a1f575b8585336110d9565b60005b8181106109bd575050156109b7576109639051610888565b9160005b83518110156109b157806109a761099561098e6109876109ac95876108f1565b51876108f1565b51600f0b90565b61099f83886108f1565b90600f0b9052565b6108ba565b610967565b50505090565b50905090565b80600180920160051b80870151600f9080820b9182156000146109e557505050505b0161094b565b6000831315610a05575050610a009187015133903090613d4f565b6109df565b909150610a009288015191600003900b9030903390614177565b610a49610a2b866137cb565b610a3c610a3734610b3c565b610b2c565b90889060010160051b0152565b610940565b80600180920160051b80880151600f0b90610a6c6000831215610881565b60008213610a7d575b50500161092e565b610aa3610a97610abe93610ab2938b01513090339061414a565b6001600160801b031690565b6001600160801b0316600f0b90565b6001830160051b890152565b3880610a75565b506101008410610912565b15610ad757565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b9061022282600f0b928314610ad0565b6001600160ff1b038111610b4d5790565b60405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608490fd5b9392600192610be4927f079bb613b46d8aca7a0fbe9d391ceb5913593f8825aa19f06db6024aa331ac7596610bdb600289541061080a565b60028855610be8565b9255565b9290928351835181149081610c88575b5015610c5157610c198284610c0f8795828761230f565b98919590506110d9565b156109b757610c289051610888565b9160005b83518110156109b157806109a761099561098e610987610c4c95876108f1565b610c2c565b60405162461bcd60e51b815260206004820152600f60248201526e1b585b199bdc9b5959081a5b9c1d5d608a1b6044820152606490fd5b61010091501038610bf8565b15610c9b57565b60405162461bcd60e51b81526020600482015260076024820152667369707061676560c81b6044820152606490fd5b15610cd157565b60405162461bcd60e51b815260206004820152602260248201527f796f752063616e2774207769746864726177206f7468657227732062616c616e604482015261636560f01b6064820152608490fd5b6001600160a01b031660009081527f643b8a6b3ed8752748bc6461fd4a02b0c30db5660ff05b0028ccebefb6b5f2636020526040902090565b6001600160a01b031660009081527f7d9b04b9e52f7a4e4f7cdff570205d7c27d6f7283dab59d340ff6676d10571b66020526040902090565b6001600160a01b031660009081527fe35cc21d37873d362c6d20195c3a1c72fa511d9573329821aa68d4bc28c9e7b86020526040902090565b6001600160a01b031660009081526000805160206141ab8339815191526020526040902090565b9060018060a01b0316600052602052604060002090565b919091600083820193841291129080158216911516176107f857565b600f91820b910b039060016001607f1b0319821260016001607f1b038313176107f857565b90815180825260208080930193019160005b828110610e6b575050505090565b835185529381019392810192600101610e5d565b9091610e9661045d93604084526040840190610e4b565b916020818403910152610415565b9496959192610ec760a09594610ed593885260c0602089015260c0880190610e4b565b908682036040880152610415565b95600180851b038093166060860152608085015216910152565b919082519283825260005b848110610f1b575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201610efa565b92610f5761045d9593610f659360018060a01b03168652608060208701526080860190610e4b565b908482036040860152610415565b916060818403910152610eef565b6040513d6000823e3d90fd5b81601f8201121561019757805191610f9683610175565b92610fa46040519485610154565b808452602092838086019260051b820101928311610197578301905b828210610fce575050505090565b8380918351610fdc8161018c565b815201910190610fc0565b906020828203126101975781516001600160401b0381116101975761045d9201610f7f565b9061101f90604083526040830190610e4b565b81810360209283015282518082529082019282019160005b828110611045575050505090565b835185529381019392810192600101611037565b600f0b60016001607f1b031981146107f85760000390565b600f91820b910b019060016001607f1b0319821260016001607f1b038313176107f857565b919091604081840312610197578051926001600160401b039384811161019757816110c2918401610f7f565b9360208301519081116101975761045d9201610f7f565b91939290600091825b8151811015611bcc576110f581836108f1565b5160208101519081519061110882610888565b92839161111484610888565b9160005b858110611adc57508a8251938460001a801560001461125f57506040938401518451631d86f10160e31b815296879361115693919060048601610f2f565b6001600160a01b0394851696916000918791900381838a5af191821561125a57878f88906000988996611228575b5092859289926111a695878551148061121e575b6111a190610881565b612a70565b60005b8181106111fa57505050917fbaec78ca3218aba6fc32d82b79acdd1a47663d7b8da46e0c00947206d08f2071916111ed6111f597969594519283928d169683610e7f565b0390a36108ba565b6110e2565b80611218610ab2600180940160051b80870151908a015101600f0b90565b016111a9565b5085518814611198565b6111a69492965061124c9193993d8091833e6112448183610154565b810190611096565b909890959193909290611184565b610f73565b90955090506001810361138e5750891561137c575b6001600160a01b0392831694611289866128ed565b6000878d6112b06040809701518751998a948594631072ff1f60e11b865260048601610f2f565b0381838a5af191821561125a57878f88906000988996611352575b5092859289926112e795878551148061121e576111a190610881565b60005b81811061132e57505050917fded5415ee05ea676deae44e3fdba7daa1ec0c86fed40cc0d0fa9908a98baa168916111ed6111f597969594519283928d169683610e7f565b8061134c610ab2600180940160051b80870151908a015101600f0b90565b016112ea565b6112e79492965061136e9193993d8091833e6112448183610154565b9098909591939092906112cb565b98506113866127cf565b600198611274565b939490936002908082036115b25750506113a781610888565b6001600160a01b039384169590949060005b838110611537575060408094015190873b156101975760008e918a6113f3885195869384936313c679ff60e01b8552600497888601610f2f565b0381838c5af190811561125a576000928a9261151e575b5061142686519889938493631d51e53960e31b8552840161100c565b038183305af194851561125a576000956114fb575b5060008e5b8382106114855750505050917f613a0b8d7d8bf2705187bfe8332a743e6bbffa1e4f8bafec7b6f0ed8fca59201916111ed6111f597969594519283928d169683610e7f565b906109a7610ab26114f5936114ef6001850160051b9161099f838d01936114cd6114af8651611059565b918b0151916001600160801b038316600f90810b91900b1315610881565b6114e985519160f81c916114e461098e84876108f1565b611071565b926108f1565b51611059565b8e611440565b61151791953d8091833e61150f8183610154565b810190610fe7565b933861143b565b8061152b61153192610126565b8061063b565b3861140a565b806001611594920160051b808b019061156061155430845161392a565b6001850160051b8c0152565b8401518a81600f0b60008113908115916115a1575b506115995791516109a7926001600160801b0390921691903090613d4f565b6113b9565b5050506108ba565b60016001607f1b0314905038611575565b90939694925060038114600014611925575050508715611913575b6115df6001600160a01b0385166128ed565b6115f16001600160a01b038516610d93565b9063ffffffff9081611607845463ffffffff1690565b16156118f9575b8161161d845463ffffffff1690565b1660018111611809575b505050906111f5949392918b8a61165f7f0000000000000000000000000000000000000000000000000000000000000000809561385e565b60009590600181016116b7575b5050604051600f9590950b85525050506001600160a01b038981169316917f79a02325cb94513a3505278348f98ec59be59bfe1bd80376ae39c5917247463f915080602081016111ed565b60010160051b01519450919290919089600f86810b60016001607f1b03146117fb5761098e6117dd6117e99489946117e4946117d761099f996117d1610a976117886117f09f60018161175e8f61173961173461173e9261172b61171f611734995460901c90565b6001600160701b031690565b9d0b809d610e0a565b611c70565b611c07565b82546001600160901b031660909190911b6001600160901b031916178255565b6000805160206141cb833981519152546117bf9061178d9061178890611734908d9060801c610e0a565b611bee565b6000805160206141cb83398151915280546001600160801b031660809290921b6001600160801b031916919091179055565b01966117cb8689610df3565b54610e0a565b92610df3565b5561385e565b80966108f1565b610e26565b918d6108f1565b38808b8a828061166c565b5050505050505060006117f0565b61181390426107fd565b908161184c575b5050906118406111f596959493924216829063ffffffff1663ffffffff19825416179055565b90919293943880611627565b8301549060008e8b8e5b858410611866575050505061181a565b60008b866118af6118df9796956118a185966040519485938a602086019863669a9d9d60e01b8a5260018060a01b0316918d60248801610ea4565b03601f198101835282610154565b51907f00000000000000000000000000000000000000000000000000000000000000005af46118e7575b506108ba565b8e8b8e611856565b60006020825160051b92013e8f6118d9565b825463ffffffff191663ffffffff4284161617835561160e565b965061191d6127cf565b6001966115cd565b9195949392509060048103611a6c57506001600160a01b038a81169594169385851460008e5b84821061198f5750505050506111f5949392917f953ae389afac40aac3257d935e810a67594cd53c82841043b9cb722af8189a5c916111ed60405192839283610e7f565b906109a7611a49926119f26117348a6119ec6119e661098e8f6119df8f6119d08c8f81956119cb82848d6114e9959215611a4f575b5050610cca565b610d5a565b51600052602052604060002090565b54946108f1565b600f0b90565b90610e0a565b611a086119fe8c610d5a565b6119d0868c6108f1565b5561099f611a1961098e858c6108f1565b6114e9611a3b611a35611a356001890160051b8c015160f81c90565b60ff1690565b916117e461098e84876108f1565b8e61194b565b60009250611a609161098e916108f1565b600f0b1215848d6119c4565b92509392505060058091146000146101975760005b838110611a9557505050506111f5906108ba565b80611ad68c611ac46119e6611abb61098e6001809801891b8a0151948560f81c906108f1565b600003600f0b90565b90848060801b0316600f0b1215610c94565b01611a81565b600191929394508d828b600592828501841b938488015193611b158d8887841a94848960001a01901b80970151919060010160051b0152565b81611b455750505050611b3a9150838060801b0316600f0b82879060010160051b0152565b019085939291611118565b92935090918103611b7157505060016001607f1b036001840160051b88015250611b6c9050565b611b3a565b60028103611b8c575001516001830160051b87015250611b3a565b90506003915014611b9e575b50611b3a565b611bba6119e6611bb5611bc6938b0151309061392a565b611bd5565b6001830160051b870152565b38611b98565b50505050509050565b60026001607f1b0380821015611be9575090565b905090565b6001600160801b0390611c0382821115610ad0565b1690565b6001600160701b0390818111611c1b571690565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663132206269747360c81b6064820152608490fd5b60008112611c7b5790565b606460405162461bcd60e51b815260206004820152602060248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152fd5b919091611ccc8151610888565b600090815b8351811015611d62576001810160051b90818501611d04611cfb611cf630845161392a565b610b3c565b93890151610b3c565b928584820394128185128116918513901516176107f857611d27611d4a93610b2c565b611d388184879060010160051b0152565b600f0b858113611d4f575b50506108ba565b611cd1565b611d5b91309051613baa565b3880611d43565b5093505050565b91608083830312610197578251906001600160401b03918281116101975784019383601f86011215610197578451611da081610175565b90611dae6040519283610154565b808252602096878084019260051b820101918783116101975788809201905b838210611e1f5750505050948101518381116101975784611def918301610f7f565b9360408201518481116101975781611e08918401610f7f565b9360608301519081116101975761045d9201610f7f565b81518152908201908201611dcd565b6001600160a01b039091168152602081019190915260400190565b600160ff1b81146107f85760000390565b90670de0b6b3a7640000918281029281840414901517156107f857565b90633b9aca0091808302928304036107f857565b818102929181159184041417156107f857565b8115611ea8570490565b634e487b7160e01b600052601260045260246000fd5b919082018092116107f857565b611eeb611ef79197969295979493946002611ee58a610d93565b016121d4565b6001600160a01b031690565b60405163376fc5bf60e01b81526001600160a01b03808316969193909260009291600490849087908190611f2e908f868401611e2e565b0381838d5af193841561125a57808093819882976121a2575b50611f648351865181149081612197575b8161218c575b50610881565b815b835181101561218157808f8f928f8f928f928f918f918f918f918f918f918f91908f918f908f9b6001998a850160051b80990198808a51611fa790600f0b90565b9e019d8e51611fb690600f0b90565b611fbf91610e0a565b90808301918251611fd090600f0b90565b611fd991610e0a565b611fe290611e49565b611feb90611c70565b9801519d8e9a8b98611fff8a998a966108f1565b51600f0b600f0b131561201190610881565b51905191519261202094612711565b61202990610d93565b9485019061203691610df3565b60009182526020526040902096835461204f9060901c90565b6001600160701b03161561214657505061208261206e61208992611e5a565b61207c61171f855460901c90565b90611e9e565b8654611ebe565b85555b8684865496019461209d8287610df3565b546120a890886107fd565b9201906120b491610df3565b546120be91611e8b565b670de0b6b3a76400009004976120d392613732565b936120dd91610df3565b5561211095600019831461211557505061099f906114e9612103610a376109a796610b3c565b6114e461098e84876108f1565b611f66565b61213f9350612137925061212890610d5a565b90600052602052604060002090565b918254611ebe565b90556108ba565b90612128612176927f8f688873691912f8fe135293a1e4047b82cd30dddf57571cb75b40a636c8f5d65416610d5a565b90815401905561208c565b8a5160051b60208c01f35b905088511438611f5e565b8b5181149150611f58565b9250955092506121c59196503d8084833e6121bd8183610154565b810190611d69565b97929390939193979538611f47565b906121de9161221a565b905460039190911b1c6001600160a01b031690565b60008051602061426b83398151915280548210156108ec5760005260206000200190600090565b80548210156108ec5760005260206000200190600090565b1561223957565b60405162461bcd60e51b815260206004820152601060248201526f323ab83634b1b0ba32b2103a37b5b2b760811b6044820152606490fd5b1561227857565b60405162461bcd60e51b815260206004820152602560248201527f6475706c69636174656420746f6b656e20696e2056656c6f636f72654f70657260448201526430ba34b7b760d91b6064820152608490fd5b156122d257565b60405162461bcd60e51b81526020600482015260156024820152743a37b5b2b7103737ba1034b7103a37b5b2b72932b360591b6044820152606490fd5b919261231b8351610888565b926123268151610888565b926000958683519282519460015b85811061256557505050612533575b60005b8381106123535750505050565b602061235f82846108f1565b5101518381519160005b8381106123a557509161238c91600194938215928315612392575b5050506122cb565b01612346565b60051b015160001a109050853880612384565b9091508a15612524576001810160051b8201516123f36123e66123d66123cf8d8560001a906108f1565b5160ff1690565b60f81b6001600160f81b03191690565b6001600160f81b03191690565b6001600160f81b03909116176001820160051b83018190525b816001831015806124fd575b61242a575b5050600101908591612369565b929a919b9396949597999890995b836001811015806124d6575b1561246b578c6124669160001901958060051b820151919060010160051b0152565b612438565b6001939c94509a6124a29199979698959d929a9b806000198751011480156124a9575b61249790612271565b60010160051b850152565b903861241d565b506124976002820160051b87015160001a60ff60f81b60f891818660001a841b16921b161415905061248e565b508b8d60ff60f81b908360051b015160001a8160f891821b169260001a901b161115612444565b5060ff60f81b8360051b85015160001a908060f892831b16918460001a901b161115612418565b6001810160051b82015161240c565b60005b8281106125435750612343565b8061255f81600180940160051b8a0151899060010160051b0152565b01612536565b9091925061257a81808b9060010160051b0152565b6001810160051b80830151906125968360051b85015183111590565b6125a9575b505060010190899291612334565b869b50840151908a83918560019e8f805b61262a575b5095848196946125f9856125ed61260496859861260f9b60019e6000190114918215612616575b5050612232565b6001840160051b8c0152565b9060010160051b0152565b60010160051b860152565b903861259b565b6002880160051b015114159050828e6125e6565b92939491505080878b84831015806126a2575b156126965750509061268b91600019019461267b8260051b9161266a838c0151858d9060010160051b0152565b8383820151919060010160051b0152565b89015190899060010160051b0152565b908589838f946125ba565b919594939092506125bf565b506126b38360051b83015187111590565b61263d565b906040929160018060a01b0316936126fe6000938685526000805160206141ab83398151915292836020528686208587526020528686205490600f0b91600f0b90613707565b9483526020528282209082526020522055565b93919392909260018060a01b03169061275a6000958387526000805160206141ab833981519152928360205260408820878952602052604088205490600f0b91600f0b90613707565b908286526020526040852084865260205260408520558382600f0b12612781575b50505050565b61278d61279a92611059565b600f0b928391309161414a565b106100e95780808061277b565b90816020910312610197575190565b6001600160801b0391821690821601919082116107f857565b6000805160206141cb833981519152805460801c6127ea5750565b60405163056d8d4d60e11b81529060208260048160007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af191821561125a576000926128a4575b5081612845575050565b6102229161286761178861285d612876945493611e77565b8360801c90611e9e565b906001600160801b03166127b6565b6000805160206141cb83398151915280546001600160801b0319166001600160801b03909216919091179055565b6128c691925060203d81116128cd575b6128be8183610154565b8101906127a7565b903861283b565b503d6128b4565b6001600160801b0391821690821603919082116107f857565b600163ffffffff61290a61290084610d93565b5463ffffffff1690565b16036129b9576000905b61291d81610dcc565b9060018060a01b039161297461296a85612964867f000000000000000000000000000000000000000000000000000000000000000016809590600052602052604060002090565b54613676565b9161212884610dcc565b5516803b1561019757604051620f038760eb1b815260048101929092526000908290602490829084905af1801561125a576129ac5750565b8061152b61022292610126565b6000805160206141cb8339815191525490612a6b612a2d612a23612a07610a976129f861171f6129e888610d93565b5460201c6001600160701b031690565b6001600160801b0388166128d4565b612a1d61171f612a1687610d93565b5460901c90565b90611e8b565b633b9aca00900490565b926001600160701b0316612a4083610d93565b8054640100000000600160901b03191660209290921b640100000000600160901b0316919091179055565b612914565b9194928551946000805b878110612a8c57505050505050505050565b6001810160051b90818401518289015192612aa78483611071565b8782018051919590916001600160801b0316600f90810b9087900b13612b0557612b00956117e48f61099f94612aef8f97958f996109a79a612af99861098e960151906126b8565b518a1a80966108f1565b918a6108f1565b612a7a565b60405162461bcd60e51b81526020600482015260166024820152750e8ded6cadc40e4cae6ead8e840c2c4deecca40dac2f60531b6044820152606490fd5b604090815191612b5283610139565b600183528291600091825b602080821015612b8f57825160209291612b7682610106565b8682528681830152606085830152828901015201612b5d565b50505091925050565b60405190612ba582610139565b6001825260203681840137565b929192606091828201838352815180915260809384840191858160051b860101956020809501936000915b838310612c155750505050505061045d9394612c029183019060018060a01b03169052565b6040818303910152602090600081520190565b909192939497607f198882030183528851908681019060018060a01b038351168152888301516003811015612cab5784828b9594939286809401528a604080960151958201528451809452019201906000905b808210612c875750505090806001929a01930193019194939290612bdd565b82516001600160e01b03191684528a94938401939092019160019190910190612c68565b634e487b7160e01b600052602160045260246000fd5b636988ad4560e11b600081815260008051602061422b833981519152602081905260008051602061424b83398151915254909190612d415760008051602061426b83398151915280549290600160401b84101561012157600184018082558410156108ec5784604094828552602085200155549382526020522055600190565b91505090565b60018101636988ad4560e11b91826000528160205260406000205415600014612db0578054600160401b81101561012157806001612d88920183558261221a565b81549060031b9085821b91600019901b19161790555491600052602052604060002055600190565b505050600090565b637a97f8cf60e01b600081815260008051602061422b833981519152602081905260008051602061428b83398151915254909190612d415760008051602061426b83398151915280549290600160401b84101561012157600184018082558410156108ec5784604094828552602085200155549382526020522055600190565b60018101637a97f8cf60e01b91826000528160205260406000205415600014612db0578054600160401b81101561012157806001612d88920183558261221a565b631d51e53960e31b600081815260008051602061422b833981519152602081905260008051602061420b83398151915254909190612d415760008051602061426b83398151915280549290600160401b84101561012157600184018082558410156108ec5784604094828552602085200155549382526020522055600190565b60018101631d51e53960e31b91826000528160205260406000205415600014612db0578054600160401b81101561012157806001612d88920183558261221a565b60008051602061426b8339815191528054908115612f72576000198281019290818410156108ec576000918383526020832001015555565b634e487b7160e01b600052603160045260246000fd5b8054908115612f725760001991820191612fa2838361221a565b909182549160031b1b1916905555565b636988ad4560e11b60005260008051602061422b83398151915260205260008051602061424b8339815191525480156130bb576000198181018281116107f85760008051602061426b833981519152549182019182116107f857808203613054575b50505061301f612f3a565b636988ad4560e11b600090815260008051602061422b83398151915260205260008051602061424b8339815191525b55600190565b61309561307c9161307461306a6130b2956121f3565b90549060031b1c90565b9283916121f3565b90919082549060031b91821b91600019901b1916179055565b60005260008051602061422b833981519152602052604060002090565b55388080613014565b50600090565b636988ad4560e11b600090815260018201602081905260409091205491908215612db05760001991838301908482116107f85780549384019384116107f857600094848361311b9461304e9703613131575b505050612f88565b636988ad4560e11b600052602052604060002090565b61315161307c9161314861306a613161958861221a565b9283918761221a565b8590600052602052604060002090565b55388080613113565b637a97f8cf60e01b600090815260018201602081905260409091205491908215612db05760001991838301908482116107f85780549384019384116107f85760009484836131c39461304e97036131d957505050612f88565b637a97f8cf60e01b600052602052604060002090565b61315161307c916131ed613161948761221a565b90549060031b1c9283918761221a565b637a97f8cf60e01b60005260008051602061422b83398151915260205260008051602061428b8339815191525480156130bb576000198181018281116107f85760008051602061426b833981519152549182019182116107f85780820361329d575b50505061326a612f3a565b637a97f8cf60e01b600090815260008051602061422b83398151915260205260008051602061428b83398151915261304e565b61309561307c916132b06132bf946121f3565b90549060031b1c9283916121f3565b5538808061325f565b631d51e53960e31b600090815260018201602081905260409091205491908215612db05760001991838301908482116107f85780549384019384116107f85760009484836133219461304e97036131d957505050612f88565b631d51e53960e31b600052602052604060002090565b631d51e53960e31b60005260008051602061422b83398151915260205260008051602061420b8339815191525480156130bb576000198181018281116107f85760008051602061426b833981519152549182019182116107f8578082036133d7575b5050506133a4612f3a565b631d51e53960e31b600090815260008051602061422b83398151915260205260008051602061420b83398151915261304e565b61309561307c916132b06133ea946121f3565b55388080613399565b63d3115a8a195490600090600160a01b83101561340c57565b91199160019150565b637a97f8cf195490600090600160a01b83101561340c57565b63ea8f29c8195490600090600160a01b83101561340c57565b61344f613415565b50613458612b43565b906134668361069b846108df565b60006020613473846108df565b51015261347e612b98565b6040613489846108df565b5101526134a961349d60406106e1856108df565b637a97f8cf60e01b9052565b6001600160a01b038181161515906000805160206141eb83398151915290859083613550575b811615948561353d575b6134e860405192839283612bb2565b0390a18319637a97f8cf1955613525575b501561350b57506135086131fd565b50565b6135206135089161351a612db8565b50610d21565b612e38565b61353161353691610d21565b61316a565b50386134f9565b61354b60206107ab836108df565b6134d9565b61355e60206107c6886108df565b6134cf565b61356b61342e565b50613574612b43565b906135828361069b846108df565b6000602061358f846108df565b51015261359a612b98565b60406135a5846108df565b5101526135c56135b960406106e1856108df565b631d51e53960e31b9052565b6001600160a01b038181161515906000805160206141eb83398151915290859083613663575b8116159485613650575b61360460405192839283612bb2565b0390a1831963ea8f29c81955613638575b50156136245750613508613337565b6136336135089161351a612e79565b612ef9565b61364461364991610d21565b6132c8565b5038613615565b61365e60206107ab836108df565b6135f5565b61367160206107c6886108df565b6135eb565b90611734613687918360801c610e0a565b6001600160801b03918216600081128015166107f8576136a690611c70565b9180831680931490816136fb575b50156136cb5760801b6001600160801b0319161790565b60405162461bcd60e51b81526020600482015260086024820152676f766572666c6f7760c01b6044820152606490fd5b905081168114386136b4565b919061173461371f6117346136a6938660801c610e0a565b6001600160801b03949093908516610e0a565b909182156137c257600090600019938481019081116107f85793929193905b8185111561376157505050905090565b6001858303811c860180968160051b86013584811460001461378857505050505050505090565b879850938095969791929394106000146137a9575050015b93929190613751565b9250935080156137ba5701916137a0565b505050505090565b50505060001990565b8051908115613856576137df6000926107e9565b905b818311156137f25750505060001990565b600192808303841c8101938401908160051b83015160008051602061418b8339815191529081811460001461382a5750505050505090565b959192939495106000146138425750505b91906137e1565b9150925080156137c257600019019161383b565b505060001990565b80519182156137c257906138736000936107e9565b905b81841115613887575050505060001990565b600192848303841c85019485948601908160051b840151968388146000146138b457505050505050905090565b9193955091809496106000146138cf5750505b929091613875565b9150935080156138e35760001901926138c7565b5050505060001990565b90816020910312610197575161045d81610204565b60609060208152600d60208201526c34b73b30b634b2103a37b5b2b760991b60408201520190565b6001600160f81b03198116806139bd57506139869160209161395960a082901c6001600160581b031615610881565b6040516370a0823160e01b81526001600160a01b0390921660048301529092839190829081906024820190565b03916001600160a01b03165afa90811561125a576000916139a5575090565b61045d915060203d81116128cd576128be8183610154565b600160f91b81036139fb5750604051627eeac760e11b8152916020918391829081906139869060a085901c6001600160581b03169060048401611e2e565b600160f81b03613a92576040516331a9108f60e11b81526001600160581b0360a083901c166004820152906001600160a01b03906020908390602490829085165afa91821561125a57600092613a62575b508060009316911614600014611a355750600190565b613a8491925060203d8111613a8b575b613a7c8183610154565b8101906138ed565b9038613a4c565b503d613a72565b60008051602061418b83398151915214613ac35760405162461bcd60e51b815280613abf60048201613902565b0390fd5b3190565b15613ace57565b60405162461bcd60e51b815260206004820152600e60248201526d1a5b9d985b1a5908185b5bdd5b9d60921b6044820152606490fd5b6001600160a01b03909116815263deadbeef6020820152604081019190915260600190565b6001600160a01b03918216815291166020820152604081019190915260600190565b15613b5257565b60405162461bcd60e51b815260206004820152602a60248201527f6e617469766520746f6b656e207472616e7366657246726f6d206973206e6f74604482015269081cdd5c1c1bdc9d195960b21b6064820152608490fd5b91906001600160f81b0319831680613bfc5750613bd460a084901c6001600160581b031615610881565b6001600160a01b03908082163003613bf157506102229216613eca565b906102229316613f4c565b60008051602061418b8339815191528492939414600014613c445750613c2e916001600160a01b031630149050613b4b565b6000808080809463deadbeef5af1156100e95750565b91929091600160f81b8103613cb957506001613c609114613ac7565b6001600160a01b03811691823b1561019757604051632142170760e11b8152926000928492839185918391613ca89160a09190911c6001600160581b03169060048401613b04565b03925af1801561125a576129ac5750565b600160f91b03613d36576001600160a01b038216803b1561019757604051637921219560e11b81526001600160a01b03909416600485015263deadbeef602485015260a092831c6001600160581b0316604485015260648401919091526084830191909152600060a4830181905290829081838160c48101613ca8565b60405162461bcd60e51b815280613abf60048201613902565b9291906001600160f81b0319841680613da25750613d7a60a085901c6001600160581b031615610881565b6001600160a01b03908082163003613d9757506102229316613f12565b906102229416613f73565b60008051602061418b833981519152859293949514600014613de75750613dd5916001600160a01b031630149050613b4b565b60008080809481945af1156100e95750565b92939092600160f81b8103613e4b57506001613e039114613ac7565b6001600160a01b038216803b1561019757604051632142170760e11b8152936000938593849286928492613ca89260a09290921c6001600160581b0316919060048501613b29565b909390600160f91b03613d36576001600160a01b03831690813b1561019757604051637921219560e11b81526001600160a01b0393841660048201529216602483015260a092831c6001600160581b0316604483015260648201939093526084810191909152600060a482018190529091829081838160c48101613ca8565b906040519063a9059cbb60e01b602083015263deadbeef602483015260448201526044815260808101918183106001600160401b038411176101215761022292604052613ffa565b613f476102229392613f3960405194859263a9059cbb60e01b602085015260248401611e2e565b03601f198101845283610154565b613ffa565b613f476102229392613f396040519485926323b872dd60e01b602085015260248401613b04565b90613f4790613f39610222956040519586936323b872dd60e01b602086015260248501613b29565b15613fa257565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608490fd5b60018060a01b031661407660405161401181610139565b6020928382527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564848301526000808686829851910182855af13d156140ad573d9161405b8361028f565b926140696040519485610154565b83523d878785013e6140b1565b8051806140835750505050565b818391810103126100ec5701519081151582036100e957506140a490613f9b565b3880808061277b565b6060915b9192901561411357508151156140c5575090565b3b156140ce5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156141265750805190602001fd5b60405162461bcd60e51b815260206004820152908190613abf906024830190610eef565b61416561416a9392948361415e818561392a565b9684613d4f565b61392a565b9081039081116107f85790565b9183916141839361414a565b106101975756feeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee41cdc826884889a9d86ce2ed24c534af045774747691a4897641494ae5dd896be35cc21d37873d362c6d20195c3a1c72fa511d9573329821aa68d4bc28c9e7b78faa70878671ccd212d20771b795c50af8fd3ff6cf27f4bde57e5d4de0aeb6734820e2cd0662908c357e2fb320164dcb72822080d1ebe5c73f3fcb31f7680cb3643b8a6b3ed8752748bc6461fd4a02b0c30db5660ff05b0028ccebefb6b5f262bab7550cdc7b21dbbee8fdbbc70303a61ab056018f92c3a9256fa6502aa8e167643b8a6b3ed8752748bc6461fd4a02b0c30db5660ff05b0028ccebefb6b5f26115187d60e1e9a8d1ffcf993b3a6f69d8b9d84a727170945ca56b329bc0ea506fa26469706673582212209a33787c80ccdb01893065a949f63fe8b665ec11963fee4dc5f2a01f47fcacaa64736f6c63430008130033000000000000000000000000cc22f6aa610d1b2a0e89ef228079cb3e1831b1d1000000000000000000000000aec06345b26451bda999d83b361beaad6ea93f87
Deployed Bytecode
0x6080604052600436101561001257600080fd5b6000803560e01c908163669a9d9d1461006a575080637a97f8cf14610065578063d3115a8a14610060578063ea8f29c81461005b5763fe8886651461005657600080fd5b610646565b610597565b6104eb565b610460565b60c03660031901126100e9576024356001600160401b038082116100ec57366023830112156100ec578160040135928184116100e9573660248560051b850101116100e9576044359182116100e957506100c890369060040161019c565b6100d0610215565b906100d9610224565b9360246084359401600435611ecb565b80fd5b8280fd5b634e487b7160e01b600052604160045260246000fd5b606081019081106001600160401b0382111761012157604052565b6100f0565b6001600160401b03811161012157604052565b604081019081106001600160401b0382111761012157604052565b90601f801991011681019081106001600160401b0382111761012157604052565b6001600160401b0381116101215760051b60200190565b80600f0b0361019757565b600080fd5b81601f82011215610197578035916101b383610175565b926101c16040519485610154565b808452602092838086019260051b820101928311610197578301905b8282106101eb575050505090565b83809183356101f98161018c565b8152019101906101dd565b6001600160a01b0381160361019757565b6064359061022282610204565b565b60a4359061022282610204565b81601f820112156101975780359161024883610175565b926102566040519485610154565b808452602092838086019260051b820101928311610197578301905b828210610280575050505090565b81358152908301908301610272565b6001600160401b03811161012157601f01601f191660200190565b81601f82011215610197578035906102c18261028f565b926102cf6040519485610154565b8284526020838301011161019757816000926020809301838601378301015290565b81601f820112156101975780359061030882610175565b92604061031781519586610154565b8385526020938486019185600592831b8601019484861161019757868101935b86851061034957505050505050505090565b6001600160401b03853581811161019757830191606080601f19858b0301126101975785519061037882610106565b8b8501358252868501358481116101975785018a603f8201121561019757808d80920135896103a682610175565b936103b382519586610154565b8285528401918c1b830101918d8311610197578f908b01915b8383106104045750915050830152840135928311610197576103f5898c809695819601016102aa565b86820152815201940193610337565b819083358152019101908f906103cc565b90815180825260208080930193019160005b828110610435575050505090565b8351600f0b85529381019392810192600101610427565b90602061045d928181520190610415565b90565b346101975760803660031901126101975760043561047d81610204565b6001600160401b036024358181116101975761049d903690600401610231565b91604435828111610197576104b690369060040161019c565b606435928311610197576104e7936104d56104db9436906004016102f1565b92610ba3565b6040519182918261044c565b0390f35b6060366003190112610197576001600160401b0360043581811161019757610517903690600401610231565b6024358281116101975761052f90369060040161019c565b604435928311610197576105896001916105506104e79536906004016102f1565b907f079bb613b46d8aca7a0fbe9d391ceb5913593f8825aa19f06db6024aa331ac7594610580600287541061080a565b60028655610905565b91556040519182918261044c565b34610197576040366003190112610197576001600160401b03600435818111610197576105c8903690600401610231565b60243591821161019757366023830112156101975781600401356105eb81610175565b926105f96040519485610154565b81845260209160248386019160051b8301019136831161019757602401905b82821061062c576104e76104db8787611cbf565b81358152908301908301610618565b600091031261019757565b34610197576000806003193601126100e9576107627f0000000000000000000000002e98ef87f7f0d31987a0d94051b8bc5d001152e86106846133f3565b5061068d612b43565b906106ab8361069b846108df565b516001600160a01b039091169052565b8460206106b7846108df565b5101526106c2612b98565b60406106cd846108df565b5101526106f56106e960406106e1856108df565b5101516108df565b636988ad4560e11b9052565b6001600160a01b038181161515906000805160206141eb833981519152908590836107b8575b811615948561079d575b61073460405192839283612bb2565b0390a18363d3115a8a1955610785575b501561076557610752612fb2565b505b61075d81613447565b613563565b80f35b61076d612cc1565b5061077f61077a82610d21565b612d47565b50610754565b61079161079691610d21565b6130c1565b5038610744565b6107b360206107ab836108df565b510160029052565b610725565b6107ce60206107c6886108df565b510160019052565b61071b565b634e487b7160e01b600052601160045260246000fd5b6000198101919082116107f857565b6107d3565b919082039182116107f857565b1561081157565b60405162461bcd60e51b815260206004820152600a6024820152695245454e5452414e435960b01b6044820152606490fd5b1561084a57565b60405162461bcd60e51b815260206004820152600f60248201526e6d616c666f726d656420617272617960881b6044820152606490fd5b1561019757565b9061089282610175565b61089f6040519182610154565b82815280926108b0601f1991610175565b0190602036910137565b60001981146107f85760010190565b634e487b7160e01b600052603260045260246000fd5b8051156108ec5760200190565b6108c9565b80518210156108ec5760209160051b010190565b8051928251841480610ac5575b61091b90610843565b61092681848461230f565b959192905060005b828110610a4e57506109489034610a1f575b8585336110d9565b60005b8181106109bd575050156109b7576109639051610888565b9160005b83518110156109b157806109a761099561098e6109876109ac95876108f1565b51876108f1565b51600f0b90565b61099f83886108f1565b90600f0b9052565b6108ba565b610967565b50505090565b50905090565b80600180920160051b80870151600f9080820b9182156000146109e557505050505b0161094b565b6000831315610a05575050610a009187015133903090613d4f565b6109df565b909150610a009288015191600003900b9030903390614177565b610a49610a2b866137cb565b610a3c610a3734610b3c565b610b2c565b90889060010160051b0152565b610940565b80600180920160051b80880151600f0b90610a6c6000831215610881565b60008213610a7d575b50500161092e565b610aa3610a97610abe93610ab2938b01513090339061414a565b6001600160801b031690565b6001600160801b0316600f0b90565b6001830160051b890152565b3880610a75565b506101008410610912565b15610ad757565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b9061022282600f0b928314610ad0565b6001600160ff1b038111610b4d5790565b60405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608490fd5b9392600192610be4927f079bb613b46d8aca7a0fbe9d391ceb5913593f8825aa19f06db6024aa331ac7596610bdb600289541061080a565b60028855610be8565b9255565b9290928351835181149081610c88575b5015610c5157610c198284610c0f8795828761230f565b98919590506110d9565b156109b757610c289051610888565b9160005b83518110156109b157806109a761099561098e610987610c4c95876108f1565b610c2c565b60405162461bcd60e51b815260206004820152600f60248201526e1b585b199bdc9b5959081a5b9c1d5d608a1b6044820152606490fd5b61010091501038610bf8565b15610c9b57565b60405162461bcd60e51b81526020600482015260076024820152667369707061676560c81b6044820152606490fd5b15610cd157565b60405162461bcd60e51b815260206004820152602260248201527f796f752063616e2774207769746864726177206f7468657227732062616c616e604482015261636560f01b6064820152608490fd5b6001600160a01b031660009081527f643b8a6b3ed8752748bc6461fd4a02b0c30db5660ff05b0028ccebefb6b5f2636020526040902090565b6001600160a01b031660009081527f7d9b04b9e52f7a4e4f7cdff570205d7c27d6f7283dab59d340ff6676d10571b66020526040902090565b6001600160a01b031660009081527fe35cc21d37873d362c6d20195c3a1c72fa511d9573329821aa68d4bc28c9e7b86020526040902090565b6001600160a01b031660009081526000805160206141ab8339815191526020526040902090565b9060018060a01b0316600052602052604060002090565b919091600083820193841291129080158216911516176107f857565b600f91820b910b039060016001607f1b0319821260016001607f1b038313176107f857565b90815180825260208080930193019160005b828110610e6b575050505090565b835185529381019392810192600101610e5d565b9091610e9661045d93604084526040840190610e4b565b916020818403910152610415565b9496959192610ec760a09594610ed593885260c0602089015260c0880190610e4b565b908682036040880152610415565b95600180851b038093166060860152608085015216910152565b919082519283825260005b848110610f1b575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201610efa565b92610f5761045d9593610f659360018060a01b03168652608060208701526080860190610e4b565b908482036040860152610415565b916060818403910152610eef565b6040513d6000823e3d90fd5b81601f8201121561019757805191610f9683610175565b92610fa46040519485610154565b808452602092838086019260051b820101928311610197578301905b828210610fce575050505090565b8380918351610fdc8161018c565b815201910190610fc0565b906020828203126101975781516001600160401b0381116101975761045d9201610f7f565b9061101f90604083526040830190610e4b565b81810360209283015282518082529082019282019160005b828110611045575050505090565b835185529381019392810192600101611037565b600f0b60016001607f1b031981146107f85760000390565b600f91820b910b019060016001607f1b0319821260016001607f1b038313176107f857565b919091604081840312610197578051926001600160401b039384811161019757816110c2918401610f7f565b9360208301519081116101975761045d9201610f7f565b91939290600091825b8151811015611bcc576110f581836108f1565b5160208101519081519061110882610888565b92839161111484610888565b9160005b858110611adc57508a8251938460001a801560001461125f57506040938401518451631d86f10160e31b815296879361115693919060048601610f2f565b6001600160a01b0394851696916000918791900381838a5af191821561125a57878f88906000988996611228575b5092859289926111a695878551148061121e575b6111a190610881565b612a70565b60005b8181106111fa57505050917fbaec78ca3218aba6fc32d82b79acdd1a47663d7b8da46e0c00947206d08f2071916111ed6111f597969594519283928d169683610e7f565b0390a36108ba565b6110e2565b80611218610ab2600180940160051b80870151908a015101600f0b90565b016111a9565b5085518814611198565b6111a69492965061124c9193993d8091833e6112448183610154565b810190611096565b909890959193909290611184565b610f73565b90955090506001810361138e5750891561137c575b6001600160a01b0392831694611289866128ed565b6000878d6112b06040809701518751998a948594631072ff1f60e11b865260048601610f2f565b0381838a5af191821561125a57878f88906000988996611352575b5092859289926112e795878551148061121e576111a190610881565b60005b81811061132e57505050917fded5415ee05ea676deae44e3fdba7daa1ec0c86fed40cc0d0fa9908a98baa168916111ed6111f597969594519283928d169683610e7f565b8061134c610ab2600180940160051b80870151908a015101600f0b90565b016112ea565b6112e79492965061136e9193993d8091833e6112448183610154565b9098909591939092906112cb565b98506113866127cf565b600198611274565b939490936002908082036115b25750506113a781610888565b6001600160a01b039384169590949060005b838110611537575060408094015190873b156101975760008e918a6113f3885195869384936313c679ff60e01b8552600497888601610f2f565b0381838c5af190811561125a576000928a9261151e575b5061142686519889938493631d51e53960e31b8552840161100c565b038183305af194851561125a576000956114fb575b5060008e5b8382106114855750505050917f613a0b8d7d8bf2705187bfe8332a743e6bbffa1e4f8bafec7b6f0ed8fca59201916111ed6111f597969594519283928d169683610e7f565b906109a7610ab26114f5936114ef6001850160051b9161099f838d01936114cd6114af8651611059565b918b0151916001600160801b038316600f90810b91900b1315610881565b6114e985519160f81c916114e461098e84876108f1565b611071565b926108f1565b51611059565b8e611440565b61151791953d8091833e61150f8183610154565b810190610fe7565b933861143b565b8061152b61153192610126565b8061063b565b3861140a565b806001611594920160051b808b019061156061155430845161392a565b6001850160051b8c0152565b8401518a81600f0b60008113908115916115a1575b506115995791516109a7926001600160801b0390921691903090613d4f565b6113b9565b5050506108ba565b60016001607f1b0314905038611575565b90939694925060038114600014611925575050508715611913575b6115df6001600160a01b0385166128ed565b6115f16001600160a01b038516610d93565b9063ffffffff9081611607845463ffffffff1690565b16156118f9575b8161161d845463ffffffff1690565b1660018111611809575b505050906111f5949392918b8a61165f7f000000000000000000000000aec06345b26451bda999d83b361beaad6ea93f87809561385e565b60009590600181016116b7575b5050604051600f9590950b85525050506001600160a01b038981169316917f79a02325cb94513a3505278348f98ec59be59bfe1bd80376ae39c5917247463f915080602081016111ed565b60010160051b01519450919290919089600f86810b60016001607f1b03146117fb5761098e6117dd6117e99489946117e4946117d761099f996117d1610a976117886117f09f60018161175e8f61173961173461173e9261172b61171f611734995460901c90565b6001600160701b031690565b9d0b809d610e0a565b611c70565b611c07565b82546001600160901b031660909190911b6001600160901b031916178255565b6000805160206141cb833981519152546117bf9061178d9061178890611734908d9060801c610e0a565b611bee565b6000805160206141cb83398151915280546001600160801b031660809290921b6001600160801b031916919091179055565b01966117cb8689610df3565b54610e0a565b92610df3565b5561385e565b80966108f1565b610e26565b918d6108f1565b38808b8a828061166c565b5050505050505060006117f0565b61181390426107fd565b908161184c575b5050906118406111f596959493924216829063ffffffff1663ffffffff19825416179055565b90919293943880611627565b8301549060008e8b8e5b858410611866575050505061181a565b60008b866118af6118df9796956118a185966040519485938a602086019863669a9d9d60e01b8a5260018060a01b0316918d60248801610ea4565b03601f198101835282610154565b51907f0000000000000000000000002e98ef87f7f0d31987a0d94051b8bc5d001152e85af46118e7575b506108ba565b8e8b8e611856565b60006020825160051b92013e8f6118d9565b825463ffffffff191663ffffffff4284161617835561160e565b965061191d6127cf565b6001966115cd565b9195949392509060048103611a6c57506001600160a01b038a81169594169385851460008e5b84821061198f5750505050506111f5949392917f953ae389afac40aac3257d935e810a67594cd53c82841043b9cb722af8189a5c916111ed60405192839283610e7f565b906109a7611a49926119f26117348a6119ec6119e661098e8f6119df8f6119d08c8f81956119cb82848d6114e9959215611a4f575b5050610cca565b610d5a565b51600052602052604060002090565b54946108f1565b600f0b90565b90610e0a565b611a086119fe8c610d5a565b6119d0868c6108f1565b5561099f611a1961098e858c6108f1565b6114e9611a3b611a35611a356001890160051b8c015160f81c90565b60ff1690565b916117e461098e84876108f1565b8e61194b565b60009250611a609161098e916108f1565b600f0b1215848d6119c4565b92509392505060058091146000146101975760005b838110611a9557505050506111f5906108ba565b80611ad68c611ac46119e6611abb61098e6001809801891b8a0151948560f81c906108f1565b600003600f0b90565b90848060801b0316600f0b1215610c94565b01611a81565b600191929394508d828b600592828501841b938488015193611b158d8887841a94848960001a01901b80970151919060010160051b0152565b81611b455750505050611b3a9150838060801b0316600f0b82879060010160051b0152565b019085939291611118565b92935090918103611b7157505060016001607f1b036001840160051b88015250611b6c9050565b611b3a565b60028103611b8c575001516001830160051b87015250611b3a565b90506003915014611b9e575b50611b3a565b611bba6119e6611bb5611bc6938b0151309061392a565b611bd5565b6001830160051b870152565b38611b98565b50505050509050565b60026001607f1b0380821015611be9575090565b905090565b6001600160801b0390611c0382821115610ad0565b1690565b6001600160701b0390818111611c1b571690565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663132206269747360c81b6064820152608490fd5b60008112611c7b5790565b606460405162461bcd60e51b815260206004820152602060248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152fd5b919091611ccc8151610888565b600090815b8351811015611d62576001810160051b90818501611d04611cfb611cf630845161392a565b610b3c565b93890151610b3c565b928584820394128185128116918513901516176107f857611d27611d4a93610b2c565b611d388184879060010160051b0152565b600f0b858113611d4f575b50506108ba565b611cd1565b611d5b91309051613baa565b3880611d43565b5093505050565b91608083830312610197578251906001600160401b03918281116101975784019383601f86011215610197578451611da081610175565b90611dae6040519283610154565b808252602096878084019260051b820101918783116101975788809201905b838210611e1f5750505050948101518381116101975784611def918301610f7f565b9360408201518481116101975781611e08918401610f7f565b9360608301519081116101975761045d9201610f7f565b81518152908201908201611dcd565b6001600160a01b039091168152602081019190915260400190565b600160ff1b81146107f85760000390565b90670de0b6b3a7640000918281029281840414901517156107f857565b90633b9aca0091808302928304036107f857565b818102929181159184041417156107f857565b8115611ea8570490565b634e487b7160e01b600052601260045260246000fd5b919082018092116107f857565b611eeb611ef79197969295979493946002611ee58a610d93565b016121d4565b6001600160a01b031690565b60405163376fc5bf60e01b81526001600160a01b03808316969193909260009291600490849087908190611f2e908f868401611e2e565b0381838d5af193841561125a57808093819882976121a2575b50611f648351865181149081612197575b8161218c575b50610881565b815b835181101561218157808f8f928f8f928f928f918f918f918f918f918f918f91908f918f908f9b6001998a850160051b80990198808a51611fa790600f0b90565b9e019d8e51611fb690600f0b90565b611fbf91610e0a565b90808301918251611fd090600f0b90565b611fd991610e0a565b611fe290611e49565b611feb90611c70565b9801519d8e9a8b98611fff8a998a966108f1565b51600f0b600f0b131561201190610881565b51905191519261202094612711565b61202990610d93565b9485019061203691610df3565b60009182526020526040902096835461204f9060901c90565b6001600160701b03161561214657505061208261206e61208992611e5a565b61207c61171f855460901c90565b90611e9e565b8654611ebe565b85555b8684865496019461209d8287610df3565b546120a890886107fd565b9201906120b491610df3565b546120be91611e8b565b670de0b6b3a76400009004976120d392613732565b936120dd91610df3565b5561211095600019831461211557505061099f906114e9612103610a376109a796610b3c565b6114e461098e84876108f1565b611f66565b61213f9350612137925061212890610d5a565b90600052602052604060002090565b918254611ebe565b90556108ba565b90612128612176927f8f688873691912f8fe135293a1e4047b82cd30dddf57571cb75b40a636c8f5d65416610d5a565b90815401905561208c565b8a5160051b60208c01f35b905088511438611f5e565b8b5181149150611f58565b9250955092506121c59196503d8084833e6121bd8183610154565b810190611d69565b97929390939193979538611f47565b906121de9161221a565b905460039190911b1c6001600160a01b031690565b60008051602061426b83398151915280548210156108ec5760005260206000200190600090565b80548210156108ec5760005260206000200190600090565b1561223957565b60405162461bcd60e51b815260206004820152601060248201526f323ab83634b1b0ba32b2103a37b5b2b760811b6044820152606490fd5b1561227857565b60405162461bcd60e51b815260206004820152602560248201527f6475706c69636174656420746f6b656e20696e2056656c6f636f72654f70657260448201526430ba34b7b760d91b6064820152608490fd5b156122d257565b60405162461bcd60e51b81526020600482015260156024820152743a37b5b2b7103737ba1034b7103a37b5b2b72932b360591b6044820152606490fd5b919261231b8351610888565b926123268151610888565b926000958683519282519460015b85811061256557505050612533575b60005b8381106123535750505050565b602061235f82846108f1565b5101518381519160005b8381106123a557509161238c91600194938215928315612392575b5050506122cb565b01612346565b60051b015160001a109050853880612384565b9091508a15612524576001810160051b8201516123f36123e66123d66123cf8d8560001a906108f1565b5160ff1690565b60f81b6001600160f81b03191690565b6001600160f81b03191690565b6001600160f81b03909116176001820160051b83018190525b816001831015806124fd575b61242a575b5050600101908591612369565b929a919b9396949597999890995b836001811015806124d6575b1561246b578c6124669160001901958060051b820151919060010160051b0152565b612438565b6001939c94509a6124a29199979698959d929a9b806000198751011480156124a9575b61249790612271565b60010160051b850152565b903861241d565b506124976002820160051b87015160001a60ff60f81b60f891818660001a841b16921b161415905061248e565b508b8d60ff60f81b908360051b015160001a8160f891821b169260001a901b161115612444565b5060ff60f81b8360051b85015160001a908060f892831b16918460001a901b161115612418565b6001810160051b82015161240c565b60005b8281106125435750612343565b8061255f81600180940160051b8a0151899060010160051b0152565b01612536565b9091925061257a81808b9060010160051b0152565b6001810160051b80830151906125968360051b85015183111590565b6125a9575b505060010190899291612334565b869b50840151908a83918560019e8f805b61262a575b5095848196946125f9856125ed61260496859861260f9b60019e6000190114918215612616575b5050612232565b6001840160051b8c0152565b9060010160051b0152565b60010160051b860152565b903861259b565b6002880160051b015114159050828e6125e6565b92939491505080878b84831015806126a2575b156126965750509061268b91600019019461267b8260051b9161266a838c0151858d9060010160051b0152565b8383820151919060010160051b0152565b89015190899060010160051b0152565b908589838f946125ba565b919594939092506125bf565b506126b38360051b83015187111590565b61263d565b906040929160018060a01b0316936126fe6000938685526000805160206141ab83398151915292836020528686208587526020528686205490600f0b91600f0b90613707565b9483526020528282209082526020522055565b93919392909260018060a01b03169061275a6000958387526000805160206141ab833981519152928360205260408820878952602052604088205490600f0b91600f0b90613707565b908286526020526040852084865260205260408520558382600f0b12612781575b50505050565b61278d61279a92611059565b600f0b928391309161414a565b106100e95780808061277b565b90816020910312610197575190565b6001600160801b0391821690821601919082116107f857565b6000805160206141cb833981519152805460801c6127ea5750565b60405163056d8d4d60e11b81529060208260048160007f000000000000000000000000cc22f6aa610d1b2a0e89ef228079cb3e1831b1d16001600160a01b03165af191821561125a576000926128a4575b5081612845575050565b6102229161286761178861285d612876945493611e77565b8360801c90611e9e565b906001600160801b03166127b6565b6000805160206141cb83398151915280546001600160801b0319166001600160801b03909216919091179055565b6128c691925060203d81116128cd575b6128be8183610154565b8101906127a7565b903861283b565b503d6128b4565b6001600160801b0391821690821603919082116107f857565b600163ffffffff61290a61290084610d93565b5463ffffffff1690565b16036129b9576000905b61291d81610dcc565b9060018060a01b039161297461296a85612964867f000000000000000000000000cc22f6aa610d1b2a0e89ef228079cb3e1831b1d116809590600052602052604060002090565b54613676565b9161212884610dcc565b5516803b1561019757604051620f038760eb1b815260048101929092526000908290602490829084905af1801561125a576129ac5750565b8061152b61022292610126565b6000805160206141cb8339815191525490612a6b612a2d612a23612a07610a976129f861171f6129e888610d93565b5460201c6001600160701b031690565b6001600160801b0388166128d4565b612a1d61171f612a1687610d93565b5460901c90565b90611e8b565b633b9aca00900490565b926001600160701b0316612a4083610d93565b8054640100000000600160901b03191660209290921b640100000000600160901b0316919091179055565b612914565b9194928551946000805b878110612a8c57505050505050505050565b6001810160051b90818401518289015192612aa78483611071565b8782018051919590916001600160801b0316600f90810b9087900b13612b0557612b00956117e48f61099f94612aef8f97958f996109a79a612af99861098e960151906126b8565b518a1a80966108f1565b918a6108f1565b612a7a565b60405162461bcd60e51b81526020600482015260166024820152750e8ded6cadc40e4cae6ead8e840c2c4deecca40dac2f60531b6044820152606490fd5b604090815191612b5283610139565b600183528291600091825b602080821015612b8f57825160209291612b7682610106565b8682528681830152606085830152828901015201612b5d565b50505091925050565b60405190612ba582610139565b6001825260203681840137565b929192606091828201838352815180915260809384840191858160051b860101956020809501936000915b838310612c155750505050505061045d9394612c029183019060018060a01b03169052565b6040818303910152602090600081520190565b909192939497607f198882030183528851908681019060018060a01b038351168152888301516003811015612cab5784828b9594939286809401528a604080960151958201528451809452019201906000905b808210612c875750505090806001929a01930193019194939290612bdd565b82516001600160e01b03191684528a94938401939092019160019190910190612c68565b634e487b7160e01b600052602160045260246000fd5b636988ad4560e11b600081815260008051602061422b833981519152602081905260008051602061424b83398151915254909190612d415760008051602061426b83398151915280549290600160401b84101561012157600184018082558410156108ec5784604094828552602085200155549382526020522055600190565b91505090565b60018101636988ad4560e11b91826000528160205260406000205415600014612db0578054600160401b81101561012157806001612d88920183558261221a565b81549060031b9085821b91600019901b19161790555491600052602052604060002055600190565b505050600090565b637a97f8cf60e01b600081815260008051602061422b833981519152602081905260008051602061428b83398151915254909190612d415760008051602061426b83398151915280549290600160401b84101561012157600184018082558410156108ec5784604094828552602085200155549382526020522055600190565b60018101637a97f8cf60e01b91826000528160205260406000205415600014612db0578054600160401b81101561012157806001612d88920183558261221a565b631d51e53960e31b600081815260008051602061422b833981519152602081905260008051602061420b83398151915254909190612d415760008051602061426b83398151915280549290600160401b84101561012157600184018082558410156108ec5784604094828552602085200155549382526020522055600190565b60018101631d51e53960e31b91826000528160205260406000205415600014612db0578054600160401b81101561012157806001612d88920183558261221a565b60008051602061426b8339815191528054908115612f72576000198281019290818410156108ec576000918383526020832001015555565b634e487b7160e01b600052603160045260246000fd5b8054908115612f725760001991820191612fa2838361221a565b909182549160031b1b1916905555565b636988ad4560e11b60005260008051602061422b83398151915260205260008051602061424b8339815191525480156130bb576000198181018281116107f85760008051602061426b833981519152549182019182116107f857808203613054575b50505061301f612f3a565b636988ad4560e11b600090815260008051602061422b83398151915260205260008051602061424b8339815191525b55600190565b61309561307c9161307461306a6130b2956121f3565b90549060031b1c90565b9283916121f3565b90919082549060031b91821b91600019901b1916179055565b60005260008051602061422b833981519152602052604060002090565b55388080613014565b50600090565b636988ad4560e11b600090815260018201602081905260409091205491908215612db05760001991838301908482116107f85780549384019384116107f857600094848361311b9461304e9703613131575b505050612f88565b636988ad4560e11b600052602052604060002090565b61315161307c9161314861306a613161958861221a565b9283918761221a565b8590600052602052604060002090565b55388080613113565b637a97f8cf60e01b600090815260018201602081905260409091205491908215612db05760001991838301908482116107f85780549384019384116107f85760009484836131c39461304e97036131d957505050612f88565b637a97f8cf60e01b600052602052604060002090565b61315161307c916131ed613161948761221a565b90549060031b1c9283918761221a565b637a97f8cf60e01b60005260008051602061422b83398151915260205260008051602061428b8339815191525480156130bb576000198181018281116107f85760008051602061426b833981519152549182019182116107f85780820361329d575b50505061326a612f3a565b637a97f8cf60e01b600090815260008051602061422b83398151915260205260008051602061428b83398151915261304e565b61309561307c916132b06132bf946121f3565b90549060031b1c9283916121f3565b5538808061325f565b631d51e53960e31b600090815260018201602081905260409091205491908215612db05760001991838301908482116107f85780549384019384116107f85760009484836133219461304e97036131d957505050612f88565b631d51e53960e31b600052602052604060002090565b631d51e53960e31b60005260008051602061422b83398151915260205260008051602061420b8339815191525480156130bb576000198181018281116107f85760008051602061426b833981519152549182019182116107f8578082036133d7575b5050506133a4612f3a565b631d51e53960e31b600090815260008051602061422b83398151915260205260008051602061420b83398151915261304e565b61309561307c916132b06133ea946121f3565b55388080613399565b63d3115a8a195490600090600160a01b83101561340c57565b91199160019150565b637a97f8cf195490600090600160a01b83101561340c57565b63ea8f29c8195490600090600160a01b83101561340c57565b61344f613415565b50613458612b43565b906134668361069b846108df565b60006020613473846108df565b51015261347e612b98565b6040613489846108df565b5101526134a961349d60406106e1856108df565b637a97f8cf60e01b9052565b6001600160a01b038181161515906000805160206141eb83398151915290859083613550575b811615948561353d575b6134e860405192839283612bb2565b0390a18319637a97f8cf1955613525575b501561350b57506135086131fd565b50565b6135206135089161351a612db8565b50610d21565b612e38565b61353161353691610d21565b61316a565b50386134f9565b61354b60206107ab836108df565b6134d9565b61355e60206107c6886108df565b6134cf565b61356b61342e565b50613574612b43565b906135828361069b846108df565b6000602061358f846108df565b51015261359a612b98565b60406135a5846108df565b5101526135c56135b960406106e1856108df565b631d51e53960e31b9052565b6001600160a01b038181161515906000805160206141eb83398151915290859083613663575b8116159485613650575b61360460405192839283612bb2565b0390a1831963ea8f29c81955613638575b50156136245750613508613337565b6136336135089161351a612e79565b612ef9565b61364461364991610d21565b6132c8565b5038613615565b61365e60206107ab836108df565b6135f5565b61367160206107c6886108df565b6135eb565b90611734613687918360801c610e0a565b6001600160801b03918216600081128015166107f8576136a690611c70565b9180831680931490816136fb575b50156136cb5760801b6001600160801b0319161790565b60405162461bcd60e51b81526020600482015260086024820152676f766572666c6f7760c01b6044820152606490fd5b905081168114386136b4565b919061173461371f6117346136a6938660801c610e0a565b6001600160801b03949093908516610e0a565b909182156137c257600090600019938481019081116107f85793929193905b8185111561376157505050905090565b6001858303811c860180968160051b86013584811460001461378857505050505050505090565b879850938095969791929394106000146137a9575050015b93929190613751565b9250935080156137ba5701916137a0565b505050505090565b50505060001990565b8051908115613856576137df6000926107e9565b905b818311156137f25750505060001990565b600192808303841c8101938401908160051b83015160008051602061418b8339815191529081811460001461382a5750505050505090565b959192939495106000146138425750505b91906137e1565b9150925080156137c257600019019161383b565b505060001990565b80519182156137c257906138736000936107e9565b905b81841115613887575050505060001990565b600192848303841c85019485948601908160051b840151968388146000146138b457505050505050905090565b9193955091809496106000146138cf5750505b929091613875565b9150935080156138e35760001901926138c7565b5050505060001990565b90816020910312610197575161045d81610204565b60609060208152600d60208201526c34b73b30b634b2103a37b5b2b760991b60408201520190565b6001600160f81b03198116806139bd57506139869160209161395960a082901c6001600160581b031615610881565b6040516370a0823160e01b81526001600160a01b0390921660048301529092839190829081906024820190565b03916001600160a01b03165afa90811561125a576000916139a5575090565b61045d915060203d81116128cd576128be8183610154565b600160f91b81036139fb5750604051627eeac760e11b8152916020918391829081906139869060a085901c6001600160581b03169060048401611e2e565b600160f81b03613a92576040516331a9108f60e11b81526001600160581b0360a083901c166004820152906001600160a01b03906020908390602490829085165afa91821561125a57600092613a62575b508060009316911614600014611a355750600190565b613a8491925060203d8111613a8b575b613a7c8183610154565b8101906138ed565b9038613a4c565b503d613a72565b60008051602061418b83398151915214613ac35760405162461bcd60e51b815280613abf60048201613902565b0390fd5b3190565b15613ace57565b60405162461bcd60e51b815260206004820152600e60248201526d1a5b9d985b1a5908185b5bdd5b9d60921b6044820152606490fd5b6001600160a01b03909116815263deadbeef6020820152604081019190915260600190565b6001600160a01b03918216815291166020820152604081019190915260600190565b15613b5257565b60405162461bcd60e51b815260206004820152602a60248201527f6e617469766520746f6b656e207472616e7366657246726f6d206973206e6f74604482015269081cdd5c1c1bdc9d195960b21b6064820152608490fd5b91906001600160f81b0319831680613bfc5750613bd460a084901c6001600160581b031615610881565b6001600160a01b03908082163003613bf157506102229216613eca565b906102229316613f4c565b60008051602061418b8339815191528492939414600014613c445750613c2e916001600160a01b031630149050613b4b565b6000808080809463deadbeef5af1156100e95750565b91929091600160f81b8103613cb957506001613c609114613ac7565b6001600160a01b03811691823b1561019757604051632142170760e11b8152926000928492839185918391613ca89160a09190911c6001600160581b03169060048401613b04565b03925af1801561125a576129ac5750565b600160f91b03613d36576001600160a01b038216803b1561019757604051637921219560e11b81526001600160a01b03909416600485015263deadbeef602485015260a092831c6001600160581b0316604485015260648401919091526084830191909152600060a4830181905290829081838160c48101613ca8565b60405162461bcd60e51b815280613abf60048201613902565b9291906001600160f81b0319841680613da25750613d7a60a085901c6001600160581b031615610881565b6001600160a01b03908082163003613d9757506102229316613f12565b906102229416613f73565b60008051602061418b833981519152859293949514600014613de75750613dd5916001600160a01b031630149050613b4b565b60008080809481945af1156100e95750565b92939092600160f81b8103613e4b57506001613e039114613ac7565b6001600160a01b038216803b1561019757604051632142170760e11b8152936000938593849286928492613ca89260a09290921c6001600160581b0316919060048501613b29565b909390600160f91b03613d36576001600160a01b03831690813b1561019757604051637921219560e11b81526001600160a01b0393841660048201529216602483015260a092831c6001600160581b0316604483015260648201939093526084810191909152600060a482018190529091829081838160c48101613ca8565b906040519063a9059cbb60e01b602083015263deadbeef602483015260448201526044815260808101918183106001600160401b038411176101215761022292604052613ffa565b613f476102229392613f3960405194859263a9059cbb60e01b602085015260248401611e2e565b03601f198101845283610154565b613ffa565b613f476102229392613f396040519485926323b872dd60e01b602085015260248401613b04565b90613f4790613f39610222956040519586936323b872dd60e01b602086015260248501613b29565b15613fa257565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608490fd5b60018060a01b031661407660405161401181610139565b6020928382527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564848301526000808686829851910182855af13d156140ad573d9161405b8361028f565b926140696040519485610154565b83523d878785013e6140b1565b8051806140835750505050565b818391810103126100ec5701519081151582036100e957506140a490613f9b565b3880808061277b565b6060915b9192901561411357508151156140c5575090565b3b156140ce5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156141265750805190602001fd5b60405162461bcd60e51b815260206004820152908190613abf906024830190610eef565b61416561416a9392948361415e818561392a565b9684613d4f565b61392a565b9081039081116107f85790565b9183916141839361414a565b106101975756feeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee41cdc826884889a9d86ce2ed24c534af045774747691a4897641494ae5dd896be35cc21d37873d362c6d20195c3a1c72fa511d9573329821aa68d4bc28c9e7b78faa70878671ccd212d20771b795c50af8fd3ff6cf27f4bde57e5d4de0aeb6734820e2cd0662908c357e2fb320164dcb72822080d1ebe5c73f3fcb31f7680cb3643b8a6b3ed8752748bc6461fd4a02b0c30db5660ff05b0028ccebefb6b5f262bab7550cdc7b21dbbee8fdbbc70303a61ab056018f92c3a9256fa6502aa8e167643b8a6b3ed8752748bc6461fd4a02b0c30db5660ff05b0028ccebefb6b5f26115187d60e1e9a8d1ffcf993b3a6f69d8b9d84a727170945ca56b329bc0ea506fa26469706673582212209a33787c80ccdb01893065a949f63fe8b665ec11963fee4dc5f2a01f47fcacaa64736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000cc22f6aa610d1b2a0e89ef228079cb3e1831b1d1000000000000000000000000aec06345b26451bda999d83b361beaad6ea93f87
-----Decoded View---------------
Arg [0] : vc_ (address): 0xcc22F6AA610D1b2a0e89EF228079cB3e1831b1D1
Arg [1] : ballot_ (bytes32): 0x000000000000000000000000aec06345b26451bda999d83b361beaad6ea93f87
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000cc22f6aa610d1b2a0e89ef228079cb3e1831b1d1
Arg [1] : 000000000000000000000000aec06345b26451bda999d83b361beaad6ea93f87
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.