FactoryFA2

Code

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

State-Changing Functions

setDexFunction(func, index)

1
(pair %setDexFunction
2
(lambda %func
3
(pair
4
(pair
5
(or
6
(or
7
(or
8
(pair %divestLiquidity
9
(pair (nat %min_tez) (nat %min_tokens))
10
(nat %shares))
11
(nat %initializeExchange))
12
(or (nat %investLiquidity)
13
(pair %tezToTokenPayment (nat %min_out)
14
(address %receiver))))
15
(or
16
(or
17
(pair %tokenToTezPayment
18
(pair (nat %amount) (nat %min_out))
19
(address %receiver))
20
(pair %veto (nat %value) (address %voter)))
21
(or
22
(pair %vote (pair (key_hash %candidate) (nat %value))
23
(address %voter))
24
(address %withdrawProfit))))
25
(pair
26
(pair
27
(pair
28
(pair
29
(pair (address %baker_validator)
30
(option %current_candidate key_hash))
31
(pair (option %current_delegated key_hash)
32
(timestamp %last_update_time)))
33
(pair
34
(pair (timestamp %last_veto)
35
(big_map %ledger address
36
(pair
37
(pair (set %allowances address)
38
(nat %balance))
39
(nat %frozen_balance))))
40
(pair (timestamp %period_finish) (nat %reward))))
41
(pair
42
(pair (pair (nat %reward_paid) (nat %reward_per_sec))
43
(pair (nat %reward_per_share) (nat %tez_pool)))
44
(pair (pair (address %token_address) (nat %token_id))
45
(pair (nat %token_pool) (nat %total_reward)))))
46
(pair
47
(pair (pair (nat %total_supply) (nat %total_votes))
48
(pair
49
(big_map %user_rewards address
50
(pair (nat %reward)
51
(nat %reward_paid)))
52
(nat %veto)))
53
(pair
54
(pair (big_map %vetos key_hash timestamp)
55
(big_map %voters address
56
(pair
57
(pair
58
(option %candidate key_hash)
59
(timestamp %last_veto))
60
(pair (nat %veto) (nat %vote)))))
61
(big_map %votes key_hash nat)))))
62
address)
63
(pair (list operation)
64
(pair
65
(pair
66
(pair
67
(pair
68
(pair (address %baker_validator)
69
(option %current_candidate key_hash))
70
(pair (option %current_delegated key_hash)
71
(timestamp %last_update_time)))
72
(pair
73
(pair (timestamp %last_veto)
74
(big_map %ledger address
75
(pair
76
(pair
77
(set %allowances address)
78
(nat %balance))
79
(nat %frozen_balance))))
80
(pair (timestamp %period_finish) (nat %reward))))
81
(pair
82
(pair (pair (nat %reward_paid) (nat %reward_per_sec))
83
(pair (nat %reward_per_share) (nat %tez_pool)))
84
(pair (pair (address %token_address) (nat %token_id))
85
(pair (nat %token_pool) (nat %total_reward)))))
86
(pair
87
(pair (pair (nat %total_supply) (nat %total_votes))
88
(pair
89
(big_map %user_rewards address
90
(pair (nat %reward)
91
(nat %reward_paid)))
92
(nat %veto)))
93
(pair
94
(pair (big_map %vetos key_hash timestamp)
95
(big_map %voters address
96
(pair
97
(pair
98
(option %candidate key_hash)
99
(timestamp %last_veto))
100
(pair (nat %veto) (nat %vote)))))
101
(big_map %votes key_hash nat))))))
102
(nat %index))
Copied!
Sets the Dex specific function. Should be used before the whole system is launched. Fails if the function was set before or the index exceeds the number of Dex functions minus one(8).
Parameter
Type
Description
index
nat
The key in functions map
func
lambda
Function code
Each index is designed for a specific func:
1
%initializeExchange -> 0n
2
%tezToTokenPayment -> 1n
3
%iokenToTezPayment -> 2n
4
%withdrawProfit -> 3n
5
%investLiquidity -> 4n
6
%divestLiquidity -> 5n
7
%vote -> 6n
8
%veto -> 7n
Copied!

setTokenFunction(func, index)

1
(pair %setTokenFunction
2
(lambda %func
3
(pair
4
(pair
5
(or
6
(or
7
(pair %iBalance_of
8
(list %requests (pair (address %owner) (nat %token_id)))
9
(contract %callback (list (pair
10
(pair %request (address %owner)
11
(nat %token_id))
12
(nat %balance)))))
13
(list %iTransfer (pair (address %from_)
14
(list %txs (pair (address %to_)
15
(pair (nat %token_id)
16
(nat %amount)))))))
17
(list %iUpdate_operators (or
18
(pair %add_operator (address %owner)
19
(pair
20
(address %operator)
21
(nat %token_id)))
22
(pair %remove_operator (address %owner)
23
(pair
24
(address %operator)
25
(nat %token_id))))))
26
(pair
27
(pair
28
(pair
29
(pair
30
(pair (address %baker_validator)
31
(option %current_candidate key_hash))
32
(pair (option %current_delegated key_hash)
33
(timestamp %last_update_time)))
34
(pair
35
(pair (timestamp %last_veto)
36
(big_map %ledger address
37
(pair
38
(pair (set %allowances address)
39
(nat %balance))
40
(nat %frozen_balance))))
41
(pair (timestamp %period_finish) (nat %reward))))
42
(pair
43
(pair (pair (nat %reward_paid) (nat %reward_per_sec))
44
(pair (nat %reward_per_share) (nat %tez_pool)))
45
(pair (pair (address %token_address) (nat %token_id))
46
(pair (nat %token_pool) (nat %total_reward)))))
47
(pair
48
(pair (pair (nat %total_supply) (nat %total_votes))
49
(pair
50
(big_map %user_rewards address
51
(pair (nat %reward)
52
(nat %reward_paid)))
53
(nat %veto)))
54
(pair
55
(pair (big_map %vetos key_hash timestamp)
56
(big_map %voters address
57
(pair
58
(pair (option %candidate key_hash)
59
(timestamp %last_veto))
60
(pair (nat %veto) (nat %vote)))))
61
(big_map %votes key_hash nat)))))
62
address)
63
(pair (list operation)
64
(pair
65
(pair
66
(pair
67
(pair
68
(pair (address %baker_validator)
69
(option %current_candidate key_hash))
70
(pair (option %current_delegated key_hash)
71
(timestamp %last_update_time)))
72
(pair
73
(pair (timestamp %last_veto)
74
(big_map %ledger address
75
(pair
76
(pair (set %allowances address)
77
(nat %balance))
78
(nat %frozen_balance))))
79
(pair (timestamp %period_finish) (nat %reward))))
80
(pair
81
(pair (pair (nat %reward_paid) (nat %reward_per_sec))
82
(pair (nat %reward_per_share) (nat %tez_pool)))
83
(pair (pair (address %token_address) (nat %token_id))
84
(pair (nat %token_pool) (nat %total_reward)))))
85
(pair
86
(pair (pair (nat %total_supply) (nat %total_votes))
87
(pair
88
(big_map %user_rewards address
89
(pair (nat %reward)
90
(nat %reward_paid)))
91
(nat %veto)))
92
(pair
93
(pair (big_map %vetos key_hash timestamp)
94
(big_map %voters address
95
(pair
96
(pair (option %candidate key_hash)
97
(timestamp %last_veto))
98
(pair (nat %veto) (nat %vote)))))
99
(big_map %votes key_hash nat))))))
100
(nat %index))
Copied!
Sets the FA2 function. Should be used before the whole system is launched. Fails if the function was set before or the index exceeds the number of Dex functions minus one(3).
Parameter
Type
Description
index
nat
The key in functions map
func
lambda
Function code
Each index is designed for a specific func which functionality in described in TZIP-7:
1
%transfer -> 0n
2
%approve -> 1n
3
%balance_of -> 2n
Copied!

launchExchange(token, token_amount)

1
(pair %launchExchange (pair %token address nat) (nat %token_amount))
Copied!
Deploys a new empty Dex for token, stores the address of the new contract, and puts initial liquidity; has to be called with XTZ amount that will be used as initial liquidity. The token_amount of token should be allowed to be spent by Factory. Initial liquidity can't be zero.
Parameter
Type
Description
token
(address, nat)
Address and the token id of the paired token
token_amount
nat
Amount of tokens that will be withdrawn from the user account and used as initial liquidity.
tez_amount
tez
Attached XTZ for initial liquidity should be sent along with the launch transaction.

Interface

1
parameter (or
2
(or (pair %launchExchange (pair %token address nat) (nat %token_amount))
3
(pair %setDexFunction
4
(lambda %func
5
(pair
6
(pair
7
(or
8
(or
9
(or
10
(pair %divestLiquidity
11
(pair (nat %min_tez) (nat %min_tokens))
12
(nat %shares))
13
(nat %initializeExchange))
14
(or (nat %investLiquidity)
15
(pair %tezToTokenPayment (nat %min_out)
16
(address %receiver))))
17
(or
18
(or
19
(pair %tokenToTezPayment
20
(pair (nat %amount) (nat %min_out))
21
(address %receiver))
22
(pair %veto (nat %value) (address %voter)))
23
(or
24
(pair %vote (pair (key_hash %candidate) (nat %value))
25
(address %voter))
26
(address %withdrawProfit))))
27
(pair
28
(pair
29
(pair
30
(pair
31
(pair (address %baker_validator)
32
(option %current_candidate key_hash))
33
(pair (option %current_delegated key_hash)
34
(timestamp %last_update_time)))
35
(pair
36
(pair (timestamp %last_veto)
37
(big_map %ledger address
38
(pair
39
(pair (set %allowances address)
40
(nat %balance))
41
(nat %frozen_balance))))
42
(pair (timestamp %period_finish) (nat %reward))))
43
(pair
44
(pair (pair (nat %reward_paid) (nat %reward_per_sec))
45
(pair (nat %reward_per_share) (nat %tez_pool)))
46
(pair (pair (address %token_address) (nat %token_id))
47
(pair (nat %token_pool) (nat %total_reward)))))
48
(pair
49
(pair (pair (nat %total_supply) (nat %total_votes))
50
(pair
51
(big_map %user_rewards address
52
(pair (nat %reward)
53
(nat %reward_paid)))
54
(nat %veto)))
55
(pair
56
(pair (big_map %vetos key_hash timestamp)
57
(big_map %voters address
58
(pair
59
(pair
60
(option %candidate key_hash)
61
(timestamp %last_veto))
62
(pair (nat %veto) (nat %vote)))))
63
(big_map %votes key_hash nat)))))
64
address)
65
(pair (list operation)
66
(pair
67
(pair
68
(pair
69
(pair
70
(pair (address %baker_validator)
71
(option %current_candidate key_hash))
72
(pair (option %current_delegated key_hash)
73
(timestamp %last_update_time)))
74
(pair
75
(pair (timestamp %last_veto)
76
(big_map %ledger address
77
(pair
78
(pair
79
(set %allowances address)
80
(nat %balance))
81
(nat %frozen_balance))))
82
(pair (timestamp %period_finish) (nat %reward))))
83
(pair
84
(pair (pair (nat %reward_paid) (nat %reward_per_sec))
85
(pair (nat %reward_per_share) (nat %tez_pool)))
86
(pair (pair (address %token_address) (nat %token_id))
87
(pair (nat %token_pool) (nat %total_reward)))))
88
(pair
89
(pair (pair (nat %total_supply) (nat %total_votes))
90
(pair
91
(big_map %user_rewards address
92
(pair (nat %reward)
93
(nat %reward_paid)))
94
(nat %veto)))
95
(pair
96
(pair (big_map %vetos key_hash timestamp)
97
(big_map %voters address
98
(pair
99
(pair
100
(option %candidate key_hash)
101
(timestamp %last_veto))
102
(pair (nat %veto) (nat %vote)))))
103
(big_map %votes key_hash nat))))))
104
(nat %index)))
105
(pair %setTokenFunction
106
(lambda %func
107
(pair
108
(pair
109
(or
110
(or
111
(pair %iBalance_of
112
(list %requests (pair (address %owner) (nat %token_id)))
113
(contract %callback (list (pair
114
(pair %request (address %owner)
115
(nat %token_id))
116
(nat %balance)))))
117
(list %iTransfer (pair (address %from_)
118
(list %txs (pair (address %to_)
119
(pair (nat %token_id)
120
(nat %amount)))))))
121
(list %iUpdate_operators (or
122
(pair %add_operator (address %owner)
123
(pair
124
(address %operator)
125
(nat %token_id)))
126
(pair %remove_operator (address %owner)
127
(pair
128
(address %operator)
129
(nat %token_id))))))
130
(pair
131
(pair
132
(pair
133
(pair
134
(pair (address %baker_validator)
135
(option %current_candidate key_hash))
136
(pair (option %current_delegated key_hash)
137
(timestamp %last_update_time)))
138
(pair
139
(pair (timestamp %last_veto)
140
(big_map %ledger address
141
(pair
142
(pair (set %allowances address)
143
(nat %balance))
144
(nat %frozen_balance))))
145
(pair (timestamp %period_finish) (nat %reward))))
146
(pair
147
(pair (pair (nat %reward_paid) (nat %reward_per_sec))
148
(pair (nat %reward_per_share) (nat %tez_pool)))
149
(pair (pair (address %token_address) (nat %token_id))
150
(pair (nat %token_pool) (nat %total_reward)))))
151
(pair
152
(pair (pair (nat %total_supply) (nat %total_votes))
153
(pair
154
(big_map %user_rewards address
155
(pair (nat %reward)
156
(nat %reward_paid)))
157
(nat %veto)))
158
(pair
159
(pair (big_map %vetos key_hash timestamp)
160
(big_map %voters address
161
(pair
162
(pair (option %candidate key_hash)
163
(timestamp %last_veto))
164
(pair (nat %veto) (nat %vote)))))
165
(big_map %votes key_hash nat)))))
166
address)
167
(pair (list operation)
168
(pair
169
(pair
170
(pair
171
(pair
172
(pair (address %baker_validator)
173
(option %current_candidate key_hash))
174
(pair (option %current_delegated key_hash)
175
(timestamp %last_update_time)))
176
(pair
177
(pair (timestamp %last_veto)
178
(big_map %ledger address
179
(pair
180
(pair (set %allowances address)
181
(nat %balance))
182
(nat %frozen_balance))))
183
(pair (timestamp %period_finish) (nat %reward))))
184
(pair
185
(pair (pair (nat %reward_paid) (nat %reward_per_sec))
186
(pair (nat %reward_per_share) (nat %tez_pool)))
187
(pair (pair (address %token_address) (nat %token_id))
188
(pair (nat %token_pool) (nat %total_reward)))))
189
(pair
190
(pair (pair (nat %total_supply) (nat %total_votes))
191
(pair
192
(big_map %user_rewards address
193
(pair (nat %reward)
194
(nat %reward_paid)))
195
(nat %veto)))
196
(pair
197
(pair (big_map %vetos key_hash timestamp)
198
(big_map %voters address
199
(pair
200
(pair (option %candidate key_hash)
201
(timestamp %last_veto))
202
(pair (nat %veto) (nat %vote)))))
203
(big_map %votes key_hash nat))))))
204
(nat %index)));
Copied!
Last modified 6mo ago