core-artifacts
Version:
Consist artifacts of the maple protocol
10 lines • 6.13 MB
JSON
{
"id": "b59f8c42631bdfa87d5a140a9a37c6ab",
"_format": "hh-sol-build-info-1",
"solcVersion": "0.6.11",
"solcLongVersion": "0.6.11+commit.5ef660b1",
"input": {
"language": "Solidity",
"sources": {
"contracts/core/pool/v1/PoolFactory.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later // hevm: flattened sources of contracts/core/pool/v1/PoolFactory.sol\npragma solidity =0.6.11 >=0.6.0 <0.8.0 >=0.6.2 <0.8.0;\n\n////// lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\n/* pragma solidity >=0.6.0 <0.8.0; */\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n\n////// contracts/core/funds-distribution-token/v1/interfaces/IBasicFDT.sol\n/* pragma solidity 0.6.11; */\n\n/* import { IERC20 } from \"../../../../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\"; */\n\n/// @title BasicFDT implements the basic level FDT functionality for accounting for revenues.\ninterface IBasicFDT is IERC20 {\n\n /**\n @dev This event emits when new funds are distributed.\n @param by The address of the sender that distributed funds.\n @param fundsDistributed The amount of funds received for distribution.\n */\n event FundsDistributed(address indexed by, uint256 fundsDistributed);\n\n /**\n @dev This event emits when distributed funds are withdrawn by a token holder.\n @param by The address of the receiver of funds.\n @param fundsWithdrawn The amount of funds that were withdrawn.\n @param totalWithdrawn The total amount of funds that were withdrawn.\n */\n event FundsWithdrawn(address indexed by, uint256 fundsWithdrawn, uint256 totalWithdrawn);\n\n /**\n @dev This event emits when the internal `pointsPerShare` is updated.\n @dev First, and only, parameter is the new value of the internal `pointsPerShare`.\n */\n event PointsPerShareUpdated(uint256);\n\n /**\n @dev This event emits when an account's `pointsCorrection` is updated.\n @dev First parameter is the address of some account.\n @dev Second parameter is the new value of the account's `pointsCorrection`.\n */\n event PointsCorrectionUpdated(address indexed, int256);\n\n /**\n @dev Returns the amount of funds that an account can withdraw.\n @param _owner The address of some FDT holder.\n @return The amount funds that `_owner` can withdraw.\n */\n function withdrawableFundsOf(address _owner) external view returns (uint256);\n\n /**\n @dev Withdraws all available funds for the calling FDT holder.\n */\n function withdrawFunds() external;\n\n /**\n @dev Returns the amount of funds that an account has withdrawn.\n @param _owner The address of a token holder.\n @return The amount of funds that `_owner` has withdrawn.\n */\n function withdrawnFundsOf(address _owner) external view returns (uint256);\n\n /**\n @dev Returns the amount of funds that an account has earned in total. \n @dev accumulativeFundsOf(_owner) = withdrawableFundsOf(_owner) + withdrawnFundsOf(_owner) \n = (pointsPerShare * balanceOf(_owner) + pointsCorrection[_owner]) / pointsMultiplier \n @param _owner The address of a token holder.\n @return The amount of funds that `_owner` has earned in total.\n */\n function accumulativeFundsOf(address _owner) external view returns (uint256);\n\n /**\n @dev Registers a payment of funds in tokens. \n @dev May be called directly after a deposit is made. \n @dev Calls _updateFundsTokenBalance(), whereby the contract computes the delta of the new and previous \n `fundsToken` balance and increments the total received funds (cumulative), by delta, by calling _distributeFunds().\n */\n function updateFundsReceived() external;\n\n}\n\n////// contracts/core/loan/v1/interfaces/ILoanFDT.sol\n/* pragma solidity 0.6.11; */\n\n/* import { IERC20 } from \"../../../../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\"; */\n\n/* import { IBasicFDT } from \"../../../funds-distribution-token/v1/interfaces/IBasicFDT.sol\"; */\n\ninterface ILoanFDT is IBasicFDT {\n\n /**\n @dev The `fundsToken` (dividends).\n */\n function fundsToken() external view returns (IERC20);\n\n /**\n @dev The amount of `fundsToken` (Liquidity Asset) currently present and accounted for in this contract.\n */\n function fundsTokenBalance() external view returns (uint256);\n\n /**\n @dev Withdraws all available funds for a token holder.\n */\n function withdrawFunds() external override;\n\n}\n\n////// contracts/core/loan/v1/interfaces/ILoan.sol\n/* pragma solidity 0.6.11; */\n\n/* import { IERC20 } from \"../../../../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\"; */\n\n/* import { ILoanFDT } from \"./ILoanFDT.sol\"; */\n\ninterface ILoan is ILoanFDT {\n\n /**\n Ready = The Loan has been initialized and is ready for funding (assuming funding period hasn't ended).\n Active = The Loan has been drawdown and the Borrower is making payments.\n Matured = The Loan is fully paid off and has \"matured\".\n Expired = The Loan did not initiate, and all funding was returned to Lenders.\n Liquidated = The Loan has been liquidated.\n */\n enum State { Ready, Active, Matured, Expired, Liquidated }\n\n /**\n @dev Emits an event indicating the Loan was funded.\n @param fundedBy The Pool that funded the Loan.\n @param amountFunded The amount the Loan was funded for.\n */\n event LoanFunded(address indexed fundedBy, uint256 amountFunded);\n\n /**\n @dev Emits an event indicating the balance for an account was updated.\n @param account The address of an account.\n @param token The token address of the asset.\n @param balance The new balance of `token` for `account`.\n */\n event BalanceUpdated(address indexed account, address indexed token, uint256 balance);\n\n /**\n @dev Emits an event indicating the some loaned amount was drawn down.\n @param drawdownAmount The amount that was drawn down.\n */\n event Drawdown(uint256 drawdownAmount);\n\n /**\n @dev Emits an event indicating the state of the Loan changed.\n @param state The state of the Loan.\n */\n event LoanStateChanged(State state);\n\n /**\n @dev Emits an event indicating the an Admin for the Loan was set.\n @param loanAdmin The address of some Loan Admin.\n @param allowed Whether `loanAdmin` is a Loan Admin for this Loan.\n */\n event LoanAdminSet(address indexed loanAdmin, bool allowed);\n\n /**\n @dev Emits an event indicating the a payment was made for the Loan.\n @param totalPaid The total amount paid.\n @param principalPaid The principal portion of the amount paid.\n @param interestPaid The interest portion of the amount paid.\n @param paymentsRemaining The amount of payment remaining.\n @param principalOwed The outstanding principal of the Loan.\n @param nextPaymentDue The timestamp of the due date of the next payment.\n @param latePayment Whether this payment was late.\n */\n event PaymentMade(\n uint256 totalPaid,\n uint256 principalPaid,\n uint256 interestPaid,\n uint256 paymentsRemaining,\n uint256 principalOwed,\n uint256 nextPaymentDue,\n bool latePayment\n );\n\n /**\n @dev Emits an event indicating the the Loan was liquidated.\n @param collateralSwapped The amount of Collateral Asset swapped.\n @param liquidityAssetReturned The amount of Liquidity Asset recovered from swap.\n @param liquidationExcess The amount of Liquidity Asset returned to borrower.\n @param defaultSuffered The remaining losses after the liquidation.\n */\n event Liquidation(\n uint256 collateralSwapped,\n uint256 liquidityAssetReturned,\n uint256 liquidationExcess,\n uint256 defaultSuffered\n );\n\n /**\n @dev The current state of this Loan, as defined in the State enum below.\n */\n function loanState() external view returns (State);\n\n /**\n @dev The asset deposited by Lenders into the FundingLocker, when funding this Loan.\n */\n function liquidityAsset() external view returns (IERC20);\n\n /**\n @dev The asset deposited by Borrower into the CollateralLocker, for collateralizing this Loan.\n */\n function collateralAsset() external view returns (IERC20);\n\n /**\n @dev The FundingLocker that holds custody of Loan funds before drawdown.\n */\n function fundingLocker() external view returns (address);\n\n /**\n @dev The FundingLockerFactory.\n */\n function flFactory() external view returns (address);\n\n /**\n @dev The CollateralLocker that holds custody of Loan collateral.\n */\n function collateralLocker() external view returns (address);\n\n /**\n @dev The CollateralLockerFactory.\n */\n function clFactory() external view returns (address);\n\n /**\n @dev The Borrower of this Loan, responsible for repayments.\n */\n function borrower() external view returns (address);\n\n /**\n @dev The RepaymentCalc for this Loan.\n */\n function repaymentCalc() external view returns (address);\n\n /**\n @dev The LateFeeCalc for this Loan.\n */\n function lateFeeCalc() external view returns (address);\n\n /**\n @dev The PremiumCalc for this Loan.\n */\n function premiumCalc() external view returns (address);\n\n /**\n @dev The LoanFactory that deployed this Loan.\n */\n function superFactory() external view returns (address);\n\n /**\n @param loanAdmin The address of some admin.\n @return Whether the `loanAdmin` has permission to do certain operations in case of disaster management.\n */\n function loanAdmins(address loanAdmin) external view returns (bool);\n\n /**\n @dev The unix timestamp due date of the next payment.\n */\n function nextPaymentDue() external view returns (uint256);\n\n /**\n @dev The APR in basis points.\n */\n function apr() external view returns (uint256);\n\n /**\n @dev The number of payments remaining on the Loan.\n */\n function paymentsRemaining() external view returns (uint256);\n\n /**\n @dev The total length of the Loan term in days.\n */\n function termDays() external view returns (uint256);\n\n /**\n @dev The time between Loan payments in seconds.\n */\n function paymentIntervalSeconds() external view returns (uint256);\n\n /**\n @dev The total requested amount for Loan.\n */\n function requestAmount() external view returns (uint256);\n\n /**\n @dev The percentage of value of the drawdown amount to post as collateral in basis points.\n */\n function collateralRatio() external view returns (uint256);\n\n /**\n @dev The timestamp of when Loan was instantiated.\n */\n function createdAt() external view returns (uint256);\n\n /**\n @dev The time for a Loan to be funded in seconds.\n */\n function fundingPeriod() external view returns (uint256);\n\n /**\n @dev The time a Borrower has, after a payment is due, to make a payment before a liquidation can occur.\n */\n function defaultGracePeriod() external view returns (uint256);\n\n /**\n @dev The amount of principal owed (initially the drawdown amount).\n */\n function principalOwed() external view returns (uint256);\n\n /**\n @dev The amount of principal that has been paid by the Borrower since the Loan instantiation.\n */\n function principalPaid() external view returns (uint256);\n\n /**\n @dev The amount of interest that has been paid by the Borrower since the Loan instantiation.\n */\n function interestPaid() external view returns (uint256);\n\n /**\n @dev The amount of fees that have been paid by the Borrower since the Loan instantiation.\n */\n function feePaid() external view returns (uint256);\n\n /**\n @dev The amount of excess that has been returned to the Lenders after the Loan drawdown.\n */\n function excessReturned() external view returns (uint256);\n\n /**\n @dev The amount of Collateral Asset that has been liquidated after default.\n */\n function amountLiquidated() external view returns (uint256);\n\n /**\n @dev The amount of Liquidity Asset that has been recovered after default.\n */\n function amountRecovered() external view returns (uint256);\n\n /**\n @dev The difference between `amountRecovered` and `principalOwed` after liquidation.\n */\n function defaultSuffered() external view returns (uint256);\n\n /**\n @dev The amount of Liquidity Asset that is to be returned to the Borrower, if `amountRecovered > principalOwed`.\n */\n function liquidationExcess() external view returns (uint256);\n\n /**\n @dev Draws down funding from FundingLocker, posts collateral, and transitions the Loan state from `Ready` to `Active`. \n @dev Only the Borrower can call this function. \n @dev It emits four `BalanceUpdated` events. \n @dev It emits a `LoanStateChanged` event. \n @dev It emits a `Drawdown` event. \n @param amt the amount of Liquidity Asset the Borrower draws down. Remainder is returned to the Loan where it can be claimed back by LoanFDT holders.\n */\n function drawdown(uint256 amt) external;\n\n /**\n @dev Makes a payment for this Loan. \n @dev Amounts are calculated for the Borrower. \n */\n function makePayment() external;\n\n /**\n @dev Makes the full payment for this Loan (a.k.a. \"calling\" the Loan). \n @dev This requires the Borrower to pay a premium fee. \n */\n function makeFullPayment() external;\n \n /**\n @dev Funds this Loan and mints LoanFDTs for `mintTo` (DebtLocker in the case of Pool funding). \n @dev Only LiquidityLocker using valid/approved Pool can call this function. \n @dev It emits a `LoanFunded` event. \n @dev It emits a `BalanceUpdated` event. \n @param mintTo The address that LoanFDTs are minted to.\n @param amt The amount to fund the Loan.\n */\n function fundLoan(address mintTo, uint256 amt) external;\n\n /**\n @dev Handles returning capital to the Loan, where it can be claimed back by LoanFDT holders, \n if the Borrower has not drawn down on the Loan past the drawdown grace period. \n @dev It emits a `LoanStateChanged` event. \n */\n function unwind() external;\n\n /**\n @dev Triggers a default if the Loan meets certain default conditions, liquidating all collateral and updating accounting. \n @dev Only the an account with sufficient LoanFDTs of this Loan can call this function. \n @dev It emits a `BalanceUpdated` event. \n @dev It emits a `Liquidation` event. \n @dev It emits a `LoanStateChanged` event. \n */\n function triggerDefault() external;\n\n /**\n @dev Triggers paused state. \n @dev Halts functionality for certain functions. Only the Borrower or a Loan Admin can call this function. \n */\n function pause() external;\n\n /**\n @dev Triggers unpaused state. \n @dev Restores functionality for certain functions. \n @dev Only the Borrower or a Loan Admin can call this function. \n */\n function unpause() external;\n\n /**\n @dev Sets a Loan Admin. \n @dev Only the Borrower can call this function. \n @dev It emits a `LoanAdminSet` event. \n @param loanAdmin The address being allowed or disallowed as a Loan Admin.\n @param allowed The atatus of a Loan Admin.\n */\n function setLoanAdmin(address loanAdmin, bool allowed) external;\n\n /**\n @dev Transfers any locked funds to the Governor. \n @dev Only the Governor can call this function. \n @param token The address of the token to be reclaimed.\n */\n function reclaimERC20(address token) external;\n\n /**\n @dev Withdraws all available funds earned through LoanFDT for a token holder. \n @dev It emits a `BalanceUpdated` event. \n */\n function withdrawFunds() external override;\n\n /**\n @dev Returns the expected amount of Liquidity Asset to be recovered from a liquidation based on current oracle prices.\n @return The minimum amount of Liquidity Asset that can be expected by swapping Collateral Asset.\n */\n function getExpectedAmountRecovered() external view returns (uint256);\n\n /**\n @dev Returns information of the next payment amount.\n @return The entitled interest of the next payment (Principal + Interest only when the next payment is last payment of the Loan).\n @return The entitled principal amount needed to be paid in the next payment.\n @return The entitled interest amount needed to be paid in the next payment.\n @return The payment due date.\n @return Whether the payment is late.\n */\n function getNextPayment() external view returns (uint256, uint256, uint256, uint256, bool);\n\n /**\n @dev Returns the information of a full payment amount.\n @return total Principal and interest owed, combined.\n @return principal Principal owed.\n @return interest Interest owed.\n */\n function getFullPayment() external view returns (uint256 total, uint256 principal, uint256 interest);\n\n /**\n @dev Calculates the collateral required to draw down amount.\n @param amt The amount of the Liquidity Asset to draw down from the FundingLocker.\n @return The amount of the Collateral Asset required to post in the CollateralLocker for a given drawdown amount.\n */\n function collateralRequiredForDrawdown(uint256 amt) external view returns (uint256);\n\n}\n\n////// contracts/core/debt-locker/v1/interfaces/IDebtLocker.sol\n/* pragma solidity 0.6.11; */\n\n/* import { IERC20 } from \"../../../../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\"; */\n\n/* import { ILoan } from \"../../../loan/v1/interfaces/ILoan.sol\"; */\n\n/// @title DebtLocker holds custody of LoanFDT tokens.\ninterface IDebtLocker {\n\n /**\n @dev The Loan contract this locker is holding tokens for.\n */\n function loan() external view returns (ILoan);\n\n /**\n @dev The Liquidity Asset this locker can claim.\n */\n function liquidityAsset() external view returns (IERC20);\n\n /**\n @dev The owner of this Locker (the Pool).\n */\n function pool() external view returns (address);\n\n /**\n @dev The Loan total principal paid at last time `claim()` was called.\n */\n function lastPrincipalPaid() external view returns (uint256);\n\n /**\n @dev The Loan total interest paid at last time `claim()` was called.\n */\n function lastInterestPaid() external view returns (uint256);\n\n /**\n @dev The Loan total fees paid at last time `claim()` was called.\n */\n function lastFeePaid() external view returns (uint256);\n\n /**\n @dev The Loan total excess returned at last time `claim()` was called.\n */\n function lastExcessReturned() external view returns (uint256);\n\n /**\n @dev The Loan total default suffered at last time `claim()` was called.\n */\n function lastDefaultSuffered() external view returns (uint256);\n\n /**\n @dev Then Liquidity Asset (a.k.a. loan asset) recovered from liquidation of Loan collateral.\n */\n function lastAmountRecovered() external view returns (uint256);\n\n /**\n @dev Claims funds distribution for Loan via LoanFDT. \n @dev Only the Pool can call this function. \n @return [0] => Total Claimed.\n [1] => Interest Claimed.\n [2] => Principal Claimed.\n [3] => Pool Delegate Fee Claimed.\n [4] => Excess Returned Claimed.\n [5] => Amount Recovered (from Liquidation).\n [6] => Default Suffered.\n */\n function claim() external returns (uint256[7] memory);\n\n /**\n @dev Liquidates a Loan that is held by this contract. \n @dev Only the Pool can call this function. \n */\n function triggerDefault() external;\n\n}\n\n////// contracts/core/subfactory/v1/interfaces/ISubFactory.sol\n/* pragma solidity 0.6.11; */\n\n/// @title SubFactory creates instances downstream of another factory.\ninterface ISubFactory {\n\n /**\n @dev The type of the factory\n */\n function factoryType() external pure returns (uint8);\n\n}\n\n////// contracts/core/debt-locker/v1/interfaces/IDebtLockerFactory.sol\n/* pragma solidity 0.6.11; */\n\n/* import { ISubFactory } from \"../../../subfactory/v1/interfaces/ISubFactory.sol\"; */\n\n/// @title DebtLockerFactory instantiates DebtLockers.\ninterface IDebtLockerFactory is ISubFactory {\n\n /**\n @dev Emits an event indicating a DebtLocker was created.\n @param owner The owner of the DebtLocker.\n @param debtLocker The address of the DebtLocker.\n @param loan The Loan tied to the DebtLocker.\n */\n event DebtLockerCreated(address indexed owner, address debtLocker, address loan);\n\n /**\n @param debtLocker The address of a DebtLocker.\n @return The address of the owner of DebtLocker at `debtLocker`.\n */\n function owner(address debtLocker) external view returns (address);\n\n /**\n @param debtLocker Some address.\n @return Whether `debtLocker` is a DebtLocker.\n */\n function isLocker(address debtLocker) external view returns (bool);\n\n /**\n @dev The type of the factory (i.e FactoryType::DEBT_LOCKER_FACTORY).\n */\n function factoryType() external override pure returns (uint8);\n\n /**\n @dev Instantiates a DebtLocker. \n @dev It emits a `DebtLockerCreated` event. \n @param loan The Loan this DebtLocker will be tied to.\n @return debtLocker The address of the instantiated DebtLocker.\n */\n function newLocker(address loan) external returns (address debtLocker);\n\n}\n\n////// contracts/libraries/math/v1/SafeMathInt.sol\n/* pragma solidity 0.6.11; */\n\nlibrary SafeMathInt {\n\n function toUint256Safe(int256 a) internal pure returns (uint256) {\n require(a >= 0, \"SMI:NEG\");\n return uint256(a);\n }\n\n}\n\n////// contracts/libraries/math/v1/SafeMathUint.sol\n/* pragma solidity 0.6.11; */\n\nlibrary SafeMathUint {\n\n function toInt256Safe(uint256 a) internal pure returns (int256 b) {\n b = int256(a);\n require(b >= 0, \"SMU:OOB\");\n }\n\n}\n\n////// lib/openzeppelin-contracts/contracts/math/SafeMath.sol\n/* pragma solidity >=0.6.0 <0.8.0; */\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMath {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return sub(a, b, \"SafeMath: subtraction overflow\");\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b <= a, errorMessage);\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return div(a, b, \"SafeMath: division by zero\");\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return mod(a, b, \"SafeMath: modulo by zero\");\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts with custom message when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b != 0, errorMessage);\n return a % b;\n }\n}\n\n////// lib/openzeppelin-contracts/contracts/math/SignedSafeMath.sol\n/* pragma solidity >=0.6.0 <0.8.0; */\n\n/**\n * @title SignedSafeMath\n * @dev Signed math operations with safety checks that revert on error.\n */\nlibrary SignedSafeMath {\n int256 constant private _INT256_MIN = -2**255;\n\n /**\n * @dev Returns the multiplication of two signed integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(int256 a, int256 b) internal pure returns (int256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n require(!(a == -1 && b == _INT256_MIN), \"SignedSafeMath: multiplication overflow\");\n\n int256 c = a * b;\n require(c / a == b, \"SignedSafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two signed integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(int256 a, int256 b) internal pure returns (int256) {\n require(b != 0, \"SignedSafeMath: division by zero\");\n require(!(b == -1 && a == _INT256_MIN), \"SignedSafeMath: division overflow\");\n\n int256 c = a / b;\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two signed integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a - b;\n require((b >= 0 && c <= a) || (b < 0 && c > a), \"SignedSafeMath: subtraction overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the addition of two signed integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a + b;\n require((b >= 0 && c >= a) || (b < 0 && c < a), \"SignedSafeMath: addition overflow\");\n\n return c;\n }\n}\n\n////// lib/openzeppelin-contracts/contracts/GSN/Context.sol\n/* pragma solidity >=0.6.0 <0.8.0; */\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address payable) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes memory) {\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n return msg.data;\n }\n}\n\n////// lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol\n/* pragma solidity >=0.6.0 <0.8.0; */\n\n/* import \"../../GSN/Context.sol\"; */\n/* import \"./IERC20.sol\"; */\n/* import \"../../math/SafeMath.sol\"; */\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin guidelines: functions revert instead\n * of returning `false` on failure. This behavior is nonetheless conventional\n * and does not conflict with the expectations of ERC20 applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20 {\n using SafeMath for uint256;\n\n mapping (address => uint256) private _balances;\n\n mapping (address => mapping (address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n uint8 private _decimals;\n\n /**\n * @dev Sets the values for {name} and {symbol}, initializes {decimals} with\n * a default value of 18.\n *\n * To select a different value for {decimals}, use {_setupDecimals}.\n *\n * All three of these values are immutable: they can only be set once during\n * construction.\n */\n constructor (string memory name_, string memory symbol_) public {\n _name = name_;\n _symbol = symbol_;\n _decimals = 18;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5,05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is\n * called.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view returns (uint8) {\n return _decimals;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `recipient` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address recipient, uint256 amount) public virtual override returns (bool) {\n _transfer(_msgSender(), recipient, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n _approve(_msgSender(), spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * Requirements:\n *\n * - `sender` and `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n * - the caller must have allowance for ``sender``'s tokens of at least\n * `amount`.\n */\n function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {\n _transfer(sender, recipient, amount);\n _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, \"ERC20: transfer amount exceeds allowance\"));\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, \"ERC20: decreased allowance below zero\"));\n return true;\n }\n\n /**\n * @dev Moves tokens `amount` from `sender` to `recipient`.\n *\n * This is internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `sender` cannot be the zero address.\n * - `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n */\n function _transfer(address sender, address recipient, uint256 amount) internal virtual {\n require(sender != address(0), \"ERC20: transfer from the zero address\");\n require(recipient != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(sender, recipient, amount);\n\n _balances[sender] = _balances[sender].sub(amount, \"ERC20: transfer amount exceeds balance\");\n _balances[recipient] = _balances[recipient].add(amount);\n emit Transfer(sender, recipient, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply = _totalSupply.add(amount);\n _balances[account] = _balances[account].add(amount);\n emit Transfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n _balances[account] = _balances[account].sub(amount, \"ERC20: burn amount exceeds balance\");\n _totalSupply = _totalSupply.sub(amount);\n emit Transfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(address owner, address spender, uint256 amount) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Sets {decimals} to a value other than the default one of 18.\n *\n * WARNING: This function should only be called from the constructor. Most\n * applications that interact with token contracts will not expect\n * {decimals} to ever change, and may work incorrectly if it does.\n */\n function _setupDecimals(uint8 decimals_) internal {\n _decimals = decimals_;\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be to transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }\n}\n\n////// contracts/core/funds-distribution-token/v1/BasicFDT.sol\n/* pragma solidity 0.6.11; */\n\n/* import { SafeMath } from \"../../../../lib/openzeppelin-contracts/contracts/math/SafeMath.sol\"; */\n/* import { SignedSafeMath } from \"../../../../lib/openzeppelin-contracts/contracts/math/SignedSafeMath.sol\"; */\n/* import { ERC20 } from \"../../../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol\"; */\n\n/* import { SafeMathInt } from \"../../../libraries/math/v1/SafeMathInt.sol\"; */\n/* import { SafeMathUint } from \"../../../libraries/math/v1/SafeMathUint.sol\"; */\n\n/* import { IBasicFDT } from \"./interfaces/IBasicFDT.sol\"; */\n\n/// @title BasicFDT implements the basic level FDT functionality for accounting for revenues.\nabstract contract BasicFDT is IBasicFDT, ERC20 {\n\n using SafeMath for uint256;\n using SafeMathUint for uint256;\n using SignedSafeMath for int256;\n using SafeMathInt for int256;\n\n uint256 internal constant pointsMultiplier = 2 ** 128;\n uint256 internal pointsPerShare;\n\n mapping(address => int256) internal pointsCorrection;\n mapping(address => uint256) internal withdrawnFunds;\n\n constructor(string memory name, string memory symbol) ERC20(name, symbol) public { }\n\n /**\n @dev Distributes funds to token holders.\n @dev It reverts if the total supply of tokens is 0.\n @dev It emits a `FundsDistributed` event if the amount of received funds is greater than 0.\n @dev It emits a `PointsPerShareUpdated` event if the amount of received funds is greater than 0.\n About undistributed funds:\n In each distribution, there is a small amount of funds which do not get distributed,\n which is `(value pointsMultiplier) % totalSupply()`.\n With a well-chosen `pointsMultiplier`, the amount funds that are not getting distributed\n in a distribution can be less than 1 (base unit).\n We can actually keep track of the undistributed funds in a distribution\n and try to distribute it in the next distribution.\n */\n function _distributeFunds(uint256 value) internal {\n require(totalSupply() > 0, \"FDT:ZERO_SUPPLY\");\n\n if (value == 0) return;\n\n pointsPerShare = pointsPerShare.add(value.mul(pointsMultiplier) / totalSupply());\n emit FundsDistributed(msg.sender, value);\n emit PointsPerShareUpdated(pointsPerShare);\n }\n\n /**\n @dev Prepares the withdrawal of funds.\n @dev It emits a `FundsWithdrawn` event if the amount of withdrawn funds is greater than 0.\n @return withdrawableDividend The amount of dividend funds that can be withdrawn.\n */\n function _prepareWithdraw() internal returns (uint256 withdrawableDividend) {\n withdrawableDividend = withdrawableFundsOf(msg.sender);\n uint256 _withdrawnFunds = withdrawnFunds[msg.sender].add(withdrawableDividend);\n withdrawnFunds[msg.sender] = _withdrawnFunds;\n\n emit FundsWithdrawn(msg.sender, withdrawableDividend, _withdrawnFunds);\n }\n\n function withdrawableFundsOf(address _owner) public view override returns (uint256) {\n return accumulativeFundsOf(_owner).sub(withdrawnFunds[_owner]);\n }\n\n function withdrawnFundsOf(address _owner) external override view returns (uint256) {\n return withdrawnFunds[_owner];\n }\n\n function accumulativeF