The Credit Manager is the core contract that manages credit accounts, handles collateral checks, debt management, and liquidations.
View Functions
pool
function pool() external view returns (address)
Returns the address of the pool connected to this credit manager.
The pool contract address
underlying
function underlying() external view returns (address)
Returns the address of the underlying token.
The underlying token address
creditFacade
function creditFacade() external view returns (address)
Returns the address of the credit facade.
The credit facade contract address
creditConfigurator
function creditConfigurator() external view returns (address)
Returns the address of the credit configurator.
The credit configurator contract address
accountFactory
function accountFactory() external view returns (address)
Returns the address of the account factory.
The account factory contract address
priceOracle
function priceOracle() external view returns (address)
Returns the address of the price oracle.
The price oracle contract address
poolQuotaKeeper
function poolQuotaKeeper() external view returns (address)
Returns the address of the pool quota keeper.
The pool quota keeper contract address
name
function name() external view returns (string memory)
Returns the name of the credit manager.
Account Management
openCreditAccount
function openCreditAccount(address onBehalfOf) external returns (address)
Opens a new credit account.
The address to open the credit account for
The address of the newly created credit account
closeCreditAccount
function closeCreditAccount(address creditAccount) external
Closes a credit account.
The credit account to close
liquidateCreditAccount
function liquidateCreditAccount(
address creditAccount,
CollateralDebtData calldata collateralDebtData,
address to,
bool isExpired
) external returns (uint256 remainingFunds, uint256 loss)
Liquidates a credit account.
The credit account to liquidate
collateralDebtData
CollateralDebtData
required
Collateral and debt data for the account
Address to send remaining funds to
Whether the account is being liquidated due to expiration
Amount of funds remaining after liquidation
Amount of loss incurred during liquidation
manageDebt
function manageDebt(
address creditAccount,
uint256 amount,
uint256 enabledTokensMask,
ManageDebtAction action
) external returns (uint256 newDebt, uint256, uint256)
Manages debt for a credit account (increase or decrease).
The credit account to manage debt for
The amount to increase or decrease debt by
Bitmask of enabled tokens
The action to perform (INCREASE_DEBT or DECREASE_DEBT)
The new debt amount after the operation
addCollateral
function addCollateral(
address payer,
address creditAccount,
address token,
uint256 amount
) external returns (uint256)
Adds collateral to a credit account.
The address paying for the collateral
The credit account to add collateral to
The token to add as collateral
Bitmask of tokens to enable
withdrawCollateral
function withdrawCollateral(
address creditAccount,
address token,
uint256 amount,
address to
) external returns (uint256)
Withdraws collateral from a credit account.
The credit account to withdraw from
Bitmask of tokens to disable
externalCall
function externalCall(
address creditAccount,
address target,
bytes calldata callData
) external returns (bytes memory result)
Executes an external call from a credit account.
The credit account making the call
The target contract address
The result of the external call
approveToken
function approveToken(
address creditAccount,
address token,
address spender,
uint256 amount
) external
Approves a token for spending from a credit account.
The address to approve for spending
Adapters
adapterToContract
function adapterToContract(address adapter) external view returns (address targetContract)
Returns the target contract for an adapter.
The target contract address
contractToAdapter
function contractToAdapter(address targetContract) external view returns (address adapter)
Returns the adapter for a target contract.
The target contract address
execute
function execute(bytes calldata data) external returns (bytes memory result)
Executes an adapter call.
The result of the execution
approveCreditAccount
function approveCreditAccount(address token, uint256 amount) external
Approves a token from the active credit account.
setActiveCreditAccount
function setActiveCreditAccount(address creditAccount) external
Sets the active credit account for the current adapter call.
The credit account to set as active
getActiveCreditAccountOrRevert
function getActiveCreditAccountOrRevert() external view returns (address creditAccount)
Returns the active credit account, reverts if none is set.
The active credit account address
Collateral Checks
fullCollateralCheck
function fullCollateralCheck(
address creditAccount,
uint256 enabledTokensMask,
uint256[] calldata collateralHints,
uint16 minHealthFactor,
bool useSafePrices
) external returns (uint256)
Performs a full collateral check on a credit account.
The credit account to check
Bitmask of enabled tokens
Optional array of token masks to check first
Minimum health factor in basis points
Whether to use safe prices from the oracle
Updated enabled tokens mask
isLiquidatable
function isLiquidatable(
address creditAccount,
uint16 minHealthFactor
) external view returns (bool)
Checks if a credit account is liquidatable.
The credit account to check
Minimum health factor in basis points
Whether the account is liquidatable
calcDebtAndCollateral
function calcDebtAndCollateral(
address creditAccount,
CollateralCalcTask task
) external view returns (CollateralDebtData memory cdd)
Calculates debt and collateral data for a credit account.
The credit account to calculate for
task
CollateralCalcTask
required
The calculation task to perform
The calculated collateral and debt data
Quotas
quotedTokensMask
function quotedTokensMask() external view returns (uint256)
Returns the bitmask of quoted tokens.
Bitmask of tokens with quotas enabled
updateQuota
function updateQuota(
address creditAccount,
address token,
int96 quotaChange,
uint96 minQuota,
uint96 maxQuota
) external returns (uint256 tokensToEnable, uint256 tokensToDisable)
Updates the quota for a token on a credit account.
The credit account to update quota for
The token to update quota for
The change in quota (can be negative)
Bitmask of tokens to enable
Bitmask of tokens to disable
Credit Manager Parameters
maxEnabledTokens
function maxEnabledTokens() external view returns (uint8)
Returns the maximum number of enabled tokens allowed per account.
Maximum number of enabled tokens
fees
function fees() external view returns (
uint16 feeInterest,
uint16 feeLiquidation,
uint16 liquidationDiscount,
uint16 feeLiquidationExpired,
uint16 liquidationDiscountExpired
)
Returns the fee parameters.
Interest fee in basis points
Liquidation fee in basis points
Liquidation discount in basis points
Expired liquidation fee in basis points
liquidationDiscountExpired
Expired liquidation discount in basis points
collateralTokensCount
function collateralTokensCount() external view returns (uint8)
Returns the number of collateral tokens.
Number of collateral tokens
getTokenMaskOrRevert
function getTokenMaskOrRevert(address token) external view returns (uint256 tokenMask)
Returns the token mask for a token, reverts if token is not recognized.
getTokenByMask
function getTokenByMask(uint256 tokenMask) external view returns (address token)
Returns the token address for a token mask.
liquidationThresholds
function liquidationThresholds(address token) external view returns (uint16 lt)
Returns the liquidation threshold for a token.
Liquidation threshold in basis points
ltParams
function ltParams(address token) external view returns (
uint16 ltInitial,
uint16 ltFinal,
uint40 timestampRampStart,
uint24 rampDuration
)
Returns liquidation threshold ramping parameters for a token.
Initial liquidation threshold
Final liquidation threshold
Timestamp when ramping starts
Duration of the ramp in seconds
collateralTokenByMask
function collateralTokenByMask(uint256 tokenMask) external view returns (
address token,
uint16 liquidationThreshold
)
Returns the collateral token and liquidation threshold for a token mask.
Liquidation threshold in basis points
Account Info
creditAccountInfo
function creditAccountInfo(address creditAccount) external view returns (
uint256 debt,
uint256 cumulativeIndexLastUpdate,
uint128 cumulativeQuotaInterest,
uint128 quotaFees,
uint256 enabledTokensMask,
uint16 flags,
uint64 lastDebtUpdate,
address borrower
)
Returns comprehensive information about a credit account.
The credit account address
cumulativeIndexLastUpdate
Cumulative index at last update
Cumulative quota interest
Bitmask of enabled tokens
Timestamp of last debt update
Address of the account borrower
getBorrowerOrRevert
function getBorrowerOrRevert(address creditAccount) external view returns (address borrower)
Returns the borrower address for a credit account, reverts if account doesn’t exist.
The credit account address
flagsOf
function flagsOf(address creditAccount) external view returns (uint16)
Returns the flags for a credit account.
The credit account address
setFlagFor
function setFlagFor(
address creditAccount,
uint16 flag,
bool value
) external
Sets a flag for a credit account.
The credit account address
Whether to enable or disable the flag
enabledTokensMaskOf
function enabledTokensMaskOf(address creditAccount) external view returns (uint256)
Returns the enabled tokens mask for a credit account.
The credit account address
Bitmask of enabled tokens
creditAccounts
function creditAccounts() external view returns (address[] memory)
Returns all credit accounts.
Array of all credit account addresses
function creditAccounts(
uint256 offset,
uint256 limit
) external view returns (address[] memory)
Returns a paginated list of credit accounts.
The maximum number of accounts to return
Array of credit account addresses
creditAccountsLen
function creditAccountsLen() external view returns (uint256)
Returns the total number of credit accounts.
Total number of credit accounts
Configuration
addToken
function addToken(address token) external
Adds a new collateral token.
setCollateralTokenData
function setCollateralTokenData(
address token,
uint16 ltInitial,
uint16 ltFinal,
uint40 timestampRampStart,
uint24 rampDuration
) external
Sets collateral token data including liquidation threshold ramping.
Initial liquidation threshold
Final liquidation threshold
Timestamp when ramping starts
Duration of the ramp in seconds
setFees
function setFees(
uint16 feeInterest,
uint16 feeLiquidation,
uint16 liquidationDiscount,
uint16 feeLiquidationExpired,
uint16 liquidationDiscountExpired
) external
Sets fee parameters.
Interest fee in basis points
Liquidation fee in basis points
Liquidation discount in basis points
Expired liquidation fee in basis points
liquidationDiscountExpired
Expired liquidation discount in basis points
setContractAllowance
function setContractAllowance(
address adapter,
address targetContract
) external
Sets contract allowance for an adapter.
The target contract address
setCreditFacade
function setCreditFacade(address creditFacade) external
Sets the credit facade address.
The new credit facade address
setPriceOracle
function setPriceOracle(address priceOracle) external
Sets the price oracle address.
The new price oracle address
setCreditConfigurator
function setCreditConfigurator(address creditConfigurator) external
Sets the credit configurator address.
The new credit configurator address