Skip to main content
POST
/
accounts
/
{account_id}
/
plan
/
swap-and-supply
Plan Swap and Supply
curl --request POST \
  --url https://api.example.com/accounts/{account_id}/plan/swap-and-supply

Plan Swap and Supply

Creates a plan that atomically swaps one asset for another and immediately supplies the result into a DeFi yield protocol. This is useful for one-step “zap” operations where you have one asset but want to earn on another. Returns a plan ID and an EIP-712 digest that must be signed to authorize execution.

Request

POST /accounts/:account_id/plan/swap-and-supply

Path parameters

ParameterTypeDescription
account_idstringThe sub-account ID

Body parameters

ParameterTypeRequiredDescription
sell_assetstringYesAsset to sell (e.g., "WETH")
sell_amountstringYesAmount to sell in the asset’s smallest unit
buy_assetstringYesAsset to buy and supply (e.g., "USDC")
protocolstringYesProtocol to supply into: "compound", "aave", or "morpho_vault"
networkstringYesTarget network (e.g., "base", "mainnet"). Funds on other chains are bridged automatically.
marketstringNoMarket reference (required for morpho_vault)

Examples

curl -X POST https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/plan/swap-and-supply \
  -H "Authorization: Bearer $LEGEND_QUERY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sell_asset": "WETH",
    "sell_amount": "1000000000000000000",
    "buy_asset": "USDC",
    "protocol": "compound",
    "network": "base"
  }'
Response (201 Created)
{
  "plan_id": "pln_71mcui082png",
  "details": {
    "quark_operation_actions": [...],
    "eip712_data": {
      "digest": "0x8a3f...b7c2",
      "domain_separator": "0x...",
      "hash_struct": "0x..."
    }
  },
  "expires_at": "2025-06-15T10:32:00Z"
}

Response fields

FieldTypeDescription
plan_idstringUnique identifier for this plan (pln_ prefix)
detailsobjectTransaction details including EIP-712 signing data
details.eip712_data.digeststringThe hash to sign with the account’s signer key
expires_atstringISO 8601 timestamp — plan must be executed before this time

Errors

StatusCodeDescription
400invalid_paramsMissing required parameters, unsupported protocol, or missing market for morpho_vault
400plan_failedCould not generate a valid plan (e.g., insufficient balance)
400no_walletAccount has no wallets
408timeoutFolio computation timed out
422swap_quote_failedCould not fetch a swap quote from the DEX aggregator

Notes

  • Plans expire after 2 minutes. Sign and execute via Execute Plan before expiry.
  • The swap and supply happen atomically in a single transaction.
  • A 0.15% Legend fee is applied to the buy side of the swap quote.
  • The full swapped amount (after fee) is deposited into the protocol.
  • When using morpho_vault as the protocol, you must provide the market parameter.