# Operations Reference

Detailed guides for encoding each multicall operation in Solidity.

> For TypeScript/SDK implementation, see [Multicalls](https://docs.gearbox.finance/dev/sdk-guide-typescript/multicalls/multicalls).

## Why This Section?

The main [multicalls.md](https://docs.gearbox.finance/dev/solidity-guide/multicalls) 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](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/adding-collateral)                 |
| Increase Debt        | `increaseDebt`                              | Borrow from pool                           | [Debt Management](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/debt-management)                     |
| Decrease Debt        | `decreaseDebt`                              | Repay borrowed funds                       | [Debt Management](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/debt-management)                     |
| Update Quota         | `updateQuota`                               | Enable/adjust quota token exposure         | [Updating Quotas](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/updating-quotas)                     |
| Withdraw Collateral  | `withdrawCollateral`                        | Remove tokens from account                 | [Withdrawing Collateral](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/withdrawing-collateral)       |
| Slippage Control     | `storeExpectedBalances` / `compareBalances` | Protect swaps from sandwich attacks        | [Controlling Slippage](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/controlling-slippage)           |
| External Calls       | Adapter-specific                            | Interact with Uniswap, Curve, etc.         | [Making External Calls](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/making-external-calls)         |
| Enable/Disable Token | `enableToken` / `disableToken`              | Explicit collateral management             | [Enabling/Disabling Tokens](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/enabling-disabling-tokens) |
| Price Updates        | `onDemandPriceUpdate`                       | Update Pyth/Redstone feeds                 | [Updating Price Feeds](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/updating-price-feeds)           |
| Check Params         | `setFullCheckParams`                        | Optimize gas, set min health factor        | [Collateral Check Params](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/collateral-check-params)     |
| Revoke Allowances    | `revokeAdapterAllowances`                   | Security measure after suspicious activity | [Revoke Allowances](https://docs.gearbox.finance/dev/solidity-guide/multicalls/multicalls/revoke-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";
```

## Related

* [Multicalls Overview](https://docs.gearbox.finance/dev/solidity-guide/multicalls) - Fundamentals and the diff pattern
* [Credit Manager](https://docs.gearbox.finance/dev/core-contracts/credit-manager) - Underlying execution layer
* [SDK Multicalls](https://docs.gearbox.finance/dev/sdk-guide-typescript/multicalls/multicalls) - TypeScript implementation
