Skip to content
Docs

Cloud SDK

DeFi and swaps

Read DeFi positions, prepare DeFi actions, and request swap or bridge quotes with @gray3/cloud.

DeFi positions

ts
const positions = await gray.defi.positions({
  chainId: "ethereum",
  address: "0xYourAddress",
  protocolId: "aave-v3", // optional filter
});

const everywhere = await gray.defi.getMany({
  address: "0xYourAddress",
  chainIds: ["ethereum", "base", "arbitrum"],
});

Prepare a DeFi action

@gray3/cloud

gray.defi.prepareAction

prepareAction(request: DefiPrepareRequest): Promise<DefiActionPlan>
ts
const plan = await gray.defi.prepareAction({
  kind: "enter", // "enter" | "exit" | "claim"
  chainId: "ethereum",
  fromAddress: "0xYourAddress",
  investmentId: "…", // from a position or protocol listing
  inputs: [{ tokenAddress: "0xA0b8…eB48", amount: "100000000" }],
  slippage: "0.005",
});
// Sign and broadcast each step in plan.steps, in order.

Field details are in Prepare a DeFi action and Inputs, slippage, and redemption.

Swap and bridge quotes

ts
const quote = await gray.swap.quote({
  fromChainId: "ethereum",
  toChainId: "base",
  fromToken: "native", // defaults to "native"
  toToken: "native",
  fromAmount: "10000000000000000", // base units
  fromAddress: "0xYourAddress",
});
console.log(quote.toAmount, quote.estimatedGasUsd ?? "no gas estimate"); // estimatedGasUsd may be absent

// After the swap transaction is broadcast:
const status = await gray.swap.status({
  txHash: "0x…",
  fromChainId: "ethereum",
  toChainId: "base",
});
// status.status: "not_found" | "pending" | "done" | "failed" | "unknown"

DeFi and swaps are mainnet-only.