> ## 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.

# Credit on Base (Morpho Blue)

> Borrow cNGN against gNTB, or lend cNGN, through Morpho Blue on Base.

On Base, credit runs on [Morpho Blue](https://docs.morpho.org): a single immutable
contract holding isolated markets. Each market is fixed forever by five parameters: loan
token, collateral token, oracle, interest-rate model and liquidation LTV (LLTV). You call
Morpho directly; GetEquity supplies the oracle.

<Warning>
  **Base Sepolia only.** No gNTB market exists on Base mainnet yet.
</Warning>

## The gNTB / cNGN market (Base Sepolia)

| Parameter | Value |
| - | - |
| Morpho Blue | `0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb` |
| Market id | `0x36826669f77801235f02f4d6319487a383dd89f91efd73f55e298228c26c76a3` |
| `loanToken` (cNGN) | `0x7E29CF1D8b1F4c847D0f821b79dDF6E67A5c11F8` |
| `collateralToken` (gNTB) | `0x3efAb39D8EE258d552b404B462832738F502C1f9` |
| `oracle` (MorphoChainlinkOracleV2) | `0x7554feCE759eDA89A2858035DC00b5016E885C47` |
| `irm` (AdaptiveCurveIRM) | `0x46415998764C29aB2a25CbeA6254146D50D22687` |
| `lltv` | `770000000000000000` (77%) |

Most Morpho calls take the parameters as a struct, not the id:

```solidity theme={null}
struct MarketParams {
    address loanToken;
    address collateralToken;
    address oracle;
    address irm;
    uint256 lltv;
}
```

Read them back from chain rather than hard-coding them:
`Morpho.idToMarketParams(0x3682…76a3)`.

## Borrowing

Approve Morpho for the token first (`approve(0xBBBB…EFFCb, amount)` on gNTB to post
collateral, on cNGN to repay). Amounts are in token base units: on Base Sepolia gNTB has
**18** decimals and cNGN **6**. Read `decimals()` on each token rather than assuming.

<Steps>
  <Step title="Post collateral">
    ```solidity theme={null}
    morpho.supplyCollateral(params, assets, onBehalf, "");
    ```

    `onBehalf` is the wallet that will own the position, normally your own.
  </Step>

  <Step title="Borrow cNGN">
    ```solidity theme={null}
    morpho.borrow(params, assets, 0, onBehalf, receiver);
    ```

    Pass the amount as `assets` and `0` shares. Reverts if the position would exceed the
    77% LLTV, or if the market has less idle cNGN than you ask for.
  </Step>

  <Step title="Repay">
    ```solidity theme={null}
    // a fixed amount
    morpho.repay(params, assets, 0, onBehalf, "");
    // everything, with no dust left by interest accrued since you read the debt
    morpho.repay(params, 0, position.borrowShares, onBehalf, "");
    ```

    For a full repay, approve a little more than the debt (for example +0.1%); Morpho
    pulls only what is owed.
  </Step>

  <Step title="Withdraw collateral">
    ```solidity theme={null}
    morpho.withdrawCollateral(params, assets, onBehalf, receiver);
    ```

    Reverts if what remains would leave the loan above the LLTV.
  </Step>
</Steps>

## Lending

```solidity theme={null}
morpho.supply(params, assets, 0, onBehalf, "");     // after approving cNGN
morpho.withdraw(params, assets, 0, onBehalf, receiver);
morpho.withdraw(params, 0, position.supplyShares, onBehalf, receiver); // everything
```

You can withdraw only cNGN that is not lent out: `totalSupplyAssets − totalBorrowAssets`.

## Reading a position

```solidity theme={null}
(uint256 supplyShares, uint128 borrowShares, uint128 collateral) = morpho.position(id, user);
(uint128 totalSupplyAssets, uint128 totalSupplyShares,
 uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee) = morpho.market(id);
uint256 price = IOracle(oracle).price(); // loan-token units per collateral unit, scaled by 1e36
```

* Debt (assets) = `borrowShares × totalBorrowAssets ÷ totalBorrowShares`, rounded up.
* Collateral value in cNGN = `collateral × price ÷ 1e36`.
* Health = `collateral value × 0.77 ÷ debt`.

`market()` totals are as of `lastUpdate`; to include interest since then, use Morpho's
`MorphoBalancesLib` (or accrue with the IRM's `borrowRateView`).

## The oracle

```
Market.currentPriceScaled(gNTB)   GetEquity's accrued price, live to the second
        │
RWAPriceOracle  0x31FCfAcd4f1A376606f2AF7297E1e573cf15d191
        │   Chainlink-style latestRoundData(), 18 decimals, priced in the payment token
MorphoChainlinkOracleV2  0x7554feCE759eDA89A2858035DC00b5016E885C47
        │   price() in Morpho's 1e36 scale
Morpho Blue
```

`RWAPriceOracle` **reverts with `NoPrice`** instead of returning 0, including when the
asset's payment token has changed. While it reverts, Morpho cannot price the collateral,
so borrows, withdrawals and liquidations revert too; repaying and supplying still work.

## Liquidation

When health ≤ 1.0, anyone may call:

```solidity theme={null}
morpho.liquidate(params, borrower, seizedAssets, repaidShares, "");
```

The liquidator repays debt and seizes collateral worth the repaid amount × the
liquidation incentive factor: about **1.074** at a 77% LLTV. Morpho allows liquidating
the whole position; GetEquity's own liquidator repays only enough to restore health.

## Events to index

From Morpho Blue: `SupplyCollateral`, `Borrow`, `Repay`, `WithdrawCollateral`, `Supply`,
`Withdraw`, `Liquidate`, each keyed by market `id`. See
[Morpho's contract reference](https://docs.morpho.org) for the full signatures.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.