core-artifacts
Version:
Consist artifacts of the maple protocol
123 lines (122 loc) • 1.43 MB
JSON
{
"id": "c35625ee00c9485e9643ee34f38de361",
"_format": "hh-sol-build-info-1",
"solcVersion": "0.6.11",
"solcLongVersion": "0.6.11+commit.5ef660b1",
"input": {
"language": "Solidity",
"sources": {
"contracts/core/pool/v1/PoolFDT.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later // hevm: flattened sources of contracts/core/pool/v1/PoolFDT.sol\npragma solidity =0.6.11 >=0.6.0 <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/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 accumulativeFundsOf(address _owner) public override view returns (uint256) {\n return\n pointsPerShare\n .mul(balanceOf(_owner))\n .toInt256Safe()\n .add(pointsCorrection[_owner])\n .toUint256Safe() / pointsMultiplier;\n }\n\n /**\n @dev Transfers tokens from one account to another. Updates pointsCorrection to keep funds unchanged.\n @dev It emits two `PointsCorrectionUpdated` events, one for the sender and one for the receiver.\n @param from The address to transfer from.\n @param to The address to transfer to.\n @param value The amount to be transferred.\n */\n function _transfer(\n address from,\n address to,\n uint256 value\n ) internal virtual override {\n super._transfer(from, to, value);\n\n int256 _magCorrection = pointsPerShare.mul(value).toInt256Safe();\n int256 pointsCorrectionFrom = pointsCorrection[from].add(_magCorrection);\n pointsCorrection[from] = pointsCorrectionFrom;\n int256 pointsCorrectionTo = pointsCorrection[to].sub(_magCorrection);\n pointsCorrection[to] = pointsCorrectionTo;\n\n emit PointsCorrectionUpdated(from, pointsCorrectionFrom);\n emit PointsCorrectionUpdated(to, pointsCorrectionTo);\n }\n\n /**\n @dev Mints tokens to an account. Updates pointsCorrection to keep funds unchanged.\n @param account The account that will receive the created tokens.\n @param value The amount that will be created.\n */\n function _mint(address account, uint256 value) internal virtual override {\n super._mint(account, value);\n\n int256 _pointsCorrection = pointsCorrection[account].sub(\n (pointsPerShare.mul(value)).toInt256Safe()\n );\n\n pointsCorrection[account] = _pointsCorrection;\n\n emit PointsCorrectionUpdated(account, _pointsCorrection);\n }\n\n /**\n @dev Burns an amount of the token of a given account. Updates pointsCorrection to keep funds unchanged.\n @dev It emits a `PointsCorrectionUpdated` event.\n @param account The account whose tokens will be burnt.\n @param value The amount that will be burnt.\n */\n function _burn(address account, uint256 value) internal virtual override {\n super._burn(account, value);\n\n int256 _pointsCorrection = pointsCorrection[account].add(\n (pointsPerShare.mul(value)).toInt256Safe()\n );\n\n pointsCorrection[account] = _pointsCorrection;\n\n emit PointsCorrectionUpdated(account, _pointsCorrection);\n }\n\n function withdrawFunds() public virtual override {}\n\n /**\n @dev Updates the current `fundsToken` balance and returns the difference of the new and previous `fundsToken` balance.\n @return A int256 representing the difference of the new and previous `fundsToken` balance.\n */\n function _updateFundsTokenBalance() internal virtual returns (int256) {}\n\n function updateFundsReceived() public override virtual {\n int256 newFunds = _updateFundsTokenBalance();\n\n if (newFunds <= 0) return;\n\n _distributeFunds(newFunds.toUint256Safe());\n }\n\n}\n\n////// contracts/core/funds-distribution-token/v1/interfaces/IExtendedFDT.sol\n/* pragma solidity 0.6.11; */\n\n/* import { IBasicFDT } from \"./IBasicFDT.sol\"; */\n\n/// @title ExtendedFDT implements the FDT functionality for accounting for losses.\ninterface IExtendedFDT is IBasicFDT {\n\n /**\n @dev This event emits when the internal `lossesPerShare` is updated.\n @dev First, and only, parameter is the new value of the internal `lossesPerShare`.\n */\n event LossesPerShareUpdated(uint256);\n\n /**\n @dev This event emits when an account's `lossesCorrection` is updated.\n @dev First parameter is the address of some account.\n @dev Second parameter is the new value of the account's `lossesCorrection`.\n */\n event LossesCorrectionUpdated(address indexed, int256);\n\n /**\n @dev This event emits when new losses are distributed.\n @dev First parameter is the address of the account that has distributed losses.\n @dev Second parameter is the amount of losses received for distribution.\n */\n event LossesDistributed(address indexed, uint256);\n\n /**\n @dev This event emits when distributed losses are recognized by a token holder.\n @dev First parameter is the address of the receiver of losses.\n @dev Second parameter is the amount of losses that were recognized.\n @dev Third parameter is the total amount of losses that are recognized.\n */\n event LossesRecognized(address indexed, uint256, uint256);\n\n /**\n @dev Returns the amount of losses that an account can withdraw.\n @param _owner The address of a token holder.\n @return The amount of losses that `_owner` can withdraw.\n */\n function recognizableLossesOf(address _owner) external view returns (uint256);\n\n /**\n @dev Returns the amount of losses that an account has recognized.\n @param _owner The address of a token holder.\n @return The amount of losses that `_owner` has recognized.\n */\n function recognizedLossesOf(address _owner) external view returns (uint256);\n\n /**\n @dev Returns the amount of losses that an account has earned in total. \n @dev accumulativeLossesOf(_owner) = recognizableLossesOf(_owner) + recognizedLossesOf(_owner) \n = (lossesPerShare * balanceOf(_owner) + lossesCorrection[_owner]) / pointsMultiplier \n @param _owner The address of a token holder.\n @return The amount of losses that `_owner` has earned in total.\n */\n function accumulativeLossesOf(address _owner) external view returns (uint256);\n\n /**\n @dev Registers a loss. \n @dev May be called directly after a shortfall after BPT burning occurs. \n @dev Calls _updateLossesTokenBalance(), whereby the contract computes the delta of the new and previous \n losses balance and increments the total losses (cumulative), by delta, by calling _distributeLosses(). \n */\n function updateLossesReceived() external;\n\n}\n\n////// contracts/core/funds-distribution-token/v1/ExtendedFDT.sol\n/* pragma solidity 0.6.11; */\n\n/* import { IExtendedFDT } from \"./interfaces/IExtendedFDT.sol\"; */\n\n/* import { BasicFDT, SafeMath, SafeMathInt, SafeMathUint, SignedSafeMath } from \"./BasicFDT.sol\"; */\n\n/// @title ExtendedFDT implements the FDT functionality for accounting for losses.\nabstract contract ExtendedFDT is IExtendedFDT, BasicFDT {\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 lossesPerShare;\n\n mapping(address => int256) internal lossesCorrection;\n mapping(address => uint256) internal recognizedLosses;\n\n constructor(string memory name, string memory symbol) BasicFDT(name, symbol) public { }\n\n /**\n @dev Distributes losses to token holders.\n @dev It reverts if the total supply of tokens is 0.\n @dev It emits a `LossesDistributed` event if the amount of received losses is greater than 0.\n @dev It emits a `LossesPerShareUpdated` event if the amount of received losses is greater than 0.\n About undistributed losses:\n In each distribution, there is a small amount of losses which do not get distributed,\n which is `(value * pointsMultiplier) % totalSupply()`.\n With a well-chosen `pointsMultiplier`, the amount losses 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 losses in a distribution\n and try to distribute it in the next distribution.\n */\n function _distributeLosses(uint256 value) internal {\n require(totalSupply() > 0, \"FDT:ZERO_SUPPLY\");\n\n if (value == 0) return;\n\n uint256 _lossesPerShare = lossesPerShare.add(value.mul(pointsMultiplier) / totalSupply());\n lossesPerShare = _lossesPerShare;\n\n emit LossesDistributed(msg.sender, value);\n emit LossesPerShareUpdated(_lossesPerShare);\n }\n\n /**\n @dev Prepares losses for a withdrawal.\n @dev It emits a `LossesWithdrawn` event if the amount of withdrawn losses is greater than 0.\n @return recognizableDividend The amount of dividend losses that can be recognized.\n */\n function _prepareLossesWithdraw() internal returns (uint256 recognizableDividend) {\n recognizableDividend = recognizableLossesOf(msg.sender);\n\n uint256 _recognizedLosses = recognizedLosses[msg.sender].add(recognizableDividend);\n recognizedLosses[msg.sender] = _recognizedLosses;\n\n emit LossesRecognized(msg.sender, recognizableDividend, _recognizedLosses);\n }\n\n function recognizableLossesOf(address _owner) public override view returns (uint256) {\n return accumulativeLossesOf(_owner).sub(recognizedLosses[_owner]);\n }\n\n function recognizedLossesOf(address _owner) external override view returns (uint256) {\n return recognizedLosses[_owner];\n }\n\n function accumulativeLossesOf(address _owner) public override view returns (uint256) {\n return\n lossesPerShare\n .mul(balanceOf(_owner))\n .toInt256Safe()\n .add(lossesCorrection[_owner])\n .toUint256Safe() / pointsMultiplier;\n }\n\n /**\n @dev Transfers tokens from one account to another. Updates pointsCorrection to keep funds unchanged.\n @dev It emits two `LossesCorrectionUpdated` events, one for the sender and one for the receiver.\n @param from The address to transfer from.\n @param to The address to transfer to.\n @param value The amount to be transferred.\n */\n function _transfer(\n address from,\n address to,\n uint256 value\n ) internal virtual override {\n super._transfer(from, to, value);\n\n int256 _lossesCorrection = lossesPerShare.mul(value).toInt256Safe();\n int256 lossesCorrectionFrom = lossesCorrection[from].add(_lossesCorrection);\n lossesCorrection[from] = lossesCorrectionFrom;\n int256 lossesCorrectionTo = lossesCorrection[to].sub(_lossesCorrection);\n lossesCorrection[to] = lossesCorrectionTo;\n\n emit LossesCorrectionUpdated(from, lossesCorrectionFrom);\n emit LossesCorrectionUpdated(to, lossesCorrectionTo);\n }\n\n /**\n @dev Mints tokens to an account. Updates lossesCorrection to keep losses unchanged.\n @dev It emits a `LossesCorrectionUpdated` event.\n @param account The account that will receive the created tokens.\n @param value The amount that will be created.\n */\n function _mint(address account, uint256 value) internal virtual override {\n super._mint(account, value);\n\n int256 _lossesCorrection = lossesCorrection[account].sub(\n (lossesPerShare.mul(value)).toInt256Safe()\n );\n\n lossesCorrection[account] = _lossesCorrection;\n\n emit LossesCorrectionUpdated(account, _lossesCorrection);\n }\n\n /**\n @dev Burns an amount of the token of a given account. Updates lossesCorrection to keep losses unchanged.\n @dev It emits a `LossesCorrectionUpdated` event.\n @param account The account from which tokens will be burnt.\n @param value The amount that will be burnt.\n */\n function _burn(address account, uint256 value) internal virtual override {\n super._burn(account, value);\n\n int256 _lossesCorrection = lossesCorrection[account].add(\n (lossesPerShare.mul(value)).toInt256Safe()\n );\n\n lossesCorrection[account] = _lossesCorrection;\n\n emit LossesCorrectionUpdated(account, _lossesCorrection);\n }\n\n function updateLossesReceived() public override virtual {\n int256 newLosses = _updateLossesBalance();\n\n if (newLosses <= 0) return;\n\n _distributeLosses(newLosses.toUint256Safe());\n }\n\n /**\n @dev Recognizes all recognizable losses for an account using loss accounting.\n */\n function _recognizeLosses() internal virtual returns (uint256 losses) { }\n\n /**\n @dev Updates the current losses balance and returns the difference of the new and previous losses balance.\n @return A int256 representing the difference of the new and previous losses balance.\n */\n function _updateLossesBalance() internal virtual returns (int256) { }\n\n}\n\n////// contracts/core/pool/v1/interfaces/IPoolFDT.sol\n/* pragma solidity 0.6.11; */\n\n/* import { IExtendedFDT } from \"../../../funds-distribution-token/v1/interfaces/IExtendedFDT.sol\"; */\n\n/// @title PoolFDT inherits ExtendedFDT and accounts for gains/losses for Liquidity Providers.\ninterface IPoolFDT is IExtendedFDT {\n\n /**\n @dev The sum of all withdrawable interest.\n */\n function interestSum() external view returns (uint256);\n\n /**\n @dev The sum of all unrecognized losses.\n */\n function poolLosses() external view returns (uint256);\n\n /**\n @dev The amount of earned interest present and accounted for in this contract.\n */\n function interestBalance() external view returns (uint256);\n\n /**\n @dev The amount of losses present and accounted for in this contract.\n */\n function lossesBalance() external view returns (uint256);\n\n}\n\n////// contracts/core/pool/v1/PoolFDT.sol\n/* pragma solidity 0.6.11; */\n\n/* import { ExtendedFDT, SafeMath } from \"../../funds-distribution-token/v1/ExtendedFDT.sol\"; */\n\n/* import { IPoolFDT } from \"./interfaces/IPoolFDT.sol\"; */\n\n/// @title PoolFDT inherits ExtendedFDT and accounts for gains/losses for Liquidity Providers.\nabstract contract PoolFDT is IPoolFDT, ExtendedFDT {\n\n using SafeMath for uint256;\n\n uint256 public override interestSum;\n uint256 public override poolLosses;\n\n uint256 public override interestBalance;\n uint256 public override lossesBalance;\n\n constructor(string memory name, string memory symbol) ExtendedFDT(name, symbol) public { }\n\n /**\n @dev Realizes losses incurred to LPs.\n */\n function _recognizeLosses() internal override returns (uint256 losses) {\n losses = _prepareLossesWithdraw();\n\n poolLosses = poolLosses.sub(losses);\n\n _updateLossesBalance();\n }\n\n /**\n @dev Updates the current losses balance and returns the difference of the new and previous losses balance.\n @return A int256 representing the difference of the new and previous losses balance.\n */\n function _updateLossesBalance() internal override returns (int256) {\n uint256 _prevLossesTokenBalance = lossesBalance;\n\n lossesBalance = poolLosses;\n\n return int256(lossesBalance).sub(int256(_prevLossesTokenBalance));\n }\n\n /**\n @dev Updates the current interest balance and returns the difference of the new and previous interest balance.\n @return A int256 representing the difference of the new and previous interest balance.\n */\n function _updateFundsTokenBalance() internal override returns (int256) {\n uint256 _prevFundsTokenBalance = interestBalance;\n\n interestBalance = interestSum;\n\n return int256(interestBalance).sub(int256(_prevFundsTokenBalance));\n }\n\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers"
],
"": [
"ast"
]
}
}
}
},
"output": {
"contracts": {
"contracts/core/pool/v1/PoolFDT.sol": {
"BasicFDT": {
"abi": [
{
"inputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "symbol",
"type": "string"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"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": "by",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "fundsDistributed",
"type": "uint256"
}
],
"name": "FundsDistributed",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "by",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "fundsWithdrawn",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "totalWithdrawn",
"type": "uint256"
}
],
"name": "FundsWithdrawn",
"type": "event"
},