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 { |
---|
622 | 617 | | } |
---|
623 | 618 | | else throw("Strict value is not equal to itself.") |
---|
624 | 619 | | } |
---|
625 | 620 | | else throw("Strict value is not equal to itself.") |
---|
626 | 621 | | } |
---|
627 | 622 | | else throw("Strict value is not equal to itself.") |
---|
628 | 623 | | } |
---|
629 | 624 | | else throw("Strict value is not equal to itself.") |
---|
630 | 625 | | } |
---|
631 | 626 | | |
---|
632 | 627 | | |
---|
633 | 628 | | |
---|
634 | 629 | | @Callable(i) |
---|
635 | 630 | | func finalizeHelper () = { |
---|
636 | 631 | | let force = valueOrElse(getBoolean(keyFinalizationShouldBeForced), false) |
---|
637 | 632 | | let epoch = valueOrElse(getInteger(this, keyCurrentEpoch), 0) |
---|
638 | 633 | | let previousEpoch = (epoch - 1) |
---|
639 | 634 | | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
640 | 635 | | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
641 | 636 | | let endHeight = (startHeight + epochLength) |
---|
642 | 637 | | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
643 | 638 | | if (if (if ((height >= endHeight)) |
---|
644 | 639 | | then (finalizationStageOrUnit == unit) |
---|
645 | 640 | | else false) |
---|
646 | 641 | | then !(force) |
---|
647 | 642 | | else false) |
---|
648 | 643 | | then { |
---|
649 | 644 | | let newEpoch = (epoch + 1) |
---|
650 | 645 | | let newEpochLengthOption = getInteger(this, keyEpochLengthNew) |
---|
651 | 646 | | let newEpochLengthActions = match newEpochLengthOption { |
---|
652 | 647 | | case newEpochLength: Int => |
---|
653 | 648 | | [IntegerEntry(keyEpochLength, newEpochLength), DeleteEntry(keyEpochLengthNew)] |
---|
654 | 649 | | case _: Unit => |
---|
655 | 650 | | nil |
---|
656 | 651 | | case _ => |
---|
657 | 652 | | throw("Match error") |
---|
658 | 653 | | } |
---|
659 | 654 | | $Tuple2(([IntegerEntry(keyStartHeightByEpoch(newEpoch), height), IntegerEntry(keyStartHeight, height), IntegerEntry(keyCurrentEpoch, newEpoch), IntegerEntry(keyFinalizationStage, finalizationStageTotal), IntegerEntry(keyEpochLengthByEpoch(epoch), epochLength)] ++ newEpochLengthActions), true) |
---|
660 | 655 | | } |
---|
661 | 656 | | else if (if (force) |
---|
662 | 657 | | then (finalizationStageOrUnit == unit) |
---|
663 | 658 | | else false) |
---|
664 | 659 | | then $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares)], true) |
---|
665 | 660 | | else if ((finalizationStageOrUnit == unit)) |
---|
666 | 661 | | then $Tuple2(nil, false) |
---|
667 | 662 | | else if ((finalizationStageOrUnit == finalizationStageTotal)) |
---|
668 | 663 | | then { |
---|
669 | 664 | | let poolOrUnit = getString(keyNextPool) |
---|
670 | 665 | | let userOrUnit = getString(keyNextUser) |
---|
671 | 666 | | match poolOrUnit { |
---|
672 | 667 | | case _: Unit => |
---|
673 | 668 | | match getString(keyListHead(poolsListName)) { |
---|
674 | 669 | | case _: Unit => |
---|
675 | 670 | | $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares), DeleteEntry(keyNextPool), DeleteEntry(keyNextUser)], true) |
---|
676 | 671 | | case poolsHeadStr: String => |
---|
677 | 672 | | $Tuple2([StringEntry(keyNextPool, poolsHeadStr)], true) |
---|
678 | 673 | | case _ => |
---|
679 | 674 | | throw("Match error") |
---|
680 | 675 | | } |
---|
681 | 676 | | case poolStr: String => |
---|
682 | 677 | | let pool = stringToPool(poolStr) |
---|
683 | 678 | | let nextUserOrUnit = match userOrUnit { |
---|
684 | 679 | | case _: Unit => |
---|
685 | 680 | | getString(keyListHead(getVotesListName(pool))) |
---|
686 | 681 | | case user: String => |
---|
687 | 682 | | let next = getString(keyListNext(getVotesListName(pool), user)) |
---|
688 | 683 | | if ((next == next)) |
---|
689 | 684 | | then { |
---|
690 | 685 | | let processVoteInv = invoke(this, "processVoteINTERNAL", [poolStr, user], nil) |
---|
691 | 686 | | if ((processVoteInv == processVoteInv)) |
---|
692 | 687 | | then next |
---|
693 | 688 | | else throw("Strict value is not equal to itself.") |
---|
694 | 689 | | } |
---|
695 | 690 | | else throw("Strict value is not equal to itself.") |
---|
696 | 691 | | case _ => |
---|
697 | 692 | | throw("Match error") |
---|
698 | 693 | | } |
---|
699 | 694 | | match nextUserOrUnit { |
---|
700 | 695 | | case _: Unit => |
---|
701 | 696 | | let nextPoolOrUnit = getString(keyListNext(poolsListName, poolStr)) |
---|
702 | 697 | | match nextPoolOrUnit { |
---|
703 | 698 | | case _: Unit => |
---|
704 | 699 | | $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares), DeleteEntry(keyNextPool), DeleteEntry(keyNextUser)], true) |
---|
705 | 700 | | case s: String => |
---|
706 | 701 | | $Tuple2([StringEntry(keyNextPool, s), DeleteEntry(keyNextUser)], true) |
---|
707 | 702 | | case _ => |
---|
708 | 703 | | throw("Match error") |
---|
709 | 704 | | } |
---|
710 | 705 | | case nextUser: String => |
---|
711 | 706 | | $Tuple2([StringEntry(keyNextUser, nextUser)], true) |
---|
712 | 707 | | case _ => |
---|
713 | 708 | | throw("Match error") |
---|
714 | 709 | | } |
---|
715 | 710 | | case _ => |
---|
716 | 711 | | throw("Match error") |
---|
717 | 712 | | } |
---|
718 | 713 | | } |
---|
719 | 714 | | else if ((finalizationStageOrUnit == finalizationStageShares)) |
---|
720 | 715 | | then { |
---|
721 | 716 | | let poolOrUnit = getString(keyNextPool) |
---|
722 | 717 | | match poolOrUnit { |
---|
723 | 718 | | case _: Unit => |
---|
724 | 719 | | match getString(keyListHead(poolsListName)) { |
---|
725 | 720 | | case _: Unit => |
---|
726 | 721 | | let actions = if (force) |
---|
727 | 722 | | then [DeleteEntry(keyFinalizationStage), DeleteEntry(keyFinalizationShouldBeForced)] |
---|
728 | 723 | | else [DeleteEntry(keyFinalizationStage), BooleanEntry(keyFinalized(previousEpoch), true), IntegerEntry(keyCurrentEpochUi, epoch), IntegerEntry(keyStartHeightUi, startHeight)] |
---|
729 | 724 | | let gwxRewardDepositInv = gwxRewardDeposit() |
---|
730 | 725 | | if ((gwxRewardDepositInv == gwxRewardDepositInv)) |
---|
731 | 726 | | then $Tuple2(actions, true) |
---|
732 | 727 | | else throw("Strict value is not equal to itself.") |
---|
733 | 728 | | case nextPoolStr: String => |
---|
734 | 729 | | $Tuple2([StringEntry(keyNextPool, nextPoolStr)], true) |
---|
735 | 730 | | case _ => |
---|
736 | 731 | | throw("Match error") |
---|
737 | 732 | | } |
---|
738 | 733 | | case poolStr: String => |
---|
739 | 734 | | let nextPoolOrUnit = getString(keyListNext(poolsListName, poolStr)) |
---|
740 | 735 | | if ((nextPoolOrUnit == nextPoolOrUnit)) |
---|
741 | 736 | | then { |
---|
742 | 737 | | let r = { |
---|
743 | 738 | | let @ = invoke(this, "processPoolINTERNAL", [poolStr, force], nil) |
---|
744 | 739 | | if ($isInstanceOf(@, "Boolean")) |
---|
745 | 740 | | then @ |
---|
746 | 741 | | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
747 | 742 | | } |
---|
748 | 743 | | if ((r == r)) |
---|
749 | 744 | | then if (r) |
---|
750 | 745 | | then $Tuple2(nil, true) |
---|
751 | 746 | | else match nextPoolOrUnit { |
---|
752 | 747 | | case _: Unit => |
---|
753 | 748 | | let actions = if (force) |
---|
754 | 749 | | then [DeleteEntry(keyFinalizationStage), DeleteEntry(keyFinalizationShouldBeForced), DeleteEntry(keyNextPool)] |
---|
755 | 750 | | else [DeleteEntry(keyFinalizationStage), BooleanEntry(keyFinalized(previousEpoch), true), IntegerEntry(keyCurrentEpochUi, epoch), IntegerEntry(keyStartHeightUi, startHeight), DeleteEntry(keyNextPool)] |
---|
756 | 751 | | let gwxRewardDepositInv = gwxRewardDeposit() |
---|
757 | 752 | | if ((gwxRewardDepositInv == gwxRewardDepositInv)) |
---|
758 | 753 | | then $Tuple2(actions, true) |
---|
759 | 754 | | else throw("Strict value is not equal to itself.") |
---|
760 | 755 | | case nextPoolStr: String => |
---|
761 | 756 | | $Tuple2([StringEntry(keyNextPool, nextPoolStr)], true) |
---|
762 | 757 | | case _ => |
---|
763 | 758 | | throw("Match error") |
---|
764 | 759 | | } |
---|
765 | 760 | | else throw("Strict value is not equal to itself.") |
---|
766 | 761 | | } |
---|
767 | 762 | | else throw("Strict value is not equal to itself.") |
---|
768 | 763 | | case _ => |
---|
769 | 764 | | throw("Match error") |
---|
770 | 765 | | } |
---|
771 | 766 | | } |
---|
772 | 767 | | else throwErr("finalization is broken") |
---|
773 | 768 | | } |
---|
774 | 769 | | |
---|
775 | 770 | | |
---|
776 | 771 | | |
---|
777 | 772 | | @Callable(i) |
---|
778 | 773 | | func finalizeWrapper (counter) = { |
---|
779 | 774 | | let votingEmissionRateContract = addressFromStringValue(getStringValue(this, keyVotingEmissionRateContract)) |
---|
780 | 775 | | let result = { |
---|
781 | 776 | | let @ = invoke(this, "finalizeHelper", nil, nil) |
---|
782 | 777 | | if ($isInstanceOf(@, "Boolean")) |
---|
783 | 778 | | then @ |
---|
784 | 779 | | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
785 | 780 | | } |
---|
786 | 781 | | if ((result == result)) |
---|
787 | 782 | | then if (!(result)) |
---|
788 | 783 | | then if ((counter == 0)) |
---|
789 | 784 | | then throwErr("Current voting is not over yet") |
---|
790 | 785 | | else { |
---|
791 | 786 | | let inv = invoke(votingEmissionRateContract, "finalize", nil, nil) |
---|
792 | 787 | | if ((inv == inv)) |
---|
793 | 788 | | then $Tuple2(nil, unit) |
---|
794 | 789 | | else throw("Strict value is not equal to itself.") |
---|
795 | 790 | | } |
---|
796 | 791 | | else { |
---|
797 | 792 | | let maxDepth = valueOrElse(getInteger(this, keyMaxDepth), maxDepthDefault) |
---|
798 | 793 | | if ((maxDepth > counter)) |
---|
799 | 794 | | then { |
---|
800 | 795 | | let inv = invoke(this, "finalizeWrapper", [(counter + 1)], nil) |
---|
801 | 796 | | if ((inv == inv)) |
---|
802 | 797 | | then $Tuple2(nil, unit) |
---|
803 | 798 | | else throw("Strict value is not equal to itself.") |
---|
804 | 799 | | } |
---|
805 | 800 | | else $Tuple2(nil, unit) |
---|
806 | 801 | | } |
---|
807 | 802 | | else throw("Strict value is not equal to itself.") |
---|
808 | 803 | | } |
---|
809 | 804 | | |
---|
810 | 805 | | |
---|
811 | 806 | | |
---|
812 | 807 | | @Callable(i) |
---|
813 | 808 | | func finalize () = { |
---|
814 | 809 | | let inv = invoke(this, "finalizeWrapper", [0], nil) |
---|
815 | 810 | | if ((inv == inv)) |
---|
816 | 811 | | then $Tuple2(nil, unit) |
---|
817 | 812 | | else throw("Strict value is not equal to itself.") |
---|
818 | 813 | | } |
---|
819 | 814 | | |
---|
820 | 815 | | |
---|
821 | 816 | | |
---|
822 | 817 | | @Callable(i) |
---|
823 | 818 | | func containsNodeREADONLY (listName,id) = $Tuple2(nil, containsNode(listName, id)) |
---|
824 | 819 | | |
---|
825 | 820 | | |
---|
826 | 821 | | |
---|
827 | 822 | | @Callable(i) |
---|
828 | 823 | | func insertNode (listName,id) = { |
---|
829 | 824 | | let checkCaller = mustManager(i) |
---|
830 | 825 | | if ((checkCaller == checkCaller)) |
---|
831 | 826 | | then $Tuple2(insertNodeActions(listName, id), unit) |
---|
832 | 827 | | else throw("Strict value is not equal to itself.") |
---|
833 | 828 | | } |
---|
834 | 829 | | |
---|
835 | 830 | | |
---|
836 | 831 | | |
---|
837 | 832 | | @Callable(i) |
---|
838 | 833 | | func deleteNode (listName,id) = { |
---|
839 | 834 | | let checkCaller = mustManager(i) |
---|
840 | 835 | | if ((checkCaller == checkCaller)) |
---|
841 | 836 | | then $Tuple2(deleteNodeActions(listName, id), unit) |
---|
842 | 837 | | else throw("Strict value is not equal to itself.") |
---|
843 | 838 | | } |
---|
844 | 839 | | |
---|
845 | 840 | | |
---|
846 | 841 | | |
---|
847 | 842 | | @Callable(i) |
---|
848 | 843 | | func isFinalizationInProgress () = { |
---|
849 | 844 | | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
850 | 845 | | let finalizationInProgress = (finalizationStageOrUnit != unit) |
---|
851 | 846 | | $Tuple2(nil, finalizationInProgress) |
---|
852 | 847 | | } |
---|
853 | 848 | | |
---|
854 | 849 | | |
---|
855 | 850 | | |
---|
856 | 851 | | @Callable(i) |
---|
857 | 852 | | func deletePool (amountAssetId,priceAssetId) = { |
---|
858 | 853 | | let checkCaller = if (if ((i.caller == factoryContract)) |
---|
859 | 854 | | then true |
---|
860 | 855 | | else mustManager(i)) |
---|
861 | 856 | | then true |
---|
862 | 857 | | else throwErr("Permission denied") |
---|
863 | 858 | | if ((checkCaller == checkCaller)) |
---|
864 | 859 | | then { |
---|
865 | 860 | | let listName = "pools" |
---|
866 | 861 | | let pool = $Tuple2(amountAssetId, priceAssetId) |
---|
867 | 862 | | let id = makeString([amountAssetId, priceAssetId], separator) |
---|
868 | 863 | | let actions = if (containsNode(listName, id)) |
---|
869 | 864 | | then deleteNodeActions(listName, id) |
---|
870 | 865 | | else nil |
---|
871 | 866 | | ([DeleteEntry(keyInList(pool))] ++ actions) |
---|
872 | 867 | | } |
---|
873 | 868 | | else throw("Strict value is not equal to itself.") |
---|
874 | 869 | | } |
---|
875 | 870 | | |
---|
876 | 871 | | |
---|
877 | 872 | | @Verifier(tx) |
---|
878 | 873 | | func verify () = { |
---|
879 | 874 | | let targetPublicKey = match managerPublicKeyOrUnit() { |
---|
880 | 875 | | case pk: ByteVector => |
---|
881 | 876 | | pk |
---|
882 | 877 | | case _: Unit => |
---|
883 | 878 | | tx.senderPublicKey |
---|
884 | 879 | | case _ => |
---|
885 | 880 | | throw("Match error") |
---|
886 | 881 | | } |
---|
887 | 882 | | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
888 | 883 | | } |
---|
889 | 884 | | |
---|