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