DocumentationOpen App

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

OperationFunctionWhen to UseGuide
Add CollateraladdCollateralDeposit tokens to increase health factorAdding Collateral
Increase DebtincreaseDebtBorrow from poolDebt Management
Decrease DebtdecreaseDebtRepay borrowed fundsDebt Management
Update QuotaupdateQuotaEnable/adjust quota token exposureUpdating Quotas
Withdraw CollateralwithdrawCollateralRemove tokens from accountWithdrawing Collateral
Slippage ControlstoreExpectedBalances / compareBalancesProtect swaps from sandwich attacksControlling Slippage
External CallsAdapter-specificInteract with Uniswap, Curve, etc.Making External Calls
Enable/Disable TokenenableToken / disableTokenExplicit collateral managementEnabling/Disabling Tokens
Price UpdatesonDemandPriceUpdateUpdate Pyth/Redstone feedsUpdating Price Feeds
Check ParamssetFullCheckParamsOptimize gas, set min health factorCollateral Check Params
Revoke AllowancesrevokeAdapterAllowancesSecurity measure after suspicious activityRevoke Allowances

Page Structure

Each operation guide follows the same structure:

  1. Why - When you need this operation
  2. What - What it does and how it fits the system
  3. How - Working Solidity code
  4. Gotchas - Common mistakes and edge cases
  5. 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:

  1. Price updates (onDemandPriceUpdate) - Must be first in the calls array
  2. Collateral check params (setFullCheckParams) - Should be early, affects final check
  3. External calls - Can be anywhere after price updates
  4. Slippage checks - storeExpectedBalances before swaps, compareBalances after

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";