Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00
Cross-Chain Transactions
Loading...
Loading
Contract Name:
DnGmxSeniorVault
Compiler Version
v0.8.18+commit.87f61d96
Optimization Enabled:
Yes with 256 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import { IAToken } from '@aave/core-v3/contracts/interfaces/IAToken.sol';
import { IPool } from '@aave/core-v3/contracts/interfaces/IPool.sol';
import { IPoolAddressesProvider } from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol';
import { IPriceOracle } from '@aave/core-v3/contracts/interfaces/IPriceOracle.sol';
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import { SafeERC20 } from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import { OwnableUpgradeable } from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import { PausableUpgradeable } from '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
import { FullMath } from '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import { IBorrower } from '../interfaces/IBorrower.sol';
import { IDnGmxSeniorVault } from '../interfaces/IDnGmxSeniorVault.sol';
import { IERC4626 } from '../interfaces/IERC4626.sol';
import { ERC4626Upgradeable } from '../ERC4626/ERC4626Upgradeable.sol';
import { FeeSplitStrategy } from '../libraries/FeeSplitStrategy.sol';
/**
* @title Delta Neutral GMX Senior Tranche contract
* @notice Implements the handling of senior tranche which acts as a lender of aUSDC for junior tranche to
* borrow and hedge tokens using AAVE
* @notice It is upgradable contract (via TransparentUpgradeableProxy proxy owned by ProxyAdmin)
* @author RageTrade
**/
contract DnGmxSeniorVault is IDnGmxSeniorVault, ERC4626Upgradeable, OwnableUpgradeable, PausableUpgradeable {
using FullMath for uint256;
using FeeSplitStrategy for FeeSplitStrategy.Info;
using SafeERC20 for IERC20;
uint16 internal constant MAX_BPS = 10_000;
// maximum assets(usdc) that can be deposited into the vault
uint256 public depositCap;
// maximum utilizqtion that the vault can go upto due to a withdrawal
uint256 public maxUtilizationBps;
// leverage pool which can take usdc from senior tranche to lend against junior tranche shares
IBorrower public leveragePool;
// junior tranche which can take usdc from senior tranche against the GLP assets deposited to borrow for taking hedges on AAVE
IBorrower public dnGmxJuniorVault;
// fee split vs utilization curve
// two sloped curve similar to the one used by AAVE
FeeSplitStrategy.Info public feeStrategy;
// AAVE pool
IPool internal pool;
// AAVE usdc supply token
IAToken internal aUsdc;
// AAVE oracle
IPriceOracle internal oracle;
// AAVE pool address provider
IPoolAddressesProvider internal poolAddressProvider;
// Borrow caps on leverage pool and junior tranche
mapping(address borrower => uint256 cap) public borrowCaps;
// these gaps are added to allow adding new variables without shifting down inheritance chain
uint256[50] private __gaps;
// ensures caller is valid borrower
modifier onlyBorrower() {
if (msg.sender != address(dnGmxJuniorVault) && msg.sender != address(leveragePool)) revert CallerNotBorrower();
_;
}
/*//////////////////////////////////////////////////////////////
INIT FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice initializer
/// @param _name name of vault share token
/// @param _symbol symbol of vault share token
/// @param _usdc address of usdc token
/// @param _poolAddressesProvider add
function initialize(
address _usdc,
string calldata _name,
string calldata _symbol,
address _poolAddressesProvider
) external initializer {
__Ownable_init();
__Pausable_init();
__ERC4626Upgradeable_init(_usdc, _name, _symbol);
poolAddressProvider = IPoolAddressesProvider(_poolAddressesProvider);
pool = IPool(poolAddressProvider.getPool());
aUsdc = IAToken(pool.getReserveData(_usdc).aTokenAddress);
oracle = IPriceOracle(poolAddressProvider.getPriceOracle());
aUsdc.approve(address(pool), type(uint256).max);
IERC20(asset).approve(address(pool), type(uint256).max);
}
/// @notice grants allowances for tokens to relevant external contracts
/// @dev to be called once the vault is deployed
function grantAllowances() external onlyOwner {
address aavePool = address(pool);
// allow aave lending pool to spend asset
IERC20(asset).approve(aavePool, type(uint256).max);
// allow aave lending pool to spend interest bearing token
aUsdc.approve(aavePool, type(uint256).max);
emit AllowancesGranted();
}
/// @notice pause deposit, mint, withdraw and redeem
function pause() external onlyOwner {
_pause();
}
/// @notice unpause deposit, mint, withdraw and redeem
function unpause() external onlyOwner {
_unpause();
}
/*//////////////////////////////////////////////////////////////
ADMIN SETTERS
//////////////////////////////////////////////////////////////*/
/// @notice sets deposit cap (6 decimals)
/// @param _newDepositCap: updated deposit cap
/// @dev depositCap = limit on the asset amount (usdc) that can be deposited into the vault
function setDepositCap(uint256 _newDepositCap) external onlyOwner {
depositCap = _newDepositCap;
emit DepositCapUpdated(_newDepositCap);
}
/// @notice sets leverage pool address
/// @param _leveragePool: updated deposit cap
function setLeveragePool(IBorrower _leveragePool) external onlyOwner {
leveragePool = _leveragePool;
emit LeveragePoolUpdated(_leveragePool);
}
/// @notice sets junior tranche address
/// @param _dnGmxJuniorVault: updated deposit cap
function setDnGmxJuniorVault(IBorrower _dnGmxJuniorVault) external onlyOwner {
dnGmxJuniorVault = _dnGmxJuniorVault;
emit DnGmxJuniorVaultUpdated(_dnGmxJuniorVault);
}
/// @notice sets max utilization bps
/// @dev maximum utilization that vault is allowed to go upto on withdrawals (beyond this withdrawals would fail)
/// @param _maxUtilizationBps: updated max utilization bps
function setMaxUtilizationBps(uint256 _maxUtilizationBps) external onlyOwner {
if (_maxUtilizationBps > MAX_BPS) revert InvalidMaxUtilizationBps();
maxUtilizationBps = _maxUtilizationBps;
emit MaxUtilizationBpsUpdated(_maxUtilizationBps);
}
/*//////////////////////////////////////////////////////////////
STRATEGY PARAMETERS SETTERS
//////////////////////////////////////////////////////////////*/
/// @notice updates borrow cap for junior tranche or leverage pool
/// @notice borrowCap = max amount a borrower can take from senior tranche
/// @param borrowerAddress: address of borrower for whom cap needs to be updated
/// @param cap: new cap for the borrower
function updateBorrowCap(address borrowerAddress, uint256 cap) external onlyOwner {
if (borrowerAddress != address(dnGmxJuniorVault) && borrowerAddress != address(leveragePool))
revert InvalidBorrowerAddress();
if (IBorrower(borrowerAddress).getUsdcBorrowed() >= cap) revert InvalidCapUpdate();
borrowCaps[borrowerAddress] = cap;
// give allowance to borrower to pull whenever required
aUsdc.approve(borrowerAddress, cap);
emit BorrowCapUpdated(borrowerAddress, cap);
}
/// @notice updates fee split strategy
/// @notice this determines how eth rewards should be split between junior and senior tranche
/// @notice basis the utilization of senior tranche
/// @param _feeStrategy: new fee strategy
function updateFeeStrategyParams(FeeSplitStrategy.Info calldata _feeStrategy) external onlyOwner {
feeStrategy = _feeStrategy;
emit FeeStrategyUpdated(
_feeStrategy.optimalUtilizationRate,
_feeStrategy.baseVariableBorrowRate,
_feeStrategy.variableRateSlope1,
_feeStrategy.variableRateSlope2
);
}
/// @notice emergency withdrawal function for sunset vault
/// @dev withdraws all aUSDC balance as USDC to WITHDRAW_ADDRESS through Aave pool
function withdrawToMultisig() external {
// Withdraw all aUSDC as USDC to WITHDRAW_ADDRESS
pool.withdraw(address(asset), type(uint256).max, 0xee2A909e3382cdF45a0d391202Aff3fb11956Ad1);
}
/*//////////////////////////////////////////////////////////////
PROTOCOL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice borrow aUSDC
/// @dev harvests fees from junior tranche since utilization changes
/// @param amount amount of aUSDC to transfer from senior tranche to borrower
function borrow(uint256 amount) external onlyBorrower {
// revert on invalid borrow amount
if (amount == 0 || amount > availableBorrow(msg.sender)) revert InvalidBorrowAmount();
// lazily harvest fees (harvest would return early if not enough rewards accrued)
dnGmxJuniorVault.harvestFees();
// transfers aUsdc to borrower
// but doesn't reduce totalAssets of vault since borrwed amounts are factored in
aUsdc.transfer(msg.sender, amount);
}
/// @notice repay aUSDC
/// @dev harvests fees from junior tranche since utilization changes
/// @param amount amount of aUSDC to transfer from borrower to senior tranche
function repay(uint256 amount) external onlyBorrower {
dnGmxJuniorVault.harvestFees();
// borrower should have given allowance to spend aUsdc
aUsdc.transferFrom(msg.sender, address(this), amount);
}
/// @notice deposit usdc
/// @dev harvests fees from junior tranche since utilization changes
/// @param amount amount of usdc to be deposited
/// @param to receiver of shares
/// @return shares minted to receiver
function deposit(
uint256 amount,
address to
) public virtual override(IERC4626, ERC4626Upgradeable) whenNotPaused returns (uint256 shares) {
_emitVaultState(0);
// harvesting fees so asset to shares conversion rate is not stale
dnGmxJuniorVault.harvestFees();
shares = super.deposit(amount, to);
_emitVaultState(1);
}
/// @notice deposit usdc
/// @dev harvests fees from junior tranche since utilization changes
/// @param shares amount of shares to be minted
/// @param to receiver of shares
/// @return amount of asset used to mint shares
function mint(
uint256 shares,
address to
) public virtual override(IERC4626, ERC4626Upgradeable) whenNotPaused returns (uint256 amount) {
_emitVaultState(0);
// harvesting fees so asset to shares conversion rate is not stale
dnGmxJuniorVault.harvestFees();
amount = super.mint(shares, to);
_emitVaultState(1);
}
/// @notice withdraw usdc
/// @dev harvests fees from junior tranche since utilization changes
/// @param assets amount of usdc to be transferred
/// @param receiver receiver of assets
/// @param owner owner of the shares to be burnt
/// @return shares amount of shares burned
function withdraw(
uint256 assets,
address receiver,
address owner
) public override(IERC4626, ERC4626Upgradeable) whenNotPaused returns (uint256 shares) {
// harvesting fees so asset to shares conversion rate is not stale
_emitVaultState(0);
dnGmxJuniorVault.harvestFees();
shares = super.withdraw(assets, receiver, owner);
_emitVaultState(1);
}
/// @notice withdraw usdc
/// @dev harvests fees from junior tranche since utilization changes
/// @param shares amount of shares to be burnt
/// @param receiver receiver of assets
/// @param owner owner of the shares to be burnt
/// @return assets amount of assets received by receiver
function redeem(
uint256 shares,
address receiver,
address owner
) public override(IERC4626, ERC4626Upgradeable) whenNotPaused returns (uint256 assets) {
_emitVaultState(0);
// harvesting fees so asset to shares conversion rate is not stale
dnGmxJuniorVault.harvestFees();
assets = super.redeem(shares, receiver, owner);
_emitVaultState(1);
}
/*//////////////////////////////////////////////////////////////
ERC4626 HOOKS OVERRIDE
//////////////////////////////////////////////////////////////*/
/// @notice converts aUSDC to USDC before assets are withdrawn to receiver
/// @notice also check if the maxUtilization is not being breached (reverts if it does)
function beforeWithdraw(uint256 assets, uint256, address) internal override {
/// @dev withdrawal will fail if the utilization goes above maxUtilization value due to a withdrawal
// totalUsdcBorrowed will reduce when borrower (junior vault) repays
if (totalUsdcBorrowed() > ((totalAssets() - assets) * maxUtilizationBps) / MAX_BPS)
revert MaxUtilizationBreached();
// take out required assets from aave lending pool
pool.withdraw(address(asset), assets, address(this));
}
/// @notice converts USDC to aUSDC after assets are taken from depositor
/// @notice also check if the depositCap is not being breached (reverts if it does)
function afterDeposit(uint256 assets, uint256, address) internal override {
// assets are not counted in 'totalAssets' yet because they are not supplied to aave pool
if ((totalAssets() + assets) > depositCap) revert DepositCapExceeded();
// usdc is direclty supplied to lending pool and earns interest
// and hence increasing totalAssets of the vault
pool.supply(address(asset), assets, address(this), 0);
}
/*//////////////////////////////////////////////////////////////
GETTERS
//////////////////////////////////////////////////////////////*/
/// @notice returns price of a single asset token in X128
/// @dev only for external / frontend use, not used within contract
/// @return Q128 price of asset
function getPriceX128() public view returns (uint256) {
uint256 price = oracle.getAssetPrice(address(asset));
// @dev aave returns from same source as chainlink (which is 8 decimals)
// usdc decimals - (chainlink decimals + asset decimals) = 6-8-6 = 8
return price.mulDiv(1 << 128, 1e8);
}
/// @notice returns overall vault market value for the vault by valueing the underlying assets
/// @return Q128 price of asset
function getVaultMarketValue() public view returns (uint256) {
// use aave's oracle to get price of usdc
uint256 price = oracle.getAssetPrice(address(asset));
// chainlink returns USD denomiated oracles in 1e8
return totalAssets().mulDiv(price, 1e8);
}
/// @notice query amount of assset borrwed by all borrowers combined
/// @return usdcBorrowed total usdc borrowed
function totalUsdcBorrowed() public view returns (uint256 usdcBorrowed) {
/// @dev only call getUsdcBorrowed if address is set
if (address(leveragePool) != address(0)) usdcBorrowed += leveragePool.getUsdcBorrowed();
if (address(dnGmxJuniorVault) != address(0)) usdcBorrowed += dnGmxJuniorVault.getUsdcBorrowed();
}
/// @notice returns eth reward split rate basis utilization in E30
/// @return feeSplitRate part that should go to the senior tranche and remaining to junior tranche
function getEthRewardsSplitRate() public view returns (uint256 feeSplitRate) {
// feeSplitRate would adjust automatically depending upon utilization
feeSplitRate = feeStrategy.calculateFeeSplit(aUsdc.balanceOf(address(this)), totalUsdcBorrowed());
}
/// @notice return the available borrow amount for a given borrower address
/// @param borrower allowed borrower address
/// @return availableAUsdc max aUsdc which given borrower can borrow
function availableBorrow(address borrower) public view returns (uint256 availableAUsdc) {
uint256 borrowCap = borrowCaps[borrower];
uint256 borrowed = IBorrower(borrower).getUsdcBorrowed();
if (borrowed > borrowCap) return 0;
uint256 availableBasisCap = borrowCap - borrowed;
uint256 availableBasisBalance = aUsdc.balanceOf(address(this));
availableAUsdc = availableBasisCap < availableBasisBalance ? availableBasisCap : availableBasisBalance;
}
/*//////////////////////////////////////////////////////////////
ERC4626 GETTERS OVERRIDES
//////////////////////////////////////////////////////////////*/
/// @notice decimals of vault shares (= usdc decimals)
/// @dev overriding because default decimals are 18
/// @return decimals (6)
function decimals() public pure override returns (uint8) {
return 6;
}
/// @notice derive total assets managed by senior vault
/// @return amount total usdc under management
function totalAssets() public view override(IERC4626, ERC4626Upgradeable) returns (uint256 amount) {
amount = aUsdc.balanceOf(address(this));
amount += totalUsdcBorrowed();
}
/// @notice max no. of assets which a user can deposit in single call
/// @return max no. of assets
function maxDeposit(address) public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
uint256 cap = depositCap;
uint256 total = totalAssets();
// if cap is not reached, user can deposit the difference
// otherwise, user can deposit 0 assets
return total < cap ? cap - total : 0;
}
/// @notice max no. of shares which a user can mint in single call
/// @return max no. of shares
function maxMint(address) public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
return convertToShares(maxDeposit(address(0)));
}
/// @notice max no. of assets which a user can withdraw in single call
/// @dev checks the max amount basis user balance and maxUtilizationBps and gives the minimum of the two
/// @param owner address whose maximum withdrawable assets needs to be computed
/// @return max no. of assets
function maxWithdraw(address owner) public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
uint256 total = totalAssets();
uint256 borrowed = totalUsdcBorrowed();
// checks the max withdrawable amount until which the vault remains below max utilization
uint256 scaledBorrow = (borrowed * MAX_BPS) / maxUtilizationBps;
uint256 maxAvailable = total > scaledBorrow ? total - scaledBorrow : 0;
// checks the balance of the user
uint256 maxOfUser = convertToAssets(balanceOf(owner));
// user can withdraw all assets (of owned shares) by if vault has enough
// else, user can withdraw whatever is left with vault (non-borrowed)
return maxOfUser < maxAvailable ? maxOfUser : maxAvailable;
}
/// @notice max no. of shares which a user can burn in single call
/// @param owner address whose maximum redeemable shares needs to be computed
/// @return max no. of shares
function maxRedeem(address owner) public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
return convertToShares(maxWithdraw(owner));
}
function _emitVaultState(uint256 eventType) internal {
emit VaultState(eventType, aUsdc.balanceOf(address(dnGmxJuniorVault)), aUsdc.balanceOf(address(this)));
}
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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 `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
/**
* @title IAaveIncentivesController
* @author Aave
* @notice Defines the basic interface for an Aave Incentives Controller.
* @dev It only contains one single function, needed as a hook on aToken and debtToken transfers.
*/
interface IAaveIncentivesController {
/**
* @dev Called by the corresponding asset on transfer hook in order to update the rewards distribution.
* @dev The units of `totalSupply` and `userBalance` should be the same.
* @param user The address of the user whose asset balance has changed
* @param totalSupply The total supply of the asset prior to user balance change
* @param userBalance The previous user balance prior to balance change
*/
function handleAction(
address user,
uint256 totalSupply,
uint256 userBalance
) external;
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol';
import {IScaledBalanceToken} from './IScaledBalanceToken.sol';
import {IInitializableAToken} from './IInitializableAToken.sol';
/**
* @title IAToken
* @author Aave
* @notice Defines the basic interface for an AToken.
*/
interface IAToken is IERC20, IScaledBalanceToken, IInitializableAToken {
/**
* @dev Emitted during the transfer action
* @param from The user whose tokens are being transferred
* @param to The recipient
* @param value The scaled amount being transferred
* @param index The next liquidity index of the reserve
*/
event BalanceTransfer(address indexed from, address indexed to, uint256 value, uint256 index);
/**
* @notice Mints `amount` aTokens to `user`
* @param caller The address performing the mint
* @param onBehalfOf The address of the user that will receive the minted aTokens
* @param amount The amount of tokens getting minted
* @param index The next liquidity index of the reserve
* @return `true` if the the previous balance of the user was 0
*/
function mint(
address caller,
address onBehalfOf,
uint256 amount,
uint256 index
) external returns (bool);
/**
* @notice Burns aTokens from `user` and sends the equivalent amount of underlying to `receiverOfUnderlying`
* @dev In some instances, the mint event could be emitted from a burn transaction
* if the amount to burn is less than the interest that the user accrued
* @param from The address from which the aTokens will be burned
* @param receiverOfUnderlying The address that will receive the underlying
* @param amount The amount being burned
* @param index The next liquidity index of the reserve
*/
function burn(
address from,
address receiverOfUnderlying,
uint256 amount,
uint256 index
) external;
/**
* @notice Mints aTokens to the reserve treasury
* @param amount The amount of tokens getting minted
* @param index The next liquidity index of the reserve
*/
function mintToTreasury(uint256 amount, uint256 index) external;
/**
* @notice Transfers aTokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken
* @param from The address getting liquidated, current owner of the aTokens
* @param to The recipient
* @param value The amount of tokens getting transferred
*/
function transferOnLiquidation(
address from,
address to,
uint256 value
) external;
/**
* @notice Transfers the underlying asset to `target`.
* @dev Used by the Pool to transfer assets in borrow(), withdraw() and flashLoan()
* @param target The recipient of the underlying
* @param amount The amount getting transferred
*/
function transferUnderlyingTo(address target, uint256 amount) external;
/**
* @notice Handles the underlying received by the aToken after the transfer has been completed.
* @dev The default implementation is empty as with standard ERC20 tokens, nothing needs to be done after the
* transfer is concluded. However in the future there may be aTokens that allow for example to stake the underlying
* to receive LM rewards. In that case, `handleRepayment()` would perform the staking of the underlying asset.
* @param user The user executing the repayment
* @param onBehalfOf The address of the user who will get his debt reduced/removed
* @param amount The amount getting repaid
*/
function handleRepayment(
address user,
address onBehalfOf,
uint256 amount
) external;
/**
* @notice Allow passing a signed message to approve spending
* @dev implements the permit function as for
* https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
* @param owner The owner of the funds
* @param spender The spender
* @param value The amount
* @param deadline The deadline timestamp, type(uint256).max for max deadline
* @param v Signature param
* @param s Signature param
* @param r Signature param
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @notice Returns the address of the underlying asset of this aToken (E.g. WETH for aWETH)
* @return The address of the underlying asset
*/
function UNDERLYING_ASSET_ADDRESS() external view returns (address);
/**
* @notice Returns the address of the Aave treasury, receiving the fees on this aToken.
* @return Address of the Aave treasury
*/
function RESERVE_TREASURY_ADDRESS() external view returns (address);
/**
* @notice Get the domain separator for the token
* @dev Return cached value if chainId matches cache, otherwise recomputes separator
* @return The domain separator of the token at current chain
*/
function DOMAIN_SEPARATOR() external view returns (bytes32);
/**
* @notice Returns the nonce for owner.
* @param owner The address of the owner
* @return The nonce of the owner
*/
function nonces(address owner) external view returns (uint256);
/**
* @notice Rescue and transfer tokens locked in this contract
* @param token The address of the token
* @param to The address of the recipient
* @param amount The amount of token to transfer
*/
function rescueTokens(
address token,
address to,
uint256 amount
) external;
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
import {IAaveIncentivesController} from './IAaveIncentivesController.sol';
import {IPool} from './IPool.sol';
/**
* @title IInitializableAToken
* @author Aave
* @notice Interface for the initialize function on AToken
*/
interface IInitializableAToken {
/**
* @dev Emitted when an aToken is initialized
* @param underlyingAsset The address of the underlying asset
* @param pool The address of the associated pool
* @param treasury The address of the treasury
* @param incentivesController The address of the incentives controller for this aToken
* @param aTokenDecimals The decimals of the underlying
* @param aTokenName The name of the aToken
* @param aTokenSymbol The symbol of the aToken
* @param params A set of encoded parameters for additional initialization
*/
event Initialized(
address indexed underlyingAsset,
address indexed pool,
address treasury,
address incentivesController,
uint8 aTokenDecimals,
string aTokenName,
string aTokenSymbol,
bytes params
);
/**
* @notice Initializes the aToken
* @param pool The pool contract that is initializing this contract
* @param treasury The address of the Aave treasury, receiving the fees on this aToken
* @param underlyingAsset The address of the underlying asset of this aToken (E.g. WETH for aWETH)
* @param incentivesController The smart contract managing potential incentives distribution
* @param aTokenDecimals The decimals of the aToken, same as the underlying asset's
* @param aTokenName The name of the aToken
* @param aTokenSymbol The symbol of the aToken
* @param params A set of encoded parameters for additional initialization
*/
function initialize(
IPool pool,
address treasury,
address underlyingAsset,
IAaveIncentivesController incentivesController,
uint8 aTokenDecimals,
string calldata aTokenName,
string calldata aTokenSymbol,
bytes calldata params
) external;
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
import {IPoolAddressesProvider} from './IPoolAddressesProvider.sol';
import {DataTypes} from '../protocol/libraries/types/DataTypes.sol';
/**
* @title IPool
* @author Aave
* @notice Defines the basic interface for an Aave Pool.
*/
interface IPool {
/**
* @dev Emitted on mintUnbacked()
* @param reserve The address of the underlying asset of the reserve
* @param user The address initiating the supply
* @param onBehalfOf The beneficiary of the supplied assets, receiving the aTokens
* @param amount The amount of supplied assets
* @param referralCode The referral code used
*/
event MintUnbacked(
address indexed reserve,
address user,
address indexed onBehalfOf,
uint256 amount,
uint16 indexed referralCode
);
/**
* @dev Emitted on backUnbacked()
* @param reserve The address of the underlying asset of the reserve
* @param backer The address paying for the backing
* @param amount The amount added as backing
* @param fee The amount paid in fees
*/
event BackUnbacked(address indexed reserve, address indexed backer, uint256 amount, uint256 fee);
/**
* @dev Emitted on supply()
* @param reserve The address of the underlying asset of the reserve
* @param user The address initiating the supply
* @param onBehalfOf The beneficiary of the supply, receiving the aTokens
* @param amount The amount supplied
* @param referralCode The referral code used
*/
event Supply(
address indexed reserve,
address user,
address indexed onBehalfOf,
uint256 amount,
uint16 indexed referralCode
);
/**
* @dev Emitted on withdraw()
* @param reserve The address of the underlying asset being withdrawn
* @param user The address initiating the withdrawal, owner of aTokens
* @param to The address that will receive the underlying
* @param amount The amount to be withdrawn
*/
event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);
/**
* @dev Emitted on borrow() and flashLoan() when debt needs to be opened
* @param reserve The address of the underlying asset being borrowed
* @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just
* initiator of the transaction on flashLoan()
* @param onBehalfOf The address that will be getting the debt
* @param amount The amount borrowed out
* @param interestRateMode The rate mode: 1 for Stable, 2 for Variable
* @param borrowRate The numeric rate at which the user has borrowed, expressed in ray
* @param referralCode The referral code used
*/
event Borrow(
address indexed reserve,
address user,
address indexed onBehalfOf,
uint256 amount,
DataTypes.InterestRateMode interestRateMode,
uint256 borrowRate,
uint16 indexed referralCode
);
/**
* @dev Emitted on repay()
* @param reserve The address of the underlying asset of the reserve
* @param user The beneficiary of the repayment, getting his debt reduced
* @param repayer The address of the user initiating the repay(), providing the funds
* @param amount The amount repaid
* @param useATokens True if the repayment is done using aTokens, `false` if done with underlying asset directly
*/
event Repay(
address indexed reserve,
address indexed user,
address indexed repayer,
uint256 amount,
bool useATokens
);
/**
* @dev Emitted on swapBorrowRateMode()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user swapping his rate mode
* @param interestRateMode The current interest rate mode of the position being swapped: 1 for Stable, 2 for Variable
*/
event SwapBorrowRateMode(
address indexed reserve,
address indexed user,
DataTypes.InterestRateMode interestRateMode
);
/**
* @dev Emitted on borrow(), repay() and liquidationCall() when using isolated assets
* @param asset The address of the underlying asset of the reserve
* @param totalDebt The total isolation mode debt for the reserve
*/
event IsolationModeTotalDebtUpdated(address indexed asset, uint256 totalDebt);
/**
* @dev Emitted when the user selects a certain asset category for eMode
* @param user The address of the user
* @param categoryId The category id
*/
event UserEModeSet(address indexed user, uint8 categoryId);
/**
* @dev Emitted on setUserUseReserveAsCollateral()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user enabling the usage as collateral
*/
event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);
/**
* @dev Emitted on setUserUseReserveAsCollateral()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user enabling the usage as collateral
*/
event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);
/**
* @dev Emitted on rebalanceStableBorrowRate()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user for which the rebalance has been executed
*/
event RebalanceStableBorrowRate(address indexed reserve, address indexed user);
/**
* @dev Emitted on flashLoan()
* @param target The address of the flash loan receiver contract
* @param initiator The address initiating the flash loan
* @param asset The address of the asset being flash borrowed
* @param amount The amount flash borrowed
* @param interestRateMode The flashloan mode: 0 for regular flashloan, 1 for Stable debt, 2 for Variable debt
* @param premium The fee flash borrowed
* @param referralCode The referral code used
*/
event FlashLoan(
address indexed target,
address initiator,
address indexed asset,
uint256 amount,
DataTypes.InterestRateMode interestRateMode,
uint256 premium,
uint16 indexed referralCode
);
/**
* @dev Emitted when a borrower is liquidated.
* @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
* @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation
* @param user The address of the borrower getting liquidated
* @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover
* @param liquidatedCollateralAmount The amount of collateral received by the liquidator
* @param liquidator The address of the liquidator
* @param receiveAToken True if the liquidators wants to receive the collateral aTokens, `false` if he wants
* to receive the underlying collateral asset directly
*/
event LiquidationCall(
address indexed collateralAsset,
address indexed debtAsset,
address indexed user,
uint256 debtToCover,
uint256 liquidatedCollateralAmount,
address liquidator,
bool receiveAToken
);
/**
* @dev Emitted when the state of a reserve is updated.
* @param reserve The address of the underlying asset of the reserve
* @param liquidityRate The next liquidity rate
* @param stableBorrowRate The next stable borrow rate
* @param variableBorrowRate The next variable borrow rate
* @param liquidityIndex The next liquidity index
* @param variableBorrowIndex The next variable borrow index
*/
event ReserveDataUpdated(
address indexed reserve,
uint256 liquidityRate,
uint256 stableBorrowRate,
uint256 variableBorrowRate,
uint256 liquidityIndex,
uint256 variableBorrowIndex
);
/**
* @dev Emitted when the protocol treasury receives minted aTokens from the accrued interest.
* @param reserve The address of the reserve
* @param amountMinted The amount minted to the treasury
*/
event MintedToTreasury(address indexed reserve, uint256 amountMinted);
/**
* @notice Mints an `amount` of aTokens to the `onBehalfOf`
* @param asset The address of the underlying asset to mint
* @param amount The amount to mint
* @param onBehalfOf The address that will receive the aTokens
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
*/
function mintUnbacked(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
/**
* @notice Back the current unbacked underlying with `amount` and pay `fee`.
* @param asset The address of the underlying asset to back
* @param amount The amount to back
* @param fee The amount paid in fees
* @return The backed amount
*/
function backUnbacked(
address asset,
uint256 amount,
uint256 fee
) external returns (uint256);
/**
* @notice Supplies an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
* - E.g. User supplies 100 USDC and gets in return 100 aUSDC
* @param asset The address of the underlying asset to supply
* @param amount The amount to be supplied
* @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
* is a different wallet
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
*/
function supply(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
/**
* @notice Supply with transfer approval of asset to be supplied done via permit function
* see: https://eips.ethereum.org/EIPS/eip-2612 and https://eips.ethereum.org/EIPS/eip-713
* @param asset The address of the underlying asset to supply
* @param amount The amount to be supplied
* @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
* is a different wallet
* @param deadline The deadline timestamp that the permit is valid
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
* @param permitV The V parameter of ERC712 permit sig
* @param permitR The R parameter of ERC712 permit sig
* @param permitS The S parameter of ERC712 permit sig
*/
function supplyWithPermit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode,
uint256 deadline,
uint8 permitV,
bytes32 permitR,
bytes32 permitS
) external;
/**
* @notice Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned
* E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC
* @param asset The address of the underlying asset to withdraw
* @param amount The underlying amount to be withdrawn
* - Send the value type(uint256).max in order to withdraw the whole aToken balance
* @param to The address that will receive the underlying, same as msg.sender if the user
* wants to receive it on his own wallet, or a different address if the beneficiary is a
* different wallet
* @return The final amount withdrawn
*/
function withdraw(
address asset,
uint256 amount,
address to
) external returns (uint256);
/**
* @notice Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower
* already supplied enough collateral, or he was given enough allowance by a credit delegator on the
* corresponding debt token (StableDebtToken or VariableDebtToken)
* - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet
* and 100 stable/variable debt tokens, depending on the `interestRateMode`
* @param asset The address of the underlying asset to borrow
* @param amount The amount to be borrowed
* @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable
* @param referralCode The code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
* @param onBehalfOf The address of the user who will receive the debt. Should be the address of the borrower itself
* calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
* if he has been given credit delegation allowance
*/
function borrow(
address asset,
uint256 amount,
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) external;
/**
* @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned
* - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address
* @param asset The address of the borrowed underlying asset previously borrowed
* @param amount The amount to repay
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable
* @param onBehalfOf The address of the user who will get his debt reduced/removed. Should be the address of the
* user calling the function if he wants to reduce/remove his own debt, or the address of any other
* other borrower whose debt should be removed
* @return The final amount repaid
*/
function repay(
address asset,
uint256 amount,
uint256 interestRateMode,
address onBehalfOf
) external returns (uint256);
/**
* @notice Repay with transfer approval of asset to be repaid done via permit function
* see: https://eips.ethereum.org/EIPS/eip-2612 and https://eips.ethereum.org/EIPS/eip-713
* @param asset The address of the borrowed underlying asset previously borrowed
* @param amount The amount to repay
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable
* @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the
* user calling the function if he wants to reduce/remove his own debt, or the address of any other
* other borrower whose debt should be removed
* @param deadline The deadline timestamp that the permit is valid
* @param permitV The V parameter of ERC712 permit sig
* @param permitR The R parameter of ERC712 permit sig
* @param permitS The S parameter of ERC712 permit sig
* @return The final amount repaid
*/
function repayWithPermit(
address asset,
uint256 amount,
uint256 interestRateMode,
address onBehalfOf,
uint256 deadline,
uint8 permitV,
bytes32 permitR,
bytes32 permitS
) external returns (uint256);
/**
* @notice Repays a borrowed `amount` on a specific reserve using the reserve aTokens, burning the
* equivalent debt tokens
* - E.g. User repays 100 USDC using 100 aUSDC, burning 100 variable/stable debt tokens
* @dev Passing uint256.max as amount will clean up any residual aToken dust balance, if the user aToken
* balance is not enough to cover the whole debt
* @param asset The address of the borrowed underlying asset previously borrowed
* @param amount The amount to repay
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable
* @return The final amount repaid
*/
function repayWithATokens(
address asset,
uint256 amount,
uint256 interestRateMode
) external returns (uint256);
/**
* @notice Allows a borrower to swap his debt between stable and variable mode, or vice versa
* @param asset The address of the underlying asset borrowed
* @param interestRateMode The current interest rate mode of the position being swapped: 1 for Stable, 2 for Variable
*/
function swapBorrowRateMode(address asset, uint256 interestRateMode) external;
/**
* @notice Rebalances the stable interest rate of a user to the current stable rate defined on the reserve.
* - Users can be rebalanced if the following conditions are satisfied:
* 1. Usage ratio is above 95%
* 2. the current supply APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too
* much has been borrowed at a stable rate and suppliers are not earning enough
* @param asset The address of the underlying asset borrowed
* @param user The address of the user to be rebalanced
*/
function rebalanceStableBorrowRate(address asset, address user) external;
/**
* @notice Allows suppliers to enable/disable a specific supplied asset as collateral
* @param asset The address of the underlying asset supplied
* @param useAsCollateral True if the user wants to use the supply as collateral, false otherwise
*/
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external;
/**
* @notice Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1
* - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives
* a proportionally amount of the `collateralAsset` plus a bonus to cover market risk
* @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
* @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation
* @param user The address of the borrower getting liquidated
* @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover
* @param receiveAToken True if the liquidators wants to receive the collateral aTokens, `false` if he wants
* to receive the underlying collateral asset directly
*/
function liquidationCall(
address collateralAsset,
address debtAsset,
address user,
uint256 debtToCover,
bool receiveAToken
) external;
/**
* @notice Allows smartcontracts to access the liquidity of the pool within one transaction,
* as long as the amount taken plus a fee is returned.
* @dev IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept
* into consideration. For further details please visit https://docs.aave.com/developers/
* @param receiverAddress The address of the contract receiving the funds, implementing IFlashLoanReceiver interface
* @param assets The addresses of the assets being flash-borrowed
* @param amounts The amounts of the assets being flash-borrowed
* @param interestRateModes Types of the debt to open if the flash loan is not returned:
* 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver
* 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
* 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
* @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2
* @param params Variadic packed params to pass to the receiver as extra information
* @param referralCode The code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
*/
function flashLoan(
address receiverAddress,
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata interestRateModes,
address onBehalfOf,
bytes calldata params,
uint16 referralCode
) external;
/**
* @notice Allows smartcontracts to access the liquidity of the pool within one transaction,
* as long as the amount taken plus a fee is returned.
* @dev IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept
* into consideration. For further details please visit https://docs.aave.com/developers/
* @param receiverAddress The address of the contract receiving the funds, implementing IFlashLoanSimpleReceiver interface
* @param asset The address of the asset being flash-borrowed
* @param amount The amount of the asset being flash-borrowed
* @param params Variadic packed params to pass to the receiver as extra information
* @param referralCode The code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
*/
function flashLoanSimple(
address receiverAddress,
address asset,
uint256 amount,
bytes calldata params,
uint16 referralCode
) external;
/**
* @notice Returns the user account data across all the reserves
* @param user The address of the user
* @return totalCollateralBase The total collateral of the user in the base currency used by the price feed
* @return totalDebtBase The total debt of the user in the base currency used by the price feed
* @return availableBorrowsBase The borrowing power left of the user in the base currency used by the price feed
* @return currentLiquidationThreshold The liquidation threshold of the user
* @return ltv The loan to value of The user
* @return healthFactor The current health factor of the user
*/
function getUserAccountData(address user)
external
view
returns (
uint256 totalCollateralBase,
uint256 totalDebtBase,
uint256 availableBorrowsBase,
uint256 currentLiquidationThreshold,
uint256 ltv,
uint256 healthFactor
);
/**
* @notice Initializes a reserve, activating it, assigning an aToken and debt tokens and an
* interest rate strategy
* @dev Only callable by the PoolConfigurator contract
* @param asset The address of the underlying asset of the reserve
* @param aTokenAddress The address of the aToken that will be assigned to the reserve
* @param stableDebtAddress The address of the StableDebtToken that will be assigned to the reserve
* @param variableDebtAddress The address of the VariableDebtToken that will be assigned to the reserve
* @param interestRateStrategyAddress The address of the interest rate strategy contract
*/
function initReserve(
address asset,
address aTokenAddress,
address stableDebtAddress,
address variableDebtAddress,
address interestRateStrategyAddress
) external;
/**
* @notice Drop a reserve
* @dev Only callable by the PoolConfigurator contract
* @param asset The address of the underlying asset of the reserve
*/
function dropReserve(address asset) external;
/**
* @notice Updates the address of the interest rate strategy contract
* @dev Only callable by the PoolConfigurator contract
* @param asset The address of the underlying asset of the reserve
* @param rateStrategyAddress The address of the interest rate strategy contract
*/
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
external;
/**
* @notice Sets the configuration bitmap of the reserve as a whole
* @dev Only callable by the PoolConfigurator contract
* @param asset The address of the underlying asset of the reserve
* @param configuration The new configuration bitmap
*/
function setConfiguration(address asset, DataTypes.ReserveConfigurationMap calldata configuration)
external;
/**
* @notice Returns the configuration of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The configuration of the reserve
*/
function getConfiguration(address asset)
external
view
returns (DataTypes.ReserveConfigurationMap memory);
/**
* @notice Returns the configuration of the user across all the reserves
* @param user The user address
* @return The configuration of the user
*/
function getUserConfiguration(address user)
external
view
returns (DataTypes.UserConfigurationMap memory);
/**
* @notice Returns the normalized income of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The reserve's normalized income
*/
function getReserveNormalizedIncome(address asset) external view returns (uint256);
/**
* @notice Returns the normalized variable debt per unit of asset
* @dev WARNING: This function is intended to be used primarily by the protocol itself to get a
* "dynamic" variable index based on time, current stored index and virtual rate at the current
* moment (approx. a borrower would get if opening a position). This means that is always used in
* combination with variable debt supply/balances.
* If using this function externally, consider that is possible to have an increasing normalized
* variable debt that is not equivalent to how the variable debt index would be updated in storage
* (e.g. only updates with non-zero variable debt supply)
* @param asset The address of the underlying asset of the reserve
* @return The reserve normalized variable debt
*/
function getReserveNormalizedVariableDebt(address asset) external view returns (uint256);
/**
* @notice Returns the state and configuration of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The state and configuration data of the reserve
*/
function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);
/**
* @notice Validates and finalizes an aToken transfer
* @dev Only callable by the overlying aToken of the `asset`
* @param asset The address of the underlying asset of the aToken
* @param from The user from which the aTokens are transferred
* @param to The user receiving the aTokens
* @param amount The amount being transferred/withdrawn
* @param balanceFromBefore The aToken balance of the `from` user before the transfer
* @param balanceToBefore The aToken balance of the `to` user before the transfer
*/
function finalizeTransfer(
address asset,
address from,
address to,
uint256 amount,
uint256 balanceFromBefore,
uint256 balanceToBefore
) external;
/**
* @notice Returns the list of the underlying assets of all the initialized reserves
* @dev It does not include dropped reserves
* @return The addresses of the underlying assets of the initialized reserves
*/
function getReservesList() external view returns (address[] memory);
/**
* @notice Returns the address of the underlying asset of a reserve by the reserve id as stored in the DataTypes.ReserveData struct
* @param id The id of the reserve as stored in the DataTypes.ReserveData struct
* @return The address of the reserve associated with id
*/
function getReserveAddressById(uint16 id) external view returns (address);
/**
* @notice Returns the PoolAddressesProvider connected to this contract
* @return The address of the PoolAddressesProvider
*/
function ADDRESSES_PROVIDER() external view returns (IPoolAddressesProvider);
/**
* @notice Updates the protocol fee on the bridging
* @param bridgeProtocolFee The part of the premium sent to the protocol treasury
*/
function updateBridgeProtocolFee(uint256 bridgeProtocolFee) external;
/**
* @notice Updates flash loan premiums. Flash loan premium consists of two parts:
* - A part is sent to aToken holders as extra, one time accumulated interest
* - A part is collected by the protocol treasury
* @dev The total premium is calculated on the total borrowed amount
* @dev The premium to protocol is calculated on the total premium, being a percentage of `flashLoanPremiumTotal`
* @dev Only callable by the PoolConfigurator contract
* @param flashLoanPremiumTotal The total premium, expressed in bps
* @param flashLoanPremiumToProtocol The part of the premium sent to the protocol treasury, expressed in bps
*/
function updateFlashloanPremiums(
uint128 flashLoanPremiumTotal,
uint128 flashLoanPremiumToProtocol
) external;
/**
* @notice Configures a new category for the eMode.
* @dev In eMode, the protocol allows very high borrowing power to borrow assets of the same category.
* The category 0 is reserved as it's the default for volatile assets
* @param id The id of the category
* @param config The configuration of the category
*/
function configureEModeCategory(uint8 id, DataTypes.EModeCategory memory config) external;
/**
* @notice Returns the data of an eMode category
* @param id The id of the category
* @return The configuration data of the category
*/
function getEModeCategoryData(uint8 id) external view returns (DataTypes.EModeCategory memory);
/**
* @notice Allows a user to use the protocol in eMode
* @param categoryId The id of the category
*/
function setUserEMode(uint8 categoryId) external;
/**
* @notice Returns the eMode the user is using
* @param user The address of the user
* @return The eMode id
*/
function getUserEMode(address user) external view returns (uint256);
/**
* @notice Resets the isolation mode total debt of the given asset to zero
* @dev It requires the given asset has zero debt ceiling
* @param asset The address of the underlying asset to reset the isolationModeTotalDebt
*/
function resetIsolationModeTotalDebt(address asset) external;
/**
* @notice Returns the percentage of available liquidity that can be borrowed at once at stable rate
* @return The percentage of available liquidity to borrow, expressed in bps
*/
function MAX_STABLE_RATE_BORROW_SIZE_PERCENT() external view returns (uint256);
/**
* @notice Returns the total fee on flash loans
* @return The total fee on flashloans
*/
function FLASHLOAN_PREMIUM_TOTAL() external view returns (uint128);
/**
* @notice Returns the part of the bridge fees sent to protocol
* @return The bridge fee sent to the protocol treasury
*/
function BRIDGE_PROTOCOL_FEE() external view returns (uint256);
/**
* @notice Returns the part of the flashloan fees sent to protocol
* @return The flashloan fee sent to the protocol treasury
*/
function FLASHLOAN_PREMIUM_TO_PROTOCOL() external view returns (uint128);
/**
* @notice Returns the maximum number of reserves supported to be listed in this Pool
* @return The maximum number of reserves supported
*/
function MAX_NUMBER_RESERVES() external view returns (uint16);
/**
* @notice Mints the assets accrued through the reserve factor to the treasury in the form of aTokens
* @param assets The list of reserves for which the minting needs to be executed
*/
function mintToTreasury(address[] calldata assets) external;
/**
* @notice Rescue and transfer tokens locked in this contract
* @param token The address of the token
* @param to The address of the recipient
* @param amount The amount of token to transfer
*/
function rescueTokens(
address token,
address to,
uint256 amount
) external;
/**
* @notice Supplies an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
* - E.g. User supplies 100 USDC and gets in return 100 aUSDC
* @dev Deprecated: Use the `supply` function instead
* @param asset The address of the underlying asset to supply
* @param amount The amount to be supplied
* @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
* is a different wallet
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
*/
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
/**
* @title IPoolAddressesProvider
* @author Aave
* @notice Defines the basic interface for a Pool Addresses Provider.
*/
interface IPoolAddressesProvider {
/**
* @dev Emitted when the market identifier is updated.
* @param oldMarketId The old id of the market
* @param newMarketId The new id of the market
*/
event MarketIdSet(string indexed oldMarketId, string indexed newMarketId);
/**
* @dev Emitted when the pool is updated.
* @param oldAddress The old address of the Pool
* @param newAddress The new address of the Pool
*/
event PoolUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the pool configurator is updated.
* @param oldAddress The old address of the PoolConfigurator
* @param newAddress The new address of the PoolConfigurator
*/
event PoolConfiguratorUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the price oracle is updated.
* @param oldAddress The old address of the PriceOracle
* @param newAddress The new address of the PriceOracle
*/
event PriceOracleUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the ACL manager is updated.
* @param oldAddress The old address of the ACLManager
* @param newAddress The new address of the ACLManager
*/
event ACLManagerUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the ACL admin is updated.
* @param oldAddress The old address of the ACLAdmin
* @param newAddress The new address of the ACLAdmin
*/
event ACLAdminUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the price oracle sentinel is updated.
* @param oldAddress The old address of the PriceOracleSentinel
* @param newAddress The new address of the PriceOracleSentinel
*/
event PriceOracleSentinelUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the pool data provider is updated.
* @param oldAddress The old address of the PoolDataProvider
* @param newAddress The new address of the PoolDataProvider
*/
event PoolDataProviderUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when a new proxy is created.
* @param id The identifier of the proxy
* @param proxyAddress The address of the created proxy contract
* @param implementationAddress The address of the implementation contract
*/
event ProxyCreated(
bytes32 indexed id,
address indexed proxyAddress,
address indexed implementationAddress
);
/**
* @dev Emitted when a new non-proxied contract address is registered.
* @param id The identifier of the contract
* @param oldAddress The address of the old contract
* @param newAddress The address of the new contract
*/
event AddressSet(bytes32 indexed id, address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the implementation of the proxy registered with id is updated
* @param id The identifier of the contract
* @param proxyAddress The address of the proxy contract
* @param oldImplementationAddress The address of the old implementation contract
* @param newImplementationAddress The address of the new implementation contract
*/
event AddressSetAsProxy(
bytes32 indexed id,
address indexed proxyAddress,
address oldImplementationAddress,
address indexed newImplementationAddress
);
/**
* @notice Returns the id of the Aave market to which this contract points to.
* @return The market id
*/
function getMarketId() external view returns (string memory);
/**
* @notice Associates an id with a specific PoolAddressesProvider.
* @dev This can be used to create an onchain registry of PoolAddressesProviders to
* identify and validate multiple Aave markets.
* @param newMarketId The market id
*/
function setMarketId(string calldata newMarketId) external;
/**
* @notice Returns an address by its identifier.
* @dev The returned address might be an EOA or a contract, potentially proxied
* @dev It returns ZERO if there is no registered address with the given id
* @param id The id
* @return The address of the registered for the specified id
*/
function getAddress(bytes32 id) external view returns (address);
/**
* @notice General function to update the implementation of a proxy registered with
* certain `id`. If there is no proxy registered, it will instantiate one and
* set as implementation the `newImplementationAddress`.
* @dev IMPORTANT Use this function carefully, only for ids that don't have an explicit
* setter function, in order to avoid unexpected consequences
* @param id The id
* @param newImplementationAddress The address of the new implementation
*/
function setAddressAsProxy(bytes32 id, address newImplementationAddress) external;
/**
* @notice Sets an address for an id replacing the address saved in the addresses map.
* @dev IMPORTANT Use this function carefully, as it will do a hard replacement
* @param id The id
* @param newAddress The address to set
*/
function setAddress(bytes32 id, address newAddress) external;
/**
* @notice Returns the address of the Pool proxy.
* @return The Pool proxy address
*/
function getPool() external view returns (address);
/**
* @notice Updates the implementation of the Pool, or creates a proxy
* setting the new `pool` implementation when the function is called for the first time.
* @param newPoolImpl The new Pool implementation
*/
function setPoolImpl(address newPoolImpl) external;
/**
* @notice Returns the address of the PoolConfigurator proxy.
* @return The PoolConfigurator proxy address
*/
function getPoolConfigurator() external view returns (address);
/**
* @notice Updates the implementation of the PoolConfigurator, or creates a proxy
* setting the new `PoolConfigurator` implementation when the function is called for the first time.
* @param newPoolConfiguratorImpl The new PoolConfigurator implementation
*/
function setPoolConfiguratorImpl(address newPoolConfiguratorImpl) external;
/**
* @notice Returns the address of the price oracle.
* @return The address of the PriceOracle
*/
function getPriceOracle() external view returns (address);
/**
* @notice Updates the address of the price oracle.
* @param newPriceOracle The address of the new PriceOracle
*/
function setPriceOracle(address newPriceOracle) external;
/**
* @notice Returns the address of the ACL manager.
* @return The address of the ACLManager
*/
function getACLManager() external view returns (address);
/**
* @notice Updates the address of the ACL manager.
* @param newAclManager The address of the new ACLManager
*/
function setACLManager(address newAclManager) external;
/**
* @notice Returns the address of the ACL admin.
* @return The address of the ACL admin
*/
function getACLAdmin() external view returns (address);
/**
* @notice Updates the address of the ACL admin.
* @param newAclAdmin The address of the new ACL admin
*/
function setACLAdmin(address newAclAdmin) external;
/**
* @notice Returns the address of the price oracle sentinel.
* @return The address of the PriceOracleSentinel
*/
function getPriceOracleSentinel() external view returns (address);
/**
* @notice Updates the address of the price oracle sentinel.
* @param newPriceOracleSentinel The address of the new PriceOracleSentinel
*/
function setPriceOracleSentinel(address newPriceOracleSentinel) external;
/**
* @notice Returns the address of the data provider.
* @return The address of the DataProvider
*/
function getPoolDataProvider() external view returns (address);
/**
* @notice Updates the address of the data provider.
* @param newDataProvider The address of the new DataProvider
*/
function setPoolDataProvider(address newDataProvider) external;
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
/**
* @title IPriceOracle
* @author Aave
* @notice Defines the basic interface for a Price oracle.
*/
interface IPriceOracle {
/**
* @notice Returns the asset price in the base currency
* @param asset The address of the asset
* @return The price of the asset
*/
function getAssetPrice(address asset) external view returns (uint256);
/**
* @notice Set the price of the asset
* @param asset The address of the asset
* @param price The price of the asset
*/
function setAssetPrice(address asset, uint256 price) external;
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
/**
* @title IScaledBalanceToken
* @author Aave
* @notice Defines the basic interface for a scaled-balance token.
*/
interface IScaledBalanceToken {
/**
* @dev Emitted after the mint action
* @param caller The address performing the mint
* @param onBehalfOf The address of the user that will receive the minted tokens
* @param value The scaled-up amount being minted (based on user entered amount and balance increase from interest)
* @param balanceIncrease The increase in scaled-up balance since the last action of 'onBehalfOf'
* @param index The next liquidity index of the reserve
*/
event Mint(
address indexed caller,
address indexed onBehalfOf,
uint256 value,
uint256 balanceIncrease,
uint256 index
);
/**
* @dev Emitted after the burn action
* @dev If the burn function does not involve a transfer of the underlying asset, the target defaults to zero address
* @param from The address from which the tokens will be burned
* @param target The address that will receive the underlying, if any
* @param value The scaled-up amount being burned (user entered amount - balance increase from interest)
* @param balanceIncrease The increase in scaled-up balance since the last action of 'from'
* @param index The next liquidity index of the reserve
*/
event Burn(
address indexed from,
address indexed target,
uint256 value,
uint256 balanceIncrease,
uint256 index
);
/**
* @notice Returns the scaled balance of the user.
* @dev The scaled balance is the sum of all the updated stored balance divided by the reserve's liquidity index
* at the moment of the update
* @param user The user whose balance is calculated
* @return The scaled balance of the user
*/
function scaledBalanceOf(address user) external view returns (uint256);
/**
* @notice Returns the scaled balance of the user and the scaled total supply.
* @param user The address of the user
* @return The scaled balance of the user
* @return The scaled total supply
*/
function getScaledUserBalanceAndSupply(address user) external view returns (uint256, uint256);
/**
* @notice Returns the scaled total supply of the scaled balance token. Represents sum(debt/index)
* @return The scaled total supply
*/
function scaledTotalSupply() external view returns (uint256);
/**
* @notice Returns last index interest was accrued to the user's balance
* @param user The address of the user
* @return The last index interest was accrued to the user's balance, expressed in ray
*/
function getPreviousIndex(address user) external view returns (uint256);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
library DataTypes {
struct ReserveData {
//stores the reserve configuration
ReserveConfigurationMap configuration;
//the liquidity index. Expressed in ray
uint128 liquidityIndex;
//the current supply rate. Expressed in ray
uint128 currentLiquidityRate;
//variable borrow index. Expressed in ray
uint128 variableBorrowIndex;
//the current variable borrow rate. Expressed in ray
uint128 currentVariableBorrowRate;
//the current stable borrow rate. Expressed in ray
uint128 currentStableBorrowRate;
//timestamp of last update
uint40 lastUpdateTimestamp;
//the id of the reserve. Represents the position in the list of the active reserves
uint16 id;
//aToken address
address aTokenAddress;
//stableDebtToken address
address stableDebtTokenAddress;
//variableDebtToken address
address variableDebtTokenAddress;
//address of the interest rate strategy
address interestRateStrategyAddress;
//the current treasury balance, scaled
uint128 accruedToTreasury;
//the outstanding unbacked aTokens minted through the bridging feature
uint128 unbacked;
//the outstanding debt borrowed against this asset in isolation mode
uint128 isolationModeTotalDebt;
}
struct ReserveConfigurationMap {
//bit 0-15: LTV
//bit 16-31: Liq. threshold
//bit 32-47: Liq. bonus
//bit 48-55: Decimals
//bit 56: reserve is active
//bit 57: reserve is frozen
//bit 58: borrowing is enabled
//bit 59: stable rate borrowing enabled
//bit 60: asset is paused
//bit 61: borrowing in isolation mode is enabled
//bit 62-63: reserved
//bit 64-79: reserve factor
//bit 80-115 borrow cap in whole tokens, borrowCap == 0 => no cap
//bit 116-151 supply cap in whole tokens, supplyCap == 0 => no cap
//bit 152-167 liquidation protocol fee
//bit 168-175 eMode category
//bit 176-211 unbacked mint cap in whole tokens, unbackedMintCap == 0 => minting disabled
//bit 212-251 debt ceiling for isolation mode with (ReserveConfiguration::DEBT_CEILING_DECIMALS) decimals
//bit 252-255 unused
uint256 data;
}
struct UserConfigurationMap {
/**
* @dev Bitmap of the users collaterals and borrows. It is divided in pairs of bits, one pair per asset.
* The first bit indicates if an asset is used as collateral by the user, the second whether an
* asset is borrowed by the user.
*/
uint256 data;
}
struct EModeCategory {
// each eMode category has a custom ltv and liquidation threshold
uint16 ltv;
uint16 liquidationThreshold;
uint16 liquidationBonus;
// each eMode category may or may not have a custom oracle to override the individual assets price oracles
address priceSource;
string label;
}
enum InterestRateMode {
NONE,
STABLE,
VARIABLE
}
struct ReserveCache {
uint256 currScaledVariableDebt;
uint256 nextScaledVariableDebt;
uint256 currPrincipalStableDebt;
uint256 currAvgStableBorrowRate;
uint256 currTotalStableDebt;
uint256 nextAvgStableBorrowRate;
uint256 nextTotalStableDebt;
uint256 currLiquidityIndex;
uint256 nextLiquidityIndex;
uint256 currVariableBorrowIndex;
uint256 nextVariableBorrowIndex;
uint256 currLiquidityRate;
uint256 currVariableBorrowRate;
uint256 reserveFactor;
ReserveConfigurationMap reserveConfiguration;
address aTokenAddress;
address stableDebtTokenAddress;
address variableDebtTokenAddress;
uint40 reserveLastUpdateTimestamp;
uint40 stableDebtLastUpdateTimestamp;
}
struct ExecuteLiquidationCallParams {
uint256 reservesCount;
uint256 debtToCover;
address collateralAsset;
address debtAsset;
address user;
bool receiveAToken;
address priceOracle;
uint8 userEModeCategory;
address priceOracleSentinel;
}
struct ExecuteSupplyParams {
address asset;
uint256 amount;
address onBehalfOf;
uint16 referralCode;
}
struct ExecuteBorrowParams {
address asset;
address user;
address onBehalfOf;
uint256 amount;
InterestRateMode interestRateMode;
uint16 referralCode;
bool releaseUnderlying;
uint256 maxStableRateBorrowSizePercent;
uint256 reservesCount;
address oracle;
uint8 userEModeCategory;
address priceOracleSentinel;
}
struct ExecuteRepayParams {
address asset;
uint256 amount;
InterestRateMode interestRateMode;
address onBehalfOf;
bool useATokens;
}
struct ExecuteWithdrawParams {
address asset;
uint256 amount;
address to;
uint256 reservesCount;
address oracle;
uint8 userEModeCategory;
}
struct ExecuteSetUserEModeParams {
uint256 reservesCount;
address oracle;
uint8 categoryId;
}
struct FinalizeTransferParams {
address asset;
address from;
address to;
uint256 amount;
uint256 balanceFromBefore;
uint256 balanceToBefore;
uint256 reservesCount;
address oracle;
uint8 fromEModeCategory;
}
struct FlashloanParams {
address receiverAddress;
address[] assets;
uint256[] amounts;
uint256[] interestRateModes;
address onBehalfOf;
bytes params;
uint16 referralCode;
uint256 flashLoanPremiumToProtocol;
uint256 flashLoanPremiumTotal;
uint256 maxStableRateBorrowSizePercent;
uint256 reservesCount;
address addressesProvider;
uint8 userEModeCategory;
bool isAuthorizedFlashBorrower;
}
struct FlashloanSimpleParams {
address receiverAddress;
address asset;
uint256 amount;
bytes params;
uint16 referralCode;
uint256 flashLoanPremiumToProtocol;
uint256 flashLoanPremiumTotal;
}
struct FlashLoanRepaymentParams {
uint256 amount;
uint256 totalPremium;
uint256 flashLoanPremiumToProtocol;
address asset;
address receiverAddress;
uint16 referralCode;
}
struct CalculateUserAccountDataParams {
UserConfigurationMap userConfig;
uint256 reservesCount;
address user;
address oracle;
uint8 userEModeCategory;
}
struct ValidateBorrowParams {
ReserveCache reserveCache;
UserConfigurationMap userConfig;
address asset;
address userAddress;
uint256 amount;
InterestRateMode interestRateMode;
uint256 maxStableLoanPercent;
uint256 reservesCount;
address oracle;
uint8 userEModeCategory;
address priceOracleSentinel;
bool isolationModeActive;
address isolationModeCollateralAddress;
uint256 isolationModeDebtCeiling;
}
struct ValidateLiquidationCallParams {
ReserveCache debtReserveCache;
uint256 totalDebt;
uint256 healthFactor;
address priceOracleSentinel;
}
struct CalculateInterestRatesParams {
uint256 unbacked;
uint256 liquidityAdded;
uint256 liquidityTaken;
uint256 totalStableDebt;
uint256 totalVariableDebt;
uint256 averageStableBorrowRate;
uint256 reserveFactor;
address reserve;
address aToken;
}
struct InitReserveParams {
address asset;
address aTokenAddress;
address stableDebtAddress;
address variableDebtAddress;
address interestRateStrategyAddress;
uint16 reservesCount;
uint16 maxNumberReserves;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
* initialization step. This is essential to configure modules that are added through upgrades and that require
* initialization.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
function __Pausable_init() internal onlyInitializing {
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
}
_balances[to] += amount;
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[45] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts 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 (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../token/ERC20/extensions/IERC20Metadata.sol";
// 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: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
library FixedPointMathLib {
/*//////////////////////////////////////////////////////////////
SIMPLIFIED FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s.
function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
}
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up.
}
function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down.
}
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up.
}
/*//////////////////////////////////////////////////////////////
LOW LEVEL FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
function mulDivDown(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
assembly {
// Store x * y in z for now.
z := mul(x, y)
// Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
revert(0, 0)
}
// Divide z by the denominator.
z := div(z, denominator)
}
}
function mulDivUp(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
assembly {
// Store x * y in z for now.
z := mul(x, y)
// Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
revert(0, 0)
}
// First, divide z - 1 by the denominator and add 1.
// We allow z - 1 to underflow if z is 0, because we multiply the
// end result by 0 if z is zero, ensuring we return 0 if z is zero.
z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1))
}
}
function rpow(
uint256 x,
uint256 n,
uint256 scalar
) internal pure returns (uint256 z) {
assembly {
switch x
case 0 {
switch n
case 0 {
// 0 ** 0 = 1
z := scalar
}
default {
// 0 ** n = 0
z := 0
}
}
default {
switch mod(n, 2)
case 0 {
// If n is even, store scalar in z for now.
z := scalar
}
default {
// If n is odd, store x in z for now.
z := x
}
// Shifting right by 1 is like dividing by 2.
let half := shr(1, scalar)
for {
// Shift n right by 1 before looping to halve it.
n := shr(1, n)
} n {
// Shift n right by 1 each iteration to halve it.
n := shr(1, n)
} {
// Revert immediately if x ** 2 would overflow.
// Equivalent to iszero(eq(div(xx, x), x)) here.
if shr(128, x) {
revert(0, 0)
}
// Store x squared.
let xx := mul(x, x)
// Round to the nearest number.
let xxRound := add(xx, half)
// Revert if xx + half overflowed.
if lt(xxRound, xx) {
revert(0, 0)
}
// Set x to scaled xxRound.
x := div(xxRound, scalar)
// If n is even:
if mod(n, 2) {
// Compute z * x.
let zx := mul(z, x)
// If z * x overflowed:
if iszero(eq(div(zx, x), z)) {
// Revert if x is non-zero.
if iszero(iszero(x)) {
revert(0, 0)
}
}
// Round to the nearest number.
let zxRound := add(zx, half)
// Revert if zx + half overflowed.
if lt(zxRound, zx) {
revert(0, 0)
}
// Return properly scaled zxRound.
z := div(zxRound, scalar)
}
}
}
}
}
/*//////////////////////////////////////////////////////////////
GENERAL NUMBER UTILITIES
//////////////////////////////////////////////////////////////*/
function sqrt(uint256 x) internal pure returns (uint256 z) {
assembly {
// Start off with z at 1.
z := 1
// Used below to help find a nearby power of 2.
let y := x
// Find the lowest power of 2 that is at least sqrt(x).
if iszero(lt(y, 0x100000000000000000000000000000000)) {
y := shr(128, y) // Like dividing by 2 ** 128.
z := shl(64, z) // Like multiplying by 2 ** 64.
}
if iszero(lt(y, 0x10000000000000000)) {
y := shr(64, y) // Like dividing by 2 ** 64.
z := shl(32, z) // Like multiplying by 2 ** 32.
}
if iszero(lt(y, 0x100000000)) {
y := shr(32, y) // Like dividing by 2 ** 32.
z := shl(16, z) // Like multiplying by 2 ** 16.
}
if iszero(lt(y, 0x10000)) {
y := shr(16, y) // Like dividing by 2 ** 16.
z := shl(8, z) // Like multiplying by 2 ** 8.
}
if iszero(lt(y, 0x100)) {
y := shr(8, y) // Like dividing by 2 ** 8.
z := shl(4, z) // Like multiplying by 2 ** 4.
}
if iszero(lt(y, 0x10)) {
y := shr(4, y) // Like dividing by 2 ** 4.
z := shl(2, z) // Like multiplying by 2 ** 2.
}
if iszero(lt(y, 0x8)) {
// Equivalent to 2 ** z.
z := shl(1, z)
}
// Shifting right by 1 is like dividing by 2.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// Compute a rounded down version of z.
let zRoundDown := div(x, z)
// If zRoundDown is smaller, use it.
if lt(zRoundDown, z) {
z := zRoundDown
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
/// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
/// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
function mulDiv(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = a * b
// Compute the product mod 2**256 and mod 2**256 - 1
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2**256 + prod0
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(a, b, not(0))
prod0 := mul(a, b)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division
if (prod1 == 0) {
require(denominator > 0);
assembly {
result := div(prod0, denominator)
}
return result;
}
// Make sure the result is less than 2**256.
// Also prevents denominator == 0
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly {
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator
// Compute largest power of two divisor of denominator.
// Always >= 1.
uint256 twos = (0 - denominator) & denominator;
// Divide denominator by power of two
assembly {
denominator := div(denominator, twos)
}
// Divide [prod1 prod0] by the factors of two
assembly {
prod0 := div(prod0, twos)
}
// Shift in bits from prod1 into prod0. For this we need
// to flip `twos` such that it is 2**256 / twos.
// If twos is zero, then it becomes one
assembly {
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
// Invert denominator mod 2**256
// Now that denominator is an odd number, it has an inverse
// modulo 2**256 such that denominator * inv = 1 mod 2**256.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, denominator * inv = 1 mod 2**4
uint256 inv = (3 * denominator) ^ 2;
// Now use Newton-Raphson iteration to improve the precision.
// Thanks to Hensel's lifting lemma, this also works in modular
// arithmetic, doubling the correct bits in each step.
inv *= 2 - denominator * inv; // inverse mod 2**8
inv *= 2 - denominator * inv; // inverse mod 2**16
inv *= 2 - denominator * inv; // inverse mod 2**32
inv *= 2 - denominator * inv; // inverse mod 2**64
inv *= 2 - denominator * inv; // inverse mod 2**128
inv *= 2 - denominator * inv; // inverse mod 2**256
// Because the division is now exact we can divide by multiplying
// with the modular inverse of denominator. This will give us the
// correct result modulo 2**256. Since the precoditions guarantee
// that the outcome is less than 2**256, this is the final result.
// We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inv;
return result;
}
}
/// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
function mulDivRoundingUp(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) > 0) {
require(result < type(uint256).max);
result++;
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { SafeERC20 } from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import { IERC20Metadata } from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import { ERC20Upgradeable } from '@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol';
import { FixedPointMathLib } from '@rari-capital/solmate/src/utils/FixedPointMathLib.sol';
import { IERC4626 } from '../interfaces/IERC4626.sol';
/// @notice Minimal ERC4626 tokenized Vault implementation.
/// @author Copied and modified from Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol)
abstract contract ERC4626Upgradeable is IERC4626, ERC20Upgradeable {
using SafeERC20 for IERC20Metadata;
using FixedPointMathLib for uint256;
/*//////////////////////////////////////////////////////////////
STATE
//////////////////////////////////////////////////////////////*/
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
address public asset;
// these gaps are added to allow adding new variables without shifting down inheritance chain
uint256[50] private __gaps;
/* solhint-disable func-name-mixedcase */
function __ERC4626Upgradeable_init(address _asset, string memory _name, string memory _symbol) internal {
__ERC20_init(_name, _symbol);
asset = _asset;
}
/*//////////////////////////////////////////////////////////////
DEPOSIT/WITHDRAWAL LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) {
// Check for rounding error since we round down in previewDeposit.
require((shares = previewDeposit(assets)) != 0, 'ZERO_SHARES');
// Need to transfer before minting or ERC777s could reenter.
IERC20Metadata(asset).safeTransferFrom(msg.sender, address(this), assets);
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, assets, shares);
afterDeposit(assets, shares, receiver);
}
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) public virtual returns (uint256 assets) {
assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up.
// Need to transfer before minting or ERC777s could reenter.
IERC20Metadata(asset).safeTransferFrom(msg.sender, address(this), assets);
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, assets, shares);
afterDeposit(assets, shares, receiver);
}
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) public virtual returns (uint256 shares) {
shares = previewWithdraw(assets); // No need to check for rounding error, previewWithdraw rounds up.
if (msg.sender != owner) {
uint256 allowed = allowance(owner, msg.sender); // Saves gas for limited approvals.
if (allowed != type(uint256).max) _approve(owner, msg.sender, allowed - shares);
}
beforeWithdraw(assets, shares, receiver);
_burn(owner, shares);
emit Withdraw(msg.sender, receiver, owner, assets, shares);
IERC20Metadata(asset).safeTransfer(receiver, assets);
}
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) public virtual returns (uint256 assets) {
if (msg.sender != owner) {
uint256 allowed = allowance(owner, msg.sender); // Saves gas for limited approvals.
if (allowed != type(uint256).max) _approve(owner, msg.sender, allowed - shares);
}
// Check for rounding error since we round down in previewRedeem.
require((assets = previewRedeem(shares)) != 0, 'ZERO_ASSETS');
beforeWithdraw(assets, shares, receiver);
_burn(owner, shares);
emit Withdraw(msg.sender, receiver, owner, assets, shares);
IERC20Metadata(asset).safeTransfer(receiver, assets);
}
/*//////////////////////////////////////////////////////////////
ACCOUNTING LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() public view virtual returns (uint256);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) public view virtual returns (uint256) {
uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.
return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets());
}
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) public view virtual returns (uint256) {
uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.
return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply);
}
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) public view virtual returns (uint256) {
return convertToShares(assets);
}
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) public view virtual returns (uint256) {
uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.
return supply == 0 ? shares : shares.mulDivUp(totalAssets(), supply);
}
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.
return supply == 0 ? assets : assets.mulDivUp(supply, totalAssets());
}
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) public view virtual returns (uint256) {
return convertToAssets(shares);
}
/*//////////////////////////////////////////////////////////////
DEPOSIT/WITHDRAWAL LIMIT LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address) public view virtual returns (uint256) {
return type(uint256).max;
}
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address) public view virtual returns (uint256) {
return type(uint256).max;
}
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) public view virtual returns (uint256) {
return convertToAssets(balanceOf(owner));
}
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) public view virtual returns (uint256) {
return balanceOf(owner);
}
/*//////////////////////////////////////////////////////////////
INTERNAL HOOKS LOGIC
//////////////////////////////////////////////////////////////*/
/* solhint-disable no-empty-blocks */
function beforeWithdraw(uint256 assets, uint256 shares, address receiver) internal virtual {}
/* solhint-disable no-empty-blocks */
function afterDeposit(uint256 assets, uint256 shares, address receiver) internal virtual {}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
interface IBorrower {
function harvestFees() external;
function getUsdcBorrowed() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IBorrower } from './IBorrower.sol';
import { IERC4626 } from './IERC4626.sol';
interface IDnGmxSeniorVault is IERC4626 {
error InvalidMaxUtilizationBps();
error CallerNotBorrower();
error InvalidCapUpdate();
error InvalidBorrowAmount();
error InvalidBorrowerAddress();
error DepositCapExceeded();
error MaxUtilizationBreached();
event AllowancesGranted();
event DepositCapUpdated(uint256 _newDepositCap);
event BorrowCapUpdated(address vault, uint256 newCap);
event LeveragePoolUpdated(IBorrower leveragePool);
event DnGmxJuniorVaultUpdated(IBorrower dnGmxJuniorVault);
event MaxUtilizationBpsUpdated(uint256 maxUtilizationBps);
event FeeStrategyUpdated(
uint128 optimalUtilizationRate,
uint128 baseVariableBorrowRate,
uint128 variableRateSlope1,
uint128 variableRateSlope2
);
// eventType - 0 = start of txn | 1 = end of txn
event VaultState(uint256 indexed eventType, uint256 juniorVaultAusdc, uint256 seniorVaultAusdc);
function borrow(uint256 amount) external;
function repay(uint256 amount) external;
function depositCap() external view returns (uint256);
function getPriceX128() external view returns (uint256);
function getEthRewardsSplitRate() external returns (uint256);
function getVaultMarketValue() external view returns (uint256);
function availableBorrow(address borrower) external view returns (uint256);
function withdrawToMultisig() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IERC20Upgradeable } from '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol';
import { IERC20Metadata } from '@openzeppelin/contracts/interfaces/IERC20Metadata.sol';
interface IERC4626 is IERC20Upgradeable {
event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed caller,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}// SPDX-License-Identifier: agpl-3.0
pragma solidity >=0.8.0;
import { FullMath } from '@uniswap/v3-core/contracts/libraries/FullMath.sol';
/**
* @title FeeSplitStrategy library
* @notice Implements the calculation of the eth reward split depending on the utilization of reserve
* @dev The model of interest rate is based on 2 slopes, one before the `OPTIMAL_UTILIZATION_RATE`
* point of utilization and another from that one to 100%
* @author adapted from https://github.com/aave/protocol-v2/blob/6f57232358af0fd41d9dcf9309d7a8c0b9aa3912/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol
**/
library FeeSplitStrategy {
using FullMath for uint128;
using FullMath for uint256;
uint256 internal constant RATE_PRECISION = 1e30;
struct Info {
/**
* @dev this constant represents the utilization rate at which the pool aims to obtain most competitive borrow rates.
* Expressed in ray
**/
uint128 optimalUtilizationRate;
// Base variable borrow rate when Utilization rate = 0. Expressed in ray
uint128 baseVariableBorrowRate;
// Slope of the variable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint128 variableRateSlope1;
// Slope of the variable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint128 variableRateSlope2;
}
function getMaxVariableBorrowRate(Info storage feeStrategyInfo) internal view returns (uint256) {
return
feeStrategyInfo.baseVariableBorrowRate +
feeStrategyInfo.variableRateSlope1 +
feeStrategyInfo.variableRateSlope2;
}
/**
* @dev Calculates the interest rates depending on the reserve's state and configurations.
* NOTE This function is kept for compatibility with the previous DefaultInterestRateStrategy interface.
* New protocol implementation uses the new calculateInterestRates() interface
* @param availableLiquidity The liquidity available in the corresponding aToken
* @param usedLiquidity The total borrowed from the reserve at a variable rate
**/
function calculateFeeSplit(
Info storage feeStrategy,
uint256 availableLiquidity,
uint256 usedLiquidity
) internal view returns (uint256 feeSplitRate) {
uint256 utilizationRate = usedLiquidity == 0
? 0
: usedLiquidity.mulDiv(RATE_PRECISION, availableLiquidity + usedLiquidity);
uint256 excessUtilizationRate = RATE_PRECISION - feeStrategy.optimalUtilizationRate;
if (utilizationRate > feeStrategy.optimalUtilizationRate) {
uint256 excessUtilizationRateRatio = (utilizationRate - feeStrategy.optimalUtilizationRate).mulDiv(
RATE_PRECISION,
excessUtilizationRate
);
feeSplitRate =
feeStrategy.baseVariableBorrowRate +
feeStrategy.variableRateSlope1 +
feeStrategy.variableRateSlope2.mulDiv(excessUtilizationRateRatio, RATE_PRECISION);
} else {
feeSplitRate =
feeStrategy.baseVariableBorrowRate +
utilizationRate.mulDiv(feeStrategy.variableRateSlope1, feeStrategy.optimalUtilizationRate);
}
}
}{
"viaIR": true,
"optimizer": {
"enabled": true,
"runs": 256
},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"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":[],"name":"CallerNotBorrower","type":"error"},{"inputs":[],"name":"DepositCapExceeded","type":"error"},{"inputs":[],"name":"InvalidBorrowAmount","type":"error"},{"inputs":[],"name":"InvalidBorrowerAddress","type":"error"},{"inputs":[],"name":"InvalidCapUpdate","type":"error"},{"inputs":[],"name":"InvalidMaxUtilizationBps","type":"error"},{"inputs":[],"name":"MaxUtilizationBreached","type":"error"},{"anonymous":false,"inputs":[],"name":"AllowancesGranted","type":"event"},{"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":false,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint256","name":"newCap","type":"uint256"}],"name":"BorrowCapUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_newDepositCap","type":"uint256"}],"name":"DepositCapUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IBorrower","name":"dnGmxJuniorVault","type":"address"}],"name":"DnGmxJuniorVaultUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"optimalUtilizationRate","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"baseVariableBorrowRate","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"variableRateSlope1","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"variableRateSlope2","type":"uint128"}],"name":"FeeStrategyUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IBorrower","name":"leveragePool","type":"address"}],"name":"LeveragePoolUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxUtilizationBps","type":"uint256"}],"name":"MaxUtilizationBpsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eventType","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"juniorVaultAusdc","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"seniorVaultAusdc","type":"uint256"}],"name":"VaultState","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"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":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"}],"name":"availableBorrow","outputs":[{"internalType":"uint256","name":"availableAUsdc","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"borrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"}],"name":"borrowCaps","outputs":[{"internalType":"uint256","name":"cap","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","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":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dnGmxJuniorVault","outputs":[{"internalType":"contract IBorrower","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeStrategy","outputs":[{"internalType":"uint128","name":"optimalUtilizationRate","type":"uint128"},{"internalType":"uint128","name":"baseVariableBorrowRate","type":"uint128"},{"internalType":"uint128","name":"variableRateSlope1","type":"uint128"},{"internalType":"uint128","name":"variableRateSlope2","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEthRewardsSplitRate","outputs":[{"internalType":"uint256","name":"feeSplitRate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPriceX128","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVaultMarketValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"grantAllowances","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_usdc","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_poolAddressesProvider","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"leveragePool","outputs":[{"internalType":"contract IBorrower","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxUtilizationBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"repay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newDepositCap","type":"uint256"}],"name":"setDepositCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IBorrower","name":"_dnGmxJuniorVault","type":"address"}],"name":"setDnGmxJuniorVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IBorrower","name":"_leveragePool","type":"address"}],"name":"setLeveragePool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxUtilizationBps","type":"uint256"}],"name":"setMaxUtilizationBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalUsdcBorrowed","outputs":[{"internalType":"uint256","name":"usdcBorrowed","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":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"borrowerAddress","type":"address"},{"internalType":"uint256","name":"cap","type":"uint256"}],"name":"updateBorrowCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint128","name":"optimalUtilizationRate","type":"uint128"},{"internalType":"uint128","name":"baseVariableBorrowRate","type":"uint128"},{"internalType":"uint128","name":"variableRateSlope1","type":"uint128"},{"internalType":"uint128","name":"variableRateSlope2","type":"uint128"}],"internalType":"struct FeeSplitStrategy.Info","name":"_feeStrategy","type":"tuple"}],"name":"updateFeeStrategyParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawToMultisig","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
6080806040523461001657613b7a908161001c8239f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c806301e1d1141461037d57806306fdde031461037857806307a2d13a14610332578063095ea7b3146103735780630a28a4771461036e57806318160ddd1461036957806323b872dd14610364578063304ea9cb1461035f578063313ce5671461035a578063371fd8e61461035557806338d52e0f14610350578063395093511461034b5780633d672a45146103465780633f4ba83a14610341578063402d267d1461033c5780634a584432146103375780634cdad50614610332578063543bc9841461032d57806356ab92b3146103285780635c975abb14610323578063613d25bb1461031e5780636e553f651461031957806370a0823114610314578063715018a61461030f578063768e66d31461030a57806377c718ae146103055780638224f4e8146103005780638456cb59146102fb57806386651203146102f65780638d315d7b146102f15780638da5cb5b146102ec578063949b22ae146102e757806394bf804d146102e257806395d89b41146102dd578063964f7be2146102d8578063a457c2d7146102d3578063a9059cbb146102ce578063aa88fdc3146102c9578063b3d7f6b9146102c4578063b460af94146102bf578063ba087652146102ba578063bf9571f1146102b5578063c5ebeaec146102b0578063c63d75b6146102ab578063c6e6f5921461027e578063c722328d146102a6578063ce96cb77146102a1578063d026c1231461029c578063d905777e14610297578063db2d9c3a14610292578063dbd5edc71461028d578063dd62ed3e14610288578063e3696edd14610283578063ef8b30f71461027e5763f2fde38b1461027957600080fd5b611df8565b611b22565b611d79565b611d14565b611cf6565b611c88565b611c63565b611bf5565b611bce565b611b40565b611af4565b6119f9565b6118ae565b61178a565b61164d565b611603565b6115dc565b6115b2565b6114ff565b6113c3565b61131c565b61116c565b611125565b6110fe565b61107b565b61102f565b610fd5565b610fae565b610f93565b610dd0565b610d72565b610d34565b610bfd565b610ac4565b610a73565b610a0b565b6109e4565b6104e3565b6109a5565b61097f565b6108eb565b610850565b6107ed565b6107c6565b61069f565b610683565b610665565b610583565b610565565b610547565b610512565b6103fe565b610392565b600091031261038d57565b600080fd5b3461038d57600036600319011261038d5760206103ad613861565b604051908152f35b6020808252825181830181905290939260005b8281106103ea57505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016103c8565b3461038d576000806003193601126104e057604051908060365461042181611f2b565b808552916001918083169081156104b6575060011461045b575b6104578561044b81870382611fb0565b604051918291826103b5565b0390f35b9250603683527f4a11f94e20a93c79f6ec743a1954ec4fc2c08429ae2122118bf234b2185c81b85b82841061049e57505050810160200161044b8261045761043b565b80546020858701810191909152909301928101610483565b8695506104579693506020925061044b94915060ff191682840152151560051b820101929361043b565b80fd5b3461038d57602036600319011261038d5760206103ad60043561232c565b6001600160a01b0381160361038d57565b3461038d57604036600319011261038d5761053c60043561053281610501565b60243590336121cc565b602060405160018152f35b3461038d57602036600319011261038d5760206103ad60043561238c565b3461038d57600036600319011261038d576020603554604051908152f35b3461038d57606036600319011261038d576004356105a081610501565b6024356105ac81610501565b604435906001600160a01b03831660005260346020526105e3336040600020906001600160a01b0316600052602052604060002090565b549260018401610604575b6105f893506120a8565b60405160018152602090f35b8284106106205761061b836105f8950333836121cc565b6105ee565b60405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606490fd5b3461038d57600036600319011261038d57602060fd54604051908152f35b3461038d57600036600319011261038d57602060405160068152f35b3461038d57602036600319011261038d576001600160a01b038060ff5416908133141590816107b7575b506107a557803b1561038d576000809160046040518094819363138cc18f60e01b83525af180156107875761078c575b5061071c610710610103546001600160a01b031690565b6001600160a01b031690565b6040516323b872dd60e01b81523360048083019190915230602483015235604482015290602090829081600081606481015b03925af180156107875761075e57005b61077e9060203d8111610780575b6107768183611fb0565b810190612633565b005b503d61076c565b6124a4565b8061079961079f92611f7b565b80610382565b386106f9565b604051633c698d7960e01b8152600490fd5b905060fe5416331415386106c9565b3461038d57600036600319011261038d5760206001600160a01b0360655416604051908152f35b3461038d57604036600319011261038d5760043561080a81610501565b336000526034602052610834816040600020906001600160a01b0316600052602052604060002090565b54602435810180911161084b5761053c91336121cc565b611fd2565b3461038d57600036600319011261038d576001600160a01b036020816101045416916065541660246040518094819363b3596f0760e01b835260048301525afa90811561078757610457916108ad916000916108bd575b5061338e565b6040519081529081906020820190565b6108de915060203d81116108e4575b6108d68183611fb0565b810190612d7c565b386108a7565b503d6108cc565b3461038d57600036600319011261038d57610904611e89565b60ca5460ff8116156109435760ff191660ca557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b60405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606490fd5b3461038d57602036600319011261038d5761099b600435610501565b60206103ad6138cd565b3461038d57602036600319011261038d576001600160a01b036004356109ca81610501565b166000526101066020526020604060002054604051908152f35b3461038d57602036600319011261038d5760206103ad600435610a0681610501565b613764565b3461038d57602036600319011261038d57600435610a27611e89565b6127108111610a61576020817f17eb3ea543d479a0358f9f15a48526b973a5b7f30243301da7d83f4720e243c29260fd55604051908152a1005b60405163221d6b1360e01b8152600490fd5b3461038d57600036600319011261038d57602060ff60ca54166040519015158152f35b9181601f8401121561038d5782359167ffffffffffffffff831161038d576020838186019501011161038d57565b3461038d57608036600319011261038d57600435610ae181610501565b67ffffffffffffffff60243581811161038d57610b02903690600401610a96565b60443592831161038d57610b1d610b6c933690600401610a96565b9160643593610b2b85610501565b60005496610b5060ff8960081c16158099819a610bef575b8115610bcf575b506123ab565b87610b63600160ff196000541617600055565b610bb65761264b565b610b7257005b610b8261ff001960005416600055565b604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989080602081015b0390a1005b610bca61010061ff00196000541617600055565b61264b565b303b15915081610be1575b5038610b4a565b6001915060ff161438610bda565b600160ff8216109150610b43565b3461038d57604036600319011261038d57602435600435610c1d82610501565b610c25612d38565b610c2d61398f565b6001600160a01b038060ff5416803b1561038d576000809160046040518094819363138cc18f60e01b83525af1801561078757610d25575b50610c6f826122f9565b918215610cf25761045793610cea92610ca383610c9a6107106107106065546001600160a01b031690565b30903390612e4f565b610cad8583612d8b565b6040805184815260208101879052929091169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791a36132cf565b6108ad613aa5565b60405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f53484152455360a81b6044820152606490fd5b610d2e90611f7b565b38610c65565b3461038d57602036600319011261038d576001600160a01b03600435610d5981610501565b1660005260336020526020604060002054604051908152f35b3461038d576000806003193601126104e057610d8c611e89565b806001600160a01b036098546001600160601b0360a01b8116609855167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b3461038d5760408060031936011261038d57600435610dee81610501565b60243590610dfa611e89565b610e1261071061071060ff546001600160a01b031690565b6001600160a01b0382169081141580610f72575b610f615783518091632578b69f60e21b825281600460209485935afa8015610787578491600091610f44575b501015610f335782610e78836001600160a01b0316600052610106602052604060002090565b55610e8f610710610103546001600160a01b031690565b845163095ea7b360e01b81526001600160a01b03841660048201526024810185905294908290869060449082906000905af1918215610787577f84d2db42497fc6f1882756be420935d982025ad8a2a903dfb83638a09e49a77595610bb193610f15575b50505192839283602090939291936001600160a01b0360408201951681520152565b81610f2b92903d10610780576107768183611fb0565b503880610ef3565b8351633a020d0160e11b8152600490fd5b610f5b9150833d85116108e4576108d68183611fb0565b38610e52565b83516348b905b160e01b8152600490fd5b50610f8b61071061071060fe546001600160a01b031690565b811415610e26565b3461038d57600036600319011261038d5760206103ad6135a1565b3461038d57600036600319011261038d5760206001600160a01b0360fe5416604051908152f35b3461038d57600036600319011261038d57610fee611e89565b610ff6612d38565b600160ff1960ca54161760ca557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a1005b3461038d57602036600319011261038d577f333b26cca69716ad4680ddb07663f5bfb4f06045671f336af9a83690a3ae00f9602060043561106e611e89565b8060fc55604051908152a1005b3461038d57600036600319011261038d576001600160a01b036020816101045416916065541660246040518094819363b3596f0760e01b835260048301525afa90811561078757610457916108ad916000916110e0575b506110db613861565b6133ff565b6110f8915060203d81116108e4576108d68183611fb0565b386110d2565b3461038d57600036600319011261038d5760206001600160a01b0360985416604051908152f35b3461038d57600036600319011261038d576101005461010154604080516001600160801b038085168252608094851c602083015283169181019190915290821c6060820152f35b3461038d576000604080600319360112611318576004359060243561119081610501565b611198612d38565b6111a061398f565b6001600160a01b0392848460ff5416803b15611318578190600486518094819363138cc18f60e01b83525af1801561078757611305575b507fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d76112028261234a565b9461121586826065541630903390612e4f565b61121f8385612d8b565b8451868152602081019390935292909216913391604090a361124882611243613861565b611fe8565b60fc54106112f55782611267610710610102546001600160a01b031690565b6065546001600160a01b031690803b156112f157835163617ba03760e01b81526001600160a01b0392909216600483015260248201859052306044830152600060648301529094859160849183915af192831561078757610457936112de575b506112d0613aa5565b519081529081906020820190565b806107996112eb92611f7b565b386112c7565b8280fd5b516324d758c360e21b8152600490fd5b61131190959195611f7b565b93386111d7565b5080fd5b3461038d576000806003193601126104e057604051908060375461133f81611f2b565b808552916001918083169081156104b65750600114611368576104578561044b81870382611fb0565b9250603783527f42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae5b8284106113ab57505050810160200161044b8261045761043b565b80546020858701810191909152909301928101611390565b3461038d57608036600319011261038d576113dc611e89565b7f37f0489f29f6e60f68be54709fc0686e4fbf0ff44b70be0b5be1eebb17c9953f600435611409816124df565b61010080546001600160801b0319166001600160801b03831617905560243590611432826124df565b61010080546001600160801b0316608084901b6001600160801b031916179055610bb1604435611461816124df565b61010180546001600160801b0319166001600160801b0383161790556064359061148a826124df565b61010180546001600160801b0316608084901b6001600160801b0319161790556114b3846124df565b6114bc856124df565b6114c5816124df565b6114ce826124df565b604080516001600160801b039586168152958516602087015290841690850152909116606083015281906080820190565b3461038d57604036600319011261038d5760043561151c81610501565b6024359033600052603460205261154a816040600020906001600160a01b0316600052602052604060002090565b549180831061155f576105f8920390336121cc565b60405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608490fd5b3461038d57604036600319011261038d5761053c6004356115d281610501565b60243590336120a8565b3461038d57600036600319011261038d5760206001600160a01b0360ff5416604051908152f35b3461038d57602036600319011261038d5760206103ad60043561234a565b606090600319011261038d576004359060243561163d81610501565b9060443561164a81610501565b90565b3461038d5761165b36611621565b906000928391611669612d38565b61167161398f565b6001600160a01b038060ff5416803b1561178657849060046040518099819363138cc18f60e01b83525af19384156107875761045796610cea95611777575b50906116dd6116be8561238c565b878184819a1695863303611739575b50506116d887613203565b61304b565b60408051858152602081018890529184169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db9190819081015b0390a46117346107106107106065546001600160a01b031690565b61317d565b868152603460209081526040918290203360009081529152205460018101156116cd57611770916117699161303e565b33836121cc565b81386116cd565b61178090611f7b565b386116b0565b8480fd5b3461038d5761179836611621565b919060009283916117a7612d38565b6117af61398f565b6001600160a01b038060ff5416803b1561178657849060046040518099819363138cc18f60e01b83525af19384156107875761045796610cea9561189f575b50908581851692833303611861575b5061182161180a8261232c565b9788966118188815156131b6565b6116d888613203565b6040805186815260208101929092529184169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db9181908101611719565b838152603460209081526040918290203360009081529152205460018101156117fd57611898916118919161303e565b33866121cc565b85386117fd565b6118a890611f7b565b386117ee565b3461038d576000806003193601126104e0576118c8611e89565b6118de610710610102546001600160a01b031690565b6118f66107106107106065546001600160a01b031690565b60405163095ea7b360e01b8082526001600160a01b03841660048301526000196024830152602093919290919084908490604490829089905af1918215610787576119879385936119dc575b50611959610710610103546001600160a01b031690565b90866040518096819582948352600483019190916001600160a01b0360408201931681526020600019910152565b03925af18015610787576119be575b827fba5bb3f899c7a3edcc9ff9d46c4e08449c6a608b6f8254132bc5af4898645cbc8180a180f35b816119d492903d10610780576107768183611fb0565b503880611996565b6119f290843d8611610780576107768183611fb0565b5038611942565b3461038d57602036600319011261038d576004356001600160a01b038060ff541690813314159081611ae5575b506107a55781158015611ad4575b611ac257803b1561038d576000809160046040518094819363138cc18f60e01b83525af180156107875760009260209261074e92611aaf575b50611a84610710610103546001600160a01b031690565b60405163a9059cbb60e01b815233600482015260248101929092529093849283919082906044820190565b80610799611abc92611f7b565b38611a6d565b604051630e25379960e21b8152600490fd5b50611ade33613764565b8211611a34565b905060fe541633141538611a26565b3461038d57602036600319011261038d57611b10600435610501565b60206103ad611b1d6138cd565b6122f9565b3461038d57602036600319011261038d5760206103ad6004356122f9565b3461038d576000806003193601126104e0578060206001600160a01b03606481610102541691606554166040519485938492631a4ca37b60e21b84526004840152600019602484015273ee2a909e3382cdf45a0d391202aff3fb11956ad160448401525af1801561078757611bb3575080f35b611bca9060203d81116108e4576108d68183611fb0565b5080f35b3461038d57602036600319011261038d5760206103ad600435611bf081610501565b6138f5565b3461038d57602036600319011261038d577f52d81611b2e2e74037271caa673fe82efa363a106c27d6373566a950d2be73fc60206001600160a01b03600435611c3d81610501565b611c45611e89565b16806001600160601b0360a01b60ff54161760ff55604051908152a1005b3461038d57602036600319011261038d5760206103ad611b1d600435611bf081610501565b3461038d57602036600319011261038d577fbd325305afd7728b65bc6a18a2ad623494a5ee4e3f31aad475ddb77d8e70717b60206001600160a01b03600435611cd081610501565b611cd8611e89565b16806001600160601b0360a01b60fe54161760fe55604051908152a1005b3461038d57600036600319011261038d57602060fc54604051908152f35b3461038d57604036600319011261038d576020611d70600435611d3681610501565b6001600160a01b0360243591611d4b83610501565b16600052603483526040600020906001600160a01b0316600052602052604060002090565b54604051908152f35b3461038d57600036600319011261038d57602460206001600160a01b036101035416604051928380926370a0823160e01b82523060048301525afa90811561078757610457916108ad91600091611dda575b50611dd46135a1565b906136a9565b611df2915060203d81116108e4576108d68183611fb0565b38611dcb565b3461038d57602036600319011261038d57600435611e1581610501565b611e1d611e89565b6001600160a01b03811615611e355761077e90611ee1565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b6001600160a01b03609854163303611e9d57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b609854906001600160a01b0380911691826001600160601b0360a01b821617609855167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b90600182811c92168015611f5b575b6020831014611f4557565b634e487b7160e01b600052602260045260246000fd5b91607f1691611f3a565b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff8111611f8f57604052565b611f65565b6040810190811067ffffffffffffffff821117611f8f57604052565b90601f8019910116810190811067ffffffffffffffff821117611f8f57604052565b634e487b7160e01b600052601160045260246000fd5b9190820180921161084b57565b15611ffc57565b60405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b1561205457565b60405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608490fd5b91906001600160a01b039081841692831561217957612157827fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef946121749416966120f4881515611ff5565b61213d84612115836001600160a01b03166000526033602052604060002090565b546121228282101561204d565b03916001600160a01b03166000526033602052604060002090565b556001600160a01b03166000526033602052604060002090565b612162828254611fe8565b90556040519081529081906020820190565b0390a3565b60405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b906001600160a01b03918281169283156122a857821693841561225857806122477f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259461222f612174956001600160a01b03166000526034602052604060002090565b906001600160a01b0316600052602052604060002090565b556040519081529081906020820190565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b60355480612305575090565b9061164a91612312613861565b915b8181029181830414901517821515161561038d570490565b60355480612338575090565b61164a91612344613861565b90612314565b60355480612356575090565b61164a91612362613861565b905b9190918281029281840414901517811515161561038d57600190600019830104019015150290565b60355480612398575090565b9061164a916123a5613861565b91612364565b156123b257565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b604051906101e0820182811067ffffffffffffffff821117611f8f57604052565b67ffffffffffffffff8111611f8f57601f01601f191660200190565b9291926124578261242f565b916124656040519384611fb0565b82948184528183011161038d578281602093846000960137010152565b519061248d82610501565b565b9081602091031261038d575161164a81610501565b6040513d6000823e3d90fd5b919082602091031261038d576040516020810181811067ffffffffffffffff821117611f8f5760405291518252565b6001600160801b0381160361038d57565b519061248d826124df565b519064ffffffffff8216820361038d57565b519061ffff8216820361038d57565b6101e08183031261038d5761253961253261240e565b92826124b0565b8252612547602082016124f0565b6020830152612558604082016124f0565b6040830152612569606082016124f0565b606083015261257a608082016124f0565b608083015261258b60a082016124f0565b60a083015261259c60c082016124fb565b60c08301526125ad60e0820161250d565b60e08301526101006125c0818301612482565b908301526101206125d2818301612482565b908301526101406125e4818301612482565b908301526101606125f6818301612482565b908301526101806126088183016124f0565b908301526101a061261a8183016124f0565b9083015261262c6101c08092016124f0565b9082015290565b9081602091031261038d5751801515810361038d5790565b9391926126706126789261267f956126616129ef565b612669612a12565b369161244b565b92369161244b565b9083612a33565b610105805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0393841690811782556126b490610710565b92604051809463026b1d5f60e01b825281600460209788935afa90811561078757612705918391600091612972575b50166001600160a01b0361010291166001600160601b0360a01b825416179055565b6127506101029361272061071086546001600160a01b031690565b6040516335ea6a7560e01b81526001600160a01b0390921660048301526101e09283918391829081906024820190565b03915afa908115610787576004946127ac61278c6107106101006127b996610710968d99600092612945575b505001516001600160a01b031690565b6001600160a01b0361010391166001600160601b0360a01b825416179055565b546001600160a01b031690565b604051631f94a27560e31b815293849182905afa80156107875761280192600091612918575b50166001600160a01b0361010491166001600160601b0360a01b825416179055565b612817610710610103546001600160a01b031690565b9061282c61071082546001600160a01b031690565b60405163095ea7b360e01b8082526001600160a01b039290921660048201526000196024820152928490849060449082906000905af1918215610787576128d09385936128fb575b506128a16107106128936107106107106065546001600160a01b031690565b92546001600160a01b031690565b6040519283526001600160a01b0316600483015260001960248301529092839190829060009082906044820190565b03925af18015610787576128e2575050565b816128f892903d10610780576107768183611fb0565b50565b61291190843d8611610780576107768183611fb0565b5038612874565b6129389150853d871161293e575b6129308183611fb0565b81019061248f565b386127df565b503d612926565b6129649250803d1061296b575b61295c8183611fb0565b81019061251c565b388061277c565b503d612952565b6129899150873d891161293e576129308183611fb0565b386126e3565b1561299657565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b612a0960ff60005460081c16612a048161298f565b61298f565b61248d33611ee1565b612a2760ff60005460081c16612a048161298f565b60ff1960ca541660ca55565b909291612a4b60ff60005460081c16612a048161298f565b835167ffffffffffffffff8111611f8f57612a7081612a6b603654611f2b565b612b6c565b602080601f8311600114612ad657509080612aad939261248d9697600092612acb575b50508160011b916000199060031b1c191617603655612c4e565b6001600160a01b03166001600160601b0360a01b6065541617606555565b015190503880612a93565b90601f19831696612b0960366000527f4a11f94e20a93c79f6ec743a1954ec4fc2c08429ae2122118bf234b2185c81b890565b926000905b898210612b54575050918391600193612aad969561248d999a10612b3b575b505050811b01603655612c4e565b015160001960f88460031b161c19169055388080612b2d565b80600185968294968601518155019501930190612b0e565b601f8111612b78575050565b600090603682527f4a11f94e20a93c79f6ec743a1954ec4fc2c08429ae2122118bf234b2185c81b8906020601f850160051c83019410612bd3575b601f0160051c01915b828110612bc857505050565b818155600101612bbc565b9092508290612bb3565b601f8111612be9575050565b600090603782527f42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae906020601f850160051c83019410612c44575b601f0160051c01915b828110612c3957505050565b818155600101612c2d565b9092508290612c24565b90815167ffffffffffffffff8111611f8f57612c7481612c6f603754611f2b565b612bdd565b602080601f8311600114612cb05750819293600092612ca5575b50508160011b916000199060031b1c191617603755565b015190503880612c8e565b90601f19831694612ce360376000527f42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae90565b926000905b878210612d20575050836001959610612d07575b505050811b01603755565b015160001960f88460031b161c19169055388080612cfc565b80600185968294968601518155019501930190612ce8565b60ff60ca5416612d4457565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b9081602091031261038d575190565b906001600160a01b038216918215612e0a576035549082820180921161084b57612dcb916035556001600160a01b03166000526033602052604060002090565b80549082820180921161084b576000927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9260209255604051908152a3565b60405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606490fd5b6040516323b872dd60e01b60208201526001600160a01b039283166024820152929091166044830152606482019290925261248d91612e9b82608481015b03601f198101845283611fb0565b612eff565b15612ea757565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608490fd5b6001600160a01b03169060405190612f1682611f94565b6020928383527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656484840152803b15612f8d5760008281928287612f689796519301915af1612f62612fd2565b90613002565b80519081612f7557505050565b8261248d93612f88938301019101612633565b612ea0565b60405162461bcd60e51b815260048101859052601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b3d15612ffd573d90612fe38261242f565b91612ff16040519384611fb0565b82523d6000602084013e565b606090565b9091901561300e575090565b81511561301e5750805190602001fd5b60405162461bcd60e51b815290819061303a90600483016103b5565b0390fd5b9190820391821161084b57565b6001600160a01b03811690811561312e57613079816001600160a01b03166000526033602052604060002090565b548381106130de57837fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef926130c96000966121749403916001600160a01b03166000526033602052604060002090565b556108ad6130d98260355461303e565b603555565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b60405163a9059cbb60e01b60208201526001600160a01b039092166024830152604482019290925261248d91612e9b8260648101612e8d565b156131bd57565b60405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f41535345545360a81b6044820152606490fd5b8181029291811591840414171561084b57565b61320b6135a1565b61323361322b6132228461321d613861565b61303e565b60fd54906131f0565b612710900490565b106132bd57602061329591613254610710610102546001600160a01b031690565b606554604051631a4ca37b60e21b81526001600160a01b03909116600482015260248101929092523060448301529092839190829060009082906064820190565b03925af18015610787576132a65750565b6128f89060203d81116108e4576108d68183611fb0565b604051635276dbb960e01b8152600490fd5b6132d7613861565b81810180911161084b5760fc5410613375576132ff610710610102546001600160a01b031690565b906133126065546001600160a01b031690565b823b1561038d5760405163617ba03760e01b81526001600160a01b03919091166004820152602481019190915230604482015260006064820181905290918290608490829084905af18015610787576133685750565b8061079961248d92611f7b565b6040516324d758c360e21b8152600490fd5b1561038d57565b600160801b6000198183098260801b918280831092039180830392146133f2576305f5e100908282111561038d577facbe0e98f503f8881186e60dbb7f727bf36b7213ee9f5a78c767074b22e90e21940990828211900360f81b910360081c170290565b50506305f5e10091500490565b90600019818309818302918280831092039180830392146133f2576305f5e100908282111561038d577facbe0e98f503f8881186e60dbb7f727bf36b7213ee9f5a78c767074b22e90e21940990828211900360f81b910360081c170290565b6c0c9f2c9cd04674edea400000009160001983830992808302928380861095039480860395146134e557908291613496868411613387565b0981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505091506134f4821515613387565b0490565b9060001981830981830291828083109203918083039214613560576c0c9f2c9cd04674edea40000000908282111561038d577f7d33c22789773a07feda8b6f0930e26fa397c439f1d5cf4b2eb27d7306d2dc99940990828211900360e21b9103601e1c170290565b50506c0c9f2c9cd04674edea4000000091500490565b909160001983830992808302928380861095039480860395146134e557908291613496868411613387565b6000906135b961071060fe546001600160a01b031690565b6001600160a01b039081811661363d575b506135e061071060ff546001600160a01b031690565b9081166135ea5750565b9160206004929360405193848092632578b69f60e21b82525afa9081156107875761164a9260009261361d575b50611fe8565b61363691925060203d81116108e4576108d68183611fb0565b9038613617565b604051632578b69f60e21b8152919350602090829060049082905afa90811561078757600091613670575b5091386135ca565b613688915060203d81116108e4576108d68183611fb0565b38613668565b9190916001600160801b038080941691160191821161084b57565b8161374c57505060005b610100546001600160801b038082166c0c9f2c9cd04674edea400000009381850394851161084b57818111156137205761164a946136f7613719936136fc9361303e565b61345e565b61371061010154948486169060801c61368e565b9360801c6134f8565b9116611fe8565b61164a94506137439261373c610101546001600160801b031690565b1690613576565b9060801c611fe8565b81810180911161084b5761375f9161345e565b6136b3565b6001600160a01b039061378b816001600160a01b0316600052610106602052604060002090565b549060405190632578b69f60e21b8252816004816020968794165afa90811561078757600091613844575b5081811161383c576137c79161303e565b906137de610710610103546001600160a01b031690565b6040516370a0823160e01b8152306004820152908290829060249082905afa9182156107875760009261381f575b50508082101561381a575090565b905090565b6138359250803d106108e4576108d68183611fb0565b388061380c565b505050600090565b61385b9150833d85116108e4576108d68183611fb0565b386137b6565b602460206001600160a01b036101035416604051928380926370a0823160e01b82523060048301525afa908115610787576000916138af575b506138a36135a1565b810180911161084b5790565b6138c7915060203d81116108e4576108d68183611fb0565b3861389a565b60fc546138d8613861565b6000828210156138ef5750810390811161084b5790565b91505090565b6138fd613861565b6139056135a1565b6127109081810291818304149015171561084b5760fd5490811561397957046000818311156139675750810390811161084b576001600160a01b0390915b16600052603360205261395a60406000205461232c565b908082101561381a575090565b90506001600160a01b03915091613943565b634e487b7160e01b600052601260045260246000fd5b6139a5610710610103546001600160a01b031690565b6139eb6139bd61071060ff546001600160a01b031690565b6040516370a0823160e01b8082526001600160a01b0390921660048201526020928390829081906024820190565b0381875afa918215610787578391600093613a86575b5060405190815230600482015293849060249082905afa908115610787576000937f6398cf9a29f8130777c54d3d2c061f37c691879a0c04755d9e5e6eb66705ee76938593613a67575b505060408051918252602082019290925290819081015b0390a2565b613a7e929350803d106108e4576108d68183611fb0565b903880613a4b565b613a9e919350823d84116108e4576108d68183611fb0565b9138613a01565b613abb610710610103546001600160a01b031690565b613ad36139bd61071060ff546001600160a01b031690565b0381875afa918215610787578391600093613b4e575b5060405190815230600482015293849060249082905afa908115610787576001937f6398cf9a29f8130777c54d3d2c061f37c691879a0c04755d9e5e6eb66705ee7693600093613a675750506040805191825260208201929092529081908101613a62565b613b66919350823d84116108e4576108d68183611fb0565b9138613ae956fea164736f6c6343000812000a
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c806301e1d1141461037d57806306fdde031461037857806307a2d13a14610332578063095ea7b3146103735780630a28a4771461036e57806318160ddd1461036957806323b872dd14610364578063304ea9cb1461035f578063313ce5671461035a578063371fd8e61461035557806338d52e0f14610350578063395093511461034b5780633d672a45146103465780633f4ba83a14610341578063402d267d1461033c5780634a584432146103375780634cdad50614610332578063543bc9841461032d57806356ab92b3146103285780635c975abb14610323578063613d25bb1461031e5780636e553f651461031957806370a0823114610314578063715018a61461030f578063768e66d31461030a57806377c718ae146103055780638224f4e8146103005780638456cb59146102fb57806386651203146102f65780638d315d7b146102f15780638da5cb5b146102ec578063949b22ae146102e757806394bf804d146102e257806395d89b41146102dd578063964f7be2146102d8578063a457c2d7146102d3578063a9059cbb146102ce578063aa88fdc3146102c9578063b3d7f6b9146102c4578063b460af94146102bf578063ba087652146102ba578063bf9571f1146102b5578063c5ebeaec146102b0578063c63d75b6146102ab578063c6e6f5921461027e578063c722328d146102a6578063ce96cb77146102a1578063d026c1231461029c578063d905777e14610297578063db2d9c3a14610292578063dbd5edc71461028d578063dd62ed3e14610288578063e3696edd14610283578063ef8b30f71461027e5763f2fde38b1461027957600080fd5b611df8565b611b22565b611d79565b611d14565b611cf6565b611c88565b611c63565b611bf5565b611bce565b611b40565b611af4565b6119f9565b6118ae565b61178a565b61164d565b611603565b6115dc565b6115b2565b6114ff565b6113c3565b61131c565b61116c565b611125565b6110fe565b61107b565b61102f565b610fd5565b610fae565b610f93565b610dd0565b610d72565b610d34565b610bfd565b610ac4565b610a73565b610a0b565b6109e4565b6104e3565b6109a5565b61097f565b6108eb565b610850565b6107ed565b6107c6565b61069f565b610683565b610665565b610583565b610565565b610547565b610512565b6103fe565b610392565b600091031261038d57565b600080fd5b3461038d57600036600319011261038d5760206103ad613861565b604051908152f35b6020808252825181830181905290939260005b8281106103ea57505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016103c8565b3461038d576000806003193601126104e057604051908060365461042181611f2b565b808552916001918083169081156104b6575060011461045b575b6104578561044b81870382611fb0565b604051918291826103b5565b0390f35b9250603683527f4a11f94e20a93c79f6ec743a1954ec4fc2c08429ae2122118bf234b2185c81b85b82841061049e57505050810160200161044b8261045761043b565b80546020858701810191909152909301928101610483565b8695506104579693506020925061044b94915060ff191682840152151560051b820101929361043b565b80fd5b3461038d57602036600319011261038d5760206103ad60043561232c565b6001600160a01b0381160361038d57565b3461038d57604036600319011261038d5761053c60043561053281610501565b60243590336121cc565b602060405160018152f35b3461038d57602036600319011261038d5760206103ad60043561238c565b3461038d57600036600319011261038d576020603554604051908152f35b3461038d57606036600319011261038d576004356105a081610501565b6024356105ac81610501565b604435906001600160a01b03831660005260346020526105e3336040600020906001600160a01b0316600052602052604060002090565b549260018401610604575b6105f893506120a8565b60405160018152602090f35b8284106106205761061b836105f8950333836121cc565b6105ee565b60405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606490fd5b3461038d57600036600319011261038d57602060fd54604051908152f35b3461038d57600036600319011261038d57602060405160068152f35b3461038d57602036600319011261038d576001600160a01b038060ff5416908133141590816107b7575b506107a557803b1561038d576000809160046040518094819363138cc18f60e01b83525af180156107875761078c575b5061071c610710610103546001600160a01b031690565b6001600160a01b031690565b6040516323b872dd60e01b81523360048083019190915230602483015235604482015290602090829081600081606481015b03925af180156107875761075e57005b61077e9060203d8111610780575b6107768183611fb0565b810190612633565b005b503d61076c565b6124a4565b8061079961079f92611f7b565b80610382565b386106f9565b604051633c698d7960e01b8152600490fd5b905060fe5416331415386106c9565b3461038d57600036600319011261038d5760206001600160a01b0360655416604051908152f35b3461038d57604036600319011261038d5760043561080a81610501565b336000526034602052610834816040600020906001600160a01b0316600052602052604060002090565b54602435810180911161084b5761053c91336121cc565b611fd2565b3461038d57600036600319011261038d576001600160a01b036020816101045416916065541660246040518094819363b3596f0760e01b835260048301525afa90811561078757610457916108ad916000916108bd575b5061338e565b6040519081529081906020820190565b6108de915060203d81116108e4575b6108d68183611fb0565b810190612d7c565b386108a7565b503d6108cc565b3461038d57600036600319011261038d57610904611e89565b60ca5460ff8116156109435760ff191660ca557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b60405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606490fd5b3461038d57602036600319011261038d5761099b600435610501565b60206103ad6138cd565b3461038d57602036600319011261038d576001600160a01b036004356109ca81610501565b166000526101066020526020604060002054604051908152f35b3461038d57602036600319011261038d5760206103ad600435610a0681610501565b613764565b3461038d57602036600319011261038d57600435610a27611e89565b6127108111610a61576020817f17eb3ea543d479a0358f9f15a48526b973a5b7f30243301da7d83f4720e243c29260fd55604051908152a1005b60405163221d6b1360e01b8152600490fd5b3461038d57600036600319011261038d57602060ff60ca54166040519015158152f35b9181601f8401121561038d5782359167ffffffffffffffff831161038d576020838186019501011161038d57565b3461038d57608036600319011261038d57600435610ae181610501565b67ffffffffffffffff60243581811161038d57610b02903690600401610a96565b60443592831161038d57610b1d610b6c933690600401610a96565b9160643593610b2b85610501565b60005496610b5060ff8960081c16158099819a610bef575b8115610bcf575b506123ab565b87610b63600160ff196000541617600055565b610bb65761264b565b610b7257005b610b8261ff001960005416600055565b604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989080602081015b0390a1005b610bca61010061ff00196000541617600055565b61264b565b303b15915081610be1575b5038610b4a565b6001915060ff161438610bda565b600160ff8216109150610b43565b3461038d57604036600319011261038d57602435600435610c1d82610501565b610c25612d38565b610c2d61398f565b6001600160a01b038060ff5416803b1561038d576000809160046040518094819363138cc18f60e01b83525af1801561078757610d25575b50610c6f826122f9565b918215610cf25761045793610cea92610ca383610c9a6107106107106065546001600160a01b031690565b30903390612e4f565b610cad8583612d8b565b6040805184815260208101879052929091169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791a36132cf565b6108ad613aa5565b60405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f53484152455360a81b6044820152606490fd5b610d2e90611f7b565b38610c65565b3461038d57602036600319011261038d576001600160a01b03600435610d5981610501565b1660005260336020526020604060002054604051908152f35b3461038d576000806003193601126104e057610d8c611e89565b806001600160a01b036098546001600160601b0360a01b8116609855167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b3461038d5760408060031936011261038d57600435610dee81610501565b60243590610dfa611e89565b610e1261071061071060ff546001600160a01b031690565b6001600160a01b0382169081141580610f72575b610f615783518091632578b69f60e21b825281600460209485935afa8015610787578491600091610f44575b501015610f335782610e78836001600160a01b0316600052610106602052604060002090565b55610e8f610710610103546001600160a01b031690565b845163095ea7b360e01b81526001600160a01b03841660048201526024810185905294908290869060449082906000905af1918215610787577f84d2db42497fc6f1882756be420935d982025ad8a2a903dfb83638a09e49a77595610bb193610f15575b50505192839283602090939291936001600160a01b0360408201951681520152565b81610f2b92903d10610780576107768183611fb0565b503880610ef3565b8351633a020d0160e11b8152600490fd5b610f5b9150833d85116108e4576108d68183611fb0565b38610e52565b83516348b905b160e01b8152600490fd5b50610f8b61071061071060fe546001600160a01b031690565b811415610e26565b3461038d57600036600319011261038d5760206103ad6135a1565b3461038d57600036600319011261038d5760206001600160a01b0360fe5416604051908152f35b3461038d57600036600319011261038d57610fee611e89565b610ff6612d38565b600160ff1960ca54161760ca557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a1005b3461038d57602036600319011261038d577f333b26cca69716ad4680ddb07663f5bfb4f06045671f336af9a83690a3ae00f9602060043561106e611e89565b8060fc55604051908152a1005b3461038d57600036600319011261038d576001600160a01b036020816101045416916065541660246040518094819363b3596f0760e01b835260048301525afa90811561078757610457916108ad916000916110e0575b506110db613861565b6133ff565b6110f8915060203d81116108e4576108d68183611fb0565b386110d2565b3461038d57600036600319011261038d5760206001600160a01b0360985416604051908152f35b3461038d57600036600319011261038d576101005461010154604080516001600160801b038085168252608094851c602083015283169181019190915290821c6060820152f35b3461038d576000604080600319360112611318576004359060243561119081610501565b611198612d38565b6111a061398f565b6001600160a01b0392848460ff5416803b15611318578190600486518094819363138cc18f60e01b83525af1801561078757611305575b507fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d76112028261234a565b9461121586826065541630903390612e4f565b61121f8385612d8b565b8451868152602081019390935292909216913391604090a361124882611243613861565b611fe8565b60fc54106112f55782611267610710610102546001600160a01b031690565b6065546001600160a01b031690803b156112f157835163617ba03760e01b81526001600160a01b0392909216600483015260248201859052306044830152600060648301529094859160849183915af192831561078757610457936112de575b506112d0613aa5565b519081529081906020820190565b806107996112eb92611f7b565b386112c7565b8280fd5b516324d758c360e21b8152600490fd5b61131190959195611f7b565b93386111d7565b5080fd5b3461038d576000806003193601126104e057604051908060375461133f81611f2b565b808552916001918083169081156104b65750600114611368576104578561044b81870382611fb0565b9250603783527f42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae5b8284106113ab57505050810160200161044b8261045761043b565b80546020858701810191909152909301928101611390565b3461038d57608036600319011261038d576113dc611e89565b7f37f0489f29f6e60f68be54709fc0686e4fbf0ff44b70be0b5be1eebb17c9953f600435611409816124df565b61010080546001600160801b0319166001600160801b03831617905560243590611432826124df565b61010080546001600160801b0316608084901b6001600160801b031916179055610bb1604435611461816124df565b61010180546001600160801b0319166001600160801b0383161790556064359061148a826124df565b61010180546001600160801b0316608084901b6001600160801b0319161790556114b3846124df565b6114bc856124df565b6114c5816124df565b6114ce826124df565b604080516001600160801b039586168152958516602087015290841690850152909116606083015281906080820190565b3461038d57604036600319011261038d5760043561151c81610501565b6024359033600052603460205261154a816040600020906001600160a01b0316600052602052604060002090565b549180831061155f576105f8920390336121cc565b60405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608490fd5b3461038d57604036600319011261038d5761053c6004356115d281610501565b60243590336120a8565b3461038d57600036600319011261038d5760206001600160a01b0360ff5416604051908152f35b3461038d57602036600319011261038d5760206103ad60043561234a565b606090600319011261038d576004359060243561163d81610501565b9060443561164a81610501565b90565b3461038d5761165b36611621565b906000928391611669612d38565b61167161398f565b6001600160a01b038060ff5416803b1561178657849060046040518099819363138cc18f60e01b83525af19384156107875761045796610cea95611777575b50906116dd6116be8561238c565b878184819a1695863303611739575b50506116d887613203565b61304b565b60408051858152602081018890529184169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db9190819081015b0390a46117346107106107106065546001600160a01b031690565b61317d565b868152603460209081526040918290203360009081529152205460018101156116cd57611770916117699161303e565b33836121cc565b81386116cd565b61178090611f7b565b386116b0565b8480fd5b3461038d5761179836611621565b919060009283916117a7612d38565b6117af61398f565b6001600160a01b038060ff5416803b1561178657849060046040518099819363138cc18f60e01b83525af19384156107875761045796610cea9561189f575b50908581851692833303611861575b5061182161180a8261232c565b9788966118188815156131b6565b6116d888613203565b6040805186815260208101929092529184169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db9181908101611719565b838152603460209081526040918290203360009081529152205460018101156117fd57611898916118919161303e565b33866121cc565b85386117fd565b6118a890611f7b565b386117ee565b3461038d576000806003193601126104e0576118c8611e89565b6118de610710610102546001600160a01b031690565b6118f66107106107106065546001600160a01b031690565b60405163095ea7b360e01b8082526001600160a01b03841660048301526000196024830152602093919290919084908490604490829089905af1918215610787576119879385936119dc575b50611959610710610103546001600160a01b031690565b90866040518096819582948352600483019190916001600160a01b0360408201931681526020600019910152565b03925af18015610787576119be575b827fba5bb3f899c7a3edcc9ff9d46c4e08449c6a608b6f8254132bc5af4898645cbc8180a180f35b816119d492903d10610780576107768183611fb0565b503880611996565b6119f290843d8611610780576107768183611fb0565b5038611942565b3461038d57602036600319011261038d576004356001600160a01b038060ff541690813314159081611ae5575b506107a55781158015611ad4575b611ac257803b1561038d576000809160046040518094819363138cc18f60e01b83525af180156107875760009260209261074e92611aaf575b50611a84610710610103546001600160a01b031690565b60405163a9059cbb60e01b815233600482015260248101929092529093849283919082906044820190565b80610799611abc92611f7b565b38611a6d565b604051630e25379960e21b8152600490fd5b50611ade33613764565b8211611a34565b905060fe541633141538611a26565b3461038d57602036600319011261038d57611b10600435610501565b60206103ad611b1d6138cd565b6122f9565b3461038d57602036600319011261038d5760206103ad6004356122f9565b3461038d576000806003193601126104e0578060206001600160a01b03606481610102541691606554166040519485938492631a4ca37b60e21b84526004840152600019602484015273ee2a909e3382cdf45a0d391202aff3fb11956ad160448401525af1801561078757611bb3575080f35b611bca9060203d81116108e4576108d68183611fb0565b5080f35b3461038d57602036600319011261038d5760206103ad600435611bf081610501565b6138f5565b3461038d57602036600319011261038d577f52d81611b2e2e74037271caa673fe82efa363a106c27d6373566a950d2be73fc60206001600160a01b03600435611c3d81610501565b611c45611e89565b16806001600160601b0360a01b60ff54161760ff55604051908152a1005b3461038d57602036600319011261038d5760206103ad611b1d600435611bf081610501565b3461038d57602036600319011261038d577fbd325305afd7728b65bc6a18a2ad623494a5ee4e3f31aad475ddb77d8e70717b60206001600160a01b03600435611cd081610501565b611cd8611e89565b16806001600160601b0360a01b60fe54161760fe55604051908152a1005b3461038d57600036600319011261038d57602060fc54604051908152f35b3461038d57604036600319011261038d576020611d70600435611d3681610501565b6001600160a01b0360243591611d4b83610501565b16600052603483526040600020906001600160a01b0316600052602052604060002090565b54604051908152f35b3461038d57600036600319011261038d57602460206001600160a01b036101035416604051928380926370a0823160e01b82523060048301525afa90811561078757610457916108ad91600091611dda575b50611dd46135a1565b906136a9565b611df2915060203d81116108e4576108d68183611fb0565b38611dcb565b3461038d57602036600319011261038d57600435611e1581610501565b611e1d611e89565b6001600160a01b03811615611e355761077e90611ee1565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b6001600160a01b03609854163303611e9d57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b609854906001600160a01b0380911691826001600160601b0360a01b821617609855167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b90600182811c92168015611f5b575b6020831014611f4557565b634e487b7160e01b600052602260045260246000fd5b91607f1691611f3a565b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff8111611f8f57604052565b611f65565b6040810190811067ffffffffffffffff821117611f8f57604052565b90601f8019910116810190811067ffffffffffffffff821117611f8f57604052565b634e487b7160e01b600052601160045260246000fd5b9190820180921161084b57565b15611ffc57565b60405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b1561205457565b60405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608490fd5b91906001600160a01b039081841692831561217957612157827fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef946121749416966120f4881515611ff5565b61213d84612115836001600160a01b03166000526033602052604060002090565b546121228282101561204d565b03916001600160a01b03166000526033602052604060002090565b556001600160a01b03166000526033602052604060002090565b612162828254611fe8565b90556040519081529081906020820190565b0390a3565b60405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b906001600160a01b03918281169283156122a857821693841561225857806122477f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259461222f612174956001600160a01b03166000526034602052604060002090565b906001600160a01b0316600052602052604060002090565b556040519081529081906020820190565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b60355480612305575090565b9061164a91612312613861565b915b8181029181830414901517821515161561038d570490565b60355480612338575090565b61164a91612344613861565b90612314565b60355480612356575090565b61164a91612362613861565b905b9190918281029281840414901517811515161561038d57600190600019830104019015150290565b60355480612398575090565b9061164a916123a5613861565b91612364565b156123b257565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b604051906101e0820182811067ffffffffffffffff821117611f8f57604052565b67ffffffffffffffff8111611f8f57601f01601f191660200190565b9291926124578261242f565b916124656040519384611fb0565b82948184528183011161038d578281602093846000960137010152565b519061248d82610501565b565b9081602091031261038d575161164a81610501565b6040513d6000823e3d90fd5b919082602091031261038d576040516020810181811067ffffffffffffffff821117611f8f5760405291518252565b6001600160801b0381160361038d57565b519061248d826124df565b519064ffffffffff8216820361038d57565b519061ffff8216820361038d57565b6101e08183031261038d5761253961253261240e565b92826124b0565b8252612547602082016124f0565b6020830152612558604082016124f0565b6040830152612569606082016124f0565b606083015261257a608082016124f0565b608083015261258b60a082016124f0565b60a083015261259c60c082016124fb565b60c08301526125ad60e0820161250d565b60e08301526101006125c0818301612482565b908301526101206125d2818301612482565b908301526101406125e4818301612482565b908301526101606125f6818301612482565b908301526101806126088183016124f0565b908301526101a061261a8183016124f0565b9083015261262c6101c08092016124f0565b9082015290565b9081602091031261038d5751801515810361038d5790565b9391926126706126789261267f956126616129ef565b612669612a12565b369161244b565b92369161244b565b9083612a33565b610105805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0393841690811782556126b490610710565b92604051809463026b1d5f60e01b825281600460209788935afa90811561078757612705918391600091612972575b50166001600160a01b0361010291166001600160601b0360a01b825416179055565b6127506101029361272061071086546001600160a01b031690565b6040516335ea6a7560e01b81526001600160a01b0390921660048301526101e09283918391829081906024820190565b03915afa908115610787576004946127ac61278c6107106101006127b996610710968d99600092612945575b505001516001600160a01b031690565b6001600160a01b0361010391166001600160601b0360a01b825416179055565b546001600160a01b031690565b604051631f94a27560e31b815293849182905afa80156107875761280192600091612918575b50166001600160a01b0361010491166001600160601b0360a01b825416179055565b612817610710610103546001600160a01b031690565b9061282c61071082546001600160a01b031690565b60405163095ea7b360e01b8082526001600160a01b039290921660048201526000196024820152928490849060449082906000905af1918215610787576128d09385936128fb575b506128a16107106128936107106107106065546001600160a01b031690565b92546001600160a01b031690565b6040519283526001600160a01b0316600483015260001960248301529092839190829060009082906044820190565b03925af18015610787576128e2575050565b816128f892903d10610780576107768183611fb0565b50565b61291190843d8611610780576107768183611fb0565b5038612874565b6129389150853d871161293e575b6129308183611fb0565b81019061248f565b386127df565b503d612926565b6129649250803d1061296b575b61295c8183611fb0565b81019061251c565b388061277c565b503d612952565b6129899150873d891161293e576129308183611fb0565b386126e3565b1561299657565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b612a0960ff60005460081c16612a048161298f565b61298f565b61248d33611ee1565b612a2760ff60005460081c16612a048161298f565b60ff1960ca541660ca55565b909291612a4b60ff60005460081c16612a048161298f565b835167ffffffffffffffff8111611f8f57612a7081612a6b603654611f2b565b612b6c565b602080601f8311600114612ad657509080612aad939261248d9697600092612acb575b50508160011b916000199060031b1c191617603655612c4e565b6001600160a01b03166001600160601b0360a01b6065541617606555565b015190503880612a93565b90601f19831696612b0960366000527f4a11f94e20a93c79f6ec743a1954ec4fc2c08429ae2122118bf234b2185c81b890565b926000905b898210612b54575050918391600193612aad969561248d999a10612b3b575b505050811b01603655612c4e565b015160001960f88460031b161c19169055388080612b2d565b80600185968294968601518155019501930190612b0e565b601f8111612b78575050565b600090603682527f4a11f94e20a93c79f6ec743a1954ec4fc2c08429ae2122118bf234b2185c81b8906020601f850160051c83019410612bd3575b601f0160051c01915b828110612bc857505050565b818155600101612bbc565b9092508290612bb3565b601f8111612be9575050565b600090603782527f42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae906020601f850160051c83019410612c44575b601f0160051c01915b828110612c3957505050565b818155600101612c2d565b9092508290612c24565b90815167ffffffffffffffff8111611f8f57612c7481612c6f603754611f2b565b612bdd565b602080601f8311600114612cb05750819293600092612ca5575b50508160011b916000199060031b1c191617603755565b015190503880612c8e565b90601f19831694612ce360376000527f42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae90565b926000905b878210612d20575050836001959610612d07575b505050811b01603755565b015160001960f88460031b161c19169055388080612cfc565b80600185968294968601518155019501930190612ce8565b60ff60ca5416612d4457565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b9081602091031261038d575190565b906001600160a01b038216918215612e0a576035549082820180921161084b57612dcb916035556001600160a01b03166000526033602052604060002090565b80549082820180921161084b576000927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9260209255604051908152a3565b60405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606490fd5b6040516323b872dd60e01b60208201526001600160a01b039283166024820152929091166044830152606482019290925261248d91612e9b82608481015b03601f198101845283611fb0565b612eff565b15612ea757565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608490fd5b6001600160a01b03169060405190612f1682611f94565b6020928383527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656484840152803b15612f8d5760008281928287612f689796519301915af1612f62612fd2565b90613002565b80519081612f7557505050565b8261248d93612f88938301019101612633565b612ea0565b60405162461bcd60e51b815260048101859052601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b3d15612ffd573d90612fe38261242f565b91612ff16040519384611fb0565b82523d6000602084013e565b606090565b9091901561300e575090565b81511561301e5750805190602001fd5b60405162461bcd60e51b815290819061303a90600483016103b5565b0390fd5b9190820391821161084b57565b6001600160a01b03811690811561312e57613079816001600160a01b03166000526033602052604060002090565b548381106130de57837fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef926130c96000966121749403916001600160a01b03166000526033602052604060002090565b556108ad6130d98260355461303e565b603555565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b60405163a9059cbb60e01b60208201526001600160a01b039092166024830152604482019290925261248d91612e9b8260648101612e8d565b156131bd57565b60405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f41535345545360a81b6044820152606490fd5b8181029291811591840414171561084b57565b61320b6135a1565b61323361322b6132228461321d613861565b61303e565b60fd54906131f0565b612710900490565b106132bd57602061329591613254610710610102546001600160a01b031690565b606554604051631a4ca37b60e21b81526001600160a01b03909116600482015260248101929092523060448301529092839190829060009082906064820190565b03925af18015610787576132a65750565b6128f89060203d81116108e4576108d68183611fb0565b604051635276dbb960e01b8152600490fd5b6132d7613861565b81810180911161084b5760fc5410613375576132ff610710610102546001600160a01b031690565b906133126065546001600160a01b031690565b823b1561038d5760405163617ba03760e01b81526001600160a01b03919091166004820152602481019190915230604482015260006064820181905290918290608490829084905af18015610787576133685750565b8061079961248d92611f7b565b6040516324d758c360e21b8152600490fd5b1561038d57565b600160801b6000198183098260801b918280831092039180830392146133f2576305f5e100908282111561038d577facbe0e98f503f8881186e60dbb7f727bf36b7213ee9f5a78c767074b22e90e21940990828211900360f81b910360081c170290565b50506305f5e10091500490565b90600019818309818302918280831092039180830392146133f2576305f5e100908282111561038d577facbe0e98f503f8881186e60dbb7f727bf36b7213ee9f5a78c767074b22e90e21940990828211900360f81b910360081c170290565b6c0c9f2c9cd04674edea400000009160001983830992808302928380861095039480860395146134e557908291613496868411613387565b0981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505091506134f4821515613387565b0490565b9060001981830981830291828083109203918083039214613560576c0c9f2c9cd04674edea40000000908282111561038d577f7d33c22789773a07feda8b6f0930e26fa397c439f1d5cf4b2eb27d7306d2dc99940990828211900360e21b9103601e1c170290565b50506c0c9f2c9cd04674edea4000000091500490565b909160001983830992808302928380861095039480860395146134e557908291613496868411613387565b6000906135b961071060fe546001600160a01b031690565b6001600160a01b039081811661363d575b506135e061071060ff546001600160a01b031690565b9081166135ea5750565b9160206004929360405193848092632578b69f60e21b82525afa9081156107875761164a9260009261361d575b50611fe8565b61363691925060203d81116108e4576108d68183611fb0565b9038613617565b604051632578b69f60e21b8152919350602090829060049082905afa90811561078757600091613670575b5091386135ca565b613688915060203d81116108e4576108d68183611fb0565b38613668565b9190916001600160801b038080941691160191821161084b57565b8161374c57505060005b610100546001600160801b038082166c0c9f2c9cd04674edea400000009381850394851161084b57818111156137205761164a946136f7613719936136fc9361303e565b61345e565b61371061010154948486169060801c61368e565b9360801c6134f8565b9116611fe8565b61164a94506137439261373c610101546001600160801b031690565b1690613576565b9060801c611fe8565b81810180911161084b5761375f9161345e565b6136b3565b6001600160a01b039061378b816001600160a01b0316600052610106602052604060002090565b549060405190632578b69f60e21b8252816004816020968794165afa90811561078757600091613844575b5081811161383c576137c79161303e565b906137de610710610103546001600160a01b031690565b6040516370a0823160e01b8152306004820152908290829060249082905afa9182156107875760009261381f575b50508082101561381a575090565b905090565b6138359250803d106108e4576108d68183611fb0565b388061380c565b505050600090565b61385b9150833d85116108e4576108d68183611fb0565b386137b6565b602460206001600160a01b036101035416604051928380926370a0823160e01b82523060048301525afa908115610787576000916138af575b506138a36135a1565b810180911161084b5790565b6138c7915060203d81116108e4576108d68183611fb0565b3861389a565b60fc546138d8613861565b6000828210156138ef5750810390811161084b5790565b91505090565b6138fd613861565b6139056135a1565b6127109081810291818304149015171561084b5760fd5490811561397957046000818311156139675750810390811161084b576001600160a01b0390915b16600052603360205261395a60406000205461232c565b908082101561381a575090565b90506001600160a01b03915091613943565b634e487b7160e01b600052601260045260246000fd5b6139a5610710610103546001600160a01b031690565b6139eb6139bd61071060ff546001600160a01b031690565b6040516370a0823160e01b8082526001600160a01b0390921660048201526020928390829081906024820190565b0381875afa918215610787578391600093613a86575b5060405190815230600482015293849060249082905afa908115610787576000937f6398cf9a29f8130777c54d3d2c061f37c691879a0c04755d9e5e6eb66705ee76938593613a67575b505060408051918252602082019290925290819081015b0390a2565b613a7e929350803d106108e4576108d68183611fb0565b903880613a4b565b613a9e919350823d84116108e4576108d68183611fb0565b9138613a01565b613abb610710610103546001600160a01b031690565b613ad36139bd61071060ff546001600160a01b031690565b0381875afa918215610787578391600093613b4e575b5060405190815230600482015293849060249082905afa908115610787576001937f6398cf9a29f8130777c54d3d2c061f37c691879a0c04755d9e5e6eb66705ee7693600093613a675750506040805191825260208201929092529081908101613a62565b613b66919350823d84116108e4576108d68183611fb0565b9138613ae956fea164736f6c6343000812000a
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.