Borrow is not Earn’s Lending. Lending supplies an asset to earn yield through the Earn API. Borrow supplies collateral and borrows against it through the Borrow API. A Borrow
supply action and a lending yield are different positions, even on the same protocol.At a glance
Prerequisites
- Borrow enabled for your project. Borrow is enabled per project. Contact hello@yield.xyz with the API key you test with. Start with your dev environment.
- Markets enabled for your project. The default market list returns only the markets enabled for your project. Browse every market with
scope=all(see List markets) and send Yield.xyz the market ids you want. Enabling a market changes what the list returns. It does not block actions on other active markets, so restrict users to certain markets in your own UI. - A funded test wallet on Ethereum or Base, holding collateral (for example WETH or cbBTC) and native gas. Testing on Base costs less than on Ethereum.
- A signer for the target network: an EOA, smart account, MPC or custodial signer. See Transaction signing for EVM signing code.
We construct. You sign. Every action returns unsigned transactions. Yield.xyz never holds keys and never signs on your behalf. Inspect
signablePayload before you sign it, and never modify it.Basics
The examples use these shell variables:
Integrations and networks
Use theintegrationId everywhere a request needs an integration.
This table lists what the API supports. Your project settings decide which markets the default list returns. See Coverage for the protocols behind each integration.
The lifecycle
Seven calls cover every flow, in this order: discover integrations, list markets, read one market, read positions, build an action, sign and report each transaction, then poll the action.1. Discover integrations
id, providerId, name, networks[], metadata (description, externalLink, logoURI) and actions[]. Each action has an id, a label and a JSON schema of its arguments. Read actions[] for your key rather than hard-coding the list, since the actions available can depend on your project’s configuration.
Action ids, sent as action in requests: supply, borrow, repay, withdraw, enableCollateral, disableCollateral.
- Aave and SparkLend expose
supply,borrow,repay,withdraw,enableCollateralanddisableCollateral. - Morpho Blue and Lista expose
supply,borrow,repayandwithdraw.
2. List markets
integrationId, network, scope (enabled or all, default enabled), offset and limit.
scope=enabled returns only the markets enabled for your project. If none are enabled yet, the response is an empty list (total: 0), not an error. scope=all lists every market, so you can browse and pick the ids to enable. POST /v1/actions accepts any active market, whatever the list returns.
There is no server-side filter by token symbol. Filter on your side, as in Testing with USDC markets.
Market fields
Market fields
3. Read one market
cURL
404 for an unknown id and for a market that is no longer active. Always take ids from GET /v1/markets and never build them yourself: the format differs by integration, and Morpho Blue and Lista ids carry an on-chain market key.
4. Read positions for an address
address must be a 0x EVM address. One call covers one integration on one network.
pendingActions[] on each row is { type, label, args }. type is the value to send as action in POST /v1/actions, and args comes pre-filled. An Aave debt row, for example, offers a repay with repayAll: true. This is the shortest way to build Repay and Withdraw buttons.
Position fields
Position fields
The top level carries
address, integrationId, network, totalSuppliedUsd, totalCollateralUsd, totalBorrowedUsd, netWorthUsd, healthFactor, currentLtv, maxLtv, liquidationThreshold, availableToBorrowUsd, netApy, supplyBalances[] and debtBalances[].supplyBalances[]:marketId,tokenAddress,tokenSymbol,balance,balanceRaw,balanceUsd,apy,isCollateral,positionState(isolated markets only, see Risk fields) andpendingActions[].debtBalances[]:marketId,tokenAddress,tokenSymbol,balance,balanceRaw,balanceUsd,apyandpendingActions[].
5. Build an action
Every action is aPOST /v1/actions with the same envelope:
args fields: marketId (required), amount or amountRaw, tokenAddress, collateralTokenAddress, collateralAmount or collateralAmountRaw, repayAll, and borrowAmount with targetLtv. The network comes from the market, so you do not send it.
Preview with simulate
POST /v1/actions/simulate takes the same body, saves nothing, and returns:
gas:amount(the total native-token cost,nullunless every transaction has an estimate),token, andtransactions[]withamount,token,gasLimitandtypefor each transaction that has an estimate.outcome: the predicted risk fields described in Risk fields.
Action bodies
Pick the tab for the action you are building. Each tab lists the transactions the API returns, in order.- Supply + borrow
- Supply
- Borrow more
- Repay
- Withdraw
- Collateral toggle
Supply collateral and borrow in one action. Use On Aave,
action: "borrow" with a collateral leg. The API returns the collateral transactions first, then the borrow.On Aave (a pool market), pick the market whose loanToken is the token to borrow, and pick the collateral from that market’s collateralTokens[]. On Morpho Blue (an isolated market), the market fixes the collateral token, so you send amounts only:collateralTokenAddress is required whenever you send collateralAmount. The loan token comes from the market, so tokenAddress is optional on borrow and repay. If you send it, it must match loanToken.address.The transactions[] order, without fees:To size collateral from a target LTV instead,
supply accepts borrowAmount plus targetLtv (for example "0.5") in place of amount, and the API calculates the collateral. On Aave this mode also needs tokenAddress, the collateral token. On Aave, SparkLend and Morpho Blue the result comes back as metadata.effectiveCollateralAmount. You then send a separate borrow.What POST /v1/actions returns
Status 201, with id (the action id), integrationId, action, address, status, transactions[], hasNextStep, currentStep, totalSteps, rawArguments, metadata and createdAt.
Response (excerpt)
Fields in each transactions[] item
Fields in each transactions[] item
chainId) and EIP-1559 fees.
Borrow actions are single-step: hasNextStep is false and totalSteps is 1, so you never call POST /v1/actions/{id}/step. Calling it returns 400.
6. Sign, broadcast, report the hash
Go throughtransactions[] in array order. For each transaction:
1
Sign
Parse
signablePayload, set the nonce and fees, and sign.2
Broadcast
Broadcast the signed transaction.
3
Report the hash
cURL
4
Wait for confirmation
Poll the action (step 7) until this transaction is
CONFIRMED, then sign the next one.SUPPLY needs its APPROVAL mined first, or it reverts for insufficient allowance. If a gas estimate fails because of such a dependency when the API builds the action, the API uses a fixed gas limit instead. Do not treat gasLimit on later transactions as a live estimate.
To have Yield.xyz broadcast for you, send { "signedPayload": "0x..." } instead of transactionHash. Send one of the two, never both.
The response carries transactionHash, link (a block explorer URL) and status, which is BROADCASTED on success. A transaction can be submitted once, while it is still CREATED. A second submit returns 400 with its current status. When Yield.xyz fails to broadcast a signedPayload, the call returns 503 and the transaction is marked FAILED.
7. Poll status
cURL
Transaction statuses:
CREATED, BROADCASTED, CONFIRMED and FAILED. The full enums, including values the Borrow API does not return, are in Borrow objects.
After SUCCESS, call GET /v1/positions again to show the new balances.
Risk fields
A health factor above 1 is safe. Below 1, the position can be liquidated. Health factors are
null when there is no debt, and predictedHealthFactor is null when the action leaves no debt.
Pooled and isolated markets
- Pooled (Aave, SparkLend)
- Isolated (Morpho Blue, Lista)
Aave and SparkLend pool all collateral in the account. Read the top-level
healthFactor, currentLtv, maxLtv, liquidationThreshold and availableToBorrowUsd. maxLtv and liquidationThreshold are blended across all of the account’s collateral and include e-mode. supplyBalances[].positionState is not present.Predicted health factor
Every action response hasmetadata with currentHealthFactor, predictedHealthFactor, currentLtv, predictedLtv and liquidationThreshold. Show predictedHealthFactor on the confirm screen, and block an action client side when it would push the health factor below a level you accept.
Liquidation history (Morpho Blue only)
cURL
marketId (a market id or the on-chain bytes32 market key), offset and limit. Results are newest first. Each item has id, marketId, type (partial, full or null), realizedBadDebt, occurredAt, blockNumber, transactionHash, transactionLink, liquidator, repaidDebt, seizedCollateral, badDebt and lif. A fully liquidated position no longer appears in GET /v1/positions, so this endpoint is the only place to show it.
Fees
Fees are available on Morpho Blue markets only, and are off unless configured for your project. With no fee configuration, and on Aave, SparkLend and Lista, the fee fields on each market are"0" or null.
A project can have two kinds of fee: a deposit fee on supplied collateral (supplyCollateralFeeBps, up to 500 bps, enforced on-chain by the fee wrapper) and an origination fee on borrows (originationFeeBps). With an origination fee, amount stays what the user receives, and the recorded debt is that amount plus the fee (metadata.originationFeeAmount, metadata.effectivePrincipalAmount). With a 1% fee, for example, a 500 USDC borrow opens about 505 USDC of debt and the user receives 500 USDC. Origination fees also add the AUTHORIZE and DEAUTHORIZE transactions described in the Authorize (Morpho) tab of Action bodies.
To set up fees, contact hello@yield.xyz. See Borrow monetization for how the fee contracts work.
Testing with USDC markets
Find the market ids
List markets withscope=all and filter for USDC as the loan token:
cURL
total is above 100, page with offset=100, offset=200 and so on. To try the other chain, swap network=base and network=ethereum. Both integrations support both chains. For Morpho Blue, pick a market with enough availableLiquidity for your test borrow and a collateral your test wallet already holds.
Run the flow
- Call
POST /v1/actions/simulatewith a smallborrowpluscollateralAmount(the body from the Supply + borrow tab in Action bodies). Checkoutcome.predictedHealthFactorandgas. - Send the same body to
POST /v1/actions. Sign and submit each transaction as in step 6, and poll as in step 7. - Check
GET /v1/positions: the top-level fields on Aave,supplyBalances[].positionStateon Morpho Blue. - Close the position:
repaywithrepayAll: true, thenwithdrawthe full collateral. Check that the debt and supply rows are gone fromGET /v1/positions.
Reporting
- Per wallet
- Project-wide
On the Borrow API:
cURL
address is required. Optional filters: integrationId, network, action, status, statuses (comma-separated or repeated, up to 7; it overrides status), offset and limit. Results cover your project’s actions only, newest first, with the same item shape as GET /v1/actions/{id} minus metadata.Troubleshooting
Pick the area, then open the error string or symptom you see for its cause and fix.- Auth
- Markets
- Amounts
- Repay
- Submit
- Onchain
401 API key is missing or invalid
401 API key is missing or invalid
The header is missing, is not a UUID, or the key is unknown. Check
x-api-key. Expired and rotated keys return their own 401 message.429
429
Too many requests for your key. Back off and retry.
400 naming an unexpected property
400 naming an unexpected property
An unknown field in the body or query. The API rejects anything it does not define.
400 Must be a valid Ethereum address
400 Must be a valid Ethereum address
address or a token address is not 0x plus 40 hex characters.Next steps
Borrow widget
Add the Borrow tab to the Yield.xyz widget instead of building your own UI.
Core concepts
The market, position and action model behind every integration.
Borrow objects
Every enum, field and nullability rule in the Borrow API.
Transaction signing
EVM signing code for the transactions this guide returns.

