Source Code
Latest 25 from a total of 75 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Deploy | 16651290 | 314 days ago | IN | 0 ETH | 0.00000055 | ||||
| Deploy | 16648868 | 314 days ago | IN | 0 ETH | 0.00000051 | ||||
| Deploy | 11635910 | 431 days ago | IN | 0 ETH | 0.00000409 | ||||
| Deploy | 9371102 | 483 days ago | IN | 0 ETH | 0.0000094 | ||||
| Deploy | 7087608 | 536 days ago | IN | 0 ETH | 0.00000077 | ||||
| Deploy | 6989794 | 538 days ago | IN | 0 ETH | 0.00000792 | ||||
| Deploy | 6418910 | 551 days ago | IN | 0 ETH | 0.00000004 | ||||
| Deploy | 6385396 | 552 days ago | IN | 0 ETH | 0.00000415 | ||||
| Deploy | 6256214 | 555 days ago | IN | 0 ETH | 0.0000012 | ||||
| Deploy | 5866601 | 564 days ago | IN | 0 ETH | 0.00001573 | ||||
| Deploy | 5820811 | 565 days ago | IN | 0 ETH | 0.00006364 | ||||
| Deploy | 5401869 | 575 days ago | IN | 0 ETH | 0.00003503 | ||||
| Deploy | 5394491 | 575 days ago | IN | 0 ETH | 0.00003472 | ||||
| Deploy | 5376890 | 575 days ago | IN | 0 ETH | 0.00003564 | ||||
| Deploy | 5373657 | 575 days ago | IN | 0 ETH | 0.00003522 | ||||
| Deploy | 5358874 | 576 days ago | IN | 0 ETH | 0.00004049 | ||||
| Deploy | 5343561 | 576 days ago | IN | 0 ETH | 0.0001976 | ||||
| Deploy | 5309380 | 577 days ago | IN | 0 ETH | 0.00109651 | ||||
| Deploy | 5284841 | 578 days ago | IN | 0 ETH | 0.00003124 | ||||
| Deploy | 5087943 | 582 days ago | IN | 0 ETH | 0.00139478 | ||||
| Deploy | 5021423 | 584 days ago | IN | 0 ETH | 0.0004194 | ||||
| Deploy | 4934736 | 586 days ago | IN | 0 ETH | 0.00049555 | ||||
| Deploy | 4913822 | 586 days ago | IN | 0 ETH | 0.00089451 | ||||
| Deploy | 4846545 | 588 days ago | IN | 0 ETH | 0.00003856 | ||||
| Deploy | 4811096 | 589 days ago | IN | 0 ETH | 0.00005456 |
Latest 25 internal transactions (View All)
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
XYKPoolFactory
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: UNLICENSED
pragma solidity ^0.8.19;
import "../Satellite.sol";
import "./XYKPool.sol";
contract XYKPoolFactory is Satellite {
event PoolCreated(XYKPool indexed pool, Token t1, Token t2);
using TokenLib for Token;
using UncheckedMemory for Token[];
using UncheckedMemory for uint256[];
uint32 fee1e9;
uint32 decay = 4294955811;
XYKPool[] public poolList;
mapping(Token => mapping(Token => XYKPool)) public pools;
mapping(XYKPool => bool) public isPool;
event FeeChanged(uint256 fee1e18);
event DecayChanged(uint256 decay);
function setFee(uint32 fee1e9_) external authenticate {
fee1e9 = fee1e9_;
require(fee1e9 <= 0.1e9);
emit FeeChanged(fee1e9 * uint256(1e8));
}
function setDecay(uint32 decay_) external authenticate {
decay = decay_;
emit DecayChanged(decay_);
}
function getPools(uint256 begin, uint256 maxLength) external view returns (XYKPool[] memory pools) {
uint256 len = poolList.length <= begin ? 0 : Math.min(poolList.length - begin, maxLength);
pools = new XYKPool[](len);
unchecked {
for (uint256 i = begin; i < begin + len; i++) {
pools[i] = poolList[i];
}
}
}
function poolsLength() external view returns (uint256) {
return poolList.length;
}
constructor(IVault vault_) Satellite(vault_, address(this)) {
}
function deploy(Token quoteToken, Token baseToken) external returns (XYKPool) {
require(!(baseToken == quoteToken));
require(address(pools[quoteToken][baseToken]) == address(0));
if (!(quoteToken < baseToken)) {
(quoteToken, baseToken) = (baseToken, quoteToken);
}
XYKPool ret = new XYKPool(
vault,
string(abi.encodePacked("BladeSwap LP: ", quoteToken.symbol(), " + ", baseToken.symbol())),
string(abi.encodePacked(quoteToken.symbol(), "-", baseToken.symbol(), "-VLP")),
quoteToken,
baseToken,
fee1e9,
decay
);
poolList.push(ret);
isPool[ret] = true;
pools[baseToken][quoteToken] = ret;
pools[quoteToken][baseToken] = ret;
emit PoolCreated(ret, quoteToken, baseToken);
return ret;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "contracts/interfaces/IVault.sol";
import "contracts/Common.sol";
/**
* @dev a base contract for peripheral contracts.
*
* 1. delegates access control to the vault
* 2. use Diamond.yul's 'read' intrinsic function to read its storages
*
*/
contract Satellite is Common {
IVault immutable vault;
address public immutable factory;
constructor(IVault vault_, address factory_) {
vault = vault_;
factory = factory_;
}
modifier onlyVault() {
require(msg.sender == address(vault), "only vault");
_;
}
function _readVaultStorage(bytes32 slot) internal view returns (bytes32 ret) {
address vaultAddress = address(vault);
assembly ("memory-safe") {
mstore(0, 0x7265616400000000000000000000000000000000000000000000000000000000)
mstore(4, slot)
let success := staticcall(gas(), vaultAddress, 0, 36, 0, 32)
if iszero(success) { revert(0, 0) }
ret := mload(0)
}
}
modifier authenticate() {
require(
IAuthorizer(address(uint160(uint256(_readVaultStorage(SSLOT_HYPERCORE_AUTHORIZER))))).canPerform(
keccak256(abi.encodePacked(bytes32(uint256(uint160(factory))), msg.sig)), msg.sender, address(this)
),
"unauthorized"
);
_;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "openzeppelin/utils/math/Math.sol";
import "openzeppelin/utils/math/SignedMath.sol";
import "openzeppelin/utils/math/SafeCast.sol";
import {ud60x18, intoUint256, exp2, log2, convert, pow} from "@prb/math/src/UD60x18.sol";
import "contracts/lib/Token.sol";
import "contracts/lib/UncheckedMemory.sol";
import "contracts/lib/PoolBalanceLib.sol";
import {rpow} from "contracts/lib/RPow.sol";
import "contracts/pools/SingleTokenGauge.sol";
/**
* @dev a pool with weighted geometric average as its invariant, aka Balancer weighted pool.
* Please refer to the url below for detailed mathematical explanation.
* https://velocore.gitbook.io/velocore-v2/technical-docs/pool-specifics/generalized-cpmm
*
* There is two implementation of the same mathematical function. one in this contract, and another in ConstantProductLibrary.
* they were separated to make compiled bytecode less than 24kb.
*
* one implementation uses integer division; they are cheap and accurate, but prone to overflows, especially when weights are high.
* one implementation uses addition and substraction over logarithm; they are expensive and inaccurate, but can handle far more ranges.
*
* this contract is the first one. it falls back to the second one (ConstantProductLibrary) when neccesary.
*
*/
contract XYKPool is SingleTokenGauge, PoolWithLPToken, ISwap, IBribe {
using UncheckedMemory for uint256[];
using UncheckedMemory for int128[];
using UncheckedMemory for Token[];
using SafeCast for int256;
using SafeCast for uint256;
using TokenLib for Token;
event FeeChanged(uint256 fee1e18);
event DecayChanged(uint256 decay);
Token immutable token0_;
Token immutable token1_;
uint256 internal immutable _3token_i_0;
uint256 internal immutable _3token_i_1;
uint256 internal immutable _3token_i_lp;
uint32 public decayRate;
uint32 public fee1e9;
uint32 public lastWithdrawTimestamp;
uint32 lastTradeTimestamp;
uint128 public feeMultiplier;
uint8 internal immutable _lpDecimals;
int256 public index;
int256 lastIndex;
int256 logYieldEMA;
function token0() external view returns (address) {
if (token0_ == NATIVE_TOKEN) return WETH_ADDRESS;
else return token0_.addr();
}
function token1() external view returns (address) {
if (token1_ == NATIVE_TOKEN) return WETH_ADDRESS;
else return token1_.addr();
}
function getLogYieldEMA() external view returns (int256) {
int256 indexNew = ((_invariant() * 1e18) / (totalSupply() + 2))
.toInt256();
if (lastTradeTimestamp != block.timestamp) {
int256 an = int256(
rpow(
0.999983955055097432543272791e27,
block.timestamp - lastTradeTimestamp,
1e27
)
);
int256 logYield = (int256(
intoUint256(log2(ud60x18(uint256(indexNew * 1e27))))
) - int256(intoUint256(log2(ud60x18(uint256(lastIndex * 1e27)))))) /
int256(block.timestamp - lastTradeTimestamp);
return (logYieldEMA * an + (1e27 - an) * logYield) / 1e27;
}
return logYieldEMA;
}
function floorDiv(int256 a, int256 b) internal pure returns (int256) {
uint256 a_ = SignedMath.abs(a);
uint256 b_ = SignedMath.abs(b);
if ((a > 0) == (b > 0)) {
return SafeCast.toInt256(a_ / b_);
} else {
return -SafeCast.toInt256(Math.ceilDiv(a_, b_));
}
}
function ceilDiv(int256 a, int256 b) internal pure returns (int256) {
uint256 a_ = SignedMath.abs(a);
uint256 b_ = SignedMath.abs(b);
if ((a > 0) == (b > 0)) {
return SafeCast.toInt256(Math.ceilDiv(a_, b_));
} else {
return -SafeCast.toInt256(a_ / b_);
}
}
function setDecay(uint256 decayRate_) external authenticate {
decayRate = uint32(decayRate_);
emit DecayChanged(decayRate);
}
function setFee(uint256 fee1e9_, uint256 decayRate_) external authenticate {
require(fee1e9 <= 0.1e9);
fee1e9 = uint32(fee1e9_);
emit FeeChanged(fee1e9 * uint256(1e8));
}
constructor(
IVault vault_,
string memory _name,
string memory _symbol,
Token t0,
Token t1,
uint32 fee1e9_,
uint32 decay
) SingleTokenGauge(vault_, toToken(this), this) {
decayRate = decay;
fee1e9 = fee1e9_;
index = 1e18;
lastIndex = 1e18;
PoolWithLPToken._initialize(_name, _symbol);
emit FeeChanged(fee1e9 * uint256(1e8));
emit DecayChanged(decayRate);
token0_ = t0;
token1_ = t1;
uint256 ilp;
uint256 i0;
uint256 i1;
if (toToken(this) < t0) {
ilp = 0;
i0 = 1;
i1 = 2;
} else if (toToken(this) < t1) {
ilp = 1;
i0 = 0;
i1 = 2;
} else {
ilp = 2;
i0 = 0;
i1 = 1;
}
_3token_i_0 = i0;
_3token_i_1 = i1;
_3token_i_lp = ilp;
_lpDecimals = (t0.decimals() + t1.decimals()) / 2;
}
// positive amount => pool receives, user gives
// negative amount => user receives, pool gives
// type(int256).max => to be computed
event Sync(uint112 reserve0, uint112 reserve1);
function velocore__execute(
address user,
Token[] calldata t,
int128[] memory r,
bytes calldata
)
external
onlyVault
returns (int128[] memory deltaGauge, int128[] memory deltaPool)
{
deltaGauge = new int128[](t.length);
deltaPool = new int128[](t.length);
(int256 a_0, int256 a_1, ) = getReserves();
emit Sync(uint112(uint256(a_0)), uint112(uint256(a_1)));
a_0 += 1;
a_1 += 1;
if (lastWithdrawTimestamp != block.timestamp) {
feeMultiplier = 1e9;
}
if (!vault.emissionStarted()) {
int256 indexNew = ((_invariant() * 1e18) / (totalSupply() + 1))
.toInt256();
if (
lastTradeTimestamp != block.timestamp && lastIndex != indexNew
) {
int256 an = int256(
rpow(
0.999983955055097432543272791e27,
block.timestamp - lastTradeTimestamp,
1e27
)
);
int256 logYield = (int256(
intoUint256(log2(ud60x18(uint256(indexNew * 1e27))))
) -
int256(
intoUint256(log2(ud60x18(uint256(lastIndex * 1e27))))
)) / int256(block.timestamp - lastTradeTimestamp);
logYieldEMA =
(logYieldEMA * an + (1e27 - an) * logYield) /
1e27;
lastIndex = indexNew;
lastTradeTimestamp = uint32(block.timestamp);
}
index = indexNew;
}
if (t.length == 3) {
require(
t.u(_3token_i_lp) == toToken(this) &&
t.u(_3token_i_0) == token0_ &&
t.u(_3token_i_1) == token1_
);
int256 r_lp = r.u(_3token_i_lp);
int256 r_0 = r.u(_3token_i_0);
int256 r_1 = r.u(_3token_i_1);
if (r_lp != type(int128).max) {
if (r_0 != type(int128).max) {
r_1 = _exchange_for_t1(
a_0,
a_1,
r_0,
floorDiv(r_lp * index, 1e18),
int256(uint256(fee1e9 * feeMultiplier))
);
} else if (r_1 != type(int128).max) {
r_0 = _exchange_for_t0(
a_0,
a_1,
r_1,
floorDiv(r_lp * index, 1e18),
int256(uint256(fee1e9 * feeMultiplier))
);
} else {
(r_0, r_1) = _exchange_from_lp(
a_0,
a_1,
floorDiv(r_lp * index, 1e18)
);
}
} else {
require(r_0 != type(int128).max || r_1 != type(int128).max);
if (r_0 == type(int128).max) {
r_0 = (r_1 * (a_0)) / (a_1);
} else if (r_1 == type(int128).max) {
r_1 = (r_0 * (a_1)) / (a_0);
}
r_lp = ceilDiv(
_exchange_for_lp(
a_0,
a_1,
r_0,
r_1,
int256(uint256(fee1e9 * feeMultiplier))
) * 1e18,
index
);
}
deltaPool.u(_3token_i_0, r_0.toInt128());
deltaPool.u(_3token_i_1, r_1.toInt128());
deltaPool.u(_3token_i_lp, r_lp.toInt128());
_handleSwap(user, r_lp, r_0, r_1);
return (deltaGauge, deltaPool);
} else if (t.length == 2) {
require(
(r.u(0) == type(int128).max) != (r.u(1) == type(int128).max)
);
uint256 i_lp = 2;
uint256 i_0 = 2;
uint256 i_1 = 2;
Token tt = t.u(0);
if (tt == toToken(this)) i_lp = 0;
else if (tt == token0_) i_0 = 0;
else if (tt == token1_) i_1 = 0;
else revert("unsupported token");
tt = t.u(1);
if (tt == toToken(this)) i_lp = 1;
else if (tt == token0_) i_0 = 1;
else if (tt == token1_) i_1 = 1;
else revert("unsupported token");
int256 r_lp = i_lp == 2 ? int256(0) : r.u(i_lp);
int256 r_0 = i_0 == 2 ? int256(0) : r.u(i_0);
int256 r_1 = i_1 == 2 ? int256(0) : r.u(i_1);
if (r_lp == type(int128).max) {
r_lp = ceilDiv(
_exchange_for_lp(
a_0,
a_1,
r_0,
r_1,
int256(uint256(fee1e9 * feeMultiplier))
) * 1e18,
index
);
} else if (r_1 == type(int128).max) {
r_1 = _exchange_for_t1(
a_0,
a_1,
r_0,
floorDiv(r_lp * index, 1e18),
int256(uint256(fee1e9 * feeMultiplier))
);
} else {
r_0 = _exchange_for_t0(
a_0,
a_1,
r_1,
floorDiv(r_lp * index, 1e18),
int256(uint256(fee1e9 * feeMultiplier))
);
}
if (i_lp != 2) {
deltaPool.u(i_lp, r_lp.toInt128());
} else {
require(r_lp == 0);
}
if (i_0 != 2) {
deltaPool.u(i_0, r_0.toInt128());
} else {
require(r_0 == 0);
}
if (i_1 != 2) {
deltaPool.u(i_1, r_1.toInt128());
} else {
require(r_1 == 0);
}
_handleSwap(user, r_lp, r_0, r_1);
return (deltaGauge, deltaPool);
} else {
revert("unsupported operation");
}
}
function getReserves() public view returns (int256, int256, uint256) {
return (
_getPoolBalance(token0_).toInt256(),
_getPoolBalance(token1_).toInt256(),
block.timestamp
);
}
function _exchange(
int256 a_0,
int256 a_1,
int256 b_1,
int256 d_k,
int256 fee
) internal returns (int256) {
int256 a_k = Math
.sqrt((a_0.toUint256()) * (a_1.toUint256()), Math.Rounding.Up)
.toInt256();
int256 b_k = a_k - d_k;
require(b_k > 0);
if (a_k <= b_k) {
b_1 -= (SignedMath.max(((a_k * b_1) / b_k) - a_1, 0) * fee) / 1e18;
} else if (a_k >= b_k) {
b_1 -= (SignedMath.max(b_1 - ((b_k * a_1) / a_k), 0) * fee) / 1e18;
}
int256 b_0 = ceilDiv(b_k ** 2, b_1);
if (a_k <= b_k) {
b_0 +=
(SignedMath.max(((a_k * b_0) / b_k) - a_0, 0) * fee) /
(1e18 - fee);
} else if (a_k > b_k) {
b_0 +=
(SignedMath.max(b_0 - ((b_k * a_0) / a_k), 0) * fee) /
(1e18 - fee);
}
return b_0 - a_0;
}
function _exchange_for_t0(
int256 a_0,
int256 a_1,
int256 r_1,
int256 r_lp,
int256 fee
) internal returns (int256) {
return _exchange(a_0, a_1, a_1 + r_1, r_lp, fee);
}
function _exchange_for_t1(
int256 a_0,
int256 a_1,
int256 r_0,
int256 r_lp,
int256 fee
) internal returns (int256) {
return _exchange(a_1, a_0, a_0 + r_0, r_lp, fee);
}
function _exchange_for_lp(
int256 a_0,
int256 a_1,
int256 r_0,
int256 r_1,
int256 fee
) internal returns (int256) {
int256 b_0 = a_0 + r_0;
int256 b_1 = a_1 + r_1;
int256 a_k = Math
.sqrt((a_0 * a_1).toUint256(), Math.Rounding.Up)
.toInt256();
int256 b_k = invariant(b_0, b_1);
if (a_k <= b_k) {
b_0 -= (SignedMath.max(((a_k * b_0) / b_k) - a_0, 0) * fee) / 1e18;
b_1 -= (SignedMath.max(((a_k * b_1) / b_k) - a_1, 0) * fee) / 1e18;
} else if (a_k > b_k) {
b_0 -= (SignedMath.max(b_0 - ((b_k * a_0) / a_k), 0) * fee) / 1e18;
b_1 -= (SignedMath.max(b_1 - ((b_k * a_1) / a_k), 0) * fee) / 1e18;
}
return a_k - invariant(b_0, b_1);
}
function _exchange_from_lp(
int256 a_0,
int256 a_1,
int256 r_lp
) internal returns (int256, int256) {
Math.Rounding r = r_lp > 0 ? Math.Rounding.Up : Math.Rounding.Down;
int256 inv = Math
.sqrt((a_0.toUint256()) * (a_1.toUint256()), r)
.toInt256();
return (ceilDiv(-((a_0) * r_lp), inv), ceilDiv(-((a_1) * r_lp), inv));
}
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(
address indexed sender,
uint amount0,
uint amount1,
address indexed to
);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
function _handleSwap(
address user,
int256 rlp,
int256 r0,
int256 r1
) internal {
if (rlp > 0) {
emit Burn(user, uint256(-int256(r0)), uint256(-int256(r1)), user);
_simulateBurn(uint256(int256(rlp)));
uint256 inv = _invariant();
uint256 d = (inv - uint256(int256(rlp)));
feeMultiplier = uint128((feeMultiplier * inv) / Math.max(1, d));
} else if (rlp < 0) {
emit Mint(user, uint256(int256(r0)), uint256(int256(r1)));
_simulateMint(uint256(-int256(rlp)));
} else {
uint256 a0i;
uint256 a1i;
uint256 a0o;
uint256 a1o;
if (r0 > 0) {
a0i = uint256(int256(r0));
} else {
a0o = uint256(int256(-r0));
}
if (r1 > 0) {
a1i = uint256(int256(r1));
} else {
a1o = uint256(int256(-r1));
}
emit Swap(user, a0i, a1i, a0o, a1o, user);
}
}
function poolBalances() public view returns (uint256[] memory) {
return _getPoolBalances(relevantTokens());
}
function relevantTokens() public view virtual returns (Token[] memory) {
Token[] memory ret = new Token[](3);
unchecked {
ret.u(0, toToken(this));
ret.u(1, token0_);
ret.u(2, token1_);
}
return ret;
}
function invariant(int256 a, int256 b) internal pure returns (int256) {
uint256 a_ = a.toUint256();
uint256 b_ = b.toUint256();
return invariant(a_, b_).toInt256();
}
function invariant(uint256 a, uint256 b) internal pure returns (uint256) {
return Math.sqrt(a * b);
}
function _invariant() internal view virtual returns (uint256) {
(int256 a_0, int256 a_1, ) = getReserves();
return invariant(a_0 + 1, a_1 + 1).toUint256();
}
function _excessInvariant() internal view virtual returns (uint256) {
uint256 minted = Math.ceilDiv(
(totalSupply() + 1) * index.toUint256(),
1e18
);
(int256 a_0, int256 a_1, ) = getReserves();
uint256 actual = _invariant();
return actual < minted ? 0 : actual - minted;
}
function listedTokens() public view override returns (Token[] memory) {
Token[] memory ret = new Token[](2);
unchecked {
ret.u(0, token0_);
ret.u(1, token1_);
}
return ret;
}
function swapType() external view override returns (string memory) {
return "cpmm";
}
function lpTokens() public view override returns (Token[] memory ret) {
ret = new Token[](1);
ret[0] = toToken(this);
}
function poolParams()
external
view
override(IPool, Pool)
returns (bytes memory)
{
uint256[] memory r = new uint256[](2);
r[0] = 1;
r[1] = 1;
return abi.encode(fee1e9 * uint256(1e9), r);
}
function decimals() external view override returns (uint8) {
return _lpDecimals;
}
function velocore__bribe(
IGauge gauge,
uint256 elapsed
)
external
onlyVault
returns (
Token[] memory bribeTokens,
int128[] memory deltaGauge,
int128[] memory deltaPool,
int128[] memory deltaExternal
)
{
require(address(gauge) == address(this));
bribeTokens[0] = toToken(this);
deltaGauge = new int128[](1);
deltaPool = new int128[](1);
deltaExternal = new int128[](1);
if (IVault(vault).emissionStarted()) {
uint256 decay = 2 ** 32 - rpow(decayRate, elapsed, 2 ** 32);
uint256 decayed = (_excessInvariant() * 1e18 / uint256(index) * decay) / 2 ** 32;
bribeTokens = new Token[](1);
deltaPool.u(0, -decayed.toInt256().toInt128());
}
}
function bribeTokens(IGauge gauge) external view returns (Token[] memory) {
Token v = toToken(this);
assembly {
mstore(0, 0x20)
mstore(0x20, 1)
mstore(0x40, v)
return(0, 0x60)
}
}
function bribeRates(IGauge gauge) external view returns (uint256[] memory) {
uint256 v;
unchecked {
v = address(gauge) == address(this)
? (_excessInvariant() * 1e18 / uint256(index) * (2 ** 32 - uint256(decayRate))) /
2 ** 32
: 0;
}
assembly {
mstore(0, 0x20)
mstore(0x20, 1)
mstore(0x40, v)
return(0, 0x60)
}
}
function underlyingTokens(
Token tok
) external view returns (Token[] memory) {
require(tok == toToken(this));
return listedTokens();
}
function setFeeToZero() external onlyVault {
feeMultiplier = 0;
fee1e9 = 0;
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "contracts/interfaces/IAuthorizer.sol";
import "contracts/interfaces/IFacet.sol";
import "contracts/interfaces/IGauge.sol";
import "contracts/interfaces/IConverter.sol";
import "contracts/interfaces/IBribe.sol";
import "contracts/interfaces/ISwap.sol";
import "contracts/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_REBASEORACLES = bytes32(
uint256(keccak256("hypercore.rebaseOracles")) - 1
);
bytes32 constant SSLOT_HYPERCORE_LASTBALANCES = bytes32(
uint256(keccak256("hypercore.lastBalances")) - 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 emissionStarted() external view returns (bool);
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);
function getPoolBalance(address, Token) external view returns (uint256);
function getGaugeBalance(address, Token) external view returns (uint256);
function claimGasses(address[] memory, address) external;
function removeLiquidityETH(
address token,
bool stable,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function deposit(address p, uint256 a) external;
function withdraw(address p, uint256 a) external;
function quoteRemoveLiquidity(
address tokenA,
address tokenB,
bool stable,
uint256 liquidity
) external returns (uint256 amountA, uint256 amountB);
function addLiquidityETH(
address tokenA,
bool stable,
uint256 amountADesired,
uint256 amountAMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external payable returns (uint256 amountA, uint256 amountETH, uint256 liquidity);
function addLiquidity(
address tokenA,
address tokenB,
bool stable,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external payable returns (uint256 amountA, uint256 amountB, uint256 liquidity);
function quoteAddLiquidity(
address tokenA,
address tokenB,
bool stable,
uint256 amountADesired,
uint256 amountBDesired
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
bool stable,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "contracts/blast/IBLAST.sol";
contract Common {
address constant governor = 0x65432138ae74065Aeb3Bd71aEaC887CCAE0E32a4;
constructor() {
BLAST.configureClaimableGas();
BLAST.configureGovernor(governor);
}
}// 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: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/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 pragma solidity >=0.8.19; /* ██████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██╗ ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║ ██║ ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║ ██║ ███████║ ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██╔══██║ ██║ ██║ ██║██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ██╗ ██╗██████╗ ██████╗ ██████╗ ██╗ ██╗ ██╗ █████╗ ██║ ██║██╔══██╗██╔════╝ ██╔═████╗╚██╗██╔╝███║██╔══██╗ ██║ ██║██║ ██║███████╗ ██║██╔██║ ╚███╔╝ ╚██║╚█████╔╝ ██║ ██║██║ ██║██╔═══██╗████╔╝██║ ██╔██╗ ██║██╔══██╗ ╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝██╔╝ ██╗ ██║╚█████╔╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚════╝ */ import "./ud60x18/Casting.sol"; import "./ud60x18/Constants.sol"; import "./ud60x18/Conversions.sol"; import "./ud60x18/Errors.sol"; import "./ud60x18/Helpers.sol"; import "./ud60x18/Math.sol"; import "./ud60x18/ValueType.sol";
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "openzeppelin/token/ERC20/utils/SafeERC20.sol";
import "openzeppelin/token/ERC1155/IERC1155.sol";
import "openzeppelin/token/ERC1155/extensions/ERC1155Supply.sol";
import "openzeppelin/token/ERC20/extensions/IERC20Metadata.sol";
import "openzeppelin/token/ERC721/extensions/IERC721Metadata.sol";
import "contracts/blast/IERC20Rebasing.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;
Token constant NATIVE_TOKEN = Token.wrap(bytes32(0xEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE) & TOKEN_MASK);
address constant WETH_ADDRESS = 0x4300000000000000000000000000000000000004;
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);
}
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_)))
);
}
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 == NATIVE_TOKEN) {
return user.balance;
} else 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;
}
revert("invalid token");
}
function totalSupply(Token tok) internal view returns (uint256) {
require (tok != NATIVE_TOKEN);
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;
}
revert("invalid token");
}
function symbol(Token tok) internal view returns (string memory) {
if (tok == NATIVE_TOKEN) {
return NATIVE_TOKEN_SYMBOL;
} else 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();
}
}
function decimals(Token tok) internal view returns (uint8) {
if (tok == NATIVE_TOKEN) {
return 18;
} else if (tok.spec() == TokenSpec.ERC20) {
require(tok.id() == 0);
return IERC20Metadata(tok.addr()).decimals();
}
return 0;
}
function transferFrom(Token tok, address from, address to, uint256 amount) internal {
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.ERC20) {
require(tok.id() == 0);
if (from == address(this)) {
tok.toIERC20().safeTransfer(to, amount);
} else {
tok.toIERC20().safeTransferFrom(from, to, amount);
}
} 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);
}
function toScaledBalance(Token tok, uint256 amount) internal view returns (uint256) {
if (block.chainid == 81457) {
if (tok == toToken(BLAST_USDB)) {
return amount * 1e9 / BLAST_USDB.price();
} else if (tok == NATIVE_TOKEN) {
return amount * 1e9 / IERC20Rebasing(0x4300000000000000000000000000000000000000).price();
}
}
return amount;
}
function fromScaledBalance(Token tok, uint256 amount) internal view returns (uint256) {
if (block.chainid == 81457) {
if (tok == toToken(BLAST_USDB)) {
return amount * BLAST_USDB.price() / 1e9;
} else if (tok == NATIVE_TOKEN) {
return amount * IERC20Rebasing(0x4300000000000000000000000000000000000000).price() / 1e9;
}
}
return amount;
}
function toScaledBalance(Token tok, int128 amount) internal view returns (int128) {
if (block.chainid == 81457) {
if (tok == toToken(BLAST_USDB)) {
return amount * 1e9 / int128(int256(BLAST_USDB.price()));
} else if (tok == NATIVE_TOKEN) {
return amount * 1e9 / int128(int256(IERC20Rebasing(0x4300000000000000000000000000000000000000).price()));
}
}
return amount;
}
function fromScaledBalance(Token tok, int128 amount) internal view returns (int128) {
if (block.chainid == 81457) {
if (tok == toToken(BLAST_USDB)) {
return amount * int128(int256(BLAST_USDB.price())) / 1e9;
} else if (tok == NATIVE_TOKEN) {
return amount * int128(int256(IERC20Rebasing(0x4300000000000000000000000000000000000000).price())) / 1e9;
}
}
return amount;
}
}// SPDX-License-Identifier: AUNLICENSED
pragma solidity ^0.8.0;
import {Token} from "contracts/lib/Token.sol";
// solidity by default perform bound check for every array access.
// we define functions for unchecked access here
library UncheckedMemory {
using UncheckedMemory for bytes32[];
using UncheckedMemory for uint256[];
using UncheckedMemory for Token[];
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)
}
}
}
using UncheckedMemory for bytes32[];
using UncheckedMemory for uint256[];
using UncheckedMemory for Token[];
// 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;
}// SPDX-License-Identifier: AUNLICENSED
pragma solidity ^0.8.0;
import "openzeppelin/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: AUNLICENSED // From MakerDAO DSS // Copyright (C) 2018 Rain <[email protected]> // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. pragma solidity ^0.8.0; function rpow(uint256 x, uint256 n, uint256 base) pure returns (uint256 z) { assembly { switch x case 0 { switch n case 0 { z := base } default { z := 0 } } default { switch mod(n, 2) case 0 { z := base } default { z := x } let half := div(base, 2) // for rounding. for { n := div(n, 2) } n { n := div(n, 2) } { let xx := mul(x, x) if iszero(eq(div(xx, x), x)) { revert(0, 0) } let xxRound := add(xx, half) if lt(xxRound, xx) { revert(0, 0) } x := div(xxRound, base) if mod(n, 2) { let zx := mul(z, x) if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0, 0) } let zxRound := add(zx, half) if lt(zxRound, zx) { revert(0, 0) } z := div(zxRound, base) } } } } }
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "./PoolWithLPToken.sol";
import "contracts/interfaces/IGauge.sol";
import "contracts/lib/RPow.sol";
import "contracts/lib/UncheckedMemory.sol";
import "openzeppelin/utils/math/SafeCast.sol";
import "openzeppelin/utils/structs/EnumerableSet.sol";
/**
* @dev a base contract for gauges with single stakes.
*
* pretty standard Masterchef-like design.
*
*/
struct StakerInformation {
uint128 staked;
uint128 emissionPerStake1e9AtLastClaim;
}
contract SingleTokenGauge is Pool, IGauge {
using UncheckedMemory for uint256[];
using UncheckedMemory for int128[];
using UncheckedMemory for Token[];
using TokenLib for Token;
using SafeCast for uint256;
using SafeCast for int256;
uint128 emissionPerStake1e9;
mapping(address => StakerInformation) stakerInformation;
Token internal immutable emissionToken;
Token public immutable stake;
constructor(
IVault vault_,
Token stake_,
IBribe bribe
) Pool(vault_, address(this), msg.sender) {
emissionToken = vault_.emissionToken();
vault_.attachBribe(this, bribe);
stake = stake_;
}
/**
* called by the vault to nofity new emission
*/
function velocore__emission(uint256 newEmissions) external onlyVault {
if (newEmissions > 0) {
uint256 totalStakes = _getGaugeBalance(stake);
if (totalStakes > 0) {
unchecked {
// totalSupply of emissionToken * 1e9 < uint128_max
emissionPerStake1e9 += uint128(
(newEmissions * 1e9) / totalStakes
);
}
}
}
}
function velocore__gauge(
address user,
Token[] calldata tokens,
int128[] memory amounts,
bytes calldata
)
external
virtual
onlyVault
returns (int128[] memory deltaGauge, int128[] memory deltaPool)
{
deltaGauge = new int128[](tokens.length);
deltaPool = new int128[](tokens.length);
uint256 stakeIndex = _binarySearch(tokens, stake); // assumed to exist
uint256 emissionIndex = _binarySearch(tokens, emissionToken);
unchecked {
// total emissions cannot be greater than the total supply of the emissionToken (200Me18). log10(2^128) - 18 - 9 - 8 > 0; therefore it doesnt overflow.
uint256 claimed = ((emissionPerStake1e9 -
stakerInformation[user].emissionPerStake1e9AtLastClaim) *
stakerInformation[user].staked) / 1e9;
// the total supply of the emissionToken = 200Me18 < int128_max
deltaGauge.u(emissionIndex, -int128(int256(claimed)));
}
if (stakeIndex != type(uint256).max) {
stakerInformation[user].staked = (int256(
uint256(stakerInformation[user].staked)
) + amounts.u(stakeIndex)).toUint256().toUint128();
deltaGauge.u(stakeIndex, amounts.u(stakeIndex));
}
stakerInformation[user]
.emissionPerStake1e9AtLastClaim = emissionPerStake1e9;
}
function stakeableTokens() external view virtual returns (Token[] memory) {
Token v = stake;
assembly {
mstore(0, 0x20)
mstore(0x20, 1)
mstore(0x40, v)
return(0, 0x60)
}
}
function stakedTokens(
address user
) external view virtual returns (uint256[] memory) {
uint256 v = stakerInformation[user].staked;
assembly {
mstore(0, 0x20)
mstore(0x20, 1)
mstore(0x40, v)
return(0, 0x60)
}
}
function stakedTokens() external view virtual returns (uint256[] memory) {
uint256 v = _getGaugeBalance(stake);
assembly {
mstore(0, 0x20)
mstore(0x20, 1)
mstore(0x40, v)
return(0, 0x60)
}
}
function emissionShare(
address user
) external view virtual returns (uint256) {
uint256 gb = _getGaugeBalance(stake);
if (gb == 0) return 0;
unchecked {
return (stakerInformation[user].staked * uint256(1e18)) / gb;
}
}
function naturalBribes() external view returns (Token[] memory) {
return ISwap(stake.addr()).listedTokens();
}
}// 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;
interface IFacet {
function initializeFacet() external;
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "contracts/lib/Token.sol";
import "contracts/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 "contracts/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 "contracts/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: AGPL-3.0-only
pragma solidity ^0.8.19;
import "contracts/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);
}IBlast constant BLAST = IBlast(0x4300000000000000000000000000000000000002);
interface IBlast {
enum GasMode {
VOID,
CLAIMABLE
}
enum YieldMode {
AUTOMATIC,
VOID,
CLAIMABLE
}
// configure
function configureContract(
address contractAddress,
YieldMode _yield,
GasMode gasMode,
address governor
) external;
function configure(
YieldMode _yield,
GasMode gasMode,
address governor
) external;
// base configuration options
function configureClaimableYield() external;
function configureClaimableYieldOnBehalf(address contractAddress) external;
function configureAutomaticYield() external;
function configureAutomaticYieldOnBehalf(address contractAddress) external;
function configureVoidYield() external;
function configureVoidYieldOnBehalf(address contractAddress) external;
function configureClaimableGas() external;
function configureClaimableGasOnBehalf(address contractAddress) external;
function configureVoidGas() external;
function configureVoidGasOnBehalf(address contractAddress) external;
function configureGovernor(address _governor) external;
function configureGovernorOnBehalf(
address _newGovernor,
address contractAddress
) external;
// claim yield
function claimYield(
address contractAddress,
address recipientOfYield,
uint256 amount
) external returns (uint256);
function claimAllYield(
address contractAddress,
address recipientOfYield
) external returns (uint256);
// claim gas
function claimAllGas(
address contractAddress,
address recipientOfGas
) external returns (uint256);
function claimGasAtMinClaimRate(
address contractAddress,
address recipientOfGas,
uint256 minClaimRateBips
) external returns (uint256);
function claimMaxGas(
address contractAddress,
address recipientOfGas
) external returns (uint256);
function claimGas(
address contractAddress,
address recipientOfGas,
uint256 gasToClaim,
uint256 gasSecondsToConsume
) external returns (uint256);
// read functions
function readClaimableYield(
address contractAddress
) external view returns (uint256);
function readYieldConfiguration(
address contractAddress
) external view returns (uint8);
function readGasParams(
address contractAddress
)
external
view
returns (
uint256 etherSeconds,
uint256 etherBalance,
uint256 lastUpdated,
GasMode
);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_SD59x18 } from "../sd59x18/Constants.sol";
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Casts a UD60x18 number into SD1x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(UD60x18 x) pure returns (SD1x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(int256(uMAX_SD1x18))) {
revert CastingErrors.PRBMath_UD60x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(uint64(xUint)));
}
/// @notice Casts a UD60x18 number into UD2x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_UD2x18`.
function intoUD2x18(UD60x18 x) pure returns (UD2x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uMAX_UD2x18) {
revert CastingErrors.PRBMath_UD60x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(xUint));
}
/// @notice Casts a UD60x18 number into SD59x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_SD59x18`.
function intoSD59x18(UD60x18 x) pure returns (SD59x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(uMAX_SD59x18)) {
revert CastingErrors.PRBMath_UD60x18_IntoSD59x18_Overflow(x);
}
result = SD59x18.wrap(int256(xUint));
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev This is basically an alias for {unwrap}.
function intoUint256(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT128`.
function intoUint128(UD60x18 x) pure returns (uint128 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT128) {
revert CastingErrors.PRBMath_UD60x18_IntoUint128_Overflow(x);
}
result = uint128(xUint);
}
/// @notice Casts a UD60x18 number into uint40.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(UD60x18 x) pure returns (uint40 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT40) {
revert CastingErrors.PRBMath_UD60x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Alias for {wrap}.
function ud60x18(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Unwraps a UD60x18 number into uint256.
function unwrap(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Wraps a uint256 number into the UD60x18 value type.
function wrap(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as a UD60x18 number.
UD60x18 constant E = UD60x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
uint256 constant uEXP_MAX_INPUT = 133_084258667509499440;
UD60x18 constant EXP_MAX_INPUT = UD60x18.wrap(uEXP_MAX_INPUT);
/// @dev The maximum input permitted in {exp2}.
uint256 constant uEXP2_MAX_INPUT = 192e18 - 1;
UD60x18 constant EXP2_MAX_INPUT = UD60x18.wrap(uEXP2_MAX_INPUT);
/// @dev Half the UNIT number.
uint256 constant uHALF_UNIT = 0.5e18;
UD60x18 constant HALF_UNIT = UD60x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as a UD60x18 number.
uint256 constant uLOG2_10 = 3_321928094887362347;
UD60x18 constant LOG2_10 = UD60x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as a UD60x18 number.
uint256 constant uLOG2_E = 1_442695040888963407;
UD60x18 constant LOG2_E = UD60x18.wrap(uLOG2_E);
/// @dev The maximum value a UD60x18 number can have.
uint256 constant uMAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935;
UD60x18 constant MAX_UD60x18 = UD60x18.wrap(uMAX_UD60x18);
/// @dev The maximum whole value a UD60x18 number can have.
uint256 constant uMAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000;
UD60x18 constant MAX_WHOLE_UD60x18 = UD60x18.wrap(uMAX_WHOLE_UD60x18);
/// @dev PI as a UD60x18 number.
UD60x18 constant PI = UD60x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD60x18.
uint256 constant uUNIT = 1e18;
UD60x18 constant UNIT = UD60x18.wrap(uUNIT);
/// @dev The unit number squared.
uint256 constant uUNIT_SQUARED = 1e36;
UD60x18 constant UNIT_SQUARED = UD60x18.wrap(uUNIT_SQUARED);
/// @dev Zero as a UD60x18 number.
UD60x18 constant ZERO = UD60x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { uMAX_UD60x18, uUNIT } from "./Constants.sol";
import { PRBMath_UD60x18_Convert_Overflow } from "./Errors.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Converts a UD60x18 number to a simple integer by dividing it by `UNIT`.
/// @dev The result is rounded down.
/// @param x The UD60x18 number to convert.
/// @return result The same number in basic integer form.
function convert(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x) / uUNIT;
}
/// @notice Converts a simple integer to UD60x18 by multiplying it by `UNIT`.
///
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UD60x18 / UNIT`.
///
/// @param x The basic integer to convert.
/// @param result The same number converted to UD60x18.
function convert(uint256 x) pure returns (UD60x18 result) {
if (x > uMAX_UD60x18 / uUNIT) {
revert PRBMath_UD60x18_Convert_Overflow(x);
}
unchecked {
result = UD60x18.wrap(x * uUNIT);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
/// @notice Thrown when ceiling a number overflows UD60x18.
error PRBMath_UD60x18_Ceil_Overflow(UD60x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows UD60x18.
error PRBMath_UD60x18_Convert_Overflow(uint256 x);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_UD60x18_Exp_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows UD60x18.
error PRBMath_UD60x18_Gm_Overflow(UD60x18 x, UD60x18 y);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_UD60x18_IntoSD1x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD59x18.
error PRBMath_UD60x18_IntoSD59x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_UD60x18_IntoUD2x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_UD60x18_IntoUint128_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_UD60x18_IntoUint40_Overflow(UD60x18 x);
/// @notice Thrown when taking the logarithm of a number less than 1.
error PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x);
/// @notice Thrown when calculating the square root overflows UD60x18.
error PRBMath_UD60x18_Sqrt_Overflow(UD60x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the UD60x18 type.
function add(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and2(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal operation (==) in the UD60x18 type.
function eq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the UD60x18 type.
function gt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the UD60x18 type.
function gte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the UD60x18 type.
function isZero(UD60x18 x) pure returns (bool result) {
// This wouldn't work if x could be negative.
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the UD60x18 type.
function lshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the UD60x18 type.
function lt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the UD60x18 type.
function lte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the checked modulo operation (%) in the UD60x18 type.
function mod(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the UD60x18 type.
function neq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the UD60x18 type.
function not(UD60x18 x) pure returns (UD60x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the UD60x18 type.
function or(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the UD60x18 type.
function rshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the UD60x18 type.
function sub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the UD60x18 type.
function uncheckedAdd(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the UD60x18 type.
function uncheckedSub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the UD60x18 type.
function xor(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { wrap } from "./Casting.sol";
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_UD60x18,
uMAX_WHOLE_UD60x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { UD60x18 } from "./ValueType.sol";
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the arithmetic average of x and y using the following formula:
///
/// $$
/// avg(x, y) = (x & y) + ((xUint ^ yUint) / 2)
/// $$
//
/// In English, this is what this formula does:
///
/// 1. AND x and y.
/// 2. Calculate half of XOR x and y.
/// 3. Add the two results together.
///
/// This technique is known as SWAR, which stands for "SIMD within a register". You can read more about it here:
/// https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223
///
/// @dev Notes:
/// - The result is rounded down.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The arithmetic average as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
unchecked {
result = wrap((xUint & yUint) + ((xUint ^ yUint) >> 1));
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev This is optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be less than or equal to `MAX_WHOLE_UD60x18`.
///
/// @param x The UD60x18 number to ceil.
/// @param result The smallest whole number greater than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint > uMAX_WHOLE_UD60x18) {
revert Errors.PRBMath_UD60x18_Ceil_Overflow(x);
}
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `UNIT - remainder`.
let delta := sub(uUNIT, remainder)
// Equivalent to `x + delta * (remainder > 0 ? 1 : 0)`.
result := add(x, mul(delta, gt(remainder, 0)))
}
}
/// @notice Divides two UD60x18 numbers, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @param x The numerator as a UD60x18 number.
/// @param y The denominator as a UD60x18 number.
/// @param result The quotient as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv(x.unwrap(), uUNIT, y.unwrap()));
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Requirements:
/// - x must be less than 133_084258667509499441.
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// This check prevents values greater than 192 from being passed to {exp2}.
if (xUint > uEXP_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
uint256 doubleUnitProduct = xUint * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method.
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693
///
/// Requirements:
/// - x must be less than 192e18.
/// - The result must fit in UD60x18.
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xUint > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp2_InputTooBig(x);
}
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = (xUint << 64) / uUNIT;
// Pass x to the {Common.exp2} function, which uses the 192.64-bit fixed-point number representation.
result = wrap(Common.exp2(x_192x64));
}
/// @notice Yields the greatest whole number less than or equal to x.
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
/// @param x The UD60x18 number to floor.
/// @param result The greatest whole number less than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `x - remainder * (remainder > 0 ? 1 : 0)`.
result := sub(x, mul(remainder, gt(remainder, 0)))
}
}
/// @notice Yields the excess beyond the floor of x using the odd function definition.
/// @dev See https://en.wikipedia.org/wiki/Fractional_part.
/// @param x The UD60x18 number to get the fractional part of.
/// @param result The fractional part of x as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function frac(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
result := mod(x, uUNIT)
}
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$, rounding down.
///
/// @dev Requirements:
/// - x * y must fit in UD60x18.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
if (xUint == 0 || yUint == 0) {
return ZERO;
}
unchecked {
// Checking for overflow this way is faster than letting Solidity do it.
uint256 xyUint = xUint * yUint;
if (xyUint / xUint != yUint) {
revert Errors.PRBMath_UD60x18_Gm_Overflow(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
result = wrap(Common.sqrt(xyUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded down.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The UD60x18 number for which to calculate the inverse.
/// @return result The inverse as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~196_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this assembly block is the standard multiplication operation, not {UD60x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 59) }
default { result := uMAX_UD60x18 }
}
if (result.unwrap() == uMAX_UD60x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm.
///
/// For $0 \leq x < 1$, the logarithm is calculated as:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x must be greater than zero.
///
/// @param x The UD60x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
unchecked {
// Calculate the integer part of the logarithm, add it to the result and finally calculate $y = x * 2^{-n}$.
uint256 n = Common.msb(xUint / uUNIT);
// This is the integer part of the logarithm as a UD60x18 number. The operation can't overflow because n
// n is at most 255 and UNIT is 1e18.
uint256 resultUint = n * uUNIT;
// This is $y = x * 2^{-n}$.
uint256 y = xUint >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultUint);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
uint256 DOUBLE_UNIT = 2e18;
for (uint256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultUint += delta;
// Corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
result = wrap(resultUint);
}
}
/// @notice Multiplies two UD60x18 numbers together, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @dev See the documentation in {Common.mulDiv18}.
/// @param x The multiplicand as a UD60x18 number.
/// @param y The multiplier as a UD60x18 number.
/// @return result The product as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv18(x.unwrap(), y.unwrap()));
}
/// @notice Raises x to the power of y.
///
/// For $1 \leq x \leq \infty$, the following standard formula is used:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// For $0 \leq x \lt 1$, since the unsigned {log2} is undefined, an equivalent formula is used:
///
/// $$
/// i = \frac{1}{x}
/// w = 2^{log_2{i} * y}
/// x^y = \frac{1}{w}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2} and {mul}.
/// - Returns `UNIT` for 0^0.
/// - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xUint == 0) {
return yUint == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xUint == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yUint == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yUint == uUNIT) {
return x;
}
// If x is greater than `UNIT`, use the standard formula.
if (xUint > uUNIT) {
result = exp2(mul(log2(x), y));
}
// Conversely, if x is less than `UNIT`, use the equivalent formula.
else {
UD60x18 i = wrap(uUNIT_SQUARED / xUint);
UD60x18 w = exp2(mul(log2(i), y));
result = wrap(uUNIT_SQUARED / w.unwrap());
}
}
/// @notice Raises x (a UD60x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - The result must fit in UD60x18.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(UD60x18 x, uint256 y) pure returns (UD60x18 result) {
// Calculate the first iteration of the loop in advance.
uint256 xUint = x.unwrap();
uint256 resultUint = y & 1 > 0 ? xUint : uUNIT;
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
for (y >>= 1; y > 0; y >>= 1) {
xUint = Common.mulDiv18(xUint, xUint);
// Equivalent to `y % 2 == 1`.
if (y & 1 > 0) {
resultUint = Common.mulDiv18(resultUint, xUint);
}
}
result = wrap(resultUint);
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - The result is rounded down.
///
/// Requirements:
/// - x must be less than `MAX_UD60x18 / UNIT`.
///
/// @param x The UD60x18 number for which to calculate the square root.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
unchecked {
if (xUint > uMAX_UD60x18 / uUNIT) {
revert Errors.PRBMath_UD60x18_Sqrt_Overflow(x);
}
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two UD60x18 numbers.
// In this case, the two numbers are both the square root.
result = wrap(Common.sqrt(xUint * uUNIT));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The unsigned 60.18-decimal fixed-point number representation, which can have up to 60 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the Solidity type uint256.
/// @dev The value type is defined here so it can be imported in all other files.
type UD60x18 is uint256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD1x18,
Casting.intoUD2x18,
Casting.intoSD59x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.ln,
Math.log10,
Math.log2,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.xor
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the UD60x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.or as |,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.sub as -,
Helpers.xor as ^
} for UD60x18 global;// 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);
}import "openzeppelin/token/ERC20/IERC20.sol";
IERC20Rebasing constant BLAST_USDB = IERC20Rebasing(
0x4300000000000000000000000000000000000003
);
IERC20Rebasing constant BLAST_WETH = IERC20Rebasing(
0x4300000000000000000000000000000000000004
);
interface IERC20Rebasing is IERC20 {
enum YieldMode {
AUTOMATIC,
VOID,
CLAIMABLE
}
function configure(YieldMode) external returns (uint256);
function claim(
address recipient,
uint256 amount
) external returns (uint256);
function getClaimableAmount(
address account
) external view returns (uint256);
function price() external view returns (uint256);
function sharePrice() external view returns (uint256);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "contracts/interfaces/IVault.sol";
import "contracts/lib/Token.sol";
import "./Pool.sol";
/**
* @dev a base contract for pools with single ERC20 lp token.
*
* Two notable features:
* <1>
* Inspired by composable pools of Balancer, it mints MAX_SUPPLY tokens to the vault on initialization, allowing this pool to 'mint' lp tokens from velocore__execute().
* However, the initial mint only happens in vault's perspective; balanceOf() and totalSupply() is customized to trick the vault into thinking it has MAX_SUPPLY tokens.
* when msg.sender != vault, the view functions behave normally.
*
* <2>
* the vault has max allowance on every addresses by default, and this can't be changed.
*/
abstract contract PoolWithLPToken is Pool, IERC20 {
uint128 constant MAX_SUPPLY = uint128(type(uint112).max);
string public name;
string public symbol;
mapping(address => uint256) _balanceOf;
mapping(address => mapping(address => uint256)) _allowance;
function _initialize(string memory name_, string memory symbol_) internal {
name = name_;
symbol = symbol_;
_mintVirtualSupply();
}
function _mintVirtualSupply() internal {
_balanceOf[address(vault)] = MAX_SUPPLY;
vault.notifyInitialSupply(toToken(this), 0, MAX_SUPPLY); // this sets pool balances to the given value.
}
/**
* @dev due to the mechanism of 'minting' by transferring, mint and burn events behave weirdly.
* this function should be called whenever new tokens are created by transferring.
* these simulate minting and burning from/to the vault.
*/
function _simulateMint(uint256 amount) internal {
emit Transfer(address(0), address(vault), amount);
}
function _simulateBurn(uint256 amount) internal {
emit Transfer(address(vault), address(0), amount);
}
/**
* @dev vault balance is subtracted by pool balance to behave "normally"
*/
function balanceOf(address addr) external view returns (uint256) {
if (msg.sender != address(vault) && addr == address(vault)) {
unchecked {
return _balanceOf[addr] - _getPoolBalance(toToken(this));
}
}
return _balanceOf[addr];
}
function decimals() external view virtual returns (uint8) {
return 18;
}
function allowance(address from, address spender) external view returns (uint256) {
return (spender == address(vault)) ? type(uint256).max : _allowance[from][spender];
}
/**
* @dev subtracted by pool balance to behave "normally"
*/
function totalSupply() public view virtual returns (uint256) {
return MAX_SUPPLY - _getPoolBalance(toToken(this));
}
function approve(address spender, uint256 amount) public virtual returns (bool) {
_allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function increaseAllowance(address _spender, uint256 _addedValue) public returns (bool) {
approve(_spender, _allowance[msg.sender][_spender] + _addedValue);
return true;
}
function decreaseAllowance(address _spender, uint256 _subtractedValue) public returns (bool) {
approve(_spender, _allowance[msg.sender][_spender] - _subtractedValue);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
_balanceOf[msg.sender] -= amount;
unchecked {
_balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {
if (msg.sender != address(vault)) {
uint256 allowed = _allowance[from][msg.sender];
if (allowed != type(uint256).max) _allowance[from][msg.sender] = allowed - amount;
}
_balanceOf[from] -= amount;
unchecked {
_balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
}// 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: AGPL-3.0-only
pragma solidity ^0.8.19;
import "contracts/lib/Token.sol";
interface IPool {
function poolParams() external view returns (bytes memory);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
// Common.sol
//
// Common mathematical functions needed by both SD59x18 and UD60x18. Note that these global functions do not
// always operate with SD59x18 and UD60x18 numbers.
/*//////////////////////////////////////////////////////////////////////////
CUSTOM ERRORS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);
/// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);
/// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
error PRBMath_MulDivSigned_InputTooSmall();
/// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @dev The maximum value a uint128 number can have.
uint128 constant MAX_UINT128 = type(uint128).max;
/// @dev The maximum value a uint40 number can have.
uint40 constant MAX_UINT40 = type(uint40).max;
/// @dev The unit number, which the decimal precision of the fixed-point types.
uint256 constant UNIT = 1e18;
/// @dev The unit number inverted mod 2^256.
uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;
/// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
/// bit in the binary representation of `UNIT`.
uint256 constant UNIT_LPOTD = 262144;
/*//////////////////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the binary exponent of x using the binary fraction method.
/// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
/// @param x The exponent as an unsigned 192.64-bit fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function exp2(uint256 x) pure returns (uint256 result) {
unchecked {
// Start from 0.5 in the 192.64-bit fixed-point format.
result = 0x800000000000000000000000000000000000000000000000;
// The following logic multiplies the result by $\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
//
// 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
// 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
// a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
// we know that `x & 0xFF` is also 1.
if (x & 0xFF00000000000000 > 0) {
if (x & 0x8000000000000000 > 0) {
result = (result * 0x16A09E667F3BCC909) >> 64;
}
if (x & 0x4000000000000000 > 0) {
result = (result * 0x1306FE0A31B7152DF) >> 64;
}
if (x & 0x2000000000000000 > 0) {
result = (result * 0x1172B83C7D517ADCE) >> 64;
}
if (x & 0x1000000000000000 > 0) {
result = (result * 0x10B5586CF9890F62A) >> 64;
}
if (x & 0x800000000000000 > 0) {
result = (result * 0x1059B0D31585743AE) >> 64;
}
if (x & 0x400000000000000 > 0) {
result = (result * 0x102C9A3E778060EE7) >> 64;
}
if (x & 0x200000000000000 > 0) {
result = (result * 0x10163DA9FB33356D8) >> 64;
}
if (x & 0x100000000000000 > 0) {
result = (result * 0x100B1AFA5ABCBED61) >> 64;
}
}
if (x & 0xFF000000000000 > 0) {
if (x & 0x80000000000000 > 0) {
result = (result * 0x10058C86DA1C09EA2) >> 64;
}
if (x & 0x40000000000000 > 0) {
result = (result * 0x1002C605E2E8CEC50) >> 64;
}
if (x & 0x20000000000000 > 0) {
result = (result * 0x100162F3904051FA1) >> 64;
}
if (x & 0x10000000000000 > 0) {
result = (result * 0x1000B175EFFDC76BA) >> 64;
}
if (x & 0x8000000000000 > 0) {
result = (result * 0x100058BA01FB9F96D) >> 64;
}
if (x & 0x4000000000000 > 0) {
result = (result * 0x10002C5CC37DA9492) >> 64;
}
if (x & 0x2000000000000 > 0) {
result = (result * 0x1000162E525EE0547) >> 64;
}
if (x & 0x1000000000000 > 0) {
result = (result * 0x10000B17255775C04) >> 64;
}
}
if (x & 0xFF0000000000 > 0) {
if (x & 0x800000000000 > 0) {
result = (result * 0x1000058B91B5BC9AE) >> 64;
}
if (x & 0x400000000000 > 0) {
result = (result * 0x100002C5C89D5EC6D) >> 64;
}
if (x & 0x200000000000 > 0) {
result = (result * 0x10000162E43F4F831) >> 64;
}
if (x & 0x100000000000 > 0) {
result = (result * 0x100000B1721BCFC9A) >> 64;
}
if (x & 0x80000000000 > 0) {
result = (result * 0x10000058B90CF1E6E) >> 64;
}
if (x & 0x40000000000 > 0) {
result = (result * 0x1000002C5C863B73F) >> 64;
}
if (x & 0x20000000000 > 0) {
result = (result * 0x100000162E430E5A2) >> 64;
}
if (x & 0x10000000000 > 0) {
result = (result * 0x1000000B172183551) >> 64;
}
}
if (x & 0xFF00000000 > 0) {
if (x & 0x8000000000 > 0) {
result = (result * 0x100000058B90C0B49) >> 64;
}
if (x & 0x4000000000 > 0) {
result = (result * 0x10000002C5C8601CC) >> 64;
}
if (x & 0x2000000000 > 0) {
result = (result * 0x1000000162E42FFF0) >> 64;
}
if (x & 0x1000000000 > 0) {
result = (result * 0x10000000B17217FBB) >> 64;
}
if (x & 0x800000000 > 0) {
result = (result * 0x1000000058B90BFCE) >> 64;
}
if (x & 0x400000000 > 0) {
result = (result * 0x100000002C5C85FE3) >> 64;
}
if (x & 0x200000000 > 0) {
result = (result * 0x10000000162E42FF1) >> 64;
}
if (x & 0x100000000 > 0) {
result = (result * 0x100000000B17217F8) >> 64;
}
}
if (x & 0xFF000000 > 0) {
if (x & 0x80000000 > 0) {
result = (result * 0x10000000058B90BFC) >> 64;
}
if (x & 0x40000000 > 0) {
result = (result * 0x1000000002C5C85FE) >> 64;
}
if (x & 0x20000000 > 0) {
result = (result * 0x100000000162E42FF) >> 64;
}
if (x & 0x10000000 > 0) {
result = (result * 0x1000000000B17217F) >> 64;
}
if (x & 0x8000000 > 0) {
result = (result * 0x100000000058B90C0) >> 64;
}
if (x & 0x4000000 > 0) {
result = (result * 0x10000000002C5C860) >> 64;
}
if (x & 0x2000000 > 0) {
result = (result * 0x1000000000162E430) >> 64;
}
if (x & 0x1000000 > 0) {
result = (result * 0x10000000000B17218) >> 64;
}
}
if (x & 0xFF0000 > 0) {
if (x & 0x800000 > 0) {
result = (result * 0x1000000000058B90C) >> 64;
}
if (x & 0x400000 > 0) {
result = (result * 0x100000000002C5C86) >> 64;
}
if (x & 0x200000 > 0) {
result = (result * 0x10000000000162E43) >> 64;
}
if (x & 0x100000 > 0) {
result = (result * 0x100000000000B1721) >> 64;
}
if (x & 0x80000 > 0) {
result = (result * 0x10000000000058B91) >> 64;
}
if (x & 0x40000 > 0) {
result = (result * 0x1000000000002C5C8) >> 64;
}
if (x & 0x20000 > 0) {
result = (result * 0x100000000000162E4) >> 64;
}
if (x & 0x10000 > 0) {
result = (result * 0x1000000000000B172) >> 64;
}
}
if (x & 0xFF00 > 0) {
if (x & 0x8000 > 0) {
result = (result * 0x100000000000058B9) >> 64;
}
if (x & 0x4000 > 0) {
result = (result * 0x10000000000002C5D) >> 64;
}
if (x & 0x2000 > 0) {
result = (result * 0x1000000000000162E) >> 64;
}
if (x & 0x1000 > 0) {
result = (result * 0x10000000000000B17) >> 64;
}
if (x & 0x800 > 0) {
result = (result * 0x1000000000000058C) >> 64;
}
if (x & 0x400 > 0) {
result = (result * 0x100000000000002C6) >> 64;
}
if (x & 0x200 > 0) {
result = (result * 0x10000000000000163) >> 64;
}
if (x & 0x100 > 0) {
result = (result * 0x100000000000000B1) >> 64;
}
}
if (x & 0xFF > 0) {
if (x & 0x80 > 0) {
result = (result * 0x10000000000000059) >> 64;
}
if (x & 0x40 > 0) {
result = (result * 0x1000000000000002C) >> 64;
}
if (x & 0x20 > 0) {
result = (result * 0x10000000000000016) >> 64;
}
if (x & 0x10 > 0) {
result = (result * 0x1000000000000000B) >> 64;
}
if (x & 0x8 > 0) {
result = (result * 0x10000000000000006) >> 64;
}
if (x & 0x4 > 0) {
result = (result * 0x10000000000000003) >> 64;
}
if (x & 0x2 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
if (x & 0x1 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
}
// In the code snippet below, two operations are executed simultaneously:
//
// 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
// accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
// 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
//
// The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
// integer part, $2^n$.
result *= UNIT;
result >>= (191 - (x >> 64));
}
}
/// @notice Finds the zero-based index of the first 1 in the binary representation of x.
///
/// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
///
/// Each step in this implementation is equivalent to this high-level code:
///
/// ```solidity
/// if (x >= 2 ** 128) {
/// x >>= 128;
/// result += 128;
/// }
/// ```
///
/// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
/// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
///
/// The Yul instructions used below are:
///
/// - "gt" is "greater than"
/// - "or" is the OR bitwise operator
/// - "shl" is "shift left"
/// - "shr" is "shift right"
///
/// @param x The uint256 number for which to find the index of the most significant bit.
/// @return result The index of the most significant bit as a uint256.
/// @custom:smtchecker abstract-function-nondet
function msb(uint256 x) pure returns (uint256 result) {
// 2^128
assembly ("memory-safe") {
let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^64
assembly ("memory-safe") {
let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^32
assembly ("memory-safe") {
let factor := shl(5, gt(x, 0xFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^16
assembly ("memory-safe") {
let factor := shl(4, gt(x, 0xFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^8
assembly ("memory-safe") {
let factor := shl(3, gt(x, 0xFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^4
assembly ("memory-safe") {
let factor := shl(2, gt(x, 0xF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^2
assembly ("memory-safe") {
let factor := shl(1, gt(x, 0x3))
x := shr(factor, x)
result := or(result, factor)
}
// 2^1
// No need to shift x any more.
assembly ("memory-safe") {
let factor := gt(x, 0x1)
result := or(result, factor)
}
}
/// @notice Calculates floor(x*y÷denominator) with 512-bit precision.
///
/// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
///
/// Notes:
/// - The result is rounded down.
///
/// Requirements:
/// - The denominator must not be zero.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as a uint256.
/// @param y The multiplier as a uint256.
/// @param denominator The divisor as a uint256.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
// 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 ("memory-safe") {
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) {
unchecked {
return prod0 / denominator;
}
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (prod1 >= denominator) {
revert PRBMath_MulDiv_Overflow(x, y, denominator);
}
////////////////////////////////////////////////////////////////////////////
// 512 by 256 division
////////////////////////////////////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using the mulmod Yul instruction.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512-bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
unchecked {
// Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
// because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
// For more detail, see https://cs.stackexchange.com/q/138556/92363.
uint256 lpotdod = denominator & (~denominator + 1);
uint256 flippedLpotdod;
assembly ("memory-safe") {
// Factor powers of two out of denominator.
denominator := div(denominator, lpotdod)
// Divide [prod1 prod0] by lpotdod.
prod0 := div(prod0, lpotdod)
// Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
// `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
// However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * flippedLpotdod;
// 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;
}
}
/// @notice Calculates floor(x*y÷1e18) with 512-bit precision.
///
/// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
///
/// Notes:
/// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
/// - The result is rounded down.
/// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
///
/// $$
/// \begin{cases}
/// x * y = MAX\_UINT256 * UNIT \\
/// (x * y) \% UNIT \geq \frac{UNIT}{2}
/// \end{cases}
/// $$
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
/// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
uint256 prod0;
uint256 prod1;
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
unchecked {
return prod0 / UNIT;
}
}
if (prod1 >= UNIT) {
revert PRBMath_MulDiv18_Overflow(x, y);
}
uint256 remainder;
assembly ("memory-safe") {
remainder := mulmod(x, y, UNIT)
result :=
mul(
or(
div(sub(prod0, remainder), UNIT_LPOTD),
mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
),
UNIT_INVERSE
)
}
}
/// @notice Calculates floor(x*y÷denominator) with 512-bit precision.
///
/// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
///
/// Notes:
/// - Unlike {mulDiv}, the result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - None of the inputs can be `type(int256).min`.
/// - The result must fit in int256.
///
/// @param x The multiplicand as an int256.
/// @param y The multiplier as an int256.
/// @param denominator The divisor as an int256.
/// @return result The result as an int256.
/// @custom:smtchecker abstract-function-nondet
function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
revert PRBMath_MulDivSigned_InputTooSmall();
}
// Get hold of the absolute values of x, y and the denominator.
uint256 xAbs;
uint256 yAbs;
uint256 dAbs;
unchecked {
xAbs = x < 0 ? uint256(-x) : uint256(x);
yAbs = y < 0 ? uint256(-y) : uint256(y);
dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
}
// Compute the absolute value of x*y÷denominator. The result must fit in int256.
uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
if (resultAbs > uint256(type(int256).max)) {
revert PRBMath_MulDivSigned_Overflow(x, y);
}
// Get the signs of x, y and the denominator.
uint256 sx;
uint256 sy;
uint256 sd;
assembly ("memory-safe") {
// This works thanks to two's complement.
// "sgt" stands for "signed greater than" and "sub(0,1)" is max uint256.
sx := sgt(x, sub(0, 1))
sy := sgt(y, sub(0, 1))
sd := sgt(denominator, sub(0, 1))
}
// XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
// If there are, the result should be negative. Otherwise, it should be positive.
unchecked {
result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - If x is not a perfect square, the result is rounded down.
/// - Credits to OpenZeppelin for the explanations in comments below.
///
/// @param x The uint256 number for which to calculate the square root.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function sqrt(uint256 x) pure returns (uint256 result) {
if (x == 0) {
return 0;
}
// For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
//
// We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
//
// $$
// msb(x) <= x <= 2*msb(x)$
// $$
//
// We write $msb(x)$ as $2^k$, and we get:
//
// $$
// k = log_2(x)
// $$
//
// Thus, we can write the initial inequality as:
//
// $$
// 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\
// sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\
// 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
// $$
//
// Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
uint256 xAux = uint256(x);
result = 1;
if (xAux >= 2 ** 128) {
xAux >>= 128;
result <<= 64;
}
if (xAux >= 2 ** 64) {
xAux >>= 64;
result <<= 32;
}
if (xAux >= 2 ** 32) {
xAux >>= 32;
result <<= 16;
}
if (xAux >= 2 ** 16) {
xAux >>= 16;
result <<= 8;
}
if (xAux >= 2 ** 8) {
xAux >>= 8;
result <<= 4;
}
if (xAux >= 2 ** 4) {
xAux >>= 4;
result <<= 2;
}
if (xAux >= 2 ** 2) {
result <<= 1;
}
// At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
// most 128 bits, 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 + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
// If x is not a perfect square, round down the result.
uint256 roundedDownResult = x / result;
if (result >= roundedDownResult) {
result = roundedDownResult;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @dev Euler's number as an SD1x18 number.
SD1x18 constant E = SD1x18.wrap(2_718281828459045235);
/// @dev The maximum value an SD1x18 number can have.
int64 constant uMAX_SD1x18 = 9_223372036854775807;
SD1x18 constant MAX_SD1x18 = SD1x18.wrap(uMAX_SD1x18);
/// @dev The maximum value an SD1x18 number can have.
int64 constant uMIN_SD1x18 = -9_223372036854775808;
SD1x18 constant MIN_SD1x18 = SD1x18.wrap(uMIN_SD1x18);
/// @dev PI as an SD1x18 number.
SD1x18 constant PI = SD1x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD1x18.
SD1x18 constant UNIT = SD1x18.wrap(1e18);
int256 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The signed 1.18-decimal fixed-point number representation, which can have up to 1 digit and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int64. This is useful when end users want to use int64 to save gas, e.g. with tight variable packing in contract
/// storage.
type SD1x18 is int64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD2x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for SD1x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as an SD59x18 number.
SD59x18 constant E = SD59x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
int256 constant uEXP_MAX_INPUT = 133_084258667509499440;
SD59x18 constant EXP_MAX_INPUT = SD59x18.wrap(uEXP_MAX_INPUT);
/// @dev The maximum input permitted in {exp2}.
int256 constant uEXP2_MAX_INPUT = 192e18 - 1;
SD59x18 constant EXP2_MAX_INPUT = SD59x18.wrap(uEXP2_MAX_INPUT);
/// @dev Half the UNIT number.
int256 constant uHALF_UNIT = 0.5e18;
SD59x18 constant HALF_UNIT = SD59x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as an SD59x18 number.
int256 constant uLOG2_10 = 3_321928094887362347;
SD59x18 constant LOG2_10 = SD59x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as an SD59x18 number.
int256 constant uLOG2_E = 1_442695040888963407;
SD59x18 constant LOG2_E = SD59x18.wrap(uLOG2_E);
/// @dev The maximum value an SD59x18 number can have.
int256 constant uMAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967;
SD59x18 constant MAX_SD59x18 = SD59x18.wrap(uMAX_SD59x18);
/// @dev The maximum whole value an SD59x18 number can have.
int256 constant uMAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MAX_WHOLE_SD59x18 = SD59x18.wrap(uMAX_WHOLE_SD59x18);
/// @dev The minimum value an SD59x18 number can have.
int256 constant uMIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968;
SD59x18 constant MIN_SD59x18 = SD59x18.wrap(uMIN_SD59x18);
/// @dev The minimum whole value an SD59x18 number can have.
int256 constant uMIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MIN_WHOLE_SD59x18 = SD59x18.wrap(uMIN_WHOLE_SD59x18);
/// @dev PI as an SD59x18 number.
SD59x18 constant PI = SD59x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD59x18.
int256 constant uUNIT = 1e18;
SD59x18 constant UNIT = SD59x18.wrap(1e18);
/// @dev The unit number squared.
int256 constant uUNIT_SQUARED = 1e36;
SD59x18 constant UNIT_SQUARED = SD59x18.wrap(uUNIT_SQUARED);
/// @dev Zero as an SD59x18 number.
SD59x18 constant ZERO = SD59x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The signed 59.18-decimal fixed-point number representation, which can have up to 59 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int256.
type SD59x18 is int256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoInt256,
Casting.intoSD1x18,
Casting.intoUD2x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Math.abs,
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.log10,
Math.log2,
Math.ln,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.uncheckedUnary,
Helpers.xor
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the SD59x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.or as |,
Helpers.sub as -,
Helpers.unary as -,
Helpers.xor as ^
} for SD59x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @dev Euler's number as a UD2x18 number.
UD2x18 constant E = UD2x18.wrap(2_718281828459045235);
/// @dev The maximum value a UD2x18 number can have.
uint64 constant uMAX_UD2x18 = 18_446744073709551615;
UD2x18 constant MAX_UD2x18 = UD2x18.wrap(uMAX_UD2x18);
/// @dev PI as a UD2x18 number.
UD2x18 constant PI = UD2x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD2x18.
uint256 constant uUNIT = 1e18;
UD2x18 constant UNIT = UD2x18.wrap(1e18);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The unsigned 2.18-decimal fixed-point number representation, which can have up to 2 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type uint64. This is useful when end users want to use uint64 to save gas, e.g. with tight variable packing in contract
/// storage.
type UD2x18 is uint64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD1x18,
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for UD2x18 global;// 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: UNLICENSED
pragma solidity ^0.8.19;
import "contracts/lib/Token.sol";
import "contracts/lib/PoolBalanceLib.sol";
import "contracts/lib/UncheckedMemory.sol";
import "contracts/interfaces/IVault.sol";
import "contracts/interfaces/ISwap.sol";
import "contracts/interfaces/IAuthorizer.sol";
import "contracts/VaultStorage.sol";
import "./Satellite.sol";
/**
* @dev a base contract for pools.
*
* - holds pool-specific slot of vault's storage as an immutable value.
* - provides getters for the slot.
*
*/
abstract contract Pool is IPool, Satellite {
using PoolBalanceLib for PoolBalance;
using UncheckedMemory for bytes32[];
using UncheckedMemory for Token[];
address immutable selfAddr;
constructor(
IVault vault_,
address selfAddr_,
address factory
) Satellite(vault_, factory) {
selfAddr = selfAddr_;
}
/**
* pool balance is stored as two uint128; poolBalance and gaugeBalance.
*/
function _getPoolBalance(Token token) internal view returns (uint256) {
return vault.getPoolBalance(selfAddr, token);
}
function _getGaugeBalance(Token token) internal view returns (uint256) {
return vault.getGaugeBalance(selfAddr, token);
}
function _getPoolBalances(
Token[] memory tokens
) internal view returns (uint256[] memory ret2) {
uint256[] memory ret = new uint256[](tokens.length);
for (uint256 i = 0; i < tokens.length; ++i) {
ret[i] = vault.getPoolBalance(selfAddr, tokens[i]);
}
}
function poolParams()
external
view
virtual
override
returns (bytes memory)
{
return "";
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as CastingErrors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD1x18 } from "./ValueType.sol";
/// @notice Casts an SD1x18 number into SD59x18.
/// @dev There is no overflow check because the domain of SD1x18 is a subset of SD59x18.
function intoSD59x18(SD1x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(SD1x18.unwrap(x)));
}
/// @notice Casts an SD1x18 number into UD2x18.
/// - x must be positive.
function intoUD2x18(SD1x18 x) pure returns (UD2x18 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUD2x18_Underflow(x);
}
result = UD2x18.wrap(uint64(xInt));
}
/// @notice Casts an SD1x18 number into UD60x18.
/// @dev Requirements:
/// - x must be positive.
function intoUD60x18(SD1x18 x) pure returns (UD60x18 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint256.
/// @dev Requirements:
/// - x must be positive.
function intoUint256(SD1x18 x) pure returns (uint256 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint256_Underflow(x);
}
result = uint256(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint128.
/// @dev Requirements:
/// - x must be positive.
function intoUint128(SD1x18 x) pure returns (uint128 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint128_Underflow(x);
}
result = uint128(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint40.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(SD1x18 x) pure returns (uint40 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Underflow(x);
}
if (xInt > int64(uint64(Common.MAX_UINT40))) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Overflow(x);
}
result = uint40(uint64(xInt));
}
/// @notice Alias for {wrap}.
function sd1x18(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}
/// @notice Unwraps an SD1x18 number into int64.
function unwrap(SD1x18 x) pure returns (int64 result) {
result = SD1x18.unwrap(x);
}
/// @notice Wraps an int64 number into SD1x18.
function wrap(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18, uMIN_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Casts an SD59x18 number into int256.
/// @dev This is basically a functional alias for {unwrap}.
function intoInt256(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Casts an SD59x18 number into SD1x18.
/// @dev Requirements:
/// - x must be greater than or equal to `uMIN_SD1x18`.
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(SD59x18 x) pure returns (SD1x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < uMIN_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Underflow(x);
}
if (xInt > uMAX_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(xInt));
}
/// @notice Casts an SD59x18 number into UD2x18.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `uMAX_UD2x18`.
function intoUD2x18(SD59x18 x) pure returns (UD2x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Underflow(x);
}
if (xInt > int256(uint256(uMAX_UD2x18))) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(uint256(xInt)));
}
/// @notice Casts an SD59x18 number into UD60x18.
/// @dev Requirements:
/// - x must be positive.
function intoUD60x18(SD59x18 x) pure returns (UD60x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint256.
/// @dev Requirements:
/// - x must be positive.
function intoUint256(SD59x18 x) pure returns (uint256 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint256_Underflow(x);
}
result = uint256(xInt);
}
/// @notice Casts an SD59x18 number into uint128.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `uMAX_UINT128`.
function intoUint128(SD59x18 x) pure returns (uint128 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT128))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Overflow(x);
}
result = uint128(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint40.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(SD59x18 x) pure returns (uint40 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT40))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Overflow(x);
}
result = uint40(uint256(xInt));
}
/// @notice Alias for {wrap}.
function sd(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Alias for {wrap}.
function sd59x18(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Unwraps an SD59x18 number into int256.
function unwrap(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Wraps an int256 number into SD59x18.
function wrap(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the SD59x18 type.
function add(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and(SD59x18 x, int256 bits) pure returns (SD59x18 result) {
return wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and2(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal (=) operation in the SD59x18 type.
function eq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the SD59x18 type.
function gt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the SD59x18 type.
function gte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the SD59x18 type.
function isZero(SD59x18 x) pure returns (bool result) {
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the SD59x18 type.
function lshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the SD59x18 type.
function lt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the SD59x18 type.
function lte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the unchecked modulo operation (%) in the SD59x18 type.
function mod(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the SD59x18 type.
function neq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the SD59x18 type.
function not(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the SD59x18 type.
function or(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the SD59x18 type.
function rshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the SD59x18 type.
function sub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the checked unary minus operation (-) in the SD59x18 type.
function unary(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(-x.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the SD59x18 type.
function uncheckedAdd(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the SD59x18 type.
function uncheckedSub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the unchecked unary minus operation (-) in the SD59x18 type.
function uncheckedUnary(SD59x18 x) pure returns (SD59x18 result) {
unchecked {
result = wrap(-x.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the SD59x18 type.
function xor(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_SD59x18,
uMAX_WHOLE_SD59x18,
uMIN_SD59x18,
uMIN_WHOLE_SD59x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { wrap } from "./Helpers.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Calculates the absolute value of x.
///
/// @dev Requirements:
/// - x must be greater than `MIN_SD59x18`.
///
/// @param x The SD59x18 number for which to calculate the absolute value.
/// @param result The absolute value of x as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function abs(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Abs_MinSD59x18();
}
result = xInt < 0 ? wrap(-xInt) : x;
}
/// @notice Calculates the arithmetic average of x and y.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The arithmetic average as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
unchecked {
// This operation is equivalent to `x / 2 + y / 2`, and it can never overflow.
int256 sum = (xInt >> 1) + (yInt >> 1);
if (sum < 0) {
// If at least one of x and y is odd, add 1 to the result, because shifting negative numbers to the right
// rounds down to infinity. The right part is equivalent to `sum + (x % 2 == 1 || y % 2 == 1)`.
assembly ("memory-safe") {
result := add(sum, and(or(xInt, yInt), 1))
}
} else {
// Add 1 if both x and y are odd to account for the double 0.5 remainder truncated after shifting.
result = wrap(sum + (xInt & yInt & 1));
}
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be less than or equal to `MAX_WHOLE_SD59x18`.
///
/// @param x The SD59x18 number to ceil.
/// @param result The smallest whole number greater than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt > uMAX_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Ceil_Overflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt > 0) {
resultInt += uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Divides two SD59x18 numbers, returning a new SD59x18 number.
///
/// @dev This is an extension of {Common.mulDiv} for signed numbers, which works by computing the signs and the absolute
/// values separately.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The denominator must not be zero.
/// - The result must fit in SD59x18.
///
/// @param x The numerator as an SD59x18 number.
/// @param y The denominator as an SD59x18 number.
/// @param result The quotient as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Div_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*UNIT÷y). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv(xAbs, uint256(uUNIT), yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Div_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}.
///
/// Requirements:
/// - Refer to the requirements in {exp2}.
/// - x must be less than 133_084258667509499441.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
// This check prevents values greater than 192 from being passed to {exp2}.
if (xInt > uEXP_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
int256 doubleUnitProduct = xInt * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method using the following formula:
///
/// $$
/// 2^{-x} = \frac{1}{2^x}
/// $$
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693.
///
/// Notes:
/// - If x is less than -59_794705707972522261, the result is zero.
///
/// Requirements:
/// - x must be less than 192e18.
/// - The result must fit in SD59x18.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
// The inverse of any number less than this is truncated to zero.
if (xInt < -59_794705707972522261) {
return ZERO;
}
unchecked {
// Inline the fixed-point inversion to save gas.
result = wrap(uUNIT_SQUARED / exp2(wrap(-xInt)).unwrap());
}
} else {
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xInt > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp2_InputTooBig(x);
}
unchecked {
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = uint256((xInt << 64) / uUNIT);
// It is safe to cast the result to int256 due to the checks above.
result = wrap(int256(Common.exp2(x_192x64)));
}
}
}
/// @notice Yields the greatest whole number less than or equal to x.
///
/// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be greater than or equal to `MIN_WHOLE_SD59x18`.
///
/// @param x The SD59x18 number to floor.
/// @param result The greatest whole number less than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < uMIN_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Floor_Underflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt < 0) {
resultInt -= uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right.
/// of the radix point for negative numbers.
/// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
/// @param x The SD59x18 number to get the fractional part of.
/// @param result The fractional part of x as an SD59x18 number.
function frac(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % uUNIT);
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x * y must fit in SD59x18.
/// - x * y must not be negative, since complex numbers are not supported.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == 0 || yInt == 0) {
return ZERO;
}
unchecked {
// Equivalent to `xy / x != y`. Checking for overflow this way is faster than letting Solidity do it.
int256 xyInt = xInt * yInt;
if (xyInt / xInt != yInt) {
revert Errors.PRBMath_SD59x18_Gm_Overflow(x, y);
}
// The product must not be negative, since complex numbers are not supported.
if (xyInt < 0) {
revert Errors.PRBMath_SD59x18_Gm_NegativeProduct(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
uint256 resultUint = Common.sqrt(uint256(xyInt));
result = wrap(int256(resultUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The SD59x18 number for which to calculate the inverse.
/// @return result The inverse as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(SD59x18 x) pure returns (SD59x18 result) {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~195_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this block is the standard multiplication operation, not {SD59x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
default { result := uMAX_SD59x18 }
}
if (result.unwrap() == uMAX_SD59x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm.
///
/// For $0 \leq x \lt 1$, the logarithm is calculated as:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation.
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x must be greater than zero.
///
/// @param x The SD59x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt <= 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
unchecked {
int256 sign;
if (xInt >= uUNIT) {
sign = 1;
} else {
sign = -1;
// Inline the fixed-point inversion to save gas.
xInt = uUNIT_SQUARED / xInt;
}
// Calculate the integer part of the logarithm and add it to the result and finally calculate $y = x * 2^{-n}$.
uint256 n = Common.msb(uint256(xInt / uUNIT));
// This is the integer part of the logarithm as an SD59x18 number. The operation can't overflow
// because n is at most 255, `UNIT` is 1e18, and the sign is either 1 or -1.
int256 resultInt = int256(n) * uUNIT;
// This is $y = x * 2^{-n}$.
int256 y = xInt >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultInt * sign);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
int256 DOUBLE_UNIT = 2e18;
for (int256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultInt = resultInt + delta;
// Corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
resultInt *= sign;
result = wrap(resultInt);
}
}
/// @notice Multiplies two SD59x18 numbers together, returning a new SD59x18 number.
///
/// @dev Notes:
/// - Refer to the notes in {Common.mulDiv18}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv18}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The result must fit in SD59x18.
///
/// @param x The multiplicand as an SD59x18 number.
/// @param y The multiplier as an SD59x18 number.
/// @return result The product as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Mul_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*y÷UNIT). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv18(xAbs, yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Mul_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Raises x to the power of y using the following formula:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}, {log2}, and {mul}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as an SD59x18 number.
/// @param y Exponent to raise x to, as an SD59x18 number
/// @return result x raised to power y, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xInt == 0) {
return yInt == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xInt == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yInt == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yInt == uUNIT) {
return x;
}
// Calculate the result using the formula.
result = exp2(mul(log2(x), y));
}
/// @notice Raises x (an SD59x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {abs} and {Common.mulDiv18}.
/// - The result must fit in SD59x18.
///
/// @param x The base as an SD59x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(SD59x18 x, uint256 y) pure returns (SD59x18 result) {
uint256 xAbs = uint256(abs(x).unwrap());
// Calculate the first iteration of the loop in advance.
uint256 resultAbs = y & 1 > 0 ? xAbs : uint256(uUNIT);
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
uint256 yAux = y;
for (yAux >>= 1; yAux > 0; yAux >>= 1) {
xAbs = Common.mulDiv18(xAbs, xAbs);
// Equivalent to `y % 2 == 1`.
if (yAux & 1 > 0) {
resultAbs = Common.mulDiv18(resultAbs, xAbs);
}
}
// The result must fit in SD59x18.
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Powu_Overflow(x, y);
}
unchecked {
// Is the base negative and the exponent odd? If yes, the result should be negative.
int256 resultInt = int256(resultAbs);
bool isNegative = x.unwrap() < 0 && y & 1 == 1;
if (isNegative) {
resultInt = -resultInt;
}
result = wrap(resultInt);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - Only the positive root is returned.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x cannot be negative, since complex numbers are not supported.
/// - x must be less than `MAX_SD59x18 / UNIT`.
///
/// @param x The SD59x18 number for which to calculate the square root.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Sqrt_NegativeInput(x);
}
if (xInt > uMAX_SD59x18 / uUNIT) {
revert Errors.PRBMath_SD59x18_Sqrt_Overflow(x);
}
unchecked {
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two SD59x18 numbers.
// In this case, the two numbers are both the square root.
uint256 resultUint = Common.sqrt(uint256(xInt * uUNIT));
result = wrap(int256(resultUint));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { UD2x18 } from "./ValueType.sol";
/// @notice Casts a UD2x18 number into SD1x18.
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(UD2x18 x) pure returns (SD1x18 result) {
uint64 xUint = UD2x18.unwrap(x);
if (xUint > uint64(uMAX_SD1x18)) {
revert Errors.PRBMath_UD2x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(xUint));
}
/// @notice Casts a UD2x18 number into SD59x18.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of SD59x18.
function intoSD59x18(UD2x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(uint256(UD2x18.unwrap(x))));
}
/// @notice Casts a UD2x18 number into UD60x18.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of UD60x18.
function intoUD60x18(UD2x18 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint128.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of uint128.
function intoUint128(UD2x18 x) pure returns (uint128 result) {
result = uint128(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint256.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of uint256.
function intoUint256(UD2x18 x) pure returns (uint256 result) {
result = uint256(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint40.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(UD2x18 x) pure returns (uint40 result) {
uint64 xUint = UD2x18.unwrap(x);
if (xUint > uint64(Common.MAX_UINT40)) {
revert Errors.PRBMath_UD2x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud2x18(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}
/// @notice Unwrap a UD2x18 number into uint64.
function unwrap(UD2x18 x) pure returns (uint64 result) {
result = UD2x18.unwrap(x);
}
/// @notice Wraps a uint64 number into UD2x18.
function wrap(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}// 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;
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import "contracts/lib/Token.sol";
import "contracts/interfaces/IVault.sol";
import "contracts/interfaces/IGauge.sol";
import "contracts/lib/PoolBalanceLib.sol";
import "contracts/interfaces/IGauge.sol";
import "contracts/interfaces/IBribe.sol";
import "contracts/interfaces/IAuthorizer.sol";
import "openzeppelin/utils/structs/BitMaps.sol";
import "openzeppelin/utils/StorageSlot.sol";
import "openzeppelin/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
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in UD2x18.
error PRBMath_SD1x18_ToUD2x18_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in UD60x18.
error PRBMath_SD1x18_ToUD60x18_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint128.
error PRBMath_SD1x18_ToUint128_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint256.
error PRBMath_SD1x18_ToUint256_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Overflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Underflow(SD1x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
/// @notice Thrown when taking the absolute value of `MIN_SD59x18`.
error PRBMath_SD59x18_Abs_MinSD59x18();
/// @notice Thrown when ceiling a number overflows SD59x18.
error PRBMath_SD59x18_Ceil_Overflow(SD59x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMath_SD59x18_Convert_Overflow(int256 x);
/// @notice Thrown when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMath_SD59x18_Convert_Underflow(int256 x);
/// @notice Thrown when dividing two numbers and one of them is `MIN_SD59x18`.
error PRBMath_SD59x18_Div_InputTooSmall();
/// @notice Thrown when dividing two numbers and one of the intermediary unsigned results overflows SD59x18.
error PRBMath_SD59x18_Div_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_SD59x18_Exp_InputTooBig(SD59x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_SD59x18_Exp2_InputTooBig(SD59x18 x);
/// @notice Thrown when flooring a number underflows SD59x18.
error PRBMath_SD59x18_Floor_Underflow(SD59x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and their product is negative.
error PRBMath_SD59x18_Gm_NegativeProduct(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows SD59x18.
error PRBMath_SD59x18_Gm_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD60x18.
error PRBMath_SD59x18_IntoUD60x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint256.
error PRBMath_SD59x18_IntoUint256_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Underflow(SD59x18 x);
/// @notice Thrown when taking the logarithm of a number less than or equal to zero.
error PRBMath_SD59x18_Log_InputTooSmall(SD59x18 x);
/// @notice Thrown when multiplying two numbers and one of the inputs is `MIN_SD59x18`.
error PRBMath_SD59x18_Mul_InputTooSmall();
/// @notice Thrown when multiplying two numbers and the intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Mul_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when raising a number to a power and hte intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Powu_Overflow(SD59x18 x, uint256 y);
/// @notice Thrown when taking the square root of a negative number.
error PRBMath_SD59x18_Sqrt_NegativeInput(SD59x18 x);
/// @notice Thrown when the calculating the square root overflows SD59x18.
error PRBMath_SD59x18_Sqrt_Overflow(SD59x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in SD1x18.
error PRBMath_UD2x18_IntoSD1x18_Overflow(UD2x18 x);
/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in uint40.
error PRBMath_UD2x18_IntoUint40_Overflow(UD2x18 x);// 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
}
}
}{
"remappings": [
"@prb/test/=lib/prb-math/lib/prb-test/src/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"openzeppelin/=lib/openzeppelin-contracts/contracts/",
"openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@prb/math/=lib/prb-math/",
"prb-test/=lib/prb-math/lib/prb-test/src/",
"solmate/=lib/solmate/src/",
"lzapp/=lib/solidity-examples/contracts/",
"LayerZero/=lib/LayerZero/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"prb-math/=lib/prb-math/src/",
"solidity-examples/=lib/solidity-examples/contracts/"
],
"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 IVault","name":"vault_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"decay","type":"uint256"}],"name":"DecayChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee1e18","type":"uint256"}],"name":"FeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract XYKPool","name":"pool","type":"address"},{"indexed":false,"internalType":"Token","name":"t1","type":"bytes32"},{"indexed":false,"internalType":"Token","name":"t2","type":"bytes32"}],"name":"PoolCreated","type":"event"},{"inputs":[{"internalType":"Token","name":"quoteToken","type":"bytes32"},{"internalType":"Token","name":"baseToken","type":"bytes32"}],"name":"deploy","outputs":[{"internalType":"contract XYKPool","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"begin","type":"uint256"},{"internalType":"uint256","name":"maxLength","type":"uint256"}],"name":"getPools","outputs":[{"internalType":"contract XYKPool[]","name":"pools","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract XYKPool","name":"","type":"address"}],"name":"isPool","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"poolList","outputs":[{"internalType":"contract XYKPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Token","name":"","type":"bytes32"},{"internalType":"Token","name":"","type":"bytes32"}],"name":"pools","outputs":[{"internalType":"contract XYKPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"decay_","type":"uint32"}],"name":"setDecay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"fee1e9_","type":"uint32"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60c03461018657601f620053b038819003918201601f191683019260009290916001600160401b0385118386101761017257816020928492604097885283398101031261014357516001600160a01b038116810361014357734300000000000000000000000000000000000002803b15610151578351634e606c4760e01b8152838160048183865af1801561016857610155575b50803b15610151578280916024865180948193631d70c8d360e31b83527365432138ae74065aeb3bd71aeac887ccae0e32a460048401525af180156101475790839161012f575b50506080523060a052805463ffffffff60201b191667ffffd32300000000179055516151fb9081620001b582396080518181816107890152610a28015260a05181818160a80152818161028101526104e40152f35b6101389061018b565b6101435781386100da565b5080fd5b84513d85823e3d90fd5b8280fd5b6101619093919361018b565b9138610093565b85513d86823e3d90fd5b634e487b7160e01b84526041600452602484fd5b600080fd5b6001600160401b03811161019e57604052565b634e487b7160e01b600052604160045260246000fdfe604060808152600490813610156200001657600080fd5b6000918235908160e01c918263171223dd14620006025782631ab971ab146200049357826320c47e3c14620004585782632716ae6614620004365782632a48235b14620003ec5782635b16ebb714620003a957826362e28932146200022f57508163bbe9583714620000db575063c45a0155146200009357600080fd5b34620000d75781600319360112620000d757517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b5080fd5b9050346200022b57816003193601126200022b5760018054909360249291823591908435838211620001ef5750508092919593955b6200011b8262000a5c565b926200012a8751948562000941565b828452620001388362000a5c565b9760209384860199601f1901368b37835b8185018110620001965750505050508451948186019282875251809352850195925b828110620001795785870386f35b83516001600160a01b03168752958101959281019284016200016b565b620001a8819b999b989697986200090f565b90548951831015620001dd5760039190911b1c6001600160a01b0316600582901b890188015297999794969594880162000149565b634e487b7160e01b8852603286528488fd5b8382039182116200021957808210156200021157505b90929195939562000110565b905062000205565b634e487b7160e01b8352601185528583fd5b8280fd5b9092915034620003a55760209182600319360112620003a157833563ffffffff8116928382036200039d57620002f89585916001600160a01b0390620002c6620002d5836200027d620009ef565b89517f00000000000000000000000000000000000000000000000000000000000000009096168887019081526001600160e01b0319909516602086015216939182906024850190565b03601f19810183528262000941565b51902085516326f8aa2160e21b8152988993849283929130913391850162000993565b03915afa94851562000393577f78e0b45656b8fb6065c79a36aeaf92fbf473dc06966bb96e5fe995247e887503956200033a9188916200035f575b50620009b3565b855467ffffffff00000000191690841b67ffffffff000000001617855551908152a180f35b620003849150863d88116200038b575b6200037b818362000941565b81019062000979565b3862000333565b503d6200036f565b82513d88823e3d90fd5b8680fd5b8480fd5b8380fd5b509050346200022b5760203660031901126200022b57356001600160a01b038116908190036200022b57818360ff92602095526003855220541690519015158152f35b509050346200022b5760203660031901126200022b5735916001548310156200043357506200041d6020926200090f565b905491519160018060a01b039160031b1c168152f35b80fd5b50505034620000d75781600319360112620000d7576020906001549051908152f35b50505034620000d7576020916200046f36620008f3565b9082526002845282822090825283528190205490516001600160a01b039091168152f35b838591346200022b5760209182600319360112620003a55784359163ffffffff8316809303620003a1576200054b9084906001600160a01b0390620002c66200052983620004e0620009ef565b88517f00000000000000000000000000000000000000000000000000000000000000009096168787019081526001600160e01b0319909516602086015216939182906024850190565b51902090845180809581946326f8aa2160e21b83528c30913391850162000993565b03915afa908115620005f857906200056b918691620005d65750620009b3565b835463ffffffff1916821784556305f5e10091828111620003a157828102928184041490151715620005c3577f6bbc57480a46553fa4d156ce702beef5f3ad66303b0ed1a5d4cb44966c6584c393945051908152a180f35b634e487b7160e01b845260118552602484fd5b620005f19150853d87116200038b576200037b818362000941565b8762000333565b82513d87823e3d90fd5b848285346200022b576200061636620008f3565b93909283918591858714620000d75785825260209660028852858320818452885260018060a01b0396878785205416620003a55781811015620008e6575b50506200072d620006ca620006da60316200066f8862000b34565b6200067a8862000b34565b8c8b519586936d0213630b232a9bbb0b81026281d160951b83860152620006ab8151809285602e8901910162000a74565b8401916201015960ed1b602e8401528351938491878501910162000a74565b0103601181018452018262000941565b6200074a6025620006eb8862000b34565b620006f68862000b34565b8c8b51968362000710899551809285808901910162000a74565b840191602d60f81b81840152835193849160218501910162000a74565b016302d564c560e41b602182015203600581018552018362000941565b83549087519261453991828501928584106001600160401b03851117620008d35785949392620007b960c0938f8f9060e091620007c79662000c8d8c397f000000000000000000000000000000000000000000000000000000000000000016885287015260e086019062000a99565b908482038d86015262000a99565b9289606084015288608084015263ffffffff9081811660a08501528d1c16910152039083f0908115620008c95760015490600160401b821015620008b657509285928795926200083f8660017f5f28326c23d3e7607ba7f55dcee451cc4dbb16e3f016b27f013c99fb1d7d416898016001556200090f565b9790911698899782549060031b9189831b921b191617905585815260038952838120600160ff1982541617905581815260028952838120838252895285848083209260018060a01b031993838582541617905560028c528181208582528c522091825416179055825191825287820152a251908152f35b634e487b7160e01b845260419052602483fd5b85513d84823e3d90fd5b634e487b7160e01b885260418752602488fd5b9094509250878062000654565b60409060031901126200090a576004359060243590565b600080fd5b6001548110156200092b57600160005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b90601f801991011681019081106001600160401b038211176200096357604052565b634e487b7160e01b600052604160045260246000fd5b908160209103126200090a575180151581036200090a5790565b9081526001600160a01b0391821660208201529116604082015260600190565b15620009bb57565b60405162461bcd60e51b815260206004820152600c60248201526b1d5b985d5d1a1bdc9a5e995960a21b6044820152606490fd5b631c99585960e21b60009081527f0ebf818546cf436ba3e823ca878b84c3d55a00f566d51f4b07ec1ab90533db4e6004526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa1562000433575190565b6001600160401b038111620009635760051b60200190565b60005b83811062000a885750506000910152565b818101518382015260200162000a77565b9060209162000ab48151809281855285808601910162000a74565b601f01601f1916010190565b6020818303126200090a5780516001600160401b03918282116200090a57019082601f830112156200090a57815190811162000963576040519262000b10601f8301601f19166020018562000941565b818452602082840101116200090a5762000b31916020808501910162000a74565b90565b6060919073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810362000b8757509050604051604081018181106001600160401b038211176200096357604052600381526208aa8960eb1b602082015290565b6001600160f81b031981168062000c11575090915060a081901c6001600160581b03166200090a576040516395d89b4160e01b815290600090829060049082906001600160a01b03165afa90811562000c055760009162000be6575090565b62000b31913d8091833e62000bfc818362000941565b81019062000ac0565b6040513d6000823e3d90fd5b600160f91b810362000c455750509050604051602081018181106001600160401b0382111762000963576040526000815290565b600160f81b1462000c535750565b6040516395d89b4160e01b8152919250600090829060049082906001600160a01b03165afa90811562000c055760009162000be657509056fe6101e080604052346200094f5760006200453980380380916200002382866200097e565b843982019060e0838303126200094c578251916001600160a01b03831690818403620009485760208501516001600160401b0381116200064057816200006b918701620009a2565b60408601519091906001600160401b038111620008b5579062000090918701620009a2565b90606086015194608087015193620000b960c0620000b160a08b0162000a19565b990162000a19565b917343000000000000000000000000000000000000023b15620008f757604051634e606c4760e01b81528781600481837343000000000000000000000000000000000000025af18015620009275762000932575b507343000000000000000000000000000000000000023b15620008f757604051631d70c8d360e31b81527365432138ae74065aeb3bd71aeac887ccae0e32a460048201528781602481837343000000000000000000000000000000000000025af1801562000927579088916200090f575b50506080523360a0523060c052604051631c41328760e31b81526020816004818a865af190811562000904578791620008c8575b5060e052803b15620008c45785809160446040518094819363343e66c560e21b83523060048401523060248401525af18015620008b9579086916200089d575b50506101009630885263ffffffff67ffffffff000000006006549260201b1692169060018060401b0319161717600655670de0b6b3a76400008060075560085580519060018060401b0382116200088957600254600181811c911680156200087e575b60208210146200086a579081601f8493116200080b575b50602090601f83116001146200078f57869262000783575b50508160011b916000199060031b1c1916176002555b8051906001600160401b0382116200076f57600354600181811c9116801562000764575b602082101462000750579081601f849311620006dd575b50602090601f83116001146200065057859262000644575b50508160011b916000199060031b1c1916176003555b6080516001600160a01b03168083526004602052604083206001600160701b0390819055813b156200064057839160648392604051948593849263d2441f0360e01b845230600485015282602485015260448401525af18015620006355790839162000619575b505060065463ffffffff8160201c166305f5e1009081810291818304149015171562000605577f78e0b45656b8fb6065c79a36aeaf92fbf473dc06966bb96e5fe995247e887503917f6bbc57480a46553fa4d156ce702beef5f3ad66303b0ed1a5d4cb44966c6584c360208093604051908152a163ffffffff60405191168152a16101209280845261014091808352813010600014620005c857839260019160ff8062000437620004306002975b6101609788526101809889526101a0998a5262000a2b565b9362000a2b565b169116019460ff8611620005b45750607f6101c09560011c16855260405195613a08978862000b11893960805188818161082b01528181610a8801528181610c8501528181610f1f015281816111950152818161121e015281816116730152818161170701528181611900015281816119e3015281816121ae01528181612375015281816132c60152613313015260a0518881816110660152611584015260c051888181610efd015281816119b70152611b60015260e051886108a10152518781816105a90152818161087801528181610e7901528181611258015281816115c9015281816117c80152611cbb015251868181611d1e015281816127470152818161295b01528181612a0201528181612ca9015281816133f201526134c1015251858181611d66015281816126e80152818161299301528181612a3e01528181612cd60152818161341801526134e7015251848181612424015261272001525183818161245d01526126c1015251826123d601525181610bb30152f35b634e487b7160e01b81526011600452602490fd5b803010600014620005ec57600192849160ff80620004376200043060029762000418565b600292849160ff80620004376200043060019762000418565b634e487b7160e01b84526011600452602484fd5b620006249062000954565b620006315781386200036a565b5080fd5b6040513d85823e3d90fd5b8380fd5b015190503880620002ed565b600386528593507fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b91905b601f1984168510620006c1576001945083601f19811610620006a7575b505050811b0160035562000303565b015160001960f88460031b161c1916905538808062000698565b818101518355602094850194600190930192909101906200067b565b600386529091507fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b601f840160051c8101916020851062000745575b90601f859493920160051c01905b818110620007365750620002d5565b86815584935060010162000727565b909150819062000719565b634e487b7160e01b85526022600452602485fd5b90607f1690620002be565b634e487b7160e01b84526041600452602484fd5b01519050388062000284565b600287528693506000805160206200451983398151915291905b601f1984168510620007ef576001945083601f19811610620007d5575b505050811b016002556200029a565b015160001960f88460031b161c19169055388080620007c6565b81810151835560209485019460019093019290910190620007a9565b6002875290915060008051602062004519833981519152601f840160051c81016020851062000862575b90849392915b601f830160051c82018110620008535750506200026c565b8881558594506001016200083b565b508062000835565b634e487b7160e01b86526022600452602486fd5b90607f169062000255565b634e487b7160e01b85526041600452602485fd5b620008a89062000954565b620008b5578438620001f2565b8480fd5b6040513d88823e3d90fd5b8580fd5b90506020813d602011620008fb575b81620008e6602093836200097e565b81010312620008f7575138620001b2565b8680fd5b3d9150620008d7565b6040513d89823e3d90fd5b6200091a9062000954565b620008f75786386200017e565b6040513d8a823e3d90fd5b620009409097919762000954565b95386200010d565b8280fd5b80fd5b600080fd5b6001600160401b0381116200096857604052565b634e487b7160e01b600052604160045260246000fd5b601f909101601f19168101906001600160401b038211908210176200096857604052565b919080601f840112156200094f578251906001600160401b038211620009685760405191602091620009de601f8301601f19168401856200097e565b8184528282870101116200094f5760005b81811062000a0557508260009394955001015290565b8581018301518482018401528201620009ef565b519063ffffffff821682036200094f57565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810362000a4d5750601290565b7fff0000000000000000000000000000000000000000000000000000000000000081161562000a7c5750600090565b60a081901c6001600160581b03166200094f5760405163313ce56760e01b815290602090829060049082906001600160a01b03165afa90811562000b045760009162000ac6575090565b6020813d821162000afb575b8162000ae1602093836200097e565b810103126200063157519060ff821682036200094c575090565b3d915062000ad2565b6040513d6000823e3d90fdfe6080604052600436101561001257600080fd5b60003560e01c806306fdde03146102c75780630902f1ac146102c2578063095ea7b3146102bd5780630b1150de146102b85780630dfe1681146102b3578063165cad8d146102ae57806318160ddd146102a957806319706b38146102a457806320e5fe3e1461029f57806323b872dd1461029a578063282b4c86146102955780632986c0e514610290578063313ce5671461028b57806334c0b46b14610286578063376fc5bf1461028157806338706d1f1461027c57806339509351146102775780633a4b66f114610272578063412330bc1461026d57806348313a81146102685780634a3d6bda1461026357806352f7c9881461025e57806369fa25c4146102595780636b35b93d1461025457806370a082311461024f578063781c38001461024a57806395d89b41146102455780639acaa0f4146102405780639c77ac511461023b578063a457c2d714610236578063a5b39cfb14610231578063a9059cbb1461022c578063a9c1f2f114610227578063b3331de414610222578063c45a01551461021d578063cb62900914610218578063ce98f8aa14610213578063d21220a71461020e578063dd62ed3e14610209578063e5a70ef714610204578063ec378808146101ff578063f38a02d0146101fa5763ff7bd55b146101f557600080fd5b6117a1565b61174a565b6116e8565b6116c7565b611638565b61161d565b6115ed565b6115b3565b61156e565b611553565b61152f565b6114b2565b611469565b61141f565b6113f8565b61137f565b6112bc565b611204565b6111dd565b61117e565b61112e565b61102b565b61100f565b610fe9565b610ed7565b610e61565b610e06565b610dea565b610c5d565b610bd7565b610b99565b610b7b565b610b54565b610a40565b61080c565b6105f4565b6105d1565b61058c565b61055f565b610526565b6104ac565b61046d565b61035c565b634e487b7160e01b600052604160045260246000fd5b90601f801991011681019081106001600160401b0382111761030357604052565b6102cc565b919082519283825260005b848110610334575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201610313565b906020610359928181520190610308565b90565b34610468576000806003193601126104655760405190806002549060019180831c9280821692831561045b575b602092838610851461044757858852602088019490811561042657506001146103cd575b6103c9876103bd818903826102e2565b60405191829182610348565b0390f35b600260005294509192917f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b83861061041557505050910190506103bd826103c938806103ad565b8054858701529482019481016103f9565b60ff191685525050505090151560051b0190506103bd826103c938806103ad565b634e487b7160e01b82526022600452602482fd5b93607f1693610389565b80fd5b600080fd5b34610468576000366003190112610468576060610488612ca1565b9060405192835260208301526040820152f35b6001600160a01b0381160361046857565b346104685760403660031901126104685760206104d76004356104ce8161049b565b60243590611a8a565b6040519015158152f35b90815180825260208080930193019160005b828110610501575050505090565b8351855293810193928101926001016104f3565b9060206103599281815201906104e1565b34610468576020366003190112610468573060043503610468576103c961054b6134b7565b6040519182916020835260208301906104e1565b3461046857600036600319011261046857602061057a611d1c565b6040516001600160a01b039091168152f35b3461046857600036600319011261046857602060005260016020527f000000000000000000000000000000000000000000000000000000000000000060405260606000f35b346104685760003660031901126104685760206105ec611a6c565b604051908152f35b346104685760003660031901126104685761060d613352565b80511561067457600160208201528051600110156106745780600160406103c99301526103bd61065463ffffffff61064e60065463ffffffff9060201c1690565b16611dac565b6106666040519384926020840161350e565b03601f1981018352826102e2565b61338d565b6001600160401b0381116103035760051b60200190565b81601f82011215610468578035916106a783610679565b926106b560405194856102e2565b808452602092838086019260051b820101928311610468578301905b8282106106df575050505090565b813580600f0b81036104685781529083019083016106d1565b9181601f84011215610468578235916001600160401b038311610468576020838186019501011161046857565b60806003198201126104685760043561073d8161049b565b91602435916001600160401b0391828411610468578160238501121561046857836004013593838511610468578260248660051b83010111610468576024019392604435818111610468578361079591600401610690565b92606435918211610468576107ac916004016106f8565b9091565b90815180825260208080930193019160005b8281106107d0575050505090565b8351600f0b855293810193928101926001016107c2565b90916107fe610359936040845260408401906107b0565b9160208184039101526107b0565b34610468576109b061081d36610725565b5092949193919250610859337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614611aee565b61086284611bb2565b9361096c6108c661087283611bb2565b9761089e7f00000000000000000000000000000000000000000000000000000000000000008583611c1d565b937f000000000000000000000000000000000000000000000000000000000000000091611c1d565b61095f61095661095061094461093061090a6108e960005460018060801b031690565b6108fc6108f58d6118aa565b5460801c90565b90036001600160801b031690565b6109236109168c6118aa565b546001600160801b031690565b026001600160801b031690565b633b9aca006001600160801b039091160490565b6001600160801b031690565b600f0b90565b600003600f0b90565b90879060010160051b0152565b600181016109bf575b505060005461098d906001600160801b0316916118aa565b80546001600160801b031660809290921b6001600160801b031916919091179055565b6103c9604051928392836107e7565b610a3991610a2b610a036109fe6109f96109de6109446109168a6118aa565b946001870160051b01946109f38651600f0b90565b90611c01565b6137e2565b6137c9565b610a0c866118aa565b80546001600160801b0319166001600160801b03909216919091179055565b5190859060010160051b0152565b3880610975565b3461046857606036600319011261046857600435610a5d8161049b565b602435610a698161049b565b604435906000805160206139b3833981519152906001600160a01b03907f000000000000000000000000000000000000000000000000000000000000000082163303610af5575b610ab9856118c4565b610ac4858254611a5f565b9055610acf816118c4565b805485019055604051938452811693169180602081015b0390a360405160018152602090f35b8185166000526005602052610b0e3360406000206118de565b548460018201610b20575b5050610ab0565b610b2991611a5f565b6001600160a01b0386166000908152600560205260409020610b4c9033906118de565b553884610b19565b346104685760203660031901126104685760206105ec600435610b768161049b565b611cb6565b34610468576000366003190112610468576020600754604051908152f35b3461046857600036600319011261046857602060405160ff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b3461046857600036600319011261046857610bf0611b88565b805115610674576103c9903060208201526040519182916020835260208301906104e1565b92610c416103599593610c33610c4f946080885260808801906104e1565b9086820360208801526107b0565b9084820360408601526107b0565b9160608184039101526107b0565b3461046857604036600319011261046857600435610c7a8161049b565b6001600160a01b03907f0000000000000000000000000000000000000000000000000000000000000000821690610cc190610cb6338414611aee565b6060931630146121e1565b30610cca6133a3565b52610cd3611b88565b91610cdc611b88565b9160046020610ce9611b88565b92604051928380926313c716cd60e21b82525afa908115610de557600091610db7575b50610d23575b6103c9919260405194859485610c15565b6103c99150610d83610d7d610d5c610d57602435610d52610d4960065463ffffffff1690565b63ffffffff1690565b611f9e565b611a4d565b610d78610d6f610d6a61356a565b611dc5565b60075490611b3d565b611de2565b60201c90565b92610daf610da8610da3610d9e610d98611b88565b97613841565b613831565b613552565b8260200152565b929150610d12565b610dd8915060203d8111610dde575b610dd081836102e2565b8101906120e0565b38610d0c565b503d610dc6565b611992565b34610468576000366003190112610468576103c961054b6133c4565b3461046857604036600319011261046857600435610e238161049b565b336000526005602052610e3a8160406000206118de565b546024358101809111610e5c57610e5091611a8a565b50602060405160018152f35b611a37565b346104685760003660031901126104685760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b6020604081830192828152606051809452019160809160005b828110610ec3575050505090565b835185529381019392810192600101610eb5565b346104685760008060031936011261046557610ef16133c4565b610efb8151611bb2565b7f0000000000000000000000000000000000000000000000000000000000000000927f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690805b8451811015610fdc5780610f61610f8192876133b0565b5160405190633d44217960e21b8252818060209586938c60048401611977565b0381885afa908115610de557610faa938592610faf575b5050610fa482876133b0565b5261337e565b610f4a565b610fce9250803d10610fd5575b610fc681836102e2565b810190611968565b3880610f98565b503d610fbc565b604051806103c981610e9c565b3461046857600036600319011261046857602060065463ffffffff60405191831c168152f35b34610468576000366003190112610468576103c961054b6134b7565b34610468576040366003190112610468576110e76020611061611055611055611055611055612175565b6001600160a01b031690565b6040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168382019081526000356001600160e01b0319166020820152906110b48160248401610666565b5190206040516326f8aa2160e21b8152600481019190915233602482015230604482015292839190829081906064820190565b03915afa8015610de55761110391600091611110575b506120f8565b61110e6004356121e8565b005b611128915060203d8111610dde57610dd081836102e2565b386110fd565b34610468576020366003190112610468576111586020611061611055611055611055611055612175565b03915afa8015610de5576111739160009161111057506120f8565b61110e600435612133565b34610468576000366003190112610468576111c3337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614611aee565b600680546fffffffffffffffff00000000ffffffff169055005b346104685760203660031901126104685760206105ec6004356111ff8161049b565b6118f5565b346104685760203660031901126104685760043561124c337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614611aee565b8061125357005b61127c7f0000000000000000000000000000000000000000000000000000000000000000611b47565b908115801561128757005b6112b757633b9aca00906000549260018060801b0392839202041681831601169060018060801b03191617600055005b611b27565b34610468576000806003193601126104655760405190806003549060019180831c92808216928315611375575b6020928386108514610447578588526020880194908115610426575060011461131c576103c9876103bd818903826102e2565b600360005294509192917fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b83861061136457505050910190506103bd826103c938806103ad565b805485870152948201948101611348565b93607f16936112e9565b346104685760203660031901126104685760043561139c8161049b565b6000906001600160a01b031630036113f35750670de0b6b3a76400006113c061356a565b0260075480156112b75763ffffffff60065416600160201b0391040260201c5b6020600052600160205260405260606000f35b6113e0565b3461046857600036600319011261046857602060065463ffffffff6040519160401c168152f35b346104685760403660031901126104685760043561143c8161049b565b3360005260056020526114538160406000206118de565b546024358103908111610e5c57610e5091611a8a565b34610468576020366003190112610468576004356114868161049b565b60018060a01b0316600052600160205260018060801b0360406000205416602060005260405260606000f35b34610468576040366003190112610468576004356114cf8161049b565b602435903360005260046020526040600020805490838203918211610e5c575560018060a01b03169081600052600460205260406000208181540190556000805160206139b383398151915260405180610ae63394829190602083019252565b3461046857600036600319011261046857602063ffffffff60065416604051908152f35b346104685760003660031901126104685760206105ec611ed2565b34610468576000366003190112610468576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610468576000366003190112610468576113e07f0000000000000000000000000000000000000000000000000000000000000000611b47565b346104685760203660031901126104685761160960043561049b565b602060005260016020523060405260606000f35b3461046857600036600319011261046857602061057a611d64565b34610468576040366003190112610468576004356116558161049b565b602435906116628261049b565b6000916001600160a01b03918282167f00000000000000000000000000000000000000000000000000000000000000008416036116aa57505050506020600019604051908152f35b6020936116c19360409216815260058552206118de565b546105ec565b3461046857600036600319011261046857602060065460801c604051908152f35b346104685761173a6116f936610725565b5090939192919050611735337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614611aee565b6122cc565b906103c9604051928392836107e7565b346104685760003660031901126104685760405160408101908082106001600160401b03831117610303576103c991604052600481526363706d6d60e01b6020820152604051918291602083526020830190610308565b34610468576000806003193601126104655760405163251eb5ed60e11b81529080826004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610de557809161180e575b604051806103c98482610515565b90503d8082843e61181f81846102e2565b820160209283818303126118a2578051906001600160401b0382116118a6570181601f820112156118a25780519061185682610679565b9361186460405195866102e2565b828552858086019360051b83010193841161046557508401905b828210611893575050506103c9915038611800565b8151815290840190840161187e565b8280fd5b8380fd5b6001600160a01b0316600090815260016020526040902090565b6001600160a01b0316600090815260046020526040902090565b9060018060a01b0316600052602052604060002090565b6001600160a01b03907f0000000000000000000000000000000000000000000000000000000000000000821633811415908161195c575b5061193f5761193b91506118c4565b5490565b1660005260046020526040600020546119573061199e565b900390565b9050828216143861192c565b90816020910312610468575190565b6001600160a01b039091168152602081019190915260400190565b6040513d6000823e3d90fd5b60206119df9160405180938192633d44217960e21b83527f000000000000000000000000000000000000000000000000000000000000000060048401611977565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610de557600091611a1f575090565b610359915060203d8111610fd557610fc681836102e2565b634e487b7160e01b600052601160045260246000fd5b90600160201b918203918211610e5c57565b91908203918211610e5c57565b611a753061199e565b6001600160701b03908103908111610e5c5790565b33600052600560205281611aa28260406000206118de565b556040519182526001600160a01b03169033907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590602090a3600190565b9060018201809211610e5c57565b15611af557565b60405162461bcd60e51b815260206004820152600a6024820152691bdb9b1e481d985d5b1d60b21b6044820152606490fd5b634e487b7160e01b600052601260045260246000fd5b81156112b7570490565b60206119df916040518093819263ebd8189f60e01b83527f000000000000000000000000000000000000000000000000000000000000000060048401611977565b60405190604082018281106001600160401b03821117610303576040526001825260203681840137565b90611bbc82610679565b611bc960405191826102e2565b8281528092611bda601f1991610679565b0190602036910137565b9060018201916000600184129112908015821691151617610e5c57565b91909160008382019384129112908015821691151617610e5c57565b90918215611cad5760009060001993848101908111610e5c5793929193905b81851115611c4c57505050905090565b6001858303811c860180968160051b860135848114600014611c7357505050505050505090565b87985093809596979192939410600014611c94575050015b93929190611c3c565b925093508015611ca5570191611c8b565b505050505090565b50505060001990565b611cdf7f0000000000000000000000000000000000000000000000000000000000000000611b47565b908115611d15576001600160a01b03166000908152600160205260409020546001600160801b0316670de0b6b3a7640000020490565b5050600090565b7f000000000000000000000000000000000000000000000000000000000000000073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810361105557506004604360981b0190565b7f000000000000000000000000000000000000000000000000000000000000000073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810361105557506004604360981b0190565b90633b9aca0091828102928184041490151715610e5c57565b90670de0b6b3a764000091828102928184041490151715610e5c57565b81810292918115918404141715610e5c57565b90676765c793fa10079d601b1b91828102928184051490151715610e5c57565b90670de0b6b3a764000091828102928184051490151715610e5c57565b818102929160008212600160ff1b821416610e5c578184051490151715610e5c57565b90676765c793fa10079d601b1b60008382039312818412811691841390151617610e5c57565b90670de0b6b3a764000060008382039312818412811691841390151617610e5c57565b81810392916000138015828513169184121617610e5c57565b81156112b757600160ff1b8114600019831416610e5c570590565b611edd610d6a613460565b611ee5611a6c565b60028101809111610e5c5780156112b757611f009104613841565b60065460601c63ffffffff16428103611f1b57505060095490565b610359916109f3611f7383611f6d611f66611f52611f4d611f47611f42611f8d9a42611a5f565b61203a565b97611df5565b6138c7565b611f60611f4d600854611df5565b90611e9e565b9142611a5f565b90611eb7565b611f88611f8284600954611e32565b93611e55565b611e32565b676765c793fa10079d601b1b900590565b90919080156120265760018381161561201b5781935b811c805b611fc2575050505b565b82800292808404036104685763800000009283810190811061046857602090811c93838316611ff6575b5050811c80611fb8565b848793970292858404141585151516610468578201918210610468571c933880611fec565b600160201b93611fb4565b50901561203257600090565b600160201b90565b906b033b2ad6d379451d40331f576001808416156120ce5781935b811c805b61206257505050565b8280029280840403610468576b019d971e4fe8401e740000009283810190811061046857676765c793fa10079d601b1b809104938383166120a8575b5050811c80612059565b84879293970291858304141585151516610468578101908110610468570493388061209e565b676765c793fa10079d601b1b93612055565b90816020910312610468575180151581036104685790565b156120ff57565b60405162461bcd60e51b815260206004820152600c60248201526b1d5b985d5d1a1bdc9a5e995960a21b6044820152606490fd5b602063ffffffff7f78e0b45656b8fb6065c79a36aeaf92fbf473dc06966bb96e5fe995247e88750392168063ffffffff196006541617600655604051908152a1565b631c99585960e21b60009081527f0ebf818546cf436ba3e823ca878b84c3d55a00f566d51f4b07ec1ab90533db4e6004526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa15610465575190565b1561046857565b600654906305f5e1009163ffffffff9183838360201c16116104685763ffffffff60201b9060201b169063ffffffff60201b1916178060065560201c16818102918183041490151715610e5c5760207f6bbc57480a46553fa4d156ce702beef5f3ad66303b0ed1a5d4cb44966c6584c391604051908152a1565b929161226d82610679565b9161227b60405193846102e2565b829481845260208094019160051b810192831161046857905b8282106122a15750505050565b81358152908301908301612294565b6001600160801b039182169082160290811691908203610e5c57565b939291612338906122dc81611bb2565b936122e682611bb2565b9661233e6122f2612ca1565b50604080516001600160701b03848116825283166020820152919792917f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad19190a1611be4565b94611be4565b9261235260065463ffffffff9060401c1690565b63ffffffff42911603612b99575b6040516313c716cd60e21b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610de557600091612b7a575b5015612aae575b6003810361276d5794612420612536966124176123d3368386612262565b917f0000000000000000000000000000000000000000000000000000000000000000946001860160051b809401513014918261270f575b826126b1575b50506121e1565b840151600f0b90565b92897f0000000000000000000000000000000000000000000000000000000000000000966124576001890160051b840151600f0b90565b9661248c7f0000000000000000000000000000000000000000000000000000000000000000946001860160051b0151600f0b90565b60016001607f1b038881146125bf5789811461253a57505061251b926124ee612531969593612505938b6124cb6124c68d60075490611e32565b612bc6565b916124e861094460065463ffffffff8160801c9160201c166122b0565b93612f20565b995b6124f98a613831565b919060010160051b0152565b61250e88613831565b908c9060010160051b0152565b61252484613831565b908a9060010160051b0152565b6130d4565b9190565b90999850891461258f5761251b92612589612531969593612505938c6125666124c68d60075490611e32565b9161258361094460065463ffffffff8160801c9160201c166122b0565b93612cff565b986124f0565b61251b9298506125b7612531959492612505926125b16124c66007548c611e32565b91613022565b9990986124f0565b819a9850808a92939a14808015906126a7575b6125db906121e1565b1561264557505061251b9261263f612636612631858561260c8e6126076125319d9c9a6125059a611e32565b611eb7565b809e5b61262b61094460065463ffffffff8160801c9160201c166122b0565b93612f2f565b611e15565b60075490612c33565b976124f0565b9098911461266c575b61251b9261263f6126366126316125319897958d8d6125059761260f565b87985061251b9261263f61263661263185856126956125319b9a988f6125059961260791611e32565b9e50955095979850505050925061264e565b50838214156125d2565b6126bd92503691612262565b60017f00000000000000000000000000000000000000000000000000000000000000000160051b01517f0000000000000000000000000000000000000000000000000000000000000000143880612410565b915061271c368383612262565b60017f00000000000000000000000000000000000000000000000000000000000000000160051b01517f0000000000000000000000000000000000000000000000000000000000000000149161240a565b9293919260028103612a7157602084015160408501516127a29160016001607f1b03600f91820b81149290910b1414156121e1565b6002906002966002926127c06127b9368585612262565b6020015190565b3081036129fc5750506127db6127e2916000935b3691612262565b6040015190565b308103612956575050612536956001935b60028503612943576000965b87600284036129315760005b976002860361291f57506000985b8960016001607f1b0382036128cd575050506126316128549289896126369461262b61094460065463ffffffff8160801c9160201c166122b0565b935b600281146128bd5761286b9061250e86613831565b600281146128ad5761288d9061288086613831565b908b9060010160051b0152565b600281146128a2576125319061252486613831565b5061253184156121e1565b506128b884156121e1565b61288d565b506128c884156121e1565b61286b565b9799919790919060016001607f1b03810361290057505090876124cb6124c66128fa959460075490611e32565b95612856565b909998506125666124c661291995949360075490611e32565b94612856565b6001860160051b0151600f0b98612819565b6001840160051b880151600f0b61280b565b6001850160051b860151600f0b966127ff565b9093907f0000000000000000000000000000000000000000000000000000000000000000810361298e575061253696506001906127f3565b9091507f0000000000000000000000000000000000000000000000000000000000000000036129c357612536956001916127f3565b60405162461bcd60e51b81526020600482015260116024820152703ab739bab83837b93a32b2103a37b5b2b760791b6044820152606490fd5b929890927f00000000000000000000000000000000000000000000000000000000000000008103612a385750506127db6127e2916000996127d4565b909893507f0000000000000000000000000000000000000000000000000000000000000000036129c3576127db6127e2916000946127d4565b60405162461bcd60e51b81526020600482015260156024820152743ab739bab83837b93a32b21037b832b930ba34b7b760591b6044820152606490fd5b612b07612add612ad8612ac2610d6a613460565b612ad2612acd611a6c565b611ae0565b90611b3d565b613841565b600654612af29060601c63ffffffff16610d49565b4281141580612b6e575b612b0c575b50600755565b6123b5565b612b3c611f8d826109f3611f73612b29611f42612b419742611a5f565b92611f6d611f66611f52611f4d8b611df5565b600955565b612b4a81600855565b6006805463ffffffff60601b19164260601b63ffffffff60601b1617905538612b01565b50816008541415612afc565b612b93915060203d602011610dde57610dd081836102e2565b386123ae565b600680546001600160801b0316621dcd6560891b179055612360565b600160ff1b8114610e5c5760000390565b60016000612bd3836138b6565b921303612bed57670de0b6b3a76400006103599104613841565b80612c055750610359612c006000613841565b612bb5565b6000198101908111610e5c57670de0b6b3a7640000900460018101809111610e5c57612c0061035991613841565b612c3c816138b6565b90600080612c49856138b6565b9413911314600014612c8d5780612c665750506103596000613841565b6000198101908111610e5c5781156112b7570460018101809111610e5c5761035990613841565b81156112b75761035991612c009104613841565b612ccd612ad87f000000000000000000000000000000000000000000000000000000000000000061199e565b90612cfa612ad87f000000000000000000000000000000000000000000000000000000000000000061199e565b904290565b90612d0f61035995949382611c01565b91612dcd565b8015612dc7576000811380600114612daf5715612d98575b80026001805b60018111612d695750600081136001600160ff1b03839004821116610e5c5760008112600160ff1b839005821216610e5c570290565b916001600160ff1b038190048111610e5c5760018316612d8f575b80029160011c612d33565b80910290612d84565b6001600160ff1b03819005811215612d2d57611a37565b506001600160ff1b03819004811115612d2d57611a37565b50600090565b9291938361035995612e05612dfe612ad8612df9612dea866137e2565b612df3896137e2565b90611de2565b613749565b9586611e9e565b90612e12600083136121e1565b612e6d8287139185831597858a8a600014612ee15792611f88612e4c611f6094612e47612e51956126078a612e5f9b9a611e32565b611e9e565b6138a8565b670de0b6b3a7640000900590565b612e6884612d15565b612c33565b9415612e9d5750612e9783611f88612e4c6109f39695612e47611f6d966126078b612e479d611e32565b91611e7b565b94929394612eaf575b50505050611e9e565b612e9784611f88612e4c612ed26109f397612607612ed89b9a98611f6d98611e32565b88611e9e565b38808381612ea6565b9190821215612ef3575b505050612e5f565b612f189392611f88612e4c612f12611f6095612607612e51968d611e32565b86611e9e565b858838612eeb565b612d0f61035995949382611c01565b929061035994612f4c612f45611f609587611c01565b9383611c01565b91612f60612ad8612df96109f9848a611e32565b9584612f6d85899761343f565b9182871380612fc05750612e4c611f6094612e47856126078a612fb488611f608f612fba9f9e611f88612e4c612e519f9d839f611f889f612607612e4792612e5198611e32565b9c611e32565b9061343f565b96929493919596612fd6575b505050505061343f565b612e4c612f128461260787956130116130179b611f60612e518d9f9d9c611f88612e4c611f609f612e519f612607611f889f612f1293611e32565b9b611e32565b903880858180612fcc565b9092916000808213156130ce57506001915b613049613040826137e2565b612df3876137e2565b613052816135fd565b9060038510156130b85761309e612e6893612e68612c00613096612c0096899660016103599c1490816130ac575b50600090156130a4575060ff60015b1601613841565b978893611e32565b96611e32565b60ff9061308f565b90508180021038613080565b634e487b7160e01b600052602160045260246000fd5b91613034565b9092909160008085131561319d57509261317892610944927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d8193649661312261311c611fc098612bb5565b92612bb5565b6040805193845260208401919091526001600160a01b0393909316928392a361314a81613308565b612ad261317261316261315b613460565b9384611a5f565b92610d7861094460065460801c90565b916135ec565b600680546001600160801b031660809290921b6001600160801b031916919091179055565b909290808512156131fc5750604080519384526020840192909252611fc0936131f79390926001600160a01b0392909216917f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f91a2612bb5565b6132be565b9350839290918391829081808213156132ac5750925b82131561327457509061326f7fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822935b60018060a01b0316958695604051948594859094939260609260808301968352602083015260408201520152565b0390a3565b91907fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229395506132a661326f91612bb5565b95613241565b9395506132b890612bb5565b94613212565b6040519081527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906000906000805160206139b383398151915290602090a3565b6040519081526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906000805160206139b383398151915290602090a3565b60405190606082018281106001600160401b038211176103035760405260028252604082602036910137565b6000198114610e5c5760010190565b634e487b7160e01b600052603260045260246000fd5b6060511561067457608090565b80518210156106745760209160051b010190565b604051608081018181106001600160401b0382111761030357604052600381526020810160603682373090527f000000000000000000000000000000000000000000000000000000000000000060408201527f0000000000000000000000000000000000000000000000000000000000000000606082015290565b61345b61035992612df3613455612ad8946137e2565b916137e2565b6135fd565b613468612ca1565b509060018101906000600183129112908015821691151617610e5c5760018201916000600184129112908015821691151617610e5c57612ad861345b61035993612df36134556109f9956137e2565b6134bf613352565b7f000000000000000000000000000000000000000000000000000000000000000060208201527f0000000000000000000000000000000000000000000000000000000000000000604082015290565b9060609160408101918152602092816040858094015285518094520193019160005b82811061353e575050505090565b835185529381019392810192600101613530565b600f0b60016001607f1b03198114610e5c5760000390565b613572611a6c565b60018101809111610e5c5761358c90612df36007546137e2565b806135c4575060005b61359d612ca1565b5050506135a8613460565b90808210156135b8575050600090565b8103908111610e5c5790565b6000198101908111610e5c57670de0b6b3a76400009004600181018091111561359557611a37565b806001116000146103595750600190565b8015612dc757806136d06136c96136bf6136b56136ab6136a161369761368d60016103599a6000908b60801c8061372b575b508060401c8061371e575b508060201c80613711575b508060101c80613704575b508060081c806136f7575b508060041c806136ea575b508060021c806136dd575b50821c6136d6575b811c1b613686818b611b3d565b0160011c90565b613686818a611b3d565b6136868189611b3d565b6136868188611b3d565b6136868187611b3d565b6136868186611b3d565b6136868185611b3d565b8092611b3d565b90613737565b8101613679565b6002915091019038613671565b6004915091019038613666565b600891509101903861365b565b6010915091019038613650565b6020915091019038613645565b604091509101903861363a565b9150506080903861362f565b9080821015613744575090565b905090565b613752816135fd565b906000908280021015613766575060010190565b60ff160190565b1561377457565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b6001600160801b03906137de8282111561376d565b1690565b600081126137ed5790565b606460405162461bcd60e51b815260206004820152602060248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152fd5b90611fc082600f0b92831461376d565b6001600160ff1b0381116138525790565b60405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608490fd5b600080821315613744575090565b60008082126138c3575090565b0390565b90670de0b6b3a76400009182811061399a5782810460018060801b03811160071b90811c906001600160401b03821160061b91821c63ffffffff811160051b90811c61ffff811160041b90811c60ff811160031b90811c91600f831160021b92831c936001968760038711811b96871c11961717171717171791848302921c93808514613993576706f05b59d3b2000094855b61396657509193505050565b808291020494671bc16d674ec80000861015613986575b821c948561395a565b8095930192821c9461397d565b5090925050565b6024906040519063036d32ef60e41b82526004820152fdfeddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220eaac9e506e37c4bb32f1cd873b82632cd5213f90c7901120c31bfc7614bd465a64736f6c63430008130033405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5acea2646970667358221220f8f2843547af08c7b83234ae69ee86ab5a8f73b7914ec7a6230b552c809ec4cf64736f6c6343000813003300000000000000000000000010f6b147d51f7578f760065df7f174c3bc95382c
Deployed Bytecode
0x604060808152600490813610156200001657600080fd5b6000918235908160e01c918263171223dd14620006025782631ab971ab146200049357826320c47e3c14620004585782632716ae6614620004365782632a48235b14620003ec5782635b16ebb714620003a957826362e28932146200022f57508163bbe9583714620000db575063c45a0155146200009357600080fd5b34620000d75781600319360112620000d757517f00000000000000000000000075cb3ec310d3d1e22637f79d61eab5d9abcd68bd6001600160a01b03168152602090f35b5080fd5b9050346200022b57816003193601126200022b5760018054909360249291823591908435838211620001ef5750508092919593955b6200011b8262000a5c565b926200012a8751948562000941565b828452620001388362000a5c565b9760209384860199601f1901368b37835b8185018110620001965750505050508451948186019282875251809352850195925b828110620001795785870386f35b83516001600160a01b03168752958101959281019284016200016b565b620001a8819b999b989697986200090f565b90548951831015620001dd5760039190911b1c6001600160a01b0316600582901b890188015297999794969594880162000149565b634e487b7160e01b8852603286528488fd5b8382039182116200021957808210156200021157505b90929195939562000110565b905062000205565b634e487b7160e01b8352601185528583fd5b8280fd5b9092915034620003a55760209182600319360112620003a157833563ffffffff8116928382036200039d57620002f89585916001600160a01b0390620002c6620002d5836200027d620009ef565b89517f00000000000000000000000075cb3ec310d3d1e22637f79d61eab5d9abcd68bd9096168887019081526001600160e01b0319909516602086015216939182906024850190565b03601f19810183528262000941565b51902085516326f8aa2160e21b8152988993849283929130913391850162000993565b03915afa94851562000393577f78e0b45656b8fb6065c79a36aeaf92fbf473dc06966bb96e5fe995247e887503956200033a9188916200035f575b50620009b3565b855467ffffffff00000000191690841b67ffffffff000000001617855551908152a180f35b620003849150863d88116200038b575b6200037b818362000941565b81019062000979565b3862000333565b503d6200036f565b82513d88823e3d90fd5b8680fd5b8480fd5b8380fd5b509050346200022b5760203660031901126200022b57356001600160a01b038116908190036200022b57818360ff92602095526003855220541690519015158152f35b509050346200022b5760203660031901126200022b5735916001548310156200043357506200041d6020926200090f565b905491519160018060a01b039160031b1c168152f35b80fd5b50505034620000d75781600319360112620000d7576020906001549051908152f35b50505034620000d7576020916200046f36620008f3565b9082526002845282822090825283528190205490516001600160a01b039091168152f35b838591346200022b5760209182600319360112620003a55784359163ffffffff8316809303620003a1576200054b9084906001600160a01b0390620002c66200052983620004e0620009ef565b88517f00000000000000000000000075cb3ec310d3d1e22637f79d61eab5d9abcd68bd9096168787019081526001600160e01b0319909516602086015216939182906024850190565b51902090845180809581946326f8aa2160e21b83528c30913391850162000993565b03915afa908115620005f857906200056b918691620005d65750620009b3565b835463ffffffff1916821784556305f5e10091828111620003a157828102928184041490151715620005c3577f6bbc57480a46553fa4d156ce702beef5f3ad66303b0ed1a5d4cb44966c6584c393945051908152a180f35b634e487b7160e01b845260118552602484fd5b620005f19150853d87116200038b576200037b818362000941565b8762000333565b82513d87823e3d90fd5b848285346200022b576200061636620008f3565b93909283918591858714620000d75785825260209660028852858320818452885260018060a01b0396878785205416620003a55781811015620008e6575b50506200072d620006ca620006da60316200066f8862000b34565b6200067a8862000b34565b8c8b519586936d0213630b232a9bbb0b81026281d160951b83860152620006ab8151809285602e8901910162000a74565b8401916201015960ed1b602e8401528351938491878501910162000a74565b0103601181018452018262000941565b6200074a6025620006eb8862000b34565b620006f68862000b34565b8c8b51968362000710899551809285808901910162000a74565b840191602d60f81b81840152835193849160218501910162000a74565b016302d564c560e41b602182015203600581018552018362000941565b83549087519261453991828501928584106001600160401b03851117620008d35785949392620007b960c0938f8f9060e091620007c79662000c8d8c397f00000000000000000000000010f6b147d51f7578f760065df7f174c3bc95382c16885287015260e086019062000a99565b908482038d86015262000a99565b9289606084015288608084015263ffffffff9081811660a08501528d1c16910152039083f0908115620008c95760015490600160401b821015620008b657509285928795926200083f8660017f5f28326c23d3e7607ba7f55dcee451cc4dbb16e3f016b27f013c99fb1d7d416898016001556200090f565b9790911698899782549060031b9189831b921b191617905585815260038952838120600160ff1982541617905581815260028952838120838252895285848083209260018060a01b031993838582541617905560028c528181208582528c522091825416179055825191825287820152a251908152f35b634e487b7160e01b845260419052602483fd5b85513d84823e3d90fd5b634e487b7160e01b885260418752602488fd5b9094509250878062000654565b60409060031901126200090a576004359060243590565b600080fd5b6001548110156200092b57600160005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b90601f801991011681019081106001600160401b038211176200096357604052565b634e487b7160e01b600052604160045260246000fd5b908160209103126200090a575180151581036200090a5790565b9081526001600160a01b0391821660208201529116604082015260600190565b15620009bb57565b60405162461bcd60e51b815260206004820152600c60248201526b1d5b985d5d1a1bdc9a5e995960a21b6044820152606490fd5b631c99585960e21b60009081527f0ebf818546cf436ba3e823ca878b84c3d55a00f566d51f4b07ec1ab90533db4e6004526020816024817f00000000000000000000000010f6b147d51f7578f760065df7f174c3bc95382c6001600160a01b03165afa1562000433575190565b6001600160401b038111620009635760051b60200190565b60005b83811062000a885750506000910152565b818101518382015260200162000a77565b9060209162000ab48151809281855285808601910162000a74565b601f01601f1916010190565b6020818303126200090a5780516001600160401b03918282116200090a57019082601f830112156200090a57815190811162000963576040519262000b10601f8301601f19166020018562000941565b818452602082840101116200090a5762000b31916020808501910162000a74565b90565b6060919073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810362000b8757509050604051604081018181106001600160401b038211176200096357604052600381526208aa8960eb1b602082015290565b6001600160f81b031981168062000c11575090915060a081901c6001600160581b03166200090a576040516395d89b4160e01b815290600090829060049082906001600160a01b03165afa90811562000c055760009162000be6575090565b62000b31913d8091833e62000bfc818362000941565b81019062000ac0565b6040513d6000823e3d90fd5b600160f91b810362000c455750509050604051602081018181106001600160401b0382111762000963576040526000815290565b600160f81b1462000c535750565b6040516395d89b4160e01b8152919250600090829060049082906001600160a01b03165afa90811562000c055760009162000be657509056fe6101e080604052346200094f5760006200453980380380916200002382866200097e565b843982019060e0838303126200094c578251916001600160a01b03831690818403620009485760208501516001600160401b0381116200064057816200006b918701620009a2565b60408601519091906001600160401b038111620008b5579062000090918701620009a2565b90606086015194608087015193620000b960c0620000b160a08b0162000a19565b990162000a19565b917343000000000000000000000000000000000000023b15620008f757604051634e606c4760e01b81528781600481837343000000000000000000000000000000000000025af18015620009275762000932575b507343000000000000000000000000000000000000023b15620008f757604051631d70c8d360e31b81527365432138ae74065aeb3bd71aeac887ccae0e32a460048201528781602481837343000000000000000000000000000000000000025af1801562000927579088916200090f575b50506080523360a0523060c052604051631c41328760e31b81526020816004818a865af190811562000904578791620008c8575b5060e052803b15620008c45785809160446040518094819363343e66c560e21b83523060048401523060248401525af18015620008b9579086916200089d575b50506101009630885263ffffffff67ffffffff000000006006549260201b1692169060018060401b0319161717600655670de0b6b3a76400008060075560085580519060018060401b0382116200088957600254600181811c911680156200087e575b60208210146200086a579081601f8493116200080b575b50602090601f83116001146200078f57869262000783575b50508160011b916000199060031b1c1916176002555b8051906001600160401b0382116200076f57600354600181811c9116801562000764575b602082101462000750579081601f849311620006dd575b50602090601f83116001146200065057859262000644575b50508160011b916000199060031b1c1916176003555b6080516001600160a01b03168083526004602052604083206001600160701b0390819055813b156200064057839160648392604051948593849263d2441f0360e01b845230600485015282602485015260448401525af18015620006355790839162000619575b505060065463ffffffff8160201c166305f5e1009081810291818304149015171562000605577f78e0b45656b8fb6065c79a36aeaf92fbf473dc06966bb96e5fe995247e887503917f6bbc57480a46553fa4d156ce702beef5f3ad66303b0ed1a5d4cb44966c6584c360208093604051908152a163ffffffff60405191168152a16101209280845261014091808352813010600014620005c857839260019160ff8062000437620004306002975b6101609788526101809889526101a0998a5262000a2b565b9362000a2b565b169116019460ff8611620005b45750607f6101c09560011c16855260405195613a08978862000b11893960805188818161082b01528181610a8801528181610c8501528181610f1f015281816111950152818161121e015281816116730152818161170701528181611900015281816119e3015281816121ae01528181612375015281816132c60152613313015260a0518881816110660152611584015260c051888181610efd015281816119b70152611b60015260e051886108a10152518781816105a90152818161087801528181610e7901528181611258015281816115c9015281816117c80152611cbb015251868181611d1e015281816127470152818161295b01528181612a0201528181612ca9015281816133f201526134c1015251858181611d66015281816126e80152818161299301528181612a3e01528181612cd60152818161341801526134e7015251848181612424015261272001525183818161245d01526126c1015251826123d601525181610bb30152f35b634e487b7160e01b81526011600452602490fd5b803010600014620005ec57600192849160ff80620004376200043060029762000418565b600292849160ff80620004376200043060019762000418565b634e487b7160e01b84526011600452602484fd5b620006249062000954565b620006315781386200036a565b5080fd5b6040513d85823e3d90fd5b8380fd5b015190503880620002ed565b600386528593507fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b91905b601f1984168510620006c1576001945083601f19811610620006a7575b505050811b0160035562000303565b015160001960f88460031b161c1916905538808062000698565b818101518355602094850194600190930192909101906200067b565b600386529091507fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b601f840160051c8101916020851062000745575b90601f859493920160051c01905b818110620007365750620002d5565b86815584935060010162000727565b909150819062000719565b634e487b7160e01b85526022600452602485fd5b90607f1690620002be565b634e487b7160e01b84526041600452602484fd5b01519050388062000284565b600287528693506000805160206200451983398151915291905b601f1984168510620007ef576001945083601f19811610620007d5575b505050811b016002556200029a565b015160001960f88460031b161c19169055388080620007c6565b81810151835560209485019460019093019290910190620007a9565b6002875290915060008051602062004519833981519152601f840160051c81016020851062000862575b90849392915b601f830160051c82018110620008535750506200026c565b8881558594506001016200083b565b508062000835565b634e487b7160e01b86526022600452602486fd5b90607f169062000255565b634e487b7160e01b85526041600452602485fd5b620008a89062000954565b620008b5578438620001f2565b8480fd5b6040513d88823e3d90fd5b8580fd5b90506020813d602011620008fb575b81620008e6602093836200097e565b81010312620008f7575138620001b2565b8680fd5b3d9150620008d7565b6040513d89823e3d90fd5b6200091a9062000954565b620008f75786386200017e565b6040513d8a823e3d90fd5b620009409097919762000954565b95386200010d565b8280fd5b80fd5b600080fd5b6001600160401b0381116200096857604052565b634e487b7160e01b600052604160045260246000fd5b601f909101601f19168101906001600160401b038211908210176200096857604052565b919080601f840112156200094f578251906001600160401b038211620009685760405191602091620009de601f8301601f19168401856200097e565b8184528282870101116200094f5760005b81811062000a0557508260009394955001015290565b8581018301518482018401528201620009ef565b519063ffffffff821682036200094f57565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810362000a4d5750601290565b7fff0000000000000000000000000000000000000000000000000000000000000081161562000a7c5750600090565b60a081901c6001600160581b03166200094f5760405163313ce56760e01b815290602090829060049082906001600160a01b03165afa90811562000b045760009162000ac6575090565b6020813d821162000afb575b8162000ae1602093836200097e565b810103126200063157519060ff821682036200094c575090565b3d915062000ad2565b6040513d6000823e3d90fdfe6080604052600436101561001257600080fd5b60003560e01c806306fdde03146102c75780630902f1ac146102c2578063095ea7b3146102bd5780630b1150de146102b85780630dfe1681146102b3578063165cad8d146102ae57806318160ddd146102a957806319706b38146102a457806320e5fe3e1461029f57806323b872dd1461029a578063282b4c86146102955780632986c0e514610290578063313ce5671461028b57806334c0b46b14610286578063376fc5bf1461028157806338706d1f1461027c57806339509351146102775780633a4b66f114610272578063412330bc1461026d57806348313a81146102685780634a3d6bda1461026357806352f7c9881461025e57806369fa25c4146102595780636b35b93d1461025457806370a082311461024f578063781c38001461024a57806395d89b41146102455780639acaa0f4146102405780639c77ac511461023b578063a457c2d714610236578063a5b39cfb14610231578063a9059cbb1461022c578063a9c1f2f114610227578063b3331de414610222578063c45a01551461021d578063cb62900914610218578063ce98f8aa14610213578063d21220a71461020e578063dd62ed3e14610209578063e5a70ef714610204578063ec378808146101ff578063f38a02d0146101fa5763ff7bd55b146101f557600080fd5b6117a1565b61174a565b6116e8565b6116c7565b611638565b61161d565b6115ed565b6115b3565b61156e565b611553565b61152f565b6114b2565b611469565b61141f565b6113f8565b61137f565b6112bc565b611204565b6111dd565b61117e565b61112e565b61102b565b61100f565b610fe9565b610ed7565b610e61565b610e06565b610dea565b610c5d565b610bd7565b610b99565b610b7b565b610b54565b610a40565b61080c565b6105f4565b6105d1565b61058c565b61055f565b610526565b6104ac565b61046d565b61035c565b634e487b7160e01b600052604160045260246000fd5b90601f801991011681019081106001600160401b0382111761030357604052565b6102cc565b919082519283825260005b848110610334575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201610313565b906020610359928181520190610308565b90565b34610468576000806003193601126104655760405190806002549060019180831c9280821692831561045b575b602092838610851461044757858852602088019490811561042657506001146103cd575b6103c9876103bd818903826102e2565b60405191829182610348565b0390f35b600260005294509192917f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b83861061041557505050910190506103bd826103c938806103ad565b8054858701529482019481016103f9565b60ff191685525050505090151560051b0190506103bd826103c938806103ad565b634e487b7160e01b82526022600452602482fd5b93607f1693610389565b80fd5b600080fd5b34610468576000366003190112610468576060610488612ca1565b9060405192835260208301526040820152f35b6001600160a01b0381160361046857565b346104685760403660031901126104685760206104d76004356104ce8161049b565b60243590611a8a565b6040519015158152f35b90815180825260208080930193019160005b828110610501575050505090565b8351855293810193928101926001016104f3565b9060206103599281815201906104e1565b34610468576020366003190112610468573060043503610468576103c961054b6134b7565b6040519182916020835260208301906104e1565b3461046857600036600319011261046857602061057a611d1c565b6040516001600160a01b039091168152f35b3461046857600036600319011261046857602060005260016020527f000000000000000000000000000000000000000000000000000000000000000060405260606000f35b346104685760003660031901126104685760206105ec611a6c565b604051908152f35b346104685760003660031901126104685761060d613352565b80511561067457600160208201528051600110156106745780600160406103c99301526103bd61065463ffffffff61064e60065463ffffffff9060201c1690565b16611dac565b6106666040519384926020840161350e565b03601f1981018352826102e2565b61338d565b6001600160401b0381116103035760051b60200190565b81601f82011215610468578035916106a783610679565b926106b560405194856102e2565b808452602092838086019260051b820101928311610468578301905b8282106106df575050505090565b813580600f0b81036104685781529083019083016106d1565b9181601f84011215610468578235916001600160401b038311610468576020838186019501011161046857565b60806003198201126104685760043561073d8161049b565b91602435916001600160401b0391828411610468578160238501121561046857836004013593838511610468578260248660051b83010111610468576024019392604435818111610468578361079591600401610690565b92606435918211610468576107ac916004016106f8565b9091565b90815180825260208080930193019160005b8281106107d0575050505090565b8351600f0b855293810193928101926001016107c2565b90916107fe610359936040845260408401906107b0565b9160208184039101526107b0565b34610468576109b061081d36610725565b5092949193919250610859337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614611aee565b61086284611bb2565b9361096c6108c661087283611bb2565b9761089e7f00000000000000000000000000000000000000000000000000000000000000008583611c1d565b937f000000000000000000000000000000000000000000000000000000000000000091611c1d565b61095f61095661095061094461093061090a6108e960005460018060801b031690565b6108fc6108f58d6118aa565b5460801c90565b90036001600160801b031690565b6109236109168c6118aa565b546001600160801b031690565b026001600160801b031690565b633b9aca006001600160801b039091160490565b6001600160801b031690565b600f0b90565b600003600f0b90565b90879060010160051b0152565b600181016109bf575b505060005461098d906001600160801b0316916118aa565b80546001600160801b031660809290921b6001600160801b031916919091179055565b6103c9604051928392836107e7565b610a3991610a2b610a036109fe6109f96109de6109446109168a6118aa565b946001870160051b01946109f38651600f0b90565b90611c01565b6137e2565b6137c9565b610a0c866118aa565b80546001600160801b0319166001600160801b03909216919091179055565b5190859060010160051b0152565b3880610975565b3461046857606036600319011261046857600435610a5d8161049b565b602435610a698161049b565b604435906000805160206139b3833981519152906001600160a01b03907f000000000000000000000000000000000000000000000000000000000000000082163303610af5575b610ab9856118c4565b610ac4858254611a5f565b9055610acf816118c4565b805485019055604051938452811693169180602081015b0390a360405160018152602090f35b8185166000526005602052610b0e3360406000206118de565b548460018201610b20575b5050610ab0565b610b2991611a5f565b6001600160a01b0386166000908152600560205260409020610b4c9033906118de565b553884610b19565b346104685760203660031901126104685760206105ec600435610b768161049b565b611cb6565b34610468576000366003190112610468576020600754604051908152f35b3461046857600036600319011261046857602060405160ff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b3461046857600036600319011261046857610bf0611b88565b805115610674576103c9903060208201526040519182916020835260208301906104e1565b92610c416103599593610c33610c4f946080885260808801906104e1565b9086820360208801526107b0565b9084820360408601526107b0565b9160608184039101526107b0565b3461046857604036600319011261046857600435610c7a8161049b565b6001600160a01b03907f0000000000000000000000000000000000000000000000000000000000000000821690610cc190610cb6338414611aee565b6060931630146121e1565b30610cca6133a3565b52610cd3611b88565b91610cdc611b88565b9160046020610ce9611b88565b92604051928380926313c716cd60e21b82525afa908115610de557600091610db7575b50610d23575b6103c9919260405194859485610c15565b6103c99150610d83610d7d610d5c610d57602435610d52610d4960065463ffffffff1690565b63ffffffff1690565b611f9e565b611a4d565b610d78610d6f610d6a61356a565b611dc5565b60075490611b3d565b611de2565b60201c90565b92610daf610da8610da3610d9e610d98611b88565b97613841565b613831565b613552565b8260200152565b929150610d12565b610dd8915060203d8111610dde575b610dd081836102e2565b8101906120e0565b38610d0c565b503d610dc6565b611992565b34610468576000366003190112610468576103c961054b6133c4565b3461046857604036600319011261046857600435610e238161049b565b336000526005602052610e3a8160406000206118de565b546024358101809111610e5c57610e5091611a8a565b50602060405160018152f35b611a37565b346104685760003660031901126104685760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b6020604081830192828152606051809452019160809160005b828110610ec3575050505090565b835185529381019392810192600101610eb5565b346104685760008060031936011261046557610ef16133c4565b610efb8151611bb2565b7f0000000000000000000000000000000000000000000000000000000000000000927f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690805b8451811015610fdc5780610f61610f8192876133b0565b5160405190633d44217960e21b8252818060209586938c60048401611977565b0381885afa908115610de557610faa938592610faf575b5050610fa482876133b0565b5261337e565b610f4a565b610fce9250803d10610fd5575b610fc681836102e2565b810190611968565b3880610f98565b503d610fbc565b604051806103c981610e9c565b3461046857600036600319011261046857602060065463ffffffff60405191831c168152f35b34610468576000366003190112610468576103c961054b6134b7565b34610468576040366003190112610468576110e76020611061611055611055611055611055612175565b6001600160a01b031690565b6040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168382019081526000356001600160e01b0319166020820152906110b48160248401610666565b5190206040516326f8aa2160e21b8152600481019190915233602482015230604482015292839190829081906064820190565b03915afa8015610de55761110391600091611110575b506120f8565b61110e6004356121e8565b005b611128915060203d8111610dde57610dd081836102e2565b386110fd565b34610468576020366003190112610468576111586020611061611055611055611055611055612175565b03915afa8015610de5576111739160009161111057506120f8565b61110e600435612133565b34610468576000366003190112610468576111c3337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614611aee565b600680546fffffffffffffffff00000000ffffffff169055005b346104685760203660031901126104685760206105ec6004356111ff8161049b565b6118f5565b346104685760203660031901126104685760043561124c337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614611aee565b8061125357005b61127c7f0000000000000000000000000000000000000000000000000000000000000000611b47565b908115801561128757005b6112b757633b9aca00906000549260018060801b0392839202041681831601169060018060801b03191617600055005b611b27565b34610468576000806003193601126104655760405190806003549060019180831c92808216928315611375575b6020928386108514610447578588526020880194908115610426575060011461131c576103c9876103bd818903826102e2565b600360005294509192917fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b83861061136457505050910190506103bd826103c938806103ad565b805485870152948201948101611348565b93607f16936112e9565b346104685760203660031901126104685760043561139c8161049b565b6000906001600160a01b031630036113f35750670de0b6b3a76400006113c061356a565b0260075480156112b75763ffffffff60065416600160201b0391040260201c5b6020600052600160205260405260606000f35b6113e0565b3461046857600036600319011261046857602060065463ffffffff6040519160401c168152f35b346104685760403660031901126104685760043561143c8161049b565b3360005260056020526114538160406000206118de565b546024358103908111610e5c57610e5091611a8a565b34610468576020366003190112610468576004356114868161049b565b60018060a01b0316600052600160205260018060801b0360406000205416602060005260405260606000f35b34610468576040366003190112610468576004356114cf8161049b565b602435903360005260046020526040600020805490838203918211610e5c575560018060a01b03169081600052600460205260406000208181540190556000805160206139b383398151915260405180610ae63394829190602083019252565b3461046857600036600319011261046857602063ffffffff60065416604051908152f35b346104685760003660031901126104685760206105ec611ed2565b34610468576000366003190112610468576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610468576000366003190112610468576113e07f0000000000000000000000000000000000000000000000000000000000000000611b47565b346104685760203660031901126104685761160960043561049b565b602060005260016020523060405260606000f35b3461046857600036600319011261046857602061057a611d64565b34610468576040366003190112610468576004356116558161049b565b602435906116628261049b565b6000916001600160a01b03918282167f00000000000000000000000000000000000000000000000000000000000000008416036116aa57505050506020600019604051908152f35b6020936116c19360409216815260058552206118de565b546105ec565b3461046857600036600319011261046857602060065460801c604051908152f35b346104685761173a6116f936610725565b5090939192919050611735337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614611aee565b6122cc565b906103c9604051928392836107e7565b346104685760003660031901126104685760405160408101908082106001600160401b03831117610303576103c991604052600481526363706d6d60e01b6020820152604051918291602083526020830190610308565b34610468576000806003193601126104655760405163251eb5ed60e11b81529080826004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610de557809161180e575b604051806103c98482610515565b90503d8082843e61181f81846102e2565b820160209283818303126118a2578051906001600160401b0382116118a6570181601f820112156118a25780519061185682610679565b9361186460405195866102e2565b828552858086019360051b83010193841161046557508401905b828210611893575050506103c9915038611800565b8151815290840190840161187e565b8280fd5b8380fd5b6001600160a01b0316600090815260016020526040902090565b6001600160a01b0316600090815260046020526040902090565b9060018060a01b0316600052602052604060002090565b6001600160a01b03907f0000000000000000000000000000000000000000000000000000000000000000821633811415908161195c575b5061193f5761193b91506118c4565b5490565b1660005260046020526040600020546119573061199e565b900390565b9050828216143861192c565b90816020910312610468575190565b6001600160a01b039091168152602081019190915260400190565b6040513d6000823e3d90fd5b60206119df9160405180938192633d44217960e21b83527f000000000000000000000000000000000000000000000000000000000000000060048401611977565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610de557600091611a1f575090565b610359915060203d8111610fd557610fc681836102e2565b634e487b7160e01b600052601160045260246000fd5b90600160201b918203918211610e5c57565b91908203918211610e5c57565b611a753061199e565b6001600160701b03908103908111610e5c5790565b33600052600560205281611aa28260406000206118de565b556040519182526001600160a01b03169033907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590602090a3600190565b9060018201809211610e5c57565b15611af557565b60405162461bcd60e51b815260206004820152600a6024820152691bdb9b1e481d985d5b1d60b21b6044820152606490fd5b634e487b7160e01b600052601260045260246000fd5b81156112b7570490565b60206119df916040518093819263ebd8189f60e01b83527f000000000000000000000000000000000000000000000000000000000000000060048401611977565b60405190604082018281106001600160401b03821117610303576040526001825260203681840137565b90611bbc82610679565b611bc960405191826102e2565b8281528092611bda601f1991610679565b0190602036910137565b9060018201916000600184129112908015821691151617610e5c57565b91909160008382019384129112908015821691151617610e5c57565b90918215611cad5760009060001993848101908111610e5c5793929193905b81851115611c4c57505050905090565b6001858303811c860180968160051b860135848114600014611c7357505050505050505090565b87985093809596979192939410600014611c94575050015b93929190611c3c565b925093508015611ca5570191611c8b565b505050505090565b50505060001990565b611cdf7f0000000000000000000000000000000000000000000000000000000000000000611b47565b908115611d15576001600160a01b03166000908152600160205260409020546001600160801b0316670de0b6b3a7640000020490565b5050600090565b7f000000000000000000000000000000000000000000000000000000000000000073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810361105557506004604360981b0190565b7f000000000000000000000000000000000000000000000000000000000000000073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810361105557506004604360981b0190565b90633b9aca0091828102928184041490151715610e5c57565b90670de0b6b3a764000091828102928184041490151715610e5c57565b81810292918115918404141715610e5c57565b90676765c793fa10079d601b1b91828102928184051490151715610e5c57565b90670de0b6b3a764000091828102928184051490151715610e5c57565b818102929160008212600160ff1b821416610e5c578184051490151715610e5c57565b90676765c793fa10079d601b1b60008382039312818412811691841390151617610e5c57565b90670de0b6b3a764000060008382039312818412811691841390151617610e5c57565b81810392916000138015828513169184121617610e5c57565b81156112b757600160ff1b8114600019831416610e5c570590565b611edd610d6a613460565b611ee5611a6c565b60028101809111610e5c5780156112b757611f009104613841565b60065460601c63ffffffff16428103611f1b57505060095490565b610359916109f3611f7383611f6d611f66611f52611f4d611f47611f42611f8d9a42611a5f565b61203a565b97611df5565b6138c7565b611f60611f4d600854611df5565b90611e9e565b9142611a5f565b90611eb7565b611f88611f8284600954611e32565b93611e55565b611e32565b676765c793fa10079d601b1b900590565b90919080156120265760018381161561201b5781935b811c805b611fc2575050505b565b82800292808404036104685763800000009283810190811061046857602090811c93838316611ff6575b5050811c80611fb8565b848793970292858404141585151516610468578201918210610468571c933880611fec565b600160201b93611fb4565b50901561203257600090565b600160201b90565b906b033b2ad6d379451d40331f576001808416156120ce5781935b811c805b61206257505050565b8280029280840403610468576b019d971e4fe8401e740000009283810190811061046857676765c793fa10079d601b1b809104938383166120a8575b5050811c80612059565b84879293970291858304141585151516610468578101908110610468570493388061209e565b676765c793fa10079d601b1b93612055565b90816020910312610468575180151581036104685790565b156120ff57565b60405162461bcd60e51b815260206004820152600c60248201526b1d5b985d5d1a1bdc9a5e995960a21b6044820152606490fd5b602063ffffffff7f78e0b45656b8fb6065c79a36aeaf92fbf473dc06966bb96e5fe995247e88750392168063ffffffff196006541617600655604051908152a1565b631c99585960e21b60009081527f0ebf818546cf436ba3e823ca878b84c3d55a00f566d51f4b07ec1ab90533db4e6004526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa15610465575190565b1561046857565b600654906305f5e1009163ffffffff9183838360201c16116104685763ffffffff60201b9060201b169063ffffffff60201b1916178060065560201c16818102918183041490151715610e5c5760207f6bbc57480a46553fa4d156ce702beef5f3ad66303b0ed1a5d4cb44966c6584c391604051908152a1565b929161226d82610679565b9161227b60405193846102e2565b829481845260208094019160051b810192831161046857905b8282106122a15750505050565b81358152908301908301612294565b6001600160801b039182169082160290811691908203610e5c57565b939291612338906122dc81611bb2565b936122e682611bb2565b9661233e6122f2612ca1565b50604080516001600160701b03848116825283166020820152919792917f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad19190a1611be4565b94611be4565b9261235260065463ffffffff9060401c1690565b63ffffffff42911603612b99575b6040516313c716cd60e21b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610de557600091612b7a575b5015612aae575b6003810361276d5794612420612536966124176123d3368386612262565b917f0000000000000000000000000000000000000000000000000000000000000000946001860160051b809401513014918261270f575b826126b1575b50506121e1565b840151600f0b90565b92897f0000000000000000000000000000000000000000000000000000000000000000966124576001890160051b840151600f0b90565b9661248c7f0000000000000000000000000000000000000000000000000000000000000000946001860160051b0151600f0b90565b60016001607f1b038881146125bf5789811461253a57505061251b926124ee612531969593612505938b6124cb6124c68d60075490611e32565b612bc6565b916124e861094460065463ffffffff8160801c9160201c166122b0565b93612f20565b995b6124f98a613831565b919060010160051b0152565b61250e88613831565b908c9060010160051b0152565b61252484613831565b908a9060010160051b0152565b6130d4565b9190565b90999850891461258f5761251b92612589612531969593612505938c6125666124c68d60075490611e32565b9161258361094460065463ffffffff8160801c9160201c166122b0565b93612cff565b986124f0565b61251b9298506125b7612531959492612505926125b16124c66007548c611e32565b91613022565b9990986124f0565b819a9850808a92939a14808015906126a7575b6125db906121e1565b1561264557505061251b9261263f612636612631858561260c8e6126076125319d9c9a6125059a611e32565b611eb7565b809e5b61262b61094460065463ffffffff8160801c9160201c166122b0565b93612f2f565b611e15565b60075490612c33565b976124f0565b9098911461266c575b61251b9261263f6126366126316125319897958d8d6125059761260f565b87985061251b9261263f61263661263185856126956125319b9a988f6125059961260791611e32565b9e50955095979850505050925061264e565b50838214156125d2565b6126bd92503691612262565b60017f00000000000000000000000000000000000000000000000000000000000000000160051b01517f0000000000000000000000000000000000000000000000000000000000000000143880612410565b915061271c368383612262565b60017f00000000000000000000000000000000000000000000000000000000000000000160051b01517f0000000000000000000000000000000000000000000000000000000000000000149161240a565b9293919260028103612a7157602084015160408501516127a29160016001607f1b03600f91820b81149290910b1414156121e1565b6002906002966002926127c06127b9368585612262565b6020015190565b3081036129fc5750506127db6127e2916000935b3691612262565b6040015190565b308103612956575050612536956001935b60028503612943576000965b87600284036129315760005b976002860361291f57506000985b8960016001607f1b0382036128cd575050506126316128549289896126369461262b61094460065463ffffffff8160801c9160201c166122b0565b935b600281146128bd5761286b9061250e86613831565b600281146128ad5761288d9061288086613831565b908b9060010160051b0152565b600281146128a2576125319061252486613831565b5061253184156121e1565b506128b884156121e1565b61288d565b506128c884156121e1565b61286b565b9799919790919060016001607f1b03810361290057505090876124cb6124c66128fa959460075490611e32565b95612856565b909998506125666124c661291995949360075490611e32565b94612856565b6001860160051b0151600f0b98612819565b6001840160051b880151600f0b61280b565b6001850160051b860151600f0b966127ff565b9093907f0000000000000000000000000000000000000000000000000000000000000000810361298e575061253696506001906127f3565b9091507f0000000000000000000000000000000000000000000000000000000000000000036129c357612536956001916127f3565b60405162461bcd60e51b81526020600482015260116024820152703ab739bab83837b93a32b2103a37b5b2b760791b6044820152606490fd5b929890927f00000000000000000000000000000000000000000000000000000000000000008103612a385750506127db6127e2916000996127d4565b909893507f0000000000000000000000000000000000000000000000000000000000000000036129c3576127db6127e2916000946127d4565b60405162461bcd60e51b81526020600482015260156024820152743ab739bab83837b93a32b21037b832b930ba34b7b760591b6044820152606490fd5b612b07612add612ad8612ac2610d6a613460565b612ad2612acd611a6c565b611ae0565b90611b3d565b613841565b600654612af29060601c63ffffffff16610d49565b4281141580612b6e575b612b0c575b50600755565b6123b5565b612b3c611f8d826109f3611f73612b29611f42612b419742611a5f565b92611f6d611f66611f52611f4d8b611df5565b600955565b612b4a81600855565b6006805463ffffffff60601b19164260601b63ffffffff60601b1617905538612b01565b50816008541415612afc565b612b93915060203d602011610dde57610dd081836102e2565b386123ae565b600680546001600160801b0316621dcd6560891b179055612360565b600160ff1b8114610e5c5760000390565b60016000612bd3836138b6565b921303612bed57670de0b6b3a76400006103599104613841565b80612c055750610359612c006000613841565b612bb5565b6000198101908111610e5c57670de0b6b3a7640000900460018101809111610e5c57612c0061035991613841565b612c3c816138b6565b90600080612c49856138b6565b9413911314600014612c8d5780612c665750506103596000613841565b6000198101908111610e5c5781156112b7570460018101809111610e5c5761035990613841565b81156112b75761035991612c009104613841565b612ccd612ad87f000000000000000000000000000000000000000000000000000000000000000061199e565b90612cfa612ad87f000000000000000000000000000000000000000000000000000000000000000061199e565b904290565b90612d0f61035995949382611c01565b91612dcd565b8015612dc7576000811380600114612daf5715612d98575b80026001805b60018111612d695750600081136001600160ff1b03839004821116610e5c5760008112600160ff1b839005821216610e5c570290565b916001600160ff1b038190048111610e5c5760018316612d8f575b80029160011c612d33565b80910290612d84565b6001600160ff1b03819005811215612d2d57611a37565b506001600160ff1b03819004811115612d2d57611a37565b50600090565b9291938361035995612e05612dfe612ad8612df9612dea866137e2565b612df3896137e2565b90611de2565b613749565b9586611e9e565b90612e12600083136121e1565b612e6d8287139185831597858a8a600014612ee15792611f88612e4c611f6094612e47612e51956126078a612e5f9b9a611e32565b611e9e565b6138a8565b670de0b6b3a7640000900590565b612e6884612d15565b612c33565b9415612e9d5750612e9783611f88612e4c6109f39695612e47611f6d966126078b612e479d611e32565b91611e7b565b94929394612eaf575b50505050611e9e565b612e9784611f88612e4c612ed26109f397612607612ed89b9a98611f6d98611e32565b88611e9e565b38808381612ea6565b9190821215612ef3575b505050612e5f565b612f189392611f88612e4c612f12611f6095612607612e51968d611e32565b86611e9e565b858838612eeb565b612d0f61035995949382611c01565b929061035994612f4c612f45611f609587611c01565b9383611c01565b91612f60612ad8612df96109f9848a611e32565b9584612f6d85899761343f565b9182871380612fc05750612e4c611f6094612e47856126078a612fb488611f608f612fba9f9e611f88612e4c612e519f9d839f611f889f612607612e4792612e5198611e32565b9c611e32565b9061343f565b96929493919596612fd6575b505050505061343f565b612e4c612f128461260787956130116130179b611f60612e518d9f9d9c611f88612e4c611f609f612e519f612607611f889f612f1293611e32565b9b611e32565b903880858180612fcc565b9092916000808213156130ce57506001915b613049613040826137e2565b612df3876137e2565b613052816135fd565b9060038510156130b85761309e612e6893612e68612c00613096612c0096899660016103599c1490816130ac575b50600090156130a4575060ff60015b1601613841565b978893611e32565b96611e32565b60ff9061308f565b90508180021038613080565b634e487b7160e01b600052602160045260246000fd5b91613034565b9092909160008085131561319d57509261317892610944927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d8193649661312261311c611fc098612bb5565b92612bb5565b6040805193845260208401919091526001600160a01b0393909316928392a361314a81613308565b612ad261317261316261315b613460565b9384611a5f565b92610d7861094460065460801c90565b916135ec565b600680546001600160801b031660809290921b6001600160801b031916919091179055565b909290808512156131fc5750604080519384526020840192909252611fc0936131f79390926001600160a01b0392909216917f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f91a2612bb5565b6132be565b9350839290918391829081808213156132ac5750925b82131561327457509061326f7fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822935b60018060a01b0316958695604051948594859094939260609260808301968352602083015260408201520152565b0390a3565b91907fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229395506132a661326f91612bb5565b95613241565b9395506132b890612bb5565b94613212565b6040519081527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906000906000805160206139b383398151915290602090a3565b6040519081526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906000805160206139b383398151915290602090a3565b60405190606082018281106001600160401b038211176103035760405260028252604082602036910137565b6000198114610e5c5760010190565b634e487b7160e01b600052603260045260246000fd5b6060511561067457608090565b80518210156106745760209160051b010190565b604051608081018181106001600160401b0382111761030357604052600381526020810160603682373090527f000000000000000000000000000000000000000000000000000000000000000060408201527f0000000000000000000000000000000000000000000000000000000000000000606082015290565b61345b61035992612df3613455612ad8946137e2565b916137e2565b6135fd565b613468612ca1565b509060018101906000600183129112908015821691151617610e5c5760018201916000600184129112908015821691151617610e5c57612ad861345b61035993612df36134556109f9956137e2565b6134bf613352565b7f000000000000000000000000000000000000000000000000000000000000000060208201527f0000000000000000000000000000000000000000000000000000000000000000604082015290565b9060609160408101918152602092816040858094015285518094520193019160005b82811061353e575050505090565b835185529381019392810192600101613530565b600f0b60016001607f1b03198114610e5c5760000390565b613572611a6c565b60018101809111610e5c5761358c90612df36007546137e2565b806135c4575060005b61359d612ca1565b5050506135a8613460565b90808210156135b8575050600090565b8103908111610e5c5790565b6000198101908111610e5c57670de0b6b3a76400009004600181018091111561359557611a37565b806001116000146103595750600190565b8015612dc757806136d06136c96136bf6136b56136ab6136a161369761368d60016103599a6000908b60801c8061372b575b508060401c8061371e575b508060201c80613711575b508060101c80613704575b508060081c806136f7575b508060041c806136ea575b508060021c806136dd575b50821c6136d6575b811c1b613686818b611b3d565b0160011c90565b613686818a611b3d565b6136868189611b3d565b6136868188611b3d565b6136868187611b3d565b6136868186611b3d565b6136868185611b3d565b8092611b3d565b90613737565b8101613679565b6002915091019038613671565b6004915091019038613666565b600891509101903861365b565b6010915091019038613650565b6020915091019038613645565b604091509101903861363a565b9150506080903861362f565b9080821015613744575090565b905090565b613752816135fd565b906000908280021015613766575060010190565b60ff160190565b1561377457565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b6001600160801b03906137de8282111561376d565b1690565b600081126137ed5790565b606460405162461bcd60e51b815260206004820152602060248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152fd5b90611fc082600f0b92831461376d565b6001600160ff1b0381116138525790565b60405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608490fd5b600080821315613744575090565b60008082126138c3575090565b0390565b90670de0b6b3a76400009182811061399a5782810460018060801b03811160071b90811c906001600160401b03821160061b91821c63ffffffff811160051b90811c61ffff811160041b90811c60ff811160031b90811c91600f831160021b92831c936001968760038711811b96871c11961717171717171791848302921c93808514613993576706f05b59d3b2000094855b61396657509193505050565b808291020494671bc16d674ec80000861015613986575b821c948561395a565b8095930192821c9461397d565b5090925050565b6024906040519063036d32ef60e41b82526004820152fdfeddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220eaac9e506e37c4bb32f1cd873b82632cd5213f90c7901120c31bfc7614bd465a64736f6c63430008130033405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5acea2646970667358221220f8f2843547af08c7b83234ae69ee86ab5a8f73b7914ec7a6230b552c809ec4cf64736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000010f6b147d51f7578f760065df7f174c3bc95382c
-----Decoded View---------------
Arg [0] : vault_ (address): 0x10F6b147D51f7578F760065DF7f174c3bc95382c
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000010f6b147d51f7578f760065df7f174c3bc95382c
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
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.