Source Code
Overview
MON Balance
MON Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
Funding
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 200 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import {DataStore} from "./DataStore.sol";
import {FundingStore} from "./FundingStore.sol";
import {MarketStore} from "./MarketStore.sol";
import {PositionStore} from "./PositionStore.sol";
import "./Roles.sol";
import {RiskStore} from "./RiskStore.sol";
/**
* @title Funding
* @notice Funding rates are calculated hourly for each market and collateral
* asset based on the real-time open interest imbalance
*/
contract Funding is Roles {
// Events
event FundingUpdated(
address indexed asset,
string market,
uint256 OILong,
uint256 OIShort,
int256 accruedFundingV1,
int256 accruedFundingV2,
int256 onePeriodFundingIncrement,
int256 fundingTracker
);
// Constants
uint256 public constant UNIT = 10 ** 18;
// Contracts
DataStore public DS;
FundingStore public fundingStore;
MarketStore public marketStore;
PositionStore public positionStore;
RiskStore public riskStore;
/// @dev Initializes DataStore address
function initialize(address rs, address ds) external initializer {
DS = DataStore(ds);
roleStore = RoleStore(rs);
_setGov(msg.sender);
}
/// @notice Initializes protocol contracts
/// @dev Only callable by governance
function link() external onlyGov {
fundingStore = FundingStore(DS.getAddress("FundingStore"));
marketStore = MarketStore(DS.getAddress("MarketStore"));
positionStore = PositionStore(DS.getAddress("PositionStore"));
riskStore = RiskStore(DS.getAddress("RiskStore"));
}
/// @notice Updates funding tracker of `market` and `asset`
/// @dev Only callable by other protocol contracts
function updateFundingTracker(
address asset,
string calldata market
) external onlyContract {
uint256 lastUpdated = fundingStore.getLastUpdated(asset, market);
uint256 _now = block.timestamp;
// condition is true only on the very first execution
if (lastUpdated == 0) {
fundingStore.setLastUpdated(asset, market, _now);
return;
}
// returns if block.timestamp - lastUpdated is less than funding interval
if (lastUpdated + fundingStore.fundingInterval() > _now) return;
// positive funding increment indicates that shorts pay longs, negative that longs pay shorts
(
int256 fundingIncrement,
int256 emaFundingRate,
int256 onePeriodFR,
int256 capedEmaFundingRate
) = getAccruedFundingV2(asset, market, 0); // in UNIT * bps
// return if funding increment is zero
if (fundingIncrement == 0) {
// Ensure state advances even when increment is zero to avoid stale accrual
fundingStore.setLastEmaFundingRate(asset, market, emaFundingRate);
fundingStore.setLastCappedEmaFundingRate(
asset,
market,
capedEmaFundingRate
);
fundingStore.setLastUpdated(asset, market, _now);
return;
}
fundingStore.setLastEmaFundingRate(asset, market, emaFundingRate);
fundingStore.setLastCappedEmaFundingRate(
asset,
market,
capedEmaFundingRate
);
fundingStore.updateFundingTracker(asset, market, fundingIncrement);
fundingStore.setLastUpdated(asset, market, _now);
emit FundingUpdated(
asset,
market,
positionStore.getOILong(asset, market),
positionStore.getOIShort(asset, market),
getAccruedFunding(asset, market, 1),
fundingIncrement,
onePeriodFR,
fundingStore.getFundingTracker(asset, market)
);
}
/// @notice Returns accrued funding of `market` and `asset`
function getAccruedFunding(
address asset,
string memory market,
uint256 intervals
) public view returns (int256) {
if (intervals == 0) {
intervals =
(block.timestamp - fundingStore.getLastUpdated(asset, market)) /
fundingStore.fundingInterval();
}
if (intervals == 0) return 0;
uint256 OILong = positionStore.getOILong(asset, market);
uint256 OIShort = positionStore.getOIShort(asset, market);
if (OIShort == 0 && OILong == 0) return 0;
uint256 OIDiff = OIShort > OILong ? OIShort - OILong : OILong - OIShort;
MarketStore.Market memory marketInfo = marketStore.get(market);
uint256 yearlyFundingFactor = marketInfo.fundingFactor;
uint256 accruedFunding = (UNIT *
yearlyFundingFactor *
OIDiff *
intervals) / (24 * 365 * (OILong + OIShort)); // in UNIT * bps
if (OILong > OIShort) {
// Longs pay shorts. Increase funding tracker.
return int256(accruedFunding);
} else {
// Shorts pay longs. Decrease funding tracker.
return -1 * int256(accruedFunding);
}
}
/// @notice Returns accrued funding of `market` and `asset`
function getAccruedFundingV2(
address asset,
string memory market,
uint256 intervals
) public view returns (int256, int256, int256, int256) {
if (intervals == 0) {
intervals =
(block.timestamp - fundingStore.getLastUpdated(asset, market)) /
fundingStore.fundingInterval();
}
if (intervals == 0) return (0, 0, 0, 0);
uint256 OILong = positionStore.getOILong(asset, market);
uint256 OIShort = positionStore.getOIShort(asset, market);
if (OIShort == 0 && OILong == 0) return (0, 0, 0, 0);
MarketStore.Market memory marketInfo = marketStore.get(market);
uint256 yearlyFundingFactor = marketInfo.fundingFactor;
uint256 maxDelta = riskStore.getMaxDelta(market, asset);
int256 lastEmaFundingRate = fundingStore.getLastEmaFundingRate(
asset,
market
);
uint256 minFactor = marketInfo.minFactor;
uint256 sampleSize = marketInfo.sampleSize;
uint256 absDelta = OIShort > OILong
? OIShort - OILong
: OILong - OIShort;
if (
minFactor == 0 || sampleSize == 0 || absDelta == 0 || maxDelta == 0
) {
return (0, 0, 0, 0);
}
// Δ/MaxDelta = (OILong - OIShort) / MaxDelta
int256 deltaRatio = ((int256(OILong) - int256(OIShort)) *
int256(UNIT)) / int256(maxDelta);
// min(UNIT, Δ/MaxDelta)
if (deltaRatio > int256(UNIT)) {
deltaRatio = int256(UNIT);
}
// max(-UNIT, min(UNIT, Δ/MaxDelta))
if (deltaRatio < -int256(UNIT)) {
deltaRatio = -int256(UNIT);
}
// FR(Δ) = FundingFactor * max(-UNIT, min(UNIT, Δ/MaxDelta))
int256 FR = int256(yearlyFundingFactor) * deltaRatio;
// α = 2 * UNIT / (N + 1)
int256 alpha = (2 * int256(UNIT)) / (int256(sampleSize) + 1);
// FR(EMA_t) = (α * FR(t) + (1 - α) * FR(EMA_t-1)) / UNIT -> FR(EMA_t): bps × UNIT
int256 emaFundingRate = (alpha *
FR +
(int256(UNIT) - alpha) *
lastEmaFundingRate) / int256(UNIT);
int256 incr = emaFundingRate;
// Cap the funding rate
if (incr > 0 && incr < int256(minFactor) * int256(UNIT)) {
incr = int256(minFactor) * int256(UNIT);
} else if (incr < 0 && incr > -int256(minFactor) * int256(UNIT)) {
incr = -int256(minFactor) * int256(UNIT);
}
uint256 accruedFunding = (uint256(incr > 0 ? incr : -incr) *
intervals) / (24 * 365);
uint256 onePeriodFundingIncrement = (uint256(incr > 0 ? incr : -incr)) /
(24 * 365);
if (OILong > OIShort) {
// Longs pay shorts. Increase funding tracker.
return (
int256(accruedFunding),
emaFundingRate,
int256(onePeriodFundingIncrement),
incr
);
} else {
// Shorts pay longs. Decrease funding tracker.
return (
-1 * int256(accruedFunding),
emaFundingRate,
-1 * int256(onePeriodFundingIncrement),
incr
);
}
}
function getRealTimeFundingTracker(
address asset,
string calldata market
) public view returns (int256) {
int256 currentFundingTracker = fundingStore.getFundingTracker(
asset,
market
);
uint256 lastUpdated = fundingStore.getLastUpdated(asset, market);
int256 totalPeriodFundingIncrement = fundingStore
.getLastCappedEmaFundingRate(asset, market) / int256(24 * 365);
uint256 fundingInterval = fundingStore.fundingInterval();
uint256 ratio = (UNIT * (block.timestamp - lastUpdated)) /
(fundingInterval);
if (ratio == 0) return currentFundingTracker;
int256 realTimeFundingTracker = currentFundingTracker +
(totalPeriodFundingIncrement * int256(ratio)) /
int256(UNIT);
return realTimeFundingTracker;
}
function getRealTimeFundingTrackers(
address asset,
string[] calldata markets
) external view returns (int256[] memory) {
uint256 length = markets.length;
int256[] memory realTimeFundingTrackers = new int256[](length);
for (uint256 i = 0; i < length; i++) {
realTimeFundingTrackers[i] = getRealTimeFundingTracker(
asset,
markets[i]
);
}
return realTimeFundingTrackers;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import {Governable} from "./Governable.sol";
/// @title DataStore
/// @notice General purpose storage contract
/// @dev Access is restricted to governance
contract DataStore is Governable {
// Key-value stores
mapping(bytes32 => uint256) public uintValues;
mapping(bytes32 => int256) public intValues;
mapping(bytes32 => address) public addressValues;
mapping(bytes32 => bytes32) public dataValues;
mapping(bytes32 => bool) public boolValues;
mapping(bytes32 => string) public stringValues;
function initialize() external initializer {
_setGov(msg.sender);
}
/// @param key The key for the record
/// @param value value to store
/// @param overwrite Overwrites existing value if set to true
function setUint(
string calldata key,
uint256 value,
bool overwrite
) external onlyGov returns (bool) {
bytes32 hash = getHash(key);
if (overwrite || uintValues[hash] == 0) {
uintValues[hash] = value;
return true;
}
return false;
}
/// @param key The key for the record
function getUint(string calldata key) external view returns (uint256) {
return uintValues[getHash(key)];
}
/// @param key The key for the record
/// @param value value to store
/// @param overwrite Overwrites existing value if set to true
function setInt(
string calldata key,
int256 value,
bool overwrite
) external onlyGov returns (bool) {
bytes32 hash = getHash(key);
if (overwrite || intValues[hash] == 0) {
intValues[hash] = value;
return true;
}
return false;
}
/// @param key The key for the record
function getInt(string calldata key) external view returns (int256) {
return intValues[getHash(key)];
}
/// @param key The key for the record
/// @param value address to store
/// @param overwrite Overwrites existing value if set to true
function setAddress(
string calldata key,
address value,
bool overwrite
) external onlyGov returns (bool) {
bytes32 hash = getHash(key);
if (overwrite || addressValues[hash] == address(0)) {
addressValues[hash] = value;
return true;
}
return false;
}
/// @param key The key for the record
function getAddress(string calldata key) external view returns (address) {
return addressValues[getHash(key)];
}
/// @param key The key for the record
/// @param value byte value to store
function setData(
string calldata key,
bytes32 value
) external onlyGov returns (bool) {
dataValues[getHash(key)] = value;
return true;
}
/// @param key The key for the record
function getData(string calldata key) external view returns (bytes32) {
return dataValues[getHash(key)];
}
/// @param key The key for the record
/// @param value value to store (true / false)
function setBool(
string calldata key,
bool value
) external onlyGov returns (bool) {
boolValues[getHash(key)] = value;
return true;
}
/// @param key The key for the record
function getBool(string calldata key) external view returns (bool) {
return boolValues[getHash(key)];
}
/// @param key The key for the record
/// @param value string to store
function setString(
string calldata key,
string calldata value
) external onlyGov returns (bool) {
stringValues[getHash(key)] = value;
return true;
}
/// @param key The key for the record
function getString(
string calldata key
) external view returns (string memory) {
return stringValues[getHash(key)];
}
/// @param key string to hash
function getHash(string memory key) public pure returns (bytes32) {
return keccak256(abi.encodePacked(key));
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import "./Roles.sol";
/// @title FundingStore
/// @notice Storage of funding trackers for all supported markets
contract FundingStore is Roles {
// interval used to calculate accrued funding
uint256 public fundingInterval;
// asset => market => funding tracker (long) (short is opposite)
mapping(address => mapping(string => int256)) private fundingTrackers;
// asset => market => last time fundingTracker was updated. In seconds.
mapping(address => mapping(string => uint256)) private lastUpdated;
// asset => market => last ema funding rate
mapping(address => mapping(string => int256)) private lastEmaFundingRate;
// asset => market => capped ema funding rate
mapping(address => mapping(string => int256))
private lastCappedEmaFundingRate;
function initialize(address rs) external initializer {
roleStore = RoleStore(rs);
_setGov(msg.sender);
fundingInterval = 8 hours;
}
/// @notice updates `fundingInterval`
/// @dev Only callable by governance
/// @param interval new funding interval, in seconds
function setFundingInterval(uint256 interval) external onlyGov {
require(interval > 0, "!interval");
fundingInterval = interval;
}
/// @notice updates `lastEmaFundingRate` mapping
/// @dev Only callable by other protocol contracts
/// @param asset Asset address, e.g. address(0) for ETH
/// @param market Market, e.g. "ETH-USD"
/// @param emaFundingRate Last ema funding rate
function setLastEmaFundingRate(
address asset,
string calldata market,
int256 emaFundingRate
) external onlyContract {
lastEmaFundingRate[asset][market] = emaFundingRate;
}
/// @notice updates `lastCappedEmaFundingRate` mapping
/// @dev Only callable by other protocol contracts
/// @param asset Asset address, e.g. address(0) for ETH
/// @param market Market, e.g. "ETH-USD"
/// @param cappedEmaFundingRate Last capped ema funding rate
function setLastCappedEmaFundingRate(
address asset,
string calldata market,
int256 cappedEmaFundingRate
) external onlyContract {
lastCappedEmaFundingRate[asset][market] = cappedEmaFundingRate;
}
/// @notice returns `lastEmaFundingRate` mapping
/// @param asset Asset address, e.g. address(0) for ETH
/// @param market Market, e.g. "ETH-USD"
function getLastEmaFundingRate(
address asset,
string calldata market
) external view returns (int256) {
return lastEmaFundingRate[asset][market];
}
/// @notice returns `lastCappedEmaFundingRate` mapping
/// @param asset Asset address, e.g. address(0) for ETH
/// @param market Market, e.g. "ETH-USD"
function getLastCappedEmaFundingRate(
address asset,
string calldata market
) external view returns (int256) {
return lastCappedEmaFundingRate[asset][market];
}
/// @notice Updates `lastUpdated` mapping
/// @dev Only callable by other protocol contracts
/// @dev Invoked by Funding.updateFundingTracker
/// @param asset Asset address, e.g. address(0) for ETH
/// @param market Market, e.g. "ETH-USD"
/// @param timestamp Timestamp in seconds
function setLastUpdated(
address asset,
string calldata market,
uint256 timestamp
) external onlyContract {
lastUpdated[asset][market] = timestamp;
}
/// @notice updates `fundingTracker` mapping
/// @dev Only callable by other protocol contracts
/// @dev Invoked by Funding.updateFundingTracker
/// @param asset Asset address, e.g. address(0) for ETH
/// @param market Market, e.g. "ETH-USD"
/// @param fundingIncrement Accrued funding of given asset and market
function updateFundingTracker(
address asset,
string calldata market,
int256 fundingIncrement
) external onlyContract {
fundingTrackers[asset][market] += fundingIncrement;
}
/// @notice Returns last update timestamp of `asset` and `market`
/// @param asset Asset address, e.g. address(0) for ETH
/// @param market Market, e.g. "ETH-USD"
function getLastUpdated(
address asset,
string calldata market
) external view returns (uint256) {
return lastUpdated[asset][market];
}
/// @notice Returns funding tracker of `asset` and `market`
/// @param asset Asset address, e.g. address(0) for ETH
/// @param market Market, e.g. "ETH-USD"
function getFundingTracker(
address asset,
string calldata market
) external view returns (int256) {
return fundingTrackers[asset][market];
}
/// @notice Returns funding trackers of `assets` and `markets`
/// @param assets Array of asset addresses
/// @param markets Array of market strings
function getFundingTrackers(
address[] calldata assets,
string[] calldata markets
) external view returns (int256[] memory fts) {
uint256 assetsLength = assets.length;
uint256 marketsLength = markets.length;
fts = new int256[](assetsLength * marketsLength);
uint256 index = 0;
for (uint256 i = 0; i < assetsLength; i++) {
for (uint256 j = 0; j < marketsLength; j++) {
fts[index] = fundingTrackers[assets[i]][markets[j]];
index++;
}
}
return fts;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import "./Roles.sol";
/// @title MarketStore
/// @notice Persistent storage of supported markets
contract MarketStore is Roles {
// Market struct
struct Market {
string name; // Market's full name, e.g. Bitcoin / U.S. Dollar
string category; // crypto, fx, commodities, or indices
address chainlinkFeed; // Price feed contract address
uint256 maxLeverage; // No decimals
uint256 maxDeviation; // In bps, max price difference from oracle to chainlink price
uint256 fee; // In bps. 10 = 0.1%
uint256 liqThreshold; // In bps
uint256 fundingFactor; // Yearly funding rate if OI is completely skewed to one side. In bps.
uint256 minOrderAge; // Min order age before is can be executed. In seconds
uint256 pythMaxAge; // Max Pyth submitted price age, in seconds
bytes32 pythFeed; // Pyth price feed id
bool allowChainlinkExecution; // Allow anyone to execute orders with chainlink
bool isReduceOnly; // accepts only reduce only orders
uint256 minFactor; // funding rate min factor
uint256 sampleSize; // funding rate sample size
}
// Constants to limit gov power
uint256 public constant BPS_DIVIDER = 10000; // 100%
uint256 public constant MAX_FEE = 1000; // 10%
uint256 public constant MAX_DEVIATION = 1000; // 10%
uint256 public constant MAX_LIQTHRESHOLD = 10000; // 100%
uint256 public constant MAX_MIN_ORDER_AGE = 30;
uint256 public constant MIN_PYTH_MAX_AGE = 3;
// list of supported markets
string[] public marketList; // "ETH-USD", "BTC-USD", etc
mapping(string => Market) private markets;
function initialize(address rs) external initializer {
roleStore = RoleStore(rs);
_setGov(msg.sender);
}
/// @notice Set or update a market
/// @dev Only callable by governance
/// @param market String identifier, e.g. "ETH-USD"
/// @param marketInfo Market struct containing required market data
function set(
string calldata market,
Market memory marketInfo
) external onlyGov {
require(marketInfo.fee <= MAX_FEE, "!max-fee");
require(marketInfo.maxLeverage >= 1, "!max-leverage");
require(marketInfo.maxDeviation <= MAX_DEVIATION, "!max-deviation");
require(
marketInfo.liqThreshold <= MAX_LIQTHRESHOLD,
"!max-liqthreshold"
);
require(
marketInfo.minOrderAge <= MAX_MIN_ORDER_AGE,
"!max-minorderage"
);
require(marketInfo.pythMaxAge >= MIN_PYTH_MAX_AGE, "!min-pythmaxage");
require(
marketInfo.maxLeverage * marketInfo.fee <= BPS_DIVIDER,
"!max-leverage-fee"
);
markets[market] = marketInfo;
for (uint256 i = 0; i < marketList.length; i++) {
// check if market already exists, if yes return
if (
keccak256(abi.encodePacked(marketList[i])) ==
keccak256(abi.encodePacked(market))
) return;
}
marketList.push(market);
}
/// @notice Returns market struct of `market`
/// @param market String identifier, e.g. "ETH-USD"
function get(string calldata market) external view returns (Market memory) {
return markets[market];
}
/// @notice Returns market struct array of specified markets
/// @param _markets Array of market strings, e.g. ["ETH-USD", "BTC-USD"]
function getMany(
string[] calldata _markets
) external view returns (Market[] memory) {
uint256 length = _markets.length;
Market[] memory _marketInfos = new Market[](length);
for (uint256 i = 0; i < length; i++) {
_marketInfos[i] = markets[_markets[i]];
}
return _marketInfos;
}
/// @notice Returns market identifier at `index`
/// @param index index of marketList
function getMarketByIndex(
uint256 index
) external view returns (string memory) {
return marketList[index];
}
/// @notice Get a list of all supported markets
function getMarketList() external view returns (string[] memory) {
return marketList;
}
/// @notice Get number of supported markets
function getMarketCount() external view returns (uint256) {
return marketList.length;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import "./EnumerableSet.sol";
import "./Roles.sol";
/// @title PositionStore
/// @notice Persistent storage for Positions.sol
contract PositionStore is Roles {
// Libraries
using EnumerableSet for EnumerableSet.Bytes32Set;
// Position struct
struct Position {
address user; // User that submitted the position
address asset; // Asset address, e.g. address(0) for ETH
string market; // Market this position was submitted on
bool isLong; // Wether the position is long or short
uint256 size; // The position's size (margin * leverage)
uint256 margin; // Collateral tied to this position. In wei
int256 fundingTracker; // Market funding rate tracker
uint256 price; // The position's average execution price
uint256 timestamp; // Time at which the position was created
}
// Constants
uint256 public constant BPS_DIVIDER = 10000;
uint256 public constant MAX_KEEPER_FEE_SHARE = 2000; // 20%
// State variables
uint256 public removeMarginBuffer;
uint256 public keeperFeeShare;
// Mappings
mapping(address => mapping(string => uint256)) private OI; // open interest. market => asset => amount
mapping(address => mapping(string => uint256)) private OILong; // open interest. market => asset => amount
mapping(address => mapping(string => uint256)) private OIShort; // open interest. market => asset => amount]
mapping(bytes32 => Position) private positions; // key = asset,user,market
EnumerableSet.Bytes32Set private positionKeys; // [position keys..]
mapping(address => EnumerableSet.Bytes32Set) private positionKeysForUser; // user => [position keys..]
function initialize(address rs) external initializer {
roleStore = RoleStore(rs);
_setGov(msg.sender);
removeMarginBuffer = 1000;
keeperFeeShare = 500;
}
/// @notice Updates `removeMarginBuffer`
/// @dev Only callable by governance
/// @param bps new `removeMarginBuffer` in bps
function setRemoveMarginBuffer(uint256 bps) external onlyGov {
require(bps < BPS_DIVIDER, "!bps");
removeMarginBuffer = bps;
}
/// @notice Sets keeper fee share
/// @dev Only callable by governance
/// @param bps new `keeperFeeShare` in bps
function setKeeperFeeShare(uint256 bps) external onlyGov {
require(bps <= MAX_KEEPER_FEE_SHARE, "!keeper-fee-share");
keeperFeeShare = bps;
}
/// @notice Adds new position or updates exisiting one
/// @dev Only callable by other protocol contracts
/// @param position Position to add/update
function addOrUpdate(Position memory position) external onlyContract {
bytes32 key = _getPositionKey(
position.user,
position.asset,
position.market
);
positions[key] = position;
positionKeysForUser[position.user].add(key);
positionKeys.add(key);
}
/// @notice Removes position
/// @dev Only callable by other protocol contracts
function remove(
address user,
address asset,
string calldata market
) external onlyContract {
bytes32 key = _getPositionKey(user, asset, market);
positionKeysForUser[user].remove(key);
positionKeys.remove(key);
delete positions[key];
}
/// @notice Increments open interest
/// @dev Only callable by other protocol contracts
/// @dev Invoked by Positions.increasePosition
function incrementOI(
address asset,
string calldata market,
uint256 amount,
bool isLong
) external onlyContract {
OI[asset][market] += amount;
if (isLong) {
OILong[asset][market] += amount;
} else {
OIShort[asset][market] += amount;
}
}
/// @notice Decrements open interest
/// @dev Only callable by other protocol contracts
/// @dev Invoked whenever a position is closed or decreased
function decrementOI(
address asset,
string calldata market,
uint256 amount,
bool isLong
) external onlyContract {
OI[asset][market] = OI[asset][market] <= amount
? 0
: OI[asset][market] - amount;
if (isLong) {
OILong[asset][market] = OILong[asset][market] <= amount
? 0
: OILong[asset][market] - amount;
} else {
OIShort[asset][market] = OIShort[asset][market] <= amount
? 0
: OIShort[asset][market] - amount;
}
}
/// @notice Returns open interest of `asset` and `market`
function getOI(
address asset,
string calldata market
) external view returns (uint256) {
return OILong[asset][market] + OIShort[asset][market];
}
/// @notice Sets open interest of long positions
function setOILong(
address asset,
string calldata market,
uint256 amount
) external onlyGov {
OILong[asset][market] = amount;
}
/// @notice Sets open interest of short positions
function setOIShort(
address asset,
string calldata market,
uint256 amount
) external onlyGov {
OIShort[asset][market] = amount;
}
/// @notice Returns open interest of long positions
function getOILong(
address asset,
string calldata market
) external view returns (uint256) {
return OILong[asset][market];
}
/// @notice Returns open interest of short positions
function getOIShort(
address asset,
string calldata market
) external view returns (uint256) {
return OIShort[asset][market];
}
/// @notice Returns position of `user`
/// @param asset Base asset of position
/// @param market Market this position was submitted on
function getPosition(
address user,
address asset,
string memory market
) public view returns (Position memory) {
bytes32 key = _getPositionKey(user, asset, market);
return positions[key];
}
/// @notice Returns positions of `users`
/// @param assets Base assets of positions
/// @param markets Markets of positions
function getPositions(
address[] calldata users,
address[] calldata assets,
string[] calldata markets
) external view returns (Position[] memory) {
uint256 length = users.length;
Position[] memory _positions = new Position[](length);
for (uint256 i = 0; i < length; i++) {
_positions[i] = getPosition(users[i], assets[i], markets[i]);
}
return _positions;
}
/// @notice Returns positions
/// @param keys Position keys
function getPositions(
bytes32[] calldata keys
) external view returns (Position[] memory) {
uint256 length = keys.length;
Position[] memory _positions = new Position[](length);
for (uint256 i = 0; i < length; i++) {
_positions[i] = positions[keys[i]];
}
return _positions;
}
/// @notice Returns number of positions
function getPositionCount() external view returns (uint256) {
return positionKeys.length();
}
/// @notice Returns `length` amount of positions starting from `offset`
function getPositions(
uint256 length,
uint256 offset
) external view returns (Position[] memory) {
uint256 _length = positionKeys.length();
require(offset <= _length, "Offset out of bounds");
uint256 availableLength = _length - offset;
uint256 resultLength = length > availableLength
? availableLength
: length;
Position[] memory _positions = new Position[](resultLength);
for (uint256 i = 0; i < resultLength; i++) {
_positions[i] = positions[positionKeys.at(i + offset)];
}
return _positions;
}
/// @notice Returns all positions of `user`
function getUserPositions(
address user
) external view returns (Position[] memory) {
uint256 length = positionKeysForUser[user].length();
Position[] memory _positions = new Position[](length);
for (uint256 i = 0; i < length; i++) {
_positions[i] = positions[positionKeysForUser[user].at(i)];
}
return _positions;
}
/// @dev Returns position key by hashing (user, asset, market)
function _getPositionKey(
address user,
address asset,
string memory market
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(user, asset, market));
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import "./Governable.sol";
import "./RoleStore.sol";
/// @title Roles
/// @notice Role-based access control mechanism via onlyContract modifier
abstract contract Roles is Governable {
bytes32 internal constant CONTRACT_ROLE = keccak256("CONTRACT");
RoleStore public roleStore;
/// @dev Reverts if caller address has not the contract role
modifier onlyContract() {
require(roleStore.hasRole(msg.sender, CONTRACT_ROLE), "!contract-role");
_;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import {DataStore} from "./DataStore.sol";
import {PoolStore} from "./PoolStore.sol";
import {PositionStore} from "./PositionStore.sol";
import "./Roles.sol";
/// @title RiskStore
/// @notice Implementation of risk mitigation measures such as maximum open interest and maximum pool drawdown
contract RiskStore is Roles {
// Constants
uint256 public constant BPS_DIVIDER = 10000;
mapping(string => mapping(address => uint256)) private maxOI; // market => asset => amount
// Pool Risk Measures
uint256 public poolHourlyDecay; // bps = 4.16% hourly, disappears after 24 hours
mapping(address => int256) private poolProfitTracker; // asset => amount (amortized)
mapping(address => uint256) private poolProfitLimit; // asset => bps
mapping(address => uint256) private poolLastChecked; // asset => timestamp
// Contracts
DataStore public DS;
/// @dev Initialize DataStore address
function initialize(address rs, address ds) external initializer {
DS = DataStore(ds);
roleStore = RoleStore(rs);
_setGov(msg.sender);
poolHourlyDecay = 416;
}
// V2 Delta Long-Short
mapping(string => mapping(address => uint256)) private maxDelta; // market => asset => amount
// V3 Max Position Size
uint256 private maxPositionSizeFactor; // 10000 = 100%
// V4 ADL
mapping(address => uint256) private adlThreshold; // asset => threshold (bps)
/// @notice Set maximum delta between longs and shorts
/// @dev Only callable by governance
/// @param market Market to set, e.g. "ETH-USD"
/// @param asset Address of base asset, e.g. address(0) for ETH
/// @param amount Max delta to set
function setMaxDelta(
string calldata market,
address asset,
uint256 amount
) external onlyGov {
require(amount > 0, "!amount");
maxDelta[market][asset] = amount;
}
/// @notice Set maximum open interest
/// @notice Once current open interest exceeds this value, orders are no longer accepted
/// @dev Only callable by governance
/// @param market Market to set, e.g. "ETH-USD"
/// @param asset Address of base asset, e.g. address(0) for ETH
/// @param amount Max open interest to set
function setMaxOI(
string calldata market,
address asset,
uint256 amount
) external onlyGov {
require(amount > 0, "!amount");
maxOI[market][asset] = amount;
}
/// @notice Set maximum position size factor
/// @dev Only callable by governance
/// @param factor Max position size factor
function setMaxPositionSizeFactor(uint256 factor) external onlyGov {
maxPositionSizeFactor = factor;
}
/// @notice Set hourly pool decay
/// @dev Only callable by governance
/// @param bps Hourly pool decay in bps
function setPoolHourlyDecay(uint256 bps) external onlyGov {
require(bps < BPS_DIVIDER, "!bps");
poolHourlyDecay = bps;
}
/// @notice Set pool profit limit of `asset`
/// @dev Only callable by governance
/// @param asset Address of asset, e.g. address(0) for ETH
/// @param bps Pool profit limit in bps
function setPoolProfitLimit(address asset, uint256 bps) external onlyGov {
require(bps < BPS_DIVIDER, "!bps");
poolProfitLimit[asset] = bps;
}
/// @notice Set ADL threshold of `asset`
/// @dev Only callable by governance
/// @param asset Address of asset, e.g. address(0) for ETH
/// @param bps ADL threshold in bps
function setADLThreshold(address asset, uint256 bps) external onlyGov {
require(bps < BPS_DIVIDER, "!bps");
adlThreshold[asset] = bps;
}
/// @notice Measures the net loss of a pool over time
/// @notice Reverts if time-weighted drawdown is higher than the allowed profit limit
/// @dev Only callable by other protocol contracts
/// @dev Invoked by Positions.decreasePosition
function checkPoolDrawdown(
address asset,
int256 pnl
) external onlyContract {
// Get available amount of `asset` in the pool (pool balance + buffer balance)
uint256 poolAvailable = PoolStore(DS.getAddress("PoolStore"))
.getAvailable(asset);
// Get profit tracker, pnl > 0 means trader win
int256 profitTracker = getPoolProfitTracker(asset) + pnl;
// get profit limit of pool
uint256 profitLimit = poolProfitLimit[asset];
// update storage vars
poolProfitTracker[asset] = profitTracker;
poolLastChecked[asset] = block.timestamp;
// return if profit limit or profit tracker is zero / less than zero
if (profitLimit == 0 || profitTracker <= 0) return;
// revert if profitTracker > profitLimit * available funds
require(
uint256(profitTracker) <
(profitLimit * poolAvailable) / BPS_DIVIDER,
"!pool-risk"
);
}
/// @notice Checks if maximum delta and maximum open interest are reached
/// @param asset Address of base asset, e.g. address(0) for ETH
/// @param market Market to check, e.g. "ETH-USD"
/// @param size Size of the position
/// @param isLong Whether position is long (true) or short (false)
function checkMaxDelta(
address asset,
string calldata market,
uint256 size,
bool isLong
) external view {
// Get current OI values
uint256 oiLong = PositionStore(DS.getAddress("PositionStore"))
.getOILong(asset, market);
uint256 oiShort = PositionStore(DS.getAddress("PositionStore"))
.getOIShort(asset, market);
uint256 _maxDelta = maxDelta[market][asset];
if (_maxDelta > 0) {
if (isLong) {
// available long = maxDelta - oiLong + oiShort
int256 availableLong = int256(_maxDelta) -
int256(oiLong) +
int256(oiShort);
if (availableLong < 0) {
availableLong = 0;
}
require(size <= uint256(availableLong), "!max-delta");
} else {
// available short = maxDelta + oiLong - oiShort
int256 availableShort = int256(_maxDelta) +
int256(oiLong) -
int256(oiShort);
if (availableShort < 0) {
availableShort = 0;
}
require(size <= uint256(availableShort), "!max-delta");
}
}
// Check max OI
// uint256 openInterest = PositionStore(DS.getAddress('PositionStore')).getOI(asset, market);
uint256 openInterest = oiLong + oiShort;
uint256 _maxOI = maxOI[market][asset];
if (_maxOI > 0 && openInterest + size > _maxOI) revert("!max-oi");
}
/// @notice Checks if maximum open interest is reached
/// @param market Market to check, e.g. "ETH-USD"
/// @param asset Address of base asset, e.g. address(0) for ETH
function checkMaxOI(
address asset,
string calldata market,
uint256 size
) external view {
uint256 openInterest = PositionStore(DS.getAddress("PositionStore"))
.getOI(asset, market);
uint256 _maxOI = maxOI[market][asset];
if (_maxOI > 0 && openInterest + size > _maxOI) revert("!max-oi");
}
/// @notice Get maximum position size of `market`
/// @param market Market to check, e.g. "ETH-USD"
/// @param asset Address of base asset, e.g. address(0) for ETH
function getMaxPositionSize(
string calldata market,
address asset
) external view returns (uint256) {
return (maxOI[market][asset] * maxPositionSizeFactor) / 10000;
}
/// @notice Checks if maximum position size is reached
/// @param asset Address of base asset, e.g. address(0) for ETH
/// @param market Market to check, e.g. "ETH-USD"
/// @param sizeToAdd Size of the position to add
/// @param currentSize Current size of the position
/// @param isLongOrder Whether the order is long or short
/// @param isLongPosition Whether the position is long or short
function checkMaxPositionSize(
address asset,
string calldata market,
uint256 sizeToAdd,
uint256 currentSize,
bool isLongOrder,
bool isLongPosition
) external view {
if (maxPositionSizeFactor == 0) return;
uint256 maxPositionSize = (maxOI[market][asset] *
maxPositionSizeFactor) / 10000;
uint256 newSize;
if (currentSize == 0) {
newSize = sizeToAdd;
} else if (isLongOrder == isLongPosition) {
newSize = currentSize + sizeToAdd;
} else {
newSize = currentSize > sizeToAdd
? currentSize - sizeToAdd
: sizeToAdd - currentSize;
}
require(newSize <= maxPositionSize, "!max-position-size");
}
/// @notice Get maximum delta of `market`
/// @param market Market to check, e.g. "ETH-USD"
/// @param asset Address of base asset, e.g. address(0) for ETH
function getMaxDelta(
string calldata market,
address asset
) external view returns (uint256) {
return maxDelta[market][asset];
}
/// @notice Get maximum open interest of `market`
/// @param market Market to check, e.g. "ETH-USD"
/// @param asset Address of base asset, e.g. address(0) for ETH
function getMaxOI(
string calldata market,
address asset
) external view returns (uint256) {
return maxOI[market][asset];
}
/// @notice Returns pool profit tracker of `asset`
/// @dev Amortized every hour by 4.16% unless otherwise set
function getPoolProfitTracker(address asset) public view returns (int256) {
int256 profitTracker = poolProfitTracker[asset];
uint256 lastCheckedHourId = poolLastChecked[asset] / (1 hours);
uint256 currentHourId = block.timestamp / (1 hours);
if (currentHourId > lastCheckedHourId) {
// hours passed since last check
uint256 hoursPassed = currentHourId - lastCheckedHourId;
if (hoursPassed >= BPS_DIVIDER / poolHourlyDecay) {
profitTracker = 0;
} else {
// reduce profit tracker by `poolHourlyDecay` for every hour that passed since last check
for (uint256 i = 0; i < hoursPassed; i++) {
profitTracker =
(profitTracker *
(int256(BPS_DIVIDER) - int256(poolHourlyDecay))) /
int256(BPS_DIVIDER);
}
}
}
return profitTracker;
}
/// @notice Returns pool profit limit of `asset`
function getPoolProfitLimit(address asset) external view returns (uint256) {
return poolProfitLimit[asset];
}
/// @notice Get ADL threshold of `asset`
/// @param asset Address of asset, e.g. address(0) for ETH
function getADLThreshold(address asset) external view returns (uint256) {
return adlThreshold[asset];
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
/// @title Governable
/// @notice Basic access control mechanism, gov has access to certain functions
abstract contract Governable is Initializable {
address public gov;
event SetGov(address prevGov, address nextGov);
/// @dev Reverts if called by any account other than gov
modifier onlyGov() {
require(msg.sender == gov, "!gov");
_;
}
/// @notice Sets a new governance address
/// @dev Only callable by governance
function setGov(address _gov) external onlyGov {
_setGov(_gov);
}
/// @notice Sets a new governance address
/// @dev Internal function without access restriction
function _setGov(address _gov) internal {
require(_gov != address(0), "!zero-gov");
address prevGov = gov;
gov = _gov;
emit SetGov(prevGov, _gov);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity 0.8.17;
/**
* @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: BUSL-1.1
pragma solidity 0.8.17;
import "./EnumerableSet.sol";
import "./Governable.sol";
/**
* @title RoleStore
* @notice Role-based access control mechanism. Governance can grant and
* revoke roles dynamically via {grantRole} and {revokeRole}
*/
contract RoleStore is Governable {
// Libraries
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableSet for EnumerableSet.Bytes32Set;
event RoleGranted(
bytes32 indexed role,
address indexed account,
address indexed sender
);
event RoleRevoked(
bytes32 indexed role,
address indexed account,
address indexed sender
);
// Set of roles
EnumerableSet.Bytes32Set internal roles;
// Role -> address
mapping(bytes32 => EnumerableSet.AddressSet) internal roleMembers;
function initialize() external initializer {
_setGov(msg.sender);
}
/// @notice Grants `role` to `account`
/// @dev Only callable by governance
function grantRole(address account, bytes32 role) external onlyGov {
// add role if not already present
if (!roles.contains(role)) roles.add(role);
require(roleMembers[role].add(account));
emit RoleGranted(role, account, msg.sender);
}
/// @notice Revokes `role` from `account`
/// @dev Only callable by governance
function revokeRole(address account, bytes32 role) external onlyGov {
require(roleMembers[role].remove(account));
emit RoleRevoked(role, account, msg.sender);
// Remove role if it has no longer any members
if (roleMembers[role].length() == 0) {
roles.remove(role);
}
}
/// @notice Returns `true` if `account` has been granted `role`
function hasRole(
address account,
bytes32 role
) external view returns (bool) {
return roleMembers[role].contains(account);
}
/// @notice Returns number of roles
function getRoleCount() external view returns (uint256) {
return roles.length();
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import "./Roles.sol";
/// @title PoolStore
/// @notice Persistent storage for Pool.sol
contract PoolStore is Roles {
// Constants
uint256 public constant BPS_DIVIDER = 10000;
// State variables
uint256 public feeShare;
uint256 public depositId;
uint256[] public lockupPeriods;
mapping(address => uint256) private clpSupply; // asset => clp supply
mapping(address => uint256) private balances; // asset => balance
mapping(address => mapping(address => uint256)) private userClpBalances; // asset => account => clp amount
mapping(address => mapping(address => uint256[]))
private depositIdsForAccount; // account => asset => [depositIds..]
mapping(uint256 => uint256) private depositClpBalances; // depositId => clp balance
mapping(uint256 => uint256) private depositTimestamps; // depositId => timestamp
mapping(address => uint256) private bufferBalances; // asset => balance
mapping(address => uint256) private lastPaid; // asset => timestamp
mapping(address => uint256) private bufferPayoutPeriods; // asset => period
// Custom fees (deposit/withdraw) configuration
mapping(address => bool) private customWithdrawalTaxesActive; // asset => is custom withdrawal tax active
mapping(address => uint256) private withdrawalTaxes; // asset => custom withdrawal tax bps
mapping(address => bool) private customDepositTaxesUnlocked; // asset => is custom deposit tax unlocked
mapping(address => bool) private customDepositTaxesLocked; // asset => is custom deposit tax locked
mapping(address => uint256) private depositTaxesUnlocked; // asset => custom deposit tax bps for unlocked deposits
mapping(address => uint256) private depositTaxLocked; // asset => custom deposit tax bps for locked deposits
function initialize(
address rs,
uint256[] calldata periods
) external initializer {
roleStore = RoleStore(rs);
_setGov(msg.sender);
feeShare = 5000;
depositId = 0;
for (uint256 i = 0; i < periods.length; i++) {
lockupPeriods.push(periods[i]);
}
}
/// @notice Set pool fee
/// @dev Only callable by governance
/// @param bps fee share in bps
function setFeeShare(uint256 bps) external onlyGov {
require(bps < BPS_DIVIDER, "!bps");
feeShare = bps;
}
/// @notice Set lockup periods
/// @dev Only callable by governance
/// @param periods Lockup periods in seconds (can include 0 for no lockup)
function setLockupPeriods(uint256[] calldata periods) external onlyGov {
require(periods.length > 0, "!length");
delete lockupPeriods;
for (uint256 i = 0; i < periods.length; i++) {
lockupPeriods.push(periods[i]);
}
}
/// @notice Set buffer payout periods
/// @dev Only callable by governance
/// @param assets Assets
/// @param periods Buffer payout periods in seconds
function setBufferPayoutPeriods(
address[] calldata assets,
uint256[] calldata periods
) external onlyGov {
require(periods.length == assets.length, "!length");
for (uint256 i = 0; i < assets.length; i++) {
require(periods[i] > 0, "!period");
bufferPayoutPeriods[assets[i]] = periods[i];
}
}
/// @notice Returns buffer payout period for an asset
/// @param asset Asset
/// @return Buffer payout period in seconds
function getBufferPayoutPeriod(
address asset
) external view returns (uint256) {
return bufferPayoutPeriods[asset];
}
/// @notice Enable/disable custom deposit tax for an asset
/// @param _isActive Whether custom deposit tax is active
/// @param asset Asset address
function setCustomDepositTaxesLocked(
bool _isActive,
address asset
) external onlyGov {
customDepositTaxesLocked[asset] = _isActive;
}
/// @notice Set custom deposit tax (in bps) for an asset
/// @param asset Asset address
/// @param tax Custom deposit tax in bps
function setDepositTaxLocked(address asset, uint256 tax) external onlyGov {
require(tax < BPS_DIVIDER, "!tax");
depositTaxLocked[asset] = tax;
}
/// @notice Enable/disable custom deposit tax for an asset
/// @param _isActive Whether custom deposit tax is active
/// @param asset Asset address
function setCustomDepositTaxesUnlocked(
bool _isActive,
address asset
) external onlyGov {
customDepositTaxesUnlocked[asset] = _isActive;
}
/// @notice Set custom deposit tax (in bps) for an asset
/// @param asset Asset address
/// @param tax Custom deposit tax in bps
function setDepositTaxUnlocked(
address asset,
uint256 tax
) external onlyGov {
require(tax < BPS_DIVIDER, "!tax");
depositTaxesUnlocked[asset] = tax;
}
/// @notice Returns whether custom deposit tax (locked) is active for an asset
/// @param asset Asset address
function isCustomDepositTaxesLockedActive(
address asset
) external view returns (bool) {
return customDepositTaxesLocked[asset];
}
/// @notice Returns whether custom deposit tax (unlocked) is active for an asset
/// @param asset Asset address
function isCustomDepositTaxesUnlockedActive(
address asset
) external view returns (bool) {
return customDepositTaxesUnlocked[asset];
}
/// @notice Returns custom deposit tax (in bps) for an asset
/// @param asset Asset address
function getDepositTaxLocked(
address asset
) external view returns (uint256) {
return depositTaxLocked[asset];
}
/// @notice Returns custom deposit tax (in bps) for an asset
/// @param asset Asset address
function getDepositTaxUnlocked(
address asset
) external view returns (uint256) {
return depositTaxesUnlocked[asset];
}
/// @notice Enable/disable custom withdrawal tax for an asset
/// @param _isActive Whether custom withdrawal tax is active
/// @param asset Asset address
function setCustomWithdrawalTaxes(
bool _isActive,
address asset
) external onlyGov {
customWithdrawalTaxesActive[asset] = _isActive;
}
/// @notice Set custom withdrawal tax (in bps) for an asset
/// @param asset Asset address
/// @param tax Custom withdrawal tax in bps
function setWithdrawalTax(address asset, uint256 tax) external onlyGov {
withdrawalTaxes[asset] = tax;
}
/// @notice Returns whether custom withdrawal tax is active for an asset
/// @param asset Asset address
function isCustomWithdrawalTaxesActive(
address asset
) external view returns (bool) {
return customWithdrawalTaxesActive[asset];
}
/// @notice Returns custom withdrawal tax (bps) for an asset
/// @param asset Asset address
function getWithdrawalTax(address asset) external view returns (uint256) {
return withdrawalTaxes[asset];
}
/// @notice Increments pool balance
/// @dev Only callable by other protocol contracts
function incrementBalance(
address asset,
uint256 amount
) external onlyContract {
balances[asset] += amount;
}
/// @notice Decrements pool balance
/// @dev Only callable by other protocol contracts
function decrementBalance(
address asset,
uint256 amount
) external onlyContract {
balances[asset] = balances[asset] <= amount
? 0
: balances[asset] - amount;
}
/// @notice Increments buffer balance
/// @dev Only callable by other protocol contracts
function incrementBufferBalance(
address asset,
uint256 amount
) external onlyContract {
bufferBalances[asset] += amount;
}
/// @notice Decrements buffer balance
/// @dev Only callable by other protocol contracts
function decrementBufferBalance(
address asset,
uint256 amount
) external onlyContract {
bufferBalances[asset] = bufferBalances[asset] <= amount
? 0
: bufferBalances[asset] - amount;
}
/// @notice Updates `lastPaid`
/// @dev Only callable by other protocol contracts
function setLastPaid(
address asset,
uint256 timestamp
) external onlyContract {
lastPaid[asset] = timestamp;
}
/// @notice Increments `clpSupply`, `userClpBalances` and `depositIdsForAccount`
/// @dev Only callable by other protocol contracts
/// @param asset Asset
/// @param user User
/// @param amount Amount
/// @param lockupPeriodIndex Lockup period index
/// @return depositId Deposit ID
/// @return lockupPeriod Lockup period
function incrementUserClpBalance(
address asset,
address user,
uint256 amount,
uint256 lockupPeriodIndex
) external onlyContract returns (uint256, uint256) {
require(amount > 0, "!amount");
require(
lockupPeriodIndex < lockupPeriods.length,
"!lockup-period-index"
);
clpSupply[asset] += amount;
userClpBalances[asset][user] += amount;
uint256 lockupPeriod = lockupPeriods[lockupPeriodIndex];
uint256 currentDepositId = depositId;
depositIdsForAccount[user][asset].push(currentDepositId);
depositClpBalances[currentDepositId] = amount;
if (lockupPeriod > 0) {
depositTimestamps[currentDepositId] =
block.timestamp +
lockupPeriod;
} else {
depositTimestamps[currentDepositId] = 0;
}
unchecked {
depositId++;
}
return (currentDepositId, lockupPeriod);
}
/// @notice Decrements `clpSupply` and `userClpBalances`
/// @dev Only callable by other protocol contracts
/// @param asset Asset
/// @param user User
/// @param amount Amount
/// @return depositIds Array of deposit IDs
/// @return amounts Array of deposit amounts
function decrementUserClpBalance(
address asset,
address user,
uint256 amount
) external onlyContract returns (uint256[] memory, uint256[] memory) {
require(amount > 0, "!amount");
clpSupply[asset] = clpSupply[asset] <= amount
? 0
: clpSupply[asset] - amount;
userClpBalances[asset][user] = userClpBalances[asset][user] <= amount
? 0
: userClpBalances[asset][user] - amount;
uint256[] storage userDeposits = depositIdsForAccount[user][asset];
uint256 len = userDeposits.length;
uint256[] memory depositIds = new uint256[](len);
uint256[] memory amounts = new uint256[](len);
uint256 remainingAmount = amount;
uint256 writeIndex = 0;
uint256 upd = 0;
for (uint256 i = 0; i < len; i++) {
uint256 dId = userDeposits[i];
uint256 depositBalance = depositClpBalances[dId];
uint256 depositTimestamp = depositTimestamps[dId];
if (depositBalance > 0) {
bool isUnlocked = block.timestamp >= depositTimestamp;
if (isUnlocked && remainingAmount > 0) {
if (depositBalance > remainingAmount) {
uint256 newBal = depositBalance - remainingAmount;
depositClpBalances[dId] = newBal;
remainingAmount = 0;
if (writeIndex != i) {
userDeposits[writeIndex] = dId;
}
writeIndex++;
depositIds[upd] = dId;
amounts[upd] = newBal;
upd++;
} else {
remainingAmount -= depositBalance;
depositIds[upd] = dId;
amounts[upd] = 0;
delete depositClpBalances[dId];
delete depositTimestamps[dId];
upd++;
}
} else {
if (writeIndex != i) {
userDeposits[writeIndex] = dId;
}
writeIndex++;
}
}
}
while (userDeposits.length > writeIndex) {
userDeposits.pop();
}
require(remainingAmount == 0, "!locked-amount");
assembly {
mstore(depositIds, upd)
mstore(amounts, upd)
}
return (depositIds, amounts);
}
/// @notice Reset lockup timestamp for a deposit
/// @dev Only callable by governance
/// @param _depositId Deposit ID
function resetLockupTimestamp(uint256 _depositId) external onlyGov {
depositTimestamps[_depositId] = 0;
}
/// @notice Returns the sum of buffer and pool balance of `asset`
/// @param asset Asset address
/// @return Available balance
function getAvailable(address asset) external view returns (uint256) {
return balances[asset] + bufferBalances[asset];
}
/// @notice Returns amount of `asset` in pool
/// @param asset Asset address
/// @return Balance
function getBalance(address asset) external view returns (uint256) {
return balances[asset];
}
/// @notice Returns amount of `asset` in buffer
/// @param asset Asset address
/// @return Buffer balance
function getBufferBalance(address asset) external view returns (uint256) {
return bufferBalances[asset];
}
/// @notice Returns pool balances of `_assets`
/// @param _assets Assets
/// @return Balances
function getBalances(
address[] calldata _assets
) external view returns (uint256[] memory) {
uint256 length = _assets.length;
uint256[] memory _balances = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
_balances[i] = balances[_assets[i]];
}
return _balances;
}
/// @notice Returns buffer balances of `_assets`
/// @param _assets Assets
/// @return Balances
function getBufferBalances(
address[] calldata _assets
) external view returns (uint256[] memory) {
uint256 length = _assets.length;
uint256[] memory _balances = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
_balances[i] = bufferBalances[_assets[i]];
}
return _balances;
}
/// @notice Returns last time pool was paid
/// @param asset Asset address
/// @return Last paid timestamp
function getLastPaid(address asset) external view returns (uint256) {
return lastPaid[asset];
}
/// @notice Returns `asset` balance of `account`
/// @param asset Asset address
/// @param account User address
/// @return Balance
function getUserBalance(
address asset,
address account
) public view returns (uint256) {
if (clpSupply[asset] == 0) return 0;
return
(userClpBalances[asset][account] * balances[asset]) /
clpSupply[asset];
}
/// @notice Returns `_assets` balance of `account`
/// @param _assets Assets
/// @param account User address
/// @return Balances
function getUserBalances(
address[] calldata _assets,
address account
) external view returns (uint256[] memory) {
uint256 length = _assets.length;
uint256[] memory _balances = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
_balances[i] = getUserBalance(_assets[i], account);
}
return _balances;
}
/// @notice Returns `asset` balances of multiple `accounts`
/// @param asset Asset address
/// @param accounts User addresses
/// @return Balances
function getUsersBalances(
address asset,
address[] calldata accounts
) external view returns (uint256[] memory) {
uint256[] memory _balances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; i++) {
_balances[i] = getUserBalance(asset, accounts[i]);
}
return _balances;
}
/// @notice Returns total amount of CLP for `asset`
/// @param asset Asset address
/// @return CLP supply
function getClpSupply(address asset) public view returns (uint256) {
return clpSupply[asset];
}
/// @notice Returns amount of CLP of `account` for `asset`
/// @param asset Asset address
/// @param account User address
/// @return CLP amount
function getUserClpBalance(
address asset,
address account
) public view returns (uint256) {
return userClpBalances[asset][account];
}
/// @notice Returns CLP balances of `accounts` for `asset`
/// @param asset Asset address
/// @param accounts User addresses
/// @return clpAmounts CLP amounts
function getUsersClpBalances(
address asset,
address[] calldata accounts
) external view returns (uint256[] memory clpAmounts) {
uint256 len = accounts.length;
clpAmounts = new uint256[](len);
for (uint256 i = 0; i < len; i++) {
clpAmounts[i] = userClpBalances[asset][accounts[i]];
}
return clpAmounts;
}
/// @notice Returns deposit IDs for a user and asset
/// @param user User address
/// @param asset Asset address
/// @return Deposit IDs
function getDepositIdsForAccount(
address user,
address asset
) external view returns (uint256[] memory) {
return depositIdsForAccount[user][asset];
}
/// @notice Returns deposit info for a specific deposit ID
/// @param dId Deposit ID
/// @return balance Deposit balance
/// @return timestamp Deposit timestamp
function getDepositInfo(
uint256 dId
) external view returns (uint256 balance, uint256 timestamp) {
return (depositClpBalances[dId], depositTimestamps[dId]);
}
/// @notice Returns the amount of unlocked CLP for a user
/// @param asset Asset address
/// @param account User address
/// @return Unlocked CLP amount
function getUnlockedClpBalance(
address asset,
address account
) external view returns (uint256) {
uint256[] memory userDeposits = depositIdsForAccount[account][asset];
uint256 unlockedAmount = 0;
for (uint256 i = 0; i < userDeposits.length; i++) {
uint256 dId = userDeposits[i];
uint256 depositBalance = depositClpBalances[dId];
uint256 unlockTimestamp = depositTimestamps[dId];
if (depositBalance > 0 && block.timestamp >= unlockTimestamp) {
unlockedAmount += depositBalance;
}
}
return unlockedAmount;
}
/// @notice Returns the amount of locked CLP for a user
/// @param asset Asset address
/// @param account User address
/// @return Locked CLP amount
function getLockedClpBalance(
address asset,
address account
) external view returns (uint256) {
uint256[] memory userDeposits = depositIdsForAccount[account][asset];
uint256 lockedAmount = 0;
for (uint256 i = 0; i < userDeposits.length; i++) {
uint256 dId = userDeposits[i];
uint256 depositBalance = depositClpBalances[dId];
uint256 unlockTimestamp = depositTimestamps[dId];
if (depositBalance > 0 && block.timestamp < unlockTimestamp) {
lockedAmount += depositBalance;
}
}
return lockedAmount;
}
// @notice Returns lockup period for a given index
/// @param index Lockup period index
/// @return Lockup period in seconds
function getLockupPeriod(uint256 index) external view returns (uint256) {
return lockupPeriods[index];
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/Address.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Internal function that returns the initialized version. Returns `_initialized`
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Internal function that returns the initialized version. Returns `_initializing`
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// 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);
}
}
}{
"remappings": [
"@openzeppelin/=lib/openzeppelin-contracts/",
"chainlink/=node_modules/@chainlink/",
"pyth-sdk-solidity/=node_modules/@pythnetwork/pyth-sdk-solidity/",
"@uniswap/v2-periphery/=node_modules/@uniswap/v2-periphery/",
"@uniswap/v2-core/=node_modules/@uniswap/v2-core/",
"ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs"
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "london",
"viaIR": true
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"string","name":"market","type":"string"},{"indexed":false,"internalType":"uint256","name":"OILong","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"OIShort","type":"uint256"},{"indexed":false,"internalType":"int256","name":"accruedFundingV1","type":"int256"},{"indexed":false,"internalType":"int256","name":"accruedFundingV2","type":"int256"},{"indexed":false,"internalType":"int256","name":"onePeriodFundingIncrement","type":"int256"},{"indexed":false,"internalType":"int256","name":"fundingTracker","type":"int256"}],"name":"FundingUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"prevGov","type":"address"},{"indexed":false,"internalType":"address","name":"nextGov","type":"address"}],"name":"SetGov","type":"event"},{"inputs":[],"name":"DS","outputs":[{"internalType":"contract DataStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fundingStore","outputs":[{"internalType":"contract FundingStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"string","name":"market","type":"string"},{"internalType":"uint256","name":"intervals","type":"uint256"}],"name":"getAccruedFunding","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"string","name":"market","type":"string"},{"internalType":"uint256","name":"intervals","type":"uint256"}],"name":"getAccruedFundingV2","outputs":[{"internalType":"int256","name":"","type":"int256"},{"internalType":"int256","name":"","type":"int256"},{"internalType":"int256","name":"","type":"int256"},{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"string","name":"market","type":"string"}],"name":"getRealTimeFundingTracker","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"string[]","name":"markets","type":"string[]"}],"name":"getRealTimeFundingTrackers","outputs":[{"internalType":"int256[]","name":"","type":"int256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gov","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rs","type":"address"},{"internalType":"address","name":"ds","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"link","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"marketStore","outputs":[{"internalType":"contract MarketStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionStore","outputs":[{"internalType":"contract PositionStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"riskStore","outputs":[{"internalType":"contract RiskStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roleStore","outputs":[{"internalType":"contract RoleStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_gov","type":"address"}],"name":"setGov","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"string","name":"market","type":"string"}],"name":"updateFundingTracker","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
6080806040523461001657612523908161001c8239f35b600080fdfe60a060408181526004918236101561001657600080fd5b600092833560e01c91826312d43a51146108fe575081631c4695f4146106795781633157d39d146106505781634242bac014610627578163485cc955146104cb5781634a4a7b04146104a25781635f7ddaaa146104795781635ff21387146103775781636de8ef6b1461035b5781638265d95b146101e4578163861b6a90146101bb5781639d8e217714610198578163b8d2c6931461016c57508063cfad57a21461012d578063d8a162d2146100fa5763f6126207146100d557600080fd5b346100f6576020906100ef6100e936610940565b91612246565b9051908152f35b5080fd5b50346100f65760809061011561010f36610a3c565b91611f37565b92939091815194855260208501528301526060820152f35b82346101695760203660031901126101695761016661014a610925565b61016160018060a01b03845460101c163314610a94565b61244a565b80f35b80fd5b9050346101945782600319360112610194575490516001600160a01b03909116815260209150f35b8280fd5b5050346100f657816003193601126100f65760209051670de0b6b3a76400008152f35b5050346100f657816003193601126100f65760065490516001600160a01b039091168152602090f35b905082346101695782600319360112610169576101ff610925565b9167ffffffffffffffff9160248035848111610194573660238201121561019457808401359385851161035757600591368487851b830101116103535761024b86939998979596612432565b94610258895196876109c7565b83865261026484612432565b60209a878c019991601f1901368b37368490036042190190895b8781106102c5578d8d8d8d8d83519485948186019282875251809352850193925b8281106102ae57505050500390f35b83518552869550938101939281019260010161029f565b80829e9b9a9c9d9e1b8981880101358481121561034f5787018a8101359087821161034b57604401813603811361034b57906103019187612246565b908d51831015610339578d018c01526000198114610327576001019c9b9a98999c61027e565b634e487b7160e01b8a5260118752888afd5b634e487b7160e01b8c52603289528a8cfd5b8c80fd5b8b80fd5b8480fd5b8380fd5b5050346100f6576020906100ef61037136610a3c565b91611684565b839150346100f65761038836610940565b600154865163ac4ab3fb60e01b815233818701527fa66b7a3e6b19d24ccb6f717fc232a1bb0278a7f83f8e2211835fc4ed0fe69f19602482015291949293929190602090829060449082906001600160a01b03165afa90811561046f578691610432575b50156103fe5750610166939450610b7b565b606490602087519162461bcd60e51b8352820152600e60248201526d21636f6e74726163742d726f6c6560901b6044820152fd5b90506020813d8211610467575b8161044c602093836109c7565b810103126104635761045d90610ada565b876103ec565b8580fd5b3d915061043f565b87513d88823e3d90fd5b5050346100f657816003193601126100f65760035490516001600160a01b039091168152602090f35b5050346100f657816003193601126100f65760015490516001600160a01b039091168152602090f35b9050346101945781600319360112610194576104e5610925565b6001600160a01b03602435818116929083900361046357855460ff8160081c16159485809661061a575b8015610603575b156105a9575060ff198116600117875584610598575b506bffffffffffffffffffffffff60a01b928360025416176002551690600154161760015561055a3361244a565b610562575080f35b60207f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989161ff001984541684555160018152a180f35b61ffff19166101011786553861052c565b608490602088519162461bcd60e51b8352820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152fd5b50303b1580156105165750600160ff831614610516565b50600160ff83161061050f565b5050346100f657816003193601126100f65760025490516001600160a01b039091168152602090f35b5050346100f657816003193601126100f65760055490516001600160a01b039091168152602090f35b9190503461019457826003193601126101945760018060a01b03906106a582855460101c163314610a94565b816002541681519363bf40fac160e01b908186526020928382880152600c60248801526b46756e64696e6753746f726560a01b60448801528387606481845afa9687156108f45788976108b9575b50856bffffffffffffffffffffffff60a01b971687600354161760035584518381528483820152600b60248201526a4d61726b657453746f726560a81b60448201528481606481855afa908115610877579087918a91610881575b50168783541617825584518381528483820152600d60248201526c506f736974696f6e53746f726560981b60448201528481606481855afa908115610877578593929188918b91610830575b5091849591606493168a600554161760055587519687948593845283015260096024830152685269736b53746f726560b81b60448301525afa928315610827575085926107f1575b50501690600654161760065580f35b90809250813d8311610820575b61080881836109c7565b810103126103575761081990610ac6565b38806107e2565b503d6107fe565b513d87823e3d90fd5b92948092508391503d8311610870575b61084a81836109c7565b8101031261086c578493849388610862606494610ac6565b919350919561079a565b8880fd5b503d610840565b86513d8b823e3d90fd5b809250868092503d83116108b2575b61089a81836109c7565b8101031261086c576108ac8791610ac6565b3861074e565b503d610890565b9096508381813d83116108ed575b6108d181836109c7565b810103126108e9576108e290610ac6565b95386106f3565b8780fd5b503d6108c7565b85513d8a823e3d90fd5b8490346100f657816003193601126100f657905460101c6001600160a01b03168152602090f35b600435906001600160a01b038216820361093b57565b600080fd5b604060031982011261093b576004356001600160a01b038116810361093b579160243567ffffffffffffffff9283821161093b578060238301121561093b57816004013593841161093b576024848301011161093b576024019190565b67ffffffffffffffff81116109b157604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff8211176109b157604052565b67ffffffffffffffff81116109b157601f01601f191660200190565b929192610a11826109e9565b91610a1f60405193846109c7565b82948184528183011161093b578281602093846000960137010152565b90606060031983011261093b576004356001600160a01b038116810361093b57916024359067ffffffffffffffff821161093b578060238301121561093b57816024610a8d93600401359101610a05565b9060443590565b15610a9b57565b606460405162461bcd60e51b815260206004820152600460248201526310b3b7bb60e11b6044820152fd5b51906001600160a01b038216820361093b57565b5190811515820361093b57565b908060209392818452848401376000828201840152601f01601f1916010190565b6001600160a01b039091168152604060208201819052610b2a93910191610ae7565b90565b94939291604092610b539260018060a01b03168752606060208801526060870191610ae7565b930152565b91908201809211610b6557565b634e487b7160e01b600052601160045260246000fd5b6003805460408051630cf6928760e41b815290969594926001600160a01b039260009290841660208280610bb48b8a8c60048501610b08565b0381845afa9182156111c7578492611193575b50811561113b575083825416908951634c24f20960e11b8152602081600481865afa8015610f8c578590611107575b610c0291504292610b58565b116110fc57610c1b610c15368988610a05565b87611a0c565b91909492938415610fcc575086835416803b15610fc8578a87918a8f8d610c588692519788968795869463160ad65760e11b865260048601610b2d565b03925af18015610fbe57908691610faa575b505085825416803b156104635789869189838f610c9d8e915197889687958694635d4944eb60e11b865260048601610b2d565b03925af18015610f8c57908591610f96575b505084815416803b15610353578489849289838f610ce38e9151978896879586946308c6451f60e21b865260048601610b2d565b03925af18015610f8c57908591610f78575b505084815416803b15610353578a51608081815263a22966cd60e01b90915251859181610d28428d8c8e60048601610b2d565b039083608051915af1998a15610f6f5788999a98969798610f4c575b85600554166020898b610d6a85519e8f9384936301d25add60e21b855260048501610b08565b0381845afa9a8b15610f4257869b610f0b575b5090602088610da4938b8d8551968794859384936312e1541b60e31b855260048501610b08565b03915afa918215610f0157908695949392918b9792610eca575b5087610dcb368b8d610a05565b610dd59089611432565b935416898b83519d8e92839263183bb37960e01b84526004840192610df993610b08565b03815a93602094fa958615610ebf5795610e6b575b7f7b07d770ce1ec5e65e87ba3075e60ecec1e641c1ef713ebdbee0c408a6448ee09a50610e4781519a8b9a60e08c5260e08c0191610ae7565b9b60208a01528801526060870152608086015260a085015260c084015216930390a2565b945060208a3d602011610eb7575b81610e86602093836109c7565b8101031261093b577f7b07d770ce1ec5e65e87ba3075e60ecec1e641c1ef713ebdbee0c408a6448ee0995194610e0e565b3d9150610e79565b9051903d90823e3d90fd5b965090506020863d602011610ef9575b81610ee7602093836109c7565b8101031261093b578995519038610dbe565b3d9150610eda565b81513d88823e3d90fd5b91909a506020823d602011610f3a575b81610f28602093836109c7565b8101031261093b579051996020610d7d565b3d9150610f1b565b82513d88823e3d90fd5b9091929380959650610f5f60805161099d565b6103535790889594939291610d44565b513d85823e3d90fd5b610f819061099d565b610357578338610cf5565b8b513d87823e3d90fd5b610f9f9061099d565b610357578338610caf565b610fb39061099d565b610353578438610c6a565b8c513d88823e3d90fd5b8680fd5b919350919350809a989594999a3b156110f857858a9188838b6110048e519788968795869463160ad65760e11b865260048601610b2d565b03925af180156110ee579089916110da575b505082825416803b1561086c5784899187838a6110488d5197889687958694635d4944eb60e11b865260048601610b2d565b03925af180156110d0579088916110bc575b5050541691823b15610463579184939186809461108e97519788958694859363a22966cd60e01b8552429260048601610b2d565b03925af19081156110b357506110a2575050565b6110ac829161099d565b6101695750565b513d84823e3d90fd5b6110c59061099d565b610fc857863861105a565b87513d8a823e3d90fd5b6110e39061099d565b6108e9578738611016565b88513d8b823e3d90fd5b8980fd5b505050505050509050565b506020813d602011611133575b81611121602093836109c7565b8101031261093b57610c029051610bf6565b3d9150611114565b949297989693505050823b15610463579184939186809461117397519788958694859363a22966cd60e01b8552429260048601610b2d565b03925af19081156110b35750611187575050565b6111909061099d565b50565b9091506020813d6020116111bf575b816111af602093836109c7565b8101031261035757519038610bc7565b3d91506111a2565b8a513d86823e3d90fd5b60005b8381106111e45750506000910152565b81810151838201526020016111d4565b9060209161120d815180928185528580860191016111d1565b601f01601f1916010190565b6001600160a01b039091168152604060208201819052610b2a929101906111f4565b91908203918211610b6557565b8115611252570490565b634e487b7160e01b600052601260045260246000fd5b81601f8201121561093b57805161127e816109e9565b9261128c60405194856109c7565b8184526020828401011161093b57610b2a91602080850191016111d1565b60208183031261093b57805167ffffffffffffffff9182821161093b5701906101e092838382031261093b57604051938401848110838211176109b157604052825182811161093b57816112ff918501611268565b8452602083015191821161093b57611318918301611268565b602083015261132960408201610ac6565b6040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151908301526101208082015190830152610140808201519083015261016061138f818301610ada565b908301526101806113a1818301610ada565b908301526101a080820151908301526101c0809101519082015290565b81810292918115918404141715610b6557565b60008190039190600160ff1b8114600116610b6557600019830503610b6557565b90670de0b6b3a764000091828102928184051490151715610b6557565b818102929160008212600160ff1b821416610b65578184051490151715610b6557565b600554604080516301d25add60e21b81526001600160a01b039283169594909360049392919060209081878061146b86858b8401611219565b03818c5afa9687156116795760009761164a575b50826114a397989983928651809a819482936312e1541b60e31b84528c8401611219565b03915afa95861561163f57600096611610575b50851580611608575b6115fc5761150291600091888811156115ec576114dc898961123b565b955b87541690855180958194829363349f642f60e11b84528b84015260248301906111f4565b03915afa9182156115e257509060e0916000916115c1575b500151670de0b6b3a764000090808202918204036115ac579061153c916113be565b80800460011481151715611597576115548385610b58565b91612238928084029384040361158257509061156f91611248565b9111156115795790565b610b2a906113d1565b601190634e487b7160e01b6000525260246000fd5b601182634e487b7160e01b6000525260246000fd5b601183634e487b7160e01b6000525260246000fd5b6115dc913d8091833e6115d481836109c7565b8101906112aa565b3861151a565b513d6000823e3d90fd5b6115f6888a61123b565b956114de565b50505050505050600090565b5086156114bf565b90958682813d8311611638575b61162781836109c7565b8101031261016957505194386114b6565b503d61161d565b83513d6000823e3d90fd5b90968282813d8311611672575b61166181836109c7565b81010312610169575051958261147f565b503d611657565b84513d6000823e3d90fd5b9291928315611863575b831561185b5760018060a01b039384600554169460408051946301d25add60e21b865260206004958188806116c686858c8401611219565b03818d5afa9788156116795760009861182c575b50826116fe98999a83928651809b819482936312e1541b60e31b84528d8401611219565b03915afa96871561163f576000976117fd575b508615806117f5575b6117e85761175d91600091898911156117d8576117378a8a61123b565b955b88541690855180958194829363349f642f60e11b84528c84015260248301906111f4565b03915afa9182156115e257509060e0916000916117bf575b500151670de0b6b3a764000090808202918204036117aa576117a0929161179b916113be565b6113be565b6115548385610b58565b601184634e487b7160e01b6000525260246000fd5b6117d2913d8091833e6115d481836109c7565b38611775565b6117e2898b61123b565b95611739565b5050505050505050600090565b50871561171a565b90968782813d8311611825575b61181481836109c7565b810103126101695750519538611711565b503d61180a565b90978282813d8311611854575b61184381836109c7565b8101031261016957505196826116da565b503d611839565b506000925050565b600354604051630cf6928760e41b81529194506001600160a01b031690602090818180611894878a60048401611219565b0381865afa801561191c578291600091611928575b50906118b76004924261123b565b9360405192838092634c24f20960e11b82525afa91821561191c576000926118eb575b50506118e591611248565b9261168e565b81819392933d8311611915575b61190281836109c7565b810103126101695750516118e5386118da565b503d6118f8565b6040513d6000823e3d90fd5b9182813d8311611951575b61193d81836109c7565b8101031261016957505181906118b76118a9565b503d611933565b90670de0b6b3a764000060008382039312818412811691841390151617610b6557565b81810392916000138015828513169184121617610b6557565b801561125257671bc16d674ec800000590565b811561125257600160ff1b8114600019831416610b65570590565b600160ff1b8114610b655760000390565b9060018201916000600184129112908015821691151617610b6557565b91909160008382019384129112908015821691151617610b6557565b60035460408051630cf6928760e41b815293946001600160a01b03928316949092602092600492848180611a438c8b898401611219565b03818b5afa8015611f2c57600090611efd575b611a6191504261123b565b8151634c24f20960e11b8152858186818c5afa90811561163f57600091611ece575b50611a8d91611248565b938415611d7f57611abe96979883600554169982828c8c8751809d819482936301d25add60e21b84528d8401611219565b03915afa98891561167957600099611e9d575b5082828b9c611af59b9c8751809d819482936312e1541b60e31b84528d8401611219565b03915afa98891561167957600099611e6e575b50881580611e66575b611e4d57848654169a60008551809d63349f642f60e11b8252868a8301528180611b3e60248201896111f4565b03915afa9b8c15611e425760009c611e27575b5060e08c01519684876006541697875198898080936311467f2f60e21b82528b87830152611b82604483018b6111f4565b908816602483015203915afa968715611e1c57600097611deb575b508551630c3fe1f960e01b815295949384938793909284928392611bc2928401611219565b03915afa9182156115e25750600091611dbf575b5090506101c06101a089015198015191878711600014611db057611bfa888861123b565b8915908115611da7575b8115611d9e575b508015611d96575b611d7f57611c989291611c8d611c87611c80611c7b611c75611c4b611c92978f8f611c4190611c469261197b565b6113f2565b6119a7565b670de0b6b3a76400009a8b8213611d77575b670de0b6b3a763ffff19808312611d6f575b5061140f565b966119d3565b611994565b948561140f565b93611958565b61140f565b906119f0565b0594856000811380611d5e575b15611d1d5750611cb4906113f2565b925b60008413918215611d0f57845b611cd16122389283926113be565b049215611d0157845b04941115611ce85793929190565b611cf4611cfa916113d1565b936113d1565b9293929190565b611d0a856119c2565b611cda565b611d18856119c2565b611cc3565b93906000851280611d4a575b611d34575b50611cb6565b611d43919450611c41906119c2565b9238611d2e565b50611d57611c41826119c2565b8513611d29565b50611d68826113f2565b8112611ca5565b915038611c6f565b8b9150611c5d565b505050505092505050600090600090600090600090565b508015611c13565b90501538611c0b565b84159150611c04565b611dba878961123b565b611bfa565b82813d8311611de4575b611dd381836109c7565b810103126101695750518038611bd6565b503d611dc9565b90968582813d8311611e15575b611e0281836109c7565b8101031261016957505195611bc2611b9d565b503d611df8565b86513d6000823e3d90fd5b611e3b919c3d8091833e6115d481836109c7565b9a38611b51565b85513d6000823e3d90fd5b5050505050505092505050600090600090600090600090565b508915611b11565b90988382813d8311611e96575b611e8581836109c7565b810103126101695750519738611b08565b503d611e7b565b9a98838c813d8311611ec7575b611eb481836109c7565b8101031261016957509951979982611ad1565b503d611eaa565b908682813d8311611ef6575b611ee481836109c7565b81010312610169575051611a8d611a83565b503d611eda565b8582813d8311611f25575b611f1281836109c7565b810103126101695750611a619051611a56565b503d611f08565b82513d6000823e3d90fd5b9192831561215d575b831561214f5760018060a01b03938385600554169560408051956301d25add60e21b8752602090818880611f798460049d8e8401611219565b03818d5afa97881561163f5760009861211e575b5081818a9b87611fb29b9c87519c8d94859384936312e1541b60e31b85528401611219565b03915afa97881561163f576000986120ef575b508715806120e7575b6120cf57838a54169960008451809c63349f642f60e11b825285848301528180611ffb60248201886111f4565b03915afa9a8b156116795760009b6120b4575b5060e08b01519585600654169584865180986311467f2f60e21b82528886830152818061203e604482018a6111f4565b868816602483015203915afa968715611e1c57600097612083575b5091849391611bc29695936003541691865197889485938493630c3fe1f960e01b85528401611219565b90968582813d83116120ad575b61209a81836109c7565b8101031261016957505195611bc2612059565b503d612090565b6120c8919b3d8091833e6115d481836109c7565b993861200e565b50505050505092505050600090600090600090600090565b508815611fce565b90978282813d8311612117575b61210681836109c7565b810103126101695750519638611fc5565b503d6120fc565b9997828b813d8311612148575b61213581836109c7565b8101031261016957509851969881611f8d565b503d61212b565b600093508392508291508190565b600354604051630cf6928760e41b81529194506001600160a01b03169060209081818061218e878960048401611219565b0381865afa801561191c578291600091612216575b50906121b16004924261123b565b9360405192838092634c24f20960e11b82525afa91821561191c576000926121e5575b50506121df91611248565b92611f40565b81819392933d831161220f575b6121fc81836109c7565b810103126101695750516121df386121d4565b503d6121f2565b9182813d831161223f575b61222b81836109c7565b8101031261016957505181906121b16121a3565b503d612221565b6003546040805163183bb37960e01b8152939092916020916001600160a01b039091169082868061227c8a858960048501610b08565b0381855afa958615611e4257600096612403575b508451630cf6928760e41b8152938385806122b08b868660048501610b08565b0381865afa948515611e1c576000956123d4575b509083916122e58751998a938493638de095a360e01b855260048501610b08565b0381845afa958615611679576000966123a5575b509080600492855193848092634c24f20960e11b82525afa9384156115e25750600093612372575b505061232d904261123b565b670de0b6b3a7640000918183029183830403610b655761234c91611248565b92831561236b57610b2a93612238612364920561140f565b05906119f0565b5050905090565b8181949293943d831161239e575b61238a81836109c7565b810103126101695750519061232d38612321565b503d612380565b90958282813d83116123cd575b6123bc81836109c7565b8101031261016957505194816122f9565b503d6123b2565b90948482813d83116123fc575b6123eb81836109c7565b8101031261016957505193836122c4565b503d6123e1565b90958382813d831161242b575b61241a81836109c7565b810103126101695750519438612290565b503d612410565b67ffffffffffffffff81116109b15760051b60200190565b6001600160a01b038181169182156124bc576000805462010000600160b01b03198116601093841b62010000600160b01b031617909155604080519190921c909216825260208201929092527f53351836099c03ffc3b1727d8abd4b0222afa87d4ed76ae3102d51369ef7f7859190a1565b60405162461bcd60e51b815260206004820152600960248201526810bd32b93796b3b7bb60b91b6044820152606490fdfea2646970667358221220ae415cf63ac86ddcec31e14ca1bdade988ea46af29d8e937433e10a8e6ed3e2164736f6c63430008110033
Deployed Bytecode
0x60a060408181526004918236101561001657600080fd5b600092833560e01c91826312d43a51146108fe575081631c4695f4146106795781633157d39d146106505781634242bac014610627578163485cc955146104cb5781634a4a7b04146104a25781635f7ddaaa146104795781635ff21387146103775781636de8ef6b1461035b5781638265d95b146101e4578163861b6a90146101bb5781639d8e217714610198578163b8d2c6931461016c57508063cfad57a21461012d578063d8a162d2146100fa5763f6126207146100d557600080fd5b346100f6576020906100ef6100e936610940565b91612246565b9051908152f35b5080fd5b50346100f65760809061011561010f36610a3c565b91611f37565b92939091815194855260208501528301526060820152f35b82346101695760203660031901126101695761016661014a610925565b61016160018060a01b03845460101c163314610a94565b61244a565b80f35b80fd5b9050346101945782600319360112610194575490516001600160a01b03909116815260209150f35b8280fd5b5050346100f657816003193601126100f65760209051670de0b6b3a76400008152f35b5050346100f657816003193601126100f65760065490516001600160a01b039091168152602090f35b905082346101695782600319360112610169576101ff610925565b9167ffffffffffffffff9160248035848111610194573660238201121561019457808401359385851161035757600591368487851b830101116103535761024b86939998979596612432565b94610258895196876109c7565b83865261026484612432565b60209a878c019991601f1901368b37368490036042190190895b8781106102c5578d8d8d8d8d83519485948186019282875251809352850193925b8281106102ae57505050500390f35b83518552869550938101939281019260010161029f565b80829e9b9a9c9d9e1b8981880101358481121561034f5787018a8101359087821161034b57604401813603811361034b57906103019187612246565b908d51831015610339578d018c01526000198114610327576001019c9b9a98999c61027e565b634e487b7160e01b8a5260118752888afd5b634e487b7160e01b8c52603289528a8cfd5b8c80fd5b8b80fd5b8480fd5b8380fd5b5050346100f6576020906100ef61037136610a3c565b91611684565b839150346100f65761038836610940565b600154865163ac4ab3fb60e01b815233818701527fa66b7a3e6b19d24ccb6f717fc232a1bb0278a7f83f8e2211835fc4ed0fe69f19602482015291949293929190602090829060449082906001600160a01b03165afa90811561046f578691610432575b50156103fe5750610166939450610b7b565b606490602087519162461bcd60e51b8352820152600e60248201526d21636f6e74726163742d726f6c6560901b6044820152fd5b90506020813d8211610467575b8161044c602093836109c7565b810103126104635761045d90610ada565b876103ec565b8580fd5b3d915061043f565b87513d88823e3d90fd5b5050346100f657816003193601126100f65760035490516001600160a01b039091168152602090f35b5050346100f657816003193601126100f65760015490516001600160a01b039091168152602090f35b9050346101945781600319360112610194576104e5610925565b6001600160a01b03602435818116929083900361046357855460ff8160081c16159485809661061a575b8015610603575b156105a9575060ff198116600117875584610598575b506bffffffffffffffffffffffff60a01b928360025416176002551690600154161760015561055a3361244a565b610562575080f35b60207f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989161ff001984541684555160018152a180f35b61ffff19166101011786553861052c565b608490602088519162461bcd60e51b8352820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152fd5b50303b1580156105165750600160ff831614610516565b50600160ff83161061050f565b5050346100f657816003193601126100f65760025490516001600160a01b039091168152602090f35b5050346100f657816003193601126100f65760055490516001600160a01b039091168152602090f35b9190503461019457826003193601126101945760018060a01b03906106a582855460101c163314610a94565b816002541681519363bf40fac160e01b908186526020928382880152600c60248801526b46756e64696e6753746f726560a01b60448801528387606481845afa9687156108f45788976108b9575b50856bffffffffffffffffffffffff60a01b971687600354161760035584518381528483820152600b60248201526a4d61726b657453746f726560a81b60448201528481606481855afa908115610877579087918a91610881575b50168783541617825584518381528483820152600d60248201526c506f736974696f6e53746f726560981b60448201528481606481855afa908115610877578593929188918b91610830575b5091849591606493168a600554161760055587519687948593845283015260096024830152685269736b53746f726560b81b60448301525afa928315610827575085926107f1575b50501690600654161760065580f35b90809250813d8311610820575b61080881836109c7565b810103126103575761081990610ac6565b38806107e2565b503d6107fe565b513d87823e3d90fd5b92948092508391503d8311610870575b61084a81836109c7565b8101031261086c578493849388610862606494610ac6565b919350919561079a565b8880fd5b503d610840565b86513d8b823e3d90fd5b809250868092503d83116108b2575b61089a81836109c7565b8101031261086c576108ac8791610ac6565b3861074e565b503d610890565b9096508381813d83116108ed575b6108d181836109c7565b810103126108e9576108e290610ac6565b95386106f3565b8780fd5b503d6108c7565b85513d8a823e3d90fd5b8490346100f657816003193601126100f657905460101c6001600160a01b03168152602090f35b600435906001600160a01b038216820361093b57565b600080fd5b604060031982011261093b576004356001600160a01b038116810361093b579160243567ffffffffffffffff9283821161093b578060238301121561093b57816004013593841161093b576024848301011161093b576024019190565b67ffffffffffffffff81116109b157604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff8211176109b157604052565b67ffffffffffffffff81116109b157601f01601f191660200190565b929192610a11826109e9565b91610a1f60405193846109c7565b82948184528183011161093b578281602093846000960137010152565b90606060031983011261093b576004356001600160a01b038116810361093b57916024359067ffffffffffffffff821161093b578060238301121561093b57816024610a8d93600401359101610a05565b9060443590565b15610a9b57565b606460405162461bcd60e51b815260206004820152600460248201526310b3b7bb60e11b6044820152fd5b51906001600160a01b038216820361093b57565b5190811515820361093b57565b908060209392818452848401376000828201840152601f01601f1916010190565b6001600160a01b039091168152604060208201819052610b2a93910191610ae7565b90565b94939291604092610b539260018060a01b03168752606060208801526060870191610ae7565b930152565b91908201809211610b6557565b634e487b7160e01b600052601160045260246000fd5b6003805460408051630cf6928760e41b815290969594926001600160a01b039260009290841660208280610bb48b8a8c60048501610b08565b0381845afa9182156111c7578492611193575b50811561113b575083825416908951634c24f20960e11b8152602081600481865afa8015610f8c578590611107575b610c0291504292610b58565b116110fc57610c1b610c15368988610a05565b87611a0c565b91909492938415610fcc575086835416803b15610fc8578a87918a8f8d610c588692519788968795869463160ad65760e11b865260048601610b2d565b03925af18015610fbe57908691610faa575b505085825416803b156104635789869189838f610c9d8e915197889687958694635d4944eb60e11b865260048601610b2d565b03925af18015610f8c57908591610f96575b505084815416803b15610353578489849289838f610ce38e9151978896879586946308c6451f60e21b865260048601610b2d565b03925af18015610f8c57908591610f78575b505084815416803b15610353578a51608081815263a22966cd60e01b90915251859181610d28428d8c8e60048601610b2d565b039083608051915af1998a15610f6f5788999a98969798610f4c575b85600554166020898b610d6a85519e8f9384936301d25add60e21b855260048501610b08565b0381845afa9a8b15610f4257869b610f0b575b5090602088610da4938b8d8551968794859384936312e1541b60e31b855260048501610b08565b03915afa918215610f0157908695949392918b9792610eca575b5087610dcb368b8d610a05565b610dd59089611432565b935416898b83519d8e92839263183bb37960e01b84526004840192610df993610b08565b03815a93602094fa958615610ebf5795610e6b575b7f7b07d770ce1ec5e65e87ba3075e60ecec1e641c1ef713ebdbee0c408a6448ee09a50610e4781519a8b9a60e08c5260e08c0191610ae7565b9b60208a01528801526060870152608086015260a085015260c084015216930390a2565b945060208a3d602011610eb7575b81610e86602093836109c7565b8101031261093b577f7b07d770ce1ec5e65e87ba3075e60ecec1e641c1ef713ebdbee0c408a6448ee0995194610e0e565b3d9150610e79565b9051903d90823e3d90fd5b965090506020863d602011610ef9575b81610ee7602093836109c7565b8101031261093b578995519038610dbe565b3d9150610eda565b81513d88823e3d90fd5b91909a506020823d602011610f3a575b81610f28602093836109c7565b8101031261093b579051996020610d7d565b3d9150610f1b565b82513d88823e3d90fd5b9091929380959650610f5f60805161099d565b6103535790889594939291610d44565b513d85823e3d90fd5b610f819061099d565b610357578338610cf5565b8b513d87823e3d90fd5b610f9f9061099d565b610357578338610caf565b610fb39061099d565b610353578438610c6a565b8c513d88823e3d90fd5b8680fd5b919350919350809a989594999a3b156110f857858a9188838b6110048e519788968795869463160ad65760e11b865260048601610b2d565b03925af180156110ee579089916110da575b505082825416803b1561086c5784899187838a6110488d5197889687958694635d4944eb60e11b865260048601610b2d565b03925af180156110d0579088916110bc575b5050541691823b15610463579184939186809461108e97519788958694859363a22966cd60e01b8552429260048601610b2d565b03925af19081156110b357506110a2575050565b6110ac829161099d565b6101695750565b513d84823e3d90fd5b6110c59061099d565b610fc857863861105a565b87513d8a823e3d90fd5b6110e39061099d565b6108e9578738611016565b88513d8b823e3d90fd5b8980fd5b505050505050509050565b506020813d602011611133575b81611121602093836109c7565b8101031261093b57610c029051610bf6565b3d9150611114565b949297989693505050823b15610463579184939186809461117397519788958694859363a22966cd60e01b8552429260048601610b2d565b03925af19081156110b35750611187575050565b6111909061099d565b50565b9091506020813d6020116111bf575b816111af602093836109c7565b8101031261035757519038610bc7565b3d91506111a2565b8a513d86823e3d90fd5b60005b8381106111e45750506000910152565b81810151838201526020016111d4565b9060209161120d815180928185528580860191016111d1565b601f01601f1916010190565b6001600160a01b039091168152604060208201819052610b2a929101906111f4565b91908203918211610b6557565b8115611252570490565b634e487b7160e01b600052601260045260246000fd5b81601f8201121561093b57805161127e816109e9565b9261128c60405194856109c7565b8184526020828401011161093b57610b2a91602080850191016111d1565b60208183031261093b57805167ffffffffffffffff9182821161093b5701906101e092838382031261093b57604051938401848110838211176109b157604052825182811161093b57816112ff918501611268565b8452602083015191821161093b57611318918301611268565b602083015261132960408201610ac6565b6040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151908301526101208082015190830152610140808201519083015261016061138f818301610ada565b908301526101806113a1818301610ada565b908301526101a080820151908301526101c0809101519082015290565b81810292918115918404141715610b6557565b60008190039190600160ff1b8114600116610b6557600019830503610b6557565b90670de0b6b3a764000091828102928184051490151715610b6557565b818102929160008212600160ff1b821416610b65578184051490151715610b6557565b600554604080516301d25add60e21b81526001600160a01b039283169594909360049392919060209081878061146b86858b8401611219565b03818c5afa9687156116795760009761164a575b50826114a397989983928651809a819482936312e1541b60e31b84528c8401611219565b03915afa95861561163f57600096611610575b50851580611608575b6115fc5761150291600091888811156115ec576114dc898961123b565b955b87541690855180958194829363349f642f60e11b84528b84015260248301906111f4565b03915afa9182156115e257509060e0916000916115c1575b500151670de0b6b3a764000090808202918204036115ac579061153c916113be565b80800460011481151715611597576115548385610b58565b91612238928084029384040361158257509061156f91611248565b9111156115795790565b610b2a906113d1565b601190634e487b7160e01b6000525260246000fd5b601182634e487b7160e01b6000525260246000fd5b601183634e487b7160e01b6000525260246000fd5b6115dc913d8091833e6115d481836109c7565b8101906112aa565b3861151a565b513d6000823e3d90fd5b6115f6888a61123b565b956114de565b50505050505050600090565b5086156114bf565b90958682813d8311611638575b61162781836109c7565b8101031261016957505194386114b6565b503d61161d565b83513d6000823e3d90fd5b90968282813d8311611672575b61166181836109c7565b81010312610169575051958261147f565b503d611657565b84513d6000823e3d90fd5b9291928315611863575b831561185b5760018060a01b039384600554169460408051946301d25add60e21b865260206004958188806116c686858c8401611219565b03818d5afa9788156116795760009861182c575b50826116fe98999a83928651809b819482936312e1541b60e31b84528d8401611219565b03915afa96871561163f576000976117fd575b508615806117f5575b6117e85761175d91600091898911156117d8576117378a8a61123b565b955b88541690855180958194829363349f642f60e11b84528c84015260248301906111f4565b03915afa9182156115e257509060e0916000916117bf575b500151670de0b6b3a764000090808202918204036117aa576117a0929161179b916113be565b6113be565b6115548385610b58565b601184634e487b7160e01b6000525260246000fd5b6117d2913d8091833e6115d481836109c7565b38611775565b6117e2898b61123b565b95611739565b5050505050505050600090565b50871561171a565b90968782813d8311611825575b61181481836109c7565b810103126101695750519538611711565b503d61180a565b90978282813d8311611854575b61184381836109c7565b8101031261016957505196826116da565b503d611839565b506000925050565b600354604051630cf6928760e41b81529194506001600160a01b031690602090818180611894878a60048401611219565b0381865afa801561191c578291600091611928575b50906118b76004924261123b565b9360405192838092634c24f20960e11b82525afa91821561191c576000926118eb575b50506118e591611248565b9261168e565b81819392933d8311611915575b61190281836109c7565b810103126101695750516118e5386118da565b503d6118f8565b6040513d6000823e3d90fd5b9182813d8311611951575b61193d81836109c7565b8101031261016957505181906118b76118a9565b503d611933565b90670de0b6b3a764000060008382039312818412811691841390151617610b6557565b81810392916000138015828513169184121617610b6557565b801561125257671bc16d674ec800000590565b811561125257600160ff1b8114600019831416610b65570590565b600160ff1b8114610b655760000390565b9060018201916000600184129112908015821691151617610b6557565b91909160008382019384129112908015821691151617610b6557565b60035460408051630cf6928760e41b815293946001600160a01b03928316949092602092600492848180611a438c8b898401611219565b03818b5afa8015611f2c57600090611efd575b611a6191504261123b565b8151634c24f20960e11b8152858186818c5afa90811561163f57600091611ece575b50611a8d91611248565b938415611d7f57611abe96979883600554169982828c8c8751809d819482936301d25add60e21b84528d8401611219565b03915afa98891561167957600099611e9d575b5082828b9c611af59b9c8751809d819482936312e1541b60e31b84528d8401611219565b03915afa98891561167957600099611e6e575b50881580611e66575b611e4d57848654169a60008551809d63349f642f60e11b8252868a8301528180611b3e60248201896111f4565b03915afa9b8c15611e425760009c611e27575b5060e08c01519684876006541697875198898080936311467f2f60e21b82528b87830152611b82604483018b6111f4565b908816602483015203915afa968715611e1c57600097611deb575b508551630c3fe1f960e01b815295949384938793909284928392611bc2928401611219565b03915afa9182156115e25750600091611dbf575b5090506101c06101a089015198015191878711600014611db057611bfa888861123b565b8915908115611da7575b8115611d9e575b508015611d96575b611d7f57611c989291611c8d611c87611c80611c7b611c75611c4b611c92978f8f611c4190611c469261197b565b6113f2565b6119a7565b670de0b6b3a76400009a8b8213611d77575b670de0b6b3a763ffff19808312611d6f575b5061140f565b966119d3565b611994565b948561140f565b93611958565b61140f565b906119f0565b0594856000811380611d5e575b15611d1d5750611cb4906113f2565b925b60008413918215611d0f57845b611cd16122389283926113be565b049215611d0157845b04941115611ce85793929190565b611cf4611cfa916113d1565b936113d1565b9293929190565b611d0a856119c2565b611cda565b611d18856119c2565b611cc3565b93906000851280611d4a575b611d34575b50611cb6565b611d43919450611c41906119c2565b9238611d2e565b50611d57611c41826119c2565b8513611d29565b50611d68826113f2565b8112611ca5565b915038611c6f565b8b9150611c5d565b505050505092505050600090600090600090600090565b508015611c13565b90501538611c0b565b84159150611c04565b611dba878961123b565b611bfa565b82813d8311611de4575b611dd381836109c7565b810103126101695750518038611bd6565b503d611dc9565b90968582813d8311611e15575b611e0281836109c7565b8101031261016957505195611bc2611b9d565b503d611df8565b86513d6000823e3d90fd5b611e3b919c3d8091833e6115d481836109c7565b9a38611b51565b85513d6000823e3d90fd5b5050505050505092505050600090600090600090600090565b508915611b11565b90988382813d8311611e96575b611e8581836109c7565b810103126101695750519738611b08565b503d611e7b565b9a98838c813d8311611ec7575b611eb481836109c7565b8101031261016957509951979982611ad1565b503d611eaa565b908682813d8311611ef6575b611ee481836109c7565b81010312610169575051611a8d611a83565b503d611eda565b8582813d8311611f25575b611f1281836109c7565b810103126101695750611a619051611a56565b503d611f08565b82513d6000823e3d90fd5b9192831561215d575b831561214f5760018060a01b03938385600554169560408051956301d25add60e21b8752602090818880611f798460049d8e8401611219565b03818d5afa97881561163f5760009861211e575b5081818a9b87611fb29b9c87519c8d94859384936312e1541b60e31b85528401611219565b03915afa97881561163f576000986120ef575b508715806120e7575b6120cf57838a54169960008451809c63349f642f60e11b825285848301528180611ffb60248201886111f4565b03915afa9a8b156116795760009b6120b4575b5060e08b01519585600654169584865180986311467f2f60e21b82528886830152818061203e604482018a6111f4565b868816602483015203915afa968715611e1c57600097612083575b5091849391611bc29695936003541691865197889485938493630c3fe1f960e01b85528401611219565b90968582813d83116120ad575b61209a81836109c7565b8101031261016957505195611bc2612059565b503d612090565b6120c8919b3d8091833e6115d481836109c7565b993861200e565b50505050505092505050600090600090600090600090565b508815611fce565b90978282813d8311612117575b61210681836109c7565b810103126101695750519638611fc5565b503d6120fc565b9997828b813d8311612148575b61213581836109c7565b8101031261016957509851969881611f8d565b503d61212b565b600093508392508291508190565b600354604051630cf6928760e41b81529194506001600160a01b03169060209081818061218e878960048401611219565b0381865afa801561191c578291600091612216575b50906121b16004924261123b565b9360405192838092634c24f20960e11b82525afa91821561191c576000926121e5575b50506121df91611248565b92611f40565b81819392933d831161220f575b6121fc81836109c7565b810103126101695750516121df386121d4565b503d6121f2565b9182813d831161223f575b61222b81836109c7565b8101031261016957505181906121b16121a3565b503d612221565b6003546040805163183bb37960e01b8152939092916020916001600160a01b039091169082868061227c8a858960048501610b08565b0381855afa958615611e4257600096612403575b508451630cf6928760e41b8152938385806122b08b868660048501610b08565b0381865afa948515611e1c576000956123d4575b509083916122e58751998a938493638de095a360e01b855260048501610b08565b0381845afa958615611679576000966123a5575b509080600492855193848092634c24f20960e11b82525afa9384156115e25750600093612372575b505061232d904261123b565b670de0b6b3a7640000918183029183830403610b655761234c91611248565b92831561236b57610b2a93612238612364920561140f565b05906119f0565b5050905090565b8181949293943d831161239e575b61238a81836109c7565b810103126101695750519061232d38612321565b503d612380565b90958282813d83116123cd575b6123bc81836109c7565b8101031261016957505194816122f9565b503d6123b2565b90948482813d83116123fc575b6123eb81836109c7565b8101031261016957505193836122c4565b503d6123e1565b90958382813d831161242b575b61241a81836109c7565b810103126101695750519438612290565b503d612410565b67ffffffffffffffff81116109b15760051b60200190565b6001600160a01b038181169182156124bc576000805462010000600160b01b03198116601093841b62010000600160b01b031617909155604080519190921c909216825260208201929092527f53351836099c03ffc3b1727d8abd4b0222afa87d4ed76ae3102d51369ef7f7859190a1565b60405162461bcd60e51b815260206004820152600960248201526810bd32b93796b3b7bb60b91b6044820152606490fdfea2646970667358221220ae415cf63ac86ddcec31e14ca1bdade988ea46af29d8e937433e10a8e6ed3e2164736f6c63430008110033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MON
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
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.