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
  • Base types
  • Staker accumulator - accumulator of QUIPU staking rewards.
  • Fee storage - fee rates record
  • Token information type - pool underlying token info
  • Pool type - DEX pool storage
  • Storage - main contract storage
  • Full storage type - storage root
  1. Smart Contracts
  2. QuipuSwap stable swap DEX
  3. Factory
  4. Deployed from factory DEX

Storage and types overview

Contract typings and storage

Base types

type token_id_t        is nat

type pool_id_t         is nat

type token_pool_idx_t  is nat

type fa12_token_t      is address

type fa2_token_t       is [@layout:comb] record[ 
    token_address        : address; 
    token_id             : token_id_t; 
]

type token_t           is 
| Fa12                   of fa12_token_t 
| Fa2                    of fa2_token_t

type tokens_map_t      is map(nat, token_t);

Staker accumulator - accumulator of QUIPU staking rewards.

Field
Type
Hint
Description

accumulator

map(token_pool_idx_t, nat)

Mapping of token index and corresponding underlying accumulated balance of token

total_staked

nat

balance of staked QUIPU tokens to current pool

type staker_accum_t     is [@layout:comb] record [
  accumulator             : map(token_pool_idx_t, nat);
  total_staked            : nat;
]

Fee storage - fee rates record

Field
Type
Hint
Description

lp

nat

Percent of fee goes to liquidity providers.

This fee stays in liquidity pool to increase LP token price.

stakers

nat

Percent of fee goes to QUIPU token stakers of pool. This fee goes to staking accumulator and spreads between users who staked QUIPU token to pool. If noone staked this fee part goes to liquidity pool as additional fee.

ref

nat

Percent of fee goes to referral of DEX call. This fee goes to referral address passed to DEX call. If referral not passed, fee goes to default referral.

type fees_storage_t     is [@layout:comb] record [
  lp                      : nat;
  stakers                 : nat;
  ref                     : nat;
]

Token information type - pool underlying token info

Field
Type
Hint
Description

rate

nat

Calculates with pecisions. By default LP precision is 1e18. Rate is the value allowing to set custom exchange ratios between underlying tokens

Indicates how much LP token belongs to each underlying stablecoin

precision_multiplier

nat

value that underlying token reserves are multiplied by in order to adjust their precision to LP decimal places

reserves

nat

balance of underlying token, locked in pool

type token_info_t       is  [@layout:comb] record [
  rate                    : nat;
  precision_multiplier    : nat;
  reserves                : nat;
]

Pool type - DEX pool storage

Field
Type
Hint
Description

initial_A

nat

Start value of ramping A contant.

initial_A_time

timestamp

Timestamp in seconds

Time when ramping A constant was started.

future_A

nat

End value of ramping A contant.

future_A_time

timestamp

Timestamp in seconds

Time when ramping A constant will be finished

tokens_info

map(token_pool_idx_t, token_info_t)

fee

fees_storage_t

staker_accumulator

staker_accum_t

total_supply

nat

Total supply of LP token.

type pool_t             is [@layout:comb] record [
  initial_A               : nat;
  initial_A_time          : timestamp;
  future_A                : nat;
  future_A_time           : timestamp;
  tokens_info             : map(token_pool_idx_t, token_info_t);
  fee                     : fees_storage_t;
  staker_accumulator      : staker_accum_t;
  total_supply            : nat;
]

Storage - main contract storage

Field
Type
Hint
Description

admin

address

Administator of current contract

default_referral

address

Default referral address to apply fees

managers

set(address)

Manager could edit LP token metadata.

Set of managers addresses

pools_count

nat

Counter. Always 1

Amount of pools created inside current contract.

tokens

big_map(pool_id_t, tokens_map_t)

Mapping of tokens, that exchanges inside created pool.

pool_to_id

big_map(bytes, nat)

Bytes - packed by Bytes.pack(tokens) where tokens is valid tokens_map_t (sorted tokens).

Mapping that allows finding pool id by packed bytes of tokens_map_t

pools

big_map(pool_id_t, pool_t)

ledger

big_map(

(address * pool_id_t), nat)

Mapping of user's LP token balance related to pool

allowances

big_map(

(address * pool_id_t), allowances_data_t)

Storage of operators allowed to transfer LP tokens of user's behalf.

dev_rewards

big_map(token_t, nat)

Mapping of accrued developer rewards by each token.

referral_rewards

big_map(

(address * token_t), nat)

Mapping of accrued referral rewards by each user-token key.

stakers_balance

big_map(

(address * pool_id_t), staker_info_t)

Mapping of accrued staking rewards by each user-token key.

quipu_token

fa2_token_t

QUIPU token address and token ID

started

bool

flag that used in initialization stage

factory_address

address

this field setted at deploy and has no methods for changing

address of factory

type storage_t          is [@layout:comb] record [
  (* Management *)
  admin                   : address;
  default_referral        : address;
  managers                : set(address);

  (* Pools data *)
  pools_count             : nat; (* total pools count *)
  tokens                  : big_map(pool_id_t, tokens_map_t); (* all the tokens list *)
  pool_to_id              : big_map(bytes, nat); (* all the tokens list *)
  pools                   : big_map(pool_id_t, pool_t); (* pool info per token id *)

  (* FA2 data *)
  ledger                  : big_map((address * pool_id_t), nat); (* account info per address *)
  allowances              : big_map((address * pool_id_t), allowances_data_t); (* account info per each lp provider *)

  (* Rewards and accumulators *)
  dev_rewards             : big_map(token_t, nat);
  referral_rewards        : big_map((address * token_t), nat);
  stakers_balance         : big_map((address * pool_id_t), staker_info_t);
  quipu_token             : fa2_token_t;
  (* dev storage params *)
  dev_store               : dev_storage_t;
]

Full storage type - storage root

Field
Type
Hint
Description

storage

storage_t

Indicates how much LP token belongs to each underlying stablecoin

metadata

big_map(string, bytes)

TZIP-016

token_metadata

big_map(token_id_t, token_meta_info_t)

TZIP-016, TZIP-012

admin_lambdas

big_map(nat, bytes)

Administrative lambda-methods storage

dex_lambdas

big_map(nat, bytes)

DEX stable swap protocol lambda-methods storage

token_lambdas

big_map(nat, bytes)

FA2 lambda-methods storage

type full_storage_t     is [@layout:comb] record [
  storage                 : storage_t; (* real dex storage_t *)
  (* Token Metadata *)
  metadata                : big_map(string, bytes); (* metadata storage_t according to TZIP-016 *)
  token_metadata          : big_map(token_id_t, token_meta_info_t);
  (* Contract lambdas storage *)
  admin_lambdas           : big_map(nat, bytes); (* map with admin-related functions code *)
  dex_lambdas             : big_map(nat, bytes); (* map with exchange-related functions code *)
  token_lambdas           : big_map(nat, bytes); (* map with token-related functions code *)
]
PreviousDeployed from factory DEXNextInitialization

Last updated 3 years ago

For better accuracy, stored with multiplication by .

Decimal value. Multiplied by .

Decimal value. Multiplied by .

Decimal value. Multiplied by .

By default LP precision is 1e18. Than precision_multiplier is

A constant stores as multiplied value. (10^2 is precision)

A constant stores as multiplied value. (10^2 is precision)

Mapping of pool to it's corresponding pool

contract metadata by

mapping each token metadata by

🏭
💱
📄
101010^{10}1010
101010^{10}1010
101010^{10}1010
101010^{10}1010
10decimalsLP−decimalstoken10^{decimals_{LP} - decimals_{token}}10decimalsLP​−decimalstoken​
A∗nn−1∗102 A * n^{n-1} * 10^2A∗nn−1∗102
A∗nn−1∗102 A * n^{n-1} * 10^2A∗nn−1∗102
freeze
Token information type - pool underlying token info
Fee storage - fee rates record
#staker-accumulator-accumulator-of-quipu-staking-rewards.
Pool type - DEX pool storage
Storage - main contract storage
TZIP-016
TZIP-012