swap
In the current implementation, under the hood, all swaps are actually flash swaps. This simply means that contract sends output tokens to the recipient before enforcing that enough input tokens have been received. This is slightly atypical, as one might expect a pair to ensure it's received payment before delivery. However, because Tezos transactions are atomic, we can roll back the entire swap if it turns out that the contract hasn't received enough tokens to make itself whole by the end of the transaction.
Below you can find detailed description of both use cases: simple swap and flash swap.
Swap
An entrypoint that executes swaps in different liquidity pools (pairs).
All possible routes for swaps are allowed. For example: FA1.2->TEZ
, TEZ->FA1.2
, FA2->TEZ
, TEZ->FA2
, FA1.2->FA1.2
, FA2->FA2
, FA1.2->FA2
, FA2->FA1.2
.
Multi token routes are allowed too. For example: FA1.2->FA2->TEZ->FA2
, TEZ->FA2->FA1.2->TEZ
, FA2->TEZ->FA2->TEZ->FA1.2
.
Call parameters
swap_slice_t
Field | Type | Description |
---|---|---|
direction | swap_direction_t | Swap direction: A->B or B->A |
pair_id | token_id_t (nat) | ID of a pair in which swap will be executed |
get_swap_min_res_t
Field | Type | Description |
---|---|---|
lambda | option(unit -> list(operation)) | Users's lambda function that doesn't accept any parameters (unit) and returns a list of operations (transactions, calls). Must be |
swaps | list(swap_slice_t) | A route of a swap |
deadline | timestamp | The time until which the transaction remains valid and will not be rejected |
receiver | address | The receiver of exchanged tokens |
referrer | address | Referrer to whom interface fee will be paid |
amount_in | nat | Amount of tokens to swap from |
min_amount_out | nat | The minimum number of outgoing tokens that the user agrees to |
Usage
You need to pass positive TEZ/mutez amount to the send() method in case of TEZ->FA1.2 or TEZ -> FA2 swaps (see example below).
Also don't forget to add the DexCore contract as the operator for your FA2 tokens or make an approve for spending of FA1.2 tokens in time of FA1.2/FA2->FA1.2/FA2/TEZ swaps.
Errors
108
- pair (pool) with the specifiedtoken_id
not listed.109
- pair doesn't have a liquidity.116
- high expectations of output tokens.117
- empty route of swaps.118
- zero amount in was passed as the parameter.119
- wrong route of a swap.120
- wrong TEZ amount were passed to the transaction.130
- referring on yourself is forbidden.136
- reentrancy.139
- too few swaps.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 swapping NOT from TEZ token.
Flash swap
An entrypoint that allows to make a flash swaps. QuipuSwap flash swaps allows you to exchange up to the full reserves of any FA1.2/FA2/TEZ token on QuipuSwap and execute arbitrary logic at no upfront cost, provided that by the end of the transaction you will pay for the withdrawn FA1.2/FA2/TEZ tokens with the corresponding pair tokens.
After execution of user's lambda, flash_swap_callback entrypoint will be executed (only in case of TEZ tokens loan).
All possible routes for swaps are allowed. Also, supports multi token routes.
Call parameters
swap_slice_t
Field | Type | Description |
---|---|---|
direction | swap_direction_t | Swap direction: A->B or B->A |
pair_id | token_id_t (nat) | ID of a pair in which swap will be executed |
get_swap_min_res_t
Field | Type | Description |
---|---|---|
lambda | option(unit -> list(operation)) | Users's lambda function that doesn't accept any parameters (unit) and returns a list of operations (transactions, calls) |
swaps | list(swap_slice_t) | A route of a swap |
deadline | timestamp | The time until which the transaction remains valid and will not be rejected |
receiver | address | The receiver of exchanged tokens |
referrer | address | Referrer to whom interface fee will be paid |
amount_in | nat | Amount of tokens to swap from |
min_amount_out | nat | The minimum number of outgoing tokens that the user agrees to |
Usage
Lambda function example
FlashSwapAgent - contract that implements different arbitrary logic.
Errors
108
- pair (pool) with the specifiedtoken_id
not listed.109
- pair doesn't have a liquidity.116
- high expectations of output tokens.117
- empty route of swaps.118
- zero amount in was passed as the parameter.119
- wrong route of a swap.120
- wrong TEZ amount were passed to the transaction.130
- referring on yourself is forbidden.136
- reentrancy.139
- too few swaps.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 swapping NOT from TEZ token.all errors from the flash_swap_callback entrypoint.
Last updated