Source Code
Overview
POL Balance
Token Holdings
More Info
ContractCreator
TokenTracker
Multichain Info
N/A
Latest 25 from a total of 123,732 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Migrate Funds To | 17178374 | 27 days ago | IN | 0 POL | 0.00278873 | ||||
Set Approval For... | 13249084 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248948 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248898 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248814 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248802 | 125 days ago | IN | 0 POL | 0.00157773 | ||||
Set Approval For... | 13248644 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248639 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248633 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248504 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248498 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248493 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248432 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248419 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248401 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248396 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248390 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248384 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248379 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248372 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248367 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248361 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248353 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248335 | 125 days ago | IN | 0 POL | 0.00157811 | ||||
Set Approval For... | 13248323 | 125 days ago | IN | 0 POL | 0.00157811 |
Loading...
Loading
Contract Name:
MarketFundingPool
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 200 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import { IERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol"; import { ParentFundingPool, IParentFundingPoolV1 } from "../funding/ParentFundingPool.sol"; import { ChildFundingPool, IChildFundingPoolV1 } from "../funding/ChildFundingPool.sol"; import { AdminExecutorAccess } from "../AdminExecutorAccess.sol"; import { IConditionalTokens } from "../conditions/IConditionalTokens.sol"; import { IMarketFactory, IMarketMakerV1, MarketAddressParams } from "./IMarketFactory.sol"; import { MarketErrors } from "./MarketErrors.sol"; interface MarketFundingPoolErrors { error InvalidLimitsArray(); error NotAFactory(address); error FactoryNotApproved(address); } interface MarketFundingPoolEvents { event MarketFactoryApproval(address indexed factory, bool approved); } /// @dev This acts as a central Liquidity Pool for all created markets, and /// ensures that the markets can be trusted by including the factory. Batch /// market creation with approval is possible contract MarketFundingPool is ParentFundingPool, MarketFundingPoolErrors, MarketFundingPoolEvents, MarketErrors { using ERC165Checker for address; struct Params { IConditionalTokens conditionalTokens; IERC20Metadata collateralToken; address admin; address executor; } IConditionalTokens public immutable conditionalTokens; mapping(address => bool) private factoryApproval; bytes4 private constant MARKET_INTERFACE_ID = 0x19a298e7; bytes4 private constant FACTORY_INTERFACE_ID = 0xaecc550a; /// @custom:oz-upgrades-unsafe-allow constructor constructor(Params memory params, address prevPool) ParentFundingPool(params.admin, params.collateralToken, prevPool) { conditionalTokens = params.conditionalTokens; _grantRole(EXECUTOR_ROLE, params.executor); } /// @dev allow a factory to be used to create markets for the fund. function setFactoryApproval(address factory, bool approved) external onlyAdmin { // If approving, require not to be paused // If removing approval, can be paused if (approved) { _requireNotPaused(); } bool supportsFactory = factory.supportsInterface(FACTORY_INTERFACE_ID); if (!supportsFactory) revert NotAFactory(factory); if (factoryApproval[factory] != approved) { factoryApproval[factory] = approved; emit MarketFactoryApproval(factory, approved); } } /// @dev Create markets and approve them as child markets, so they can /// request funding directly from this pool. The function is idempotent, so /// if a market was already created, or approved, it will not fail and just /// succeed gracefully function createMarketsWithPrices( IMarketFactory factory, address priceOracle, address conditionOracle, uint256 fee, uint256[] calldata marketLimits, IMarketFactory.PriceMarketParams[] calldata marketParamsArray ) external returns (IMarketMakerV1[] memory markets) { if (!factoryApproval[address(factory)]) revert FactoryNotApproved(address(factory)); if (marketLimits.length != marketParamsArray.length) revert InvalidLimitsArray(); markets = new IMarketMakerV1[](marketParamsArray.length); MarketAddressParams memory addresses = MarketAddressParams(conditionalTokens, collateralToken, address(this), priceOracle, conditionOracle); for (uint256 i = 0; i < marketParamsArray.length; ++i) { IMarketMakerV1 market = factory.createMarket(fee, addresses, marketParamsArray[i]); bool supportsMarket = address(market).supportsInterface(MARKET_INTERFACE_ID); if (!supportsMarket) revert NotAFactory(address(factory)); markets[i] = market; // Slither has a medium-level warning for re-entrancy here. The // issue is that we change a local state (child approval) after an // external call (to factory.createMarket) . In usual re-entrancy // problems, the state change is something like a balance change, // but in this case we are actually allowing operations only after // creation. Meaning, even if the factory or created market // re-enters another method, approval is false at that time, so // nothing nefarious is possible. // slither-disable-next-line reentrancy-no-eth setApprovalForChild(address(market), marketLimits[i]); } } function getFactoryApproval(address factory) public view returns (bool) { return factoryApproval[factory]; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.2) (utils/introspection/ERC165Checker.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Library used to query support of an interface declared via {IERC165}. * * Note that these functions return the actual result of the query: they do not * `revert` if an interface is not supported. It is up to the caller to decide * what to do in these cases. */ library ERC165Checker { // As per the EIP-165 spec, no interface should ever match 0xffffffff bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; /** * @dev Returns true if `account` supports the {IERC165} interface. */ function supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) && !supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID); } /** * @dev Returns true if `account` supports the interface defined by * `interfaceId`. Support for {IERC165} itself is queried automatically. * * See {IERC165-supportsInterface}. */ function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId); } /** * @dev Returns a boolean array where each value corresponds to the * interfaces passed in and whether they're supported or not. This allows * you to batch check interfaces for a contract where your expectation * is that some interfaces may not be supported. * * See {IERC165-supportsInterface}. * * _Available since v3.4._ */ function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool[] memory) { // an array of booleans corresponding to interfaceIds and whether they're supported or not bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length); // query support of ERC165 itself if (supportsERC165(account)) { // query support of each interface in interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]); } } return interfaceIdsSupported; } /** * @dev Returns true if `account` supports all the interfaces defined in * `interfaceIds`. Support for {IERC165} itself is queried automatically. * * Batch-querying can lead to gas savings by skipping repeated checks for * {IERC165} support. * * See {IERC165-supportsInterface}. */ function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!supportsERC165(account)) { return false; } // query support of each interface in interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; } /** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with {supportsERC165}. * * Some precompiled contracts will falsely indicate support for a given interface, so caution * should be exercised when using this function. * * Interface identification is specified in ERC-165. */ function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) { // prepare call bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId); // perform static call bool success; uint256 returnSize; uint256 returnValue; assembly { success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20) returnSize := returndatasize() returnValue := mload(0x00) } return success && returnSize >= 0x20 && returnValue > 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { IERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol"; import { ContextUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol"; import { Context } from "@openzeppelin/contracts/utils/Context.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { SafeERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { FundingPool, IFundingPoolV1_1, IFundingPoolV1, FundingMath } from "./FundingPool.sol"; import { IParentFundingPoolV1 } from "./IParentFundingPoolV1.sol"; import { ChildFundingPool, IChildFundingPoolV1 } from "./ChildFundingPool.sol"; import { ClampedMath } from "../Math.sol"; import { AdminExecutorAccess } from "../AdminExecutorAccess.sol"; interface MigrateFundsEvents { event MigratedFunds(address indexed receiver, uint256 collateralMigrated, uint256 costBasis, uint256 sharesGranted); } /// @dev Interface for migrating funds from current Parent pool to another interface IMigrateFundsSender is MigrateFundsEvents { error DoesNotSupportMigrateFundsInterface(address); error DoesNotSupportParentPoolInterface(address); function migrateFundsTo(address newPool) external returns (uint256 collateralMigrated, uint256 costBasis, uint256 sharesGranted); } /// @dev Interface for migrating funds from another Parent pool to this one. interface IMigrateFundsReceiver { error NoPrevPoolConfigured(); error SenderIsNotPrevPool(address); /// @dev Call to initiate migration through requestFunding. Must be called /// by the pool from which the funds are being migrated /// @return collateralMigrated quantity of collateral that was able to be migrated /// @return costBasis the recorded costBasis of the migrated collateral /// @return sharesGranted number of liquidity shares given for the migrated funds function migrateFundsFromSender() external returns (uint256 collateralMigrated, uint256 costBasis, uint256 sharesGranted); } contract ParentFundingPool is FundingPool, IParentFundingPoolV1, AdminExecutorAccess, ChildFundingPool, IMigrateFundsReceiver, IMigrateFundsSender { using ERC165Checker for address; using ClampedMath for uint256; using Math for uint256; using SafeERC20 for IERC20Metadata; using SafeERC20Upgradeable for IFundingPoolV1; struct FunderShareRemovals { uint256 removedAsCollateral; uint256 removedAsChildShares; } /// @dev Current state of investement in a child pool struct ChildValue { /// @dev How much collateral is locked up in a child pool uint256 locked; /// @dev realized losses or gains by child when returning funds int256 pnl; } /// @dev a struct to keep track of the current state of pool during liquidity removal struct RemovalContext { uint256 currentFunderShares; uint256 totalShares; uint256 poolValue; uint256 totalChildValueLocked; FunderShareRemovals removals; } /// @dev What is the maximum any child fund can request. Managed by DEFAULT_ADMIN_ROLE uint256 public requestLimit; /// @dev What is the maximum a particular child fund can request to be funded. Managed by FUND_MANAGER_ROLE mapping(address => uint256) private childApproval; // Interface ids for interoperability with already deployed contracts bytes4 private constant FUNDING_POOL_INTERFACE_ID = 0x0dc4a76a; bytes4 private constant FUNDING_POOL_V1_1_INTERFACE_ID = 0x5ee02cbf; bytes4 private constant CHILD_POOL_INTERFACE_ID = 0xd2da4040; bytes4 private constant PARENT_FUNDING_POOL_INTERFACE_ID = 0xd0632e9a; bytes4 private constant MIGRATE_FUNDS_RECEIVER_INTERFACE_ID = 0x49bcbcc0; /// @dev How much collateral is used up in a child pool mapping(address => ChildValue) private childValue; /// @dev current value locked in all child pools uint256 public totalChildValueLocked; /// @dev Keeps track of how many shares were directly exchanged for /// "unlocked"/"locked" collateral in the pool. Used to prevent funders /// withdrawing all their shares only in collateral, leaving other funders /// stuck with only locked liquidity. mapping(address => FunderShareRemovals) private funderShareRemovals; mapping(address => mapping(address => uint256)) private funderShareRemovalsForChild; /// @dev Create a ParentFundingPool, and potentially set up a migration from previous pool /// @param admin address with admin priveleges /// @param _collateralToken The collateral token to use for investing in the pool /// @param prevPool optional address of previous ParentFundingPool, from which funds should be migrated /// @custom:oz-upgrades-unsafe-allow constructor constructor(address admin, IERC20Metadata _collateralToken, address prevPool) AdminExecutorAccess(admin) { // The contract is not meant to be upgradeable or run behind a proxy, // but uses upgradeable base contracts because it shares some base // classes with other contracts that need to be behind a proxy initialize(_collateralToken, prevPool); _disableInitializers(); } /// @inheritdoc IFundingPoolV1 function addFunding(uint256 collateralAdded) external returns (uint256 sharesMinted) { return addFundingFor(_msgSender(), collateralAdded); } /// @inheritdoc IParentFundingPoolV1 function requestFunding(uint256 collateralRequested) external whenNotPaused returns (uint256 collateralAdded, uint256 sharesMinted) { IFundingPoolV1 childPool = _childPoolSender(); // how much is remaining to be requested from the limit and collateral (uint256 limitRemaining,) = getAvailableFunding(address(childPool)); // clamp collateralRequested to the limit collateralAdded = Math.min(limitRemaining, collateralRequested); if (collateralAdded > 0) { childValue[address(childPool)].locked += collateralAdded; totalChildValueLocked += collateralAdded; collateralToken.safeApprove(address(childPool), collateralAdded); sharesMinted = childPool.addFunding(collateralAdded); emit FundingGiven(address(childPool), collateralAdded); // NOTE: currently childPool cannot be completely trustless, as // childPool itself is the ERC20 fund share token, which means it // can burn shares without the knowledge of the parent, in effect // keeping all the funds. This is at least mitigated by the fact // that a child pool cannot exceed its limit. } } /// @notice Set the maximum any child fund can request. function setRequestLimit(uint256 limit) public onlyAdmin { requestLimit = limit; emit RequestLimitChanged(limit); } /// @dev This entirely depends on trusting the child pool to report /// fundingReturned correctly. This is accomplished here because this single pool /// controls exactly what code the child pool (markets) are running. In a /// future implementation it would be better to express pool ownership /// through ERC1155 tokens, and utilize the ERC1155Receiver functionality to /// automatically be called back when shares are returned. function fundingReturned(uint256 collateralReturned, uint256 childSharesBurnt) external { IFundingPoolV1 childPool = _childPoolSender(); uint256 childSharesBefore = childPool.balanceOf(address(this)) + childSharesBurnt; ChildValue storage child = childValue[address(childPool)]; uint256 valueLocked = child.locked; uint256 valueUnlocked = childSharesBefore > 0 ? (childSharesBurnt * valueLocked) / childSharesBefore : 0; if (collateralReturned > uint256(type(int256).max)) revert ExcessiveFunding(); assert(valueUnlocked <= uint256(type(int256).max)); child.locked = valueLocked - valueUnlocked; child.pnl += int256(collateralReturned) - int256(valueUnlocked); totalChildValueLocked -= valueUnlocked; emit FundingReturned(address(childPool), collateralReturned, valueUnlocked); } function feesReturned(uint256 fees) external { _checkChildPool(_msgSender()); _retainFees(fees); } /// @dev Remove liquidity in collateral by burning a portion of the funder's shares. /// The proportion of shares that can be removed this way cannot exceed the /// proportion of collateral in the parent pool. To maximize the amount of /// collateral removed, do collateral removal first before trying to remove /// liquidity as child shares. /// @param sharesToBurn How many funder shares to burn /// @return collateralReturned How much collateral was returned /// @return sharesBurnt How much many shares were burnt function removeCollateral(uint256 sharesToBurn) external whenNotPaused returns (uint256 collateralReturned, uint256 sharesBurnt) { address funder = _msgSender(); (collateralReturned, sharesBurnt) = calcRemoveCollateral(funder, sharesToBurn); if (sharesBurnt == 0) return (collateralReturned, sharesBurnt); funderShareRemovals[funder].removedAsCollateral += sharesBurnt; _burnSharesOf(funder, sharesBurnt); collateralToken.safeTransfer(funder, collateralReturned); uint256[] memory noTokens = new uint256[](0); emit FundingRemoved(funder, collateralReturned, noTokens, sharesBurnt); } /// @dev Remove liquidity in assets by burning a portion of the funder's shares. /// The proportion of a funder's shares that can be removed in terms of a /// particular child pool's shares cannot exceed the proportion of liquidity /// in that child pool among all child pools /// @param child address of child pool /// @param sharesToBurn How many funder shares to burn function removeChildShares(address child, uint256 sharesToBurn) external whenNotPaused returns (uint256 childSharesReturned, uint256 sharesBurnt) { IFundingPoolV1 childPool = _childPool(child); address funder = _msgSender(); mapping(address => uint256) storage removalsForChild = funderShareRemovalsForChild[funder]; RemovalContext memory context = _getRemovalContext(funder); (childSharesReturned, sharesBurnt) = _removeChildShares(childPool, context, sharesToBurn, removalsForChild); if (childSharesReturned > 0) { assert(sharesBurnt > 0); // Update state funderShareRemovals[funder] = context.removals; totalChildValueLocked = context.totalChildValueLocked; // Burn and transfer childPool.safeTransfer(funder, childSharesReturned); emit FundingRemovedAsToken(funder, uint256(bytes32(bytes20(child))), childSharesReturned, sharesBurnt); _burnSharesOf(funder, sharesBurnt); } // with fractional shares it's possible to have leftover shares that are // not worth 1 wei of collateral. It is up to the user to avoid // needlessly burning shares } function batchRemoveChildShares(address[] calldata children, uint256[] calldata sharesToBurn) external whenNotPaused returns (uint256 totalSharesBurnt) { if (children.length != sharesToBurn.length) revert InvalidBatchLength(); address funder = _msgSender(); mapping(address => uint256) storage removalsForChild = funderShareRemovalsForChild[funder]; RemovalContext memory context = _getRemovalContext(funder); for (uint256 i = 0; i < children.length; ++i) { IFundingPoolV1 childPool = _childPool(children[i]); (uint256 childSharesReturned, uint256 sharesBurnt) = _removeChildShares(childPool, context, sharesToBurn[i], removalsForChild); totalSharesBurnt += sharesBurnt; if (childSharesReturned > 0) { assert(sharesBurnt > 0); childPool.safeTransfer(funder, childSharesReturned); emit FundingRemovedAsToken( funder, uint256(bytes32(bytes20(children[i]))), childSharesReturned, sharesBurnt ); } else { assert(sharesBurnt == 0); } } // Update state and burn funderShareRemovals[funder] = context.removals; totalChildValueLocked = context.totalChildValueLocked; _burnSharesOf(funder, totalSharesBurnt); } function migrateFundsTo(address newPool) external onlyAdmin returns (uint256 collateralMigrated, uint256 costBasis, uint256 sharesGranted) { if (!newPool.supportsInterface(PARENT_FUNDING_POOL_INTERFACE_ID)) { revert DoesNotSupportParentPoolInterface(newPool); } if (!newPool.supportsInterface(MIGRATE_FUNDS_RECEIVER_INTERFACE_ID)) { revert DoesNotSupportMigrateFundsInterface(newPool); } // Total funder cost basis is the target balance of the pool without any PNL uint256 globalTarget = getTotalFunderCostBasis(); // child approval is usually done by the fund executor. We need to override it for this operation grantRole(EXECUTOR_ROLE, msg.sender); setApprovalForChild(newPool, globalTarget); revokeRole(EXECUTOR_ROLE, msg.sender); // Expand request limit to be able to cover the full migration. Will be restored later uint256 prevRequestLimit = requestLimit; setRequestLimit(globalTarget); IMigrateFundsReceiver newParentPool = IMigrateFundsReceiver(newPool); (collateralMigrated, costBasis, sharesGranted) = newParentPool.migrateFundsFromSender(); // Restore previous request limit setRequestLimit(prevRequestLimit); emit MigratedFunds(newPool, collateralMigrated, costBasis, sharesGranted); } /// @inheritdoc IMigrateFundsReceiver function migrateFundsFromSender() external returns (uint256 collateralMigrated, uint256 costBasis, uint256 sharesGranted) { address senderPool = getParentPool(); if (senderPool == address(0x0)) revert NoPrevPoolConfigured(); if (msg.sender != senderPool) revert SenderIsNotPrevPool(msg.sender); bool supportsFundingPool = senderPool.supportsInterface(FUNDING_POOL_V1_1_INTERFACE_ID); if (!supportsFundingPool) revert NotAParentPool(senderPool); uint256 senderCostBasis = IFundingPoolV1_1(senderPool).getTotalFunderCostBasis(); uint256 senderReserves = IFundingPoolV1_1(senderPool).reserves(); uint256 senderTotalValue = IFundingPoolV1_1(senderPool).getPoolValue(); // Don't proceed if there is no collateral available to be migrated if (senderReserves == 0) { return (0, 0, 0); } uint256 costBasisOfSenderBeforeMigration = getFunderCostBasis(senderPool); // senderPool is guaranteed to support parent pool interface, because it // was assigned in constructor to ChildFundingPool, which checks the // interface support assert(senderPool.supportsInterface(PARENT_FUNDING_POOL_INTERFACE_ID)); IParentFundingPoolV1 senderParentPool = IParentFundingPoolV1(senderPool); // Migrate only the collateral that is immediately available, avoiding any locked liquidity. // The migration can be repeated to migrate everything eventually (collateralMigrated, sharesGranted) = senderParentPool.requestFunding(senderReserves); // Now adjust the cost basis, to match the sender pool. This means // that any unrealized losses will be carried over to this pool { assert(collateralMigrated == (getFunderCostBasis(senderPool) - costBasisOfSenderBeforeMigration)); // Don't carry over unrealized gains, as those will be kept by the original pool senderCostBasis = Math.max(senderCostBasis, senderTotalValue); costBasis = (collateralMigrated * senderCostBasis) / senderTotalValue; assert(costBasis >= collateralMigrated); uint256 adjustment = costBasis - collateralMigrated; _adjustCostBasis(senderPool, adjustment); } } /// @param sharesToBurn How many funder shares to burn /// @return collateralReturned How much collateral was returned /// @return sharesBurnt How much many shares were burnt function calcRemoveCollateral(address funder, uint256 sharesToBurn) public view returns (uint256 collateralReturned, uint256 sharesBurnt) { uint256 _reserves = reserves(); uint256 poolValue = getPoolValue(); if (poolValue == 0) revert PoolValueZero(); FunderShareRemovals memory removals = funderShareRemovals[funder]; uint256 funderTotalShares = balanceOf(funder) + removals.removedAsCollateral; sharesBurnt = FundingMath.calcMaxParentSharesToBurnForAsset( funderTotalShares, sharesToBurn, removals.removedAsCollateral, _reserves, poolValue ); if (sharesBurnt == 0) return (collateralReturned, sharesBurnt); collateralReturned = FundingMath.calcReturnAmount(sharesBurnt, totalSupply(), poolValue); assert(collateralReturned <= _reserves); } /// @inheritdoc IParentFundingPoolV1 function setApprovalForChild(address childPool, uint256 approval) public onlyExecutor { // If approving, require not to be paused // If removing approval, can be paused if (approval > 0) { _requireNotPaused(); } // reduce gas cost if approval matches the previous value if (childApproval[childPool] == approval) return; bool supportsFundingPool = childPool.supportsInterface(FUNDING_POOL_INTERFACE_ID); if (!supportsFundingPool) revert NotAChildPool(childPool); bool supportsChildPool = childPool.supportsInterface(CHILD_POOL_INTERFACE_ID); if (!(supportsChildPool && IChildFundingPoolV1(childPool).getParentPool() == address(this))) { revert NotAChildPool(childPool); } childApproval[childPool] = approval; emit ChildPoolApproval(childPool, approval); } /// @inheritdoc IFundingPoolV1 function addFundingFor(address receiver, uint256 collateralAdded) public whenNotPaused returns (uint256 sharesMinted) { sharesMinted = _mintSharesFor(receiver, collateralAdded, getPoolValue()); } /// @inheritdoc IParentFundingPoolV1 function getAvailableFunding(address childPool) public view returns (uint256 availableFunding, uint256 availableTarget) { uint256 globalTarget = getTotalFunderCostBasis(); availableTarget = Math.min(requestLimit, childApproval[childPool]); availableTarget = Math.min(globalTarget, availableTarget); availableFunding = availableTarget; // Do not adjust funding based on gains/losses // remaining target after taking into account how much was already spent ChildValue memory child = childValue[childPool]; availableTarget = availableTarget.subClamp(child.locked); availableFunding = availableFunding.subClamp(child.locked); // It is important not to limit availableTarget to reserves. The target // is used to signal the ideal balance for a child pool, regardless of // gains or losses. It serves as a stable baseline for the child pool to // assess its performance. This is important to keep accurate because // collateral is requested and returned constantly between the child and // the parent as needed. If available funding is less than target, that // means the child pool has lost some value and must increase slippage // to regain value back. // If target is reduced to keep pace with reserves, when a child loses // money, it's available funding and target will stay in sync, giving // the illusion that it is doing fine (target and available funding are // the same). It will continue losing money as the reserves shrink. Thus // available funding is relative to reserves, while available target is // relative to cost basis - the original collateral deposited. // Available funding takes into account how much was lost or gained by the child availableFunding = Math.min(reserves(), availableFunding.addClamp(child.pnl)); } function getApprovalForChild(address childPool) public view returns (uint256) { return childApproval[childPool]; } function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165Upgradeable, AccessControl) returns (bool) { return interfaceId == type(IParentFundingPoolV1).interfaceId || interfaceId == type(IFundingPoolV1).interfaceId || interfaceId == type(IFundingPoolV1_1).interfaceId || interfaceId == type(IChildFundingPoolV1).interfaceId || interfaceId == type(IMigrateFundsSender).interfaceId || interfaceId == type(IMigrateFundsReceiver).interfaceId || super.supportsInterface(interfaceId); } function _msgSender() internal view override(ContextUpgradeable, Context) returns (address) { return Context._msgSender(); } // Have to override, otherwise does not compile // slither-disable-next-line dead-code function _msgData() internal view override(ContextUpgradeable, Context) returns (bytes calldata) { return Context._msgData(); } function _checkChildPool(address childPool) internal view { if (getApprovalForChild(childPool) == 0) revert ChildPoolNotApproved(childPool); } function _childPoolSender() internal view returns (IFundingPoolV1) { return _childPool(_msgSender()); } function _childPool(address childPool) internal view returns (IFundingPoolV1) { _checkChildPool(childPool); // Don't need to check if childPool supports the right interfaces - that // was already done when it was approved return IFundingPoolV1(childPool); } function _afterFeesWithdrawn(address funder, uint256 collateralRemovedFromFees) internal virtual override { address parent = getParentPool(); if (funder == parent) { IParentFundingPoolV1(parent).feesReturned(collateralRemovedFromFees); } } function _removeChildShares( IFundingPoolV1 childPool, RemovalContext memory context, uint256 sharesToBurn, mapping(address => uint256) storage removalsForChild ) private returns (uint256 childSharesReturned, uint256 sharesBurnt) { if (sharesToBurn > context.currentFunderShares) revert InvalidBurnAmount(); uint256 childLocked = childValue[address(childPool)].locked; // slither-disable-next-line dangerous-strict-equalities if (childLocked == 0) return (childSharesReturned, sharesBurnt); // To explain the below two max values, let's set up a scenario // Setup: // - total 100 liquidity shares for parent pool // - 25% of value is locked in child A, 25% of value is locked in child B // Calculate how many parent shares can be removed from the pool in the form of child pool shares. // Regardless of the funder, in the above scenario, only 25 liquidity // shares of the parent are convertible to child shares of A or B. This is just 25% of the total pool uint256 maxTotalSharesRedeemableForChild = (context.totalShares * childLocked).ceilDiv(context.poolValue); // Limit number of funder shares redeemable to proportion of child value // of overall locked value. In the above scenario, if a funder had 20 // shares in the parent pool, they cannot convert all 20 shares for a // single child's shares. Since each child's portion of locked value is // 50%, at most 10 parent shares of the funder can be converted into // each of the child's shares. This is to limit removals where one // child's liquidity value is more advantageous to remove than another. sharesBurnt = FundingMath.calcMaxParentSharesToBurnForAsset( context.currentFunderShares + context.removals.removedAsChildShares, Math.min(sharesToBurn, maxTotalSharesRedeemableForChild), removalsForChild[address(childPool)], childLocked, context.totalChildValueLocked // instead of pool value ); if (sharesBurnt == 0) return (childSharesReturned, sharesBurnt); uint256 valueReturned = FundingMath.calcReturnAmount(sharesBurnt, context.totalShares, context.poolValue); valueReturned = Math.min(valueReturned, childLocked); context.removals.removedAsChildShares += sharesBurnt; removalsForChild[address(childPool)] += sharesBurnt; uint256 childShares = childPool.balanceOf(address(this)); childSharesReturned = (childShares * valueReturned) / childLocked; context.currentFunderShares -= sharesBurnt; context.totalShares -= sharesBurnt; context.poolValue -= valueReturned; context.totalChildValueLocked -= valueReturned; childValue[address(childPool)].locked = childLocked - valueReturned; } function _getRemovalContext(address funder) private view returns (RemovalContext memory) { uint256 funderShares = balanceOf(funder); uint256 poolValue = getPoolValue(); // If there is no value in the pool, it doesn't make sense to remove value from it. if (poolValue == 0) revert PoolValueZero(); FunderShareRemovals memory removals = funderShareRemovals[funder]; return RemovalContext(funderShares, totalSupply(), poolValue, totalChildValueLocked, removals); } function getPoolValue() public view returns (uint256 poolValue) { poolValue = reserves() + totalChildValueLocked; } function initialize(IERC20Metadata _collateralToken, address prevPool) private initializer { __FundingPool_init(_collateralToken); __ChildFundingPool_init(prevPool); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IChildFundingPoolV1 } from "./IChildFundingPoolV1.sol"; import { IParentFundingPoolV1 } from "./IParentFundingPoolV1.sol"; import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; /// @dev A Mixin contract that provides a basic implementation of the IChildFundingPoolV1 interface abstract contract ChildFundingPool is Initializable, IChildFundingPoolV1 { using ERC165Checker for address; address private _parent; bytes4 private constant PARENT_FUNDING_POOL_INTERFACE_ID = 0xd0632e9a; function getParentPool() public view returns (address) { return _parent; } // solhint-disable-next-line func-name-mixedcase function __ChildFundingPool_init(address parentPool) internal onlyInitializing { __ChildFundingPool_init_unchained(parentPool); } // solhint-disable-next-line func-name-mixedcase function __ChildFundingPool_init_unchained(address parentPool) internal onlyInitializing { assert(address(_parent) == address(0x0)); if ( parentPool != address(0x0) && !IParentFundingPoolV1(parentPool).supportsInterface(PARENT_FUNDING_POOL_INTERFACE_ID) ) { revert NotAParentPool(parentPool); } _parent = parentPool; emit ParentPoolAdded(parentPool); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol"; import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol"; /// @dev Simple Access Control, that has an admin role that administers an /// executor role. The intent is to have a multi-sig or other mechanism to be /// the admin, and be able to grant/revoke accounts as executors. contract AdminExecutorAccess is AccessControl, Pausable { bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE"); modifier onlyAdmin() { checkAdmin(_msgSender()); _; } modifier onlyExecutor() { checkExecutor(_msgSender()); _; } // Not upgradeable but inherited by a contract that also inherits upgradeable /// @custom:oz-upgrades-unsafe-allow constructor constructor(address admin) { _grantRole(DEFAULT_ADMIN_ROLE, admin); // DEFAULT_ADMIN_ROLE already is admin for executor by default, so no need for _setRoleAdmin } function pause() public onlyAdmin { _pause(); } function unpause() public onlyAdmin { _unpause(); } /// @dev Check is a particular account has executor permissions. Reverts if not the case. /// @param account the account to check function checkExecutor(address account) public view { _checkRole(EXECUTOR_ROLE, account); } function checkAdmin(address account) public view { _checkRole(DEFAULT_ADMIN_ROLE, account); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IERC1155Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol"; import { ConditionID, QuestionID } from "./CTHelpers.sol"; import { ConditionalTokensErrors } from "./ConditionalTokensErrors.sol"; /// @title Events emitted by conditional tokens /// @dev Minimal interface to be used for blockchain indexing (e.g subgraph) interface IConditionalTokensEvents { /// @dev Emitted upon the successful preparation of a condition. /// @param conditionId The condition's ID. This ID may be derived from the /// other three parameters via ``keccak256(abi.encodePacked(oracle, /// questionId, outcomeSlotCount))``. /// @param oracle The account assigned to report the result for the prepared condition. /// @param questionId An identifier for the question to be answered by the oracle. /// @param outcomeSlotCount The number of outcome slots which should be used /// for this condition. Must not exceed 256. event ConditionPreparation( ConditionID indexed conditionId, address indexed oracle, QuestionID indexed questionId, uint256 outcomeSlotCount ); event ConditionResolution( ConditionID indexed conditionId, address indexed oracle, QuestionID indexed questionId, uint256 outcomeSlotCount, uint256[] payoutNumerators ); /// @dev Emitted when a position is successfully split. event PositionSplit( address indexed stakeholder, IERC20 collateralToken, ConditionID indexed conditionId, uint256 amount ); /// @dev Emitted when positions are successfully merged. event PositionsMerge( address indexed stakeholder, IERC20 collateralToken, ConditionID indexed conditionId, uint256 amount ); /// @notice Emitted when a subset of outcomes are redeemed for a condition event PayoutRedemption( address indexed redeemer, IERC20 indexed collateralToken, ConditionID conditionId, uint256[] indices, uint256 payout ); } interface IConditionalTokens is IERC1155Upgradeable, IConditionalTokensEvents, ConditionalTokensErrors { function prepareCondition(address oracle, QuestionID questionId, uint256 outcomeSlotCount) external returns (ConditionID); function reportPayouts(QuestionID questionId, uint256[] calldata payouts) external; function batchReportPayouts( QuestionID[] calldata questionIDs, uint256[] calldata payouts, uint256[] calldata outcomeSlotCounts ) external; function splitPosition(IERC20 collateralToken, ConditionID conditionId, uint256 amount) external; function mergePositions(IERC20 collateralToken, ConditionID conditionId, uint256 amount) external; function redeemPositionsFor( address receiver, IERC20 collateralToken, ConditionID conditionId, uint256[] calldata indices, uint256[] calldata quantities ) external returns (uint256); function redeemAll(IERC20 collateralToken, ConditionID[] calldata conditionIds, uint256[] calldata indices) external; function redeemAllOf( address ownerAndReceiver, IERC20 collateralToken, ConditionID[] calldata conditionIds, uint256[] calldata indices ) external returns (uint256 totalPayout); function balanceOfCondition(address account, IERC20 collateralToken, ConditionID conditionId) external view returns (uint256[] memory); function isResolved(ConditionID conditionId) external view returns (bool); function getPositionIds(IERC20 collateralToken, ConditionID conditionId) external view returns (uint256[] memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import { IMarketMakerV1 } from "./IMarketMaker.sol"; import { MarketAddressParams } from "./MarketAddressParams.sol"; import { IConditionalTokens, ConditionID, QuestionID } from "../conditions/IConditionalTokens.sol"; /// @title Events for a market factory /// @dev Use these events for blockchain indexing interface IMarketFactoryEvents { event MarketMakerCreation( address indexed creator, IMarketMakerV1 marketMaker, IConditionalTokens indexed conditionalTokens, IERC20 indexed collateralToken, ConditionID conditionId, uint256 haltTime, uint256 fee ); } interface IMarketFactory is IMarketFactoryEvents, IERC165 { /// @dev Parameters unique to a single Market creation struct PriceMarketParams { QuestionID questionId; uint256[] fairPriceDecimals; uint128 minPriceDecimal; uint256 haltTime; } function createMarket(uint256 fee, MarketAddressParams calldata addresses, PriceMarketParams memory params) external returns (IMarketMakerV1); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { AmmErrors } from "./AmmErrors.sol"; import { FundingErrors } from "../funding/FundingErrors.sol"; interface MarketErrors is AmmErrors, FundingErrors { error MarketHalted(); error MarketUndecided(); error MustBeCalledByOracle(); // Buy error InvalidInvestmentAmount(); error MinimumBuyAmountNotReached(); // Sell error InvalidReturnAmount(); error MaximumSellAmountExceeded(); error InvestmentDrainsPool(); error OperationNotSupported(); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(account), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; import "../extensions/draft-IERC20PermitUpgradeable.sol"; import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable { using AddressUpgradeable for address; function safeTransfer( IERC20Upgradeable token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20Upgradeable 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( IERC20Upgradeable token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20Upgradeable 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( IERC20Upgradeable token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20PermitUpgradeable token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { IFundingPoolV1_1, IFundingPoolV1 } from "./IFundingPoolV1_1.sol"; import { FundingMath } from "./FundingMath.sol"; import { ArrayMath, ClampedMath } from "../Math.sol"; /// @dev A contract with the necessary storage to keep track of funding. Should /// not be used as a standalone contract, but like a mixin abstract contract FundingPool is IFundingPoolV1_1, ERC20Upgradeable { using Math for uint256; using ArrayMath for uint256[]; using SafeERC20 for IERC20Metadata; IERC20Metadata public collateralToken; uint256 private feePoolWeight; mapping(address => uint256) private withdrawnFees; uint256 private totalWithdrawnFees; /// @dev Keeps track of total collateral used to enter the current liquidity /// position of the funder. It is increased by the collateral amount every /// time the funder funds, and then reduced proportionally to how many LP /// shares are withdrawn during defunding. This can be considered the "cost /// basis" of the lp shares of each funder mapping(address => uint256) private funderCostBasis; /// @dev Total collateral put into funding the current LP shares uint256 private totalFunderCostBasis; /// @inheritdoc IFundingPoolV1 function withdrawFees(address funder) public returns (uint256 collateralRemovedFromFees) { collateralRemovedFromFees = feesWithdrawableBy(funder); if (collateralRemovedFromFees > 0) { withdrawnFees[funder] += collateralRemovedFromFees; totalWithdrawnFees = totalWithdrawnFees + collateralRemovedFromFees; collateralToken.safeTransfer(funder, collateralRemovedFromFees); emit FeesWithdrawn(funder, collateralRemovedFromFees); _afterFeesWithdrawn(funder, collateralRemovedFromFees); } } /// @inheritdoc IFundingPoolV1 function feesWithdrawableBy(address account) public view returns (uint256) { uint256 rawAmount = (feePoolWeight * balanceOf(account)) / totalSupply(); // Sometimes when feePoolWeight is not exactly divisible, the truncation // during division may result in rawAmount being 1 less than // `withdrawnFees`. This is ok, and that descrepancy will fix itself as // more users remove their shares/fees. assert(rawAmount + 1 >= withdrawnFees[account]); rawAmount = Math.max(rawAmount, withdrawnFees[account]); return rawAmount - withdrawnFees[account]; } /// @inheritdoc IFundingPoolV1 function collectedFees() public view returns (uint256) { return feePoolWeight - totalWithdrawnFees; } /// @inheritdoc IFundingPoolV1 function reserves() public view returns (uint256 collateral) { uint256 totalCollateral = collateralToken.balanceOf(address(this)); uint256 fees = collectedFees(); assert(totalCollateral >= fees); return totalCollateral - fees; } // solhint-disable-next-line func-name-mixedcase function __FundingPool_init(IERC20Metadata _collateralToken) internal onlyInitializing { __ERC20_init("", ""); __FundingPool_init_unchained(_collateralToken); } // solhint-disable-next-line func-name-mixedcase function __FundingPool_init_unchained(IERC20Metadata _collateralToken) internal onlyInitializing { if (_collateralToken.decimals() > 18) revert ExcessiveCollateralDecimals(); collateralToken = _collateralToken; } /// @dev Burns the LP shares corresponding to a particular owner account /// Also note that _beforeTokenTransfer will be invoked to make sure the fee /// bookkeeping is updated for the owner. /// @param owner Account to whom the LP shares belongs to. /// @param sharesToBurn Portion of LP pool to burn. function _burnSharesOf(address owner, uint256 sharesToBurn) internal { // slither-disable-next-line dangerous-strict-equalities if (sharesToBurn == 0) revert InvalidBurnAmount(); uint256 costBasisReduction = FundingMath.calcCostBasisReduction(balanceOf(owner), sharesToBurn, funderCostBasis[owner]); funderCostBasis[owner] -= costBasisReduction; totalFunderCostBasis -= costBasisReduction; _burn(owner, sharesToBurn); } function _mintSharesFor(address receiver, uint256 collateralAdded, uint256 poolValue) internal returns (uint256 sharesMinted) { if (collateralAdded == 0) revert InvalidFundingAmount(); sharesMinted = FundingMath.calcFunding(collateralAdded, totalSupply(), poolValue); // Ensure this stays below type(uint128).max to avoid overflow in liquidity calculations uint256 costBasisAfter = funderCostBasis[receiver] + collateralAdded; if (costBasisAfter > type(uint128).max) revert ExcessiveFunding(); funderCostBasis[receiver] = costBasisAfter; totalFunderCostBasis += collateralAdded; address sender = _msgSender(); collateralToken.safeTransferFrom(sender, address(this), collateralAdded); // Ensure total shares for funding does not exceed type(uint128).max to avoid overflow uint256 sharesAfter = balanceOf(receiver) + sharesMinted; if (sharesAfter > type(uint128).max) revert ExcessiveFunding(); _mint(receiver, sharesMinted); emit FundingAdded(sender, receiver, collateralAdded, sharesMinted); } /// @dev adjust cost basis for a funder function _adjustCostBasis(address funder, uint256 adjustment) internal { funderCostBasis[funder] = funderCostBasis[funder] + adjustment; totalFunderCostBasis = totalFunderCostBasis + adjustment; } /// @notice Computes the fees when positions are bought, sold or transferred function _beforeTokenTransfer(address from, address to, uint256 amount) internal override { if (from != address(0)) { // LP tokens being transferred away from a funder - any fees that // have accumulated so far due to trading activity should be given // to the original owner for the period of time he held the LP // tokens withdrawFees(from); } // `supply` includes `amount` during: // - funder to funder transfer // - burning // `supply` does _not_ include `amount` during: // - minting uint256 supply = totalSupply(); // Fee pool weight proportional to the shares of LP total supply. This // proportion of fee pool weight will be transferred between funders, so // that their claim to the fees does not increase/descrease // instantaneously. uint256 withdrawnFeesTransfer; if (from != address(0)) { // Transferring lp shares away from a funder withdrawnFeesTransfer = (withdrawnFees[from] * amount) / balanceOf(from); withdrawnFees[from] = withdrawnFees[from] - withdrawnFeesTransfer; totalWithdrawnFees = totalWithdrawnFees - withdrawnFeesTransfer; } else { // minting new lp shares. Grow the weight of the fee pool // proportionally to the LP total supply // slither-disable-next-line dangerous-strict-equalities withdrawnFeesTransfer = supply == 0 ? feePoolWeight : (feePoolWeight * amount) / supply; feePoolWeight = feePoolWeight + withdrawnFeesTransfer; } if (to != address(0)) { // Transferring lp shares to a funder withdrawnFees[to] = withdrawnFees[to] + withdrawnFeesTransfer; totalWithdrawnFees = totalWithdrawnFees + withdrawnFeesTransfer; } else { // burning lp shares. Shrink the weight of the fee pool // proportionally to the LP total supply feePoolWeight = feePoolWeight - withdrawnFeesTransfer; } } /// @dev Sets aside some collateral as fees function _retainFees(uint256 collateralFees) internal { if (collateralFees > reserves()) revert FeesExceedReserves(); feePoolWeight = feePoolWeight + collateralFees; emit FeesRetained(collateralFees); } /// @dev implement this to get a callback when fees are transferred // solhint-disable-next-line no-empty-blocks function _afterFeesWithdrawn(address funder, uint256 collateralRemovedFromFees) internal virtual { } /// @dev How much collateral was spent by all funders to obtain their current shares function getTotalFunderCostBasis() public view returns (uint256) { return totalFunderCostBasis; } function getFunderCostBasis(address funder) public view returns (uint256) { return funderCostBasis[funder]; } // solhint-disable-next-line ordering uint256[50] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol"; import { ContextUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; interface ParentFundingPoolErrors { /// @dev Occurs when a child pool does not support the necessary interfaces error NotAChildPool(address childPool); /// @dev Occurs when a child pool is not approved to perform the operation error ChildPoolNotApproved(address childPool); /// @dev Occurs when batch operations have mismatching array lengths error InvalidBatchLength(); } interface ParentFundingPoolEvents { /// @dev A child pool approval was added or removed event ChildPoolApproval(address indexed childPool, uint256 approved); /// @dev Limit of how much can be requested has changed event RequestLimitChanged(uint256 limit); /// @dev A child pool has requested some funds, and the parent gives it. The /// value locked into the child is exactly equal to the collateralGiven event FundingGiven(address indexed childPool, uint256 collateralGiven); /// @dev A child pool has returned some funding, unlocking some value /// @param childPool the child pool that borrowed the funds /// @param collateralReturned quantity of collateral given back to the pool /// @param valueUnlocked due to profit/loss, collateral returned may not /// equal in value to what was originally given. valueUnlocked corresponds /// to the portion of original collateral that is returned event FundingReturned(address indexed childPool, uint256 collateralReturned, uint256 valueUnlocked); } /// @dev Interface for a FundingPool that allows child FundingPools to request/return funds interface IParentFundingPoolV1 is IERC165Upgradeable, ParentFundingPoolEvents, ParentFundingPoolErrors { /// @dev childPool should support IFundingPoolV1 interface function setApprovalForChild(address childPool, uint256 approval) external; /// @dev Called by an approved child pool, to request collateral /// NOTE: assumes msg.sender supports IFundingPool that is approved /// @param collateralRequested how much collateral is requested by the childPool /// @return collateralAdded Actual amount given (which may be lower than collateralRequested) /// @return sharesMinted How many child shares were given due to the funding function requestFunding(uint256 collateralRequested) external returns (uint256 collateralAdded, uint256 sharesMinted); /// @dev Notify parent after voluntarily returning back some collateral, and burning corresponding shares /// @param collateralReturned how much collateral funding was transferred from child to parent /// @param sharesBurnt how many child shares were burnt as a result function fundingReturned(uint256 collateralReturned, uint256 sharesBurnt) external; /// @dev Notify parent after voluntarily returning back some fees /// @param fees how much fees (in collateral) was transferred from child to parent function feesReturned(uint256 fees) external; /// @dev What is the maximum amount of collateral a child can request from the parent function getApprovalForChild(address childPool) external view returns (uint256 approval); /// @dev See how much funding is available for a particular child pool. /// Takes into account how much has already been consumed from the approval, /// and how much collateral is available in the pool. /// @param childPool address of the childPool /// @return availableFunding how much collateral can be requested, that takes into account any gains or losses /// @return targetFunding The target funding amount that can be requested, without gains or losses function getAvailableFunding(address childPool) external view returns (uint256 availableFunding, uint256 targetFunding); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; // Note on libraries. If any functions are not `internal`, then contracts that // use the libraries, must be linked. library ArrayMath { function sum(uint256[] memory values) internal pure returns (uint256) { uint256 result = 0; for (uint256 i = 0; i < values.length; i++) { result += values[i]; } return result; } function hasNonzeroEntries(uint256[] memory values) internal pure returns (bool) { for (uint256 i = 0; i < values.length; i++) { if (values[i] > 0) return true; } return false; } } /// @dev Math with saturation/clamping for overflow/underflow handling library ClampedMath { /// @dev min(upper, max(lower, x)) function clampBetween(uint256 x, uint256 lower, uint256 upper) internal pure returns (uint256) { unchecked { return x < lower ? lower : (x > upper ? upper : x); } } /// @dev max(0, a - b) function subClamp(uint256 a, uint256 b) internal pure returns (uint256) { unchecked { return a > b ? a - b : 0; } } /// @dev min(type(uint256).max, max(0, a + b)) function addClamp(uint256 a, int256 b) internal pure returns (uint256) { unchecked { if (b < 0) { // The absolute value of type(int256).min is not representable // in int256, so have to dance about with the + 1 uint256 positiveB = uint256(-(b + 1)) + 1; return (a > positiveB) ? (a - positiveB) : 0; } else { return type(uint256).max - a > uint256(b) ? a + uint256(b) : type(uint256).max; } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol"; interface ChildFundingPoolErrors { error NotAParentPool(address parentPool); } interface ChildFundingPoolEvents { event ParentPoolAdded(address indexed parentPool); } /// @dev Interface for a funding pool that can be added as a child to a Parent Funding pool interface IChildFundingPoolV1 is IERC165Upgradeable, ChildFundingPoolEvents, ChildFundingPoolErrors { function getParentPool() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ``` * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes calldata data ) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; type QuestionID is bytes32; type ConditionID is bytes32; type CollectionID is bytes32; library CTHelpers { /// @dev Constructs a condition ID from an oracle, a question ID, and the /// outcome slot count for the question. /// @param oracle The account assigned to report the result for the prepared condition. /// @param questionId An identifier for the question to be answered by the oracle. /// @param outcomeSlotCount The number of outcome slots which should be used /// for this condition. Must not exceed 256. function getConditionId(address oracle, QuestionID questionId, uint256 outcomeSlotCount) internal pure returns (ConditionID) { assert(outcomeSlotCount < 257); // `<` uses less gas than `<=` return ConditionID.wrap(keccak256(abi.encodePacked(oracle, questionId, outcomeSlotCount))); } /// @dev Constructs an outcome collection ID /// @param conditionId Condition ID of the outcome collection /// @param index outcome index function getCollectionId(ConditionID conditionId, uint256 index) internal pure returns (CollectionID) { return CollectionID.wrap(keccak256(abi.encodePacked(conditionId, index))); } /// @dev Constructs a position ID from a collateral token and an outcome /// collection. These IDs are used as the ERC-1155 ID for this contract. /// @param collateralToken Collateral token which backs the position. /// @param collectionId ID of the outcome collection associated with this position. function getPositionId(IERC20 collateralToken, CollectionID collectionId) internal pure returns (uint256) { return uint256(keccak256(abi.encodePacked(collateralToken, collectionId))); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; interface ConditionalTokensErrors { error ConditionAlreadyPrepared(); error PayoutAlreadyReported(); error PayoutsAreAllZero(); error InvalidOutcomeSlotCountsArray(); error InvalidPayoutArray(); error ResultNotReceivedYet(); error InvalidIndex(); error NoPositionsToRedeem(); error ConditionNotFound(); error InvalidAmount(); error InvalidOutcomeSlotsAmount(); error InvalidQuantities(); /// @dev using unapproved ERC20 token with protocol error InvalidERC20(); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { MarketErrors } from "./MarketErrors.sol"; import { IFundingPoolV1 } from "../funding/IFundingPoolV1.sol"; import { IUpdateFairPrices } from "./IUpdateFairPrices.sol"; /// @dev Interface evolution is done by creating new versions of the interfaces /// and making sure that the derived MarketMaker supports all of them. /// Alternatively we could have gone with breaking the interface down into each /// function one by one and checking each function selector. This would /// introduce a lot more code in `supportsInterface` which is called often, so /// it's easier to keep track of incremental evolution than all the constituent /// pieces interface IMarketMakerV1 is IFundingPoolV1, IUpdateFairPrices, MarketErrors { event MarketBuy( address indexed buyer, uint256 investmentAmount, uint256 feeAmount, uint256 indexed outcomeIndex, uint256 outcomeTokensBought ); event MarketSell( address indexed seller, uint256 returnAmount, uint256 feeAmount, uint256 indexed outcomeIndex, uint256 outcomeTokensSold ); event MarketSpontaneousPrices(uint256[] spontaneousPrices); function removeFunding(uint256 sharesToBurn) external returns (uint256 collateral, uint256[] memory sendAmounts); function buyFor(address receiver, uint256 investmentAmount, uint256 outcomeIndex, uint256 minOutcomeTokensToBuy) external returns (uint256 outcomeTokensBought, uint256 feeAmount, uint256[] memory spontaneousPrices); function buy(uint256 investmentAmount, uint256 outcomeIndex, uint256 minOutcomeTokensToBuy) external returns (uint256 outcomeTokensBought, uint256 feeAmount, uint256[] memory spontaneousPrices); function sell(uint256 returnAmount, uint256 outcomeIndex, uint256 maxOutcomeTokensToSell) external returns (uint256 outcomeTokensSold); function removeCollateralFundingOf(address ownerAndReceiver, uint256 sharesToBurn) external returns (uint256[] memory sendAmounts, uint256 collateral); function removeAllCollateralFunding(address[] calldata funders) external returns (uint256 totalSharesBurnt, uint256 totalCollateralRemoved); function isHalted() external view returns (bool); function calcBuyAmount(uint256 investmentAmount, uint256 outcomeIndex) external view returns (uint256 outcomeTokensBought, uint256 feeAmount, uint256[] memory spontaneousPrices); function calcSellAmount(uint256 returnAmount, uint256 outcomeIndex) external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IConditionalTokens } from "../conditions/IConditionalTokens.sol"; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; struct MarketAddressParams { IConditionalTokens conditionalTokens; IERC20Metadata collateralToken; address parentPool; address priceOracle; address conditionOracle; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; interface AmmErrors { error InvalidOutcomeIndex(); error InvalidPrices(); error NoLiquidityAvailable(); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; interface FundingErrors { error InvalidFundingAmount(); error InvalidBurnAmount(); error InvalidReceiverAddress(); error PoolValueZero(); /// @dev Fee is is or exceeds 100% error InvalidFee(); /// @dev Trying to retain fees that exceed the current reserves error FeesExceedReserves(); /// @dev Funding is so large, that it may lead to overflow errors in future /// actions error ExcessiveFunding(); /// @dev Collateral ERC20 decimals exceed 18, leading to potential overflows error ExcessiveCollateralDecimals(); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20PermitUpgradeable { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20Upgradeable.sol"; import "./extensions/IERC20MetadataUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../proxy/utils/Initializable.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.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead 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 ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { 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 default 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. */ function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _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: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, 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}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, 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}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, 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) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, 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) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This 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: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; } emit Transfer(from, to, amount); _afterTokenTransfer(from, to, 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: * * - `account` 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; unchecked { // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. _balances[account] += amount; } emit Transfer(address(0), account, amount); _afterTokenTransfer(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"); unchecked { _balances[account] = accountBalance - amount; // Overflow not possible: amount <= accountBalance <= totalSupply. _totalSupply -= amount; } emit Transfer(account, address(0), amount); _afterTokenTransfer(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 Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - 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 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 {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[45] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IFundingPoolV1 } from "./IFundingPoolV1.sol"; /// @dev An extension to IFundingPoolV1 that adds more methods to inspect cost basis, interface IFundingPoolV1_1 is IFundingPoolV1 { /// @dev How much collateral was spent by a funder to obtain their current shares function getFunderCostBasis(address funder) external returns (uint256); /// @dev How much collateral was spent by all funders to obtain their current shares function getTotalFunderCostBasis() external returns (uint256); /// @dev Current estimated value in collateral of the entire pool function getPoolValue() external returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { ClampedMath } from "../Math.sol"; import { FundingErrors } from "./FundingErrors.sol"; library FundingMath { using ClampedMath for uint256; using Math for uint256; uint256 internal constant SHARE_PRECISION_DECIMALS = 4; uint256 internal constant SHARE_PRECISION_OFFSET = 10 ** SHARE_PRECISION_DECIMALS; /// @dev We always try to keep the pools balanced. There are never any /// "sendBackAmounts" like in a typical constant product AMM where the /// balances need to be maintained to determine the prices. We want to /// use all the available collateral for liquidity no matter what the /// probabilities of the outcomes are. /// @param collateralAdded how much collateral the funder is adding to the pool /// @param totalShares the current number of liquidity pool shares in circulation /// @param poolValue total sum of value of all tokens /// @return sharesMinted how many liquidity pool shares should be minted function calcFunding(uint256 collateralAdded, uint256 totalShares, uint256 poolValue) internal pure returns (uint256 sharesMinted) { // To prevent inflation attack. See articles and reference implementation: // https://mixbytes.io/blog/overview-of-the-inflation-attack // https://docs.openzeppelin.com/contracts/4.x/erc4626#defending_with_a_virtual_offset // https://github.com/boringcrypto/YieldBox/blob/master/contracts/YieldBoxRebase.sol#L24-L29 poolValue++; totalShares += SHARE_PRECISION_OFFSET; assert(totalShares > 0); // mint LP tokens proportional to how much value the new investment // brings to the pool sharesMinted = (collateralAdded * totalShares).ceilDiv(poolValue); } /// @dev Calculate how much of an asset in the liquidity pool to return to a funder. /// @param sharesToBurn how many liquidity pool shares a funder wants to burn /// @param totalShares the current number of liquidity pool shares in circulation /// @param balance number of an asset in the pool /// @return sendAmount how many asset tokens to give back to funder function calcReturnAmount(uint256 sharesToBurn, uint256 totalShares, uint256 balance) internal pure returns (uint256 sendAmount) { if (sharesToBurn > totalShares) revert FundingErrors.InvalidBurnAmount(); if (sharesToBurn == 0) return sendAmount; sendAmount = (balance * sharesToBurn) / totalShares; } /// @dev Calculate how much of the assets in the liquidity pool to return to a funder. /// @param sharesToBurn how many liquidity pool shares a funder wants to burn /// @param totalShares the current number of liquidity pool shares in circulation /// @param balances number of each asset in the pool /// @return sendAmounts how many asset tokens to give back to funder function calcReturnAmounts(uint256 sharesToBurn, uint256 totalShares, uint256[] memory balances) internal pure returns (uint256[] memory sendAmounts) { if (sharesToBurn > totalShares) revert FundingErrors.InvalidBurnAmount(); sendAmounts = new uint256[](balances.length); if (sharesToBurn == 0) return sendAmounts; for (uint256 i = 0; i < balances.length; i++) { sendAmounts[i] = (balances[i] * sharesToBurn) / totalShares; } } /// @dev Calculate how much to reduce the cost basis due to shares being burnt /// @param funderShares how many liquidity pool shares a funder currently owns /// @param sharesToBurn how many liquidity pool shares a funder currently owns /// @param funderCostBasis how much collateral was spent acquiring the funder's liquidity pool shares /// @return costBasisReduction the amount by which to reduce the costbasis for the funder function calcCostBasisReduction(uint256 funderShares, uint256 sharesToBurn, uint256 funderCostBasis) internal pure returns (uint256 costBasisReduction) { if (sharesToBurn > funderShares) revert FundingErrors.InvalidBurnAmount(); costBasisReduction = funderShares == 0 ? 0 : (funderCostBasis * sharesToBurn) / funderShares; } /// @dev Calculate how many shares to burn for an asset, so that how many /// parent shares are removed are not a larger proportion of funder's /// shares, than the proportion of the asset value among other assets. /// /// i.e. /// ((funderSharesRemovedAsAsset + sharesBurnt) / funderTotalShares) /// <= /// (assetValue / totalValue) /// /// @param funderTotalShares Total parent shares owned and removed by funder /// @param sharesToBurn How many funder shares we're trying to burn /// @param funderSharesRemovedAsAsset quantity of shares already removed as the asset /// @param assetValue current value of the asset /// @param totalValue the total value to compare the asset value to. The /// ratio of asset value to this total is what sharesBurnt should not exceed /// @return sharesBurnt quantity of shares that can be burnt given the above restrictions function calcMaxParentSharesToBurnForAsset( uint256 funderTotalShares, uint256 sharesToBurn, uint256 funderSharesRemovedAsAsset, uint256 assetValue, uint256 totalValue ) internal pure returns (uint256 sharesBurnt) { uint256 maxShares = ((funderTotalShares * assetValue).ceilDiv(totalValue)).subClamp(funderSharesRemovedAsAsset); sharesBurnt = Math.min(sharesToBurn, maxShares); if (sharesBurnt > 0) { // This is a re-arrangement of the inequality given in the // description. It only applies when we are trying to give out some // shares. If sharesBurnt is 0, that means we've already exceeded // how many shares we can safely burn, so the inequality is // violated. // The -1 is due to the rounding up in ceilDiv above, used to // prevent never being able to burn the last remaining share assert(((funderSharesRemovedAsAsset + sharesBurnt - 1) * totalValue) < (assetValue * funderTotalShares)); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import { FundingErrors } from "./FundingErrors.sol"; interface FundingPoolEvents { /// @notice Collateral is added to the liquidity pool /// @param sender the account that initiated and supplied the collateral for the funding /// @param funder the account that receives the liquidity pool shares /// @param collateralAdded the quantity of collateral supplied to the pool /// @param sharesMinted the quantity of liquidity pool shares created as sa result of the funding event FundingAdded(address indexed sender, address indexed funder, uint256 collateralAdded, uint256 sharesMinted); /// @notice Funding is removed as a mix of tokens and collateral /// @param funder the owner of liquidity pool shares /// @param collateralRemoved the quantity of collateral removed from the pool proportional to funder's shares /// @param tokensRemoved the quantity of tokens removed from the pool proportional to funder's shares. Can be empty /// @param sharesBurnt the quantity of liquidity pool shares burnt event FundingRemoved( address indexed funder, uint256 collateralRemoved, uint256[] tokensRemoved, uint256 sharesBurnt ); /// @notice Funding is removed as a specific token, referred to by an id /// @param funder the owner of liquidity pool shares /// @param tokenId an id that identifies a single asset token in the pool. Up to the pool to decide the meaning of the id /// @param tokensRemoved the quantity of a token removed from the pool /// @param sharesBurnt the quantity of liquidity pool shares burnt event FundingRemovedAsToken( address indexed funder, uint256 indexed tokenId, uint256 tokensRemoved, uint256 sharesBurnt ); /// @notice Some portion of collateral was withdrawn for fee purposes event FeesWithdrawn(address indexed funder, uint256 collateralRemovedFromFees); /// @notice Some portion of collateral was retained for fee purposes event FeesRetained(uint256 collateralAddedToFees); } /// @dev A funding pool deals with 3 different assets: /// - collateral with which to make investments (ERC20 tokens of general usage, e.g. USDT, USDC, DAI, etc.) /// - shares which represent the stake in the fund (ERC20 tokens minted and burned by the funding pool) /// - tokens that are the actual investments (e.g. ERC1155 conditional tokens) interface IFundingPoolV1 is IERC20Upgradeable, FundingErrors, FundingPoolEvents { /// @notice Funds the market with collateral from the sender /// @param collateralAdded Amount of funds from the sender to transfer to the market function addFunding(uint256 collateralAdded) external returns (uint256 sharesMinted); /// @notice Funds the market on behalf of receiver. /// @param receiver Account that receives LP tokens. /// @param collateralAdded Amount of funds from the sender to transfer to the market function addFundingFor(address receiver, uint256 collateralAdded) external returns (uint256 sharesMinted); /// @notice Withdraws the fees from a particular liquidity provider. /// @param funder Account address to withdraw its available fees. function withdrawFees(address funder) external returns (uint256 collateralRemovedFromFees); /// @notice Returns the amount of fee in collateral to be withdrawn by the liquidity providers. /// @param account Account address to check for fees available. function feesWithdrawableBy(address account) external view returns (uint256 collateralFees); /// @notice How much collateral is available that is not set aside for fees function reserves() external view returns (uint256 collateral); /// @notice Returns the current collected fees on this market. function collectedFees() external view returns (uint256 collateralFees); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; interface UpdateFairPricesEvents { event MarketPricesUpdated(uint256[] fairPriceDecimals); event MarketMinPriceUpdated(uint128 minPriceDecimal); } interface IUpdateFairPrices is UpdateFairPricesEvents { function updateFairPrices(uint256[] calldata fairPriceDecimals) external; function updateMinPrice(uint128 minPriceDecimal) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20MetadataUpgradeable is IERC20Upgradeable { /** * @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); }
{ "remappings": [ "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", "@prb/math/=lib/prb-math/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/", "upgrade-scripts/=lib/upgrade-scripts/src/", "UDS/=lib/upgrade-scripts/lib/UDS/src/", "@prb/test/=lib/prb-math/lib/prb-test/src/", "futils/=lib/upgrade-scripts/lib/UDS/lib/futils/src/", "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "prb-math/=lib/prb-math/src/", "prb-test/=lib/prb-math/lib/prb-test/src/", "src/=lib/prb-math/src/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "viaIR": false, "libraries": {} }
[{"inputs":[{"components":[{"internalType":"contract IConditionalTokens","name":"conditionalTokens","type":"address"},{"internalType":"contract IERC20Metadata","name":"collateralToken","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"address","name":"executor","type":"address"}],"internalType":"struct MarketFundingPool.Params","name":"params","type":"tuple"},{"internalType":"address","name":"prevPool","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"childPool","type":"address"}],"name":"ChildPoolNotApproved","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"DoesNotSupportMigrateFundsInterface","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"DoesNotSupportParentPoolInterface","type":"error"},{"inputs":[],"name":"ExcessiveCollateralDecimals","type":"error"},{"inputs":[],"name":"ExcessiveFunding","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"FactoryNotApproved","type":"error"},{"inputs":[],"name":"FeesExceedReserves","type":"error"},{"inputs":[],"name":"InvalidBatchLength","type":"error"},{"inputs":[],"name":"InvalidBurnAmount","type":"error"},{"inputs":[],"name":"InvalidFee","type":"error"},{"inputs":[],"name":"InvalidFundingAmount","type":"error"},{"inputs":[],"name":"InvalidInvestmentAmount","type":"error"},{"inputs":[],"name":"InvalidLimitsArray","type":"error"},{"inputs":[],"name":"InvalidOutcomeIndex","type":"error"},{"inputs":[],"name":"InvalidPrices","type":"error"},{"inputs":[],"name":"InvalidReceiverAddress","type":"error"},{"inputs":[],"name":"InvalidReturnAmount","type":"error"},{"inputs":[],"name":"InvestmentDrainsPool","type":"error"},{"inputs":[],"name":"MarketHalted","type":"error"},{"inputs":[],"name":"MarketUndecided","type":"error"},{"inputs":[],"name":"MaximumSellAmountExceeded","type":"error"},{"inputs":[],"name":"MinimumBuyAmountNotReached","type":"error"},{"inputs":[],"name":"MustBeCalledByOracle","type":"error"},{"inputs":[],"name":"NoLiquidityAvailable","type":"error"},{"inputs":[],"name":"NoPrevPoolConfigured","type":"error"},{"inputs":[{"internalType":"address","name":"childPool","type":"address"}],"name":"NotAChildPool","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"NotAFactory","type":"error"},{"inputs":[{"internalType":"address","name":"parentPool","type":"address"}],"name":"NotAParentPool","type":"error"},{"inputs":[],"name":"OperationNotSupported","type":"error"},{"inputs":[],"name":"PoolValueZero","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"SenderIsNotPrevPool","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"childPool","type":"address"},{"indexed":false,"internalType":"uint256","name":"approved","type":"uint256"}],"name":"ChildPoolApproval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"collateralAddedToFees","type":"uint256"}],"name":"FeesRetained","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"funder","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralRemovedFromFees","type":"uint256"}],"name":"FeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"funder","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralAdded","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesMinted","type":"uint256"}],"name":"FundingAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"childPool","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralGiven","type":"uint256"}],"name":"FundingGiven","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"funder","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralRemoved","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"tokensRemoved","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"sharesBurnt","type":"uint256"}],"name":"FundingRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"funder","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensRemoved","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesBurnt","type":"uint256"}],"name":"FundingRemovedAsToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"childPool","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralReturned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"valueUnlocked","type":"uint256"}],"name":"FundingReturned","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"factory","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"MarketFactoryApproval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralMigrated","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"costBasis","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesGranted","type":"uint256"}],"name":"MigratedFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"parentPool","type":"address"}],"name":"ParentPoolAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"limit","type":"uint256"}],"name":"RequestLimitChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EXECUTOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"collateralAdded","type":"uint256"}],"name":"addFunding","outputs":[{"internalType":"uint256","name":"sharesMinted","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"collateralAdded","type":"uint256"}],"name":"addFundingFor","outputs":[{"internalType":"uint256","name":"sharesMinted","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"children","type":"address[]"},{"internalType":"uint256[]","name":"sharesToBurn","type":"uint256[]"}],"name":"batchRemoveChildShares","outputs":[{"internalType":"uint256","name":"totalSharesBurnt","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"funder","type":"address"},{"internalType":"uint256","name":"sharesToBurn","type":"uint256"}],"name":"calcRemoveCollateral","outputs":[{"internalType":"uint256","name":"collateralReturned","type":"uint256"},{"internalType":"uint256","name":"sharesBurnt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"checkAdmin","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"checkExecutor","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateralToken","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collectedFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"conditionalTokens","outputs":[{"internalType":"contract IConditionalTokens","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IMarketFactory","name":"factory","type":"address"},{"internalType":"address","name":"priceOracle","type":"address"},{"internalType":"address","name":"conditionOracle","type":"address"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256[]","name":"marketLimits","type":"uint256[]"},{"components":[{"internalType":"QuestionID","name":"questionId","type":"bytes32"},{"internalType":"uint256[]","name":"fairPriceDecimals","type":"uint256[]"},{"internalType":"uint128","name":"minPriceDecimal","type":"uint128"},{"internalType":"uint256","name":"haltTime","type":"uint256"}],"internalType":"struct IMarketFactory.PriceMarketParams[]","name":"marketParamsArray","type":"tuple[]"}],"name":"createMarketsWithPrices","outputs":[{"internalType":"contract IMarketMakerV1[]","name":"markets","type":"address[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fees","type":"uint256"}],"name":"feesReturned","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"feesWithdrawableBy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"collateralReturned","type":"uint256"},{"internalType":"uint256","name":"childSharesBurnt","type":"uint256"}],"name":"fundingReturned","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"childPool","type":"address"}],"name":"getApprovalForChild","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"childPool","type":"address"}],"name":"getAvailableFunding","outputs":[{"internalType":"uint256","name":"availableFunding","type":"uint256"},{"internalType":"uint256","name":"availableTarget","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"factory","type":"address"}],"name":"getFactoryApproval","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"funder","type":"address"}],"name":"getFunderCostBasis","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getParentPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolValue","outputs":[{"internalType":"uint256","name":"poolValue","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalFunderCostBasis","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"migrateFundsFromSender","outputs":[{"internalType":"uint256","name":"collateralMigrated","type":"uint256"},{"internalType":"uint256","name":"costBasis","type":"uint256"},{"internalType":"uint256","name":"sharesGranted","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newPool","type":"address"}],"name":"migrateFundsTo","outputs":[{"internalType":"uint256","name":"collateralMigrated","type":"uint256"},{"internalType":"uint256","name":"costBasis","type":"uint256"},{"internalType":"uint256","name":"sharesGranted","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"child","type":"address"},{"internalType":"uint256","name":"sharesToBurn","type":"uint256"}],"name":"removeChildShares","outputs":[{"internalType":"uint256","name":"childSharesReturned","type":"uint256"},{"internalType":"uint256","name":"sharesBurnt","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"sharesToBurn","type":"uint256"}],"name":"removeCollateral","outputs":[{"internalType":"uint256","name":"collateralReturned","type":"uint256"},{"internalType":"uint256","name":"sharesBurnt","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"collateralRequested","type":"uint256"}],"name":"requestFunding","outputs":[{"internalType":"uint256","name":"collateralAdded","type":"uint256"},{"internalType":"uint256","name":"sharesMinted","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"requestLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"reserves","outputs":[{"internalType":"uint256","name":"collateral","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"childPool","type":"address"},{"internalType":"uint256","name":"approval","type":"uint256"}],"name":"setApprovalForChild","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"factory","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setFactoryApproval","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"limit","type":"uint256"}],"name":"setRequestLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalChildValueLocked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"funder","type":"address"}],"name":"withdrawFees","outputs":[{"internalType":"uint256","name":"collateralRemovedFromFees","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60a06040523480156200001157600080fd5b5060405162004cca38038062004cca8339810160408190526200003491620007fa565b60408201516020830151609e805460ff19169055828262000057600082620000b9565b5062000064828262000160565b6200006e6200028f565b505082516001600160a01b0316608052506060820151620000b1907fd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e6390620000b9565b505062000a73565b6000828152609d602090815260408083206001600160a01b038516845290915290205460ff166200015c576000828152609d602090815260408083206001600160a01b03851684529091529020805460ff191660011790556200011b6200033d565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b600054610100900460ff1615808015620001815750600054600160ff909116105b80620001b157506200019e306200035960201b620020401760201c565b158015620001b1575060005460ff166001145b6200021a5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff1916600117905580156200023e576000805461ff0019166101001790555b620002498362000368565b6200025482620003f8565b80156200028a576000805461ff00191690556040516001815260008051602062004caa8339815191529060200160405180910390a15b505050565b600054610100900460ff1615620002f95760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840162000211565b60005460ff90811610156200033b576000805460ff191660ff90811790915560405190815260008051602062004caa8339815191529060200160405180910390a15b565b6000620003546200045f60201b6200204f1760201c565b905090565b6001600160a01b03163b151590565b600054610100900460ff16620003c45760405162461bcd60e51b815260206004820152602b602482015260008051602062004c8a83398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000211565b604080516020808201835260008083528351918201909352918252620003ea9162000463565b620003f581620004cb565b50565b600054610100900460ff16620004545760405162461bcd60e51b815260206004820152602b602482015260008051602062004c8a83398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000211565b620003f581620005d3565b3390565b600054610100900460ff16620004bf5760405162461bcd60e51b815260206004820152602b602482015260008051602062004c8a83398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000211565b6200015c828262000755565b600054610100900460ff16620005275760405162461bcd60e51b815260206004820152602b602482015260008051602062004c8a83398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000211565b6012816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000568573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200058e9190620008b3565b60ff161115620005b1576040516347aad2ef60e11b815260040160405180910390fd5b606580546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff166200062f5760405162461bcd60e51b815260206004820152602b602482015260008051602062004c8a83398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000211565b609e5461010090046001600160a01b031615620006505762000650620008df565b6001600160a01b03811615801590620006d857506040516301ffc9a760e01b8152636831974d60e11b60048201526001600160a01b038216906301ffc9a790602401602060405180830381865afa158015620006b0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620006d69190620008f5565b155b1562000703576040516320d6c2ad60e01b81526001600160a01b038216600482015260240162000211565b609e8054610100600160a81b0319166101006001600160a01b038416908102919091179091556040517f18da49b0178612731ce8a0d4a3052637cc23b8bfb85385e67c4373011d86ed1390600090a250565b600054610100900460ff16620007b15760405162461bcd60e51b815260206004820152602b602482015260008051602062004c8a83398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000211565b6036620007bf8382620009a7565b5060376200028a8282620009a7565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114620003f557600080fd5b60008082840360a08112156200080f57600080fd5b60808112156200081e57600080fd5b50604051608081016001600160401b0381118282101715620008445762000844620007ce565b60405283516200085481620007e4565b815260208401516200086681620007e4565b602082015260408401516200087b81620007e4565b604082015260608401516200089081620007e4565b60608201526080840151909250620008a881620007e4565b809150509250929050565b600060208284031215620008c657600080fd5b815160ff81168114620008d857600080fd5b9392505050565b634e487b7160e01b600052600160045260246000fd5b6000602082840312156200090857600080fd5b81518015158114620008d857600080fd5b600181811c908216806200092e57607f821691505b6020821081036200094f57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200028a57600081815260208120601f850160051c810160208610156200097e5750805b601f850160051c820191505b818110156200099f578281556001016200098a565b505050505050565b81516001600160401b03811115620009c357620009c3620007ce565b620009db81620009d4845462000919565b8462000955565b602080601f83116001811462000a135760008415620009fa5750858301515b600019600386901b1c1916600185901b1785556200099f565b600085815260208120601f198616915b8281101562000a445788860151825594840194600190910190840162000a23565b508582101562000a635787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6080516141f462000a966000396000818161054101526109c401526141f46000f3fe608060405234801561001057600080fd5b50600436106103425760003560e01c806366261532116101b857806392727cdd11610104578063b8cc1f36116100a2578063d547741f1161007c578063d547741f14610759578063d77eb4c71461076c578063dd62ed3e1461077f578063efa892c31461079257600080fd5b8063b8cc1f361461071d578063cb02e53614610730578063d2da40401461074357600080fd5b8063a457c2d7116100de578063a457c2d7146106d1578063a9059cbb146106e4578063b2016bd4146106f7578063b518d9a41461070a57600080fd5b806392727cdd146106ae57806395d89b41146106c1578063a217fddf146106c957600080fd5b80637e90618e116101715780639003adfe1161014b5780639003adfe1461066d5780639026dee814610675578063909370831461068857806391d148541461069b57600080fd5b80637e90618e1461063f57806383edf317146106525780638456cb591461066557600080fd5b806366261532146105ac5780636a12209c146105d557806370a08231146105e857806372441d54146105fb57806375172a8b1461062457806379df81e41461062c57600080fd5b80633237c1581161029257806349bcbcc0116102305780635bd9e2991161020a5780635bd9e2991461053c5780635c975abb1461057b5780635cd9ef81146105865780635d5d46131461059957600080fd5b806349bcbcc01461050757806353e8c8501461052a57806354c97ff71461053357600080fd5b8063390ca1271161026c578063390ca127146104ad57806339509351146104d95780633f036cb0146104ec5780633f4ba83a146104ff57600080fd5b80633237c1581461046a57806336568abe146104925780633706c4da146104a557600080fd5b806316dbd776116102ff57806323b872dd116102d957806323b872dd14610410578063248a9ca3146104235780632f2ff15d14610446578063313ce5671461045b57600080fd5b806316dbd776146103ed57806318160ddd146104005780631ba2f5311461040857600080fd5b806301ffc9a71461034757806306fdde031461036f57806307bd026514610384578063095ea7b3146103a75780630dab3ae8146103ba578063164e68de146103da575b600080fd5b61035a6103553660046138e1565b6107a5565b60405190151581526020015b60405180910390f35b610377610857565b604051610366919061392f565b61039960008051602061419f83398151915281565b604051908152602001610366565b61035a6103b5366004613977565b6108e9565b6103cd6103c83660046139e8565b610901565b6040516103669190613a99565b6103996103e8366004613ae6565b610b6e565b6103996103fb366004613ae6565b610c28565b603554610399565b610399610cda565b61035a61041e366004613b03565b610cf6565b610399610431366004613b44565b6000908152609d602052604090206001015490565b610459610454366004613b5d565b610d1a565b005b60405160128152602001610366565b61047d610478366004613b44565b610d44565b60408051928352602083019190915201610366565b6104596104a0366004613b5d565b610e19565b606a54610399565b61035a6104bb366004613ae6565b6001600160a01b0316600090815260a5602052604090205460ff1690565b61035a6104e7366004613977565b610e97565b6104596104fa366004613b44565b610eb9565b610459610ece565b61050f610ee1565b60408051938452602084019290925290820152606001610366565b61039960a25481565b610399609f5481565b6105637f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610366565b609e5460ff1661035a565b61047d610594366004613b44565b611222565b6103996105a7366004613b44565b611365565b6103996105ba366004613ae6565b6001600160a01b0316600090815260a0602052604090205490565b6104596105e3366004613b44565b611371565b6103996105f6366004613ae6565b6113b6565b610399610609366004613ae6565b6001600160a01b031660009081526069602052604090205490565b6103996113d1565b61047d61063a366004613977565b611471565b61047d61064d366004613977565b611582565b610459610660366004613ae6565b61165a565b610459611672565b610399611683565b610459610683366004613ae6565b611695565b61047d610696366004613ae6565b6116a0565b61035a6106a9366004613b5d565b611765565b6104596106bc366004613977565b611790565b61037761192d565b610399600081565b61035a6106df366004613977565b61193c565b61035a6106f2366004613977565b6119b7565b606554610563906001600160a01b031681565b610399610718366004613977565b6119c5565b61050f61072b366004613ae6565b6119e1565b61039961073e366004613b8d565b611b94565b609e5461010090046001600160a01b0316610563565b610459610767366004613b5d565b611d73565b61045961077a366004613bf9565b611d98565b61039961078d366004613c1b565b611f31565b6104596107a0366004613c57565b611f5c565b60006001600160e01b03198216636831974d60e11b14806107d657506001600160e01b031982166306e253b560e11b145b806107f157506001600160e01b03198216635ee02cbf60e01b145b8061080c57506001600160e01b0319821663034b690160e61b145b8061082757506001600160e01b03198216635c660f9b60e11b145b8061084257506001600160e01b03198216630126f2f360e61b145b80610851575061085182612053565b92915050565b60606036805461086690613c85565b80601f016020809104026020016040519081016040528092919081815260200182805461089290613c85565b80156108df5780601f106108b4576101008083540402835291602001916108df565b820191906000526020600020905b8154815290600101906020018083116108c257829003601f168201915b5050505050905090565b6000336108f7818585612088565b5060019392505050565b6001600160a01b038816600090815260a5602052604090205460609060ff1661094d57604051631fbef81160e21b81526001600160a01b038a1660048201526024015b60405180910390fd5b83821461096d57604051630a14dfb760e21b815260040160405180910390fd5b8167ffffffffffffffff81111561098657610986613cbf565b6040519080825280602002602001820160405280156109af578160200160208202803683370190505b506040805160a0810182526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811682526065548116602083015230928201929092528a82166060820152908916608082015290915060005b83811015610b605760008b6001600160a01b031663aecc550a8a85898987818110610a3c57610a3c613cd5565b9050602002810190610a4e9190613ceb565b6040518463ffffffff1660e01b8152600401610a6c93929190613d22565b6020604051808303816000875af1158015610a8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aaf9190613e21565b90506000610acd6001600160a01b0383166319a298e760e01b6121ac565b905080610af85760405163531f290560e11b81526001600160a01b038e166004820152602401610944565b81858481518110610b0b57610b0b613cd5565b60200260200101906001600160a01b031690816001600160a01b031681525050610b4d828a8a86818110610b4157610b41613cd5565b90506020020135611790565b505080610b5990613e54565b9050610a0f565b505098975050505050505050565b6000610b7982610c28565b90508015610c23576001600160a01b03821660009081526067602052604081208054839290610ba9908490613e6d565b9091555050606854610bbc908290613e6d565b606855606554610bd6906001600160a01b031683836121c8565b816001600160a01b03167fc0819c13be868895eb93e40eaceb96de976442fa1d404e5c55f14bb65a8c489a82604051610c1191815260200190565b60405180910390a2610c23828261222b565b919050565b600080610c3460355490565b610c3d846113b6565b606654610c4a9190613e80565b610c549190613e97565b6001600160a01b038416600090815260676020526040902054909150610c7b826001613e6d565b1015610c8957610c89613eb9565b6001600160a01b038316600090815260676020526040902054610cad9082906122a7565b6001600160a01b038416600090815260676020526040902054909150610cd39082613ecf565b9392505050565b600060a254610ce76113d1565b610cf19190613e6d565b905090565b600033610d048582856122bd565b610d0f858585612337565b506001949350505050565b6000828152609d6020526040902060010154610d35816124ed565b610d3f83836124f7565b505050565b600080610d4f61257d565b33610d5a8185611582565b90935091506000829003610d6e5750915091565b6001600160a01b038116600090815260a3602052604081208054849290610d96908490613e6d565b90915550610da6905081836125c3565b606554610dbd906001600160a01b031682856121c8565b60408051600081526020810191829052906001600160a01b038316907f96bd1544577eb6c104cdc0a1e4eda89c64f8875c006dfda5baaef1aa5628b4b990610e0a90879085908890613ee2565b60405180910390a25050915091565b6001600160a01b0381163314610e895760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610944565b610e938282612668565b5050565b6000336108f7818585610eaa8383611f31565b610eb49190613e6d565b612088565b610ec2336126cf565b610ecb81612713565b50565b610ed733611695565b610edf61277c565b565b600080600080610eff609e546001600160a01b036101009091041690565b90506001600160a01b038116610f285760405163297d81a560e01b815260040160405180910390fd5b336001600160a01b03821614610f5357604051632c3b4def60e21b8152336004820152602401610944565b6000610f6f6001600160a01b038316635ee02cbf60e01b6121ac565b905080610f9a576040516320d6c2ad60e01b81526001600160a01b0383166004820152602401610944565b6000826001600160a01b0316633706c4da6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610fdc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110009190613f39565b90506000836001600160a01b03166375172a8b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611042573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110669190613f39565b90506000846001600160a01b0316631ba2f5316040518163ffffffff1660e01b81526004016020604051808303816000875af11580156110aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ce9190613f39565b9050816000036110ea5750600097889750879650945050505050565b6001600160a01b0385166000818152606960205260409020549061111590636831974d60e11b6121ac565b61112157611121613eb9565b604051635cd9ef8160e01b81526004810184905286906001600160a01b03821690635cd9ef819060240160408051808303816000875af1158015611169573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118d9190613f52565b909a509750816111b2886001600160a01b031660009081526069602052604090205490565b6111bc9190613ecf565b8a146111ca576111ca613eb9565b6111d485846122a7565b9450826111e1868c613e80565b6111eb9190613e97565b9850898910156111fd576111fd613eb9565b60006112098b8b613ecf565b905061121588826127ce565b5050505050505050909192565b60008061122d61257d565b6000611237612820565b90506000611244826116a0565b509050611251818661282b565b9350831561135e576001600160a01b038216600090815260a1602052604081208054869290611281908490613e6d565b925050819055508360a2600082825461129a9190613e6d565b90915550506065546112b6906001600160a01b0316838661283a565b604051635d5d461360e01b8152600481018590526001600160a01b03831690635d5d4613906024016020604051808303816000875af11580156112fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113219190613f39565b9250816001600160a01b03167fb741f30322e51134d94cb3c8e4d323dfbcfd60a7a86243f62faa4ae60528f8b085604051610e0a91815260200190565b5050915091565b600061085133836119c5565b61137a33611695565b609f8190556040518181527fcbfebec0d4837dbe12cf8045696140fec0f1ae16160c3474010c7ac91f4b74a2906020015b60405180910390a150565b6001600160a01b031660009081526033602052604090205490565b6065546040516370a0823160e01b815230600482015260009182916001600160a01b03909116906370a0823190602401602060405180830381865afa15801561141e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114429190613f39565b9050600061144e611683565b90508082101561146057611460613eb9565b61146a8183613ecf565b9250505090565b60008061147c61257d565b60006114878561294f565b33600081815260a4602052604081209293509091906114a58361295e565b90506114b384828985612a09565b9096509450851561157757600085116114ce576114ce613eb9565b60808101516001600160a01b03808516600090815260a36020908152604090912083518155920151600190920191909155606082015160a25561151490851684886121c8565b60408051878152602081018790526bffffffffffffffffffffffff1960608b901b16916001600160a01b038616917fe39d5363f820fc9aad3f881a88f5aa05338eaa1cfe575250c49fc7ff5bf5eaa3910160405180910390a361157783866125c3565b505050509250929050565b600080600061158f6113d1565b9050600061159b610cda565b9050806000036115be5760405163ee7b33a760e01b815260040160405180910390fd5b6001600160a01b038616600090815260a360209081526040808320815180830190925280548083526001909101549282019290925291906115fe896113b6565b6116089190613e6d565b905061161b818884600001518787612c4d565b94508460000361162e5750505050611653565b6116418561163b60355490565b85612cbe565b95508386111561157757611577613eb9565b9250929050565b610ecb60008051602061419f83398151915282612d04565b61167b33611695565b610edf612d5d565b6000606854606654610cf19190613ecf565b610ecb600082612d04565b60008060006116ae606a5490565b609f546001600160a01b038616600090815260a060205260409020549192506116d69161282b565b91506116e2818361282b565b6001600160a01b038516600090815260a1602090815260409182902082518084019093528054808452600190910154918301919091529194508493509061172a908490612d9a565b815190935061173a908590612d9a565b935061175c6117476113d1565b6020830151611757908790612db0565b61282b565b93505050915091565b6000918252609d602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6117993361165a565b80156117a7576117a761257d565b6001600160a01b038216600090815260a060205260409020548114610e935760006117e26001600160a01b0384166306e253b560e11b6121ac565b90508061180d576040516332be158160e01b81526001600160a01b0384166004820152602401610944565b60006118296001600160a01b03851663034b690160e61b6121ac565b90508080156118aa5750306001600160a01b0316846001600160a01b031663d2da40406040518163ffffffff1660e01b8152600401602060405180830381865afa15801561187b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189f9190613e21565b6001600160a01b0316145b6118d2576040516332be158160e01b81526001600160a01b0385166004820152602401610944565b6001600160a01b038416600081815260a0602052604090819020859055517f087334644551f4ef9c19d46c1dbbb3593f9f48d51f0fea493a43e312a65242489061191f9086815260200190565b60405180910390a250505050565b60606037805461086690613c85565b6000338161194a8286611f31565b9050838110156119aa5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610944565b610d0f8286868403612088565b6000336108f7818585612337565b60006119cf61257d565b610cd383836119dc610cda565b612df7565b600080806119ee33611695565b611a086001600160a01b038516636831974d60e11b6121ac565b611a305760405163793463e360e01b81526001600160a01b0385166004820152602401610944565b611a4a6001600160a01b038516630126f2f360e61b6121ac565b611a725760405163284e951160e21b81526001600160a01b0385166004820152602401610944565b6000611a7d606a5490565b9050611a9760008051602061419f83398151915233610d1a565b611aa18582611790565b611ab960008051602061419f83398151915233611d73565b609f54611ac582611371565b6000869050806001600160a01b03166349bcbcc06040518163ffffffff1660e01b81526004016060604051808303816000875af1158015611b0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b2e9190613f76565b91975095509350611b3e82611371565b60408051878152602081018790529081018590526001600160a01b038816907f2b909767077de53708f0c9bf65c9ea6cfe4ffaf377981f178880e5eb307d81299060600160405180910390a25050509193909250565b6000611b9e61257d565b838214611bbe5760405163ca3487f760e01b815260040160405180910390fd5b33600081815260a46020526040812090611bd78361295e565b905060005b87811015611d28576000611c158a8a84818110611bfb57611bfb613cd5565b9050602002016020810190611c109190613ae6565b61294f565b9050600080611c3e83868c8c88818110611c3157611c31613cd5565b9050602002013589612a09565b9092509050611c4d8189613e6d565b97508115611d065760008111611c6557611c65613eb9565b611c796001600160a01b03841688846121c8565b8b8b85818110611c8b57611c8b613cd5565b9050602002016020810190611ca09190613ae6565b60601b6bffffffffffffffffffffffff191660001c876001600160a01b03167fe39d5363f820fc9aad3f881a88f5aa05338eaa1cfe575250c49fc7ff5bf5eaa38484604051611cf9929190918252602082015260400190565b60405180910390a3611d14565b8015611d1457611d14613eb9565b50505080611d2190613e54565b9050611bdc565b5060808101516001600160a01b038416600090815260a36020908152604090912082518155910151600190910155606081015160a255611d6883856125c3565b505050949350505050565b6000828152609d6020526040902060010154611d8e816124ed565b610d3f8383612668565b6000611da2612820565b6040516370a0823160e01b815230600482015290915060009083906001600160a01b038416906370a0823190602401602060405180830381865afa158015611dee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e129190613f39565b611e1c9190613e6d565b6001600160a01b038316600090815260a1602052604081208054929350919083611e47576000611e5c565b83611e528388613e80565b611e5c9190613e97565b90506001600160ff1b03871115611e8657604051637756904960e01b815260040160405180910390fd5b6001600160ff1b03811115611e9d57611e9d613eb9565b611ea78183613ecf565b8355611eb38188613fa4565b836001016000828254611ec69190613fcb565b925050819055508060a26000828254611edf9190613ecf565b909155505060408051888152602081018390526001600160a01b038716917fdabd725b6d0865b98c42345bb716aada43ac75fcb5b70d2d189bf7afad456d2e910160405180910390a250505050505050565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b611f6533611695565b8015611f7357611f7361257d565b6000611f8f6001600160a01b0384166357662a8560e11b6121ac565b905080611fba5760405163531f290560e11b81526001600160a01b0384166004820152602401610944565b6001600160a01b038316600090815260a5602052604090205460ff16151582151514610d3f576001600160a01b038316600081815260a56020908152604091829020805460ff191686151590811790915591519182527f51228fedbb1530958ad763d83204397c34a21dc73a3525e68bdce060da256360910160405180910390a2505050565b6001600160a01b03163b151590565b3390565b60006001600160e01b03198216637965db0b60e01b148061085157506301ffc9a760e01b6001600160e01b0319831614610851565b6001600160a01b0383166120ea5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610944565b6001600160a01b03821661214b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610944565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006121b783612f75565b8015610cd35750610cd38383612fa8565b6040516001600160a01b038316602482015260448101829052610d3f90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613031565b609e546001600160a01b036101009091048116908316819003610d3f576040516303f036cb60e41b8152600481018390526001600160a01b03821690633f036cb090602401600060405180830381600087803b15801561228a57600080fd5b505af115801561229e573d6000803e3d6000fd5b50505050505050565b60008183116122b65781610cd3565b5090919050565b60006122c98484611f31565b9050600019811461233157818110156123245760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610944565b6123318484848403612088565b50505050565b6001600160a01b03831661239b5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610944565b6001600160a01b0382166123fd5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610944565b612408838383613103565b6001600160a01b038316600090815260336020526040902054818110156124805760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610944565b6001600160a01b0380851660008181526033602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906124e09086815260200190565b60405180910390a3612331565b610ecb8133612d04565b6125018282611765565b610e93576000828152609d602090815260408083206001600160a01b03851684529091529020805460ff191660011790556125393390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b609e5460ff1615610edf5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610944565b806000036125e4576040516302075cc160e41b815260040160405180910390fd5b60006126126125f2846113b6565b6001600160a01b038516600090815260696020526040902054849061327f565b6001600160a01b03841660009081526069602052604081208054929350839290919061263f908490613ecf565b9250508190555080606a60008282546126589190613ecf565b90915550610d3f905083836132cc565b6126728282611765565b15610e93576000828152609d602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6001600160a01b038116600090815260a06020526040902054600003610ecb5760405163a0adfe6b60e01b81526001600160a01b0382166004820152602401610944565b61271b6113d1565b81111561273b576040516311d681c960e21b815260040160405180910390fd5b806066546127499190613e6d565b6066556040518181527f7545428d48c07276e600a1b3c9689be2420624a568454764744bed2ed4785b5e906020016113ab565b61278461340c565b609e805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b0382166000908152606960205260409020546127f2908290613e6d565b6001600160a01b038316600090815260696020526040902055606a54612819908290613e6d565b606a555050565b6000610cf13361294f565b60008183106122b65781610cd3565b8015806128b45750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa15801561288e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128b29190613f39565b155b61291f5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610944565b6040516001600160a01b038316602482015260448101829052610d3f90849063095ea7b360e01b906064016121f4565b600061295a826126cf565b5090565b612966613898565b6000612971836113b6565b9050600061297d610cda565b9050806000036129a05760405163ee7b33a760e01b815260040160405180910390fd5b6001600160a01b038416600090815260a36020908152604091829020825180840184528154815260019091015481830152825160a08101909352848352919081016129ea60355490565b8152602081019390935260a25460408401526060909201529392505050565b6000808460000151841115612a31576040516302075cc160e41b815260040160405180910390fd5b6001600160a01b038616600090815260a1602052604081205490819003612a585750612c44565b6000612a788760400151838960200151612a729190613e80565b90613455565b9050612ac48760800151602001518860000151612a959190613e6d565b612a9f888461282b565b6001600160a01b038b1660009081526020899052604090205460608b01518690612c4d565b925082600003612ad5575050612c44565b6000612aea8489602001518a60400151612cbe565b9050612af6818461282b565b9050838860800151602001818151612b0e9190613e6d565b9052506001600160a01b03891660009081526020879052604081208054869290612b39908490613e6d565b90915550506040516370a0823160e01b81523060048201526000906001600160a01b038b16906370a0823190602401602060405180830381865afa158015612b85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ba99190613f39565b905083612bb68383613e80565b612bc09190613e97565b95508489600001818151612bd49190613ecf565b905250602089018051869190612beb908390613ecf565b905250604089018051839190612c02908390613ecf565b905250606089018051839190612c19908390613ecf565b905250612c268285613ecf565b6001600160a01b038b16600090815260a16020526040902055505050505b94509492505050565b600080612c6885612c6285612a72888c613e80565b90612d9a565b9050612c74868261282b565b91508115612cb457612c868785613e80565b836001612c938589613e6d565b612c9d9190613ecf565b612ca79190613e80565b10612cb457612cb4613eb9565b5095945050505050565b600082841115612ce1576040516302075cc160e41b815260040160405180910390fd5b8315610cd35782612cf28584613e80565b612cfc9190613e97565b949350505050565b612d0e8282611765565b610e9357612d1b8161348c565b612d2683602061349e565b604051602001612d37929190613ff3565b60408051601f198184030181529082905262461bcd60e51b82526109449160040161392f565b612d6561257d565b609e805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586127b13390565b6000818311612daa576000610cd3565b50900390565b600080821215612dd9576000829003808411612dcd576000612dd1565b8084035b915050610851565b81836000190311612dec57600019612df0565b8183015b9050610851565b600082600003612e1a57604051632ec86ff560e21b815260040160405180910390fd5b612e2d83612e2760355490565b8461363a565b6001600160a01b03851660009081526069602052604081205491925090612e55908590613e6d565b90506001600160801b03811115612e7f57604051637756904960e01b815260040160405180910390fd5b6001600160a01b0385166000908152606960205260408120829055606a8054869290612eac908490613e6d565b90915550506065543390612ecb906001600160a01b0316823088613680565b600083612ed7886113b6565b612ee19190613e6d565b90506001600160801b03811115612f0b57604051637756904960e01b815260040160405180910390fd5b612f1587856136b8565b866001600160a01b0316826001600160a01b03167fdcde3dce73cebc28787eaab2e2b0474ab6f06f519882e7ee490a3f57e46abed38887604051612f63929190918252602082015260400190565b60405180910390a35050509392505050565b6000612f88826301ffc9a760e01b612fa8565b80156108515750612fa1826001600160e01b0319612fa8565b1592915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d9150600051905082801561301a575060208210155b80156130265750600081115b979650505050505050565b6000613086826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166137859092919063ffffffff16565b805190915015610d3f57808060200190518101906130a49190614068565b610d3f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610944565b6001600160a01b0383161561311d5761311b83610b6e565b505b600061312860355490565b905060006001600160a01b038516156131c857613144856113b6565b6001600160a01b038616600090815260676020526040902054613168908590613e80565b6131729190613e97565b6001600160a01b038616600090815260676020526040902054909150613199908290613ecf565b6001600160a01b0386166000908152606760205260409020556068546131c0908290613ecf565b606855613204565b81156131ec5781836066546131dd9190613e80565b6131e79190613e97565b6131f0565b6066545b9050806066546132009190613e6d565b6066555b6001600160a01b03841615613266576001600160a01b038416600090815260676020526040902054613237908290613e6d565b6001600160a01b03851660009081526067602052604090205560685461325e908290613e6d565b606855613278565b806066546132749190613ecf565b6066555b5050505050565b6000838311156132a2576040516302075cc160e41b815260040160405180910390fd5b83156132c257836132b38484613e80565b6132bd9190613e97565b612cfc565b6000949350505050565b6001600160a01b03821661332c5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610944565b61333882600083613103565b6001600160a01b038216600090815260336020526040902054818110156133ac5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610944565b6001600160a01b03831660008181526033602090815260408083208686039055603580548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b609e5460ff16610edf5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610944565b600082156134835781613469600185613ecf565b6134739190613e97565b61347e906001613e6d565b610cd3565b50600092915050565b60606108516001600160a01b03831660145b606060006134ad836002613e80565b6134b8906002613e6d565b67ffffffffffffffff8111156134d0576134d0613cbf565b6040519080825280601f01601f1916602001820160405280156134fa576020820181803683370190505b509050600360fc1b8160008151811061351557613515613cd5565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061354457613544613cd5565b60200101906001600160f81b031916908160001a9053506000613568846002613e80565b613573906001613e6d565b90505b60018111156135eb576f181899199a1a9b1b9c1cb0b131b232b360811b85600f16601081106135a7576135a7613cd5565b1a60f81b8282815181106135bd576135bd613cd5565b60200101906001600160f81b031916908160001a90535060049490941c936135e481614085565b9050613576565b508315610cd35760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610944565b60008161364681613e54565b925061365690506004600a614180565b6136609084613e6d565b92506000831161367257613672613eb9565b612cfc82612a728587613e80565b6040516001600160a01b03808516602483015283166044820152606481018290526123319085906323b872dd60e01b906084016121f4565b6001600160a01b03821661370e5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610944565b61371a60008383613103565b806035600082825461372c9190613e6d565b90915550506001600160a01b0382166000818152603360209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6060612cfc848460008585600080866001600160a01b031685876040516137ac919061418c565b60006040518083038185875af1925050503d80600081146137e9576040519150601f19603f3d011682016040523d82523d6000602084013e6137ee565b606091505b50915091506130268783838760608315613869578251600003613862576001600160a01b0385163b6138625760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610944565b5081612cfc565b612cfc838381511561387e5781518083602001fd5b8060405162461bcd60e51b8152600401610944919061392f565b6040518060a00160405280600081526020016000815260200160008152602001600081526020016138dc604051806040016040528060008152602001600081525090565b905290565b6000602082840312156138f357600080fd5b81356001600160e01b031981168114610cd357600080fd5b60005b8381101561392657818101518382015260200161390e565b50506000910152565b602081526000825180602084015261394e81604085016020870161390b565b601f01601f19169190910160400192915050565b6001600160a01b0381168114610ecb57600080fd5b6000806040838503121561398a57600080fd5b823561399581613962565b946020939093013593505050565b60008083601f8401126139b557600080fd5b50813567ffffffffffffffff8111156139cd57600080fd5b6020830191508360208260051b850101111561165357600080fd5b60008060008060008060008060c0898b031215613a0457600080fd5b8835613a0f81613962565b97506020890135613a1f81613962565b96506040890135613a2f81613962565b955060608901359450608089013567ffffffffffffffff80821115613a5357600080fd5b613a5f8c838d016139a3565b909650945060a08b0135915080821115613a7857600080fd5b50613a858b828c016139a3565b999c989b5096995094979396929594505050565b6020808252825182820181905260009190848201906040850190845b81811015613ada5783516001600160a01b031683529284019291840191600101613ab5565b50909695505050505050565b600060208284031215613af857600080fd5b8135610cd381613962565b600080600060608486031215613b1857600080fd5b8335613b2381613962565b92506020840135613b3381613962565b929592945050506040919091013590565b600060208284031215613b5657600080fd5b5035919050565b60008060408385031215613b7057600080fd5b823591506020830135613b8281613962565b809150509250929050565b60008060008060408587031215613ba357600080fd5b843567ffffffffffffffff80821115613bbb57600080fd5b613bc7888389016139a3565b90965094506020870135915080821115613be057600080fd5b50613bed878288016139a3565b95989497509550505050565b60008060408385031215613c0c57600080fd5b50508035926020909101359150565b60008060408385031215613c2e57600080fd5b8235613c3981613962565b91506020830135613b8281613962565b8015158114610ecb57600080fd5b60008060408385031215613c6a57600080fd5b8235613c7581613962565b91506020830135613b8281613c49565b600181811c90821680613c9957607f821691505b602082108103613cb957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b60008235607e19833603018112613d0157600080fd5b9190910192915050565b80356001600160801b0381168114610c2357600080fd5b838152600060018060a01b038085511660208401528060208601511660408401528060408601511660608401528060608601511660808401528060808601511660a08401525060e060c0830152823560e08301526020830135601e19843603018112613d8d57600080fd5b830160208101903567ffffffffffffffff811115613daa57600080fd5b8060051b803603831315613dbd57600080fd5b608061010086015261016085018290526101806001600160fb1b03831115613de457600080fd5b818482880137613df660408801613d0b565b6001600160801b03166101208701526060969096013561014086015290930190930195945050505050565b600060208284031215613e3357600080fd5b8151610cd381613962565b634e487b7160e01b600052601160045260246000fd5b600060018201613e6657613e66613e3e565b5060010190565b8082018082111561085157610851613e3e565b808202811582820484141761085157610851613e3e565b600082613eb457634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052600160045260246000fd5b8181038181111561085157610851613e3e565b6000606082018583526020606081850152818651808452608086019150828801935060005b81811015613f2357845183529383019391830191600101613f07565b5050809350505050826040830152949350505050565b600060208284031215613f4b57600080fd5b5051919050565b60008060408385031215613f6557600080fd5b505080516020909101519092909150565b600080600060608486031215613f8b57600080fd5b8351925060208401519150604084015190509250925092565b8181036000831280158383131683831282161715613fc457613fc4613e3e565b5092915050565b8082018281126000831280158216821582161715613feb57613feb613e3e565b505092915050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161402b81601785016020880161390b565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161405c81602884016020880161390b565b01602801949350505050565b60006020828403121561407a57600080fd5b8151610cd381613c49565b60008161409457614094613e3e565b506000190190565b600181815b808511156140d75781600019048211156140bd576140bd613e3e565b808516156140ca57918102915b93841c93908002906140a1565b509250929050565b6000826140ee57506001610851565b816140fb57506000610851565b8160018114614111576002811461411b57614137565b6001915050610851565b60ff84111561412c5761412c613e3e565b50506001821b610851565b5060208310610133831016604e8410600b841016171561415a575081810a610851565b614164838361409c565b806000190482111561417857614178613e3e565b029392505050565b6000610cd383836140df565b60008251613d0181846020870161390b56fed8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63a2646970667358221220a613be7eb3818c497a87a1e39695ec13e9c4d67b68af7d2762b30ac4a1e798d164736f6c63430008110033496e697469616c697a61626c653a20636f6e7472616374206973206e6f7420697f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024980000000000000000000000004bde5ef48fb211e914de3cb45506d1e533f49a910000000000000000000000006a313a0e1130810f4488c175d78472e165e0004e000000000000000000000000d14d2f62949e83708af8633ed555752923c9b9fe0000000000000000000000004720cda43b2bfb177d42a99538d01362543f0a670000000000000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106103425760003560e01c806366261532116101b857806392727cdd11610104578063b8cc1f36116100a2578063d547741f1161007c578063d547741f14610759578063d77eb4c71461076c578063dd62ed3e1461077f578063efa892c31461079257600080fd5b8063b8cc1f361461071d578063cb02e53614610730578063d2da40401461074357600080fd5b8063a457c2d7116100de578063a457c2d7146106d1578063a9059cbb146106e4578063b2016bd4146106f7578063b518d9a41461070a57600080fd5b806392727cdd146106ae57806395d89b41146106c1578063a217fddf146106c957600080fd5b80637e90618e116101715780639003adfe1161014b5780639003adfe1461066d5780639026dee814610675578063909370831461068857806391d148541461069b57600080fd5b80637e90618e1461063f57806383edf317146106525780638456cb591461066557600080fd5b806366261532146105ac5780636a12209c146105d557806370a08231146105e857806372441d54146105fb57806375172a8b1461062457806379df81e41461062c57600080fd5b80633237c1581161029257806349bcbcc0116102305780635bd9e2991161020a5780635bd9e2991461053c5780635c975abb1461057b5780635cd9ef81146105865780635d5d46131461059957600080fd5b806349bcbcc01461050757806353e8c8501461052a57806354c97ff71461053357600080fd5b8063390ca1271161026c578063390ca127146104ad57806339509351146104d95780633f036cb0146104ec5780633f4ba83a146104ff57600080fd5b80633237c1581461046a57806336568abe146104925780633706c4da146104a557600080fd5b806316dbd776116102ff57806323b872dd116102d957806323b872dd14610410578063248a9ca3146104235780632f2ff15d14610446578063313ce5671461045b57600080fd5b806316dbd776146103ed57806318160ddd146104005780631ba2f5311461040857600080fd5b806301ffc9a71461034757806306fdde031461036f57806307bd026514610384578063095ea7b3146103a75780630dab3ae8146103ba578063164e68de146103da575b600080fd5b61035a6103553660046138e1565b6107a5565b60405190151581526020015b60405180910390f35b610377610857565b604051610366919061392f565b61039960008051602061419f83398151915281565b604051908152602001610366565b61035a6103b5366004613977565b6108e9565b6103cd6103c83660046139e8565b610901565b6040516103669190613a99565b6103996103e8366004613ae6565b610b6e565b6103996103fb366004613ae6565b610c28565b603554610399565b610399610cda565b61035a61041e366004613b03565b610cf6565b610399610431366004613b44565b6000908152609d602052604090206001015490565b610459610454366004613b5d565b610d1a565b005b60405160128152602001610366565b61047d610478366004613b44565b610d44565b60408051928352602083019190915201610366565b6104596104a0366004613b5d565b610e19565b606a54610399565b61035a6104bb366004613ae6565b6001600160a01b0316600090815260a5602052604090205460ff1690565b61035a6104e7366004613977565b610e97565b6104596104fa366004613b44565b610eb9565b610459610ece565b61050f610ee1565b60408051938452602084019290925290820152606001610366565b61039960a25481565b610399609f5481565b6105637f0000000000000000000000004bde5ef48fb211e914de3cb45506d1e533f49a9181565b6040516001600160a01b039091168152602001610366565b609e5460ff1661035a565b61047d610594366004613b44565b611222565b6103996105a7366004613b44565b611365565b6103996105ba366004613ae6565b6001600160a01b0316600090815260a0602052604090205490565b6104596105e3366004613b44565b611371565b6103996105f6366004613ae6565b6113b6565b610399610609366004613ae6565b6001600160a01b031660009081526069602052604090205490565b6103996113d1565b61047d61063a366004613977565b611471565b61047d61064d366004613977565b611582565b610459610660366004613ae6565b61165a565b610459611672565b610399611683565b610459610683366004613ae6565b611695565b61047d610696366004613ae6565b6116a0565b61035a6106a9366004613b5d565b611765565b6104596106bc366004613977565b611790565b61037761192d565b610399600081565b61035a6106df366004613977565b61193c565b61035a6106f2366004613977565b6119b7565b606554610563906001600160a01b031681565b610399610718366004613977565b6119c5565b61050f61072b366004613ae6565b6119e1565b61039961073e366004613b8d565b611b94565b609e5461010090046001600160a01b0316610563565b610459610767366004613b5d565b611d73565b61045961077a366004613bf9565b611d98565b61039961078d366004613c1b565b611f31565b6104596107a0366004613c57565b611f5c565b60006001600160e01b03198216636831974d60e11b14806107d657506001600160e01b031982166306e253b560e11b145b806107f157506001600160e01b03198216635ee02cbf60e01b145b8061080c57506001600160e01b0319821663034b690160e61b145b8061082757506001600160e01b03198216635c660f9b60e11b145b8061084257506001600160e01b03198216630126f2f360e61b145b80610851575061085182612053565b92915050565b60606036805461086690613c85565b80601f016020809104026020016040519081016040528092919081815260200182805461089290613c85565b80156108df5780601f106108b4576101008083540402835291602001916108df565b820191906000526020600020905b8154815290600101906020018083116108c257829003601f168201915b5050505050905090565b6000336108f7818585612088565b5060019392505050565b6001600160a01b038816600090815260a5602052604090205460609060ff1661094d57604051631fbef81160e21b81526001600160a01b038a1660048201526024015b60405180910390fd5b83821461096d57604051630a14dfb760e21b815260040160405180910390fd5b8167ffffffffffffffff81111561098657610986613cbf565b6040519080825280602002602001820160405280156109af578160200160208202803683370190505b506040805160a0810182526001600160a01b037f0000000000000000000000004bde5ef48fb211e914de3cb45506d1e533f49a91811682526065548116602083015230928201929092528a82166060820152908916608082015290915060005b83811015610b605760008b6001600160a01b031663aecc550a8a85898987818110610a3c57610a3c613cd5565b9050602002810190610a4e9190613ceb565b6040518463ffffffff1660e01b8152600401610a6c93929190613d22565b6020604051808303816000875af1158015610a8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aaf9190613e21565b90506000610acd6001600160a01b0383166319a298e760e01b6121ac565b905080610af85760405163531f290560e11b81526001600160a01b038e166004820152602401610944565b81858481518110610b0b57610b0b613cd5565b60200260200101906001600160a01b031690816001600160a01b031681525050610b4d828a8a86818110610b4157610b41613cd5565b90506020020135611790565b505080610b5990613e54565b9050610a0f565b505098975050505050505050565b6000610b7982610c28565b90508015610c23576001600160a01b03821660009081526067602052604081208054839290610ba9908490613e6d565b9091555050606854610bbc908290613e6d565b606855606554610bd6906001600160a01b031683836121c8565b816001600160a01b03167fc0819c13be868895eb93e40eaceb96de976442fa1d404e5c55f14bb65a8c489a82604051610c1191815260200190565b60405180910390a2610c23828261222b565b919050565b600080610c3460355490565b610c3d846113b6565b606654610c4a9190613e80565b610c549190613e97565b6001600160a01b038416600090815260676020526040902054909150610c7b826001613e6d565b1015610c8957610c89613eb9565b6001600160a01b038316600090815260676020526040902054610cad9082906122a7565b6001600160a01b038416600090815260676020526040902054909150610cd39082613ecf565b9392505050565b600060a254610ce76113d1565b610cf19190613e6d565b905090565b600033610d048582856122bd565b610d0f858585612337565b506001949350505050565b6000828152609d6020526040902060010154610d35816124ed565b610d3f83836124f7565b505050565b600080610d4f61257d565b33610d5a8185611582565b90935091506000829003610d6e5750915091565b6001600160a01b038116600090815260a3602052604081208054849290610d96908490613e6d565b90915550610da6905081836125c3565b606554610dbd906001600160a01b031682856121c8565b60408051600081526020810191829052906001600160a01b038316907f96bd1544577eb6c104cdc0a1e4eda89c64f8875c006dfda5baaef1aa5628b4b990610e0a90879085908890613ee2565b60405180910390a25050915091565b6001600160a01b0381163314610e895760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610944565b610e938282612668565b5050565b6000336108f7818585610eaa8383611f31565b610eb49190613e6d565b612088565b610ec2336126cf565b610ecb81612713565b50565b610ed733611695565b610edf61277c565b565b600080600080610eff609e546001600160a01b036101009091041690565b90506001600160a01b038116610f285760405163297d81a560e01b815260040160405180910390fd5b336001600160a01b03821614610f5357604051632c3b4def60e21b8152336004820152602401610944565b6000610f6f6001600160a01b038316635ee02cbf60e01b6121ac565b905080610f9a576040516320d6c2ad60e01b81526001600160a01b0383166004820152602401610944565b6000826001600160a01b0316633706c4da6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610fdc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110009190613f39565b90506000836001600160a01b03166375172a8b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611042573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110669190613f39565b90506000846001600160a01b0316631ba2f5316040518163ffffffff1660e01b81526004016020604051808303816000875af11580156110aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ce9190613f39565b9050816000036110ea5750600097889750879650945050505050565b6001600160a01b0385166000818152606960205260409020549061111590636831974d60e11b6121ac565b61112157611121613eb9565b604051635cd9ef8160e01b81526004810184905286906001600160a01b03821690635cd9ef819060240160408051808303816000875af1158015611169573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118d9190613f52565b909a509750816111b2886001600160a01b031660009081526069602052604090205490565b6111bc9190613ecf565b8a146111ca576111ca613eb9565b6111d485846122a7565b9450826111e1868c613e80565b6111eb9190613e97565b9850898910156111fd576111fd613eb9565b60006112098b8b613ecf565b905061121588826127ce565b5050505050505050909192565b60008061122d61257d565b6000611237612820565b90506000611244826116a0565b509050611251818661282b565b9350831561135e576001600160a01b038216600090815260a1602052604081208054869290611281908490613e6d565b925050819055508360a2600082825461129a9190613e6d565b90915550506065546112b6906001600160a01b0316838661283a565b604051635d5d461360e01b8152600481018590526001600160a01b03831690635d5d4613906024016020604051808303816000875af11580156112fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113219190613f39565b9250816001600160a01b03167fb741f30322e51134d94cb3c8e4d323dfbcfd60a7a86243f62faa4ae60528f8b085604051610e0a91815260200190565b5050915091565b600061085133836119c5565b61137a33611695565b609f8190556040518181527fcbfebec0d4837dbe12cf8045696140fec0f1ae16160c3474010c7ac91f4b74a2906020015b60405180910390a150565b6001600160a01b031660009081526033602052604090205490565b6065546040516370a0823160e01b815230600482015260009182916001600160a01b03909116906370a0823190602401602060405180830381865afa15801561141e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114429190613f39565b9050600061144e611683565b90508082101561146057611460613eb9565b61146a8183613ecf565b9250505090565b60008061147c61257d565b60006114878561294f565b33600081815260a4602052604081209293509091906114a58361295e565b90506114b384828985612a09565b9096509450851561157757600085116114ce576114ce613eb9565b60808101516001600160a01b03808516600090815260a36020908152604090912083518155920151600190920191909155606082015160a25561151490851684886121c8565b60408051878152602081018790526bffffffffffffffffffffffff1960608b901b16916001600160a01b038616917fe39d5363f820fc9aad3f881a88f5aa05338eaa1cfe575250c49fc7ff5bf5eaa3910160405180910390a361157783866125c3565b505050509250929050565b600080600061158f6113d1565b9050600061159b610cda565b9050806000036115be5760405163ee7b33a760e01b815260040160405180910390fd5b6001600160a01b038616600090815260a360209081526040808320815180830190925280548083526001909101549282019290925291906115fe896113b6565b6116089190613e6d565b905061161b818884600001518787612c4d565b94508460000361162e5750505050611653565b6116418561163b60355490565b85612cbe565b95508386111561157757611577613eb9565b9250929050565b610ecb60008051602061419f83398151915282612d04565b61167b33611695565b610edf612d5d565b6000606854606654610cf19190613ecf565b610ecb600082612d04565b60008060006116ae606a5490565b609f546001600160a01b038616600090815260a060205260409020549192506116d69161282b565b91506116e2818361282b565b6001600160a01b038516600090815260a1602090815260409182902082518084019093528054808452600190910154918301919091529194508493509061172a908490612d9a565b815190935061173a908590612d9a565b935061175c6117476113d1565b6020830151611757908790612db0565b61282b565b93505050915091565b6000918252609d602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6117993361165a565b80156117a7576117a761257d565b6001600160a01b038216600090815260a060205260409020548114610e935760006117e26001600160a01b0384166306e253b560e11b6121ac565b90508061180d576040516332be158160e01b81526001600160a01b0384166004820152602401610944565b60006118296001600160a01b03851663034b690160e61b6121ac565b90508080156118aa5750306001600160a01b0316846001600160a01b031663d2da40406040518163ffffffff1660e01b8152600401602060405180830381865afa15801561187b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189f9190613e21565b6001600160a01b0316145b6118d2576040516332be158160e01b81526001600160a01b0385166004820152602401610944565b6001600160a01b038416600081815260a0602052604090819020859055517f087334644551f4ef9c19d46c1dbbb3593f9f48d51f0fea493a43e312a65242489061191f9086815260200190565b60405180910390a250505050565b60606037805461086690613c85565b6000338161194a8286611f31565b9050838110156119aa5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610944565b610d0f8286868403612088565b6000336108f7818585612337565b60006119cf61257d565b610cd383836119dc610cda565b612df7565b600080806119ee33611695565b611a086001600160a01b038516636831974d60e11b6121ac565b611a305760405163793463e360e01b81526001600160a01b0385166004820152602401610944565b611a4a6001600160a01b038516630126f2f360e61b6121ac565b611a725760405163284e951160e21b81526001600160a01b0385166004820152602401610944565b6000611a7d606a5490565b9050611a9760008051602061419f83398151915233610d1a565b611aa18582611790565b611ab960008051602061419f83398151915233611d73565b609f54611ac582611371565b6000869050806001600160a01b03166349bcbcc06040518163ffffffff1660e01b81526004016060604051808303816000875af1158015611b0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b2e9190613f76565b91975095509350611b3e82611371565b60408051878152602081018790529081018590526001600160a01b038816907f2b909767077de53708f0c9bf65c9ea6cfe4ffaf377981f178880e5eb307d81299060600160405180910390a25050509193909250565b6000611b9e61257d565b838214611bbe5760405163ca3487f760e01b815260040160405180910390fd5b33600081815260a46020526040812090611bd78361295e565b905060005b87811015611d28576000611c158a8a84818110611bfb57611bfb613cd5565b9050602002016020810190611c109190613ae6565b61294f565b9050600080611c3e83868c8c88818110611c3157611c31613cd5565b9050602002013589612a09565b9092509050611c4d8189613e6d565b97508115611d065760008111611c6557611c65613eb9565b611c796001600160a01b03841688846121c8565b8b8b85818110611c8b57611c8b613cd5565b9050602002016020810190611ca09190613ae6565b60601b6bffffffffffffffffffffffff191660001c876001600160a01b03167fe39d5363f820fc9aad3f881a88f5aa05338eaa1cfe575250c49fc7ff5bf5eaa38484604051611cf9929190918252602082015260400190565b60405180910390a3611d14565b8015611d1457611d14613eb9565b50505080611d2190613e54565b9050611bdc565b5060808101516001600160a01b038416600090815260a36020908152604090912082518155910151600190910155606081015160a255611d6883856125c3565b505050949350505050565b6000828152609d6020526040902060010154611d8e816124ed565b610d3f8383612668565b6000611da2612820565b6040516370a0823160e01b815230600482015290915060009083906001600160a01b038416906370a0823190602401602060405180830381865afa158015611dee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e129190613f39565b611e1c9190613e6d565b6001600160a01b038316600090815260a1602052604081208054929350919083611e47576000611e5c565b83611e528388613e80565b611e5c9190613e97565b90506001600160ff1b03871115611e8657604051637756904960e01b815260040160405180910390fd5b6001600160ff1b03811115611e9d57611e9d613eb9565b611ea78183613ecf565b8355611eb38188613fa4565b836001016000828254611ec69190613fcb565b925050819055508060a26000828254611edf9190613ecf565b909155505060408051888152602081018390526001600160a01b038716917fdabd725b6d0865b98c42345bb716aada43ac75fcb5b70d2d189bf7afad456d2e910160405180910390a250505050505050565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b611f6533611695565b8015611f7357611f7361257d565b6000611f8f6001600160a01b0384166357662a8560e11b6121ac565b905080611fba5760405163531f290560e11b81526001600160a01b0384166004820152602401610944565b6001600160a01b038316600090815260a5602052604090205460ff16151582151514610d3f576001600160a01b038316600081815260a56020908152604091829020805460ff191686151590811790915591519182527f51228fedbb1530958ad763d83204397c34a21dc73a3525e68bdce060da256360910160405180910390a2505050565b6001600160a01b03163b151590565b3390565b60006001600160e01b03198216637965db0b60e01b148061085157506301ffc9a760e01b6001600160e01b0319831614610851565b6001600160a01b0383166120ea5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610944565b6001600160a01b03821661214b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610944565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006121b783612f75565b8015610cd35750610cd38383612fa8565b6040516001600160a01b038316602482015260448101829052610d3f90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613031565b609e546001600160a01b036101009091048116908316819003610d3f576040516303f036cb60e41b8152600481018390526001600160a01b03821690633f036cb090602401600060405180830381600087803b15801561228a57600080fd5b505af115801561229e573d6000803e3d6000fd5b50505050505050565b60008183116122b65781610cd3565b5090919050565b60006122c98484611f31565b9050600019811461233157818110156123245760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610944565b6123318484848403612088565b50505050565b6001600160a01b03831661239b5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610944565b6001600160a01b0382166123fd5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610944565b612408838383613103565b6001600160a01b038316600090815260336020526040902054818110156124805760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610944565b6001600160a01b0380851660008181526033602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906124e09086815260200190565b60405180910390a3612331565b610ecb8133612d04565b6125018282611765565b610e93576000828152609d602090815260408083206001600160a01b03851684529091529020805460ff191660011790556125393390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b609e5460ff1615610edf5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610944565b806000036125e4576040516302075cc160e41b815260040160405180910390fd5b60006126126125f2846113b6565b6001600160a01b038516600090815260696020526040902054849061327f565b6001600160a01b03841660009081526069602052604081208054929350839290919061263f908490613ecf565b9250508190555080606a60008282546126589190613ecf565b90915550610d3f905083836132cc565b6126728282611765565b15610e93576000828152609d602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6001600160a01b038116600090815260a06020526040902054600003610ecb5760405163a0adfe6b60e01b81526001600160a01b0382166004820152602401610944565b61271b6113d1565b81111561273b576040516311d681c960e21b815260040160405180910390fd5b806066546127499190613e6d565b6066556040518181527f7545428d48c07276e600a1b3c9689be2420624a568454764744bed2ed4785b5e906020016113ab565b61278461340c565b609e805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b0382166000908152606960205260409020546127f2908290613e6d565b6001600160a01b038316600090815260696020526040902055606a54612819908290613e6d565b606a555050565b6000610cf13361294f565b60008183106122b65781610cd3565b8015806128b45750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa15801561288e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128b29190613f39565b155b61291f5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610944565b6040516001600160a01b038316602482015260448101829052610d3f90849063095ea7b360e01b906064016121f4565b600061295a826126cf565b5090565b612966613898565b6000612971836113b6565b9050600061297d610cda565b9050806000036129a05760405163ee7b33a760e01b815260040160405180910390fd5b6001600160a01b038416600090815260a36020908152604091829020825180840184528154815260019091015481830152825160a08101909352848352919081016129ea60355490565b8152602081019390935260a25460408401526060909201529392505050565b6000808460000151841115612a31576040516302075cc160e41b815260040160405180910390fd5b6001600160a01b038616600090815260a1602052604081205490819003612a585750612c44565b6000612a788760400151838960200151612a729190613e80565b90613455565b9050612ac48760800151602001518860000151612a959190613e6d565b612a9f888461282b565b6001600160a01b038b1660009081526020899052604090205460608b01518690612c4d565b925082600003612ad5575050612c44565b6000612aea8489602001518a60400151612cbe565b9050612af6818461282b565b9050838860800151602001818151612b0e9190613e6d565b9052506001600160a01b03891660009081526020879052604081208054869290612b39908490613e6d565b90915550506040516370a0823160e01b81523060048201526000906001600160a01b038b16906370a0823190602401602060405180830381865afa158015612b85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ba99190613f39565b905083612bb68383613e80565b612bc09190613e97565b95508489600001818151612bd49190613ecf565b905250602089018051869190612beb908390613ecf565b905250604089018051839190612c02908390613ecf565b905250606089018051839190612c19908390613ecf565b905250612c268285613ecf565b6001600160a01b038b16600090815260a16020526040902055505050505b94509492505050565b600080612c6885612c6285612a72888c613e80565b90612d9a565b9050612c74868261282b565b91508115612cb457612c868785613e80565b836001612c938589613e6d565b612c9d9190613ecf565b612ca79190613e80565b10612cb457612cb4613eb9565b5095945050505050565b600082841115612ce1576040516302075cc160e41b815260040160405180910390fd5b8315610cd35782612cf28584613e80565b612cfc9190613e97565b949350505050565b612d0e8282611765565b610e9357612d1b8161348c565b612d2683602061349e565b604051602001612d37929190613ff3565b60408051601f198184030181529082905262461bcd60e51b82526109449160040161392f565b612d6561257d565b609e805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586127b13390565b6000818311612daa576000610cd3565b50900390565b600080821215612dd9576000829003808411612dcd576000612dd1565b8084035b915050610851565b81836000190311612dec57600019612df0565b8183015b9050610851565b600082600003612e1a57604051632ec86ff560e21b815260040160405180910390fd5b612e2d83612e2760355490565b8461363a565b6001600160a01b03851660009081526069602052604081205491925090612e55908590613e6d565b90506001600160801b03811115612e7f57604051637756904960e01b815260040160405180910390fd5b6001600160a01b0385166000908152606960205260408120829055606a8054869290612eac908490613e6d565b90915550506065543390612ecb906001600160a01b0316823088613680565b600083612ed7886113b6565b612ee19190613e6d565b90506001600160801b03811115612f0b57604051637756904960e01b815260040160405180910390fd5b612f1587856136b8565b866001600160a01b0316826001600160a01b03167fdcde3dce73cebc28787eaab2e2b0474ab6f06f519882e7ee490a3f57e46abed38887604051612f63929190918252602082015260400190565b60405180910390a35050509392505050565b6000612f88826301ffc9a760e01b612fa8565b80156108515750612fa1826001600160e01b0319612fa8565b1592915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d9150600051905082801561301a575060208210155b80156130265750600081115b979650505050505050565b6000613086826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166137859092919063ffffffff16565b805190915015610d3f57808060200190518101906130a49190614068565b610d3f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610944565b6001600160a01b0383161561311d5761311b83610b6e565b505b600061312860355490565b905060006001600160a01b038516156131c857613144856113b6565b6001600160a01b038616600090815260676020526040902054613168908590613e80565b6131729190613e97565b6001600160a01b038616600090815260676020526040902054909150613199908290613ecf565b6001600160a01b0386166000908152606760205260409020556068546131c0908290613ecf565b606855613204565b81156131ec5781836066546131dd9190613e80565b6131e79190613e97565b6131f0565b6066545b9050806066546132009190613e6d565b6066555b6001600160a01b03841615613266576001600160a01b038416600090815260676020526040902054613237908290613e6d565b6001600160a01b03851660009081526067602052604090205560685461325e908290613e6d565b606855613278565b806066546132749190613ecf565b6066555b5050505050565b6000838311156132a2576040516302075cc160e41b815260040160405180910390fd5b83156132c257836132b38484613e80565b6132bd9190613e97565b612cfc565b6000949350505050565b6001600160a01b03821661332c5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610944565b61333882600083613103565b6001600160a01b038216600090815260336020526040902054818110156133ac5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610944565b6001600160a01b03831660008181526033602090815260408083208686039055603580548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b609e5460ff16610edf5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610944565b600082156134835781613469600185613ecf565b6134739190613e97565b61347e906001613e6d565b610cd3565b50600092915050565b60606108516001600160a01b03831660145b606060006134ad836002613e80565b6134b8906002613e6d565b67ffffffffffffffff8111156134d0576134d0613cbf565b6040519080825280601f01601f1916602001820160405280156134fa576020820181803683370190505b509050600360fc1b8160008151811061351557613515613cd5565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061354457613544613cd5565b60200101906001600160f81b031916908160001a9053506000613568846002613e80565b613573906001613e6d565b90505b60018111156135eb576f181899199a1a9b1b9c1cb0b131b232b360811b85600f16601081106135a7576135a7613cd5565b1a60f81b8282815181106135bd576135bd613cd5565b60200101906001600160f81b031916908160001a90535060049490941c936135e481614085565b9050613576565b508315610cd35760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610944565b60008161364681613e54565b925061365690506004600a614180565b6136609084613e6d565b92506000831161367257613672613eb9565b612cfc82612a728587613e80565b6040516001600160a01b03808516602483015283166044820152606481018290526123319085906323b872dd60e01b906084016121f4565b6001600160a01b03821661370e5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610944565b61371a60008383613103565b806035600082825461372c9190613e6d565b90915550506001600160a01b0382166000818152603360209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6060612cfc848460008585600080866001600160a01b031685876040516137ac919061418c565b60006040518083038185875af1925050503d80600081146137e9576040519150601f19603f3d011682016040523d82523d6000602084013e6137ee565b606091505b50915091506130268783838760608315613869578251600003613862576001600160a01b0385163b6138625760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610944565b5081612cfc565b612cfc838381511561387e5781518083602001fd5b8060405162461bcd60e51b8152600401610944919061392f565b6040518060a00160405280600081526020016000815260200160008152602001600081526020016138dc604051806040016040528060008152602001600081525090565b905290565b6000602082840312156138f357600080fd5b81356001600160e01b031981168114610cd357600080fd5b60005b8381101561392657818101518382015260200161390e565b50506000910152565b602081526000825180602084015261394e81604085016020870161390b565b601f01601f19169190910160400192915050565b6001600160a01b0381168114610ecb57600080fd5b6000806040838503121561398a57600080fd5b823561399581613962565b946020939093013593505050565b60008083601f8401126139b557600080fd5b50813567ffffffffffffffff8111156139cd57600080fd5b6020830191508360208260051b850101111561165357600080fd5b60008060008060008060008060c0898b031215613a0457600080fd5b8835613a0f81613962565b97506020890135613a1f81613962565b96506040890135613a2f81613962565b955060608901359450608089013567ffffffffffffffff80821115613a5357600080fd5b613a5f8c838d016139a3565b909650945060a08b0135915080821115613a7857600080fd5b50613a858b828c016139a3565b999c989b5096995094979396929594505050565b6020808252825182820181905260009190848201906040850190845b81811015613ada5783516001600160a01b031683529284019291840191600101613ab5565b50909695505050505050565b600060208284031215613af857600080fd5b8135610cd381613962565b600080600060608486031215613b1857600080fd5b8335613b2381613962565b92506020840135613b3381613962565b929592945050506040919091013590565b600060208284031215613b5657600080fd5b5035919050565b60008060408385031215613b7057600080fd5b823591506020830135613b8281613962565b809150509250929050565b60008060008060408587031215613ba357600080fd5b843567ffffffffffffffff80821115613bbb57600080fd5b613bc7888389016139a3565b90965094506020870135915080821115613be057600080fd5b50613bed878288016139a3565b95989497509550505050565b60008060408385031215613c0c57600080fd5b50508035926020909101359150565b60008060408385031215613c2e57600080fd5b8235613c3981613962565b91506020830135613b8281613962565b8015158114610ecb57600080fd5b60008060408385031215613c6a57600080fd5b8235613c7581613962565b91506020830135613b8281613c49565b600181811c90821680613c9957607f821691505b602082108103613cb957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b60008235607e19833603018112613d0157600080fd5b9190910192915050565b80356001600160801b0381168114610c2357600080fd5b838152600060018060a01b038085511660208401528060208601511660408401528060408601511660608401528060608601511660808401528060808601511660a08401525060e060c0830152823560e08301526020830135601e19843603018112613d8d57600080fd5b830160208101903567ffffffffffffffff811115613daa57600080fd5b8060051b803603831315613dbd57600080fd5b608061010086015261016085018290526101806001600160fb1b03831115613de457600080fd5b818482880137613df660408801613d0b565b6001600160801b03166101208701526060969096013561014086015290930190930195945050505050565b600060208284031215613e3357600080fd5b8151610cd381613962565b634e487b7160e01b600052601160045260246000fd5b600060018201613e6657613e66613e3e565b5060010190565b8082018082111561085157610851613e3e565b808202811582820484141761085157610851613e3e565b600082613eb457634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052600160045260246000fd5b8181038181111561085157610851613e3e565b6000606082018583526020606081850152818651808452608086019150828801935060005b81811015613f2357845183529383019391830191600101613f07565b5050809350505050826040830152949350505050565b600060208284031215613f4b57600080fd5b5051919050565b60008060408385031215613f6557600080fd5b505080516020909101519092909150565b600080600060608486031215613f8b57600080fd5b8351925060208401519150604084015190509250925092565b8181036000831280158383131683831282161715613fc457613fc4613e3e565b5092915050565b8082018281126000831280158216821582161715613feb57613feb613e3e565b505092915050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161402b81601785016020880161390b565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161405c81602884016020880161390b565b01602801949350505050565b60006020828403121561407a57600080fd5b8151610cd381613c49565b60008161409457614094613e3e565b506000190190565b600181815b808511156140d75781600019048211156140bd576140bd613e3e565b808516156140ca57918102915b93841c93908002906140a1565b509250929050565b6000826140ee57506001610851565b816140fb57506000610851565b8160018114614111576002811461411b57614137565b6001915050610851565b60ff84111561412c5761412c613e3e565b50506001821b610851565b5060208310610133831016604e8410600b841016171561415a575081810a610851565b614164838361409c565b806000190482111561417857614178613e3e565b029392505050565b6000610cd383836140df565b60008251613d0181846020870161390b56fed8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63a2646970667358221220a613be7eb3818c497a87a1e39695ec13e9c4d67b68af7d2762b30ac4a1e798d164736f6c63430008110033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000004bde5ef48fb211e914de3cb45506d1e533f49a910000000000000000000000006a313a0e1130810f4488c175d78472e165e0004e000000000000000000000000d14d2f62949e83708af8633ed555752923c9b9fe0000000000000000000000004720cda43b2bfb177d42a99538d01362543f0a670000000000000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : params (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [1] : prevPool (address): 0x0000000000000000000000000000000000000000
-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 0000000000000000000000004bde5ef48fb211e914de3cb45506d1e533f49a91
Arg [1] : 0000000000000000000000006a313a0e1130810f4488c175d78472e165e0004e
Arg [2] : 000000000000000000000000d14d2f62949e83708af8633ed555752923c9b9fe
Arg [3] : 0000000000000000000000004720cda43b2bfb177d42a99538d01362543f0a67
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.