Quipuswap
  • introduction
    • What is QuipuSwap?
    • Participants
    • QuipuSwap subprojects
      • QuipuSwap Farms
      • Quipuswap Stable DEX
      • Token to Token Swaps
      • Governance (text-only)
  • Get Started
    • Install Wallet
    • How to get TEZ
    • How to find my tokens
    • Connect wallet
    • FAQ
  • Dex Guides
    • Overview
    • Types of the exchange (Token/TEZ, Token/Token)
    • How to use the DEX
      • Trade
      • How to add liquidity to an existing liquidity pool
      • How to create a new liquidity pool
      • How to remove liquidity
      • How to vote for a baker
      • How to ban/veto a baker
  • Tezos Tokens
    • What is a Token?
    • What is the difference between FA1.2 and FA2 standards?
    • QUIPU Tokenomics
  • Smart Contracts
    • Dex token edition
      • Overview
      • Dex
      • Exceptions
    • QuipuSwap stable swap DEX
      • 🛠️Developer module
        • 📄Storage & action types
        • 🔵Developer setter entrypoints
          • set_dev_address
          • set_dev_fee
      • 🏠Standalone DEX
        • 📄Storage and types overview
        • 🟡Initialization
          • set_admin_function
          • set_dev_function
          • set_dex_function
          • set_token_function
        • 🟠Add new dex
          • add_pool
        • 🔵DEX methods
          • invest
          • swap
          • 📤Divesting
            • divest
            • divest_imbalanced
            • divest_one_coin
          • 🤑DEX rewards
            • claim_referral
            • stake
        • 🛠️Developer methods
          • claim_developer
          • Dev module entrypoints
        • 🛑Admin methods
          • add_rem_managers
          • ramp_A
          • set_admin
          • set_fees
          • stop_ramp_A
      • 🏭Factory
        • 📄Storage and types overview
        • 🟡Initial setup
          • set_init_function
          • set_dev_function
          • DEX compiled codebase setup
            • set_admin_function
            • set_dex_function
            • set_token_function
        • 🟠Initialize new DEX flow
          • add_pool
          • start_dex
        • 💱Deployed from factory DEX
          • 📄Storage and types overview
          • 🟡Initialization
            • copy_dex_function
            • freeze
          • 🔵DEX methods
          • 🛠️Claim developer rewards
          • 🛑Admin methods
        • 🛑Developer methods
          • claim_rewards
          • 🧑‍💻Factory management
            • 🟢Factory params
              • set_burn_rate
              • set_price
              • set_whitelist
            • 🔵Dev module entrypoints
    • Dex 2.0
      • ⁉️Errors overview
      • 🥐BakerRegistry contract
        • Storage and types overview
        • Entrypoints overview
          • validate
          • register
      • ⚙️FlashSwapsProxy contract
        • Storage and types overview
        • Entrypoints overview
          • default
      • 🧺Bucket contract
        • Storage and types overview
        • Entrypoints overview
          • fill
          • pour_out
          • pour_over
          • withdraw_rewards
          • ban_baker
          • vote
          • default
        • On-chain views overview
          • is_banned_baker
          • get_tez_balance
          • get_user_candidate
      • ⚖️Auction contract
        • Storage and types overview
        • Entrypoints overview
          • Auction entrypoints
            • receive_fee
            • launch_auction
            • place_bid
            • claim
          • Admin entrypoints
            • set_admin
            • confirm_admin
            • set_baker
            • set_fees
            • set_auction_duration
            • set_min_bid
            • update_whitelist
            • withdraw_dev_fee
            • withdraw_public_fee
            • burn_bid_fee
      • 🏦DexCore contract
        • Storage and types overview
        • Entrypoints overview
          • DEX entrypoints
            • launch_exchange
            • invest_liquidity
            • divest_liquidity
            • swap
            • withdraw_profit
            • claim_interface_fee
            • claim_interface_tez_fee
            • withdraw_auction_fee
            • vote
          • Admin entrypoints
            • set_admin
            • confirm_admin
            • set_flash_swaps_proxy
            • set_auction
            • add_managers
            • set_fees
            • set_collecting_period
            • update_token_metadata
            • ban
          • Permits' entrypoints
            • permit
            • set_expiry
          • FA2 entrypoints
            • transfer
            • update_operators
            • balance_of
          • Callbacks
            • launch_callback
            • flash_swap_callback
            • close
        • On-chain views overview
          • check_is_banned_baker
          • get_reserves
          • get_total_supply
          • get_swap_min_res
          • get_toks_per_share
          • get_cumulative_prices
          • get_collecting_period
    • Trusted contracts
    • Farming
      • Referral system overview
      • Fees overview
      • Rewards precision overview
      • BakerRegistry contract
        • Storage and types overview
        • Entrypoints overview
          • validate
          • register
      • Burner contract
        • Storage and types overview
        • Entrypoints overview
          • default
          • burn_callback
      • ProxyMinter contract
        • Storage and types overview
        • Entrypoints overview
          • Admin entrypoints
            • add_minter
            • withdraw_tokens
            • set_admin
            • confirm_admin
          • Minter entrypoint
            • mint_tokens
      • QFarm contract
        • Storage and types overview
        • Entrypoints overview
          • Farming entrypoints
            • deposit
            • withdraw
            • harvest
          • FA2 entrypoints
            • transfer
            • update_operators
            • balance_of
          • Admin entrypoints
            • set_admin
            • confirm_admin
            • set_fees
            • set_reward_per_second
            • set_burner
            • set_proxy_minter
            • set_baker_registry
            • set_is_v1_lp
            • ban_bakers
            • add_new_farm
            • pause_farms
            • burn_tez_rewards
            • withdraw_farm_depo
            • update_token_metadata
          • Other entrypoints
            • burn_farm_rewards
            • default
      • TFarm contract
        • Storage and types overview
        • Entrypoints overview
          • Farming entrypoints
            • deposit
            • withdraw
            • harvest
          • FA2 entrypoints
            • transfer
            • update_operators
            • balance_of
          • Admin entrypoints
            • set_admin
            • confirm_admin
            • set_fees
            • set_reward_per_second
            • set_burner
            • set_baker_registry
            • set_is_v1_lp
            • ban_bakers
            • add_new_farm
            • pause_farms
            • burn_tez_rewards
            • claim_farm_rewards
            • withdraw_farm_depo
            • update_token_metadata
          • Other entrypoints
            • default
  • Brand and Logos
Powered by GitBook
On this page
  • Code
  • State-Changing Functions
  • AddPair
  • Swap
  • Invest
  • Divest
  • Close
  • Read-Only Functions
  • Get_reserves
  1. Smart Contracts
  2. Dex token edition

Dex

PreviousOverviewNextExceptions

Last updated 3 years ago

The contract is responsible for launching new exchange pairs and serves as the automatic market maker engine. The contract manages pools for FA1.2/FA1.2, FA2/FA2 and FA2/FA1.2 tokens. The only instance of the pool for the same pair exists.

The contract fully implements the entrypoints of the FA2 standard according to . The other exchange-specific entrypoints are described in the doc.

Code

State-Changing Functions

AddPair

types.ligo
type fa2_token_type     is
record [
  token_address           : address;
  token_id                : nat;
]

type token_type        is
| Fa12                    of address
| Fa2                     of fa2_token_type


type tokens_type        is 
[@layout:comb]
record [
  token_a_type            : token_type; (* token A standard *)
  token_b_type            : token_type; (* token B standard *)
]


type add_pair_params  is 
[@layout:comb]
record [
  pair                    : tokens_type; (* exchange pair info *)
  token_a_in              : nat; (* min amount of tokens A invested  *)
  token_b_in              : nat; (* min amount of tokens B invested *)
]

Setup the new exchange or relaunch the exchange after all the liquidity was drained. amount_a_in and amount_b_in of tokens must be approved. Initial liquidity should be non-zero. All the storage parameters are reset to default values. The sender receives shares equal to a minimum of amount_a_in and amount_b_in. Tokens types must be provided in ascending order.

Parameter
Type
Description

token_a_type

tokens_type

The type of the first token

token_b_type

tokens_type

The type of the second token

token_a_in

nat

Amount of the first token to be invested

token_b_in

nat

Amount of the second token to be invested

Swap

type swap_type          is
| A_to_b
| B_to_a

type swap_slice_type    is 
record [
  pair_id                 : nat;
  operation               : swap_type;
]

type swap_type          is 
[@layout:comb]
record [
  swaps                   : list(swap_slice_type);
  amount_in               : nat;
  min_amount_out          : nat;
  receiver                : address;
  deadline                : timestamp;
]
 

Swaps the token to another token. a_to_b type is used to exchange token_a to token_b. b_to_a performs the opposite swap from token_b_address to token_a_address. The token_a and token_b are the corresponding tokens of pair_id pool. The amount_in of the token will be charged from the user. If the received amount is smaller than min_amount_out then the transaction is reverted. Tokens types must be provided in ascending order. Deadlines should be in the future.

Parameter
Type
Description

swaps

list of swap_slice_type

Swaps to perform; each swap consist of pair_id of the pool and swap_type to be executed; all the exchanges should be sequential.

amount_in

nat

Amount of the token to swap

min_amount_out

nat

The minimal amount of the token to receive

receiver

address

Receiver's address

deadline

timestamp

Time until the operation is valid

Invest

type invest_type        is 
[@layout:comb]
record [
  pair_id                 : nat;
  shares                  : nat;
  token_a_in              : nat;
  token_b_in              : nat;
  deadline                : timestamp;
]

Adds more liquidity to the exchange. token_a_in and token_b_in must be approved. Initial liquidity should be non-zero. The sender spends token_a_in and token_b_in at most otherwise, the transaction fails. Tokens types must be provided in ascending order. Deadlines should be in the future.

Parameter
Type
Description

pair_id

nat

Pair identifier

shares

nat

Amount of LP tokens to mint

token_a_in

nat

Max amount of the first token to invest

token_b_in

nat

Max amount of the second token to invest

deadline

timestamp

Time until the operation is valid

Divest

type divest_type        is 
[@layout:comb]
record [
  pair_id                 : nat;
  min_token_a_out         : nat;
  min_token_b_out         : nat;
  shares                  : nat;
  deadline                : timestamp;
]

Burns shares and sends tokens to the owner; operation is reverted if the amount of appropriate divested tokens is smaller than min_token_a_out or min_token_b_out. Tokens types must be provided in ascending order. Deadlines should be in the future.

Parameter
Type
Description

pair_id

nat

Pair identifier

min_token_a_out

nat

Minimal amount of the first token to receive

min_token_b_out

nat

Minimal amount of the second token to receive

shares

nat

The amount of the shares to burn

deadline

timestamp

Time until the operation is valid

Close

type close_type        is unit

Is used after all the exchange calls to prevent reentrancy. It can only be called by the exchange itself.

Read-Only Functions

Get_reserves

type reserves_type      is 
record [
  receiver                : contract(nat * nat);
  pair_id                 : nat;
]

Returns the amount of tokens reserves. No arguments are needed.

TZIP-12
https://github.com/madfish-solutions/quipuswap-token2token-core/blob/master/contracts/main/Dex.ligogithub.com