# Liquidity

To be able to swap 2 tokens at any time we need liquidity and to add liquidity we need to send a "proof of deposit" to users (Liquidity Pool token)

```rust
    #[only_owner]
    #[payable("EGLD")]
    #[endpoint(issueLpToken)]
    
    issueLpToken@first_token(mid)@second_token(mex)@LPname@LpTicker
```

At this stage only the owner of the contract (us) can call the function to create a new liquidity pool. If you want to    enable swap on our application please contact us.&#x20;

Must send 0,05 EGLD to pay ESDT creation

The resulting esdt ticker will be saved in pool information&#x20;

```
#[endpoint(setLocalRoles)]

setLocalRoles@first_token(mid)@second_token(mex)
```

We need to call this function once to allow the SC to mint and burn the LP token&#x20;

```rust
   #[payable("*")]
   #[endpoint(addLp)]
   fn add_lp(&self)
   
   MultiESDTNFTTransfer
   @erd1qqqqqqqqqqqqqpgqgdf6vk43c2jxk4a6nw2adv8vmnpqagegtxfqmf8et2(SC)
   @2(2 tokens)
   @MID-ecb7bf(first ticker)
   @0(nonce)
   @4000000000000000000000 (first token qty)
   @MEX-455c57 (second token)
   @0(nonce)
   @12000000000000000000000000 (second token qty)
   @addLp

```

Exemple: <https://explorer.multiversx.com/transactions/3b58877b00280ee5ff5c7d02423dfc0f0d42a726c1682aaac38f94163a6e5589>

If this is the very first deposit, the SC will consider the two amounts as the exchange ratio to be applied

If it is an addition of liquidity, the contract will calculate the maximum possible ratio and return the surplus to the user.&#x20;

In both cases, the user will receive an amount of LP tokens corresponding to his participation rate in the liquidity provision

```rust
    #[payable("*")]
    #[endpoint(removeLp)]
    fn remove_lp(&self, first_token: TokenIdentifier, second_token: TokenIdentifier)
```

The user can send his LP tokens to the SC by specifying the pairs concerned, he will receive in exchange his shares of the liquidity in place.


---

# 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.middlestaking.fr/contracts/swap-contract/liquidity.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.
