tx · BUoHs4MUrGhiiPig3euEmnLiezVAXC4B8fnjGLBBj5kr

3MzLFrUuyxbbNsHJrwSZo4iMaSG1z68kHL1:  -0.00500000 Waves

2023.03.16 11:34 [2492340] smart account 3MzLFrUuyxbbNsHJrwSZo4iMaSG1z68kHL1 > SELF 0.00000000 Waves

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

github/deemru/w8io/169f3d6 
52.68 ms