[ Download CSV Export ]
Contract Name:
PositionManager
Compiler Version
v0.8.9+commit.e5eed63a
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20Upgradeable.sol"; import "./extensions/IERC20MetadataUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, _allowances[owner][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = _allowances[owner][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Spend `amount` form the allowance of `owner` toward `spender`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[45] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20MetadataUpgradeable is IERC20Upgradeable { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; import "./IERC721Upgradeable.sol"; import "./IERC721ReceiverUpgradeable.sol"; import "./extensions/IERC721MetadataUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../utils/StringsUpgradeable.sol"; import "../../utils/introspection/ERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable { using AddressUpgradeable for address; using StringsUpgradeable for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ function __ERC721_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC721_init_unchained(name_, symbol_); } function __ERC721_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) { return interfaceId == type(IERC721Upgradeable).interfaceId || interfaceId == type(IERC721MetadataUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721Upgradeable.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721Upgradeable.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); _afterTokenTransfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721Upgradeable.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721Upgradeable.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721ReceiverUpgradeable.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[44] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721ReceiverUpgradeable { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721Upgradeable.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721MetadataUpgradeable is IERC721Upgradeable { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender ; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; import "./interfaces/IBorrowerPools.sol"; import "./interfaces/IPoolsController.sol"; import "./interfaces/IPositionDescriptor.sol"; import "./interfaces/IPositionManager.sol"; import "./lib/Errors.sol"; import "./lib/Roles.sol"; import "./lib/Scaling.sol"; import "./lib/Types.sol"; contract PositionManager is ERC721Upgradeable, IPositionManager { using Scaling for uint128; IBorrowerPools public pools; IPositionDescriptor public positionDescriptor; // next position id uint128 private _nextId; mapping(uint128 => Types.PositionDetails) public _positions; function initialize( string memory _name, string memory _symbol, IBorrowerPools _pools, IPositionDescriptor _positionDescriptor ) public virtual initializer { __ERC721_init(_name, _symbol); pools = _pools; positionDescriptor = _positionDescriptor; _nextId = 1; } // VIEW METHODS /** * @notice Emitted when #withdraw is called and is a success * @param tokenId The tokenId of the position * @return poolHash The identifier of the pool * @return adjustedBalance Adjusted balance of the position original deposit * @return rate Position bidding rate * @return underlyingToken Address of the tokens the position contains * @return remainingBonds Quantity of bonds remaining in the position after a partial withdraw * @return bondsMaturity Maturity of the position's remaining bonds * @return bondsIssuanceIndex Borrow period the deposit was made in **/ function position(uint128 tokenId) public view override returns ( bytes32 poolHash, uint128 adjustedBalance, uint128 rate, address underlyingToken, uint128 remainingBonds, uint128 bondsMaturity, uint128 bondsIssuanceIndex ) { Types.PositionDetails memory _position = _positions[tokenId]; return ( _position.poolHash, _position.adjustedBalance, _position.rate, _position.underlyingToken, _position.remainingBonds, _position.bondsMaturity, _position.bondsIssuanceIndex ); } /** * @notice Returns the encoded svg data * @param tokenId The tokenId of the position * @return encoded svg **/ function tokenURI(uint256 tokenId) public view override returns (string memory) { if (!_exists(tokenId)) { revert Errors.POS_POSITION_DOES_NOT_EXIST(); } return IPositionDescriptor(positionDescriptor).tokenURI(this, uint128(tokenId)); } /** * @notice Returns the balance on yield provider and the quantity of bond held * @param tokenId The tokenId of the position * @return bondsQuantity Quantity of bond held, represents funds borrowed * @return normalizedDepositedAmount Amount of deposit placed on yield provider **/ function getPositionRepartition(uint128 tokenId) external view override returns (uint128 bondsQuantity, uint128 normalizedDepositedAmount) { if (!_exists(tokenId)) { return (0, 0); } uint256 poolCurrentMaturity = pools.getPoolMaturity(_positions[tokenId].poolHash); if ((_positions[tokenId].bondsMaturity > 0) && (_positions[tokenId].bondsMaturity == poolCurrentMaturity)) { return (_positions[tokenId].remainingBonds, 0); } return pools.getAmountRepartition( _positions[tokenId].poolHash, _positions[tokenId].rate, _positions[tokenId].adjustedBalance, _positions[tokenId].bondsIssuanceIndex ); } function revertIfPositionDefaulted(uint256 tokenId) private view { (, bool defaulted, , , , , , , , , , ) = IPoolsController(address(pools)).getPoolState( _positions[uint128(tokenId)].poolHash ); if (defaulted) { revert Errors.POS_POOL_DEFAULTED(); } } // ERC721 OVERRIDDEN TRANSFERS /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public override { revertIfPositionDefaulted(tokenId); super.transferFrom(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public override { revertIfPositionDefaulted(tokenId); super.safeTransferFrom(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public override { revertIfPositionDefaulted(tokenId); super.safeTransferFrom(from, to, tokenId, _data); } // LENDER METHODS /** * @notice Deposits tokens into the yield provider and places a bid at the indicated rate within the * respective pool's order book. A new position is created within the positions map that keeps * track of this position's composition. An ERC721 NFT is minted for the user as a representation * of the position. * @param to The address for which the position is created * @param amount The amount of tokens to be deposited * @param rate The rate at which to bid for a bonds * @param poolHash The identifier of the pool * @param underlyingToken The contract address of the token to be deposited **/ function deposit( address to, uint128 amount, uint128 rate, bytes32 poolHash, address underlyingToken ) external override returns (uint128 tokenId) { if (amount == 0) { revert Errors.POS_ZERO_AMOUNT(); } tokenId = _nextId++; _safeMint(to, tokenId); uint8 decimals = ERC20Upgradeable(underlyingToken).decimals(); uint128 normalizedAmount = amount.scaleToWad(decimals); (uint128 adjustedBalance, uint128 bondsIssuanceIndex) = pools.deposit( rate, poolHash, underlyingToken, _msgSender(), normalizedAmount ); _positions[tokenId] = Types.PositionDetails({ adjustedBalance: adjustedBalance, rate: rate, poolHash: poolHash, underlyingToken: underlyingToken, remainingBonds: 0, bondsMaturity: 0, bondsIssuanceIndex: bondsIssuanceIndex, creationTimestamp: uint128(block.timestamp) }); emit Deposit(to, tokenId, normalizedAmount, rate, poolHash, bondsIssuanceIndex); } /** * @notice Allows a user to update the rate at which to bid for bonds. A rate is only * upgradable as long as the full amount of deposits are currently allocated with the * yield provider i.e the position does not hold any bonds. * @param tokenId The tokenId of the position * @param newRate The new rate at which to bid for bonds **/ function updateRate(uint128 tokenId, uint128 newRate) external override { if (ownerOf(tokenId) != _msgSender()) { revert Errors.POS_MGMT_ONLY_OWNER(); } if (_positions[tokenId].creationTimestamp == block.timestamp) { revert Errors.POS_TIMELOCK(); } uint128 oldRate = _positions[tokenId].rate; (uint128 newAmount, uint128 newBondsIssuanceIndex, uint128 normalizedAmount) = pools.updateRate( _positions[tokenId].adjustedBalance, _positions[tokenId].poolHash, oldRate, newRate, _positions[tokenId].bondsIssuanceIndex ); _positions[tokenId].adjustedBalance = newAmount; _positions[tokenId].rate = newRate; _positions[tokenId].bondsIssuanceIndex = newBondsIssuanceIndex; emit UpdateRate(_msgSender(), tokenId, normalizedAmount, newRate, _positions[tokenId].poolHash); } /** * @notice Withdraws the amount of tokens that are deposited with the yield provider. * The bonds portion of the position is not affected. * @param tokenId The tokenId of the position **/ function withdraw(uint128 tokenId) external override { if (ownerOf(tokenId) != _msgSender()) { revert Errors.POS_MGMT_ONLY_OWNER(); } if (_positions[tokenId].creationTimestamp == block.timestamp) { revert Errors.POS_TIMELOCK(); } uint256 poolCurrentMaturity = pools.getPoolMaturity(_positions[tokenId].poolHash); if ( !((_positions[tokenId].remainingBonds == 0) || ((block.timestamp >= _positions[tokenId].bondsMaturity) && (_positions[tokenId].bondsMaturity != poolCurrentMaturity))) ) { revert Errors.POS_POSITION_ONLY_IN_BONDS(); } ( uint128 adjustedAmountToWithdraw, uint128 depositedAmountToWithdraw, uint128 remainingBondsQuantity, uint128 bondsMaturity ) = pools.getWithdrawAmounts( _positions[tokenId].poolHash, _positions[tokenId].rate, _positions[tokenId].adjustedBalance, _positions[tokenId].bondsIssuanceIndex ); _positions[tokenId].adjustedBalance -= depositedAmountToWithdraw; _positions[tokenId].remainingBonds = remainingBondsQuantity; _positions[tokenId].bondsMaturity = bondsMaturity; uint128 normalizedWithdrawnDeposit = pools.withdraw( _positions[tokenId].poolHash, _positions[tokenId].rate, adjustedAmountToWithdraw, _positions[tokenId].bondsIssuanceIndex, _msgSender() ); emit Withdraw( _msgSender(), tokenId, normalizedWithdrawnDeposit, remainingBondsQuantity, _positions[tokenId].rate, _positions[tokenId].poolHash ); if (_positions[tokenId].remainingBonds == 0) { _burn(tokenId); delete _positions[tokenId]; } } // GOVERNANCE METHOD function setPositionDescriptor(address _positionDescriptor) external override { if (!AccessControlUpgradeable(address(pools)).hasRole(Roles.GOVERNANCE_ROLE, _msgSender())) { revert Errors.POS_NOT_ALLOWED(); } if (_positionDescriptor == address(0)) { revert Errors.POS_ZERO_ADDRESS(); } positionDescriptor = IPositionDescriptor(_positionDescriptor); emit SetPositionDescriptor(_positionDescriptor); } }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; interface ILendingPool { /** * @dev Emitted on deposit() * @param reserve The address of the underlying asset of the reserve * @param user The address initiating the deposit * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens * @param amount The amount deposited * @param referral The referral code used **/ event Deposit( address indexed reserve, address user, address indexed onBehalfOf, uint256 amount, uint16 indexed referral ); /** * @dev Emitted on withdraw() * @param reserve The address of the underlyng asset being withdrawn * @param user The address initiating the withdrawal, owner of aTokens * @param to Address that will receive the underlying * @param amount The amount to be withdrawn **/ event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount); /** * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens. * - E.g. User deposits 100 USDC and gets in return 100 aUSDC * @param asset The address of the underlying asset to deposit * @param amount The amount to be deposited * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens * is a different wallet * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man **/ function deposit( address asset, uint256 amount, address onBehalfOf, uint16 referralCode ) external; /** * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC * @param asset The address of the underlying asset to withdraw * @param amount The underlying amount to be withdrawn * - Send the value type(uint256).max in order to withdraw the whole aToken balance * @param to Address that will receive the underlying, same as msg.sender if the user * wants to receive it on his own wallet, or a different address if the beneficiary is a * different wallet * @return The final amount withdrawn **/ function withdraw( address asset, uint256 amount, address to ) external returns (uint256); /** * @dev Returns the normalized income normalized income of the reserve * @param asset The address of the underlying asset of the reserve * @return The reserve's normalized income */ function getReserveNormalizedIncome(address asset) external view returns (uint256); }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import "../extensions/AaveILendingPool.sol"; import "../lib/Types.sol"; /** * @title IBorrowerPools * @notice Used by the Position contract to pool lender positions in the borrowers order books * Used by the borrowers to manage their loans on their pools **/ interface IBorrowerPools { // EVENTS /** * @notice Emitted after a successful borrow * @param poolHash The identifier of the pool * @param normalizedBorrowedAmount The actual amount of tokens borrowed * @param establishmentFees Fees paid to the protocol at borrow time **/ event Borrow(bytes32 indexed poolHash, uint128 normalizedBorrowedAmount, uint128 establishmentFees); /** * @notice Emitted after a successful further borrow * @param poolHash The identifier of the pool * @param normalizedBorrowedAmount The actual amount of tokens borrowed * @param establishmentFees Fees paid to the protocol at borrow time **/ event FurtherBorrow(bytes32 indexed poolHash, uint128 normalizedBorrowedAmount, uint128 establishmentFees); /** * @notice Emitted after a successful repay * @param poolHash The identifier of the pool * @param normalizedRepayAmount The actual amount of tokens repaid * @param repaymentFee The amount of fee paid to the protocol at repay time * @param normalizedDepositsAfterRepay The actual amount of tokens deposited and available for next loan after repay * @param nextLoanMinStart The timestamp after which a new loan can be taken **/ event Repay( bytes32 indexed poolHash, uint128 normalizedRepayAmount, uint128 repaymentFee, uint128 normalizedDepositsAfterRepay, uint128 nextLoanMinStart ); /** * @notice Emitted after a successful early repay * @param poolHash The identifier of the pool * @param normalizedRepayAmount The actual amount of tokens repaid * @param repaymentFee The amount of fee paid to the protocol at repay time * @param normalizedDepositsAfterRepay The actual amount of tokens deposited and available for next loan after repay * @param nextLoanMinStart The timestamp after which a new loan can be taken **/ event EarlyRepay( bytes32 indexed poolHash, uint128 normalizedRepayAmount, uint128 repaymentFee, uint128 normalizedDepositsAfterRepay, uint128 nextLoanMinStart ); /** * @notice Emitted after a successful repay, made after the repayment period * Includes a late repay fee * @param poolHash The identifier of the pool * @param normalizedRepayAmount The actual amount of tokens repaid * @param lateRepayFee The amount of fee paid due to a late repayment * @param repaymentFee The amount of fee paid to the protocol at repay time * @param normalizedDepositsAfterRepay The actual amount of tokens deposited and available for next loan after repay * @param nextLoanMinStart The timestamp after which a new loan can be taken **/ event LateRepay( bytes32 indexed poolHash, uint128 normalizedRepayAmount, uint128 lateRepayFee, uint128 repaymentFee, uint128 normalizedDepositsAfterRepay, uint128 nextLoanMinStart ); /** * @notice Emitted after a borrower successfully deposits tokens in its pool liquidity rewards reserve * @param poolHash The identifier of the pool * @param normalizedAmount The actual amount of tokens deposited into the reserve **/ event TopUpLiquidityRewards(bytes32 poolHash, uint128 normalizedAmount); // The below events and enums are being used in the PoolLogic library // The same way that libraries don't have storage, they don't have an event log // Hence event logs will be saved in the calling contract // For the contract abi to reflect this and be used by offchain libraries, // we define these events and enums in the contract itself as well /** * @notice Emitted when a tick is initialized, i.e. when its first deposited in * @param poolHash The identifier of the pool * @param rate The tick's bidding rate * @param atlendisLiquidityRatio The tick current liquidity index **/ event TickInitialized(bytes32 poolHash, uint128 rate, uint128 atlendisLiquidityRatio); /** * @notice Emitted after a deposit on a tick that was done during a loan * @param poolHash The identifier of the pool * @param rate The position bidding rate * @param adjustedPendingDeposit The amount of tokens deposited during a loan, adjusted to the current liquidity index **/ event TickLoanDeposit(bytes32 poolHash, uint128 rate, uint128 adjustedPendingDeposit); /** * @notice Emitted after a deposit on a tick that was done without an active loan * @param poolHash The identifier of the pool * @param rate The position bidding rate * @param adjustedAvailableDeposit The amount of tokens available to the borrower for its next loan * @param atlendisLiquidityRatio The tick current liquidity index **/ event TickNoLoanDeposit( bytes32 poolHash, uint128 rate, uint128 adjustedAvailableDeposit, uint128 atlendisLiquidityRatio ); /** * @notice Emitted when a borrow successfully impacts a tick * @param poolHash The identifier of the pool * @param rate The tick's bidding rate * @param adjustedRemainingAmountReduction The amount of tokens left to borrow from other ticks * @param loanedAmount The amount borrowed from the tick * @param atlendisLiquidityRatio The tick current liquidity index * @param unborrowedRatio Proportion of ticks funds that were not borrowed **/ event TickBorrow( bytes32 poolHash, uint128 rate, uint128 adjustedRemainingAmountReduction, uint128 loanedAmount, uint128 atlendisLiquidityRatio, uint128 unborrowedRatio ); /** * @notice Emitted when a withdraw is done outside of a loan on the tick * @param poolHash The identifier of the pool * @param rate The tick's bidding rate * @param adjustedAmountToWithdraw The amount of tokens to withdraw, adjusted to the tick liquidity index **/ event TickWithdrawPending(bytes32 poolHash, uint128 rate, uint128 adjustedAmountToWithdraw); /** * @notice Emitted when a withdraw is done during a loan on the tick * @param poolHash The identifier of the pool * @param rate The tick's bidding rate * @param adjustedAmountToWithdraw The amount of tokens to withdraw, adjusted to the tick liquidity index * @param atlendisLiquidityRatio The tick current liquidity index * @param accruedFeesToWithdraw The amount of fees the position has a right to claim **/ event TickWithdrawRemaining( bytes32 poolHash, uint128 rate, uint128 adjustedAmountToWithdraw, uint128 atlendisLiquidityRatio, uint128 accruedFeesToWithdraw ); /** * @notice Emitted when pending amounts are merged with the rest of the pool during a repay * @param poolHash The identifier of the pool * @param rate The tick's bidding rate * @param adjustedPendingAmount The amount of pending funds deposited with available funds **/ event TickPendingDeposit( bytes32 poolHash, uint128 rate, uint128 adjustedPendingAmount, bool poolBondIssuanceIndexIncremented ); /** * @notice Emitted when funds from a tick are repaid by the borrower * @param poolHash The identifier of the pool * @param rate The tick's bidding rate * @param adjustedRemainingAmount The total amount of tokens available to the borrower for * its next loan, adjusted to the tick current liquidity index * @param atlendisLiquidityRatio The tick current liquidity index **/ event TickRepay(bytes32 poolHash, uint128 rate, uint128 adjustedRemainingAmount, uint128 atlendisLiquidityRatio); /** * @notice Emitted when liquidity rewards are distributed to a tick * @param poolHash The identifier of the pool * @param rate The tick's bidding rate * @param remainingLiquidityRewards the amount of liquidityRewards added to the tick * @param addedAccruedFees Increase in accrued fees for that tick **/ event CollectFeesForTick(bytes32 poolHash, uint128 rate, uint128 remainingLiquidityRewards, uint128 addedAccruedFees); // VIEW METHODS /** * @notice Returns the liquidity ratio of a given tick in a pool's order book. * The liquidity ratio is an accounting construct to deduce the accrued interest over time. * @param poolHash The identifier of the pool * @param rate The tick rate from which to extract the liquidity ratio * @return liquidityRatio The liquidity ratio of the given tick **/ function getTickLiquidityRatio(bytes32 poolHash, uint128 rate) external view returns (uint128 liquidityRatio); /** * @notice Returns the repartition between bonds and deposits of the given tick. * @param poolHash The identifier of the pool * @param rate The tick rate from which to get data * @return adjustedTotalAmount Total amount of deposit in the tick * @return adjustedRemainingAmount Amount of tokens in tick deposited with the * underlying yield provider that were deposited before bond issuance * @return bondsQuantity The quantity of bonds within the tick * @return adjustedPendingAmount Amount of deposit in tick deposited with the * underlying yield provider that were deposited after bond issuance * @return atlendisLiquidityRatio The liquidity ratio of the given tick * @return accruedFees The total fees claimable in the current tick, either from * yield provider interests or liquidity rewards accrual **/ function getTickAmounts(bytes32 poolHash, uint128 rate) external view returns ( uint128 adjustedTotalAmount, uint128 adjustedRemainingAmount, uint128 bondsQuantity, uint128 adjustedPendingAmount, uint128 atlendisLiquidityRatio, uint128 accruedFees ); /** * @notice Returns the timestamp of the last fee distribution to the tick * @param poolHash The identifier of the pool * @param rate The tick rate from which to get data * @return lastFeeDistributionTimestamp Timestamp of the last fee's distribution to the tick **/ function getTickLastUpdate(string calldata poolHash, uint128 rate) external view returns (uint128 lastFeeDistributionTimestamp); /** * @notice Returns the current state of the pool's parameters * @param poolHash The identifier of the pool * @return weightedAverageLendingRate The average deposit bidding rate in the order book * @return adjustedPendingDeposits Amount of tokens deposited after bond * issuance and currently on third party yield provider **/ function getPoolAggregates(bytes32 poolHash) external view returns (uint128 weightedAverageLendingRate, uint128 adjustedPendingDeposits); /** * @notice Returns the current maturity of the pool * @param poolHash The identifier of the pool * @return poolCurrentMaturity The pool's current maturity **/ function getPoolMaturity(bytes32 poolHash) external view returns (uint128 poolCurrentMaturity); /** * @notice Estimates the lending rate corresponding to the input amount, * depending on the current state of the pool * @param normalizedBorrowedAmount The amount to be borrowed from the pool * @param poolHash The identifier of the pool * @return estimatedRate The estimated loan rate for the current state of the pool **/ function estimateLoanRate(uint128 normalizedBorrowedAmount, bytes32 poolHash) external view returns (uint128 estimatedRate); /** * @notice Returns the token amount's repartition between bond quantity and normalized * deposited amount currently placed on third party yield provider * @param poolHash The identifier of the pool * @param rate Tick's rate * @param adjustedAmount Adjusted amount of tokens currently on third party yield provider * @param bondsIssuanceIndex The identifier of the borrow group * @return bondsQuantity Quantity of bonds held * @return normalizedDepositedAmount Amount of deposit currently on third party yield provider **/ function getAmountRepartition( bytes32 poolHash, uint128 rate, uint128 adjustedAmount, uint128 bondsIssuanceIndex ) external view returns (uint128 bondsQuantity, uint128 normalizedDepositedAmount); /** * @notice Returns the total amount a borrower has to repay to a pool. Includes borrowed * amount, late repay fees and protocol fees * @param poolHash The identifier of the pool * @param earlyRepay indicates if this is an early repay * @return normalizedRepayAmount Total repay amount * @return lateRepayFee Normalized amount to be paid to each bond in case of late repayment * @return repaymentFee Normalized fee amount paid to the protocol **/ function getRepayAmounts(bytes32 poolHash, bool earlyRepay) external view returns ( uint128 normalizedRepayAmount, uint128 lateRepayFee, uint128 repaymentFee ); // LENDER METHODS /** * @notice Gets called within the Position.deposit() function and enables a lender to deposit assets * into a given borrower's order book. The lender specifies a rate (price) at which it is willing to * lend out its assets (bid on the zero coupon bond). The full amount will initially be deposited * on the underlying yield provider until the borrower sells bonds at the specified rate. * @param normalizedAmount The amount of the given asset to deposit * @param rate The rate at which to bid for a bond * @param poolHash The identifier of the pool * @param underlyingToken Contract' address of the token to be deposited * @param sender The lender address who calls the deposit function on the Position * @return adjustedAmount Deposited amount adjusted with current liquidity index * @return bondsIssuanceIndex The identifier of the borrow group to which the deposit has been allocated **/ function deposit( uint128 rate, bytes32 poolHash, address underlyingToken, address sender, uint128 normalizedAmount ) external returns (uint128 adjustedAmount, uint128 bondsIssuanceIndex); /** * @notice Gets called within the Position.withdraw() function and enables a lender to * evaluate the exact amount of tokens it is allowed to withdraw * @dev This method is meant to be used exclusively with the withdraw() method * Under certain circumstances, this method can return incorrect values, that would otherwise * be rejected by the checks made in the withdraw() method * @param poolHash The identifier of the pool * @param rate The rate the position is bidding for * @param adjustedAmount The amount of tokens in the position, adjusted to the deposit liquidity ratio * @param bondsIssuanceIndex An index determining deposit timing * @return adjustedAmountToWithdraw The amount of tokens to withdraw, adjuste for borrow pool use * @return depositedAmountToWithdraw The amount of tokens to withdraw, adjuste for position use * @return remainingBondsQuantity The quantity of bonds remaining within the position * @return bondsMaturity The maturity of bonds remaining within the position after withdraw **/ function getWithdrawAmounts( bytes32 poolHash, uint128 rate, uint128 adjustedAmount, uint128 bondsIssuanceIndex ) external view returns ( uint128 adjustedAmountToWithdraw, uint128 depositedAmountToWithdraw, uint128 remainingBondsQuantity, uint128 bondsMaturity ); /** * @notice Gets called within the Position.withdraw() function and enables a lender to * withdraw assets that are deposited with the underlying yield provider * @param poolHash The identifier of the pool * @param rate The rate the position is bidding for * @param adjustedAmountToWithdraw The actual amount of tokens to withdraw from the position * @param bondsIssuanceIndex An index determining deposit timing * @param owner The address to which the withdrawns funds are sent * @return normalizedDepositedAmountToWithdraw Actual amount of tokens withdrawn and sent to the lender **/ function withdraw( bytes32 poolHash, uint128 rate, uint128 adjustedAmountToWithdraw, uint128 bondsIssuanceIndex, address owner ) external returns (uint128 normalizedDepositedAmountToWithdraw); /** * @notice Gets called within Position.updateRate() and updates the order book ticks affected by the position * updating its rate. This is only possible as long as there are no bonds in the position, i.e the full * position currently lies with the yield provider * @param adjustedAmount The adjusted balance of tokens of the given position * @param poolHash The identifier of the pool * @param oldRate The current rate of the position * @param newRate The new rate of the position * @param oldBondsIssuanceIndex The identifier of the borrow group from the given position * @return newAdjustedAmount The updated amount of tokens of the position adjusted by the * new tick's global liquidity ratio * @return newBondsIssuanceIndex The new borrow group id to which the updated position is linked **/ function updateRate( uint128 adjustedAmount, bytes32 poolHash, uint128 oldRate, uint128 newRate, uint128 oldBondsIssuanceIndex ) external returns ( uint128 newAdjustedAmount, uint128 newBondsIssuanceIndex, uint128 normalizedAmount ); // BORROWER METHODS /** * @notice Called by the borrower to sell bonds to the order book. * The affected ticks get updated according the amount of bonds sold. * @param to The address to which the borrowed funds should be sent. * @param loanAmount The total amount of the loan **/ function borrow(address to, uint128 loanAmount) external; /** * @notice Repays a currently outstanding bonds of the given borrower. **/ function repay() external; /** * @notice Called by the borrower to top up liquidity rewards' reserve that * is distributed to liquidity providers at the pre-defined distribution rate. * @param normalizedAmount Amount of tokens that will be add up to the borrower's liquidity rewards reserve **/ function topUpLiquidityRewards(uint128 normalizedAmount) external; // FEE COLLECTION /** * @notice Collect yield provider fees as well as liquidity rewards for the target tick * @param poolHash The identifier of the pool **/ function collectFeesForTick(bytes32 poolHash, uint128 rate) external; /** * @notice Collect yield provider fees as well as liquidity rewards for the whole pool * Iterates over all pool initialized ticks * @param poolHash The identifier of the pool **/ function collectFees(bytes32 poolHash) external; }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import "../lib/Types.sol"; /** * @title IPoolsController * @notice Management of the pools **/ interface IPoolsController { // EVENTS /** * @notice Emitted after a pool was creted **/ event PoolCreated(PoolCreationParams params); /** * @notice Emitted after a borrower address was allowed to borrow from a pool * @param borrowerAddress The address to allow * @param poolHash The identifier of the pool **/ event BorrowerAllowed(address borrowerAddress, bytes32 poolHash); /** * @notice Emitted after a borrower address was disallowed to borrow from a pool * @param borrowerAddress The address to disallow * @param poolHash The identifier of the pool **/ event BorrowerDisallowed(address borrowerAddress, bytes32 poolHash); /** * @notice Emitted when a pool is active, i.e. after the borrower deposits enough tokens * in its pool liquidity rewards reserve as agreed before the pool creation * @param poolHash The identifier of the pool **/ event PoolActivated(bytes32 poolHash); /** * @notice Emitted after pool is closed * @param poolHash The identifier of the pool * @param collectedLiquidityRewards The amount of liquidity rewards to have been collected at closing time **/ event PoolClosed(bytes32 poolHash, uint128 collectedLiquidityRewards); /** * @notice Emitted when a pool defaults on its loan repayment * @param poolHash The identifier of the pool * @param distributedLiquidityRewards The remaining liquidity rewards distributed to * bond holders **/ event Default(bytes32 poolHash, uint128 distributedLiquidityRewards); /** * @notice Emitted after governance sets the maximum borrowable amount for a pool **/ event SetMaxBorrowableAmount(uint128 maxTokenDeposit, bytes32 poolHash); /** * @notice Emitted after governance sets the liquidity rewards distribution rate for a pool **/ event SetLiquidityRewardsDistributionRate(uint128 distributionRate, bytes32 poolHash); /** * @notice Emitted after governance sets the establishment fee for a pool **/ event SetEstablishmentFeeRate(uint128 establishmentRate, bytes32 poolHash); /** * @notice Emitted after governance sets the repayment fee for a pool **/ event SetRepaymentFeeRate(uint128 repaymentFeeRate, bytes32 poolHash); /** * @notice Emitted after governance claims the fees associated with a pool * @param poolHash The identifier of the pool * @param normalizedAmount The amount of tokens claimed * @param to The address receiving the fees **/ event ClaimProtocolFees(bytes32 poolHash, uint128 normalizedAmount, address to); // VIEW METHODS /** * @notice Returns the parameters of a pool * @param poolHash The identifier of the pool * @return underlyingToken Address of the underlying token of the pool * @return minRate Minimum rate of deposits accepted in the pool * @return maxRate Maximum rate of deposits accepted in the pool * @return rateSpacing Difference between two rates in the pool * @return maxBorrowableAmount Maximum amount of tokens that can be borrowed from the pool * @return loanDuration Duration of a loan in the pool * @return liquidityRewardsDistributionRate Rate at which liquidity rewards are distributed to lenders * @return cooldownPeriod Period after a loan during which a borrower cannot take another loan * @return repaymentPeriod Period after a loan end during which a borrower can repay without penalty * @return lateRepayFeePerBondRate Penalty a borrower has to pay when it repays late * @return liquidityRewardsActivationThreshold Minimum amount of liqudity rewards a borrower has to * deposit to active the pool **/ function getPoolParameters(bytes32 poolHash) external view returns ( address underlyingToken, uint128 minRate, uint128 maxRate, uint128 rateSpacing, uint128 maxBorrowableAmount, uint128 loanDuration, uint128 liquidityRewardsDistributionRate, uint128 cooldownPeriod, uint128 repaymentPeriod, uint128 lateRepayFeePerBondRate, uint128 liquidityRewardsActivationThreshold ); /** * @notice Returns the fee rates of a pool * @return establishmentFeeRate Amount of fees paid to the protocol at borrow time * @return repaymentFeeRate Amount of fees paid to the protocol at repay time **/ function getPoolFeeRates(bytes32 poolHash) external view returns (uint128 establishmentFeeRate, uint128 repaymentFeeRate); /** * @notice Returns the state of a pool * @param poolHash The identifier of the pool * @return active Signals if a pool is active and ready to accept deposits * @return defaulted Signals if a pool was defaulted * @return closed Signals if a pool was closed * @return currentMaturity End timestamp of current loan * @return bondsIssuedQuantity Amount of bonds issued, to be repaid at maturity * @return normalizedBorrowedAmount Actual amount of tokens that were borrowed * @return normalizedAvailableDeposits Actual amount of tokens available to be borrowed * @return lowerInterestRate Minimum rate at which a deposit was made * @return nextLoanMinStart Cool down period, minimum timestamp after which a new loan can be taken * @return remainingAdjustedLiquidityRewardsReserve Remaining liquidity rewards to be distributed to lenders * @return yieldProviderLiquidityRatio Last recorded yield provider liquidity ratio * @return currentBondsIssuanceIndex Current borrow period identifier of the pool **/ function getPoolState(bytes32 poolHash) external view returns ( bool active, bool defaulted, bool closed, uint128 currentMaturity, uint128 bondsIssuedQuantity, uint128 normalizedBorrowedAmount, uint128 normalizedAvailableDeposits, uint128 lowerInterestRate, uint128 nextLoanMinStart, uint128 remainingAdjustedLiquidityRewardsReserve, uint128 yieldProviderLiquidityRatio, uint128 currentBondsIssuanceIndex ); /** * @notice Signals whether the early repay feature is activated or not * @return earlyRepay Flag that signifies whether the early repay feature is activated or not **/ function isEarlyRepay(bytes32 poolHash) external view returns (bool earlyRepay); /** * @notice Returns the state of a pool * @return defaultTimestamp The timestamp at which the pool was defaulted **/ function getDefaultTimestamp(bytes32 poolHash) external view returns (uint128 defaultTimestamp); // GOVERNANCE METHODS /** * @notice Parameters used for a pool creation * @param poolHash The identifier of the pool * @param underlyingToken Address of the pool underlying token * @param yieldProvider Yield provider of the pool * @param minRate Minimum bidding rate for the pool * @param maxRate Maximum bidding rate for the pool * @param rateSpacing Difference between two tick rates in the pool * @param maxBorrowableAmount Maximum amount of tokens a borrower can get from a pool * @param loanDuration Duration of a loan i.e. maturity of the issued bonds * @param distributionRate Rate at which the liquidity rewards are distributed to unmatched positions * @param cooldownPeriod Period of time after a repay during which the borrow cannot take a loan * @param repaymentPeriod Period after the end of a loan during which the borrower can repay without penalty * @param lateRepayFeePerBondRate Additional fees applied when a borrower repays its loan after the repayment period ends * @param establishmentFeeRate Fees paid to Atlendis at borrow time * @param repaymentFeeRate Fees paid to Atlendis at repay time * @param liquidityRewardsActivationThreshold Amount of tokens the borrower has to lock into the liquidity * @param earlyRepay Is early repay activated * rewards reserve to activate the pool **/ struct PoolCreationParams { bytes32 poolHash; address underlyingToken; ILendingPool yieldProvider; uint128 minRate; uint128 maxRate; uint128 rateSpacing; uint128 maxBorrowableAmount; uint128 loanDuration; uint128 distributionRate; uint128 cooldownPeriod; uint128 repaymentPeriod; uint128 lateRepayFeePerBondRate; uint128 establishmentFeeRate; uint128 repaymentFeeRate; uint128 liquidityRewardsActivationThreshold; bool earlyRepay; } /** * @notice Creates a new pool * @param params A struct defining the pool creation parameters **/ function createNewPool(PoolCreationParams calldata params) external; /** * @notice Allow an address to interact with a borrower pool * @param borrowerAddress The address to allow * @param poolHash The identifier of the pool **/ function allow(address borrowerAddress, bytes32 poolHash) external; /** * @notice Remove pool interaction rights from an address * @param borrowerAddress The address to disallow * @param poolHash The identifier of the borrower pool **/ function disallow(address borrowerAddress, bytes32 poolHash) external; /** * @notice Flags the pool as closed * @param poolHash The identifier of the pool to be closed * @param to An address to which the remaining liquidity rewards will be sent **/ function closePool(bytes32 poolHash, address to) external; /** * @notice Flags the pool as defaulted * @param poolHash The identifier of the pool to default **/ function setDefault(bytes32 poolHash) external; /** * @notice Set the maximum amount of tokens that can be borrowed in the target pool **/ function setMaxBorrowableAmount(uint128 maxTokenDeposit, bytes32 poolHash) external; /** * @notice Set the pool liquidity rewards distribution rate **/ function setLiquidityRewardsDistributionRate(uint128 distributionRate, bytes32 poolHash) external; /** * @notice Set the pool establishment protocol fee rate **/ function setEstablishmentFeeRate(uint128 establishmentFeeRate, bytes32 poolHash) external; /** * @notice Set the pool repayment protocol fee rate **/ function setRepaymentFeeRate(uint128 repaymentFeeRate, bytes32 poolHash) external; /** * @notice Withdraws protocol fees to a target address * @param poolHash The identifier of the pool * @param normalizedAmount The amount of tokens claimed * @param to The address receiving the fees **/ function claimProtocolFees( bytes32 poolHash, uint128 normalizedAmount, address to ) external; /** * @notice Stops all actions on all pools **/ function freezePool() external; /** * @notice Cancel a freeze, makes actions available again on all pools **/ function unfreezePool() external; }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import "./IPositionManager.sol"; /** * @title IPositionDescriptor * @notice Generates the SVG artwork for lenders positions **/ interface IPositionDescriptor { /** * @notice Emitted after the string identifier of a pool has been set * @param poolIdentifier The string identifier of the pool * @param poolHash The hash identifier of the pool **/ event SetPoolIdentifier(string poolIdentifier, bytes32 poolHash); /** * @notice Get the pool identifier corresponding to the input pool hash * @param poolHash The identifier of the pool **/ function getPoolIdentifier(bytes32 poolHash) external view returns (string memory); /** * @notice Set the pool string identifier corresponding to the input pool hash * @param poolIdentifier The string identifier to associate with the corresponding pool hash * @param poolHash The identifier of the pool **/ function setPoolIdentifier(string calldata poolIdentifier, bytes32 poolHash) external; /** * @notice Returns the encoded svg for positions artwork * @param position The address of the position manager contract * @param tokenId The tokenId of the position **/ function tokenURI(IPositionManager position, uint128 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import "./IBorrowerPools.sol"; /** * @title IPositionManager * @notice Contains methods that can be called by lenders to create and manage their position **/ interface IPositionManager { /** * @notice Emitted when #deposit is called and is a success * @param lender The address of the lender depositing token on the protocol * @param tokenId The tokenId of the position * @param amount The amount of deposited token * @param rate The position bidding rate * @param poolHash The identifier of the pool * @param bondsIssuanceIndex The borrow period assigned to the position **/ event Deposit( address indexed lender, uint128 tokenId, uint128 amount, uint128 rate, bytes32 poolHash, uint128 bondsIssuanceIndex ); /** * @notice Emitted when #updateRate is called and is a success * @param lender The address of the lender updating their position * @param tokenId The tokenId of the position * @param amount The amount of deposited token plus their accrued interests * @param rate The new rate required by lender to lend their deposited token * @param poolHash The identifier of the pool **/ event UpdateRate(address indexed lender, uint128 tokenId, uint128 amount, uint128 rate, bytes32 poolHash); /** * @notice Emitted when #withdraw is called and is a success * @param lender The address of the withdrawing lender * @param tokenId The tokenId of the position * @param amount The amount of tokens withdrawn * @param rate The position bidding rate * @param poolHash The identifier of the pool **/ event Withdraw( address indexed lender, uint128 tokenId, uint128 amount, uint128 remainingBonds, uint128 rate, bytes32 poolHash ); /** * @notice Set the position descriptor address * @param positionDescriptor The address of the new position descriptor **/ event SetPositionDescriptor(address positionDescriptor); /** * @notice Emitted when #withdraw is called and is a success * @param tokenId The tokenId of the position * @return poolHash The identifier of the pool * @return adjustedBalance Adjusted balance of the position original deposit * @return rate Position bidding rate * @return underlyingToken Address of the tokens the position contains * @return remainingBonds Quantity of bonds remaining in the position after a partial withdraw * @return bondsMaturity Maturity of the position's remaining bonds * @return bondsIssuanceIndex Borrow period the deposit was made in **/ function position(uint128 tokenId) external view returns ( bytes32 poolHash, uint128 adjustedBalance, uint128 rate, address underlyingToken, uint128 remainingBonds, uint128 bondsMaturity, uint128 bondsIssuanceIndex ); /** * @notice Returns the balance on yield provider and the quantity of bond held * @param tokenId The tokenId of the position * @return bondsQuantity Quantity of bond held, represents funds borrowed * @return normalizedDepositedAmount Amount of deposit placed on yield provider **/ function getPositionRepartition(uint128 tokenId) external view returns (uint128 bondsQuantity, uint128 normalizedDepositedAmount); /** * @notice Deposits tokens into the yield provider and places a bid at the indicated rate within the * respective borrower's order book. A new position is created within the positions map that keeps * track of this position's composition. An ERC721 NFT is minted for the user as a representation * of the position. * @param to The address for which the position is created * @param amount The amount of tokens to be deposited * @param rate The rate at which to bid for a bonds * @param poolHash The identifier of the pool * @param underlyingToken The contract address of the token to be deposited **/ function deposit( address to, uint128 amount, uint128 rate, bytes32 poolHash, address underlyingToken ) external returns (uint128 tokenId); /** * @notice Allows a user to update the rate at which to bid for bonds. A rate is only * upgradable as long as the full amount of deposits are currently allocated with the * yield provider i.e the position does not hold any bonds. * @param tokenId The tokenId of the position * @param newRate The new rate at which to bid for bonds **/ function updateRate(uint128 tokenId, uint128 newRate) external; /** * @notice Withdraws the amount of tokens that are deposited with the yield provider. * The bonds portion of the position is not affected. * @param tokenId The tokenId of the position **/ function withdraw(uint128 tokenId) external; /** * @notice Set the address of the position descriptor. * Only accessible to governance. * @param positionDescriptor The address of the position descriptor **/ function setPositionDescriptor(address positionDescriptor) external; }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; library Errors { // *** Contract Specific Errors *** // BorrowerPools error BP_BORROW_MAX_BORROWABLE_AMOUNT_EXCEEDED(); // "Amount borrowed is too big, exceeding borrowable capacity"; error BP_REPAY_NO_ACTIVE_LOAN(); // "No active loan to be repaid, action cannot be performed"; error BP_BORROW_UNSUFFICIENT_BORROWABLE_AMOUNT_WITHIN_BRACKETS(); // "Amount provided is greater than available amount within min rate and max rate brackets"; error BP_REPAY_AT_MATURITY_ONLY(); // "Maturity has not been reached yet, action cannot be performed"; error BP_BORROW_COOLDOWN_PERIOD_NOT_OVER(); // "Cooldown period after a repayment is not over"; error BP_MULTIPLE_BORROW_AFTER_MATURITY(); // "Cannot borrow again from pool after loan maturity"; error BP_POOL_NOT_ACTIVE(); // "Pool not active" error BP_POOL_DEFAULTED(); // "Pool defaulted" error BP_LOAN_ONGOING(); // "There's a loan ongoing, cannot update rate" error BP_BORROW_OUT_OF_BOUND_AMOUNT(); // "Amount provided is greater than available amount, action cannot be performed"; error BP_POOL_CLOSED(); // "Pool closed"; error BP_OUT_OF_BOUND_MIN_RATE(); // "Rate provided is lower than minimum rate of the pool"; error BP_OUT_OF_BOUND_MAX_RATE(); // "Rate provided is greater than maximum rate of the pool"; error BP_UNMATCHED_TOKEN(); // "Token/Asset provided does not match the underlying token of the pool"; error BP_RATE_SPACING(); // "Decimals of rate provided do not comply with rate spacing of the pool"; error BP_BOND_ISSUANCE_ID_TOO_HIGH(); // "Bond issuance id is too high"; error BP_NO_DEPOSIT_TO_WITHDRAW(); // "Deposited amount non-borrowed equals to zero"; error BP_TARGET_BOND_ISSUANCE_INDEX_EMPTY(); // "Target bond issuance index has no amount to withdraw"; error BP_EARLY_REPAY_NOT_ACTIVATED(); // "The early repay feature is not activated for this pool"; // PoolController error PC_POOL_NOT_ACTIVE(); // "Pool not active" error PC_POOL_DEFAULTED(); // "Pool defaulted" error PC_POOL_ALREADY_SET_FOR_BORROWER(); // "Targeted borrower is already set for another pool"; error PC_POOL_TOKEN_NOT_SUPPORTED(); // "Underlying token is not supported by the yield provider"; error PC_DISALLOW_UNMATCHED_BORROWER(); // "Revoking the wrong borrower as the provided borrower does not match the provided address"; error PC_RATE_SPACING_COMPLIANCE(); // "Provided rate must be compliant with rate spacing"; error PC_NO_ONGOING_LOAN(); // "Cannot default a pool that has no ongoing loan"; error PC_NOT_ENOUGH_PROTOCOL_FEES(); // "Not enough registered protocol fees to withdraw"; error PC_POOL_ALREADY_CLOSED(); // "Pool already closed"; error PC_ZERO_POOL(); // "Cannot make actions on the zero pool"; error PC_ZERO_ADDRESS(); // "Cannot make actions on the zero address"; error PC_REPAYMENT_PERIOD_ONGOING(); // "Cannot default pool while repayment period in ongoing" error PC_ESTABLISHMENT_FEES_TOO_HIGH(); // "Cannot set establishment fee over 100% of loan amount" error PC_BORROWER_ALREADY_AUTHORIZED(); // "Borrower already authorized on another pool" // PositionManager error POS_MGMT_ONLY_OWNER(); // "Only the owner of the position token can manage it (update rate, withdraw)"; error POS_POSITION_ONLY_IN_BONDS(); // "Cannot withdraw a position that's only in bonds"; error POS_ZERO_AMOUNT(); // "Cannot deposit zero amount"; error POS_TIMELOCK(); // "Cannot withdraw or update rate in the same block as deposit"; error POS_POSITION_DOES_NOT_EXIST(); // "Position does not exist"; error POS_POOL_DEFAULTED(); // "Pool defaulted"; error POS_ZERO_ADDRESS(); // "Cannot make actions on the zero address"; error POS_NOT_ALLOWED(); // "Transaction sender is not allowed to perform the target action"; // PositionDescriptor error POD_BAD_INPUT(); // "Input pool identifier does not correspond to input pool hash"; //*** Library Specific Errors *** // WadRayMath error MATH_MULTIPLICATION_OVERFLOW(); // "The multiplication would result in a overflow"; error MATH_ADDITION_OVERFLOW(); // "The addition would result in a overflow"; error MATH_DIVISION_BY_ZERO(); // "The division would result in a divzion by zero"; }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; library Roles { bytes32 public constant BORROWER_ROLE = keccak256("BORROWER_ROLE"); bytes32 public constant GOVERNANCE_ROLE = keccak256("GOVERNANCE_ROLE"); bytes32 public constant POSITION_ROLE = keccak256("POSITION_ROLE"); }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; /** * @title Scaling library * @author Atlendis * @dev Scale an arbitrary number to or from WAD precision **/ library Scaling { uint256 internal constant WAD = 1e18; /** * @notice Scales an input amount to wad precision **/ function scaleToWad(uint128 a, uint256 precision) internal pure returns (uint128) { return uint128((uint256(a) * WAD) / 10**precision); } /** * @notice Scales an input amount from wad to target precision **/ function scaleFromWad(uint128 a, uint256 precision) internal pure returns (uint128) { return uint128((uint256(a) * 10**precision) / WAD); } }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "../extensions/AaveILendingPool.sol"; library Types { struct PositionDetails { uint128 adjustedBalance; uint128 rate; bytes32 poolHash; address underlyingToken; uint128 bondsIssuanceIndex; uint128 remainingBonds; uint128 bondsMaturity; uint128 creationTimestamp; } struct Tick { mapping(uint128 => uint128) bondsIssuanceIndexMultiplier; uint128 bondsQuantity; uint128 adjustedTotalAmount; uint128 adjustedRemainingAmount; uint128 adjustedWithdrawnAmount; uint128 adjustedPendingAmount; uint128 normalizedLoanedAmount; uint128 lastFeeDistributionTimestamp; uint128 atlendisLiquidityRatio; uint128 yieldProviderLiquidityRatio; uint128 accruedFees; } struct PoolParameters { bytes32 POOL_HASH; address UNDERLYING_TOKEN; uint8 TOKEN_DECIMALS; ILendingPool YIELD_PROVIDER; uint128 MIN_RATE; uint128 MAX_RATE; uint128 RATE_SPACING; uint128 MAX_BORROWABLE_AMOUNT; uint128 LOAN_DURATION; uint128 LIQUIDITY_REWARDS_DISTRIBUTION_RATE; uint128 COOLDOWN_PERIOD; uint128 REPAYMENT_PERIOD; uint128 LATE_REPAY_FEE_PER_BOND_RATE; uint128 ESTABLISHMENT_FEE_RATE; uint128 REPAYMENT_FEE_RATE; uint128 LIQUIDITY_REWARDS_ACTIVATION_THRESHOLD; bool EARLY_REPAY; } struct PoolState { bool active; bool defaulted; bool closed; uint128 currentMaturity; uint128 bondsIssuedQuantity; uint128 normalizedBorrowedAmount; uint128 normalizedAvailableDeposits; uint128 lowerInterestRate; uint128 nextLoanMinStart; uint128 remainingAdjustedLiquidityRewardsReserve; uint128 yieldProviderLiquidityRatio; uint128 currentBondsIssuanceIndex; uint128 defaultTimestamp; } struct Pool { PoolParameters parameters; PoolState state; mapping(uint256 => Tick) ticks; } }
{ "evmVersion": "istanbul", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 200 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"name":"POS_MGMT_ONLY_OWNER","type":"error"},{"inputs":[],"name":"POS_NOT_ALLOWED","type":"error"},{"inputs":[],"name":"POS_POOL_DEFAULTED","type":"error"},{"inputs":[],"name":"POS_POSITION_DOES_NOT_EXIST","type":"error"},{"inputs":[],"name":"POS_POSITION_ONLY_IN_BONDS","type":"error"},{"inputs":[],"name":"POS_TIMELOCK","type":"error"},{"inputs":[],"name":"POS_ZERO_ADDRESS","type":"error"},{"inputs":[],"name":"POS_ZERO_AMOUNT","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"uint128","name":"tokenId","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"rate","type":"uint128"},{"indexed":false,"internalType":"bytes32","name":"poolHash","type":"bytes32"},{"indexed":false,"internalType":"uint128","name":"bondsIssuanceIndex","type":"uint128"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"positionDescriptor","type":"address"}],"name":"SetPositionDescriptor","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"uint128","name":"tokenId","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"rate","type":"uint128"},{"indexed":false,"internalType":"bytes32","name":"poolHash","type":"bytes32"}],"name":"UpdateRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"uint128","name":"tokenId","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"remainingBonds","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"rate","type":"uint128"},{"indexed":false,"internalType":"bytes32","name":"poolHash","type":"bytes32"}],"name":"Withdraw","type":"event"},{"inputs":[{"internalType":"uint128","name":"","type":"uint128"}],"name":"_positions","outputs":[{"internalType":"uint128","name":"adjustedBalance","type":"uint128"},{"internalType":"uint128","name":"rate","type":"uint128"},{"internalType":"bytes32","name":"poolHash","type":"bytes32"},{"internalType":"address","name":"underlyingToken","type":"address"},{"internalType":"uint128","name":"bondsIssuanceIndex","type":"uint128"},{"internalType":"uint128","name":"remainingBonds","type":"uint128"},{"internalType":"uint128","name":"bondsMaturity","type":"uint128"},{"internalType":"uint128","name":"creationTimestamp","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"rate","type":"uint128"},{"internalType":"bytes32","name":"poolHash","type":"bytes32"},{"internalType":"address","name":"underlyingToken","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint128","name":"tokenId","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"tokenId","type":"uint128"}],"name":"getPositionRepartition","outputs":[{"internalType":"uint128","name":"bondsQuantity","type":"uint128"},{"internalType":"uint128","name":"normalizedDepositedAmount","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"contract IBorrowerPools","name":"_pools","type":"address"},{"internalType":"contract IPositionDescriptor","name":"_positionDescriptor","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pools","outputs":[{"internalType":"contract IBorrowerPools","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"tokenId","type":"uint128"}],"name":"position","outputs":[{"internalType":"bytes32","name":"poolHash","type":"bytes32"},{"internalType":"uint128","name":"adjustedBalance","type":"uint128"},{"internalType":"uint128","name":"rate","type":"uint128"},{"internalType":"address","name":"underlyingToken","type":"address"},{"internalType":"uint128","name":"remainingBonds","type":"uint128"},{"internalType":"uint128","name":"bondsMaturity","type":"uint128"},{"internalType":"uint128","name":"bondsIssuanceIndex","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionDescriptor","outputs":[{"internalType":"contract IPositionDescriptor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_positionDescriptor","type":"address"}],"name":"setPositionDescriptor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"tokenId","type":"uint128"},{"internalType":"uint128","name":"newRate","type":"uint128"}],"name":"updateRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"tokenId","type":"uint128"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b50612da0806100206000396000f3fe608060405234801561001057600080fd5b506004361061014d5760003560e01c806370a08231116100c3578063b88d4fde1161007c578063b88d4fde146103cf578063c5c51dca146103e2578063c87b56dd146103f5578063cd10049714610408578063d89f46ab146104cd578063e985e9c51461050057600080fd5b806370a082311461034257806374b7cc0a146103635780638f15b4141461038e57806392208f37146103a157806395d89b41146103b4578063a22cb465146103bc57600080fd5b8063106d023111610115578063106d0231146101e257806323b872dd146101f557806342842e0e1461020857806360bc5b231461021b5780636206ea321461022e5780636352211e1461032f57600080fd5b806301ffc9a71461015257806302387a7b1461017a57806306fdde031461018f578063081812fc146101a4578063095ea7b3146101cf575b600080fd5b61016561016036600461232e565b610513565b60405190151581526020015b60405180910390f35b61018d610188366004612360565b610565565b005b610197610a46565b60405161017191906123d5565b6101b76101b23660046123e8565b610ad8565b6040516001600160a01b039091168152602001610171565b61018d6101dd366004612416565b610b72565b6098546101b7906001600160a01b031681565b61018d610203366004612442565b610c88565b61018d610216366004612442565b610c9c565b61018d610229366004612483565b610cb0565b6102e261023c366004612360565b6001600160801b039081166000908152609a60209081526040918290208251610100810184528154808616808352600160801b918290048716948301859052600184015495830186905260028401546001600160a01b03166060840181905260038501548089166080860181905290849004891660a08601819052600490960154808a1660c0870181905294900490981660e09094019390935294969495939491939091565b604080519788526001600160801b039687166020890152948616948701949094526001600160a01b03909216606086015283166080850152821660a08401521660c082015260e001610171565b6101b761033d3660046123e8565b610ea6565b6103556103503660046124bc565b610f1d565b604051908152602001610171565b6103766103713660046124d9565b610fa4565b6040516001600160801b039091168152602001610171565b61018d61039c36600461260e565b6113c8565b61018d6103af3660046124bc565b6114d2565b61019761161a565b61018d6103ca3660046126a5565b611629565b61018d6103dd3660046126d3565b611638565b6097546101b7906001600160a01b031681565b6101976104033660046123e8565b611653565b610476610416366004612360565b609a60205260009081526040902080546001820154600283015460038401546004909401546001600160801b0380851695600160801b958690048216956001600160a01b0390941693818316939181900483169282811692919091041688565b604080516001600160801b03998a16815297891660208901528701959095526001600160a01b0390931660608601529085166080850152841660a0840152831660c08301529190911660e082015261010001610171565b6104e06104db366004612360565b611719565b604080516001600160801b03938416815292909116602083015201610171565b61016561050e366004612753565b611933565b60006001600160e01b031982166380ac58cd60e01b148061054457506001600160e01b03198216635b5e139f60e01b145b8061055f57506301ffc9a760e01b6001600160e01b03198316145b92915050565b336105786001600160801b038316610ea6565b6001600160a01b03161461059f576040516398bb581360e01b815260040160405180910390fd5b6001600160801b038082166000908152609a6020526040902060040154600160801b9004164214156105e457604051633b95e01560e21b815260040160405180910390fd5b6097546001600160801b0382166000908152609a602052604080822060010154905163631296d760e11b815291926001600160a01b03169163c6252dae916106329160040190815260200190565b60206040518083038186803b15801561064a57600080fd5b505afa15801561065e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106829190612791565b6001600160801b038381166000908152609a60205260409020600301549181169250600160801b9091041615806106fe57506001600160801b038083166000908152609a60205260409020600401541642108015906106fe57506001600160801b038083166000908152609a6020526040902060040154168114155b61071b5760405163c9f240d560e01b815260040160405180910390fd5b6097546001600160801b038381166000908152609a6020526040808220600181015481546003909201549251633cec31f360e21b81526004810191909152600160801b820485166024820152908416604482015292166064830152918291829182916001600160a01b039091169063f3b0c7cc9060840160806040518083038186803b1580156107aa57600080fd5b505afa1580156107be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e291906127ae565b6001600160801b03808b166000908152609a602052604081208054969a50949850929650909450869361081791859116612818565b82546101009290920a6001600160801b038181021990931691831602179091558781166000908152609a602052604081206003810180548416600160801b88861681028281179093556004840180546001600160801b031916898816179055609754600185015494549597506001600160a01b03169563dc3fbbbc95919091048116928b929116173360405160e087901b6001600160e01b031916815260048101959095526001600160801b039384166024860152918316604485015290911660648301526001600160a01b0316608482015260a401602060405180830381600087803b15801561090757600080fd5b505af115801561091b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061093f9190612791565b6001600160801b038881166000818152609a6020908152604091829020805460019091015483519485528587169285019290925288851684840152600160801b900490931660608301526080820192909252905191925033917f4551962dda62f19a9b991852d8918d0cc22d52bb9906864571aa31dcf6ab13cc9181900360a00190a26001600160801b038088166000908152609a6020526040902060030154600160801b900416610a3d576109fd876001600160801b0316611961565b6001600160801b0387166000908152609a60205260408120818155600181018290556002810180546001600160a01b031916905560038101829055600401555b50505050505050565b606060658054610a5590612840565b80601f0160208091040260200160405190810160405280929190818152602001828054610a8190612840565b8015610ace5780601f10610aa357610100808354040283529160200191610ace565b820191906000526020600020905b815481529060010190602001808311610ab157829003601f168201915b5050505050905090565b6000818152606760205260408120546001600160a01b0316610b565760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152606960205260409020546001600160a01b031690565b6000610b7d82610ea6565b9050806001600160a01b0316836001600160a01b03161415610beb5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610b4d565b336001600160a01b0382161480610c075750610c078133611933565b610c795760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610b4d565b610c8383836119fc565b505050565b610c9181611a6a565b610c83838383611b35565b610ca581611a6a565b610c83838383611b66565b33610cc36001600160801b038416610ea6565b6001600160a01b031614610cea576040516398bb581360e01b815260040160405180910390fd5b6001600160801b038083166000908152609a6020526040902060040154600160801b900416421415610d2f57604051633b95e01560e21b815260040160405180910390fd5b6001600160801b038281166000908152609a6020526040808220805460975460018301546003909301549351637ded35c560e01b815282871660048201526024810193909352600160801b90910485166044830181905286861660648401529290941660848201529092829182916001600160a01b031690637ded35c59060a401606060405180830381600087803b158015610dca57600080fd5b505af1158015610dde573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e02919061287b565b6001600160801b038981166000818152609a60209081526040918290208c8516600160801b81028987161782556003820180548988166001600160801b03199091161790556001909101548351948552948616918401919091528282015260608201929092529051939650919450925033917f5c4c281a4feeeeb1b77e0356a23027125c988b5efc21b7ee375c7501ab96d4c69181900360800190a2505050505050565b6000818152606760205260408120546001600160a01b03168061055f5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610b4d565b60006001600160a01b038216610f885760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610b4d565b506001600160a01b031660009081526068602052604090205490565b60006001600160801b038516610fcd576040516301c149dd60e11b815260040160405180910390fd5b609980546001600160801b0316906000610fe6836128c8565b91906101000a8154816001600160801b0302191690836001600160801b03160217905550905061101f86826001600160801b0316611b81565b6000826001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561105a57600080fd5b505afa15801561106e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109291906128ef565b905060006110ac6001600160801b03881660ff8416611b9b565b6097546040805163f3d1d26360e01b81526001600160801b03808b166004830152602482018a90526001600160a01b038981166044840152336064840152908516608483015282519495506000948594919091169263f3d1d2639260a4808201939182900301818787803b15801561112357600080fd5b505af1158015611137573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115b9190612912565b91509150604051806101000160405280836001600160801b03168152602001896001600160801b03168152602001888152602001876001600160a01b03168152602001826001600160801b0316815260200160006001600160801b0316815260200160006001600160801b03168152602001426001600160801b0316815250609a6000876001600160801b03166001600160801b0316815260200190815260200160002060008201518160000160006101000a8154816001600160801b0302191690836001600160801b0316021790555060208201518160000160106101000a8154816001600160801b0302191690836001600160801b031602179055506040820151816001015560608201518160020160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060808201518160030160006101000a8154816001600160801b0302191690836001600160801b0316021790555060a08201518160030160106101000a8154816001600160801b0302191690836001600160801b0316021790555060c08201518160040160006101000a8154816001600160801b0302191690836001600160801b0316021790555060e08201518160040160106101000a8154816001600160801b0302191690836001600160801b03160217905550905050896001600160a01b03167fca6b4104f5adde18e393df5899aa82f81b6578973d6573dab8fd306ac6fb011286858b8b866040516113b39594939291906001600160801b039586168152938516602085015291841660408401526060830152909116608082015260a00190565b60405180910390a25050505095945050505050565b600054610100900460ff166113e35760005460ff16156113e7565b303b155b61144a5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610b4d565b600054610100900460ff1615801561146c576000805461ffff19166101011790555b6114768585611bd4565b609780546001600160a01b038086166001600160a01b0319928316179092556098805492851692909116919091179055609980546001600160801b031916600117905580156114cb576000805461ff00191690555b5050505050565b6097546001600160a01b03166391d148547f71840dc4906352362b0cdaf79870196c8e42acafade72d5d5a6d59291253ceb1336040516001600160e01b031960e085901b16815260048101929092526001600160a01b0316602482015260440160206040518083038186803b15801561154a57600080fd5b505afa15801561155e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115829190612941565b61159f576040516346bd1df960e11b815260040160405180910390fd5b6001600160a01b0381166115c6576040516379273f9960e01b815260040160405180910390fd5b609880546001600160a01b0319166001600160a01b0383169081179091556040519081527ffbc3466f121a348b708d9e3b66d3ad6cbf373042f0a7e4ef942bd03b3bc6822c9060200160405180910390a150565b606060668054610a5590612840565b611634338383611c05565b5050565b61164182611a6a565b61164d84848484611cd4565b50505050565b6000818152606760205260409020546060906001600160a01b031661168b57604051631a77a95160e21b815260040160405180910390fd5b6098546040516324945e5b60e21b81523060048201526001600160801b03841660248201526001600160a01b0390911690639251796c9060440160006040518083038186803b1580156116dd57600080fd5b505afa1580156116f1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261055f919081019061295e565b6001600160801b03811660009081526067602052604081205481906001600160a01b031661174c57506000928392509050565b6097546001600160801b0384166000908152609a602052604080822060010154905163631296d760e11b815291926001600160a01b03169163c6252dae9161179a9160040190815260200190565b60206040518083038186803b1580156117b257600080fd5b505afa1580156117c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117ea9190612791565b6001600160801b038581166000908152609a60205260409020600401549181169250161580159061183757506001600160801b038085166000908152609a60205260409020600401541681145b15611869575050506001600160801b039081166000908152609a6020526040812060030154600160801b900490911691565b6097546001600160801b038581166000908152609a60205260409081902060018101548154600390920154925163b74e0b1360e01b81526004810191909152600160801b8204841660248201529083166044820152911660648201526001600160a01b039091169063b74e0b1390608401604080518083038186803b1580156118f157600080fd5b505afa158015611905573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119299190612912565b9250925050915091565b6001600160a01b039182166000908152606a6020908152604080832093909416825291909152205460ff1690565b600061196c82610ea6565b90506119796000836119fc565b6001600160a01b03811660009081526068602052604081208054600192906119a29084906129d5565b909155505060008281526067602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b600081815260696020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611a3182610ea6565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6097546001600160801b0382166000908152609a6020526040808220600101549051636acaa04560e11b815291926001600160a01b03169163d595408a91611ab89160040190815260200190565b6101806040518083038186803b158015611ad157600080fd5b505afa158015611ae5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b0991906129ec565b50505050505050505050915050801561163457604051634ebfed1160e01b815260040160405180910390fd5b611b3f3382611d06565b611b5b5760405162461bcd60e51b8152600401610b4d90612ad9565b610c83838383611ddd565b610c8383838360405180602001604052806000815250611638565b611634828260405180602001604052806000815250611f79565b6000611ba882600a612c0e565b611bc3670de0b6b3a76400006001600160801b038616612c1a565b611bcd9190612c39565b9392505050565b600054610100900460ff16611bfb5760405162461bcd60e51b8152600401610b4d90612c5b565b6116348282611fac565b816001600160a01b0316836001600160a01b03161415611c675760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610b4d565b6001600160a01b038381166000818152606a6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611cde3383611d06565b611cfa5760405162461bcd60e51b8152600401610b4d90612ad9565b61164d84848484611ffa565b6000818152606760205260408120546001600160a01b0316611d7f5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610b4d565b6000611d8a83610ea6565b9050806001600160a01b0316846001600160a01b03161480611dc55750836001600160a01b0316611dba84610ad8565b6001600160a01b0316145b80611dd55750611dd58185611933565b949350505050565b826001600160a01b0316611df082610ea6565b6001600160a01b031614611e545760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610b4d565b6001600160a01b038216611eb65760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610b4d565b611ec16000826119fc565b6001600160a01b0383166000908152606860205260408120805460019290611eea9084906129d5565b90915550506001600160a01b0382166000908152606860205260408120805460019290611f18908490612ca6565b909155505060008181526067602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b611f83838361202d565b611f90600084848461216f565b610c835760405162461bcd60e51b8152600401610b4d90612cbe565b600054610100900460ff16611fd35760405162461bcd60e51b8152600401610b4d90612c5b565b8151611fe690606590602085019061227c565b508051610c8390606690602084019061227c565b612005848484611ddd565b6120118484848461216f565b61164d5760405162461bcd60e51b8152600401610b4d90612cbe565b6001600160a01b0382166120835760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610b4d565b6000818152606760205260409020546001600160a01b0316156120e85760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610b4d565b6001600160a01b0382166000908152606860205260408120805460019290612111908490612ca6565b909155505060008181526067602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b60006001600160a01b0384163b1561227157604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906121b3903390899088908890600401612d10565b602060405180830381600087803b1580156121cd57600080fd5b505af19250505080156121fd575060408051601f3d908101601f191682019092526121fa91810190612d4d565b60015b612257573d80801561222b576040519150601f19603f3d011682016040523d82523d6000602084013e612230565b606091505b50805161224f5760405162461bcd60e51b8152600401610b4d90612cbe565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611dd5565b506001949350505050565b82805461228890612840565b90600052602060002090601f0160209004810192826122aa57600085556122f0565b82601f106122c357805160ff19168380011785556122f0565b828001600101855582156122f0579182015b828111156122f05782518255916020019190600101906122d5565b506122fc929150612300565b5090565b5b808211156122fc5760008155600101612301565b6001600160e01b03198116811461232b57600080fd5b50565b60006020828403121561234057600080fd5b8135611bcd81612315565b6001600160801b038116811461232b57600080fd5b60006020828403121561237257600080fd5b8135611bcd8161234b565b60005b83811015612398578181015183820152602001612380565b8381111561164d5750506000910152565b600081518084526123c181602086016020860161237d565b601f01601f19169290920160200192915050565b602081526000611bcd60208301846123a9565b6000602082840312156123fa57600080fd5b5035919050565b6001600160a01b038116811461232b57600080fd5b6000806040838503121561242957600080fd5b823561243481612401565b946020939093013593505050565b60008060006060848603121561245757600080fd5b833561246281612401565b9250602084013561247281612401565b929592945050506040919091013590565b6000806040838503121561249657600080fd5b82356124a18161234b565b915060208301356124b18161234b565b809150509250929050565b6000602082840312156124ce57600080fd5b8135611bcd81612401565b600080600080600060a086880312156124f157600080fd5b85356124fc81612401565b9450602086013561250c8161234b565b9350604086013561251c8161234b565b925060608601359150608086013561253381612401565b809150509295509295909350565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561258057612580612541565b604052919050565b600067ffffffffffffffff8211156125a2576125a2612541565b50601f01601f191660200190565b60006125c36125be84612588565b612557565b90508281528383830111156125d757600080fd5b828260208301376000602084830101529392505050565b600082601f8301126125ff57600080fd5b611bcd838335602085016125b0565b6000806000806080858703121561262457600080fd5b843567ffffffffffffffff8082111561263c57600080fd5b612648888389016125ee565b9550602087013591508082111561265e57600080fd5b5061266b878288016125ee565b935050604085013561267c81612401565b9150606085013561268c81612401565b939692955090935050565b801515811461232b57600080fd5b600080604083850312156126b857600080fd5b82356126c381612401565b915060208301356124b181612697565b600080600080608085870312156126e957600080fd5b84356126f481612401565b9350602085013561270481612401565b925060408501359150606085013567ffffffffffffffff81111561272757600080fd5b8501601f8101871361273857600080fd5b612747878235602084016125b0565b91505092959194509250565b6000806040838503121561276657600080fd5b823561277181612401565b915060208301356124b181612401565b805161278c8161234b565b919050565b6000602082840312156127a357600080fd5b8151611bcd8161234b565b600080600080608085870312156127c457600080fd5b84516127cf8161234b565b60208601519094506127e08161234b565b60408601519093506127f18161234b565b606086015190925061268c8161234b565b634e487b7160e01b600052601160045260246000fd5b60006001600160801b038381169083168181101561283857612838612802565b039392505050565b600181811c9082168061285457607f821691505b6020821081141561287557634e487b7160e01b600052602260045260246000fd5b50919050565b60008060006060848603121561289057600080fd5b835161289b8161234b565b60208501519093506128ac8161234b565b60408501519092506128bd8161234b565b809150509250925092565b60006001600160801b03808316818114156128e5576128e5612802565b6001019392505050565b60006020828403121561290157600080fd5b815160ff81168114611bcd57600080fd5b6000806040838503121561292557600080fd5b82516129308161234b565b60208401519092506124b18161234b565b60006020828403121561295357600080fd5b8151611bcd81612697565b60006020828403121561297057600080fd5b815167ffffffffffffffff81111561298757600080fd5b8201601f8101841361299857600080fd5b80516129a66125be82612588565b8181528560208385010111156129bb57600080fd5b6129cc82602083016020860161237d565b95945050505050565b6000828210156129e7576129e7612802565b500390565b6000806000806000806000806000806000806101808d8f031215612a0f57600080fd5b8c51612a1a81612697565b60208e0151909c50612a2b81612697565b60408e0151909b50612a3c81612697565b60608e0151909a50612a4d8161234b565b60808e0151909950612a5e8161234b565b60a08e0151909850612a6f8161234b565b9650612a7d60c08e01612781565b9550612a8b60e08e01612781565b9450612a9a6101008e01612781565b9350612aa96101208e01612781565b9250612ab86101408e01612781565b9150612ac76101608e01612781565b90509295989b509295989b509295989b565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b600181815b80851115612b65578160001904821115612b4b57612b4b612802565b80851615612b5857918102915b93841c9390800290612b2f565b509250929050565b600082612b7c5750600161055f565b81612b895750600061055f565b8160018114612b9f5760028114612ba957612bc5565b600191505061055f565b60ff841115612bba57612bba612802565b50506001821b61055f565b5060208310610133831016604e8410600b8410161715612be8575081810a61055f565b612bf28383612b2a565b8060001904821115612c0657612c06612802565b029392505050565b6000611bcd8383612b6d565b6000816000190483118215151615612c3457612c34612802565b500290565b600082612c5657634e487b7160e01b600052601260045260246000fd5b500490565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60008219821115612cb957612cb9612802565b500190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612d43908301846123a9565b9695505050505050565b600060208284031215612d5f57600080fd5b8151611bcd8161231556fea2646970667358221220cef5927139e39f9932b31495122690922bda227af39aee646ac7770d848ad44264736f6c63430008090033
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.