Skip to main content
Use this recipe when your Base app wants to offer lending and borrowing without running its own money market. SODAX pools lending liquidity on the hub and lets a user act from any supported network: supply collateral from Base and borrow liquidity delivered to another network, or borrow into Base against collateral held elsewhere.

What you will build

A position flow that supplies collateral from Base, borrows against it with the borrowed asset delivered to another network, and reads the position back to render a health factor.
The money market list on Base is separate from the swap list: a token can appear in one and not the other. See Networks & Assets.

Prerequisites

  • @sodax/sdk and a wallet provider from @sodax/wallet-sdk-core or @sodax/wallet-sdk-react.
  • A Base wallet funded with ETH for gas, and a SODAX API key kept on your server. See API keys.
SODAX is mainnet only, so test with small amounts. See Is SODAX on Testnet?.

How it works

1

Supply collateral from Base

The action is keyed by srcChainKey: ChainKeys.BASE_MAINNET and the token comes from the Base money market list. An ERC-20 needs an allowance first, so approve only when it is short, and wait for the approval to confirm before you supply.
2

Borrow, delivered to another network

The cross-network part is one parameter. The user still acts from Base, but dstChainKey and dstAddress decide where the borrowed liquidity lands, and the token comes from the destination network’s list. To borrow into Base against collateral held elsewhere, swap the roles. Borrow and withdraw need no approval; repaying an ERC-20 does.
3

Read the position

sodax.moneyMarket.data returns USD-converted rates per reserve and the user’s totals and health factor.

Code

A small helper finds a token by symbol in a network’s list and throws if it isn’t there:
Supply, borrow and read the position:

Failures

Each method returns a typed Result; the error codes are in Lend / Borrow (Money Market). Read the position before you borrow, so the amount stays within what the collateral covers.

Next steps