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

# flashloan

> 通过从闪电贷提供方借入金额来提供 flow 输入，并在同一笔交易内偿还。

<Warning>
  **尚未公开。** 请联系我们以获取抢先体验。
</Warning>

`flashloan` 通过从闪电贷提供方**借入**金额来提供 flow 输入，而不是从签名者处拉取资金。借入的金额会作为 flow 的输入提供，因此 flow 的其余部分可以花费用户手中原本并不持有的资金。

由于闪电贷必须在同一笔交易内偿还，通过此 materialiser 借款的 flow **必须**在结束前结清贷款（本金 + 提供方费用）—— 通常使用一个或多个 [`lifi.flashloanRepay`](/composer/composer-api/ops) op。如果贷款未被偿还，模拟就会回滚。

Config：

| 字段             | 类型                                                         | 说明                                                         |
| -------------- | ---------------------------------------------------------- | ---------------------------------------------------------- |
| `providerKind` | `'aave-v3' \| 'erc3156' \| 'balancer-v2' \| 'morpho-blue'` | 从哪个闪电贷提供方借款。费用因提供方而异（例如 Aave V3 收取 5 bps；Balancer V2 不收费）。 |
| `amount`       | integer string                                             | 借入的金额，以代币的最小单位表示。                                          |

## 示例

通过 Aave V3 闪电贷借入 USDC，并在 flow 内结清：

```ts theme={"system"}
const builder = sdk.flow(8453, {
  name: 'flashloan-borrow',
  inputs: {
    borrowed: resources.erc20(USDC, 8453),
  },
});

// ... spend `builder.inputs.borrowed` across ops, then repay the loan
// (principal + fee) with `lifi.flashloanRepay` before the flow ends ...

const request = sdk.request(builder.build(), {
  signer: OWNER,
  inputs: {
    borrowed: materialisers.flashloan({
      providerKind: 'aave-v3',
      amount: '1000000000', // 1,000 USDC (6 decimals)
    }),
  },
});
```

若需要一个完整、经过测试、使用两笔并发闪电贷来迁移借款仓位的 flow，请参见 [debt-migration 配方](/composer/composer-api/recipes/debt-migration)以及 [`aaveToMorphoDebtMigration.ts`](https://github.com/lifinance/composer-sdk-examples/blob/main/examples/staged/aaveToMorphoDebtMigration.ts)。若需要最小化的借入并偿还的形式，请参见 [`flashloanRepay.ts`](https://github.com/lifinance/composer-sdk-examples/blob/main/examples/staged/flashloanRepay.ts)。
