Overview
Integrate directly with Gearbox contracts from your Solidity code. This guide covers on-chain integration patterns for smart contract developers.
Prerequisites
- Solidity 0.8.x experience
- Familiarity with interface-based contract interaction
- Understanding of ERC-20 and common DeFi patterns
What You'll Learn
| Topic | Description |
|---|---|
| Credit Accounts | Contract discovery, CreditFacade, CreditManager interactions |
| Multicall Encoding | Build and execute multicalls in Solidity |
| Pool Operations | Deposit, withdraw, and read pool state |
Guide Structure
- Credit Accounts - Contract discovery, ICreditFacadeV3, ICreditManagerV3 interfaces
- Multicalls - MultiCall struct encoding, adapter calls
- Pool Operations - IPoolV3 deposit/withdraw, ERC-4626 functions
Note: Contract discovery patterns (AddressProvider, ContractsRegister) are covered in the Credit Accounts guide.
Key Interfaces
Solidity
// Core interfaces you'll use import {IAddressProviderV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IAddressProviderV3.sol"; import {ICreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol"; import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol"; import {IPoolV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolV3.sol";
When to Use Solidity Integration
| Use Case | Recommended |
|---|---|
| On-chain protocol integration | Yes |
| Building adapters | Yes |
| Composable strategies | Yes |
| Backend services | No (use SDK Guide) |
| Frontend applications | No (use SDK Guide) |
For TypeScript/JavaScript applications, see the SDK Guide.
Architecture Understanding
For conceptual background on how Gearbox works:
- Credit Suite Architecture - How Credit Managers, Facades, and Configurators work together
- Pool Architecture - Lending pools and ERC-4626 compliance
- Multicall System - How multicalls execute and validate
Detailed Guides
Multicall Operations
Complete reference for each multicall operation with Solidity examples:
| Operation | Description |
|---|---|
| Adding Collateral | Transfer tokens to credit account |
| Debt Management | Borrow and repay |
| Updating Quotas | Manage collateral quotas |
| Withdrawing Collateral | Remove tokens from account |
| Controlling Slippage | Protect against price movement |
| Making External Calls | Interact with DeFi protocols via adapters |
| Enabling/Disabling Tokens | Manage active collateral |
| Updating Price Feeds | On-demand oracle updates (Pyth, Redstone) |
| Collateral Check Params | Optimize health checks with hints |
| Revoke Allowances | Security cleanup |
See Multicalls Overview for the diff pattern and complete encoding examples.
Use Case Guides
Integration-specific guides for common development scenarios:
| Building | Guide | Focus |
|---|---|---|
| New DeFi Adapter | Adapter Development | AbstractAdapter, security patterns, diff functions |
| Strategy Contract | Protocol Integration | Multicall building, access control, automation |
| Core Extensions | Core Extension | Extending core contracts, advanced customizations |
| Liquidation Contract | Liquidation Bots | On-chain liquidation, flash loans, keeper integration |