1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let separator = "__" |
---|
5 | 5 | | |
---|
6 | 6 | | let poolWeightMult = 100000000 |
---|
7 | 7 | | |
---|
8 | 8 | | let maxDepthDefault = 10 |
---|
9 | 9 | | |
---|
10 | 10 | | let finalizationStageTotal = 0 |
---|
11 | 11 | | |
---|
12 | 12 | | let finalizationStageShares = 1 |
---|
13 | 13 | | |
---|
14 | 14 | | let keyEpochLength = makeString(["%s", "epochLength"], separator) |
---|
15 | 15 | | |
---|
16 | 16 | | let keyEpochLengthNew = makeString(["%s%s", "epochLength__new"], separator) |
---|
17 | 17 | | |
---|
18 | 18 | | func keyEpochLengthByEpoch (epoch) = makeString(["%s%d", "epochLength", toString(epoch)], separator) |
---|
19 | 19 | | |
---|
20 | 20 | | |
---|
21 | 21 | | let keyCurrentEpoch = makeString(["%s", "currentEpoch"], separator) |
---|
22 | 22 | | |
---|
23 | 23 | | let keyMaxDepth = makeString(["%s", "maxDepth"], separator) |
---|
24 | 24 | | |
---|
25 | 25 | | let keyVotingEmissionCandidateContract = makeString(["%s", "votingEmissionCandidateContract"], separator) |
---|
26 | 26 | | |
---|
27 | 27 | | let keyVotingEmissionRateContract = makeString(["%s", "votingEmissionRateContract"], separator) |
---|
28 | 28 | | |
---|
29 | 29 | | let keyFactoryContract = makeString(["%s", "factoryContract"], separator) |
---|
30 | 30 | | |
---|
31 | 31 | | let keyBoostingContract = makeString(["%s", "boostingContract"], separator) |
---|
32 | 32 | | |
---|
33 | 33 | | let keyStakingContract = makeString(["%s", "stakingContract"], separator) |
---|
34 | 34 | | |
---|
35 | 35 | | let keyFinalizationStage = makeString(["%s", "finalizationStage"], separator) |
---|
36 | 36 | | |
---|
37 | 37 | | let keyNextPool = makeString(["%s", "nextPool"], separator) |
---|
38 | 38 | | |
---|
39 | 39 | | let keyNextUser = makeString(["%s", "nextUser"], separator) |
---|
40 | 40 | | |
---|
41 | 41 | | let keyStartHeight = makeString(["%s", "startHeight"], separator) |
---|
42 | 42 | | |
---|
43 | 43 | | let keyCurrentEpochUi = makeString(["%s", "currentEpochUi"], separator) |
---|
44 | 44 | | |
---|
45 | 45 | | let keyStartHeightUi = makeString(["%s", "startHeightUi"], separator) |
---|
46 | 46 | | |
---|
47 | 47 | | let keyFinalizationShouldBeForced = makeString(["%s", "force"], separator) |
---|
48 | 48 | | |
---|
49 | 49 | | func keyStartHeightByEpoch (epoch) = makeString(["%s%d", "startHeight", toString(epoch)], separator) |
---|
50 | 50 | | |
---|
51 | 51 | | |
---|
52 | 52 | | func keyFinalized (epoch) = makeString(["%s%d", "finalized", toString(epoch)], separator) |
---|
53 | 53 | | |
---|
54 | 54 | | |
---|
55 | 55 | | func keyInList (pool) = { |
---|
56 | 56 | | let $t017881828 = pool |
---|
57 | 57 | | let amountAssetId = $t017881828._1 |
---|
58 | 58 | | let priceAssetId = $t017881828._2 |
---|
59 | 59 | | makeString(["%s%s%s", "inList", amountAssetId, priceAssetId], separator) |
---|
60 | 60 | | } |
---|
61 | 61 | | |
---|
62 | 62 | | |
---|
63 | 63 | | func keyUsed (address,epoch) = makeString(["%s%s%d", "used", toString(address), toString(epoch)], separator) |
---|
64 | 64 | | |
---|
65 | 65 | | |
---|
66 | 66 | | func keyVote (pool,address,epoch) = { |
---|
67 | 67 | | let $t021022142 = pool |
---|
68 | 68 | | let amountAssetId = $t021022142._1 |
---|
69 | 69 | | let priceAssetId = $t021022142._2 |
---|
70 | 70 | | makeString(["%s%s%s%s%d", "vote", amountAssetId, priceAssetId, toString(address), toString(epoch)], separator) |
---|
71 | 71 | | } |
---|
72 | 72 | | |
---|
73 | 73 | | |
---|
74 | 74 | | func keyVotingResult (pool,epoch) = { |
---|
75 | 75 | | let $t023242364 = pool |
---|
76 | 76 | | let amountAssetId = $t023242364._1 |
---|
77 | 77 | | let priceAssetId = $t023242364._2 |
---|
78 | 78 | | makeString(["%s%s%s%d", "votingResult", amountAssetId, priceAssetId, toString(epoch)], separator) |
---|
79 | 79 | | } |
---|
80 | 80 | | |
---|
81 | 81 | | |
---|
82 | 82 | | func keyVotingResultStaked (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStaked", lpAssetIdStr, toString(epoch)], separator) |
---|
83 | 83 | | |
---|
84 | 84 | | |
---|
85 | 85 | | func keyPoolShare (pool,epoch) = { |
---|
86 | 86 | | let $t026852725 = pool |
---|
87 | 87 | | let amountAssetId = $t026852725._1 |
---|
88 | 88 | | let priceAssetId = $t026852725._2 |
---|
89 | 89 | | makeString(["%s%s%s%d", "poolShare", amountAssetId, priceAssetId, toString(epoch)], separator) |
---|
90 | 90 | | } |
---|
91 | 91 | | |
---|
92 | 92 | | |
---|
93 | 93 | | func keyTotalVotes (epoch) = makeString(["%s%d", "totalVotes", toString(epoch)], separator) |
---|
94 | 94 | | |
---|
95 | 95 | | |
---|
96 | 96 | | func keyStakedByUser (lpAssetIdStr,userAddressStr) = makeString(["%s%s%s", "staked", userAddressStr, lpAssetIdStr], separator) |
---|
97 | 97 | | |
---|
98 | 98 | | |
---|
99 | 99 | | func wrapErr (msg) = makeString(["voting_emission.ride:", msg], " ") |
---|
100 | 100 | | |
---|
101 | 101 | | |
---|
102 | 102 | | func throwErr (msg) = throw(wrapErr(msg)) |
---|
103 | 103 | | |
---|
104 | 104 | | |
---|
105 | 105 | | func getValueOrFail (address,key,type) = { |
---|
106 | 106 | | let error = wrapErr(makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) |
---|
107 | 107 | | valueOrErrorMessage( match type { |
---|
108 | 108 | | case str: String => |
---|
109 | 109 | | getString(address, key) |
---|
110 | 110 | | case int: Int => |
---|
111 | 111 | | getInteger(address, key) |
---|
112 | 112 | | case _ => |
---|
113 | 113 | | throwErr("invalid entry type") |
---|
114 | 114 | | }, error) |
---|
115 | 115 | | } |
---|
116 | 116 | | |
---|
117 | 117 | | |
---|
118 | 118 | | func getStrOrFail (address,key) = { |
---|
119 | 119 | | let @ = getValueOrFail(address, key, "") |
---|
120 | 120 | | if ($isInstanceOf(@, "String")) |
---|
121 | 121 | | then @ |
---|
122 | 122 | | else throw(($getType(@) + " couldn't be cast to String")) |
---|
123 | 123 | | } |
---|
124 | 124 | | |
---|
125 | 125 | | |
---|
126 | 126 | | func getIntOrFail (address,key) = { |
---|
127 | 127 | | let @ = getValueOrFail(address, key, 0) |
---|
128 | 128 | | if ($isInstanceOf(@, "Int")) |
---|
129 | 129 | | then @ |
---|
130 | 130 | | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
131 | 131 | | } |
---|
132 | 132 | | |
---|
133 | 133 | | |
---|
134 | 134 | | func poolToString (pool) = ((pool._1 + separator) + pool._2) |
---|
135 | 135 | | |
---|
136 | 136 | | |
---|
137 | 137 | | func stringToPool (str) = { |
---|
138 | 138 | | let parts = split(str, separator) |
---|
139 | 139 | | if ((size(parts) == 2)) |
---|
140 | 140 | | then $Tuple2(parts[0], parts[1]) |
---|
141 | 141 | | else throwErr("invalid pool string") |
---|
142 | 142 | | } |
---|
143 | 143 | | |
---|
144 | 144 | | |
---|
145 | 145 | | let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract)) |
---|
146 | 146 | | |
---|
147 | 147 | | let IdxFactoryCfgGwxRewardDapp = 10 |
---|
148 | 148 | | |
---|
149 | 149 | | func keyFactoryCfg () = "%s__factoryConfig" |
---|
150 | 150 | | |
---|
151 | 151 | | |
---|
152 | 152 | | func readFactoryCfgOrFail (factory) = split(getStrOrFail(factory, keyFactoryCfg()), separator) |
---|
153 | 153 | | |
---|
154 | 154 | | |
---|
155 | 155 | | func getGwxRewardAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgGwxRewardDapp]) |
---|
156 | 156 | | |
---|
157 | 157 | | |
---|
158 | 158 | | func getLpAssetByPoolAssets (amountAssetId,priceAssetId) = { |
---|
159 | 159 | | func keyMappingsBaseAsset2internalId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr) |
---|
160 | 160 | | |
---|
161 | 161 | | func keyMappingPoolAssetsToPoolContractAddress (internalAmountAssetIdStr,internalPriceAssetIdStr) = (((("%d%d%s%s__" + toString(internalAmountAssetIdStr)) + "__") + toString(internalPriceAssetIdStr)) + "__mappings__poolAssets2PoolContract") |
---|
162 | 162 | | |
---|
163 | 163 | | func keyMappingPoolContractToLPAsset (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset") |
---|
164 | 164 | | |
---|
165 | 165 | | let amountAssetInternalId = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amountAssetId)) |
---|
166 | 166 | | let priceAssetInternalId = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAssetId)) |
---|
167 | 167 | | let poolContractAddress = getStrOrFail(factoryContract, keyMappingPoolAssetsToPoolContractAddress(amountAssetInternalId, priceAssetInternalId)) |
---|
168 | 168 | | let lpAssetId = getStrOrFail(factoryContract, keyMappingPoolContractToLPAsset(poolContractAddress)) |
---|
169 | 169 | | lpAssetId |
---|
170 | 170 | | } |
---|
171 | 171 | | |
---|
172 | 172 | | |
---|
173 | 173 | | func checkWxEmissionPoolLabel (pool) = { |
---|
174 | 174 | | let $t055655605 = pool |
---|
175 | 175 | | let amountAssetId = $t055655605._1 |
---|
176 | 176 | | let priceAssetId = $t055655605._2 |
---|
177 | 177 | | let @ = invoke(factoryContract, "checkWxEmissionPoolLabel", [amountAssetId, priceAssetId], nil) |
---|
178 | 178 | | if ($isInstanceOf(@, "Boolean")) |
---|
179 | 179 | | then @ |
---|
180 | 180 | | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
181 | 181 | | } |
---|
182 | 182 | | |
---|
183 | 183 | | |
---|
184 | 184 | | func gwxRewardDeposit () = { |
---|
185 | 185 | | let factoryCfg = readFactoryCfgOrFail(factoryContract) |
---|
186 | 186 | | let gwxRewardsContract = getGwxRewardAddressOrFail(factoryCfg) |
---|
187 | 187 | | invoke(gwxRewardsContract, "deposit", nil, nil) |
---|
188 | 188 | | } |
---|
189 | 189 | | |
---|
190 | 190 | | |
---|
191 | 191 | | let poolsListName = "pools" |
---|
192 | 192 | | |
---|
193 | 193 | | func getVotesListName (pool) = { |
---|
194 | 194 | | let $t060226062 = pool |
---|
195 | 195 | | let amountAssetId = $t060226062._1 |
---|
196 | 196 | | let priceAssetId = $t060226062._2 |
---|
197 | 197 | | makeString(["votes", amountAssetId, priceAssetId], separator) |
---|
198 | 198 | | } |
---|
199 | 199 | | |
---|
200 | 200 | | |
---|
201 | 201 | | func keyListHead (listName) = { |
---|
202 | 202 | | let meta = if ((listName == poolsListName)) |
---|
203 | 203 | | then "%s%s" |
---|
204 | 204 | | else "%s%s%s%s" |
---|
205 | 205 | | makeString([meta, listName, "head"], separator) |
---|
206 | 206 | | } |
---|
207 | 207 | | |
---|
208 | 208 | | |
---|
209 | 209 | | func keyListSize (listName) = { |
---|
210 | 210 | | let meta = if ((listName == poolsListName)) |
---|
211 | 211 | | then "%s%s" |
---|
212 | 212 | | else "%s%s%s%s" |
---|
213 | 213 | | makeString([meta, listName, "size"], separator) |
---|
214 | 214 | | } |
---|
215 | 215 | | |
---|
216 | 216 | | |
---|
217 | 217 | | func keyListPrev (listName,id) = { |
---|
218 | 218 | | let meta = if ((listName == poolsListName)) |
---|
219 | 219 | | then "%s%s%s%s" |
---|
220 | 220 | | else "%s%s%s%s%s" |
---|
221 | 221 | | makeString([meta, listName, id, "prev"], separator) |
---|
222 | 222 | | } |
---|
223 | 223 | | |
---|
224 | 224 | | |
---|
225 | 225 | | func keyListNext (listName,id) = { |
---|
226 | 226 | | let meta = if ((listName == poolsListName)) |
---|
227 | 227 | | then "%s%s%s%s" |
---|
228 | 228 | | else "%s%s%s%s%s" |
---|
229 | 229 | | makeString([meta, listName, id, "next"], separator) |
---|
230 | 230 | | } |
---|
231 | 231 | | |
---|
232 | 232 | | |
---|
233 | 233 | | func containsNode (listName,id) = { |
---|
234 | 234 | | let headOrUnit = getString(this, keyListHead(listName)) |
---|
235 | 235 | | let prevOrUnit = getString(this, keyListPrev(listName, id)) |
---|
236 | 236 | | let nextOrUnit = getString(this, keyListNext(listName, id)) |
---|
237 | 237 | | if (if ((id == valueOrElse(headOrUnit, ""))) |
---|
238 | 238 | | then true |
---|
239 | 239 | | else (prevOrUnit != unit)) |
---|
240 | 240 | | then true |
---|
241 | 241 | | else (nextOrUnit != unit) |
---|
242 | 242 | | } |
---|
243 | 243 | | |
---|
244 | 244 | | |
---|
245 | 245 | | func insertNodeActions (listName,id) = { |
---|
246 | 246 | | let headOrUnit = getString(this, keyListHead(listName)) |
---|
247 | 247 | | let listSize = valueOrElse(getInteger(this, keyListSize(listName)), 0) |
---|
248 | 248 | | let checkNode = if (!(containsNode(listName, id))) |
---|
249 | 249 | | then true |
---|
250 | 250 | | else throwErr("Node exists") |
---|
251 | 251 | | if ((checkNode == checkNode)) |
---|
252 | 252 | | then (([IntegerEntry(keyListSize(listName), (listSize + 1))] ++ (if ((headOrUnit != unit)) |
---|
253 | 253 | | then [StringEntry(keyListNext(listName, id), value(headOrUnit)), StringEntry(keyListPrev(listName, value(headOrUnit)), id)] |
---|
254 | 254 | | else nil)) ++ [StringEntry(keyListHead(listName), id)]) |
---|
255 | 255 | | else throw("Strict value is not equal to itself.") |
---|
256 | 256 | | } |
---|
257 | 257 | | |
---|
258 | 258 | | |
---|
259 | 259 | | func deleteNodeActions (listName,id) = { |
---|
260 | 260 | | let headOrUnit = getString(this, keyListHead(listName)) |
---|
261 | 261 | | let listSize = valueOrElse(getInteger(this, keyListSize(listName)), 0) |
---|
262 | 262 | | let prevOrUnit = getString(this, keyListPrev(listName, id)) |
---|
263 | 263 | | let nextOrUnit = getString(this, keyListNext(listName, id)) |
---|
264 | 264 | | ([IntegerEntry(keyListSize(listName), (listSize - 1))] ++ (if (if ((prevOrUnit != unit)) |
---|
265 | 265 | | then (nextOrUnit != unit) |
---|
266 | 266 | | else false) |
---|
267 | 267 | | then [StringEntry(keyListNext(listName, value(prevOrUnit)), value(nextOrUnit)), StringEntry(keyListPrev(listName, value(nextOrUnit)), value(prevOrUnit)), DeleteEntry(keyListPrev(listName, id)), DeleteEntry(keyListNext(listName, id))] |
---|
268 | 268 | | else if ((nextOrUnit != unit)) |
---|
269 | 269 | | then [StringEntry(keyListHead(listName), value(nextOrUnit)), DeleteEntry(keyListNext(listName, id)), DeleteEntry(keyListPrev(listName, value(nextOrUnit)))] |
---|
270 | 270 | | else if ((prevOrUnit != unit)) |
---|
271 | 271 | | then [DeleteEntry(keyListPrev(listName, id)), DeleteEntry(keyListNext(listName, value(prevOrUnit)))] |
---|
272 | 272 | | else if ((id == valueOrElse(headOrUnit, ""))) |
---|
273 | 273 | | then [DeleteEntry(keyListHead(listName))] |
---|
274 | 274 | | else throwErr(((("invalid node: " + listName) + ".") + id)))) |
---|
275 | 275 | | } |
---|
276 | 276 | | |
---|
277 | 277 | | |
---|
278 | 278 | | func keyManagerVaultAddress () = "%s__managerVaultAddress" |
---|
279 | 279 | | |
---|
280 | 280 | | |
---|
281 | 281 | | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
282 | 282 | | |
---|
283 | 283 | | |
---|
284 | 284 | | func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) { |
---|
285 | 285 | | case s: String => |
---|
286 | 286 | | addressFromStringValue(s) |
---|
287 | 287 | | case _ => |
---|
288 | 288 | | this |
---|
289 | 289 | | } |
---|
290 | 290 | | |
---|
291 | 291 | | |
---|
292 | 292 | | func managerPublicKeyOrUnit () = { |
---|
293 | 293 | | let managerVaultAddress = getManagerVaultAddressOrThis() |
---|
294 | 294 | | match getString(managerVaultAddress, keyManagerPublicKey()) { |
---|
295 | 295 | | case s: String => |
---|
296 | 296 | | fromBase58String(s) |
---|
297 | 297 | | case _: Unit => |
---|
298 | 298 | | unit |
---|
299 | 299 | | case _ => |
---|
300 | 300 | | throw("Match error") |
---|
301 | 301 | | } |
---|
302 | 302 | | } |
---|
303 | 303 | | |
---|
304 | 304 | | |
---|
305 | 305 | | func isManager (i) = match managerPublicKeyOrUnit() { |
---|
306 | 306 | | case pk: ByteVector => |
---|
307 | 307 | | (i.callerPublicKey == pk) |
---|
308 | 308 | | case _: Unit => |
---|
309 | 309 | | (i.caller == this) |
---|
310 | 310 | | case _ => |
---|
311 | 311 | | throw("Match error") |
---|
312 | 312 | | } |
---|
313 | 313 | | |
---|
314 | 314 | | |
---|
315 | 315 | | func mustManager (i) = if (isManager(i)) |
---|
316 | 316 | | then true |
---|
317 | 317 | | else throw("permission denied") |
---|
318 | 318 | | |
---|
319 | 319 | | |
---|
320 | 320 | | func mustThis (i) = if ((i.caller == this)) |
---|
321 | 321 | | then true |
---|
322 | 322 | | else throw("permission denied") |
---|
323 | 323 | | |
---|
324 | 324 | | |
---|
325 | 325 | | @Callable(i) |
---|
326 | 326 | | func getUserGwxAmountAtHeight (userAddress,targetHeight) = { |
---|
327 | 327 | | let boostingContractAddress = valueOrErrorMessage(addressFromString(getStrOrFail(this, keyBoostingContract)), wrapErr("invalid boosting contract address")) |
---|
328 | 328 | | $Tuple2(nil, { |
---|
329 | 329 | | let @ = invoke(boostingContractAddress, "getUserGwxAmountAtHeightREADONLY", [userAddress, targetHeight], nil) |
---|
330 | 330 | | if ($isInstanceOf(@, "Int")) |
---|
331 | 331 | | then @ |
---|
332 | 332 | | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
333 | 333 | | }) |
---|
334 | 334 | | } |
---|
335 | 335 | | |
---|
336 | 336 | | |
---|
337 | 337 | | |
---|
338 | 338 | | @Callable(i) |
---|
339 | 339 | | func constructor (factoryContract,votingEmissionCandidateContract,boostingContract,stakingContract,epochLength) = { |
---|
340 | 340 | | let checks = [mustManager(i), if ((addressFromString(factoryContract) != unit)) |
---|
341 | 341 | | then true |
---|
342 | 342 | | else "invalid factory contract address", if ((addressFromString(votingEmissionCandidateContract) != unit)) |
---|
343 | 343 | | then true |
---|
344 | 344 | | else "invalid voting emission candidate contract address", if ((addressFromString(boostingContract) != unit)) |
---|
345 | 345 | | then true |
---|
346 | 346 | | else "invalid boosting contract address", if ((addressFromString(stakingContract) != unit)) |
---|
347 | 347 | | then true |
---|
348 | 348 | | else "invalid staking contract address", if ((epochLength > 0)) |
---|
349 | 349 | | then true |
---|
350 | 350 | | else throwErr("invalid epoch length")] |
---|
351 | 351 | | if ((checks == checks)) |
---|
352 | 352 | | then $Tuple2([StringEntry(keyFactoryContract, factoryContract), StringEntry(keyVotingEmissionCandidateContract, votingEmissionCandidateContract), StringEntry(keyBoostingContract, boostingContract), StringEntry(keyStakingContract, stakingContract), IntegerEntry(keyEpochLength, epochLength)], unit) |
---|
353 | 353 | | else throw("Strict value is not equal to itself.") |
---|
354 | 354 | | } |
---|
355 | 355 | | |
---|
356 | 356 | | |
---|
357 | 357 | | |
---|
358 | 358 | | @Callable(i) |
---|
359 | 359 | | func create (amountAssetId,priceAssetId) = { |
---|
360 | 360 | | let checks = [if ((toBase58String(i.caller.bytes) == valueOrElse(getString(this, keyVotingEmissionCandidateContract), ""))) |
---|
361 | 361 | | then true |
---|
362 | 362 | | else mustManager(i)] |
---|
363 | 363 | | if ((checks == checks)) |
---|
364 | 364 | | then { |
---|
365 | 365 | | let pool = $Tuple2(amountAssetId, priceAssetId) |
---|
366 | 366 | | let inListActions = ([BooleanEntry(keyInList(pool), true)] ++ insertNodeActions(poolsListName, poolToString(pool))) |
---|
367 | 367 | | let currentEpochIsNotDefined = (getInteger(this, keyCurrentEpoch) == unit) |
---|
368 | 368 | | let startHeightActions = if (currentEpochIsNotDefined) |
---|
369 | 369 | | then { |
---|
370 | 370 | | let epoch = 0 |
---|
371 | 371 | | [IntegerEntry(keyCurrentEpoch, epoch), IntegerEntry(keyStartHeightByEpoch(epoch), height), IntegerEntry(keyStartHeight, height), IntegerEntry(keyCurrentEpochUi, epoch), IntegerEntry(keyStartHeightUi, height)] |
---|
372 | 372 | | } |
---|
373 | 373 | | else nil |
---|
374 | 374 | | $Tuple2((inListActions ++ startHeightActions), unit) |
---|
375 | 375 | | } |
---|
376 | 376 | | else throw("Strict value is not equal to itself.") |
---|
377 | 377 | | } |
---|
378 | 378 | | |
---|
379 | 379 | | |
---|
380 | 380 | | |
---|
381 | 381 | | @Callable(i) |
---|
382 | 382 | | func vote (amountAssetId,priceAssetId,amount) = { |
---|
383 | 383 | | let pool = $Tuple2(amountAssetId, priceAssetId) |
---|
384 | 384 | | let epoch = valueOrElse(getInteger(this, keyCurrentEpoch), 0) |
---|
385 | 385 | | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
386 | 386 | | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
387 | 387 | | let endHeight = (startHeight + epochLength) |
---|
388 | 388 | | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
389 | 389 | | let used = valueOrElse(getInteger(this, keyUsed(i.caller, epoch)), 0) |
---|
390 | 390 | | let vote = valueOrElse(getInteger(this, keyVote(pool, i.caller, epoch)), 0) |
---|
391 | 391 | | let poolResult = valueOrElse(getInteger(this, keyVotingResult(pool, epoch)), 0) |
---|
392 | 392 | | let totalVotes = valueOrElse(getInteger(this, keyTotalVotes(epoch)), 0) |
---|
393 | 393 | | let gwxAmountAtEndTotal = { |
---|
394 | 394 | | let @ = invoke(this, "getUserGwxAmountAtHeight", [toBase58String(i.caller.bytes), endHeight], nil) |
---|
395 | 395 | | if ($isInstanceOf(@, "Int")) |
---|
396 | 396 | | then @ |
---|
397 | 397 | | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
398 | 398 | | } |
---|
399 | 399 | | let available = (gwxAmountAtEndTotal - used) |
---|
400 | 400 | | let newVote = (vote + amount) |
---|
401 | 401 | | let wxEmission = checkWxEmissionPoolLabel(pool) |
---|
402 | 402 | | let checks = [if ((getBoolean(keyInList(pool)) != unit)) |
---|
403 | 403 | | then true |
---|
404 | 404 | | else throwErr("invalid assets"), if ((endHeight > height)) |
---|
405 | 405 | | then true |
---|
406 | 406 | | else throwErr("invalid height"), if ((finalizationStageOrUnit == unit)) |
---|
407 | 407 | | then true |
---|
408 | 408 | | else throwErr("finalization in progress"), if ((gwxAmountAtEndTotal > 0)) |
---|
409 | 409 | | then true |
---|
410 | 410 | | else throwErr("you do not have gWX"), if (if ((amount > 0)) |
---|
411 | 411 | | then (available >= amount) |
---|
412 | 412 | | else false) |
---|
413 | 413 | | then true |
---|
414 | 414 | | else throwErr("invalid amount"), if (wxEmission) |
---|
415 | 415 | | then true |
---|
416 | 416 | | else throwErr("pool hasn't WX_EMISSION label")] |
---|
417 | 417 | | if ((checks == checks)) |
---|
418 | 418 | | then { |
---|
419 | 419 | | let votesListName = getVotesListName(pool) |
---|
420 | 420 | | let userAddressStr = toString(i.caller) |
---|
421 | 421 | | let votesListActions = if (containsNode(votesListName, userAddressStr)) |
---|
422 | 422 | | then nil |
---|
423 | 423 | | else insertNodeActions(votesListName, userAddressStr) |
---|
424 | 424 | | $Tuple2(([IntegerEntry(keyUsed(i.caller, epoch), (used + amount)), IntegerEntry(keyVote(pool, i.caller, epoch), newVote), IntegerEntry(keyVotingResult(pool, epoch), (poolResult + amount)), IntegerEntry(keyTotalVotes(epoch), (totalVotes + amount))] ++ votesListActions), unit) |
---|
425 | 425 | | } |
---|
426 | 426 | | else throw("Strict value is not equal to itself.") |
---|
427 | 427 | | } |
---|
428 | 428 | | |
---|
429 | 429 | | |
---|
430 | 430 | | |
---|
431 | 431 | | @Callable(i) |
---|
432 | 432 | | func cancelVote (amountAssetId,priceAssetId) = { |
---|
433 | 433 | | let pool = $Tuple2(amountAssetId, priceAssetId) |
---|
434 | 434 | | let epoch = valueOrElse(getInteger(this, keyCurrentEpoch), 0) |
---|
435 | 435 | | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
436 | 436 | | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
437 | 437 | | let endHeight = (startHeight + epochLength) |
---|
438 | 438 | | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
439 | 439 | | let used = valueOrElse(getInteger(this, keyUsed(i.caller, epoch)), 0) |
---|
440 | 440 | | let vote = valueOrElse(getInteger(this, keyVote(pool, i.caller, epoch)), 0) |
---|
441 | 441 | | let poolResult = valueOrElse(getInteger(this, keyVotingResult(pool, epoch)), 0) |
---|
442 | 442 | | let totalVotes = valueOrElse(getInteger(this, keyTotalVotes(epoch)), 0) |
---|
443 | 443 | | let checks = [if ((getBoolean(keyInList(pool)) != unit)) |
---|
444 | 444 | | then true |
---|
445 | 445 | | else throwErr("invalid assets"), if ((endHeight > height)) |
---|
446 | 446 | | then true |
---|
447 | 447 | | else throwErr("invalid height"), if ((finalizationStageOrUnit == unit)) |
---|
448 | 448 | | then true |
---|
449 | 449 | | else throwErr("finalization in progress"), if ((vote > 0)) |
---|
450 | 450 | | then true |
---|
451 | 451 | | else throwErr("no vote")] |
---|
452 | 452 | | if ((checks == checks)) |
---|
453 | 453 | | then { |
---|
454 | 454 | | let votesListName = getVotesListName(pool) |
---|
455 | 455 | | let userAddressStr = toString(i.caller) |
---|
456 | 456 | | $Tuple2(([IntegerEntry(keyUsed(i.caller, epoch), max([(used - vote), 0])), DeleteEntry(keyVote(pool, i.caller, epoch)), IntegerEntry(keyVotingResult(pool, epoch), (poolResult - vote)), IntegerEntry(keyTotalVotes(epoch), (totalVotes - vote))] ++ deleteNodeActions(votesListName, userAddressStr)), unit) |
---|
457 | 457 | | } |
---|
458 | 458 | | else throw("Strict value is not equal to itself.") |
---|
459 | 459 | | } |
---|
460 | 460 | | |
---|
461 | 461 | | |
---|
462 | 462 | | |
---|
463 | 463 | | @Callable(i) |
---|
464 | 464 | | func setEpochLength (newEpochLength) = { |
---|
465 | 465 | | let checks = [mustManager(i), if ((newEpochLength > 0)) |
---|
466 | 466 | | then true |
---|
467 | 467 | | else throwErr("invalid epoch length")] |
---|
468 | 468 | | if ((checks == checks)) |
---|
469 | 469 | | then $Tuple2([IntegerEntry(keyEpochLengthNew, newEpochLength)], unit) |
---|
470 | 470 | | else throw("Strict value is not equal to itself.") |
---|
471 | 471 | | } |
---|
472 | 472 | | |
---|
473 | 473 | | |
---|
474 | 474 | | |
---|
475 | 475 | | @Callable(i) |
---|
476 | 476 | | func setMaxDepth (newMaxDepth) = { |
---|
477 | 477 | | let checks = [mustManager(i), if ((newMaxDepth > 0)) |
---|
478 | 478 | | then true |
---|
479 | 479 | | else throwErr("invalid max depth")] |
---|
480 | 480 | | if ((checks == checks)) |
---|
481 | 481 | | then $Tuple2([IntegerEntry(keyMaxDepth, newMaxDepth)], unit) |
---|
482 | 482 | | else throw("Strict value is not equal to itself.") |
---|
483 | 483 | | } |
---|
484 | 484 | | |
---|
485 | 485 | | |
---|
486 | 486 | | |
---|
487 | 487 | | @Callable(i) |
---|
488 | 488 | | func processVoteINTERNAL (poolStr,userAddressStr) = { |
---|
489 | 489 | | let checkCaller = mustThis(i) |
---|
490 | 490 | | if ((checkCaller == checkCaller)) |
---|
491 | 491 | | then { |
---|
492 | 492 | | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr(("processVoteINTERNAL: invalid user address " + userAddressStr))) |
---|
493 | 493 | | let epoch = getIntOrFail(this, keyCurrentEpoch) |
---|
494 | 494 | | let epochPrevious = (epoch - 1) |
---|
495 | 495 | | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
496 | 496 | | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
497 | 497 | | let endHeight = (startHeight + epochLength) |
---|
498 | 498 | | let startHeightPrevious = getIntOrFail(this, keyStartHeightByEpoch(epochPrevious)) |
---|
499 | 499 | | let epochLengthPrevious = getIntOrFail(this, keyEpochLengthByEpoch(epochPrevious)) |
---|
500 | 500 | | let endHeightPrevious = (startHeightPrevious + epochLengthPrevious) |
---|
501 | 501 | | let checkTargetEpoch = if ((epochPrevious >= 0)) |
---|
502 | 502 | | then true |
---|
503 | 503 | | else throwErr("processVoteINTERNAL: invalid previous epoch") |
---|
504 | 504 | | if ((checkTargetEpoch == checkTargetEpoch)) |
---|
505 | 505 | | then { |
---|
506 | 506 | | let pool = stringToPool(poolStr) |
---|
507 | 507 | | let $t01806518105 = pool |
---|
508 | 508 | | let amountAssetId = $t01806518105._1 |
---|
509 | 509 | | let priceAssetId = $t01806518105._2 |
---|
510 | 510 | | let wxEmission = checkWxEmissionPoolLabel(pool) |
---|
511 | 511 | | let gwxAmountAtEndTotal = { |
---|
512 | 512 | | let @ = invoke(this, "getUserGwxAmountAtHeight", [userAddressStr, endHeight], nil) |
---|
513 | 513 | | if ($isInstanceOf(@, "Int")) |
---|
514 | 514 | | then @ |
---|
515 | 515 | | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
516 | 516 | | } |
---|
517 | 517 | | let gwxAmountAtEndTotalPrevious = { |
---|
518 | 518 | | let @ = invoke(this, "getUserGwxAmountAtHeight", [userAddressStr, endHeightPrevious], nil) |
---|
519 | 519 | | if ($isInstanceOf(@, "Int")) |
---|
520 | 520 | | then @ |
---|
521 | 521 | | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
522 | 522 | | } |
---|
523 | 523 | | let totalVotes = valueOrElse(getInteger(keyTotalVotes(epoch)), 0) |
---|
524 | 524 | | let votingResult = valueOrElse(getInteger(keyVotingResult(pool, epoch)), 0) |
---|
525 | 525 | | let votePrevious = valueOrErrorMessage(getInteger(keyVote(pool, userAddress, epochPrevious)), wrapErr((((("processVoteINTERNAL " + poolStr) + " ") + userAddressStr) + ": no previous vote"))) |
---|
526 | 526 | | let used = valueOrElse(getInteger(this, keyUsed(userAddress, epoch)), 0) |
---|
527 | 527 | | let lpAssetIdStr = getLpAssetByPoolAssets(amountAssetId, priceAssetId) |
---|
528 | 528 | | let votingResultStakedPrevious = valueOrElse(getInteger(keyVotingResultStaked(lpAssetIdStr, epochPrevious)), 0) |
---|
529 | 529 | | let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract)) |
---|
530 | 530 | | let stakedByUser = valueOrElse(getInteger(stakingContract, keyStakedByUser(lpAssetIdStr, userAddressStr)), 0) |
---|
531 | 531 | | let votingResultStakedActions = if ((stakedByUser == 0)) |
---|
532 | 532 | | then nil |
---|
533 | 533 | | else [IntegerEntry(keyVotingResultStaked(lpAssetIdStr, epochPrevious), (votingResultStakedPrevious + votePrevious))] |
---|
534 | 534 | | let newVote = if ((gwxAmountAtEndTotalPrevious > 0)) |
---|
535 | 535 | | then fraction(votePrevious, gwxAmountAtEndTotal, gwxAmountAtEndTotalPrevious) |
---|
536 | 536 | | else 0 |
---|
537 | 537 | | let actions = if (if ((newVote > 0)) |
---|
538 | 538 | | then wxEmission |
---|
539 | 539 | | else false) |
---|
540 | 540 | | then [IntegerEntry(keyVote(pool, userAddress, epoch), newVote), IntegerEntry(keyTotalVotes(epoch), (totalVotes + newVote)), IntegerEntry(keyVotingResult(pool, epoch), (votingResult + newVote)), IntegerEntry(keyUsed(userAddress, epoch), (used + newVote))] |
---|
541 | 541 | | else deleteNodeActions(getVotesListName(pool), userAddressStr) |
---|
542 | 542 | | $Tuple2((actions ++ votingResultStakedActions), unit) |
---|
543 | 543 | | } |
---|
544 | 544 | | else throw("Strict value is not equal to itself.") |
---|
545 | 545 | | } |
---|
546 | 546 | | else throw("Strict value is not equal to itself.") |
---|
547 | 547 | | } |
---|
548 | 548 | | |
---|
549 | 549 | | |
---|
550 | 550 | | |
---|
551 | 551 | | @Callable(i) |
---|
552 | 552 | | func processPoolINTERNAL (poolStr,force) = { |
---|
553 | 553 | | let checkCaller = mustThis(i) |
---|
554 | 554 | | if ((checkCaller == checkCaller)) |
---|
555 | 555 | | then { |
---|
556 | 556 | | let targetEpoch = { |
---|
557 | 557 | | let currentEpoch = getIntOrFail(this, keyCurrentEpoch) |
---|
558 | 558 | | if (force) |
---|
559 | 559 | | then currentEpoch |
---|
560 | 560 | | else (currentEpoch - 1) |
---|
561 | 561 | | } |
---|
562 | 562 | | let checkTargetEpoch = if ((targetEpoch >= 0)) |
---|
563 | 563 | | then true |
---|
564 | 564 | | else throwErr("processPoolINTERNAL: invalid target epoch") |
---|
565 | 565 | | if ((checkTargetEpoch == checkTargetEpoch)) |
---|
566 | 566 | | then { |
---|
567 | 567 | | let pool = stringToPool(poolStr) |
---|
568 | 568 | | let $t02046220502 = pool |
---|
569 | 569 | | let amountAssetId = $t02046220502._1 |
---|
570 | 570 | | let priceAssetId = $t02046220502._2 |
---|
571 | 571 | | let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract)) |
---|
572 | 572 | | let lpAssetId = getLpAssetByPoolAssets(amountAssetId, priceAssetId) |
---|
573 | 573 | | let r = { |
---|
574 | 574 | | let @ = invoke(stakingContract, "usersListTraversal", [lpAssetId], nil) |
---|
575 | 575 | | if ($isInstanceOf(@, "Boolean")) |
---|
576 | 576 | | then @ |
---|
577 | 577 | | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
578 | 578 | | } |
---|
579 | 579 | | if ((r == r)) |
---|
580 | 580 | | then if (r) |
---|
581 | 581 | | then $Tuple2(nil, true) |
---|
582 | 582 | | else { |
---|
583 | 583 | | let wxEmission = checkWxEmissionPoolLabel(pool) |
---|
584 | 584 | | let totalVotes = valueOrElse(getInteger(this, keyTotalVotes(targetEpoch)), 0) |
---|
585 | 585 | | let votingResult = valueOrElse(getInteger(this, keyVotingResult(pool, targetEpoch)), 0) |
---|
586 | 586 | | let share = if (if ((totalVotes == 0)) |
---|
587 | 587 | | then true |
---|
588 | 588 | | else !(wxEmission)) |
---|
589 | 589 | | then 0 |
---|
590 | 590 | | else fraction(votingResult, poolWeightMult, totalVotes) |
---|
591 | 591 | | let modifyWeightInv = invoke(factoryContract, "modifyWeight", [lpAssetId, share], nil) |
---|
592 | 592 | | if ((modifyWeightInv == modifyWeightInv)) |
---|
593 | 593 | | then { |
---|
594 | 594 | | let poolsListActions = if (if (wxEmission) |
---|
595 | 595 | | then true |
---|
596 | 596 | | else force) |
---|
597 | 597 | | then nil |
---|
598 | 598 | | else ([DeleteEntry(keyInList(pool))] ++ deleteNodeActions(poolsListName, poolStr)) |
---|
599 | 599 | | $Tuple2(([IntegerEntry(keyPoolShare(pool, targetEpoch), share)] ++ poolsListActions), false) |
---|
600 | 600 | | } |
---|
601 | 601 | | else throw("Strict value is not equal to itself.") |
---|
602 | 602 | | } |
---|
603 | 603 | | else throw("Strict value is not equal to itself.") |
---|
604 | 604 | | } |
---|
605 | 605 | | else throw("Strict value is not equal to itself.") |
---|
606 | 606 | | } |
---|
607 | 607 | | else throw("Strict value is not equal to itself.") |
---|
608 | 608 | | } |
---|
609 | 609 | | |
---|
610 | 610 | | |
---|
611 | 611 | | |
---|
612 | 612 | | @Callable(i) |
---|
613 | 613 | | func finalizeHelper () = { |
---|
614 | 614 | | let force = valueOrElse(getBoolean(keyFinalizationShouldBeForced), false) |
---|
615 | 615 | | let epoch = valueOrElse(getInteger(this, keyCurrentEpoch), 0) |
---|
616 | 616 | | let previousEpoch = (epoch - 1) |
---|
617 | 617 | | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
618 | 618 | | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
619 | 619 | | let endHeight = (startHeight + epochLength) |
---|
620 | 620 | | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
621 | 621 | | if (if (if ((height >= endHeight)) |
---|
622 | 622 | | then (finalizationStageOrUnit == unit) |
---|
623 | 623 | | else false) |
---|
624 | 624 | | then !(force) |
---|
625 | 625 | | else false) |
---|
626 | 626 | | then { |
---|
627 | 627 | | let newEpoch = (epoch + 1) |
---|
628 | 628 | | let newEpochLengthOption = getInteger(this, keyEpochLengthNew) |
---|
629 | 629 | | let newEpochLengthActions = match newEpochLengthOption { |
---|
630 | 630 | | case newEpochLength: Int => |
---|
631 | 631 | | [IntegerEntry(keyEpochLength, newEpochLength), DeleteEntry(keyEpochLengthNew)] |
---|
632 | 632 | | case _: Unit => |
---|
633 | 633 | | nil |
---|
634 | 634 | | case _ => |
---|
635 | 635 | | throw("Match error") |
---|
636 | 636 | | } |
---|
637 | 637 | | $Tuple2(([IntegerEntry(keyStartHeightByEpoch(newEpoch), height), IntegerEntry(keyStartHeight, height), IntegerEntry(keyCurrentEpoch, newEpoch), IntegerEntry(keyFinalizationStage, finalizationStageTotal), IntegerEntry(keyEpochLengthByEpoch(epoch), epochLength)] ++ newEpochLengthActions), true) |
---|
638 | 638 | | } |
---|
639 | 639 | | else if (if (force) |
---|
640 | 640 | | then (finalizationStageOrUnit == unit) |
---|
641 | 641 | | else false) |
---|
642 | 642 | | then $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares)], true) |
---|
643 | 643 | | else if ((finalizationStageOrUnit == unit)) |
---|
644 | 644 | | then $Tuple2(nil, false) |
---|
645 | 645 | | else if ((finalizationStageOrUnit == finalizationStageTotal)) |
---|
646 | 646 | | then { |
---|
647 | 647 | | let poolOrUnit = getString(keyNextPool) |
---|
648 | 648 | | let userOrUnit = getString(keyNextUser) |
---|
649 | 649 | | match poolOrUnit { |
---|
650 | 650 | | case _: Unit => |
---|
651 | 651 | | match getString(keyListHead(poolsListName)) { |
---|
652 | 652 | | case _: Unit => |
---|
653 | 653 | | $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares), DeleteEntry(keyNextPool), DeleteEntry(keyNextUser)], true) |
---|
654 | 654 | | case poolsHeadStr: String => |
---|
655 | 655 | | $Tuple2([StringEntry(keyNextPool, poolsHeadStr)], true) |
---|
656 | 656 | | case _ => |
---|
657 | 657 | | throw("Match error") |
---|
658 | 658 | | } |
---|
659 | 659 | | case poolStr: String => |
---|
660 | 660 | | let pool = stringToPool(poolStr) |
---|
661 | 661 | | let nextUserOrUnit = match userOrUnit { |
---|
662 | 662 | | case _: Unit => |
---|
663 | 663 | | getString(keyListHead(getVotesListName(pool))) |
---|
664 | 664 | | case user: String => |
---|
665 | 665 | | let next = getString(keyListNext(getVotesListName(pool), user)) |
---|
666 | 666 | | if ((next == next)) |
---|
667 | 667 | | then { |
---|
668 | 668 | | let processVoteInv = invoke(this, "processVoteINTERNAL", [poolStr, user], nil) |
---|
669 | 669 | | if ((processVoteInv == processVoteInv)) |
---|
670 | 670 | | then next |
---|
671 | 671 | | else throw("Strict value is not equal to itself.") |
---|
672 | 672 | | } |
---|
673 | 673 | | else throw("Strict value is not equal to itself.") |
---|
674 | 674 | | case _ => |
---|
675 | 675 | | throw("Match error") |
---|
676 | 676 | | } |
---|
677 | 677 | | match nextUserOrUnit { |
---|
678 | 678 | | case _: Unit => |
---|
679 | 679 | | let nextPoolOrUnit = getString(keyListNext(poolsListName, poolStr)) |
---|
680 | 680 | | match nextPoolOrUnit { |
---|
681 | 681 | | case _: Unit => |
---|
682 | 682 | | $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares), DeleteEntry(keyNextPool), DeleteEntry(keyNextUser)], true) |
---|
683 | 683 | | case s: String => |
---|
684 | 684 | | $Tuple2([StringEntry(keyNextPool, s), DeleteEntry(keyNextUser)], true) |
---|
685 | 685 | | case _ => |
---|
686 | 686 | | throw("Match error") |
---|
687 | 687 | | } |
---|
688 | 688 | | case nextUser: String => |
---|
689 | 689 | | $Tuple2([StringEntry(keyNextUser, nextUser)], true) |
---|
690 | 690 | | case _ => |
---|
691 | 691 | | throw("Match error") |
---|
692 | 692 | | } |
---|
693 | 693 | | case _ => |
---|
694 | 694 | | throw("Match error") |
---|
695 | 695 | | } |
---|
696 | 696 | | } |
---|
697 | 697 | | else if ((finalizationStageOrUnit == finalizationStageShares)) |
---|
698 | 698 | | then { |
---|
699 | 699 | | let poolOrUnit = getString(keyNextPool) |
---|
700 | 700 | | match poolOrUnit { |
---|
701 | 701 | | case _: Unit => |
---|
702 | 702 | | match getString(keyListHead(poolsListName)) { |
---|
703 | 703 | | case _: Unit => |
---|
704 | 704 | | let actions = if (force) |
---|
705 | 705 | | then [DeleteEntry(keyFinalizationStage), DeleteEntry(keyFinalizationShouldBeForced)] |
---|
706 | 706 | | else [DeleteEntry(keyFinalizationStage), BooleanEntry(keyFinalized(previousEpoch), true), IntegerEntry(keyCurrentEpochUi, epoch), IntegerEntry(keyStartHeightUi, startHeight)] |
---|
707 | 707 | | let gwxRewardDepositInv = gwxRewardDeposit() |
---|
708 | 708 | | if ((gwxRewardDepositInv == gwxRewardDepositInv)) |
---|
709 | 709 | | then $Tuple2(actions, true) |
---|
710 | 710 | | else throw("Strict value is not equal to itself.") |
---|
711 | 711 | | case nextPoolStr: String => |
---|
712 | 712 | | $Tuple2([StringEntry(keyNextPool, nextPoolStr)], true) |
---|
713 | 713 | | case _ => |
---|
714 | 714 | | throw("Match error") |
---|
715 | 715 | | } |
---|
716 | 716 | | case poolStr: String => |
---|
717 | 717 | | let nextPoolOrUnit = getString(keyListNext(poolsListName, poolStr)) |
---|
718 | 718 | | if ((nextPoolOrUnit == nextPoolOrUnit)) |
---|
719 | 719 | | then { |
---|
720 | 720 | | let r = { |
---|
721 | 721 | | let @ = invoke(this, "processPoolINTERNAL", [poolStr, force], nil) |
---|
722 | 722 | | if ($isInstanceOf(@, "Boolean")) |
---|
723 | 723 | | then @ |
---|
724 | 724 | | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
725 | 725 | | } |
---|
726 | 726 | | if ((r == r)) |
---|
727 | 727 | | then if (r) |
---|
728 | 728 | | then $Tuple2(nil, true) |
---|
729 | 729 | | else match nextPoolOrUnit { |
---|
730 | 730 | | case _: Unit => |
---|
731 | 731 | | let actions = if (force) |
---|
732 | 732 | | then [DeleteEntry(keyFinalizationStage), DeleteEntry(keyFinalizationShouldBeForced), DeleteEntry(keyNextPool)] |
---|
733 | 733 | | else [DeleteEntry(keyFinalizationStage), BooleanEntry(keyFinalized(previousEpoch), true), IntegerEntry(keyCurrentEpochUi, epoch), IntegerEntry(keyStartHeightUi, startHeight), DeleteEntry(keyNextPool)] |
---|
734 | 734 | | let gwxRewardDepositInv = gwxRewardDeposit() |
---|
735 | 735 | | if ((gwxRewardDepositInv == gwxRewardDepositInv)) |
---|
736 | 736 | | then $Tuple2(actions, true) |
---|
737 | 737 | | else throw("Strict value is not equal to itself.") |
---|
738 | 738 | | case nextPoolStr: String => |
---|
739 | 739 | | $Tuple2([StringEntry(keyNextPool, nextPoolStr)], true) |
---|
740 | 740 | | case _ => |
---|
741 | 741 | | throw("Match error") |
---|
742 | 742 | | } |
---|
743 | 743 | | else throw("Strict value is not equal to itself.") |
---|
744 | 744 | | } |
---|
745 | 745 | | else throw("Strict value is not equal to itself.") |
---|
746 | 746 | | case _ => |
---|
747 | 747 | | throw("Match error") |
---|
748 | 748 | | } |
---|
749 | 749 | | } |
---|
750 | 750 | | else throwErr("finalization is broken") |
---|
751 | 751 | | } |
---|
752 | 752 | | |
---|
753 | 753 | | |
---|
754 | 754 | | |
---|
755 | 755 | | @Callable(i) |
---|
756 | 756 | | func finalizeWrapper (counter) = { |
---|
757 | 757 | | let votingEmissionRateContract = addressFromStringValue(getStringValue(this, keyVotingEmissionRateContract)) |
---|
758 | 758 | | let result = { |
---|
759 | 759 | | let @ = invoke(this, "finalizeHelper", nil, nil) |
---|
760 | 760 | | if ($isInstanceOf(@, "Boolean")) |
---|
761 | 761 | | then @ |
---|
762 | 762 | | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
763 | 763 | | } |
---|
764 | 764 | | if ((result == result)) |
---|
765 | 765 | | then if (!(result)) |
---|
766 | 766 | | then if ((counter == 0)) |
---|
767 | 767 | | then throwErr("Current voting is not over yet") |
---|
768 | 768 | | else { |
---|
769 | 769 | | let inv = invoke(votingEmissionRateContract, "finalize", nil, nil) |
---|
770 | 770 | | if ((inv == inv)) |
---|
771 | 771 | | then $Tuple2(nil, unit) |
---|
772 | 772 | | else throw("Strict value is not equal to itself.") |
---|
773 | 773 | | } |
---|
774 | 774 | | else { |
---|
775 | 775 | | let maxDepth = valueOrElse(getInteger(this, keyMaxDepth), maxDepthDefault) |
---|
776 | 776 | | if ((maxDepth > counter)) |
---|
777 | 777 | | then { |
---|
778 | 778 | | let inv = invoke(this, "finalizeWrapper", [(counter + 1)], nil) |
---|
779 | 779 | | if ((inv == inv)) |
---|
780 | 780 | | then $Tuple2(nil, unit) |
---|
781 | 781 | | else throw("Strict value is not equal to itself.") |
---|
782 | 782 | | } |
---|
783 | 783 | | else $Tuple2(nil, unit) |
---|
784 | 784 | | } |
---|
785 | 785 | | else throw("Strict value is not equal to itself.") |
---|
786 | 786 | | } |
---|
787 | 787 | | |
---|
788 | 788 | | |
---|
789 | 789 | | |
---|
790 | 790 | | @Callable(i) |
---|
791 | 791 | | func finalize () = { |
---|
792 | 792 | | let inv = invoke(this, "finalizeWrapper", [0], nil) |
---|
793 | 793 | | if ((inv == inv)) |
---|
794 | 794 | | then $Tuple2(nil, unit) |
---|
795 | 795 | | else throw("Strict value is not equal to itself.") |
---|
796 | 796 | | } |
---|
797 | 797 | | |
---|
798 | 798 | | |
---|
799 | 799 | | |
---|
800 | 800 | | @Callable(i) |
---|
801 | 801 | | func containsNodeREADONLY (listName,id) = $Tuple2(nil, containsNode(listName, id)) |
---|
802 | 802 | | |
---|
803 | 803 | | |
---|
804 | 804 | | |
---|
805 | 805 | | @Callable(i) |
---|
806 | 806 | | func insertNode (listName,id) = { |
---|
807 | 807 | | let checkCaller = mustManager(i) |
---|
808 | 808 | | if ((checkCaller == checkCaller)) |
---|
809 | 809 | | then $Tuple2(insertNodeActions(listName, id), unit) |
---|
810 | 810 | | else throw("Strict value is not equal to itself.") |
---|
811 | 811 | | } |
---|
812 | 812 | | |
---|
813 | 813 | | |
---|
814 | 814 | | |
---|
815 | 815 | | @Callable(i) |
---|
816 | 816 | | func deleteNode (listName,id) = { |
---|
817 | 817 | | let checkCaller = mustManager(i) |
---|
818 | 818 | | if ((checkCaller == checkCaller)) |
---|
819 | 819 | | then $Tuple2(deleteNodeActions(listName, id), unit) |
---|
820 | 820 | | else throw("Strict value is not equal to itself.") |
---|
821 | 821 | | } |
---|
822 | 822 | | |
---|
823 | 823 | | |
---|
824 | 824 | | |
---|
825 | 825 | | @Callable(i) |
---|
826 | 826 | | func isFinalizationInProgress () = { |
---|
827 | 827 | | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
828 | 828 | | let finalizationInProgress = (finalizationStageOrUnit != unit) |
---|
829 | 829 | | $Tuple2(nil, finalizationInProgress) |
---|
830 | 830 | | } |
---|
831 | 831 | | |
---|
832 | 832 | | |
---|
833 | 833 | | |
---|
834 | 834 | | @Callable(i) |
---|
835 | 835 | | func deletePool (amountAssetId,priceAssetId) = { |
---|
836 | 836 | | let checkCaller = if (if ((i.caller == factoryContract)) |
---|
837 | 837 | | then true |
---|
838 | 838 | | else mustManager(i)) |
---|
839 | 839 | | then true |
---|
840 | 840 | | else throwErr("Permission denied") |
---|
841 | 841 | | if ((checkCaller == checkCaller)) |
---|
842 | 842 | | then { |
---|