# launch\_exchange

An entrypoint that launches a new exchanges. Next types of exchanges are supported:

* FA1.2/FA1.2;
* FA1.2/FA2;
* FA1.2/TEZ;
* FA2/FA1.2;
* FA2/FA2;
* FA2/TEZ;
* TEZ/FA1.2;
* TEZ/FA2.

In case of TOK/TEZ exchange launch [voting](/smart-contracts/dex-2.0/bucket-contract/entrypoints-overview/vote.md) in appropriative [Bucket](/smart-contracts/dex-2.0/bucket-contract.md) contract is executed. Also all TEZ tokens is [transferred](/smart-contracts/dex-2.0/bucket-contract/entrypoints-overview/fill.md) to the same [Bucket](/smart-contracts/dex-2.0/bucket-contract.md) contract before voting.

In time of first exchange launch, this contract calls [***launch\_callback***](/smart-contracts/dex-2.0/dexcore-contract/entrypoints-overview/callbacks/launch_callback.md) entrypoint. This is done in order to vote on a [Bucket](/smart-contracts/dex-2.0/bucket-contract.md) contract that has just been deployed and cannot be accessed until the launch exchange transaction completes. Therefore, voting takes place in the next transaction, sent from [***launch\_callback***](/smart-contracts/dex-2.0/dexcore-contract/entrypoints-overview/callbacks/launch_callback.md).

### Call parameters

```pascaligo
type tez_t              is unit

type fa12_token_t       is address

type fa2_token_t        is [@layout:comb] record [
  token                   : address;
  id                      : nat;
]

type token_t            is
| Tez                     of tez_t
| Fa12                    of fa12_token_t
| Fa2                     of fa2_token_t

type tokens_t           is [@layout:comb] record [
  token_a                 : token_t;
  token_b                 : token_t;
]

type launch_exchange_t  is [@layout:comb] record [
  pair                    : tokens_t;
  token_a_in              : nat;
  token_b_in              : nat;
  shares_receiver         : address;
  candidate               : key_hash;
  deadline                : timestamp;
]
```

#### tokens\_t

| Field    | Type     | Description         |
| -------- | -------- | ------------------- |
| token\_a | token\_t | FA1.2/FA2/TEZ token |
| token\_b | token\_t | FA1.2/FA2/TEZ token |

#### launch\_exchange\_t

<table><thead><tr><th>Field</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td>pair</td><td><a href="#tokens_t">tokens_t</a></td><td>Tokens to launch exchange with</td></tr><tr><td>token_a_in</td><td>nat</td><td>Amount of token A for investment</td></tr><tr><td>token_b_in</td><td>nat</td><td>Amount of token B for investment</td></tr><tr><td>shares_receiver</td><td>address</td><td>Receiver of LP tokens</td></tr><tr><td>candidate</td><td>key_hash</td><td>Baker for voting (is used only in case of TOK/TEZ exchanges launch). Ignored otherwise</td></tr><tr><td>deadline</td><td>timestamp</td><td>The time until which the transaction remains valid and will not be rejected</td></tr></tbody></table>

### Usage

{% hint style="danger" %}
Note: you need to pass positive TEZ/mutez amount to the ***send()*** method in case of FA1.2/TEZ or FA2/TEZ exchanges launch (see example below).

Also don't forget to add the [DexCore](/smart-contracts/dex-2.0/dexcore-contract.md) contract as the operator for your FA2 tokens or make an approve for spending of FA1.2 tokens in time of exchange launch.
{% endhint %}

{% tabs %}
{% tab title="🌮 Taquito" %}

```javascript
const dexCoreAddress = "KT1...";
const params = {
    pair: {
        token_a: {
            fa12: "KT1...",
        }, 
        token_b: {
            tez: undefined,
        },
    },
    token_a_in: 100,
    token_b_in: 100,
    shares_receiver: "tz1.../KT1...",
    candidate: "tz1...",
    deadline: String(Date.parse((await tezos.rpc.getBlockHeader()).timestamp) / 1000 + 100),
};
const dexCore = await tezos.contract.at(dexCoreAddress);
const operation = await dexCore.methodsObject.launch_exchange(params).send({ amount: params.token_b_in, mutez: true });

await operation.confirmation();
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Pass `candidate: "tz1ZZZZZZZZZZZZZZZZZZZZZZZZZZZZNkiRg"`in case of launching TOK/TOK exchange
{% endhint %}

### Errors

* `104` - wrong order of a tokens from parameters.
* `105` - zero token A amount in.
* `106` - zero token B amount in.
* `107` - pair (pool) with the specified `token_id` already listed.
* `120` - wrong TEZ amount were passed to the transaction.
* `136` - reentrancy.
* `144` - action outdated (the time until which the transaction remained valid was passed).
* `412` - non payable entrypoint (can't accept TEZ tokens during call of an entrypoint). Only in case of launching of TOK/TOK liquidity pools (pairs).


---

# 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/dex-entrypoints/launch_exchange.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.
