# Refinance / roll-over (move debt to a fixed term)

Endpoint reference for the 1delta API. Index: https://docs.1delta.io/llms.txt · every endpoint: https://docs.1delta.io/llms-full.txt

---

### GET /v1/actions/loop/refinance

- operationId: `refinance-roll-over-move-debt-to-a-fixed-term`
- docs: https://docs.1delta.io/1delta-api/refinance-roll-over-move-debt-to-a-fixed-term/
- markdown: https://docs.1delta.io/1delta-api/refinance-roll-over-move-debt-to-a-fixed-term.md
- tags: Loop (Actions)

Refinance / roll-over (move debt to a fixed term)

Move a user's fixed-term debt into a fresh term — "refinance" / "roll-over".

Serves **two** lenders, each with its own mechanism (the response shape is the same: a transaction plus its permissions):

- **Lista DAO brokered markets** — a flash-loan-backed 1delta composer bundle (repay the source loan, open the new fixed loan).
- **Exactly** — the protocol's OWN periphery (`DebtManager` on Optimism, `DebtRoller` on Base): ONE direct transaction that flash-loans from Balancer, repays the source position and re-borrows into the target. Because it acts on `msg.sender`'s own position it must be sent by the borrower, and it needs a Market **borrow allowance** (returned as a permission). Maps `fromLoanId` → source maturity and `termId` → target maturity, with `termId=0` meaning "roll into the variable/floating position" and an absent `fromLoanId` meaning "roll FROM the floating position". Base ships only the fixed→fixed direction. The response adds an `exactly` block (`direction`, `percentage`, `rolledAssets`, `projectedFaceValue`).

- **Refinance** (default, omit `fromLoanId`): roll the **dynamic/float** position into a fixed term — e.g. an expired fixed loan the keeper rolled into the dynamic bracket. Lista's own `refinanceMaturedFixedPositions` (matured fixed → dynamic) is keeper-only; this is the user-driven inverse.
- **Roll-over** (`fromLoanId` = a fixed loan's posId): roll one **fixed** loan into a different term (rate/duration). Rolling a not-yet-matured fixed loan repays it early, so `amount` must also cover its accrued interest + early-repayment penalty.

Same collateral, same principal, different rate bracket.

**Flash-loan backed** (robust at any LTV). The flash comes free from the market's own Moolah singleton, and the new fixed loan repays it. The returned transaction is a single composer bundle:
```
flashLoan(loanToken, amount) from Moolah:
  approve loanToken → Moolah            # so Moolah can pull the flash repayment
  broker.repay(amount, DYNAMIC, user)   # repay the float position with the flashed funds
  broker.borrow(amount, termId, user, receiver=composer)  # open the new fixed loan; repays the flash
→ sweep residual loanToken back to user
```
Because the dynamic is repaid **before** the fixed borrow, the borrow's health check sees the original (net) debt — no 2× peak — so it works regardless of LTV.

Net debt is unchanged. A `setAuthorization(composer)` permission (on Moolah) is returned **only when the composer isn't already authorized** — the broker's on-behalf borrow requires it, but `setAuthorization` reverts `AlreadySet()` if re-applied, so the server reads `isAuthorized(user, composer)` on-chain and omits the permission when it's already set. `actions.permissions` is empty in that case.

**Notes:**
- Single-market, debt-side only — pass the **loan-token** `marketUid` of a brokered market.
- **Full close (default — omit `amount`):** the server sizes the flash to the source loan's borrow balance + a small (0.05%) margin, clearing it to zero (the broker refunds the margin, swept back). The balance is the **max** of (a) the `borrowBalance` you POST in the body and (b) a fresh on-chain read — robust whether or not the worker's live RPC is current. Avoids the `REMAIN_BORROW_TOO_LOW` revert from a stale client snapshot `amount`. **Prefer POST** with `borrowBalance` (+ `earlyRepayPenalty` for a not-yet-matured fixed source) from `/v1/data/lending/user-positions`; a plain GET also works (on-chain read only). Never make the user hand-pick an over-funded amount.
- **Partial re-fix:** pass an explicit `amount` (leave `isAll` unset) < the source outstanding. Both the new fixed (`amount`) and the remaining source must clear `minLoan`.

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `marketUid` | query | string | yes | Loan-token market identifier of a Lista brokered market (`lender:chainId:address`). |
| `amount` | query | string | no | Flash / repay / new-fixed amount (loan-token wei). **Required only for a partial re-fix** (provide `amount`, leave `isAll` unset). For a full close, omit it — the server sizes the flash itself; if present alongside a full close it is used only as a floor hint. |
| `isAll` | query | boolean | no | Force a full close even when `amount` is present. A full close is also the DEFAULT whenever `amount` is omitted. The server sizes the flash to the source loan's borrow balance — the max of the POST-body `borrowBalance` (+ `earlyRepayPenalty`) and a fresh on-chain read (dynamic = `getUserTotalDebt` minus each fixed position's current debt; fixed = that position's current debt + early-repay penalty) — plus a small (0.05%) margin. The repay clears the source to zero and the broker refunds the margin (swept back), so there is no sub-`minLoan` dust and no `REMAIN_BORROW_TOO_LOW`. Set `amount` (and leave this unset) only for a deliberate partial re-fix. |
| `termId` | query | integer | yes | Fixed term to move the debt into, from the market's `terms[]` rate card (`MarketTerm.termId`). |
| `fromLoanId` | query | string | no | Source loan to roll FROM: a fixed loan's `loanId` (posId) to roll one fixed loan into another term, or omit (defaults to `type(uint128).max`) to refinance the dynamic/float position. |
| `operator` | query | string | yes | The borrower (and tx sender). Both the repaid source loan and the new fixed loan are this account. |

**Request body** (`application/json`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `borrowBalance` | string | no | Source loan's current borrow balance (loan-token wei). |
| `earlyRepayPenalty` | string | no | Source loan's early-repay penalty (loan-token wei) — fixed, not-yet-matured source only. |

**Example request body**

```json
{
  "borrowBalance": "100030000000000000",
  "earlyRepayPenalty": "0"
}
```

**Response `200`** — Flash-loan composer transaction (repay source loan + borrow new fixed term) and the borrow-authorization permission

| Field | Type | Description |
| --- | --- | --- |
| `success` | true |  |
| `data` | object | Response from proxy-mode lending operations (via 1delta composer). |
| `data.transaction` | object | An EVM transaction ready to sign and broadcast. Send `to`, `data` and `value` as-is; do not re-encode them. |
| `data.transaction.to` | string | Target contract address |
| `data.transaction.data` | string | Encoded calldata |
| `data.transaction.value` | string | ETH value to send with the transaction |
| `data.transaction.description` | string | Human-readable label. For `alternatives`, this is the aggregator name (e.g. "Paraswap"). For `transactions`, describes the setup action (e.g. "Switch e-mode to 1"). |
| `data.permissionTxns` | object[] | Approval transactions that must be executed before the main transaction. Empty when the user already has sufficient allowances. |
| `data.permissionTxns[].to` | string | Target contract address |
| `data.permissionTxns[].data` | string | Encoded calldata |
| `data.permissionTxns[].value` | string | ETH value |
| `data.permissionTxns[].description` | string | Human-readable description of the approval (e.g. "Approve borrow for AAVE_V3", "Approve ERC20") |
| `data.permissionTxns[].spender` | string | ERC-20 approve spender (x-chain permissions). Match it against the selected quote's `approvalTarget` — several bridges can share one spender, so do not match by description. |
| `data.rateImpact` | object[] | Projected interest-rate impact per market. Single-market actions produce 1 entry; loop actions produce 2. Null if IRM data is unavailable. |
| `data.rateImpact[].marketUid` | string | Market identifier (format: `lender:chainId:address`) |
| `data.rateImpact[].utilization` | object | A current/projected pair for a single rate metric. |
| `data.rateImpact[].utilization.current` | number | Current value |
| `data.rateImpact[].utilization.projected` | number | Projected value after the action |
| `data.rateImpact[].borrowRate` | object | A current/projected pair for a single rate metric. |
| `data.rateImpact[].borrowRate.current` | number | Current value |
| `data.rateImpact[].borrowRate.projected` | number | Projected value after the action |
| `data.rateImpact[].depositRate` | object | A current/projected pair for a single rate metric. |
| `data.rateImpact[].depositRate.current` | number | Current value |
| `data.rateImpact[].depositRate.projected` | number | Projected value after the action |
| `actions` | object | Transaction calldata and approvals. Null for quote-only responses (no account provided). |
| `actions.transactions` | object[] | Pre-trade setup transactions (e.g. e-mode switch, collateral enable). Execute these before the main swap. Empty when no setup is needed. |
| `actions.transactions[].to` | string | Target contract address |
| `actions.transactions[].data` | string | Encoded calldata |
| `actions.transactions[].value` | string | ETH value to send with the transaction |
| `actions.transactions[].description` | string | Human-readable label. For `alternatives`, this is the aggregator name (e.g. "Paraswap"). For `transactions`, describes the setup action (e.g. "Switch e-mode to 1"). |
| `actions.alternatives` | object[] | DEX aggregator swap transactions sorted by best output (descending). Each entry's `description` is the aggregator name. The client should pick one to execute. Present on loop action endpoints. |
| `actions.alternatives[].to` | string | Target contract address |
| `actions.alternatives[].data` | string | Encoded calldata |
| `actions.alternatives[].value` | string | ETH value to send with the transaction |
| `actions.alternatives[].description` | string | Human-readable label. For `alternatives`, this is the aggregator name (e.g. "Paraswap"). For `transactions`, describes the setup action (e.g. "Switch e-mode to 1"). |
| `actions.permissions` | object[] | Approval/delegation transactions that must execute before both `transactions` and `alternatives`. Includes ERC20 allowances (targeting the composer contract) and lender borrow/withdrawal delegations (targeting the lending protocol contract directly). Filtered against on-chain state so only missing approvals are returned. Null when no approvals are needed. |
| `actions.permissions[].to` | string | Target contract address |
| `actions.permissions[].data` | string | Encoded calldata |
| `actions.permissions[].value` | string | ETH value |
| `actions.permissions[].description` | string | Human-readable description of the approval (e.g. "Approve borrow for AAVE_V3", "Approve ERC20") |
| `actions.permissions[].spender` | string | ERC-20 approve spender (x-chain permissions). Match it against the selected quote's `approvalTarget` — several bridges can share one spender, so do not match by description. |

**Example response**

```json
{
  "success": true,
  "data": {
    "transaction": {
      "to": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
      "data": "0x617ba037000000000000000000000000c02aaa39b2",
      "value": "0",
      "description": "string"
    },
    "permissionTxns": [
      {
        "to": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "data": "0x617ba037000000000000000000000000c02aaa39b2",
        "value": "0",
        "description": "string",
        "spender": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
      }
    ],
    "rateImpact": [
      {
        "marketUid": "AAVE_V3:8453:0x4200000000000000000000000000000000000006",
        "utilization": {
          "current": 1,
          "projected": 1
        },
        "borrowRate": {
          "current": 1,
          "projected": 1
        },
        "depositRate": {
          "current": 1,
          "projected": 1
        }
      }
    ]
  },
  "actions": {
    "transactions": [
      {
        "to": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
        "data": "0x617ba037000000000000000000000000c02aaa39b2",
        "value": "0",
        "description": "string"
      }
    ],
    "alternatives": [
      {
        "to": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
        "data": "0x617ba037000000000000000000000000c02aaa39b2",
        "value": "0",
        "description": "string"
      }
    ],
    "permissions": [
      {
        "to": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "data": "0x617ba037000000000000000000000000c02aaa39b2",
        "value": "0",
        "description": "string",
        "spender": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
      }
    ]
  }
}
```

**Response `400`** — Validation error

**Response `429`** — Rate limited. Unauthenticated callers share a per-IP budget; send an `x-api-key` header to lift it. Retry with exponential backoff.

**Response `500`** — Unexpected server error. Safe to retry with backoff.

**Response `502`** — An upstream data source or protocol origin failed (`error.code` is `ORIGIN_FAILED`). `error.details` carries the per-origin status. This is also what a missing or malformed required parameter currently returns, rather than a 400.
