# 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**](https://docs.quipuswap.com/smart-contracts/dex-2.0/bucket-contract/entrypoints-overview/fill) it to the appropriative [Bucket](https://docs.quipuswap.com/smart-contracts/dex-2.0/bucket-contract) contract.

When user need to return TEZ tokens, he need to transfer correct amount of TEZ tokens to the [DexCore](https://docs.quipuswap.com/smart-contracts/dex-2.0/dexcore-contract) 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="../..">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](https://docs.quipuswap.com/smart-contracts/dex-2.0/dexcore-contract) contract can call this entrypoint.

### Errors

* `108` - pair (pool) with the specified `token_id` not listed.
* `113` - a [Bucket](https://docs.quipuswap.com/smart-contracts/dex-2.0/bucket-contract) 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](https://docs.quipuswap.com/smart-contracts/dex-2.0/dexcore-contract) contract.
* `412` - non payable entrypoint (can't accept TEZ tokens during call of an entrypoint).
