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