DexFA12
The contract fully implements the entrypoints of FA1.2 standard according to TZIP-7.
Along with two other entrypoints: Use for exchange-related methods and Default for processing all the baker payments and donations.

Code

quipuswap-core/DexFA12.ligo at master · madfish-solutions/quipuswap-core
GitHub

State-Changing Functions

Default()

1
(unit %default)
Copied!
Used to collect rewards from bakers, donations, or misguided payments without specified entrypoint. Perform global loyalty distribution and distribute rewards if the reward epoch is finished.

Use(params)

Executes the exchange-related functions. They can`t be separated into independent entrypoint due to the operation size limit. The parameter is a variant type of the really required functionality described below.

initializeExchange(token_amount)

1
(nat %initializeExchange)
Copied!
Setup the exchange after all the liquidity was drained. XTZ must be sent and amount of tokens should be approved. Initial liquidity should be non-zero. All the storage parameters are reset to default values, the new rewards period is started. The sender receives shares equal to the sent mutez.
Parameter
Type
Description
token_amount
nat
The token amount for initial liquidity
tez_amount
tez
The XTZ for initial liquidity should be sent along with the launch transaction

tezToTokenPayment(min_out, receiver)

1
(pair %tezToTokenPayment (nat %min_out) (address %receiver))
Copied!
Exchanges XTZ to tokens and sends them to receiver; operation is reverted if the amount of exchanged tokens is less than min_out. The number of received tokens can't exceed 1/3 of reserves for security reasons. Both min_out and sent XTZ are non-zero values. The fees of 0.3% are charged. The receiver must have a default entrypoint.
Parameter
Type
Description
min_out
nat
Minimal amount of tokens received to accept exchange
receiver
address
Tokens receiver
tez_amount
tez
The XTZ to be exchanged

tokenToTezPayment(amount, min_out, receiver)

1
(pair %tokenToTezPayment (pair (nat %amount) (nat %min_out))
2
(address %receiver))
Copied!
Exchanges amount tokens to XTZ and sends them to receiver; operation is reverted if the amount of exchanged XTZ is less than min_out. The amount of received XTZ can't exceed 1/3 of reserves for security reasons. Both amount and min_out out are non-zero values. The fees of 0.3% are charged. Th receiver must have a default entrypoint.
Parameter
Type
Description
amount
tez
The amount of tokens to be exchanged
min_out
nat
Minimal amount of XTZ received to accept exchange
receiver
address
Tokens receiver

investLiquidity(max_token_in)

1
(nat %investLiquidity)
Copied!
Mints shares by investing tokens and XTZ; the corresponding amount of XTZ has to be sent via transaction and the max amount of tokens to be spent should be approved for Dex. Both global and user loyalty are updated as well as bakers' rewards are distributed if the reward epoch is finished. The amount of shares is calculated based on the amounts of XTZ sent to the contract. If the amount of invested tokens is higher than max_token_in or the amount of invested tokens is zero the transaction is reverted.
Parameter
Type
Description
max_token_in
nat
The maximum amount of tokens to be invested
tez_amount
tez
The XTZ for initial liquidity should be sent along with the invest transaction

divestLiquidity(min_tez, min_tokens, shares)

1
(pair %divestLiquidity (pair (nat %min_tez) (nat %min_tokens))
2
(nat %shares))
Copied!
Burns shares and sends tokens and XTZ to the owner; operation is reverted if the amount of divested tokens is smaller than min_tokens or the amount of divested XTZ is smaller than min_tez. Both global and user loyalty are updated as well as bakers' rewards are distributed if the reward epoch finished. All parameters are non-zero values.
Parameter
Type
Description
shares
nat
The number of shares to be burnt
min_tez
nat
The minimal amount of XTZ received to accept the divestment
min_tokens
nat
The minimal amount of tokens received to accept the divestment

vote(candidate, value, voter)

1
(pair %vote (pair (key_hash %candidate) (nat %value))
2
(address %voter))
Copied!
Votes for candidate with shares of voter. The candidate cannot be on the banned list. Value cannot exceed the number of liquid voter's shares (not used in veto voting). If the user has participated in voting before his votes are automatically returned to the liquid balance before new voting.
If the candidate receives more votes than the current best candidate he takes that place. If the candidate collects more votes than the current delegate the candidate becomes a new delegate and the delegate becomes the new best candidate.
Parameter
Type
Description
candidate
key_hash
The chosen baker
value
nat
The number of shares that are used to vote
voter
address
The account from which the voting is done

veto(value, voter)

1
(pair %veto (nat %value) (address %voter))
Copied!
Votes against current delegate with value shares of voter; the value is frozen and can't be transferred or used for another voting. If the user has participated in the veto voting before his votes are automatically returned to the liquid balance before new voting.
If the limit of 1/3 of total votes is reached the current delegated is banned and can't be chosen as a delegated for 3 months. The best candidate becomes the new delegate.
Parameter
Type
Description
value
nat
The number of shares that are used for veto
voter
address
The account from which the veto is done

withdrawProfit(receiver)

1
(address %withdrawProfit)
Copied!
Withdraws delegation reward of the sender to receiver address. Both global and user loyalty are updated as well as bakers' rewards are distributed if the reward epoch finished. The user's reward is sent only if any is collected. The receiver must have a default entrypoint.
Parameter
Type
Description
receiver
address
Rewards receiver

API

1
parameter (or
2
(or (or (pair %approve (address %spender) (nat %value)) (unit %default))
3
(or
4
(pair %getAllowance (pair (address %owner) (address %spender))
5
(contract nat))
6
(pair %getBalance (address %owner) (contract nat))))
7
(or
8
(or (contract %getReserves (pair nat nat))
9
(pair %getTotalSupply unit (contract nat)))
10
(or (pair %transfer (address %from) (address %to) (nat %value))
11
(or %use
12
(or
13
(or
14
(pair %divestLiquidity (pair (nat %min_tez) (nat %min_tokens))
15
(nat %shares))
16
(nat %initializeExchange))
17
(or (nat %investLiquidity)
18
(pair %tezToTokenPayment (nat %min_out) (address %receiver))))
19
(or
20
(or
21
(pair %tokenToTezPayment (pair (nat %amount) (nat %min_out))
22
(address %receiver))
23
(pair %veto (nat %value) (address %voter)))
24
(or
25
(pair %vote (pair (key_hash %candidate) (nat %value))
26
(address %voter))
27
(address %withdrawProfit)))))));
Copied!
Last modified 3mo ago