Contract
0x57ee47829369e2ef62fbb423648bec70d0366204
1
Contract Overview
Balance:
0 MATIC
My Name Tag:
Not Available
[ Download CSV Export ]
Latest 18 internal transactions
[ Download CSV Export ]
Contract Name:
LongShortPairCreator
Compiler Version
v0.8.4+commit.c7e474f2
Optimization Enabled:
Yes with 199 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "../../common/interfaces/ExpandedIERC20.sol"; import "../../common/interfaces/IERC20Standard.sol"; import "../../oracle/interfaces/FinderInterface.sol"; import "../../common/implementation/Testable.sol"; import "../../common/implementation/Lockable.sol"; import "../common/TokenFactory.sol"; import "./LongShortPair.sol"; import "../common/financial-product-libraries/long-short-pair-libraries/LongShortPairFinancialProductLibrary.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; /** * @title Long Short Pair Contract Creator. * @notice Factory contract to create new instances of long short pair contracts. * Responsible for constraining the parameters used to construct a new LSP. These constraints can evolve over time and * are initially constrained to conservative values in this first iteration. */ contract LongShortPairCreator is Testable, Lockable { using FixedPoint for FixedPoint.Unsigned; using SafeERC20 for IERC20Standard; struct CreatorParams { string pairName; uint64 expirationTimestamp; uint256 collateralPerPair; bytes32 priceIdentifier; string longSynthName; string longSynthSymbol; string shortSynthName; string shortSynthSymbol; IERC20Standard collateralToken; LongShortPairFinancialProductLibrary financialProductLibrary; bytes customAncillaryData; uint256 prepaidProposerReward; uint256 optimisticOracleLivenessTime; uint256 optimisticOracleProposerBond; } // Address of TokenFactory used to create a new synthetic token. TokenFactory public tokenFactory; FinderInterface public finder; event CreatedLongShortPair( address indexed longShortPair, address indexed deployerAddress, address longToken, address shortToken ); /** * @notice Constructs the LongShortPairCreator contract. * @param _finder UMA protocol Finder used to discover other protocol contracts. * @param _tokenFactory ERC20 token factory used to deploy synthetic token instances. * @param _timer Contract that stores the current time in a testing environment. */ constructor( FinderInterface _finder, TokenFactory _tokenFactory, address _timer ) Testable(_timer) nonReentrant() { tokenFactory = _tokenFactory; finder = _finder; } /** * @notice Creates a longShortPair contract and associated long and short tokens. * @dev The caller must approve this contract to transfer `prepaidProposerReward` amount of collateral. * @param params Constructor params used to initialize the LSP. Key-valued object with the following structure: * pairName: Name of the long short pair contract. * expirationTimestamp: unix timestamp of when the contract will expire. * collateralPerPair: how many units of collateral are required to mint one pair of synthetic tokens. * priceIdentifier: registered in the DVM for the synthetic. * longSynthName: Name of the long synthetic tokens to be created. * longSynthSymbol: Symbol of the long synthetic tokens to be created. * shortSynthName: Name of the short synthetic tokens to be created. * shortSynthSymbol: Symbol of the short synthetic tokens to be created. * collateralToken: ERC20 token used as collateral in the LSP. * financialProductLibrary: Contract providing settlement payout logic. * customAncillaryData: Custom ancillary data to be passed along with the price request. If not needed, this * should be left as a 0-length bytes array. * prepaidProposerReward: Proposal reward forwarded to the created LSP to incentivize price proposals. * optimisticOracleLivenessTime: Optimistic oracle liveness time for price requests. optimisticOracleProposerBond: optimistic oracle proposer bond for price requests. * @return lspAddress the deployed address of the new long short pair contract. * @notice Created LSP is not registered within the registry as the LSP uses the Optimistic Oracle for settlement. * @notice The LSP constructor does a number of validations on input params. These are not repeated here. */ function createLongShortPair(CreatorParams memory params) public nonReentrant() returns (address) { // Create a new synthetic token using the params. require(bytes(params.longSynthName).length != 0, "Missing long synthetic name"); require(bytes(params.shortSynthName).length != 0, "Missing short synthetic name"); require(bytes(params.longSynthSymbol).length != 0, "Missing long synthetic symbol"); require(bytes(params.shortSynthSymbol).length != 0, "Missing short synthetic symbol"); // If the collateral token does not have a `decimals()` method, then a default precision of 18 will be // applied to the newly created synthetic token. uint8 collateralDecimals = _getSyntheticDecimals(params.collateralToken); ExpandedIERC20 longToken = tokenFactory.createToken(params.longSynthName, params.longSynthSymbol, collateralDecimals); ExpandedIERC20 shortToken = tokenFactory.createToken(params.shortSynthName, params.shortSynthSymbol, collateralDecimals); // Deploy the LPS contract. LongShortPair lsp = new LongShortPair(_convertParams(params, longToken, shortToken)); // Move prepaid proposer reward from the deployer to the newly deployed contract. if (params.prepaidProposerReward > 0) params.collateralToken.safeTransferFrom(msg.sender, address(lsp), params.prepaidProposerReward); address lspAddress = address(lsp); // Give permissions to new lsp contract and then hand over ownership. longToken.addMinter(lspAddress); longToken.addBurner(lspAddress); longToken.resetOwner(lspAddress); shortToken.addMinter(lspAddress); shortToken.addBurner(lspAddress); shortToken.resetOwner(lspAddress); emit CreatedLongShortPair(lspAddress, msg.sender, address(longToken), address(shortToken)); return lspAddress; } // Converts createLongShortPair creator params to LongShortPair constructor params. function _convertParams( CreatorParams memory creatorParams, ExpandedIERC20 longToken, ExpandedIERC20 shortToken ) private view returns (LongShortPair.ConstructorParams memory constructorParams) { // Input from function call. constructorParams.pairName = creatorParams.pairName; constructorParams.expirationTimestamp = creatorParams.expirationTimestamp; constructorParams.collateralPerPair = creatorParams.collateralPerPair; constructorParams.priceIdentifier = creatorParams.priceIdentifier; constructorParams.collateralToken = creatorParams.collateralToken; constructorParams.financialProductLibrary = creatorParams.financialProductLibrary; constructorParams.customAncillaryData = creatorParams.customAncillaryData; constructorParams.prepaidProposerReward = creatorParams.prepaidProposerReward; constructorParams.optimisticOracleLivenessTime = creatorParams.optimisticOracleLivenessTime; constructorParams.optimisticOracleProposerBond = creatorParams.optimisticOracleProposerBond; // Constructed long & short synthetic tokens. constructorParams.longToken = longToken; constructorParams.shortToken = shortToken; // Finder and timer. Should be the same as that used in this factory contract. constructorParams.finder = finder; constructorParams.timerAddress = timerAddress; } // IERC20Standard.decimals() will revert if the collateral contract has not implemented the decimals() method, // which is possible since the method is only an OPTIONAL method in the ERC20 standard: // https://eips.ethereum.org/EIPS/eip-20#methods. function _getSyntheticDecimals(IERC20Standard _collateralToken) private view returns (uint8 decimals) { try _collateralToken.decimals() returns (uint8 _decimals) { return _decimals; } catch { return 18; } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title ERC20 interface that includes burn and mint methods. */ abstract contract ExpandedIERC20 is IERC20 { /** * @notice Burns a specific amount of the caller's tokens. * @dev Only burns the caller's tokens, so it is safe to leave this method permissionless. */ function burn(uint256 value) external virtual; /** * @dev Burns `value` tokens owned by `recipient`. * @param recipient address to burn tokens from. * @param value amount of tokens to burn. */ function burnFrom(address recipient, uint256 value) external virtual returns (bool); /** * @notice Mints tokens and adds them to the balance of the `to` address. * @dev This method should be permissioned to only allow designated parties to mint tokens. */ function mint(address to, uint256 value) external virtual returns (bool); function addMinter(address account) external virtual; function addBurner(address account) external virtual; function resetOwner(address account) external virtual; }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title ERC20 interface that includes the decimals read only method. */ interface IERC20Standard is IERC20 { /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should be displayed to a user as `5,05` * (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. This is the value * {ERC20} uses, unless {_setupDecimals} is called. * * NOTE: This information is only used for _display_ purposes: it in no way affects any of the arithmetic * of the contract, including {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Provides addresses of the live contracts implementing certain interfaces. * @dev Examples are the Oracle or Store interfaces. */ interface FinderInterface { /** * @notice Updates the address of the contract that implements `interfaceName`. * @param interfaceName bytes32 encoding of the interface name that is either changed or registered. * @param implementationAddress address of the deployed contract that implements the interface. */ function changeImplementationAddress(bytes32 interfaceName, address implementationAddress) external; /** * @notice Gets the address of the contract that implements the given `interfaceName`. * @param interfaceName queried interface. * @return implementationAddress address of the deployed contract that implements the interface. */ function getImplementationAddress(bytes32 interfaceName) external view returns (address); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "./Timer.sol"; /** * @title Base class that provides time overrides, but only if being run in test mode. */ abstract contract Testable { // If the contract is being run in production, then `timerAddress` will be the 0x0 address. // Note: this variable should be set on construction and never modified. address public timerAddress; /** * @notice Constructs the Testable contract. Called by child contracts. * @param _timerAddress Contract that stores the current time in a testing environment. * Must be set to 0x0 for production environments that use live time. */ constructor(address _timerAddress) { timerAddress = _timerAddress; } /** * @notice Reverts if not running in test mode. */ modifier onlyIfTest { require(timerAddress != address(0x0)); _; } /** * @notice Sets the current time. * @dev Will revert if not running in test mode. * @param time timestamp to set current Testable time to. */ function setCurrentTime(uint256 time) external onlyIfTest { Timer(timerAddress).setCurrentTime(time); } /** * @notice Gets the current time. Will return the last time set in `setCurrentTime` if running in test mode. * Otherwise, it will return the block timestamp. * @return uint for the current Testable timestamp. */ function getCurrentTime() public view returns (uint256) { if (timerAddress != address(0x0)) { return Timer(timerAddress).getCurrentTime(); } else { return block.timestamp; // solhint-disable-line not-rely-on-time } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title A contract that provides modifiers to prevent reentrancy to state-changing and view-only methods. This contract * is inspired by https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/ReentrancyGuard.sol * and https://github.com/balancer-labs/balancer-core/blob/master/contracts/BPool.sol. */ contract Lockable { bool private _notEntered; constructor() { // Storing an initial non-zero value makes deployment a bit more expensive, but in exchange the refund on every // call to nonReentrant will be lower in amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to increase the likelihood of the full // refund coming into effect. _notEntered = true; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` function is not supported. It is possible to * prevent this from happening by making the `nonReentrant` function external, and making it call a `private` * function that does the actual state modification. */ modifier nonReentrant() { _preEntranceCheck(); _preEntranceSet(); _; _postEntranceReset(); } /** * @dev Designed to prevent a view-only method from being re-entered during a call to a `nonReentrant()` state-changing method. */ modifier nonReentrantView() { _preEntranceCheck(); _; } // Internal methods are used to avoid copying the require statement's bytecode to every `nonReentrant()` method. // On entry into a function, `_preEntranceCheck()` should always be called to check if the function is being // re-entered. Then, if the function modifies state, it should call `_postEntranceSet()`, perform its logic, and // then call `_postEntranceReset()`. // View-only methods can simply call `_preEntranceCheck()` to make sure that it is not being re-entered. function _preEntranceCheck() internal view { // On the first call to nonReentrant, _notEntered will be true require(_notEntered, "ReentrancyGuard: reentrant call"); } function _preEntranceSet() internal { // Any calls to nonReentrant after this point will fail _notEntered = false; } function _postEntranceReset() internal { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _notEntered = true; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "./SyntheticToken.sol"; import "../../common/interfaces/ExpandedIERC20.sol"; import "../../common/implementation/Lockable.sol"; /** * @title Factory for creating new mintable and burnable tokens. */ contract TokenFactory is Lockable { /** * @notice Create a new token and return it to the caller. * @dev The caller will become the only minter and burner and the new owner capable of assigning the roles. * @param tokenName used to describe the new token. * @param tokenSymbol short ticker abbreviation of the name. Ideally < 5 chars. * @param tokenDecimals used to define the precision used in the token's numerical representation. * @return newToken an instance of the newly created token interface. */ function createToken( string calldata tokenName, string calldata tokenSymbol, uint8 tokenDecimals ) external nonReentrant() returns (ExpandedIERC20 newToken) { SyntheticToken mintableToken = new SyntheticToken(tokenName, tokenSymbol, tokenDecimals); mintableToken.resetOwner(msg.sender); newToken = ExpandedIERC20(address(mintableToken)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../common/financial-product-libraries/long-short-pair-libraries/LongShortPairFinancialProductLibrary.sol"; import "../../common/implementation/Testable.sol"; import "../../common/implementation/Lockable.sol"; import "../../common/implementation/FixedPoint.sol"; import "../../common/interfaces/ExpandedIERC20.sol"; import "../../oracle/interfaces/OracleInterface.sol"; import "../../common/interfaces/AddressWhitelistInterface.sol"; import "../../oracle/interfaces/FinderInterface.sol"; import "../../oracle/interfaces/OptimisticOracleInterface.sol"; import "../../oracle/interfaces/IdentifierWhitelistInterface.sol"; import "../../oracle/implementation/Constants.sol"; /** * @title Long Short Pair. * @notice Uses a combination of long and short tokens to tokenize the bounded price exposure to a given identifier. */ contract LongShortPair is Testable, Lockable { using FixedPoint for FixedPoint.Unsigned; using SafeERC20 for IERC20; /********************************************* * LONG SHORT PAIR DATA STRUCTURES * *********************************************/ // Define the contract's constructor parameters as a struct to enable more variables to be specified. struct ConstructorParams { string pairName; // Name of the long short pair contract. uint64 expirationTimestamp; // Unix timestamp of when the contract will expire. uint256 collateralPerPair; // How many units of collateral are required to mint one pair of synthetic tokens. bytes32 priceIdentifier; // Price identifier, registered in the DVM for the long short pair. ExpandedIERC20 longToken; // Token used as long in the LSP. Mint and burn rights needed by this contract. ExpandedIERC20 shortToken; // Token used as short in the LSP. Mint and burn rights needed by this contract. IERC20 collateralToken; // Collateral token used to back LSP synthetics. LongShortPairFinancialProductLibrary financialProductLibrary; // Contract providing settlement payout logic. bytes customAncillaryData; // Custom ancillary data to be passed along with the price request to the OO. uint256 prepaidProposerReward; // Preloaded reward to incentivize settlement price proposals. uint256 optimisticOracleLivenessTime; // OO liveness time for price requests. uint256 optimisticOracleProposerBond; // OO proposer bond for price requests. FinderInterface finder; // DVM finder to find other UMA ecosystem contracts. address timerAddress; // Timer used to synchronize contract time in testing. Set to 0x000... in production. } enum ContractState { Open, ExpiredPriceRequested, ExpiredPriceReceived } // @dev note contractState and expirationTimestamp are declared in this order so they use the same storage slot. ContractState public contractState; uint64 public expirationTimestamp; string public pairName; // Amount of collateral a pair of tokens is always redeemable for. uint256 public collateralPerPair; // Price returned from the Optimistic oracle at settlement time. int256 public expiryPrice; // Number between 0 and 1e18 to allocate collateral between long & short tokens at redemption. 0 entitles each short // to collateralPerPair and long worth 0. 1e18 makes each long worth collateralPerPair and short 0. uint256 public expiryPercentLong; bytes32 public priceIdentifier; IERC20 public collateralToken; ExpandedIERC20 public longToken; ExpandedIERC20 public shortToken; FinderInterface public finder; LongShortPairFinancialProductLibrary public financialProductLibrary; // Optimistic oracle customization parameters. bytes public customAncillaryData; uint256 public prepaidProposerReward; uint256 public optimisticOracleLivenessTime; uint256 public optimisticOracleProposerBond; /**************************************** * EVENTS * ****************************************/ event TokensCreated(address indexed sponsor, uint256 indexed collateralUsed, uint256 indexed tokensMinted); event TokensRedeemed(address indexed sponsor, uint256 indexed collateralReturned, uint256 indexed tokensRedeemed); event ContractExpired(address indexed caller); event PositionSettled(address indexed sponsor, uint256 collateralReturned, uint256 longTokens, uint256 shortTokens); /**************************************** * MODIFIERS * ****************************************/ modifier preExpiration() { require(getCurrentTime() < expirationTimestamp, "Only callable pre-expiry"); _; } modifier postExpiration() { require(getCurrentTime() >= expirationTimestamp, "Only callable post-expiry"); _; } modifier onlyOpenState() { require(contractState == ContractState.Open, "Contract state is not Open"); _; } /** * @notice Construct the LongShortPair * @param params Constructor params used to initialize the LSP. Key-valued object with the following structure: * pairName: Name of the long short pair contract. * expirationTimestamp: Unix timestamp of when the contract will expire. * collateralPerPair: How many units of collateral are required to mint one pair of synthetic tokens. * priceIdentifier: Price identifier, registered in the DVM for the long short pair. * longToken: Token used as long in the LSP. Mint and burn rights needed by this contract. * shortToken: Token used as short in the LSP. Mint and burn rights needed by this contract. * collateralToken: Collateral token used to back LSP synthetics. * financialProductLibrary: Contract providing settlement payout logic. * customAncillaryData: Custom ancillary data to be passed along with the price request to the OO. * prepaidProposerReward: Preloaded reward to incentivize settlement price proposals. * optimisticOracleLivenessTime: OO liveness time for price requests. * optimisticOracleProposerBond: OO proposer bond for price requests. * finder: DVM finder to find other UMA ecosystem contracts. * timerAddress: Timer used to synchronize contract time in testing. Set to 0x000... in production. */ constructor(ConstructorParams memory params) Testable(params.timerAddress) { finder = params.finder; require(bytes(params.pairName).length > 0, "Pair name cant be empty"); require(params.expirationTimestamp > getCurrentTime(), "Expiration timestamp in past"); require(params.collateralPerPair > 0, "Collateral per pair cannot be 0"); require(_getIdentifierWhitelist().isIdentifierSupported(params.priceIdentifier), "Identifier not registered"); require(address(_getOptimisticOracle()) != address(0), "Invalid finder"); require(address(params.financialProductLibrary) != address(0), "Invalid FinancialProductLibrary"); require(_getCollateralWhitelist().isOnWhitelist(address(params.collateralToken)), "Collateral not whitelisted"); require(params.optimisticOracleLivenessTime > 0, "OO liveness cannot be 0"); require(params.optimisticOracleLivenessTime < 5200 weeks, "OO liveness too large"); pairName = params.pairName; expirationTimestamp = params.expirationTimestamp; collateralPerPair = params.collateralPerPair; priceIdentifier = params.priceIdentifier; longToken = params.longToken; shortToken = params.shortToken; collateralToken = params.collateralToken; financialProductLibrary = params.financialProductLibrary; OptimisticOracleInterface optimisticOracle = _getOptimisticOracle(); require( optimisticOracle.stampAncillaryData(params.customAncillaryData, address(this)).length <= optimisticOracle.ancillaryBytesLimit(), "Ancillary Data too long" ); customAncillaryData = params.customAncillaryData; prepaidProposerReward = params.prepaidProposerReward; optimisticOracleLivenessTime = params.optimisticOracleLivenessTime; optimisticOracleProposerBond = params.optimisticOracleProposerBond; } /**************************************** * POSITION FUNCTIONS * ****************************************/ /** * @notice Creates a pair of long and short tokens equal in number to tokensToCreate. Pulls the required collateral * amount into this contract, defined by the collateralPerPair value. * @dev The caller must approve this contract to transfer `tokensToCreate * collateralPerPair` amount of collateral. * @param tokensToCreate number of long and short synthetic tokens to create. * @return collateralUsed total collateral used to mint the synthetics. */ function create(uint256 tokensToCreate) public preExpiration() nonReentrant() returns (uint256 collateralUsed) { // Note the use of mulCeil to prevent small collateralPerPair causing rounding of collateralUsed to 0 enabling // callers to mint dust LSP tokens without paying any collateral. collateralUsed = FixedPoint.Unsigned(tokensToCreate).mulCeil(FixedPoint.Unsigned(collateralPerPair)).rawValue; collateralToken.safeTransferFrom(msg.sender, address(this), collateralUsed); require(longToken.mint(msg.sender, tokensToCreate)); require(shortToken.mint(msg.sender, tokensToCreate)); emit TokensCreated(msg.sender, collateralUsed, tokensToCreate); } /** * @notice Redeems a pair of long and short tokens equal in number to tokensToRedeem. Returns the commensurate * amount of collateral to the caller for the pair of tokens, defined by the collateralPerPair value. * @dev This contract must have the `Burner` role for the `longToken` and `shortToken` in order to call `burnFrom`. * @dev The caller does not need to approve this contract to transfer any amount of `tokensToRedeem` since long * and short tokens are burned, rather than transferred, from the caller. * @param tokensToRedeem number of long and short synthetic tokens to redeem. * @return collateralReturned total collateral returned in exchange for the pair of synthetics. */ function redeem(uint256 tokensToRedeem) public nonReentrant() returns (uint256 collateralReturned) { require(longToken.burnFrom(msg.sender, tokensToRedeem)); require(shortToken.burnFrom(msg.sender, tokensToRedeem)); collateralReturned = FixedPoint.Unsigned(tokensToRedeem).mul(FixedPoint.Unsigned(collateralPerPair)).rawValue; collateralToken.safeTransfer(msg.sender, collateralReturned); emit TokensRedeemed(msg.sender, collateralReturned, tokensToRedeem); } /** * @notice Settle long and/or short tokens in for collateral at a rate informed by the contract settlement. * @dev Uses financialProductLibrary to compute the redemption rate between long and short tokens. * @dev This contract must have the `Burner` role for the `longToken` and `shortToken` in order to call `burnFrom`. * @dev The caller does not need to approve this contract to transfer any amount of `tokensToRedeem` since long * and short tokens are burned, rather than transferred, from the caller. * @param longTokensToRedeem number of long tokens to settle. * @param shortTokensToRedeem number of short tokens to settle. * @return collateralReturned total collateral returned in exchange for the pair of synthetics. */ function settle(uint256 longTokensToRedeem, uint256 shortTokensToRedeem) public postExpiration() nonReentrant() returns (uint256 collateralReturned) { // If the contract state is open and postExpiration passed then `expire()` has not yet been called. require(contractState != ContractState.Open, "Unexpired contract"); // Get the current settlement price and store it. If it is not resolved, will revert. if (contractState != ContractState.ExpiredPriceReceived) { expiryPrice = _getOraclePriceExpiration(expirationTimestamp); // Cap the return value at 1. expiryPercentLong = Math.min( financialProductLibrary.percentageLongCollateralAtExpiry(expiryPrice), FixedPoint.fromUnscaledUint(1).rawValue ); contractState = ContractState.ExpiredPriceReceived; } require(longToken.burnFrom(msg.sender, longTokensToRedeem)); require(shortToken.burnFrom(msg.sender, shortTokensToRedeem)); // expiryPercentLong is a number between 0 and 1e18. 0 means all collateral goes to short tokens and 1e18 means // all collateral goes to the long token. Total collateral returned is the sum of payouts. uint256 longCollateralRedeemed = FixedPoint .Unsigned(longTokensToRedeem) .mul(FixedPoint.Unsigned(collateralPerPair)) .mul(FixedPoint.Unsigned(expiryPercentLong)) .rawValue; uint256 shortCollateralRedeemed = FixedPoint .Unsigned(shortTokensToRedeem) .mul(FixedPoint.Unsigned(collateralPerPair)) .mul(FixedPoint.fromUnscaledUint(1).sub(FixedPoint.Unsigned(expiryPercentLong))) .rawValue; collateralReturned = longCollateralRedeemed + shortCollateralRedeemed; collateralToken.safeTransfer(msg.sender, collateralReturned); emit PositionSettled(msg.sender, collateralReturned, longTokensToRedeem, shortTokensToRedeem); } /**************************************** * GLOBAL STATE FUNCTIONS * ****************************************/ function expire() public postExpiration() onlyOpenState() nonReentrant() { _requestOraclePriceExpiration(); contractState = ContractState.ExpiredPriceRequested; emit ContractExpired(msg.sender); } /**************************************** * GLOBAL ACCESSORS FUNCTIONS * ****************************************/ /** * @notice Returns the number of long and short tokens a sponsor wallet holds. * @param sponsor address of the sponsor to query. * @return [uint256, uint256]. First is long tokens held by sponsor and second is short tokens held by sponsor. */ function getPositionTokens(address sponsor) public view nonReentrantView() returns (uint256, uint256) { return (longToken.balanceOf(sponsor), shortToken.balanceOf(sponsor)); } /**************************************** * INTERNAL FUNCTIONS * ****************************************/ function _getOraclePriceExpiration(uint256 requestedTime) internal returns (int256) { // Create an instance of the oracle and get the price. If the price is not resolved revert. OptimisticOracleInterface optimisticOracle = _getOptimisticOracle(); require(optimisticOracle.hasPrice(address(this), priceIdentifier, requestedTime, customAncillaryData)); int256 oraclePrice = optimisticOracle.settleAndGetPrice(priceIdentifier, requestedTime, customAncillaryData); return oraclePrice; } function _requestOraclePriceExpiration() internal { OptimisticOracleInterface optimisticOracle = _getOptimisticOracle(); // Use the prepaidProposerReward as the proposer reward. if (prepaidProposerReward > 0) collateralToken.safeApprove(address(optimisticOracle), prepaidProposerReward); optimisticOracle.requestPrice( priceIdentifier, expirationTimestamp, customAncillaryData, collateralToken, prepaidProposerReward ); // Set the Optimistic oracle liveness for the price request. optimisticOracle.setCustomLiveness( priceIdentifier, expirationTimestamp, customAncillaryData, optimisticOracleLivenessTime ); // Set the Optimistic oracle proposer bond for the price request. optimisticOracle.setBond( priceIdentifier, expirationTimestamp, customAncillaryData, optimisticOracleProposerBond ); } function _getIdentifierWhitelist() internal view returns (IdentifierWhitelistInterface) { return IdentifierWhitelistInterface(finder.getImplementationAddress(OracleInterfaces.IdentifierWhitelist)); } function _getCollateralWhitelist() internal view returns (AddressWhitelistInterface) { return AddressWhitelistInterface(finder.getImplementationAddress(OracleInterfaces.CollateralWhitelist)); } function _getOptimisticOracle() internal view returns (OptimisticOracleInterface) { return OptimisticOracleInterface(finder.getImplementationAddress(OracleInterfaces.OptimisticOracle)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "../../../../common/implementation/FixedPoint.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; interface ExpiringContractInterface { function expirationTimestamp() external view returns (uint256); } abstract contract LongShortPairFinancialProductLibrary { function percentageLongCollateralAtExpiry(int256 expiryPrice) public view virtual returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Universal store of current contract time for testing environments. */ contract Timer { uint256 private currentTime; constructor() { currentTime = block.timestamp; // solhint-disable-line not-rely-on-time } /** * @notice Sets the current time. * @dev Will revert if not running in test mode. * @param time timestamp to set `currentTime` to. */ function setCurrentTime(uint256 time) external { currentTime = time; } /** * @notice Gets the currentTime variable set in the Timer. * @return uint256 for the current Testable timestamp. */ function getCurrentTime() public view returns (uint256) { return currentTime; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "../../common/implementation/ExpandedERC20.sol"; import "../../common/implementation/Lockable.sol"; /** * @title Burnable and mintable ERC20. * @dev The contract deployer will initially be the only minter, burner and owner capable of adding new roles. */ contract SyntheticToken is ExpandedERC20, Lockable { /** * @notice Constructs the SyntheticToken. * @param tokenName The name which describes the new token. * @param tokenSymbol The ticker abbreviation of the name. Ideally < 5 chars. * @param tokenDecimals The number of decimals to define token precision. */ constructor( string memory tokenName, string memory tokenSymbol, uint8 tokenDecimals ) ExpandedERC20(tokenName, tokenSymbol, tokenDecimals) nonReentrant() {} /** * @notice Add Minter role to account. * @dev The caller must have the Owner role. * @param account The address to which the Minter role is added. */ function addMinter(address account) external override nonReentrant() { addMember(uint256(Roles.Minter), account); } /** * @notice Remove Minter role from account. * @dev The caller must have the Owner role. * @param account The address from which the Minter role is removed. */ function removeMinter(address account) external nonReentrant() { removeMember(uint256(Roles.Minter), account); } /** * @notice Add Burner role to account. * @dev The caller must have the Owner role. * @param account The address to which the Burner role is added. */ function addBurner(address account) external override nonReentrant() { addMember(uint256(Roles.Burner), account); } /** * @notice Removes Burner role from account. * @dev The caller must have the Owner role. * @param account The address from which the Burner role is removed. */ function removeBurner(address account) external nonReentrant() { removeMember(uint256(Roles.Burner), account); } /** * @notice Reset Owner role to account. * @dev The caller must have the Owner role. * @param account The new holder of the Owner role. */ function resetOwner(address account) external override nonReentrant() { resetMember(uint256(Roles.Owner), account); } /** * @notice Checks if a given account holds the Minter role. * @param account The address which is checked for the Minter role. * @return bool True if the provided account is a Minter. */ function isMinter(address account) public view nonReentrantView() returns (bool) { return holdsRole(uint256(Roles.Minter), account); } /** * @notice Checks if a given account holds the Burner role. * @param account The address which is checked for the Burner role. * @return bool True if the provided account is a Burner. */ function isBurner(address account) public view nonReentrantView() returns (bool) { return holdsRole(uint256(Roles.Burner), account); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "./MultiRole.sol"; import "../interfaces/ExpandedIERC20.sol"; /** * @title An ERC20 with permissioned burning and minting. The contract deployer will initially * be the owner who is capable of adding new roles. */ contract ExpandedERC20 is ExpandedIERC20, ERC20, MultiRole { enum Roles { // Can set the minter and burner. Owner, // Addresses that can mint new tokens. Minter, // Addresses that can burn tokens that address owns. Burner } uint8 _decimals; /** * @notice Constructs the ExpandedERC20. * @param _tokenName The name which describes the new token. * @param _tokenSymbol The ticker abbreviation of the name. Ideally < 5 chars. * @param _tokenDecimals The number of decimals to define token precision. */ constructor( string memory _tokenName, string memory _tokenSymbol, uint8 _tokenDecimals ) ERC20(_tokenName, _tokenSymbol) { _decimals = _tokenDecimals; _createExclusiveRole(uint256(Roles.Owner), uint256(Roles.Owner), msg.sender); _createSharedRole(uint256(Roles.Minter), uint256(Roles.Owner), new address[](0)); _createSharedRole(uint256(Roles.Burner), uint256(Roles.Owner), new address[](0)); } function decimals() public view virtual override(ERC20) returns (uint8) { return _decimals; } /** * @dev Mints `value` tokens to `recipient`, returning true on success. * @param recipient address to mint to. * @param value amount of tokens to mint. * @return True if the mint succeeded, or False. */ function mint(address recipient, uint256 value) external override onlyRoleHolder(uint256(Roles.Minter)) returns (bool) { _mint(recipient, value); return true; } /** * @dev Burns `value` tokens owned by `msg.sender`. * @param value amount of tokens to burn. */ function burn(uint256 value) external override onlyRoleHolder(uint256(Roles.Burner)) { _burn(msg.sender, value); } /** * @dev Burns `value` tokens owned by `recipient`. * @param recipient address to burn tokens from. * @param value amount of tokens to burn. * @return True if the burn succeeded, or False. */ function burnFrom(address recipient, uint256 value) external override onlyRoleHolder(uint256(Roles.Burner)) returns (bool) { _burn(recipient, value); return true; } /** * @notice Add Minter role to account. * @dev The caller must have the Owner role. * @param account The address to which the Minter role is added. */ function addMinter(address account) external virtual override { addMember(uint256(Roles.Minter), account); } /** * @notice Add Burner role to account. * @dev The caller must have the Owner role. * @param account The address to which the Burner role is added. */ function addBurner(address account) external virtual override { addMember(uint256(Roles.Burner), account); } /** * @notice Reset Owner role to account. * @dev The caller must have the Owner role. * @param account The new holder of the Owner role. */ function resetOwner(address account) external virtual override { resetMember(uint256(Roles.Owner), account); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; library Exclusive { struct RoleMembership { address member; } function isMember(RoleMembership storage roleMembership, address memberToCheck) internal view returns (bool) { return roleMembership.member == memberToCheck; } function resetMember(RoleMembership storage roleMembership, address newMember) internal { require(newMember != address(0x0), "Cannot set an exclusive role to 0x0"); roleMembership.member = newMember; } function getMember(RoleMembership storage roleMembership) internal view returns (address) { return roleMembership.member; } function init(RoleMembership storage roleMembership, address initialMember) internal { resetMember(roleMembership, initialMember); } } library Shared { struct RoleMembership { mapping(address => bool) members; } function isMember(RoleMembership storage roleMembership, address memberToCheck) internal view returns (bool) { return roleMembership.members[memberToCheck]; } function addMember(RoleMembership storage roleMembership, address memberToAdd) internal { require(memberToAdd != address(0x0), "Cannot add 0x0 to a shared role"); roleMembership.members[memberToAdd] = true; } function removeMember(RoleMembership storage roleMembership, address memberToRemove) internal { roleMembership.members[memberToRemove] = false; } function init(RoleMembership storage roleMembership, address[] memory initialMembers) internal { for (uint256 i = 0; i < initialMembers.length; i++) { addMember(roleMembership, initialMembers[i]); } } } /** * @title Base class to manage permissions for the derived class. */ abstract contract MultiRole { using Exclusive for Exclusive.RoleMembership; using Shared for Shared.RoleMembership; enum RoleType { Invalid, Exclusive, Shared } struct Role { uint256 managingRole; RoleType roleType; Exclusive.RoleMembership exclusiveRoleMembership; Shared.RoleMembership sharedRoleMembership; } mapping(uint256 => Role) private roles; event ResetExclusiveMember(uint256 indexed roleId, address indexed newMember, address indexed manager); event AddedSharedMember(uint256 indexed roleId, address indexed newMember, address indexed manager); event RemovedSharedMember(uint256 indexed roleId, address indexed oldMember, address indexed manager); /** * @notice Reverts unless the caller is a member of the specified roleId. */ modifier onlyRoleHolder(uint256 roleId) { require(holdsRole(roleId, msg.sender), "Sender does not hold required role"); _; } /** * @notice Reverts unless the caller is a member of the manager role for the specified roleId. */ modifier onlyRoleManager(uint256 roleId) { require(holdsRole(roles[roleId].managingRole, msg.sender), "Can only be called by a role manager"); _; } /** * @notice Reverts unless the roleId represents an initialized, exclusive roleId. */ modifier onlyExclusive(uint256 roleId) { require(roles[roleId].roleType == RoleType.Exclusive, "Must be called on an initialized Exclusive role"); _; } /** * @notice Reverts unless the roleId represents an initialized, shared roleId. */ modifier onlyShared(uint256 roleId) { require(roles[roleId].roleType == RoleType.Shared, "Must be called on an initialized Shared role"); _; } /** * @notice Whether `memberToCheck` is a member of roleId. * @dev Reverts if roleId does not correspond to an initialized role. * @param roleId the Role to check. * @param memberToCheck the address to check. * @return True if `memberToCheck` is a member of `roleId`. */ function holdsRole(uint256 roleId, address memberToCheck) public view returns (bool) { Role storage role = roles[roleId]; if (role.roleType == RoleType.Exclusive) { return role.exclusiveRoleMembership.isMember(memberToCheck); } else if (role.roleType == RoleType.Shared) { return role.sharedRoleMembership.isMember(memberToCheck); } revert("Invalid roleId"); } /** * @notice Changes the exclusive role holder of `roleId` to `newMember`. * @dev Reverts if the caller is not a member of the managing role for `roleId` or if `roleId` is not an * initialized, ExclusiveRole. * @param roleId the ExclusiveRole membership to modify. * @param newMember the new ExclusiveRole member. */ function resetMember(uint256 roleId, address newMember) public onlyExclusive(roleId) onlyRoleManager(roleId) { roles[roleId].exclusiveRoleMembership.resetMember(newMember); emit ResetExclusiveMember(roleId, newMember, msg.sender); } /** * @notice Gets the current holder of the exclusive role, `roleId`. * @dev Reverts if `roleId` does not represent an initialized, exclusive role. * @param roleId the ExclusiveRole membership to check. * @return the address of the current ExclusiveRole member. */ function getMember(uint256 roleId) public view onlyExclusive(roleId) returns (address) { return roles[roleId].exclusiveRoleMembership.getMember(); } /** * @notice Adds `newMember` to the shared role, `roleId`. * @dev Reverts if `roleId` does not represent an initialized, SharedRole or if the caller is not a member of the * managing role for `roleId`. * @param roleId the SharedRole membership to modify. * @param newMember the new SharedRole member. */ function addMember(uint256 roleId, address newMember) public onlyShared(roleId) onlyRoleManager(roleId) { roles[roleId].sharedRoleMembership.addMember(newMember); emit AddedSharedMember(roleId, newMember, msg.sender); } /** * @notice Removes `memberToRemove` from the shared role, `roleId`. * @dev Reverts if `roleId` does not represent an initialized, SharedRole or if the caller is not a member of the * managing role for `roleId`. * @param roleId the SharedRole membership to modify. * @param memberToRemove the current SharedRole member to remove. */ function removeMember(uint256 roleId, address memberToRemove) public onlyShared(roleId) onlyRoleManager(roleId) { roles[roleId].sharedRoleMembership.removeMember(memberToRemove); emit RemovedSharedMember(roleId, memberToRemove, msg.sender); } /** * @notice Removes caller from the role, `roleId`. * @dev Reverts if the caller is not a member of the role for `roleId` or if `roleId` is not an * initialized, SharedRole. * @param roleId the SharedRole membership to modify. */ function renounceMembership(uint256 roleId) public onlyShared(roleId) onlyRoleHolder(roleId) { roles[roleId].sharedRoleMembership.removeMember(msg.sender); emit RemovedSharedMember(roleId, msg.sender, msg.sender); } /** * @notice Reverts if `roleId` is not initialized. */ modifier onlyValidRole(uint256 roleId) { require(roles[roleId].roleType != RoleType.Invalid, "Attempted to use an invalid roleId"); _; } /** * @notice Reverts if `roleId` is initialized. */ modifier onlyInvalidRole(uint256 roleId) { require(roles[roleId].roleType == RoleType.Invalid, "Cannot use a pre-existing role"); _; } /** * @notice Internal method to initialize a shared role, `roleId`, which will be managed by `managingRoleId`. * `initialMembers` will be immediately added to the role. * @dev Should be called by derived contracts, usually at construction time. Will revert if the role is already * initialized. */ function _createSharedRole( uint256 roleId, uint256 managingRoleId, address[] memory initialMembers ) internal onlyInvalidRole(roleId) { Role storage role = roles[roleId]; role.roleType = RoleType.Shared; role.managingRole = managingRoleId; role.sharedRoleMembership.init(initialMembers); require( roles[managingRoleId].roleType != RoleType.Invalid, "Attempted to use an invalid role to manage a shared role" ); } /** * @notice Internal method to initialize an exclusive role, `roleId`, which will be managed by `managingRoleId`. * `initialMember` will be immediately added to the role. * @dev Should be called by derived contracts, usually at construction time. Will revert if the role is already * initialized. */ function _createExclusiveRole( uint256 roleId, uint256 managingRoleId, address initialMember ) internal onlyInvalidRole(roleId) { Role storage role = roles[roleId]; role.roleType = RoleType.Exclusive; role.managingRole = managingRoleId; role.exclusiveRoleMembership.init(initialMember); require( roles[managingRoleId].roleType != RoleType.Invalid, "Attempted to use an invalid role to manage an exclusive role" ); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/math/SignedSafeMath.sol"; /** * @title Library for fixed point arithmetic on uints */ library FixedPoint { using SafeMath for uint256; using SignedSafeMath for int256; // Supports 18 decimals. E.g., 1e18 represents "1", 5e17 represents "0.5". // For unsigned values: // This can represent a value up to (2^256 - 1)/10^18 = ~10^59. 10^59 will be stored internally as uint256 10^77. uint256 private constant FP_SCALING_FACTOR = 10**18; // --------------------------------------- UNSIGNED ----------------------------------------------------------------------------- struct Unsigned { uint256 rawValue; } /** * @notice Constructs an `Unsigned` from an unscaled uint, e.g., `b=5` gets stored internally as `5*(10**18)`. * @param a uint to convert into a FixedPoint. * @return the converted FixedPoint. */ function fromUnscaledUint(uint256 a) internal pure returns (Unsigned memory) { return Unsigned(a.mul(FP_SCALING_FACTOR)); } /** * @notice Whether `a` is equal to `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if equal, or False. */ function isEqual(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue == fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is equal to `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if equal, or False. */ function isEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue == b.rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if `a > b`, or False. */ function isGreaterThan(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue > b.rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if `a > b`, or False. */ function isGreaterThan(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue > fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a uint256. * @param b a FixedPoint. * @return True if `a > b`, or False. */ function isGreaterThan(uint256 a, Unsigned memory b) internal pure returns (bool) { return fromUnscaledUint(a).rawValue > b.rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue >= b.rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue >= fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a uint256. * @param b a FixedPoint. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(uint256 a, Unsigned memory b) internal pure returns (bool) { return fromUnscaledUint(a).rawValue >= b.rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if `a < b`, or False. */ function isLessThan(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue < b.rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if `a < b`, or False. */ function isLessThan(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue < fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a uint256. * @param b a FixedPoint. * @return True if `a < b`, or False. */ function isLessThan(uint256 a, Unsigned memory b) internal pure returns (bool) { return fromUnscaledUint(a).rawValue < b.rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue <= b.rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue <= fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a uint256. * @param b a FixedPoint. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(uint256 a, Unsigned memory b) internal pure returns (bool) { return fromUnscaledUint(a).rawValue <= b.rawValue; } /** * @notice The minimum of `a` and `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return the minimum of `a` and `b`. */ function min(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { return a.rawValue < b.rawValue ? a : b; } /** * @notice The maximum of `a` and `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return the maximum of `a` and `b`. */ function max(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { return a.rawValue > b.rawValue ? a : b; } /** * @notice Adds two `Unsigned`s, reverting on overflow. * @param a a FixedPoint. * @param b a FixedPoint. * @return the sum of `a` and `b`. */ function add(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { return Unsigned(a.rawValue.add(b.rawValue)); } /** * @notice Adds an `Unsigned` to an unscaled uint, reverting on overflow. * @param a a FixedPoint. * @param b a uint256. * @return the sum of `a` and `b`. */ function add(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { return add(a, fromUnscaledUint(b)); } /** * @notice Subtracts two `Unsigned`s, reverting on overflow. * @param a a FixedPoint. * @param b a FixedPoint. * @return the difference of `a` and `b`. */ function sub(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { return Unsigned(a.rawValue.sub(b.rawValue)); } /** * @notice Subtracts an unscaled uint256 from an `Unsigned`, reverting on overflow. * @param a a FixedPoint. * @param b a uint256. * @return the difference of `a` and `b`. */ function sub(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { return sub(a, fromUnscaledUint(b)); } /** * @notice Subtracts an `Unsigned` from an unscaled uint256, reverting on overflow. * @param a a uint256. * @param b a FixedPoint. * @return the difference of `a` and `b`. */ function sub(uint256 a, Unsigned memory b) internal pure returns (Unsigned memory) { return sub(fromUnscaledUint(a), b); } /** * @notice Multiplies two `Unsigned`s, reverting on overflow. * @dev This will "floor" the product. * @param a a FixedPoint. * @param b a FixedPoint. * @return the product of `a` and `b`. */ function mul(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { // There are two caveats with this computation: // 1. Max output for the represented number is ~10^41, otherwise an intermediate value overflows. 10^41 is // stored internally as a uint256 ~10^59. // 2. Results that can't be represented exactly are truncated not rounded. E.g., 1.4 * 2e-18 = 2.8e-18, which // would round to 3, but this computation produces the result 2. // No need to use SafeMath because FP_SCALING_FACTOR != 0. return Unsigned(a.rawValue.mul(b.rawValue) / FP_SCALING_FACTOR); } /** * @notice Multiplies an `Unsigned` and an unscaled uint256, reverting on overflow. * @dev This will "floor" the product. * @param a a FixedPoint. * @param b a uint256. * @return the product of `a` and `b`. */ function mul(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { return Unsigned(a.rawValue.mul(b)); } /** * @notice Multiplies two `Unsigned`s and "ceil's" the product, reverting on overflow. * @param a a FixedPoint. * @param b a FixedPoint. * @return the product of `a` and `b`. */ function mulCeil(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { uint256 mulRaw = a.rawValue.mul(b.rawValue); uint256 mulFloor = mulRaw / FP_SCALING_FACTOR; uint256 mod = mulRaw.mod(FP_SCALING_FACTOR); if (mod != 0) { return Unsigned(mulFloor.add(1)); } else { return Unsigned(mulFloor); } } /** * @notice Multiplies an `Unsigned` and an unscaled uint256 and "ceil's" the product, reverting on overflow. * @param a a FixedPoint. * @param b a FixedPoint. * @return the product of `a` and `b`. */ function mulCeil(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { // Since b is an int, there is no risk of truncation and we can just mul it normally return Unsigned(a.rawValue.mul(b)); } /** * @notice Divides one `Unsigned` by an `Unsigned`, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a FixedPoint numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function div(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { // There are two caveats with this computation: // 1. Max value for the number dividend `a` represents is ~10^41, otherwise an intermediate value overflows. // 10^41 is stored internally as a uint256 10^59. // 2. Results that can't be represented exactly are truncated not rounded. E.g., 2 / 3 = 0.6 repeating, which // would round to 0.666666666666666667, but this computation produces the result 0.666666666666666666. return Unsigned(a.rawValue.mul(FP_SCALING_FACTOR).div(b.rawValue)); } /** * @notice Divides one `Unsigned` by an unscaled uint256, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a FixedPoint numerator. * @param b a uint256 denominator. * @return the quotient of `a` divided by `b`. */ function div(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { return Unsigned(a.rawValue.div(b)); } /** * @notice Divides one unscaled uint256 by an `Unsigned`, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a uint256 numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function div(uint256 a, Unsigned memory b) internal pure returns (Unsigned memory) { return div(fromUnscaledUint(a), b); } /** * @notice Divides one `Unsigned` by an `Unsigned` and "ceil's" the quotient, reverting on overflow or division by 0. * @param a a FixedPoint numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function divCeil(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { uint256 aScaled = a.rawValue.mul(FP_SCALING_FACTOR); uint256 divFloor = aScaled.div(b.rawValue); uint256 mod = aScaled.mod(b.rawValue); if (mod != 0) { return Unsigned(divFloor.add(1)); } else { return Unsigned(divFloor); } } /** * @notice Divides one `Unsigned` by an unscaled uint256 and "ceil's" the quotient, reverting on overflow or division by 0. * @param a a FixedPoint numerator. * @param b a uint256 denominator. * @return the quotient of `a` divided by `b`. */ function divCeil(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { // Because it is possible that a quotient gets truncated, we can't just call "Unsigned(a.rawValue.div(b))" // similarly to mulCeil with a uint256 as the second parameter. Therefore we need to convert b into an Unsigned. // This creates the possibility of overflow if b is very large. return divCeil(a, fromUnscaledUint(b)); } /** * @notice Raises an `Unsigned` to the power of an unscaled uint256, reverting on overflow. E.g., `b=2` squares `a`. * @dev This will "floor" the result. * @param a a FixedPoint numerator. * @param b a uint256 denominator. * @return output is `a` to the power of `b`. */ function pow(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory output) { output = fromUnscaledUint(1); for (uint256 i = 0; i < b; i = i.add(1)) { output = mul(output, a); } } // ------------------------------------------------- SIGNED ------------------------------------------------------------- // Supports 18 decimals. E.g., 1e18 represents "1", 5e17 represents "0.5". // For signed values: // This can represent a value up (or down) to +-(2^255 - 1)/10^18 = ~10^58. 10^58 will be stored internally as int256 10^76. int256 private constant SFP_SCALING_FACTOR = 10**18; struct Signed { int256 rawValue; } function fromSigned(Signed memory a) internal pure returns (Unsigned memory) { require(a.rawValue >= 0, "Negative value provided"); return Unsigned(uint256(a.rawValue)); } function fromUnsigned(Unsigned memory a) internal pure returns (Signed memory) { require(a.rawValue <= uint256(type(int256).max), "Unsigned too large"); return Signed(int256(a.rawValue)); } /** * @notice Constructs a `Signed` from an unscaled int, e.g., `b=5` gets stored internally as `5*(10**18)`. * @param a int to convert into a FixedPoint.Signed. * @return the converted FixedPoint.Signed. */ function fromUnscaledInt(int256 a) internal pure returns (Signed memory) { return Signed(a.mul(SFP_SCALING_FACTOR)); } /** * @notice Whether `a` is equal to `b`. * @param a a FixedPoint.Signed. * @param b a int256. * @return True if equal, or False. */ function isEqual(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue == fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is equal to `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if equal, or False. */ function isEqual(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue == b.rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if `a > b`, or False. */ function isGreaterThan(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue > b.rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a FixedPoint.Signed. * @param b an int256. * @return True if `a > b`, or False. */ function isGreaterThan(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue > fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a an int256. * @param b a FixedPoint.Signed. * @return True if `a > b`, or False. */ function isGreaterThan(int256 a, Signed memory b) internal pure returns (bool) { return fromUnscaledInt(a).rawValue > b.rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue >= b.rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a FixedPoint.Signed. * @param b an int256. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue >= fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a an int256. * @param b a FixedPoint.Signed. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(int256 a, Signed memory b) internal pure returns (bool) { return fromUnscaledInt(a).rawValue >= b.rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if `a < b`, or False. */ function isLessThan(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue < b.rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a FixedPoint.Signed. * @param b an int256. * @return True if `a < b`, or False. */ function isLessThan(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue < fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is less than `b`. * @param a an int256. * @param b a FixedPoint.Signed. * @return True if `a < b`, or False. */ function isLessThan(int256 a, Signed memory b) internal pure returns (bool) { return fromUnscaledInt(a).rawValue < b.rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue <= b.rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a FixedPoint.Signed. * @param b an int256. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue <= fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a an int256. * @param b a FixedPoint.Signed. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(int256 a, Signed memory b) internal pure returns (bool) { return fromUnscaledInt(a).rawValue <= b.rawValue; } /** * @notice The minimum of `a` and `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the minimum of `a` and `b`. */ function min(Signed memory a, Signed memory b) internal pure returns (Signed memory) { return a.rawValue < b.rawValue ? a : b; } /** * @notice The maximum of `a` and `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the maximum of `a` and `b`. */ function max(Signed memory a, Signed memory b) internal pure returns (Signed memory) { return a.rawValue > b.rawValue ? a : b; } /** * @notice Adds two `Signed`s, reverting on overflow. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the sum of `a` and `b`. */ function add(Signed memory a, Signed memory b) internal pure returns (Signed memory) { return Signed(a.rawValue.add(b.rawValue)); } /** * @notice Adds an `Signed` to an unscaled int, reverting on overflow. * @param a a FixedPoint.Signed. * @param b an int256. * @return the sum of `a` and `b`. */ function add(Signed memory a, int256 b) internal pure returns (Signed memory) { return add(a, fromUnscaledInt(b)); } /** * @notice Subtracts two `Signed`s, reverting on overflow. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the difference of `a` and `b`. */ function sub(Signed memory a, Signed memory b) internal pure returns (Signed memory) { return Signed(a.rawValue.sub(b.rawValue)); } /** * @notice Subtracts an unscaled int256 from an `Signed`, reverting on overflow. * @param a a FixedPoint.Signed. * @param b an int256. * @return the difference of `a` and `b`. */ function sub(Signed memory a, int256 b) internal pure returns (Signed memory) { return sub(a, fromUnscaledInt(b)); } /** * @notice Subtracts an `Signed` from an unscaled int256, reverting on overflow. * @param a an int256. * @param b a FixedPoint.Signed. * @return the difference of `a` and `b`. */ function sub(int256 a, Signed memory b) internal pure returns (Signed memory) { return sub(fromUnscaledInt(a), b); } /** * @notice Multiplies two `Signed`s, reverting on overflow. * @dev This will "floor" the product. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the product of `a` and `b`. */ function mul(Signed memory a, Signed memory b) internal pure returns (Signed memory) { // There are two caveats with this computation: // 1. Max output for the represented number is ~10^41, otherwise an intermediate value overflows. 10^41 is // stored internally as an int256 ~10^59. // 2. Results that can't be represented exactly are truncated not rounded. E.g., 1.4 * 2e-18 = 2.8e-18, which // would round to 3, but this computation produces the result 2. // No need to use SafeMath because SFP_SCALING_FACTOR != 0. return Signed(a.rawValue.mul(b.rawValue) / SFP_SCALING_FACTOR); } /** * @notice Multiplies an `Signed` and an unscaled int256, reverting on overflow. * @dev This will "floor" the product. * @param a a FixedPoint.Signed. * @param b an int256. * @return the product of `a` and `b`. */ function mul(Signed memory a, int256 b) internal pure returns (Signed memory) { return Signed(a.rawValue.mul(b)); } /** * @notice Multiplies two `Signed`s and "ceil's" the product, reverting on overflow. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the product of `a` and `b`. */ function mulAwayFromZero(Signed memory a, Signed memory b) internal pure returns (Signed memory) { int256 mulRaw = a.rawValue.mul(b.rawValue); int256 mulTowardsZero = mulRaw / SFP_SCALING_FACTOR; // Manual mod because SignedSafeMath doesn't support it. int256 mod = mulRaw % SFP_SCALING_FACTOR; if (mod != 0) { bool isResultPositive = isLessThan(a, 0) == isLessThan(b, 0); int256 valueToAdd = isResultPositive ? int256(1) : int256(-1); return Signed(mulTowardsZero.add(valueToAdd)); } else { return Signed(mulTowardsZero); } } /** * @notice Multiplies an `Signed` and an unscaled int256 and "ceil's" the product, reverting on overflow. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the product of `a` and `b`. */ function mulAwayFromZero(Signed memory a, int256 b) internal pure returns (Signed memory) { // Since b is an int, there is no risk of truncation and we can just mul it normally return Signed(a.rawValue.mul(b)); } /** * @notice Divides one `Signed` by an `Signed`, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a FixedPoint numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function div(Signed memory a, Signed memory b) internal pure returns (Signed memory) { // There are two caveats with this computation: // 1. Max value for the number dividend `a` represents is ~10^41, otherwise an intermediate value overflows. // 10^41 is stored internally as an int256 10^59. // 2. Results that can't be represented exactly are truncated not rounded. E.g., 2 / 3 = 0.6 repeating, which // would round to 0.666666666666666667, but this computation produces the result 0.666666666666666666. return Signed(a.rawValue.mul(SFP_SCALING_FACTOR).div(b.rawValue)); } /** * @notice Divides one `Signed` by an unscaled int256, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a FixedPoint numerator. * @param b an int256 denominator. * @return the quotient of `a` divided by `b`. */ function div(Signed memory a, int256 b) internal pure returns (Signed memory) { return Signed(a.rawValue.div(b)); } /** * @notice Divides one unscaled int256 by an `Signed`, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a an int256 numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function div(int256 a, Signed memory b) internal pure returns (Signed memory) { return div(fromUnscaledInt(a), b); } /** * @notice Divides one `Signed` by an `Signed` and "ceil's" the quotient, reverting on overflow or division by 0. * @param a a FixedPoint numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function divAwayFromZero(Signed memory a, Signed memory b) internal pure returns (Signed memory) { int256 aScaled = a.rawValue.mul(SFP_SCALING_FACTOR); int256 divTowardsZero = aScaled.div(b.rawValue); // Manual mod because SignedSafeMath doesn't support it. int256 mod = aScaled % b.rawValue; if (mod != 0) { bool isResultPositive = isLessThan(a, 0) == isLessThan(b, 0); int256 valueToAdd = isResultPositive ? int256(1) : int256(-1); return Signed(divTowardsZero.add(valueToAdd)); } else { return Signed(divTowardsZero); } } /** * @notice Divides one `Signed` by an unscaled int256 and "ceil's" the quotient, reverting on overflow or division by 0. * @param a a FixedPoint numerator. * @param b an int256 denominator. * @return the quotient of `a` divided by `b`. */ function divAwayFromZero(Signed memory a, int256 b) internal pure returns (Signed memory) { // Because it is possible that a quotient gets truncated, we can't just call "Signed(a.rawValue.div(b))" // similarly to mulCeil with an int256 as the second parameter. Therefore we need to convert b into an Signed. // This creates the possibility of overflow if b is very large. return divAwayFromZero(a, fromUnscaledInt(b)); } /** * @notice Raises an `Signed` to the power of an unscaled uint256, reverting on overflow. E.g., `b=2` squares `a`. * @dev This will "floor" the result. * @param a a FixedPoint.Signed. * @param b a uint256 (negative exponents are not allowed). * @return output is `a` to the power of `b`. */ function pow(Signed memory a, uint256 b) internal pure returns (Signed memory output) { output = fromUnscaledInt(1); for (uint256 i = 0; i < b; i = i.add(1)) { output = mul(output, a); } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Financial contract facing Oracle interface. * @dev Interface used by financial contracts to interact with the Oracle. Voters will use a different interface. */ abstract contract OracleInterface { /** * @notice Enqueues a request (if a request isn't already present) for the given `identifier`, `time` pair. * @dev Time must be in the past and the identifier must be supported. * @param identifier uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested. * @param time unix timestamp for the price request. */ function requestPrice(bytes32 identifier, uint256 time) public virtual; /** * @notice Whether the price for `identifier` and `time` is available. * @dev Time must be in the past and the identifier must be supported. * @param identifier uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested. * @param time unix timestamp for the price request. * @return bool if the DVM has resolved to a price for the given identifier and timestamp. */ function hasPrice(bytes32 identifier, uint256 time) public view virtual returns (bool); /** * @notice Gets the price for `identifier` and `time` if it has already been requested and resolved. * @dev If the price is not available, the method reverts. * @param identifier uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested. * @param time unix timestamp for the price request. * @return int256 representing the resolved price for the given identifier and timestamp. */ function getPrice(bytes32 identifier, uint256 time) public view virtual returns (int256); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; interface AddressWhitelistInterface { function addToWhitelist(address newElement) external; function removeFromWhitelist(address newElement) external virtual; function isOnWhitelist(address newElement) external view virtual returns (bool); function getWhitelist() external view virtual returns (address[] memory); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title Financial contract facing Oracle interface. * @dev Interface used by financial contracts to interact with the Oracle. Voters will use a different interface. */ abstract contract OptimisticOracleInterface { // Struct representing the state of a price request. enum State { Invalid, // Never requested. Requested, // Requested, no other actions taken. Proposed, // Proposed, but not expired or disputed yet. Expired, // Proposed, not disputed, past liveness. Disputed, // Disputed, but no DVM price returned yet. Resolved, // Disputed and DVM price is available. Settled // Final price has been set in the contract (can get here from Expired or Resolved). } // Struct representing a price request. struct Request { address proposer; // Address of the proposer. address disputer; // Address of the disputer. IERC20 currency; // ERC20 token used to pay rewards and fees. bool settled; // True if the request is settled. bool refundOnDispute; // True if the requester should be refunded their reward on dispute. int256 proposedPrice; // Price that the proposer submitted. int256 resolvedPrice; // Price resolved once the request is settled. uint256 expirationTime; // Time at which the request auto-settles without a dispute. uint256 reward; // Amount of the currency to pay to the proposer on settlement. uint256 finalFee; // Final fee to pay to the Store upon request to the DVM. uint256 bond; // Bond that the proposer and disputer must pay on top of the final fee. uint256 customLiveness; // Custom liveness value set by the requester. } // This value must be <= the Voting contract's `ancillaryBytesLimit` value otherwise it is possible // that a price can be requested to this contract successfully, but cannot be disputed because the DVM refuses // to accept a price request made with ancillary data length over a certain size. uint256 public constant ancillaryBytesLimit = 8192; /** * @notice Requests a new price. * @param identifier price identifier being requested. * @param timestamp timestamp of the price being requested. * @param ancillaryData ancillary data representing additional args being passed with the price request. * @param currency ERC20 token used for payment of rewards and fees. Must be approved for use with the DVM. * @param reward reward offered to a successful proposer. Will be pulled from the caller. Note: this can be 0, * which could make sense if the contract requests and proposes the value in the same call or * provides its own reward system. * @return totalBond default bond (final fee) + final fee that the proposer and disputer will be required to pay. * This can be changed with a subsequent call to setBond(). */ function requestPrice( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, IERC20 currency, uint256 reward ) external virtual returns (uint256 totalBond); /** * @notice Set the proposal bond associated with a price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @param bond custom bond amount to set. * @return totalBond new bond + final fee that the proposer and disputer will be required to pay. This can be * changed again with a subsequent call to setBond(). */ function setBond( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, uint256 bond ) external virtual returns (uint256 totalBond); /** * @notice Sets the request to refund the reward if the proposal is disputed. This can help to "hedge" the caller * in the event of a dispute-caused delay. Note: in the event of a dispute, the winner still receives the other's * bond, so there is still profit to be made even if the reward is refunded. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. */ function setRefundOnDispute( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) external virtual; /** * @notice Sets a custom liveness value for the request. Liveness is the amount of time a proposal must wait before * being auto-resolved. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @param customLiveness new custom liveness. */ function setCustomLiveness( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, uint256 customLiveness ) external virtual; /** * @notice Proposes a price value on another address' behalf. Note: this address will receive any rewards that come * from this proposal. However, any bonds are pulled from the caller. * @param proposer address to set as the proposer. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @param proposedPrice price being proposed. * @return totalBond the amount that's pulled from the caller's wallet as a bond. The bond will be returned to * the proposer once settled if the proposal is correct. */ function proposePriceFor( address proposer, address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, int256 proposedPrice ) public virtual returns (uint256 totalBond); /** * @notice Proposes a price value for an existing price request. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @param proposedPrice price being proposed. * @return totalBond the amount that's pulled from the proposer's wallet as a bond. The bond will be returned to * the proposer once settled if the proposal is correct. */ function proposePrice( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, int256 proposedPrice ) external virtual returns (uint256 totalBond); /** * @notice Disputes a price request with an active proposal on another address' behalf. Note: this address will * receive any rewards that come from this dispute. However, any bonds are pulled from the caller. * @param disputer address to set as the disputer. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return totalBond the amount that's pulled from the caller's wallet as a bond. The bond will be returned to * the disputer once settled if the dispute was value (the proposal was incorrect). */ function disputePriceFor( address disputer, address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) public virtual returns (uint256 totalBond); /** * @notice Disputes a price value for an existing price request with an active proposal. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return totalBond the amount that's pulled from the disputer's wallet as a bond. The bond will be returned to * the disputer once settled if the dispute was valid (the proposal was incorrect). */ function disputePrice( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) external virtual returns (uint256 totalBond); /** * @notice Retrieves a price that was previously requested by a caller. Reverts if the request is not settled * or settleable. Note: this method is not view so that this call may actually settle the price request if it * hasn't been settled. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return resolved price. */ function settleAndGetPrice( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) external virtual returns (int256); /** * @notice Attempts to settle an outstanding price request. Will revert if it isn't settleable. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return payout the amount that the "winner" (proposer or disputer) receives on settlement. This amount includes * the returned bonds as well as additional rewards. */ function settle( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) external virtual returns (uint256 payout); /** * @notice Gets the current data structure containing all information about a price request. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return the Request data structure. */ function getRequest( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) public view virtual returns (Request memory); /** * @notice Returns the state of a price request. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return the State enum value. */ function getState( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) public view virtual returns (State); /** * @notice Checks if a given request has resolved or been settled (i.e the optimistic oracle has a price). * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return true if price has resolved or settled, false otherwise. */ function hasPrice( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) public view virtual returns (bool); function stampAncillaryData(bytes memory ancillaryData, address requester) public view virtual returns (bytes memory); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Interface for whitelists of supported identifiers that the oracle can provide prices for. */ interface IdentifierWhitelistInterface { /** * @notice Adds the provided identifier as a supported identifier. * @dev Price requests using this identifier will succeed after this call. * @param identifier bytes32 encoding of the string identifier. Eg: BTC/USD. */ function addSupportedIdentifier(bytes32 identifier) external; /** * @notice Removes the identifier from the whitelist. * @dev Price requests using this identifier will no longer succeed after this call. * @param identifier bytes32 encoding of the string identifier. Eg: BTC/USD. */ function removeSupportedIdentifier(bytes32 identifier) external; /** * @notice Checks whether an identifier is on the whitelist. * @param identifier bytes32 encoding of the string identifier. Eg: BTC/USD. * @return bool if the identifier is supported (or not). */ function isIdentifierSupported(bytes32 identifier) external view returns (bool); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Stores common interface names used throughout the DVM by registration in the Finder. */ library OracleInterfaces { bytes32 public constant Oracle = "Oracle"; bytes32 public constant IdentifierWhitelist = "IdentifierWhitelist"; bytes32 public constant Store = "Store"; bytes32 public constant FinancialContractsAdmin = "FinancialContractsAdmin"; bytes32 public constant Registry = "Registry"; bytes32 public constant CollateralWhitelist = "CollateralWhitelist"; bytes32 public constant OptimisticOracle = "OptimisticOracle"; bytes32 public constant Bridge = "Bridge"; bytes32 public constant GenericHandler = "GenericHandler"; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 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"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (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 functionCall(target, data, "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"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(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) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // 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 // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SignedSafeMath { /** * @dev Returns the multiplication of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(int256 a, int256 b) internal pure returns (int256) { return a * b; } /** * @dev Returns the integer division of two signed integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(int256 a, int256 b) internal pure returns (int256) { return a / b; } /** * @dev Returns the subtraction of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(int256 a, int256 b) internal pure returns (int256) { return a - b; } /** * @dev Returns the addition of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(int256 a, int256 b) internal pure returns (int256) { return a + b; } }
{ "optimizer": { "enabled": true, "runs": 199 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
[{"inputs":[{"internalType":"contract FinderInterface","name":"_finder","type":"address"},{"internalType":"contract TokenFactory","name":"_tokenFactory","type":"address"},{"internalType":"address","name":"_timer","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"longShortPair","type":"address"},{"indexed":true,"internalType":"address","name":"deployerAddress","type":"address"},{"indexed":false,"internalType":"address","name":"longToken","type":"address"},{"indexed":false,"internalType":"address","name":"shortToken","type":"address"}],"name":"CreatedLongShortPair","type":"event"},{"inputs":[{"components":[{"internalType":"string","name":"pairName","type":"string"},{"internalType":"uint64","name":"expirationTimestamp","type":"uint64"},{"internalType":"uint256","name":"collateralPerPair","type":"uint256"},{"internalType":"bytes32","name":"priceIdentifier","type":"bytes32"},{"internalType":"string","name":"longSynthName","type":"string"},{"internalType":"string","name":"longSynthSymbol","type":"string"},{"internalType":"string","name":"shortSynthName","type":"string"},{"internalType":"string","name":"shortSynthSymbol","type":"string"},{"internalType":"contract IERC20Standard","name":"collateralToken","type":"address"},{"internalType":"contract LongShortPairFinancialProductLibrary","name":"financialProductLibrary","type":"address"},{"internalType":"bytes","name":"customAncillaryData","type":"bytes"},{"internalType":"uint256","name":"prepaidProposerReward","type":"uint256"},{"internalType":"uint256","name":"optimisticOracleLivenessTime","type":"uint256"},{"internalType":"uint256","name":"optimisticOracleProposerBond","type":"uint256"}],"internalType":"struct LongShortPairCreator.CreatorParams","name":"params","type":"tuple"}],"name":"createLongShortPair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"finder","outputs":[{"internalType":"contract FinderInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"time","type":"uint256"}],"name":"setCurrentTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"timerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenFactory","outputs":[{"internalType":"contract TokenFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60806040523480156200001157600080fd5b5060405162003db238038062003db2833981016040819052620000349162000124565b600080546001600160a81b0319166001600160a01b03831617600160a01b1790556200005f620000c4565b620000726000805460ff60a01b19169055565b600180546001600160a01b038085166001600160a01b0319928316179092556002805492861692909116919091179055620000bb6000805460ff60a01b1916600160a01b179055565b50505062000190565b600054600160a01b900460ff16620001225760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640160405180910390fd5b565b60008060006060848603121562000139578283fd5b8351620001468162000177565b6020850151909350620001598162000177565b60408501519092506200016c8162000177565b809150509250925092565b6001600160a01b03811681146200018d57600080fd5b50565b613c1280620001a06000396000f3fe60806040523480156200001157600080fd5b50600436106200006a5760003560e01c806308dda04f146200006f5780631c39c38d14620000a357806322f8e56614620000b757806329cb924d14620000d0578063b9a3c84c14620000e9578063e77772fe14620000fd575b600080fd5b620000866200008036600462000dd4565b62000111565b6040516001600160a01b0390911681526020015b60405180910390f35b60005462000086906001600160a01b031681565b620000ce620000c836600462000f7a565b62000808565b005b620000da62000881565b6040519081526020016200009a565b60025462000086906001600160a01b031681565b60015462000086906001600160a01b031681565b60006200011d62000926565b620001306000805460ff60a01b19169055565b608082015151620001885760405162461bcd60e51b815260206004820152601b60248201527f4d697373696e67206c6f6e672073796e746865746963206e616d65000000000060448201526064015b60405180910390fd5b60c082015151620001dc5760405162461bcd60e51b815260206004820152601c60248201527f4d697373696e672073686f72742073796e746865746963206e616d650000000060448201526064016200017f565b60a082015151620002305760405162461bcd60e51b815260206004820152601d60248201527f4d697373696e67206c6f6e672073796e7468657469632073796d626f6c00000060448201526064016200017f565b60e082015151620002845760405162461bcd60e51b815260206004820152601e60248201527f4d697373696e672073686f72742073796e7468657469632073796d626f6c000060448201526064016200017f565b60006200029683610100015162000983565b600154608085015160a086015160405163e8a0aed360e01b81529394506000936001600160a01b039093169263e8a0aed392620002da929091879060040162001030565b602060405180830381600087803b158015620002f557600080fd5b505af11580156200030a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000330919062000db5565b60015460c086015160e087015160405163e8a0aed360e01b81529394506000936001600160a01b039093169263e8a0aed39262000374929091889060040162001030565b602060405180830381600087803b1580156200038f57600080fd5b505af1158015620003a4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003ca919062000db5565b90506000620004f7868484604080516101c08101825260608082526000602083018190529282018390528082018390526080820183905260a0820183905260c0820183905260e0820183905261010082015261012081018290526101408101829052610160810182905261018081018290526101a08101919091528351815260208085015167ffffffffffffffff16908201526040808501519082015260608085015190820152610100808501516001600160a01b0390811660c084015261012080870151821660e08501526101408088015193850193909352610160808801519185019190915261018080880151938501939093526101a09687015190840152938416608083015291831660a08201526002548316918101919091526000549091169181019190915290565b604051620005059062000cd0565b6200051191906200106d565b604051809103906000f0801580156200052e573d6000803e3d6000fd5b50610160870151909150156200056a576200056a33828861016001518961010001516001600160a01b031662000a05909392919063ffffffff16565b604051634c1d96ab60e11b81526001600160a01b03808316600483015282919085169063983b2d5690602401600060405180830381600087803b158015620005b157600080fd5b505af1158015620005c6573d6000803e3d6000fd5b5050604051637a231bdd60e11b81526001600160a01b0384811660048301528716925063f44637ba9150602401600060405180830381600087803b1580156200060e57600080fd5b505af115801562000623573d6000803e3d6000fd5b50506040516339e6401560e11b81526001600160a01b038481166004830152871692506373cc802a9150602401600060405180830381600087803b1580156200066b57600080fd5b505af115801562000680573d6000803e3d6000fd5b5050604051634c1d96ab60e11b81526001600160a01b0384811660048301528616925063983b2d569150602401600060405180830381600087803b158015620006c857600080fd5b505af1158015620006dd573d6000803e3d6000fd5b5050604051637a231bdd60e11b81526001600160a01b0384811660048301528616925063f44637ba9150602401600060405180830381600087803b1580156200072557600080fd5b505af11580156200073a573d6000803e3d6000fd5b50506040516339e6401560e11b81526001600160a01b038481166004830152861692506373cc802a9150602401600060405180830381600087803b1580156200078257600080fd5b505af115801562000797573d6000803e3d6000fd5b5050604080516001600160a01b0388811682528781166020830152339450851692507fd007d1b8d04c15a0cadef913ed5a5c4b381d3dcd2927c2de9a6dcc1ddab2d2f8910160405180910390a3945050505050620008036000805460ff60a01b1916600160a01b179055565b919050565b6000546001600160a01b03166200081e57600080fd5b60005460405163117c72b360e11b8152600481018390526001600160a01b03909116906322f8e56690602401600060405180830381600087803b1580156200086557600080fd5b505af11580156200087a573d6000803e3d6000fd5b5050505050565b600080546001600160a01b031615620009215760008054906101000a90046001600160a01b03166001600160a01b03166329cb924d6040518163ffffffff1660e01b815260040160206040518083038186803b158015620008e157600080fd5b505afa158015620008f6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200091c919062000f93565b905090565b504290565b600054600160a01b900460ff16620009815760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016200017f565b565b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015620009bf57600080fd5b505afa925050508015620009f2575060408051601f3d908101601f19168201909252620009ef9181019062000fac565b60015b620009ff57506012919050565b92915050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b17905262000a6190859062000a67565b50505050565b600062000abe826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031662000b459092919063ffffffff16565b80519091501562000b40578080602001905181019062000adf919062000d93565b62000b405760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016200017f565b505050565b606062000b56848460008562000b60565b90505b9392505050565b60608247101562000bc35760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016200017f565b843b62000c135760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016200017f565b600080866001600160a01b0316858760405162000c31919062000ffd565b60006040518083038185875af1925050503d806000811462000c70576040519150601f19603f3d011682016040523d82523d6000602084013e62000c75565b606091505b509150915062000c8782828662000c92565b979650505050505050565b6060831562000ca357508162000b59565b82511562000cb45782518084602001fd5b8160405162461bcd60e51b81526004016200017f91906200101b565b6129ab806200123283390190565b600082601f83011262000cef578081fd5b813567ffffffffffffffff8082111562000d0d5762000d0d62001202565b604051601f8301601f19908116603f0116810190828211818310171562000d385762000d3862001202565b8160405283815286602085880101111562000d51578485fd5b8360208701602083013792830160200193909352509392505050565b8035620008038162001218565b803567ffffffffffffffff811681146200080357600080fd5b60006020828403121562000da5578081fd5b8151801515811462000b59578182fd5b60006020828403121562000dc7578081fd5b815162000b598162001218565b60006020828403121562000de6578081fd5b813567ffffffffffffffff8082111562000dfe578283fd5b908301906101c0828603121562000e13578283fd5b62000e1d620011a6565b82358281111562000e2c578485fd5b62000e3a8782860162000cde565b82525062000e4b6020840162000d7a565b6020820152604083013560408201526060830135606082015260808301358281111562000e76578485fd5b62000e848782860162000cde565b60808301525060a08301358281111562000e9c578485fd5b62000eaa8782860162000cde565b60a08301525060c08301358281111562000ec2578485fd5b62000ed08782860162000cde565b60c08301525060e08301358281111562000ee8578485fd5b62000ef68782860162000cde565b60e08301525061010062000f0c81850162000d6d565b9082015261012062000f2084820162000d6d565b90820152610140838101358381111562000f38578586fd5b62000f468882870162000cde565b9183019190915250610160838101359082015261018080840135908201526101a09283013592810192909252509392505050565b60006020828403121562000f8c578081fd5b5035919050565b60006020828403121562000fa5578081fd5b5051919050565b60006020828403121562000fbe578081fd5b815160ff8116811462000b59578182fd5b6000815180845262000fe9816020860160208601620011d3565b601f01601f19169290920160200192915050565b6000825162001011818460208701620011d3565b9190910192915050565b60208152600062000b59602083018462000fcf565b60608152600062001045606083018662000fcf565b828103602084015262001059818662000fcf565b91505060ff83166040830152949350505050565b60208152600082516101c08060208501526200108e6101e085018362000fcf565b91506020850151620010ac604086018267ffffffffffffffff169052565b5060408501516060850152606085015160808501526080850151620010dc60a08601826001600160a01b03169052565b5060a08501516001600160a01b03811660c08601525060c08501516001600160a01b03811660e08601525060e085015161010062001124818701836001600160a01b03169052565b80870151915050610120601f19868503018187015262001145848362000fcf565b9087015161014087810191909152870151610160808801919091528701516101808088019190915287015190935090506101a06200118d818701836001600160a01b03169052565b909501516001600160a01b031693019290925250919050565b6040516101c0810167ffffffffffffffff81118282101715620011cd57620011cd62001202565b60405290565b60005b83811015620011f0578181015183820152602001620011d6565b8381111562000a615750506000910152565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146200122e57600080fd5b5056fe60806040523480156200001157600080fd5b50604051620029ab380380620029ab833981016040819052620000349162000abe565b6101a0810151600080546001600160a81b0319166001600160a01b0392831617600160a01b17905561018082015160098054919092166001600160a01b031991909116179055805151620000cf5760405162461bcd60e51b815260206004820152601760248201527f50616972206e616d652063616e7420626520656d70747900000000000000000060448201526064015b60405180910390fd5b620000d9620006fc565b81602001516001600160401b031611620001365760405162461bcd60e51b815260206004820152601c60248201527f45787069726174696f6e2074696d657374616d7020696e2070617374000000006044820152606401620000c6565b60008160400151116200018c5760405162461bcd60e51b815260206004820152601f60248201527f436f6c6c61746572616c2070657220706169722063616e6e6f742062652030006044820152606401620000c6565b62000196620007a1565b6001600160a01b03166390978d1b82606001516040518263ffffffff1660e01b8152600401620001c891815260200190565b60206040518083038186803b158015620001e157600080fd5b505afa158015620001f6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200021c919062000a5e565b6200026a5760405162461bcd60e51b815260206004820152601960248201527f4964656e746966696572206e6f742072656769737465726564000000000000006044820152606401620000c6565b60006200027662000842565b6001600160a01b03161415620002c05760405162461bcd60e51b815260206004820152600e60248201526d24b73b30b634b2103334b73232b960911b6044820152606401620000c6565b60e08101516001600160a01b03166200031c5760405162461bcd60e51b815260206004820152601f60248201527f496e76616c69642046696e616e6369616c50726f647563744c696272617279006044820152606401620000c6565b6200032662000887565b60c0820151604051631d1d5b3960e11b81526001600160a01b039182166004820152911690633a3ab6729060240160206040518083038186803b1580156200036d57600080fd5b505afa15801562000382573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003a8919062000a5e565b620003f65760405162461bcd60e51b815260206004820152601a60248201527f436f6c6c61746572616c206e6f742077686974656c69737465640000000000006044820152606401620000c6565b6000816101400151116200044d5760405162461bcd60e51b815260206004820152601760248201527f4f4f206c6976656e6573732063616e6e6f7420626520300000000000000000006044820152606401620000c6565b63bb74480081610140015110620004a75760405162461bcd60e51b815260206004820152601560248201527f4f4f206c6976656e65737320746f6f206c6172676500000000000000000000006044820152606401620000c6565b80518051620004bf91600191602090910190620008d9565b506020810151600080546001600160401b03909216600160b01b02600160b01b600160f01b0319909216919091178155604082015160025560608201516005556080820151600780546001600160a01b039283166001600160a01b03199182161790915560a08401516008805491841691831691909117905560c08401516006805491841691831691909117905560e0840151600a80549190931691161790556200056962000842565b9050806001600160a01b031663c371dda76040518163ffffffff1660e01b815260040160206040518083038186803b158015620005a557600080fd5b505afa158015620005ba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620005e0919062000c1b565b61010083015160405163af5d2f3960e01b81526001600160a01b0384169163af5d2f3991620006159190309060040162000c34565b60006040518083038186803b1580156200062e57600080fd5b505afa15801562000643573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526200066d919081019062000a80565b511115620006be5760405162461bcd60e51b815260206004820152601760248201527f416e63696c6c617279204461746120746f6f206c6f6e670000000000000000006044820152606401620000c6565b6101008201518051620006da91600b91602090910190620008d9565b5050610120810151600c55610140810151600d556101600151600e5562000d45565b600080546001600160a01b0316156200079c5760008054906101000a90046001600160a01b03166001600160a01b03166329cb924d6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200075c57600080fd5b505afa15801562000771573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000797919062000c1b565b905090565b504290565b6009546040516302abf57960e61b81527f4964656e74696669657257686974656c6973740000000000000000000000000060048201526000916001600160a01b03169063aafd5e40906024015b60206040518083038186803b1580156200080757600080fd5b505afa1580156200081c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000797919062000a38565b6009546040516302abf57960e61b81526f4f7074696d69737469634f7261636c6560801b60048201526000916001600160a01b03169063aafd5e4090602401620007ee565b6009546040516302abf57960e61b81527f436f6c6c61746572616c57686974656c6973740000000000000000000000000060048201526000916001600160a01b03169063aafd5e4090602401620007ee565b828054620008e79062000cd9565b90600052602060002090601f0160209004810192826200090b576000855562000956565b82601f106200092657805160ff191683800117855562000956565b8280016001018555821562000956579182015b828111156200095657825182559160200191906001019062000939565b506200096492915062000968565b5090565b5b8082111562000964576000815560010162000969565b80516200098c8162000d2c565b919050565b600082601f830112620009a2578081fd5b81516001600160401b0380821115620009bf57620009bf62000d16565b604051601f8301601f19908116603f01168101908282118183101715620009ea57620009ea62000d16565b8160405283815286602085880101111562000a03578485fd5b62000a1684602083016020890162000ca6565b9695505050505050565b80516001600160401b03811681146200098c57600080fd5b60006020828403121562000a4a578081fd5b815162000a578162000d2c565b9392505050565b60006020828403121562000a70578081fd5b8151801515811462000a57578182fd5b60006020828403121562000a92578081fd5b81516001600160401b0381111562000aa8578182fd5b62000ab68482850162000991565b949350505050565b60006020828403121562000ad0578081fd5b81516001600160401b038082111562000ae7578283fd5b908301906101c0828603121562000afc578283fd5b62000b0662000c7a565b82518281111562000b15578485fd5b62000b238782860162000991565b82525062000b346020840162000a20565b6020820152604083015160408201526060830151606082015262000b5b608084016200097f565b608082015262000b6e60a084016200097f565b60a082015262000b8160c084016200097f565b60c082015262000b9460e084016200097f565b60e0820152610100808401518381111562000bad578586fd5b62000bbb8882870162000991565b9183019190915250610120838101519082015261014080840151908201526101608084015190820152610180915062000bf68284016200097f565b828201526101a0915062000c0c8284016200097f565b91810191909152949350505050565b60006020828403121562000c2d578081fd5b5051919050565b604081526000835180604084015262000c5581606085016020880162000ca6565b6001600160a01b0393909316602083015250601f91909101601f191601606001919050565b6040516101c081016001600160401b038111828210171562000ca05762000ca062000d16565b60405290565b60005b8381101562000cc357818101518382015260200162000ca9565b8381111562000cd3576000848401525b50505050565b600181811c9082168062000cee57607f821691505b6020821081141562000d1057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811462000d4257600080fd5b50565b611c568062000d556000396000f3fe608060405234801561001057600080fd5b50600436106101585760003560e01c806397523661116100c3578063b9a3c84c1161007c578063b9a3c84c146102dd578063b9fd36c8146102f0578063db006a75146102f9578063e3065da71461030c578063e964ae021461031f578063edfa9a9b1461032857600080fd5b8063975236611461025e5780639a9c29f6146102675780639f43ddd21461027a578063a9ae29df146102ae578063b2016bd4146102b7578063b66333cd146102ca57600080fd5b8063780900dc11610115578063780900dc146101fe57806379599f96146102115780638150fd3d1461021957806385209ee01461022157806385c98474146102425780639375f0e91461024b57600080fd5b80631c39c38d1461015d57806322f8e5661461018d57806329cb924d146101a257806340794c3b146101b85780634eef4a73146101cd5780634fe4ecbf146101f5575b600080fd5b600054610170906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6101a061019b3660046118c6565b610331565b005b6101aa6103a7565b604051908152602001610184565b6101c0610447565b6040516101849190611ac4565b6101e06101db366004611856565b6104d5565b60408051928352602083019190915201610184565b6101aa600d5481565b6101aa61020c3660046118c6565b6105e3565b6101a0610803565b6101c061094a565b60005461023590600160a81b900460ff1681565b6040516101849190611ad7565b6101aa600e5481565b600a54610170906001600160a01b031681565b6101aa60055481565b6101aa6102753660046118de565b610957565b60005461029590600160b01b900467ffffffffffffffff1681565b60405167ffffffffffffffff9091168152602001610184565b6101aa60045481565b600654610170906001600160a01b031681565b600754610170906001600160a01b031681565b600954610170906001600160a01b031681565b6101aa600c5481565b6101aa6103073660046118c6565b610d6b565b600854610170906001600160a01b031681565b6101aa60025481565b6101aa60035481565b6000546001600160a01b031661034657600080fd5b60005460405163117c72b360e11b8152600481018390526001600160a01b03909116906322f8e56690602401600060405180830381600087803b15801561038c57600080fd5b505af11580156103a0573d6000803e3d6000fd5b5050505050565b600080546001600160a01b0316156104425760008054906101000a90046001600160a01b03166001600160a01b03166329cb924d6040518163ffffffff1660e01b815260040160206040518083038186803b15801561040557600080fd5b505afa158015610419573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043d91906118ae565b905090565b504290565b6001805461045490611b8d565b80601f016020809104026020016040519081016040528092919081815260200182805461048090611b8d565b80156104cd5780601f106104a2576101008083540402835291602001916104cd565b820191906000526020600020905b8154815290600101906020018083116104b057829003601f168201915b505050505081565b6000806104e0610f18565b6007546040516370a0823160e01b81526001600160a01b038581166004830152909116906370a082319060240160206040518083038186803b15801561052557600080fd5b505afa158015610539573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061055d91906118ae565b6008546040516370a0823160e01b81526001600160a01b038681166004830152909116906370a082319060240160206040518083038186803b1580156105a257600080fd5b505afa1580156105b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105da91906118ae565b91509150915091565b60008054600160b01b900467ffffffffffffffff166106006103a7565b106106525760405162461bcd60e51b815260206004820152601860248201527f4f6e6c792063616c6c61626c65207072652d657870697279000000000000000060448201526064015b60405180910390fd5b61065a610f18565b61066c6000805460ff60a01b19169055565b6040805160208082018352600254825282519081019092528382526106919190610f71565b516006549091506106ad906001600160a01b0316333084610fff565b6007546040516340c10f1960e01b8152336004820152602481018490526001600160a01b03909116906340c10f1990604401602060405180830381600087803b1580156106f957600080fd5b505af115801561070d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610731919061188e565b61073a57600080fd5b6008546040516340c10f1960e01b8152336004820152602481018490526001600160a01b03909116906340c10f1990604401602060405180830381600087803b15801561078657600080fd5b505af115801561079a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107be919061188e565b6107c757600080fd5b6040518290829033907f2b42f4b25222a5d447ca19dfca2afd1b8d32adfed550f7b87bf9569f6da70c0090600090a46107fe611070565b919050565b600054600160b01b900467ffffffffffffffff1661081f6103a7565b10156108695760405162461bcd60e51b81526020600482015260196024820152784f6e6c792063616c6c61626c6520706f73742d65787069727960381b6044820152606401610649565b60008054600160a81b900460ff16600281111561089657634e487b7160e01b600052602160045260246000fd5b146108e35760405162461bcd60e51b815260206004820152601a60248201527f436f6e7472616374207374617465206973206e6f74204f70656e0000000000006044820152606401610649565b6108eb610f18565b6108fd6000805460ff60a01b19169055565b610905611085565b6000805460ff60a81b1916600160a81b17815560405133917f18600820405d6cf356e3556301762ca32395e72d8c81494fa344835c9da3633d91a2610948611070565b565b600b805461045490611b8d565b60008054600160b01b900467ffffffffffffffff166109746103a7565b10156109be5760405162461bcd60e51b81526020600482015260196024820152784f6e6c792063616c6c61626c6520706f73742d65787069727960381b6044820152606401610649565b6109c6610f18565b6109d86000805460ff60a01b19169055565b60008054600160a81b900460ff166002811115610a0557634e487b7160e01b600052602160045260246000fd5b1415610a485760405162461bcd60e51b8152602060048201526012602482015271155b995e1c1a5c99590818dbdb9d1c9858dd60721b6044820152606401610649565b6002600054600160a81b900460ff166002811115610a7657634e487b7160e01b600052602160045260246000fd5b14610b4557600054610a9890600160b01b900467ffffffffffffffff16611279565b6003819055600a54604051632da5236160e01b81526004810192909252610b2e916001600160a01b0390911690632da523619060240160206040518083038186803b158015610ae657600080fd5b505afa158015610afa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b1e91906118ae565b610b2860016113a4565b516113d9565b6004556000805460ff60a81b1916600160a91b1790555b60075460405163079cc67960e41b8152336004820152602481018590526001600160a01b03909116906379cc679090604401602060405180830381600087803b158015610b9157600080fd5b505af1158015610ba5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc9919061188e565b610bd257600080fd5b60085460405163079cc67960e41b8152336004820152602481018490526001600160a01b03909116906379cc679090604401602060405180830381600087803b158015610c1e57600080fd5b505af1158015610c32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c56919061188e565b610c5f57600080fd5b604080516020808201835260045482528251808201845260025481528351918201909352858152600092610c9d9291610c97916113f1565b906113f1565b6000015190506000610cf1610ccc6040518060200160405280600454815250610cc660016113a4565b90611437565b604080516020808201835260025482528251908101909252878252610c9791906113f1565b519050610cfe8183611aff565b600654909350610d18906001600160a01b03163385611461565b604080518481526020810187905290810185905233907fe8fdc264e5a5640d893f125384c4e2c5afe2d9a04aef1129e643caaa72771cff9060600160405180910390a25050610d65611070565b92915050565b6000610d75610f18565b610d876000805460ff60a01b19169055565b60075460405163079cc67960e41b8152336004820152602481018490526001600160a01b03909116906379cc679090604401602060405180830381600087803b158015610dd357600080fd5b505af1158015610de7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0b919061188e565b610e1457600080fd5b60085460405163079cc67960e41b8152336004820152602481018490526001600160a01b03909116906379cc679090604401602060405180830381600087803b158015610e6057600080fd5b505af1158015610e74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e98919061188e565b610ea157600080fd5b604080516020808201835260025482528251908101909252838252610ec691906113f1565b51600654909150610ee1906001600160a01b03163383611461565b6040518290829033907fd171fb179b26c49e23fe46eddd44d3048a1ad277b62144ac0725fbcf1dbf6d5290600090a46107fe611070565b600054600160a01b900460ff166109485760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610649565b6040805160208101909152600080825282518451610f8e91611496565b90506000610fa4670de0b6b3a764000083611b17565b90506000610fba83670de0b6b3a76400006114a2565b90508015610fe657604080516020810190915280610fd98460016114ae565b8152509350505050610d65565b6040518060200160405280838152509350505050610d65565b6040516001600160a01b038085166024830152831660448201526064810182905261106a9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526114ba565b50505050565b6000805460ff60a01b1916600160a01b179055565b600061108f61158c565b600c54909150156110b757600c546006546110b7916001600160a01b0390911690839061161b565b600554600054600654600c546040516311df92f160e01b81526001600160a01b03868116956311df92f19561110a959194600160b01b90910467ffffffffffffffff1693600b9390921691600401611a44565b602060405180830381600087803b15801561112457600080fd5b505af1158015611138573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115c91906118ae565b50600554600054600d5460405163239e22ff60e11b81526001600160a01b0385169363473c45fe936111a8939192600160b01b90910467ffffffffffffffff1691600b91600401611a8a565b600060405180830381600087803b1580156111c257600080fd5b505af11580156111d6573d6000803e3d6000fd5b5050600554600054600e546040516356ad3aad60e11b81526001600160a01b038716955063ad5a755a94506112239392600160b01b900467ffffffffffffffff1691600b91600401611a8a565b602060405180830381600087803b15801561123d57600080fd5b505af1158015611251573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061127591906118ae565b5050565b60008061128461158c565b600554604051635e2c665560e11b81529192506001600160a01b0383169163bc58ccaa916112bc913091908890600b906004016119e5565b60206040518083038186803b1580156112d457600080fd5b505afa1580156112e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061130c919061188e565b61131557600080fd5b6005546040516353b5923960e01b81526000916001600160a01b038416916353b592399161134a918890600b90600401611a1c565b602060405180830381600087803b15801561136457600080fd5b505af1158015611378573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139c91906118ae565b949350505050565b6040805160208101909152600081526040805160208101909152806113d184670de0b6b3a7640000611496565b905292915050565b60008183106113e857816113ea565b825b9392505050565b6040805160208101909152600081526040805160208101909152825184518291670de0b6b3a76400009161142491611496565b61142e9190611b17565b90529392505050565b604080516020810190915260008152604080516020810190915282518451829161142e919061173f565b6040516001600160a01b03831660248201526044810182905261149190849063a9059cbb60e01b90606401611033565b505050565b60006113ea8284611b2b565b60006113ea8284611bc8565b60006113ea8284611aff565b600061150f826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661174b9092919063ffffffff16565b805190915015611491578080602001905181019061152d919061188e565b6114915760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610649565b6009546040516302abf57960e61b81526f4f7074696d69737469634f7261636c6560801b60048201526000916001600160a01b03169063aafd5e409060240160206040518083038186803b1580156115e357600080fd5b505afa1580156115f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043d9190611872565b8015806116a45750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b15801561166a57600080fd5b505afa15801561167e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116a291906118ae565b155b61170f5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610649565b6040516001600160a01b03831660248201526044810182905261149190849063095ea7b360e01b90606401611033565b60006113ea8284611b4a565b606061139c848460008585843b6117a45760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610649565b600080866001600160a01b031685876040516117c091906119c9565b60006040518083038185875af1925050503d80600081146117fd576040519150601f19603f3d011682016040523d82523d6000602084013e611802565b606091505b509150915061181282828661181d565b979650505050505050565b6060831561182c5750816113ea565b82511561183c5782518084602001fd5b8160405162461bcd60e51b81526004016106499190611ac4565b600060208284031215611867578081fd5b81356113ea81611c08565b600060208284031215611883578081fd5b81516113ea81611c08565b60006020828403121561189f578081fd5b815180151581146113ea578182fd5b6000602082840312156118bf578081fd5b5051919050565b6000602082840312156118d7578081fd5b5035919050565b600080604083850312156118f0578081fd5b50508035926020909101359150565b60008151808452611917816020860160208601611b61565b601f01601f19169290920160200192915050565b8054600090600181811c908083168061194557607f831692505b602080841082141561196557634e487b7160e01b86526022600452602486fd5b838852602088018280156119805760018114611991576119bc565b60ff198716825282820197506119bc565b60008981526020902060005b878110156119b65781548482015290860190840161199d565b83019850505b5050505050505092915050565b600082516119db818460208701611b61565b9190910192915050565b60018060a01b0385168152836020820152826040820152608060608201526000611a12608083018461192b565b9695505050505050565b838152826020820152606060408201526000611a3b606083018461192b565b95945050505050565b85815267ffffffffffffffff8516602082015260a060408201526000611a6d60a083018661192b565b6001600160a01b0394909416606083015250608001529392505050565b84815267ffffffffffffffff84166020820152608060408201526000611ab3608083018561192b565b905082606083015295945050505050565b6020815260006113ea60208301846118ff565b6020810160038310611af957634e487b7160e01b600052602160045260246000fd5b91905290565b60008219821115611b1257611b12611bdc565b500190565b600082611b2657611b26611bf2565b500490565b6000816000190483118215151615611b4557611b45611bdc565b500290565b600082821015611b5c57611b5c611bdc565b500390565b60005b83811015611b7c578181015183820152602001611b64565b8381111561106a5750506000910152565b600181811c90821680611ba157607f821691505b60208210811415611bc257634e487b7160e01b600052602260045260246000fd5b50919050565b600082611bd757611bd7611bf2565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b6001600160a01b0381168114611c1d57600080fd5b5056fea26469706673582212209436933c4a6cee6e25f053b3972de74cb8cccc8d0553e7bda36de0d9e240e37f64736f6c63430008040033a2646970667358221220df3a77b9021f01933f3a1c0a657b8bc080df8422ed929b9a98f32f0f54ed14ed64736f6c63430008040033000000000000000000000000b22033ff04ad01fbe8d78ef4622a20626834271b00000000000000000000000056f2c8353049270d3553773e680b0d6c632544b60000000000000000000000000000000000000000000000000000000000000000
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000b22033ff04ad01fbe8d78ef4622a20626834271b00000000000000000000000056f2c8353049270d3553773e680b0d6c632544b60000000000000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _finder (address): 0xb22033ff04ad01fbe8d78ef4622a20626834271b
Arg [1] : _tokenFactory (address): 0x56f2c8353049270d3553773e680b0d6c632544b6
Arg [2] : _timer (address): 0x0000000000000000000000000000000000000000
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000b22033ff04ad01fbe8d78ef4622a20626834271b
Arg [1] : 00000000000000000000000056f2c8353049270d3553773e680b0d6c632544b6
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000000
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|