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