Source Code
More Info
Private Name Tags
ContractCreator
TokenTracker
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 23529165 | 178 days ago | Contract Creation | 0 FRAX |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
StaticATokenLM
Compiler Version
v0.8.24+commit.e11b9ed9
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// --- DLend fork imports ---
import {IPool} from "contracts/lending/core/interfaces/IPool.sol";
import {DataTypes} from "contracts/lending/core/protocol/libraries/types/DataTypes.sol";
import {ReserveConfiguration} from "contracts/lending/core/protocol/libraries/configuration/ReserveConfiguration.sol";
import {IScaledBalanceToken} from "contracts/lending/core/interfaces/IScaledBalanceToken.sol";
import {IRewardsController} from "contracts/lending/periphery/rewards/interfaces/IRewardsController.sol";
import {WadRayMath} from "contracts/lending/core/protocol/libraries/math/WadRayMath.sol";
import {MathUtils} from "contracts/lending/core/protocol/libraries/math/MathUtils.sol";
import {SafeCast} from "contracts/lending/core/dependencies/openzeppelin/contracts/SafeCast.sol";
import {Initializable} from "contracts/lending/core/dependencies/openzeppelin/upgradeability/Initializable.sol";
import {SafeERC20} from "@openzeppelin/contracts-5/token/ERC20/utils/SafeERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts-5/token/ERC20/extensions/IERC20Metadata.sol";
import {IERC20} from "@openzeppelin/contracts-5/token/ERC20/IERC20.sol";
import {IERC20WithPermit} from "contracts/lending/core/interfaces/IERC20WithPermit.sol";
// --- Local imports ---
import {IStaticATokenLM} from "./interfaces/IStaticATokenLM.sol";
import {IAToken} from "./interfaces/IAToken.sol";
import {ERC20} from "./ERC20.sol";
import {StaticATokenErrors} from "./StaticATokenErrors.sol";
import {RayMathExplicitRounding, Rounding} from "./RayMathExplicitRounding.sol";
import {IERC4626} from "./interfaces/IERC4626.sol";
import {ECDSA} from "./ECDSA.sol";
/**
* @title StaticATokenLM
* @notice Wrapper smart contract that allows to deposit tokens on the Aave protocol and receive
* a token which balance doesn't increase automatically, but uses an ever-increasing exchange rate.
* It supports claiming liquidity mining rewards from the Aave system.
* @author BGD labs
*/
contract StaticATokenLM is ERC20, IStaticATokenLM, IERC4626 {
using SafeERC20 for IERC20;
using SafeCast for uint256;
using WadRayMath for uint256;
using RayMathExplicitRounding for uint256;
bytes32 public constant METADEPOSIT_TYPEHASH =
keccak256(
"Deposit(address depositor,address receiver,uint256 assets,uint16 referralCode,bool depositToAave,uint256 nonce,uint256 deadline,PermitParams permit)"
);
bytes32 public constant METAWITHDRAWAL_TYPEHASH =
keccak256(
"Withdraw(address owner,address receiver,uint256 shares,uint256 assets,bool withdrawFromAave,uint256 nonce,uint256 deadline)"
);
uint256 public constant STATIC__ATOKEN_LM_REVISION = 2;
IPool public immutable POOL;
IRewardsController public immutable REWARDS_CONTROLLER;
IERC20 internal _aToken;
address internal _aTokenUnderlying;
address[] internal _rewardTokens;
mapping(address => RewardIndexCache) internal _startIndex;
mapping(address => mapping(address => UserRewardsData))
internal _userRewardsData;
constructor(
IPool pool,
IRewardsController rewardsController,
address newAToken,
string memory staticATokenName,
string memory staticATokenSymbol
)
ERC20(
staticATokenName,
staticATokenSymbol,
IERC20Metadata(newAToken).decimals()
)
{
POOL = pool;
REWARDS_CONTROLLER = rewardsController;
_aToken = IERC20(newAToken);
_aTokenUnderlying = IAToken(newAToken).UNDERLYING_ASSET_ADDRESS();
// Use standard approve for trusted protocol token (aToken underlying) and trusted protocol contract (dLEND POOL)
IERC20(_aTokenUnderlying).approve(address(POOL), type(uint256).max);
if (address(REWARDS_CONTROLLER) != address(0)) {
refreshRewardTokens();
}
}
///@inheritdoc IStaticATokenLM
function refreshRewardTokens() public override {
address[] memory rewards = REWARDS_CONTROLLER.getRewardsByAsset(
address(_aToken)
);
for (uint256 i = 0; i < rewards.length; i++) {
_registerRewardToken(rewards[i]);
}
}
///@inheritdoc IStaticATokenLM
function isRegisteredRewardToken(
address reward
) public view override returns (bool) {
return _startIndex[reward].isRegistered;
}
///@inheritdoc IStaticATokenLM
function metaDeposit(
address depositor,
address receiver,
uint256 assets,
uint16 referralCode,
bool depositToAave,
uint256 deadline,
PermitParams calldata permit,
SignatureParams calldata sigParams
) external returns (uint256) {
require(depositor != address(0), StaticATokenErrors.INVALID_DEPOSITOR);
//solium-disable-next-line
require(
deadline >= block.timestamp,
StaticATokenErrors.INVALID_EXPIRATION
);
uint256 nonce = nonces[depositor];
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
METADEPOSIT_TYPEHASH,
depositor,
receiver,
assets,
referralCode,
depositToAave,
nonce,
deadline,
permit
)
)
)
);
nonces[depositor] = nonce + 1;
require(
depositor ==
ECDSA.recover(
digest,
sigParams.v,
sigParams.r,
sigParams.s
),
StaticATokenErrors.INVALID_SIGNATURE
);
}
// assume if deadline 0 no permit was supplied
if (permit.deadline != 0) {
try
IERC20WithPermit(
depositToAave
? address(_aTokenUnderlying)
: address(_aToken)
).permit(
depositor,
address(this),
permit.value,
permit.deadline,
permit.v,
permit.r,
permit.s
)
{} catch {}
}
(uint256 shares, ) = _deposit(
depositor,
receiver,
0,
assets,
referralCode,
depositToAave
);
return shares;
}
///@inheritdoc IStaticATokenLM
function metaWithdraw(
address owner,
address receiver,
uint256 shares,
uint256 assets,
bool withdrawFromAave,
uint256 deadline,
SignatureParams calldata sigParams
) external returns (uint256, uint256) {
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
//solium-disable-next-line
require(
deadline >= block.timestamp,
StaticATokenErrors.INVALID_EXPIRATION
);
uint256 nonce = nonces[owner];
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
METAWITHDRAWAL_TYPEHASH,
owner,
receiver,
shares,
assets,
withdrawFromAave,
nonce,
deadline
)
)
)
);
nonces[owner] = nonce + 1;
require(
owner ==
ECDSA.recover(
digest,
sigParams.v,
sigParams.r,
sigParams.s
),
StaticATokenErrors.INVALID_SIGNATURE
);
}
return _withdraw(owner, receiver, shares, assets, withdrawFromAave);
}
///@inheritdoc IERC4626
function previewRedeem(
uint256 shares
) public view virtual returns (uint256) {
return _convertToAssets(shares, Rounding.DOWN);
}
///@inheritdoc IERC4626
function previewMint(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Rounding.UP);
}
///@inheritdoc IERC4626
function previewWithdraw(
uint256 assets
) public view virtual returns (uint256) {
return _convertToShares(assets, Rounding.UP);
}
///@inheritdoc IERC4626
function previewDeposit(
uint256 assets
) public view virtual returns (uint256) {
return _convertToShares(assets, Rounding.DOWN);
}
///@inheritdoc IStaticATokenLM
function rate() public view returns (uint256) {
return POOL.getReserveNormalizedIncome(_aTokenUnderlying);
}
///@inheritdoc IStaticATokenLM
function collectAndUpdateRewards(address reward) public returns (uint256) {
if (reward == address(0)) {
return 0;
}
address[] memory assets = new address[](1);
assets[0] = address(_aToken);
return
REWARDS_CONTROLLER.claimRewards(
assets,
type(uint256).max,
address(this),
reward
);
}
///@inheritdoc IStaticATokenLM
function claimRewardsOnBehalf(
address onBehalfOf,
address receiver,
address[] memory rewards
) external {
require(
msg.sender == onBehalfOf ||
msg.sender == REWARDS_CONTROLLER.getClaimer(onBehalfOf),
StaticATokenErrors.INVALID_CLAIMER
);
_claimRewardsOnBehalf(onBehalfOf, receiver, rewards);
}
///@inheritdoc IStaticATokenLM
function claimRewards(address receiver, address[] memory rewards) external {
_claimRewardsOnBehalf(msg.sender, receiver, rewards);
}
///@inheritdoc IStaticATokenLM
function claimRewardsToSelf(address[] memory rewards) external {
_claimRewardsOnBehalf(msg.sender, msg.sender, rewards);
}
///@inheritdoc IStaticATokenLM
function getCurrentRewardsIndex(
address reward
) public view returns (uint256) {
if (address(reward) == address(0)) {
return 0;
}
(, uint256 nextIndex) = REWARDS_CONTROLLER.getAssetIndex(
address(_aToken),
reward
);
return nextIndex;
}
///@inheritdoc IStaticATokenLM
function getTotalClaimableRewards(
address reward
) external view returns (uint256) {
if (reward == address(0)) {
return 0;
}
address[] memory assets = new address[](1);
assets[0] = address(_aToken);
uint256 freshRewards = REWARDS_CONTROLLER.getUserRewards(
assets,
address(this),
reward
);
return IERC20(reward).balanceOf(address(this)) + freshRewards;
}
///@inheritdoc IStaticATokenLM
function getClaimableRewards(
address user,
address reward
) external view returns (uint256) {
return
_getClaimableRewards(
user,
reward,
balanceOf[user],
getCurrentRewardsIndex(reward)
);
}
///@inheritdoc IStaticATokenLM
function getUnclaimedRewards(
address user,
address reward
) external view returns (uint256) {
return _userRewardsData[user][reward].unclaimedRewards;
}
///@inheritdoc IERC4626
function asset() external view returns (address) {
return address(_aTokenUnderlying);
}
///@inheritdoc IStaticATokenLM
function aToken() external view returns (IERC20) {
return _aToken;
}
///@inheritdoc IStaticATokenLM
function rewardTokens() external view returns (address[] memory) {
return _rewardTokens;
}
///@inheritdoc IERC4626
function totalAssets() external view returns (uint256) {
return _aToken.balanceOf(address(this));
}
///@inheritdoc IERC4626
function convertToShares(uint256 assets) external view returns (uint256) {
return _convertToShares(assets, Rounding.DOWN);
}
///@inheritdoc IERC4626
function convertToAssets(uint256 shares) external view returns (uint256) {
return _convertToAssets(shares, Rounding.DOWN);
}
///@inheritdoc IERC4626
function maxMint(address) public view virtual returns (uint256) {
uint256 assets = maxDeposit(address(0));
if (assets == type(uint256).max) return type(uint256).max;
return _convertToShares(assets, Rounding.DOWN);
}
///@inheritdoc IERC4626
function maxWithdraw(address owner) public view virtual returns (uint256) {
uint256 shares = maxRedeem(owner);
return _convertToAssets(shares, Rounding.DOWN);
}
///@inheritdoc IERC4626
function maxRedeem(address owner) public view virtual returns (uint256) {
address cachedATokenUnderlying = _aTokenUnderlying;
DataTypes.ReserveData memory reserveData = POOL.getReserveData(
cachedATokenUnderlying
);
// if paused or inactive users cannot withdraw underlying
if (
!ReserveConfiguration.getActive(reserveData.configuration) ||
ReserveConfiguration.getPaused(reserveData.configuration)
) {
return 0;
}
// otherwise users can withdraw up to the available amount
uint256 underlyingTokenBalanceInShares = _convertToShares(
IERC20(cachedATokenUnderlying).balanceOf(reserveData.aTokenAddress),
Rounding.DOWN
);
uint256 cachedUserBalance = balanceOf[owner];
return
underlyingTokenBalanceInShares >= cachedUserBalance
? cachedUserBalance
: underlyingTokenBalanceInShares;
}
///@inheritdoc IERC4626
function maxDeposit(address) public view virtual returns (uint256) {
DataTypes.ReserveData memory reserveData = POOL.getReserveData(
_aTokenUnderlying
);
// if inactive, paused or frozen users cannot deposit underlying
if (
!ReserveConfiguration.getActive(reserveData.configuration) ||
ReserveConfiguration.getPaused(reserveData.configuration) ||
ReserveConfiguration.getFrozen(reserveData.configuration)
) {
return 0;
}
uint256 supplyCap = ReserveConfiguration.getSupplyCap(
reserveData.configuration
) * (10 ** ReserveConfiguration.getDecimals(reserveData.configuration));
// if no supply cap deposit is unlimited
if (supplyCap == 0) return type(uint256).max;
// return remaining supply cap margin
uint256 currentSupply = (IAToken(reserveData.aTokenAddress)
.scaledTotalSupply() + reserveData.accruedToTreasury).rayMulRoundUp(
_getNormalizedIncome(reserveData)
);
return currentSupply > supplyCap ? 0 : supplyCap - currentSupply;
}
///@inheritdoc IERC4626
function deposit(
uint256 assets,
address receiver
) external virtual returns (uint256) {
(uint256 shares, ) = _deposit(msg.sender, receiver, 0, assets, 0, true);
return shares;
}
///@inheritdoc IERC4626
function mint(
uint256 shares,
address receiver
) external virtual returns (uint256) {
(, uint256 assets) = _deposit(msg.sender, receiver, shares, 0, 0, true);
return assets;
}
///@inheritdoc IERC4626
function withdraw(
uint256 assets,
address receiver,
address owner
) external virtual returns (uint256) {
(uint256 shares, ) = _withdraw(owner, receiver, 0, assets, true);
return shares;
}
///@inheritdoc IERC4626
function redeem(
uint256 shares,
address receiver,
address owner
) external virtual returns (uint256) {
(, uint256 assets) = _withdraw(owner, receiver, shares, 0, true);
return assets;
}
/// @notice Deposit aTokens and mint static tokens to receiver
function depositATokens(
uint256 aTokenAmount,
address receiver
) external override returns (uint256) {
require(aTokenAmount > 0, StaticATokenErrors.INVALID_ZERO_AMOUNT);
// allow compensation for rebase during tx
uint256 userBalance = _aToken.balanceOf(msg.sender);
uint256 amount = aTokenAmount > userBalance
? userBalance
: aTokenAmount;
// determine shares to mint
uint256 shares = previewDeposit(amount);
require(shares != 0, StaticATokenErrors.INVALID_ZERO_AMOUNT);
// transfer aTokens in
_aToken.safeTransferFrom(msg.sender, address(this), amount);
// mint static tokens
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, amount, shares);
return shares;
}
/// @notice Burn static tokens and return aTokens to receiver
function redeemATokens(
uint256 shares,
address receiver,
address owner
) external override returns (uint256) {
require(shares > 0, StaticATokenErrors.INVALID_ZERO_AMOUNT);
// determine assets to return
uint256 assets = previewRedeem(shares);
require(assets != 0, StaticATokenErrors.INVALID_ZERO_AMOUNT);
// handle allowance if not owner
if (msg.sender != owner) {
uint256 allowed = allowance[owner][msg.sender];
if (allowed != type(uint256).max) {
allowance[owner][msg.sender] = allowed - shares;
}
}
// burn static tokens
_burn(owner, shares);
emit Withdraw(msg.sender, receiver, owner, assets, shares);
// transfer aTokens out
_aToken.safeTransfer(receiver, assets);
return assets;
}
function _deposit(
address depositor,
address receiver,
uint256 _shares,
uint256 _assets,
uint16 referralCode,
bool depositToAave
) internal returns (uint256, uint256) {
require(receiver != address(0), StaticATokenErrors.INVALID_RECIPIENT);
require(
_shares == 0 || _assets == 0,
StaticATokenErrors.ONLY_ONE_AMOUNT_FORMAT_ALLOWED
);
uint256 assets = _assets;
uint256 shares = _shares;
if (shares > 0) {
if (depositToAave) {
require(
shares <= maxMint(receiver),
"ERC4626: mint more than max"
);
}
assets = previewMint(shares);
} else {
if (depositToAave) {
require(
assets <= maxDeposit(receiver),
"ERC4626: deposit more than max"
);
}
shares = previewDeposit(assets);
}
require(shares != 0, StaticATokenErrors.INVALID_ZERO_AMOUNT);
if (depositToAave) {
address cachedATokenUnderlying = _aTokenUnderlying;
SafeERC20.safeTransferFrom(
IERC20(cachedATokenUnderlying),
depositor,
address(this),
assets
);
POOL.deposit(
cachedATokenUnderlying,
assets,
address(this),
referralCode
);
} else {
_aToken.safeTransferFrom(depositor, address(this), assets);
}
_mint(receiver, shares);
emit Deposit(depositor, receiver, assets, shares);
return (shares, assets);
}
function _withdraw(
address owner,
address receiver,
uint256 _shares,
uint256 _assets,
bool withdrawFromAave
) internal returns (uint256, uint256) {
require(receiver != address(0), StaticATokenErrors.INVALID_RECIPIENT);
require(
_shares == 0 || _assets == 0,
StaticATokenErrors.ONLY_ONE_AMOUNT_FORMAT_ALLOWED
);
require(_shares != _assets, StaticATokenErrors.INVALID_ZERO_AMOUNT);
uint256 assets = _assets;
uint256 shares = _shares;
if (shares > 0) {
if (withdrawFromAave) {
require(
shares <= maxRedeem(owner),
"ERC4626: redeem more than max"
);
}
assets = previewRedeem(shares);
} else {
if (withdrawFromAave) {
require(
assets <= maxWithdraw(owner),
"ERC4626: withdraw more than max"
);
}
shares = previewWithdraw(assets);
}
if (msg.sender != owner) {
uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max)
allowance[owner][msg.sender] = allowed - shares;
}
_burn(owner, shares);
emit Withdraw(msg.sender, receiver, owner, assets, shares);
if (withdrawFromAave) {
POOL.withdraw(_aTokenUnderlying, assets, receiver);
} else {
_aToken.safeTransfer(receiver, assets);
}
return (shares, assets);
}
/**
* @notice Updates rewards for senders and receiver in a transfer (not updating rewards for address(0))
* @param from The address of the sender of tokens
* @param to The address of the receiver of tokens
*/
function _beforeTokenTransfer(
address from,
address to,
uint256
) internal override {
for (uint256 i = 0; i < _rewardTokens.length; i++) {
address rewardToken = address(_rewardTokens[i]);
uint256 rewardsIndex = getCurrentRewardsIndex(rewardToken);
if (from != address(0)) {
_updateUser(from, rewardsIndex, rewardToken);
}
if (to != address(0) && from != to) {
_updateUser(to, rewardsIndex, rewardToken);
}
}
}
/**
* @notice Adding the pending rewards to the unclaimed for specific user and updating user index
* @param user The address of the user to update
* @param currentRewardsIndex The current rewardIndex
* @param rewardToken The address of the reward token
*/
function _updateUser(
address user,
uint256 currentRewardsIndex,
address rewardToken
) internal {
uint256 balance = balanceOf[user];
if (balance > 0) {
_userRewardsData[user][rewardToken]
.unclaimedRewards = _getClaimableRewards(
user,
rewardToken,
balance,
currentRewardsIndex
).toUint128();
}
_userRewardsData[user][rewardToken]
.rewardsIndexOnLastInteraction = currentRewardsIndex.toUint128();
}
/**
* @notice Compute the pending in WAD. Pending is the amount to add (not yet unclaimed) rewards in WAD.
* @param balance The balance of the user
* @param rewardsIndexOnLastInteraction The index which was on the last interaction of the user
* @param currentRewardsIndex The current rewards index in the system
* @param assetUnit One unit of asset (10**decimals)
* @return The amount of pending rewards in WAD
*/
function _getPendingRewards(
uint256 balance,
uint256 rewardsIndexOnLastInteraction,
uint256 currentRewardsIndex,
uint256 assetUnit
) internal pure returns (uint256) {
if (balance == 0) {
return 0;
}
return
(balance * (currentRewardsIndex - rewardsIndexOnLastInteraction)) /
assetUnit;
}
/**
* @notice Compute the claimable rewards for a user
* @param user The address of the user
* @param reward The address of the reward
* @param balance The balance of the user in WAD
* @param currentRewardsIndex The current rewards index
* @return The total rewards that can be claimed by the user (if `fresh` flag true, after updating rewards)
*/
function _getClaimableRewards(
address user,
address reward,
uint256 balance,
uint256 currentRewardsIndex
) internal view returns (uint256) {
RewardIndexCache memory rewardsIndexCache = _startIndex[reward];
require(
rewardsIndexCache.isRegistered == true,
StaticATokenErrors.REWARD_NOT_INITIALIZED
);
UserRewardsData memory currentUserRewardsData = _userRewardsData[user][
reward
];
uint256 assetUnit = 10 ** decimals;
return
currentUserRewardsData.unclaimedRewards +
_getPendingRewards(
balance,
currentUserRewardsData.rewardsIndexOnLastInteraction == 0
? rewardsIndexCache.lastUpdatedIndex
: currentUserRewardsData.rewardsIndexOnLastInteraction,
currentRewardsIndex,
assetUnit
);
}
/**
* @notice Claim rewards on behalf of a user and send them to a receiver
* @param onBehalfOf The address to claim on behalf of
* @param rewards The addresses of the rewards
* @param receiver The address to receive the rewards
*/
function _claimRewardsOnBehalf(
address onBehalfOf,
address receiver,
address[] memory rewards
) internal {
for (uint256 i = 0; i < rewards.length; i++) {
if (address(rewards[i]) == address(0)) {
continue;
}
uint256 currentRewardsIndex = getCurrentRewardsIndex(rewards[i]);
uint256 balance = balanceOf[onBehalfOf];
uint256 userReward = _getClaimableRewards(
onBehalfOf,
rewards[i],
balance,
currentRewardsIndex
);
uint256 totalRewardTokenBalance = IERC20(rewards[i]).balanceOf(
address(this)
);
uint256 unclaimedReward = 0;
if (userReward > totalRewardTokenBalance) {
totalRewardTokenBalance += collectAndUpdateRewards(
address(rewards[i])
);
}
if (userReward > totalRewardTokenBalance) {
unclaimedReward = userReward - totalRewardTokenBalance;
userReward = totalRewardTokenBalance;
}
if (userReward > 0) {
_userRewardsData[onBehalfOf][rewards[i]]
.unclaimedRewards = unclaimedReward.toUint128();
_userRewardsData[onBehalfOf][rewards[i]]
.rewardsIndexOnLastInteraction = currentRewardsIndex
.toUint128();
IERC20(rewards[i]).safeTransfer(receiver, userReward);
}
}
}
function _convertToShares(
uint256 assets,
Rounding rounding
) internal view returns (uint256) {
if (rounding == Rounding.UP) return assets.rayDivRoundUp(rate());
return assets.rayDivRoundDown(rate());
}
function _convertToAssets(
uint256 shares,
Rounding rounding
) internal view returns (uint256) {
if (rounding == Rounding.UP) return shares.rayMulRoundUp(rate());
return shares.rayMulRoundDown(rate());
}
/**
* @notice Initializes a new rewardToken
* @param reward The reward token to be registered
*/
function _registerRewardToken(address reward) internal {
if (isRegisteredRewardToken(reward)) return;
uint256 startIndex = getCurrentRewardsIndex(reward);
_rewardTokens.push(reward);
_startIndex[reward] = RewardIndexCache(true, uint240(startIndex));
emit RewardTokenRegistered(reward, startIndex);
}
/**
* @notice Returns the ongoing normalized income for the reserve.
* @dev A value of 1e27 means there is no income. As time passes, the income is accrued
* @dev A value of 2*1e27 means for each unit of asset one unit of income has been accrued
* @param reserve The reserve object
* @return The normalized income, expressed in ray
*/
function _getNormalizedIncome(
DataTypes.ReserveData memory reserve
) internal view returns (uint256) {
uint40 timestamp = reserve.lastUpdateTimestamp;
//solium-disable-next-line
if (timestamp == block.timestamp) {
//if the index was updated in the same block, no need to perform any calculation
return reserve.liquidityIndex;
} else {
return
MathUtils
.calculateLinearInterest(
reserve.currentLiquidityRate,
timestamp
)
.rayMul(reserve.liquidityIndex);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
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 v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @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.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
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].
*
* CAUTION: See Security Considerations above.
*/
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 (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @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);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// 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 cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
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: MIT
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(
value <= type(uint224).max,
"SafeCast: value doesn't fit in 224 bits"
);
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(
value <= type(uint128).max,
"SafeCast: value doesn't fit in 128 bits"
);
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(
value <= type(uint96).max,
"SafeCast: value doesn't fit in 96 bits"
);
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(
value <= type(uint64).max,
"SafeCast: value doesn't fit in 64 bits"
);
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(
value <= type(uint32).max,
"SafeCast: value doesn't fit in 32 bits"
);
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(
value <= type(uint16).max,
"SafeCast: value doesn't fit in 16 bits"
);
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(
value <= type(uint8).max,
"SafeCast: value doesn't fit in 8 bits"
);
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(
value >= type(int128).min && value <= type(int128).max,
"SafeCast: value doesn't fit in 128 bits"
);
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(
value >= type(int64).min && value <= type(int64).max,
"SafeCast: value doesn't fit in 64 bits"
);
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(
value >= type(int32).min && value <= type(int32).max,
"SafeCast: value doesn't fit in 32 bits"
);
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(
value >= type(int16).min && value <= type(int16).max,
"SafeCast: value doesn't fit in 16 bits"
);
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(
value >= type(int8).min && value <= type(int8).max,
"SafeCast: value doesn't fit in 8 bits"
);
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(
value <= uint256(type(int256).max),
"SafeCast: value doesn't fit in an int256"
);
return int256(value);
}
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.0;
/**
* @title Initializable
*
* @dev Helper contract to support initializer functions. To use it, replace
* the constructor with a function that has the `initializer` modifier.
* WARNING: Unlike constructors, initializer functions must be manually
* invoked. This applies both to deploying an Initializable contract, as well
* as extending an Initializable contract via inheritance.
* WARNING: When used with inheritance, manual care must be taken to not invoke
* a parent initializer twice, or ensure that all initializers are idempotent,
* because this is not dealt with automatically as with constructors.
*/
contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private initializing;
/**
* @dev Modifier to use in the initializer function of a contract.
*/
modifier initializer() {
require(
initializing || isConstructor() || !initialized,
"Contract instance has already been initialized"
);
bool isTopLevelCall = !initializing;
if (isTopLevelCall) {
initializing = true;
initialized = true;
}
_;
if (isTopLevelCall) {
initializing = false;
}
}
/// @dev Returns true if and only if the function is running in the constructor
function isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
uint256 cs;
//solium-disable-next-line
assembly {
cs := extcodesize(address())
}
return cs == 0;
}
// Reserved storage space to allow for layout changes in the future.
uint256[50] private ______gap;
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.0;
import {IPriceOracleGetter} from "./IPriceOracleGetter.sol";
import {IPoolAddressesProvider} from "./IPoolAddressesProvider.sol";
/**
* @title IAaveOracle
* @author Aave
* @notice Defines the basic interface for the Aave Oracle
*/
interface IAaveOracle is IPriceOracleGetter {
/**
* @dev Emitted after the base currency is set
* @param baseCurrency The base currency of used for price quotes
* @param baseCurrencyUnit The unit of the base currency
*/
event BaseCurrencySet(
address indexed baseCurrency,
uint256 baseCurrencyUnit
);
/**
* @dev Emitted after the price source of an asset is updated
* @param asset The address of the asset
* @param source The price source of the asset
*/
event AssetSourceUpdated(address indexed asset, address indexed source);
/**
* @dev Emitted after the address of fallback oracle is updated
* @param fallbackOracle The address of the fallback oracle
*/
event FallbackOracleUpdated(address indexed fallbackOracle);
/**
* @notice Returns the PoolAddressesProvider
* @return The address of the PoolAddressesProvider contract
*/
function ADDRESSES_PROVIDER()
external
view
returns (IPoolAddressesProvider);
/**
* @notice Sets or replaces price sources of assets
* @param assets The addresses of the assets
* @param sources The addresses of the price sources
*/
function setAssetSources(
address[] calldata assets,
address[] calldata sources
) external;
/**
* @notice Sets the fallback oracle
* @param fallbackOracle The address of the fallback oracle
*/
function setFallbackOracle(address fallbackOracle) external;
/**
* @notice Returns a list of prices from a list of assets addresses
* @param assets The list of assets addresses
* @return The prices of the given assets
*/
function getAssetsPrices(
address[] calldata assets
) external view returns (uint256[] memory);
/**
* @notice Returns the address of the source for an asset address
* @param asset The address of the asset
* @return The address of the source
*/
function getSourceOfAsset(address asset) external view returns (address);
/**
* @notice Returns the address of the fallback oracle
* @return The address of the fallback oracle
*/
function getFallbackOracle() external view returns (address);
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.0;
import {IERC20} from "../dependencies/openzeppelin/contracts/IERC20.sol";
/**
* @title IERC20WithPermit
* @author Aave
* @notice Interface for the permit function (EIP-2612)
*/
interface IERC20WithPermit is IERC20 {
/**
* @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;
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
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
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
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 getAddressFromID(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
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.0;
/**
* @title IPriceOracleGetter
* @author Aave
* @notice Interface for the Aave price oracle.
*/
interface IPriceOracleGetter {
/**
* @notice Returns the base currency address
* @dev Address 0x0 is reserved for USD as base currency.
* @return Returns the base currency address.
*/
function BASE_CURRENCY() external view returns (address);
/**
* @notice Returns the base currency unit
* @dev 1 ether for ETH, 1e8 for USD.
* @return Returns the base currency unit.
*/
function BASE_CURRENCY_UNIT() external view returns (uint256);
/**
* @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);
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
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
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.0;
import {Errors} from "../helpers/Errors.sol";
import {DataTypes} from "../types/DataTypes.sol";
/**
* @title ReserveConfiguration library
* @author Aave
* @notice Implements the bitmap logic to handle the reserve configuration
*/
library ReserveConfiguration {
uint256 internal constant LTV_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000; // prettier-ignore
uint256 internal constant LIQUIDATION_THRESHOLD_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFF; // prettier-ignore
uint256 internal constant LIQUIDATION_BONUS_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFF; // prettier-ignore
uint256 internal constant DECIMALS_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFF; // prettier-ignore
uint256 internal constant ACTIVE_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant FROZEN_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant STABLE_BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant PAUSED_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant BORROWABLE_IN_ISOLATION_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant SILOED_BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant FLASHLOAN_ENABLED_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant SUPPLY_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant LIQUIDATION_PROTOCOL_FEE_MASK = 0xFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant EMODE_CATEGORY_MASK = 0xFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant UNBACKED_MINT_CAP_MASK = 0xFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant DEBT_CEILING_MASK = 0xF0000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
/// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed
uint256 internal constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16;
uint256 internal constant LIQUIDATION_BONUS_START_BIT_POSITION = 32;
uint256 internal constant RESERVE_DECIMALS_START_BIT_POSITION = 48;
uint256 internal constant IS_ACTIVE_START_BIT_POSITION = 56;
uint256 internal constant IS_FROZEN_START_BIT_POSITION = 57;
uint256 internal constant BORROWING_ENABLED_START_BIT_POSITION = 58;
uint256 internal constant STABLE_BORROWING_ENABLED_START_BIT_POSITION = 59;
uint256 internal constant IS_PAUSED_START_BIT_POSITION = 60;
uint256 internal constant BORROWABLE_IN_ISOLATION_START_BIT_POSITION = 61;
uint256 internal constant SILOED_BORROWING_START_BIT_POSITION = 62;
uint256 internal constant FLASHLOAN_ENABLED_START_BIT_POSITION = 63;
uint256 internal constant RESERVE_FACTOR_START_BIT_POSITION = 64;
uint256 internal constant BORROW_CAP_START_BIT_POSITION = 80;
uint256 internal constant SUPPLY_CAP_START_BIT_POSITION = 116;
uint256 internal constant LIQUIDATION_PROTOCOL_FEE_START_BIT_POSITION = 152;
uint256 internal constant EMODE_CATEGORY_START_BIT_POSITION = 168;
uint256 internal constant UNBACKED_MINT_CAP_START_BIT_POSITION = 176;
uint256 internal constant DEBT_CEILING_START_BIT_POSITION = 212;
uint256 internal constant MAX_VALID_LTV = 65535;
uint256 internal constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535;
uint256 internal constant MAX_VALID_LIQUIDATION_BONUS = 65535;
uint256 internal constant MAX_VALID_DECIMALS = 255;
uint256 internal constant MAX_VALID_RESERVE_FACTOR = 65535;
uint256 internal constant MAX_VALID_BORROW_CAP = 68719476735;
uint256 internal constant MAX_VALID_SUPPLY_CAP = 68719476735;
uint256 internal constant MAX_VALID_LIQUIDATION_PROTOCOL_FEE = 65535;
uint256 internal constant MAX_VALID_EMODE_CATEGORY = 255;
uint256 internal constant MAX_VALID_UNBACKED_MINT_CAP = 68719476735;
uint256 internal constant MAX_VALID_DEBT_CEILING = 1099511627775;
uint256 public constant DEBT_CEILING_DECIMALS = 2;
uint16 public constant MAX_RESERVES_COUNT = 128;
/**
* @notice Sets the Loan to Value of the reserve
* @param self The reserve configuration
* @param ltv The new ltv
*/
function setLtv(
DataTypes.ReserveConfigurationMap memory self,
uint256 ltv
) internal pure {
require(ltv <= MAX_VALID_LTV, Errors.INVALID_LTV);
self.data = (self.data & LTV_MASK) | ltv;
}
/**
* @notice Gets the Loan to Value of the reserve
* @param self The reserve configuration
* @return The loan to value
*/
function getLtv(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return self.data & ~LTV_MASK;
}
/**
* @notice Sets the liquidation threshold of the reserve
* @param self The reserve configuration
* @param threshold The new liquidation threshold
*/
function setLiquidationThreshold(
DataTypes.ReserveConfigurationMap memory self,
uint256 threshold
) internal pure {
require(
threshold <= MAX_VALID_LIQUIDATION_THRESHOLD,
Errors.INVALID_LIQ_THRESHOLD
);
self.data =
(self.data & LIQUIDATION_THRESHOLD_MASK) |
(threshold << LIQUIDATION_THRESHOLD_START_BIT_POSITION);
}
/**
* @notice Gets the liquidation threshold of the reserve
* @param self The reserve configuration
* @return The liquidation threshold
*/
function getLiquidationThreshold(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return
(self.data & ~LIQUIDATION_THRESHOLD_MASK) >>
LIQUIDATION_THRESHOLD_START_BIT_POSITION;
}
/**
* @notice Sets the liquidation bonus of the reserve
* @param self The reserve configuration
* @param bonus The new liquidation bonus
*/
function setLiquidationBonus(
DataTypes.ReserveConfigurationMap memory self,
uint256 bonus
) internal pure {
require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.INVALID_LIQ_BONUS);
self.data =
(self.data & LIQUIDATION_BONUS_MASK) |
(bonus << LIQUIDATION_BONUS_START_BIT_POSITION);
}
/**
* @notice Gets the liquidation bonus of the reserve
* @param self The reserve configuration
* @return The liquidation bonus
*/
function getLiquidationBonus(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return
(self.data & ~LIQUIDATION_BONUS_MASK) >>
LIQUIDATION_BONUS_START_BIT_POSITION;
}
/**
* @notice Sets the decimals of the underlying asset of the reserve
* @param self The reserve configuration
* @param decimals The decimals
*/
function setDecimals(
DataTypes.ReserveConfigurationMap memory self,
uint256 decimals
) internal pure {
require(decimals <= MAX_VALID_DECIMALS, Errors.INVALID_DECIMALS);
self.data =
(self.data & DECIMALS_MASK) |
(decimals << RESERVE_DECIMALS_START_BIT_POSITION);
}
/**
* @notice Gets the decimals of the underlying asset of the reserve
* @param self The reserve configuration
* @return The decimals of the asset
*/
function getDecimals(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return
(self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION;
}
/**
* @notice Sets the active state of the reserve
* @param self The reserve configuration
* @param active The active state
*/
function setActive(
DataTypes.ReserveConfigurationMap memory self,
bool active
) internal pure {
self.data =
(self.data & ACTIVE_MASK) |
(uint256(active ? 1 : 0) << IS_ACTIVE_START_BIT_POSITION);
}
/**
* @notice Gets the active state of the reserve
* @param self The reserve configuration
* @return The active state
*/
function getActive(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~ACTIVE_MASK) != 0;
}
/**
* @notice Sets the frozen state of the reserve
* @param self The reserve configuration
* @param frozen The frozen state
*/
function setFrozen(
DataTypes.ReserveConfigurationMap memory self,
bool frozen
) internal pure {
self.data =
(self.data & FROZEN_MASK) |
(uint256(frozen ? 1 : 0) << IS_FROZEN_START_BIT_POSITION);
}
/**
* @notice Gets the frozen state of the reserve
* @param self The reserve configuration
* @return The frozen state
*/
function getFrozen(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~FROZEN_MASK) != 0;
}
/**
* @notice Sets the paused state of the reserve
* @param self The reserve configuration
* @param paused The paused state
*/
function setPaused(
DataTypes.ReserveConfigurationMap memory self,
bool paused
) internal pure {
self.data =
(self.data & PAUSED_MASK) |
(uint256(paused ? 1 : 0) << IS_PAUSED_START_BIT_POSITION);
}
/**
* @notice Gets the paused state of the reserve
* @param self The reserve configuration
* @return The paused state
*/
function getPaused(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~PAUSED_MASK) != 0;
}
/**
* @notice Sets the borrowable in isolation flag for the reserve.
* @dev When this flag is set to true, the asset will be borrowable against isolated collaterals and the borrowed
* amount will be accumulated in the isolated collateral's total debt exposure.
* @dev Only assets of the same family (eg USD stablecoins) should be borrowable in isolation mode to keep
* consistency in the debt ceiling calculations.
* @param self The reserve configuration
* @param borrowable True if the asset is borrowable
*/
function setBorrowableInIsolation(
DataTypes.ReserveConfigurationMap memory self,
bool borrowable
) internal pure {
self.data =
(self.data & BORROWABLE_IN_ISOLATION_MASK) |
(uint256(borrowable ? 1 : 0) <<
BORROWABLE_IN_ISOLATION_START_BIT_POSITION);
}
/**
* @notice Gets the borrowable in isolation flag for the reserve.
* @dev If the returned flag is true, the asset is borrowable against isolated collateral. Assets borrowed with
* isolated collateral is accounted for in the isolated collateral's total debt exposure.
* @dev Only assets of the same family (eg USD stablecoins) should be borrowable in isolation mode to keep
* consistency in the debt ceiling calculations.
* @param self The reserve configuration
* @return The borrowable in isolation flag
*/
function getBorrowableInIsolation(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~BORROWABLE_IN_ISOLATION_MASK) != 0;
}
/**
* @notice Sets the siloed borrowing flag for the reserve.
* @dev When this flag is set to true, users borrowing this asset will not be allowed to borrow any other asset.
* @param self The reserve configuration
* @param siloed True if the asset is siloed
*/
function setSiloedBorrowing(
DataTypes.ReserveConfigurationMap memory self,
bool siloed
) internal pure {
self.data =
(self.data & SILOED_BORROWING_MASK) |
(uint256(siloed ? 1 : 0) << SILOED_BORROWING_START_BIT_POSITION);
}
/**
* @notice Gets the siloed borrowing flag for the reserve.
* @dev When this flag is set to true, users borrowing this asset will not be allowed to borrow any other asset.
* @param self The reserve configuration
* @return The siloed borrowing flag
*/
function getSiloedBorrowing(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~SILOED_BORROWING_MASK) != 0;
}
/**
* @notice Enables or disables borrowing on the reserve
* @param self The reserve configuration
* @param enabled True if the borrowing needs to be enabled, false otherwise
*/
function setBorrowingEnabled(
DataTypes.ReserveConfigurationMap memory self,
bool enabled
) internal pure {
self.data =
(self.data & BORROWING_MASK) |
(uint256(enabled ? 1 : 0) << BORROWING_ENABLED_START_BIT_POSITION);
}
/**
* @notice Gets the borrowing state of the reserve
* @param self The reserve configuration
* @return The borrowing state
*/
function getBorrowingEnabled(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~BORROWING_MASK) != 0;
}
/**
* @notice Enables or disables stable rate borrowing on the reserve
* @param self The reserve configuration
* @param enabled True if the stable rate borrowing needs to be enabled, false otherwise
*/
function setStableRateBorrowingEnabled(
DataTypes.ReserveConfigurationMap memory self,
bool enabled
) internal pure {
self.data =
(self.data & STABLE_BORROWING_MASK) |
(uint256(enabled ? 1 : 0) <<
STABLE_BORROWING_ENABLED_START_BIT_POSITION);
}
/**
* @notice Gets the stable rate borrowing state of the reserve
* @param self The reserve configuration
* @return The stable rate borrowing state
*/
function getStableRateBorrowingEnabled(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~STABLE_BORROWING_MASK) != 0;
}
/**
* @notice Sets the reserve factor of the reserve
* @param self The reserve configuration
* @param reserveFactor The reserve factor
*/
function setReserveFactor(
DataTypes.ReserveConfigurationMap memory self,
uint256 reserveFactor
) internal pure {
require(
reserveFactor <= MAX_VALID_RESERVE_FACTOR,
Errors.INVALID_RESERVE_FACTOR
);
self.data =
(self.data & RESERVE_FACTOR_MASK) |
(reserveFactor << RESERVE_FACTOR_START_BIT_POSITION);
}
/**
* @notice Gets the reserve factor of the reserve
* @param self The reserve configuration
* @return The reserve factor
*/
function getReserveFactor(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return
(self.data & ~RESERVE_FACTOR_MASK) >>
RESERVE_FACTOR_START_BIT_POSITION;
}
/**
* @notice Sets the borrow cap of the reserve
* @param self The reserve configuration
* @param borrowCap The borrow cap
*/
function setBorrowCap(
DataTypes.ReserveConfigurationMap memory self,
uint256 borrowCap
) internal pure {
require(borrowCap <= MAX_VALID_BORROW_CAP, Errors.INVALID_BORROW_CAP);
self.data =
(self.data & BORROW_CAP_MASK) |
(borrowCap << BORROW_CAP_START_BIT_POSITION);
}
/**
* @notice Gets the borrow cap of the reserve
* @param self The reserve configuration
* @return The borrow cap
*/
function getBorrowCap(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION;
}
/**
* @notice Sets the supply cap of the reserve
* @param self The reserve configuration
* @param supplyCap The supply cap
*/
function setSupplyCap(
DataTypes.ReserveConfigurationMap memory self,
uint256 supplyCap
) internal pure {
require(supplyCap <= MAX_VALID_SUPPLY_CAP, Errors.INVALID_SUPPLY_CAP);
self.data =
(self.data & SUPPLY_CAP_MASK) |
(supplyCap << SUPPLY_CAP_START_BIT_POSITION);
}
/**
* @notice Gets the supply cap of the reserve
* @param self The reserve configuration
* @return The supply cap
*/
function getSupplyCap(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION;
}
/**
* @notice Sets the debt ceiling in isolation mode for the asset
* @param self The reserve configuration
* @param ceiling The maximum debt ceiling for the asset
*/
function setDebtCeiling(
DataTypes.ReserveConfigurationMap memory self,
uint256 ceiling
) internal pure {
require(ceiling <= MAX_VALID_DEBT_CEILING, Errors.INVALID_DEBT_CEILING);
self.data =
(self.data & DEBT_CEILING_MASK) |
(ceiling << DEBT_CEILING_START_BIT_POSITION);
}
/**
* @notice Gets the debt ceiling for the asset if the asset is in isolation mode
* @param self The reserve configuration
* @return The debt ceiling (0 = isolation mode disabled)
*/
function getDebtCeiling(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return
(self.data & ~DEBT_CEILING_MASK) >> DEBT_CEILING_START_BIT_POSITION;
}
/**
* @notice Sets the liquidation protocol fee of the reserve
* @param self The reserve configuration
* @param liquidationProtocolFee The liquidation protocol fee
*/
function setLiquidationProtocolFee(
DataTypes.ReserveConfigurationMap memory self,
uint256 liquidationProtocolFee
) internal pure {
require(
liquidationProtocolFee <= MAX_VALID_LIQUIDATION_PROTOCOL_FEE,
Errors.INVALID_LIQUIDATION_PROTOCOL_FEE
);
self.data =
(self.data & LIQUIDATION_PROTOCOL_FEE_MASK) |
(liquidationProtocolFee <<
LIQUIDATION_PROTOCOL_FEE_START_BIT_POSITION);
}
/**
* @dev Gets the liquidation protocol fee
* @param self The reserve configuration
* @return The liquidation protocol fee
*/
function getLiquidationProtocolFee(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return
(self.data & ~LIQUIDATION_PROTOCOL_FEE_MASK) >>
LIQUIDATION_PROTOCOL_FEE_START_BIT_POSITION;
}
/**
* @notice Sets the unbacked mint cap of the reserve
* @param self The reserve configuration
* @param unbackedMintCap The unbacked mint cap
*/
function setUnbackedMintCap(
DataTypes.ReserveConfigurationMap memory self,
uint256 unbackedMintCap
) internal pure {
require(
unbackedMintCap <= MAX_VALID_UNBACKED_MINT_CAP,
Errors.INVALID_UNBACKED_MINT_CAP
);
self.data =
(self.data & UNBACKED_MINT_CAP_MASK) |
(unbackedMintCap << UNBACKED_MINT_CAP_START_BIT_POSITION);
}
/**
* @dev Gets the unbacked mint cap of the reserve
* @param self The reserve configuration
* @return The unbacked mint cap
*/
function getUnbackedMintCap(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return
(self.data & ~UNBACKED_MINT_CAP_MASK) >>
UNBACKED_MINT_CAP_START_BIT_POSITION;
}
/**
* @notice Sets the eMode asset category
* @param self The reserve configuration
* @param category The asset category when the user selects the eMode
*/
function setEModeCategory(
DataTypes.ReserveConfigurationMap memory self,
uint256 category
) internal pure {
require(
category <= MAX_VALID_EMODE_CATEGORY,
Errors.INVALID_EMODE_CATEGORY
);
self.data =
(self.data & EMODE_CATEGORY_MASK) |
(category << EMODE_CATEGORY_START_BIT_POSITION);
}
/**
* @dev Gets the eMode asset category
* @param self The reserve configuration
* @return The eMode category for the asset
*/
function getEModeCategory(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256) {
return
(self.data & ~EMODE_CATEGORY_MASK) >>
EMODE_CATEGORY_START_BIT_POSITION;
}
/**
* @notice Sets the flashloanable flag for the reserve
* @param self The reserve configuration
* @param flashLoanEnabled True if the asset is flashloanable, false otherwise
*/
function setFlashLoanEnabled(
DataTypes.ReserveConfigurationMap memory self,
bool flashLoanEnabled
) internal pure {
self.data =
(self.data & FLASHLOAN_ENABLED_MASK) |
(uint256(flashLoanEnabled ? 1 : 0) <<
FLASHLOAN_ENABLED_START_BIT_POSITION);
}
/**
* @notice Gets the flashloanable flag for the reserve
* @param self The reserve configuration
* @return The flashloanable flag
*/
function getFlashLoanEnabled(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~FLASHLOAN_ENABLED_MASK) != 0;
}
/**
* @notice Gets the configuration flags of the reserve
* @param self The reserve configuration
* @return The state flag representing active
* @return The state flag representing frozen
* @return The state flag representing borrowing enabled
* @return The state flag representing stableRateBorrowing enabled
* @return The state flag representing paused
*/
function getFlags(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool, bool, bool, bool, bool) {
uint256 dataLocal = self.data;
return (
(dataLocal & ~ACTIVE_MASK) != 0,
(dataLocal & ~FROZEN_MASK) != 0,
(dataLocal & ~BORROWING_MASK) != 0,
(dataLocal & ~STABLE_BORROWING_MASK) != 0,
(dataLocal & ~PAUSED_MASK) != 0
);
}
/**
* @notice Gets the configuration parameters of the reserve from storage
* @param self The reserve configuration
* @return The state param representing ltv
* @return The state param representing liquidation threshold
* @return The state param representing liquidation bonus
* @return The state param representing reserve decimals
* @return The state param representing reserve factor
* @return The state param representing eMode category
*/
function getParams(
DataTypes.ReserveConfigurationMap memory self
)
internal
pure
returns (uint256, uint256, uint256, uint256, uint256, uint256)
{
uint256 dataLocal = self.data;
return (
dataLocal & ~LTV_MASK,
(dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >>
LIQUIDATION_THRESHOLD_START_BIT_POSITION,
(dataLocal & ~LIQUIDATION_BONUS_MASK) >>
LIQUIDATION_BONUS_START_BIT_POSITION,
(dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
(dataLocal & ~RESERVE_FACTOR_MASK) >>
RESERVE_FACTOR_START_BIT_POSITION,
(dataLocal & ~EMODE_CATEGORY_MASK) >>
EMODE_CATEGORY_START_BIT_POSITION
);
}
/**
* @notice Gets the caps parameters of the reserve from storage
* @param self The reserve configuration
* @return The state param representing borrow cap
* @return The state param representing supply cap.
*/
function getCaps(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (uint256, uint256) {
uint256 dataLocal = self.data;
return (
(dataLocal & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION,
(dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
);
}
}// SPDX-License-Identifier: BUSL-1.1
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.0;
/**
* @title Errors library
* @author Aave
* @notice Defines the error messages emitted by the different contracts of the Aave protocol
*/
library Errors {
string public constant CALLER_NOT_POOL_ADMIN = "1"; // 'The caller of the function is not a pool admin'
string public constant CALLER_NOT_EMERGENCY_ADMIN = "2"; // 'The caller of the function is not an emergency admin'
string public constant CALLER_NOT_POOL_OR_EMERGENCY_ADMIN = "3"; // 'The caller of the function is not a pool or emergency admin'
string public constant CALLER_NOT_RISK_OR_POOL_ADMIN = "4"; // 'The caller of the function is not a risk or pool admin'
string public constant CALLER_NOT_ASSET_LISTING_OR_POOL_ADMIN = "5"; // 'The caller of the function is not an asset listing or pool admin'
string public constant CALLER_NOT_BRIDGE = "6"; // 'The caller of the function is not a bridge'
string public constant ADDRESSES_PROVIDER_NOT_REGISTERED = "7"; // 'Pool addresses provider is not registered'
string public constant INVALID_ADDRESSES_PROVIDER_ID = "8"; // 'Invalid id for the pool addresses provider'
string public constant NOT_CONTRACT = "9"; // 'Address is not a contract'
string public constant CALLER_NOT_POOL_CONFIGURATOR = "10"; // 'The caller of the function is not the pool configurator'
string public constant CALLER_NOT_ATOKEN = "11"; // 'The caller of the function is not an AToken'
string public constant INVALID_ADDRESSES_PROVIDER = "12"; // 'The address of the pool addresses provider is invalid'
string public constant INVALID_FLASHLOAN_EXECUTOR_RETURN = "13"; // 'Invalid return value of the flashloan executor function'
string public constant RESERVE_ALREADY_ADDED = "14"; // 'Reserve has already been added to reserve list'
string public constant NO_MORE_RESERVES_ALLOWED = "15"; // 'Maximum amount of reserves in the pool reached'
string public constant EMODE_CATEGORY_RESERVED = "16"; // 'Zero eMode category is reserved for volatile heterogeneous assets'
string public constant INVALID_EMODE_CATEGORY_ASSIGNMENT = "17"; // 'Invalid eMode category assignment to asset'
string public constant RESERVE_LIQUIDITY_NOT_ZERO = "18"; // 'The liquidity of the reserve needs to be 0'
string public constant FLASHLOAN_PREMIUM_INVALID = "19"; // 'Invalid flashloan premium'
string public constant INVALID_RESERVE_PARAMS = "20"; // 'Invalid risk parameters for the reserve'
string public constant INVALID_EMODE_CATEGORY_PARAMS = "21"; // 'Invalid risk parameters for the eMode category'
string public constant BRIDGE_PROTOCOL_FEE_INVALID = "22"; // 'Invalid bridge protocol fee'
string public constant CALLER_MUST_BE_POOL = "23"; // 'The caller of this function must be a pool'
string public constant INVALID_MINT_AMOUNT = "24"; // 'Invalid amount to mint'
string public constant INVALID_BURN_AMOUNT = "25"; // 'Invalid amount to burn'
string public constant INVALID_AMOUNT = "26"; // 'Amount must be greater than 0'
string public constant RESERVE_INACTIVE = "27"; // 'Action requires an active reserve'
string public constant RESERVE_FROZEN = "28"; // 'Action cannot be performed because the reserve is frozen'
string public constant RESERVE_PAUSED = "29"; // 'Action cannot be performed because the reserve is paused'
string public constant BORROWING_NOT_ENABLED = "30"; // 'Borrowing is not enabled'
string public constant STABLE_BORROWING_NOT_ENABLED = "31"; // 'Stable borrowing is not enabled'
string public constant NOT_ENOUGH_AVAILABLE_USER_BALANCE = "32"; // 'User cannot withdraw more than the available balance'
string public constant INVALID_INTEREST_RATE_MODE_SELECTED = "33"; // 'Invalid interest rate mode selected'
string public constant COLLATERAL_BALANCE_IS_ZERO = "34"; // 'The collateral balance is 0'
string public constant HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD =
"35"; // 'Health factor is lesser than the liquidation threshold'
string public constant COLLATERAL_CANNOT_COVER_NEW_BORROW = "36"; // 'There is not enough collateral to cover a new borrow'
string public constant COLLATERAL_SAME_AS_BORROWING_CURRENCY = "37"; // 'Collateral is (mostly) the same currency that is being borrowed'
string public constant AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = "38"; // 'The requested amount is greater than the max loan size in stable rate mode'
string public constant NO_DEBT_OF_SELECTED_TYPE = "39"; // 'For repayment of a specific type of debt, the user needs to have debt that type'
string public constant NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = "40"; // 'To repay on behalf of a user an explicit amount to repay is needed'
string public constant NO_OUTSTANDING_STABLE_DEBT = "41"; // 'User does not have outstanding stable rate debt on this reserve'
string public constant NO_OUTSTANDING_VARIABLE_DEBT = "42"; // 'User does not have outstanding variable rate debt on this reserve'
string public constant UNDERLYING_BALANCE_ZERO = "43"; // 'The underlying balance needs to be greater than 0'
string public constant INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = "44"; // 'Interest rate rebalance conditions were not met'
string public constant HEALTH_FACTOR_NOT_BELOW_THRESHOLD = "45"; // 'Health factor is not below the threshold'
string public constant COLLATERAL_CANNOT_BE_LIQUIDATED = "46"; // 'The collateral chosen cannot be liquidated'
string public constant SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = "47"; // 'User did not borrow the specified currency'
string public constant INCONSISTENT_FLASHLOAN_PARAMS = "49"; // 'Inconsistent flashloan parameters'
string public constant BORROW_CAP_EXCEEDED = "50"; // 'Borrow cap is exceeded'
string public constant SUPPLY_CAP_EXCEEDED = "51"; // 'Supply cap is exceeded'
string public constant UNBACKED_MINT_CAP_EXCEEDED = "52"; // 'Unbacked mint cap is exceeded'
string public constant DEBT_CEILING_EXCEEDED = "53"; // 'Debt ceiling is exceeded'
string public constant UNDERLYING_CLAIMABLE_RIGHTS_NOT_ZERO = "54"; // 'Claimable rights over underlying not zero (aToken supply or accruedToTreasury)'
string public constant STABLE_DEBT_NOT_ZERO = "55"; // 'Stable debt supply is not zero'
string public constant VARIABLE_DEBT_SUPPLY_NOT_ZERO = "56"; // 'Variable debt supply is not zero'
string public constant LTV_VALIDATION_FAILED = "57"; // 'Ltv validation failed'
string public constant INCONSISTENT_EMODE_CATEGORY = "58"; // 'Inconsistent eMode category'
string public constant PRICE_ORACLE_SENTINEL_CHECK_FAILED = "59"; // 'Price oracle sentinel validation failed'
string public constant ASSET_NOT_BORROWABLE_IN_ISOLATION = "60"; // 'Asset is not borrowable in isolation mode'
string public constant RESERVE_ALREADY_INITIALIZED = "61"; // 'Reserve has already been initialized'
string public constant USER_IN_ISOLATION_MODE_OR_LTV_ZERO = "62"; // 'User is in isolation mode or ltv is zero'
string public constant INVALID_LTV = "63"; // 'Invalid ltv parameter for the reserve'
string public constant INVALID_LIQ_THRESHOLD = "64"; // 'Invalid liquidity threshold parameter for the reserve'
string public constant INVALID_LIQ_BONUS = "65"; // 'Invalid liquidity bonus parameter for the reserve'
string public constant INVALID_DECIMALS = "66"; // 'Invalid decimals parameter of the underlying asset of the reserve'
string public constant INVALID_RESERVE_FACTOR = "67"; // 'Invalid reserve factor parameter for the reserve'
string public constant INVALID_BORROW_CAP = "68"; // 'Invalid borrow cap for the reserve'
string public constant INVALID_SUPPLY_CAP = "69"; // 'Invalid supply cap for the reserve'
string public constant INVALID_LIQUIDATION_PROTOCOL_FEE = "70"; // 'Invalid liquidation protocol fee for the reserve'
string public constant INVALID_EMODE_CATEGORY = "71"; // 'Invalid eMode category for the reserve'
string public constant INVALID_UNBACKED_MINT_CAP = "72"; // 'Invalid unbacked mint cap for the reserve'
string public constant INVALID_DEBT_CEILING = "73"; // 'Invalid debt ceiling for the reserve
string public constant INVALID_RESERVE_INDEX = "74"; // 'Invalid reserve index'
string public constant ACL_ADMIN_CANNOT_BE_ZERO = "75"; // 'ACL admin cannot be set to the zero address'
string public constant INCONSISTENT_PARAMS_LENGTH = "76"; // 'Array parameters that should be equal length are not'
string public constant ZERO_ADDRESS_NOT_VALID = "77"; // 'Zero address not valid'
string public constant INVALID_EXPIRATION = "78"; // 'Invalid expiration'
string public constant INVALID_SIGNATURE = "79"; // 'Invalid signature'
string public constant OPERATION_NOT_SUPPORTED = "80"; // 'Operation not supported'
string public constant DEBT_CEILING_NOT_ZERO = "81"; // 'Debt ceiling is not zero'
string public constant ASSET_NOT_LISTED = "82"; // 'Asset is not listed'
string public constant INVALID_OPTIMAL_USAGE_RATIO = "83"; // 'Invalid optimal usage ratio'
string public constant INVALID_OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO = "84"; // 'Invalid optimal stable to total debt ratio'
string public constant UNDERLYING_CANNOT_BE_RESCUED = "85"; // 'The underlying asset cannot be rescued'
string public constant ADDRESSES_PROVIDER_ALREADY_ADDED = "86"; // 'Reserve has already been added to reserve list'
string public constant POOL_ADDRESSES_DO_NOT_MATCH = "87"; // 'The token implementation pool address and the pool address provided by the initializing pool do not match'
string public constant STABLE_BORROWING_ENABLED = "88"; // 'Stable borrowing is enabled'
string public constant SILOED_BORROWING_VIOLATION = "89"; // 'User is trying to borrow multiple assets including a siloed one'
string public constant RESERVE_DEBT_NOT_ZERO = "90"; // the total debt of the reserve needs to be 0
string public constant FLASHLOAN_DISABLED = "91"; // FlashLoaning for this asset is disabled
}// SPDX-License-Identifier: BUSL-1.1
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.0;
import {WadRayMath} from "./WadRayMath.sol";
/**
* @title MathUtils library
* @author Aave
* @notice Provides functions to perform linear and compounded interest calculations
*/
library MathUtils {
using WadRayMath for uint256;
/// @dev Ignoring leap years
uint256 internal constant SECONDS_PER_YEAR = 365 days;
/**
* @dev Function to calculate the interest accumulated using a linear interest rate formula
* @param rate The interest rate, in ray
* @param lastUpdateTimestamp The timestamp of the last update of the interest
* @return The interest rate linearly accumulated during the timeDelta, in ray
*/
function calculateLinearInterest(
uint256 rate,
uint40 lastUpdateTimestamp
) internal view returns (uint256) {
//solium-disable-next-line
uint256 result = rate *
(block.timestamp - uint256(lastUpdateTimestamp));
unchecked {
result = result / SECONDS_PER_YEAR;
}
return WadRayMath.RAY + result;
}
/**
* @dev Function to calculate the interest using a compounded interest rate formula
* To avoid expensive exponentiation, the calculation is performed using a binomial approximation:
*
* (1+x)^n = 1+n*x+[n/2*(n-1)]*x^2+[n/6*(n-1)*(n-2)*x^3...
*
* The approximation slightly underpays liquidity providers and undercharges borrowers, with the advantage of great
* gas cost reductions. The whitepaper contains reference to the approximation and a table showing the margin of
* error per different time periods
*
* @param rate The interest rate, in ray
* @param lastUpdateTimestamp The timestamp of the last update of the interest
* @return The interest rate compounded during the timeDelta, in ray
*/
function calculateCompoundedInterest(
uint256 rate,
uint40 lastUpdateTimestamp,
uint256 currentTimestamp
) internal pure returns (uint256) {
//solium-disable-next-line
uint256 exp = currentTimestamp - uint256(lastUpdateTimestamp);
if (exp == 0) {
return WadRayMath.RAY;
}
uint256 expMinusOne;
uint256 expMinusTwo;
uint256 basePowerTwo;
uint256 basePowerThree;
unchecked {
expMinusOne = exp - 1;
expMinusTwo = exp > 2 ? exp - 2 : 0;
basePowerTwo =
rate.rayMul(rate) /
(SECONDS_PER_YEAR * SECONDS_PER_YEAR);
basePowerThree = basePowerTwo.rayMul(rate) / SECONDS_PER_YEAR;
}
uint256 secondTerm = exp * expMinusOne * basePowerTwo;
unchecked {
secondTerm /= 2;
}
uint256 thirdTerm = exp * expMinusOne * expMinusTwo * basePowerThree;
unchecked {
thirdTerm /= 6;
}
return
WadRayMath.RAY +
(rate * exp) /
SECONDS_PER_YEAR +
secondTerm +
thirdTerm;
}
/**
* @dev Calculates the compounded interest between the timestamp of the last update and the current block timestamp
* @param rate The interest rate (in ray)
* @param lastUpdateTimestamp The timestamp from which the interest accumulation needs to be calculated
* @return The interest rate compounded between lastUpdateTimestamp and current block timestamp, in ray
*/
function calculateCompoundedInterest(
uint256 rate,
uint40 lastUpdateTimestamp
) internal view returns (uint256) {
return
calculateCompoundedInterest(
rate,
lastUpdateTimestamp,
block.timestamp
);
}
}// SPDX-License-Identifier: BUSL-1.1
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.0;
/**
* @title WadRayMath library
* @author Aave
* @notice Provides functions to perform calculations with Wad and Ray units
* @dev Provides mul and div function for wads (decimal numbers with 18 digits of precision) and rays (decimal numbers
* with 27 digits of precision)
* @dev Operations are rounded. If a value is >=.5, will be rounded up, otherwise rounded down.
*/
library WadRayMath {
// HALF_WAD and HALF_RAY expressed with extended notation as constant with operations are not supported in Yul assembly
uint256 internal constant WAD = 1e18;
uint256 internal constant HALF_WAD = 0.5e18;
uint256 internal constant RAY = 1e27;
uint256 internal constant HALF_RAY = 0.5e27;
uint256 internal constant WAD_RAY_RATIO = 1e9;
/**
* @dev Multiplies two wad, rounding half up to the nearest wad
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
* @param a Wad
* @param b Wad
* @return c = a*b, in wad
*/
function wadMul(uint256 a, uint256 b) internal pure returns (uint256 c) {
// to avoid overflow, a <= (type(uint256).max - HALF_WAD) / b
assembly {
if iszero(
or(iszero(b), iszero(gt(a, div(sub(not(0), HALF_WAD), b))))
) {
revert(0, 0)
}
c := div(add(mul(a, b), HALF_WAD), WAD)
}
}
/**
* @dev Divides two wad, rounding half up to the nearest wad
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
* @param a Wad
* @param b Wad
* @return c = a/b, in wad
*/
function wadDiv(uint256 a, uint256 b) internal pure returns (uint256 c) {
// to avoid overflow, a <= (type(uint256).max - halfB) / WAD
assembly {
if or(
iszero(b),
iszero(iszero(gt(a, div(sub(not(0), div(b, 2)), WAD))))
) {
revert(0, 0)
}
c := div(add(mul(a, WAD), div(b, 2)), b)
}
}
/**
* @notice Multiplies two ray, rounding half up to the nearest ray
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
* @param a Ray
* @param b Ray
* @return c = a raymul b
*/
function rayMul(uint256 a, uint256 b) internal pure returns (uint256 c) {
// to avoid overflow, a <= (type(uint256).max - HALF_RAY) / b
assembly {
if iszero(
or(iszero(b), iszero(gt(a, div(sub(not(0), HALF_RAY), b))))
) {
revert(0, 0)
}
c := div(add(mul(a, b), HALF_RAY), RAY)
}
}
/**
* @notice Divides two ray, rounding half up to the nearest ray
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
* @param a Ray
* @param b Ray
* @return c = a raydiv b
*/
function rayDiv(uint256 a, uint256 b) internal pure returns (uint256 c) {
// to avoid overflow, a <= (type(uint256).max - halfB) / RAY
assembly {
if or(
iszero(b),
iszero(iszero(gt(a, div(sub(not(0), div(b, 2)), RAY))))
) {
revert(0, 0)
}
c := div(add(mul(a, RAY), div(b, 2)), b)
}
}
/**
* @dev Casts ray down to wad
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
* @param a Ray
* @return b = a converted to wad, rounded half up to the nearest wad
*/
function rayToWad(uint256 a) internal pure returns (uint256 b) {
assembly {
b := div(a, WAD_RAY_RATIO)
let remainder := mod(a, WAD_RAY_RATIO)
if iszero(lt(remainder, div(WAD_RAY_RATIO, 2))) {
b := add(b, 1)
}
}
}
/**
* @dev Converts wad up to ray
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
* @param a Wad
* @return b = a converted in ray
*/
function wadToRay(uint256 a) internal pure returns (uint256 b) {
// to avoid overflow, b/WAD_RAY_RATIO == a
assembly {
b := mul(a, WAD_RAY_RATIO)
if iszero(eq(div(b, WAD_RAY_RATIO), a)) {
revert(0, 0)
}
}
}
}// SPDX-License-Identifier: BUSL-1.1
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
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: siloed borrowing enabled
//bit 63: flashloaning enabled
//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: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.10;
import {IAaveOracle} from "contracts/lending/core/interfaces/IAaveOracle.sol";
import {IRewardsDistributor} from "./IRewardsDistributor.sol";
import {ITransferStrategyBase} from "./ITransferStrategyBase.sol";
import {RewardsDataTypes} from "../libraries/RewardsDataTypes.sol";
/**
* @title IRewardsController
* @author Aave
* @notice Defines the basic interface for a Rewards Controller.
*/
interface IRewardsController is IRewardsDistributor {
/**
* @dev Emitted when a new address is whitelisted as claimer of rewards on behalf of a user
* @param user The address of the user
* @param claimer The address of the claimer
*/
event ClaimerSet(address indexed user, address indexed claimer);
/**
* @dev Emitted when rewards are claimed
* @param user The address of the user rewards has been claimed on behalf of
* @param reward The address of the token reward is claimed
* @param to The address of the receiver of the rewards
* @param claimer The address of the claimer
* @param amount The amount of rewards claimed
*/
event RewardsClaimed(
address indexed user,
address indexed reward,
address indexed to,
address claimer,
uint256 amount
);
/**
* @dev Emitted when a transfer strategy is installed for the reward distribution
* @param reward The address of the token reward
* @param transferStrategy The address of TransferStrategy contract
*/
event TransferStrategyInstalled(
address indexed reward,
address indexed transferStrategy
);
/**
* @dev Emitted when the reward oracle is updated
* @param reward The address of the token reward
* @param rewardOracle The address of oracle
*/
event RewardOracleUpdated(
address indexed reward,
address indexed rewardOracle
);
/**
* @dev Whitelists an address to claim the rewards on behalf of another address
* @param user The address of the user
* @param claimer The address of the claimer
*/
function setClaimer(address user, address claimer) external;
/**
* @dev Sets a TransferStrategy logic contract that determines the logic of the rewards transfer
* @param reward The address of the reward token
* @param transferStrategy The address of the TransferStrategy logic contract
*/
function setTransferStrategy(
address reward,
ITransferStrategyBase transferStrategy
) external;
/**
* @dev Sets an Aave Oracle contract to enforce rewards with a source of value.
* @notice At the moment of reward configuration, the Incentives Controller performs
* a check to see if the reward asset oracle is compatible with IAaveOracle interface.
* This check is enforced for integrators to be able to show incentives at
* the current Aave UI without the need to setup an external price registry
* @param reward The address of the reward to set the price aggregator
* @param rewardOracle The address of price aggregator that follows IAaveOracle interface
*/
function setRewardOracle(address reward, IAaveOracle rewardOracle) external;
/**
* @dev Get the price aggregator oracle address
* @param reward The address of the reward
* @return The price oracle of the reward
*/
function getRewardOracle(address reward) external view returns (address);
/**
* @dev Returns the whitelisted claimer for a certain address (0x0 if not set)
* @param user The address of the user
* @return The claimer address
*/
function getClaimer(address user) external view returns (address);
/**
* @dev Returns the Transfer Strategy implementation contract address being used for a reward address
* @param reward The address of the reward
* @return The address of the TransferStrategy contract
*/
function getTransferStrategy(
address reward
) external view returns (address);
/**
* @dev Configure assets to incentivize with an emission of rewards per second until the end of distribution.
* @param config The assets configuration input, the list of structs contains the following fields:
* uint104 emissionPerSecond: The emission per second following rewards unit decimals.
* uint256 totalSupply: The total supply of the asset to incentivize
* uint40 distributionEnd: The end of the distribution of the incentives for an asset
* address asset: The asset address to incentivize
* address reward: The reward token address
* ITransferStrategy transferStrategy: The TransferStrategy address with the install hook and claim logic.
* IEACAggregatorProxy rewardOracle: The Price Oracle of a reward to visualize the incentives at the UI Frontend.
* Must follow Chainlink Aggregator IEACAggregatorProxy interface to be compatible.
*/
function configureAssets(
RewardsDataTypes.RewardsConfigInput[] memory config
) external;
/**
* @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;
/**
* @dev Claims reward for a user to the desired address, on all the assets of the pool, accumulating the pending rewards
* @param assets List of assets to check eligible distributions before claiming rewards
* @param amount The amount of rewards to claim
* @param to The address that will be receiving the rewards
* @param reward The address of the reward token
* @return The amount of rewards claimed
**/
function claimRewards(
address[] calldata assets,
uint256 amount,
address to,
address reward
) external returns (uint256);
/**
* @dev Claims reward for a user on behalf, on all the assets of the pool, accumulating the pending rewards. The
* caller must be whitelisted via "allowClaimOnBehalf" function by the RewardsAdmin role manager
* @param assets The list of assets to check eligible distributions before claiming rewards
* @param amount The amount of rewards to claim
* @param user The address to check and claim rewards
* @param to The address that will be receiving the rewards
* @param reward The address of the reward token
* @return The amount of rewards claimed
**/
function claimRewardsOnBehalf(
address[] calldata assets,
uint256 amount,
address user,
address to,
address reward
) external returns (uint256);
/**
* @dev Claims reward for msg.sender, on all the assets of the pool, accumulating the pending rewards
* @param assets The list of assets to check eligible distributions before claiming rewards
* @param amount The amount of rewards to claim
* @param reward The address of the reward token
* @return The amount of rewards claimed
**/
function claimRewardsToSelf(
address[] calldata assets,
uint256 amount,
address reward
) external returns (uint256);
/**
* @dev Claims all rewards for a user to the desired address, on all the assets of the pool, accumulating the pending rewards
* @param assets The list of assets to check eligible distributions before claiming rewards
* @param to The address that will be receiving the rewards
* @return rewardsList List of addresses of the reward tokens
* @return claimedAmounts List that contains the claimed amount per reward, following same order as "rewardList"
**/
function claimAllRewards(
address[] calldata assets,
address to
)
external
returns (address[] memory rewardsList, uint256[] memory claimedAmounts);
/**
* @dev Claims all rewards for a user on behalf, on all the assets of the pool, accumulating the pending rewards. The caller must
* be whitelisted via "allowClaimOnBehalf" function by the RewardsAdmin role manager
* @param assets The list of assets to check eligible distributions before claiming rewards
* @param user The address to check and claim rewards
* @param to The address that will be receiving the rewards
* @return rewardsList List of addresses of the reward tokens
* @return claimedAmounts List that contains the claimed amount per reward, following same order as "rewardsList"
**/
function claimAllRewardsOnBehalf(
address[] calldata assets,
address user,
address to
)
external
returns (address[] memory rewardsList, uint256[] memory claimedAmounts);
/**
* @dev Claims all reward for msg.sender, on all the assets of the pool, accumulating the pending rewards
* @param assets The list of assets to check eligible distributions before claiming rewards
* @return rewardsList List of addresses of the reward tokens
* @return claimedAmounts List that contains the claimed amount per reward, following same order as "rewardsList"
**/
function claimAllRewardsToSelf(
address[] calldata assets
)
external
returns (address[] memory rewardsList, uint256[] memory claimedAmounts);
/**
* @dev Recieve more fund from the user to existing reward
* @param reward The reward address is being distributed
* @param amount The token amount is being funded
* @param from The address of the one who funds the rewards
*/
function depositRewardFrom(
address reward,
uint256 amount,
address from
) external;
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.10;
/**
* @title IRewardsDistributor
* @author Aave
* @notice Defines the basic interface for a Rewards Distributor.
*/
interface IRewardsDistributor {
/**
* @dev Emitted when the configuration of the rewards of an asset is updated.
* @param asset The address of the incentivized asset
* @param reward The address of the reward token
* @param oldEmission The old emissions per second value of the reward distribution
* @param newEmission The new emissions per second value of the reward distribution
* @param oldDistributionEnd The old end timestamp of the reward distribution
* @param newDistributionEnd The new end timestamp of the reward distribution
* @param assetIndex The index of the asset distribution
*/
event AssetConfigUpdated(
address indexed asset,
address indexed reward,
uint256 oldEmission,
uint256 newEmission,
uint256 oldDistributionEnd,
uint256 newDistributionEnd,
uint256 assetIndex
);
/**
* @dev Emitted when rewards of an asset are accrued on behalf of a user.
* @param asset The address of the incentivized asset
* @param reward The address of the reward token
* @param user The address of the user that rewards are accrued on behalf of
* @param assetIndex The index of the asset distribution
* @param userIndex The index of the asset distribution on behalf of the user
* @param rewardsAccrued The amount of rewards accrued
*/
event Accrued(
address indexed asset,
address indexed reward,
address indexed user,
uint256 assetIndex,
uint256 userIndex,
uint256 rewardsAccrued
);
/**
* @dev Sets the end date for the distribution
* @param asset The asset to incentivize
* @param reward The reward token that incentives the asset
* @param newDistributionEnd The end date of the incentivization, in unix time format
**/
function setDistributionEnd(
address asset,
address reward,
uint32 newDistributionEnd
) external;
/**
* @dev Sets the emission per second of a set of reward distributions
* @param asset The asset is being incentivized
* @param rewards List of reward addresses are being distributed
* @param newEmissionsPerSecond List of new reward emissions per second
*/
function setEmissionPerSecond(
address asset,
address[] calldata rewards,
uint88[] calldata newEmissionsPerSecond
) external;
/**
* @dev Gets the end date for the distribution
* @param asset The incentivized asset
* @param reward The reward token of the incentivized asset
* @return The timestamp with the end of the distribution, in unix time format
**/
function getDistributionEnd(
address asset,
address reward
) external view returns (uint256);
/**
* @dev Returns the index of a user on a reward distribution
* @param user Address of the user
* @param asset The incentivized asset
* @param reward The reward token of the incentivized asset
* @return The current user asset index, not including new distributions
**/
function getUserAssetIndex(
address user,
address asset,
address reward
) external view returns (uint256);
/**
* @dev Returns the configuration of the distribution reward for a certain asset
* @param asset The incentivized asset
* @param reward The reward token of the incentivized asset
* @return The index of the asset distribution
* @return The emission per second of the reward distribution
* @return The timestamp of the last update of the index
* @return The timestamp of the distribution end
**/
function getRewardsData(
address asset,
address reward
) external view returns (uint256, uint256, uint256, uint256);
/**
* @dev Calculates the next value of an specific distribution index, with validations.
* @param asset The incentivized asset
* @param reward The reward token of the incentivized asset
* @return The old index of the asset distribution
* @return The new index of the asset distribution
**/
function getAssetIndex(
address asset,
address reward
) external view returns (uint256, uint256);
/**
* @dev Returns the list of available reward token addresses of an incentivized asset
* @param asset The incentivized asset
* @return List of rewards addresses of the input asset
**/
function getRewardsByAsset(
address asset
) external view returns (address[] memory);
/**
* @dev Returns the list of available reward addresses
* @return List of rewards supported in this contract
**/
function getRewardsList() external view returns (address[] memory);
/**
* @dev Returns the accrued rewards balance of a user, not including virtually accrued rewards since last distribution.
* @param user The address of the user
* @param reward The address of the reward token
* @return Unclaimed rewards, not including new distributions
**/
function getUserAccruedRewards(
address user,
address reward
) external view returns (uint256);
/**
* @dev Returns a single rewards balance of a user, including virtually accrued and unrealized claimable rewards.
* @param assets List of incentivized assets to check eligible distributions
* @param user The address of the user
* @param reward The address of the reward token
* @return The rewards amount
**/
function getUserRewards(
address[] calldata assets,
address user,
address reward
) external view returns (uint256);
/**
* @dev Returns a list all rewards of a user, including already accrued and unrealized claimable rewards
* @param assets List of incentivized assets to check eligible distributions
* @param user The address of the user
* @return The list of reward addresses
* @return The list of unclaimed amount of rewards
**/
function getAllUserRewards(
address[] calldata assets,
address user
) external view returns (address[] memory, uint256[] memory);
/**
* @dev Returns the decimals of an asset to calculate the distribution delta
* @param asset The address to retrieve decimals
* @return The decimals of an underlying asset
*/
function getAssetDecimals(address asset) external view returns (uint8);
/**
* @dev Returns the address of the emission manager
* @return The address of the EmissionManager
*/
function EMISSION_MANAGER() external view returns (address);
/**
* @dev Returns the address of the emission manager.
* Deprecated: This getter is maintained for compatibility purposes. Use the `EMISSION_MANAGER()` function instead.
* @return The address of the EmissionManager
*/
function getEmissionManager() external view returns (address);
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.10;
interface ITransferStrategyBase {
event EmergencyWithdrawal(
address indexed caller,
address indexed token,
address indexed to,
uint256 amount
);
/**
* @dev Perform custom transfer logic via delegate call from source contract to a TransferStrategy implementation
* @param to Account to transfer rewards
* @param reward Address of the reward token
* @param amount Amount to transfer to the "to" address parameter
* @return Returns true bool if transfer logic succeeds
*/
function performTransfer(
address to,
address reward,
uint256 amount
) external returns (bool);
/**
* @return Returns the address of the Incentives Controller
*/
function getIncentivesController() external view returns (address);
/**
* @return Returns the address of the Rewards admin
*/
function getRewardsAdmin() external view returns (address);
/**
* @dev Perform an emergency token withdrawal only callable by the Rewards admin
* @param token Address of the token to withdraw funds from this contract
* @param to Address of the recipient of the withdrawal
* @param amount Amount of the withdrawal
*/
function emergencyWithdrawal(
address token,
address to,
uint256 amount
) external;
}// SPDX-License-Identifier: AGPL-3.0
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.10;
import {IAaveOracle} from "contracts/lending/core/interfaces/IAaveOracle.sol";
import {ITransferStrategyBase} from "../interfaces/ITransferStrategyBase.sol";
library RewardsDataTypes {
struct RewardsConfigInput {
uint88 emissionPerSecond;
uint256 totalSupply;
uint32 distributionEnd;
address asset;
address reward;
ITransferStrategyBase transferStrategy;
IAaveOracle rewardOracle;
}
struct UserAssetBalance {
address asset;
uint256 userBalance;
uint256 totalSupply;
}
struct UserData {
// Liquidity index of the reward distribution for the user
uint104 index;
// Amount of accrued rewards for the user since last user index update
uint128 accrued;
}
struct RewardData {
// Liquidity index of the reward distribution
uint104 index;
// Amount of reward tokens distributed per second
uint88 emissionPerSecond;
// Timestamp of the last reward index update
uint32 lastUpdateTimestamp;
// The end of the distribution of rewards (in seconds)
uint32 distributionEnd;
// Map of user addresses and their rewards data (userAddress => userData)
mapping(address => UserData) usersData;
}
struct AssetData {
// Map of reward token addresses and their data (rewardTokenAddress => rewardData)
mapping(address => RewardData) rewards;
// List of reward token addresses for the asset
mapping(uint128 => address) availableRewards;
// Count of reward tokens for the asset
uint128 availableRewardsCount;
// Number of decimals of the asset
uint8 decimals;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(
bytes32 hash,
bytes memory signature
) internal pure returns (address, RecoverError, bytes32) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (
address(0),
RecoverError.InvalidSignatureLength,
bytes32(signature.length)
);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(
bytes32 hash,
bytes memory signature
) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(
hash,
signature
);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError, bytes32) {
unchecked {
bytes32 s = vs &
bytes32(
0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(
hash,
r,
vs
);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError, bytes32) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (
uint256(s) >
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0
) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(
hash,
v,
r,
s
);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.20;
import {ECDSA} from "./ECDSA.sol";
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
bytes32 public constant PERMIT_TYPEHASH =
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);
/* //////////////////////////////////////////////////////////////
EVENTS
////////////////////////////////////////////////////////////// */
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(
address indexed owner,
address indexed spender,
uint256 amount
);
/* //////////////////////////////////////////////////////////////
METADATA STORAGE
////////////////////////////////////////////////////////////// */
string public name;
string public symbol;
uint8 public decimals;
/* //////////////////////////////////////////////////////////////
ERC20 STORAGE
////////////////////////////////////////////////////////////// */
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/* //////////////////////////////////////////////////////////////
EIP-2612 STORAGE
////////////////////////////////////////////////////////////// */
mapping(address => uint256) public nonces;
/* //////////////////////////////////////////////////////////////
CONSTRUCTOR
////////////////////////////////////////////////////////////// */
constructor(string memory _name, string memory _symbol, uint8 _decimals) {
name = _name;
symbol = _symbol;
decimals = _decimals;
}
/* //////////////////////////////////////////////////////////////
ERC20 LOGIC
////////////////////////////////////////////////////////////// */
function approve(
address spender,
uint256 amount
) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(
address to,
uint256 amount
) public virtual returns (bool) {
_beforeTokenTransfer(msg.sender, to, amount);
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
_beforeTokenTransfer(from, to, amount);
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max)
allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/* //////////////////////////////////////////////////////////////
EIP-2612 LOGIC
////////////////////////////////////////////////////////////// */
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address signer = ECDSA.recover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
PERMIT_TYPEHASH,
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(signer == owner, "INVALID_SIGNER");
allowance[signer][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/* //////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
////////////////////////////////////////////////////////////// */
function _mint(address to, uint256 amount) internal virtual {
_beforeTokenTransfer(address(0), to, amount);
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
_beforeTokenTransfer(from, address(0), amount);
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), 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 to 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 {}
}// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.20;
import {IRewardsController} from "../../../lending/periphery/rewards/interfaces/IRewardsController.sol";
interface IAToken {
function POOL() external view returns (address);
function getIncentivesController() external view returns (address);
function UNDERLYING_ASSET_ADDRESS() external view returns (address);
/**
* @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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*
* _Available since v4.7._
*/
interface IERC4626 {
event Deposit(
address indexed sender,
address indexed owner,
uint256 assets,
uint256 shares
);
event Withdraw(
address indexed sender,
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 unless due to integer overflow caused by an unreasonably large input.
*
* 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.
* While deposit of aToken is not affected by aave pool configrations, deposit of the aTokenUnderlying will need to deposit to aave
* so it is affected by current aave pool configuration.
* Reference: https://github.com/aave/aave-v3-core/blob/29ff9b9f89af7cd8255231bc5faf26c3ce0fb7ce/contracts/protocol/libraries/logic/ValidationLogic.sol#L57
* - 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 unless due to integer overflow caused by an unreasonably large input.
*/
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 to the aToken underlying.
* While redeem of aToken is not affected by aave pool configrations, redeeming of the aTokenUnderlying will need to redeem from aave
* so it is affected by current aave pool configuration.
* Reference: https://github.com/aave/aave-v3-core/blob/29ff9b9f89af7cd8255231bc5faf26c3ce0fb7ce/contracts/protocol/libraries/logic/ValidationLogic.sol#L87
* - 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.20;
import {IERC20} from "@openzeppelin/contracts-5/token/ERC20/IERC20.sol";
import {IPool} from "contracts/lending/core/interfaces/IPool.sol";
import {IRewardsController} from "contracts/lending/periphery/rewards/interfaces/IRewardsController.sol";
interface IStaticATokenLM {
struct SignatureParams {
uint8 v;
bytes32 r;
bytes32 s;
}
struct PermitParams {
address owner;
address spender;
uint256 value;
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
}
struct UserRewardsData {
uint128 rewardsIndexOnLastInteraction; // (in RAYs)
uint128 unclaimedRewards; // (in RAYs)
}
struct RewardIndexCache {
bool isRegistered;
uint248 lastUpdatedIndex;
}
event RewardTokenRegistered(address indexed reward, uint256 startIndex);
/**
* @notice Allows to deposit on Aave via meta-transaction
* https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
* @param depositor Address from which the funds to deposit are going to be pulled
* @param receiver Address that will receive the staticATokens, in the average case, same as the `depositor`
* @param assets The amount to deposit
* @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 depositToAave bool
* - `true` if the msg.sender comes with underlying tokens (e.g. USDC)
* - `false` if the msg.sender comes already with aTokens (e.g. aUSDC)
* @param deadline The deadline timestamp, type(uint256).max for max deadline
* @param sigParams Signature params: v,r,s
* @return uint256 The amount of StaticAToken minted, static balance
*/
function metaDeposit(
address depositor,
address receiver,
uint256 assets,
uint16 referralCode,
bool depositToAave,
uint256 deadline,
PermitParams calldata permit,
SignatureParams calldata sigParams
) external returns (uint256);
/**
* @notice Allows to withdraw from Aave via meta-transaction
* https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
* @param owner Address owning the staticATokens
* @param receiver Address that will receive the underlying withdrawn from Aave
* @param shares The amount of staticAToken to withdraw. If > 0, `assets` needs to be 0
* @param assets The amount of underlying/aToken to withdraw. If > 0, `shares` needs to be 0
* @param withdrawFromAave bool
* - `true` for the receiver to get underlying tokens (e.g. USDC)
* - `false` for the receiver to get aTokens (e.g. aUSDC)
* @param deadline The deadline timestamp, type(uint256).max for max deadline
* @param sigParams Signature params: v,r,s
* @return amountToBurn: StaticATokens burnt, static balance
* @return amountToWithdraw: underlying/aToken send to `receiver`, dynamic balance
*/
function metaWithdraw(
address owner,
address receiver,
uint256 shares,
uint256 assets,
bool withdrawFromAave,
uint256 deadline,
SignatureParams calldata sigParams
) external returns (uint256, uint256);
/**
* @notice Returns the Aave liquidity index of the underlying aToken, denominated rate here
* as it can be considered as an ever-increasing exchange rate
* @return The liquidity index
**/
function rate() external view returns (uint256);
/**
* @notice Claims rewards from `INCENTIVES_CONTROLLER` and updates internal accounting of rewards.
* @param reward The reward to claim
* @return uint256 Amount collected
*/
function collectAndUpdateRewards(address reward) external returns (uint256);
/**
* @notice Claim rewards on behalf of a user and send them to a receiver
* @dev Only callable by if sender is onBehalfOf or sender is approved claimer
* @param onBehalfOf The address to claim on behalf of
* @param receiver The address to receive the rewards
* @param rewards The rewards to claim
*/
function claimRewardsOnBehalf(
address onBehalfOf,
address receiver,
address[] memory rewards
) external;
/**
* @notice Claim rewards and send them to a receiver
* @param receiver The address to receive the rewards
* @param rewards The rewards to claim
*/
function claimRewards(address receiver, address[] memory rewards) external;
/**
* @notice Claim rewards
* @param rewards The rewards to claim
*/
function claimRewardsToSelf(address[] memory rewards) external;
/**
* @notice Get the total claimable rewards of the contract.
* @param reward The reward to claim
* @return uint256 The current balance + pending rewards from the `_incentivesController`
*/
function getTotalClaimableRewards(
address reward
) external view returns (uint256);
/**
* @notice Get the total claimable rewards for a user in WAD
* @param user The address of the user
* @param reward The reward to claim
* @return uint256 The claimable amount of rewards in WAD
*/
function getClaimableRewards(
address user,
address reward
) external view returns (uint256);
/**
* @notice The unclaimed rewards for a user in WAD
* @param user The address of the user
* @param reward The reward to claim
* @return uint256 The unclaimed amount of rewards in WAD
*/
function getUnclaimedRewards(
address user,
address reward
) external view returns (uint256);
/**
* @notice The underlying asset reward index in RAY
* @param reward The reward to claim
* @return uint256 The underlying asset reward index in RAY
*/
function getCurrentRewardsIndex(
address reward
) external view returns (uint256);
/**
* @notice The aToken used inside the 4626 vault.
* @return IERC20 The aToken IERC20.
*/
function aToken() external view returns (IERC20);
/**
* @notice The IERC20s that are currently rewarded to addresses of the vault via LM on incentivescontroller.
* @return IERC20 The IERC20s of the rewards.
*/
function rewardTokens() external view returns (address[] memory);
/**
* @notice Fetches all rewardTokens from the incentivecontroller and registers the missing ones.
*/
function refreshRewardTokens() external;
/**
* @notice Checks if the passed token is a registered reward.
* @return bool signaling if token is a registered reward.
*/
function isRegisteredRewardToken(
address reward
) external view returns (bool);
/**
* @notice Deposits aTokens and mints static aTokens to the receiver
* @param aTokenAmount The amount of aTokens to deposit
* @param receiver The address that will receive the static aTokens
* @return uint256 The amount of StaticAToken minted, static balance
*/
function depositATokens(
uint256 aTokenAmount,
address receiver
) external returns (uint256);
/**
* @notice Burns static aTokens and returns aTokens to the receiver
* @param shares The amount of static aTokens to burn
* @param receiver The address that will receive the aTokens
* @param owner The address whose static aTokens will be burned
* @return uint256 The amount of aTokens returned
*/
function redeemATokens(
uint256 shares,
address receiver,
address owner
) external returns (uint256);
}// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.20;
import {Math} from "@openzeppelin/contracts-5/utils/math/Math.sol";
enum Rounding {
UP,
DOWN
}
/**
* Simplified version of RayMath that instead of half-up rounding does explicit rounding in a specified direction.
* This is needed to have a 4626 complient implementation, that always predictable rounds in favor of the vault / static a token.
*/
library RayMathExplicitRounding {
uint256 internal constant RAY = 1e27;
uint256 internal constant WAD_RAY_RATIO = 1e9;
function rayMulRoundDown(
uint256 a,
uint256 b
) internal pure returns (uint256) {
if (a == 0 || b == 0) {
return 0;
}
return Math.mulDiv(a, b, RAY); // default is rounding down
}
function rayMulRoundUp(
uint256 a,
uint256 b
) internal pure returns (uint256) {
if (a == 0 || b == 0) {
return 0;
}
return Math.mulDiv(a, b, RAY, Math.Rounding.Ceil);
}
function rayDivRoundDown(
uint256 a,
uint256 b
) internal pure returns (uint256) {
return Math.mulDiv(a, RAY, b); // rounding down
}
function rayDivRoundUp(
uint256 a,
uint256 b
) internal pure returns (uint256) {
return Math.mulDiv(a, RAY, b, Math.Rounding.Ceil);
}
function rayToWadRoundDown(uint256 a) internal pure returns (uint256) {
return a / WAD_RAY_RATIO;
}
}// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.20;
library StaticATokenErrors {
string public constant INVALID_OWNER = "1";
string public constant INVALID_EXPIRATION = "2";
string public constant INVALID_SIGNATURE = "3";
string public constant INVALID_DEPOSITOR = "4";
string public constant INVALID_RECIPIENT = "5";
string public constant INVALID_CLAIMER = "6";
string public constant ONLY_ONE_AMOUNT_FORMAT_ALLOWED = "7";
string public constant INVALID_ZERO_AMOUNT = "8";
string public constant REWARD_NOT_INITIALIZED = "9";
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"viaIR": true,
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IPool","name":"pool","type":"address"},{"internalType":"contract IRewardsController","name":"rewardsController","type":"address"},{"internalType":"address","name":"newAToken","type":"address"},{"internalType":"string","name":"staticATokenName","type":"string"},{"internalType":"string","name":"staticATokenSymbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"MathOverflowedMulDiv","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","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":true,"internalType":"address","name":"reward","type":"address"},{"indexed":false,"internalType":"uint256","name":"startIndex","type":"uint256"}],"name":"RewardTokenRegistered","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":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","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":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"METADEPOSIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"METAWITHDRAWAL_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POOL","outputs":[{"internalType":"contract IPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REWARDS_CONTROLLER","outputs":[{"internalType":"contract IRewardsController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STATIC__ATOKEN_LM_REVISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"aToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","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":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address[]","name":"rewards","type":"address[]"}],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"onBehalfOf","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address[]","name":"rewards","type":"address[]"}],"name":"claimRewardsOnBehalf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"rewards","type":"address[]"}],"name":"claimRewardsToSelf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"reward","type":"address"}],"name":"collectAndUpdateRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","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":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"aTokenAmount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"depositATokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"reward","type":"address"}],"name":"getClaimableRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"reward","type":"address"}],"name":"getCurrentRewardsIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"reward","type":"address"}],"name":"getTotalClaimableRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"reward","type":"address"}],"name":"getUnclaimedRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"reward","type":"address"}],"name":"isRegisteredRewardToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"depositor","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint16","name":"referralCode","type":"uint16"},{"internalType":"bool","name":"depositToAave","type":"bool"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct IStaticATokenLM.PermitParams","name":"permit","type":"tuple"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct IStaticATokenLM.SignatureParams","name":"sigParams","type":"tuple"}],"name":"metaDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"bool","name":"withdrawFromAave","type":"bool"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct IStaticATokenLM.SignatureParams","name":"sigParams","type":"tuple"}],"name":"metaWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","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":[],"name":"rate","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":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeemATokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"refreshRewardTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60c080604052346200048757620049fa803803809162000020828562000739565b8339810160a082820312620004875781516001600160a01b038116810362000487576020830151916001600160a01b0383168303620004875762000067604085016200075d565b60608501519094906001600160401b0381116200048757826200008c91830162000772565b60808201519092906001600160401b0381116200048757620000af920162000772565b60405163313ce56760e01b8152916020836004816001600160a01b038a165afa9283156200044557600093620006ee575b508051906001600160401b038211620005e25760005490600182811c92168015620006e3575b6020831014620005c15781601f84931162000680575b50602090601f83116001146200060457600092620005f8575b50508160011b916000199060031b1c1916176000555b8051906001600160401b038211620005e257600154600181811c91168015620005d7575b6020821014620005c157601f811162000568575b50602090601f8311600114620004ea5760ff93929160009183620004de575b50508160011b916000199060031b1c1916176001555b600280549190921660ff1990911617905560805260a052600780546001600160a01b03929092166001600160a01b031992831681179091556040516358b50cef60e11b815290602090829060049082905afa908115620004455760009162000495575b50600880546001600160a01b0392831693168317905560805160405163095ea7b360e01b815291166004820152600019602482015290602090829060449082906000905af18015620004455762000451575b5060a0516001600160a01b031680620002fe575b6040516140159081620009a58239608051818181610f89015281816110e8015281816112de0152818161169b01528181611fc4015281816122ae015281816127a8015281816134b7015261368f015260a051818181610b4b0152818161196201528181611e2b015281816125780152818161269301526128ff0152f35b600060018060a01b0360075416602460405180948193636657732f60e01b835260048301525afa908115620004455760009162000377575b5060005b81518110156200036e57600581901b8201602001516001919062000367906001600160a01b0316620007e8565b016200033a565b50503862000281565b3d8083833e62000388818362000739565b81019060208183031262000441578051906001600160401b0382116200043d57019181601f8401121562000426578251926001600160401b03841162000429578360051b9160405194620003e0602085018762000739565b8552602080860193830101938411620004265750602001905b8282106200040b575050503862000336565b602080916200041a846200075d565b815201910190620003f9565b80fd5b634e487b7160e01b82526041600452602482fd5b8380fd5b8280fd5b6040513d6000823e3d90fd5b6020813d6020116200048c575b816200046d6020938362000739565b81010312620004875751801515036200048757386200026d565b600080fd5b3d91506200045e565b90506020813d602011620004d5575b81620004b36020938362000739565b810103126200048757600091620004cc6020926200075d565b9150916200021b565b3d9150620004a4565b015190503880620001a2565b60016000908152600080516020620049da833981519152929190601f198516905b8181106200054f575091600193918560ff9796941062000535575b505050811b01600155620001b8565b015160001960f88460031b161c1916905538808062000526565b929360206001819287860151815501950193016200050b565b6001600052600080516020620049da833981519152601f840160051c81019160208510620005b6575b601f0160051c01905b818110620005a9575062000183565b600081556001016200059a565b909150819062000591565b634e487b7160e01b600052602260045260246000fd5b90607f16906200016f565b634e487b7160e01b600052604160045260246000fd5b01519050388062000135565b60008080529350600080516020620049ba83398151915291905b601f198416851062000664576001945083601f198116106200064a575b505050811b016000556200014b565b015160001960f88460031b161c191690553880806200063b565b818101518355602094850194600190930192909101906200061e565b60008052909150600080516020620049ba833981519152601f840160051c81019160208510620006d8575b90601f859493920160051c01905b818110620006c857506200011c565b60008155849350600101620006b9565b9091508190620006ab565b91607f169162000106565b6020939193813d60201162000730575b816200070d6020938362000739565b810103126200072c57519060ff821682036200042657509138620000e0565b5080fd5b3d9150620006fe565b601f909101601f19168101906001600160401b03821190821017620005e257604052565b51906001600160a01b03821682036200048757565b919080601f84011215620004875782516001600160401b038111620005e25760209060405192620007ad83601f19601f850116018562000739565b818452828287010111620004875760005b818110620007d457508260009394955001015290565b8581018301518482018401528201620007be565b60018060a01b03811690600090828252600a60205260409060ff82842054166200090257620008179062000908565b916009546801000000000000000081101562000429576001810180600955811015620008ee57600982527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0180546001600160a01b031916851790558151908183016001600160401b0381118382101762000429578352600182526001600160f01b0384166020808401918252868352600a8152918490209251905160081b60ff191690151560ff161790915590519182527fa8f4dd7e60441ca288d902a295362002a0255a46560b24825821b36716d6fe5b91a2565b634e487b7160e01b82526032600452602482fd5b50505050565b6001600160a01b039081169081156200099d5760a0516007546040805163886fe70b60e01b81529184166004830152602482019490945291839183916044918391165afa91821562000993576000926200096157505090565b90809250813d83116200098b575b6200097b818362000739565b8101031262000487576020015190565b503d6200096f565b513d6000823e3d90fd5b505060009056fe6080604052600436101561001257600080fd5b60003560e01c806301e1d1141461033d57806306fdde031461033857806307a2d13a146102f2578063090edf9a14610333578063095ea7b31461032e5780630a28a4771461032957806318160ddd146103245780632026ffa31461031f57806323b872dd1461031a5780632c4e722e146103155780632f813b0d1461031057806330adf81f1461030b578063313ce567146103065780633644e5151461030157806338d52e0f146102fc578063402d267d146102f75780634cdad506146102f257806360266557146102ed57806360d8fdd8146102e857806363210537146102e35780636e553f65146102de5780636fe0b5a5146102d957806370a08231146102d45780637535d246146102cf5780637ecebe00146102ca57806386894b29146102c55780638d948415146102c05780638daaf5aa146102bb57806394bf804d146102b657806395d89b41146102b1578063a0c1f15e146102ac578063a9059cbb146102a7578063b3d7f6b9146102a2578063b460af941461029d578063ba08765214610298578063bcd1784814610293578063c2b18aa01461028e578063c63d75b614610289578063c6e6f59214610257578063cd086d4514610284578063ce96cb771461027f578063d505accf1461027a578063d905777e14610275578063dd62ed3e14610270578063de9cee981461026b578063e25ec34914610266578063ea9be77c14610261578063ee0fc6d31461025c578063ef8b30f714610257578063f56f4f0f146102525763fa7146101461024d57600080fd5b611ed8565b611e9d565b611926565b611d93565b611d21565b611c0c565b611be5565b611ba0565b611b7e565b6119d4565b611991565b61194c565b611900565b61187a565b611816565b611714565b6115a0565b61157a565b611482565b611459565b6113b2565b611236565b6111fc565b6111c1565b611179565b611117565b6110d2565b611095565b611053565b610efb565b610ec0565b610e99565b610cc3565b6105af565b610c82565b610c59565b610c3e565b610c1d565b610be2565b610ae8565b610acd565b610913565b6108ca565b6107fc565b6107d6565b610747565b61061a565b6104c8565b610352565b600091031261034d57565b600080fd5b3461034d57600036600319011261034d576007546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156103d6576020916000916103a9575b50604051908152f35b6103c99150823d84116103cf575b6103c1818361045e565b810190611ef4565b386103a0565b503d6103b7565b611f03565b90600182811c9216801561040b575b60208310146103f557565b634e487b7160e01b600052602260045260246000fd5b91607f16916103ea565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161043e57604052565b610415565b604081019081106001600160401b0382111761043e57604052565b90601f801991011681019081106001600160401b0382111761043e57604052565b6020808252825181830181905290939260005b8281106104b457505060409293506000838284010152601f8019910116010190565b818101860151848201604001528501610492565b3461034d576000806003193601126105ac5760405190808054906104eb826103db565b8085529160209160019182811690811561057f5750600114610528575b610524866105188188038261045e565b6040519182918261047f565b0390f35b80809550527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5635b83851061056c575050505081016020016105188261052438610508565b805486860184015293820193810161054f565b90508695506105249693506020925061051894915060ff191682840152151560051b820101929338610508565b80fd5b3461034d57602036600319011261034d5760206105d56105cd611f97565b6004356139fd565b604051908152f35b6001600160a01b0381160361034d57565b606090600319011261034d576004359060243561060a816105dd565b90604435610617816105dd565b90565b3461034d576105246106c461062e366105ee565b92919061064461063c611f2a565b831515611f47565b61065561064f611f97565b836139fd565b93849261066b610663611f2a565b851515611f47565b60018060a01b039061068781838516948533036106d457612c78565b604080518681526020810192909252918416913391600080516020613f608339815191529190a46007546001600160a01b0316612d45565b612d45565b6040519081529081906020820190565b600086815260056020908152604080832033845290915290205b548260018201610700575b5050612c78565b61070991611f85565b6001600160a01b038216600090815260056020526040902061073f9033905b9060018060a01b0316600052602052604060002090565b5538826106f9565b3461034d57604036600319011261034d57600435610764816105dd565b60243590336000526005602052816107928260406000209060018060a01b0316600052602052604060002090565b556040519182526001600160a01b03169033907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590602090a3602060405160018152f35b3461034d57602036600319011261034d5760206105d56107f4611f97565b600435613c65565b3461034d57600036600319011261034d576020600354604051908152f35b604051906101e082018281106001600160401b0382111761043e57604052565b6040519061084782610443565b565b6001600160401b03811161043e5760051b60200190565b9080601f8301121561034d57602090823561087a81610849565b93610888604051958661045e565b81855260208086019260051b82010192831161034d57602001905b8282106108b1575050505090565b83809183356108bf816105dd565b8152019101906108a3565b3461034d57604036600319011261034d576004356108e7816105dd565b602435906001600160401b03821161034d5761090a610911923690600401610860565b9033612d94565b005b3461034d57606036600319011261034d57600435610930816105dd565b60243561093c816105dd565b60009160443591906001600160a01b0380821680151591841680151591875b600980548210156109d7578952600080516020613fa08339815191528101546001919086906001600160a01b0316610992816128c7565b916109c7575b86806109bd575b6109ac575b50500161095b565b6109b6918a613b47565b38806109a4565b508585141561099f565b6109d281838b613b47565b610998565b5050600080516020613f80833981519152610a8a88610a7489610a4d8a610a26610a138260018060a01b03166000526005602052604060002090565b3360009081526020919091526040902090565b548560018201610a99575b50506001600160a01b0316600090815260046020526040902090565b610a58848254611f85565b90556001600160a01b0316600090815260046020526040902090565b8054820190556040519081529081906020820190565b0390a360405160018152602090f35b610aa291611f85565b6001600160a01b0382166000908152600560205260409020610ac5903390610728565b558985610a31565b3461034d57600036600319011261034d5760206105d5611f97565b3461034d576000806003193601126105ac57600754610b4791908190610b1e906001600160a01b03165b6001600160a01b031690565b604051636657732f60e01b81526001600160a01b03909116600482015292839081906024820190565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9182156103d6578192610bbe575b50805b8251811015610bba5780610bb4610baf610ba2600194876120c7565b516001600160a01b031690565b612fd3565b01610b86565b5080f35b610bdb9192503d8084833e610bd3818361045e565b81019061201c565b9038610b83565b3461034d57600036600319011261034d5760206040517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98152f35b3461034d57600036600319011261034d57602060ff60025416604051908152f35b3461034d57600036600319011261034d5760206105d56130c4565b3461034d57600036600319011261034d576008546040516001600160a01b039091168152602090f35b3461034d57602036600319011261034d57610c9e6004356105dd565b60206105d561227f565b8015150361034d57565b60609060c319011261034d5760c490565b3461034d5761012036600319011261034d57610e87600435610ce4816105dd565b602435610cf0816105dd565b6044356064359160843593610d0485610ca8565b610e82610d47610e73610b1260a4358960018a610e2c610e388c8b8d610dee610d2c36610cb2565b99888060a01b0384169d8e610d3f612442565b901515611f47565b610d5b610d5261245f565b42831015611f47565b6001600160a01b038416600090815260066020526040902054809a610d7e6130c4565b9960405197889660208801988993909260e09592989796936101008601997f406ef09971b1bfa50a48ce277d3302602d78c94d58a376e8953b590702de7b31875260018060a01b03809216602088015216604086015260608501526080840152151560a083015260c08201520152565b0391610e02601f199384810183528261045e565b519020604051938491602083019687909160429261190160f01b8352600283015260228201520190565b0390810183528261045e565b5190209101610e598860018060a01b03166000526006602052604060002090565b55610e6382612496565b60206040840135930135916132dc565b14610e7c6124a0565b90611f47565b6133c6565b60408051928352602083019190915290f35b3461034d57602036600319011261034d5760206105d5600435610ebb816105dd565b612506565b3461034d57600036600319011261034d5760206040517f2a83c73b9e01ec0a1b95ff05940d809179668cc004230412d7047ffac3846ce78152f35b3461034d57604036600319011261034d57602435600435610f1b826105dd565b6001600160a01b039082821690610f3361063c6132f4565b610f3b613311565b50610f4f610f4761227f565b821115613582565b610f60610f5a611f97565b82613de1565b92610f6c610663611f2a565b6008546001600160a01b031690610f87833033848616613785565b7f000000000000000000000000000000000000000000000000000000000000000016803b1561034d5760405163e8eda9df60e01b81526001600160a01b0392909216600483015260248201839052306044830152600060648301819052908290608490829084905af180156103d65760209561100a92869261103a575b506137dd565b60408051918252602082018490523391600080516020613fc083398151915291819081015b0390a3604051908152f35b8061104761104d9261042b565b80610342565b38611004565b3461034d57602036600319011261034d57600435611070816105dd565b60018060a01b0316600052600a602052602060ff604060002054166040519015158152f35b3461034d57602036600319011261034d576004356110b2816105dd565b60018060a01b031660005260046020526020604060002054604051908152f35b3461034d57600036600319011261034d576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461034d57602036600319011261034d57600435611134816105dd565b60018060a01b031660005260066020526020604060002054604051908152f35b604090600319011261034d5760043561116c816105dd565b90602435610617816105dd565b3461034d5760206111b561118c36611154565b6001600160a01b039182166000908152600b855260408082209290931681526020919091522090565b5460801c604051908152f35b3461034d57600036600319011261034d5760206040517f406ef09971b1bfa50a48ce277d3302602d78c94d58a376e8953b590702de7b318152f35b3461034d57602036600319011261034d576004356001600160401b03811161034d5761122f610911913690600401610860565b3333612d94565b3461034d57604036600319011261034d57602435600435611256826105dd565b6001600160a01b03908282169061126e61063c6132f4565b801590811591826113aa575b61128690610e7c613311565b906000901561138857506112a361129b6126c7565b8211156135ce565b6112b46112ae611f97565b82613298565b925b6112c161063c611f2a565b6008546001600160a01b0316906112dc853033848616613785565b7f000000000000000000000000000000000000000000000000000000000000000016803b1561034d5760405163e8eda9df60e01b81526001600160a01b0392909216600483015260248201859052306044830152600060648301819052908290608490829084905af180156103d65760209561135e92849261103a57506137dd565b6040805184815260208101929092523391600080516020613fc0833981519152918190810161102f565b92905061139361227f565b506113a461139f611f97565b613dd7565b906112b6565b50600161127a565b3461034d576000806003193601126105ac57604051908060018054906113d7826103db565b808652926020926001811690811561057f575060011461140157610524866105188188038261045e565b9350600184527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b838510611446575050505081016020016105188261052438610508565b8054868601840152938201938101611429565b3461034d57600036600319011261034d576007546040516001600160a01b039091168152602090f35b3461034d57604036600319011261034d5760043561149f816105dd565b600090602435906001600160a01b038116331515811515855b60098054821015611534578752600080516020613fa08339815191528101546001919084906001600160a01b03166114ef816128c7565b91611524575b848061151a575b611509575b5050016114b8565b6115139188613b47565b3880611501565b50863314156114fc565b61152f818333613b47565b6114f5565b33600090815260046020526040902085908890611552908990610a4d565b8054820190556040519081523390600080516020613f80833981519152908060208101610a8a565b3461034d57602036600319011261034d5760206105d5611598611f97565b600435613298565b3461034d5761169760206115b3366105ee565b6001600160a01b03828116949390916115d56115cd6132f4565b871515611f47565b6115dd613311565b506115e961063c611f2a565b6116056115fd6115f88361277a565b612c6c565b83111561332e565b611616611610611f97565b83613c65565b9561162b87858416938433036116f157612c78565b60408051848152602081018990523391600080516020613f6083398151915291a46008546000906001600160a01b03165b604051631a4ca37b60e21b81526001600160a01b03918216600482015260248101939093529093166044820152948592839182906064820190565b03927f0000000000000000000000000000000000000000000000000000000000000000165af19182156103d6576020926116d45750604051908152f35b6116ea90833d85116103cf576103c1818361045e565b50386103a0565b6001600160a01b03811660009081526005602052604090206106ee903390610728565b3461034d57611697611725366105ee565b6001600160a01b03808316929161173d6106636132f4565b8415938415948561180e575b61175590610e7c613311565b611766611760611f2a565b86611f47565b60009594156117e85760209495506117886117808361277a565b87111561337a565b611799611793611f97565b876139fd565b955b6117af81858516948533036116f157612c78565b6040805188815260208101929092523391600080516020613f608339815191529190a460085484906000906001600160a01b031661165c565b602094506117f86115f88361277a565b50611809611804611f97565b613c40565b61179b565b506001611749565b3461034d57602036600319011261034d5760206105d5600435611838816105dd565b612627565b90815180825260208080930193019160005b82811061185d575050505090565b83516001600160a01b03168552938101939281019260010161184f565b3461034d57600036600319011261034d5760405180600954918281526020809101926009600052600080516020613fa0833981519152916000905b8282106118e057610524856118cc8189038261045e565b60405191829160208352602083019061183d565b83546001600160a01b0316865294850194600193840193909101906118b5565b3461034d57602036600319011261034d5761191c6004356105dd565b60206105d56126c7565b3461034d57602036600319011261034d5760206105d5611944611f97565b600435613de1565b3461034d57600036600319011261034d576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461034d57602036600319011261034d5760206105d56119bb6004356119b6816105dd565b61277a565b6119c3611f97565b906139fd565b60ff81160361034d57565b3461034d5760e036600319011261034d576004356119f1816105dd565b6024356119fd816105dd565b7f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560443592611b34606435611b18608435611a37816119c9565b611a43428410156126f1565b611b24611a4e6130c4565b93888a611ada611a708a60018060a01b03166000526006602052604060002090565b9384549460018601905560405194859360208501958d8791959493909260a09360c08401977f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98552600180871b038092166020860152166040840152606083015260808201520152565b0391611aee601f199384810183528261045e565b519020604051948591602083019788909160429261190160f01b8352600283015260228201520190565b0390810184528361045e565b60c4359260a435925190206132dc565b9284611b6f8261072860018060a01b0380961697611b55898883161461273d565b6001600160a01b0316600090815260056020526040902090565b556040519485521692602090a3005b3461034d57602036600319011261034d5760206105d56004356119b6816105dd565b3461034d576020611bdc611bb336611154565b6001600160a01b0391821660009081526005855260408082209290931681526020919091522090565b54604051908152f35b3461034d57602036600319011261034d5760206105d5600435611c07816105dd565b6128c7565b3461034d57604036600319011261034d57600435602435611c2c816105dd565b611c3761063c611f2a565b6007546040516370a0823160e01b81523360048201526001600160a01b03918216929190602081602481875afa80156103d65761052495600080516020613fc083398151915292600092611cf4575b5081811115611cec5750915b611cbe83611ca1610f5a611f97565b96611cb5611cad611f2a565b891515611f47565b30903390613785565b611cc885856137dd565b60408051938452602084018690529316923392a36040519081529081906020820190565b905091611c92565b611d0e91925060203d6020116103cf576103c1818361045e565b9038611c86565b61ffff81160361034d57565b3461034d5761020036600319011261034d57600435611d3f816105dd565b60243590611d4c826105dd565b60643591611d5983611d15565b608435611d6581610ca8565b60e03660c319011261034d576060366101a319011261034d57610524936106c49360a4359360443591612a56565b3461034d57606036600319011261034d57600435611db0816105dd565b602435611dbc816105dd565b6044356001600160401b03811161034d57611ddb903690600401610860565b336001600160a01b0384811691821494929392918515611e0c575b5050611e0761091194610e7c612c4f565b612d94565b90945060405190631d36517b60e21b82526004820152602081602481887f0000000000000000000000000000000000000000000000000000000000000000165afa9485156103d65761091195611e0792600091611e6e575b5016331494611df6565b611e90915060203d602011611e96575b611e88818361045e565b810190612c3a565b38611e64565b503d611e7e565b3461034d5760206105d5611eb036611154565b6001600160a01b038216600090815260048552604090205490611ed2816128c7565b92613903565b3461034d57600036600319011261034d57602060405160028152f35b9081602091031261034d575190565b6040513d6000823e3d90fd5b6001600160401b03811161043e57601f01601f191660200190565b60405190611f3782610443565b60018252600760fb1b6020830152565b15611f4f5750565b60405162461bcd60e51b8152908190611f6b906004830161047f565b0390fd5b634e487b7160e01b600052601160045260246000fd5b91908203918211611f9257565b611f6f565b60085460405163d15e005360e01b81526001600160a01b03918216600482015290602090829060249082907f0000000000000000000000000000000000000000000000000000000000000000165afa9081156103d657600091611ff8575090565b610617915060203d6020116103cf576103c1818361045e565b5190610847826105dd565b602090818184031261034d578051906001600160401b03821161034d57019180601f8401121561034d57825161205181610849565b9361205f604051958661045e565b818552838086019260051b82010192831161034d578301905b828210612086575050505090565b8380918351612094816105dd565b815201910190612078565b634e487b7160e01b600052603260045260246000fd5b8051156120c25760200190565b61209f565b80518210156120c25760209160051b010190565b919082602091031261034d57604051602081018181106001600160401b0382111761043e5760405291518252565b51906001600160801b038216820361034d57565b519064ffffffffff8216820361034d57565b519061084782611d15565b6101e08183031261034d5761215761215061081a565b92826120db565b825261216560208201612109565b602083015261217660408201612109565b604083015261218760608201612109565b606083015261219860808201612109565b60808301526121a960a08201612109565b60a08301526121ba60c0820161211d565b60c08301526121cb60e0820161212f565b60e08301526101006121de818301612011565b908301526101206121f0818301612011565b90830152610140612202818301612011565b90830152610160612214818301612011565b90830152610180612226818301612109565b908301526101a0612238818301612109565b9083015261224a6101c0809201612109565b9082015290565b604d8111611f9257600a0a90565b81810292918115918404141715611f9257565b91908201809211611f9257565b6008546040516335ea6a7560e01b81526001600160a01b0391821660048201526101e0918290829060249082907f0000000000000000000000000000000000000000000000000000000000000000165afa9182156103d657600092612415575b5050805151600160381b8116158015612406575b80156123f3575b6123ec5780640fffffffff61231760ff6123219460301c16612251565b9160741c1661225f565b9081156123e4576101008101516004919060209061234990610b12906001600160a01b031681565b60405163b1bf962d60e01b815293849182905afa80156103d6576123a16123a7916123ad946000916123c5575b5061239b61238f6101808601516001600160801b031690565b6001600160801b031690565b90612272565b9161320f565b90613298565b818111156123bc575050600090565b61061791611f85565b6123de915060203d6020116103cf576103c1818361045e565b38612376565b505060001990565b5050600090565b50670200000000000000811615156122fa565b506001603c1b811615156122f3565b6124349250803d1061243b575b61242c818361045e565b81019061213a565b38806122df565b503d612422565b6040519061244f82610443565b60018252603160f81b6020830152565b6040519061246c82610443565b60018252601960f91b6020830152565b61014435610617816119c9565b6101a435610617816119c9565b35610617816119c9565b604051906124ad82610443565b60018252603360f81b6020830152565b604051906124ca82610443565b6001825260203681840137565b916124ef60409295949560608552606085019061183d565b6001600160a01b0391821660208501529416910152565b6001600160a01b03818116801561261f5761251f6124bd565b60075461255090612538906001600160a01b0316610b12565b612541836120b5565b6001600160a01b039091169052565b60405180936370674ab960e01b8252818061257460209889963090600485016124d7565b03917f0000000000000000000000000000000000000000000000000000000000000000165afa9182156103d657600092612600575b506040516370a0823160e01b8152306004820152908390829060249082905afa9081156103d657610617936000926125e3575b5050612272565b6125f99250803d106103cf576103c1818361045e565b38806125dc565b612618919250833d85116103cf576103c1818361045e565b90386125a9565b505050600090565b6001600160a01b039081169081156123ec5761267c6020916126476124bd565b8160075416612655826120b5565b5260006040518096819582946308d8c03760e21b845260806004850152608484019061183d565b9083196024840152306044840152606483015203927f0000000000000000000000000000000000000000000000000000000000000000165af19081156103d657600091611ff8575090565b6126cf61227f565b600019908082146126ed5761061791506126e7611f97565b90613de1565b5090565b156126f857565b60405162461bcd60e51b815260206004820152601760248201527f5045524d49545f444541444c494e455f455850495245440000000000000000006044820152606490fd5b1561274457565b60405162461bcd60e51b815260206004820152600e60248201526d24a72b20a624a22fa9a4a3a722a960911b6044820152606490fd5b6008546040516335ea6a7560e01b81526001600160a01b0391821660048201819052906101e09081816024817f000000000000000000000000000000000000000000000000000000000000000088165afa9182156103d6576000926128aa575b5050805151600160381b81161590811561289a575b506128915761010001516040516370a0823160e01b81526001600160a01b0390911660048201529160209183916024918391165afa9081156103d6576128609161284491600091612872575b506126e7611f97565b6001600160a01b03909216600090815260046020526040902090565b549081811061286d575090565b905090565b61288b915060203d6020116103cf576103c1818361045e565b3861283b565b50505050600090565b6001603c1b9150161515386127ef565b6128c09250803d1061243b5761242c818361045e565b38806127da565b6001600160a01b0390811680156123ec57604090604483600754168351948593849263886fe70b60e01b8452600484015260248301527f0000000000000000000000000000000000000000000000000000000000000000165afa9081156103d657600091612933575090565b90506040813d60401161295d575b8161294e6040938361045e565b8101031261034d576020015190565b3d9150612941565b6040519061297282610443565b60018252600d60fa1b6020830152565b7f2a83c73b9e01ec0a1b95ff05940d809179668cc004230412d7047ffac3846ce781526001600160a01b0391821660208201529181166040830152606082019290925261ffff909216608083015291151560a082015260c081019290925260e08201929092526101e0810192918060c4356129fc816105dd565b1661010083015260e435612a0f816105dd565b16610120820152610104356101408201526101243561016082015260ff61014435612a39816119c9565b16610180820152610164356101a08201526101c061018435910152565b6001600160a01b039581871690612a6b612965565b612a7790831515611f47565b612a7f61245f565b612a8c9042831015611f47565b6001600160a01b03831660009081526006602052604090205490612aae6130c4565b60405191826020810191612ac890868d8d8d8d8d89612982565b0392601f19938481018252612add908261045e565b51902060405161190160f01b6020820190815260228201939093526042810191909152606292830181529091612b13908261045e565b5190206001600160a01b038416600090815260066020526040902090916001019055612b3d612489565b6101e435906101c43590612b50936132dc565b6001600160a01b031614612b626124a0565b612b6b91611f47565b610124359586612b81575b506126ed955061361a565b8515612c20576008546001600160a01b03165b16612b9d61247c565b96813b1561034d5760405163d505accf60e01b81526001600160a01b0384166004820152306024820152610104356044820152606481019190915260ff9790971660848801526101643560a48801526101843560c48801526126ed9690600090829060e490829084905af115612b765780611047612c1a9261042b565b38612b76565b600754612c35906001600160a01b0316610b12565b612b94565b9081602091031261034d5751610617816105dd565b60405190612c5c82610443565b60018252601b60f91b6020830152565b610617906119c3611f97565b60009160005b60098054821015612cd6578452600080516020613fa0833981519152810154600191906001600160a01b03908116612cb5816128c7565b918616612cc5575b505001612c7e565b612ccf9186613b47565b3880612cbd565b50506001600160a01b038216600090815260046020526040902091925090805490828203918211611f9257600093600080516020613f8083398151915292612d409255612d268460035403600355565b6040519384526001600160a01b0316929081906020820190565b0390a3565b60405163a9059cbb60e01b60208201526001600160a01b03909216602483015260448083019390935291815260808101916001600160401b0383118284101761043e5761084792604052613a31565b92919060005b8251811015612fa757612db3610b12610ba283866120c7565b15612f9f57612dc8611c07610ba283866120c7565b90612dfd82612de98860018060a01b03166000526004602052604060002090565b54612df7610ba285896120c7565b89613903565b612e10610b12610b12610ba285896120c7565b6040516370a0823160e01b815230600482015291906020908190849060249082905afa9081156103d6576001958a948992600094612f80575b505082600093808611612f65575b50808511612f50575b508584612e75575b5050505050505b01612d9a565b612f4595612ed1612ef094612ebb610ba2612eeb95612eb5612e99612f349b613ade565b6001600160a01b039097166000908152600b6020526040902090565b936120c7565b60018060a01b0316600052602052604060002090565b906001600160801b0382549181199060801b169116179055565b613ade565b6001600160a01b038a166000908152600b60205260409020612f1990612ebb610ba2888c6120c7565b906001600160801b03166001600160801b0319825416179055565b846106bf610b12610ba2868a6120c7565b853880868185612e68565b809350612f5d9194611f85565b919238612e60565b612f7a915061239b611838610ba28a876120c7565b38612e57565b612f97929450803d106103cf576103c1818361045e565b913880612e49565b600190612e6f565b5050509050565b6009548110156120c2576009600052600080516020613fa08339815191520190600090565b6001600160a01b038181166000818152600a60205260409020549092919060ff166130bf57613001826128c7565b6009546801000000000000000081101561043e577fa8f4dd7e60441ca288d902a295362002a0255a46560b24825821b36716d6fe5b936130ba9361304e8360016106c49501600955612fae565b819291549060031b9189831b921b191617905561309a61306c61083a565b60018152916001600160f01b03851660208401526001600160a01b03166000908152600a6020526040902090565b815160209092015160081b60ff191660ff92151592909216919091179055565b0390a2565b505050565b604051600090600054906130d7826103db565b9283825260209384830193600190866001821691826000146131ef575050600114613198575b505091816131136131929361318495038261045e565b519020604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f95810195865260208601929092527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc69085015246606085015230608085015291829060a0850190565b03601f19810183528261045e565b51902090565b600080805286935091907f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5635b8284106131da57505050820101816131136130fd565b805486850186015287949093019281016131c4565b60ff1916875292151560051b8501909201925083915061311390506130fd565b60c081015164ffffffffff16428103613239575060200151610617906001600160801b031661238f565b6001600160801b0360408301511690420390428211611f92576301e13380916132619161225f565b04676765c793fa10079d601b1b908101809111611f925761329261238f60206106179401516001600160801b031690565b90613c05565b90811580156132d4575b6123ec57806132bd676765c793fa10079d601b1b9284613e81565b92096132c65790565b60018101809111611f925790565b5080156132a2565b9161061793916132eb93613c8c565b90929192613d30565b6040519061330182610443565b60018252603560f81b6020830152565b6040519061331e82610443565b60018252603760f81b6020830152565b1561333557565b60405162461bcd60e51b815260206004820152601f60248201527f455243343632363a207769746864726177206d6f7265207468616e206d6178006044820152606490fd5b1561338157565b60405162461bcd60e51b815260206004820152601d60248201527f455243343632363a2072656465656d206d6f7265207468616e206d61780000006044820152606490fd5b949390916001600160a01b0391828416916133ea6133e26132f4565b841515611f47565b8015958615968761357a575b61340290610e7c613311565b61341661340d611f2a565b82841415611f47565b80919660001461353a57505080613521575b613439613433611f97565b866139fd565b9687925b61345187868416938433036116f157612c78565b60408051858152602081018990523391600080516020613f6083398151915291a41561350557600854604051631a4ca37b60e21b81526001600160a01b0391821660048201526024810192909252929092166044830152602090829060649082906000907f0000000000000000000000000000000000000000000000000000000000000000165af180156103d6576134e857509190565b6135009060203d6020116103cf576103c1818361045e565b509190565b60075461351d939192506001600160a01b0316612d45565b9190565b61353561352d8861277a565b86111561337a565b613428565b819891939650613558908361355e575b613552611f97565b90613c65565b9561343d565b61357561356d6115f88561277a565b82111561332e565b61354a565b5080156133f6565b1561358957565b60405162461bcd60e51b815260206004820152601e60248201527f455243343632363a206465706f736974206d6f7265207468616e206d617800006044820152606490fd5b156135d557565b60405162461bcd60e51b815260206004820152601b60248201527f455243343632363a206d696e74206d6f7265207468616e206d617800000000006044820152606490fd5b919493926001600160a01b0380831693929161363f6136376132f4565b861515611f47565b85613648613311565b5061376d575b61365f613659611f97565b89613de1565b809661366c61063c611f2a565b1561373857506008546001600160a01b031661368c893087868516613785565b827f00000000000000000000000000000000000000000000000000000000000000001691823b1561034d5760405163e8eda9df60e01b81526001600160a01b03929092166004830152602482018a905230604483015261ffff166064820152906000908290608490829084905af180156103d657600080516020613fc08339815191529361372092889261103a57506137dd565b60408051888152602081018790529390911692a39190565b600754600080516020613fc083398151915294613720935090613768908b906001600160a01b0316883091613785565b6137dd565b61378061377861227f565b891115613582565b61364e565b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a08101918183106001600160401b0384111761043e5761084792604052613a31565b60009160005b60098054821015613848578452600080516020613fa0833981519152810154600191906001600160a01b0390811661381a816128c7565b918616151580613843575b613832575b5050016137e3565b61383c9186613b47565b388061382a565b613825565b5050915060035490828201809211611f9257612d40600080516020613f8083398151915291613878600094600355565b6001600160a01b03811660009081526004602052604090208054860190556040519485526001600160a01b0316939081906020820190565b604051906138bd82610443565b60018252603960f81b6020830152565b906040516138da81610443565b91546001600160801b038116835260801c6020830152565b60ff16604d8111611f9257600a0a90565b6139f0906106179461398a6139856139cd956107286139348260018060a01b0316600052600a602052604060002090565b9561396b6040519761394589610443565b5497602060ff8a16151591828152019860081c895260016139646138b0565b9114611f47565b6001600160a01b03166000908152600b6020526040902090565b6138cd565b9461399f61399a60025460ff1690565b6138f2565b926139b460208801516001600160801b031690565b966001600160801b03968791516001600160801b031690565b1690816139f757516001600160f81b031690505b6001600160f81b031690613dbd565b9116612272565b506139e1565b9081158015613a14575b6123ec5761061791613e81565b508015613a07565b9081602091031261034d575161061781610ca8565b600080613a7b9260018060a01b03169360208151910182865af13d15613ad6573d90613a5c82611f0f565b91613a6a604051938461045e565b82523d6000602084013e5b83613efc565b8051908115159182613ab4575b5050613a915750565b604051635274afe760e01b81526001600160a01b03919091166004820152602490fd5b613acf925090602080613acb938301019101613a1c565b1590565b3880613a88565b606090613a75565b6001600160801b0390818111613af2571690565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b610847926040612f1992613b7f60018060a01b0382169560009287845260046020528585852054918383613b9f575b50505050613ade565b948152600b602052209060018060a01b0316600052602052604060002090565b613bd793613bb093612eeb93613903565b888552600b60209081528686206001600160a01b0389166000908152915260409020612ed1565b38858183613b76565b634e487b7160e01b600052601260045260246000fd5b8115613c00570490565b613be0565b816b019d971e4fe8401e7400000019048111158215171561034d57676765c793fa10079d601b1b91026b019d971e4fe8401e74000000010490565b8015613c0057600090676765c793fa10079d601b1b600009613c5f5790565b50600190565b90613c708183613de1565b918115613c0057676765c793fa10079d601b1b90096132c65790565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411613d0457926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa156103d65780516001600160a01b03811615613cfb57918190565b50809160019190565b50505060009160039190565b60041115613d1a57565b634e487b7160e01b600052602160045260246000fd5b613d3981613d10565b80613d42575050565b613d4b81613d10565b60018103613d655760405163f645eedf60e01b8152600490fd5b613d6e81613d10565b60028103613d8f5760405163fce698f760e01b815260048101839052602490fd5b80613d9b600392613d10565b14613da35750565b6040516335e2f38360e21b81526004810191909152602490fd5b91908215612891578103908111611f9257613bf69161225f565b15613c0057600090565b676765c793fa10079d601b1b918183029160001984820993838086109503948086039514613e745784831115613e625782910981600003821680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b60405163227bc15360e01b8152600490fd5b5050906106179250613bf6565b908082029060001981840990828083109203918083039214613ee857676765c793fa10079d601b1b9082821115613e62577f2245cd4e1f3755e770b615377cde9082e11ad04b156637b5cd27412a54f5b6b5940990828211900360e51b9103601b1c170290565b5050676765c793fa10079d601b1b91500490565b90613f235750805115613f1157805190602001fd5b604051630a12f52160e11b8152600490fd5b81511580613f56575b613f34575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b15613f2c56fefbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8dbddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7afdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7a26469706673582212201eb2b81a2bdbb1e69d0c00691f863002172f09a4e65d7293c104bce7fc1fcaa464736f6c63430008180033290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000029d0256fe397f6e442464982c4cba7670646059b00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000001a5772617070656420645452494e495459204c656e64206455534400000000000000000000000000000000000000000000000000000000000000000000000000067764645553440000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c806301e1d1141461033d57806306fdde031461033857806307a2d13a146102f2578063090edf9a14610333578063095ea7b31461032e5780630a28a4771461032957806318160ddd146103245780632026ffa31461031f57806323b872dd1461031a5780632c4e722e146103155780632f813b0d1461031057806330adf81f1461030b578063313ce567146103065780633644e5151461030157806338d52e0f146102fc578063402d267d146102f75780634cdad506146102f257806360266557146102ed57806360d8fdd8146102e857806363210537146102e35780636e553f65146102de5780636fe0b5a5146102d957806370a08231146102d45780637535d246146102cf5780637ecebe00146102ca57806386894b29146102c55780638d948415146102c05780638daaf5aa146102bb57806394bf804d146102b657806395d89b41146102b1578063a0c1f15e146102ac578063a9059cbb146102a7578063b3d7f6b9146102a2578063b460af941461029d578063ba08765214610298578063bcd1784814610293578063c2b18aa01461028e578063c63d75b614610289578063c6e6f59214610257578063cd086d4514610284578063ce96cb771461027f578063d505accf1461027a578063d905777e14610275578063dd62ed3e14610270578063de9cee981461026b578063e25ec34914610266578063ea9be77c14610261578063ee0fc6d31461025c578063ef8b30f714610257578063f56f4f0f146102525763fa7146101461024d57600080fd5b611ed8565b611e9d565b611926565b611d93565b611d21565b611c0c565b611be5565b611ba0565b611b7e565b6119d4565b611991565b61194c565b611900565b61187a565b611816565b611714565b6115a0565b61157a565b611482565b611459565b6113b2565b611236565b6111fc565b6111c1565b611179565b611117565b6110d2565b611095565b611053565b610efb565b610ec0565b610e99565b610cc3565b6105af565b610c82565b610c59565b610c3e565b610c1d565b610be2565b610ae8565b610acd565b610913565b6108ca565b6107fc565b6107d6565b610747565b61061a565b6104c8565b610352565b600091031261034d57565b600080fd5b3461034d57600036600319011261034d576007546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156103d6576020916000916103a9575b50604051908152f35b6103c99150823d84116103cf575b6103c1818361045e565b810190611ef4565b386103a0565b503d6103b7565b611f03565b90600182811c9216801561040b575b60208310146103f557565b634e487b7160e01b600052602260045260246000fd5b91607f16916103ea565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161043e57604052565b610415565b604081019081106001600160401b0382111761043e57604052565b90601f801991011681019081106001600160401b0382111761043e57604052565b6020808252825181830181905290939260005b8281106104b457505060409293506000838284010152601f8019910116010190565b818101860151848201604001528501610492565b3461034d576000806003193601126105ac5760405190808054906104eb826103db565b8085529160209160019182811690811561057f5750600114610528575b610524866105188188038261045e565b6040519182918261047f565b0390f35b80809550527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5635b83851061056c575050505081016020016105188261052438610508565b805486860184015293820193810161054f565b90508695506105249693506020925061051894915060ff191682840152151560051b820101929338610508565b80fd5b3461034d57602036600319011261034d5760206105d56105cd611f97565b6004356139fd565b604051908152f35b6001600160a01b0381160361034d57565b606090600319011261034d576004359060243561060a816105dd565b90604435610617816105dd565b90565b3461034d576105246106c461062e366105ee565b92919061064461063c611f2a565b831515611f47565b61065561064f611f97565b836139fd565b93849261066b610663611f2a565b851515611f47565b60018060a01b039061068781838516948533036106d457612c78565b604080518681526020810192909252918416913391600080516020613f608339815191529190a46007546001600160a01b0316612d45565b612d45565b6040519081529081906020820190565b600086815260056020908152604080832033845290915290205b548260018201610700575b5050612c78565b61070991611f85565b6001600160a01b038216600090815260056020526040902061073f9033905b9060018060a01b0316600052602052604060002090565b5538826106f9565b3461034d57604036600319011261034d57600435610764816105dd565b60243590336000526005602052816107928260406000209060018060a01b0316600052602052604060002090565b556040519182526001600160a01b03169033907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590602090a3602060405160018152f35b3461034d57602036600319011261034d5760206105d56107f4611f97565b600435613c65565b3461034d57600036600319011261034d576020600354604051908152f35b604051906101e082018281106001600160401b0382111761043e57604052565b6040519061084782610443565b565b6001600160401b03811161043e5760051b60200190565b9080601f8301121561034d57602090823561087a81610849565b93610888604051958661045e565b81855260208086019260051b82010192831161034d57602001905b8282106108b1575050505090565b83809183356108bf816105dd565b8152019101906108a3565b3461034d57604036600319011261034d576004356108e7816105dd565b602435906001600160401b03821161034d5761090a610911923690600401610860565b9033612d94565b005b3461034d57606036600319011261034d57600435610930816105dd565b60243561093c816105dd565b60009160443591906001600160a01b0380821680151591841680151591875b600980548210156109d7578952600080516020613fa08339815191528101546001919086906001600160a01b0316610992816128c7565b916109c7575b86806109bd575b6109ac575b50500161095b565b6109b6918a613b47565b38806109a4565b508585141561099f565b6109d281838b613b47565b610998565b5050600080516020613f80833981519152610a8a88610a7489610a4d8a610a26610a138260018060a01b03166000526005602052604060002090565b3360009081526020919091526040902090565b548560018201610a99575b50506001600160a01b0316600090815260046020526040902090565b610a58848254611f85565b90556001600160a01b0316600090815260046020526040902090565b8054820190556040519081529081906020820190565b0390a360405160018152602090f35b610aa291611f85565b6001600160a01b0382166000908152600560205260409020610ac5903390610728565b558985610a31565b3461034d57600036600319011261034d5760206105d5611f97565b3461034d576000806003193601126105ac57600754610b4791908190610b1e906001600160a01b03165b6001600160a01b031690565b604051636657732f60e01b81526001600160a01b03909116600482015292839081906024820190565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9182156103d6578192610bbe575b50805b8251811015610bba5780610bb4610baf610ba2600194876120c7565b516001600160a01b031690565b612fd3565b01610b86565b5080f35b610bdb9192503d8084833e610bd3818361045e565b81019061201c565b9038610b83565b3461034d57600036600319011261034d5760206040517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98152f35b3461034d57600036600319011261034d57602060ff60025416604051908152f35b3461034d57600036600319011261034d5760206105d56130c4565b3461034d57600036600319011261034d576008546040516001600160a01b039091168152602090f35b3461034d57602036600319011261034d57610c9e6004356105dd565b60206105d561227f565b8015150361034d57565b60609060c319011261034d5760c490565b3461034d5761012036600319011261034d57610e87600435610ce4816105dd565b602435610cf0816105dd565b6044356064359160843593610d0485610ca8565b610e82610d47610e73610b1260a4358960018a610e2c610e388c8b8d610dee610d2c36610cb2565b99888060a01b0384169d8e610d3f612442565b901515611f47565b610d5b610d5261245f565b42831015611f47565b6001600160a01b038416600090815260066020526040902054809a610d7e6130c4565b9960405197889660208801988993909260e09592989796936101008601997f406ef09971b1bfa50a48ce277d3302602d78c94d58a376e8953b590702de7b31875260018060a01b03809216602088015216604086015260608501526080840152151560a083015260c08201520152565b0391610e02601f199384810183528261045e565b519020604051938491602083019687909160429261190160f01b8352600283015260228201520190565b0390810183528261045e565b5190209101610e598860018060a01b03166000526006602052604060002090565b55610e6382612496565b60206040840135930135916132dc565b14610e7c6124a0565b90611f47565b6133c6565b60408051928352602083019190915290f35b3461034d57602036600319011261034d5760206105d5600435610ebb816105dd565b612506565b3461034d57600036600319011261034d5760206040517f2a83c73b9e01ec0a1b95ff05940d809179668cc004230412d7047ffac3846ce78152f35b3461034d57604036600319011261034d57602435600435610f1b826105dd565b6001600160a01b039082821690610f3361063c6132f4565b610f3b613311565b50610f4f610f4761227f565b821115613582565b610f60610f5a611f97565b82613de1565b92610f6c610663611f2a565b6008546001600160a01b031690610f87833033848616613785565b7f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce216803b1561034d5760405163e8eda9df60e01b81526001600160a01b0392909216600483015260248201839052306044830152600060648301819052908290608490829084905af180156103d65760209561100a92869261103a575b506137dd565b60408051918252602082018490523391600080516020613fc083398151915291819081015b0390a3604051908152f35b8061104761104d9261042b565b80610342565b38611004565b3461034d57602036600319011261034d57600435611070816105dd565b60018060a01b0316600052600a602052602060ff604060002054166040519015158152f35b3461034d57602036600319011261034d576004356110b2816105dd565b60018060a01b031660005260046020526020604060002054604051908152f35b3461034d57600036600319011261034d576040517f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce26001600160a01b03168152602090f35b3461034d57602036600319011261034d57600435611134816105dd565b60018060a01b031660005260066020526020604060002054604051908152f35b604090600319011261034d5760043561116c816105dd565b90602435610617816105dd565b3461034d5760206111b561118c36611154565b6001600160a01b039182166000908152600b855260408082209290931681526020919091522090565b5460801c604051908152f35b3461034d57600036600319011261034d5760206040517f406ef09971b1bfa50a48ce277d3302602d78c94d58a376e8953b590702de7b318152f35b3461034d57602036600319011261034d576004356001600160401b03811161034d5761122f610911913690600401610860565b3333612d94565b3461034d57604036600319011261034d57602435600435611256826105dd565b6001600160a01b03908282169061126e61063c6132f4565b801590811591826113aa575b61128690610e7c613311565b906000901561138857506112a361129b6126c7565b8211156135ce565b6112b46112ae611f97565b82613298565b925b6112c161063c611f2a565b6008546001600160a01b0316906112dc853033848616613785565b7f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce216803b1561034d5760405163e8eda9df60e01b81526001600160a01b0392909216600483015260248201859052306044830152600060648301819052908290608490829084905af180156103d65760209561135e92849261103a57506137dd565b6040805184815260208101929092523391600080516020613fc0833981519152918190810161102f565b92905061139361227f565b506113a461139f611f97565b613dd7565b906112b6565b50600161127a565b3461034d576000806003193601126105ac57604051908060018054906113d7826103db565b808652926020926001811690811561057f575060011461140157610524866105188188038261045e565b9350600184527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b838510611446575050505081016020016105188261052438610508565b8054868601840152938201938101611429565b3461034d57600036600319011261034d576007546040516001600160a01b039091168152602090f35b3461034d57604036600319011261034d5760043561149f816105dd565b600090602435906001600160a01b038116331515811515855b60098054821015611534578752600080516020613fa08339815191528101546001919084906001600160a01b03166114ef816128c7565b91611524575b848061151a575b611509575b5050016114b8565b6115139188613b47565b3880611501565b50863314156114fc565b61152f818333613b47565b6114f5565b33600090815260046020526040902085908890611552908990610a4d565b8054820190556040519081523390600080516020613f80833981519152908060208101610a8a565b3461034d57602036600319011261034d5760206105d5611598611f97565b600435613298565b3461034d5761169760206115b3366105ee565b6001600160a01b03828116949390916115d56115cd6132f4565b871515611f47565b6115dd613311565b506115e961063c611f2a565b6116056115fd6115f88361277a565b612c6c565b83111561332e565b611616611610611f97565b83613c65565b9561162b87858416938433036116f157612c78565b60408051848152602081018990523391600080516020613f6083398151915291a46008546000906001600160a01b03165b604051631a4ca37b60e21b81526001600160a01b03918216600482015260248101939093529093166044820152948592839182906064820190565b03927f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce2165af19182156103d6576020926116d45750604051908152f35b6116ea90833d85116103cf576103c1818361045e565b50386103a0565b6001600160a01b03811660009081526005602052604090206106ee903390610728565b3461034d57611697611725366105ee565b6001600160a01b03808316929161173d6106636132f4565b8415938415948561180e575b61175590610e7c613311565b611766611760611f2a565b86611f47565b60009594156117e85760209495506117886117808361277a565b87111561337a565b611799611793611f97565b876139fd565b955b6117af81858516948533036116f157612c78565b6040805188815260208101929092523391600080516020613f608339815191529190a460085484906000906001600160a01b031661165c565b602094506117f86115f88361277a565b50611809611804611f97565b613c40565b61179b565b506001611749565b3461034d57602036600319011261034d5760206105d5600435611838816105dd565b612627565b90815180825260208080930193019160005b82811061185d575050505090565b83516001600160a01b03168552938101939281019260010161184f565b3461034d57600036600319011261034d5760405180600954918281526020809101926009600052600080516020613fa0833981519152916000905b8282106118e057610524856118cc8189038261045e565b60405191829160208352602083019061183d565b83546001600160a01b0316865294850194600193840193909101906118b5565b3461034d57602036600319011261034d5761191c6004356105dd565b60206105d56126c7565b3461034d57602036600319011261034d5760206105d5611944611f97565b600435613de1565b3461034d57600036600319011261034d576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461034d57602036600319011261034d5760206105d56119bb6004356119b6816105dd565b61277a565b6119c3611f97565b906139fd565b60ff81160361034d57565b3461034d5760e036600319011261034d576004356119f1816105dd565b6024356119fd816105dd565b7f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560443592611b34606435611b18608435611a37816119c9565b611a43428410156126f1565b611b24611a4e6130c4565b93888a611ada611a708a60018060a01b03166000526006602052604060002090565b9384549460018601905560405194859360208501958d8791959493909260a09360c08401977f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98552600180871b038092166020860152166040840152606083015260808201520152565b0391611aee601f199384810183528261045e565b519020604051948591602083019788909160429261190160f01b8352600283015260228201520190565b0390810184528361045e565b60c4359260a435925190206132dc565b9284611b6f8261072860018060a01b0380961697611b55898883161461273d565b6001600160a01b0316600090815260056020526040902090565b556040519485521692602090a3005b3461034d57602036600319011261034d5760206105d56004356119b6816105dd565b3461034d576020611bdc611bb336611154565b6001600160a01b0391821660009081526005855260408082209290931681526020919091522090565b54604051908152f35b3461034d57602036600319011261034d5760206105d5600435611c07816105dd565b6128c7565b3461034d57604036600319011261034d57600435602435611c2c816105dd565b611c3761063c611f2a565b6007546040516370a0823160e01b81523360048201526001600160a01b03918216929190602081602481875afa80156103d65761052495600080516020613fc083398151915292600092611cf4575b5081811115611cec5750915b611cbe83611ca1610f5a611f97565b96611cb5611cad611f2a565b891515611f47565b30903390613785565b611cc885856137dd565b60408051938452602084018690529316923392a36040519081529081906020820190565b905091611c92565b611d0e91925060203d6020116103cf576103c1818361045e565b9038611c86565b61ffff81160361034d57565b3461034d5761020036600319011261034d57600435611d3f816105dd565b60243590611d4c826105dd565b60643591611d5983611d15565b608435611d6581610ca8565b60e03660c319011261034d576060366101a319011261034d57610524936106c49360a4359360443591612a56565b3461034d57606036600319011261034d57600435611db0816105dd565b602435611dbc816105dd565b6044356001600160401b03811161034d57611ddb903690600401610860565b336001600160a01b0384811691821494929392918515611e0c575b5050611e0761091194610e7c612c4f565b612d94565b90945060405190631d36517b60e21b82526004820152602081602481887f0000000000000000000000000000000000000000000000000000000000000000165afa9485156103d65761091195611e0792600091611e6e575b5016331494611df6565b611e90915060203d602011611e96575b611e88818361045e565b810190612c3a565b38611e64565b503d611e7e565b3461034d5760206105d5611eb036611154565b6001600160a01b038216600090815260048552604090205490611ed2816128c7565b92613903565b3461034d57600036600319011261034d57602060405160028152f35b9081602091031261034d575190565b6040513d6000823e3d90fd5b6001600160401b03811161043e57601f01601f191660200190565b60405190611f3782610443565b60018252600760fb1b6020830152565b15611f4f5750565b60405162461bcd60e51b8152908190611f6b906004830161047f565b0390fd5b634e487b7160e01b600052601160045260246000fd5b91908203918211611f9257565b611f6f565b60085460405163d15e005360e01b81526001600160a01b03918216600482015290602090829060249082907f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce2165afa9081156103d657600091611ff8575090565b610617915060203d6020116103cf576103c1818361045e565b5190610847826105dd565b602090818184031261034d578051906001600160401b03821161034d57019180601f8401121561034d57825161205181610849565b9361205f604051958661045e565b818552838086019260051b82010192831161034d578301905b828210612086575050505090565b8380918351612094816105dd565b815201910190612078565b634e487b7160e01b600052603260045260246000fd5b8051156120c25760200190565b61209f565b80518210156120c25760209160051b010190565b919082602091031261034d57604051602081018181106001600160401b0382111761043e5760405291518252565b51906001600160801b038216820361034d57565b519064ffffffffff8216820361034d57565b519061084782611d15565b6101e08183031261034d5761215761215061081a565b92826120db565b825261216560208201612109565b602083015261217660408201612109565b604083015261218760608201612109565b606083015261219860808201612109565b60808301526121a960a08201612109565b60a08301526121ba60c0820161211d565b60c08301526121cb60e0820161212f565b60e08301526101006121de818301612011565b908301526101206121f0818301612011565b90830152610140612202818301612011565b90830152610160612214818301612011565b90830152610180612226818301612109565b908301526101a0612238818301612109565b9083015261224a6101c0809201612109565b9082015290565b604d8111611f9257600a0a90565b81810292918115918404141715611f9257565b91908201809211611f9257565b6008546040516335ea6a7560e01b81526001600160a01b0391821660048201526101e0918290829060249082907f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce2165afa9182156103d657600092612415575b5050805151600160381b8116158015612406575b80156123f3575b6123ec5780640fffffffff61231760ff6123219460301c16612251565b9160741c1661225f565b9081156123e4576101008101516004919060209061234990610b12906001600160a01b031681565b60405163b1bf962d60e01b815293849182905afa80156103d6576123a16123a7916123ad946000916123c5575b5061239b61238f6101808601516001600160801b031690565b6001600160801b031690565b90612272565b9161320f565b90613298565b818111156123bc575050600090565b61061791611f85565b6123de915060203d6020116103cf576103c1818361045e565b38612376565b505060001990565b5050600090565b50670200000000000000811615156122fa565b506001603c1b811615156122f3565b6124349250803d1061243b575b61242c818361045e565b81019061213a565b38806122df565b503d612422565b6040519061244f82610443565b60018252603160f81b6020830152565b6040519061246c82610443565b60018252601960f91b6020830152565b61014435610617816119c9565b6101a435610617816119c9565b35610617816119c9565b604051906124ad82610443565b60018252603360f81b6020830152565b604051906124ca82610443565b6001825260203681840137565b916124ef60409295949560608552606085019061183d565b6001600160a01b0391821660208501529416910152565b6001600160a01b03818116801561261f5761251f6124bd565b60075461255090612538906001600160a01b0316610b12565b612541836120b5565b6001600160a01b039091169052565b60405180936370674ab960e01b8252818061257460209889963090600485016124d7565b03917f0000000000000000000000000000000000000000000000000000000000000000165afa9182156103d657600092612600575b506040516370a0823160e01b8152306004820152908390829060249082905afa9081156103d657610617936000926125e3575b5050612272565b6125f99250803d106103cf576103c1818361045e565b38806125dc565b612618919250833d85116103cf576103c1818361045e565b90386125a9565b505050600090565b6001600160a01b039081169081156123ec5761267c6020916126476124bd565b8160075416612655826120b5565b5260006040518096819582946308d8c03760e21b845260806004850152608484019061183d565b9083196024840152306044840152606483015203927f0000000000000000000000000000000000000000000000000000000000000000165af19081156103d657600091611ff8575090565b6126cf61227f565b600019908082146126ed5761061791506126e7611f97565b90613de1565b5090565b156126f857565b60405162461bcd60e51b815260206004820152601760248201527f5045524d49545f444541444c494e455f455850495245440000000000000000006044820152606490fd5b1561274457565b60405162461bcd60e51b815260206004820152600e60248201526d24a72b20a624a22fa9a4a3a722a960911b6044820152606490fd5b6008546040516335ea6a7560e01b81526001600160a01b0391821660048201819052906101e09081816024817f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce288165afa9182156103d6576000926128aa575b5050805151600160381b81161590811561289a575b506128915761010001516040516370a0823160e01b81526001600160a01b0390911660048201529160209183916024918391165afa9081156103d6576128609161284491600091612872575b506126e7611f97565b6001600160a01b03909216600090815260046020526040902090565b549081811061286d575090565b905090565b61288b915060203d6020116103cf576103c1818361045e565b3861283b565b50505050600090565b6001603c1b9150161515386127ef565b6128c09250803d1061243b5761242c818361045e565b38806127da565b6001600160a01b0390811680156123ec57604090604483600754168351948593849263886fe70b60e01b8452600484015260248301527f0000000000000000000000000000000000000000000000000000000000000000165afa9081156103d657600091612933575090565b90506040813d60401161295d575b8161294e6040938361045e565b8101031261034d576020015190565b3d9150612941565b6040519061297282610443565b60018252600d60fa1b6020830152565b7f2a83c73b9e01ec0a1b95ff05940d809179668cc004230412d7047ffac3846ce781526001600160a01b0391821660208201529181166040830152606082019290925261ffff909216608083015291151560a082015260c081019290925260e08201929092526101e0810192918060c4356129fc816105dd565b1661010083015260e435612a0f816105dd565b16610120820152610104356101408201526101243561016082015260ff61014435612a39816119c9565b16610180820152610164356101a08201526101c061018435910152565b6001600160a01b039581871690612a6b612965565b612a7790831515611f47565b612a7f61245f565b612a8c9042831015611f47565b6001600160a01b03831660009081526006602052604090205490612aae6130c4565b60405191826020810191612ac890868d8d8d8d8d89612982565b0392601f19938481018252612add908261045e565b51902060405161190160f01b6020820190815260228201939093526042810191909152606292830181529091612b13908261045e565b5190206001600160a01b038416600090815260066020526040902090916001019055612b3d612489565b6101e435906101c43590612b50936132dc565b6001600160a01b031614612b626124a0565b612b6b91611f47565b610124359586612b81575b506126ed955061361a565b8515612c20576008546001600160a01b03165b16612b9d61247c565b96813b1561034d5760405163d505accf60e01b81526001600160a01b0384166004820152306024820152610104356044820152606481019190915260ff9790971660848801526101643560a48801526101843560c48801526126ed9690600090829060e490829084905af115612b765780611047612c1a9261042b565b38612b76565b600754612c35906001600160a01b0316610b12565b612b94565b9081602091031261034d5751610617816105dd565b60405190612c5c82610443565b60018252601b60f91b6020830152565b610617906119c3611f97565b60009160005b60098054821015612cd6578452600080516020613fa0833981519152810154600191906001600160a01b03908116612cb5816128c7565b918616612cc5575b505001612c7e565b612ccf9186613b47565b3880612cbd565b50506001600160a01b038216600090815260046020526040902091925090805490828203918211611f9257600093600080516020613f8083398151915292612d409255612d268460035403600355565b6040519384526001600160a01b0316929081906020820190565b0390a3565b60405163a9059cbb60e01b60208201526001600160a01b03909216602483015260448083019390935291815260808101916001600160401b0383118284101761043e5761084792604052613a31565b92919060005b8251811015612fa757612db3610b12610ba283866120c7565b15612f9f57612dc8611c07610ba283866120c7565b90612dfd82612de98860018060a01b03166000526004602052604060002090565b54612df7610ba285896120c7565b89613903565b612e10610b12610b12610ba285896120c7565b6040516370a0823160e01b815230600482015291906020908190849060249082905afa9081156103d6576001958a948992600094612f80575b505082600093808611612f65575b50808511612f50575b508584612e75575b5050505050505b01612d9a565b612f4595612ed1612ef094612ebb610ba2612eeb95612eb5612e99612f349b613ade565b6001600160a01b039097166000908152600b6020526040902090565b936120c7565b60018060a01b0316600052602052604060002090565b906001600160801b0382549181199060801b169116179055565b613ade565b6001600160a01b038a166000908152600b60205260409020612f1990612ebb610ba2888c6120c7565b906001600160801b03166001600160801b0319825416179055565b846106bf610b12610ba2868a6120c7565b853880868185612e68565b809350612f5d9194611f85565b919238612e60565b612f7a915061239b611838610ba28a876120c7565b38612e57565b612f97929450803d106103cf576103c1818361045e565b913880612e49565b600190612e6f565b5050509050565b6009548110156120c2576009600052600080516020613fa08339815191520190600090565b6001600160a01b038181166000818152600a60205260409020549092919060ff166130bf57613001826128c7565b6009546801000000000000000081101561043e577fa8f4dd7e60441ca288d902a295362002a0255a46560b24825821b36716d6fe5b936130ba9361304e8360016106c49501600955612fae565b819291549060031b9189831b921b191617905561309a61306c61083a565b60018152916001600160f01b03851660208401526001600160a01b03166000908152600a6020526040902090565b815160209092015160081b60ff191660ff92151592909216919091179055565b0390a2565b505050565b604051600090600054906130d7826103db565b9283825260209384830193600190866001821691826000146131ef575050600114613198575b505091816131136131929361318495038261045e565b519020604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f95810195865260208601929092527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc69085015246606085015230608085015291829060a0850190565b03601f19810183528261045e565b51902090565b600080805286935091907f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5635b8284106131da57505050820101816131136130fd565b805486850186015287949093019281016131c4565b60ff1916875292151560051b8501909201925083915061311390506130fd565b60c081015164ffffffffff16428103613239575060200151610617906001600160801b031661238f565b6001600160801b0360408301511690420390428211611f92576301e13380916132619161225f565b04676765c793fa10079d601b1b908101809111611f925761329261238f60206106179401516001600160801b031690565b90613c05565b90811580156132d4575b6123ec57806132bd676765c793fa10079d601b1b9284613e81565b92096132c65790565b60018101809111611f925790565b5080156132a2565b9161061793916132eb93613c8c565b90929192613d30565b6040519061330182610443565b60018252603560f81b6020830152565b6040519061331e82610443565b60018252603760f81b6020830152565b1561333557565b60405162461bcd60e51b815260206004820152601f60248201527f455243343632363a207769746864726177206d6f7265207468616e206d6178006044820152606490fd5b1561338157565b60405162461bcd60e51b815260206004820152601d60248201527f455243343632363a2072656465656d206d6f7265207468616e206d61780000006044820152606490fd5b949390916001600160a01b0391828416916133ea6133e26132f4565b841515611f47565b8015958615968761357a575b61340290610e7c613311565b61341661340d611f2a565b82841415611f47565b80919660001461353a57505080613521575b613439613433611f97565b866139fd565b9687925b61345187868416938433036116f157612c78565b60408051858152602081018990523391600080516020613f6083398151915291a41561350557600854604051631a4ca37b60e21b81526001600160a01b0391821660048201526024810192909252929092166044830152602090829060649082906000907f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce2165af180156103d6576134e857509190565b6135009060203d6020116103cf576103c1818361045e565b509190565b60075461351d939192506001600160a01b0316612d45565b9190565b61353561352d8861277a565b86111561337a565b613428565b819891939650613558908361355e575b613552611f97565b90613c65565b9561343d565b61357561356d6115f88561277a565b82111561332e565b61354a565b5080156133f6565b1561358957565b60405162461bcd60e51b815260206004820152601e60248201527f455243343632363a206465706f736974206d6f7265207468616e206d617800006044820152606490fd5b156135d557565b60405162461bcd60e51b815260206004820152601b60248201527f455243343632363a206d696e74206d6f7265207468616e206d617800000000006044820152606490fd5b919493926001600160a01b0380831693929161363f6136376132f4565b861515611f47565b85613648613311565b5061376d575b61365f613659611f97565b89613de1565b809661366c61063c611f2a565b1561373857506008546001600160a01b031661368c893087868516613785565b827f000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce21691823b1561034d5760405163e8eda9df60e01b81526001600160a01b03929092166004830152602482018a905230604483015261ffff166064820152906000908290608490829084905af180156103d657600080516020613fc08339815191529361372092889261103a57506137dd565b60408051888152602081018790529390911692a39190565b600754600080516020613fc083398151915294613720935090613768908b906001600160a01b0316883091613785565b6137dd565b61378061377861227f565b891115613582565b61364e565b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a08101918183106001600160401b0384111761043e5761084792604052613a31565b60009160005b60098054821015613848578452600080516020613fa0833981519152810154600191906001600160a01b0390811661381a816128c7565b918616151580613843575b613832575b5050016137e3565b61383c9186613b47565b388061382a565b613825565b5050915060035490828201809211611f9257612d40600080516020613f8083398151915291613878600094600355565b6001600160a01b03811660009081526004602052604090208054860190556040519485526001600160a01b0316939081906020820190565b604051906138bd82610443565b60018252603960f81b6020830152565b906040516138da81610443565b91546001600160801b038116835260801c6020830152565b60ff16604d8111611f9257600a0a90565b6139f0906106179461398a6139856139cd956107286139348260018060a01b0316600052600a602052604060002090565b9561396b6040519761394589610443565b5497602060ff8a16151591828152019860081c895260016139646138b0565b9114611f47565b6001600160a01b03166000908152600b6020526040902090565b6138cd565b9461399f61399a60025460ff1690565b6138f2565b926139b460208801516001600160801b031690565b966001600160801b03968791516001600160801b031690565b1690816139f757516001600160f81b031690505b6001600160f81b031690613dbd565b9116612272565b506139e1565b9081158015613a14575b6123ec5761061791613e81565b508015613a07565b9081602091031261034d575161061781610ca8565b600080613a7b9260018060a01b03169360208151910182865af13d15613ad6573d90613a5c82611f0f565b91613a6a604051938461045e565b82523d6000602084013e5b83613efc565b8051908115159182613ab4575b5050613a915750565b604051635274afe760e01b81526001600160a01b03919091166004820152602490fd5b613acf925090602080613acb938301019101613a1c565b1590565b3880613a88565b606090613a75565b6001600160801b0390818111613af2571690565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b610847926040612f1992613b7f60018060a01b0382169560009287845260046020528585852054918383613b9f575b50505050613ade565b948152600b602052209060018060a01b0316600052602052604060002090565b613bd793613bb093612eeb93613903565b888552600b60209081528686206001600160a01b0389166000908152915260409020612ed1565b38858183613b76565b634e487b7160e01b600052601260045260246000fd5b8115613c00570490565b613be0565b816b019d971e4fe8401e7400000019048111158215171561034d57676765c793fa10079d601b1b91026b019d971e4fe8401e74000000010490565b8015613c0057600090676765c793fa10079d601b1b600009613c5f5790565b50600190565b90613c708183613de1565b918115613c0057676765c793fa10079d601b1b90096132c65790565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411613d0457926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa156103d65780516001600160a01b03811615613cfb57918190565b50809160019190565b50505060009160039190565b60041115613d1a57565b634e487b7160e01b600052602160045260246000fd5b613d3981613d10565b80613d42575050565b613d4b81613d10565b60018103613d655760405163f645eedf60e01b8152600490fd5b613d6e81613d10565b60028103613d8f5760405163fce698f760e01b815260048101839052602490fd5b80613d9b600392613d10565b14613da35750565b6040516335e2f38360e21b81526004810191909152602490fd5b91908215612891578103908111611f9257613bf69161225f565b15613c0057600090565b676765c793fa10079d601b1b918183029160001984820993838086109503948086039514613e745784831115613e625782910981600003821680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b60405163227bc15360e01b8152600490fd5b5050906106179250613bf6565b908082029060001981840990828083109203918083039214613ee857676765c793fa10079d601b1b9082821115613e62577f2245cd4e1f3755e770b615377cde9082e11ad04b156637b5cd27412a54f5b6b5940990828211900360e51b9103601b1c170290565b5050676765c793fa10079d601b1b91500490565b90613f235750805115613f1157805190602001fd5b604051630a12f52160e11b8152600490fd5b81511580613f56575b613f34575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b15613f2c56fefbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8dbddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7afdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7a26469706673582212201eb2b81a2bdbb1e69d0c00691f863002172f09a4e65d7293c104bce7fc1fcaa464736f6c63430008180033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000029d0256fe397f6e442464982c4cba7670646059b00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000001a5772617070656420645452494e495459204c656e64206455534400000000000000000000000000000000000000000000000000000000000000000000000000067764645553440000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : pool (address): 0xD76C827Ee2Ce1E37c37Fc2ce91376812d3c9BCE2
Arg [1] : rewardsController (address): 0x0000000000000000000000000000000000000000
Arg [2] : newAToken (address): 0x29d0256fe397F6e442464982C4Cba7670646059b
Arg [3] : staticATokenName (string): Wrapped dTRINITY Lend dUSD
Arg [4] : staticATokenSymbol (string): wddUSD
-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 000000000000000000000000d76c827ee2ce1e37c37fc2ce91376812d3c9bce2
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [2] : 00000000000000000000000029d0256fe397f6e442464982c4cba7670646059b
Arg [3] : 00000000000000000000000000000000000000000000000000000000000000a0
Arg [4] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [5] : 000000000000000000000000000000000000000000000000000000000000001a
Arg [6] : 5772617070656420645452494e495459204c656e642064555344000000000000
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000006
Arg [8] : 7764645553440000000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in FRAX
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
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.