Making External Calls

Interact with DeFi protocols through adapters.

For SDK implementation, see Making External Calls.

Why

External calls enable Credit Accounts to:

  • Swap tokens - Trade via Uniswap, Curve, Balancer

  • Provide liquidity - Add to LP pools

  • Stake - Deposit into yield protocols (Yearn, Convex, Aura)

  • Leverage farm - Build complex DeFi strategies

All external interactions go through adapters - specialized contracts that translate Credit Account calls to protocol-specific formats.

What

Adapters wrap external protocol contracts. On execution:

  1. Credit Account calls adapter (not the protocol directly)

  2. Adapter translates the call and executes on the target protocol

  3. Adapter routes output tokens back to Credit Account

  4. Token states are updated automatically

Important: Never call external protocols directly from a Credit Account. Only use registered adapters.

How

Finding Adapters

Get the adapter address for a target protocol:

Basic Swap via Uniswap

Using the Diff Pattern

When you don't know the exact input amount (e.g., after a previous swap), use diff functions:

Multi-Protocol Strategy

Swap on Uniswap, then stake in Convex:

Balancer Multi-Hop Swap

Gotchas

Recipient is Always Credit Account

Adapters override the recipient parameter:

Approvals are Handled Automatically

Adapters manage token approvals internally. You don't need to approve tokens to the adapter or target protocol.

Only Allowed Adapters Work

The Credit Manager only accepts calls to registered adapters:

Check Adapter Type

Different adapter versions have different interfaces:

Diff Functions Require Balance

Diff functions calculate: amountIn = currentBalance - leftoverAmount

If the balance is less than leftoverAmount, the operation will fail:

External Calls Set Permission Flag

The first adapter call sets EXTERNAL_CONTRACT_WAS_CALLED_FLAG:

Token Enabling

Adapters automatically enable output tokens. After a swap:

  • Output token mask is set on the Credit Account

  • Token counts toward collateral (if it has quota or is underlying)

See Also

Last updated