ERC-20
Source Code
Overview
Max Total Supply
4,576.326987 ERC20 ***
Holders
135
Market
Price
$0.00 @ 0.000000 ETH
Onchain Market Cap
-
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 6 Decimals)
Balance
0.049356 ERC20 ***Value
$0.00Loading...
Loading
Loading...
Loading
Loading...
Loading
Contract Name:
CusdcV3Wrapper
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./vendor/CometInterface.sol";
import "./WrappedERC20.sol";
import "./vendor/ICometRewards.sol";
import "./ICusdcV3Wrapper.sol";
import "./CometHelpers.sol";
/**
* @title CusdcV3Wrapper
* @notice Wrapper for cUSDCV3 / COMET that acts as a stable-balance ERC20, instead of rebasing
* token. {comet} will be used as the unit for the underlying token, and {wComet} will be used
* as the unit for wrapped tokens.
*/
contract CusdcV3Wrapper is ICusdcV3Wrapper, WrappedERC20, CometHelpers {
using SafeERC20 for IERC20;
/// From cUSDCv3, used in principal <> present calculations
uint256 public constant TRACKING_INDEX_SCALE = 1e15;
/// From cUSDCv3, scaling factor for USDC rewards
uint256 public constant RESCALE_FACTOR = 1e12;
CometInterface public immutable underlyingComet;
ICometRewards public immutable rewardsAddr;
IERC20 public immutable rewardERC20;
mapping(address => uint64) public baseTrackingIndex; // uint64 for consistency with CometHelpers
mapping(address => uint256) public baseTrackingAccrued; // uint256 to avoid overflow in L:199
mapping(address => uint256) public rewardsClaimed;
constructor(
address cusdcv3,
address rewardsAddr_,
address rewardERC20_
) WrappedERC20("Wrapped cUSDCv3", "wcUSDCv3") {
if (cusdcv3 == address(0)) revert ZeroAddress();
rewardsAddr = ICometRewards(rewardsAddr_);
rewardERC20 = IERC20(rewardERC20_);
underlyingComet = CometInterface(cusdcv3);
}
/// @return number of decimals
function decimals() public pure override returns (uint8) {
return 6;
}
/// @param amount {Comet} The amount of cUSDCv3 to deposit
function deposit(uint256 amount) external {
_deposit(msg.sender, msg.sender, msg.sender, amount);
}
/// @param dst The dst to deposit into
/// @param amount {Comet} The amount of cUSDCv3 to deposit
function depositTo(address dst, uint256 amount) external {
_deposit(msg.sender, msg.sender, dst, amount);
}
/// @param src The address to deposit from
/// @param dst The address to deposit to
/// @param amount {Comet} The amount of cUSDCv3 to deposit
function depositFrom(
address src,
address dst,
uint256 amount
) external {
_deposit(msg.sender, src, dst, amount);
}
/// Only called internally to run the deposit logic
/// Takes `amount` fo cUSDCv3 from `src` and deposits to `dst` account in the wrapper.
/// @param operator The address calling the contract (msg.sender)
/// @param src The address to deposit from
/// @param dst The address to deposit to
/// @param amount {Comet} The amount of cUSDCv3 to deposit
function _deposit(
address operator,
address src,
address dst,
uint256 amount
) internal {
if (!hasPermission(src, operator)) revert Unauthorized();
// {Comet}
uint256 srcBal = underlyingComet.balanceOf(src);
if (amount > srcBal) amount = srcBal;
if (amount == 0) revert BadAmount();
underlyingComet.accrueAccount(address(this));
underlyingComet.accrueAccount(src);
CometInterface.UserBasic memory wrappedBasic = underlyingComet.userBasic(address(this));
int104 wrapperPrePrinc = wrappedBasic.principal;
IERC20(address(underlyingComet)).safeTransferFrom(src, address(this), amount);
wrappedBasic = underlyingComet.userBasic(address(this));
int104 wrapperPostPrinc = wrappedBasic.principal;
accrueAccountRewards(dst);
// safe to cast because amount is positive
_mint(dst, uint104(wrapperPostPrinc - wrapperPrePrinc));
}
/// @param amount {Comet} The amount of cUSDCv3 to withdraw
function withdraw(uint256 amount) external {
_withdraw(msg.sender, msg.sender, msg.sender, amount);
}
/// @param dst The address to withdraw cUSDCv3 to
/// @param amount {Comet} The amount of cUSDCv3 to withdraw
function withdrawTo(address dst, uint256 amount) external {
_withdraw(msg.sender, msg.sender, dst, amount);
}
/// @param src The address to withdraw from
/// @param dst The address to withdraw cUSDCv3 to
/// @param amount {Comet} The amount of cUSDCv3 to withdraw
function withdrawFrom(
address src,
address dst,
uint256 amount
) external {
_withdraw(msg.sender, src, dst, amount);
}
/// Internally called to run the withdraw logic
/// Withdraws `amount` cUSDCv3 from `src` account in the wrapper and sends to `dst`
/// @dev Rounds conservatively so as not to over-withdraw from the wrapper
/// @param operator The address calling the contract (msg.sender)
/// @param src The address to withdraw from
/// @param dst The address to withdraw cUSDCv3 to
/// @param amount {Comet} The amount of cUSDCv3 to withdraw
function _withdraw(
address operator,
address src,
address dst,
uint256 amount
) internal {
if (!hasPermission(src, operator)) revert Unauthorized();
// {Comet}
uint256 srcBalUnderlying = underlyingBalanceOf(src);
if (srcBalUnderlying < amount) amount = srcBalUnderlying;
if (amount == 0) revert BadAmount();
underlyingComet.accrueAccount(address(this));
underlyingComet.accrueAccount(src);
uint256 srcBalPre = balanceOf(src);
CometInterface.UserBasic memory wrappedBasic = underlyingComet.userBasic(address(this));
int104 wrapperPrePrinc = wrappedBasic.principal;
// conservative rounding in favor of the wrapper
IERC20(address(underlyingComet)).safeTransfer(dst, (amount / 10) * 10);
wrappedBasic = underlyingComet.userBasic(address(this));
int104 wrapperPostPrinc = wrappedBasic.principal;
// safe to cast because principal can't go negative, wrapper is not borrowing
uint256 burnAmt = uint256(uint104(wrapperPrePrinc - wrapperPostPrinc));
// occasionally comet will withdraw 1-10 wei more than we asked for.
// this is ok because 9 times out of 10 we are rounding in favor of the wrapper.
// safe because we have already capped the comet withdraw amount to src underlying bal.
// untested:
// difficult to trigger, depends on comet rules regarding rounding
if (srcBalPre <= burnAmt) burnAmt = srcBalPre;
accrueAccountRewards(src);
_burn(src, safe104(burnAmt));
}
/// Internally called to run transfer logic.
/// Accrues rewards for `src` and `dst` before transferring value.
function _beforeTokenTransfer(
address src,
address dst,
uint256 amount
) internal virtual override {
underlyingComet.accrueAccount(address(this));
super._beforeTokenTransfer(src, dst, amount);
accrueAccountRewards(src);
accrueAccountRewards(dst);
}
function claimRewards() external {
claimTo(msg.sender, msg.sender);
}
/// @param src The account to claim from
/// @param dst The address to send claimed rewards to
function claimTo(address src, address dst) public {
address sender = msg.sender;
if (!hasPermission(src, sender)) revert Unauthorized();
accrueAccount(src);
uint256 claimed = rewardsClaimed[src];
uint256 accrued = baseTrackingAccrued[src] * RESCALE_FACTOR;
uint256 owed;
if (accrued > claimed) {
owed = accrued - claimed;
rewardsClaimed[src] = accrued;
rewardsAddr.claimTo(address(underlyingComet), address(this), address(this), true);
IERC20(rewardERC20).safeTransfer(dst, owed);
}
emit RewardsClaimed(rewardERC20, owed);
}
/// Accure the cUSDCv3 account of the wrapper
function accrue() public {
underlyingComet.accrueAccount(address(this));
}
/// @param account The address to accrue, first in cUSDCv3, then locally
function accrueAccount(address account) public {
underlyingComet.accrueAccount(address(this));
accrueAccountRewards(account);
}
/// Get the balance of cUSDCv3 that is represented by the `accounts` wrapper value.
/// @param account The address to calculate the cUSDCv3 balance of
/// @return {Comet} The cUSDCv3 balance that `account` holds in the wrapper
function underlyingBalanceOf(address account) public view returns (uint256) {
uint256 balance = balanceOf(account);
if (balance == 0) {
return 0;
}
return convertStaticToDynamic(safe104(balance));
}
/// @return The exchange rate {comet/wComet}
function exchangeRate() public view returns (uint256) {
(uint64 baseSupplyIndex, ) = getUpdatedSupplyIndicies();
return presentValueSupply(baseSupplyIndex, safe104(10**underlyingComet.decimals()));
}
/// @param amount The value of {wComet} to convert to {Comet}
/// @return {Comet} The amount of cUSDCv3 represented by `amount of {wComet}
function convertStaticToDynamic(uint104 amount) public view returns (uint256) {
(uint64 baseSupplyIndex, ) = getUpdatedSupplyIndicies();
return presentValueSupply(baseSupplyIndex, amount);
}
/// @param amount The value of {Comet} to convert to {wComet}
/// @return {wComet} The amount of wrapped token represented by `amount` of {Comet}
function convertDynamicToStatic(uint256 amount) public view returns (uint104) {
(uint64 baseSupplyIndex, ) = getUpdatedSupplyIndicies();
return principalValueSupply(baseSupplyIndex, amount);
}
/// @param account The address to view the owed rewards of
/// @return {reward} The amount of reward tokens owed to `account`
function getRewardOwed(address account) external view returns (uint256) {
(, uint64 trackingSupplyIndex) = getUpdatedSupplyIndicies();
uint256 indexDelta = uint256(trackingSupplyIndex - baseTrackingIndex[account]);
uint256 newBaseTrackingAccrued = baseTrackingAccrued[account] +
(safe104(balanceOf(account)) * indexDelta) /
TRACKING_INDEX_SCALE;
uint256 claimed = rewardsClaimed[account];
uint256 accrued = newBaseTrackingAccrued * RESCALE_FACTOR;
uint256 owed = accrued > claimed ? accrued - claimed : 0;
return owed;
}
/// Internally called to get saved indicies
/// @return baseSupplyIndex_ {1} The saved baseSupplyIndex
/// @return trackingSupplyIndex_ {1} The saved trackingSupplyIndex
function getSupplyIndices()
internal
view
returns (uint64 baseSupplyIndex_, uint64 trackingSupplyIndex_)
{
TotalsBasic memory totals = underlyingComet.totalsBasic();
baseSupplyIndex_ = totals.baseSupplyIndex;
trackingSupplyIndex_ = totals.trackingSupplyIndex;
}
/// Internally called to update the account indicies and accrued rewards for a given address
/// @param account The UserBasic struct for a target address
function accrueAccountRewards(address account) internal {
uint256 accountBal = balanceOf(account);
(, uint64 trackingSupplyIndex) = getSupplyIndices();
uint256 indexDelta = uint256(trackingSupplyIndex - baseTrackingIndex[account]);
baseTrackingAccrued[account] += (safe104(accountBal) * indexDelta) / TRACKING_INDEX_SCALE;
baseTrackingIndex[account] = trackingSupplyIndex;
}
/// Internally called to get the updated supply indicies
/// @return {1} The current baseSupplyIndex
/// @return {1} The current trackingSupplyIndex
function getUpdatedSupplyIndicies() internal view returns (uint64, uint64) {
TotalsBasic memory totals = underlyingComet.totalsBasic();
uint40 timeDelta = uint40(block.timestamp) - totals.lastAccrualTime;
uint64 baseSupplyIndex_ = totals.baseSupplyIndex;
uint64 trackingSupplyIndex_ = totals.trackingSupplyIndex;
if (timeDelta > 0) {
uint256 baseTrackingSupplySpeed = underlyingComet.baseTrackingSupplySpeed();
uint256 utilization = underlyingComet.getUtilization();
uint256 supplyRate = underlyingComet.getSupplyRate(utilization);
baseSupplyIndex_ += safe64(mulFactor(baseSupplyIndex_, supplyRate * timeDelta));
trackingSupplyIndex_ += safe64(
divBaseWei(baseTrackingSupplySpeed * timeDelta, totals.totalSupplyBase)
);
}
return (baseSupplyIndex_, trackingSupplyIndex_);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControlUpgradeable {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20PermitUpgradeable {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @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 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// 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 (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../libraries/Fixed.sol";
import "./IMain.sol";
import "./IRewardable.sol";
// Not used directly in the IAsset interface, but used by many consumers to save stack space
struct Price {
uint192 low; // {UoA/tok}
uint192 high; // {UoA/tok}
}
/**
* @title IAsset
* @notice Supertype. Any token that interacts with our system must be wrapped in an asset,
* whether it is used as RToken backing or not. Any token that can report a price in the UoA
* is eligible to be an asset.
*/
interface IAsset is IRewardable {
/// Refresh saved price
/// The Reserve protocol calls this at least once per transaction, before relying on
/// the Asset's other functions.
/// @dev Called immediately after deployment, before use
function refresh() external;
/// Should not revert
/// @return low {UoA/tok} The lower end of the price estimate
/// @return high {UoA/tok} The upper end of the price estimate
function price() external view returns (uint192 low, uint192 high);
/// Should not revert
/// lotLow should be nonzero when the asset might be worth selling
/// @return lotLow {UoA/tok} The lower end of the lot price estimate
/// @return lotHigh {UoA/tok} The upper end of the lot price estimate
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);
/// @return {tok} The balance of the ERC20 in whole tokens
function bal(address account) external view returns (uint192);
/// @return The ERC20 contract of the token with decimals() available
function erc20() external view returns (IERC20Metadata);
/// @return The number of decimals in the ERC20; just for gas optimization
function erc20Decimals() external view returns (uint8);
/// @return If the asset is an instance of ICollateral or not
function isCollateral() external view returns (bool);
/// @return {UoA} The max trade volume, in UoA
function maxTradeVolume() external view returns (uint192);
/// @return {s} The timestamp of the last refresh() that saved prices
function lastSave() external view returns (uint48);
}
// Used only in Testing. Strictly speaking an Asset does not need to adhere to this interface
interface TestIAsset is IAsset {
/// @return The address of the chainlink feed
function chainlinkFeed() external view returns (AggregatorV3Interface);
/// {1} The max % deviation allowed by the oracle
function oracleError() external view returns (uint192);
/// @return {s} Seconds that an oracle value is considered valid
function oracleTimeout() external view returns (uint48);
/// @return {s} Seconds that the lotPrice should decay over, after stale price
function priceTimeout() external view returns (uint48);
}
/// CollateralStatus must obey a linear ordering. That is:
/// - being DISABLED is worse than being IFFY, or SOUND
/// - being IFFY is worse than being SOUND.
enum CollateralStatus {
SOUND,
IFFY, // When a peg is not holding or a chainlink feed is stale
DISABLED // When the collateral has completely defaulted
}
/// Upgrade-safe maximum operator for CollateralStatus
library CollateralStatusComparator {
/// @return Whether a is worse than b
function worseThan(CollateralStatus a, CollateralStatus b) internal pure returns (bool) {
return uint256(a) > uint256(b);
}
}
/**
* @title ICollateral
* @notice A subtype of Asset that consists of the tokens eligible to back the RToken.
*/
interface ICollateral is IAsset {
/// Emitted whenever the collateral status is changed
/// @param newStatus The old CollateralStatus
/// @param newStatus The updated CollateralStatus
event CollateralStatusChanged(
CollateralStatus indexed oldStatus,
CollateralStatus indexed newStatus
);
/// @dev refresh()
/// Refresh exchange rates and update default status.
/// VERY IMPORTANT: In any valid implemntation, status() MUST become DISABLED in refresh() if
/// refPerTok() has ever decreased since last call.
/// @return The canonical name of this collateral's target unit.
function targetName() external view returns (bytes32);
/// @return The status of this collateral asset. (Is it defaulting? Might it soon?)
function status() external view returns (CollateralStatus);
// ==== Exchange Rates ====
/// @return {ref/tok} Quantity of whole reference units per whole collateral tokens
function refPerTok() external view returns (uint192);
/// @return {target/ref} Quantity of whole target units per whole reference unit in the peg
function targetPerRef() external view returns (uint192);
}
// Used only in Testing. Strictly speaking a Collateral does not need to adhere to this interface
interface TestICollateral is TestIAsset, ICollateral {
/// @return The epoch timestamp when the collateral will default from IFFY to DISABLED
function whenDefault() external view returns (uint256);
/// @return The amount of time a collateral must be in IFFY status until being DISABLED
function delayUntilDefault() external view returns (uint48);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IAsset.sol";
import "./IComponent.sol";
/// A serialization of the AssetRegistry to be passed around in the P1 impl for gas optimization
struct Registry {
IERC20[] erc20s;
IAsset[] assets;
}
/**
* @title IAssetRegistry
* @notice The AssetRegistry is in charge of maintaining the ERC20 tokens eligible
* to be handled by the rest of the system. If an asset is in the registry, this means:
* 1. Its ERC20 contract has been vetted
* 2. The asset is the only asset for that ERC20
* 3. The asset can be priced in the UoA, usually via an oracle
*/
interface IAssetRegistry is IComponent {
/// Emitted when an asset is added to the registry
/// @param erc20 The ERC20 contract for the asset
/// @param asset The asset contract added to the registry
event AssetRegistered(IERC20 indexed erc20, IAsset indexed asset);
/// Emitted when an asset is removed from the registry
/// @param erc20 The ERC20 contract for the asset
/// @param asset The asset contract removed from the registry
event AssetUnregistered(IERC20 indexed erc20, IAsset indexed asset);
// Initialization
function init(IMain main_, IAsset[] memory assets_) external;
/// Fully refresh all asset state
/// @custom:interaction
function refresh() external;
/// Register `asset`
/// If either the erc20 address or the asset was already registered, fail
/// @return true if the erc20 address was not already registered.
/// @custom:governance
function register(IAsset asset) external returns (bool);
/// Register `asset` if and only if its erc20 address is already registered.
/// If the erc20 address was not registered, revert.
/// @return swapped If the asset was swapped for a previously-registered asset
/// @custom:governance
function swapRegistered(IAsset asset) external returns (bool swapped);
/// Unregister an asset, requiring that it is already registered
/// @custom:governance
function unregister(IAsset asset) external;
/// @return {s} The timestamp of the last refresh
function lastRefresh() external view returns (uint48);
/// @return The corresponding asset for ERC20, or reverts if not registered
function toAsset(IERC20 erc20) external view returns (IAsset);
/// @return The corresponding collateral, or reverts if unregistered or not collateral
function toColl(IERC20 erc20) external view returns (ICollateral);
/// @return If the ERC20 is registered
function isRegistered(IERC20 erc20) external view returns (bool);
/// @return A list of all registered ERC20s
function erc20s() external view returns (IERC20[] memory);
/// @return reg The list of registered ERC20s and Assets, in the same order
function getRegistry() external view returns (Registry memory reg);
/// @return The number of registered ERC20s
function size() external view returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IBroker.sol";
import "./IComponent.sol";
import "./ITrading.sol";
/**
* @title IBackingManager
* @notice The BackingManager handles changes in the ERC20 balances that back an RToken.
* - It computes which trades to perform, if any, and initiates these trades with the Broker.
* - rebalance()
* - If already collateralized, excess assets are transferred to RevenueTraders.
* - forwardRevenue(IERC20[] calldata erc20s)
*/
interface IBackingManager is IComponent, ITrading {
/// Emitted when the trading delay is changed
/// @param oldVal The old trading delay
/// @param newVal The new trading delay
event TradingDelaySet(uint48 oldVal, uint48 newVal);
/// Emitted when the backing buffer is changed
/// @param oldVal The old backing buffer
/// @param newVal The new backing buffer
event BackingBufferSet(uint192 oldVal, uint192 newVal);
// Initialization
function init(
IMain main_,
uint48 tradingDelay_,
uint192 backingBuffer_,
uint192 maxTradeSlippage_,
uint192 minTradeVolume_
) external;
// Give RToken max allowance over a registered token
/// @custom:refresher
/// @custom:interaction
function grantRTokenAllowance(IERC20) external;
/// Apply the overall backing policy using the specified TradeKind, taking a haircut if unable
/// @param kind TradeKind.DUTCH_AUCTION or TradeKind.BATCH_AUCTION
/// @custom:interaction RCEI
function rebalance(TradeKind kind) external;
/// Forward revenue to RevenueTraders; reverts if not fully collateralized
/// @param erc20s The tokens to forward
/// @custom:interaction RCEI
function forwardRevenue(IERC20[] calldata erc20s) external;
}
interface TestIBackingManager is IBackingManager, TestITrading {
function tradingDelay() external view returns (uint48);
function backingBuffer() external view returns (uint192);
function setTradingDelay(uint48 val) external;
function setBackingBuffer(uint192 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "./IAsset.sol";
import "./IComponent.sol";
struct BasketRange {
uint192 bottom; // {BU}
uint192 top; // {BU}
}
/**
* @title IBasketHandler
* @notice The BasketHandler aims to maintain a reference basket of constant target unit amounts.
* When a collateral token defaults, a new reference basket of equal target units is set.
* When _all_ collateral tokens default for a target unit, only then is the basket allowed to fall
* in terms of target unit amounts. The basket is considered defaulted in this case.
*/
interface IBasketHandler is IComponent {
/// Emitted when the prime basket is set
/// @param erc20s The collateral tokens for the prime basket
/// @param targetAmts {target/BU} A list of quantities of target unit per basket unit
/// @param targetNames Each collateral token's targetName
event PrimeBasketSet(IERC20[] erc20s, uint192[] targetAmts, bytes32[] targetNames);
/// Emitted when the reference basket is set
/// @param nonce {basketNonce} The basket nonce
/// @param erc20s The list of collateral tokens in the reference basket
/// @param refAmts {ref/BU} The reference amounts of the basket collateral tokens
/// @param disabled True when the list of erc20s + refAmts may not be correct
event BasketSet(uint256 indexed nonce, IERC20[] erc20s, uint192[] refAmts, bool disabled);
/// Emitted when a backup config is set for a target unit
/// @param targetName The name of the target unit as a bytes32
/// @param max The max number to use from `erc20s`
/// @param erc20s The set of backup collateral tokens
event BackupConfigSet(bytes32 indexed targetName, uint256 max, IERC20[] erc20s);
/// Emitted when the warmup period is changed
/// @param oldVal The old warmup period
/// @param newVal The new warmup period
event WarmupPeriodSet(uint48 oldVal, uint48 newVal);
/// Emitted when the status of a basket has changed
/// @param oldStatus The previous basket status
/// @param newStatus The new basket status
event BasketStatusChanged(CollateralStatus oldStatus, CollateralStatus newStatus);
// Initialization
function init(IMain main_, uint48 warmupPeriod_) external;
/// Set the prime basket
/// @param erc20s The collateral tokens for the new prime basket
/// @param targetAmts The target amounts (in) {target/BU} for the new prime basket
/// required range: 1e9 values; absolute range irrelevant.
/// @custom:governance
function setPrimeBasket(IERC20[] memory erc20s, uint192[] memory targetAmts) external;
/// Set the backup configuration for a given target
/// @param targetName The name of the target as a bytes32
/// @param max The maximum number of collateral tokens to use from this target
/// Required range: 1-255
/// @param erc20s A list of ordered backup collateral tokens
/// @custom:governance
function setBackupConfig(
bytes32 targetName,
uint256 max,
IERC20[] calldata erc20s
) external;
/// Default the basket in order to schedule a basket refresh
/// @custom:protected
function disableBasket() external;
/// Governance-controlled setter to cause a basket switch explicitly
/// @custom:governance
/// @custom:interaction
function refreshBasket() external;
/// Track the basket status changes
/// @custom:refresher
function trackStatus() external;
/// @return If the BackingManager has sufficient collateral to redeem the entire RToken supply
function fullyCollateralized() external view returns (bool);
/// @return status The worst CollateralStatus of all collateral in the basket
function status() external view returns (CollateralStatus status);
/// @return If the basket is ready to issue and trade
function isReady() external view returns (bool);
/// @param erc20 The ERC20 token contract for the asset
/// @return {tok/BU} The whole token quantity of token in the reference basket
/// Returns 0 if erc20 is not registered or not in the basket
/// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.
/// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())
function quantity(IERC20 erc20) external view returns (uint192);
/// Like quantity(), but unsafe because it DOES NOT CONFIRM THAT THE ASSET IS CORRECT
/// @param erc20 The ERC20 token contract for the asset
/// @param asset The registered asset plugin contract for the erc20
/// @return {tok/BU} The whole token quantity of token in the reference basket
/// Returns 0 if erc20 is not registered or not in the basket
/// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.
/// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())
function quantityUnsafe(IERC20 erc20, IAsset asset) external view returns (uint192);
/// @param amount {BU}
/// @return erc20s The addresses of the ERC20 tokens in the reference basket
/// @return quantities {qTok} The quantity of each ERC20 token to issue `amount` baskets
function quote(uint192 amount, RoundingMode rounding)
external
view
returns (address[] memory erc20s, uint256[] memory quantities);
/// Return the redemption value of `amount` BUs for a linear combination of historical baskets
/// @param basketNonces An array of basket nonces to do redemption from
/// @param portions {1} An array of Fix quantities that must add up to FIX_ONE
/// @param amount {BU}
/// @return erc20s The backing collateral erc20s
/// @return quantities {qTok} ERC20 token quantities equal to `amount` BUs
function quoteCustomRedemption(
uint48[] memory basketNonces,
uint192[] memory portions,
uint192 amount
) external view returns (address[] memory erc20s, uint256[] memory quantities);
/// @return top {BU} The number of partial basket units: e.g max(coll.map((c) => c.balAsBUs())
/// bottom {BU} The number of whole basket units held by the account
function basketsHeldBy(address account) external view returns (BasketRange memory);
/// Should not revert
/// @return low {UoA/BU} The lower end of the price estimate
/// @return high {UoA/BU} The upper end of the price estimate
function price() external view returns (uint192 low, uint192 high);
/// Should not revert
/// lotLow should be nonzero if a BU could be worth selling
/// @return lotLow {UoA/tok} The lower end of the lot price estimate
/// @return lotHigh {UoA/tok} The upper end of the lot price estimate
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);
/// @return timestamp The timestamp at which the basket was last set
function timestamp() external view returns (uint48);
/// @return The current basket nonce, regardless of status
function nonce() external view returns (uint48);
}
interface TestIBasketHandler is IBasketHandler {
function warmupPeriod() external view returns (uint48);
function setWarmupPeriod(uint48 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IAsset.sol";
import "./IComponent.sol";
import "./IGnosis.sol";
import "./ITrade.sol";
enum TradeKind {
DUTCH_AUCTION,
BATCH_AUCTION
}
/// Cache of all (lot) prices for a pair to prevent re-lookup
struct TradePrices {
uint192 sellLow; // {UoA/sellTok} can be 0
uint192 sellHigh; // {UoA/sellTok} should not be 0
uint192 buyLow; // {UoA/buyTok} should not be 0
uint192 buyHigh; // {UoA/buyTok} should not be 0 or FIX_MAX
}
/// The data format that describes a request for trade with the Broker
struct TradeRequest {
IAsset sell;
IAsset buy;
uint256 sellAmount; // {qSellTok}
uint256 minBuyAmount; // {qBuyTok}
}
/**
* @title IBroker
* @notice The Broker deploys oneshot Trade contracts for Traders and monitors
* the continued proper functioning of trading platforms.
*/
interface IBroker is IComponent {
event GnosisSet(IGnosis oldVal, IGnosis newVal);
event BatchTradeImplementationSet(ITrade oldVal, ITrade newVal);
event DutchTradeImplementationSet(ITrade oldVal, ITrade newVal);
event BatchAuctionLengthSet(uint48 oldVal, uint48 newVal);
event DutchAuctionLengthSet(uint48 oldVal, uint48 newVal);
event BatchTradeDisabledSet(bool prevVal, bool newVal);
event DutchTradeDisabledSet(IERC20Metadata indexed erc20, bool prevVal, bool newVal);
// Initialization
function init(
IMain main_,
IGnosis gnosis_,
ITrade batchTradeImplemention_,
uint48 batchAuctionLength_,
ITrade dutchTradeImplemention_,
uint48 dutchAuctionLength_
) external;
/// Request a trade from the broker
/// @dev Requires setting an allowance in advance
/// @custom:interaction
function openTrade(
TradeKind kind,
TradeRequest memory req,
TradePrices memory prices
) external returns (ITrade);
/// Only callable by one of the trading contracts the broker deploys
function reportViolation() external;
function batchTradeDisabled() external view returns (bool);
function dutchTradeDisabled(IERC20Metadata erc20) external view returns (bool);
}
interface TestIBroker is IBroker {
function gnosis() external view returns (IGnosis);
function batchTradeImplementation() external view returns (ITrade);
function dutchTradeImplementation() external view returns (ITrade);
function batchAuctionLength() external view returns (uint48);
function dutchAuctionLength() external view returns (uint48);
function setGnosis(IGnosis newGnosis) external;
function setBatchTradeImplementation(ITrade newTradeImplementation) external;
function setBatchAuctionLength(uint48 newAuctionLength) external;
function setDutchTradeImplementation(ITrade newTradeImplementation) external;
function setDutchAuctionLength(uint48 newAuctionLength) external;
function enableBatchTrade() external;
function enableDutchTrade(IERC20Metadata erc20) external;
// only present on pre-3.0.0 Brokers; used by EasyAuction regression test
function disabled() external view returns (bool);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IMain.sol";
import "./IVersioned.sol";
/**
* @title IComponent
* @notice A Component is the central building block of all our system contracts. Components
* contain important state that must be migrated during upgrades, and they delegate
* their ownership to Main's owner.
*/
interface IComponent is IVersioned {
function main() external view returns (IMain);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IComponent.sol";
uint256 constant MAX_DISTRIBUTION = 1e4; // 10,000
uint8 constant MAX_DESTINATIONS = 100; // maximum number of RevenueShare destinations
struct RevenueShare {
uint16 rTokenDist; // {revShare} A value between [0, 10,000]
uint16 rsrDist; // {revShare} A value between [0, 10,000]
}
/// Assumes no more than 100 independent distributions.
struct RevenueTotals {
uint24 rTokenTotal; // {revShare}
uint24 rsrTotal; // {revShare}
}
/**
* @title IDistributor
* @notice The Distributor Component maintains a revenue distribution table that dictates
* how to divide revenue across the Furnace, StRSR, and any other destinations.
*/
interface IDistributor is IComponent {
/// Emitted when a distribution is set
/// @param dest The address set to receive the distribution
/// @param rTokenDist The distribution of RToken that should go to `dest`
/// @param rsrDist The distribution of RSR that should go to `dest`
event DistributionSet(address indexed dest, uint16 rTokenDist, uint16 rsrDist);
/// Emitted when revenue is distributed
/// @param erc20 The token being distributed, either RSR or the RToken itself
/// @param source The address providing the revenue
/// @param amount The amount of the revenue
event RevenueDistributed(IERC20 indexed erc20, address indexed source, uint256 amount);
// Initialization
function init(IMain main_, RevenueShare memory dist) external;
/// @custom:governance
function setDistribution(address dest, RevenueShare memory share) external;
/// Distribute the `erc20` token across all revenue destinations
/// Only callable by RevenueTraders
/// @custom:protected
function distribute(IERC20 erc20, uint256 amount) external;
/// @return revTotals The total of all destinations
function totals() external view returns (RevenueTotals memory revTotals);
}
interface TestIDistributor is IDistributor {
// solhint-disable-next-line func-name-mixedcase
function FURNACE() external view returns (address);
// solhint-disable-next-line func-name-mixedcase
function ST_RSR() external view returns (address);
/// @return rTokenDist The RToken distribution for the address
/// @return rsrDist The RSR distribution for the address
function distribution(address) external view returns (uint16 rTokenDist, uint16 rsrDist);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "../libraries/Fixed.sol";
import "./IComponent.sol";
/**
* @title IFurnace
* @notice A helper contract to burn RTokens slowly and permisionlessly.
*/
interface IFurnace is IComponent {
// Initialization
function init(IMain main_, uint192 ratio_) external;
/// Emitted when the melting ratio is changed
/// @param oldRatio The old ratio
/// @param newRatio The new ratio
event RatioSet(uint192 oldRatio, uint192 newRatio);
function ratio() external view returns (uint192);
/// Needed value range: [0, 1], granularity 1e-9
/// @custom:governance
function setRatio(uint192) external;
/// Performs any RToken melting that has vested since the last payout.
/// @custom:refresher
function melt() external;
}
interface TestIFurnace is IFurnace {
function lastPayout() external view returns (uint256);
function lastPayoutBal() external view returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
struct GnosisAuctionData {
IERC20 auctioningToken;
IERC20 biddingToken;
uint256 orderCancellationEndDate;
uint256 auctionEndDate;
bytes32 initialAuctionOrder;
uint256 minimumBiddingAmountPerOrder;
uint256 interimSumBidAmount;
bytes32 interimOrder;
bytes32 clearingPriceOrder;
uint96 volumeClearingPriceOrder;
bool minFundingThresholdNotReached;
bool isAtomicClosureAllowed;
uint256 feeNumerator;
uint256 minFundingThreshold;
}
/// The relevant portion of the interface of the live Gnosis EasyAuction contract
/// https://github.com/gnosis/ido-contracts/blob/main/contracts/EasyAuction.sol
interface IGnosis {
function initiateAuction(
IERC20 auctioningToken,
IERC20 biddingToken,
uint256 orderCancellationEndDate,
uint256 auctionEndDate,
uint96 auctionedSellAmount,
uint96 minBuyAmount,
uint256 minimumBiddingAmountPerOrder,
uint256 minFundingThreshold,
bool isAtomicClosureAllowed,
address accessManagerContract,
bytes memory accessManagerContractData
) external returns (uint256 auctionId);
function auctionData(uint256 auctionId) external view returns (GnosisAuctionData memory);
/// @param auctionId The external auction id
/// @dev See here for decoding: https://git.io/JMang
/// @return encodedOrder The order, encoded in a bytes 32
function settleAuction(uint256 auctionId) external returns (bytes32 encodedOrder);
/// @return The numerator over a 1000-valued denominator
function feeNumerator() external returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IAssetRegistry.sol";
import "./IBasketHandler.sol";
import "./IBackingManager.sol";
import "./IBroker.sol";
import "./IGnosis.sol";
import "./IFurnace.sol";
import "./IDistributor.sol";
import "./IRToken.sol";
import "./IRevenueTrader.sol";
import "./IStRSR.sol";
import "./ITrading.sol";
import "./IVersioned.sol";
// === Auth roles ===
bytes32 constant OWNER = bytes32(bytes("OWNER"));
bytes32 constant SHORT_FREEZER = bytes32(bytes("SHORT_FREEZER"));
bytes32 constant LONG_FREEZER = bytes32(bytes("LONG_FREEZER"));
bytes32 constant PAUSER = bytes32(bytes("PAUSER"));
/**
* Main is a central hub that maintains a list of Component contracts.
*
* Components:
* - perform a specific function
* - defer auth to Main
* - usually (but not always) contain sizeable state that require a proxy
*/
struct Components {
// Definitely need proxy
IRToken rToken;
IStRSR stRSR;
IAssetRegistry assetRegistry;
IBasketHandler basketHandler;
IBackingManager backingManager;
IDistributor distributor;
IFurnace furnace;
IBroker broker;
IRevenueTrader rsrTrader;
IRevenueTrader rTokenTrader;
}
interface IAuth is IAccessControlUpgradeable {
/// Emitted when `unfreezeAt` is changed
/// @param oldVal The old value of `unfreezeAt`
/// @param newVal The new value of `unfreezeAt`
event UnfreezeAtSet(uint48 oldVal, uint48 newVal);
/// Emitted when the short freeze duration governance param is changed
/// @param oldDuration The old short freeze duration
/// @param newDuration The new short freeze duration
event ShortFreezeDurationSet(uint48 oldDuration, uint48 newDuration);
/// Emitted when the long freeze duration governance param is changed
/// @param oldDuration The old long freeze duration
/// @param newDuration The new long freeze duration
event LongFreezeDurationSet(uint48 oldDuration, uint48 newDuration);
/// Emitted when the system is paused or unpaused for trading
/// @param oldVal The old value of `tradingPaused`
/// @param newVal The new value of `tradingPaused`
event TradingPausedSet(bool oldVal, bool newVal);
/// Emitted when the system is paused or unpaused for issuance
/// @param oldVal The old value of `issuancePaused`
/// @param newVal The new value of `issuancePaused`
event IssuancePausedSet(bool oldVal, bool newVal);
/**
* Trading Paused: Disable everything except for OWNER actions, RToken.issue, RToken.redeem,
* StRSR.stake, and StRSR.payoutRewards
* Issuance Paused: Disable RToken.issue
* Frozen: Disable everything except for OWNER actions + StRSR.stake (for governance)
*/
function tradingPausedOrFrozen() external view returns (bool);
function issuancePausedOrFrozen() external view returns (bool);
function frozen() external view returns (bool);
function shortFreeze() external view returns (uint48);
function longFreeze() external view returns (uint48);
// ====
// onlyRole(OWNER)
function freezeForever() external;
// onlyRole(SHORT_FREEZER)
function freezeShort() external;
// onlyRole(LONG_FREEZER)
function freezeLong() external;
// onlyRole(OWNER)
function unfreeze() external;
function pauseTrading() external;
function unpauseTrading() external;
function pauseIssuance() external;
function unpauseIssuance() external;
}
interface IComponentRegistry {
// === Component setters/getters ===
event RTokenSet(IRToken indexed oldVal, IRToken indexed newVal);
function rToken() external view returns (IRToken);
event StRSRSet(IStRSR oldVal, IStRSR newVal);
function stRSR() external view returns (IStRSR);
event AssetRegistrySet(IAssetRegistry oldVal, IAssetRegistry newVal);
function assetRegistry() external view returns (IAssetRegistry);
event BasketHandlerSet(IBasketHandler oldVal, IBasketHandler newVal);
function basketHandler() external view returns (IBasketHandler);
event BackingManagerSet(IBackingManager oldVal, IBackingManager newVal);
function backingManager() external view returns (IBackingManager);
event DistributorSet(IDistributor oldVal, IDistributor newVal);
function distributor() external view returns (IDistributor);
event RSRTraderSet(IRevenueTrader oldVal, IRevenueTrader newVal);
function rsrTrader() external view returns (IRevenueTrader);
event RTokenTraderSet(IRevenueTrader oldVal, IRevenueTrader newVal);
function rTokenTrader() external view returns (IRevenueTrader);
event FurnaceSet(IFurnace oldVal, IFurnace newVal);
function furnace() external view returns (IFurnace);
event BrokerSet(IBroker oldVal, IBroker newVal);
function broker() external view returns (IBroker);
}
/**
* @title IMain
* @notice The central hub for the entire system. Maintains components and an owner singleton role
*/
interface IMain is IVersioned, IAuth, IComponentRegistry {
function poke() external; // not used in p1
// === Initialization ===
event MainInitialized();
function init(
Components memory components,
IERC20 rsr_,
uint48 shortFreeze_,
uint48 longFreeze_
) external;
function rsr() external view returns (IERC20);
}
interface TestIMain is IMain {
/// @custom:governance
function setShortFreeze(uint48) external;
/// @custom:governance
function setLongFreeze(uint48) external;
function shortFreeze() external view returns (uint48);
function longFreeze() external view returns (uint48);
function longFreezes(address account) external view returns (uint256);
function tradingPaused() external view returns (bool);
function issuancePaused() external view returns (bool);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IBroker.sol";
import "./IComponent.sol";
import "./ITrading.sol";
/**
* @title IRevenueTrader
* @notice The RevenueTrader is an extension of the trading mixin that trades all
* assets at its address for a single target asset. There are two runtime instances
* of the RevenueTrader, 1 for RToken and 1 for RSR.
*/
interface IRevenueTrader is IComponent, ITrading {
// Initialization
function init(
IMain main_,
IERC20 tokenToBuy_,
uint192 maxTradeSlippage_,
uint192 minTradeVolume_
) external;
/// Distribute tokenToBuy to its destinations
/// @dev Special-case of manageTokens()
/// @custom:interaction
function distributeTokenToBuy() external;
/// Return registered ERC20s to the BackingManager if distribution for tokenToBuy is 0
/// @custom:interaction
function returnTokens(IERC20[] memory erc20s) external;
/// Process some number of tokens
/// If the tokenToBuy is included in erc20s, RevenueTrader will distribute it at end of the tx
/// @param erc20s The ERC20s to manage; can be tokenToBuy or anything registered
/// @param kinds The kinds of auctions to launch: DUTCH_AUCTION | BATCH_AUCTION
/// @custom:interaction
function manageTokens(IERC20[] memory erc20s, TradeKind[] memory kinds) external;
function tokenToBuy() external view returns (IERC20);
}
// solhint-disable-next-line no-empty-blocks
interface TestIRevenueTrader is IRevenueTrader, TestITrading {
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IComponent.sol";
import "./IMain.sol";
/**
* @title IRewardable
* @notice A simple interface mixin to support claiming of rewards.
*/
interface IRewardable {
/// Emitted whenever a reward token balance is claimed
event RewardsClaimed(IERC20 indexed erc20, uint256 amount);
/// Claim rewards earned by holding a balance of the ERC20 token
/// Must emit `RewardsClaimed` for each token rewards are claimed for
/// @custom:interaction
function claimRewards() external;
}
/**
* @title IRewardableComponent
* @notice A simple interface mixin to support claiming of rewards.
*/
interface IRewardableComponent is IRewardable {
/// Claim rewards for a single ERC20
/// Must emit `RewardsClaimed` for each token rewards are claimed for
/// @custom:interaction
function claimRewardsSingle(IERC20 erc20) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "../libraries/Fixed.sol";
import "../libraries/Throttle.sol";
import "./IAsset.sol";
import "./IComponent.sol";
import "./IMain.sol";
import "./IRewardable.sol";
/**
* @title IRToken
* @notice An RToken is an ERC20 that is permissionlessly issuable/redeemable and tracks an
* exchange rate against a single unit: baskets, or {BU} in our type notation.
*/
interface IRToken is IComponent, IERC20MetadataUpgradeable, IERC20PermitUpgradeable {
/// Emitted when an issuance of RToken occurs, whether it occurs via slow minting or not
/// @param issuer The address holding collateral tokens
/// @param recipient The address of the recipient of the RTokens
/// @param amount The quantity of RToken being issued
/// @param baskets The corresponding number of baskets
event Issuance(
address indexed issuer,
address indexed recipient,
uint256 amount,
uint192 baskets
);
/// Emitted when a redemption of RToken occurs
/// @param redeemer The address holding RToken
/// @param recipient The address of the account receiving the backing collateral tokens
/// @param amount The quantity of RToken being redeemed
/// @param baskets The corresponding number of baskets
/// @param amount {qRTok} The amount of RTokens canceled
event Redemption(
address indexed redeemer,
address indexed recipient,
uint256 amount,
uint192 baskets
);
/// Emitted when the number of baskets needed changes
/// @param oldBasketsNeeded Previous number of baskets units needed
/// @param newBasketsNeeded New number of basket units needed
event BasketsNeededChanged(uint192 oldBasketsNeeded, uint192 newBasketsNeeded);
/// Emitted when RToken is melted, i.e the RToken supply is decreased but basketsNeeded is not
/// @param amount {qRTok}
event Melted(uint256 amount);
/// Emitted when issuance SupplyThrottle params are set
event IssuanceThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);
/// Emitted when redemption SupplyThrottle params are set
event RedemptionThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);
// Initialization
function init(
IMain main_,
string memory name_,
string memory symbol_,
string memory mandate_,
ThrottleLib.Params calldata issuanceThrottleParams,
ThrottleLib.Params calldata redemptionThrottleParams
) external;
/// Issue an RToken with basket collateral
/// @param amount {qRTok} The quantity of RToken to issue
/// @custom:interaction
function issue(uint256 amount) external;
/// Issue an RToken with basket collateral, to a particular recipient
/// @param recipient The address to receive the issued RTokens
/// @param amount {qRTok} The quantity of RToken to issue
/// @custom:interaction
function issueTo(address recipient, uint256 amount) external;
/// Redeem RToken for basket collateral
/// @dev Use redeemCustom for non-current baskets
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @custom:interaction
function redeem(uint256 amount) external;
/// Redeem RToken for basket collateral to a particular recipient
/// @dev Use redeemCustom for non-current baskets
/// @param recipient The address to receive the backing collateral tokens
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @custom:interaction
function redeemTo(address recipient, uint256 amount) external;
/// Redeem RToken for a linear combination of historical baskets, to a particular recipient
/// @dev Allows partial redemptions up to the minAmounts
/// @param recipient The address to receive the backing collateral tokens
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @param basketNonces An array of basket nonces to do redemption from
/// @param portions {1} An array of Fix quantities that must add up to FIX_ONE
/// @param expectedERC20sOut An array of ERC20s expected out
/// @param minAmounts {qTok} The minimum ERC20 quantities the caller should receive
/// @custom:interaction
function redeemCustom(
address recipient,
uint256 amount,
uint48[] memory basketNonces,
uint192[] memory portions,
address[] memory expectedERC20sOut,
uint256[] memory minAmounts
) external;
/// Mint an amount of RToken equivalent to baskets BUs, scaling basketsNeeded up
/// Callable only by BackingManager
/// @param baskets {BU} The number of baskets to mint RToken for
/// @custom:protected
function mint(uint192 baskets) external;
/// Melt a quantity of RToken from the caller's account
/// @param amount {qRTok} The amount to be melted
/// @custom:protected
function melt(uint256 amount) external;
/// Burn an amount of RToken from caller's account and scale basketsNeeded down
/// Callable only by BackingManager
/// @custom:protected
function dissolve(uint256 amount) external;
/// Set the number of baskets needed directly, callable only by the BackingManager
/// @param basketsNeeded {BU} The number of baskets to target
/// needed range: pretty interesting
/// @custom:protected
function setBasketsNeeded(uint192 basketsNeeded) external;
/// @return {BU} How many baskets are being targeted
function basketsNeeded() external view returns (uint192);
/// @return {qRTok} The maximum issuance that can be performed in the current block
function issuanceAvailable() external view returns (uint256);
/// @return {qRTok} The maximum redemption that can be performed in the current block
function redemptionAvailable() external view returns (uint256);
}
interface TestIRToken is IRToken {
function setIssuanceThrottleParams(ThrottleLib.Params calldata) external;
function setRedemptionThrottleParams(ThrottleLib.Params calldata) external;
function issuanceThrottleParams() external view returns (ThrottleLib.Params memory);
function redemptionThrottleParams() external view returns (ThrottleLib.Params memory);
function increaseAllowance(address, uint256) external returns (bool);
function decreaseAllowance(address, uint256) external returns (bool);
function monetizeDonations(IERC20) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "../libraries/Fixed.sol";
import "./IComponent.sol";
import "./IMain.sol";
/**
* @title IStRSR
* @notice An ERC20 token representing shares of the RSR over-collateralization pool.
*
* StRSR permits the BackingManager to take RSR in times of need. In return, the BackingManager
* benefits the StRSR pool with RSR rewards purchased with a portion of its revenue.
*
* In the absence of collateral default or losses due to slippage, StRSR should have a
* monotonically increasing exchange rate with respect to RSR, meaning that over time
* StRSR is redeemable for more RSR. It is non-rebasing.
*/
interface IStRSR is IERC20MetadataUpgradeable, IERC20PermitUpgradeable, IComponent {
/// Emitted when RSR is staked
/// @param era The era at time of staking
/// @param staker The address of the staker
/// @param rsrAmount {qRSR} How much RSR was staked
/// @param stRSRAmount {qStRSR} How much stRSR was minted by this staking
event Staked(
uint256 indexed era,
address indexed staker,
uint256 rsrAmount,
uint256 stRSRAmount
);
/// Emitted when an unstaking is started
/// @param draftId The id of the draft.
/// @param draftEra The era of the draft.
/// @param staker The address of the unstaker
/// The triple (staker, draftEra, draftId) is a unique ID
/// @param rsrAmount {qRSR} How much RSR this unstaking will be worth, absent seizures
/// @param stRSRAmount {qStRSR} How much stRSR was burned by this unstaking
event UnstakingStarted(
uint256 indexed draftId,
uint256 indexed draftEra,
address indexed staker,
uint256 rsrAmount,
uint256 stRSRAmount,
uint256 availableAt
);
/// Emitted when RSR is unstaked
/// @param firstId The beginning of the range of draft IDs withdrawn in this transaction
/// @param endId The end of range of draft IDs withdrawn in this transaction
/// (ID i was withdrawn if firstId <= i < endId)
/// @param draftEra The era of the draft.
/// The triple (staker, draftEra, id) is a unique ID among drafts
/// @param staker The address of the unstaker
/// @param rsrAmount {qRSR} How much RSR this unstaking was worth
event UnstakingCompleted(
uint256 indexed firstId,
uint256 indexed endId,
uint256 draftEra,
address indexed staker,
uint256 rsrAmount
);
/// Emitted when RSR unstaking is cancelled
/// @param firstId The beginning of the range of draft IDs withdrawn in this transaction
/// @param endId The end of range of draft IDs withdrawn in this transaction
/// (ID i was withdrawn if firstId <= i < endId)
/// @param draftEra The era of the draft.
/// The triple (staker, draftEra, id) is a unique ID among drafts
/// @param staker The address of the unstaker
/// @param rsrAmount {qRSR} How much RSR this unstaking was worth
event UnstakingCancelled(
uint256 indexed firstId,
uint256 indexed endId,
uint256 draftEra,
address indexed staker,
uint256 rsrAmount
);
/// Emitted whenever the exchange rate changes
event ExchangeRateSet(uint192 oldVal, uint192 newVal);
/// Emitted whenever RSR are paids out
event RewardsPaid(uint256 rsrAmt);
/// Emitted if all the RSR in the staking pool is seized and all balances are reset to zero.
event AllBalancesReset(uint256 indexed newEra);
/// Emitted if all the RSR in the unstakin pool is seized, and all ongoing unstaking is voided.
event AllUnstakingReset(uint256 indexed newEra);
event UnstakingDelaySet(uint48 oldVal, uint48 newVal);
event RewardRatioSet(uint192 oldVal, uint192 newVal);
event WithdrawalLeakSet(uint192 oldVal, uint192 newVal);
// Initialization
function init(
IMain main_,
string memory name_,
string memory symbol_,
uint48 unstakingDelay_,
uint192 rewardRatio_,
uint192 withdrawalLeak_
) external;
/// Gather and payout rewards from rsrTrader
/// @custom:interaction
function payoutRewards() external;
/// Stakes an RSR `amount` on the corresponding RToken to earn yield and over-collateralized
/// the system
/// @param amount {qRSR}
/// @custom:interaction
function stake(uint256 amount) external;
/// Begins a delayed unstaking for `amount` stRSR
/// @param amount {qStRSR}
/// @custom:interaction
function unstake(uint256 amount) external;
/// Complete delayed unstaking for the account, up to (but not including!) `endId`
/// @custom:interaction
function withdraw(address account, uint256 endId) external;
/// Cancel unstaking for the account, up to (but not including!) `endId`
/// @custom:interaction
function cancelUnstake(uint256 endId) external;
/// Seize RSR, only callable by main.backingManager()
/// @custom:protected
function seizeRSR(uint256 amount) external;
/// Reset all stakes and advance era
/// @custom:governance
function resetStakes() external;
/// Return the maximum valid value of endId such that withdraw(endId) should immediately work
function endIdForWithdraw(address account) external view returns (uint256 endId);
/// @return {qRSR/qStRSR} The exchange rate between RSR and StRSR
function exchangeRate() external view returns (uint192);
}
interface TestIStRSR is IStRSR {
function rewardRatio() external view returns (uint192);
function setRewardRatio(uint192) external;
function unstakingDelay() external view returns (uint48);
function setUnstakingDelay(uint48) external;
function withdrawalLeak() external view returns (uint192);
function setWithdrawalLeak(uint192) external;
function increaseAllowance(address, uint256) external returns (bool);
function decreaseAllowance(address, uint256) external returns (bool);
/// @return {qStRSR/qRSR} The exchange rate between StRSR and RSR
function exchangeRate() external view returns (uint192);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./IBroker.sol";
enum TradeStatus {
NOT_STARTED, // before init()
OPEN, // after init() and before settle()
CLOSED, // after settle()
// === Intermediate-tx state ===
PENDING // during init() or settle() (reentrancy protection)
}
/**
* Simple generalized trading interface for all Trade contracts to obey
*
* Usage: if (canSettle()) settle()
*/
interface ITrade {
/// Complete the trade and transfer tokens back to the origin trader
/// @return soldAmt {qSellTok} The quantity of tokens sold
/// @return boughtAmt {qBuyTok} The quantity of tokens bought
function settle() external returns (uint256 soldAmt, uint256 boughtAmt);
function sell() external view returns (IERC20Metadata);
function buy() external view returns (IERC20Metadata);
/// @return The timestamp at which the trade is projected to become settle-able
function endTime() external view returns (uint48);
/// @return True if the trade can be settled
/// @dev Should be guaranteed to be true eventually as an invariant
function canSettle() external view returns (bool);
/// @return TradeKind.DUTCH_AUCTION or TradeKind.BATCH_AUCTION
// solhint-disable-next-line func-name-mixedcase
function KIND() external view returns (TradeKind);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "./IAsset.sol";
import "./IComponent.sol";
import "./ITrade.sol";
import "./IRewardable.sol";
/**
* @title ITrading
* @notice Common events and refresher function for all Trading contracts
*/
interface ITrading is IComponent, IRewardableComponent {
event MaxTradeSlippageSet(uint192 oldVal, uint192 newVal);
event MinTradeVolumeSet(uint192 oldVal, uint192 newVal);
/// Emitted when a trade is started
/// @param trade The one-time-use trade contract that was just deployed
/// @param sell The token to sell
/// @param buy The token to buy
/// @param sellAmount {qSellTok} The quantity of the selling token
/// @param minBuyAmount {qBuyTok} The minimum quantity of the buying token to accept
event TradeStarted(
ITrade indexed trade,
IERC20 indexed sell,
IERC20 indexed buy,
uint256 sellAmount,
uint256 minBuyAmount
);
/// Emitted after a trade ends
/// @param trade The one-time-use trade contract
/// @param sell The token to sell
/// @param buy The token to buy
/// @param sellAmount {qSellTok} The quantity of the token sold
/// @param buyAmount {qBuyTok} The quantity of the token bought
event TradeSettled(
ITrade indexed trade,
IERC20 indexed sell,
IERC20 indexed buy,
uint256 sellAmount,
uint256 buyAmount
);
/// Settle a single trade, expected to be used with multicall for efficient mass settlement
/// @param sell The sell token in the trade
/// @return The trade settled
/// @custom:refresher
function settleTrade(IERC20 sell) external returns (ITrade);
/// @return {%} The maximum trade slippage acceptable
function maxTradeSlippage() external view returns (uint192);
/// @return {UoA} The minimum trade volume in UoA, applies to all assets
function minTradeVolume() external view returns (uint192);
/// @return The ongoing trade for a sell token, or the zero address
function trades(IERC20 sell) external view returns (ITrade);
/// @return The number of ongoing trades open
function tradesOpen() external view returns (uint48);
/// @return The number of total trades ever opened
function tradesNonce() external view returns (uint256);
}
interface TestITrading is ITrading {
/// @custom:governance
function setMaxTradeSlippage(uint192 val) external;
/// @custom:governance
function setMinTradeVolume(uint192 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
interface IVersioned {
function version() external view returns (string memory);
}// SPDX-License-Identifier: BlueOak-1.0.0 // solhint-disable func-name-mixedcase func-visibility pragma solidity ^0.8.19; /// @title FixedPoint, a fixed-point arithmetic library defining the custom type uint192 /// @author Matt Elder <[email protected]> and the Reserve Team <https://reserve.org> /** The logical type `uint192 ` is a 192 bit value, representing an 18-decimal Fixed-point fractional value. This is what's described in the Solidity documentation as "fixed192x18" -- a value represented by 192 bits, that makes 18 digits available to the right of the decimal point. The range of values that uint192 can represent is about [-1.7e20, 1.7e20]. Unless a function explicitly says otherwise, it will fail on overflow. To be clear, the following should hold: toFix(0) == 0 toFix(1) == 1e18 */ // Analysis notes: // Every function should revert iff its result is out of bounds. // Unless otherwise noted, when a rounding mode is given, that mode is applied to // a single division that may happen as the last step in the computation. // Unless otherwise noted, when a rounding mode is *not* given but is needed, it's FLOOR. // For each, we comment: // - @return is the value expressed in "value space", where uint192(1e18) "is" 1.0 // - as-ints: is the value expressed in "implementation space", where uint192(1e18) "is" 1e18 // The "@return" expression is suitable for actually using the library // The "as-ints" expression is suitable for testing // A uint value passed to this library was out of bounds for uint192 operations error UIntOutOfBounds(); bytes32 constant UIntOutofBoundsHash = keccak256(abi.encodeWithSignature("UIntOutOfBounds()")); // Used by P1 implementation for easier casting uint256 constant FIX_ONE_256 = 1e18; uint8 constant FIX_DECIMALS = 18; // If a particular uint192 is represented by the uint192 n, then the uint192 represents the // value n/FIX_SCALE. uint64 constant FIX_SCALE = 1e18; // FIX_SCALE Squared: uint128 constant FIX_SCALE_SQ = 1e36; // The largest integer that can be converted to uint192 . // This is a bit bigger than 3.1e39 uint192 constant FIX_MAX_INT = type(uint192).max / FIX_SCALE; uint192 constant FIX_ZERO = 0; // The uint192 representation of zero. uint192 constant FIX_ONE = FIX_SCALE; // The uint192 representation of one. uint192 constant FIX_MAX = type(uint192).max; // The largest uint192. (Not an integer!) uint192 constant FIX_MIN = 0; // The smallest uint192. /// An enum that describes a rounding approach for converting to ints enum RoundingMode { FLOOR, // Round towards zero ROUND, // Round to the nearest int CEIL // Round away from zero } RoundingMode constant FLOOR = RoundingMode.FLOOR; RoundingMode constant ROUND = RoundingMode.ROUND; RoundingMode constant CEIL = RoundingMode.CEIL; /* @dev Solidity 0.8.x only allows you to change one of type or size per type conversion. Thus, all the tedious-looking double conversions like uint256(uint256 (foo)) See: https://docs.soliditylang.org/en/v0.8.17/080-breaking-changes.html#new-restrictions */ /// Explicitly convert a uint256 to a uint192. Revert if the input is out of bounds. function _safeWrap(uint256 x) pure returns (uint192) { if (FIX_MAX < x) revert UIntOutOfBounds(); return uint192(x); } /// Convert a uint to its Fix representation. /// @return x // as-ints: x * 1e18 function toFix(uint256 x) pure returns (uint192) { return _safeWrap(x * FIX_SCALE); } /// Convert a uint to its fixed-point representation, and left-shift its value `shiftLeft` /// decimal digits. /// @return x * 10**shiftLeft // as-ints: x * 10**(shiftLeft + 18) function shiftl_toFix(uint256 x, int8 shiftLeft) pure returns (uint192) { return shiftl_toFix(x, shiftLeft, FLOOR); } /// @return x * 10**shiftLeft // as-ints: x * 10**(shiftLeft + 18) function shiftl_toFix( uint256 x, int8 shiftLeft, RoundingMode rounding ) pure returns (uint192) { // conditions for avoiding overflow if (x == 0) return 0; if (shiftLeft <= -96) return (rounding == CEIL ? 1 : 0); // 0 < uint.max / 10**77 < 0.5 if (40 <= shiftLeft) revert UIntOutOfBounds(); // 10**56 < FIX_MAX < 10**57 shiftLeft += 18; uint256 coeff = 10**abs(shiftLeft); uint256 shifted = (shiftLeft >= 0) ? x * coeff : _divrnd(x, coeff, rounding); return _safeWrap(shifted); } /// Divide a uint by a uint192, yielding a uint192 /// This may also fail if the result is MIN_uint192! not fixing this for optimization's sake. /// @return x / y // as-ints: x * 1e36 / y function divFix(uint256 x, uint192 y) pure returns (uint192) { // If we didn't have to worry about overflow, we'd just do `return x * 1e36 / _y` // If it's safe to do this operation the easy way, do it: if (x < uint256(type(uint256).max / FIX_SCALE_SQ)) { return _safeWrap(uint256(x * FIX_SCALE_SQ) / y); } else { return _safeWrap(mulDiv256(x, FIX_SCALE_SQ, y)); } } /// Divide a uint by a uint, yielding a uint192 /// @return x / y // as-ints: x * 1e18 / y function divuu(uint256 x, uint256 y) pure returns (uint192) { return _safeWrap(mulDiv256(FIX_SCALE, x, y)); } /// @return min(x,y) // as-ints: min(x,y) function fixMin(uint192 x, uint192 y) pure returns (uint192) { return x < y ? x : y; } /// @return max(x,y) // as-ints: max(x,y) function fixMax(uint192 x, uint192 y) pure returns (uint192) { return x > y ? x : y; } /// @return absoluteValue(x,y) // as-ints: absoluteValue(x,y) function abs(int256 x) pure returns (uint256) { return x < 0 ? uint256(-x) : uint256(x); } /// Divide two uints, returning a uint, using rounding mode `rounding`. /// @return numerator / divisor // as-ints: numerator / divisor function _divrnd( uint256 numerator, uint256 divisor, RoundingMode rounding ) pure returns (uint256) { uint256 result = numerator / divisor; if (rounding == FLOOR) return result; if (rounding == ROUND) { if (numerator % divisor > (divisor - 1) / 2) { result++; } } else { if (numerator % divisor > 0) { result++; } } return result; } library FixLib { /// Again, all arithmetic functions fail if and only if the result is out of bounds. /// Convert this fixed-point value to a uint. Round towards zero if needed. /// @return x // as-ints: x / 1e18 function toUint(uint192 x) internal pure returns (uint136) { return toUint(x, FLOOR); } /// Convert this uint192 to a uint /// @return x // as-ints: x / 1e18 with rounding function toUint(uint192 x, RoundingMode rounding) internal pure returns (uint136) { return uint136(_divrnd(uint256(x), FIX_SCALE, rounding)); } /// Return the uint192 shifted to the left by `decimal` digits /// (Similar to a bitshift but in base 10) /// @return x * 10**decimals // as-ints: x * 10**decimals function shiftl(uint192 x, int8 decimals) internal pure returns (uint192) { return shiftl(x, decimals, FLOOR); } /// Return the uint192 shifted to the left by `decimal` digits /// (Similar to a bitshift but in base 10) /// @return x * 10**decimals // as-ints: x * 10**decimals function shiftl( uint192 x, int8 decimals, RoundingMode rounding ) internal pure returns (uint192) { // Handle overflow cases if (x == 0) return 0; if (decimals <= -59) return (rounding == CEIL ? 1 : 0); // 59, because 1e58 > 2**192 if (58 <= decimals) revert UIntOutOfBounds(); // 58, because x * 1e58 > 2 ** 192 if x != 0 uint256 coeff = uint256(10**abs(decimals)); return _safeWrap(decimals >= 0 ? x * coeff : _divrnd(x, coeff, rounding)); } /// Add a uint192 to this uint192 /// @return x + y // as-ints: x + y function plus(uint192 x, uint192 y) internal pure returns (uint192) { return x + y; } /// Add a uint to this uint192 /// @return x + y // as-ints: x + y*1e18 function plusu(uint192 x, uint256 y) internal pure returns (uint192) { return _safeWrap(x + y * FIX_SCALE); } /// Subtract a uint192 from this uint192 /// @return x - y // as-ints: x - y function minus(uint192 x, uint192 y) internal pure returns (uint192) { return x - y; } /// Subtract a uint from this uint192 /// @return x - y // as-ints: x - y*1e18 function minusu(uint192 x, uint256 y) internal pure returns (uint192) { return _safeWrap(uint256(x) - uint256(y * FIX_SCALE)); } /// Multiply this uint192 by a uint192 /// Round truncated values to the nearest available value. 5e-19 rounds away from zero. /// @return x * y // as-ints: x * y/1e18 [division using ROUND, not FLOOR] function mul(uint192 x, uint192 y) internal pure returns (uint192) { return mul(x, y, ROUND); } /// Multiply this uint192 by a uint192 /// @return x * y // as-ints: x * y/1e18 function mul( uint192 x, uint192 y, RoundingMode rounding ) internal pure returns (uint192) { return _safeWrap(_divrnd(uint256(x) * uint256(y), FIX_SCALE, rounding)); } /// Multiply this uint192 by a uint /// @return x * y // as-ints: x * y function mulu(uint192 x, uint256 y) internal pure returns (uint192) { return _safeWrap(x * y); } /// Divide this uint192 by a uint192 /// @return x / y // as-ints: x * 1e18 / y function div(uint192 x, uint192 y) internal pure returns (uint192) { return div(x, y, FLOOR); } /// Divide this uint192 by a uint192 /// @return x / y // as-ints: x * 1e18 / y function div( uint192 x, uint192 y, RoundingMode rounding ) internal pure returns (uint192) { // Multiply-in FIX_SCALE before dividing by y to preserve precision. return _safeWrap(_divrnd(uint256(x) * FIX_SCALE, y, rounding)); } /// Divide this uint192 by a uint /// @return x / y // as-ints: x / y function divu(uint192 x, uint256 y) internal pure returns (uint192) { return divu(x, y, FLOOR); } /// Divide this uint192 by a uint /// @return x / y // as-ints: x / y function divu( uint192 x, uint256 y, RoundingMode rounding ) internal pure returns (uint192) { return _safeWrap(_divrnd(x, y, rounding)); } uint64 constant FIX_HALF = uint64(FIX_SCALE) / 2; /// Raise this uint192 to a nonnegative integer power. Requires that x_ <= FIX_ONE /// Gas cost is O(lg(y)), precision is +- 1e-18. /// @return x_ ** y // as-ints: x_ ** y / 1e18**(y-1) <- technically correct for y = 0. :D function powu(uint192 x_, uint48 y) internal pure returns (uint192) { require(x_ <= FIX_ONE); if (y == 1) return x_; if (x_ == FIX_ONE || y == 0) return FIX_ONE; uint256 x = uint256(x_) * FIX_SCALE; // x is D36 uint256 result = FIX_SCALE_SQ; // result is D36 while (true) { if (y & 1 == 1) result = (result * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ; if (y <= 1) break; y = (y >> 1); x = (x * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ; } return _safeWrap(result / FIX_SCALE); } /// Comparison operators... function lt(uint192 x, uint192 y) internal pure returns (bool) { return x < y; } function lte(uint192 x, uint192 y) internal pure returns (bool) { return x <= y; } function gt(uint192 x, uint192 y) internal pure returns (bool) { return x > y; } function gte(uint192 x, uint192 y) internal pure returns (bool) { return x >= y; } function eq(uint192 x, uint192 y) internal pure returns (bool) { return x == y; } function neq(uint192 x, uint192 y) internal pure returns (bool) { return x != y; } /// Return whether or not this uint192 is less than epsilon away from y. /// @return |x - y| < epsilon // as-ints: |x - y| < epsilon function near( uint192 x, uint192 y, uint192 epsilon ) internal pure returns (bool) { uint192 diff = x <= y ? y - x : x - y; return diff < epsilon; } // ================ Chained Operations ================ // The operation foo_bar() always means: // Do foo() followed by bar(), and overflow only if the _end_ result doesn't fit in an uint192 /// Shift this uint192 left by `decimals` digits, and convert to a uint /// @return x * 10**decimals // as-ints: x * 10**(decimals - 18) function shiftl_toUint(uint192 x, int8 decimals) internal pure returns (uint256) { return shiftl_toUint(x, decimals, FLOOR); } /// Shift this uint192 left by `decimals` digits, and convert to a uint. /// @return x * 10**decimals // as-ints: x * 10**(decimals - 18) function shiftl_toUint( uint192 x, int8 decimals, RoundingMode rounding ) internal pure returns (uint256) { // Handle overflow cases if (x == 0) return 0; // always computable, no matter what decimals is if (decimals <= -42) return (rounding == CEIL ? 1 : 0); if (96 <= decimals) revert UIntOutOfBounds(); decimals -= 18; // shift so that toUint happens at the same time. uint256 coeff = uint256(10**abs(decimals)); return decimals >= 0 ? uint256(x * coeff) : uint256(_divrnd(x, coeff, rounding)); } /// Multiply this uint192 by a uint, and output the result as a uint /// @return x * y // as-ints: x * y / 1e18 function mulu_toUint(uint192 x, uint256 y) internal pure returns (uint256) { return mulDiv256(uint256(x), y, FIX_SCALE); } /// Multiply this uint192 by a uint, and output the result as a uint /// @return x * y // as-ints: x * y / 1e18 function mulu_toUint( uint192 x, uint256 y, RoundingMode rounding ) internal pure returns (uint256) { return mulDiv256(uint256(x), y, FIX_SCALE, rounding); } /// Multiply this uint192 by a uint192 and output the result as a uint /// @return x * y // as-ints: x * y / 1e36 function mul_toUint(uint192 x, uint192 y) internal pure returns (uint256) { return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ); } /// Multiply this uint192 by a uint192 and output the result as a uint /// @return x * y // as-ints: x * y / 1e36 function mul_toUint( uint192 x, uint192 y, RoundingMode rounding ) internal pure returns (uint256) { return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ, rounding); } /// Compute x * y / z avoiding intermediate overflow /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z // as-ints: x * y / z function muluDivu( uint192 x, uint256 y, uint256 z ) internal pure returns (uint192) { return muluDivu(x, y, z, FLOOR); } /// Compute x * y / z, avoiding intermediate overflow /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z // as-ints: x * y / z function muluDivu( uint192 x, uint256 y, uint256 z, RoundingMode rounding ) internal pure returns (uint192) { return _safeWrap(mulDiv256(x, y, z, rounding)); } /// Compute x * y / z on Fixes, avoiding intermediate overflow /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z // as-ints: x * y / z function mulDiv( uint192 x, uint192 y, uint192 z ) internal pure returns (uint192) { return mulDiv(x, y, z, FLOOR); } /// Compute x * y / z on Fixes, avoiding intermediate overflow /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z // as-ints: x * y / z function mulDiv( uint192 x, uint192 y, uint192 z, RoundingMode rounding ) internal pure returns (uint192) { return _safeWrap(mulDiv256(x, y, z, rounding)); } // === safe*() === /// Multiply two fixes, rounding up to FIX_MAX and down to 0 /// @param a First param to multiply /// @param b Second param to multiply function safeMul( uint192 a, uint192 b, RoundingMode rounding ) internal pure returns (uint192) { // untestable: // a will never = 0 here because of the check in _price() if (a == 0 || b == 0) return 0; // untestable: // a = FIX_MAX iff b = 0 if (a == FIX_MAX || b == FIX_MAX) return FIX_MAX; // return FIX_MAX instead of throwing overflow errors. unchecked { // p and mul *are* Fix values, so have 18 decimals (D18) uint256 rawDelta = uint256(b) * a; // {D36} = {D18} * {D18} // if we overflowed, then return FIX_MAX if (rawDelta / b != a) return FIX_MAX; uint256 shiftDelta = rawDelta; // add in rounding if (rounding == RoundingMode.ROUND) shiftDelta += (FIX_ONE / 2); else if (rounding == RoundingMode.CEIL) shiftDelta += FIX_ONE - 1; // untestable (here there be dragons): // (below explanation is for the ROUND case, but it extends to the FLOOR/CEIL too) // A) shiftDelta = rawDelta + (FIX_ONE / 2) // shiftDelta overflows if: // B) shiftDelta = MAX_UINT256 - FIX_ONE/2 + 1 // rawDelta + (FIX_ONE/2) = MAX_UINT256 - FIX_ONE/2 + 1 // b * a = MAX_UINT256 - FIX_ONE + 1 // therefore shiftDelta overflows if: // C) b = (MAX_UINT256 - FIX_ONE + 1) / a // MAX_UINT256 ~= 1e77 , FIX_MAX ~= 6e57 (6e20 difference in magnitude) // a <= 1e21 (MAX_TARGET_AMT) // a must be between 1e19 & 1e20 in order for b in (C) to be uint192, // but a would have to be < 1e18 in order for (A) to overflow if (shiftDelta < rawDelta) return FIX_MAX; // return FIX_MAX if return result would truncate if (shiftDelta / FIX_ONE > FIX_MAX) return FIX_MAX; // return _div(rawDelta, FIX_ONE, rounding) return uint192(shiftDelta / FIX_ONE); // {D18} = {D36} / {D18} } } /// Divide two fixes, rounding up to FIX_MAX and down to 0 /// @param a Numerator /// @param b Denominator function safeDiv( uint192 a, uint192 b, RoundingMode rounding ) internal pure returns (uint192) { if (a == 0) return 0; if (b == 0) return FIX_MAX; uint256 raw = _divrnd(FIX_ONE_256 * a, uint256(b), rounding); if (raw >= FIX_MAX) return FIX_MAX; return uint192(raw); // don't need _safeWrap } /// Multiplies two fixes and divide by a third /// @param a First to multiply /// @param b Second to multiply /// @param c Denominator function safeMulDiv( uint192 a, uint192 b, uint192 c, RoundingMode rounding ) internal pure returns (uint192 result) { if (a == 0 || b == 0) return 0; if (a == FIX_MAX || b == FIX_MAX || c == 0) return FIX_MAX; uint256 result_256; unchecked { (uint256 hi, uint256 lo) = fullMul(a, b); if (hi >= c) return FIX_MAX; uint256 mm = mulmod(a, b, c); if (mm > lo) hi -= 1; lo -= mm; uint256 pow2 = c & (0 - c); uint256 c_256 = uint256(c); // Warning: Should not access c below this line c_256 /= pow2; lo /= pow2; lo += hi * ((0 - pow2) / pow2 + 1); uint256 r = 1; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; result_256 = lo * r; // Apply rounding if (rounding == CEIL) { if (mm > 0) result_256 += 1; } else if (rounding == ROUND) { if (mm > ((c_256 - 1) / 2)) result_256 += 1; } } if (result_256 >= FIX_MAX) return FIX_MAX; return uint192(result_256); } } // ================ a couple pure-uint helpers================ // as-ints comments are omitted here, because they're the same as @return statements, because // these are all pure uint functions /// Return (x*y/z), avoiding intermediate overflow. // Adapted from sources: // https://medium.com/coinmonks/4db014e080b1, https://medium.com/wicketh/afa55870a65 // and quite a few of the other excellent "Mathemagic" posts from https://medium.com/wicketh /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return result x * y / z function mulDiv256( uint256 x, uint256 y, uint256 z ) pure returns (uint256 result) { unchecked { (uint256 hi, uint256 lo) = fullMul(x, y); if (hi >= z) revert UIntOutOfBounds(); uint256 mm = mulmod(x, y, z); if (mm > lo) hi -= 1; lo -= mm; uint256 pow2 = z & (0 - z); z /= pow2; lo /= pow2; lo += hi * ((0 - pow2) / pow2 + 1); uint256 r = 1; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; result = lo * r; } } /// Return (x*y/z), avoiding intermediate overflow. /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z function mulDiv256( uint256 x, uint256 y, uint256 z, RoundingMode rounding ) pure returns (uint256) { uint256 result = mulDiv256(x, y, z); if (rounding == FLOOR) return result; uint256 mm = mulmod(x, y, z); if (rounding == CEIL) { if (mm > 0) result += 1; } else { if (mm > ((z - 1) / 2)) result += 1; // z should be z-1 } return result; } /// Return (x*y) as a "virtual uint512" (lo, hi), representing (hi*2**256 + lo) /// Adapted from sources: /// https://medium.com/wicketh/27650fec525d, https://medium.com/coinmonks/4db014e080b1 /// @dev Intended to be internal to this library /// @return hi (hi, lo) satisfies hi*(2**256) + lo == x * y /// @return lo (paired with `hi`) function fullMul(uint256 x, uint256 y) pure returns (uint256 hi, uint256 lo) { unchecked { uint256 mm = mulmod(x, y, uint256(0) - uint256(1)); lo = x * y; hi = mm - lo; if (mm < lo) hi -= 1; } }
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./Fixed.sol";
uint48 constant ONE_HOUR = 3600; // {seconds/hour}
/**
* @title ThrottleLib
* A library that implements a usage throttle that can be used to ensure net issuance
* or net redemption for an RToken never exceeds some bounds per unit time (hour).
*
* It is expected for the RToken to use this library with two instances, one for issuance
* and one for redemption. Issuance causes the available redemption amount to increase, and
* visa versa.
*/
library ThrottleLib {
using FixLib for uint192;
struct Params {
uint256 amtRate; // {qRTok/hour} a quantity of RToken hourly; cannot be 0
uint192 pctRate; // {1/hour} a fraction of RToken hourly; can be 0
}
struct Throttle {
// === Gov params ===
Params params;
// === Cache ===
uint48 lastTimestamp; // {seconds}
uint256 lastAvailable; // {qRTok}
}
/// Reverts if usage amount exceeds available amount
/// @param supply {qRTok} Total RToken supply beforehand
/// @param amount {qRTok} Amount of RToken to use. Should be negative for the issuance
/// throttle during redemption and for the redemption throttle during issuance.
function useAvailable(
Throttle storage throttle,
uint256 supply,
int256 amount
) internal {
// untestable: amtRate will always be greater > 0 due to previous validations
if (throttle.params.amtRate == 0 && throttle.params.pctRate == 0) return;
// Calculate hourly limit
uint256 limit = hourlyLimit(throttle, supply); // {qRTok}
// Calculate available amount before supply change
uint256 available = currentlyAvailable(throttle, limit);
// Update throttle.timestamp if available amount changed or at limit
if (available != throttle.lastAvailable || available == limit) {
throttle.lastTimestamp = uint48(block.timestamp);
}
// Update throttle.lastAvailable
if (amount > 0) {
require(uint256(amount) <= available, "supply change throttled");
available -= uint256(amount);
// untestable: the final else statement, amount will never be 0
} else if (amount < 0) {
available += uint256(-amount);
}
throttle.lastAvailable = available;
}
/// @param limit {qRTok/hour} The hourly limit
/// @return available {qRTok} Amount currently available for consumption
function currentlyAvailable(Throttle storage throttle, uint256 limit)
internal
view
returns (uint256 available)
{
uint48 delta = uint48(block.timestamp) - throttle.lastTimestamp; // {seconds}
available = throttle.lastAvailable + (limit * delta) / ONE_HOUR;
if (available > limit) available = limit;
}
/// @return limit {qRTok} The hourly limit
function hourlyLimit(Throttle storage throttle, uint256 supply)
internal
view
returns (uint256 limit)
{
Params storage params = throttle.params;
// Calculate hourly limit as: max(params.amtRate, supply.mul(params.pctRate))
limit = (supply * params.pctRate) / FIX_ONE_256; // {qRTok}
if (params.amtRate > limit) limit = params.amtRate;
}
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
contract CometHelpers {
uint64 internal constant BASE_INDEX_SCALE = 1e15;
uint256 public constant EXP_SCALE = 1e18;
uint256 public constant BASE_SCALE = 1e6;
error InvalidUInt64();
error InvalidUInt104();
error InvalidInt256();
error NegativeNumber();
function safe64(uint256 n) internal pure returns (uint64) {
// untested:
// comet code, overflow is hard to cover
if (n > type(uint64).max) revert InvalidUInt64();
return uint64(n);
}
function presentValueSupply(uint64 baseSupplyIndex_, uint104 principalValue_)
internal
pure
returns (uint256)
{
return (uint256(principalValue_) * baseSupplyIndex_) / BASE_INDEX_SCALE;
}
function principalValueSupply(uint64 baseSupplyIndex_, uint256 presentValue_)
internal
pure
returns (uint104)
{
return safe104((presentValue_ * BASE_INDEX_SCALE) / baseSupplyIndex_);
}
function safe104(uint256 n) internal pure returns (uint104) {
// untested:
// comet code, overflow is hard to cover
if (n > type(uint104).max) revert InvalidUInt104();
return uint104(n);
}
/**
* @dev Multiply a number by a factor
*/
function mulFactor(uint256 n, uint256 factor) internal pure returns (uint256) {
return (n * factor) / EXP_SCALE;
}
function divBaseWei(uint256 n, uint256 baseWei) internal pure returns (uint256) {
return (n * BASE_SCALE) / baseWei;
}
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./vendor/CometInterface.sol";
import "./IWrappedERC20.sol";
import "../../../interfaces/IRewardable.sol";
interface ICusdcV3Wrapper is IWrappedERC20, IRewardable {
struct UserBasic {
uint104 principal;
uint64 baseTrackingAccrued;
uint64 baseTrackingIndex;
uint256 rewardsClaimed;
}
function deposit(uint256 amount) external;
function depositTo(address account, uint256 amount) external;
function depositFrom(
address from,
address dst,
uint256 amount
) external;
function withdraw(uint256 amount) external;
function withdrawTo(address to, uint256 amount) external;
function withdrawFrom(
address src,
address to,
uint256 amount
) external;
function claimTo(address src, address to) external;
function accrue() external;
function accrueAccount(address account) external;
function underlyingBalanceOf(address account) external view returns (uint256);
function getRewardOwed(address account) external view returns (uint256);
function exchangeRate() external view returns (uint256);
function convertStaticToDynamic(uint104 amount) external view returns (uint256);
function convertDynamicToStatic(uint256 amount) external view returns (uint104);
function baseTrackingAccrued(address account) external view returns (uint256);
function baseTrackingIndex(address account) external view returns (uint64);
function underlyingComet() external view returns (CometInterface);
function rewardERC20() external view returns (IERC20);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IWrappedERC20 is IERC20Metadata {
function allow(address account, bool isAllowed_) external;
function hasPermission(address owner, address manager) external view returns (bool);
function isAllowed(address first, address second) external returns (bool);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
struct TotalsBasic {
uint64 baseSupplyIndex;
uint64 baseBorrowIndex;
uint64 trackingSupplyIndex;
uint64 trackingBorrowIndex;
uint104 totalSupplyBase;
uint104 totalBorrowBase;
uint40 lastAccrualTime;
uint8 pauseFlags;
}
/**
* @title Compound's Comet Ext Interface
* @notice An efficient monolithic money market protocol
* @author Compound
*/
abstract contract CometExtInterface {
error BadAmount();
error BadNonce();
error BadSignatory();
error InvalidValueS();
error InvalidValueV();
error SignatureExpired();
function allow(address manager, bool isAllowed) external virtual;
function allowBySig(
address owner,
address manager,
bool isAllowed,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external virtual;
function collateralBalanceOf(address account, address asset)
external
view
virtual
returns (uint128);
function baseTrackingAccrued(address account) external view virtual returns (uint64);
function baseAccrualScale() external view virtual returns (uint64);
function baseIndexScale() external view virtual returns (uint64);
function factorScale() external view virtual returns (uint64);
function priceScale() external view virtual returns (uint64);
function maxAssets() external view virtual returns (uint8);
function totalsBasic() external view virtual returns (TotalsBasic memory);
function version() external view virtual returns (string memory);
/**
* ===== ERC20 interfaces =====
* Does not include the following functions/events, which are defined in `CometMainInterface`
* instead:
* - function decimals() virtual external view returns (uint8)
* - function totalSupply() virtual external view returns (uint256)
* - function transfer(address dst, uint amount) virtual external returns (bool)
* - function transferFrom(address src, address dst, uint amount) virtual external returns
(bool)
* - function balanceOf(address owner) virtual external view returns (uint256)
* - event Transfer(address indexed from, address indexed to, uint256 amount)
*/
function name() external view virtual returns (string memory);
function symbol() external view virtual returns (string memory);
/**
* @notice Approve `spender` to transfer up to `amount` from `src`
* @dev This will overwrite the approval amount for `spender`
* and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
* @param spender The address of the account which may transfer tokens
* @param amount The number of tokens that are approved (-1 means infinite)
* @return Whether or not the approval succeeded
*/
function approve(address spender, uint256 amount) external virtual returns (bool);
/**
* @notice Get the current allowance from `owner` for `spender`
* @param owner The address of the account which owns the tokens to be spent
* @param spender The address of the account which may transfer tokens
* @return The number of tokens allowed to be spent (-1 means infinite)
*/
function allowance(address owner, address spender) external view virtual returns (uint256);
event Approval(address indexed owner, address indexed spender, uint256 amount);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
import "./CometMainInterface.sol";
import "./CometExtInterface.sol";
/**
* @title Compound's Comet Interface
* @notice An efficient monolithic money market protocol
* @author Compound
*/
abstract contract CometInterface is CometMainInterface, CometExtInterface {
struct UserBasic {
int104 principal;
uint64 baseTrackingIndex;
uint64 baseTrackingAccrued;
}
function userBasic(address account) external view virtual returns (UserBasic memory);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
struct AssetInfo {
uint8 offset;
address asset;
address priceFeed;
uint64 scale;
uint64 borrowCollateralFactor;
uint64 liquidateCollateralFactor;
uint64 liquidationFactor;
uint128 supplyCap;
}
/**
* @title Compound's Comet Main Interface (without Ext)
* @notice An efficient monolithic money market protocol
* @author Compound
*/
abstract contract CometMainInterface {
error Absurd();
error AlreadyInitialized();
error BadAsset();
error BadDecimals();
error BadDiscount();
error BadMinimum();
error BadPrice();
error BorrowTooSmall();
error BorrowCFTooLarge();
error InsufficientReserves();
error LiquidateCFTooLarge();
error NoSelfTransfer();
error NotCollateralized();
error NotForSale();
error NotLiquidatable();
error Paused();
error SupplyCapExceeded();
error TimestampTooLarge();
error TooManyAssets();
error TooMuchSlippage();
error TransferInFailed();
error TransferOutFailed();
error Unauthorized();
event Supply(address indexed from, address indexed dst, uint256 amount);
event Transfer(address indexed from, address indexed to, uint256 amount);
event Withdraw(address indexed src, address indexed to, uint256 amount);
event SupplyCollateral(
address indexed from,
address indexed dst,
address indexed asset,
uint256 amount
);
event TransferCollateral(
address indexed from,
address indexed to,
address indexed asset,
uint256 amount
);
event WithdrawCollateral(
address indexed src,
address indexed to,
address indexed asset,
uint256 amount
);
/// @notice Event emitted when a borrow position is absorbed by the protocol
event AbsorbDebt(
address indexed absorber,
address indexed borrower,
uint256 basePaidOut,
uint256 usdValue
);
/// @notice Event emitted when a user's collateral is absorbed by the protocol
event AbsorbCollateral(
address indexed absorber,
address indexed borrower,
address indexed asset,
uint256 collateralAbsorbed,
uint256 usdValue
);
/// @notice Event emitted when a collateral asset is purchased from the protocol
event BuyCollateral(
address indexed buyer,
address indexed asset,
uint256 baseAmount,
uint256 collateralAmount
);
/// @notice Event emitted when an action is paused/unpaused
event PauseAction(
bool supplyPaused,
bool transferPaused,
bool withdrawPaused,
bool absorbPaused,
bool buyPaused
);
/// @notice Event emitted when reserves are withdrawn by the governor
event WithdrawReserves(address indexed to, uint256 amount);
function supply(address asset, uint256 amount) external virtual;
function supplyTo(
address dst,
address asset,
uint256 amount
) external virtual;
function supplyFrom(
address from,
address dst,
address asset,
uint256 amount
) external virtual;
function transfer(address dst, uint256 amount) external virtual returns (bool);
function transferFrom(
address src,
address dst,
uint256 amount
) external virtual returns (bool);
function transferAsset(
address dst,
address asset,
uint256 amount
) external virtual;
function transferAssetFrom(
address src,
address dst,
address asset,
uint256 amount
) external virtual;
function withdraw(address asset, uint256 amount) external virtual;
function withdrawTo(
address to,
address asset,
uint256 amount
) external virtual;
function withdrawFrom(
address src,
address to,
address asset,
uint256 amount
) external virtual;
function approveThis(
address manager,
address asset,
uint256 amount
) external virtual;
function withdrawReserves(address to, uint256 amount) external virtual;
function absorb(address absorber, address[] calldata accounts) external virtual;
function buyCollateral(
address asset,
uint256 minAmount,
uint256 baseAmount,
address recipient
) external virtual;
function quoteCollateral(address asset, uint256 baseAmount)
public
view
virtual
returns (uint256);
function getAssetInfo(uint8 i) public view virtual returns (AssetInfo memory);
function getAssetInfoByAddress(address asset) public view virtual returns (AssetInfo memory);
function getReserves() public view virtual returns (int256);
function getPrice(address priceFeed) public view virtual returns (uint256);
function isBorrowCollateralized(address account) public view virtual returns (bool);
function isLiquidatable(address account) public view virtual returns (bool);
function totalSupply() external view virtual returns (uint256);
function totalBorrow() external view virtual returns (uint256);
function balanceOf(address owner) public view virtual returns (uint256);
function borrowBalanceOf(address account) public view virtual returns (uint256);
function pause(
bool supplyPaused,
bool transferPaused,
bool withdrawPaused,
bool absorbPaused,
bool buyPaused
) external virtual;
function isSupplyPaused() public view virtual returns (bool);
function isTransferPaused() public view virtual returns (bool);
function isWithdrawPaused() public view virtual returns (bool);
function isAbsorbPaused() public view virtual returns (bool);
function isBuyPaused() public view virtual returns (bool);
function accrueAccount(address account) external virtual;
function getSupplyRate(uint256 utilization) public view virtual returns (uint64);
function getBorrowRate(uint256 utilization) public view virtual returns (uint64);
function getUtilization() public view virtual returns (uint256);
function governor() external view virtual returns (address);
function pauseGuardian() external view virtual returns (address);
function baseToken() external view virtual returns (address);
function baseTokenPriceFeed() external view virtual returns (address);
function extensionDelegate() external view virtual returns (address);
/// @dev uint64
function supplyKink() external view virtual returns (uint256);
/// @dev uint64
function supplyPerSecondInterestRateSlopeLow() external view virtual returns (uint256);
/// @dev uint64
function supplyPerSecondInterestRateSlopeHigh() external view virtual returns (uint256);
/// @dev uint64
function supplyPerSecondInterestRateBase() external view virtual returns (uint256);
/// @dev uint64
function borrowKink() external view virtual returns (uint256);
/// @dev uint64
function borrowPerSecondInterestRateSlopeLow() external view virtual returns (uint256);
/// @dev uint64
function borrowPerSecondInterestRateSlopeHigh() external view virtual returns (uint256);
/// @dev uint64
function borrowPerSecondInterestRateBase() external view virtual returns (uint256);
/// @dev uint64
function storeFrontPriceFactor() external view virtual returns (uint256);
/// @dev uint64
function baseScale() external view virtual returns (uint256);
/// @dev uint64
function trackingIndexScale() external view virtual returns (uint256);
/// @dev uint64
function baseTrackingSupplySpeed() external view virtual returns (uint256);
/// @dev uint64
function baseTrackingBorrowSpeed() external view virtual returns (uint256);
/// @dev uint104
function baseMinForRewards() external view virtual returns (uint256);
/// @dev uint104
function baseBorrowMin() external view virtual returns (uint256);
/// @dev uint104
function targetReserves() external view virtual returns (uint256);
function numAssets() external view virtual returns (uint8);
function decimals() external view virtual returns (uint8);
function initializeStorage() external virtual;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
interface ICometRewards {
struct RewardConfig {
address token;
uint64 rescaleFactor;
bool shouldUpscale;
}
struct RewardOwed {
address token;
uint256 owed;
}
function rewardConfig(address) external view returns (RewardConfig memory);
function claim(
address comet,
address src,
bool shouldAccrue
) external;
function getRewardOwed(address comet, address account) external returns (RewardOwed memory);
function claimTo(
address comet,
address src,
address to,
bool shouldAccrue
) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IWrappedERC20.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This is a "soft-fork" of Open Zeppelin's ERC20 contract but with some notable
* changes including:
*
* - The allowance system is changed so that users are either allowed or not.
* There are no approved/allowed amounts. `approve` function still exists to
* adhere to the ERC-20 interface.
*
* - Adds `allow` for easier authorization and is an easier-to-use alternative
* to `approve`.
*
* - All hooks are removed except for `_beforeTokenTransfer` in `_transfer`.
* This is done to save on gas.
*
* - All reverts use custom errors instead of strings. Another gas-optimization.
*
* - Adds `hasPermission` which works the same as `allowance` and checks whether
* a user is authorized to make balance transfers.
*
* - Some state variables are removed in anticipation of this contract
* being inherited by the cUSDCv3 wrapper
*
* 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.
*/
abstract contract WrappedERC20 is IWrappedERC20 {
error BadAmount();
error Unauthorized();
error ZeroAddress();
error ExceedsBalance(uint256 amount);
mapping(address => uint256) private _balances;
mapping(address => mapping(address => bool)) public isAllowed;
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 returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @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) {
_transfer(msg.sender, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender)
public
view
virtual
override
returns (uint256)
{
return hasPermission(owner, spender) ? type(uint256).max : 0;
}
/**
* @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) {
if (spender == address(0)) revert ZeroAddress();
if (amount == type(uint256).max) {
_allow(msg.sender, spender, true);
} else if (amount == 0) {
_allow(msg.sender, spender, false);
} else {
revert BadAmount();
}
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 be authorized to transfer ``from``'s tokens
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
if (!hasPermission(from, msg.sender)) revert Unauthorized();
_transfer(from, to, amount);
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 {
if (from == address(0)) revert ZeroAddress();
if (to == address(0)) revert ZeroAddress();
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
if (amount > fromBalance) revert ExceedsBalance(amount);
unchecked {
_balances[from] = fromBalance - amount;
}
_balances[to] += amount;
emit Transfer(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 {
if (account == address(0)) revert ZeroAddress();
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(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 {
// untestable:
// previously validated, account will not be address(0)
if (account == address(0)) revert ZeroAddress();
uint256 accountBalance = _balances[account];
// untestable:
// ammount previously capped to the account balance
if (amount > accountBalance) revert ExceedsBalance(amount);
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Allow or disallow another address to withdraw, or transfer from the sender.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `manager` cannot be the zero address.
*/
function allow(address account, bool isAllowed_) external {
_allow(msg.sender, account, isAllowed_);
}
/**
* @dev Gives `manager` control over the `owner` s tokens.
*
* This internal function is equivalent to `allow`, 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.
* - `manager` cannot be the zero address.
*/
function _allow(
address owner,
address manager,
bool isAllowed_
) internal {
if (owner == address(0)) revert ZeroAddress();
if (manager == address(0)) revert ZeroAddress();
isAllowed[owner][manager] = isAllowed_;
emit Approval(owner, manager, isAllowed_ ? type(uint256).max : 0);
}
/**
* @dev Determine if the `manager` has permission to act on behalf of the `owner`.
*/
function hasPermission(address owner, address manager) public view returns (bool) {
return owner == manager || isAllowed[owner][manager];
}
/**
* @dev Hook that is called before any transfer of tokens. This does not include
* 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.
*/
// solhint-disable no-empty-blocks
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"cusdcv3","type":"address"},{"internalType":"address","name":"rewardsAddr_","type":"address"},{"internalType":"address","name":"rewardERC20_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BadAmount","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ExceedsBalance","type":"error"},{"inputs":[],"name":"InvalidInt256","type":"error"},{"inputs":[],"name":"InvalidUInt104","type":"error"},{"inputs":[],"name":"InvalidUInt64","type":"error"},{"inputs":[],"name":"NegativeNumber","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"BASE_SCALE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EXP_SCALE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RESCALE_FACTOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TRACKING_INDEX_SCALE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accrue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"accrueAccount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"isAllowed_","type":"bool"}],"name":"allow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"baseTrackingAccrued","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"baseTrackingIndex","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"}],"name":"claimTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"convertDynamicToStatic","outputs":[{"internalType":"uint104","name":"","type":"uint104"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint104","name":"amount","type":"uint104"}],"name":"convertStaticToDynamic","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"exchangeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getRewardOwed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"manager","type":"address"}],"name":"hasPermission","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"isAllowed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardERC20","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardsAddr","outputs":[{"internalType":"contract ICometRewards","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardsClaimed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"underlyingBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlyingComet","outputs":[{"internalType":"contract CometInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawTo","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60e06040523480156200001157600080fd5b506040516200298d3803806200298d833981016040819052620000349162000102565b6040518060400160405280600f81526020016e57726170706564206355534443763360881b81525060405180604001604052806008815260200167776355534443763360c01b81525081600390816200008e9190620001f1565b5060046200009d8282620001f1565b5050506001600160a01b038316620000c85760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0391821660a052811660c05216608052620002bd565b80516001600160a01b0381168114620000fd57600080fd5b919050565b6000806000606084860312156200011857600080fd5b6200012384620000e5565b92506200013360208501620000e5565b91506200014360408501620000e5565b90509250925092565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200017757607f821691505b6020821081036200019857634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620001ec57600081815260208120601f850160051c81016020861015620001c75750805b601f850160051c820191505b81811015620001e857828155600101620001d3565b5050505b505050565b81516001600160401b038111156200020d576200020d6200014c565b62000225816200021e845462000162565b846200019e565b602080601f8311600181146200025d5760008415620002445750858301515b600019600386901b1c1916600185901b178555620001e8565b600085815260208120601f198616915b828110156200028e578886015182559484019460019091019084016200026d565b5085821015620002ad5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60805160a05160c0516125f862000395600039600081816105370152818161097701526109a20152600081816104bc015261090e01526000818161041c015281816108cf01528181610a2e01528181610b8401528181610c7301528181610e2401528181610ea501528181610f4701528181610fdb0152818161101701528181611213015281816112c40152818161134a015281816113ee01528181611615015281816116c601528181611747015281816117bc015281816118420152818161187f01528181611b080152611d8e01526125f86000f3fe608060405234801561001057600080fd5b50600436106102275760003560e01c8063790add0311610130578063b6b55f25116100b8578063d10b5a5b1161007c578063d10b5a5b14610532578063d3f730fd14610559578063dd62ed3e14610579578063f8ba4cff1461058c578063ffaad6a51461059457600080fd5b8063b6b55f25146104de578063bbba205d146104f1578063bc9416b914610500578063bfe69c8d1461050c578063cde680411461051f57600080fd5b806397008d6c116100ff57806397008d6c14610417578063a165437914610456578063a9059cbb14610484578063ab9ba7f414610497578063b15f67b3146104b757600080fd5b8063790add03146103d6578063935a8b84146103e95780639555a942146103fc57806395d89b411461040f57600080fd5b80632e1a7d4d116101b35780633ba0b9a9116101825780633ba0b9a91461032657806343631bfe1461032e5780635f2d5f6e1461035957806368a9674d1461039a57806370a08231146103ad57600080fd5b80632e1a7d4d146102e9578063313ce567146102fc57806334a1ca891461030b578063372500ab1461031e57600080fd5b806318160ddd116101fa57806318160ddd1461029e5780631f986445146102a6578063205c2878146102b057806323b872dd146102c35780632a846398146102d657600080fd5b806306fdde031461022c578063095ea7b31461024a5780630e162e1e1461026d578063110496e514610289575b600080fd5b6102346105a7565b6040516102419190611fc6565b60405180910390f35b61025d610258366004612015565b610639565b6040519015158152602001610241565b61027b66038d7ea4c6800081565b604051908152602001610241565b61029c61029736600461204d565b6106b3565b005b60025461027b565b61027b620f424081565b61029c6102be366004612015565b6106c2565b61025d6102d1366004612084565b6106ce565b61027b6102e43660046120c0565b61070c565b61029c6102f73660046120db565b610818565b60405160068152602001610241565b61029c6103193660046120f4565b610827565b61029c610a0b565b61027b610a17565b61034161033c3660046120db565b610ac4565b6040516001600160681b039091168152602001610241565b6103826103673660046120c0565b6005602052600090815260409020546001600160401b031681565b6040516001600160401b039091168152602001610241565b61029c6103a8366004612084565b610adc565b61027b6103bb3660046120c0565b6001600160a01b031660009081526020819052604090205490565b61027b6103e436600461213c565b610aed565b61027b6103f73660046120c0565b610b05565b61029c61040a366004612084565b610b3b565b610234610b47565b61043e7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610241565b61025d6104643660046120f4565b600160209081526000928352604080842090915290825290205460ff1681565b61025d610492366004612015565b610b56565b61027b6104a53660046120c0565b60066020526000908152604090205481565b61043e7f000000000000000000000000000000000000000000000000000000000000000081565b61029c6104ec3660046120db565b610b63565b61027b670de0b6b3a764000081565b61027b64e8d4a5100081565b61029c61051a3660046120c0565b610b6f565b61025d61052d3660046120f4565b610bf1565b61043e7f000000000000000000000000000000000000000000000000000000000000000081565b61027b6105673660046120c0565b60076020526000908152604090205481565b61027b6105873660046120f4565b610c3d565b61029c610c5e565b61029c6105a2366004612015565b610cd9565b6060600380546105b690612159565b80601f01602080910402602001604051908101604052809291908181526020018280546105e290612159565b801561062f5780601f106106045761010080835404028352916020019161062f565b820191906000526020600020905b81548152906001019060200180831161061257829003601f168201915b5050505050905090565b60006001600160a01b0383166106625760405163d92e233d60e01b815260040160405180910390fd5b600019820361067c5761067733846001610ce5565b6106a9565b816000036106905761067733846000610ce5565b60405163749b593960e01b815260040160405180910390fd5b5060015b92915050565b6106be338383610ce5565b5050565b6106be33338484610daf565b60006106da8433610bf1565b6106f6576040516282b42960e81b815260040160405180910390fd5b6107018484846110e0565b5060015b9392505050565b60008061071761120c565b6001600160a01b0385166000908152600560205260408120549193509150610748906001600160401b0316836121a9565b6001600160401b03169050600066038d7ea4c6800082610785610780886001600160a01b031660009081526020819052604090205490565b6114e2565b6001600160681b031661079891906121d0565b6107a291906121e7565b6001600160a01b0386166000908152600660205260409020546107c59190612209565b6001600160a01b0386166000908152600760205260408120549192506107f064e8d4a51000846121d0565b9050600082821161080257600061080c565b61080c838361221c565b98975050505050505050565b61082433333384610daf565b50565b336108328382610bf1565b61084e576040516282b42960e81b815260040160405180910390fd5b61085783610b6f565b6001600160a01b038316600090815260076020908152604080832054600690925282205490919061088e9064e8d4a51000906121d0565b90506000828211156109a0576108a4838361221c565b6001600160a01b0387811660009081526007602052604090819020859055516313fe176560e21b81527f00000000000000000000000000000000000000000000000000000000000000008216600482015230602482018190526044820152600160648201529192507f00000000000000000000000000000000000000000000000000000000000000001690634ff85d9490608401600060405180830381600087803b15801561095257600080fd5b505af1158015610966573d6000803e3d6000fd5b506109a09250506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690508683611510565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe826040516109fb91815260200190565b60405180910390a2505050505050565b610a153333610827565b565b600080610a2261120c565b509050610abe81610ab97f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a8a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aae9190612240565b61078090600a61233f565b611573565b91505090565b600080610acf61120c565b50905061070581846115a3565b610ae8338484846115cd565b505050565b600080610af861120c565b5090506107058184611573565b6001600160a01b03811660009081526020819052604081205480600003610b2f5750600092915050565b6107056103e4826114e2565b610ae833848484610daf565b6060600480546105b690612159565b60006106a93384846110e0565b610824333333846115cd565b60405163bfe69c8d60e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063bfe69c8d90602401600060405180830381600087803b158015610bd057600080fd5b505af1158015610be4573d6000803e3d6000fd5b5050505061082481611926565b6000816001600160a01b0316836001600160a01b031614806107055750506001600160a01b03918216600090815260016020908152604080832093909416825291909152205460ff1690565b6000610c498383610bf1565b610c54576000610705565b5060001992915050565b60405163bfe69c8d60e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063bfe69c8d90602401600060405180830381600087803b158015610cbf57600080fd5b505af1158015610cd3573d6000803e3d6000fd5b50505050565b6106be333384846115cd565b6001600160a01b038316610d0c5760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b038216610d335760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b038381166000818152600160209081526040808320948716808452949091529020805460ff19168415151790557f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583610d94576000610d98565b6000195b6040519081526020015b60405180910390a3505050565b610db98385610bf1565b610dd5576040516282b42960e81b815260040160405180910390fd5b6000610de084610b05565b905081811015610dee578091505b81600003610e0f5760405163749b593960e01b815260040160405180910390fd5b60405163bfe69c8d60e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063bfe69c8d90602401600060405180830381600087803b158015610e7057600080fd5b505af1158015610e84573d6000803e3d6000fd5b505060405163bfe69c8d60e01b81526001600160a01b0387811660048301527f000000000000000000000000000000000000000000000000000000000000000016925063bfe69c8d9150602401600060405180830381600087803b158015610eeb57600080fd5b505af1158015610eff573d6000803e3d6000fd5b505050506000610f24856001600160a01b031660009081526020819052604090205490565b60405163dc4abafd60e01b81523060048201529091506000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063dc4abafd90602401606060405180830381865afa158015610f8e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb29190612365565b805190915061100286610fc6600a886121e7565b610fd190600a6121d0565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169190611510565b60405163dc4abafd60e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063dc4abafd90602401606060405180830381865afa158015611066573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061108a9190612365565b8051909250600061109b82846123e7565b6001600160681b031690508085116110b05750835b6110b989611926565b6110d4896110c6836114e2565b6001600160681b0316611a1d565b50505050505050505050565b6001600160a01b0383166111075760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b03821661112e5760405163d92e233d60e01b815260040160405180910390fd5b611139838383611af3565b6001600160a01b0383166000908152602081905260409020548082111561117b57604051632e7a668d60e21b8152600481018390526024015b60405180910390fd5b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906111b2908490612209565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516111fe91815260200190565b60405180910390a350505050565b60008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b9f0baf76040518163ffffffff1660e01b815260040161010060405180830381865afa158015611270573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112949190612440565b905060008160c00151426112a89190612517565b825160408401519192509064ffffffffff8316156114d75760007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663189bb2f16040518163ffffffff1660e01b8152600401602060405180830381865afa158015611320573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113449190612535565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637eb711316040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ca9190612535565b60405163d955759d60e01b8152600481018290529091506000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063d955759d90602401602060405180830381865afa158015611435573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611459919061254e565b6001600160401b0316905061149161148c866001600160401b03168864ffffffffff168461148791906121d0565b611b7e565b611b93565b61149b9086612569565b94506114c761148c6114b464ffffffffff8916866121d0565b89608001516001600160681b0316611bbd565b6114d19085612569565b93505050505b909590945092505050565b60006001600160681b0382111561150c57604051630dc7925560e11b815260040160405180910390fd5b5090565b6040516001600160a01b038316602482015260448101829052610ae890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611bcd565b600066038d7ea4c680006115996001600160401b0385166001600160681b0385166121d0565b61070591906121e7565b60006107056001600160401b0384166115c366038d7ea4c68000856121d0565b61078091906121e7565b6115d78385610bf1565b6115f3576040516282b42960e81b815260040160405180910390fd5b6040516370a0823160e01b81526001600160a01b0384811660048301526000917f0000000000000000000000000000000000000000000000000000000000000000909116906370a0823190602401602060405180830381865afa15801561165e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116829190612535565b905080821115611690578091505b816000036116b15760405163749b593960e01b815260040160405180910390fd5b60405163bfe69c8d60e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063bfe69c8d90602401600060405180830381600087803b15801561171257600080fd5b505af1158015611726573d6000803e3d6000fd5b505060405163bfe69c8d60e01b81526001600160a01b0387811660048301527f000000000000000000000000000000000000000000000000000000000000000016925063bfe69c8d9150602401600060405180830381600087803b15801561178d57600080fd5b505af11580156117a1573d6000803e3d6000fd5b505060405163dc4abafd60e01b8152306004820152600092507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316915063dc4abafd90602401606060405180830381865afa15801561180c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118309190612365565b805190915061186a6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016873087611c9f565b60405163dc4abafd60e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063dc4abafd90602401606060405180830381865afa1580156118ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f29190612365565b805190925061190086611926565b61191c8661190e84846123e7565b6001600160681b0316611cd7565b5050505050505050565b6001600160a01b03811660009081526020819052604081205490611948611d87565b6001600160a01b0385166000908152600560205260408120549193509150611979906001600160401b0316836121a9565b6001600160401b0316905066038d7ea4c6800081611996856114e2565b6001600160681b03166119a991906121d0565b6119b391906121e7565b6001600160a01b038516600090815260066020526040812080549091906119db908490612209565b9091555050506001600160a01b03929092166000908152600560205260409020805467ffffffffffffffff19166001600160401b039093169290921790915550565b6001600160a01b038216611a445760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b03821660009081526020819052604090205480821115611a8157604051632e7a668d60e21b815260048101839052602401611172565b6001600160a01b0383166000908152602081905260408120838303905560028054849290611ab090849061221c565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001610da2565b60405163bfe69c8d60e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063bfe69c8d90602401600060405180830381600087803b158015611b5457600080fd5b505af1158015611b68573d6000803e3d6000fd5b50505050611b7583611926565b610ae882611926565b6000670de0b6b3a764000061159983856121d0565b60006001600160401b0382111561150c576040516372a1cb5160e11b815260040160405180910390fd5b600081611599620f4240856121d0565b6000611c22826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611e219092919063ffffffff16565b805190915015610ae85780806020019051810190611c409190612589565b610ae85760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401611172565b6040516001600160a01b0380851660248301528316604482015260648101829052610cd39085906323b872dd60e01b9060840161153c565b6001600160a01b038216611cfe5760405163d92e233d60e01b815260040160405180910390fd5b8060026000828254611d109190612209565b90915550506001600160a01b03821660009081526020819052604081208054839290611d3d908490612209565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b9f0baf76040518163ffffffff1660e01b815260040161010060405180830381865afa158015611deb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0f9190612440565b80516040909101519094909350915050565b6060611e308484600085611e38565b949350505050565b606082471015611e995760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401611172565b6001600160a01b0385163b611ef05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611172565b600080866001600160a01b03168587604051611f0c91906125a6565b60006040518083038185875af1925050503d8060008114611f49576040519150601f19603f3d011682016040523d82523d6000602084013e611f4e565b606091505b5091509150611f5e828286611f69565b979650505050505050565b60608315611f78575081610705565b825115611f885782518084602001fd5b8160405162461bcd60e51b81526004016111729190611fc6565b60005b83811015611fbd578181015183820152602001611fa5565b50506000910152565b6020815260008251806020840152611fe5816040850160208701611fa2565b601f01601f19169190910160400192915050565b80356001600160a01b038116811461201057600080fd5b919050565b6000806040838503121561202857600080fd5b61203183611ff9565b946020939093013593505050565b801515811461082457600080fd5b6000806040838503121561206057600080fd5b61206983611ff9565b915060208301356120798161203f565b809150509250929050565b60008060006060848603121561209957600080fd5b6120a284611ff9565b92506120b060208501611ff9565b9150604084013590509250925092565b6000602082840312156120d257600080fd5b61070582611ff9565b6000602082840312156120ed57600080fd5b5035919050565b6000806040838503121561210757600080fd5b61211083611ff9565b915061211e60208401611ff9565b90509250929050565b6001600160681b038116811461082457600080fd5b60006020828403121561214e57600080fd5b813561070581612127565b600181811c9082168061216d57607f821691505b60208210810361218d57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b6001600160401b038281168282160390808211156121c9576121c9612193565b5092915050565b80820281158282048414176106ad576106ad612193565b60008261220457634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156106ad576106ad612193565b818103818111156106ad576106ad612193565b805160ff8116811461201057600080fd5b60006020828403121561225257600080fd5b6107058261222f565b600181815b8085111561229657816000190482111561227c5761227c612193565b8085161561228957918102915b93841c9390800290612260565b509250929050565b6000826122ad575060016106ad565b816122ba575060006106ad565b81600181146122d057600281146122da576122f6565b60019150506106ad565b60ff8411156122eb576122eb612193565b50506001821b6106ad565b5060208310610133831016604e8410600b8410161715612319575081810a6106ad565b612323838361225b565b806000190482111561233757612337612193565b029392505050565b600061070560ff84168361229e565b80516001600160401b038116811461201057600080fd5b60006060828403121561237757600080fd5b604051606081018181106001600160401b03821117156123a757634e487b7160e01b600052604160045260246000fd5b6040528251600c81900b81146123bc57600080fd5b81526123ca6020840161234e565b60208201526123db6040840161234e565b60408201529392505050565b600c82810b9082900b036c7fffffffffffffffffffffffff1981126c7fffffffffffffffffffffffff821317156106ad576106ad612193565b805161201081612127565b805164ffffffffff8116811461201057600080fd5b600061010080838503121561245457600080fd5b604051908101906001600160401b038211818310171561248457634e487b7160e01b600052604160045260246000fd5b816040526124918461234e565b815261249f6020850161234e565b60208201526124b06040850161234e565b60408201526124c16060850161234e565b6060820152608084015191506124d682612127565b8160808201526124e860a08501612420565b60a08201526124f960c0850161242b565b60c082015261250a60e0850161222f565b60e0820152949350505050565b64ffffffffff8281168282160390808211156121c9576121c9612193565b60006020828403121561254757600080fd5b5051919050565b60006020828403121561256057600080fd5b6107058261234e565b6001600160401b038181168382160190808211156121c9576121c9612193565b60006020828403121561259b57600080fd5b81516107058161203f565b600082516125b8818460208701611fa2565b919091019291505056fea264697066735822122094a7ac9c521c5bbc8899d454ec7df18537e6664bbc4795660f021235d953382664736f6c634300081300330000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf000000000000000000000000123964802e6ababbe1bc9547d72ef1b69b00a6b10000000000000000000000009e1028f5f1d5ede59748ffcee5532509976840e0
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102275760003560e01c8063790add0311610130578063b6b55f25116100b8578063d10b5a5b1161007c578063d10b5a5b14610532578063d3f730fd14610559578063dd62ed3e14610579578063f8ba4cff1461058c578063ffaad6a51461059457600080fd5b8063b6b55f25146104de578063bbba205d146104f1578063bc9416b914610500578063bfe69c8d1461050c578063cde680411461051f57600080fd5b806397008d6c116100ff57806397008d6c14610417578063a165437914610456578063a9059cbb14610484578063ab9ba7f414610497578063b15f67b3146104b757600080fd5b8063790add03146103d6578063935a8b84146103e95780639555a942146103fc57806395d89b411461040f57600080fd5b80632e1a7d4d116101b35780633ba0b9a9116101825780633ba0b9a91461032657806343631bfe1461032e5780635f2d5f6e1461035957806368a9674d1461039a57806370a08231146103ad57600080fd5b80632e1a7d4d146102e9578063313ce567146102fc57806334a1ca891461030b578063372500ab1461031e57600080fd5b806318160ddd116101fa57806318160ddd1461029e5780631f986445146102a6578063205c2878146102b057806323b872dd146102c35780632a846398146102d657600080fd5b806306fdde031461022c578063095ea7b31461024a5780630e162e1e1461026d578063110496e514610289575b600080fd5b6102346105a7565b6040516102419190611fc6565b60405180910390f35b61025d610258366004612015565b610639565b6040519015158152602001610241565b61027b66038d7ea4c6800081565b604051908152602001610241565b61029c61029736600461204d565b6106b3565b005b60025461027b565b61027b620f424081565b61029c6102be366004612015565b6106c2565b61025d6102d1366004612084565b6106ce565b61027b6102e43660046120c0565b61070c565b61029c6102f73660046120db565b610818565b60405160068152602001610241565b61029c6103193660046120f4565b610827565b61029c610a0b565b61027b610a17565b61034161033c3660046120db565b610ac4565b6040516001600160681b039091168152602001610241565b6103826103673660046120c0565b6005602052600090815260409020546001600160401b031681565b6040516001600160401b039091168152602001610241565b61029c6103a8366004612084565b610adc565b61027b6103bb3660046120c0565b6001600160a01b031660009081526020819052604090205490565b61027b6103e436600461213c565b610aed565b61027b6103f73660046120c0565b610b05565b61029c61040a366004612084565b610b3b565b610234610b47565b61043e7f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf81565b6040516001600160a01b039091168152602001610241565b61025d6104643660046120f4565b600160209081526000928352604080842090915290825290205460ff1681565b61025d610492366004612015565b610b56565b61027b6104a53660046120c0565b60066020526000908152604090205481565b61043e7f000000000000000000000000123964802e6ababbe1bc9547d72ef1b69b00a6b181565b61029c6104ec3660046120db565b610b63565b61027b670de0b6b3a764000081565b61027b64e8d4a5100081565b61029c61051a3660046120c0565b610b6f565b61025d61052d3660046120f4565b610bf1565b61043e7f0000000000000000000000009e1028f5f1d5ede59748ffcee5532509976840e081565b61027b6105673660046120c0565b60076020526000908152604090205481565b61027b6105873660046120f4565b610c3d565b61029c610c5e565b61029c6105a2366004612015565b610cd9565b6060600380546105b690612159565b80601f01602080910402602001604051908101604052809291908181526020018280546105e290612159565b801561062f5780601f106106045761010080835404028352916020019161062f565b820191906000526020600020905b81548152906001019060200180831161061257829003601f168201915b5050505050905090565b60006001600160a01b0383166106625760405163d92e233d60e01b815260040160405180910390fd5b600019820361067c5761067733846001610ce5565b6106a9565b816000036106905761067733846000610ce5565b60405163749b593960e01b815260040160405180910390fd5b5060015b92915050565b6106be338383610ce5565b5050565b6106be33338484610daf565b60006106da8433610bf1565b6106f6576040516282b42960e81b815260040160405180910390fd5b6107018484846110e0565b5060015b9392505050565b60008061071761120c565b6001600160a01b0385166000908152600560205260408120549193509150610748906001600160401b0316836121a9565b6001600160401b03169050600066038d7ea4c6800082610785610780886001600160a01b031660009081526020819052604090205490565b6114e2565b6001600160681b031661079891906121d0565b6107a291906121e7565b6001600160a01b0386166000908152600660205260409020546107c59190612209565b6001600160a01b0386166000908152600760205260408120549192506107f064e8d4a51000846121d0565b9050600082821161080257600061080c565b61080c838361221c565b98975050505050505050565b61082433333384610daf565b50565b336108328382610bf1565b61084e576040516282b42960e81b815260040160405180910390fd5b61085783610b6f565b6001600160a01b038316600090815260076020908152604080832054600690925282205490919061088e9064e8d4a51000906121d0565b90506000828211156109a0576108a4838361221c565b6001600160a01b0387811660009081526007602052604090819020859055516313fe176560e21b81527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf8216600482015230602482018190526044820152600160648201529192507f000000000000000000000000123964802e6ababbe1bc9547d72ef1b69b00a6b11690634ff85d9490608401600060405180830381600087803b15801561095257600080fd5b505af1158015610966573d6000803e3d6000fd5b506109a09250506001600160a01b037f0000000000000000000000009e1028f5f1d5ede59748ffcee5532509976840e01690508683611510565b7f0000000000000000000000009e1028f5f1d5ede59748ffcee5532509976840e06001600160a01b03167ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe826040516109fb91815260200190565b60405180910390a2505050505050565b610a153333610827565b565b600080610a2261120c565b509050610abe81610ab97f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a8a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aae9190612240565b61078090600a61233f565b611573565b91505090565b600080610acf61120c565b50905061070581846115a3565b610ae8338484846115cd565b505050565b600080610af861120c565b5090506107058184611573565b6001600160a01b03811660009081526020819052604081205480600003610b2f5750600092915050565b6107056103e4826114e2565b610ae833848484610daf565b6060600480546105b690612159565b60006106a93384846110e0565b610824333333846115cd565b60405163bfe69c8d60e01b81523060048201527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b03169063bfe69c8d90602401600060405180830381600087803b158015610bd057600080fd5b505af1158015610be4573d6000803e3d6000fd5b5050505061082481611926565b6000816001600160a01b0316836001600160a01b031614806107055750506001600160a01b03918216600090815260016020908152604080832093909416825291909152205460ff1690565b6000610c498383610bf1565b610c54576000610705565b5060001992915050565b60405163bfe69c8d60e01b81523060048201527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b03169063bfe69c8d90602401600060405180830381600087803b158015610cbf57600080fd5b505af1158015610cd3573d6000803e3d6000fd5b50505050565b6106be333384846115cd565b6001600160a01b038316610d0c5760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b038216610d335760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b038381166000818152600160209081526040808320948716808452949091529020805460ff19168415151790557f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583610d94576000610d98565b6000195b6040519081526020015b60405180910390a3505050565b610db98385610bf1565b610dd5576040516282b42960e81b815260040160405180910390fd5b6000610de084610b05565b905081811015610dee578091505b81600003610e0f5760405163749b593960e01b815260040160405180910390fd5b60405163bfe69c8d60e01b81523060048201527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b03169063bfe69c8d90602401600060405180830381600087803b158015610e7057600080fd5b505af1158015610e84573d6000803e3d6000fd5b505060405163bfe69c8d60e01b81526001600160a01b0387811660048301527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf16925063bfe69c8d9150602401600060405180830381600087803b158015610eeb57600080fd5b505af1158015610eff573d6000803e3d6000fd5b505050506000610f24856001600160a01b031660009081526020819052604090205490565b60405163dc4abafd60e01b81523060048201529091506000906001600160a01b037f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf169063dc4abafd90602401606060405180830381865afa158015610f8e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb29190612365565b805190915061100286610fc6600a886121e7565b610fd190600a6121d0565b6001600160a01b037f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf169190611510565b60405163dc4abafd60e01b81523060048201527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b03169063dc4abafd90602401606060405180830381865afa158015611066573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061108a9190612365565b8051909250600061109b82846123e7565b6001600160681b031690508085116110b05750835b6110b989611926565b6110d4896110c6836114e2565b6001600160681b0316611a1d565b50505050505050505050565b6001600160a01b0383166111075760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b03821661112e5760405163d92e233d60e01b815260040160405180910390fd5b611139838383611af3565b6001600160a01b0383166000908152602081905260409020548082111561117b57604051632e7a668d60e21b8152600481018390526024015b60405180910390fd5b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906111b2908490612209565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516111fe91815260200190565b60405180910390a350505050565b60008060007f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b031663b9f0baf76040518163ffffffff1660e01b815260040161010060405180830381865afa158015611270573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112949190612440565b905060008160c00151426112a89190612517565b825160408401519192509064ffffffffff8316156114d75760007f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b031663189bb2f16040518163ffffffff1660e01b8152600401602060405180830381865afa158015611320573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113449190612535565b905060007f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b0316637eb711316040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ca9190612535565b60405163d955759d60e01b8152600481018290529091506000906001600160a01b037f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf169063d955759d90602401602060405180830381865afa158015611435573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611459919061254e565b6001600160401b0316905061149161148c866001600160401b03168864ffffffffff168461148791906121d0565b611b7e565b611b93565b61149b9086612569565b94506114c761148c6114b464ffffffffff8916866121d0565b89608001516001600160681b0316611bbd565b6114d19085612569565b93505050505b909590945092505050565b60006001600160681b0382111561150c57604051630dc7925560e11b815260040160405180910390fd5b5090565b6040516001600160a01b038316602482015260448101829052610ae890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611bcd565b600066038d7ea4c680006115996001600160401b0385166001600160681b0385166121d0565b61070591906121e7565b60006107056001600160401b0384166115c366038d7ea4c68000856121d0565b61078091906121e7565b6115d78385610bf1565b6115f3576040516282b42960e81b815260040160405180910390fd5b6040516370a0823160e01b81526001600160a01b0384811660048301526000917f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf909116906370a0823190602401602060405180830381865afa15801561165e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116829190612535565b905080821115611690578091505b816000036116b15760405163749b593960e01b815260040160405180910390fd5b60405163bfe69c8d60e01b81523060048201527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b03169063bfe69c8d90602401600060405180830381600087803b15801561171257600080fd5b505af1158015611726573d6000803e3d6000fd5b505060405163bfe69c8d60e01b81526001600160a01b0387811660048301527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf16925063bfe69c8d9150602401600060405180830381600087803b15801561178d57600080fd5b505af11580156117a1573d6000803e3d6000fd5b505060405163dc4abafd60e01b8152306004820152600092507f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b0316915063dc4abafd90602401606060405180830381865afa15801561180c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118309190612365565b805190915061186a6001600160a01b037f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf16873087611c9f565b60405163dc4abafd60e01b81523060048201527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b03169063dc4abafd90602401606060405180830381865afa1580156118ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f29190612365565b805190925061190086611926565b61191c8661190e84846123e7565b6001600160681b0316611cd7565b5050505050505050565b6001600160a01b03811660009081526020819052604081205490611948611d87565b6001600160a01b0385166000908152600560205260408120549193509150611979906001600160401b0316836121a9565b6001600160401b0316905066038d7ea4c6800081611996856114e2565b6001600160681b03166119a991906121d0565b6119b391906121e7565b6001600160a01b038516600090815260066020526040812080549091906119db908490612209565b9091555050506001600160a01b03929092166000908152600560205260409020805467ffffffffffffffff19166001600160401b039093169290921790915550565b6001600160a01b038216611a445760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b03821660009081526020819052604090205480821115611a8157604051632e7a668d60e21b815260048101839052602401611172565b6001600160a01b0383166000908152602081905260408120838303905560028054849290611ab090849061221c565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001610da2565b60405163bfe69c8d60e01b81523060048201527f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b03169063bfe69c8d90602401600060405180830381600087803b158015611b5457600080fd5b505af1158015611b68573d6000803e3d6000fd5b50505050611b7583611926565b610ae882611926565b6000670de0b6b3a764000061159983856121d0565b60006001600160401b0382111561150c576040516372a1cb5160e11b815260040160405180910390fd5b600081611599620f4240856121d0565b6000611c22826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611e219092919063ffffffff16565b805190915015610ae85780806020019051810190611c409190612589565b610ae85760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401611172565b6040516001600160a01b0380851660248301528316604482015260648101829052610cd39085906323b872dd60e01b9060840161153c565b6001600160a01b038216611cfe5760405163d92e233d60e01b815260040160405180910390fd5b8060026000828254611d109190612209565b90915550506001600160a01b03821660009081526020819052604081208054839290611d3d908490612209565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60008060007f0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf6001600160a01b031663b9f0baf76040518163ffffffff1660e01b815260040161010060405180830381865afa158015611deb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0f9190612440565b80516040909101519094909350915050565b6060611e308484600085611e38565b949350505050565b606082471015611e995760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401611172565b6001600160a01b0385163b611ef05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611172565b600080866001600160a01b03168587604051611f0c91906125a6565b60006040518083038185875af1925050503d8060008114611f49576040519150601f19603f3d011682016040523d82523d6000602084013e611f4e565b606091505b5091509150611f5e828286611f69565b979650505050505050565b60608315611f78575081610705565b825115611f885782518084602001fd5b8160405162461bcd60e51b81526004016111729190611fc6565b60005b83811015611fbd578181015183820152602001611fa5565b50506000910152565b6020815260008251806020840152611fe5816040850160208701611fa2565b601f01601f19169190910160400192915050565b80356001600160a01b038116811461201057600080fd5b919050565b6000806040838503121561202857600080fd5b61203183611ff9565b946020939093013593505050565b801515811461082457600080fd5b6000806040838503121561206057600080fd5b61206983611ff9565b915060208301356120798161203f565b809150509250929050565b60008060006060848603121561209957600080fd5b6120a284611ff9565b92506120b060208501611ff9565b9150604084013590509250925092565b6000602082840312156120d257600080fd5b61070582611ff9565b6000602082840312156120ed57600080fd5b5035919050565b6000806040838503121561210757600080fd5b61211083611ff9565b915061211e60208401611ff9565b90509250929050565b6001600160681b038116811461082457600080fd5b60006020828403121561214e57600080fd5b813561070581612127565b600181811c9082168061216d57607f821691505b60208210810361218d57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b6001600160401b038281168282160390808211156121c9576121c9612193565b5092915050565b80820281158282048414176106ad576106ad612193565b60008261220457634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156106ad576106ad612193565b818103818111156106ad576106ad612193565b805160ff8116811461201057600080fd5b60006020828403121561225257600080fd5b6107058261222f565b600181815b8085111561229657816000190482111561227c5761227c612193565b8085161561228957918102915b93841c9390800290612260565b509250929050565b6000826122ad575060016106ad565b816122ba575060006106ad565b81600181146122d057600281146122da576122f6565b60019150506106ad565b60ff8411156122eb576122eb612193565b50506001821b6106ad565b5060208310610133831016604e8410600b8410161715612319575081810a6106ad565b612323838361225b565b806000190482111561233757612337612193565b029392505050565b600061070560ff84168361229e565b80516001600160401b038116811461201057600080fd5b60006060828403121561237757600080fd5b604051606081018181106001600160401b03821117156123a757634e487b7160e01b600052604160045260246000fd5b6040528251600c81900b81146123bc57600080fd5b81526123ca6020840161234e565b60208201526123db6040840161234e565b60408201529392505050565b600c82810b9082900b036c7fffffffffffffffffffffffff1981126c7fffffffffffffffffffffffff821317156106ad576106ad612193565b805161201081612127565b805164ffffffffff8116811461201057600080fd5b600061010080838503121561245457600080fd5b604051908101906001600160401b038211818310171561248457634e487b7160e01b600052604160045260246000fd5b816040526124918461234e565b815261249f6020850161234e565b60208201526124b06040850161234e565b60408201526124c16060850161234e565b6060820152608084015191506124d682612127565b8160808201526124e860a08501612420565b60a08201526124f960c0850161242b565b60c082015261250a60e0850161222f565b60e0820152949350505050565b64ffffffffff8281168282160390808211156121c9576121c9612193565b60006020828403121561254757600080fd5b5051919050565b60006020828403121561256057600080fd5b6107058261234e565b6001600160401b038181168382160190808211156121c9576121c9612193565b60006020828403121561259b57600080fd5b81516107058161203f565b600082516125b8818460208701611fa2565b919091019291505056fea264697066735822122094a7ac9c521c5bbc8899d454ec7df18537e6664bbc4795660f021235d953382664736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf000000000000000000000000123964802e6ababbe1bc9547d72ef1b69b00a6b10000000000000000000000009e1028f5f1d5ede59748ffcee5532509976840e0
-----Decoded View---------------
Arg [0] : cusdcv3 (address): 0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf
Arg [1] : rewardsAddr_ (address): 0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1
Arg [2] : rewardERC20_ (address): 0x9e1028F5F1D5eDE59748FFceE5532509976840E0
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000009c4ec768c28520b50860ea7a15bd7213a9ff58bf
Arg [1] : 000000000000000000000000123964802e6ababbe1bc9547d72ef1b69b00a6b1
Arg [2] : 0000000000000000000000009e1028f5f1d5ede59748ffcee5532509976840e0
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.
Add Token to MetaMask (Web3)