---
agentTools:
  projectIndex: https://docs.dedust.io/llms.txt
---

# TL-B schemes

# Factory

## Message "create\_vault"

```erlang TL-B
create_vault#21cfe02b query_id:uint64 asset:Asset = InMsgBody;
```

| Name      | Type                                                        | Required | Description                                  |
| :-------- | :---------------------------------------------------------- | :------- | :------------------------------------------- |
| query\_id | uint64                                                      | no       | <<glossary:Query ID>>                        |
| asset     | [Asset](https://docs.dedust.io/reference/tlb-schemes#asset) | **yes**  | The asset for which a Vault will be created. |

## Message "create\_volatile\_pool"

```erlang TL-B
create_volatile_pool#97d51f2f query_id:uint64 asset0:Asset asset1:Asset = InMsgBody;
```

| Name      | Type                                                        | Required | Description                                 |
| :-------- | :---------------------------------------------------------- | :------- | :------------------------------------------ |
| query\_id | uint64                                                      | no       | <<glossary:Query ID>>                       |
| asset0    | [Asset](https://docs.dedust.io/reference/tlb-schemes#asset) | **yes**  | The asset for which a Pool will be created. |
| asset1    | [Asset](https://docs.dedust.io/reference/tlb-schemes#asset) | **yes**  | The asset for which a Poo will be created.  |

> 📘 Assets can be reordered.
>
> Assets can be switched (`asset0` becomes `asset1` and vice versa).
>
> This ensures a consistent address for a **Pool** regardless of asset order (e.g. A / B or B / A).

# Common Types

## Asset

```erlang TL-B
native$0000 = Asset;
jetton$0001 workchain_id:int8 address:uint256 = Asset;
extra_currency$0010 currency_id:int32 = Asset;
```

## Timestamp

```erlang TL-B
timestamp#_ _:uint32 = Timestamp;
```

## SwapKind

```erlang TL-B
given_in$0 = SwapKind;
given_out$1 = SwapKind; // Not implemented.
```

## SwapParams

Set of parameters relevant for the entire swap.

```erlang TL-B
swap_params#_ deadline:Timestamp recipient_addr:MsgAddressInt referral_addr:MsgAddress
              fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = SwapParams;
```

| Name              | Type                                                                | Required | Description                                                                                                                      |
| :---------------- | :------------------------------------------------------------------ | :------- | :------------------------------------------------------------------------------------------------------------------------------- |
| `deadline`        | [Timestamp](https://docs.dedust.io/reference/tlb-schemes#timestamp) | no       | Specifies a deadline for the swap. If the swap reaches the Pool after this time, it will be rejected. **Default**: 0 (disabled). |
| `recipient_addr`  | MsgAddress                                                          | no       | Specifies an address where funds will be sent after the swap. **Default:** sender's address.                                     |
| `referral_addr`   | MsgAddress                                                          | no       | Referral address. Required for the Referral Program.                                                                             |
| `fulfill_payload` | Maybe ^Cell                                                         | no       | Custom payload that will be attached to the fund transfer upon a **successful** swap.                                            |
| `reject_payload`  | Maybe ^Cell                                                         | no       | Custom payload that will be attached to the fund transfer upon a **rejected** swap.                                              |

## SwapStep

Set of parameters relevant for the specific step.

```erlang TL-B
step#_ pool_addr:MsgAddressInt params:SwapStepParams = SwapStep;
```

| Name       | Type                                                                          | Required | Description                                               |
| :--------- | :---------------------------------------------------------------------------- | :------- | :-------------------------------------------------------- |
| pool\_addr | MsgAddressInt                                                                 | **yes**  | The pool is responsible for swapping assets at this step. |
| params     | [SwapStepParams](https://docs.dedust.io/reference/tlb-schemes#swapstepparams) | **yes**  | Set of extra parameters relevant for a specific step.     |

## SwapStepParams

Set of extra parameters relevant for a specific step.

```erlang TL-B
step_params#_ kind:SwapKind limit:Coins next:(Maybe ^SwapStep) = SwapStepParams;
```

| Name  | Type                                                                     | Required | Description                                                                                        |
| :---- | :----------------------------------------------------------------------- | :------- | :------------------------------------------------------------------------------------------------- |
| kind  | [SwapKind](https://docs.dedust.io/reference/tlb-schemes#swapkind)        | no       | **Note**: Only `given_in` option is implemented.                                                   |
| limit | Coins                                                                    | no       | Minimum output of the swap. If the actual value is less than specified, the swap will be rejected. |
| next  | Maybe ^[SwapStep](https://docs.dedust.io/reference/tlb-schemes#swapstep) | no       | Reference to the next step. Can be used for multi-hop swaps.                                       |

## PoolType

```erlang TL-B
volatile$0 = PoolType;
stable$1 = PoolType;
```

## PoolParams

```erlang TL-B
pool_params#_ pool_type:PoolType asset0:Asset asset1:Asset = PoolParams;
```

| Name       | Type                                                              | Required | Description |
| :--------- | :---------------------------------------------------------------- | :------- | :---------- |
| pool\_type | [PoolType](https://docs.dedust.io/reference/tlb-schemes#pooltype) | **yes**  |             |
| asset0     | [Asset](https://docs.dedust.io/reference/tlb-schemes#asset)       | **yes**  |             |
| asset1     | [Asset](https://docs.dedust.io/reference/tlb-schemes#asset)       | **yes**  |             |

# Native Vault

## Message "swap"

```erlang TL-B
swap#ea06185d query_id:uint64 amount:Coins _:SwapStep swap_params:^SwapParams = InMsgBody;
```

| Name         | Type                                                                   | Required | Description                                    |
| :----------- | :--------------------------------------------------------------------- | :------- | :--------------------------------------------- |
| query\_id    | uint64                                                                 | no       | <<glossary:Query ID>>                          |
| amount       | Coins                                                                  | **yes**  | TON amount for the swap                        |
| swap\_params | ^[SwapParams](https://docs.dedust.io/reference/tlb-schemes#swapparams) | **yes**  | Set of parameters relevant for the entire swap |

## Message "deposit\_liquidity"

```erlang TL-B
deposit_liquidity#d55e4686 query_id:uint64 amount:Coins pool_params:PoolParams
                           min_lp_amount:Coins
                           asset0_target_balance:Coins asset1_target_balance:Coins
                           fulfill_payload:(Maybe ^Cell)
                           reject_payload:(Maybe ^Cell) = InMsgBody;
```

| Name                    | Type                                                                  | Required | Description           |
| :---------------------- | :-------------------------------------------------------------------- | :------- | :-------------------- |
| query\_id               | uint64                                                                | no       | <<glossary:Query ID>> |
| amount                  | Coins                                                                 | **yes**  |                       |
| pool\_params            | [PoolParams](https://docs.dedust.io/reference/tlb-schemes#poolparams) | **yes**  |                       |
| min\_lp\_amount         | Coins                                                                 | no       |                       |
| asset0\_target\_balance | Coins                                                                 | **yes**  |                       |
| asset1\_target\_balance | Coins                                                                 | **yes**  |                       |
| fulfill\_payload        | Maybe ^Cell                                                           | no       |                       |
| reject\_payload         | Maybe ^Cell                                                           | no       |                       |

## Message "payout"

```erlang TL-B
payout#474f86cf query_id:uint64 payload:(Maybe ^Cell) = InMsgBody;
```

| Name      | Type        | Required | Description           |
| :-------- | :---------- | :------- | :-------------------- |
| query\_id | uint64      | no       | <<glossary:Query ID>> |
| payload   | Maybe ^Cell | no       |                       |

# Jetton Vault

## Message "swap"

```erlang TL-B
swap#e3a0d482 _:SwapStep swap_params:^SwapParams = ForwardPayload;
```

| Name         | Type                                                                   | Required | Description |
| :----------- | :--------------------------------------------------------------------- | :------- | :---------- |
| swap\_params | ^[SwapParams](https://docs.dedust.io/reference/tlb-schemes#swapparams) | **yes**  |             |

## Message "deposit\_liquidity"

```erlang TL-B
deposit_liquidity#40e108d6 pool_params:PoolParams min_lp_amount:Coins
                           asset0_target_balance:Coins asset1_target_balance:Coins
                           fulfill_payload:(Maybe ^Cell)
                           reject_payload:(Maybe ^Cell) = ForwardPayload;
```

| Name                    | Type                                                                  | Required | Description |
| :---------------------- | :-------------------------------------------------------------------- | :------- | :---------- |
| pool\_params            | [PoolParams](https://docs.dedust.io/reference/tlb-schemes#poolparams) | **yes**  |             |
| min\_lp\_amount         | Coins                                                                 | no       |             |
| asset0\_target\_balance | Coins                                                                 | **yes**  |             |
| asset1\_target\_balance | Coins                                                                 | **yes**  |             |
| fulfill\_payload        | Maybe ^Cell                                                           | no       |             |
| reject\_payload         | Maybe ^Cell                                                           | no       |             |

# Pool Events

To simplify the process of indexing, DeDust Procotol uses mechanism of events.\
For that purpose we use "external messages" proposed by TON Blockchain.

## Event "swap"

```erlang TL-B
swap#9c610de3 asset_in:Asset asset_out:Asset amount_in:Coins amount_out:Coins
              ^[ sender_addr:MsgAddressInt referral_addr:MsgAddress
              reserve0:Coins reserve1:Coins ] = ExtOutMsgBody;
```

| Name           | Type                                                        | Required | Description                                             |
| :------------- | :---------------------------------------------------------- | :------- | :------------------------------------------------------ |
| asset\_in      | [Asset](https://docs.dedust.io/reference/tlb-schemes#asset) | **yes**  | The asset provided by the user.                         |
| asset\_out     | [Asset](https://docs.dedust.io/reference/tlb-schemes#asset) | **yes**  | The asset received by the user.                         |
| amount\_out    | Coins                                                       | **yes**  | Amount of `asset_out` received by the user.             |
| amount\_in     | Coins                                                       | **yes**  | Amount of `asset_in` supplied by the user.              |
| sender\_addr   | MsgAddressInt                                               | **yes**  | Address of the contract that initiated the swap.        |
| referral\_addr | MsgAddress                                                  | no       | Referral address. Required for the Referral Program.    |
| reserve0       | Coins                                                       | **yes**  | Amount of `asset0` remaining in reserve after the swap. |
| reserve1       | Coins                                                       | **yes**  | Amount of `asset1` remaining in reserve after the swap. |

## Event "deposit"

```erlang TL-B
deposit#b544f4a4 sender_addr:MsgAddressInt amount0:Coins amount1:Coins
                 reserve0:Coins reserve1:Coins liquidity:Coins = ExtOutMsgBody;
```

| Name          | Type          | Required | Description                                                   |
| :------------ | :------------ | :------- | :------------------------------------------------------------ |
| `sender_addr` | MsgAddressInt | **yes**  | Address of the contract that initiated the deposit.           |
| `amount0`     | Coins         | **yes**  | Amount of `asset0` provided by the sender.                    |
| `amount1`     | Coins         | **yes**  | Amount of `asset1` provided by the sender.                    |
| `reserve0`    | Coins         | **yes**  | Amount of `asset0` remaining in reserve after the withdrawal. |
| `reserve1`    | Coins         | **yes**  | Amount of `asset1` remaining in reserve after the withdrawal. |
| `liquidity`   | Coins         | **yes**  | Amount of LP tokens issued for the sender.                    |

## Event "withdrawal"

```erlang TL-B
withdrawal#3aa870a6 sender_addr:MsgAddressInt liquidity:Coins
                    amount0:Coins amount1:Coins
                    reserve0:Coins reserve1:Coins = ExtOutMsgBody;
```

| Name          | Type          | Required | Description                                                   |
| :------------ | :------------ | :------- | :------------------------------------------------------------ |
| `sender_addr` | MsgAddressInt | **yes**  | Address of the contract that initiated the withdrawal.        |
| `liquidity`   | Coins         | **yes**  | Amount of LP tokens burned by the sender.                     |
| `amount0`     | Coins         | **yes**  | Amount of `asset0` sent to the sender.                        |
| `amount1`     | Coins         | **yes**  | Amount of `asset1` sent to the sender.                        |
| `reserve0`    | Coins         | **yes**  | Amount of `asset0` remaining in reserve after the withdrawal. |
| `reserve1`    | Coins         | **yes**  | Amount of `asset1` remaining in reserve after the withdrawal. |

# Liquidity Deposit

## Message "cancel\_deposit"

```erlang TL-B
cancel_deposit#166cedee query_id:uint64 payload:(Maybe ^Cell) = InMsgBody;
```

| Name       | Type        | Required | Description                                                             |
| :--------- | :---------- | :------- | :---------------------------------------------------------------------- |
| `query_id` | uint64      | no       | <<glossary:Query ID>>                                                   |
| `payload`  | Maybe ^Cell | no       | Custom payload that will be attached to the funds transfer to the user. |