Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
OpenFundRedemptionConcrete
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 1 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@solvprotocol/contracts-v3-sft-abilities/contracts/value-issuable/SFTValueIssuableConcrete.sol";
import "@solvprotocol/contracts-v3-sft-abilities/contracts/fcfs-multi-repayable/FCFSMultiRepayableConcrete.sol";
import "./IOpenFundRedemptionConcrete.sol";
contract OpenFundRedemptionConcrete is IOpenFundRedemptionConcrete, SFTValueIssuableConcrete, FCFSMultiRepayableConcrete {
event SetRedemptionFeeReceiver(address indexed redemptionFeeReceiver);
event SetRedemtpionFeeRate(bytes32 indexed poolId, uint256 redemptionFeeRate);
mapping(uint256 => RedeemInfo) internal _redeemInfos;
address public redemptionFeeReceiver;
// poolId => redemptionFeeRate
mapping(bytes32 => uint256) public redemptionFeeRates; // base: 1e18
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize() external initializer {
__SFTIssuableConcrete_init();
}
function setRedeemNavOnlyDelegate(uint256 slot_, uint256 nav_) external virtual override onlyDelegate {
_redeemInfos[slot_].nav = nav_;
}
function setRedemptionFeeReceiverOnlyAdmin(address redemptionFeeReceiver_) external virtual onlyAdmin {
redemptionFeeReceiver = redemptionFeeReceiver_;
emit SetRedemptionFeeReceiver(redemptionFeeReceiver_);
}
function setRedemptionFeeRateOnlyAdmin(bytes32 poolId_, uint256 redemptionFeeRate_) external virtual onlyAdmin {
redemptionFeeRates[poolId_] = redemptionFeeRate_;
emit SetRedemtpionFeeRate(poolId_, redemptionFeeRate_);
}
function getRedemptionFeeRate(uint256 slot_) external view virtual returns (uint256) {
return redemptionFeeRates[_redeemInfos[slot_].poolId];
}
function getRedeemInfo(uint256 slot_) external view virtual override returns (RedeemInfo memory) {
return _redeemInfos[slot_];
}
function getRedeemNav(uint256 slot_) external view virtual override returns (uint256) {
return _redeemInfos[slot_].nav;
}
function _isSlotValid( uint256 slot_) internal view virtual override returns (bool) {
return _redeemInfos[slot_].createTime != 0;
}
function _createSlot( address /* txSender_ */, bytes memory inputSlotInfo_) internal virtual override returns (uint256 slot_) {
RedeemInfo memory redeemInfo = abi.decode(inputSlotInfo_, (RedeemInfo));
require(redeemInfo.poolId != bytes32(0), "OFRC: invalid poolId");
require(redeemInfo.currency != address(0), "OFRC: invalid currency");
require(redeemInfo.createTime != 0, "OFRC: invalid createTime");
slot_ = _getSlot(redeemInfo.poolId, redeemInfo.currency, redeemInfo.createTime);
// if the slot is already created, do nothing
if (_redeemInfos[slot_].createTime == 0) {
_redeemInfos[slot_] = redeemInfo;
}
}
function _getSlot(bytes32 poolId_, address currency_, uint256 createTime_) internal view virtual returns (uint256) {
uint256 chainId;
assembly { chainId := chainid() }
return uint256(keccak256(abi.encodePacked(chainId, delegate(), poolId_, currency_, createTime_)));
}
function _mint(
address /** txSender_ */, address currency_, address /** mintTo_ */,
uint256 slot_, uint256 /** tokenId_ */, uint256 /** amount_ */
) internal virtual override {
require(_isSlotValid(slot_), "OFRC: invalid slot");
require(_redeemInfos[slot_].currency == currency_, "OFRC: invalid currency");
}
function _burn(uint256 tokenId_, uint256 burnValue_) internal virtual override {
uint256 slot = ERC3525Upgradeable(delegate()).slotOf(tokenId_);
FCFSMultiRepayableConcrete._slotValueInfo[slot].slotTotalValue -= burnValue_;
}
function _currency( uint256 slot_) internal view virtual override returns (address) {
return _redeemInfos[slot_].currency;
}
function _repayRate( uint256 slot_) internal view virtual override returns (uint256) {
return _redeemInfos[slot_].nav;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts 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/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library CountersUpgradeable {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library MathUpgradeable {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/MathUpgradeable.sol";
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = MathUpgradeable.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, MathUpgradeable.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
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.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@solvprotocol/contracts-v3-solidity-utils/contracts/misc/Constants.sol";
import "@solvprotocol/erc-3525/ERC3525Upgradeable.sol";
import "@solvprotocol/contracts-v3-sft-core/contracts/BaseSFTConcreteUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./IFCFSMultiRepayableConcrete.sol";
abstract contract FCFSMultiRepayableConcrete is IFCFSMultiRepayableConcrete, BaseSFTConcreteUpgradeable {
mapping(uint256 => SlotRepayInfo) internal _slotRepayInfo;
mapping(address => uint256) public allocatedCurrencyBalance;
uint32 internal constant REPAY_RATE_SCALAR = 1e8;
mapping(uint256 => SlotValueInfo) internal _slotValueInfo;
function repayOnlyDelegate(address txSender_, uint256 slot_, address currency_, uint256 repayCurrencyAmount_) external payable virtual override onlyDelegate {
_beforeRepay(txSender_, slot_, currency_, repayCurrencyAmount_);
_slotRepayInfo[slot_].repaidCurrencyAmount += repayCurrencyAmount_;
_slotRepayInfo[slot_].currencyBalance += repayCurrencyAmount_;
allocatedCurrencyBalance[currency_] += repayCurrencyAmount_;
}
function repayWithBalanceOnlyDelegate(address txSender_, uint256 slot_, address currency_, uint256 repayCurrencyAmount_) external payable virtual override onlyDelegate {
_beforeRepayWithBalance(txSender_, slot_, currency_, repayCurrencyAmount_);
uint256 balance = ERC20(currency_).balanceOf(delegate());
require(repayCurrencyAmount_ <= balance - allocatedCurrencyBalance[currency_], "FMR: insufficient unallocated balance");
_slotRepayInfo[slot_].repaidCurrencyAmount += repayCurrencyAmount_;
_slotRepayInfo[slot_].currencyBalance += repayCurrencyAmount_;
allocatedCurrencyBalance[currency_] += repayCurrencyAmount_;
}
function mintOnlyDelegate(uint256 /** tokenId_ */, uint256 slot_, uint256 mintValue_) external virtual override onlyDelegate {
_slotValueInfo[slot_].slotInitialValue += mintValue_;
_slotValueInfo[slot_].slotTotalValue += mintValue_;
}
function claimOnlyDelegate(uint256 tokenId_, uint256 slot_, address currency_, uint256 claimValue_) external virtual override onlyDelegate returns (uint256 claimCurrencyAmount_) {
_beforeClaim(tokenId_, slot_, currency_, claimValue_);
require(claimValue_ <= claimableValue(tokenId_), "FMR: insufficient claimable value");
_slotValueInfo[slot_].slotTotalValue -= claimValue_;
uint8 valueDecimals = ERC3525Upgradeable(delegate()).valueDecimals();
claimCurrencyAmount_ = claimValue_ * _repayRate(slot_) / (10 ** valueDecimals);
require(claimCurrencyAmount_ <= _slotRepayInfo[slot_].currencyBalance, "FMR: insufficient repaid currency amount");
allocatedCurrencyBalance[currency_] -= claimCurrencyAmount_;
_slotRepayInfo[slot_].currencyBalance -= claimCurrencyAmount_;
}
function refundOnlyDelegate(uint256 slot_, address currency_) external virtual override onlyDelegate returns (uint256 refundableCurrencyAmount_) {
require(currency_ == _currency(slot_), "FMR: invalid currency");
uint8 valueDecimals = ERC3525Upgradeable(delegate()).valueDecimals();
uint256 dueAmount = slotTotalValue(slot_) * _repayRate(slot_) / (10 ** valueDecimals) + 1;
uint256 slotBalance = slotCurrencyBalance(slot_);
refundableCurrencyAmount_ = slotBalance > dueAmount ? slotBalance - dueAmount : 0;
if (refundableCurrencyAmount_ > 0) {
_slotRepayInfo[slot_].repaidCurrencyAmount -= refundableCurrencyAmount_;
_slotRepayInfo[slot_].currencyBalance -= refundableCurrencyAmount_;
allocatedCurrencyBalance[currency_] -= refundableCurrencyAmount_;
}
}
function transferOnlyDelegate(uint256 fromTokenId_, uint256 toTokenId_, uint256 fromTokenBalance_, uint256 transferValue_) external virtual override onlyDelegate {
_beforeTransfer(fromTokenId_, toTokenId_, fromTokenBalance_, transferValue_);
}
function claimableValue(uint256 tokenId_) public view virtual override returns (uint256) {
uint256 slot = ERC3525Upgradeable(delegate()).slotOf(tokenId_);
uint256 balance = ERC3525Upgradeable(delegate()).balanceOf(tokenId_);
uint8 valueDecimals = ERC3525Upgradeable(delegate()).valueDecimals();
uint256 repayRate = _repayRate(slot);
if (repayRate == 0) {
return 0;
} else {
uint256 dueAmount = balance * repayRate / (10 ** valueDecimals);
return dueAmount < _slotRepayInfo[slot].currencyBalance ? balance :
_slotRepayInfo[slot].currencyBalance * (10 ** valueDecimals) / repayRate;
}
}
function slotRepaidCurrencyAmount(uint256 slot_) public view virtual override returns (uint256) {
return _slotRepayInfo[slot_].repaidCurrencyAmount;
}
function slotCurrencyBalance(uint256 slot_) public view virtual override returns (uint256) {
return _slotRepayInfo[slot_].currencyBalance;
}
function slotInitialValue(uint256 slot_) public view virtual override returns (uint256) {
return _slotValueInfo[slot_].slotInitialValue;
}
function slotTotalValue(uint256 slot_) public view virtual override returns (uint256) {
return _slotValueInfo[slot_].slotTotalValue;
}
function _currency(uint256 slot_) internal view virtual returns (address);
function _repayRate(uint256 slot_) internal view virtual returns (uint256);
function _beforeRepay(address /** txSender_ */, uint256 slot_, address currency_, uint256 /** repayCurrencyAmount_ */) internal virtual {
require(currency_ == _currency(slot_), "FMR: invalid currency");
}
function _beforeRepayWithBalance(address /** txSender_ */, uint256 slot_, address currency_, uint256 /** repayCurrencyAmount_ */) internal virtual {
require(currency_ == _currency(slot_), "FMR: invalid currency");
}
function _beforeClaim(uint256 /** tokenId_ */, uint256 slot_, address currency_, uint256 /** claimValue_ */) internal virtual {
require(currency_ == _currency(slot_), "FMR: invalid currency");
}
function _beforeTransfer(uint256 fromTokenId_, uint256 toTokenId_, uint256 fromTokenBalance_, uint256 transferValue_) internal virtual {}
uint256[46] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IFCFSMultiRepayableConcrete {
struct SlotRepayInfo {
uint256 repaidCurrencyAmount;
uint256 currencyBalance;
}
struct SlotValueInfo {
uint256 slotInitialValue;
uint256 slotTotalValue;
}
function repayOnlyDelegate(address txSender_, uint256 slot_, address currency_, uint256 repayCurrencyAmount_) external payable;
function repayWithBalanceOnlyDelegate(address txSender_, uint256 slot_, address currency_, uint256 repayCurrencyAmount_) external payable;
function mintOnlyDelegate(uint256 tokenId_, uint256 slot_, uint256 mintValue_) external;
function claimOnlyDelegate(uint256 tokenId_, uint256 slot_, address currency_, uint256 claimValue_) external returns (uint256);
function refundOnlyDelegate(uint256 slot_, address currency_) external returns (uint256);
function transferOnlyDelegate(uint256 fromTokenId_, uint256 toTokenId_, uint256 fromTokenBalance_, uint256 transferValue_) external;
function slotRepaidCurrencyAmount(uint256 slot_) external view returns (uint256);
function slotCurrencyBalance(uint256 slot_) external view returns (uint256);
function slotInitialValue(uint256 slot_) external view returns (uint256);
function slotTotalValue(uint256 slot_) external view returns (uint256);
function claimableValue(uint256 tokenId_) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ISFTIssuableConcrete {
function createSlotOnlyDelegate(address txSender_, bytes calldata inputSlotInfo_) external returns (uint256 slot_);
function mintOnlyDelegate(address txSender_, address currency_, address mintTo_, uint256 slot_, uint256 tokenId_, uint256 amount_) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ISFTIssuableDelegate {
function createSlotOnlyIssueMarket(address txSender, bytes calldata inputSlotInfo) external returns(uint256 slot);
function mintOnlyIssueMarket(address txSender, address currency, address mintTo, uint256 slot, uint256 value) external payable returns(uint256 tokenId);
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@solvprotocol/contracts-v3-sft-core/contracts/BaseSFTConcreteUpgradeable.sol";
import "./ISFTIssuableDelegate.sol";
import "./ISFTIssuableConcrete.sol";
abstract contract SFTIssuableConcrete is ISFTIssuableConcrete, BaseSFTConcreteUpgradeable {
function __SFTIssuableConcrete_init() internal onlyInitializing {
__BaseSFTConcrete_init();
}
function __SFTIssuableConcrete_init_unchained() internal onlyInitializing {
}
function createSlotOnlyDelegate(address txSender_, bytes calldata inputSlotInfo_) external virtual override onlyDelegate returns (uint256 slot_) {
slot_ = _createSlot(txSender_, inputSlotInfo_);
require(slot_ != 0, "SFTIssuableConcrete: invalid slot");
}
function mintOnlyDelegate(address txSender_, address currency_, address mintTo_, uint256 slot_, uint256 tokenId_, uint256 amount_)
external virtual override onlyDelegate {
_mint(txSender_, currency_, mintTo_, slot_, tokenId_, amount_);
}
function _createSlot(address txSender_, bytes memory inputSlotInfo_) internal virtual returns (uint256 slot_);
function _mint(address txSender_, address currency_, address mintTo_, uint256 slot_, uint256 tokenId_, uint256 amount_) internal virtual;
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../issuable/ISFTIssuableConcrete.sol";
interface ISFTValueIssuableConcrete is ISFTIssuableConcrete {
function burnOnlyDelegate(uint256 tokenId, uint256 burnValue) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../issuable/ISFTIssuableDelegate.sol";
interface ISFTValueIssuableDelegate is ISFTIssuableDelegate {
function mintValueOnlyIssueMarket(address txSender, address currency, uint256 tokenId, uint256 mintValue) external payable;
function burnOnlyIssueMarket(uint256 tokenId, uint256 burnValue) external;
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@solvprotocol/contracts-v3-sft-core/contracts/BaseSFTConcreteUpgradeable.sol";
import "./ISFTValueIssuableDelegate.sol";
import "./ISFTValueIssuableConcrete.sol";
import "../issuable/SFTIssuableConcrete.sol";
abstract contract SFTValueIssuableConcrete is ISFTValueIssuableConcrete, SFTIssuableConcrete {
function __SFTValueIssuableConcrete_init() internal onlyInitializing {
__SFTIssuableConcrete_init();
}
function __SFTValueIssuableConcrete_init_unchained() internal onlyInitializing {
}
function burnOnlyDelegate(uint256 tokenId_, uint256 burnValue_) external virtual override onlyDelegate {
_burn(tokenId_, burnValue_);
}
function _burn(uint256 tokenId_, uint256 burnValue_) internal virtual;
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@solvprotocol/contracts-v3-solidity-utils/contracts/access/OwnControl.sol";
import "@solvprotocol/contracts-v3-solidity-utils/contracts/access/SFTConcreteControl.sol";
import "./interface/IBaseSFTConcrete.sol";
abstract contract BaseSFTConcreteUpgradeable is IBaseSFTConcrete, SFTConcreteControl {
modifier onlyDelegateOwner {
require(_msgSender() == OwnControl(delegate()).owner(), "only delegate owner");
_;
}
function __BaseSFTConcrete_init() internal onlyInitializing {
__SFTConcreteControl_init();
}
function isSlotValid(uint256 slot_) external view virtual override returns (bool) {
return _isSlotValid(slot_);
}
function _isSlotValid(uint256 slot_) internal view virtual returns (bool);
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IBaseSFTConcrete {
function isSlotValid(uint256 slot_) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
abstract contract AdminControl is Initializable, ContextUpgradeable {
event NewAdmin(address oldAdmin, address newAdmin);
event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);
address public admin;
address public pendingAdmin;
modifier onlyAdmin() {
require(_msgSender() == admin, "only admin");
_;
}
function __AdminControl_init(address admin_) internal onlyInitializing {
__AdminControl_init_unchained(admin_);
}
function __AdminControl_init_unchained(address admin_) internal onlyInitializing {
admin = admin_;
emit NewAdmin(address(0), admin_);
}
function setPendingAdmin(address newPendingAdmin_) external virtual onlyAdmin {
emit NewPendingAdmin(pendingAdmin, newPendingAdmin_);
pendingAdmin = newPendingAdmin_;
}
function acceptAdmin() external virtual {
require(_msgSender() == pendingAdmin, "only pending admin");
emit NewAdmin(admin, pendingAdmin);
admin = pendingAdmin;
pendingAdmin = address(0);
}
uint256[48] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ISFTConcreteControl {
event NewDelegate(address old_, address new_);
function setDelegate(address newDelegate_) external;
function delegate() external view returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./AdminControl.sol";
abstract contract OwnControl is AdminControl {
event NewOwner(address oldOwner, address newOwner);
address public owner;
modifier onlyOwner() {
require(owner == _msgSender(), "only owner");
_;
}
function __OwnControl_init(address owner_) internal onlyInitializing {
__OwnControl_init_unchained(owner_);
__AdminControl_init_unchained(_msgSender());
}
function __OwnControl_init_unchained(address owner_) internal onlyInitializing {
_setOwner(owner_);
}
function setOwnerOnlyAdmin(address newOwner_) public onlyAdmin {
_setOwner(newOwner_);
}
function _setOwner(address newOwner_) internal {
require(newOwner_ != address(0), "Owner address connot be 0");
emit NewOwner(owner, newOwner_);
owner = newOwner_;
}
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./AdminControl.sol";
import "./ISFTConcreteControl.sol";
abstract contract SFTConcreteControl is ISFTConcreteControl, AdminControl {
address private _delegate;
modifier onlyDelegate() {
require(_msgSender() == _delegate, "only delegate");
_;
}
function __SFTConcreteControl_init() internal onlyInitializing {
__AdminControl_init_unchained(_msgSender());
__SFTConcreteControl_init_unchained();
}
function __SFTConcreteControl_init_unchained() internal onlyInitializing {}
function delegate() public view override returns (address) {
return _delegate;
}
function setDelegate(address newDelegate_) external override {
if (_delegate != address(0)) {
require(_msgSender() == admin, "only admin");
}
emit NewDelegate(_delegate, newDelegate_);
_delegate = newDelegate_;
}
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library Constants {
uint32 internal constant FULL_PERCENTAGE = 10000;
uint32 internal constant SECONDS_PER_YEAR = 360 * 24 * 60 * 60;
address internal constant ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address internal constant ZERO_ADDRESS = 0x0000000000000000000000000000000000000000;
bytes32 internal constant CONTRACT_ISSUE_MARKET= "IssueMarket";
bytes32 internal constant CONTRACT_ISSUE_MARKET_PRICE_STRATEGY_MANAGER = "IMPriceStrategyManager";
bytes32 internal constant CONTRACT_ISSUE_MARKET_WHITELIST_STRATEGY_MANAGER = "IMWhitelistStrategyManager";
bytes32 internal constant CONTRACT_ISSUE_MARKET_UNDERWRITER_PROFIT_TOKEN = "IMUnderwriterProfitToken";
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
import "./IERC721Upgradeable.sol";
import "./IERC3525Upgradeable.sol";
import "./IERC721ReceiverUpgradeable.sol";
import "./IERC3525ReceiverUpgradeable.sol";
import "./extensions/IERC721EnumerableUpgradeable.sol";
import "./extensions/IERC721MetadataUpgradeable.sol";
import "./extensions/IERC3525MetadataUpgradeable.sol";
import "./periphery/interface/IERC3525MetadataDescriptorUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract ERC3525Upgradeable is Initializable, ContextUpgradeable, IERC3525MetadataUpgradeable, IERC721EnumerableUpgradeable {
using StringsUpgradeable for address;
using StringsUpgradeable for uint256;
using AddressUpgradeable for address;
using CountersUpgradeable for CountersUpgradeable.Counter;
event SetMetadataDescriptor(address indexed metadataDescriptor);
struct TokenData {
uint256 id;
uint256 slot;
uint256 balance;
address owner;
address approved;
address[] valueApprovals;
}
struct AddressData {
uint256[] ownedTokens;
mapping(uint256 => uint256) ownedTokensIndex;
mapping(address => bool) approvals;
}
string private _name;
string private _symbol;
uint8 private _decimals;
CountersUpgradeable.Counter private _tokenIdGenerator;
// id => (approval => allowance)
// @dev _approvedValues cannot be defined within TokenData, cause struct containing mappings cannot be constructed.
mapping(uint256 => mapping(address => uint256)) private _approvedValues;
TokenData[] private _allTokens;
// key: id
mapping(uint256 => uint256) private _allTokensIndex;
mapping(address => AddressData) private _addressData;
IERC3525MetadataDescriptorUpgradeable public metadataDescriptor;
function __ERC3525_init(string memory name_, string memory symbol_, uint8 decimals_) internal onlyInitializing {
__ERC3525_init_unchained(name_, symbol_, decimals_);
}
function __ERC3525_init_unchained(string memory name_, string memory symbol_, uint8 decimals_) internal onlyInitializing {
_name = name_;
_symbol = symbol_;
_decimals = decimals_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == type(IERC165Upgradeable).interfaceId ||
interfaceId == type(IERC3525Upgradeable).interfaceId ||
interfaceId == type(IERC721Upgradeable).interfaceId ||
interfaceId == type(IERC3525MetadataUpgradeable).interfaceId ||
interfaceId == type(IERC721EnumerableUpgradeable).interfaceId ||
interfaceId == type(IERC721MetadataUpgradeable).interfaceId;
}
/**
* @dev Returns the token collection name.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the token collection symbol.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals the token uses for value.
*/
function valueDecimals() public view virtual override returns (uint8) {
return _decimals;
}
function balanceOf(uint256 tokenId_) public view virtual override returns (uint256) {
_requireMinted(tokenId_);
return _allTokens[_allTokensIndex[tokenId_]].balance;
}
function ownerOf(uint256 tokenId_) public view virtual override returns (address owner_) {
_requireMinted(tokenId_);
owner_ = _allTokens[_allTokensIndex[tokenId_]].owner;
require(owner_ != address(0), "ERC3525: invalid token ID");
}
function slotOf(uint256 tokenId_) public view virtual override returns (uint256) {
_requireMinted(tokenId_);
return _allTokens[_allTokensIndex[tokenId_]].slot;
}
function _baseURI() internal view virtual returns (string memory) {
return "";
}
function contractURI() public view virtual override returns (string memory) {
string memory baseURI = _baseURI();
return
address(metadataDescriptor) != address(0) ?
metadataDescriptor.constructContractURI() :
bytes(baseURI).length > 0 ?
string(abi.encodePacked(baseURI, "contract/", StringsUpgradeable.toHexString(address(this)))) :
"";
}
function slotURI(uint256 slot_) public view virtual override returns (string memory) {
string memory baseURI = _baseURI();
return
address(metadataDescriptor) != address(0) ?
metadataDescriptor.constructSlotURI(slot_) :
bytes(baseURI).length > 0 ?
string(abi.encodePacked(baseURI, "slot/", slot_.toString())) :
"";
}
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId_) public view virtual override returns (string memory) {
_requireMinted(tokenId_);
string memory baseURI = _baseURI();
return
address(metadataDescriptor) != address(0) ?
metadataDescriptor.constructTokenURI(tokenId_) :
bytes(baseURI).length > 0 ?
string(abi.encodePacked(baseURI, tokenId_.toString())) :
"";
}
function approve(uint256 tokenId_, address to_, uint256 value_) public payable virtual override {
address owner = ERC3525Upgradeable.ownerOf(tokenId_);
require(to_ != owner, "ERC3525: approval to current owner");
require(_isApprovedOrOwner(_msgSender(), tokenId_), "ERC3525: approve caller is not owner nor approved");
_approveValue(tokenId_, to_, value_);
}
function allowance(uint256 tokenId_, address operator_) public view virtual override returns (uint256) {
_requireMinted(tokenId_);
return _approvedValues[tokenId_][operator_];
}
function transferFrom(
uint256 fromTokenId_,
address to_,
uint256 value_
) public payable virtual override returns (uint256 newTokenId) {
_spendAllowance(_msgSender(), fromTokenId_, value_);
newTokenId = _createDerivedTokenId(fromTokenId_);
_mint(to_, newTokenId, ERC3525Upgradeable.slotOf(fromTokenId_), 0);
_transferValue(fromTokenId_, newTokenId, value_);
}
function transferFrom(
uint256 fromTokenId_,
uint256 toTokenId_,
uint256 value_
) public payable virtual override {
_spendAllowance(_msgSender(), fromTokenId_, value_);
_transferValue(fromTokenId_, toTokenId_, value_);
}
function balanceOf(address owner_) public view virtual override returns (uint256 balance) {
require(owner_ != address(0), "ERC3525: balance query for the zero address");
return _addressData[owner_].ownedTokens.length;
}
function transferFrom(
address from_,
address to_,
uint256 tokenId_
) public payable virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId_), "ERC3525: transfer caller is not owner nor approved");
_transferTokenId(from_, to_, tokenId_);
}
function safeTransferFrom(
address from_,
address to_,
uint256 tokenId_,
bytes memory data_
) public payable virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId_), "ERC3525: transfer caller is not owner nor approved");
_safeTransferTokenId(from_, to_, tokenId_, data_);
}
function safeTransferFrom(
address from_,
address to_,
uint256 tokenId_
) public payable virtual override {
safeTransferFrom(from_, to_, tokenId_, "");
}
function approve(address to_, uint256 tokenId_) public payable virtual override {
address owner = ERC3525Upgradeable.ownerOf(tokenId_);
require(to_ != owner, "ERC3525: approval to current owner");
require(
_msgSender() == owner || ERC3525Upgradeable.isApprovedForAll(owner, _msgSender()),
"ERC3525: approve caller is not owner nor approved for all"
);
_approve(to_, tokenId_);
}
function getApproved(uint256 tokenId_) public view virtual override returns (address) {
_requireMinted(tokenId_);
return _allTokens[_allTokensIndex[tokenId_]].approved;
}
function setApprovalForAll(address operator_, bool approved_) public virtual override {
_setApprovalForAll(_msgSender(), operator_, approved_);
}
function isApprovedForAll(address owner_, address operator_) public view virtual override returns (bool) {
return _addressData[owner_].approvals[operator_];
}
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
function tokenByIndex(uint256 index_) public view virtual override returns (uint256) {
require(index_ < ERC3525Upgradeable.totalSupply(), "ERC3525: global index out of bounds");
return _allTokens[index_].id;
}
function tokenOfOwnerByIndex(address owner_, uint256 index_) public view virtual override returns (uint256) {
require(index_ < ERC3525Upgradeable.balanceOf(owner_), "ERC3525: owner index out of bounds");
return _addressData[owner_].ownedTokens[index_];
}
function _setApprovalForAll(
address owner_,
address operator_,
bool approved_
) internal virtual {
require(owner_ != operator_, "ERC3525: approve to caller");
_addressData[owner_].approvals[operator_] = approved_;
emit ApprovalForAll(owner_, operator_, approved_);
}
function _isApprovedOrOwner(address operator_, uint256 tokenId_) internal view virtual returns (bool) {
address owner = ERC3525Upgradeable.ownerOf(tokenId_);
return (
operator_ == owner ||
ERC3525Upgradeable.isApprovedForAll(owner, operator_) ||
ERC3525Upgradeable.getApproved(tokenId_) == operator_
);
}
function _spendAllowance(address operator_, uint256 tokenId_, uint256 value_) internal virtual {
uint256 currentAllowance = ERC3525Upgradeable.allowance(tokenId_, operator_);
if (!_isApprovedOrOwner(operator_, tokenId_) && currentAllowance != type(uint256).max) {
require(currentAllowance >= value_, "ERC3525: insufficient allowance");
_approveValue(tokenId_, operator_, currentAllowance - value_);
}
}
function _exists(uint256 tokenId_) internal view virtual returns (bool) {
return _allTokens.length != 0 && _allTokens[_allTokensIndex[tokenId_]].id == tokenId_;
}
function _requireMinted(uint256 tokenId_) internal view virtual {
require(_exists(tokenId_), "ERC3525: invalid token ID");
}
function _mint(address to_, uint256 slot_, uint256 value_) internal virtual returns (uint256 tokenId) {
tokenId = _createOriginalTokenId();
_mint(to_, tokenId, slot_, value_);
}
function _mint(address to_, uint256 tokenId_, uint256 slot_, uint256 value_) internal virtual {
require(to_ != address(0), "ERC3525: mint to the zero address");
require(tokenId_ != 0, "ERC3525: cannot mint zero tokenId");
require(!_exists(tokenId_), "ERC3525: token already minted");
_beforeValueTransfer(address(0), to_, 0, tokenId_, slot_, value_);
__mintToken(to_, tokenId_, slot_);
__mintValue(tokenId_, value_);
_afterValueTransfer(address(0), to_, 0, tokenId_, slot_, value_);
}
function _mintValue(uint256 tokenId_, uint256 value_) internal virtual {
address owner = ERC3525Upgradeable.ownerOf(tokenId_);
uint256 slot = ERC3525Upgradeable.slotOf(tokenId_);
_beforeValueTransfer(address(0), owner, 0, tokenId_, slot, value_);
__mintValue(tokenId_, value_);
_afterValueTransfer(address(0), owner, 0, tokenId_, slot, value_);
}
function __mintValue(uint256 tokenId_, uint256 value_) private {
_allTokens[_allTokensIndex[tokenId_]].balance += value_;
emit TransferValue(0, tokenId_, value_);
}
function __mintToken(address to_, uint256 tokenId_, uint256 slot_) private {
TokenData memory tokenData = TokenData({
id: tokenId_,
slot: slot_,
balance: 0,
owner: to_,
approved: address(0),
valueApprovals: new address[](0)
});
_addTokenToAllTokensEnumeration(tokenData);
_addTokenToOwnerEnumeration(to_, tokenId_);
emit Transfer(address(0), to_, tokenId_);
emit SlotChanged(tokenId_, 0, slot_);
}
function _burn(uint256 tokenId_) internal virtual {
_requireMinted(tokenId_);
TokenData storage tokenData = _allTokens[_allTokensIndex[tokenId_]];
address owner = tokenData.owner;
uint256 slot = tokenData.slot;
uint256 value = tokenData.balance;
_beforeValueTransfer(owner, address(0), tokenId_, 0, slot, value);
_clearApprovedValues(tokenId_);
_removeTokenFromOwnerEnumeration(owner, tokenId_);
_removeTokenFromAllTokensEnumeration(tokenId_);
emit TransferValue(tokenId_, 0, value);
emit SlotChanged(tokenId_, slot, 0);
emit Transfer(owner, address(0), tokenId_);
_afterValueTransfer(owner, address(0), tokenId_, 0, slot, value);
}
function _burnValue(uint256 tokenId_, uint256 burnValue_) internal virtual {
_requireMinted(tokenId_);
TokenData storage tokenData = _allTokens[_allTokensIndex[tokenId_]];
address owner = tokenData.owner;
uint256 slot = tokenData.slot;
uint256 value = tokenData.balance;
require(value >= burnValue_, "ERC3525: burn value exceeds balance");
_beforeValueTransfer(owner, address(0), tokenId_, 0, slot, burnValue_);
tokenData.balance -= burnValue_;
emit TransferValue(tokenId_, 0, burnValue_);
_afterValueTransfer(owner, address(0), tokenId_, 0, slot, burnValue_);
}
function _addTokenToOwnerEnumeration(address to_, uint256 tokenId_) private {
_allTokens[_allTokensIndex[tokenId_]].owner = to_;
_addressData[to_].ownedTokensIndex[tokenId_] = _addressData[to_].ownedTokens.length;
_addressData[to_].ownedTokens.push(tokenId_);
}
function _removeTokenFromOwnerEnumeration(address from_, uint256 tokenId_) private {
_allTokens[_allTokensIndex[tokenId_]].owner = address(0);
AddressData storage ownerData = _addressData[from_];
uint256 lastTokenIndex = ownerData.ownedTokens.length - 1;
uint256 lastTokenId = ownerData.ownedTokens[lastTokenIndex];
uint256 tokenIndex = ownerData.ownedTokensIndex[tokenId_];
ownerData.ownedTokens[tokenIndex] = lastTokenId;
ownerData.ownedTokensIndex[lastTokenId] = tokenIndex;
delete ownerData.ownedTokensIndex[tokenId_];
ownerData.ownedTokens.pop();
}
function _addTokenToAllTokensEnumeration(TokenData memory tokenData_) private {
_allTokensIndex[tokenData_.id] = _allTokens.length;
_allTokens.push(tokenData_);
}
function _removeTokenFromAllTokensEnumeration(uint256 tokenId_) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId_];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
TokenData memory lastTokenData = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenData; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenData.id] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId_];
_allTokens.pop();
}
function _approve(address to_, uint256 tokenId_) internal virtual {
_allTokens[_allTokensIndex[tokenId_]].approved = to_;
emit Approval(ERC3525Upgradeable.ownerOf(tokenId_), to_, tokenId_);
}
function _approveValue(
uint256 tokenId_,
address to_,
uint256 value_
) internal virtual {
require(to_ != address(0), "ERC3525: approve value to the zero address");
if (!_existApproveValue(to_, tokenId_)) {
_allTokens[_allTokensIndex[tokenId_]].valueApprovals.push(to_);
}
_approvedValues[tokenId_][to_] = value_;
emit ApprovalValue(tokenId_, to_, value_);
}
function _clearApprovedValues(uint256 tokenId_) internal virtual {
TokenData storage tokenData = _allTokens[_allTokensIndex[tokenId_]];
uint256 length = tokenData.valueApprovals.length;
for (uint256 i = 0; i < length; i++) {
address approval = tokenData.valueApprovals[i];
delete _approvedValues[tokenId_][approval];
}
delete tokenData.valueApprovals;
}
function _existApproveValue(address to_, uint256 tokenId_) internal view virtual returns (bool) {
uint256 length = _allTokens[_allTokensIndex[tokenId_]].valueApprovals.length;
for (uint256 i = 0; i < length; i++) {
if (_allTokens[_allTokensIndex[tokenId_]].valueApprovals[i] == to_) {
return true;
}
}
return false;
}
function _transferValue(
uint256 fromTokenId_,
uint256 toTokenId_,
uint256 value_
) internal virtual {
require(_exists(fromTokenId_), "ERC3525: transfer from invalid token ID");
require(_exists(toTokenId_), "ERC3525: transfer to invalid token ID");
TokenData storage fromTokenData = _allTokens[_allTokensIndex[fromTokenId_]];
TokenData storage toTokenData = _allTokens[_allTokensIndex[toTokenId_]];
require(fromTokenData.balance >= value_, "ERC3525: insufficient balance for transfer");
require(fromTokenData.slot == toTokenData.slot, "ERC3525: transfer to token with different slot");
_beforeValueTransfer(
fromTokenData.owner,
toTokenData.owner,
fromTokenId_,
toTokenId_,
fromTokenData.slot,
value_
);
fromTokenData.balance -= value_;
toTokenData.balance += value_;
emit TransferValue(fromTokenId_, toTokenId_, value_);
_afterValueTransfer(
fromTokenData.owner,
toTokenData.owner,
fromTokenId_,
toTokenId_,
fromTokenData.slot,
value_
);
require(
_checkOnERC3525Received(fromTokenId_, toTokenId_, value_, ""),
"ERC3525: transfer rejected by ERC3525Receiver"
);
}
function _transferTokenId(
address from_,
address to_,
uint256 tokenId_
) internal virtual {
require(ERC3525Upgradeable.ownerOf(tokenId_) == from_, "ERC3525: transfer from invalid owner");
require(to_ != address(0), "ERC3525: transfer to the zero address");
uint256 slot = ERC3525Upgradeable.slotOf(tokenId_);
uint256 value = ERC3525Upgradeable.balanceOf(tokenId_);
_beforeValueTransfer(from_, to_, tokenId_, tokenId_, slot, value);
_approve(address(0), tokenId_);
_clearApprovedValues(tokenId_);
_removeTokenFromOwnerEnumeration(from_, tokenId_);
_addTokenToOwnerEnumeration(to_, tokenId_);
emit Transfer(from_, to_, tokenId_);
_afterValueTransfer(from_, to_, tokenId_, tokenId_, slot, value);
}
function _safeTransferTokenId(
address from_,
address to_,
uint256 tokenId_,
bytes memory data_
) internal virtual {
_transferTokenId(from_, to_, tokenId_);
require(
_checkOnERC721Received(from_, to_, tokenId_, data_),
"ERC3525: transfer to non ERC721Receiver"
);
}
function _checkOnERC3525Received(
uint256 fromTokenId_,
uint256 toTokenId_,
uint256 value_,
bytes memory data_
) internal virtual returns (bool) {
address to = ERC3525Upgradeable.ownerOf(toTokenId_);
if (to.isContract()) {
try IERC165Upgradeable(to).supportsInterface(type(IERC3525ReceiverUpgradeable).interfaceId) returns (bool retval) {
if (retval) {
bytes4 receivedVal = IERC3525ReceiverUpgradeable(to).onERC3525Received(_msgSender(), fromTokenId_, toTokenId_, value_, data_);
return receivedVal == IERC3525ReceiverUpgradeable.onERC3525Received.selector;
} else {
return true;
}
} catch (bytes memory /** reason */) {
return true;
}
} else {
return true;
}
}
/**
* @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 {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/* solhint-disable */
function _beforeValueTransfer(
address from_,
address to_,
uint256 fromTokenId_,
uint256 toTokenId_,
uint256 slot_,
uint256 value_
) internal virtual {}
function _afterValueTransfer(
address from_,
address to_,
uint256 fromTokenId_,
uint256 toTokenId_,
uint256 slot_,
uint256 value_
) internal virtual {}
/* solhint-enable */
function _setMetadataDescriptor(address metadataDescriptor_) internal virtual {
metadataDescriptor = IERC3525MetadataDescriptorUpgradeable(metadataDescriptor_);
emit SetMetadataDescriptor(metadataDescriptor_);
}
function _createOriginalTokenId() internal virtual returns (uint256) {
_tokenIdGenerator.increment();
return _tokenIdGenerator.current();
}
function _createDerivedTokenId(uint256 fromTokenId_) internal virtual returns (uint256) {
fromTokenId_;
return _createOriginalTokenId();
}
/**
* @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[41] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
import "../IERC3525Upgradeable.sol";
import "./IERC721MetadataUpgradeable.sol";
/**
* @title ERC-3525 Semi-Fungible Token Standard, optional extension for metadata
* @dev Interfaces for any contract that wants to support query of the Uniform Resource Identifier
* (URI) for the ERC3525 contract as well as a specified slot.
* Because of the higher reliability of data stored in smart contracts compared to data stored in
* centralized systems, it is recommended that metadata, including `contractURI`, `slotURI` and
* `tokenURI`, be directly returned in JSON format, instead of being returned with a url pointing
* to any resource stored in a centralized system.
* See https://eips.ethereum.org/EIPS/eip-3525
* Note: the ERC-165 identifier for this interface is 0xe1600902.
*/
interface IERC3525MetadataUpgradeable is IERC3525Upgradeable, IERC721MetadataUpgradeable {
/**
* @notice Returns the Uniform Resource Identifier (URI) for the current ERC3525 contract.
* @dev This function SHOULD return the URI for this contract in JSON format, starting with
* header `data:application/json;`.
* See https://eips.ethereum.org/EIPS/eip-3525 for the JSON schema for contract URI.
* @return The JSON formatted URI of the current ERC3525 contract
*/
function contractURI() external view returns (string memory);
/**
* @notice Returns the Uniform Resource Identifier (URI) for the specified slot.
* @dev This function SHOULD return the URI for `_slot` in JSON format, starting with header
* `data:application/json;`.
* See https://eips.ethereum.org/EIPS/eip-3525 for the JSON schema for slot URI.
* @return The JSON formatted URI of `_slot`
*/
function slotURI(uint256 _slot) external view returns (string memory);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
import "../IERC721Upgradeable.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
* Note: the ERC-165 identifier for this interface is 0x780e9d63.
*/
interface IERC721EnumerableUpgradeable is IERC721Upgradeable {
/**
* @notice Count NFTs tracked by this contract
* @return A count of valid NFTs tracked by this contract, where each one of
* them has an assigned and queryable owner not equal to the zero address
*/
function totalSupply() external view returns (uint256);
/**
* @notice Enumerate valid NFTs
* @dev Throws if `_index` >= `totalSupply()`.
* @param _index A counter less than `totalSupply()`
* @return The token identifier for the `_index`th NFT,
* (sort order not specified)
*/
function tokenByIndex(uint256 _index) external view returns (uint256);
/**
* @notice Enumerate NFTs assigned to an owner
* @dev Throws if `_index` >= `balanceOf(_owner)` or if
* `_owner` is the zero address, representing invalid NFTs.
* @param _owner An address where we are interested in NFTs owned by them
* @param _index A counter less than `balanceOf(_owner)`
* @return The token identifier for the `_index`th NFT assigned to `_owner`,
* (sort order not specified)
*/
function tokenOfOwnerByIndex(address _owner, uint256 _index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
import "../IERC721Upgradeable.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
* Note: the ERC-165 identifier for this interface is 0x5b5e139f.
*/
interface IERC721MetadataUpgradeable is IERC721Upgradeable {
/**
* @notice A descriptive name for a collection of NFTs in this contract
*/
function name() external view returns (string memory);
/**
* @notice An abbreviated name for NFTs in this contract
*/
function symbol() external view returns (string memory);
/**
* @notice A distinct Uniform Resource Identifier (URI) for a given asset.
* @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
* 3986. The URI may point to a JSON file that conforms to the "ERC721
* Metadata JSON Schema".
*/
function tokenURI(uint256 _tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
/**
* @title EIP-3525 token receiver interface
* @dev Interface for a smart contract that wants to be informed by EIP-3525 contracts when
* receiving values from ANY addresses or EIP-3525 tokens.
* Note: the EIP-165 identifier for this interface is 0x009ce20b.
*/
interface IERC3525ReceiverUpgradeable {
/**
* @notice Handle the receipt of an EIP-3525 token value.
* @dev An EIP-3525 smart contract MUST check whether this function is implemented by the
* recipient contract, if the recipient contract implements this function, the EIP-3525
* contract MUST call this function after a value transfer (i.e. `transferFrom(uint256,
* uint256,uint256,bytes)`).
* MUST return 0x009ce20b (i.e. `bytes4(keccak256('onERC3525Received(address,uint256,uint256,
* uint256,bytes)'))`) if the transfer is accepted.
* MUST revert or return any value other than 0x009ce20b if the transfer is rejected.
* @param _operator The address which triggered the transfer
* @param _fromTokenId The token id to transfer value from
* @param _toTokenId The token id to transfer value to
* @param _value The transferred value
* @param _data Additional data with no specified format
* @return `bytes4(keccak256('onERC3525Received(address,uint256,uint256,uint256,bytes)'))`
* unless the transfer is rejected.
*/
function onERC3525Received(address _operator, uint256 _fromTokenId, uint256 _toTokenId, uint256 _value, bytes calldata _data) external returns (bytes4);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";
import "./IERC721Upgradeable.sol";
/**
* @title ERC-3525 Semi-Fungible Token Standard
* @dev See https://eips.ethereum.org/EIPS/eip-3525
* Note: the ERC-165 identifier for this interface is 0xd5358140.
*/
interface IERC3525Upgradeable is IERC165Upgradeable, IERC721Upgradeable {
/**
* @dev MUST emit when value of a token is transferred to another token with the same slot,
* including zero value transfers (_value == 0) as well as transfers when tokens are created
* (`_fromTokenId` == 0) or destroyed (`_toTokenId` == 0).
* @param _fromTokenId The token id to transfer value from
* @param _toTokenId The token id to transfer value to
* @param _value The transferred value
*/
event TransferValue(uint256 indexed _fromTokenId, uint256 indexed _toTokenId, uint256 _value);
/**
* @dev MUST emits when the approval value of a token is set or changed.
* @param _tokenId The token to approve
* @param _operator The operator to approve for
* @param _value The maximum value that `_operator` is allowed to manage
*/
event ApprovalValue(uint256 indexed _tokenId, address indexed _operator, uint256 _value);
/**
* @dev MUST emit when the slot of a token is set or changed.
* @param _tokenId The token of which slot is set or changed
* @param _oldSlot The previous slot of the token
* @param _newSlot The updated slot of the token
*/
event SlotChanged(uint256 indexed _tokenId, uint256 indexed _oldSlot, uint256 indexed _newSlot);
/**
* @notice Get the number of decimals the token uses for value - e.g. 6, means the user
* representation of the value of a token can be calculated by dividing it by 1,000,000.
* Considering the compatibility with third-party wallets, this function is defined as
* `valueDecimals()` instead of `decimals()` to avoid conflict with ERC20 tokens.
* @return The number of decimals for value
*/
function valueDecimals() external view returns (uint8);
/**
* @notice Get the value of a token.
* @param _tokenId The token for which to query the balance
* @return The value of `_tokenId`
*/
function balanceOf(uint256 _tokenId) external view returns (uint256);
/**
* @notice Get the slot of a token.
* @param _tokenId The identifier for a token
* @return The slot of the token
*/
function slotOf(uint256 _tokenId) external view returns (uint256);
/**
* @notice Allow an operator to manage the value of a token, up to the `_value` amount.
* @dev MUST revert unless caller is the current owner, an authorized operator, or the approved
* address for `_tokenId`.
* MUST emit ApprovalValue event.
* @param _tokenId The token to approve
* @param _operator The operator to be approved
* @param _value The maximum value of `_toTokenId` that `_operator` is allowed to manage
*/
function approve(
uint256 _tokenId,
address _operator,
uint256 _value
) external payable;
/**
* @notice Get the maximum value of a token that an operator is allowed to manage.
* @param _tokenId The token for which to query the allowance
* @param _operator The address of an operator
* @return The current approval value of `_tokenId` that `_operator` is allowed to manage
*/
function allowance(uint256 _tokenId, address _operator) external view returns (uint256);
/**
* @notice Transfer value from a specified token to another specified token with the same slot.
* @dev Caller MUST be the current owner, an authorized operator or an operator who has been
* approved the whole `_fromTokenId` or part of it.
* MUST revert if `_fromTokenId` or `_toTokenId` is zero token id or does not exist.
* MUST revert if slots of `_fromTokenId` and `_toTokenId` do not match.
* MUST revert if `_value` exceeds the balance of `_fromTokenId` or its allowance to the
* operator.
* MUST emit `TransferValue` event.
* @param _fromTokenId The token to transfer value from
* @param _toTokenId The token to transfer value to
* @param _value The transferred value
*/
function transferFrom(
uint256 _fromTokenId,
uint256 _toTokenId,
uint256 _value
) external payable;
/**
* @notice Transfer value from a specified token to an address. The caller should confirm that
* `_to` is capable of receiving ERC3525 tokens.
* @dev This function MUST create a new ERC3525 token with the same slot for `_to` to receive
* the transferred value.
* MUST revert if `_fromTokenId` is zero token id or does not exist.
* MUST revert if `_to` is zero address.
* MUST revert if `_value` exceeds the balance of `_fromTokenId` or its allowance to the
* operator.
* MUST emit `Transfer` and `TransferValue` events.
* @param _fromTokenId The token to transfer value from
* @param _to The address to transfer value to
* @param _value The transferred value
* @return ID of the new token created for `_to` which receives the transferred value
*/
function transferFrom(
uint256 _fromTokenId,
address _to,
uint256 _value
) external payable returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers from ERC721 asset contracts.
* Note: the ERC-165 identifier for this interface is 0x150b7a02.
*/
interface IERC721ReceiverUpgradeable {
/**
* @notice Handle the receipt of an NFT
* @dev The ERC721 smart contract calls this function on the recipient
* after a `transfer`. This function MAY throw to revert and reject the
* transfer. Return of other than the magic value MUST result in the
* transaction being reverted.
* Note: the contract address is always the message sender.
* @param _operator The address which called `safeTransferFrom` function
* @param _from The address which previously owned the token
* @param _tokenId The NFT identifier which is being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
* unless throwing
*/
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes calldata _data
) external returns(bytes4);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
import "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";
/**
* @title ERC-721 Non-Fungible Token Standard
* @dev See https://eips.ethereum.org/EIPS/eip-721
* Note: the ERC-165 identifier for this interface is 0x80ac58cd.
*/
interface IERC721Upgradeable is IERC165Upgradeable {
/**
* @dev This emits when ownership of any NFT changes by any mechanism.
* This event emits when NFTs are created (`from` == 0) and destroyed
* (`to` == 0). Exception: during contract creation, any number of NFTs
* may be created and assigned without emitting Transfer. At the time of
* any transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
/**
* @dev This emits when the approved address for an NFT is changed or
* reaffirmed. The zero address indicates there is no approved address.
* When a Transfer event emits, this also indicates that the approved
* address for that NFT (if any) is reset to none.
*/
event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
/**
* @dev This emits when an operator is enabled or disabled for an owner.
* The operator can manage all NFTs of the owner.
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/**
* @notice Count all NFTs assigned to an owner
* @dev NFTs assigned to the zero address are considered invalid, and this
* function throws for queries about the zero address.
* @param _owner An address for whom to query the balance
* @return The number of NFTs owned by `_owner`, possibly zero
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT
* @dev NFTs assigned to zero address are considered invalid, and queries
* about them do throw.
* @param _tokenId The identifier for an NFT
* @return The address of the owner of the NFT
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Transfers the ownership of an NFT from one address to another address
* @dev Throws unless `msg.sender` is the current owner, an authorized
* operator, or the approved address for this NFT. Throws if `_from` is
* not the current owner. Throws if `_to` is the zero address. Throws if
* `_tokenId` is not a valid NFT. When transfer is complete, this function
* checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
* @param _from The current owner of the NFT
* @param _to The new owner
* @param _tokenId The NFT to transfer
* @param data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes calldata data) external payable;
/**
* @notice Transfers the ownership of an NFT from one address to another address
* @dev This works identically to the other function with an extra data parameter,
* except this function just sets data to "".
* @param _from The current owner of the NFT
* @param _to The new owner
* @param _tokenId The NFT to transfer
*/
function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
/**
* @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
* TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE
* THEY MAY BE PERMANENTLY LOST
* @dev Throws unless `msg.sender` is the current owner, an authorized
* operator, or the approved address for this NFT. Throws if `_from` is
* not the current owner. Throws if `_to` is the zero address. Throws if
* `_tokenId` is not a valid NFT.
* @param _from The current owner of the NFT
* @param _to The new owner
* @param _tokenId The NFT to transfer
*/
function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
/**
* @notice Change or reaffirm the approved address for an NFT
* @dev The zero address indicates there is no approved address.
* Throws unless `msg.sender` is the current NFT owner, or an authorized
* operator of the current owner.
* @param _approved The new approved NFT controller
* @param _tokenId The NFT to approve
*/
function approve(address _approved, uint256 _tokenId) external payable;
/**
* @notice Enable or disable approval for a third party ("operator") to manage
* all of `msg.sender`'s assets
* @dev Emits the ApprovalForAll event. The contract MUST allow
* multiple operators per owner.
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @notice Get the approved address for a single NFT
* @dev Throws if `_tokenId` is not a valid NFT.
* @param _tokenId The NFT to find the approved address for
* @return The approved address for this NFT, or the zero address if there is none
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address
* @param _owner The address that owns the NFTs
* @param _operator The address that acts on behalf of the owner
* @return True if `_operator` is an approved operator for `_owner`, false otherwise
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC3525MetadataDescriptorUpgradeable {
function constructContractURI() external view returns (string memory);
function constructSlotURI(uint256 slot) external view returns (string memory);
function constructTokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IOpenFundRedemptionConcrete {
struct RedeemInfo {
bytes32 poolId;
address currency;
uint256 createTime;
uint256 nav;
}
function setRedeemNavOnlyDelegate(uint256 slot_, uint256 nav_) external;
function getRedeemInfo(uint256 slot_) external view returns (RedeemInfo memory);
function getRedeemNav(uint256 slot_) external view returns (uint256);
function getRedemptionFeeRate(uint256 slot_) external view returns (uint256);
function redemptionFeeReceiver() external view returns (address);
}{
"optimizer": {
"enabled": true,
"runs": 1
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"NewAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"old_","type":"address"},{"indexed":false,"internalType":"address","name":"new_","type":"address"}],"name":"NewDelegate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldPendingAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newPendingAdmin","type":"address"}],"name":"NewPendingAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"redemptionFeeReceiver","type":"address"}],"name":"SetRedemptionFeeReceiver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"redemptionFeeRate","type":"uint256"}],"name":"SetRedemtpionFeeRate","type":"event"},{"inputs":[],"name":"acceptAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"allocatedCurrencyBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId_","type":"uint256"},{"internalType":"uint256","name":"burnValue_","type":"uint256"}],"name":"burnOnlyDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId_","type":"uint256"},{"internalType":"uint256","name":"slot_","type":"uint256"},{"internalType":"address","name":"currency_","type":"address"},{"internalType":"uint256","name":"claimValue_","type":"uint256"}],"name":"claimOnlyDelegate","outputs":[{"internalType":"uint256","name":"claimCurrencyAmount_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId_","type":"uint256"}],"name":"claimableValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"txSender_","type":"address"},{"internalType":"bytes","name":"inputSlotInfo_","type":"bytes"}],"name":"createSlotOnlyDelegate","outputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"delegate","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"name":"getRedeemInfo","outputs":[{"components":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"createTime","type":"uint256"},{"internalType":"uint256","name":"nav","type":"uint256"}],"internalType":"struct IOpenFundRedemptionConcrete.RedeemInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"name":"getRedeemNav","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"name":"getRedemptionFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"name":"isSlotValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"slot_","type":"uint256"},{"internalType":"uint256","name":"mintValue_","type":"uint256"}],"name":"mintOnlyDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"txSender_","type":"address"},{"internalType":"address","name":"currency_","type":"address"},{"internalType":"address","name":"mintTo_","type":"address"},{"internalType":"uint256","name":"slot_","type":"uint256"},{"internalType":"uint256","name":"tokenId_","type":"uint256"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"mintOnlyDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pendingAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"redemptionFeeRates","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redemptionFeeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"},{"internalType":"address","name":"currency_","type":"address"}],"name":"refundOnlyDelegate","outputs":[{"internalType":"uint256","name":"refundableCurrencyAmount_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"txSender_","type":"address"},{"internalType":"uint256","name":"slot_","type":"uint256"},{"internalType":"address","name":"currency_","type":"address"},{"internalType":"uint256","name":"repayCurrencyAmount_","type":"uint256"}],"name":"repayOnlyDelegate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"txSender_","type":"address"},{"internalType":"uint256","name":"slot_","type":"uint256"},{"internalType":"address","name":"currency_","type":"address"},{"internalType":"uint256","name":"repayCurrencyAmount_","type":"uint256"}],"name":"repayWithBalanceOnlyDelegate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newDelegate_","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newPendingAdmin_","type":"address"}],"name":"setPendingAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"},{"internalType":"uint256","name":"nav_","type":"uint256"}],"name":"setRedeemNavOnlyDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"poolId_","type":"bytes32"},{"internalType":"uint256","name":"redemptionFeeRate_","type":"uint256"}],"name":"setRedemptionFeeRateOnlyAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"redemptionFeeReceiver_","type":"address"}],"name":"setRedemptionFeeReceiverOnlyAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"name":"slotCurrencyBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"name":"slotInitialValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"name":"slotRepaidCurrencyAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot_","type":"uint256"}],"name":"slotTotalValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"fromTokenId_","type":"uint256"},{"internalType":"uint256","name":"toTokenId_","type":"uint256"},{"internalType":"uint256","name":"fromTokenBalance_","type":"uint256"},{"internalType":"uint256","name":"transferValue_","type":"uint256"}],"name":"transferOnlyDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b5061001961001e565b6100de565b600054610100900460ff161561008a5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff90811610156100dc576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b61201c806100ed6000396000f3fe6080604052600436106101685760003560e01c80630e18b6811461016d578063243532e11461018457806326782247146101a4578063302b586a146101da57806335f28fa5146101fa5780633b2f48301461021a578063492e38791461022d5780634dd18bf5146102695780634f0b5d7e1461028957806356b04045146102b757806369e489ea146102d75780637d853562146102f75780638129fc1c1461031757806389197e231461032c5780638b52d6681461034c578063915530891461037c5780639a9ab07e146103b8578063a6a978d8146103d8578063a9592997146103eb578063abab3eab1461040c578063c15a4e691461043a578063c89e43611461045a578063ca5eb5e11461046f578063cc7ec17a1461048f578063dae85ba3146104af578063dc296b12146104cf578063e8e99b9714610593578063f29af2da146105b3578063f31b3b8c146105e1578063f70654ce14610601578063f851a44014610621575b600080fd5b34801561017957600080fd5b50610182610641565b005b34801561019057600080fd5b5061018261019f366004611a40565b6106fe565b3480156101b057600080fd5b506034546101c4906001600160a01b031681565b6040516101d19190611a5d565b60405180910390f35b3480156101e657600080fd5b506101826101f5366004611a71565b61077c565b34801561020657600080fd5b50610182610215366004611aa3565b6107b5565b610182610228366004611acf565b610838565b34801561023957600080fd5b5061025b610248366004611b17565b600090815261012f602052604090205490565b6040519081526020016101d1565b34801561027557600080fd5b50610182610284366004611a40565b6109f1565b34801561029557600080fd5b5061025b6102a4366004611b17565b6101606020526000908152604090205481565b3480156102c357600080fd5b5061025b6102d2366004611b17565b610a8d565b3480156102e357600080fd5b5061025b6102f2366004611b30565b610c92565b34801561030357600080fd5b50610182610312366004611b60565b610e5e565b34801561032357600080fd5b50610182610ee3565b34801561033857600080fd5b50610182610347366004611b82565b610ff5565b34801561035857600080fd5b5061036c610367366004611b17565b61103e565b60405190151581526020016101d1565b34801561038857600080fd5b5061025b610397366004611b17565b600090815261015e6020908152604080832054835261016090915290205490565b3480156103c457600080fd5b5061025b6103d3366004611b17565b61104f565b6101826103e6366004611acf565b611065565b3480156103f757600080fd5b5061015f546101c4906001600160a01b031681565b34801561041857600080fd5b5061025b610427366004611a40565b61012e6020526000908152604090205481565b34801561044657600080fd5b5061025b610455366004611b17565b611123565b34801561046657600080fd5b506101c4611139565b34801561047b57600080fd5b5061018261048a366004611a40565b611148565b34801561049b57600080fd5b506101826104aa366004611b60565b6111f5565b3480156104bb57600080fd5b5061025b6104ca366004611be7565b611236565b3480156104db57600080fd5b506105576104ea366004611b17565b604080516080808201835260008083526020808401829052838501829052606093840182905294815261015e8552839020835191820184528054825260018101546001600160a01b0316948201949094526002840154928101929092526003909201549181019190915290565b6040516101d19190815181526020808301516001600160a01b031690820152604080830151908201526060918201519181019190915260800190565b34801561059f57600080fd5b5061025b6105ae366004611b17565b61130f565b3480156105bf57600080fd5b5061025b6105ce366004611b17565b600090815261012d602052604090205490565b3480156105ed57600080fd5b5061025b6105fc366004611c6b565b611325565b34801561060d57600080fd5b5061018261061c366004611b60565b61155b565b34801561062d57600080fd5b506033546101c4906001600160a01b031681565b6034546001600160a01b0316336001600160a01b03161461069e5760405162461bcd60e51b815260206004820152601260248201527137b7363c903832b73234b7339030b236b4b760711b60448201526064015b60405180910390fd5b603354603454604051600080516020611fc7833981519152926106cf926001600160a01b0391821692911690611c9a565b60405180910390a160348054603380546001600160a01b03199081166001600160a01b03841617909155169055565b6033546001600160a01b0316336001600160a01b0316146107315760405162461bcd60e51b815260040161069590611cb4565b61015f80546001600160a01b0319166001600160a01b0383169081179091556040517f44aa4fcfe009dfd02b84beba2b2a2553af09af75408d082879f29b5a24f5db2890600090a250565b6065546001600160a01b0316336001600160a01b0316146107af5760405162461bcd60e51b815260040161069590611cd8565b50505050565b6065546001600160a01b0316336001600160a01b0316146107e85760405162461bcd60e51b815260040161069590611cd8565b600082815261012f602052604081208054839290610807908490611d15565b9091555050600082815261012f60205260408120600101805483929061082e908490611d15565b9091555050505050565b6065546001600160a01b0316336001600160a01b03161461086b5760405162461bcd60e51b815260040161069590611cd8565b610877848484846115a4565b6000826001600160a01b03166370a08231610890611139565b6040518263ffffffff1660e01b81526004016108ac9190611a5d565b602060405180830381865afa1580156108c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ed9190611d28565b6001600160a01b038416600090815261012e60205260409020549091506109149082611d41565b8211156109715760405162461bcd60e51b815260206004820152602560248201527f464d523a20696e73756666696369656e7420756e616c6c6f63617465642062616044820152646c616e636560d81b6064820152608401610695565b600084815261012d602052604081208054849290610990908490611d15565b9091555050600084815261012d6020526040812060010180548492906109b7908490611d15565b90915550506001600160a01b038316600090815261012e6020526040812080548492906109e5908490611d15565b90915550505050505050565b6033546001600160a01b0316336001600160a01b031614610a245760405162461bcd60e51b815260040161069590611cb4565b6034546040517fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a991610a63916001600160a01b03909116908490611c9a565b60405180910390a1603480546001600160a01b0319166001600160a01b0392909216919091179055565b600080610a98611139565b6001600160a01b031663263f3e7e846040518263ffffffff1660e01b8152600401610ac591815260200190565b602060405180830381865afa158015610ae2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b069190611d28565b90506000610b12611139565b6001600160a01b0316639cc7f708856040518263ffffffff1660e01b8152600401610b3f91815260200190565b602060405180830381865afa158015610b5c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b809190611d28565b90506000610b8c611139565b6001600160a01b0316633e7e86696040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bed9190611d54565b90506000610bfa8461104f565b905080600003610c105750600095945050505050565b6000610c1d83600a611e5b565b610c278386611e6a565b610c319190611e81565b600086815261012d60205260409020600101549091508110610c855781610c5984600a611e5b565b600087815261012d6020526040902060010154610c769190611e6a565b610c809190611e81565b610c87565b835b979650505050505050565b6065546000906001600160a01b0316336001600160a01b031614610cc85760405162461bcd60e51b815260040161069590611cd8565b610cd1836115dd565b6001600160a01b0316826001600160a01b031614610d015760405162461bcd60e51b815260040161069590611ea3565b6000610d0b611139565b6001600160a01b0316633e7e86696040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6c9190611d54565b90506000610d7b82600a611e5b565b610d848661104f565b610d8d87611123565b610d979190611e6a565b610da19190611e81565b610dac906001611d15565b90506000610db98661130f565b9050818111610dc9576000610dd3565b610dd38282611d41565b93508315610e5557600086815261012d602052604081208054869290610dfa908490611d41565b9091555050600086815261012d602052604081206001018054869290610e21908490611d41565b90915550506001600160a01b038516600090815261012e602052604081208054869290610e4f908490611d41565b90915550505b50505092915050565b6033546001600160a01b0316336001600160a01b031614610e915760405162461bcd60e51b815260040161069590611cb4565b60008281526101606020526040908190208290555182907f85d018be84c1c4ae756c9ff0599d92e330be6e192df471f35999591261feeb8b90610ed79084815260200190565b60405180910390a25050565b600054610100900460ff1615808015610f035750600054600160ff909116105b80610f1d5750303b158015610f1d575060005460ff166001145b610f805760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610695565b6000805460ff191660011790558015610fa3576000805461ff0019166101001790555b610fab6115fc565b8015610ff2576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50565b6065546001600160a01b0316336001600160a01b0316146110285760405162461bcd60e51b815260040161069590611cd8565b61103686868686868661162d565b505050505050565b6000611049826116b4565b92915050565b600090815261015e602052604090206003015490565b6065546001600160a01b0316336001600160a01b0316146110985760405162461bcd60e51b815260040161069590611cd8565b6110a4848484846115a4565b600083815261012d6020526040812080548392906110c3908490611d15565b9091555050600083815261012d6020526040812060010180548392906110ea908490611d15565b90915550506001600160a01b038216600090815261012e602052604081208054839290611118908490611d15565b909155505050505050565b600090815261012f602052604090206001015490565b6065546001600160a01b031690565b6065546001600160a01b03161561118c576033546001600160a01b0316336001600160a01b03161461118c5760405162461bcd60e51b815260040161069590611cb4565b6065546040517f91a2062b5d99931cce4660685e1c239d69642eedbb9cef9679a393f064ec3626916111cb916001600160a01b03909116908490611c9a565b60405180910390a1606580546001600160a01b0319166001600160a01b0392909216919091179055565b6065546001600160a01b0316336001600160a01b0316146112285760405162461bcd60e51b815260040161069590611cd8565b61123282826116cc565b5050565b6065546000906001600160a01b0316336001600160a01b03161461126c5760405162461bcd60e51b815260040161069590611cd8565b6112ac8484848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061176d92505050565b9050806000036113085760405162461bcd60e51b815260206004820152602160248201527f5346544973737561626c65436f6e63726574653a20696e76616c696420736c6f6044820152601d60fa1b6064820152608401610695565b9392505050565b600090815261012d602052604090206001015490565b6065546000906001600160a01b0316336001600160a01b03161461135b5760405162461bcd60e51b815260040161069590611cd8565b611367858585856115a4565b61137085610a8d565b8211156113c95760405162461bcd60e51b815260206004820152602160248201527f464d523a20696e73756666696369656e7420636c61696d61626c652076616c756044820152606560f81b6064820152608401610695565b600084815261012f6020526040812060010180548492906113eb908490611d41565b90915550600090506113fb611139565b6001600160a01b0316633e7e86696040518163ffffffff1660e01b8152600401602060405180830381865afa158015611438573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061145c9190611d54565b905061146981600a611e5b565b6114728661104f565b61147c9085611e6a565b6114869190611e81565b600086815261012d60205260409020600101549092508211156114fc5760405162461bcd60e51b815260206004820152602860248201527f464d523a20696e73756666696369656e74207265706169642063757272656e636044820152671e48185b5bdd5b9d60c21b6064820152608401610695565b6001600160a01b038416600090815261012e602052604081208054849290611525908490611d41565b9091555050600085815261012d60205260408120600101805484929061154c908490611d41565b90915550919695505050505050565b6065546001600160a01b0316336001600160a01b03161461158e5760405162461bcd60e51b815260040161069590611cd8565b600091825261015e602052604090912060030155565b6115ad836115dd565b6001600160a01b0316826001600160a01b0316146107af5760405162461bcd60e51b815260040161069590611ea3565b600090815261015e60205260409020600101546001600160a01b031690565b600054610100900460ff166116235760405162461bcd60e51b815260040161069590611ed2565b61162b6118cf565b565b611636836116b4565b6116775760405162461bcd60e51b815260206004820152601260248201527113d19490ce881a5b9d985b1a59081cdb1bdd60721b6044820152606401610695565b600083815261015e60205260409020600101546001600160a01b038681169116146110365760405162461bcd60e51b815260040161069590611f1d565b600090815261015e6020526040902060020154151590565b60006116d6611139565b6001600160a01b031663263f3e7e846040518263ffffffff1660e01b815260040161170391815260200190565b602060405180830381865afa158015611720573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117449190611d28565b90508161012f6000838152602001908152602001600020600101600082825461082e9190611d41565b600080828060200190518101906117849190611f4d565b80519091506117cc5760405162461bcd60e51b815260206004820152601460248201527313d19490ce881a5b9d985b1a59081c1bdbdb125960621b6044820152606401610695565b60208101516001600160a01b03166117f65760405162461bcd60e51b815260040161069590611f1d565b80604001516000036118455760405162461bcd60e51b81526020600482015260186024820152774f4652433a20696e76616c69642063726561746554696d6560401b6044820152606401610695565b61185c8160000151826020015183604001516118fe565b600081815261015e6020526040812060020154919350036118c857600082815261015e602090815260409182902083518155908301516001820180546001600160a01b0319166001600160a01b0390921691909117905590820151600282015560608201516003909101555b5092915050565b600054610100900460ff166118f65760405162461bcd60e51b815260040161069590611ed2565b61162b611969565b6000468061190a611139565b6040805160208101939093526001600160601b0319606092831b811691840191909152605483018890529086901b1660748201526088810184905260a80160408051601f19818403018152919052805160209091012095945050505050565b600054610100900460ff166119905760405162461bcd60e51b815260040161069590611ed2565b611999336119a1565b61162b611a04565b600054610100900460ff166119c85760405162461bcd60e51b815260040161069590611ed2565b603380546001600160a01b0319166001600160a01b038316179055604051600080516020611fc783398151915290610fe9906000908490611c9a565b600054610100900460ff1661162b5760405162461bcd60e51b815260040161069590611ed2565b6001600160a01b0381168114610ff257600080fd5b600060208284031215611a5257600080fd5b813561130881611a2b565b6001600160a01b0391909116815260200190565b60008060008060808587031215611a8757600080fd5b5050823594602084013594506040840135936060013592509050565b600080600060608486031215611ab857600080fd5b505081359360208301359350604090920135919050565b60008060008060808587031215611ae557600080fd5b8435611af081611a2b565b9350602085013592506040850135611b0781611a2b565b9396929550929360600135925050565b600060208284031215611b2957600080fd5b5035919050565b60008060408385031215611b4357600080fd5b823591506020830135611b5581611a2b565b809150509250929050565b60008060408385031215611b7357600080fd5b50508035926020909101359150565b60008060008060008060c08789031215611b9b57600080fd5b8635611ba681611a2b565b95506020870135611bb681611a2b565b94506040870135611bc681611a2b565b959894975094956060810135955060808101359460a0909101359350915050565b600080600060408486031215611bfc57600080fd5b8335611c0781611a2b565b925060208401356001600160401b0380821115611c2357600080fd5b818601915086601f830112611c3757600080fd5b813581811115611c4657600080fd5b876020828501011115611c5857600080fd5b6020830194508093505050509250925092565b60008060008060808587031215611c8157600080fd5b84359350602085013592506040850135611b0781611a2b565b6001600160a01b0392831681529116602082015260400190565b6020808252600a908201526937b7363c9030b236b4b760b11b604082015260600190565b6020808252600d908201526c6f6e6c792064656c656761746560981b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b8082018082111561104957611049611cff565b600060208284031215611d3a57600080fd5b5051919050565b8181038181111561104957611049611cff565b600060208284031215611d6657600080fd5b815160ff8116811461130857600080fd5b600181815b80851115611db2578160001904821115611d9857611d98611cff565b80851615611da557918102915b93841c9390800290611d7c565b509250929050565b600082611dc957506001611049565b81611dd657506000611049565b8160018114611dec5760028114611df657611e12565b6001915050611049565b60ff841115611e0757611e07611cff565b50506001821b611049565b5060208310610133831016604e8410600b8410161715611e35575081810a611049565b611e3f8383611d77565b8060001904821115611e5357611e53611cff565b029392505050565b600061130860ff841683611dba565b808202811582820484141761104957611049611cff565b600082611e9e57634e487b7160e01b600052601260045260246000fd5b500490565b602080825260159082015274464d523a20696e76616c69642063757272656e637960581b604082015260600190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6020808252601690820152754f4652433a20696e76616c69642063757272656e637960501b604082015260600190565b600060808284031215611f5f57600080fd5b604051608081016001600160401b0381118282101715611f8f57634e487b7160e01b600052604160045260246000fd5b604052825181526020830151611fa481611a2b565b602082015260408381015190820152606092830151928101929092525091905056fef9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dca264697066735822122098f966ce3e32084e4db3905246f983a04449f662836f8b520dcca4b5fef416f964736f6c63430008110033
Deployed Bytecode
0x6080604052600436106101685760003560e01c80630e18b6811461016d578063243532e11461018457806326782247146101a4578063302b586a146101da57806335f28fa5146101fa5780633b2f48301461021a578063492e38791461022d5780634dd18bf5146102695780634f0b5d7e1461028957806356b04045146102b757806369e489ea146102d75780637d853562146102f75780638129fc1c1461031757806389197e231461032c5780638b52d6681461034c578063915530891461037c5780639a9ab07e146103b8578063a6a978d8146103d8578063a9592997146103eb578063abab3eab1461040c578063c15a4e691461043a578063c89e43611461045a578063ca5eb5e11461046f578063cc7ec17a1461048f578063dae85ba3146104af578063dc296b12146104cf578063e8e99b9714610593578063f29af2da146105b3578063f31b3b8c146105e1578063f70654ce14610601578063f851a44014610621575b600080fd5b34801561017957600080fd5b50610182610641565b005b34801561019057600080fd5b5061018261019f366004611a40565b6106fe565b3480156101b057600080fd5b506034546101c4906001600160a01b031681565b6040516101d19190611a5d565b60405180910390f35b3480156101e657600080fd5b506101826101f5366004611a71565b61077c565b34801561020657600080fd5b50610182610215366004611aa3565b6107b5565b610182610228366004611acf565b610838565b34801561023957600080fd5b5061025b610248366004611b17565b600090815261012f602052604090205490565b6040519081526020016101d1565b34801561027557600080fd5b50610182610284366004611a40565b6109f1565b34801561029557600080fd5b5061025b6102a4366004611b17565b6101606020526000908152604090205481565b3480156102c357600080fd5b5061025b6102d2366004611b17565b610a8d565b3480156102e357600080fd5b5061025b6102f2366004611b30565b610c92565b34801561030357600080fd5b50610182610312366004611b60565b610e5e565b34801561032357600080fd5b50610182610ee3565b34801561033857600080fd5b50610182610347366004611b82565b610ff5565b34801561035857600080fd5b5061036c610367366004611b17565b61103e565b60405190151581526020016101d1565b34801561038857600080fd5b5061025b610397366004611b17565b600090815261015e6020908152604080832054835261016090915290205490565b3480156103c457600080fd5b5061025b6103d3366004611b17565b61104f565b6101826103e6366004611acf565b611065565b3480156103f757600080fd5b5061015f546101c4906001600160a01b031681565b34801561041857600080fd5b5061025b610427366004611a40565b61012e6020526000908152604090205481565b34801561044657600080fd5b5061025b610455366004611b17565b611123565b34801561046657600080fd5b506101c4611139565b34801561047b57600080fd5b5061018261048a366004611a40565b611148565b34801561049b57600080fd5b506101826104aa366004611b60565b6111f5565b3480156104bb57600080fd5b5061025b6104ca366004611be7565b611236565b3480156104db57600080fd5b506105576104ea366004611b17565b604080516080808201835260008083526020808401829052838501829052606093840182905294815261015e8552839020835191820184528054825260018101546001600160a01b0316948201949094526002840154928101929092526003909201549181019190915290565b6040516101d19190815181526020808301516001600160a01b031690820152604080830151908201526060918201519181019190915260800190565b34801561059f57600080fd5b5061025b6105ae366004611b17565b61130f565b3480156105bf57600080fd5b5061025b6105ce366004611b17565b600090815261012d602052604090205490565b3480156105ed57600080fd5b5061025b6105fc366004611c6b565b611325565b34801561060d57600080fd5b5061018261061c366004611b60565b61155b565b34801561062d57600080fd5b506033546101c4906001600160a01b031681565b6034546001600160a01b0316336001600160a01b03161461069e5760405162461bcd60e51b815260206004820152601260248201527137b7363c903832b73234b7339030b236b4b760711b60448201526064015b60405180910390fd5b603354603454604051600080516020611fc7833981519152926106cf926001600160a01b0391821692911690611c9a565b60405180910390a160348054603380546001600160a01b03199081166001600160a01b03841617909155169055565b6033546001600160a01b0316336001600160a01b0316146107315760405162461bcd60e51b815260040161069590611cb4565b61015f80546001600160a01b0319166001600160a01b0383169081179091556040517f44aa4fcfe009dfd02b84beba2b2a2553af09af75408d082879f29b5a24f5db2890600090a250565b6065546001600160a01b0316336001600160a01b0316146107af5760405162461bcd60e51b815260040161069590611cd8565b50505050565b6065546001600160a01b0316336001600160a01b0316146107e85760405162461bcd60e51b815260040161069590611cd8565b600082815261012f602052604081208054839290610807908490611d15565b9091555050600082815261012f60205260408120600101805483929061082e908490611d15565b9091555050505050565b6065546001600160a01b0316336001600160a01b03161461086b5760405162461bcd60e51b815260040161069590611cd8565b610877848484846115a4565b6000826001600160a01b03166370a08231610890611139565b6040518263ffffffff1660e01b81526004016108ac9190611a5d565b602060405180830381865afa1580156108c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ed9190611d28565b6001600160a01b038416600090815261012e60205260409020549091506109149082611d41565b8211156109715760405162461bcd60e51b815260206004820152602560248201527f464d523a20696e73756666696369656e7420756e616c6c6f63617465642062616044820152646c616e636560d81b6064820152608401610695565b600084815261012d602052604081208054849290610990908490611d15565b9091555050600084815261012d6020526040812060010180548492906109b7908490611d15565b90915550506001600160a01b038316600090815261012e6020526040812080548492906109e5908490611d15565b90915550505050505050565b6033546001600160a01b0316336001600160a01b031614610a245760405162461bcd60e51b815260040161069590611cb4565b6034546040517fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a991610a63916001600160a01b03909116908490611c9a565b60405180910390a1603480546001600160a01b0319166001600160a01b0392909216919091179055565b600080610a98611139565b6001600160a01b031663263f3e7e846040518263ffffffff1660e01b8152600401610ac591815260200190565b602060405180830381865afa158015610ae2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b069190611d28565b90506000610b12611139565b6001600160a01b0316639cc7f708856040518263ffffffff1660e01b8152600401610b3f91815260200190565b602060405180830381865afa158015610b5c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b809190611d28565b90506000610b8c611139565b6001600160a01b0316633e7e86696040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bed9190611d54565b90506000610bfa8461104f565b905080600003610c105750600095945050505050565b6000610c1d83600a611e5b565b610c278386611e6a565b610c319190611e81565b600086815261012d60205260409020600101549091508110610c855781610c5984600a611e5b565b600087815261012d6020526040902060010154610c769190611e6a565b610c809190611e81565b610c87565b835b979650505050505050565b6065546000906001600160a01b0316336001600160a01b031614610cc85760405162461bcd60e51b815260040161069590611cd8565b610cd1836115dd565b6001600160a01b0316826001600160a01b031614610d015760405162461bcd60e51b815260040161069590611ea3565b6000610d0b611139565b6001600160a01b0316633e7e86696040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6c9190611d54565b90506000610d7b82600a611e5b565b610d848661104f565b610d8d87611123565b610d979190611e6a565b610da19190611e81565b610dac906001611d15565b90506000610db98661130f565b9050818111610dc9576000610dd3565b610dd38282611d41565b93508315610e5557600086815261012d602052604081208054869290610dfa908490611d41565b9091555050600086815261012d602052604081206001018054869290610e21908490611d41565b90915550506001600160a01b038516600090815261012e602052604081208054869290610e4f908490611d41565b90915550505b50505092915050565b6033546001600160a01b0316336001600160a01b031614610e915760405162461bcd60e51b815260040161069590611cb4565b60008281526101606020526040908190208290555182907f85d018be84c1c4ae756c9ff0599d92e330be6e192df471f35999591261feeb8b90610ed79084815260200190565b60405180910390a25050565b600054610100900460ff1615808015610f035750600054600160ff909116105b80610f1d5750303b158015610f1d575060005460ff166001145b610f805760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610695565b6000805460ff191660011790558015610fa3576000805461ff0019166101001790555b610fab6115fc565b8015610ff2576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50565b6065546001600160a01b0316336001600160a01b0316146110285760405162461bcd60e51b815260040161069590611cd8565b61103686868686868661162d565b505050505050565b6000611049826116b4565b92915050565b600090815261015e602052604090206003015490565b6065546001600160a01b0316336001600160a01b0316146110985760405162461bcd60e51b815260040161069590611cd8565b6110a4848484846115a4565b600083815261012d6020526040812080548392906110c3908490611d15565b9091555050600083815261012d6020526040812060010180548392906110ea908490611d15565b90915550506001600160a01b038216600090815261012e602052604081208054839290611118908490611d15565b909155505050505050565b600090815261012f602052604090206001015490565b6065546001600160a01b031690565b6065546001600160a01b03161561118c576033546001600160a01b0316336001600160a01b03161461118c5760405162461bcd60e51b815260040161069590611cb4565b6065546040517f91a2062b5d99931cce4660685e1c239d69642eedbb9cef9679a393f064ec3626916111cb916001600160a01b03909116908490611c9a565b60405180910390a1606580546001600160a01b0319166001600160a01b0392909216919091179055565b6065546001600160a01b0316336001600160a01b0316146112285760405162461bcd60e51b815260040161069590611cd8565b61123282826116cc565b5050565b6065546000906001600160a01b0316336001600160a01b03161461126c5760405162461bcd60e51b815260040161069590611cd8565b6112ac8484848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061176d92505050565b9050806000036113085760405162461bcd60e51b815260206004820152602160248201527f5346544973737561626c65436f6e63726574653a20696e76616c696420736c6f6044820152601d60fa1b6064820152608401610695565b9392505050565b600090815261012d602052604090206001015490565b6065546000906001600160a01b0316336001600160a01b03161461135b5760405162461bcd60e51b815260040161069590611cd8565b611367858585856115a4565b61137085610a8d565b8211156113c95760405162461bcd60e51b815260206004820152602160248201527f464d523a20696e73756666696369656e7420636c61696d61626c652076616c756044820152606560f81b6064820152608401610695565b600084815261012f6020526040812060010180548492906113eb908490611d41565b90915550600090506113fb611139565b6001600160a01b0316633e7e86696040518163ffffffff1660e01b8152600401602060405180830381865afa158015611438573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061145c9190611d54565b905061146981600a611e5b565b6114728661104f565b61147c9085611e6a565b6114869190611e81565b600086815261012d60205260409020600101549092508211156114fc5760405162461bcd60e51b815260206004820152602860248201527f464d523a20696e73756666696369656e74207265706169642063757272656e636044820152671e48185b5bdd5b9d60c21b6064820152608401610695565b6001600160a01b038416600090815261012e602052604081208054849290611525908490611d41565b9091555050600085815261012d60205260408120600101805484929061154c908490611d41565b90915550919695505050505050565b6065546001600160a01b0316336001600160a01b03161461158e5760405162461bcd60e51b815260040161069590611cd8565b600091825261015e602052604090912060030155565b6115ad836115dd565b6001600160a01b0316826001600160a01b0316146107af5760405162461bcd60e51b815260040161069590611ea3565b600090815261015e60205260409020600101546001600160a01b031690565b600054610100900460ff166116235760405162461bcd60e51b815260040161069590611ed2565b61162b6118cf565b565b611636836116b4565b6116775760405162461bcd60e51b815260206004820152601260248201527113d19490ce881a5b9d985b1a59081cdb1bdd60721b6044820152606401610695565b600083815261015e60205260409020600101546001600160a01b038681169116146110365760405162461bcd60e51b815260040161069590611f1d565b600090815261015e6020526040902060020154151590565b60006116d6611139565b6001600160a01b031663263f3e7e846040518263ffffffff1660e01b815260040161170391815260200190565b602060405180830381865afa158015611720573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117449190611d28565b90508161012f6000838152602001908152602001600020600101600082825461082e9190611d41565b600080828060200190518101906117849190611f4d565b80519091506117cc5760405162461bcd60e51b815260206004820152601460248201527313d19490ce881a5b9d985b1a59081c1bdbdb125960621b6044820152606401610695565b60208101516001600160a01b03166117f65760405162461bcd60e51b815260040161069590611f1d565b80604001516000036118455760405162461bcd60e51b81526020600482015260186024820152774f4652433a20696e76616c69642063726561746554696d6560401b6044820152606401610695565b61185c8160000151826020015183604001516118fe565b600081815261015e6020526040812060020154919350036118c857600082815261015e602090815260409182902083518155908301516001820180546001600160a01b0319166001600160a01b0390921691909117905590820151600282015560608201516003909101555b5092915050565b600054610100900460ff166118f65760405162461bcd60e51b815260040161069590611ed2565b61162b611969565b6000468061190a611139565b6040805160208101939093526001600160601b0319606092831b811691840191909152605483018890529086901b1660748201526088810184905260a80160408051601f19818403018152919052805160209091012095945050505050565b600054610100900460ff166119905760405162461bcd60e51b815260040161069590611ed2565b611999336119a1565b61162b611a04565b600054610100900460ff166119c85760405162461bcd60e51b815260040161069590611ed2565b603380546001600160a01b0319166001600160a01b038316179055604051600080516020611fc783398151915290610fe9906000908490611c9a565b600054610100900460ff1661162b5760405162461bcd60e51b815260040161069590611ed2565b6001600160a01b0381168114610ff257600080fd5b600060208284031215611a5257600080fd5b813561130881611a2b565b6001600160a01b0391909116815260200190565b60008060008060808587031215611a8757600080fd5b5050823594602084013594506040840135936060013592509050565b600080600060608486031215611ab857600080fd5b505081359360208301359350604090920135919050565b60008060008060808587031215611ae557600080fd5b8435611af081611a2b565b9350602085013592506040850135611b0781611a2b565b9396929550929360600135925050565b600060208284031215611b2957600080fd5b5035919050565b60008060408385031215611b4357600080fd5b823591506020830135611b5581611a2b565b809150509250929050565b60008060408385031215611b7357600080fd5b50508035926020909101359150565b60008060008060008060c08789031215611b9b57600080fd5b8635611ba681611a2b565b95506020870135611bb681611a2b565b94506040870135611bc681611a2b565b959894975094956060810135955060808101359460a0909101359350915050565b600080600060408486031215611bfc57600080fd5b8335611c0781611a2b565b925060208401356001600160401b0380821115611c2357600080fd5b818601915086601f830112611c3757600080fd5b813581811115611c4657600080fd5b876020828501011115611c5857600080fd5b6020830194508093505050509250925092565b60008060008060808587031215611c8157600080fd5b84359350602085013592506040850135611b0781611a2b565b6001600160a01b0392831681529116602082015260400190565b6020808252600a908201526937b7363c9030b236b4b760b11b604082015260600190565b6020808252600d908201526c6f6e6c792064656c656761746560981b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b8082018082111561104957611049611cff565b600060208284031215611d3a57600080fd5b5051919050565b8181038181111561104957611049611cff565b600060208284031215611d6657600080fd5b815160ff8116811461130857600080fd5b600181815b80851115611db2578160001904821115611d9857611d98611cff565b80851615611da557918102915b93841c9390800290611d7c565b509250929050565b600082611dc957506001611049565b81611dd657506000611049565b8160018114611dec5760028114611df657611e12565b6001915050611049565b60ff841115611e0757611e07611cff565b50506001821b611049565b5060208310610133831016604e8410600b8410161715611e35575081810a611049565b611e3f8383611d77565b8060001904821115611e5357611e53611cff565b029392505050565b600061130860ff841683611dba565b808202811582820484141761104957611049611cff565b600082611e9e57634e487b7160e01b600052601260045260246000fd5b500490565b602080825260159082015274464d523a20696e76616c69642063757272656e637960581b604082015260600190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6020808252601690820152754f4652433a20696e76616c69642063757272656e637960501b604082015260600190565b600060808284031215611f5f57600080fd5b604051608081016001600160401b0381118282101715611f8f57634e487b7160e01b600052604160045260246000fd5b604052825181526020830151611fa481611a2b565b602082015260408381015190820152606092830151928101929092525091905056fef9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dca264697066735822122098f966ce3e32084e4db3905246f983a04449f662836f8b520dcca4b5fef416f964736f6c63430008110033
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.