{ "language": "Solidity", "sources": { "contracts/DelphiaCredit.sol": { "content": "// SPDX-License-Identifier: Apache License 2.0\n\npragma solidity 0.8.16;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./Phi.sol\";\n\ncontract DelphiaCredit is Ownable {\n\n Phi public immutable phi;\n\n struct Receipt {\n address recipient;\n uint256 amount;\n }\n\n mapping(address => bool) public operators;\n mapping(address => uint256) public withdrawBalances;\n uint256 public activeBalance;\n\n event Deposited(address indexed payee, uint256 weiAmount);\n event Distributed(address indexed payee, uint256 weiAmount);\n event Withdrawn(address indexed payee, uint256 weiAmount);\n event NewRDO(address operator);\n event RemovedRDO(address operator);\n\n /// @dev Reverts if the caller is not a Rewards Dispersement Operator or an owner\n modifier onlyRDOperator() {\n require(owner() == msg.sender || operators[msg.sender] == true,\n \"DelphiaCredit: Only RD operators can distribute rewards\");\n _;\n }\n\n /// @notice Constructor of DelphiaCredit\n /// @param token Address of Phi used as a payment\n constructor (Phi token) {\n phi = token;\n }\n\n /// @notice Function to add RDO\n /// @dev Only owner can add RDO\n /// @param operator Address of the RDO\n function addRDOperator(address operator) external onlyOwner{\n require(operators[operator] == false,\n \"DelphiaCredit.addRDOperator: There is already such operator\");\n operators[operator] = true;\n emit NewRDO(operator);\n }\n\n /// @notice Function to remove RDO\n /// @dev Only owner can remove RDO\n /// @param operator Address of the RDO\n function removeRDOperator(address operator) external onlyOwner{\n require(operators[operator] == true,\n \"DelphiaCredit.removeRDOperator: There is no such operator\");\n operators[operator] = false;\n emit RemovedRDO(operator);\n }\n\n /**\n * @dev Receives deposited tokens from the outside users.\n * @param amount The amount of tokens sent to the contract.\n */\n function deposit(uint256 amount) external {\n activeBalance += amount;\n require(phi.transferFrom(msg.sender, address (this), amount),\n \"DelphiaCredit.deposit: Can't transfer token to the DelphiaCredit\");\n emit Deposited(msg.sender, amount);\n }\n\n /**\n * @dev Withdraws deposited tokens to the outside users.\n */\n function withdraw(address payee) external {\n uint256 balance = withdrawBalances[payee];\n require(balance > 0,\n \"DelphiaCredit.withdraw: There is nothing to withdraw\");\n withdrawBalances[payee] = 0;\n require(phi.transfer(payee, balance),\n \"Failed to transfer Phi\");\n emit Withdrawn(payee, balance);\n }\n\n /**\n * @dev Distributes received tokens after the game.\n * @param receipts Array of addresses and their rewards amount.\n */\n function distribute(Receipt[] memory receipts) external onlyRDOperator{\n require(receipts.length <= 200,\n \"DelphiaCredit.distribute: Can distribute 200 receipts at max\");\n for(uint64 j = 0; j < receipts.length; j++){\n activeBalance -= receipts[j].amount;\n withdrawBalances[receipts[j].recipient] += receipts[j].amount;\n emit Distributed(receipts[j].recipient, receipts[j].amount);\n }\n }\n\n\n}\n" }, "@openzeppelin/contracts/access/Ownable.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _setOwner(_msgSender());\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _setOwner(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _setOwner(newOwner);\n }\n\n function _setOwner(address newOwner) private {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" }, "contracts/Phi.sol": { "content": "// SPDX-License-Identifier: Apache License 2.0\n\npragma solidity 0.8.16;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./utils/BondingCurveToken.sol\";\nimport \"./DelphiaPlatformToken.sol\";\n\ncontract Phi is Ownable, BondingCurveToken {\n\n\n uint32 private constant MAX_RESERVE_RATIO = 1000000;\n uint256 private constant HUNDRED_PERCENT = 1e18;\n uint256 private constant COEFFICIENT = 1e9;\n uint256 private immutable _fee; // 1e18 = 100%, 1e16 = 1%, 0 = 0%\n DelphiaPlatformToken public immutable delphiaPlatformToken;\n uint256 internal _poolBalance;\n\n event BondedToMint(address indexed receiver, uint256 bonded, uint256 received);\n event BurnedToWithdraw(address indexed receiver, uint256 withdrawn, uint256 received);\n\n /// @notice Constructor that defines BondingTokenCurve and ERC20 parameters\n /// @param token Address of Delphia Platform Token to bond\n /// @param fee fee percentage to pay\n /// @param gasPrice gasPrice limitation to prevent front running\n /// @notice BondingCurveToken is created with _reserveRatio 500000 to set:\n /// PhiSupply ^ 2 = DelphiaPlatformTokenSupply\n constructor(DelphiaPlatformToken token, uint256 fee, uint256 gasPrice) BondingCurveToken(500000, gasPrice) ERC20(\"Phi\",\"PHI\") {\n delphiaPlatformToken = token;\n require(fee= minimalAmountToReceive,\n \"Phi.bondToMint: Mints less tokens then expected\");\n _poolBalance += amountToBond;\n require(delphiaPlatformToken.transferFrom(msg.sender, address(this), amountToBond),\n \"Phi.bondToMint: Impossible to bond so much tokens\");\n }\n\n /// @notice Function that withdraws DelphiaPlatformTokens by burning Phis\n /// @param amountToBurn Amount of Phi to burn\n /// @param minimalAmountToReceive Minimal amount of Delphia Platform Tokens to receive\n function burnToWithdraw(uint256 amountToBurn, uint256 minimalAmountToReceive) external {\n require(balanceOf(msg.sender) >= amountToBurn,\n \"Phi.burnToWithdraw: Not enough funds to withdraw\");\n uint256 currentFee = (amountToBurn * _fee) / HUNDRED_PERCENT;\n _transfer(msg.sender, address(this), currentFee);\n uint256 withdrawn = _curvedBurn(amountToBurn - currentFee);\n _poolBalance = _poolBalance - withdrawn;\n require(withdrawn >= minimalAmountToReceive,\n \"CordinationToken.burnToWithdraw: Send less tokens then expected\");\n require(delphiaPlatformToken.transfer(msg.sender, withdrawn),\n \"Failed to transfer DelphiaPlatformTokens\");\n emit BurnedToWithdraw(msg.sender, amountToBurn, withdrawn);\n }\n\n /// @notice Function that returns the overall amount of bonded DelphiaPlatformTokens\n /// @return Balance of DelphiaPlatformTokens of the contract\n function poolBalance() public override view returns (uint256) {\n return _poolBalance;\n }\n\n function setGasPrice(uint256 gasPrice) public onlyOwner{\n _setGasPrice(gasPrice);\n }\n}\n" }, "@openzeppelin/contracts/utils/Context.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^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 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) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" }, "contracts/utils/BondingCurveToken.sol": { "content": "// SPDX-License-Identifier: Apache License 2.0\n\npragma solidity 0.8.16;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"./BancorFormula.sol\";\n\n/**\n * @title Bonding Curve\n * @dev Bonding curve contract based on Bacor formula\n * inspired by bancor protocol and simondlr\n * https://github.com/bancorprotocol/contracts\n * https://github.com/ConsenSys/curationmarkets/blob/master/CurationMarkets.sol\n */\nabstract contract BondingCurveToken is ERC20, BancorFormula {\n /*\n reserve ratio, represented in ppm, 1-1000000\n 1/3 corresponds to y= multiple * x^2\n 1/2 corresponds to y= multiple * x\n 2/3 corresponds to y= multiple * x^1/2\n multiple will depends on contract initialization,\n specificallytotalAmount and poolBalance parameters\n we might want to add an 'initialize' function that will allow\n the owner to send ether to the contract and mint a given amount of tokens\n */\n uint32 public reserveRatio;\n\n /*\n - Front-running attacks are currently mitigated by the following mechanisms:\n TODO - minimum return argument for each conversion\n provides a way to define a minimum/maximum price for the transaction\n - gas price limit prevents users from having control over the order of execution\n */\n uint256 public gasPrice; // maximum gas price for bancor transactions\n\n event CurvedMint(address sender, uint256 amount, uint256 deposit);\n event CurvedBurn(address sender, uint256 amount, uint256 reimbursement);\n\n constructor(uint32 _reserveRatio, uint256 _gasPrice) {\n reserveRatio = _reserveRatio;\n gasPrice = _gasPrice;\n }\n\n function calculateCurvedMintReturn(uint256 amount) public view returns (uint256) {\n return calculatePurchaseReturn(totalSupply(), poolBalance(), reserveRatio, amount);\n }\n\n function calculateCurvedBurnReturn(uint256 amount) public view returns (uint256) {\n return calculateSaleReturn(totalSupply(), poolBalance(), reserveRatio, amount);\n }\n\n /**\n * @dev Mint tokens\n */\n function _curvedMint(uint256 deposit) internal returns (uint256) {\n return _curvedMintFor(msg.sender, deposit);\n }\n\n function _curvedMintFor(address user, uint256 deposit)\n validGasPrice\n validMint(deposit)\n internal\n returns (uint256)\n {\n uint256 amount = calculateCurvedMintReturn(deposit);\n _mint(user, amount);\n emit CurvedMint(user, amount, deposit);\n return amount;\n }\n\n /**\n * @dev Burn tokens\n * @param amount Amount of tokens to withdraw\n */\n function _curvedBurn(uint256 amount) internal returns (uint256) {\n return _curvedBurnFor(msg.sender, amount);\n }\n\n function _curvedBurnFor(address user, uint256 amount) validGasPrice validBurn(amount) internal returns (uint256) {\n uint256 reimbursement = calculateCurvedBurnReturn(amount);\n _burn(user, amount);\n emit CurvedBurn(user, amount, reimbursement);\n return reimbursement;\n }\n\n /**\n @dev Allows the owner to update the gas price limit\n @param _gasPrice The new gas price limit\n */\n function _setGasPrice(uint256 _gasPrice) internal {\n require(_gasPrice > 0);\n gasPrice = _gasPrice;\n }\n\n /**\n * @dev Abstract method that returns pool balance\n */\n function poolBalance() public virtual view returns (uint256);\n\n // verifies that the gas price is lower than the universal limit\n modifier validGasPrice() {\n assert(tx.gasprice <= gasPrice);\n _;\n }\n\n modifier validBurn(uint256 amount) {\n require(amount > 0 && balanceOf(msg.sender) >= amount);\n _;\n }\n\n modifier validMint(uint256 amount) {\n require(amount > 0);\n _;\n }\n}\n" }, "contracts/DelphiaPlatformToken.sol": { "content": "// SPDX-License-Identifier: Apache License 2.0\n\npragma solidity 0.8.16;\npragma experimental ABIEncoderV2;\n\nimport \"./utils/ERC1404.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n/// @title Contract that implements the Delphia Platform Token to manage the Bonding Curve\n/// @dev This Token is being bonded in the Bonding Curve to gain Phi\n/// which is being used in the games. Delphia Platform Token is strictly managed and\n/// only whitelisted stakeholders are allowed to own it.\n/// Reference implementation of ERC1404 can be found here:\n/// https://github.com/simple-restricted-token/reference-implementation/blob/master/contracts/token/ERC1404/ERC1404ReferenceImpl.sol\n/// https://github.com/simple-restricted-token/simple-restricted-token/blob/master/contracts/token/ERC1404/SimpleRestrictedToken.sol\ncontract DelphiaPlatformToken is ERC1404, Ownable {\n\n uint8 constant private SUCCESS_CODE = 0;\n uint8 constant private ERR_RECIPIENT_CODE = 1;\n uint8 constant private ERR_BONDING_CURVE_CODE = 2;\n uint8 constant private ERR_NOT_WHITELISTED_CODE = 3;\n string constant private SUCCESS_MESSAGE = \"DelphiaPlatformToken: SUCCESS\";\n string constant private ERR_RECIPIENT_MESSAGE = \"DelphiaPlatformToken: RECIPIENT SHOULD BE IN THE WHITELIST\";\n string constant private ERR_BONDING_CURVE_MESSAGE = \"DelphiaPlatformToken: CAN TRANSFER ONLY TO BONDING CURVE\";\n string constant private ERR_NOT_WHITELISTED_MESSAGE = \"DelphiaPlatformToken: ONLY WHITELISTED USERS CAN TRANSFER TOKEN\";\n\n\n struct Role {\n bool awo;\n bool sco;\n }\n\n mapping(address => Role) public operators;\n mapping(address => bool) public whitelist;\n address public bondingCurve;\n\n\n event NewStakeholder(address stakeholer);\n event RemovedStakeholder(address stakeholer);\n event NewSCO(address operator);\n event RemovedSCO(address operator);\n event NewAWO(address operator);\n event RemovedAWO(address operator);\n\n /// @dev Reverts if the caller is not a Securities Control Operator or an owner\n modifier onlySCOperator() {\n require(owner() == msg.sender || operators[msg.sender].sco == true,\n \"DelphiaPlatformToken: Only SC operators can mint/burn token\");\n _;\n }\n\n /// @dev Reverts if the caller is not an Accreditation Whitelist Operator or an owner\n modifier onlyAWOperator() {\n require(owner() == msg.sender || operators[msg.sender].awo == true,\n \"DelphiaPlatformToken: Only AW operators can change whitelist\");\n _;\n }\n\n /// @dev Checks if transfer of 'value' amount of tokens from 'from' to 'to' is allowed\n /// @param from address of token sender\n /// @param to address of token receiver\n /// @param value amount of tokens to transfer\n modifier notRestricted (address from, address to, uint256 value) {\n uint8 restrictionCode = detectTransferRestriction(from, to, value);\n require(restrictionCode == SUCCESS_CODE, messageForTransferRestriction(restrictionCode));\n _;\n }\n\n /// @notice Constructor function of the token\n /// @param name Name of the token as it will be in the ledger\n /// @param symbol Symbol that will represent the token\n constructor(string memory name, string memory symbol) ERC20(name, symbol) {}\n\n /// @notice Function to add AWO\n /// @dev Only owner can add AWO\n /// @param operator Address of the AWO\n function addAWOperator(address operator) external onlyOwner{\n require(operators[operator].awo == false,\n \"DelphiaPlatformToken.addAWOperator: Operator already exists\");\n operators[operator].awo = true;\n emit NewAWO(operator);\n }\n\n /// @notice Function to add SCO\n /// @dev Only owner can add SCO\n /// @param operator Address of the SCO\n function addSCOperator(address operator) external onlyOwner{\n require(operators[operator].sco == false,\n \"DelphiaPlatformToken.addSCOperator: Operator already exists\");\n operators[operator].sco = true;\n emit NewSCO(operator);\n }\n\n /// @notice Function to remove AWO\n /// @dev Only owner can remove AWO\n /// @param operator Address of the AWO\n function removeAWOperator(address operator) external onlyOwner{\n require(operators[operator].awo == true,\n \"DelphiaPlatformToken.removeAWOperator: There is no such operator\");\n operators[operator].awo = false;\n emit RemovedAWO(operator);\n }\n\n /// @notice Function to remove SCO\n /// @dev Only owner can remove SCO\n /// @param operator Address of the SCO\n function removeSCOperator(address operator) external onlyOwner{\n require(operators[operator].sco == true,\n \"DelphiaPlatformToken.removeSCOperator: There is no such operator\");\n operators[operator].sco = false;\n emit RemovedSCO(operator);\n }\n\n /// @notice Function to mint DelphiaPlatformToken\n /// @dev Only SCO can mint tokens to the whitelisted addresses\n /// @param account Address of the token receiver\n /// @param amount Amount of minted tokens\n function mint(address account, uint256 amount) external onlySCOperator{\n require(whitelist[account] == true,\n \"DelphiaPlatformToken.mint: Only whitelisted users can own tokens\");\n _mint(account, amount);\n }\n\n /// @notice Function to burn DelphiaPlatformToken\n /// @dev Only SCO can burn tokens from addresses\n /// @param account Address from which tokens will be burned\n /// @param amount Amount of burned tokens\n function burn(address account, uint256 amount) external onlySCOperator{\n _burn(account, amount);\n }\n\n /// @notice Function to add address to Whitelist\n /// @dev Only AWO can add address to Whitelist\n /// @param account Address to add to the Whitelist\n function addToWhitelist(address account) public onlyAWOperator{\n whitelist[account] = true;\n emit NewStakeholder(account);\n }\n\n /// @notice Function to remove address from Whitelist\n /// @dev Only AWO can remove address from Whitelist on removal from the list user loses all of the tokens\n /// @param account Address to remove from the Whitelist\n function removeFromWhitelist(address account) external onlyAWOperator{\n require(whitelist[account] == true,\n \"DelphiaPlatformToken.removeFromWhitelist: User not in whitelist\");\n require(account != bondingCurve,\n \"DelphiaPlatformToken.removeFromWhitelist: Can't del bondingCurve\");\n whitelist[account] = false;\n emit RemovedStakeholder(account);\n }\n\n /// @notice Function to check the restriction for token transfer\n /// @param from address of sender\n /// @param to address of receiver\n /// @param value amount of tokens to transfer\n /// @return restrictionCode code of restriction for specific transfer\n function detectTransferRestriction (address from, address to, uint256 value)\n public\n view\n override\n returns (uint8 restrictionCode)\n {\n require(value > 0, \"DelphiaPlatformToken: need to transfer more than 0.\");\n if(from == bondingCurve){\n if(whitelist[to] == true){\n restrictionCode = SUCCESS_CODE;\n } else {\n restrictionCode = ERR_RECIPIENT_CODE;\n }\n } else if (whitelist[from]){\n if(to == bondingCurve){\n restrictionCode = SUCCESS_CODE;\n } else {\n restrictionCode = ERR_BONDING_CURVE_CODE;\n }\n } else{\n restrictionCode = ERR_NOT_WHITELISTED_CODE;\n }\n }\n\n\n /// @notice Function to return restriction message based on the code\n /// @param restrictionCode code of restriction\n /// @return message message of restriction for specific code\n function messageForTransferRestriction (uint8 restrictionCode)\n public\n pure\n override\n returns (string memory message)\n {\n if (restrictionCode == SUCCESS_CODE) {\n message = SUCCESS_MESSAGE;\n } else if (restrictionCode == ERR_RECIPIENT_CODE) {\n message = ERR_RECIPIENT_MESSAGE;\n } else if (restrictionCode == ERR_BONDING_CURVE_CODE) {\n message = ERR_BONDING_CURVE_MESSAGE;\n } else {\n message = ERR_NOT_WHITELISTED_MESSAGE;\n }\n }\n\n\n /// @notice Function to transfer tokens between whitelisted users\n /// @param to Address to which tokens are sent\n /// @param value Amount of tokens to send\n function transfer(address to, uint256 value)\n public\n override\n notRestricted(msg.sender, to, value)\n returns (bool)\n {\n _transfer(msg.sender, to, value);\n return true;\n }\n\n /// @notice Function to transfer tokens from some another address(used after approve)\n /// @dev Only Whitelisted addresses that have the approval can send or receive tokens\n /// @param sender Address that will be used to send tokens from\n /// @param recipient Address that will receive tokens\n /// @param amount Amount of tokens that may be sent\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n )\n public\n override\n notRestricted(sender, recipient, amount)\n returns (bool) {\n _transfer(sender, recipient, amount);\n\n uint256 currentAllowance = allowance(sender, msg.sender);\n require(currentAllowance >= amount, \"ERC20: transfer amount exceeds allowance\");\n\n unchecked {\n _approve(sender, msg.sender, currentAllowance - amount);\n }\n\n return true;\n }\n\n /// @notice Function to set BondingCurve address for the contract\n /// @param curve address of the BondingCurve\n function setupBondingCurve(address curve) external onlyOwner {\n whitelist[bondingCurve] = false;\n bondingCurve = curve;\n whitelist[bondingCurve] = true;\n }\n\n\n /// @notice Function to check if user is in a whitelist\n /// @param user Address to check\n /// @return If address is in a whitelist\n function isInWhitelist(address user) external view returns (bool) {\n return whitelist[user];\n }\n}\n" }, "@openzeppelin/contracts/token/ERC20/ERC20.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.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, IERC20Metadata {\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\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override 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 virtual override 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 this function is\n * overridden;\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 virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual 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(\n address sender,\n address recipient,\n uint256 amount\n ) public virtual override returns (bool) {\n _transfer(sender, recipient, amount);\n\n uint256 currentAllowance = _allowances[sender][_msgSender()];\n require(currentAllowance >= amount, \"ERC20: transfer amount exceeds allowance\");\n unchecked {\n _approve(sender, _msgSender(), currentAllowance - amount);\n }\n\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] + 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 uint256 currentAllowance = _allowances[_msgSender()][spender];\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(_msgSender(), spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `sender` to `recipient`.\n *\n * This 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(\n address sender,\n address recipient,\n uint256 amount\n ) 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 uint256 senderBalance = _balances[sender];\n require(senderBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[sender] = senderBalance - amount;\n }\n _balances[recipient] += amount;\n\n emit Transfer(sender, recipient, amount);\n\n _afterTokenTransfer(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 * - `account` 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 += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(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 uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n }\n _totalSupply -= amount;\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(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(\n address owner,\n address spender,\n uint256 amount\n ) 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 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 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(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after 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 * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n" }, "contracts/utils/BancorFormula.sol": { "content": "// SPDX-License-Identifier: Apache License 2.0\n\npragma solidity 0.8.16;\n\n\nimport \"./Power.sol\";\n\n/**\n* @title Bancor formula by Bancor\n* @dev Modified from the original by Slava Balasanov\n* https://github.com/bancorprotocol/contracts\n* Split Power.sol out from BancorFormula.sol and replace SafeMath formulas with zeppelin's SafeMath\n* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements;\n* and to You under the Apache License, Version 2.0. \"\n*/\ncontract BancorFormula is Power {\n string public version = \"0.3\";\n uint32 private constant MAX_WEIGHT = 1000000;\n\n /**\n * @dev given a token supply, connector balance, weight and a deposit amount (in the connector token),\n * calculates the return for a given conversion (in the main token)\n *\n * Formula:\n * Return = _supply * ((1 + _depositAmount / _connectorBalance) ^ (_connectorWeight / 1000000) - 1)\n *\n * @param _supply token total supply\n * @param _connectorBalance total connector balance\n * @param _connectorWeight connector weight, represented in ppm, 1-1000000\n * @param _depositAmount deposit amount, in connector token\n *\n * @return purchase return amount\n */\n function calculatePurchaseReturn(\n uint256 _supply,\n uint256 _connectorBalance,\n uint32 _connectorWeight,\n uint256 _depositAmount) public view returns (uint256)\n {\n // validate input\n require(_supply > 0, \"BancorFormula: Supply not > 0.\");\n require(_connectorBalance > 0, \"BancorFormula: ConnectorBalance not > 0\");\n require(_connectorWeight > 0, \"BancorFormula: Connector Weight not > 0\");\n require(_connectorWeight <= MAX_WEIGHT, \"BancorFormula: Connector Weight not <= MAX_WEIGHT\");\n\n // special case for 0 deposit amount\n if (_depositAmount == 0) {\n return 0;\n }\n // special case if the weight = 100%\n if (_connectorWeight == MAX_WEIGHT) {\n return _supply * _depositAmount / _connectorBalance;\n }\n uint256 result;\n uint8 precision;\n uint256 baseN = _depositAmount + _connectorBalance;\n (result, precision) = power(\n baseN, _connectorBalance, _connectorWeight, MAX_WEIGHT\n );\n uint256 newTokenSupply = _supply * result >> precision;\n return newTokenSupply - _supply;\n }\n\n /**\n * @dev given a token supply, connector balance, weight and a sell amount (in the main token),\n * calculates the return for a given conversion (in the connector token)\n *\n * Formula:\n * Return = _connectorBalance * (1 - (1 - _sellAmount / _supply) ^ (1 / (_connectorWeight / 1000000)))\n *\n * @param _supply token total supply\n * @param _connectorBalance total connector\n * @param _connectorWeight constant connector Weight, represented in ppm, 1-1000000\n * @param _sellAmount sell amount, in the token itself\n *\n * @return sale return amount\n */\n function calculateSaleReturn(\n uint256 _supply,\n uint256 _connectorBalance,\n uint32 _connectorWeight,\n uint256 _sellAmount) public view returns (uint256)\n {\n // validate input\n require(_supply > 0, \"BancorFormula: Supply not > 0.\");\n require(_connectorBalance > 0, \"BancorFormula: ConnectorBalance not > 0\");\n require(_connectorWeight > 0, \"BancorFormula: Connector Weight not > 0\");\n require(_connectorWeight <= MAX_WEIGHT, \"BancorFormula: Connector Weight not <= MAX_WEIGHT\");\n require(_sellAmount <= _supply, \"BancorFormula: Sell Amount not <= Supply\");\n\n // special case for 0 sell amount\n if (_sellAmount == 0) {\n return 0;\n }\n // special case for selling the entire supply\n if (_sellAmount == _supply) {\n return _connectorBalance;\n }\n // special case if the weight = 100%\n if (_connectorWeight == MAX_WEIGHT) {\n return _connectorBalance * _sellAmount / _supply;\n }\n uint256 result;\n uint8 precision;\n uint256 baseD = _supply - _sellAmount;\n (result, precision) = power(\n _supply, baseD, MAX_WEIGHT, _connectorWeight\n );\n uint256 oldBalance = _connectorBalance * result;\n uint256 newBalance = _connectorBalance << precision;\n return (oldBalance - newBalance) / result;\n }\n}\n" }, "@openzeppelin/contracts/token/ERC20/IERC20.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^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(\n address sender,\n address recipient,\n uint256 amount\n ) 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" }, "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" }, "contracts/utils/Power.sol": { "content": "// SPDX-License-Identifier: Apache License 2.0\n\n/* Apache License\nVersion 2.0, January 2004\nhttp://www.apache.org/licenses/\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n1. Definitions.\n\"License\" shall mean the terms and conditions for use, reproduction,\nand distribution as defined by Sections 1 through 9 of this document.\n\"Licensor\" shall mean the copyright owner or entity authorized by\nthe copyright owner that is granting the License.\n\"Legal Entity\" shall mean the union of the acting entity and all\nother entities that control, are controlled by, or are under common\ncontrol with that entity. For the purposes of this definition,\n\"control\" means (i) the power, direct or indirect, to cause the\ndirection or management of such entity, whether by contract or\notherwise, or (ii) ownership of fifty percent (50%) or more of the\noutstanding shares, or (iii) beneficial ownership of such entity.\n\"You\" (or \"Your\") shall mean an individual or Legal Entity\nexercising permissions granted by this License.\n\"Source\" form shall mean the preferred form for making modifications,\nincluding but not limited to software source code, documentation\nsource, and configuration files.\n\"Object\" form shall mean any form resulting from mechanical\ntransformation or translation of a Source form, including but\nnot limited to compiled object code, generated documentation,\nand conversions to other media types.\n\"Work\" shall mean the work of authorship, whether in Source or\nObject form, made available under the License, as indicated by a\ncopyright notice that is included in or attached to the work\n(an example is provided in the Appendix below).\n\"Derivative Works\" shall mean any work, whether in Source or Object\nform, that is based on (or derived from) the Work and for which the\neditorial revisions, annotations, elaborations, or other modifications\nrepresent, as a whole, an original work of authorship. For the purposes\nof this License, Derivative Works shall not include works that remain\nseparable from, or merely link (or bind by name) to the interfaces of,\nthe Work and Derivative Works thereof.\n\"Contribution\" shall mean any work of authorship, including\nthe original version of the Work and any modifications or additions\nto that Work or Derivative Works thereof, that is intentionally\nsubmitted to Licensor for inclusion in the Work by the copyright owner\nor by an individual or Legal Entity authorized to submit on behalf of\nthe copyright owner. For the purposes of this definition, \"submitted\"\nmeans any form of electronic, verbal, or written communication sent\nto the Licensor or its representatives, including but not limited to\ncommunication on electronic mailing lists, source code control systems,\nand issue tracking systems that are managed by, or on behalf of, the\nLicensor for the purpose of discussing and improving the Work, but\nexcluding communication that is conspicuously marked or otherwise\ndesignated in writing by the copyright owner as \"Not a Contribution.\"\n\"Contributor\" shall mean Licensor and any individual or Legal Entity\non behalf of whom a Contribution has been received by Licensor and\nsubsequently incorporated within the Work.\n2. Grant of Copyright License. Subject to the terms and conditions of\nthis License, each Contributor hereby grants to You a perpetual,\nworldwide, non-exclusive, no-charge, royalty-free, irrevocable\ncopyright license to reproduce, prepare Derivative Works of,\npublicly display, publicly perform, sublicense, and distribute the\nWork and such Derivative Works in Source or Object form.\n3. Grant of Patent License. Subject to the terms and conditions of\nthis License, each Contributor hereby grants to You a perpetual,\nworldwide, non-exclusive, no-charge, royalty-free, irrevocable\n(except as stated in this section) patent license to make, have made,\nuse, offer to sell, sell, import, and otherwise transfer the Work,\nwhere such license applies only to those patent claims licensable\nby such Contributor that are necessarily infringed by their\nContribution(s) alone or by combination of their Contribution(s)\nwith the Work to which such Contribution(s) was submitted. If You\ninstitute patent litigation against any entity (including a\ncross-claim or counterclaim in a lawsuit) alleging that the Work\nor a Contribution incorporated within the Work constitutes direct\nor contributory patent infringement, then any patent licenses\ngranted to You under this License for that Work shall terminate\nas of the date such litigation is filed.\n4. Redistribution. You may reproduce and distribute copies of the\nWork or Derivative Works thereof in any medium, with or without\nmodifications, and in Source or Object form, provided that You\nmeet the following conditions:\n(a) You must give any other recipients of the Work or\nDerivative Works a copy of this License; and\n(b) You must cause any modified files to carry prominent notices\nstating that You changed the files; and\n(c) You must retain, in the Source form of any Derivative Works\nthat You distribute, all copyright, patent, trademark, and\nattribution notices from the Source form of the Work,\nexcluding those notices that do not pertain to any part of\nthe Derivative Works; and\n(d) If the Work includes a \"NOTICE\" text file as part of its\ndistribution, then any Derivative Works that You distribute must\ninclude a readable copy of the attribution notices contained\nwithin such NOTICE file, excluding those notices that do not\npertain to any part of the Derivative Works, in at least one\nof the following places: within a NOTICE text file distributed\nas part of the Derivative Works; within the Source form or\ndocumentation, if provided along with the Derivative Works; or,\nwithin a display generated by the Derivative Works, if and\nwherever such third-party notices normally appear. The contents\nof the NOTICE file are for informational purposes only and\ndo not modify the License. You may add Your own attribution\nnotices within Derivative Works that You distribute, alongside\nor as an addendum to the NOTICE text from the Work, provided\nthat such additional attribution notices cannot be construed\nas modifying the License.\nYou may add Your own copyright statement to Your modifications and\nmay provide additional or different license terms and conditions\nfor use, reproduction, or distribution of Your modifications, or\nfor any such Derivative Works as a whole, provided Your use,\nreproduction, and distribution of the Work otherwise complies with\nthe conditions stated in this License.\n5. Submission of Contributions. Unless You explicitly state otherwise,\nany Contribution intentionally submitted for inclusion in the Work\nby You to the Licensor shall be under the terms and conditions of\nthis License, without any additional terms or conditions.\nNotwithstanding the above, nothing herein shall supersede or modify\nthe terms of any separate license agreement you may have executed\nwith Licensor regarding such Contributions.\n6. Trademarks. This License does not grant permission to use the trade\nnames, trademarks, service marks, or product names of the Licensor,\nexcept as required for reasonable and customary use in describing the\norigin of the Work and reproducing the content of the NOTICE file.\n7. Disclaimer of Warranty. Unless required by applicable law or\nagreed to in writing, Licensor provides the Work (and each\nContributor provides its Contributions) on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\nimplied, including, without limitation, any warranties or conditions\nof TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\nPARTICULAR PURPOSE. You are solely responsible for determining the\nappropriateness of using or redistributing the Work and assume any\nrisks associated with Your exercise of permissions under this License.\n8. Limitation of Liability. In no event and under no legal theory,\nwhether in tort (including negligence), contract, or otherwise,\nunless required by applicable law (such as deliberate and grossly\nnegligent acts) or agreed to in writing, shall any Contributor be\nliable to You for damages, including any direct, indirect, special,\nincidental, or consequential damages of any character arising as a\nresult of this License or out of the use or inability to use the\nWork (including but not limited to damages for loss of goodwill,\nwork stoppage, computer failure or malfunction, or any and all\nother commercial damages or losses), even if such Contributor\nhas been advised of the possibility of such damages.\n9. Accepting Warranty or Additional Liability. While redistributing\nthe Work or Derivative Works thereof, You may choose to offer,\nand charge a fee for, acceptance of support, warranty, indemnity,\nor other liability obligations and/or rights consistent with this\nLicense. However, in accepting such obligations, You may act only\non Your own behalf and on Your sole responsibility, not on behalf\nof any other Contributor, and only if You agree to indemnify,\ndefend, and hold each Contributor harmless for any liability\nincurred by, or claims asserted against, such Contributor by reason\nof your accepting any such warranty or additional liability.\nEND OF TERMS AND CONDITIONS\nAPPENDIX: How to apply the Apache License to your work.\nTo apply the Apache License to your work, attach the following\nboilerplate notice, with the fields enclosed by brackets \"{}\"\nreplaced with your own identifying information. (Don't include\nthe brackets!) The text should be enclosed in the appropriate\ncomment syntax for the file format. We also recommend that a\nfile or class name and description of purpose be included on the\nsame \"printed page\" as the copyright notice for easier\nidentification within third-party archives.\nCopyright 2017 Bprotocol Foundation\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttp://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License. */\n\npragma solidity 0.8.16;\n\n/**\n* @title Power function by Bancor\n* @dev https://github.com/bancorprotocol/contracts\n*\n* Modified from the original by Slava Balasanov & Tarrence van As\n*\n* Split Power.sol out from BancorFormula.sol\n*/\ncontract Power {\n\n uint256 private constant ONE = 1;\n uint8 private constant MIN_PRECISION = 32;\n uint8 private constant MAX_PRECISION = 127;\n\n /**\n The values below depend on MAX_PRECISION. If you choose to change it:\n Apply the same change in file 'PrintIntScalingFactors.py', run it and paste the results below.\n */\n uint256 private constant FIXED_1 = 0x080000000000000000000000000000000;\n uint256 private constant FIXED_2 = 0x100000000000000000000000000000000;\n uint256 private constant MAX_NUM = 0x200000000000000000000000000000000;\n\n /**\n Auto-generated via 'PrintLn2ScalingFactors.py'\n */\n uint256 private constant LN2_NUMERATOR = 0x3f80fe03f80fe03f80fe03f80fe03f8;\n uint256 private constant LN2_DENOMINATOR = 0x5b9de1d10bf4103d647b0955897ba80;\n\n /**\n Auto-generated via 'PrintFunctionOptimalLog.py' and 'PrintFunctionOptimalExp.py'\n */\n uint256 private constant OPT_LOG_MAX_VAL =\n 0x15bf0a8b1457695355fb8ac404e7a79e3;\n uint256 private constant OPT_EXP_MAX_VAL =\n 0x800000000000000000000000000000000;\n\n /**\n The values below depend on MIN_PRECISION and MAX_PRECISION. If you choose to change either one of them:\n Apply the same change in file 'PrintFunctionBancorFormula.py', run it and paste the results below.\n */\n uint256[128] private maxExpArray;\n constructor() {\n // maxExpArray[0] = 0x6bffffffffffffffffffffffffffffffff;\n // maxExpArray[1] = 0x67ffffffffffffffffffffffffffffffff;\n // maxExpArray[2] = 0x637fffffffffffffffffffffffffffffff;\n // maxExpArray[3] = 0x5f6fffffffffffffffffffffffffffffff;\n // maxExpArray[4] = 0x5b77ffffffffffffffffffffffffffffff;\n // maxExpArray[5] = 0x57b3ffffffffffffffffffffffffffffff;\n // maxExpArray[6] = 0x5419ffffffffffffffffffffffffffffff;\n // maxExpArray[7] = 0x50a2ffffffffffffffffffffffffffffff;\n // maxExpArray[8] = 0x4d517fffffffffffffffffffffffffffff;\n // maxExpArray[9] = 0x4a233fffffffffffffffffffffffffffff;\n // maxExpArray[10] = 0x47165fffffffffffffffffffffffffffff;\n // maxExpArray[11] = 0x4429afffffffffffffffffffffffffffff;\n // maxExpArray[12] = 0x415bc7ffffffffffffffffffffffffffff;\n // maxExpArray[13] = 0x3eab73ffffffffffffffffffffffffffff;\n // maxExpArray[14] = 0x3c1771ffffffffffffffffffffffffffff;\n // maxExpArray[15] = 0x399e96ffffffffffffffffffffffffffff;\n // maxExpArray[16] = 0x373fc47fffffffffffffffffffffffffff;\n // maxExpArray[17] = 0x34f9e8ffffffffffffffffffffffffffff;\n // maxExpArray[18] = 0x32cbfd5fffffffffffffffffffffffffff;\n // maxExpArray[19] = 0x30b5057fffffffffffffffffffffffffff;\n // maxExpArray[20] = 0x2eb40f9fffffffffffffffffffffffffff;\n // maxExpArray[21] = 0x2cc8340fffffffffffffffffffffffffff;\n // maxExpArray[22] = 0x2af09481ffffffffffffffffffffffffff;\n // maxExpArray[23] = 0x292c5bddffffffffffffffffffffffffff;\n // maxExpArray[24] = 0x277abdcdffffffffffffffffffffffffff;\n // maxExpArray[25] = 0x25daf6657fffffffffffffffffffffffff;\n // maxExpArray[26] = 0x244c49c65fffffffffffffffffffffffff;\n // maxExpArray[27] = 0x22ce03cd5fffffffffffffffffffffffff;\n // maxExpArray[28] = 0x215f77c047ffffffffffffffffffffffff;\n // maxExpArray[29] = 0x1fffffffffffffffffffffffffffffffff;\n // maxExpArray[30] = 0x1eaefdbdabffffffffffffffffffffffff;\n // maxExpArray[31] = 0x1d6bd8b2ebffffffffffffffffffffffff;\n maxExpArray[32] = 0x1c35fedd14ffffffffffffffffffffffff;\n maxExpArray[33] = 0x1b0ce43b323fffffffffffffffffffffff;\n maxExpArray[34] = 0x19f0028ec1ffffffffffffffffffffffff;\n maxExpArray[35] = 0x18ded91f0e7fffffffffffffffffffffff;\n maxExpArray[36] = 0x17d8ec7f0417ffffffffffffffffffffff;\n maxExpArray[37] = 0x16ddc6556cdbffffffffffffffffffffff;\n maxExpArray[38] = 0x15ecf52776a1ffffffffffffffffffffff;\n maxExpArray[39] = 0x15060c256cb2ffffffffffffffffffffff;\n maxExpArray[40] = 0x1428a2f98d72ffffffffffffffffffffff;\n maxExpArray[41] = 0x13545598e5c23fffffffffffffffffffff;\n maxExpArray[42] = 0x1288c4161ce1dfffffffffffffffffffff;\n maxExpArray[43] = 0x11c592761c666fffffffffffffffffffff;\n maxExpArray[44] = 0x110a688680a757ffffffffffffffffffff;\n maxExpArray[45] = 0x1056f1b5bedf77ffffffffffffffffffff;\n maxExpArray[46] = 0x0faadceceeff8bffffffffffffffffffff;\n maxExpArray[47] = 0x0f05dc6b27edadffffffffffffffffffff;\n maxExpArray[48] = 0x0e67a5a25da4107fffffffffffffffffff;\n maxExpArray[49] = 0x0dcff115b14eedffffffffffffffffffff;\n maxExpArray[50] = 0x0d3e7a392431239fffffffffffffffffff;\n maxExpArray[51] = 0x0cb2ff529eb71e4fffffffffffffffffff;\n maxExpArray[52] = 0x0c2d415c3db974afffffffffffffffffff;\n maxExpArray[53] = 0x0bad03e7d883f69bffffffffffffffffff;\n maxExpArray[54] = 0x0b320d03b2c343d5ffffffffffffffffff;\n maxExpArray[55] = 0x0abc25204e02828dffffffffffffffffff;\n maxExpArray[56] = 0x0a4b16f74ee4bb207fffffffffffffffff;\n maxExpArray[57] = 0x09deaf736ac1f569ffffffffffffffffff;\n maxExpArray[58] = 0x0976bd9952c7aa957fffffffffffffffff;\n maxExpArray[59] = 0x09131271922eaa606fffffffffffffffff;\n maxExpArray[60] = 0x08b380f3558668c46fffffffffffffffff;\n maxExpArray[61] = 0x0857ddf0117efa215bffffffffffffffff;\n maxExpArray[62] = 0x07ffffffffffffffffffffffffffffffff;\n maxExpArray[63] = 0x07abbf6f6abb9d087fffffffffffffffff;\n maxExpArray[64] = 0x075af62cbac95f7dfa7fffffffffffffff;\n maxExpArray[65] = 0x070d7fb7452e187ac13fffffffffffffff;\n maxExpArray[66] = 0x06c3390ecc8af379295fffffffffffffff;\n maxExpArray[67] = 0x067c00a3b07ffc01fd6fffffffffffffff;\n maxExpArray[68] = 0x0637b647c39cbb9d3d27ffffffffffffff;\n maxExpArray[69] = 0x05f63b1fc104dbd39587ffffffffffffff;\n maxExpArray[70] = 0x05b771955b36e12f7235ffffffffffffff;\n maxExpArray[71] = 0x057b3d49dda84556d6f6ffffffffffffff;\n maxExpArray[72] = 0x054183095b2c8ececf30ffffffffffffff;\n maxExpArray[73] = 0x050a28be635ca2b888f77fffffffffffff;\n maxExpArray[74] = 0x04d5156639708c9db33c3fffffffffffff;\n maxExpArray[75] = 0x04a23105873875bd52dfdfffffffffffff;\n maxExpArray[76] = 0x0471649d87199aa990756fffffffffffff;\n maxExpArray[77] = 0x04429a21a029d4c1457cfbffffffffffff;\n maxExpArray[78] = 0x0415bc6d6fb7dd71af2cb3ffffffffffff;\n maxExpArray[79] = 0x03eab73b3bbfe282243ce1ffffffffffff;\n maxExpArray[80] = 0x03c1771ac9fb6b4c18e229ffffffffffff;\n maxExpArray[81] = 0x0399e96897690418f785257fffffffffff;\n maxExpArray[82] = 0x0373fc456c53bb779bf0ea9fffffffffff;\n maxExpArray[83] = 0x034f9e8e490c48e67e6ab8bfffffffffff;\n maxExpArray[84] = 0x032cbfd4a7adc790560b3337ffffffffff;\n maxExpArray[85] = 0x030b50570f6e5d2acca94613ffffffffff;\n maxExpArray[86] = 0x02eb40f9f620fda6b56c2861ffffffffff;\n maxExpArray[87] = 0x02cc8340ecb0d0f520a6af58ffffffffff;\n maxExpArray[88] = 0x02af09481380a0a35cf1ba02ffffffffff;\n maxExpArray[89] = 0x0292c5bdd3b92ec810287b1b3fffffffff;\n maxExpArray[90] = 0x0277abdcdab07d5a77ac6d6b9fffffffff;\n maxExpArray[91] = 0x025daf6654b1eaa55fd64df5efffffffff;\n maxExpArray[92] = 0x0244c49c648baa98192dce88b7ffffffff;\n maxExpArray[93] = 0x022ce03cd5619a311b2471268bffffffff;\n maxExpArray[94] = 0x0215f77c045fbe885654a44a0fffffffff;\n maxExpArray[95] = 0x01ffffffffffffffffffffffffffffffff;\n maxExpArray[96] = 0x01eaefdbdaaee7421fc4d3ede5ffffffff;\n maxExpArray[97] = 0x01d6bd8b2eb257df7e8ca57b09bfffffff;\n maxExpArray[98] = 0x01c35fedd14b861eb0443f7f133fffffff;\n maxExpArray[99] = 0x01b0ce43b322bcde4a56e8ada5afffffff;\n maxExpArray[100] = 0x019f0028ec1fff007f5a195a39dfffffff;\n maxExpArray[101] = 0x018ded91f0e72ee74f49b15ba527ffffff;\n maxExpArray[102] = 0x017d8ec7f04136f4e5615fd41a63ffffff;\n maxExpArray[103] = 0x016ddc6556cdb84bdc8d12d22e6fffffff;\n maxExpArray[104] = 0x015ecf52776a1155b5bd8395814f7fffff;\n maxExpArray[105] = 0x015060c256cb23b3b3cc3754cf40ffffff;\n maxExpArray[106] = 0x01428a2f98d728ae223ddab715be3fffff;\n maxExpArray[107] = 0x013545598e5c23276ccf0ede68034fffff;\n maxExpArray[108] = 0x01288c4161ce1d6f54b7f61081194fffff;\n maxExpArray[109] = 0x011c592761c666aa641d5a01a40f17ffff;\n maxExpArray[110] = 0x0110a688680a7530515f3e6e6cfdcdffff;\n maxExpArray[111] = 0x01056f1b5bedf75c6bcb2ce8aed428ffff;\n maxExpArray[112] = 0x00faadceceeff8a0890f3875f008277fff;\n maxExpArray[113] = 0x00f05dc6b27edad306388a600f6ba0bfff;\n maxExpArray[114] = 0x00e67a5a25da41063de1495d5b18cdbfff;\n maxExpArray[115] = 0x00dcff115b14eedde6fc3aa5353f2e4fff;\n maxExpArray[116] = 0x00d3e7a3924312399f9aae2e0f868f8fff;\n maxExpArray[117] = 0x00cb2ff529eb71e41582cccd5a1ee26fff;\n maxExpArray[118] = 0x00c2d415c3db974ab32a51840c0b67edff;\n maxExpArray[119] = 0x00bad03e7d883f69ad5b0a186184e06bff;\n maxExpArray[120] = 0x00b320d03b2c343d4829abd6075f0cc5ff;\n maxExpArray[121] = 0x00abc25204e02828d73c6e80bcdb1a95bf;\n maxExpArray[122] = 0x00a4b16f74ee4bb2040a1ec6c15fbbf2df;\n maxExpArray[123] = 0x009deaf736ac1f569deb1b5ae3f36c130f;\n maxExpArray[124] = 0x00976bd9952c7aa957f5937d790ef65037;\n maxExpArray[125] = 0x009131271922eaa6064b73a22d0bd4f2bf;\n maxExpArray[126] = 0x008b380f3558668c46c91c49a2f8e967b9;\n maxExpArray[127] = 0x00857ddf0117efa215952912839f6473e6;\n }\n\n /**\n General Description:\n Determine a value of precision.\n Calculate an integer approximation of (_baseN / _baseD) ^ (_expN / _expD) * 2 ^ precision.\n Return the result along with the precision used.\n Detailed Description:\n Instead of calculating \"base ^ exp\", we calculate \"e ^ (log(base) * exp)\".\n The value of \"log(base)\" is represented with an integer slightly smaller than \"log(base) * 2 ^ precision\".\n The larger \"precision\" is, the more accurately this value represents the real value.\n However, the larger \"precision\" is, the more bits are required in order to store this value.\n And the exponentiation function, which takes \"x\" and calculates \"e ^ x\", is limited to a maximum exponent (maximum value of \"x\").\n This maximum exponent depends on the \"precision\" used, and it is given by \"maxExpArray[precision] >> (MAX_PRECISION - precision)\".\n Hence we need to determine the highest precision which can be used for the given input, before calling the exponentiation function.\n This allows us to compute \"base ^ exp\" with maximum accuracy and without exceeding 256 bits in any of the intermediate computations.\n This functions assumes that \"_expN < 2 ^ 256 / log(MAX_NUM - 1)\", otherwise the multiplication should be replaced with a \"safeMul\".\n */\n function power(\n uint256 _baseN,\n uint256 _baseD,\n uint32 _expN,\n uint32 _expD\n ) internal view returns (uint256, uint8)\n {\n assert(_baseN < MAX_NUM);\n require(_baseN >= _baseD, \"Bases < 1 are not supported.\");\n\n uint256 baseLog;\n uint256 base = _baseN * FIXED_1 / _baseD;\n if (base < OPT_LOG_MAX_VAL) {\n baseLog = optimalLog(base);\n } else {\n baseLog = generalLog(base);\n }\n\n uint256 baseLogTimesExp = baseLog * _expN / _expD;\n if (baseLogTimesExp < OPT_EXP_MAX_VAL) {\n return (optimalExp(baseLogTimesExp), MAX_PRECISION);\n } else {\n uint8 precision = findPositionInMaxExpArray(baseLogTimesExp);\n return (generalExp(baseLogTimesExp >> (MAX_PRECISION - precision), precision), precision);\n }\n }\n\n /**\n Compute log(x / FIXED_1) * FIXED_1.\n This functions assumes that \"x >= FIXED_1\", because the output would be negative otherwise.\n */\n function generalLog(uint256 _x) internal pure returns (uint256) {\n uint256 res = 0;\n uint256 x = _x;\n\n // If x >= 2, then we compute the integer part of log2(x), which is larger than 0.\n if (x >= FIXED_2) {\n uint8 count = floorLog2(x / FIXED_1);\n x >>= count; // now x < 2\n res = count * FIXED_1;\n }\n\n // If x > 1, then we compute the fraction part of log2(x), which is larger than 0.\n if (x > FIXED_1) {\n for (uint8 i = MAX_PRECISION; i > 0; --i) {\n x = (x * x) / FIXED_1; // now 1 < x < 4\n if (x >= FIXED_2) {\n x >>= 1; // now 1 < x < 2\n res += ONE << (i - 1);\n }\n }\n }\n\n return res * LN2_NUMERATOR / LN2_DENOMINATOR;\n }\n\n /**\n Compute the largest integer smaller than or equal to the binary logarithm of the input.\n */\n function floorLog2(uint256 _n) internal pure returns (uint8) {\n uint8 res = 0;\n uint256 n = _n;\n\n if (n < 256) {\n // At most 8 iterations\n while (n > 1) {\n n >>= 1;\n res += 1;\n }\n } else {\n // Exactly 8 iterations\n for (uint8 s = 128; s > 0; s >>= 1) {\n if (n >= (ONE << s)) {\n n >>= s;\n res |= s;\n }\n }\n }\n\n return res;\n }\n\n /**\n The global \"maxExpArray\" is sorted in descending order, and therefore the following statements are equivalent:\n - This function finds the position of [the smallest value in \"maxExpArray\" larger than or equal to \"x\"]\n - This function finds the highest position of [a value in \"maxExpArray\" larger than or equal to \"x\"]\n */\n function findPositionInMaxExpArray(uint256 _x)\n internal view returns (uint8)\n {\n uint8 lo = MIN_PRECISION;\n uint8 hi = MAX_PRECISION;\n\n while (lo + 1 < hi) {\n uint8 mid = (lo + hi) / 2;\n if (maxExpArray[mid] >= _x)\n lo = mid;\n else\n hi = mid;\n }\n\n if (maxExpArray[hi] >= _x)\n return hi;\n if (maxExpArray[lo] >= _x)\n return lo;\n\n assert(false);\n return 0;\n }\n\n /* solium-disable */\n /**\n This function can be auto-generated by the script 'PrintFunctionGeneralExp.py'.\n It approximates \"e ^ x\" via maclaurin summation: \"(x^0)/0! + (x^1)/1! + ... + (x^n)/n!\".\n It returns \"e ^ (x / 2 ^ precision) * 2 ^ precision\", that is, the result is upshifted for accuracy.\n The global \"maxExpArray\" maps each \"precision\" to \"((maximumExponent + 1) << (MAX_PRECISION - precision)) - 1\".\n The maximum permitted value for \"x\" is therefore given by \"maxExpArray[precision] >> (MAX_PRECISION - precision)\".\n */\n function generalExp(uint256 _x, uint8 _precision) internal pure returns (uint256) {\n uint256 xi = _x;\n uint256 res = 0;\n\n xi = (xi * _x) >> _precision; res += xi * 0x3442c4e6074a82f1797f72ac0000000; // add x^02 * (33! / 02!)\n xi = (xi * _x) >> _precision; res += xi * 0x116b96f757c380fb287fd0e40000000; // add x^03 * (33! / 03!)\n xi = (xi * _x) >> _precision; res += xi * 0x045ae5bdd5f0e03eca1ff4390000000; // add x^04 * (33! / 04!)\n xi = (xi * _x) >> _precision; res += xi * 0x00defabf91302cd95b9ffda50000000; // add x^05 * (33! / 05!)\n xi = (xi * _x) >> _precision; res += xi * 0x002529ca9832b22439efff9b8000000; // add x^06 * (33! / 06!)\n xi = (xi * _x) >> _precision; res += xi * 0x00054f1cf12bd04e516b6da88000000; // add x^07 * (33! / 07!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000a9e39e257a09ca2d6db51000000; // add x^08 * (33! / 08!)\n xi = (xi * _x) >> _precision; res += xi * 0x000012e066e7b839fa050c309000000; // add x^09 * (33! / 09!)\n xi = (xi * _x) >> _precision; res += xi * 0x000001e33d7d926c329a1ad1a800000; // add x^10 * (33! / 10!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000002bee513bdb4a6b19b5f800000; // add x^11 * (33! / 11!)\n xi = (xi * _x) >> _precision; res += xi * 0x00000003a9316fa79b88eccf2a00000; // add x^12 * (33! / 12!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000048177ebe1fa812375200000; // add x^13 * (33! / 13!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000005263fe90242dcbacf00000; // add x^14 * (33! / 14!)\n xi = (xi * _x) >> _precision; res += xi * 0x000000000057e22099c030d94100000; // add x^15 * (33! / 15!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000000057e22099c030d9410000; // add x^16 * (33! / 16!)\n xi = (xi * _x) >> _precision; res += xi * 0x00000000000052b6b54569976310000; // add x^17 * (33! / 17!)\n xi = (xi * _x) >> _precision; res += xi * 0x00000000000004985f67696bf748000; // add x^18 * (33! / 18!)\n xi = (xi * _x) >> _precision; res += xi * 0x000000000000003dea12ea99e498000; // add x^19 * (33! / 19!)\n xi = (xi * _x) >> _precision; res += xi * 0x00000000000000031880f2214b6e000; // add x^20 * (33! / 20!)\n xi = (xi * _x) >> _precision; res += xi * 0x000000000000000025bcff56eb36000; // add x^21 * (33! / 21!)\n xi = (xi * _x) >> _precision; res += xi * 0x000000000000000001b722e10ab1000; // add x^22 * (33! / 22!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000000000000001317c70077000; // add x^23 * (33! / 23!)\n xi = (xi * _x) >> _precision; res += xi * 0x00000000000000000000cba84aafa00; // add x^24 * (33! / 24!)\n xi = (xi * _x) >> _precision; res += xi * 0x00000000000000000000082573a0a00; // add x^25 * (33! / 25!)\n xi = (xi * _x) >> _precision; res += xi * 0x00000000000000000000005035ad900; // add x^26 * (33! / 26!)\n xi = (xi * _x) >> _precision; res += xi * 0x000000000000000000000002f881b00; // add x^27 * (33! / 27!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000000000000000000001b29340; // add x^28 * (33! / 28!)\n xi = (xi * _x) >> _precision; res += xi * 0x00000000000000000000000000efc40; // add x^29 * (33! / 29!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000000000000000000000007fe0; // add x^30 * (33! / 30!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000000000000000000000000420; // add x^31 * (33! / 31!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000000000000000000000000021; // add x^32 * (33! / 32!)\n xi = (xi * _x) >> _precision; res += xi * 0x0000000000000000000000000000001; // add x^33 * (33! / 33!)\n\n return res / 0x688589cc0e9505e2f2fee5580000000 + _x + (ONE << _precision); // divide by 33! and then add x^1 / 1! + x^0 / 0!\n }\n\n /**\n Return log(x / FIXED_1) * FIXED_1\n Input range: FIXED_1 <= x <= LOG_EXP_MAX_VAL - 1\n Auto-generated via 'PrintFunctionOptimalLog.py'\n */\n function optimalLog(uint256 x) internal pure returns (uint256) {\n uint256 res = 0;\n\n uint256 y;\n uint256 z;\n uint256 w;\n\n if (x >= 0xd3094c70f034de4b96ff7d5b6f99fcd8) {res += 0x40000000000000000000000000000000; x = x * FIXED_1 / 0xd3094c70f034de4b96ff7d5b6f99fcd8;}\n if (x >= 0xa45af1e1f40c333b3de1db4dd55f29a7) {res += 0x20000000000000000000000000000000; x = x * FIXED_1 / 0xa45af1e1f40c333b3de1db4dd55f29a7;}\n if (x >= 0x910b022db7ae67ce76b441c27035c6a1) {res += 0x10000000000000000000000000000000; x = x * FIXED_1 / 0x910b022db7ae67ce76b441c27035c6a1;}\n if (x >= 0x88415abbe9a76bead8d00cf112e4d4a8) {res += 0x08000000000000000000000000000000; x = x * FIXED_1 / 0x88415abbe9a76bead8d00cf112e4d4a8;}\n if (x >= 0x84102b00893f64c705e841d5d4064bd3) {res += 0x04000000000000000000000000000000; x = x * FIXED_1 / 0x84102b00893f64c705e841d5d4064bd3;}\n if (x >= 0x8204055aaef1c8bd5c3259f4822735a2) {res += 0x02000000000000000000000000000000; x = x * FIXED_1 / 0x8204055aaef1c8bd5c3259f4822735a2;}\n if (x >= 0x810100ab00222d861931c15e39b44e99) {res += 0x01000000000000000000000000000000; x = x * FIXED_1 / 0x810100ab00222d861931c15e39b44e99;}\n if (x >= 0x808040155aabbbe9451521693554f733) {res += 0x00800000000000000000000000000000; x = x * FIXED_1 / 0x808040155aabbbe9451521693554f733;}\n\n z = y = x - FIXED_1;\n w = y * y / FIXED_1;\n res += z * (0x100000000000000000000000000000000 - y) / 0x100000000000000000000000000000000; z = z * w / FIXED_1;\n res += z * (0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - y) / 0x200000000000000000000000000000000; z = z * w / FIXED_1;\n res += z * (0x099999999999999999999999999999999 - y) / 0x300000000000000000000000000000000; z = z * w / FIXED_1;\n res += z * (0x092492492492492492492492492492492 - y) / 0x400000000000000000000000000000000; z = z * w / FIXED_1;\n res += z * (0x08e38e38e38e38e38e38e38e38e38e38e - y) / 0x500000000000000000000000000000000; z = z * w / FIXED_1;\n res += z * (0x08ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b - y) / 0x600000000000000000000000000000000; z = z * w / FIXED_1;\n res += z * (0x089d89d89d89d89d89d89d89d89d89d89 - y) / 0x700000000000000000000000000000000; z = z * w / FIXED_1;\n res += z * (0x088888888888888888888888888888888 - y) / 0x800000000000000000000000000000000;\n\n return res;\n }\n\n /**\n Return e ^ (x / FIXED_1) * FIXED_1\n Input range: 0 <= x <= OPT_EXP_MAX_VAL - 1\n Auto-generated via 'PrintFunctionOptimalExp.py'\n */\n function optimalExp(uint256 x) internal pure returns (uint256) {\n uint256 res = 0;\n\n uint256 y;\n uint256 z;\n\n z = y = x % 0x10000000000000000000000000000000;\n z = z * y / FIXED_1; res += z * 0x10e1b3be415a0000; // add y^02 * (20! / 02!)\n z = z * y / FIXED_1; res += z * 0x05a0913f6b1e0000; // add y^03 * (20! / 03!)\n z = z * y / FIXED_1; res += z * 0x0168244fdac78000; // add y^04 * (20! / 04!)\n z = z * y / FIXED_1; res += z * 0x004807432bc18000; // add y^05 * (20! / 05!)\n z = z * y / FIXED_1; res += z * 0x000c0135dca04000; // add y^06 * (20! / 06!)\n z = z * y / FIXED_1; res += z * 0x0001b707b1cdc000; // add y^07 * (20! / 07!)\n z = z * y / FIXED_1; res += z * 0x000036e0f639b800; // add y^08 * (20! / 08!)\n z = z * y / FIXED_1; res += z * 0x00000618fee9f800; // add y^09 * (20! / 09!)\n z = z * y / FIXED_1; res += z * 0x0000009c197dcc00; // add y^10 * (20! / 10!)\n z = z * y / FIXED_1; res += z * 0x0000000e30dce400; // add y^11 * (20! / 11!)\n z = z * y / FIXED_1; res += z * 0x000000012ebd1300; // add y^12 * (20! / 12!)\n z = z * y / FIXED_1; res += z * 0x0000000017499f00; // add y^13 * (20! / 13!)\n z = z * y / FIXED_1; res += z * 0x0000000001a9d480; // add y^14 * (20! / 14!)\n z = z * y / FIXED_1; res += z * 0x00000000001c6380; // add y^15 * (20! / 15!)\n z = z * y / FIXED_1; res += z * 0x000000000001c638; // add y^16 * (20! / 16!)\n z = z * y / FIXED_1; res += z * 0x0000000000001ab8; // add y^17 * (20! / 17!)\n z = z * y / FIXED_1; res += z * 0x000000000000017c; // add y^18 * (20! / 18!)\n z = z * y / FIXED_1; res += z * 0x0000000000000014; // add y^19 * (20! / 19!)\n z = z * y / FIXED_1; res += z * 0x0000000000000001; // add y^20 * (20! / 20!)\n res = res / 0x21c3677c82b40000 + y + FIXED_1; // divide by 20! and then add y^1 / 1! + y^0 / 0!\n\n if ((x & 0x010000000000000000000000000000000) != 0) res = res * 0x1c3d6a24ed82218787d624d3e5eba95f9 / 0x18ebef9eac820ae8682b9793ac6d1e776;\n if ((x & 0x020000000000000000000000000000000) != 0) res = res * 0x18ebef9eac820ae8682b9793ac6d1e778 / 0x1368b2fc6f9609fe7aceb46aa619baed4;\n if ((x & 0x040000000000000000000000000000000) != 0) res = res * 0x1368b2fc6f9609fe7aceb46aa619baed5 / 0x0bc5ab1b16779be3575bd8f0520a9f21f;\n if ((x & 0x080000000000000000000000000000000) != 0) res = res * 0x0bc5ab1b16779be3575bd8f0520a9f21e / 0x0454aaa8efe072e7f6ddbab84b40a55c9;\n if ((x & 0x100000000000000000000000000000000) != 0) res = res * 0x0454aaa8efe072e7f6ddbab84b40a55c5 / 0x00960aadc109e7a3bf4578099615711ea;\n if ((x & 0x200000000000000000000000000000000) != 0) res = res * 0x00960aadc109e7a3bf4578099615711d7 / 0x0002bf84208204f5977f9a8cf01fdce3d;\n if ((x & 0x400000000000000000000000000000000) != 0) res = res * 0x0002bf84208204f5977f9a8cf01fdc307 / 0x0000003c6ab775dd0b95b4cbee7e65d11;\n\n return res;\n }\n /* solium-enable */\n}\n" }, "contracts/utils/ERC1404.sol": { "content": "// SPDX-License-Identifier: Apache License 2.0\n\npragma solidity 0.8.16;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\nabstract contract ERC1404 is ERC20 {\n /// @notice Detects if a transfer will be reverted and if so returns an appropriate reference code\n /// @param from Sending address\n /// @param to Receiving address\n /// @param value Amount of tokens being transferred\n /// @return Code by which to reference message for rejection reasoning\n /// @dev Overwrite with your custom transfer restriction logic\n function detectTransferRestriction (address from, address to, uint256 value) public virtual view returns (uint8);\n\n /// @notice Returns a human-readable message for a given restriction code\n /// @param restrictionCode Identifier for looking up a message\n /// @return Text showing the restriction's reasoning\n /// @dev Overwrite with your custom message and restrictionCode handling\n function messageForTransferRestriction (uint8 restrictionCode) public virtual view returns (string memory);\n}\n" }, "contracts/test/PhiMock.sol": { "content": "// SPDX-License-Identifier: Apache License 2.0\n\npragma solidity 0.8.16;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\n\ncontract PhiMock is ERC20 {\n constructor(\n string memory _tokenName,\n string memory _tokenSymbol\n )\n ERC20(\n _tokenName,\n _tokenSymbol\n )\n {}\n\n function mint(address account, uint256 value) public{\n _mint(account, value);\n }\n\n\n function burn(address account, uint256 value) public{\n _burn(account, value);\n }\n}\n" } }, "settings": { "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } }, "metadata": { "useLiteralContent": true } } }