---
title: quoteExpandExactReserveIn
description: Quote a buy of AVM with exact USDC, pledged as collateral, plus a borrow.
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

One local quote for a loop: spend `reserveFromUser` USDC on a curve buy, pledge the minted AVM, then borrow `grossDebtIncrease` USDC against the new collateral.

Composes [quoteBuyExactReserveIn](/developers/math/quote-buy-exact-reserve-in) then [quoteBorrow](/developers/math/quote-borrow) on the post-buy position. `priceImpact` is the **buy** impact; the borrow still has no impact of its own.

## Import

```ts
import { quoteExpandExactReserveIn } from "@repo/contract-client/math";
```

## Usage

```ts
import { parseUsdc } from "@repo/contract-client";
import { quoteExpandExactReserveIn } from "@repo/contract-client/math";

const quote = quoteExpandExactReserveIn(snapshot, position, {
  reserveFromUser: parseUsdc("10"),
  grossDebtIncrease: parseUsdc("5"),
});

quote.collateralAdded;
quote.reserveFromUserRaw;
quote.grossDebtIncreaseRaw;
quote.tradeFees;
quote.borrowFees;
quote.position;
quote.priceImpact.totalPriceImpactWad;
```

## Return Value

`ExpandQuote` with `kind: 'expandExactReserveIn'`

| Field                  | Meaning                |
| ---------------------- | ---------------------- |
| `reserveFromUserRaw`   | USDC spent on the buy  |
| `grossDebtIncreaseRaw` | Debt added             |
| `collateralAdded`      | AVM minted and pledged |
| `tradeFees`            | 1.25% buy fee          |
| `borrowFees`           | 3% advance fee         |
| `position`             | After both legs        |
| `priceImpact`          | From the buy           |

## Parameters

### snapshot

- **Type:** `MarketSnapshot`

```ts
quoteExpandExactReserveIn(snapshot, position, {
  reserveFromUser: parseUsdc("10"),
  grossDebtIncrease: parseUsdc("5"),
});
```

### position

- **Type:** `PersonalPosition`

Existing pledge. May be empty.

### params.reserveFromUser

- **Type:** `UsdcRaw`

Gross USDC for the buy leg.

### params.grossDebtIncrease

- **Type:** `UsdcRaw`

Gross borrow after the mint is pledged. Capacity is evaluated on the **new** collateral.

## Error

Whatever the nested buy or borrow throws: `BelowMinimum`, `BorrowCapacityExceeded`, `InsufficientBacking`.

## Tips

- Size `grossDebtIncrease` from `borrowCapacity` of the post-buy position, not the current one.
- Exact-AVM variant: [quoteExpandExactAvmOut](/developers/math/quote-expand-exact-avm-out).
