# flash\_swap\_callback

An entrypoint that executes after execution of user's lambda but only in case when user is trying to loan TEZ tokens. It checks the returns of TEZ tokens and [**fills**](/smart-contracts/dex-2.0/bucket-contract/entrypoints-overview/fill.md) it to the appropriative [Bucket](/smart-contracts/dex-2.0/bucket-contract.md) contract.

When user need to return TEZ tokens, he need to transfer correct amount of TEZ tokens to the [DexCore](/smart-contracts/dex-2.0/dexcore-contract.md) contract at the end of his lambda execution.

### Call parameters

```pascaligo
type token_id_t         is nat

type flash_swap_1_t     is [@layout:comb] record [
  pair_id                 : token_id_t;
  prev_tez_balance        : nat;
  amount_in               : nat;
]
```

<table><thead><tr><th width="150">Field</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td>pair_id</td><td>token_id_t (nat)</td><td>Identifier of the liquidity pool (pair)</td></tr><tr><td>prev_tez_balance</td><td>nat</td><td>TEZ balance of <a href="/pages/PJIKLqS3IsyXS8Bwt7tK">DexCore</a> contract before execution of user's lambda</td></tr><tr><td>amount_in</td><td>nat</td><td>The number of incoming tokens (amount that user must repay)</td></tr></tbody></table>

### Usage

Only [DexCore](/smart-contracts/dex-2.0/dexcore-contract.md) contract can call this entrypoint.

### Errors

* `108` - pair (pool) with the specified `token_id` not listed.
* `113` - a [Bucket](/smart-contracts/dex-2.0/bucket-contract.md) contract not found (not TOK/TEZ LP pair).
* `129` - wrong amount of flash swap returns.
* `138` - only entered (transaction must be not the first transaction in the chain of calls).
* `403` - `sender` of the transaction is not [DexCore](/smart-contracts/dex-2.0/dexcore-contract.md) contract.
* `412` - non payable entrypoint (can't accept TEZ tokens during call of an entrypoint).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.quipuswap.com/smart-contracts/dex-2.0/dexcore-contract/entrypoints-overview/callbacks/flash_swap_callback.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
