> ## Documentation Index
> Fetch the complete documentation index at: https://getequity.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Ethereum (Base) — Trading

> The Market and token functions you call to quote, buy, sell, and claim payouts on Base.

Everything you need to trade lives on two contracts: **`Market`** (quotes + `buy`/`sell`)
and the **RWA token** itself (ERC-20 balance/approve + payouts). The functions below are
the trader-facing subset — admin/governance functions are intentionally omitted.

## Market — quotes & trading

```solidity theme={null}
interface IMarket {
    struct AssetConfig {
        address token;          // ERC20 RWA token
        address vault;          // Vault holding payment tokens
        uint256 price;          // Price in cents per 1 token (PRICE_PRECISION = 100)
        uint256 feeBps;         // Fee in basis points (100 = 1%)
        bool    isActive;       // Whether trading is enabled
        uint256 lastUpdated;    // Timestamp of last price update
        uint8   tokenDecimals;  // Cached token decimals
    }

    // ---- Discover & read ----
    function getRegisteredTokens() external view returns (address[] memory);
    function isAssetTradeable(address token) external view returns (bool);   // registered && active
    function getAsset(address token) external view returns (AssetConfig memory);

    // ---- Quote (call before trading) ----
    function calculateBuyCost(address token, uint256 amount)
        external view returns (uint256 baseCost, uint256 fee, uint256 totalCost);
    function calculateSellPayout(address token, uint256 amount)
        external view returns (uint256 grossPayout, uint256 fee, uint256 netPayout);

    // ---- Trade ----
    function buy(address token, uint256 amount, uint256 maxCost) external;    // maxCost = slippage guard
    function sell(address token, uint256 amount, uint256 minPayout) external; // minPayout = slippage guard
}
```

## RWA token — balances, approvals & payouts

The token is a standard ERC-20 (18 decimals) plus a few reads for the asset terms and
interest payouts.

```solidity theme={null}
interface IRWAToken {
    // ---- ERC-20 ----
    function decimals() external view returns (uint8);            // 18
    function balanceOf(address account) external view returns (uint256);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transfer(address to, uint256 amount) external returns (bool);

    // ---- Asset info ----
    function payoutToken() external view returns (address);       // settlement currency
    function hasMaturity() external view returns (bool);
    function maturityDate() external view returns (uint256);      // 0 if none
    function paused() external view returns (bool);               // trading/transfers paused?

    // ---- Interest payouts (debt/fund tokens) ----
    function hasPeriodicPayouts() external view returns (bool);
    function calculatePayout(address user) external view returns (uint256 payout, uint256 periodsElapsed);
    function claimPayout() external returns (uint256);            // pull any accrued payout
}
```

<Note>
  `payoutToken()` also tells you which ERC-20 you'll spend when buying and receive when
  selling — it's the asset's settlement currency.
</Note>

## Buying

1. **Quote** the cost with `calculateBuyCost(token, amount)`.
2. **Approve** the payment token to the `Market` for at least `totalCost`.
3. **Buy** with a `maxCost` guard.

```js theme={null}
// ethers v6 — amount is in token base units (18 decimals)
const amount = 100n * 10n ** 18n; // 100 tokens

const [ , , totalCost] = await market.calculateBuyCost(token, amount);
const maxCost = totalCost + totalCost / 100n; // allow 1% slippage

const payToken = await rwaToken.payoutToken();
const pay = new ethers.Contract(payToken, erc20Abi, signer);
await (await pay.approve(marketAddress, maxCost)).wait();

await (await market.buy(token, amount, maxCost)).wait();
```

## Selling

1. **Quote** the proceeds with `calculateSellPayout(token, amount)`.
2. **Approve** the RWA token to the `Market` for `amount`.
3. **Sell** with a `minPayout` guard.

```js theme={null}
const amount = 100n * 10n ** 18n;

const [ , , netPayout] = await market.calculateSellPayout(token, amount);
const minPayout = netPayout - netPayout / 100n; // allow 1% slippage

await (await rwaToken.approve(marketAddress, amount)).wait();

await (await market.sell(token, amount, minPayout)).wait();
```

## Claiming interest payouts

For debt/fund tokens (`hasPeriodicPayouts() == true`), interest accrues on a schedule.
You don't need to do anything to receive it — a **Chainlink Automation** keeper triggers
the payout on schedule and pushes the interest to every holder in the asset's
`payoutToken()`. If you'd rather not wait for the next scheduled run, you can pull
whatever has already accrued yourself:

```js theme={null}
const [pending] = await rwaToken.calculatePayout(myAddress);
if (pending > 0n) await (await rwaToken.claimPayout()).wait();
```

Payouts arrive in the asset's `payoutToken()`.

## Redemption at maturity

When a token reaches end-of-life it is redeemed at a final price and your principal is
paid out to you automatically in the payment token — you don't need to call anything. If
`hasMaturity()` is true, `maturityDate()` tells you when.
