Credit Facade
The CreditFacadeV3 is the primary user-facing interface for Credit Account operations. It implements atomic multicall batching, enforces debt limits, manages bot permissions, and ensures all operations complete with a healthy account state.
Core Data Structures
MultiCall
struct MultiCall { address target; // Facade itself or whitelisted adapter bytes callData; // Function selector + encoded arguments }
DebtLimits
struct DebtLimits { uint128 minDebt; // Minimum principal (except 0) uint128 maxDebt; // Maximum principal }
Bot Permissions
Bot permissions are stored as a uint192 bitmask:
| Permission | Value | Operation |
|---|---|---|
ADD_COLLATERAL_PERMISSION | 1 << 0 | Add funds to account |
INCREASE_DEBT_PERMISSION | 1 << 1 | Borrow more from pool |
DECREASE_DEBT_PERMISSION | 1 << 2 | Repay debt |
WITHDRAW_COLLATERAL_PERMISSION | 1 << 5 | Withdraw assets |
UPDATE_QUOTA_PERMISSION | 1 << 6 | Change token quotas |
EXTERNAL_CALLS_PERMISSION | 1 << 16 | Execute adapter calls |
Write Methods
openCreditAccount
Creates a new Credit Account with initial operations executed atomically.
function openCreditAccount( MultiCall[] calldata calls, address onBehalfOf ) external returns (address creditAccount);
| Parameter | Type | Description |
|---|---|---|
calls | MultiCall[] | Initial operations (add collateral, increase debt, etc.) |
onBehalfOf | address | Owner of the new Credit Account |
Returns: Address of the created Credit Account.
Access: Anyone. A full collateral check is performed after all calls execute.
closeCreditAccount
Closes a Credit Account, repaying all debt and returning remaining assets.
function closeCreditAccount( address creditAccount, MultiCall[] calldata calls ) external;
| Parameter | Type | Description |
|---|---|---|
creditAccount | address | Account to close |
calls | MultiCall[] | Operations to execute before closing (e.g., swap to underlying) |
Access: Account owner only (creditAccountOwnerOnly).
multicall
Executes a batch of operations on an existing Credit Account.
function multicall( address creditAccount, MultiCall[] calldata calls ) external;
| Parameter | Type | Description |
|---|---|---|
creditAccount | address | Target account |
calls | MultiCall[] | Operations to execute |
Access: Account owner only. Full collateral check after execution.
botMulticall
Executes a batch of operations initiated by an authorized bot.
function botMulticall( address creditAccount, MultiCall[] calldata calls ) external;
| Parameter | Type | Description |
|---|---|---|
creditAccount | address | Target account |
calls | MultiCall[] | Operations to execute |
Access: Authorized bot only. Each operation is checked against the bot's permission bitmask.
liquidateCreditAccount
Liquidates an unhealthy Credit Account (HF < 1.0).
function liquidateCreditAccount( address creditAccount, address to, MultiCall[] calldata calls ) external;
| Parameter | Type | Description |
|---|---|---|
creditAccount | address | Account to liquidate |
to | address | Recipient of remaining funds |
calls | MultiCall[] | Operations to execute during liquidation |
Access: Anyone (account must be liquidatable).
setBotPermissions
Grants or revokes bot permissions for a Credit Account.
function setBotPermissions( address creditAccount, address bot, uint192 permissions ) external;
| Parameter | Type | Description |
|---|---|---|
creditAccount | address | Target account |
bot | address | Bot address to authorize |
permissions | uint192 | Permission bitmask (0 to revoke) |
Access: Account owner only.
Multicall-Only Methods
These methods can only be called as part of a MultiCall array (encoded in callData with the Facade as target).
addCollateral
function addCollateral(address token, uint256 amount) external;
Transfers tokens from the caller to the Credit Account.
increaseDebt
function increaseDebt(uint256 amount) external;
Borrows additional funds from the pool. Subject to debt limits and per-block caps.
decreaseDebt
function decreaseDebt(uint256 amount) external;
Repays debt to the pool.
withdrawCollateral
function withdrawCollateral(address token, uint256 amount, address to) external;
Withdraws collateral from the Credit Account to the specified address.
updateQuota
function updateQuota(address token, int96 quotaChange, uint96 minQuota) external;
Adjusts the quota for a specific token on the Credit Account.
storeExpectedBalances / compareBalances
function storeExpectedBalances(BalanceWithMask[] calldata balances) external; function compareBalances() external;
Slippage protection pair: store expected balances before swaps, then verify after.
View Methods
debtLimits
Returns the min/max debt bounds for this Credit Facade.
function debtLimits() external view returns (uint128 minDebt, uint128 maxDebt);
maxDebtPerBlockMultiplier
Returns the per-block borrowing multiplier. Value of 0 means borrowing is disabled.
function maxDebtPerBlockMultiplier() external view returns (uint8);
creditManager
Returns the associated Credit Manager address.
function creditManager() external view returns (address);
canLiquidate
Checks whether a Credit Account is liquidatable.
function canLiquidate(address creditAccount) external view returns (bool);
botPermissions
Returns the permission bitmask for a bot on a specific Credit Account.
function botPermissions(address creditAccount, address bot) external view returns (uint192);
expirable / expirationDate
Returns whether this Facade has an expiration date and what it is.
function expirable() external view returns (bool); function expirationDate() external view returns (uint40);
Events
StartMultiCall
event StartMultiCall(address indexed creditAccount, address indexed caller);
Emitted at the start of a multicall execution.
FinishMultiCall
event FinishMultiCall();
Emitted when a multicall completes successfully.
OpenCreditAccount
event OpenCreditAccount( address indexed creditAccount, address indexed onBehalfOf, address indexed caller );
Emitted when a Credit Account is opened through the Facade.
CloseCreditAccount
event CloseCreditAccount(address indexed creditAccount, address indexed caller);
Emitted when a Credit Account is closed.
LiquidateCreditAccount
event LiquidateCreditAccount( address indexed creditAccount, address indexed liquidator, address indexed to, uint256 remainingFunds );
Emitted when a Credit Account is liquidated.
SetBotPermissions
event SetBotPermissions( address indexed creditAccount, address indexed bot, uint192 permissions );
Emitted when bot permissions are updated.
Related Pages
- Credit Manager -- Core accounting engine
- Credit Configurator -- Administrative configuration
- Pool (PoolV3) -- Liquidity pool
- Smart Contracts Overview -- Full contract architecture