Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 12 from a total of 12 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Withdraw | 22087259 | 236 days ago | IN | 0 ETH | 0.00059278 | ||||
| Pause Unpause De... | 22029741 | 244 days ago | IN | 0 ETH | 0.00004611 | ||||
| Withdraw | 22000871 | 248 days ago | IN | 0 ETH | 0.00067687 | ||||
| Pause Unpause De... | 22000452 | 248 days ago | IN | 0 ETH | 0.00004904 | ||||
| Stake Shares | 21979336 | 251 days ago | IN | 0 ETH | 0.00003747 | ||||
| Pause Unpause De... | 21936853 | 257 days ago | IN | 0 ETH | 0.00004528 | ||||
| Pause Unpause De... | 21900622 | 262 days ago | IN | 0 ETH | 0.00004177 | ||||
| Pause Unpause De... | 21896889 | 263 days ago | IN | 0 ETH | 0.00013419 | ||||
| Deposit | 21896882 | 263 days ago | IN | 0 ETH | 0.00099146 | ||||
| Pause Unpause De... | 21896874 | 263 days ago | IN | 0 ETH | 0.00010582 | ||||
| Pause Unpause De... | 21894472 | 263 days ago | IN | 0 ETH | 0.00004302 | ||||
| Deposit | 21894246 | 263 days ago | IN | 0 ETH | 0.00040152 |
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
To
|
|||
|---|---|---|---|---|---|---|---|
| 0x3d602d80 | 21893668 | 263 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Minimal Proxy Contract for 0xde197e9267d2b90ef5d4fc545c61432dae55832b
Contract Name:
AFiBase
Compiler Version
v0.8.28+commit.7893614a
Contract Source Code (Solidity Multiple files format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;
import {IAFiStorage} from "./IAFiStorage.sol";
import {OwnableDelayModule} from "./OwnableDelayModule.sol";
import {ReentrancyGuard} from "./ReentrancyGuard.sol";
import {SafeERC20} from "./SafeERC20.sol";
import {SafeCast} from "./SafeCast.sol";
import {ILendingPool} from "./ILendingPool.sol";
import {IPoolAddressesProvider} from "./ILendingPoolAddressesProvider.sol";
import {ISwapRouter} from "./ISwapRouter.sol";
import {IUniswapOracleV3} from "./IUniswapV3.sol";
import "./IAFi.sol";
import "./IPassiveRebal.sol";
import "./ArrayUtils.sol";
import "./IUniswapV3Factory.sol";
import {ERC20} from "./ERC20.sol";
// Enum for supported DEXs
enum DexChoice {
UNISWAP_V3,
ONE_INCH,
NONE
}
interface Compound {
function mint(uint mintAmount) external returns (uint);
function redeem(uint redeemTokens) external returns (uint);
function redeemUnderlying(uint redeemAmount) external returns (uint);
function exchangeRateStored() external view returns (uint);
}
interface CompoundV3 {
function supply(address asset, uint amount) external;
function withdraw(address asset, uint amount) external;
}
interface IAFiFactory {
function setIfUserInvesting(address user, address afiContract) external;
function hasUserInvestedAlready(
address afiContract,
address user
) external view returns (bool);
function withdrawAndResetInvestmentStatus(address user, address afiContract) external;
function afiContractInitUpdate(address aFiContract, uint order) external;
}
interface LendingPoolAddressesProvider {
function getLendingPool() external view returns (address);
function getLendingPoolCore() external view returns (address);
}
interface IAggregationExecutor {
function callBytes(bytes calldata data) external payable;
}
interface IAggregationRouterV6 {
struct SwapDescription {
IERC20 srcToken;
IERC20 dstToken;
address srcReceiver;
address dstReceiver;
uint256 amount;
uint256 minReturnAmount;
uint256 flags;
}
function swap(
IAggregationExecutor caller,
SwapDescription calldata desc,
bytes calldata data
) external payable returns (uint256 returnAmount, uint256 spentAmount);
}
contract AFiVariableStorage {
uint internal pool;
address payable internal platformWallet =
payable(0xB60C61DBb7456f024f9338c739B02Be68e3F545C);
address[] internal token; // deposit stable coin
address[] internal uTokens;
uint[] internal uTokenProportions;
uint[] internal defaultProportion;
mapping(address => address) internal compound; // compound address for various u tokens
mapping(address => uint) internal depositNAV;
mapping(address => bool) internal whitelistedTokens;
}
contract AFiBase is
ERC20,
ReentrancyGuard,
OwnableDelayModule,
AFiVariableStorage,
IAFi
{
using SafeERC20 for IERC20;
using ArrayUtils for uint[];
using ArrayUtils for address[];
using SafeCast for uint256;
bool internal depositPaused;
bool internal withdrawPaused;
bool public migrated;
bool public vaultReInitialized;
bool internal isBase;
bool public isAfiTransferrable; // true if AFi tokens are transferrable
uint internal typeOfProduct;
uint256 internal cSwapCounter;
uint256 public minimumDepositLimit;
address public factory;
address public aFiOracle;
address public tLContract;
address public PARENT_VAULT;
IPassiveRebal public rebalContract;
IAFiStorage public aFiStorage;
address public aFiManager;
address[] internal nonOverlappingITokens; // Tokens that are not common between underlying and input tokens
address private constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address private constant DEAD_ADDRESS = 0x000000000000000000000000000000000000dEaD;
address private constant POOL_ADDRESS_PROVIDER =
0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e;
ISwapRouter internal constant UNISWAP_EXCHANGE =
ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
address internal constant ONEINCH_ROUTER = 0x111111125421cA6dc452d289314280a0f8842A65;
mapping(address => mapping(uint => uint)) internal nonWithdrawableShares;
mapping(address => address) public compoundV3Comet;
mapping(address => uint256) public userLockedAmount;
mapping(address => bool) public isPausedForWithdrawals; // true if deposit token is paused(users can't withdraw in this token)
event UpdateShares(address user, uint256 amount, bool lock);
event Deposit(address indexed investor, uint256 amount, address depToken);
event Withdraw(address indexed investor, uint256 amount, address withdrawnToken);
event Initialized(address indexed afiContract);
event InitializedToken(address indexed afiContract);
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {}
function initialize(
address newOwner,
string memory tokenName,
string memory tokenSymbol,
bytes memory data,
bool _isActiveRebalanced,
IAFiStorage _aFiStorage,
address[] memory _nonOverlappingITokens,
address parentVault
) external override nonReentrant {
checkFalse(isBase);
PARENT_VAULT = parentVault;
addressCheck(newOwner, address(0));
_name = tokenName;
_symbol = tokenSymbol;
_transferOwnership(newOwner);
delayModule = newOwner;
aFiStorage = _aFiStorage;
aFiOracle = aFiStorage.getAFiOracle();
nonOverlappingITokens = _nonOverlappingITokens;
IAFi.PoolsData memory pooldata = abi.decode(data, (IAFi.PoolsData));
typeOfProduct = pooldata._typeOfProduct;
factory = msg.sender;
setInitialValues(data);
defaultProportion = uTokenProportions;
IAFiStorage(_aFiStorage).setAFiActive(address(this), true);
IAFiStorage(_aFiStorage).setActiveRebalancedStatus(
address(this),
_isActiveRebalanced
);
IAFiFactory(factory).afiContractInitUpdate(address(this), 1);
}
function initializeToken(
address[] memory iToken,
address[] memory _teamWallets,
IPassiveRebal _rebalContract,
address _aFiManager
) external override nonReentrant {
checkFalse(isBase);
isBase = true;
aFiManager = _aFiManager;
rebalContract = _rebalContract;
minimumDepositLimit = 500;
aFiStorage.setTeamWallets(address(this), _teamWallets);
uint iLen = iToken.length;
unchecked {
for (uint i = 0; i < iLen; i++) {
updatetoken(iToken[i]);
setWhitelistedTok(iToken[i]);
}
}
IAFiFactory(factory).afiContractInitUpdate(address(this), 2);
}
function getNonWithdrawableShares(
address user,
uint256 csCounterValue
) public view override returns (uint256) {
return nonWithdrawableShares[user][csCounterValue];
}
function updatetoken(address tok) internal {
token.push(tok);
approval(tok, aFiOracle, ~uint(0));
}
function getcSwapCounter() external view override returns (uint256) {
return cSwapCounter;
}
function transferValidationAndSet(address from, address to, uint256 amount) internal {
checkFalse(!isAfiTransferrable);
address owner = from;
validateShares(owner, amount);
depositNAV[to] =
((depositNAV[to] * _balances[to]) + (depositNAV[owner] * amount)) /
(_balances[to] + amount);
}
function checkNav(address target) internal {
if (_balances[target] == 0) {
delete depositNAV[target];
}
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
transferValidationAndSet(_msgSender(), to, amount);
_transfer(_msgSender(), to, amount);
checkNav(_msgSender());
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
transferValidationAndSet(from, to, amount);
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
checkNav(from);
return true;
}
function setAfiTransferability(bool _afiTransferrable) external onlyOwner {
isAfiTransferrable = _afiTransferrable;
}
function reinitializeHappened(bool status) external override {
twoAddressCompare(aFiManager, aFiOracle);
vaultReInitialized = status;
}
function getReinitializeStatus()
external
view
override
returns (bool _vaultReInitialized)
{
_vaultReInitialized = vaultReInitialized;
}
/**
* @notice Pauses / unpause deposits in the contract.
* @dev Requirements: Can only be invoked by the Owner wallet.
*/
function pauseUnpauseDeposit(bool status) external {
twoAddressCompare(
rebalContract.getPauseDepositController(address(this)),
aFiOracle
);
depositPaused = status;
}
/**
* @notice Pauses / unpause withdrawals in the contract.
* @dev Requirements: Can only be invoked by the Delay Module.
*/
function pauseWithdraw(bool status) external {
checkDelayModule();
withdrawPaused = status;
}
/**
* @notice Returns the paused status of the contract.
*/
function isPaused() external view override returns (bool, bool) {
return (depositPaused, withdrawPaused);
}
/**
* @notice To update the platform wallet address and zero address should not pass.
* @dev Requirements: It can be invoked only by the owner.
* @param _platformWallet Address of the platform wallet.
*/
function setplatformWallet(address payable _platformWallet) external onlyOwner {
addressCheck(_platformWallet, address(0));
platformWallet = _platformWallet;
}
function setMinDepLimit(uint256 limit) external onlyOwner {
greaterEqualComparison(limit, 100);
minimumDepositLimit = limit;
}
function getplatformWallet() external view returns (address) {
return platformWallet;
}
function getTVLandRebalContractandType()
external
view
override
returns (uint256, address, uint256)
{
return (pool, address(rebalContract), typeOfProduct);
}
function checkFalse(bool flag) internal pure {
require(!flag, "AB03");
}
function addressEqual(address add1, address add2) internal pure {
require(add1 == add2, "AB30");
}
function twoAddressCompare(address add1, address add2) internal view {
require(msg.sender == add1 || msg.sender == add2, "AB32");
}
function addressCheck(address add1, address add2) internal pure {
require(add1 != add2, "AB05"); //solhint-disable-line reason-string
}
function greaterEqualComparison(uint256 valA, uint256 valB) internal pure {
require(valA >= valB, "AB24");
}
function greaterComparision(uint256 valA, uint256 valB) internal pure {
require(valA > valB, "AB25");
}
function togglePauseDepositTokenForWithdrawals(
address tok,
bool _pause
) external onlyOwner {
if (_pause) {
checkFalse(!whitelistedTokens[tok]);
} else {
checkFalse(!isPausedForWithdrawals[tok]);
}
isPausedForWithdrawals[tok] = _pause;
}
function checkTokInList(address tok) internal view returns (bool istok, bool isUTok) {
(, istok) = token.indexOf(tok);
(, isUTok) = uTokens.indexOf(tok);
}
function addToWhitelist(address tok) external onlyOwner {
checkFalse(whitelistedTokens[tok]);
(bool isPresent, bool isInputTokenPresent) = checkTokInList(tok);
if (!isPresent) {
updatetoken(tok);
}
// Prevent duplication in nonOverlappingITokens
(, bool isAlreadyInNonOverlapping) = nonOverlappingITokens.indexOf(tok);
if (!isInputTokenPresent && !isAlreadyInNonOverlapping) {
nonOverlappingITokens.push(tok);
}
setWhitelistedTok(tok);
}
function setWhitelistedTok(address tok) internal {
whitelistedTokens[tok] = true;
}
function getPreDepositTokensBalance(
address tok,
uint256 _cSwapCounter
) internal view returns (uint) {
return aFiStorage.getPreSwapDepositsTokens(address(this), _cSwapCounter, tok);
}
function removeFromWhitelist(
address tok,
address swapTok,
uint256 deadline,
uint256 amountOut,
bytes calldata swapData
) external onlyOwner {
checkFalse(!whitelistedTokens[tok]);
checkFalse(!whitelistedTokens[swapTok]);
delete whitelistedTokens[tok];
if (getPreDepositTokensBalance(tok, cSwapCounter) > 0) {
addressCheck(tok, swapTok);
aFiStorage.doSwapForThewhiteListRemoval(
tok,
cSwapCounter,
swapTok,
deadline,
amountOut,
swapData
);
}
token = rebalContract.removeToken(token, tok);
approval(tok, aFiOracle, 0);
// Remove tok from nonOverlappingITokens if present
nonOverlappingITokens = rebalContract.removeToken(nonOverlappingITokens, tok);
}
function contractTransfers(address tok, address to, uint256 amount) private {
IERC20(tok).safeTransfer(to, amount);
}
/**
* @dev This function is used to increase counter and to update the flag for vaultReInitialized
*/
function underlyingTokensStaking(
) external override {
checkOracle();
if (vaultReInitialized) {
vaultReInitialized = false;
}
increasecsCounter();
}
function updateCp(uint256[] memory newCp) external {
addressEqual(msg.sender, address(rebalContract));
uTokenProportions = newCp;
}
function increasecsCounter() internal {
cSwapCounter++;
}
function swap(
address inputToken,
address uTok,
uint256 amountAsPerProportion,
uint _deadline,
address middleToken,
uint256 minimumReturnAmount,
bytes calldata swapData
) external override returns (uint256 returnAmount) {
checkOracle();
if (inputToken != uTok && middleToken == address(0)) {
(returnAmount) = _routeSwap(
inputToken,
uTok,
amountAsPerProportion,
_deadline,
rebalContract.getMidToken(uTok),
minimumReturnAmount,
swapData
);
} else if (inputToken != uTok) {
(returnAmount ) = _routeSwap(
inputToken,
uTok,
amountAsPerProportion,
_deadline,
middleToken,
minimumReturnAmount,
swapData
);
}
}
function isOTokenWhitelisted(address oToken) external view override returns (bool) {
return whitelistedTokens[oToken];
}
function updateTVL() public override {
pool = aFiStorage.calculatePoolInUsd(address(this));
}
function tokenTransfer(address token, uint256 amount) internal {
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
}
function deposit(uint amount, address iToken) external nonReentrant {
if (PARENT_VAULT != address(0)) {
checkFalse(!migrated);
}
greaterEqualComparison(
(amount / (10 ** (IERC20(iToken).decimals()))),
minimumDepositLimit
);
updateTVL();
uint256 prevPool = pool;
checkFalse(!whitelistedTokens[iToken]); // Added validation to check if the token is whitelisted
checkFalse(depositPaused);
tokenTransfer(iToken, amount);
uint256 fee = (amount * 1) / (100); // 1% platform fees is deducted
contractTransfers(iToken, platformWallet, fee);
amount = amount - fee;
setPreDeposit(iToken, amount);
(uint256 shares, uint256 newDepositNAV) = aFiStorage.calculateShares(
address(this),
amount, // assuming amount is defined somewhere
prevPool,
_totalSupply,
iToken, // assuming iToken is defined somewhere
depositNAV[msg.sender],
_balances[msg.sender]
);
greaterComparision(shares, 0);
_mint(msg.sender, shares);
makeUpdates(newDepositNAV, shares);
emit Deposit(msg.sender, amount, iToken);
}
function setPreDeposit(address tok, uint256 amount) internal {
aFiStorage.setPreDepositedInputToken(cSwapCounter, amount, tok);
}
function validateWithdraw(
address user,
address oToken,
uint256 _shares
) public view override {
checkFalse(!whitelistedTokens[oToken]); // Added validation to check if the token is whitelisted
checkFalse(isPausedForWithdrawals[oToken]);
validateShares(user, _shares);
greaterEqualComparison(_shares, 1e17);
}
function validateShares(address user, uint256 _shares) internal view {
greaterEqualComparison(
_balances[user] -
(userLockedAmount[user] + getNonWithdrawableShares(user, cSwapCounter)),
_shares
);
}
function withdraw(
uint _shares,
address oToken,
uint deadline,
uint[] memory minimumReturnAmount,
uint swapMethod,
uint minAmountOut
) external nonReentrant {
checkFalse((rebalContract.isSwapMethodPaused(address(this), swapMethod)));
checkFalse(withdrawPaused);
validateWithdraw(msg.sender, oToken, _shares);
updateTVL();
// Calculate the redemption amount before updating balances
uint r = (pool * (_shares)) / (_totalSupply);
greaterComparision(r, 0);
IAFiStorage.RedemptionParams memory params = IAFiStorage.RedemptionParams({
baseContract: address(this),
r: r,
oToken: oToken,
cSwapCounter: cSwapCounter,
uTokens: uTokens,
iTokens: token,
deadline: deadline,
minimumReturnAmount: minimumReturnAmount,
_pool: pool,
tSupply: _totalSupply,
depositNAV: depositNAV[msg.sender],
minAmountOut: minAmountOut
});
uint256 redFromContract = aFiStorage.handleRedemption(
params,
_shares,
swapMethod,
new bytes[](uTokens.length + token.length)
);
burn(msg.sender, _shares);
greaterEqualComparison(balance(oToken, address(this)), redFromContract);
greaterEqualComparison(redFromContract, minAmountOut);
checkNav(msg.sender);
contractTransfers(oToken, msg.sender, redFromContract);
emit Withdraw(msg.sender, _shares, oToken);
}
function burn(address account, uint256 amount) internal {
_balances[account] -= amount;
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function compareManagerAndStorage() internal view {
twoAddressCompare(aFiManager, address(aFiStorage));
}
function swapfromSelectiveDex(
address from,
address to,
uint amount,
uint deadline,
address midTok,
uint minimumReturnAmount,
bytes calldata _oneInchSwapData
) external override returns (uint256 _amountOut) {
compareManagerAndStorage();
(_amountOut) = _routeSwap(
from,
to,
amount,
deadline,
midTok,
minimumReturnAmount,
_oneInchSwapData
);
}
function getDexType(address tokIn, address tokOut) internal view returns (DexChoice) {
return DexChoice(uint(rebalContract.getDexType(tokIn, tokOut)));
}
function _routeSwap(
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _maxTime,
address middleToken,
uint256 minimumReturnAmount,
bytes calldata oneInchSwapData
) internal returns (uint256 amountOut) {
DexChoice preferredDex = getDexType(_tokenIn, _tokenOut);
if (preferredDex == DexChoice.UNISWAP_V3 || oneInchSwapData.length == 0) {
(amountOut) = _uniswapV3Router(
_tokenIn,
_tokenOut,
_amountIn,
_maxTime,
middleToken,
minimumReturnAmount
);
} else if (preferredDex == DexChoice.ONE_INCH) {
(amountOut) = _oneInchRouter(
oneInchSwapData,
_tokenIn,
_amountIn,
_tokenOut, // Pass destination token
minimumReturnAmount, // Pass minimum return amount
address(this) // Pass recipient (the contract itself)
);
}
return (amountOut);
}
function getdatastruct(
address _tokenIn,
address _tokenOut,
uint _amountIn,
uint _maxTime,
address middleToken,
uint256 minimumReturnAmount
) internal returns (bytes memory) {
return
rebalContract.uniswapV3Oracle(
address(this),
_tokenIn,
_tokenOut,
_amountIn,
_maxTime,
middleToken,
minimumReturnAmount
);
}
function _uniswapV3Router(
address _tokenIn,
address _tokenOut,
uint _amountIn,
uint _maxTime,
address middleToken,
uint256 minimumReturnAmount
) internal returns (uint amountOut) {
approval(_tokenIn, address(UNISWAP_EXCHANGE), _amountIn);
if (
_tokenIn == WETH ||
_tokenOut == WETH ||
_tokenIn == middleToken ||
_tokenOut == middleToken
) {
bytes memory swapParams = getdatastruct(
_tokenIn,
_tokenOut,
_amountIn,
_maxTime,
middleToken,
minimumReturnAmount
);
ISwapRouter.ExactInputSingleParams memory params = abi.decode(
swapParams,
(ISwapRouter.ExactInputSingleParams)
);
amountOut = UNISWAP_EXCHANGE.exactInputSingle(params);
} else {
bytes memory swapParams = getdatastruct(
_tokenIn,
_tokenOut,
_amountIn,
_maxTime,
middleToken,
minimumReturnAmount
);
ISwapRouter.ExactInputParams memory params = abi.decode(
swapParams,
(ISwapRouter.ExactInputParams)
);
amountOut = UNISWAP_EXCHANGE.exactInput(params);
}
greaterEqualComparison(amountOut, minimumReturnAmount);
return (amountOut);
}
function _oneInchRouter(
bytes calldata swapdata,
address srcToken,
uint256 srcAmount,
address dstToken, // Add destination token parameter
uint256 minReturnAmount, // Add minimum return amount parameter
address recipient // Add recipient parameter
) internal returns (uint256 amountOut) {
greaterEqualComparison(swapdata.length, 4);
bytes calldata dataToValidate = swapdata[4:];
(address executor1, SwapDescription memory desc, bytes memory data) = abi.decode(
dataToValidate,
(address, SwapDescription, bytes)
);
addressEqual(address(desc.srcToken), srcToken);
addressEqual(address(desc.dstToken), dstToken);
addressEqual(address(desc.dstReceiver), recipient);
if (srcAmount != desc.amount) {
desc.minReturnAmount = (desc.minReturnAmount * ((srcAmount * 1e18) / desc.amount)) / 1e18;
desc.amount = srcAmount;
}
approval(srcToken, ONEINCH_ROUTER, desc.amount);
uint256 destBal = balance(dstToken, address(this));
(bool success, ) = ONEINCH_ROUTER.call{value: msg.value}(
abi.encodeWithSelector(IAggregationRouterV6.swap.selector, executor1, desc, data)
);
checkFalse(!success);
destBal = balance(dstToken, address(this)) - destBal;
greaterEqualComparison((destBal), minReturnAmount);
approval(srcToken, ONEINCH_ROUTER, 0);
return (destBal);
}
/**
* @notice Function sends profit to wallets in the process of proffir share.
* @param wallet address to send profit to.
* @param profitShare i.e. amount to be transferred.
* @param oToken address of the token to consider for amount deduction.
*/
function sendProfitOrFeeToManager(
address wallet,
uint profitShare,
address oToken
) external override {
compareManagerAndStorage();
contractTransfers(oToken, wallet, profitShare);
}
function checkStorage() internal view {
addressEqual(msg.sender, address(aFiStorage));
}
/**
* @notice _supplyCompV3 function supply the fund of token to Compound V3 protocol for yield generation.
* @dev this function should be called by AFiStorage only
* @param tok address of the token to consider for supply.
* @param amount i.e calculated amount of token to invest.
*/
function _supplyCompV3(address tok, uint amount) external override {
checkStorage();
//approval
approval(tok, compoundV3Comet[tok], amount);
CompoundV3(compoundV3Comet[tok]).supply(tok, amount);
}
/**
* @notice _withdrawCompoundV3 function withdraws the fund of token from CompoundV3 protocol.
* @param tok address of the token to consider to withdraw.
* @param amount i.e calculated amount of token to withdraw.
*/
function _withdrawCompoundV3(address tok, uint amount) external override {
checkStorage();
CompoundV3(compoundV3Comet[tok]).withdraw(tok, amount);
}
/**
* @notice _supplyAave function supply the fund of token to AAVe protocol for yield generation.
* @dev this function should be called by AFiStorage only
* @param tok address of the token to consider for supply.
* @param amount i.e calculated amount of token to invest.
*/
function _supplyAave(address tok, uint amount) external override {
checkStorage();
//approval
approval(tok, address(_lendingPool()), amount);
_lendingPool().deposit(tok, amount, address(this), 0);
}
/**
* @notice _supplyCompound function supply the fund of token to Compound protocol for yield generation.
* @dev this function should be called by AFiStorage only
* @param tok address of the token to consider for supply.
* @param amount i.e calculated amount of token to invest.
*/
function _supplyCompound(address tok, uint amount) external override {
checkStorage();
//approval
approval(tok, compound[tok], amount);
checkEqual(Compound(compound[tok]).mint(amount), 0);
}
function approval(address tok, address sender, uint256 amount) internal {
uint256 allowance = IERC20(tok).allowance(address(this), sender);
if (allowance < amount) {
IERC20(tok).safeIncreaseAllowance(sender, (amount - allowance));
}
}
/**
* @notice _withdrawAave function withdraws the fund of token from AAve protocol.
* @param tok address of the token to consider to withdraw.
* @param amount i.e calculated amount of token to withdraw.
*/
function _withdrawAave(address tok, uint amount) external override {
checkStorage();
_lendingPool().withdraw(tok, amount, address(this));
}
/**
* @notice _withdrawCompound function withdraws the fund of token from Compound protocol.
* @param tok address of the token to consider to withdraw.
* @param amount i.e calculated amount of token to withdraw.
*/
function _withdrawCompound(address tok, uint amount) external override {
checkStorage();
checkEqual(Compound(compound[tok]).redeemUnderlying(amount), 0);
}
/**
* @notice updatePoolData function updates the pool data in the process of rebalance.
* @param data encoded data to update.
*/
function updatePoolData(bytes memory data) external override nonReentrant {
checkManager();
setInitialValues(data);
}
/**
* @notice Returns the array of underlying tokens.
* @return uTokensArray Array of underlying tokens.
*/
function getUTokens() external view override returns (address[] memory uTokensArray) {
return uTokens;
}
function getProportions()
external
view
override
returns (uint[] memory, uint[] memory)
{
return (uTokenProportions, defaultProportion);
}
/**
* @notice Sets unstaking data and returns necessary information.
* @dev This function is used to set unstaking data and returns relevant information.
* @param totalQueuedShares The total number of queued shares for unstaking.
* @return token An array containing token addresses.
* @return uTokens An array containing addresses of underlying tokens.
* @return pool The address of the pool.
* @return tSupply The total supply of tokens after considering queued shares.
*/
function setUnstakeData(
uint256 totalQueuedShares
) external override returns (address[] memory, address[] memory, uint256, uint256) {
checkOracle();
uint256 tSupply = _totalSupply;
if (totalQueuedShares != 0) {
_totalSupply -= totalQueuedShares;
}
return (token, uTokens, pool, tSupply);
}
/**
* @notice Retrieves input tokens.
* @dev This function is used to retrieve input token addresses and non-overlapping input token addresses.
* @return token An array containing input token addresses.
* @return nonOverlappingITokens An array containing non-overlapping input token addresses.
*/
function getInputToken()
external
view
override
returns (address[] memory, address[] memory)
{
return (token, nonOverlappingITokens);
}
/**
* @notice setInitialValues function initialises the pool and afi product data
* @param data i.e encoded data that contains pool, product data.
*/
function setInitialValues(bytes memory data) internal {
IAFi.PoolsData memory pooldata = abi.decode(data, (IAFi.PoolsData));
IAFi.UnderlyingData memory uData = abi.decode(
pooldata.underlyingData,
(IAFi.UnderlyingData)
);
address tok;
uint uLen = uData._underlyingTokens.length;
for (uint i = 0; i < uLen; i++) {
tok = uData._underlyingTokens[i];
uTokens.push(uData._underlyingTokens[i]);
uTokenProportions.push(pooldata._underlyingTokensProportion[i]);
compound[tok] = pooldata._compound[i];
compoundV3Comet[tok] = pooldata.compoundV3Comet[i];
aFiStorage.afiSync(
address(this),
tok,
pooldata._aaveToken[i],
compoundV3Comet[tok],
compound[tok]
);
}
}
function updateuTokAndProp(address[] memory _uTokens) external override {
checkManager();
uTokens = _uTokens;
}
function checkManager() internal {
addressEqual(msg.sender, aFiManager);
}
/**
* @notice updateDp Function updates the default proportion after rebalance
* @dev it should be called by the AFiManager contract only.
* @param _defaultProportion i.e array of new default proportion
*/
function updateDp(
uint256[] memory _defaultProportion,
uint256[] memory _uTokensProportion
) external override {
checkManager();
uTokenProportions = _uTokensProportion;
defaultProportion = _defaultProportion;
}
/// @notice Retrieves Aave LendingPool address
/// @return A reference to LendingPool interface
function _lendingPool() internal view returns (ILendingPool) {
return ILendingPool(IPoolAddressesProvider(POOL_ADDRESS_PROVIDER).getPool());
}
function checkOracle() internal {
addressEqual(msg.sender, aFiOracle);
}
/**
* @notice updateShares Function locks/unlocks afi token
* @dev it should be called by the time lock contract only.
* @param user address to lock the afi token from.
* @param amount i.e. amount to be locked/unlocked.
* @param lock i.e. status if amount should be locked or unlocked.
*/
function stakeShares(address user, uint256 amount, bool lock) external {
addressCheck(user, tLContract);
if (lock) {
validateShares(user, amount);
} else {
greaterEqualComparison(userLockedAmount[user], amount);
}
updateLockedTokens(user, amount, lock, false, false, 0);
emit UpdateShares(user, amount, lock);
}
function updateLockedTokens(
address user,
uint256 amount,
bool lock,
bool queue,
bool unqueue,
uint256 newNAV
) public override {
twoAddressCompare(tLContract, aFiOracle);
if (msg.sender == tLContract) {
if (lock) {
userLockedAmount[user] = userLockedAmount[user] + (amount);
} else {
userLockedAmount[user] = userLockedAmount[user] - (amount);
}
}
if (queue) {
_balances[user] -= amount;
if (_balances[user] == 0 && userLockedAmount[user] == 0) {
delete depositNAV[user];
}
emit Transfer(user, address(0), amount);
}
if (unqueue) {
depositNAV[user] = newNAV;
_balances[user] += amount;
emit Transfer(address(0), user, amount);
}
}
/**
* @notice updateTimeLockContract Function updates timelock contract address and zero address should not pass
* @param newTL address of the timelock contract.
*/
function updateTimeLockContract(address newTL) external onlyOwner {
addressCheck(newTL, address(0));
tLContract = newTL;
}
/**
* @notice Allows the owner to emergency withdraw tokens from the contract.
* @dev Only the platform wallet can call this function.
* @param tok Address of the token to be withdrawn.
* @param wallet Address to receive the withdrawn tokens.
*/
function emergencyWithdraw(address tok, address wallet) external {
checkDelayModule();
(bool iPresent, bool present) = checkTokInList(tok);
checkFalse(present);
checkFalse(iPresent);
contractTransfers(tok, wallet, balance(tok, address(this)));
}
function checkDelayModule() internal {
addressEqual(msg.sender, delayModule);
}
/**
* @notice Returns the balance of a specific token in the AFi contract.
* @param tok The address of the token.
* @param user The address of the AFi contract or any user.
* @return The token balance.
*/
function balance(address tok, address user) internal view returns (uint) {
return IERC20(tok).balanceOf(user);
}
/**
* @notice Updates the list of input tokens for the contract.
* @dev Only the contract owner can call this function.
* @param _nonOverlappingITokens Array of addresses representing input tokens.
*/
function updateInputTokens(
address[] memory _nonOverlappingITokens
) external override {
twoAddressCompare(owner(), aFiManager);
nonOverlappingITokens = _nonOverlappingITokens;
}
/**
* @notice Returns the NAV (Net Asset Value) of a user's deposited funds.
* @param user Address of the user.
* @return The NAV of the user's deposited funds.
*/
function depositUserNav(address user) external view override returns (uint256) {
if (_balances[user] == 0) {
return 0;
} else {
return depositNAV[user];
}
}
function migration(address iToken) external onlyOwner {
addressCheck(PARENT_VAULT, address(0));
checkFalse(migrated);
_totalSupply += IERC20(PARENT_VAULT).totalSupply();
migrated = true;
increasecsCounter();
setPreDeposit(iToken, balance(iToken, address(this)));
}
function checkEqual(uint256 valA, uint256 valB) internal {
require(valA == valB, "AB222");
}
function exchangeToken() external {
checkFalse(!migrated);
uint256 shares = balance(PARENT_VAULT, msg.sender);
greaterComparision(shares, 0);
uint256 userNAV = IAFi(PARENT_VAULT).depositUserNav(msg.sender);
IERC20(PARENT_VAULT).safeTransferFrom(msg.sender, DEAD_ADDRESS, shares);
uint256 nav = depositNAV[msg.sender];
uint256 bal = _balances[msg.sender];
if (nav != 0 && bal > 0) {
userNAV = ((nav * bal) + (shares * userNAV)) / (bal + shares);
}
_balances[msg.sender] += shares;
emit Transfer(address(0), msg.sender, shares);
makeUpdates(userNAV, 0);
}
function makeUpdates(uint256 userNAV, uint256 nonwithdrawable) internal {
depositNAV[msg.sender] = userNAV; //take weigted average
nonWithdrawableShares[msg.sender][cSwapCounter] += nonwithdrawable;
}
}File 2 of 25: Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}File 3 of 25: ArrayUtils.sol
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;
// Reference: https://github.com/cryptofinlabs/cryptofin-solidity/blob/master/contracts/array-utils/AddressArrayUtils.sol
library ArrayUtils {
/**
* Deletes address at index and fills the spot with the last address.
* Order is preserved.
*/
// solhint-disable-next-line var-name-mixedcase
function sPopAddress(address[] storage A, uint index) internal {
uint length = A.length;
if (index >= length) {
revert("Error: index out of bounds");
}
for (uint i = index; i < length - 1; i++) {
A[i] = A[i + 1];
}
A.pop();
}
// solhint-disable-next-line var-name-mixedcase
function sPopUint256(uint[] storage A, uint index) internal {
uint length = A.length;
if (index >= length) {
revert("Error: index out of bounds");
}
for (uint i = index; i < length - 1; i++) {
A[i] = A[i + 1];
}
A.pop();
}
// solhint-disable-next-line var-name-mixedcase
function sumOfMArrays(
uint[] memory A,
uint[] memory B
) internal pure returns (uint[] memory sum) {
sum = new uint[](A.length);
for (uint i = 0; i < A.length; i++) {
sum[i] = A[i] + B[i];
}
return sum;
}
/**
* Finds the index of the first occurrence of the given element.
* @param A The input array to search
* @param a The value to find
* @return Returns (index and isIn) for the first occurrence starting from index 0
*/
function indexOf(address[] memory A, address a) internal pure returns (uint, bool) {
uint length = A.length;
for (uint i = 0; i < length; i++) {
if (A[i] == a) {
return (i, true);
}
}
return (type(uint).max, false);
}
/**
* Returns true if the value is present in the list. Uses indexOf internally.
* @param A The input array to search
* @param a The value to find
* @return Returns isIn for the first occurrence starting from index 0
*/
function contains(address[] memory A, address a) internal pure returns (bool) {
(, bool isIn) = indexOf(A, a);
return isIn;
}
/**
* Returns true if there are 2 elements that are the same in an array
* @param A The input array to search
* @return Returns boolean for the first occurrence of a duplicate
*/
function hasDuplicate(address[] memory A) internal pure returns (bool) {
require(A.length > 0, "A is empty");
for (uint i = 0; i < A.length - 1; i++) {
address current = A[i];
for (uint j = i + 1; j < A.length; j++) {
if (current == A[j]) {
return true;
}
}
}
return false;
}
/**
* @param A The input array to search
* @param a The address to remove
* @return Returns the array with the object removed.
*/
function remove(
address[] memory A,
address a
) internal pure returns (address[] memory) {
(uint index, bool isIn) = indexOf(A, a);
if (!isIn) {
revert("Address not in array.");
} else {
(address[] memory _A, ) = pop(A, index);
return _A;
}
}
/**
* @param A The input array to search
* @param a The address to remove
*/
function removeStorage(address[] storage A, address a) internal {
(uint index, bool isIn) = indexOf(A, a);
if (!isIn) {
revert("Address not in array.");
} else {
uint lastIndex = A.length - 1; // If the array would be empty, the previous line would throw, so no underflow here
if (index != lastIndex) {
A[index] = A[lastIndex];
}
A.pop();
}
}
/**
* Removes specified index from array
* @param A The input array to search
* @param index The index to remove
* @return Returns the new array and the removed entry
*/
function pop(
address[] memory A,
uint index
) internal pure returns (address[] memory, address) {
uint length = A.length;
require(index < A.length, "Index must be < A length");
address[] memory newAddresses = new address[](length - 1);
for (uint i = 0; i < index; i++) {
newAddresses[i] = A[i];
}
for (uint j = index + 1; j < length; j++) {
newAddresses[j - 1] = A[j];
}
return (newAddresses, A[index]);
}
/**
* Returns the combination of the two arrays
* @param A The first array
* @param B The second array
* @return Returns A extended by B
*/
function extend(
address[] memory A,
address[] memory B
) internal pure returns (address[] memory) {
uint aLength = A.length;
uint bLength = B.length;
address[] memory newAddresses = new address[](aLength + bLength);
for (uint i = 0; i < aLength; i++) {
newAddresses[i] = A[i];
}
for (uint j = 0; j < bLength; j++) {
newAddresses[aLength + j] = B[j];
}
return newAddresses;
}
/**
* Validate that address and uint array lengths match. Validate address array is not empty
* and contains no duplicate elements.
*
* @param A Array of addresses
* @param B Array of uint
*/
function validatePairsWithArray(address[] memory A, uint[] memory B) internal pure {
require(A.length == B.length, "Array length mismatch");
_validateLengthAndUniqueness(A);
}
/**
* Validate that address and bool array lengths match. Validate address array is not empty
* and contains no duplicate elements.
*
* @param A Array of addresses
* @param B Array of bool
*/
function validatePairsWithArray(address[] memory A, bool[] memory B) internal pure {
require(A.length == B.length, "Array length mismatch");
_validateLengthAndUniqueness(A);
}
/**
* Validate that address and string array lengths match. Validate address array is not empty
* and contains no duplicate elements.
*
* @param A Array of addresses
* @param B Array of strings
*/
function validatePairsWithArray(address[] memory A, string[] memory B) internal pure {
require(A.length == B.length, "Array length mismatch");
_validateLengthAndUniqueness(A);
}
/**
* Validate that address array lengths match, and calling address array are not empty
* and contain no duplicate elements.
*
* @param A Array of addresses
* @param B Array of addresses
*/
function validatePairsWithArray(
address[] memory A,
address[] memory B
) internal pure {
require(A.length == B.length, "Array length mismatch");
_validateLengthAndUniqueness(A);
}
/**
* Validate that address and bytes array lengths match. Validate address array is not empty
* and contains no duplicate elements.
*
* @param A Array of addresses
* @param B Array of bytes
*/
function validatePairsWithArray(address[] memory A, bytes[] memory B) internal pure {
require(A.length == B.length, "Array length mismatch");
_validateLengthAndUniqueness(A);
}
/**
* Validate address array is not empty and contains no duplicate elements.
*
* @param A Array of addresses
*/
function _validateLengthAndUniqueness(address[] memory A) internal pure {
require(A.length > 0, "Array length must be > 0");
require(!hasDuplicate(A), "Cannot duplicate addresses");
}
}File 4 of 25: Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}File 5 of 25: CustomizeIERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface CustomizeIERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
}File 6 of 25: DataTypes.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
library DataTypes {
struct ReserveData {
//stores the reserve configuration
ReserveConfigurationMap configuration;
//the liquidity index. Expressed in ray
uint128 liquidityIndex;
//the current supply rate. Expressed in ray
uint128 currentLiquidityRate;
//variable borrow index. Expressed in ray
uint128 variableBorrowIndex;
//the current variable borrow rate. Expressed in ray
uint128 currentVariableBorrowRate;
//the current stable borrow rate. Expressed in ray
uint128 currentStableBorrowRate;
//timestamp of last update
uint40 lastUpdateTimestamp;
//the id of the reserve. Represents the position in the list of the active reserves
uint16 id;
//aToken address
address aTokenAddress;
//stableDebtToken address
address stableDebtTokenAddress;
//variableDebtToken address
address variableDebtTokenAddress;
//address of the interest rate strategy
address interestRateStrategyAddress;
//the current treasury balance, scaled
uint128 accruedToTreasury;
//the outstanding unbacked aTokens minted through the bridging feature
uint128 unbacked;
//the outstanding debt borrowed against this asset in isolation mode
uint128 isolationModeTotalDebt;
}
struct ReserveConfigurationMap {
//bit 0-15: LTV
//bit 16-31: Liq. threshold
//bit 32-47: Liq. bonus
//bit 48-55: Decimals
//bit 56: reserve is active
//bit 57: reserve is frozen
//bit 58: borrowing is enabled
//bit 59: stable rate borrowing enabled
//bit 60: asset is paused
//bit 61: borrowing in isolation mode is enabled
//bit 62-63: reserved
//bit 64-79: reserve factor
//bit 80-115 borrow cap in whole tokens, borrowCap == 0 => no cap
//bit 116-151 supply cap in whole tokens, supplyCap == 0 => no cap
//bit 152-167 liquidation protocol fee
//bit 168-175 eMode category
//bit 176-211 unbacked mint cap in whole tokens, unbackedMintCap == 0 => minting disabled
//bit 212-251 debt ceiling for isolation mode with (ReserveConfiguration::DEBT_CEILING_DECIMALS) decimals
//bit 252-255 unused
uint256 data;
}
struct 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 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;
}
}File 7 of 25: draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}File 8 of 25: ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import {CustomizeIERC20} from "./CustomizeIERC20.sol";
import "./IERC20Metadata.sol";
import "./Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is CustomizeIERC20, Context, IERC20Metadata {
mapping(address => uint256) internal _balances;
mapping(address => mapping(address => uint256)) internal _allowances;
uint256 internal _totalSupply;
string internal _name;
string internal _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
// /**
// * @dev See {IERC20-totalSupply}.
// */
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
// /**
// * @dev See {IERC20-balanceOf}.
// */
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}File 9 of 25: IAFi.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import {IERC20Extended as IERC20} from "./IERC20Extended.sol";
import "./IAFiStorage.sol";
import "./IPassiveRebal.sol";
/**
* @title PassiveRebal.
* @notice Interface of the Passive Rebalance contract.
*/
interface PassiveRebal {
function applyRebalForProportions(
address _aFiContract,
address _aFiManager,
address _aFiStorage,
address[] memory _tokens,
uint256 strategy
) external view returns (uint[] memory proportions, uint256);
function getPauseStatus() external returns (bool);
function getRebalStrategyNumber(address aFiContract) external returns (uint);
function getPauseDepositController(address afiContract) external view returns (address);
}
interface IAFiOracle {
function uniswapV3Oracle(
address afiContract,
address _tokenIn,
address _tokenOut,
uint _amountIn,
uint _maxTime,
address middleToken,
uint256 minimumReturnAmount
) external returns (bytes memory swapParams);
}
interface IAFiManager {
function updateUTokenProportion(
address aFiContract,
address aFiStorage
) external returns (uint256[] memory);
function inputTokenUSD(
IAFi aFiContract,
uint256 cSwapCounter,
IAFiStorage _aFiStorage
) external view returns (uint256 totalPreDepositInUSD);
function rebalanceController() external view returns(address);
function pauseQueueWithdrawUnstaking(address afiContract,bool status) external;
function isQueueWithdrawUnstakingPaused(address afiContract) external view returns(bool);
function getUTokenProportion(
address aFiContract,
address _aFiStorage
)
external
view
returns (uint256[] memory underlyingTokenProportions, uint256 totalProp);
}
/**
* @title IAFi.
* @notice Interface of the AToken.
*/
interface IAFi {
struct UnderlyingData {
address[] _underlyingTokens; //uTokens
address[] _underlyingUniPoolToken; //uToken - MiddleToken
}
struct PoolsData {
address[] _depositStableCoin;
address[] _depositCoinOracle;
bytes underlyingData;
address[] _compound;
address[] _aaveToken;
address[] _priceOracles;
uint[] _underlyingTokensProportion;
address[] compoundV3Comet;
uint _typeOfProduct;
}
struct SwapParameters {
address afiContract;
address oToken;
uint256 cSwapFee;
uint256 cSwapCounter;
address[] depositTokens;
uint256[] minimumReturnAmount;
uint256[] iMinimumReturnAmount; // minimum amount out expcted after swaps For deposit tokens
address[] underlyingTokens;
uint256[] newProviders;
uint _deadline;
address[] cometToClaim;
address[] cometRewardTokens;
uint256[] rewardTokenMinReturnAmounts;
}
struct SwapDataStructure {
bytes[] firstIterationUnderlyingSwap;
bytes[] secondIterationUnderlyingSwap;
bytes[] firstIterationCumulativeSwap;
bytes[] secondIterationCumulativeSwap;
}
struct SwapDescription {
IERC20 srcToken;
IERC20 dstToken;
address payable srcReceiver;
address payable dstReceiver;
uint256 amount;
uint256 minReturnAmount;
uint256 flags;
}
/**
* @notice Function to initialize the data, owner and afi token related data.
* @dev the function should be called once only by factory
* @param newOwner indicates the owner of the created afi product.
* @param _name indicates the name of the afi Token
* @param _symbol indicates symbol of the the afi Token.
* @param data indicates the encoded data that follows the PoolsData struct format.
* @param _isActiveRebalanced indicates the active rebalance status of the afi contract.
* @param _aFiStorage indicates the afi storage contract address.
*/
function initialize(
address newOwner,
string memory _name,
string memory _symbol,
bytes memory data,
bool _isActiveRebalanced,
IAFiStorage _aFiStorage,
address[] memory _commonInputTokens,
address parentVault
) external;
/**
* @notice Function to initialize accepted tokens in deposit and withdraw functions.
* @dev the function should be called once only by factory
* @param iToken indicates the array of the accepted token addressess.
*/
function initializeToken(
address[] memory iToken,
address[] memory _teamWallets,
IPassiveRebal _rebalContract,
address _aFiManager
) external;
function getcSwapCounter() external view returns(uint256);
/**
* @notice Returns the array of underlying tokens.
* @return uTokensArray Array of underlying tokens.
*/
function getUTokens() external view returns (address[] memory uTokensArray);
function swapfromSelectiveDex(
address from,
address to,
uint amount,
uint deadline,
address midTok,
uint minimumReturnAmount,
bytes calldata _oneInchSwapData
) external returns (uint256 _amountOut);
/**
* @notice Returns the paused status of the contract.
*/
function isPaused() external view returns (bool, bool);
function getProportions()
external
view
returns (uint[] memory, uint[] memory);
/**
* @notice Updates the pool data during Active Rebalance.
* @param data that follows PoolsData format indicates the data of the token being rebalanced in Active Rebalance.
*/
function updatePoolData(bytes memory data) external;
function sendProfitOrFeeToManager(
address wallet,
uint profitShare,
address oToken
) external;
function _supplyCompV3(address tok, uint amount) external;
function _supplyAave(address tok, uint amount) external;
function _supplyCompound(address tok, uint amount) external;
function _withdrawAave(address tok, uint amount) external;
function _withdrawCompoundV3(address tok, uint amount) external;
function _withdrawCompound(address tok, uint amount) external;
function getTVLandRebalContractandType()
external
view
returns (uint256, address, uint256);
function getInputToken() external view returns (address[] memory, address[] memory);
function swap(
address inputToken,
address uTok,
uint256 amountAsPerProportion,
uint _deadline,
address middleToken,
uint256 minimumReturnAmount,
bytes calldata swapData
) external returns (uint256 returnAmount);
function updateDp(
uint256[] memory _defaultProportion,
uint256[] memory _uTokensProportion
) external;
function updateuTokAndProp(
address[] memory _uTokens
) external;
function underlyingTokensStaking() external;
function depositUserNav(address user) external view returns (uint256);
function setUnstakeData(uint256 totalQueuedShares) external returns (address[] memory, address[] memory, uint256, uint256);
function isOTokenWhitelisted(address oToken) external view returns (bool);
function validateWithdraw(address user, address oToken, uint256 _shares) external;
function updateLockedTokens(
address user,
uint256 amount,
bool lock,
bool queue,
bool unqueue,
uint256 newNAV
) external;
function updateTVL() external;
function updateInputTokens(address[] memory _inputTokens) external;
function reinitializeHappened(bool status) external;
function pauseUnpauseDeposit(bool status) external;
function getNonWithdrawableShares(address user, uint256 csCounterValue) external view returns(uint256);
function getReinitializeStatus() external view returns (bool vaultReInitialized);
function updateCp(uint256[] memory newCp) external;
}File 10 of 25: IAFiStorage.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
/**
* @title IAFiStorage.
* @notice Interface of the AFiStorage.
*/
interface IIEarnManager {
function recommend(
address _token,
address afiBase,
address afiStorage
) external view returns (string memory choice, uint capr, uint aapr, uint dapr);
}
interface IAFiStorage {
/**
* @notice Struct representing investor details.
* @param isPresent Boolean indicating whether an investor exists.
* @param uTokenBalance Investor underlying token balance.
* @param investedAmount Amount of StableCoin invested in the underlying token
*/
struct Investor {
bool isPresent;
uint depositNAV;
uint redemptionNAV;
}
struct RedemptionParams {
address baseContract;
uint r;
address oToken;
uint256 cSwapCounter;
address[] uTokens;
address[] iTokens;
uint256 deadline;
uint256[] minimumReturnAmount;
uint256 _pool;
uint256 tSupply;
uint256 depositNAV;
uint256 minAmountOut;
}
/**
* @notice Struct representing TeamWallet details.
* @param isPresent Boolean indicating whether a wallet exists.
* @param isActive Boolean indicating whether a wallet is active.
* @param walletAddress Wallet address.
*/
struct TeamWallet {
bool isPresent;
bool isActive;
address walletAddress;
}
/**
* @notice Struct representing Rebalance details.
* @param scenario Scenario can be either of 0, 1 or 2.
* @param rebalancedUToken Address of the underlying token that is rebalanced.
* @param rebalancedToUTokens Array of addresses of underlying tokens to which the uToken has been rebalanced.
*/
struct RebalanceDetails {
uint8 scenario;
address rebalancedUToken;
address[] rebalancedToUTokens;
}
/**
* @param walletAddress Address of the wallet.
* @param isActive Boolean indicating wallet active status.
*/
event TeamWalletActive(address indexed walletAddress, bool isActive);
/**
* @param walletAddress Address of the wallet.
* @param isActive Boolean indicating wallet active status.
*/
event TeamWalletAdd(address indexed walletAddress, bool isActive);
/**
* @notice Returns the team wallet details.
* @param aFiContract Address of the AFi contract.
* @param _wallet Wallet address
* @return isPresent Boolean indicating the present status of the wallet.
* @return isActive Boolean indicating whether to set the wallet to either active/inactive.
*/
function getTeamWalletDetails(
address aFiContract,
address _wallet
) external view returns (bool isPresent, bool isActive);
function handleRedemption(
RedemptionParams memory params,
uint _shares,
uint swapMethod,
bytes[] calldata swapData
) external returns (uint256 redemptionFromContract);
/**
* @notice To add a new team wallet.
* @param aFiContract Address of the AFi contract.
* @param _wallet Wallet address that has to be added in the `teamWallets` array.
* @param isActive Boolean indicating whether to set the wallet to either active/inactive.
* @param isPresent Boolean indicating the present status of the wallet.
*/
function addTeamWallet(
address aFiContract,
address _wallet,
bool isActive,
bool isPresent
) external;
/**
* @notice Returns the team wallets for an AFi.
* @param aFiContract Address of the AFi contract.
* @return _teamWallets Array of teamWallets.
*/
function getTeamWalletsOfAFi(
address aFiContract
) external view returns (address[] memory _teamWallets);
/**
* @notice Sets the address for team wallets.
* @param aFiContract Address of the AFi contract.
* @param _teamWallets Array of addresses for the team wallets.
*/
function setTeamWallets(address aFiContract, address[] memory _teamWallets) external;
/**
* @notice Sets the status for the AFi in the storage contract.
* @param aFiContract Address of the AFi contract.
* @param active status for afiContracts.
*/
function setAFiActive(address aFiContract, bool active) external;
/**
* @notice Sets Active Rebalance status of an AFi.
* @param aFiContract Address of the AFi contract.
* @param status indicating active rebalance status of the AFi contract.
*/
function setActiveRebalancedStatus(address aFiContract, bool status) external;
/**
* @notice gets Active Rebalance status of an AFi.
* @param aFiContract Address of the AFi contract.
* @return _isActiveRebalanced bool indicating active rebalance status of the AFi contract.
*/
function isAFiActiveRebalanced(
address aFiContract
) external view returns (bool _isActiveRebalanced);
function getTotalActiveWallets(address aFiContract) external view returns (uint);
function calcPoolValue(
address tok,
address afiContract
) external view returns (uint);
function calculateBalanceOfUnderlying(
address tok,
address afiContract
) external view returns (uint);
function calculatePoolInUsd(address afiContract) external view returns (uint);
function afiSync(
address afiContract,
address tok,
address aaveTok,
address compV3Comet,
address compTok
) external;
function getPriceInUSD(
address tok
) external view returns (uint256, uint256);
function validateAndGetDecimals(address tok) external view returns (uint256);
function getStakedStatus(
address aFiContract,
address uToken
) external view returns (bool);
function rearrange(address aFiContract,address[] memory underlyingTokens, uint256[] memory newProviders) external;
function swapForOtherProduct(
address afiContract,
uint r,
address oToken,
uint deadline,
uint[] memory minimumReturnAmount,
address[] memory uToken,
bytes[] calldata swapData
) external returns (uint256);
function _withdrawAll(address afiContract, address tok) external returns(bool);
function getAFiOracle() external view returns(address);
function calculateRedemptionFromContract(
address afiContract,
address tok,
uint256 r
) external view returns (uint256, bool, uint256, uint256, uint256);
function tvlRead(
address tok,
address afiContract
) external view returns (uint, uint256);
function getPreSwapDepositsTokens(
address aFiContract,
uint256 _cSwapCounter,
address stableToken
) external view returns (uint256);
function setPreDepositedInputToken(uint256 _cSwapCounter, uint256 _amount,address _oToken) external;
function setPreDepositedInputTokenInRebalance(
address aficontract,
uint256 _cSwapCounter,
uint256 _amount,
address _oToken
) external;
function convertInUSDAndTok(
address tok,
uint256 amt,
bool usd
) external view returns (uint256);
function calculateShares(
address afiContract,
uint256 amount,
uint256 prevPool,
uint256 _totalSupply,
address iToken,
uint256 currentDepositNAV,
uint256 prevBalance
) external view returns (uint256 shares, uint256 newDepositNAV);
function deletePreDepositedInputToken(
address aFiContract,
address oToken,
uint256 currentCounter
)external;
function doSwapForThewhiteListRemoval(
address tok,
uint256 _cSwapCounter,
address swapToken,
uint256 deadline,
uint256 minAmountOut,
bytes calldata swapData
) external;
function setPreDepositedInputTokenInReInitialize(
address aficontract,
uint256 _cSwapCounter,
uint256 _amount,
address _oToken
) external;
function withdrawStableTokens(
address afiContract,
uint r,
address oToken,
address[] memory token,
uint256 deadline,
uint256[] memory minimumReturnAmount,
bytes[] calldata swapData
) external returns (uint256 redemptionBalance);
}
File 11 of 25: IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}File 12 of 25: IERC20Extended.sol
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;
import "./IERC20.sol";
interface IERC20Extended is IERC20 {
function decimals() external view returns (uint8);
}File 13 of 25: IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "./CustomizeIERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is CustomizeIERC20 {
/**
* @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);
}File 14 of 25: ILendingPool.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;
import {DataTypes} from "./DataTypes.sol";
interface ILendingPool {
/**
* @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
* - E.g. User deposits 100 USDC and gets in return 100 aUSDC
* @param asset The address of the underlying asset to deposit
* @param amount The amount to be deposited
* @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
* is a different wallet
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
**/
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
/**
* @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned
* E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC
* @param asset The address of the underlying asset to withdraw
* @param amount The underlying amount to be withdrawn
* - Send the value type(uint256).max in order to withdraw the whole aToken balance
* @param to Address that will receive the underlying, same as msg.sender if the user
* wants to receive it on his own wallet, or a different address if the beneficiary is a
* different wallet
* @return The final amount withdrawn
**/
function withdraw(
address asset,
uint256 amount,
address to
) external returns (uint256);
/**
* @dev Returns the state and configuration of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The state of the reserve
**/
function getReserveData(
address asset
) external view returns (DataTypes.ReserveData memory);
}
File 15 of 25: ILendingPoolAddressesProvider.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
/**
* @title IPoolAddressesProvider
* @author Aave
* @notice Defines the basic interface for a Pool Addresses Provider.
**/
interface IPoolAddressesProvider {
/**
* @dev Emitted when the market identifier is updated.
* @param oldMarketId The old id of the market
* @param newMarketId The new id of the market
*/
event MarketIdSet(string indexed oldMarketId, string indexed newMarketId);
/**
* @dev Emitted when the pool is updated.
* @param oldAddress The old address of the Pool
* @param newAddress The new address of the Pool
*/
event PoolUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the pool configurator is updated.
* @param oldAddress The old address of the PoolConfigurator
* @param newAddress The new address of the PoolConfigurator
*/
event PoolConfiguratorUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the price oracle is updated.
* @param oldAddress The old address of the PriceOracle
* @param newAddress The new address of the PriceOracle
*/
event PriceOracleUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the ACL manager is updated.
* @param oldAddress The old address of the ACLManager
* @param newAddress The new address of the ACLManager
*/
event ACLManagerUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the ACL admin is updated.
* @param oldAddress The old address of the ACLAdmin
* @param newAddress The new address of the ACLAdmin
*/
event ACLAdminUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the price oracle sentinel is updated.
* @param oldAddress The old address of the PriceOracleSentinel
* @param newAddress The new address of the PriceOracleSentinel
*/
event PriceOracleSentinelUpdated(
address indexed oldAddress,
address indexed newAddress
);
/**
* @dev Emitted when the pool data provider is updated.
* @param oldAddress The old address of the PoolDataProvider
* @param newAddress The new address of the PoolDataProvider
*/
event PoolDataProviderUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when a new proxy is created.
* @param id The identifier of the proxy
* @param proxyAddress The address of the created proxy contract
* @param implementationAddress The address of the implementation contract
*/
event ProxyCreated(
bytes32 indexed id,
address indexed proxyAddress,
address indexed implementationAddress
);
/**
* @dev Emitted when a new non-proxied contract address is registered.
* @param id The identifier of the contract
* @param oldAddress The address of the old contract
* @param newAddress The address of the new contract
*/
event AddressSet(
bytes32 indexed id,
address indexed oldAddress,
address indexed newAddress
);
/**
* @dev Emitted when the implementation of the proxy registered with id is updated
* @param id The identifier of the contract
* @param proxyAddress The address of the proxy contract
* @param oldImplementationAddress The address of the old implementation contract
* @param newImplementationAddress The address of the new implementation contract
*/
event AddressSetAsProxy(
bytes32 indexed id,
address indexed proxyAddress,
address oldImplementationAddress,
address indexed newImplementationAddress
);
/**
* @notice Returns the id of the Aave market to which this contract points to.
* @return The market id
**/
function getMarketId() external view returns (string memory);
/**
* @notice Associates an id with a specific PoolAddressesProvider.
* @dev This can be used to create an onchain registry of PoolAddressesProviders to
* identify and validate multiple Aave markets.
* @param newMarketId The market id
*/
function setMarketId(string calldata newMarketId) external;
/**
* @notice Returns an address by its identifier.
* @dev The returned address might be an EOA or a contract, potentially proxied
* @dev It returns ZERO if there is no registered address with the given id
* @param id The id
* @return The address of the registered for the specified id
*/
function getAddress(bytes32 id) external view returns (address);
/**
* @notice General function to update the implementation of a proxy registered with
* certain `id`. If there is no proxy registered, it will instantiate one and
* set as implementation the `newImplementationAddress`.
* @dev IMPORTANT Use this function carefully, only for ids that don't have an explicit
* setter function, in order to avoid unexpected consequences
* @param id The id
* @param newImplementationAddress The address of the new implementation
*/
function setAddressAsProxy(bytes32 id, address newImplementationAddress) external;
/**
* @notice Sets an address for an id replacing the address saved in the addresses map.
* @dev IMPORTANT Use this function carefully, as it will do a hard replacement
* @param id The id
* @param newAddress The address to set
*/
function setAddress(bytes32 id, address newAddress) external;
/**
* @notice Returns the address of the Pool proxy.
* @return The Pool proxy address
**/
function getPool() external view returns (address);
/**
* @notice Updates the implementation of the Pool, or creates a proxy
* setting the new `pool` implementation when the function is called for the first time.
* @param newPoolImpl The new Pool implementation
**/
function setPoolImpl(address newPoolImpl) external;
/**
* @notice Returns the address of the PoolConfigurator proxy.
* @return The PoolConfigurator proxy address
**/
function getPoolConfigurator() external view returns (address);
/**
* @notice Updates the implementation of the PoolConfigurator, or creates a proxy
* setting the new `PoolConfigurator` implementation when the function is called for the first time.
* @param newPoolConfiguratorImpl The new PoolConfigurator implementation
**/
function setPoolConfiguratorImpl(address newPoolConfiguratorImpl) external;
/**
* @notice Returns the address of the price oracle.
* @return The address of the PriceOracle
*/
function getPriceOracle() external view returns (address);
/**
* @notice Updates the address of the price oracle.
* @param newPriceOracle The address of the new PriceOracle
*/
function setPriceOracle(address newPriceOracle) external;
/**
* @notice Returns the address of the ACL manager.
* @return The address of the ACLManager
*/
function getACLManager() external view returns (address);
/**
* @notice Updates the address of the ACL manager.
* @param newAclManager The address of the new ACLManager
**/
function setACLManager(address newAclManager) external;
/**
* @notice Returns the address of the ACL admin.
* @return The address of the ACL admin
*/
function getACLAdmin() external view returns (address);
/**
* @notice Updates the address of the ACL admin.
* @param newAclAdmin The address of the new ACL admin
*/
function setACLAdmin(address newAclAdmin) external;
/**
* @notice Returns the address of the price oracle sentinel.
* @return The address of the PriceOracleSentinel
*/
function getPriceOracleSentinel() external view returns (address);
/**
* @notice Updates the address of the price oracle sentinel.
* @param newPriceOracleSentinel The address of the new PriceOracleSentinel
**/
function setPriceOracleSentinel(address newPriceOracleSentinel) external;
/**
* @notice Returns the address of the data provider.
* @return The address of the DataProvider
*/
function getPoolDataProvider() external view returns (address);
/**
* @notice Updates the address of the data provider.
* @param newDataProvider The address of the new DataProvider
**/
function setPoolDataProvider(address newDataProvider) external;
}
File 16 of 25: IPassiveRebal.sol
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;
interface IPassiveRebal {
// Enum for supported DEXs
enum DexChoice {
UNISWAP_V3,
ONE_INCH,
NONE
}
function applyRebalForProportions(
address _aFiContract,
address _aFiManager,
address _aFiStorage,
address[] memory _tokens,
uint256 strategy
) external view returns (uint[] memory proportions, uint256 totalProp);
function getPauseStatus() external returns (bool);
function getRebalStrategyNumber(address aFiContract) external view returns (uint);
function uniswapV3Oracle(
address afiContract,
address _tokenIn,
address _tokenOut,
uint _amountIn,
uint _maxTime,
address middleToken,
uint256 minimumReturnAmount
) external returns (bytes memory swapParams);
function getMidToken(address tok) external view returns (address);
function upDateInputTokPool(address[] memory iToken, bytes memory uniData) external;
function getPriceOracle(address tok) external view returns (address);
function updateOracleData(
address _uToken,
address _oracleAddress
) external;
function removeToken(
address[] memory _nonOverlappingITokens,
address token
) external pure returns (address[] memory);
function initUniStructure(
address[] memory inputTokens,
bytes memory _poolData
) external;
function getDexType(address tokenIn, address tokenOut) external view returns (DexChoice);
function getPauseDepositController(address afiContract) external view returns (address);
function getStalePriceDelay(address uToken) external view returns (uint256);
function isSwapMethodPaused(address afiContract,uint swapMethod) external view returns (bool);
function getMinimumAmountOut(
address _tokenIn,
uint256 _amountIn,
address _tokenOut,
address _uniPool
) external view returns (uint256 amountOut);
function updateMidToken(address[] memory tok, address[] memory midTok) external;
function getPreSwapDepositLimit() external view returns (uint256);
function validateAndApplyRebalanceStrategy(
address afiContract,
address[] memory uTokens,
uint256 toSwap,
uint256 cSwapCounter
) external returns ( uint256 );
}
File 17 of 25: ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}
/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another token
/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
/// @return amountOut The amount of the received token
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
/// @return amountOut The amount of the received token
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another token
/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
/// @return amountIn The amount of the input token
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
/// @return amountIn The amount of the input token
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}File 18 of 25: IUniswapV3.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import "./IUniswapV3Factory.sol";
import "./IAFi.sol";
interface IUniswapOracleV3 {
function PERIOD() external returns (uint256);
function factory() external returns (address);
function getTotalProfit() external view returns (uint256);
function getDaoProfit() external view returns (uint256);
function update(address _tokenIn, address _tokenOut) external;
function quotePrice(IAFi aFiContract,address _tokenIn, address _depositToken, uint256 _amount) external view returns (uint256 price);
function consult(
address _tokenIn,
uint256 _amountIn,
address _tokenOut
) external view returns (uint256 _amountOut);
function estimateAmountOut(
address tokenIn,
uint128 amountIn,
address tokenOut
) external view returns (uint amountOut);
function estimateAmountOutMin(
address tokenIn,
uint128 amountIn,
address tokenOut,
address pool
) external view returns (uint amountOut);
function updateAndConsult(
address _tokenIn,
uint256 _amountIn,
address _tokenOut
) external returns (uint256 _amountOut);
function checkUnderlyingPool(address token) external view returns (bool hasPool);
function getStalePriceDelay(address aFiContract, address uToken) external view returns(uint256);
function getPriceAndDecimals(address aFiContract, address uToken, address feed) external view returns(int256 , uint8 );
function getPriceInUSD(address tok) external view returns (uint256, uint256);
function getControllers(address afiContract) external view returns(address, address);
function cumulativeSwap(IAFi.SwapParameters memory params, uint256 pauseDepositFees, IAFi.SwapDataStructure calldata dexdata, bytes calldata cometSwapData, uint256 minAmountOut) external;
function untrackedTokenSetByManager(address afiContract, address[] memory depositTokens, address[] memory uTok, uint256 csCounter) external;
}
File 19 of 25: IUniswapV3Factory.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
/// @notice Emitted when the owner of the factory is changed
/// @param oldOwner The owner before the owner was changed
/// @param newOwner The owner after the owner was changed
event OwnerChanged(address indexed oldOwner, address indexed newOwner);
/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(
address indexed token0,
address indexed token1,
uint24 indexed fee,
int24 tickSpacing,
address pool
);
/// @notice Emitted when a new fee amount is enabled for pool creation via the factory
/// @param fee The enabled fee, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);
/// @notice Returns the current owner of the factory
/// @dev Can be changed by the current owner via setOwner
/// @return The address of the factory owner
function owner() external view returns (address);
/// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
/// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
/// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
/// @return The tick spacing
function feeAmountTickSpacing(uint24 fee) external view returns (int24);
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The pool address
function getPool(
address tokenA,
address tokenB,
uint24 fee
) external view returns (address pool);
/// @notice Creates a pool for the given two tokens and fee
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param fee The desired fee for the pool
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
/// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
/// are invalid.
/// @return pool The address of the newly created pool
function createPool(
address tokenA,
address tokenB,
uint24 fee
) external returns (address pool);
/// @notice Updates the owner of the factory
/// @dev Must be called by the current owner
/// @param _owner The new owner of the factory
function setOwner(address _owner) external;
/// @notice Enables a fee amount with the given tickSpacing
/// @dev Fee amounts may never be removed once enabled
/// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
/// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}
interface IUniswapV3Pool {
function observe(
uint32[] calldata secondsAgos
) external
view
returns (
int56[] memory tickCumulatives,
uint160[] memory secondsPerLiquidityCumulativeX128s
);
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
function fee() external returns(uint24);
}File 20 of 25: Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "./Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}File 21 of 25: Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.0;
import "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address internal _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
// /**
// * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
// * Can only be called by the current owner.
// */
// function transferOwnership(address newOwner) public virtual override onlyOwner {
// _pendingOwner = newOwner;
// emit OwnershipTransferStarted(owner(), newOwner);
// }
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() external {
address sender = _msgSender();
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
_transferOwnership(sender);
}
}File 22 of 25: OwnableDelayModule.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Ownable2Step} from "./Ownable2Step.sol";
contract OwnableDelayModule is Ownable2Step {
address internal delayModule;
constructor() {
delayModule = msg.sender;
}
function isDelayModule() internal view {
require(msg.sender == delayModule, "NA");
}
function setDelayModule(address _delayModule) external {
isDelayModule();
require(_delayModule != address(0), "ODZ");
delayModule = _delayModule;
}
function getDelayModule() external view returns (address) {
return delayModule;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public override {
isDelayModule();
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
}
File 23 of 25: ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}File 24 of 25: SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
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 uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @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
*
* _Available since v4.2._
*/
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 uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(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
*
* _Available since v2.5._
*/
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 uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(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
*
* _Available since v4.2._
*/
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 uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(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
*
* _Available since v2.5._
*/
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 uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(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
*
* _Available since v2.5._
*/
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 uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(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
*
* _Available since v2.5._
*/
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
*
* _Available since v2.5._
*/
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.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @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 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @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 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @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 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @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 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @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 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
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);
}
}
File 25 of 25: SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./draft-IERC20Permit.sol";
import "./Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}Contract ABI
API[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"investor","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"depToken","type":"address"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"afiContract","type":"address"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"afiContract","type":"address"}],"name":"InitializedToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bool","name":"lock","type":"bool"}],"name":"UpdateShares","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"investor","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"withdrawnToken","type":"address"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"PARENT_VAULT","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_supplyAave","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_supplyCompV3","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_supplyCompound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_withdrawAave","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_withdrawCompound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_withdrawCompoundV3","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"aFiManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"aFiOracle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"aFiStorage","outputs":[{"internalType":"contract IAFiStorage","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"}],"name":"addToWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"compoundV3Comet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"iToken","type":"address"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"depositUserNav","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"address","name":"wallet","type":"address"}],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"exchangeToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDelayModule","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getInputToken","outputs":[{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"csCounterValue","type":"uint256"}],"name":"getNonWithdrawableShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProportions","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReinitializeStatus","outputs":[{"internalType":"bool","name":"_vaultReInitialized","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTVLandRebalContractandType","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUTokens","outputs":[{"internalType":"address[]","name":"uTokensArray","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getcSwapCounter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getplatformWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"},{"internalType":"string","name":"tokenName","type":"string"},{"internalType":"string","name":"tokenSymbol","type":"string"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"bool","name":"_isActiveRebalanced","type":"bool"},{"internalType":"contract IAFiStorage","name":"_aFiStorage","type":"address"},{"internalType":"address[]","name":"_nonOverlappingITokens","type":"address[]"},{"internalType":"address","name":"parentVault","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"iToken","type":"address[]"},{"internalType":"address[]","name":"_teamWallets","type":"address[]"},{"internalType":"contract IPassiveRebal","name":"_rebalContract","type":"address"},{"internalType":"address","name":"_aFiManager","type":"address"}],"name":"initializeToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isAfiTransferrable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"oToken","type":"address"}],"name":"isOTokenWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isPausedForWithdrawals","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"migrated","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"iToken","type":"address"}],"name":"migration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minimumDepositLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"status","type":"bool"}],"name":"pauseUnpauseDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"status","type":"bool"}],"name":"pauseWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebalContract","outputs":[{"internalType":"contract IPassiveRebal","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"status","type":"bool"}],"name":"reinitializeHappened","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"address","name":"swapTok","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"bytes","name":"swapData","type":"bytes"}],"name":"removeFromWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"wallet","type":"address"},{"internalType":"uint256","name":"profitShare","type":"uint256"},{"internalType":"address","name":"oToken","type":"address"}],"name":"sendProfitOrFeeToManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_afiTransferrable","type":"bool"}],"name":"setAfiTransferability","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delayModule","type":"address"}],"name":"setDelayModule","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"limit","type":"uint256"}],"name":"setMinDepLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"totalQueuedShares","type":"uint256"}],"name":"setUnstakeData","outputs":[{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_platformWallet","type":"address"}],"name":"setplatformWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"lock","type":"bool"}],"name":"stakeShares","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"address","name":"uTok","type":"address"},{"internalType":"uint256","name":"amountAsPerProportion","type":"uint256"},{"internalType":"uint256","name":"_deadline","type":"uint256"},{"internalType":"address","name":"middleToken","type":"address"},{"internalType":"uint256","name":"minimumReturnAmount","type":"uint256"},{"internalType":"bytes","name":"swapData","type":"bytes"}],"name":"swap","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"midTok","type":"address"},{"internalType":"uint256","name":"minimumReturnAmount","type":"uint256"},{"internalType":"bytes","name":"_oneInchSwapData","type":"bytes"}],"name":"swapfromSelectiveDex","outputs":[{"internalType":"uint256","name":"_amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tLContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tok","type":"address"},{"internalType":"bool","name":"_pause","type":"bool"}],"name":"togglePauseDepositTokenForWithdrawals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlyingTokensStaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"newCp","type":"uint256[]"}],"name":"updateCp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_defaultProportion","type":"uint256[]"},{"internalType":"uint256[]","name":"_uTokensProportion","type":"uint256[]"}],"name":"updateDp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_nonOverlappingITokens","type":"address[]"}],"name":"updateInputTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"lock","type":"bool"},{"internalType":"bool","name":"queue","type":"bool"},{"internalType":"bool","name":"unqueue","type":"bool"},{"internalType":"uint256","name":"newNAV","type":"uint256"}],"name":"updateLockedTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"updatePoolData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateTVL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newTL","type":"address"}],"name":"updateTimeLockContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_uTokens","type":"address[]"}],"name":"updateuTokAndProp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userLockedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"oToken","type":"address"},{"internalType":"uint256","name":"_shares","type":"uint256"}],"name":"validateWithdraw","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vaultReInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"address","name":"oToken","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256[]","name":"minimumReturnAmount","type":"uint256[]"},{"internalType":"uint256","name":"swapMethod","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ 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.