Multicalls
Build and execute multicalls in Solidity.
For SDK multicall helpers, see Multicalls.
Detailed Operation Guides
For comprehensive documentation of each operation:
Adding Collateral - Transfer tokens with approval patterns
Debt Management - Borrowing, repayment, and constraints
Updating Quotas - Quota mechanics and limits
Withdrawing Collateral - Safe pricing and health impact
Controlling Slippage - Balance delta protection
Making External Calls - Adapter interaction patterns
Enabling/Disabling Tokens - Token mask management
Updating Price Feeds - On-demand oracle data
Collateral Check Params - Health check optimization
Revoke Allowances - Security cleanup
The MultiCall Structure
ICreditFacadeV3Multicall Operations
All multicall operations are defined in ICreditFacadeV3Multicall:
Protocol Operations
addCollateral
(address token, uint256 amount)
addCollateralWithPermit
(address token, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
withdrawCollateral
(address token, uint256 amount, address to)
increaseDebt
(uint256 amount)
decreaseDebt
(uint256 amount)
updateQuota
(address token, int96 quotaChange, uint96 minQuota)
Safety Operations
onDemandPriceUpdate
(address token, bool reserve, bytes data)
storeExpectedBalances
(BalanceDelta[] deltas)
compareBalances
()
setFullCheckParams
(uint256[] hints, uint16 minHF)
setBotPermissions
(address bot, uint192 permissions)
Encoding Multicalls
Use abi.encodeCall for type-safe encoding:
Adapter Calls
External protocol calls go through adapters. Get the adapter address from Credit Manager:
Complete Multicall Example
8-call strategy: price update, collateral, borrow, slippage setup, swap, deposit, slippage check, quota:
The "Diff" Pattern
Adapters implement *_diff functions for handling unknown amounts:
Standard function: Requires exact
amountInDiff function: Calculates
amountIn = currentBalance - leftoverAmount
This is essential when the exact output of a previous operation is unknown.
Best Practices
Price updates first: Always put
onDemandPriceUpdatesat the start if using pull-based oraclesSlippage protection: Always use
storeExpectedBalancesbefore swaps andcompareBalancesafterApprove to Credit Manager: Token approvals go to Credit Manager, not Credit Facade
Gas optimization: Use
setFullCheckParamswith hints for accounts with many tokensDust management: Use
type(uint256).maxinwithdrawCollateralto empty balances
Next Steps
Multicall Operations - Individual operation guides
Use Cases - Adapter development and protocol integration
Pool Operations - Direct pool interaction
For architectural background, see Multicall System.
Last updated
