tx · 2gXfmWAtfJK5AKbzAuT7KLDLwqDPbpnJRrpQZ4WdX6k4 3Mp5kisFrqESzrXxAMEPk2k69zpeF41czEE: -0.01600000 Waves 2023.09.07 12:04 [2744757] smart account 3Mp5kisFrqESzrXxAMEPk2k69zpeF41czEE > SELF 0.00000000 Waves
{ "type": 13, "id": "2gXfmWAtfJK5AKbzAuT7KLDLwqDPbpnJRrpQZ4WdX6k4", "fee": 1600000, "feeAssetId": null, "timestamp": 1694077434845, "version": 2, "chainId": 84, "sender": "3Mp5kisFrqESzrXxAMEPk2k69zpeF41czEE", "senderPublicKey": "G349Uq3FTox7dRNLeAfAQeoACvwZ9iEnVSaHcEYn6j8J", "proofs": [ "5HBKnzhAvVoDsAvTiLqTwpynFvwuegfwGpuv2ppmUBWnwyXrEoZ21hzXdZrd52Dn8xkQxuCyL4iwKSqFLxD22vex" ], "script": "base64:BgLZFggCEgQKAgIBEgYKBAEYEQESBAoCCAESABIAEgMKAQgSABIECgIYERIAEgMKAQgSAwoBBCIDU0VQIgVTQ0FMRSIFTVVMVDgiB01VTFQ4QkkiCnplcm9CaWdJbnQiFHByb2Nlc3NpbmdTdGFnZVRvdGFsIhVwcm9jZXNzaW5nU3RhZ2VTaGFyZXMiBk1VTFQxOCIITVVMVDE4QkkiC3dhdmVzU3RyaW5nIgd3cmFwRXJyIgNtc2ciCHRocm93RXJyIg5nZXROdW1iZXJCeUtleSIDa2V5Ig9nZXROdW1iZXJPckZhaWwiDmdldFN0cmluZ0J5S2V5Ig9nZXRTdHJpbmdPckZhaWwiDHBhcnNlQXNzZXRJZCIFaW5wdXQiA2FicyIDdmFsIglhYnNCaWdJbnQiC2tleU1heERlcHRoIg9tYXhEZXB0aERlZmF1bHQiCG1heERlcHRoIhFrZXlGYWN0b3J5QWRkcmVzcyIRZmFjdG9yeUFkZHJlc3NTdHIiD2ZhY3RvcnlDb250cmFjdCISa2V5RW1pc3Npb25BZGRyZXNzIhlrZXlWb3RpbmdFbWlzc2lvbkNvb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WwgdG8gaXRzZWxmLgECY2wBAmNtAAQCY24EAmFTCQECYVUAAwkAAQIFAmFTAgpCeXRlVmVjdG9yBAJhWQUCYVMFAmFZAwkAAQIFAmFTAgRVbml0CAUCY2wPc2VuZGVyUHVibGljS2V5CQACAQILTWF0Y2ggZXJyb3IJAPQDAwgFAmNsCWJvZHlCeXRlcwkAkQMCCAUCY2wGcHJvb2ZzAAAFAmNuZJQbEQ==", "height": 2744757, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7NvuJ4KAwoJojGajdTuS9iD8jBXST7tKbdzaxaDqENZV Next: F4PAPxf4h7YMvKLURBZ1CyHMnE6S2NX29goD5Cu16nES Diff:
Old | New | Differences | |
---|---|---|---|
7 | 7 | ||
8 | 8 | let MULT8 = 100000000 | |
9 | 9 | ||
10 | + | let MULT8BI = toBigInt(MULT8) | |
11 | + | ||
10 | 12 | let zeroBigInt = toBigInt(0) | |
11 | 13 | ||
12 | 14 | let processingStageTotal = 0 | |
13 | 15 | ||
14 | 16 | let processingStageShares = 1 | |
15 | 17 | ||
18 | + | let MULT18 = 1000000000000000000 | |
19 | + | ||
20 | + | let MULT18BI = toBigInt(MULT18) | |
21 | + | ||
16 | 22 | let wavesString = "WAVES" | |
23 | + | ||
24 | + | func wrapErr (msg) = makeString(["gwx_reward.ride:", msg], " ") | |
25 | + | ||
26 | + | ||
27 | + | func throwErr (msg) = throw(wrapErr(msg)) | |
28 | + | ||
17 | 29 | ||
18 | 30 | func getNumberByKey (key) = valueOrElse(getInteger(this, key), 0) | |
19 | 31 | ||
20 | 32 | ||
21 | - | func getNumberOrFail (key) = valueOrErrorMessage(getInteger(this, key), (("mandatory this." + key) + " is not defined")) | |
33 | + | func getNumberOrFail (key) = valueOrErrorMessage(getInteger(this, key), wrapErr((("mandatory this." + key) + " is not defined"))) | |
22 | 34 | ||
23 | 35 | ||
24 | 36 | func getStringByKey (key) = valueOrElse(getString(this, key), "") | |
25 | 37 | ||
26 | 38 | ||
27 | - | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), (("mandatory this." + key) + " is not defined")) | |
39 | + | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), wrapErr((("mandatory this." + key) + " is not defined"))) | |
28 | 40 | ||
29 | 41 | ||
30 | 42 | func parseAssetId (input) = if ((input == wavesString)) | |
31 | 43 | then unit | |
32 | 44 | else fromBase58String(input) | |
33 | - | ||
34 | - | ||
35 | - | func wrapErr (msg) = makeString(["gwx_reward.ride:", msg], " ") | |
36 | - | ||
37 | - | ||
38 | - | func throwErr (msg) = throw(wrapErr(msg)) | |
39 | 45 | ||
40 | 46 | ||
41 | 47 | func abs (val) = if ((0 > val)) | |
138 | 144 | } | |
139 | 145 | ||
140 | 146 | ||
147 | + | let keySuspension = "%s__suspension" | |
148 | + | ||
149 | + | let isSuspended = valueOrElse(getBoolean(this, keySuspension), false) | |
150 | + | ||
151 | + | func throwIfSuspended () = if (!(isSuspended)) | |
152 | + | then true | |
153 | + | else throwErr("suspended") | |
154 | + | ||
155 | + | ||
141 | 156 | func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight" | |
142 | 157 | ||
143 | 158 | ||
144 | 159 | func keyUsersCount () = "%s__nextUserNum" | |
160 | + | ||
161 | + | ||
162 | + | func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", toString(userAddress)], SEP) | |
145 | 163 | ||
146 | 164 | ||
147 | 165 | func keyRatePerBlockCurrent () = "%s%s__ratePerBlock__current" | |
156 | 174 | func keyPoolWeightVirtual () = "%s%s__poolWeight__GWXvirtualPOOL" | |
157 | 175 | ||
158 | 176 | ||
159 | - | func keyNextProcessedUser () = "%s__nextProcessedUser" | |
160 | - | ||
161 | - | ||
162 | - | func keyLatestPeriod () = "%s__latestPeriod" | |
163 | - | ||
164 | - | ||
165 | - | func keyNextPeriod () = "%s__nextPeriod" | |
166 | - | ||
167 | - | ||
168 | - | func keyProcessingStage () = "%s__processingStage" | |
169 | - | ||
170 | - | ||
171 | - | func keyNextProcessedPeriod () = "%s__nextProcessedPeriod" | |
172 | - | ||
173 | - | ||
174 | 177 | func keyUserUnclaimed (userIndex) = makeString(["%s%d", "userUnclaimed", toString(userIndex)], SEP) | |
175 | - | ||
176 | - | ||
177 | - | func keyNextUnlaimedPeriodOfUser (userIndex) = makeString(["%s%d__nextClaimedPeriod", toString(userIndex)], SEP) | |
178 | - | ||
179 | - | ||
180 | - | func keyLastProcessedPeriodOfUser (userIndex) = makeString(["%s%d__lastProcessedPeriod", toString(userIndex)], SEP) | |
181 | - | ||
182 | - | ||
183 | - | func keyHeightForPeriod (period) = makeString(["%s%d__startHeightForPeriod", toString(period)], SEP) | |
184 | - | ||
185 | - | ||
186 | - | func keyAuxEmissionRewardForPeriod (period) = makeString(["%s%d__auxEmissionReward", toString(period)], SEP) | |
187 | - | ||
188 | - | ||
189 | - | func keyTotalAmountForPeriod (period) = makeString(["%s%d__totalAmountForPeriod", toString(period)], SEP) | |
190 | - | ||
191 | - | ||
192 | - | func keyLastPayoutInfo () = "%s__lastPayoutInfo" | |
193 | - | ||
194 | - | ||
195 | - | func PeriodPayoutInfo (period,matcherReward,emissionReward) = makeString(["%d%d%d", toString(period), toString(matcherReward), toString(emissionReward)], SEP) | |
196 | - | ||
197 | - | ||
198 | - | func keyPayoutHistoryInfo (period) = makeString(["%s%s%d__payouts__history", toString(period)], SEP) | |
199 | - | ||
200 | - | ||
201 | - | func keyTotalWeightForPeriod (period) = makeString(["%s%d__totalWeightForPeriod", toString(period)], SEP) | |
202 | - | ||
203 | - | ||
204 | - | func keyUserKValueForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "k", toString(period)], SEP) | |
205 | - | ||
206 | - | ||
207 | - | func keyUserBValueForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "b", toString(period)], SEP) | |
208 | - | ||
209 | - | ||
210 | - | func keyUserWeightForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "weight", toString(period)], SEP) | |
211 | 178 | ||
212 | 179 | ||
213 | 180 | func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP) | |
275 | 242 | } | |
276 | 243 | ||
277 | 244 | ||
278 | - | func calcUserWeight (boostingContractAddress,heightForPeriod,period,userIndex) = { | |
279 | - | let kLast = keyLastProcessedPeriodOfUser(userIndex) | |
280 | - | let kKey = keyUserKValueForPeriod(period, userIndex) | |
281 | - | let kRaw = getInteger(boostingContractAddress, kKey) | |
282 | - | let kUserWeight = keyUserWeightForPeriod(period, userIndex) | |
283 | - | if (isDefined(kRaw)) | |
284 | - | then { | |
285 | - | let k = value(kRaw) | |
286 | - | let b = value(getInteger(boostingContractAddress, keyUserBValueForPeriod(period, userIndex))) | |
287 | - | let w = ((k * heightForPeriod) + b) | |
288 | - | if ((w > 0)) | |
289 | - | then $Tuple2((w / SCALE), [IntegerEntry(kLast, period), IntegerEntry(kUserWeight, w)]) | |
290 | - | else $Tuple2(0, nil) | |
291 | - | } | |
292 | - | else { | |
293 | - | let p = getInteger(this, kLast) | |
294 | - | if (if (isDefined(p)) | |
295 | - | then (period >= value(p)) | |
296 | - | else false) | |
297 | - | then { | |
298 | - | let pv = value(p) | |
299 | - | let k = value(getInteger(boostingContractAddress, keyUserKValueForPeriod(pv, userIndex))) | |
300 | - | let b = value(getInteger(boostingContractAddress, keyUserBValueForPeriod(pv, userIndex))) | |
301 | - | let w = ((k * heightForPeriod) + b) | |
302 | - | if ((w > 0)) | |
303 | - | then $Tuple2((w / SCALE), [IntegerEntry(kUserWeight, w)]) | |
304 | - | else $Tuple2(0, nil) | |
305 | - | } | |
306 | - | else $Tuple2(0, nil) | |
307 | - | } | |
308 | - | } | |
309 | - | ||
310 | - | ||
311 | - | func calcUserWeightForClaim (boostingContractAddress,heightForPeriod,period,userIndex) = { | |
312 | - | let kUserWeight = keyUserWeightForPeriod(period, userIndex) | |
313 | - | let userWeightOrUnit = getInteger(kUserWeight) | |
314 | - | match userWeightOrUnit { | |
315 | - | case _: Unit => | |
316 | - | 0 | |
317 | - | case w: Int => | |
318 | - | (w / SCALE) | |
319 | - | case _ => | |
320 | - | throw("Match error") | |
321 | - | } | |
322 | - | } | |
323 | - | ||
324 | - | ||
325 | 245 | func getUserIndexByAddress (boostingContractAddressStr,userAddress) = { | |
326 | 246 | let key = makeString(["%s%s%s", "mapping", "user2num", userAddress], SEP) | |
327 | 247 | parseIntValue(valueOrErrorMessage(getString(Address(fromBase58String(boostingContractAddressStr)), key), ((("User address " + userAddress) + " is not found in boosting contract data, key=") + key))) | |
328 | 248 | } | |
329 | 249 | ||
330 | 250 | ||
331 | - | func | |
251 | + | func getTradingReward (userAddress) = valueOrElse(getInteger(this, keyTradingReward(userAddress)), 0) | |
332 | 252 | ||
333 | 253 | ||
334 | - | func commonClaimReward (userAddress) = { | |
335 | - | let cfgArray = readConfigArrayOrFail() | |
336 | - | let userIdx = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddress) | |
337 | - | let userUnclaimedOption = getInteger(keyUserUnclaimed(userIdx)) | |
338 | - | match userUnclaimedOption { | |
254 | + | func keyRewardPerGwxIntegral () = makeString(["%s", "rewardPerGwxIntegral"], SEP) | |
255 | + | ||
256 | + | ||
257 | + | func getGwxAmountTotalOption () = { | |
258 | + | let keyGwxTotal = "%s%s__gwx__total" | |
259 | + | getInteger(boostingContractOrFail(), keyGwxTotal) | |
260 | + | } | |
261 | + | ||
262 | + | ||
263 | + | func getUserGwxAmountTotalOption (userAddress) = { | |
264 | + | func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP) | |
265 | + | ||
266 | + | getInteger(boostingContractOrFail(), keyUserGwxAmountTotal(userAddress)) | |
267 | + | } | |
268 | + | ||
269 | + | ||
270 | + | func _refreshRewardPerGwxIntegral () = { | |
271 | + | let rewardPerGwxIntegralPrevious = valueOrElse( match getString(this, keyRewardPerGwxIntegral()) { | |
272 | + | case s: String => | |
273 | + | parseBigInt(s) | |
339 | 274 | case _: Unit => | |
340 | - | $Tuple2(0, nil) | |
341 | - | case u: Int => | |
342 | - | $Tuple2(u, [IntegerEntry(keyUserUnclaimed(userIdx), 0)]) | |
275 | + | unit | |
276 | + | case _ => | |
277 | + | throw("Match error") | |
278 | + | }, zeroBigInt) | |
279 | + | let rewardPerGwxIntegralLastHeight = valueOrErrorMessage(getInteger(this, keyGwxRewardEmissionStartHeight()), wrapErr(("invalid " + keyGwxRewardEmissionStartHeight()))) | |
280 | + | let emissionRate = valueOrErrorMessage(getInteger(emissionContract, keyRatePerBlockCurrent()), wrapErr(("invalid " + keyRatePerBlockCurrent()))) | |
281 | + | let gwxHoldersRewardCurrent = valueOrElse(getInteger(emissionContract, keyGwxHoldersRewardCurrent()), 0) | |
282 | + | let gwxAmountTotal = valueOrElse(getGwxAmountTotalOption(), 0) | |
283 | + | let dh = toBigInt((height - rewardPerGwxIntegralLastHeight)) | |
284 | + | let gwxAmountTotalBI = toBigInt(gwxAmountTotal) | |
285 | + | let rewardPerGwxIntegral = (rewardPerGwxIntegralPrevious + (if ((gwxAmountTotalBI == zeroBigInt)) | |
286 | + | then zeroBigInt | |
287 | + | else fraction(dh, ((toBigInt(emissionRate) * toBigInt(gwxHoldersRewardCurrent)) * MULT18BI), (gwxAmountTotalBI * MULT8BI)))) | |
288 | + | $Tuple2([IntegerEntry(keyGwxRewardEmissionStartHeight(), height), StringEntry(keyRewardPerGwxIntegral(), toString(rewardPerGwxIntegral))], rewardPerGwxIntegral) | |
289 | + | } | |
290 | + | ||
291 | + | ||
292 | + | func keyRewardPerGwxIntegralUserLast (userAddress) = makeString(["%s%s", "rewardPerGwxIntegralUserLast", toString(userAddress)], SEP) | |
293 | + | ||
294 | + | ||
295 | + | func _refreshUserReward (userAddress,userNum) = { | |
296 | + | let $t01029210380 = _refreshRewardPerGwxIntegral() | |
297 | + | let rewardPerGwxIntegralActions = $t01029210380._1 | |
298 | + | let rewardPerGwxIntegral = $t01029210380._2 | |
299 | + | let rewardPerGwxIntegralUserLast = match getString(this, keyRewardPerGwxIntegralUserLast(userAddress)) { | |
300 | + | case s: String => | |
301 | + | valueOrErrorMessage(parseBigInt(s), wrapErr("invalid user last integral")) | |
302 | + | case _: Unit => | |
303 | + | rewardPerGwxIntegral | |
343 | 304 | case _ => | |
344 | 305 | throw("Match error") | |
345 | 306 | } | |
307 | + | let userIdxOption = getString(boostingContractOrFail(), keyUser2NumMapping(userAddress)) | |
308 | + | let userUnclaimed = valueOrElse(getInteger(keyUserUnclaimed(userNum)), 0) | |
309 | + | let userGwxAmount = valueOrElse(getUserGwxAmountTotalOption(userAddress), 0) | |
310 | + | let userReward = (toInt(fraction(toBigInt(userGwxAmount), (rewardPerGwxIntegral - rewardPerGwxIntegralUserLast), MULT18BI)) + userUnclaimed) | |
311 | + | $Tuple2(([StringEntry(keyRewardPerGwxIntegralUserLast(userAddress), toString(rewardPerGwxIntegral))] ++ rewardPerGwxIntegralActions), userReward) | |
346 | 312 | } | |
347 | 313 | ||
348 | 314 | ||
349 | - | func getTradingReward (userAddress) = valueOrElse(getInteger(this, keyTradingReward(userAddress)), 0) | |
315 | + | func commonClaimReward (userAddressStr) = { | |
316 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
317 | + | let cfgArray = readConfigArrayOrFail() | |
318 | + | let userNum = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddressStr) | |
319 | + | let $t01167111735 = _refreshUserReward(userAddress, userNum) | |
320 | + | let actions = $t01167111735._1 | |
321 | + | let reward = $t01167111735._2 | |
322 | + | $Tuple2(reward, ([IntegerEntry(keyUserUnclaimed(userNum), 0)] ++ actions)) | |
323 | + | } | |
350 | 324 | ||
351 | 325 | ||
352 | 326 | @Callable(i) | |
353 | - | func tradeRewardInternal (paymentAmountLeftOver,userAddresses,rewards,currentIter) = if ((currentIter == size(userAddresses))) | |
354 | - | then nil | |
355 | - | else { | |
356 | - | let checks = [if ((i.caller == this)) | |
357 | - | then true | |
358 | - | else throwErr("Permission denied"), if ((paymentAmountLeftOver >= rewards[currentIter])) | |
359 | - | then true | |
360 | - | else throwErr("insufficient payment assetId")] | |
361 | - | if ((checks == checks)) | |
362 | - | then { | |
363 | - | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [(paymentAmountLeftOver - rewards[currentIter]), userAddresses, rewards, (currentIter + 1)], nil) | |
364 | - | if ((tradeRewardInternal == tradeRewardInternal)) | |
365 | - | then { | |
366 | - | let tradingRewardHistoryKey = keyTradingRewardHistory(userAddresses[currentIter], i) | |
367 | - | let userAddress = addressFromStringValue(userAddresses[currentIter]) | |
368 | - | $Tuple2([IntegerEntry(tradingRewardHistoryKey, rewards[currentIter]), IntegerEntry(keyTradingReward(userAddresses[currentIter]), rewards[currentIter])], tradeRewardInternal) | |
369 | - | } | |
370 | - | else throw("Strict value is not equal to itself.") | |
371 | - | } | |
372 | - | else throw("Strict value is not equal to itself.") | |
373 | - | } | |
374 | - | ||
375 | - | ||
376 | - | ||
377 | - | @Callable(i) | |
378 | - | func updateReferralActivity (userAddress,gWxAmountStart) = { | |
379 | - | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) | |
380 | - | let activeReferralInv = if ((referrer == unit)) | |
381 | - | then unit | |
382 | - | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (gWxAmountStart >= referralMinGWxAmount)], nil) | |
383 | - | if ((activeReferralInv == activeReferralInv)) | |
384 | - | then $Tuple2(nil, unit) | |
327 | + | func refreshUserReward (userAddressBytes,userNum) = { | |
328 | + | let suspensionCheck = throwIfSuspended() | |
329 | + | if ((suspensionCheck == suspensionCheck)) | |
330 | + | then { | |
331 | + | let checkCaller = if ((i.caller == boostingContractOrFail())) | |
332 | + | then true | |
333 | + | else throwErr("permission denied") | |
334 | + | if ((checkCaller == checkCaller)) | |
335 | + | then { | |
336 | + | let $t01206112139 = _refreshUserReward(Address(userAddressBytes), userNum) | |
337 | + | let actions = $t01206112139._1 | |
338 | + | let reward = $t01206112139._2 | |
339 | + | $Tuple2(([IntegerEntry(keyUserUnclaimed(userNum), reward)] ++ actions), reward) | |
340 | + | } | |
341 | + | else throw("Strict value is not equal to itself.") | |
342 | + | } | |
385 | 343 | else throw("Strict value is not equal to itself.") | |
386 | 344 | } | |
387 | 345 | ||
388 | 346 | ||
389 | 347 | ||
390 | 348 | @Callable(i) | |
391 | - | func finalizeHelper () = { | |
392 | - | let processingStage = valueOrElse(getInteger(keyProcessingStage()), processingStageTotal) | |
393 | - | let currentPeriod = getNumberByKey(keyNextProcessedPeriod()) | |
394 | - | let currentUser = getNumberByKey(keyNextProcessedUser()) | |
395 | - | let latestPeriod = getNumberByKey(keyLatestPeriod()) | |
396 | - | let usersCount = valueOrElse(getInteger(boostingContractOrFail(), keyUsersCount()), 0) | |
397 | - | let totalWeightKey = keyTotalWeightForPeriod(currentPeriod) | |
398 | - | let totalWeight = getNumberByKey(keyTotalWeightForPeriod(currentPeriod)) | |
399 | - | let heightForPeriod = getNumberByKey(keyHeightForPeriod(currentPeriod)) | |
400 | - | if ((currentPeriod > latestPeriod)) | |
401 | - | then $Tuple2(nil, false) | |
402 | - | else if ((processingStage == processingStageTotal)) | |
403 | - | then { | |
404 | - | let $t01451014626 = calcUserWeight(boostingContractOrFail(), heightForPeriod, currentPeriod, currentUser) | |
405 | - | let userWeight = $t01451014626._1 | |
406 | - | let userActions = $t01451014626._2 | |
407 | - | let totalWeightNew = (totalWeight + userWeight) | |
408 | - | let processingActions = if (((usersCount - 1) > currentUser)) | |
409 | - | then [IntegerEntry(keyNextProcessedUser(), (currentUser + 1))] | |
410 | - | else [IntegerEntry(keyProcessingStage(), processingStageShares), IntegerEntry(keyNextProcessedUser(), 0)] | |
411 | - | $Tuple2((([IntegerEntry(totalWeightKey, totalWeightNew)] ++ processingActions) ++ userActions), true) | |
349 | + | func tradeRewardInternal (paymentAmountLeftOver,userAddresses,rewards,currentIter) = { | |
350 | + | let suspensionCheck = throwIfSuspended() | |
351 | + | if ((suspensionCheck == suspensionCheck)) | |
352 | + | then if ((currentIter == size(userAddresses))) | |
353 | + | then nil | |
354 | + | else { | |
355 | + | let checks = [if ((i.caller == this)) | |
356 | + | then true | |
357 | + | else throwErr("Permission denied"), if ((paymentAmountLeftOver >= rewards[currentIter])) | |
358 | + | then true | |
359 | + | else throwErr("insufficient payment assetId")] | |
360 | + | if ((checks == checks)) | |
361 | + | then { | |
362 | + | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [(paymentAmountLeftOver - rewards[currentIter]), userAddresses, rewards, (currentIter + 1)], nil) | |
363 | + | if ((tradeRewardInternal == tradeRewardInternal)) | |
364 | + | then { | |
365 | + | let tradingRewardHistoryKey = keyTradingRewardHistory(userAddresses[currentIter], i) | |
366 | + | let userAddress = addressFromStringValue(userAddresses[currentIter]) | |
367 | + | $Tuple2([IntegerEntry(tradingRewardHistoryKey, rewards[currentIter]), IntegerEntry(keyTradingReward(userAddresses[currentIter]), rewards[currentIter])], tradeRewardInternal) | |
368 | + | } | |
369 | + | else throw("Strict value is not equal to itself.") | |
370 | + | } | |
371 | + | else throw("Strict value is not equal to itself.") | |
412 | 372 | } | |
413 | - | else if ((processingStage == processingStageShares)) | |
414 | - | then { | |
415 | - | let userWeight = calcUserWeightForClaim(boostingContractOrFail(), heightForPeriod, currentPeriod, currentUser) | |
416 | - | let userAmountMatcherForPeriod = fraction(getNumberByKey(keyTotalAmountForPeriod(currentPeriod)), userWeight, totalWeight) | |
417 | - | let userAmountEmissionForPeriod = fraction(getNumberByKey(keyAuxEmissionRewardForPeriod(currentPeriod)), userWeight, totalWeight) | |
418 | - | let userTotalAmount = (userAmountEmissionForPeriod + userAmountMatcherForPeriod) | |
419 | - | let userUnclaimedOption = getInteger(keyUserUnclaimed(currentUser)) | |
420 | - | let userAddress = getStringValue(boostingContractOrFail(), keyNumToUserMapping(currentUser)) | |
421 | - | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) | |
422 | - | let activeReferralInv = if ((referrer == unit)) | |
423 | - | then unit | |
424 | - | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (userWeight >= referralMinGWxAmount)], nil) | |
425 | - | if ((activeReferralInv == activeReferralInv)) | |
426 | - | then { | |
427 | - | let referralInv = if (if ((referrer == unit)) | |
428 | - | then true | |
429 | - | else (referralMinGWxAmount > userWeight)) | |
430 | - | then unit | |
431 | - | else { | |
432 | - | let referrerReward = fraction(userTotalAmount, referrerRewardPermille, SCALE) | |
433 | - | let referralReward = fraction(userTotalAmount, referralRewardPermille, SCALE) | |
434 | - | invoke(referralsContractAddressOrFail, "incUnclaimed", [referralProgramName, userAddress, referrerReward, referralReward], nil) | |
435 | - | } | |
436 | - | if ((referralInv == referralInv)) | |
437 | - | then { | |
438 | - | let unclaimedActions = [IntegerEntry(keyUserUnclaimed(currentUser), (valueOrElse(userUnclaimedOption, 0) + userTotalAmount))] | |
439 | - | let processingActions = if (((usersCount - 1) > currentUser)) | |
440 | - | then [IntegerEntry(keyNextProcessedUser(), (currentUser + 1))] | |
441 | - | else [IntegerEntry(keyNextProcessedPeriod(), (currentPeriod + 1)), IntegerEntry(keyNextProcessedUser(), 0), DeleteEntry(keyProcessingStage())] | |
442 | - | $Tuple2((unclaimedActions ++ processingActions), true) | |
443 | - | } | |
444 | - | else throw("Strict value is not equal to itself.") | |
445 | - | } | |
446 | - | else throw("Strict value is not equal to itself.") | |
447 | - | } | |
448 | - | else throw("invalid processing stage") | |
449 | - | } | |
450 | - | ||
451 | - | ||
452 | - | ||
453 | - | @Callable(i) | |
454 | - | func finalizeWrapper (counter) = { | |
455 | - | let result = { | |
456 | - | let @ = invoke(this, "finalizeHelper", nil, nil) | |
457 | - | if ($isInstanceOf(@, "Boolean")) | |
458 | - | then @ | |
459 | - | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
460 | - | } | |
461 | - | if ((result == result)) | |
462 | - | then if (!(result)) | |
463 | - | then if ((counter == maxDepth)) | |
464 | - | then throw("Nothing to process") | |
465 | - | else $Tuple2(nil, unit) | |
466 | - | else if ((counter > 0)) | |
467 | - | then $Tuple2(nil, invoke(this, "finalizeWrapper", [(counter - 1)], nil)) | |
468 | - | else $Tuple2(nil, unit) | |
469 | 373 | else throw("Strict value is not equal to itself.") | |
470 | 374 | } | |
471 | 375 | ||
472 | 376 | ||
473 | 377 | ||
474 | 378 | @Callable(i) | |
475 | - | func processPendingPeriodsAndUsers () = $Tuple2(nil, invoke(this, "finalizeWrapper", [maxDepth], nil)) | |
379 | + | func updateReferralActivity (userAddress,gWxAmountStart) = { | |
380 | + | let suspensionCheck = throwIfSuspended() | |
381 | + | if ((suspensionCheck == suspensionCheck)) | |
382 | + | then { | |
383 | + | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) | |
384 | + | let activeReferralInv = if ((referrer == unit)) | |
385 | + | then unit | |
386 | + | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (gWxAmountStart >= referralMinGWxAmount)], nil) | |
387 | + | if ((activeReferralInv == activeReferralInv)) | |
388 | + | then $Tuple2(nil, unit) | |
389 | + | else throw("Strict value is not equal to itself.") | |
390 | + | } | |
391 | + | else throw("Strict value is not equal to itself.") | |
392 | + | } | |
476 | 393 | ||
477 | 394 | ||
478 | 395 | ||
479 | 396 | @Callable(i) | |
480 | - | func deposit () = { | |
481 | - | let checkCaller = if ((i.caller == votingEmissionContract)) | |
482 | - | then true | |
483 | - | else mustManager(i) | |
484 | - | if ((checkCaller == checkCaller)) | |
397 | + | func processPendingPeriodsAndUsers () = $Tuple2(nil, throwErr("deprecated")) | |
398 | + | ||
399 | + | ||
400 | + | ||
401 | + | @Callable(i) | |
402 | + | func claimReward () = { | |
403 | + | let suspensionCheck = throwIfSuspended() | |
404 | + | if ((suspensionCheck == suspensionCheck)) | |
485 | 405 | then { | |
486 | - | let period = nextPeriod() | |
487 | - | let deltaH = (height - getNumberOrFail(keyGwxRewardEmissionStartHeight())) | |
488 | - | let emissionRate = valueOrErrorMessage(getInteger(emissionContract, keyRatePerBlockCurrent()), (("mandatory emission_contract." + keyRatePerBlockCurrent()) + " is not defined")) | |
489 | - | let gwxHoldersRewardCurrent = valueOrElse(getInteger(emissionContract, keyGwxHoldersRewardCurrent()), 0) | |
490 | - | if ((gwxHoldersRewardCurrent == gwxHoldersRewardCurrent)) | |
406 | + | let cfgArray = readConfigArrayOrFail() | |
407 | + | let userAddress = i.caller | |
408 | + | let userAddressStr = toString(userAddress) | |
409 | + | let $t01400914066 = commonClaimReward(userAddressStr) | |
410 | + | let amount = $t01400914066._1 | |
411 | + | let actions = $t01400914066._2 | |
412 | + | let checkAmount = if ((amount > 0)) | |
413 | + | then true | |
414 | + | else throw("nothing to claim") | |
415 | + | if ((checkAmount == checkAmount)) | |
491 | 416 | then { | |
492 | - | let auxAmount = fraction((deltaH * gwxHoldersRewardCurrent), emissionRate, MULT8) | |
493 | - | let em = if ((auxAmount > 0)) | |
494 | - | then invoke(emissionContract, "emit", [auxAmount], nil) | |
495 | - | else unit | |
496 | - | if ((em == em)) | |
417 | + | let userGwxAmount = { | |
418 | + | let @ = invoke(boostingContractOrFail(), "getUserGwxAmount", [userAddressStr], nil) | |
419 | + | if ($isInstanceOf(@, "Int")) | |
420 | + | then @ | |
421 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
422 | + | } | |
423 | + | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddressStr)) | |
424 | + | let activeReferralInv = if ((referrer == unit)) | |
425 | + | then unit | |
426 | + | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (userGwxAmount >= referralMinGWxAmount)], nil) | |
427 | + | if ((activeReferralInv == activeReferralInv)) | |
497 | 428 | then { | |
498 | - | let matcherPart = 0 | |
499 | - | let payoutInfo = PeriodPayoutInfo(period, matcherPart, auxAmount) | |
500 | - | let gwxHoldersRewardUpdated = { | |
501 | - | let @ = invoke(emissionContract, "gwxHoldersRewardUpdate", nil, nil) | |
502 | - | if ($isInstanceOf(@, "Boolean")) | |
503 | - | then @ | |
504 | - | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
505 | - | } | |
506 | - | if ((gwxHoldersRewardUpdated == gwxHoldersRewardUpdated)) | |
429 | + | let referralInv = if (if ((referrer == unit)) | |
430 | + | then true | |
431 | + | else (referralMinGWxAmount > userGwxAmount)) | |
432 | + | then unit | |
433 | + | else { | |
434 | + | let referrerReward = fraction(amount, referrerRewardPermille, SCALE) | |
435 | + | let referralReward = fraction(amount, referralRewardPermille, SCALE) | |
436 | + | invoke(referralsContractAddressOrFail, "incUnclaimed", [referralProgramName, userAddress, referrerReward, referralReward], nil) | |
437 | + | } | |
438 | + | if ((referralInv == referralInv)) | |
507 | 439 | then { | |
508 | - | let totalReward = (matcherPart + auxAmount) | |
509 | - | let actions = if (if ((totalReward == 0)) | |
510 | - | then !(gwxHoldersRewardUpdated) | |
511 | - | else false) | |
512 | - | then nil | |
513 | - | else [IntegerEntry(keyLatestPeriod(), period), IntegerEntry(keyHeightForPeriod(period), height), IntegerEntry(keyAuxEmissionRewardForPeriod(period), auxAmount), IntegerEntry(keyGwxRewardEmissionStartHeight(), height), IntegerEntry(keyTotalAmountForPeriod(period), matcherPart), IntegerEntry(keyNextPeriod(), (period + 1)), StringEntry(keyLastPayoutInfo(), payoutInfo), StringEntry(keyPayoutHistoryInfo(period), payoutInfo)] | |
514 | - | $Tuple2(actions, unit) | |
440 | + | let emit = invoke(emissionContract, "emit", [amount], nil) | |
441 | + | if ((emit == emit)) | |
442 | + | then { | |
443 | + | let claimedReferral = { | |
444 | + | let @ = invoke(referralsContractAddressOrFail, "claim", [referralProgramName], nil) | |
445 | + | if ($isInstanceOf(@, "Int")) | |
446 | + | then @ | |
447 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
448 | + | } | |
449 | + | if ((claimedReferral == claimedReferral)) | |
450 | + | then { | |
451 | + | let totalAmount = (amount + claimedReferral) | |
452 | + | $Tuple2(([ScriptTransfer(i.caller, amount, wxAssetId), HistoryEntry("claim", userAddressStr, totalAmount, i)] ++ actions), totalAmount) | |
453 | + | } | |
454 | + | else throw("Strict value is not equal to itself.") | |
455 | + | } | |
456 | + | else throw("Strict value is not equal to itself.") | |
515 | 457 | } | |
516 | 458 | else throw("Strict value is not equal to itself.") | |
517 | 459 | } | |
525 | 467 | ||
526 | 468 | ||
527 | 469 | @Callable(i) | |
528 | - | func claimReward () = { | |
529 | - | let cfgArray = readConfigArrayOrFail() | |
530 | - | let address = toString(i.caller) | |
531 | - | let $t01981519865 = commonClaimReward(address) | |
532 | - | let amount = $t01981519865._1 | |
533 | - | let actions = $t01981519865._2 | |
534 | - | let checkAmount = if ((amount > 0)) | |
535 | - | then true | |
536 | - | else throw("Nothing to claim") | |
537 | - | if ((checkAmount == checkAmount)) | |
538 | - | then { | |
539 | - | let amountFromEmission = 0 | |
540 | - | let claimedReferral = { | |
541 | - | let @ = invoke(referralsContractAddressOrFail, "claim", [referralProgramName], nil) | |
542 | - | if ($isInstanceOf(@, "Int")) | |
543 | - | then @ | |
544 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
545 | - | } | |
546 | - | let totalAmount = (amount + claimedReferral) | |
547 | - | $Tuple2(([ScriptTransfer(i.caller, totalAmount, fromBase58String(cfgArray[IdxCfgAssetId])), HistoryEntry("claim", address, amount, i)] ++ actions), [totalAmount, amountFromEmission]) | |
548 | - | } | |
549 | - | else throw("Strict value is not equal to itself.") | |
550 | - | } | |
551 | - | ||
552 | - | ||
553 | - | ||
554 | - | @Callable(i) | |
555 | 470 | func claimRewardREADONLY (address) = { | |
556 | - | let $ | |
557 | - | let amount = $ | |
558 | - | let actions = $ | |
471 | + | let $t01542315473 = commonClaimReward(address) | |
472 | + | let amount = $t01542315473._1 | |
473 | + | let actions = $t01542315473._2 | |
559 | 474 | let referralUnclaimed = valueOrElse(getInteger(referralsContractAddressOrFail, keyUnclaimedReferral(referralProgramName, address)), 0) | |
560 | 475 | let totalAmount = (amount + referralUnclaimed) | |
561 | 476 | $Tuple2(nil, totalAmount) | |
564 | 479 | ||
565 | 480 | ||
566 | 481 | @Callable(i) | |
567 | - | func latestFinalizedPeriodREADONLY (address) = $Tuple2(nil, valueOrElse(getInteger(this, keyLatestPeriod()), -1)) | |
568 | - | ||
569 | - | ||
570 | - | ||
571 | - | @Callable(i) | |
572 | - | func latestFinalizedPeriodInfoREADONLY (address) = $Tuple2(nil, getStringByKey(keyLastPayoutInfo())) | |
573 | - | ||
574 | - | ||
575 | - | ||
576 | - | @Callable(i) | |
577 | - | func calcGwxParamsREADONLY (gwxAmountStart,lockStartHeight,lockDurationBlocks) = { | |
578 | - | let lockEndHeight = (lockStartHeight + lockDurationBlocks) | |
579 | - | let scale8ParamK = -(fraction(gwxAmountStart, SCALE, lockDurationBlocks)) | |
580 | - | let scale8ParamB = (fraction(gwxAmountStart, SCALE, lockDurationBlocks) * lockEndHeight) | |
581 | - | $Tuple2(nil, [scale8ParamK, scale8ParamB, nextPeriod()]) | |
582 | - | } | |
583 | - | ||
584 | - | ||
585 | - | ||
586 | - | @Callable(i) | |
587 | - | func calcGwxAmountStartREADONLY (wxLockAmount,lockDuration,maxLockDuration) = { | |
588 | - | let coeffX8 = fraction(lockDuration, MULT8, maxLockDuration) | |
589 | - | let gWxAmountStart = fraction(wxLockAmount, coeffX8, MULT8) | |
590 | - | $Tuple2(nil, [gWxAmountStart]) | |
591 | - | } | |
592 | - | ||
593 | - | ||
594 | - | ||
595 | - | @Callable(i) | |
596 | - | func onEmissionForGwxStart () = if ((i.caller != factoryContract)) | |
597 | - | then throw("permissions denied") | |
598 | - | else [IntegerEntry(keyGwxRewardEmissionStartHeight(), height)] | |
599 | - | ||
600 | - | ||
601 | - | ||
602 | - | @Callable(i) | |
603 | - | func latestPeriodEmissionRewardsREADONLY (address) = { | |
604 | - | let period = nextPeriod() | |
605 | - | $Tuple2(nil, [getNumberByKey(keyAuxEmissionRewardForPeriod(period))]) | |
606 | - | } | |
607 | - | ||
608 | - | ||
609 | - | ||
610 | - | @Callable(i) | |
611 | - | func calcD (x1BigIntStr,x2BigIntStr,ampBigIntStr,aPrecisionBigIntStr,targetPrecisionBigIntStr) = { | |
612 | - | let nCoins = toBigInt(2) | |
613 | - | let aPrecision = parseBigIntValue(aPrecisionBigIntStr) | |
614 | - | let targetPrecision = parseBigIntValue(targetPrecisionBigIntStr) | |
615 | - | let x1 = parseBigIntValue(x1BigIntStr) | |
616 | - | let x2 = parseBigIntValue(x2BigIntStr) | |
617 | - | let amp = (parseBigIntValue(ampBigIntStr) * aPrecision) | |
618 | - | let s = (x1 + x2) | |
619 | - | if ((s == zeroBigInt)) | |
620 | - | then $Tuple2(nil, toString(zeroBigInt)) | |
621 | - | else { | |
622 | - | let ann = (amp * nCoins) | |
623 | - | let arr = [0, 1, 2, 3, 4, 5, 6] | |
624 | - | func calc (acc,cur) = { | |
625 | - | let $t02312123148 = acc | |
626 | - | let d = $t02312123148._1 | |
627 | - | let dPrev = $t02312123148._2 | |
628 | - | let found = $t02312123148._3 | |
629 | - | if ((found != unit)) | |
630 | - | then acc | |
631 | - | else { | |
632 | - | let dp = (((d * d) * d) / (((x1 * x2) * nCoins) * nCoins)) | |
633 | - | let dNext = (((((ann * s) / aPrecision) + (dp * nCoins)) * d) / ((((ann - aPrecision) * d) / aPrecision) + ((nCoins + toBigInt(1)) * dp))) | |
634 | - | let dDiff = absBigInt((dNext - value(d))) | |
635 | - | if ((targetPrecision >= dDiff)) | |
636 | - | then $Tuple3(dNext, d, cur) | |
637 | - | else $Tuple3(dNext, d, unit) | |
638 | - | } | |
639 | - | } | |
640 | - | ||
641 | - | let $t02374623809 = { | |
642 | - | let $l = arr | |
643 | - | let $s = size($l) | |
644 | - | let $acc0 = $Tuple3(s, unit, unit) | |
645 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
646 | - | then $a | |
647 | - | else calc($a, $l[$i]) | |
648 | - | ||
649 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
650 | - | then $a | |
651 | - | else throw("List size exceeds 7") | |
652 | - | ||
653 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7) | |
654 | - | } | |
655 | - | let dNext = $t02374623809._1 | |
656 | - | let dPrev = $t02374623809._2 | |
657 | - | let found = $t02374623809._3 | |
658 | - | if ((found != unit)) | |
659 | - | then $Tuple2(nil, toString(dNext)) | |
660 | - | else { | |
661 | - | let dDiff = absBigInt((dNext - value(dPrev))) | |
662 | - | throw(("D calculation error, dDiff = " + toString(dDiff))) | |
663 | - | } | |
664 | - | } | |
482 | + | func onEmissionForGwxStart () = { | |
483 | + | let suspensionCheck = throwIfSuspended() | |
484 | + | if ((suspensionCheck == suspensionCheck)) | |
485 | + | then if ((i.caller != factoryContract)) | |
486 | + | then throw("permissions denied") | |
487 | + | else [IntegerEntry(keyGwxRewardEmissionStartHeight(), height)] | |
488 | + | else throw("Strict value is not equal to itself.") | |
665 | 489 | } | |
666 | 490 | ||
667 | 491 | ||
668 | 492 | ||
669 | 493 | @Callable(i) | |
670 | 494 | func tradeReward (userAddresses,rewards) = { | |
671 | - | let argsComparison = (size(userAddresses) == size(rewards)) | |
672 | - | let maxRecipients = valueOrElse(getInteger(keyMaxRecipients()), 0) | |
673 | - | let payment = i.payments[0] | |
674 | - | let paymentAssetId = payment.assetId | |
675 | - | let paymentAmount = payment.amount | |
676 | - | let checks = [if ((maxRecipients >= size(userAddresses))) | |
677 | - | then true | |
678 | - | else throwErr("Too many recipients"), if (argsComparison) | |
679 | - | then true | |
680 | - | else throwErr("Arguments size mismatch"), if ((paymentAssetId == wxAssetId)) | |
681 | - | then true | |
682 | - | else throwErr("Wrong asset payment")] | |
683 | - | if ((checks == checks)) | |
495 | + | let suspensionCheck = throwIfSuspended() | |
496 | + | if ((suspensionCheck == suspensionCheck)) | |
684 | 497 | then { | |
685 | - | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [paymentAmount, userAddresses, rewards, 0], nil) | |
686 | - | if ((tradeRewardInternal == tradeRewardInternal)) | |
687 | - | then $Tuple2(nil, tradeRewardInternal) | |
498 | + | let argsComparison = (size(userAddresses) == size(rewards)) | |
499 | + | let maxRecipients = valueOrElse(getInteger(keyMaxRecipients()), 0) | |
500 | + | let payment = i.payments[0] | |
501 | + | let paymentAssetId = payment.assetId | |
502 | + | let paymentAmount = payment.amount | |
503 | + | let checks = [if ((maxRecipients >= size(userAddresses))) | |
504 | + | then true | |
505 | + | else throwErr("Too many recipients"), if (argsComparison) | |
506 | + | then true | |
507 | + | else throwErr("Arguments size mismatch"), if ((paymentAssetId == wxAssetId)) | |
508 | + | then true | |
509 | + | else throwErr("Wrong asset payment")] | |
510 | + | if ((checks == checks)) | |
511 | + | then { | |
512 | + | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [paymentAmount, userAddresses, rewards, 0], nil) | |
513 | + | if ((tradeRewardInternal == tradeRewardInternal)) | |
514 | + | then $Tuple2(nil, tradeRewardInternal) | |
515 | + | else throw("Strict value is not equal to itself.") | |
516 | + | } | |
688 | 517 | else throw("Strict value is not equal to itself.") | |
689 | 518 | } | |
690 | 519 | else throw("Strict value is not equal to itself.") | |
694 | 523 | ||
695 | 524 | @Callable(i) | |
696 | 525 | func claimTradingReward () = { | |
697 | - | let userAddress = i.caller | |
698 | - | let userAddressString = toString(userAddress) | |
699 | - | let reward = getTradingReward(userAddressString) | |
700 | - | if ((reward > 0)) | |
701 | - | then $Tuple2([ScriptTransfer(userAddress, reward, wxAssetId), IntegerEntry(keyTradingReward(userAddressString), 0)], reward) | |
702 | - | else throwErr("nothing to claim") | |
526 | + | let suspensionCheck = throwIfSuspended() | |
527 | + | if ((suspensionCheck == suspensionCheck)) | |
528 | + | then { | |
529 | + | let userAddress = i.caller | |
530 | + | let userAddressString = toString(userAddress) | |
531 | + | let reward = getTradingReward(userAddressString) | |
532 | + | if ((reward > 0)) | |
533 | + | then $Tuple2([ScriptTransfer(userAddress, reward, wxAssetId), IntegerEntry(keyTradingReward(userAddressString), 0)], reward) | |
534 | + | else throwErr("nothing to claim") | |
535 | + | } | |
536 | + | else throw("Strict value is not equal to itself.") | |
703 | 537 | } | |
704 | 538 | ||
705 | 539 | ||
706 | 540 | ||
707 | 541 | @Callable(i) | |
708 | 542 | func claimTradingRewardREADONLY (userAddress) = $Tuple2(nil, getTradingReward(userAddress)) | |
543 | + | ||
544 | + | ||
545 | + | ||
546 | + | @Callable(i) | |
547 | + | func suspend (v) = { | |
548 | + | let checkCaller = mustManager(i) | |
549 | + | if ((checkCaller == checkCaller)) | |
550 | + | then $Tuple2([BooleanEntry(keySuspension, v)], v) | |
551 | + | else throw("Strict value is not equal to itself.") | |
552 | + | } | |
709 | 553 | ||
710 | 554 | ||
711 | 555 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | 6 | let SCALE = 1000 | |
7 | 7 | ||
8 | 8 | let MULT8 = 100000000 | |
9 | 9 | ||
10 | + | let MULT8BI = toBigInt(MULT8) | |
11 | + | ||
10 | 12 | let zeroBigInt = toBigInt(0) | |
11 | 13 | ||
12 | 14 | let processingStageTotal = 0 | |
13 | 15 | ||
14 | 16 | let processingStageShares = 1 | |
15 | 17 | ||
18 | + | let MULT18 = 1000000000000000000 | |
19 | + | ||
20 | + | let MULT18BI = toBigInt(MULT18) | |
21 | + | ||
16 | 22 | let wavesString = "WAVES" | |
23 | + | ||
24 | + | func wrapErr (msg) = makeString(["gwx_reward.ride:", msg], " ") | |
25 | + | ||
26 | + | ||
27 | + | func throwErr (msg) = throw(wrapErr(msg)) | |
28 | + | ||
17 | 29 | ||
18 | 30 | func getNumberByKey (key) = valueOrElse(getInteger(this, key), 0) | |
19 | 31 | ||
20 | 32 | ||
21 | - | func getNumberOrFail (key) = valueOrErrorMessage(getInteger(this, key), (("mandatory this." + key) + " is not defined")) | |
33 | + | func getNumberOrFail (key) = valueOrErrorMessage(getInteger(this, key), wrapErr((("mandatory this." + key) + " is not defined"))) | |
22 | 34 | ||
23 | 35 | ||
24 | 36 | func getStringByKey (key) = valueOrElse(getString(this, key), "") | |
25 | 37 | ||
26 | 38 | ||
27 | - | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), (("mandatory this." + key) + " is not defined")) | |
39 | + | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), wrapErr((("mandatory this." + key) + " is not defined"))) | |
28 | 40 | ||
29 | 41 | ||
30 | 42 | func parseAssetId (input) = if ((input == wavesString)) | |
31 | 43 | then unit | |
32 | 44 | else fromBase58String(input) | |
33 | - | ||
34 | - | ||
35 | - | func wrapErr (msg) = makeString(["gwx_reward.ride:", msg], " ") | |
36 | - | ||
37 | - | ||
38 | - | func throwErr (msg) = throw(wrapErr(msg)) | |
39 | 45 | ||
40 | 46 | ||
41 | 47 | func abs (val) = if ((0 > val)) | |
42 | 48 | then -(val) | |
43 | 49 | else val | |
44 | 50 | ||
45 | 51 | ||
46 | 52 | func absBigInt (val) = if ((zeroBigInt > val)) | |
47 | 53 | then -(val) | |
48 | 54 | else val | |
49 | 55 | ||
50 | 56 | ||
51 | 57 | let keyMaxDepth = "%s__maxDepth" | |
52 | 58 | ||
53 | 59 | let maxDepthDefault = 30 | |
54 | 60 | ||
55 | 61 | let maxDepth = valueOrElse(getInteger(this, keyMaxDepth), maxDepthDefault) | |
56 | 62 | ||
57 | 63 | func keyFactoryAddress () = "%s%s__config__factoryAddress" | |
58 | 64 | ||
59 | 65 | ||
60 | 66 | let factoryAddressStr = getStringOrFail(keyFactoryAddress()) | |
61 | 67 | ||
62 | 68 | let factoryContract = addressFromStringValue(factoryAddressStr) | |
63 | 69 | ||
64 | 70 | func keyEmissionAddress () = "%s%s__config__emissionAddress" | |
65 | 71 | ||
66 | 72 | ||
67 | 73 | func keyVotingEmissionContract () = makeString(["%s", "votingEmissionContract"], SEP) | |
68 | 74 | ||
69 | 75 | ||
70 | 76 | let votingEmissionContract = addressFromStringValue(getStringValue(factoryContract, keyVotingEmissionContract())) | |
71 | 77 | ||
72 | 78 | func keyNumToUserMapping (num) = makeString(["%s%s%s", "mapping", "num2user", toString(num)], SEP) | |
73 | 79 | ||
74 | 80 | ||
75 | 81 | let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP) | |
76 | 82 | ||
77 | 83 | let referralProgramNameDefault = "wxlock" | |
78 | 84 | ||
79 | 85 | let referralProgramName = valueOrElse(getString(this, keyReferralProgramName), referralProgramNameDefault) | |
80 | 86 | ||
81 | 87 | let keyReferralMinGWxAmount = makeString(["%s%s", "referral", "minGWxAmount"], SEP) | |
82 | 88 | ||
83 | 89 | let referralMinGWxAmountDefault = (500 * MULT8) | |
84 | 90 | ||
85 | 91 | let referralMinGWxAmount = valueOrElse(getInteger(this, keyReferralMinGWxAmount), referralMinGWxAmountDefault) | |
86 | 92 | ||
87 | 93 | let keyReferrerRewardPermille = makeString(["%s%s", "referral", "referrerRewardPermille"], SEP) | |
88 | 94 | ||
89 | 95 | let referrerRewardPermilleDefault = 50 | |
90 | 96 | ||
91 | 97 | let referrerRewardPermille = valueOrElse(getInteger(this, keyReferrerRewardPermille), referrerRewardPermilleDefault) | |
92 | 98 | ||
93 | 99 | let keyReferralRewardPermille = makeString(["%s%s", "referral", "referralRewardPermille"], SEP) | |
94 | 100 | ||
95 | 101 | let referralRewardPermilleDefault = 50 | |
96 | 102 | ||
97 | 103 | let referralRewardPermille = valueOrElse(getInteger(this, keyReferralRewardPermille), referralRewardPermilleDefault) | |
98 | 104 | ||
99 | 105 | func keyReferrer (referralAddress) = makeString(["%s%s%s", "referrer", referralProgramName, referralAddress], SEP) | |
100 | 106 | ||
101 | 107 | ||
102 | 108 | func keyUnclaimedReferral (programName,claimerAddress) = makeString(["%s%s%s", "unclaimedReferral", programName, claimerAddress], SEP) | |
103 | 109 | ||
104 | 110 | ||
105 | 111 | let emissionAddressStr = getStringOrFail(keyEmissionAddress()) | |
106 | 112 | ||
107 | 113 | let emissionContract = addressFromStringValue(emissionAddressStr) | |
108 | 114 | ||
109 | 115 | let IdxCfgAssetId = 1 | |
110 | 116 | ||
111 | 117 | let IdxCfgPacemakerAddress = 2 | |
112 | 118 | ||
113 | 119 | let IdxCfgBoostingContract = 3 | |
114 | 120 | ||
115 | 121 | let IdxCfgMaxDepth = 4 | |
116 | 122 | ||
117 | 123 | func keyConfig () = "%s__config" | |
118 | 124 | ||
119 | 125 | ||
120 | 126 | func getEmissionAddress () = addressFromStringValue(valueOrErrorMessage(getString(this, keyEmissionAddress()), (("mandatory this." + keyEmissionAddress()) + " is not defined"))) | |
121 | 127 | ||
122 | 128 | ||
123 | 129 | let emissionAddress = getEmissionAddress() | |
124 | 130 | ||
125 | 131 | let wxAssetIdStr = split(value(getString(emissionAddress, keyConfig())), SEP)[1] | |
126 | 132 | ||
127 | 133 | let wxAssetId = fromBase58String(wxAssetIdStr) | |
128 | 134 | ||
129 | 135 | func readConfigArrayOrFail () = split(getStringOrFail(keyConfig()), SEP) | |
130 | 136 | ||
131 | 137 | ||
132 | 138 | func formatConfig (wxAssetIdStr,matcherPacemakerAddressStr,boostingContractAddressStr,maxDepth) = makeString(["%s%s%s%d", wxAssetIdStr, matcherPacemakerAddressStr, boostingContractAddressStr, toString(maxDepth)], SEP) | |
133 | 139 | ||
134 | 140 | ||
135 | 141 | func boostingContractOrFail () = { | |
136 | 142 | let cfgArray = readConfigArrayOrFail() | |
137 | 143 | valueOrErrorMessage(addressFromString(cfgArray[IdxCfgBoostingContract]), "boosting contract address is not defined") | |
138 | 144 | } | |
139 | 145 | ||
140 | 146 | ||
147 | + | let keySuspension = "%s__suspension" | |
148 | + | ||
149 | + | let isSuspended = valueOrElse(getBoolean(this, keySuspension), false) | |
150 | + | ||
151 | + | func throwIfSuspended () = if (!(isSuspended)) | |
152 | + | then true | |
153 | + | else throwErr("suspended") | |
154 | + | ||
155 | + | ||
141 | 156 | func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight" | |
142 | 157 | ||
143 | 158 | ||
144 | 159 | func keyUsersCount () = "%s__nextUserNum" | |
160 | + | ||
161 | + | ||
162 | + | func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", toString(userAddress)], SEP) | |
145 | 163 | ||
146 | 164 | ||
147 | 165 | func keyRatePerBlockCurrent () = "%s%s__ratePerBlock__current" | |
148 | 166 | ||
149 | 167 | ||
150 | 168 | func keyGwxHoldersRewardCurrent () = "%s%s__gwxHoldersReward__current" | |
151 | 169 | ||
152 | 170 | ||
153 | 171 | func keyGwxHoldersRewardNext () = "%s%s__gwxHoldersReward__next" | |
154 | 172 | ||
155 | 173 | ||
156 | 174 | func keyPoolWeightVirtual () = "%s%s__poolWeight__GWXvirtualPOOL" | |
157 | 175 | ||
158 | 176 | ||
159 | - | func keyNextProcessedUser () = "%s__nextProcessedUser" | |
160 | - | ||
161 | - | ||
162 | - | func keyLatestPeriod () = "%s__latestPeriod" | |
163 | - | ||
164 | - | ||
165 | - | func keyNextPeriod () = "%s__nextPeriod" | |
166 | - | ||
167 | - | ||
168 | - | func keyProcessingStage () = "%s__processingStage" | |
169 | - | ||
170 | - | ||
171 | - | func keyNextProcessedPeriod () = "%s__nextProcessedPeriod" | |
172 | - | ||
173 | - | ||
174 | 177 | func keyUserUnclaimed (userIndex) = makeString(["%s%d", "userUnclaimed", toString(userIndex)], SEP) | |
175 | - | ||
176 | - | ||
177 | - | func keyNextUnlaimedPeriodOfUser (userIndex) = makeString(["%s%d__nextClaimedPeriod", toString(userIndex)], SEP) | |
178 | - | ||
179 | - | ||
180 | - | func keyLastProcessedPeriodOfUser (userIndex) = makeString(["%s%d__lastProcessedPeriod", toString(userIndex)], SEP) | |
181 | - | ||
182 | - | ||
183 | - | func keyHeightForPeriod (period) = makeString(["%s%d__startHeightForPeriod", toString(period)], SEP) | |
184 | - | ||
185 | - | ||
186 | - | func keyAuxEmissionRewardForPeriod (period) = makeString(["%s%d__auxEmissionReward", toString(period)], SEP) | |
187 | - | ||
188 | - | ||
189 | - | func keyTotalAmountForPeriod (period) = makeString(["%s%d__totalAmountForPeriod", toString(period)], SEP) | |
190 | - | ||
191 | - | ||
192 | - | func keyLastPayoutInfo () = "%s__lastPayoutInfo" | |
193 | - | ||
194 | - | ||
195 | - | func PeriodPayoutInfo (period,matcherReward,emissionReward) = makeString(["%d%d%d", toString(period), toString(matcherReward), toString(emissionReward)], SEP) | |
196 | - | ||
197 | - | ||
198 | - | func keyPayoutHistoryInfo (period) = makeString(["%s%s%d__payouts__history", toString(period)], SEP) | |
199 | - | ||
200 | - | ||
201 | - | func keyTotalWeightForPeriod (period) = makeString(["%s%d__totalWeightForPeriod", toString(period)], SEP) | |
202 | - | ||
203 | - | ||
204 | - | func keyUserKValueForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "k", toString(period)], SEP) | |
205 | - | ||
206 | - | ||
207 | - | func keyUserBValueForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "b", toString(period)], SEP) | |
208 | - | ||
209 | - | ||
210 | - | func keyUserWeightForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "weight", toString(period)], SEP) | |
211 | 178 | ||
212 | 179 | ||
213 | 180 | func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP) | |
214 | 181 | ||
215 | 182 | ||
216 | 183 | let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(keyReferralsContractAddress())) | |
217 | 184 | ||
218 | 185 | func keyTradingRewardHistory (user,i) = makeString(["%s%s%s%s", "tradingReward", "history", user, toBase58String(i.transactionId)], SEP) | |
219 | 186 | ||
220 | 187 | ||
221 | 188 | func keyTradingReward (userAddress) = makeString(["%s%s", "tradingReward", userAddress], SEP) | |
222 | 189 | ||
223 | 190 | ||
224 | 191 | func keyMaxRecipients () = makeString(["%s", "maxRecipients"], SEP) | |
225 | 192 | ||
226 | 193 | ||
227 | 194 | func HistoryEntry (type,user,amount,i) = { | |
228 | 195 | let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], SEP) | |
229 | 196 | let historyDATA = makeString(["%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount)], SEP) | |
230 | 197 | StringEntry(historyKEY, historyDATA) | |
231 | 198 | } | |
232 | 199 | ||
233 | 200 | ||
234 | 201 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
235 | 202 | ||
236 | 203 | ||
237 | 204 | func keyManagerVaultAddress () = "%s__managerVaultAddress" | |
238 | 205 | ||
239 | 206 | ||
240 | 207 | func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) { | |
241 | 208 | case s: String => | |
242 | 209 | addressFromStringValue(s) | |
243 | 210 | case _ => | |
244 | 211 | this | |
245 | 212 | } | |
246 | 213 | ||
247 | 214 | ||
248 | 215 | func managerPublicKeyOrUnit () = { | |
249 | 216 | let managerVaultAddress = getManagerVaultAddressOrThis() | |
250 | 217 | match getString(managerVaultAddress, keyManagerPublicKey()) { | |
251 | 218 | case s: String => | |
252 | 219 | fromBase58String(s) | |
253 | 220 | case _: Unit => | |
254 | 221 | unit | |
255 | 222 | case _ => | |
256 | 223 | throw("Match error") | |
257 | 224 | } | |
258 | 225 | } | |
259 | 226 | ||
260 | 227 | ||
261 | 228 | func mustManager (i) = { | |
262 | 229 | let pd = throw("Permission denied") | |
263 | 230 | match managerPublicKeyOrUnit() { | |
264 | 231 | case pk: ByteVector => | |
265 | 232 | if ((i.callerPublicKey == pk)) | |
266 | 233 | then true | |
267 | 234 | else pd | |
268 | 235 | case _: Unit => | |
269 | 236 | if ((i.caller == this)) | |
270 | 237 | then true | |
271 | 238 | else pd | |
272 | 239 | case _ => | |
273 | 240 | throw("Match error") | |
274 | 241 | } | |
275 | 242 | } | |
276 | 243 | ||
277 | 244 | ||
278 | - | func calcUserWeight (boostingContractAddress,heightForPeriod,period,userIndex) = { | |
279 | - | let kLast = keyLastProcessedPeriodOfUser(userIndex) | |
280 | - | let kKey = keyUserKValueForPeriod(period, userIndex) | |
281 | - | let kRaw = getInteger(boostingContractAddress, kKey) | |
282 | - | let kUserWeight = keyUserWeightForPeriod(period, userIndex) | |
283 | - | if (isDefined(kRaw)) | |
284 | - | then { | |
285 | - | let k = value(kRaw) | |
286 | - | let b = value(getInteger(boostingContractAddress, keyUserBValueForPeriod(period, userIndex))) | |
287 | - | let w = ((k * heightForPeriod) + b) | |
288 | - | if ((w > 0)) | |
289 | - | then $Tuple2((w / SCALE), [IntegerEntry(kLast, period), IntegerEntry(kUserWeight, w)]) | |
290 | - | else $Tuple2(0, nil) | |
291 | - | } | |
292 | - | else { | |
293 | - | let p = getInteger(this, kLast) | |
294 | - | if (if (isDefined(p)) | |
295 | - | then (period >= value(p)) | |
296 | - | else false) | |
297 | - | then { | |
298 | - | let pv = value(p) | |
299 | - | let k = value(getInteger(boostingContractAddress, keyUserKValueForPeriod(pv, userIndex))) | |
300 | - | let b = value(getInteger(boostingContractAddress, keyUserBValueForPeriod(pv, userIndex))) | |
301 | - | let w = ((k * heightForPeriod) + b) | |
302 | - | if ((w > 0)) | |
303 | - | then $Tuple2((w / SCALE), [IntegerEntry(kUserWeight, w)]) | |
304 | - | else $Tuple2(0, nil) | |
305 | - | } | |
306 | - | else $Tuple2(0, nil) | |
307 | - | } | |
308 | - | } | |
309 | - | ||
310 | - | ||
311 | - | func calcUserWeightForClaim (boostingContractAddress,heightForPeriod,period,userIndex) = { | |
312 | - | let kUserWeight = keyUserWeightForPeriod(period, userIndex) | |
313 | - | let userWeightOrUnit = getInteger(kUserWeight) | |
314 | - | match userWeightOrUnit { | |
315 | - | case _: Unit => | |
316 | - | 0 | |
317 | - | case w: Int => | |
318 | - | (w / SCALE) | |
319 | - | case _ => | |
320 | - | throw("Match error") | |
321 | - | } | |
322 | - | } | |
323 | - | ||
324 | - | ||
325 | 245 | func getUserIndexByAddress (boostingContractAddressStr,userAddress) = { | |
326 | 246 | let key = makeString(["%s%s%s", "mapping", "user2num", userAddress], SEP) | |
327 | 247 | parseIntValue(valueOrErrorMessage(getString(Address(fromBase58String(boostingContractAddressStr)), key), ((("User address " + userAddress) + " is not found in boosting contract data, key=") + key))) | |
328 | 248 | } | |
329 | 249 | ||
330 | 250 | ||
331 | - | func | |
251 | + | func getTradingReward (userAddress) = valueOrElse(getInteger(this, keyTradingReward(userAddress)), 0) | |
332 | 252 | ||
333 | 253 | ||
334 | - | func commonClaimReward (userAddress) = { | |
335 | - | let cfgArray = readConfigArrayOrFail() | |
336 | - | let userIdx = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddress) | |
337 | - | let userUnclaimedOption = getInteger(keyUserUnclaimed(userIdx)) | |
338 | - | match userUnclaimedOption { | |
254 | + | func keyRewardPerGwxIntegral () = makeString(["%s", "rewardPerGwxIntegral"], SEP) | |
255 | + | ||
256 | + | ||
257 | + | func getGwxAmountTotalOption () = { | |
258 | + | let keyGwxTotal = "%s%s__gwx__total" | |
259 | + | getInteger(boostingContractOrFail(), keyGwxTotal) | |
260 | + | } | |
261 | + | ||
262 | + | ||
263 | + | func getUserGwxAmountTotalOption (userAddress) = { | |
264 | + | func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP) | |
265 | + | ||
266 | + | getInteger(boostingContractOrFail(), keyUserGwxAmountTotal(userAddress)) | |
267 | + | } | |
268 | + | ||
269 | + | ||
270 | + | func _refreshRewardPerGwxIntegral () = { | |
271 | + | let rewardPerGwxIntegralPrevious = valueOrElse( match getString(this, keyRewardPerGwxIntegral()) { | |
272 | + | case s: String => | |
273 | + | parseBigInt(s) | |
339 | 274 | case _: Unit => | |
340 | - | $Tuple2(0, nil) | |
341 | - | case u: Int => | |
342 | - | $Tuple2(u, [IntegerEntry(keyUserUnclaimed(userIdx), 0)]) | |
275 | + | unit | |
276 | + | case _ => | |
277 | + | throw("Match error") | |
278 | + | }, zeroBigInt) | |
279 | + | let rewardPerGwxIntegralLastHeight = valueOrErrorMessage(getInteger(this, keyGwxRewardEmissionStartHeight()), wrapErr(("invalid " + keyGwxRewardEmissionStartHeight()))) | |
280 | + | let emissionRate = valueOrErrorMessage(getInteger(emissionContract, keyRatePerBlockCurrent()), wrapErr(("invalid " + keyRatePerBlockCurrent()))) | |
281 | + | let gwxHoldersRewardCurrent = valueOrElse(getInteger(emissionContract, keyGwxHoldersRewardCurrent()), 0) | |
282 | + | let gwxAmountTotal = valueOrElse(getGwxAmountTotalOption(), 0) | |
283 | + | let dh = toBigInt((height - rewardPerGwxIntegralLastHeight)) | |
284 | + | let gwxAmountTotalBI = toBigInt(gwxAmountTotal) | |
285 | + | let rewardPerGwxIntegral = (rewardPerGwxIntegralPrevious + (if ((gwxAmountTotalBI == zeroBigInt)) | |
286 | + | then zeroBigInt | |
287 | + | else fraction(dh, ((toBigInt(emissionRate) * toBigInt(gwxHoldersRewardCurrent)) * MULT18BI), (gwxAmountTotalBI * MULT8BI)))) | |
288 | + | $Tuple2([IntegerEntry(keyGwxRewardEmissionStartHeight(), height), StringEntry(keyRewardPerGwxIntegral(), toString(rewardPerGwxIntegral))], rewardPerGwxIntegral) | |
289 | + | } | |
290 | + | ||
291 | + | ||
292 | + | func keyRewardPerGwxIntegralUserLast (userAddress) = makeString(["%s%s", "rewardPerGwxIntegralUserLast", toString(userAddress)], SEP) | |
293 | + | ||
294 | + | ||
295 | + | func _refreshUserReward (userAddress,userNum) = { | |
296 | + | let $t01029210380 = _refreshRewardPerGwxIntegral() | |
297 | + | let rewardPerGwxIntegralActions = $t01029210380._1 | |
298 | + | let rewardPerGwxIntegral = $t01029210380._2 | |
299 | + | let rewardPerGwxIntegralUserLast = match getString(this, keyRewardPerGwxIntegralUserLast(userAddress)) { | |
300 | + | case s: String => | |
301 | + | valueOrErrorMessage(parseBigInt(s), wrapErr("invalid user last integral")) | |
302 | + | case _: Unit => | |
303 | + | rewardPerGwxIntegral | |
343 | 304 | case _ => | |
344 | 305 | throw("Match error") | |
345 | 306 | } | |
307 | + | let userIdxOption = getString(boostingContractOrFail(), keyUser2NumMapping(userAddress)) | |
308 | + | let userUnclaimed = valueOrElse(getInteger(keyUserUnclaimed(userNum)), 0) | |
309 | + | let userGwxAmount = valueOrElse(getUserGwxAmountTotalOption(userAddress), 0) | |
310 | + | let userReward = (toInt(fraction(toBigInt(userGwxAmount), (rewardPerGwxIntegral - rewardPerGwxIntegralUserLast), MULT18BI)) + userUnclaimed) | |
311 | + | $Tuple2(([StringEntry(keyRewardPerGwxIntegralUserLast(userAddress), toString(rewardPerGwxIntegral))] ++ rewardPerGwxIntegralActions), userReward) | |
346 | 312 | } | |
347 | 313 | ||
348 | 314 | ||
349 | - | func getTradingReward (userAddress) = valueOrElse(getInteger(this, keyTradingReward(userAddress)), 0) | |
315 | + | func commonClaimReward (userAddressStr) = { | |
316 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
317 | + | let cfgArray = readConfigArrayOrFail() | |
318 | + | let userNum = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddressStr) | |
319 | + | let $t01167111735 = _refreshUserReward(userAddress, userNum) | |
320 | + | let actions = $t01167111735._1 | |
321 | + | let reward = $t01167111735._2 | |
322 | + | $Tuple2(reward, ([IntegerEntry(keyUserUnclaimed(userNum), 0)] ++ actions)) | |
323 | + | } | |
350 | 324 | ||
351 | 325 | ||
352 | 326 | @Callable(i) | |
353 | - | func tradeRewardInternal (paymentAmountLeftOver,userAddresses,rewards,currentIter) = if ((currentIter == size(userAddresses))) | |
354 | - | then nil | |
355 | - | else { | |
356 | - | let checks = [if ((i.caller == this)) | |
357 | - | then true | |
358 | - | else throwErr("Permission denied"), if ((paymentAmountLeftOver >= rewards[currentIter])) | |
359 | - | then true | |
360 | - | else throwErr("insufficient payment assetId")] | |
361 | - | if ((checks == checks)) | |
362 | - | then { | |
363 | - | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [(paymentAmountLeftOver - rewards[currentIter]), userAddresses, rewards, (currentIter + 1)], nil) | |
364 | - | if ((tradeRewardInternal == tradeRewardInternal)) | |
365 | - | then { | |
366 | - | let tradingRewardHistoryKey = keyTradingRewardHistory(userAddresses[currentIter], i) | |
367 | - | let userAddress = addressFromStringValue(userAddresses[currentIter]) | |
368 | - | $Tuple2([IntegerEntry(tradingRewardHistoryKey, rewards[currentIter]), IntegerEntry(keyTradingReward(userAddresses[currentIter]), rewards[currentIter])], tradeRewardInternal) | |
369 | - | } | |
370 | - | else throw("Strict value is not equal to itself.") | |
371 | - | } | |
372 | - | else throw("Strict value is not equal to itself.") | |
373 | - | } | |
374 | - | ||
375 | - | ||
376 | - | ||
377 | - | @Callable(i) | |
378 | - | func updateReferralActivity (userAddress,gWxAmountStart) = { | |
379 | - | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) | |
380 | - | let activeReferralInv = if ((referrer == unit)) | |
381 | - | then unit | |
382 | - | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (gWxAmountStart >= referralMinGWxAmount)], nil) | |
383 | - | if ((activeReferralInv == activeReferralInv)) | |
384 | - | then $Tuple2(nil, unit) | |
327 | + | func refreshUserReward (userAddressBytes,userNum) = { | |
328 | + | let suspensionCheck = throwIfSuspended() | |
329 | + | if ((suspensionCheck == suspensionCheck)) | |
330 | + | then { | |
331 | + | let checkCaller = if ((i.caller == boostingContractOrFail())) | |
332 | + | then true | |
333 | + | else throwErr("permission denied") | |
334 | + | if ((checkCaller == checkCaller)) | |
335 | + | then { | |
336 | + | let $t01206112139 = _refreshUserReward(Address(userAddressBytes), userNum) | |
337 | + | let actions = $t01206112139._1 | |
338 | + | let reward = $t01206112139._2 | |
339 | + | $Tuple2(([IntegerEntry(keyUserUnclaimed(userNum), reward)] ++ actions), reward) | |
340 | + | } | |
341 | + | else throw("Strict value is not equal to itself.") | |
342 | + | } | |
385 | 343 | else throw("Strict value is not equal to itself.") | |
386 | 344 | } | |
387 | 345 | ||
388 | 346 | ||
389 | 347 | ||
390 | 348 | @Callable(i) | |
391 | - | func finalizeHelper () = { | |
392 | - | let processingStage = valueOrElse(getInteger(keyProcessingStage()), processingStageTotal) | |
393 | - | let currentPeriod = getNumberByKey(keyNextProcessedPeriod()) | |
394 | - | let currentUser = getNumberByKey(keyNextProcessedUser()) | |
395 | - | let latestPeriod = getNumberByKey(keyLatestPeriod()) | |
396 | - | let usersCount = valueOrElse(getInteger(boostingContractOrFail(), keyUsersCount()), 0) | |
397 | - | let totalWeightKey = keyTotalWeightForPeriod(currentPeriod) | |
398 | - | let totalWeight = getNumberByKey(keyTotalWeightForPeriod(currentPeriod)) | |
399 | - | let heightForPeriod = getNumberByKey(keyHeightForPeriod(currentPeriod)) | |
400 | - | if ((currentPeriod > latestPeriod)) | |
401 | - | then $Tuple2(nil, false) | |
402 | - | else if ((processingStage == processingStageTotal)) | |
403 | - | then { | |
404 | - | let $t01451014626 = calcUserWeight(boostingContractOrFail(), heightForPeriod, currentPeriod, currentUser) | |
405 | - | let userWeight = $t01451014626._1 | |
406 | - | let userActions = $t01451014626._2 | |
407 | - | let totalWeightNew = (totalWeight + userWeight) | |
408 | - | let processingActions = if (((usersCount - 1) > currentUser)) | |
409 | - | then [IntegerEntry(keyNextProcessedUser(), (currentUser + 1))] | |
410 | - | else [IntegerEntry(keyProcessingStage(), processingStageShares), IntegerEntry(keyNextProcessedUser(), 0)] | |
411 | - | $Tuple2((([IntegerEntry(totalWeightKey, totalWeightNew)] ++ processingActions) ++ userActions), true) | |
349 | + | func tradeRewardInternal (paymentAmountLeftOver,userAddresses,rewards,currentIter) = { | |
350 | + | let suspensionCheck = throwIfSuspended() | |
351 | + | if ((suspensionCheck == suspensionCheck)) | |
352 | + | then if ((currentIter == size(userAddresses))) | |
353 | + | then nil | |
354 | + | else { | |
355 | + | let checks = [if ((i.caller == this)) | |
356 | + | then true | |
357 | + | else throwErr("Permission denied"), if ((paymentAmountLeftOver >= rewards[currentIter])) | |
358 | + | then true | |
359 | + | else throwErr("insufficient payment assetId")] | |
360 | + | if ((checks == checks)) | |
361 | + | then { | |
362 | + | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [(paymentAmountLeftOver - rewards[currentIter]), userAddresses, rewards, (currentIter + 1)], nil) | |
363 | + | if ((tradeRewardInternal == tradeRewardInternal)) | |
364 | + | then { | |
365 | + | let tradingRewardHistoryKey = keyTradingRewardHistory(userAddresses[currentIter], i) | |
366 | + | let userAddress = addressFromStringValue(userAddresses[currentIter]) | |
367 | + | $Tuple2([IntegerEntry(tradingRewardHistoryKey, rewards[currentIter]), IntegerEntry(keyTradingReward(userAddresses[currentIter]), rewards[currentIter])], tradeRewardInternal) | |
368 | + | } | |
369 | + | else throw("Strict value is not equal to itself.") | |
370 | + | } | |
371 | + | else throw("Strict value is not equal to itself.") | |
412 | 372 | } | |
413 | - | else if ((processingStage == processingStageShares)) | |
414 | - | then { | |
415 | - | let userWeight = calcUserWeightForClaim(boostingContractOrFail(), heightForPeriod, currentPeriod, currentUser) | |
416 | - | let userAmountMatcherForPeriod = fraction(getNumberByKey(keyTotalAmountForPeriod(currentPeriod)), userWeight, totalWeight) | |
417 | - | let userAmountEmissionForPeriod = fraction(getNumberByKey(keyAuxEmissionRewardForPeriod(currentPeriod)), userWeight, totalWeight) | |
418 | - | let userTotalAmount = (userAmountEmissionForPeriod + userAmountMatcherForPeriod) | |
419 | - | let userUnclaimedOption = getInteger(keyUserUnclaimed(currentUser)) | |
420 | - | let userAddress = getStringValue(boostingContractOrFail(), keyNumToUserMapping(currentUser)) | |
421 | - | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) | |
422 | - | let activeReferralInv = if ((referrer == unit)) | |
423 | - | then unit | |
424 | - | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (userWeight >= referralMinGWxAmount)], nil) | |
425 | - | if ((activeReferralInv == activeReferralInv)) | |
426 | - | then { | |
427 | - | let referralInv = if (if ((referrer == unit)) | |
428 | - | then true | |
429 | - | else (referralMinGWxAmount > userWeight)) | |
430 | - | then unit | |
431 | - | else { | |
432 | - | let referrerReward = fraction(userTotalAmount, referrerRewardPermille, SCALE) | |
433 | - | let referralReward = fraction(userTotalAmount, referralRewardPermille, SCALE) | |
434 | - | invoke(referralsContractAddressOrFail, "incUnclaimed", [referralProgramName, userAddress, referrerReward, referralReward], nil) | |
435 | - | } | |
436 | - | if ((referralInv == referralInv)) | |
437 | - | then { | |
438 | - | let unclaimedActions = [IntegerEntry(keyUserUnclaimed(currentUser), (valueOrElse(userUnclaimedOption, 0) + userTotalAmount))] | |
439 | - | let processingActions = if (((usersCount - 1) > currentUser)) | |
440 | - | then [IntegerEntry(keyNextProcessedUser(), (currentUser + 1))] | |
441 | - | else [IntegerEntry(keyNextProcessedPeriod(), (currentPeriod + 1)), IntegerEntry(keyNextProcessedUser(), 0), DeleteEntry(keyProcessingStage())] | |
442 | - | $Tuple2((unclaimedActions ++ processingActions), true) | |
443 | - | } | |
444 | - | else throw("Strict value is not equal to itself.") | |
445 | - | } | |
446 | - | else throw("Strict value is not equal to itself.") | |
447 | - | } | |
448 | - | else throw("invalid processing stage") | |
449 | - | } | |
450 | - | ||
451 | - | ||
452 | - | ||
453 | - | @Callable(i) | |
454 | - | func finalizeWrapper (counter) = { | |
455 | - | let result = { | |
456 | - | let @ = invoke(this, "finalizeHelper", nil, nil) | |
457 | - | if ($isInstanceOf(@, "Boolean")) | |
458 | - | then @ | |
459 | - | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
460 | - | } | |
461 | - | if ((result == result)) | |
462 | - | then if (!(result)) | |
463 | - | then if ((counter == maxDepth)) | |
464 | - | then throw("Nothing to process") | |
465 | - | else $Tuple2(nil, unit) | |
466 | - | else if ((counter > 0)) | |
467 | - | then $Tuple2(nil, invoke(this, "finalizeWrapper", [(counter - 1)], nil)) | |
468 | - | else $Tuple2(nil, unit) | |
469 | 373 | else throw("Strict value is not equal to itself.") | |
470 | 374 | } | |
471 | 375 | ||
472 | 376 | ||
473 | 377 | ||
474 | 378 | @Callable(i) | |
475 | - | func processPendingPeriodsAndUsers () = $Tuple2(nil, invoke(this, "finalizeWrapper", [maxDepth], nil)) | |
379 | + | func updateReferralActivity (userAddress,gWxAmountStart) = { | |
380 | + | let suspensionCheck = throwIfSuspended() | |
381 | + | if ((suspensionCheck == suspensionCheck)) | |
382 | + | then { | |
383 | + | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) | |
384 | + | let activeReferralInv = if ((referrer == unit)) | |
385 | + | then unit | |
386 | + | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (gWxAmountStart >= referralMinGWxAmount)], nil) | |
387 | + | if ((activeReferralInv == activeReferralInv)) | |
388 | + | then $Tuple2(nil, unit) | |
389 | + | else throw("Strict value is not equal to itself.") | |
390 | + | } | |
391 | + | else throw("Strict value is not equal to itself.") | |
392 | + | } | |
476 | 393 | ||
477 | 394 | ||
478 | 395 | ||
479 | 396 | @Callable(i) | |
480 | - | func deposit () = { | |
481 | - | let checkCaller = if ((i.caller == votingEmissionContract)) | |
482 | - | then true | |
483 | - | else mustManager(i) | |
484 | - | if ((checkCaller == checkCaller)) | |
397 | + | func processPendingPeriodsAndUsers () = $Tuple2(nil, throwErr("deprecated")) | |
398 | + | ||
399 | + | ||
400 | + | ||
401 | + | @Callable(i) | |
402 | + | func claimReward () = { | |
403 | + | let suspensionCheck = throwIfSuspended() | |
404 | + | if ((suspensionCheck == suspensionCheck)) | |
485 | 405 | then { | |
486 | - | let period = nextPeriod() | |
487 | - | let deltaH = (height - getNumberOrFail(keyGwxRewardEmissionStartHeight())) | |
488 | - | let emissionRate = valueOrErrorMessage(getInteger(emissionContract, keyRatePerBlockCurrent()), (("mandatory emission_contract." + keyRatePerBlockCurrent()) + " is not defined")) | |
489 | - | let gwxHoldersRewardCurrent = valueOrElse(getInteger(emissionContract, keyGwxHoldersRewardCurrent()), 0) | |
490 | - | if ((gwxHoldersRewardCurrent == gwxHoldersRewardCurrent)) | |
406 | + | let cfgArray = readConfigArrayOrFail() | |
407 | + | let userAddress = i.caller | |
408 | + | let userAddressStr = toString(userAddress) | |
409 | + | let $t01400914066 = commonClaimReward(userAddressStr) | |
410 | + | let amount = $t01400914066._1 | |
411 | + | let actions = $t01400914066._2 | |
412 | + | let checkAmount = if ((amount > 0)) | |
413 | + | then true | |
414 | + | else throw("nothing to claim") | |
415 | + | if ((checkAmount == checkAmount)) | |
491 | 416 | then { | |
492 | - | let auxAmount = fraction((deltaH * gwxHoldersRewardCurrent), emissionRate, MULT8) | |
493 | - | let em = if ((auxAmount > 0)) | |
494 | - | then invoke(emissionContract, "emit", [auxAmount], nil) | |
495 | - | else unit | |
496 | - | if ((em == em)) | |
417 | + | let userGwxAmount = { | |
418 | + | let @ = invoke(boostingContractOrFail(), "getUserGwxAmount", [userAddressStr], nil) | |
419 | + | if ($isInstanceOf(@, "Int")) | |
420 | + | then @ | |
421 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
422 | + | } | |
423 | + | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddressStr)) | |
424 | + | let activeReferralInv = if ((referrer == unit)) | |
425 | + | then unit | |
426 | + | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (userGwxAmount >= referralMinGWxAmount)], nil) | |
427 | + | if ((activeReferralInv == activeReferralInv)) | |
497 | 428 | then { | |
498 | - | let matcherPart = 0 | |
499 | - | let payoutInfo = PeriodPayoutInfo(period, matcherPart, auxAmount) | |
500 | - | let gwxHoldersRewardUpdated = { | |
501 | - | let @ = invoke(emissionContract, "gwxHoldersRewardUpdate", nil, nil) | |
502 | - | if ($isInstanceOf(@, "Boolean")) | |
503 | - | then @ | |
504 | - | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
505 | - | } | |
506 | - | if ((gwxHoldersRewardUpdated == gwxHoldersRewardUpdated)) | |
429 | + | let referralInv = if (if ((referrer == unit)) | |
430 | + | then true | |
431 | + | else (referralMinGWxAmount > userGwxAmount)) | |
432 | + | then unit | |
433 | + | else { | |
434 | + | let referrerReward = fraction(amount, referrerRewardPermille, SCALE) | |
435 | + | let referralReward = fraction(amount, referralRewardPermille, SCALE) | |
436 | + | invoke(referralsContractAddressOrFail, "incUnclaimed", [referralProgramName, userAddress, referrerReward, referralReward], nil) | |
437 | + | } | |
438 | + | if ((referralInv == referralInv)) | |
507 | 439 | then { | |
508 | - | let totalReward = (matcherPart + auxAmount) | |
509 | - | let actions = if (if ((totalReward == 0)) | |
510 | - | then !(gwxHoldersRewardUpdated) | |
511 | - | else false) | |
512 | - | then nil | |
513 | - | else [IntegerEntry(keyLatestPeriod(), period), IntegerEntry(keyHeightForPeriod(period), height), IntegerEntry(keyAuxEmissionRewardForPeriod(period), auxAmount), IntegerEntry(keyGwxRewardEmissionStartHeight(), height), IntegerEntry(keyTotalAmountForPeriod(period), matcherPart), IntegerEntry(keyNextPeriod(), (period + 1)), StringEntry(keyLastPayoutInfo(), payoutInfo), StringEntry(keyPayoutHistoryInfo(period), payoutInfo)] | |
514 | - | $Tuple2(actions, unit) | |
440 | + | let emit = invoke(emissionContract, "emit", [amount], nil) | |
441 | + | if ((emit == emit)) | |
442 | + | then { | |
443 | + | let claimedReferral = { | |
444 | + | let @ = invoke(referralsContractAddressOrFail, "claim", [referralProgramName], nil) | |
445 | + | if ($isInstanceOf(@, "Int")) | |
446 | + | then @ | |
447 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
448 | + | } | |
449 | + | if ((claimedReferral == claimedReferral)) | |
450 | + | then { | |
451 | + | let totalAmount = (amount + claimedReferral) | |
452 | + | $Tuple2(([ScriptTransfer(i.caller, amount, wxAssetId), HistoryEntry("claim", userAddressStr, totalAmount, i)] ++ actions), totalAmount) | |
453 | + | } | |
454 | + | else throw("Strict value is not equal to itself.") | |
455 | + | } | |
456 | + | else throw("Strict value is not equal to itself.") | |
515 | 457 | } | |
516 | 458 | else throw("Strict value is not equal to itself.") | |
517 | 459 | } | |
518 | 460 | else throw("Strict value is not equal to itself.") | |
519 | 461 | } | |
520 | 462 | else throw("Strict value is not equal to itself.") | |
521 | 463 | } | |
522 | 464 | else throw("Strict value is not equal to itself.") | |
523 | 465 | } | |
524 | 466 | ||
525 | 467 | ||
526 | 468 | ||
527 | 469 | @Callable(i) | |
528 | - | func claimReward () = { | |
529 | - | let cfgArray = readConfigArrayOrFail() | |
530 | - | let address = toString(i.caller) | |
531 | - | let $t01981519865 = commonClaimReward(address) | |
532 | - | let amount = $t01981519865._1 | |
533 | - | let actions = $t01981519865._2 | |
534 | - | let checkAmount = if ((amount > 0)) | |
535 | - | then true | |
536 | - | else throw("Nothing to claim") | |
537 | - | if ((checkAmount == checkAmount)) | |
538 | - | then { | |
539 | - | let amountFromEmission = 0 | |
540 | - | let claimedReferral = { | |
541 | - | let @ = invoke(referralsContractAddressOrFail, "claim", [referralProgramName], nil) | |
542 | - | if ($isInstanceOf(@, "Int")) | |
543 | - | then @ | |
544 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
545 | - | } | |
546 | - | let totalAmount = (amount + claimedReferral) | |
547 | - | $Tuple2(([ScriptTransfer(i.caller, totalAmount, fromBase58String(cfgArray[IdxCfgAssetId])), HistoryEntry("claim", address, amount, i)] ++ actions), [totalAmount, amountFromEmission]) | |
548 | - | } | |
549 | - | else throw("Strict value is not equal to itself.") | |
550 | - | } | |
551 | - | ||
552 | - | ||
553 | - | ||
554 | - | @Callable(i) | |
555 | 470 | func claimRewardREADONLY (address) = { | |
556 | - | let $ | |
557 | - | let amount = $ | |
558 | - | let actions = $ | |
471 | + | let $t01542315473 = commonClaimReward(address) | |
472 | + | let amount = $t01542315473._1 | |
473 | + | let actions = $t01542315473._2 | |
559 | 474 | let referralUnclaimed = valueOrElse(getInteger(referralsContractAddressOrFail, keyUnclaimedReferral(referralProgramName, address)), 0) | |
560 | 475 | let totalAmount = (amount + referralUnclaimed) | |
561 | 476 | $Tuple2(nil, totalAmount) | |
562 | 477 | } | |
563 | 478 | ||
564 | 479 | ||
565 | 480 | ||
566 | 481 | @Callable(i) | |
567 | - | func latestFinalizedPeriodREADONLY (address) = $Tuple2(nil, valueOrElse(getInteger(this, keyLatestPeriod()), -1)) | |
568 | - | ||
569 | - | ||
570 | - | ||
571 | - | @Callable(i) | |
572 | - | func latestFinalizedPeriodInfoREADONLY (address) = $Tuple2(nil, getStringByKey(keyLastPayoutInfo())) | |
573 | - | ||
574 | - | ||
575 | - | ||
576 | - | @Callable(i) | |
577 | - | func calcGwxParamsREADONLY (gwxAmountStart,lockStartHeight,lockDurationBlocks) = { | |
578 | - | let lockEndHeight = (lockStartHeight + lockDurationBlocks) | |
579 | - | let scale8ParamK = -(fraction(gwxAmountStart, SCALE, lockDurationBlocks)) | |
580 | - | let scale8ParamB = (fraction(gwxAmountStart, SCALE, lockDurationBlocks) * lockEndHeight) | |
581 | - | $Tuple2(nil, [scale8ParamK, scale8ParamB, nextPeriod()]) | |
582 | - | } | |
583 | - | ||
584 | - | ||
585 | - | ||
586 | - | @Callable(i) | |
587 | - | func calcGwxAmountStartREADONLY (wxLockAmount,lockDuration,maxLockDuration) = { | |
588 | - | let coeffX8 = fraction(lockDuration, MULT8, maxLockDuration) | |
589 | - | let gWxAmountStart = fraction(wxLockAmount, coeffX8, MULT8) | |
590 | - | $Tuple2(nil, [gWxAmountStart]) | |
591 | - | } | |
592 | - | ||
593 | - | ||
594 | - | ||
595 | - | @Callable(i) | |
596 | - | func onEmissionForGwxStart () = if ((i.caller != factoryContract)) | |
597 | - | then throw("permissions denied") | |
598 | - | else [IntegerEntry(keyGwxRewardEmissionStartHeight(), height)] | |
599 | - | ||
600 | - | ||
601 | - | ||
602 | - | @Callable(i) | |
603 | - | func latestPeriodEmissionRewardsREADONLY (address) = { | |
604 | - | let period = nextPeriod() | |
605 | - | $Tuple2(nil, [getNumberByKey(keyAuxEmissionRewardForPeriod(period))]) | |
606 | - | } | |
607 | - | ||
608 | - | ||
609 | - | ||
610 | - | @Callable(i) | |
611 | - | func calcD (x1BigIntStr,x2BigIntStr,ampBigIntStr,aPrecisionBigIntStr,targetPrecisionBigIntStr) = { | |
612 | - | let nCoins = toBigInt(2) | |
613 | - | let aPrecision = parseBigIntValue(aPrecisionBigIntStr) | |
614 | - | let targetPrecision = parseBigIntValue(targetPrecisionBigIntStr) | |
615 | - | let x1 = parseBigIntValue(x1BigIntStr) | |
616 | - | let x2 = parseBigIntValue(x2BigIntStr) | |
617 | - | let amp = (parseBigIntValue(ampBigIntStr) * aPrecision) | |
618 | - | let s = (x1 + x2) | |
619 | - | if ((s == zeroBigInt)) | |
620 | - | then $Tuple2(nil, toString(zeroBigInt)) | |
621 | - | else { | |
622 | - | let ann = (amp * nCoins) | |
623 | - | let arr = [0, 1, 2, 3, 4, 5, 6] | |
624 | - | func calc (acc,cur) = { | |
625 | - | let $t02312123148 = acc | |
626 | - | let d = $t02312123148._1 | |
627 | - | let dPrev = $t02312123148._2 | |
628 | - | let found = $t02312123148._3 | |
629 | - | if ((found != unit)) | |
630 | - | then acc | |
631 | - | else { | |
632 | - | let dp = (((d * d) * d) / (((x1 * x2) * nCoins) * nCoins)) | |
633 | - | let dNext = (((((ann * s) / aPrecision) + (dp * nCoins)) * d) / ((((ann - aPrecision) * d) / aPrecision) + ((nCoins + toBigInt(1)) * dp))) | |
634 | - | let dDiff = absBigInt((dNext - value(d))) | |
635 | - | if ((targetPrecision >= dDiff)) | |
636 | - | then $Tuple3(dNext, d, cur) | |
637 | - | else $Tuple3(dNext, d, unit) | |
638 | - | } | |
639 | - | } | |
640 | - | ||
641 | - | let $t02374623809 = { | |
642 | - | let $l = arr | |
643 | - | let $s = size($l) | |
644 | - | let $acc0 = $Tuple3(s, unit, unit) | |
645 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
646 | - | then $a | |
647 | - | else calc($a, $l[$i]) | |
648 | - | ||
649 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
650 | - | then $a | |
651 | - | else throw("List size exceeds 7") | |
652 | - | ||
653 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7) | |
654 | - | } | |
655 | - | let dNext = $t02374623809._1 | |
656 | - | let dPrev = $t02374623809._2 | |
657 | - | let found = $t02374623809._3 | |
658 | - | if ((found != unit)) | |
659 | - | then $Tuple2(nil, toString(dNext)) | |
660 | - | else { | |
661 | - | let dDiff = absBigInt((dNext - value(dPrev))) | |
662 | - | throw(("D calculation error, dDiff = " + toString(dDiff))) | |
663 | - | } | |
664 | - | } | |
482 | + | func onEmissionForGwxStart () = { | |
483 | + | let suspensionCheck = throwIfSuspended() | |
484 | + | if ((suspensionCheck == suspensionCheck)) | |
485 | + | then if ((i.caller != factoryContract)) | |
486 | + | then throw("permissions denied") | |
487 | + | else [IntegerEntry(keyGwxRewardEmissionStartHeight(), height)] | |
488 | + | else throw("Strict value is not equal to itself.") | |
665 | 489 | } | |
666 | 490 | ||
667 | 491 | ||
668 | 492 | ||
669 | 493 | @Callable(i) | |
670 | 494 | func tradeReward (userAddresses,rewards) = { | |
671 | - | let argsComparison = (size(userAddresses) == size(rewards)) | |
672 | - | let maxRecipients = valueOrElse(getInteger(keyMaxRecipients()), 0) | |
673 | - | let payment = i.payments[0] | |
674 | - | let paymentAssetId = payment.assetId | |
675 | - | let paymentAmount = payment.amount | |
676 | - | let checks = [if ((maxRecipients >= size(userAddresses))) | |
677 | - | then true | |
678 | - | else throwErr("Too many recipients"), if (argsComparison) | |
679 | - | then true | |
680 | - | else throwErr("Arguments size mismatch"), if ((paymentAssetId == wxAssetId)) | |
681 | - | then true | |
682 | - | else throwErr("Wrong asset payment")] | |
683 | - | if ((checks == checks)) | |
495 | + | let suspensionCheck = throwIfSuspended() | |
496 | + | if ((suspensionCheck == suspensionCheck)) | |
684 | 497 | then { | |
685 | - | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [paymentAmount, userAddresses, rewards, 0], nil) | |
686 | - | if ((tradeRewardInternal == tradeRewardInternal)) | |
687 | - | then $Tuple2(nil, tradeRewardInternal) | |
498 | + | let argsComparison = (size(userAddresses) == size(rewards)) | |
499 | + | let maxRecipients = valueOrElse(getInteger(keyMaxRecipients()), 0) | |
500 | + | let payment = i.payments[0] | |
501 | + | let paymentAssetId = payment.assetId | |
502 | + | let paymentAmount = payment.amount | |
503 | + | let checks = [if ((maxRecipients >= size(userAddresses))) | |
504 | + | then true | |
505 | + | else throwErr("Too many recipients"), if (argsComparison) | |
506 | + | then true | |
507 | + | else throwErr("Arguments size mismatch"), if ((paymentAssetId == wxAssetId)) | |
508 | + | then true | |
509 | + | else throwErr("Wrong asset payment")] | |
510 | + | if ((checks == checks)) | |
511 | + | then { | |
512 | + | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [paymentAmount, userAddresses, rewards, 0], nil) | |
513 | + | if ((tradeRewardInternal == tradeRewardInternal)) | |
514 | + | then $Tuple2(nil, tradeRewardInternal) | |
515 | + | else throw("Strict value is not equal to itself.") | |
516 | + | } | |
688 | 517 | else throw("Strict value is not equal to itself.") | |
689 | 518 | } | |
690 | 519 | else throw("Strict value is not equal to itself.") | |
691 | 520 | } | |
692 | 521 | ||
693 | 522 | ||
694 | 523 | ||
695 | 524 | @Callable(i) | |
696 | 525 | func claimTradingReward () = { | |
697 | - | let userAddress = i.caller | |
698 | - | let userAddressString = toString(userAddress) | |
699 | - | let reward = getTradingReward(userAddressString) | |
700 | - | if ((reward > 0)) | |
701 | - | then $Tuple2([ScriptTransfer(userAddress, reward, wxAssetId), IntegerEntry(keyTradingReward(userAddressString), 0)], reward) | |
702 | - | else throwErr("nothing to claim") | |
526 | + | let suspensionCheck = throwIfSuspended() | |
527 | + | if ((suspensionCheck == suspensionCheck)) | |
528 | + | then { | |
529 | + | let userAddress = i.caller | |
530 | + | let userAddressString = toString(userAddress) | |
531 | + | let reward = getTradingReward(userAddressString) | |
532 | + | if ((reward > 0)) | |
533 | + | then $Tuple2([ScriptTransfer(userAddress, reward, wxAssetId), IntegerEntry(keyTradingReward(userAddressString), 0)], reward) | |
534 | + | else throwErr("nothing to claim") | |
535 | + | } | |
536 | + | else throw("Strict value is not equal to itself.") | |
703 | 537 | } | |
704 | 538 | ||
705 | 539 | ||
706 | 540 | ||
707 | 541 | @Callable(i) | |
708 | 542 | func claimTradingRewardREADONLY (userAddress) = $Tuple2(nil, getTradingReward(userAddress)) | |
543 | + | ||
544 | + | ||
545 | + | ||
546 | + | @Callable(i) | |
547 | + | func suspend (v) = { | |
548 | + | let checkCaller = mustManager(i) | |
549 | + | if ((checkCaller == checkCaller)) | |
550 | + | then $Tuple2([BooleanEntry(keySuspension, v)], v) | |
551 | + | else throw("Strict value is not equal to itself.") | |
552 | + | } | |
709 | 553 | ||
710 | 554 | ||
711 | 555 | @Verifier(tx) | |
712 | 556 | func verify () = { | |
713 | 557 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
714 | 558 | case pk: ByteVector => | |
715 | 559 | pk | |
716 | 560 | case _: Unit => | |
717 | 561 | tx.senderPublicKey | |
718 | 562 | case _ => | |
719 | 563 | throw("Match error") | |
720 | 564 | } | |
721 | 565 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
722 | 566 | } | |
723 | 567 |
github/deemru/w8io/026f985 138.71 ms ◑