Operations Reference
Detailed guides for encoding each multicall operation in Solidity.
For TypeScript/SDK implementation, see Multicalls.
Why This Section?
The main multicalls.md covers the fundamentals: MultiCall struct encoding, call order, and the diff pattern. This section goes deeper on each operation - when you need it, complete Solidity examples, and what can go wrong.
Quick Reference
| Operation | Function | When to Use | Guide |
|---|---|---|---|
| Add Collateral | addCollateral | Deposit tokens to increase health factor | Adding Collateral |
| Increase Debt | increaseDebt | Borrow from pool | Debt Management |
| Decrease Debt | decreaseDebt | Repay borrowed funds | Debt Management |
| Update Quota | updateQuota | Enable/adjust quota token exposure | Updating Quotas |
| Withdraw Collateral | withdrawCollateral | Remove tokens from account | Withdrawing Collateral |
| Slippage Control | storeExpectedBalances / compareBalances | Protect swaps from sandwich attacks | Controlling Slippage |
| External Calls | Adapter-specific | Interact with Uniswap, Curve, etc. | Making External Calls |
| Enable/Disable Token | enableToken / disableToken | Explicit collateral management | Enabling/Disabling Tokens |
| Price Updates | onDemandPriceUpdate | Update Pyth/Redstone feeds | Updating Price Feeds |
| Check Params | setFullCheckParams | Optimize gas, set min health factor | Collateral Check Params |
| Revoke Allowances | revokeAdapterAllowances | Security measure after suspicious activity | Revoke Allowances |
Page Structure
Each operation guide follows the same structure:
- Why - When you need this operation
- What - What it does and how it fits the system
- How - Working Solidity code
- Gotchas - Common mistakes and edge cases
- See Also - Related operations and SDK reference
Core Encoding Pattern
All multicall operations use the same encoding pattern:
Solidity
import {ICreditFacadeV3Multicall} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3Multicall.sol"; import {MultiCall} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol"; MultiCall[] memory calls = new MultiCall[](1); calls[0] = MultiCall({ target: creditFacade, // or adapter address for external calls callData: abi.encodeCall( ICreditFacadeV3Multicall.functionName, (param1, param2, ...) ) }); ICreditFacadeV3(creditFacade).multicall(creditAccount, calls);
Call Order Requirements
Some operations have strict ordering rules:
- Price updates (
onDemandPriceUpdate) - Must be first in the calls array - Collateral check params (
setFullCheckParams) - Should be early, affects final check - External calls - Can be anywhere after price updates
- Slippage checks -
storeExpectedBalancesbefore swaps,compareBalancesafter
Import Patterns
Standard imports for multicall operations:
Solidity
// Core interfaces import {ICreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol"; import {ICreditFacadeV3Multicall} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3Multicall.sol"; import {MultiCall} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol"; import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol"; // For slippage protection import {BalanceDelta} from "@gearbox-protocol/core-v3/contracts/libraries/BalancesLogic.sol"; // For allowance revocation import {RevocationPair} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3Multicall.sol"; // Adapter interfaces (examples) import {IUniswapV3Adapter} from "@gearbox-protocol/integrations-v3/contracts/interfaces/uniswap/IUniswapV3Adapter.sol"; import {IYearnV2Adapter} from "@gearbox-protocol/integrations-v3/contracts/interfaces/yearn/IYearnV2Adapter.sol";
Related
- Multicalls Overview - Fundamentals and the diff pattern
- Credit Manager - Underlying execution layer
- SDK Multicalls - TypeScript implementation