Verified contractPartialMIT
MultiPool
Address0xd25ef89058854e3dfe45f01c694f3a2251ea295e
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.35
- Same code
Only this contract
Details
- Compiler
- solc 0.8.35+commit.47b9dedd
- Language
- solidity
- Optimization
- Yes, 200 runs
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,333,580
- Creation transaction
- 0xc502ceb3cb…4cfe761334
- Libraries
- project/contracts/modules/CreditModule.sol:CreditModule0x95bb…da6a29project/contracts/modules/DepositModule.sol:DepositModule0xbd79…73413a
46 files
The source code is large: one file is shown at a time. Choose a file in the list.
- project/contracts/MultiPool.solmain26.83 KB
- npm/@openzeppelin/[email protected]/access/AccessControlUpgradeable.sol8.28 KB
- npm/@openzeppelin/[email protected]/proxy/utils/Initializable.sol144 B
- npm/@openzeppelin/[email protected]/proxy/utils/UUPSUpgradeable.sol148 B
- npm/@openzeppelin/[email protected]/utils/ContextUpgradeable.sol1.22 KB
- npm/@openzeppelin/[email protected]/utils/PausableUpgradeable.sol3.68 KB
- npm/@openzeppelin/[email protected]/utils/introspection/ERC165Upgradeable.sol1.17 KB
- npm/@openzeppelin/[email protected]/access/IAccessControl.sol3.34 KB
- npm/@openzeppelin/[email protected]/interfaces/IERC1363.sol4.45 KB
- npm/@openzeppelin/[email protected]/interfaces/IERC165.sol193 B
- npm/@openzeppelin/[email protected]/interfaces/IERC1967.sol637 B
- npm/@openzeppelin/[email protected]/interfaces/IERC20.sol182 B
- npm/@openzeppelin/[email protected]/interfaces/IERC5267.sol740 B
- npm/@openzeppelin/[email protected]/interfaces/draft-IERC1822.sol882 B
- npm/@openzeppelin/[email protected]/proxy/ERC1967/ERC1967Utils.sol6.26 KB
- npm/@openzeppelin/[email protected]/proxy/beacon/IBeacon.sol473 B
- npm/@openzeppelin/[email protected]/proxy/utils/Initializable.sol9.28 KB
- npm/@openzeppelin/[email protected]/proxy/utils/UUPSUpgradeable.sol6.32 KB
- npm/@openzeppelin/[email protected]/token/ERC20/IERC20.sol2.78 KB
- npm/@openzeppelin/[email protected]/token/ERC20/utils/SafeERC20.sol13.31 KB
- npm/@openzeppelin/[email protected]/utils/Address.sol6.8 KB
- npm/@openzeppelin/[email protected]/utils/Arrays.sol35.17 KB
- npm/@openzeppelin/[email protected]/utils/Bytes.sol14.74 KB
- npm/@openzeppelin/[email protected]/utils/Comparators.sol443 B
- npm/@openzeppelin/[email protected]/utils/Errors.sol896 B
- npm/@openzeppelin/[email protected]/utils/LowLevelCall.sol5.55 KB
- npm/@openzeppelin/[email protected]/utils/Panic.sol1.97 KB
- npm/@openzeppelin/[email protected]/utils/ReentrancyGuardTransient.sol2.85 KB
- npm/@openzeppelin/[email protected]/utils/SlotDerivation.sol5.32 KB
- npm/@openzeppelin/[email protected]/utils/StorageSlot.sol4.18 KB
- npm/@openzeppelin/[email protected]/utils/Strings.sol21.54 KB
- npm/@openzeppelin/[email protected]/utils/TransientSlot.sol5.08 KB
- npm/@openzeppelin/[email protected]/utils/cryptography/ECDSA.sol12.15 KB
- npm/@openzeppelin/[email protected]/utils/cryptography/MessageHashUtils.sol8.63 KB
- npm/@openzeppelin/[email protected]/utils/introspection/IERC165.sol871 B
- npm/@openzeppelin/[email protected]/utils/math/Math.sol32.66 KB
- npm/@openzeppelin/[email protected]/utils/math/SafeCast.sol34.94 KB
- npm/@openzeppelin/[email protected]/utils/math/SignedMath.sol2.61 KB
- npm/@openzeppelin/[email protected]/utils/structs/BitMaps.sol2.02 KB
- npm/@openzeppelin/[email protected]/utils/structs/EnumerableSet.sol33.3 KB
- project/contracts/interfaces/IMultiPool.sol41.45 KB
- project/contracts/interfaces/IMultiPoolEvents.sol12.97 KB
- project/contracts/modules/CreditModule.sol12.87 KB
- project/contracts/modules/DepositModule.sol22.65 KB
- project/contracts/storage/MultiPoolStorage.sol5.58 KB
- project/contracts/utils/EIP712Upgradeable.sol6.07 KB
project/contracts/MultiPool.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.35;
import "./interfaces/IMultiPool.sol";
import "./storage/MultiPoolStorage.sol";
import "./modules/DepositModule.sol";
import "./modules/CreditModule.sol";
import "./utils/EIP712Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import { ReentrancyGuardTransient } from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
import { POOL_ACTION_TYPEHASH } from "./storage/MultiPoolStorage.sol";
/// @title CEDEX Earn Multi Pool
/// @notice Multi-token lending manager: a single upgradeable contract hosts many independent
/// deposit pools (one per `poolId`, each with its own token and parameters), while the
/// credit market is segregated per token — a borrower draws against, and repays into, the
/// combined liquidity of every pool that shares that token, rather than a single pool's
/// balance.
/// @dev Upgradeable via ERC-1967 UUPS (deploy behind `MultiPoolProxy`). All state lives at the
/// namespaced slot declared in `MultiPoolStorage` (`_getStorage()`), shared with the
/// `DepositModule`/`CreditModule` libraries — this contract implements the deposit-side
/// and credit-side state-mutating entry points.
contract MultiPool is Initializable, UUPSUpgradeable, AccessControlUpgradeable, PausableUpgradeable, ReentrancyGuardTransient, EIP712Upgradeable, MultiPoolStorage, IMultiPool {
using EnumerableSet for EnumerableSet.UintSet;
using BitMaps for BitMaps.BitMap;
/// @notice Restricts access to pool IDs.
modifier poolExists(uint32 poolId) {
require(poolId < _getStorage().poolCount, InvalidPoolId(poolId));
_;
}
/// @notice Restricts access to addresses in `token`'s borrower whitelist.
modifier onlyBorrower(IERC20 token) {
require(_getStorage().tokens[address(token)].borrowers[msg.sender], OnlyBorrower());
_;
}
/// @notice Blocks the call while `poolId` is paused, individually or globally.
modifier whenPoolNotPaused(uint32 poolId) {
require(!poolPaused(poolId), EnforcedPause());
_;
}
/// @notice Blocks the call while `token` is paused, individually or globally.
modifier whenTokenNotPaused(IERC20 token) {
require(!tokenPaused(token), EnforcedPause());
_;
}
/// @notice Requires a valid `signer()` signature over
/// `PoolAction(token, poolId, depositId, user, action, value, nonce, windowId)` for
/// `poolId`, unless the pool's `skipSignatureCheck` flag is set. Bumps `user`'s nonce for
/// `poolId` on success — except for the `withdrawOwnerProfit` sentinel pool
/// (`poolId == type(uint32).max`), where the nonce is bumped for `signer()` instead of
/// `user`, since `user` there is the withdrawal `receiver`, not a stable per-caller
/// identity. `depositId` is the deposit being acted on, unused (0) for
/// `Deposit`. `value` is the amount for `Deposit`/`WithdrawRequest`, and unused (0) for
/// `Withdraw`. `deadline` is an optional explicit expiry (0 to disable, falling back to
/// the implicit `windowId` scheme); see `_verifySignatureAndBumpNonce` for how a non-zero
/// value is enforced and signed.
modifier withValidSignature(address token, uint32 poolId, uint32 depositId, address user, DepositActionType action, uint256 value, bytes calldata signature, uint256 deadline) {
_verifySignatureAndBumpNonce(token, poolId, depositId, user, action, value, signature, deadline);
_;
}
/// @notice Disables direct initialisation of the implementation contract.
/// @dev Prevents someone from calling `initialize` on the logic contract itself, which could
/// corrupt the implementation's storage and brick all proxies pointing to it.
constructor() {
_disableInitializers();
}
/// @notice Initialises the contract, granting the initial admin both `DEFAULT_ADMIN_ROLE` and
/// `POOL_MANAGER_ROLE`, and optionally configuring the server `signer` right away.
/// @dev Called once through the proxy immediately after deployment. `DEFAULT_ADMIN_ROLE` can
/// grant/revoke `POOL_MANAGER_ROLE` to other addresses via `grantRole`/`revokeRole`.
/// Pass `initialSigner == address(0)` to leave it unset (same as never calling
/// `setSigner`) — useful when the signer isn't known yet, or every pool created will
/// have `skipSignatureCheck` set. Setting it here matters because `createPool` reverts
/// with `NeedToSetSigner` for a `skipSignatureCheck: false` pool while `signer()` is
/// still zero — configuring it during `initialize` lets such a pool be created in the
/// same deployment run, without a separate `setSigner` transaction first.
function initialize(address initialAdmin, address initialSigner) external initializer {
__AccessControl_init();
_grantRole(DEFAULT_ADMIN_ROLE, initialAdmin);
_grantRole(POOL_MANAGER_ROLE, initialAdmin);
__EIP712_init("MultiPool", "1");
if (initialSigner != address(0)) _setSigner(initialSigner);
_getStorage().initialized = true;
}
/// @dev Required by UUPSUpgradeable. Restricts upgrade authorization to `DEFAULT_ADMIN_ROLE`.
function _authorizeUpgrade(address) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}
/// @notice Verifies the `signer()` EIP-712 signature for a deposit-side action and bumps the
/// user's per-pool nonce so the same signature cannot be replayed — except for the
/// `withdrawOwnerProfit` sentinel pool (`poolId == type(uint32).max`), where the nonce
/// bumped is `signer()`'s own, since `user` there is the withdrawal receiver rather than a
/// stable per-caller identity. `token` binds the signature to the pool's ERC-20 at signing
/// time; callers pass `pool.token`.
/// @dev No-op when `pool.skipSignatureCheck` is set. Reverts with `InvalidSignature` if the
/// recovered address does not match the configured `signer`.
///
/// `deadline == 0` (the only value `deposit`/`withdrawRequest`/`withdraw` ever pass) uses
/// the implicit `windowId` scheme: the current `block.timestamp` bucketed into
/// `SIGNATURE_WINDOW`-wide slots. The server signs using its own current `windowId`;
/// since it isn't passed in, this function recomputes it from `block.timestamp` and
/// tries both the current slot and the previous one (covering a signature made just
/// before this slot began). This bounds a signature's effective lifetime to between
/// `SIGNATURE_WINDOW` and `2 * SIGNATURE_WINDOW` depending on when within its slot it
/// was signed, without the caller ever needing to supply or the contract needing to
/// store a deadline.
///
/// A non-zero `deadline` (only `withdrawOwnerProfit` exposes one) instead reverts with
/// `SignatureExpired` once `block.timestamp` passes it, and — unlike the `windowId`
/// case — is used as-is in place of `windowId` when computing `structHash`: `signer()`
/// must have signed this exact `deadline` value, or recovery fails with
/// `InvalidSignature`.
function _verifySignatureAndBumpNonce(address token, uint32 poolId, uint32 depositId, address user, DepositActionType action, uint256 value, bytes calldata signature, uint256 deadline) private {
Layout storage $ = _getStorage();
PoolData storage pool = $.pools[poolId];
if (pool.skipSignatureCheck) return;
uint256 nonce = poolId == type(uint32).max ? pool.nonces[$.signer]++ : pool.nonces[user]++;
if (deadline > 0 && deadline < block.timestamp) {
revert SignatureExpired();
} else if (deadline == 0){
deadline = block.timestamp / SIGNATURE_WINDOW;
}
bytes32 structHash = keccak256(abi.encode(POOL_ACTION_TYPEHASH, token, poolId, depositId, user, uint8(action), value, nonce, deadline));
if (_recoverSigner(structHash, signature) == $.signer) return;
require(deadline != 0, InvalidSignature());
bytes32 previousWindowStructHash = keccak256(abi.encode(POOL_ACTION_TYPEHASH, token, poolId, depositId, user, uint8(action), value, nonce, deadline - 1));
require(_recoverSigner(previousWindowStructHash, signature) == $.signer, InvalidSignature());
}
/// @inheritdoc IMultiPool
function pause() external onlyRole(POOL_MANAGER_ROLE) {
_pause();
}
/// @inheritdoc IMultiPool
function unpause() external onlyRole(POOL_MANAGER_ROLE) {
_unpause();
}
/// @inheritdoc IMultiPool
function signer() external view returns (address) {
return _getStorage().signer;
}
/// @inheritdoc IMultiPool
function setSigner(address newSigner) external onlyRole(DEFAULT_ADMIN_ROLE) {
_setSigner(newSigner);
}
/// @notice Shared by `setSigner` and `initialize` (which may configure the signer directly, see
/// its NatSpec) so both go through the same zero-check and event.
function _setSigner(address newSigner) private {
require(newSigner != address(0), ZeroAddress());
Layout storage $ = _getStorage();
emit SetNewSigner($.signer, newSigner);
$.signer = newSigner;
}
/// @inheritdoc IMultiPool
function createPool(PoolParams calldata params) external onlyRole(POOL_MANAGER_ROLE) returns (uint32 poolId) {
require(address(params.token) != address(0), ZeroAddress());
require(address(params.token).code.length > 0, TokenNotAContract());
require(params.depositApr <= MAX_APR, AprLimitExceeded());
require(params.withdrawalInterval <= params.lockPeriod, MaxWithdrawIntervalExceeded());
//need to setup reserve pools with apr = 0
// require(params.depositApr > 0, WrongApr());
Layout storage $ = _getStorage();
if($.signer == address(0)) require(params.skipSignatureCheck, NeedToSetSigner());
poolId = $.poolCount++;
PoolData storage pool = $.pools[poolId];
pool.token = params.token;
pool.depositApr = params.depositApr;
pool.lockPeriod = params.lockPeriod;
pool.minDepositAmount = params.minDepositAmount;
pool.depositCap = params.depositCap;
pool.withdrawDelay = params.withdrawDelay;
pool.skipSignatureCheck = params.skipSignatureCheck;
pool.lastUpdateTime = uint32(block.timestamp);
pool.withdrawalInterval = params.withdrawalInterval;
pool.status._data[0] = params.status;
emit PoolCreated(poolId, params.token, params.depositApr, params.lockPeriod, params.minDepositAmount, params.depositCap, params.withdrawDelay, params.skipSignatureCheck, params.withdrawalInterval, params.status);
}
/// @inheritdoc IMultiPool
function poolCount() external view returns (uint32) {
return _getStorage().poolCount;
}
/// @inheritdoc IMultiPool
function pausePool(uint32 poolId) external onlyRole(POOL_MANAGER_ROLE) poolExists(poolId) {
_getStorage().pools[poolId].paused = true;
emit PoolPaused(poolId);
}
/// @inheritdoc IMultiPool
function unpausePool(uint32 poolId) external onlyRole(POOL_MANAGER_ROLE) poolExists(poolId) {
_getStorage().pools[poolId].paused = false;
emit PoolUnpaused(poolId);
}
/// @inheritdoc IMultiPool
function poolPaused(uint32 poolId) public view returns (bool) {
return paused() || _getStorage().pools[poolId].paused;
}
/// @inheritdoc IMultiPool
function pauseToken(IERC20 token) external onlyRole(DEFAULT_ADMIN_ROLE) {
_getStorage().tokens[address(token)].paused = true;
emit TokenPaused(token);
}
/// @inheritdoc IMultiPool
function unpauseToken(IERC20 token) external onlyRole(DEFAULT_ADMIN_ROLE) {
_getStorage().tokens[address(token)].paused = false;
emit TokenUnpaused(token);
}
/// @inheritdoc IMultiPool
function tokenPaused(IERC20 token) public view returns (bool) {
return paused() || _getStorage().tokens[address(token)].paused;
}
/// @inheritdoc IMultiPool
function addBorrowerAddress(IERC20 token, address borrower) external onlyRole(DEFAULT_ADMIN_ROLE) {
bool currentBorrower = _getStorage().tokens[address(token)].borrowers[borrower];
require(borrower != address(0), ZeroAddress());
require(!currentBorrower, BorrowerAlreadySet());
_getStorage().tokens[address(token)].borrowers[borrower] = true;
emit NewBorrower(token, borrower);
}
/// @inheritdoc IMultiPool
function removeBorrowerAddress(IERC20 token, address borrower) external onlyRole(DEFAULT_ADMIN_ROLE) {
TokenData storage tokenData = _getStorage().tokens[address(token)];
require(borrower != address(0), ZeroAddress());
if (tokenData.borrowers[borrower]) {
tokenData.borrowers[borrower] = false;
} else revert BorrowerNotFound();
emit RemoveBorrower(token, borrower);
}
/// @inheritdoc IMultiPool
function setDepositApr(uint32 poolId, uint16 newApr) external poolExists(poolId) onlyRole(POOL_MANAGER_ROLE) {
require(newApr != 0, WrongApr());
require(newApr <= MAX_APR, AprLimitExceeded());
PoolData storage pool = _getStorage().pools[poolId];
uint16 oldApr = pool.depositApr;
require(oldApr != newApr, SameValue());
updateDepositAccInterestPerToken(poolId);
pool.depositApr = newApr;
emit SetNewDepositApr(poolId, newApr);
}
/// @inheritdoc IMultiPool
function setCreditApr(IERC20 token, uint16 newApr) external onlyRole(POOL_MANAGER_ROLE) {
require(newApr != 0, WrongApr());
require(newApr <= MAX_APR, AprLimitExceeded());
uint16 oldApr = _getStorage().tokens[address(token)].creditApr;
require(oldApr != newApr, SameValue());
updateCreditAccInterestPerToken(token);
_getStorage().tokens[address(token)].creditApr = newApr;
emit SetNewCreditApr(token, newApr);
}
/// @inheritdoc IMultiPool
function setMinDepositAmount(uint32 poolId, uint128 newAmount) external poolExists(poolId) onlyRole(POOL_MANAGER_ROLE) {
PoolData storage pool = _getStorage().pools[poolId];
uint128 oldAmount = pool.minDepositAmount;
require(oldAmount != newAmount, SameValue());
pool.minDepositAmount = newAmount;
emit SetNewMinDepositAmount(poolId, newAmount);
}
/// @inheritdoc IMultiPool
function setDepositCap(uint32 poolId, uint128 newCap) external poolExists(poolId) onlyRole(POOL_MANAGER_ROLE) {
PoolData storage pool = _getStorage().pools[poolId];
uint128 oldCap = pool.depositCap;
require(oldCap != newCap, SameValue());
pool.depositCap = newCap;
emit SetNewDepositCap(poolId, newCap);
}
/// @inheritdoc IMultiPool
function setWithdrawDelay(uint32 poolId, uint32 withdrawDelay) external poolExists(poolId) onlyRole(POOL_MANAGER_ROLE) {
PoolData storage pool = _getStorage().pools[poolId];
uint32 oldWithdrawDelay = pool.withdrawDelay;
require(oldWithdrawDelay != withdrawDelay, SameValue());
pool.withdrawDelay = withdrawDelay;
emit SetNewWithdrawDelay(poolId, withdrawDelay);
}
/// @inheritdoc IMultiPool
function setWithdrawalInterval(uint32 poolId, uint32 withdrawalInterval) external poolExists(poolId) onlyRole(POOL_MANAGER_ROLE) {
PoolData storage pool = _getStorage().pools[poolId];
require(withdrawalInterval <= pool.lockPeriod, MaxWithdrawIntervalExceeded());
uint32 oldWithdrawalInterval = pool.withdrawalInterval;
require(oldWithdrawalInterval != withdrawalInterval, SameValue());
pool.withdrawalInterval = withdrawalInterval;
emit SetNewWithdrawalInterval(poolId, withdrawalInterval);
}
/// @inheritdoc IMultiPool
function setPoolStatus(uint32 poolId, PoolStatusEnum[] calldata flags, bool[] calldata values) external poolExists(poolId) onlyRole(POOL_MANAGER_ROLE) {
require(flags.length == values.length, WrongLength());
BitMaps.BitMap storage status = _getStorage().pools[poolId].status;
uint256 oldRawFlags = status._data[0];
for (uint i; i < flags.length; i++) {
status.setTo(uint(flags[i]), values[i]);
}
uint256 newRawFlags = status._data[0];
emit SetPoolStatus(poolId, oldRawFlags, newRawFlags);
}
/// @inheritdoc IMultiPool
function setSkipSignatureCheck(uint32 poolId, bool skip) external onlyRole(POOL_MANAGER_ROLE) poolExists(poolId) {
if (!skip) require(_getStorage().signer != address(0), NeedToSetSigner());
_getStorage().pools[poolId].skipSignatureCheck = skip;
emit SetSkipSignatureCheck(poolId, skip);
}
/// @inheritdoc IMultiPool
function poolNonce(uint32 poolId, address user) external view returns (uint256) {
return _getStorage().pools[poolId].nonces[user];
}
function getVaultBalances(address[] calldata tokens) external view returns (uint256[] memory depositVaultBalances, uint256[] memory creditVaultBalances, uint256[] memory depositVaultApproves, uint256[] memory creditVaultApproves){
depositVaultBalances = new uint256[](tokens.length);
creditVaultBalances = new uint256[](tokens.length);
depositVaultApproves = new uint256[](tokens.length);
creditVaultApproves = new uint256[](tokens.length);
for(uint i = 0; i < tokens.length; i++){
IERC20 token = IERC20(tokens[i]);
depositVaultBalances[i] = token.balanceOf(DEPOSIT_VAULT);
creditVaultBalances[i] = token.balanceOf(CREDIT_VAULT);
depositVaultApproves[i] = token.allowance(DEPOSIT_VAULT, address(this));
creditVaultApproves[i] = token.allowance(CREDIT_VAULT, address(this));
}
}
/// @inheritdoc IMultiPool
function updateDepositAccInterestPerToken(uint32 poolId) public poolExists(poolId) returns (uint256 accInterestPerToken) {
return DepositModule.updateDepositAccInterestPerToken(poolId);
}
/// @inheritdoc IMultiPool
function updateCreditAccInterestPerToken(IERC20 token) public returns (uint256 accCreditInterestPerToken) {
return CreditModule.updateCreditAccInterestPerToken(token);
}
/// @inheritdoc IMultiPool
function deposit(uint32 poolId, uint128 amount, bytes calldata signature)
external
nonReentrant
poolExists(poolId)
whenPoolNotPaused(poolId)
withValidSignature(address(_getStorage().pools[poolId].token), poolId, 0, msg.sender, DepositActionType.Deposit, amount, signature, 0)
{
DepositModule.deposit(poolId, amount);
}
/// @inheritdoc IMultiPool
function withdrawRequest(uint32 poolId, uint104 amount, uint32 depositId, bytes calldata signature)
external
nonReentrant
poolExists(poolId)
whenPoolNotPaused(poolId)
withValidSignature(address(_getStorage().pools[poolId].token), poolId, depositId, msg.sender, DepositActionType.WithdrawRequest, amount, signature, 0)
{
DepositModule.withdrawRequest(poolId, amount, depositId);
}
/// @inheritdoc IMultiPool
function cancelWithdrawRequestsByOperator(cancelWithdrawRequestsStruct[] calldata requests)
external
onlyRole(POOL_MANAGER_ROLE) {
DepositModule.cancelWithdrawRequestsByOperator(requests);
}
/// @inheritdoc IMultiPool
function cancelWithdrawRequest(uint32 poolId, uint32 depositId) external nonReentrant poolExists(poolId) whenPoolNotPaused(poolId) {
DepositModule.cancelWithdrawRequest(poolId, depositId);
}
/// @inheritdoc IMultiPool
function secureWithdrawalFunds(UserWithdrawalRequests[] calldata requests, uint128 maxAmount)
external
whenNotPaused
onlyRole(POOL_MANAGER_ROLE)
{
DepositModule.secureWithdrawalFunds(requests, maxAmount);
}
/// @inheritdoc IMultiPool
function withdraw(uint32 poolId, address depositor, uint32 depositId, bytes calldata signature)
external
nonReentrant
poolExists(poolId)
whenPoolNotPaused(poolId)
withValidSignature(address(_getStorage().pools[poolId].token), poolId, depositId, depositor, DepositActionType.Withdraw, 0, signature, 0)
{
DepositModule.withdraw(poolId, depositor, depositId);
}
/// @inheritdoc IMultiPool
function userDeposits(uint32 poolId, address user) external view poolExists(poolId) returns (uint256[] memory depositIds) {
return _getStorage().pools[poolId].userDeposits[user].values();
}
/// @inheritdoc IMultiPool
function userDepositInfo(uint32 poolId, address user, uint32 depositId) external view poolExists(poolId) returns (DepositInfo memory depositInfo) {
return _getStorage().pools[poolId].userDepositInfo[user][depositId];
}
/// @inheritdoc IMultiPool
function userCreditLines(address token, address user) external view returns (uint256[] memory creditIds) {
return _getStorage().tokens[token].userCreditLines[user].values();
}
/// @inheritdoc IMultiPool
function creditLine(address token, address user, uint32 creditId) external view returns (CreditLine memory line) {
return _getStorage().tokens[token].creditLines[user][creditId];
}
/// @inheritdoc IMultiPool
function pendingAggregateDepositInterest(uint32 poolId, address user) public view poolExists(poolId) returns (uint256 pendingInterest) {
(, pendingInterest, ) = DepositModule.aggregateDeposits(_getStorage().pools[poolId], user);
}
/// @inheritdoc IMultiPool
function borrow(IERC20 token, uint128 amount, uint32 creditId, address receiver)
external
nonReentrant
onlyBorrower(token)
whenTokenNotPaused(token)
{
CreditModule.borrow(token, amount, creditId, receiver);
}
/// @inheritdoc IMultiPool
function repay(IERC20 token, uint128 amount, uint32 creditId)
external
nonReentrant
whenTokenNotPaused(token)
{
CreditModule.repay(token, amount, creditId);
}
/// @inheritdoc IMultiPool
function closeCreditLine(IERC20 token, uint32 creditId) external nonReentrant whenTokenNotPaused(token) {
CreditModule.closeCreditLine(token, creditId);
}
/// @inheritdoc IMultiPool
function pendingCreditInterest(IERC20 token, address user) public view returns (uint256 pendingInterest) {
(, pendingInterest, ) = CreditModule.aggregateCredits(_getStorage().tokens[address(token)], user);
}
/// @inheritdoc IMultiPool
function getUserInfo(uint32 poolId, address user) public view poolExists(poolId) returns (PoolUserInfo memory userInfo) {
return DepositModule.getUserInfo(_getStorage().pools[poolId], user);
}
/// @inheritdoc IMultiPool
function getPoolInfo(uint32 poolId, address user) public view poolExists(poolId) returns (PoolInfo memory poolInfo) {
return DepositModule.getPoolInfo(_getStorage().pools[poolId], poolId, user, poolPaused(poolId));
}
/// @inheritdoc IMultiPool
function totalDepositInterest(uint32 poolId) external view poolExists(poolId) returns (uint256 accruedInterest, uint256 paidInterest) {
return DepositModule.totalDepositInterest(_getStorage().pools[poolId]);
}
/// @inheritdoc IMultiPool
function getPoolsInfo(address user, uint32 start, uint32 limit) external view returns (PoolInfo[] memory poolInfo) {
uint32 _poolCount = _getStorage().poolCount;
require(start < _poolCount && limit > 0, WrongStartOrLimitValue());
if (limit > _poolCount - start) limit = _poolCount - start;
poolInfo = new PoolInfo[](limit);
for (uint32 i = start; i < start + limit; i++) {
poolInfo[i - start] = getPoolInfo(i, user);
}
}
/// @inheritdoc IMultiPool
function getPoolRawFlags(uint32 poolId) external view returns (uint256) {
return _getStorage().pools[poolId].status._data[0];
}
/// @inheritdoc IMultiPool
function totalCreditInterest(IERC20 token) public view returns (uint256 accruedInterest, uint256 paidInterest) {
return CreditModule.totalCreditInterest(_getStorage().tokens[address(token)]);
}
/// @inheritdoc IMultiPool
function getUserCreditInfo(IERC20 token, address user) public view returns (CreditUserInfo memory userInfo) {
return CreditModule.getUserCreditInfo(_getStorage().tokens[address(token)], user);
}
/// @inheritdoc IMultiPool
function getCreditInfo(IERC20 token, address user) external view returns (CreditInfo memory creditInfo) {
return CreditModule.getCreditInfo(_getStorage().tokens[address(token)], token, user, tokenPaused(token));
}
/// @inheritdoc IMultiPool
function withdrawOwnerProfit(address token, uint256 amount, address receiver, bytes calldata signature, uint256 deadline)
external
onlyRole(DEFAULT_ADMIN_ROLE)
withValidSignature(token, type(uint32).max, 0, receiver, DepositActionType.Withdraw, amount, signature, deadline)
{
require(receiver != address(0), ZeroAddress());
require(amount > 0, ZeroAmount());
Layout storage $ = _getStorage();
uint256 nonce = $.pools[type(uint32).max].nonces[$.signer] - 1;
SafeERC20.safeTransferFrom(IERC20(token), CREDIT_VAULT, receiver, amount);
emit WithdrawOwnerProfit(address(token), receiver, amount, nonce);
}
/// @inheritdoc IMultiPool
function getTokenPendingWithdrawalPrincipal(address token) external view returns(uint96 amount) {
uint32 count = _getStorage().poolCount;
for(uint32 i; i < count; i++){
PoolData storage pool = _getStorage().pools[i];
if(address(pool.token) == token) {
amount += pool.totalPendingWithdrawalPrincipal;
}
}
return amount;
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "none"
},
"libraries": {
"project/contracts/modules/CreditModule.sol": {
"CreditModule": "0x95bb5d5425179750333f8bedbb766c6316da6a29"
},
"project/contracts/modules/DepositModule.sol": {
"DepositModule": "0xbd799c35d1060c3a61561752b452e0314c73413a"
}
},
"optimizer": {
"runs": 200,
"enabled": true
},
"remappings": [
"npm/@openzeppelin/[email protected]/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/",
"project/:@openzeppelin/contracts-upgradeable/=npm/@openzeppelin/[email protected]/",
"project/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.