Cli

From ethereum-optimism/actions · View interactive version

Cli is an AI agent skill from the GitHub repository ethereum-optimism/actions. Invoke the Actions SDK from the shell - query assets/chains, derive an EOA address from a PRIVATE_KEY env var, read balances. Use when an agent needs to interact with the Actions SDK without embedding TypeScript.

How to use this skill

Skill file

Actions CLI - Agent Skill

Invocation

Spawn the actions binary as a subprocess. Always pass --json (as

the first flag) - the default output is human-readable and not intended

for parsing. With --json, stdout is a bare JSON document on success

and stderr is the error envelope on failure.

actions --json assets
actions --json wallet balance --chain base-sepolia

Command tree

lending markets across configured providers, optionally filtered to one

asset and/or one chain (no wallet).

(no wallet).

[--chain <name> | --chain-id <id>]` - borrow markets across configured

providers, optionally filtered (no wallet).

by name (no wallet).

read any wallet's borrow position (no PRIVATE_KEY required).

configured providers (no wallet).

market by pool id (no wallet).

(--amount-in <n> | --amount-out <n>) --chain <name>

[--provider uniswap|velodrome] [--slippage <pct>]` - best quote

(no wallet).

quote sorted best price first.

address on Ethereum mainnet (no wallet).

primary ENS name, or name: null when none is set (no wallet).

records for a name or address (no wallet).

per chain + asset; the chain flags are mutually exclusive.

balance and shares in a market.

supply assets to a market. --approval-mode max approves max-uint to

amortise approvals across future supplies (default: exact).

withdraw assets. Pass --max to withdraw the wallet's full balance in

the market (the CLI fetches the position first; subject to inflight

interest accrual).

collateral, debt, LTV, and health factor in a borrow market.

[--collateral-amount <n>] [--approval-mode <exact|max>]` - borrow

against existing or newly-deposited collateral. No --max (open path

only accepts strict amounts).

--borrow-max] [--collateral-amount <n> | --collateral-max]` - unwind a

position. Each leg is independently xor'd; the borrow leg is required.

--*-max resolves on-chain at dispatch time so interest-accrual dust

doesn't strand the position.

[--approval-mode <exact|max>]` - top up collateral without changing

debt.

(--amount <n> | --max)` - pull collateral back without touching debt.

[--approval-mode <exact|max>]` - repay debt without touching collateral.

(--amount-in <n> | --amount-out <n>) --chain <name>

[--provider uniswap|velodrome] [--slippage <pct>]` - execute a swap

on the resolved chain.

Wallet model

The CLI derives a viem LocalAccount from PRIVATE_KEY and wraps it in

an EOA-backed Actions wallet via

actions.wallet.toActionsWallet(localAccount). No smart wallet, no

bundler, no ERC-4337 UserOps - the signer pays gas directly. For the

demo, fund the EOA with testnet ETH on Base Sepolia.

Resolution rules

(e.g. USDC_DEMO, OP_DEMO, ETH). Case-insensitive. Run

actions --json assets for the current list.

--chain, or a numeric id via --chain-id (mutually exclusive).

Both flags accept a comma-separated list to scope the SDK fan-out

to multiple chains. Run actions --json chains for the current

list.

(e.g. Gauntlet USDC, Aave ETH). Case-insensitive; whitespace

and hyphens are ignored, so gauntlet-usdc and gauntletusdc

resolve to the same entry. The market entry carries its own chain

and asset, so no --chain is needed.

is stripped (so Demo dUSDC / OP and demo-dusdc-op collapse to the

same key). Borrow market identifiers are discriminated unions (e.g.

{ kind: 'morpho-blue', marketId: '0x...', chainId: ... }); the CLI

forwards the resolved config to the SDK so a future second provider

variant adds no CLI work.

quotes and execution. --pool <id> is only used for direct

swap market lookups; the poolId surfaces in swap markets.

The SDK converts to wei using the asset's decimals.

the CLI converts to the SDK's decimal form internally.

--amount-out (exact-out) is required for swap quote,

swap quotes, and wallet swap execute.

provider and skips routing. Omit to let the SDK pick the best

available.

Presentation hints (for LLM/agent callers)

These are rules for rendering CLI output to humans, not rules for the

CLI itself.

(balances, markets, positions, pools), mention the chain only for

entries that share their name/symbol/market with another entry on a

different chain in the same response. If every row is uniquely

identifiable by its name alone, drop the chain label. Count chain

occurrences after skipping zero balances. Example: two chains

in the raw payload, but only one has a non-zero balance of X -

render as X <amount> with no chain. When the user explicitly scopes

a question to one chain, still omit the label.

or pools with no meaningful data, unless the user specifically asked

about that zero value ("do I have any X on op-sepolia").

addresses in a listing add noise. Show them only when the user asks

for them explicitly, and even then truncate (0xabc…def).

Output

With --json:

gh and AWS CLI conventions).

stderr, non-zero exit. retryable: true means the caller may retry

(typically network failures). retry_after_ms is present when a

specific back-off is recommended. details is redacted - bundler

URLs with API keys, signer metadata, and raw viem request bodies are

scrubbed.

Without --json (default):

across versions.

below.

Balance semantics

Within a single actions wallet balance call, the SDK fans out via

Promise.all over (asset x chain), so any single failing RPC rejects

the whole call with a network error. Retries may succeed on a

different call - do not assume per-chain isolation.

To shrink the failure surface, scope the call with --chain or

--chain-id (both accept a comma-separated list). The SDK only

queries the chains you pass.

Lend semantics

wallet lend open and wallet lend close emit a structured envelope

on stdout:

{
  "action": "open" | "close",
  "market": { "name": "...", "address": "0x...", "chainId": ..., "provider": "..." },
  "asset":  { "symbol": "..." },
  "amount": <number>,
  "transactions": [ { "transactionHash": "0x...", "status": "success", ... } ]
}

transactions is always an array. On EOA the SDK sends approval +

position as two sequential transactions when an approval is required,

so open returns 1-2 receipts and close returns 1. Bigint receipt

fields (blockNumber, gasUsed) are stringified.

A receipt with status: "reverted" is normalised to a code: "onchain"

error envelope on stderr (exit 5), so callers do not need to inspect

receipt status to detect failure.

wallet lend position returns the SDK LendMarketPosition shape

verbatim: { balance, balanceFormatted, shares, sharesFormatted, marketId }

with bigint fields stringified.

lend markets and lend market return the SDK LendMarket shape(s)

verbatim: { marketId, name, asset, supply, apy, metadata }. These do

not require PRIVATE_KEY.

NL -> command examples:

Borrow semantics

The wallet-scoped write verbs (open, close, deposit-collateral,

withdraw-collateral, repay) emit a structured envelope on stdout:

{
  "action": "open" | "close" | "depositCollateral" | "withdrawCollateral" | "repay",
  "market": {
    "name": "...",
    "marketId": { "kind": "morpho-blue", "marketId": "0x...", "chainId": ... },
    "chainId": ...,
    "provider": "morpho"
  },
  "borrowAmount":     <number | "max">,
  "collateralAmount": <number | "max">,
  "transactions": [ { "transactionHash": "0x...", "status": "success", ... } ],
  "ltv": <number | null>,
  "healthFactor": <number | null>,
  "liquidationPriceFormatted": "<string>"
}

borrowAmount / collateralAmount echo what the verb touched (the

inverse pair is omitted; e.g. repay reports only borrowAmount). The

literal string "max" means the SDK resolved the full balance at

dispatch time. ltv and healthFactor come from the SDK's

positionAfter snapshot and are null when the action left no debt

(divide-by-zero guard); they are omitted when the SDK did not surface a

positionAfter. transactions is always an array, normalised the same

way as lend / swap.

A receipt with status: "reverted" is normalised to a code: "onchain"

error envelope on stderr (exit 5).

actions borrow position --market <name> --wallet <address> reads any wallet's

position without needing PRIVATE_KEY. wallet borrow position uses the

connected wallet.

borrow markets / borrow market / both position commands return the

SDK shapes verbatim with bigints stringified. Position fields ltv and

healthFactor are null when there is no outstanding debt.

NL -> command examples:

actions --json wallet borrow open --market demo-dusdc-op --borrow-amount 1 --collateral-amount 2

actions --json wallet borrow close --market demo-dusdc-op --borrow-max --collateral-max

actions --json wallet borrow repay --market demo-dusdc-op --max

actions --json wallet borrow withdraw-collateral --market demo-dusdc-op --max

actions --json wallet borrow deposit-collateral --market demo-dusdc-op --amount 5

actions --json borrow position --market demo-dusdc-op --wallet 0x...

actions --json wallet borrow position --market demo-dusdc-op

Swap semantics

swap quote returns the SDK SwapQuote shape verbatim: amounts (both

display and Raw bigint), price + price-impact, slippage (decimal),

deadline, and pre-built execution calldata. swap quotes is the

multi-provider variant sorted by amountOutRaw desc.

wallet swap execute emits a structured envelope on stdout:

{
  "action": "execute",
  "assetIn":  { "symbol": "USDC_DEMO" },
  "assetOut": { "symbol": "OP_DEMO" },
  "amountIn": 5, "amountOut": 4.9,
  "amountInRaw":  "5000000",
  "amountOutRaw": "4900000000000000000",
  "price": 0.98, "priceImpact": 0.001,
  "transactions": [ { "transactionHash": "0x...", "status": "success", ... } ]
}

transactions is always an array. EOA execution can fan out into

token-approval + Permit2-approval + swap (up to 3 receipts); smart

wallets collapse to a single UserOp receipt. A receipt with

status: "reverted" is normalised to code: "onchain" exit 5.

wallet swap execute --recipient <addr|ens> accepts either a 0x address

or an ENS name. Pass ENS names through this field when the user wants the

swap output sent somewhere other than the connected wallet.

NL -> command examples:

ENS semantics

Read-only name resolution on Ethereum mainnet (chain ID 1). No

PRIVATE_KEY is required. Setting MAINNET_RPC_URL uses an

operator-configured mainnet RPC; when it is unset, the SDK's public RPC

fallback is used and the CLI prints a warning to stderr.

and emits { name, address }. A non-name input (raw address, bare

label) exits validation (2).

name is null when the address has no primary ENS record. A

non-address input exits validation (2).

shape verbatim: the standard ENSIP-5 / ENSIP-18 profile text records

(avatar, display, description, url, email, keywords,

twitter, github, discord, reddit), each string or null. An

all-null result is a normal success (the name exists but set no

records), not an error.

Setting MAINNET_RPC_URL adds mainnet to the CLI's shared chain set, so

it also becomes a valid --chain mainnet / --chain-id 1 target and is

included in the default wallet balance fan-out. The demo lend/borrow/swap

markets are testnet-only, so this affects reads (balances), not write targets.

NL -> command examples:

RPC trust

*_RPC_URL env vars must point to operator-trusted endpoints. A

malicious RPC can return fake balance data, which will confuse the

caller. The same trust concern applies to MAINNET_RPC_URL for ENS

reads: a fake RPC can return a wrong address for a name. If it is unset,

the SDK public mainnet fallback is used and the CLI warns on stderr.

Exit codes

| Code | Meaning | Retryable |

| ---- | -------------------------------------- | --------- |

| 0 | Success | - |

| 1 | Unknown error | false |

| 2 | Validation (bad input) | false |

| 3 | Config error (missing env, malformed) | false |

| 4 | Network error (RPC, timeout) | true |

| 5 | Onchain error (revert, UserOp failure) | false (†) |

(†) Specific onchain sub-classes (nonce conflicts, gas underpricing)

may set retryable: true via the retryableOverride mechanism. Treat

retryable as the source of truth; the table row shows the default.

Unknown commands

Typos (actions nonsense) exit 1 with commander's default plain-text

error on stderr - not the JSON error envelope. This distinction is

deliberate: the JSON envelope is only emitted for errors thrown from

within a registered handler.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.