tx · ECZ5ks2Fr6gQpWBaUuJRgsVuctmivBG5Fo9GK2Uc75kg 3Mp5kisFrqESzrXxAMEPk2k69zpeF41czEE: -0.01500000 Waves 2023.08.17 16:29 [2714656] smart account 3Mp5kisFrqESzrXxAMEPk2k69zpeF41czEE > SELF 0.00000000 Waves
{ "type": 13, "id": "ECZ5ks2Fr6gQpWBaUuJRgsVuctmivBG5Fo9GK2Uc75kg", "fee": 1500000, "feeAssetId": null, "timestamp": 1692279033196, "version": 2, "chainId": 84, "sender": "3Mp5kisFrqESzrXxAMEPk2k69zpeF41czEE", "senderPublicKey": "G349Uq3FTox7dRNLeAfAQeoACvwZ9iEnVSaHcEYn6j8J", "proofs": [ "4qhYeHm8QWkdWzGeBEqFxBxqhjchupmdpK6JaxKvbALN3ELCgCxaTiU6ZDEgF8phhq5ZbcL3sj5VG5E6Gz6eZLmm" ], "script": "base64:BgKMFggCEgQKAgIBEgYKBAEYEQESBAoCCAESABIAEgMKAQgSABIECgIYERIAEgMKAQgiA1NFUCIFU0NBTEUiBU1VTFQ4IgdNVUxUOEJJIgp6ZXJvQmlnSW50IhRwcm9jZXNzaW5nU3RhZ2VUb3RhbCIVcHJvY2Vzc2luZ1N0YWdlU2hhcmVzIgZNVUxUMTgiCE1VTFQxOEJJIgt3YXZlc1N0cmluZyIHd3JhcEVyciIDbXNnIgh0aHJvd0VyciIOZ2V0TnVtYmVyQnlLZXkiA2tleSIPZ2V0TnVtYmVyT3JGYWlsIg5nZXRTdHJpbmdCeUtleSIPZ2V0U3RyaW5nT3JGYWlsIgxwYXJzZUFzc2V0SWQiBWlucHV0IgNhYnMiA3ZhbCIJYWJzQmlnSW50IgtrZXlNYXhEZXB0aCIPbWF4RGVwdGhEZWZhdWx0IghtYXhEZXB0aCIRa2V5RmFjdG9yeUFkZHJlc3MiEWZhY3RvcnlBZGRyZXNzU3RyIg9mYWN0b3J5Q29udHJhY3QiEmtleUVtaXNzaW9uQWRkcmVzcyIZa2V5Vm90aW5nRW1pc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ADCQABAgUCYVACCkJ5dGVWZWN0b3IEAmFWBQJhUAUCYVYDCQABAgUCYVACBFVuaXQIBQJjZg9zZW5kZXJQdWJsaWNLZXkJAAIBAgtNYXRjaCBlcnJvcgkA9AMDCAUCY2YJYm9keUJ5dGVzCQCRAwIIBQJjZgZwcm9vZnMAAAUCY2iJw1hP", "height": 2714656, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: F1jk2vaguPNe2csU8QgwMub7ZcvwW6GhDN8ZRT4PLLgA Next: G6fZHDhXeatGFoj34kPv9VhdwkiimeX6CM7cG5843yyL 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)) | |
144 | 150 | func keyUsersCount () = "%s__nextUserNum" | |
145 | 151 | ||
146 | 152 | ||
153 | + | func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", toString(userAddress)], SEP) | |
154 | + | ||
155 | + | ||
147 | 156 | func keyRatePerBlockCurrent () = "%s%s__ratePerBlock__current" | |
148 | 157 | ||
149 | 158 | ||
156 | 165 | func keyPoolWeightVirtual () = "%s%s__poolWeight__GWXvirtualPOOL" | |
157 | 166 | ||
158 | 167 | ||
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 | 168 | 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 | 169 | ||
212 | 170 | ||
213 | 171 | func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP) | |
275 | 233 | } | |
276 | 234 | ||
277 | 235 | ||
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 | 236 | func getUserIndexByAddress (boostingContractAddressStr,userAddress) = { | |
326 | 237 | let key = makeString(["%s%s%s", "mapping", "user2num", userAddress], SEP) | |
327 | 238 | parseIntValue(valueOrErrorMessage(getString(Address(fromBase58String(boostingContractAddressStr)), key), ((("User address " + userAddress) + " is not found in boosting contract data, key=") + key))) | |
328 | 239 | } | |
329 | 240 | ||
330 | 241 | ||
331 | - | func | |
242 | + | func getTradingReward (userAddress) = valueOrElse(getInteger(this, keyTradingReward(userAddress)), 0) | |
332 | 243 | ||
333 | 244 | ||
334 | - | func commonClaimReward (userAddress) = { | |
335 | - | let cfgArray = readConfigArrayOrFail() | |
336 | - | let userIdx = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddress) | |
337 | - | let userUnclaimedOption = getInteger(keyUserUnclaimed(userIdx)) | |
338 | - | match userUnclaimedOption { | |
245 | + | func keyRewardPerGwxIntegral () = makeString(["%s", "rewardPerGwxIntegral"], SEP) | |
246 | + | ||
247 | + | ||
248 | + | func getGwxAmountTotalOption () = { | |
249 | + | let keyGwxTotal = "%s%s__gwx__total" | |
250 | + | getInteger(boostingContractOrFail(), keyGwxTotal) | |
251 | + | } | |
252 | + | ||
253 | + | ||
254 | + | func getUserGwxAmountTotalOption (userAddress) = { | |
255 | + | func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP) | |
256 | + | ||
257 | + | getInteger(boostingContractOrFail(), keyUserGwxAmountTotal(userAddress)) | |
258 | + | } | |
259 | + | ||
260 | + | ||
261 | + | func _refreshRewardPerGwxIntegral () = { | |
262 | + | let rewardPerGwxIntegralPrevious = valueOrElse( match getString(this, keyRewardPerGwxIntegral()) { | |
263 | + | case s: String => | |
264 | + | parseBigInt(s) | |
339 | 265 | case _: Unit => | |
340 | - | $Tuple2(0, nil) | |
341 | - | case u: Int => | |
342 | - | $Tuple2(u, [IntegerEntry(keyUserUnclaimed(userIdx), 0)]) | |
266 | + | unit | |
267 | + | case _ => | |
268 | + | throw("Match error") | |
269 | + | }, zeroBigInt) | |
270 | + | let rewardPerGwxIntegralLastHeight = valueOrErrorMessage(getInteger(this, keyGwxRewardEmissionStartHeight()), wrapErr(("invalid " + keyGwxRewardEmissionStartHeight()))) | |
271 | + | let emissionRate = valueOrErrorMessage(getInteger(emissionContract, keyRatePerBlockCurrent()), wrapErr(("invalid " + keyRatePerBlockCurrent()))) | |
272 | + | let gwxHoldersRewardCurrent = valueOrElse(getInteger(emissionContract, keyGwxHoldersRewardCurrent()), 0) | |
273 | + | let gwxAmountTotal = valueOrElse(getGwxAmountTotalOption(), 0) | |
274 | + | let dh = toBigInt((height - rewardPerGwxIntegralLastHeight)) | |
275 | + | let gwxAmountTotalBI = toBigInt(gwxAmountTotal) | |
276 | + | let rewardPerGwxIntegral = (rewardPerGwxIntegralPrevious + (if ((gwxAmountTotalBI == zeroBigInt)) | |
277 | + | then zeroBigInt | |
278 | + | else fraction(dh, ((toBigInt(emissionRate) * toBigInt(gwxHoldersRewardCurrent)) * MULT18BI), (gwxAmountTotalBI * MULT8BI)))) | |
279 | + | $Tuple2([IntegerEntry(keyGwxRewardEmissionStartHeight(), height), StringEntry(keyRewardPerGwxIntegral(), toString(rewardPerGwxIntegral))], rewardPerGwxIntegral) | |
280 | + | } | |
281 | + | ||
282 | + | ||
283 | + | func keyRewardPerGwxIntegralUserLast (userAddress) = makeString(["%s%s", "rewardPerGwxIntegralUserLast", toString(userAddress)], SEP) | |
284 | + | ||
285 | + | ||
286 | + | func _refreshUserReward (userAddress,userNum) = { | |
287 | + | let $t01012210210 = _refreshRewardPerGwxIntegral() | |
288 | + | let rewardPerGwxIntegralActions = $t01012210210._1 | |
289 | + | let rewardPerGwxIntegral = $t01012210210._2 | |
290 | + | let rewardPerGwxIntegralUserLast = match getString(this, keyRewardPerGwxIntegralUserLast(userAddress)) { | |
291 | + | case s: String => | |
292 | + | valueOrErrorMessage(parseBigInt(s), wrapErr("invalid user last integral")) | |
293 | + | case _: Unit => | |
294 | + | rewardPerGwxIntegral | |
343 | 295 | case _ => | |
344 | 296 | throw("Match error") | |
345 | 297 | } | |
298 | + | let userIdxOption = getString(boostingContractOrFail(), keyUser2NumMapping(userAddress)) | |
299 | + | let userUnclaimed = valueOrElse(getInteger(keyUserUnclaimed(userNum)), 0) | |
300 | + | let userGwxAmount = valueOrElse(getUserGwxAmountTotalOption(userAddress), 0) | |
301 | + | let userReward = (toInt(fraction(toBigInt(userGwxAmount), (rewardPerGwxIntegral - rewardPerGwxIntegralUserLast), MULT18BI)) + userUnclaimed) | |
302 | + | $Tuple2(([StringEntry(keyRewardPerGwxIntegralUserLast(userAddress), toString(rewardPerGwxIntegral))] ++ rewardPerGwxIntegralActions), userReward) | |
346 | 303 | } | |
347 | 304 | ||
348 | 305 | ||
349 | - | func getTradingReward (userAddress) = valueOrElse(getInteger(this, keyTradingReward(userAddress)), 0) | |
306 | + | func commonClaimReward (userAddressStr) = { | |
307 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
308 | + | let cfgArray = readConfigArrayOrFail() | |
309 | + | let userNum = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddressStr) | |
310 | + | let $t01150111565 = _refreshUserReward(userAddress, userNum) | |
311 | + | let actions = $t01150111565._1 | |
312 | + | let reward = $t01150111565._2 | |
313 | + | $Tuple2(reward, ([IntegerEntry(keyUserUnclaimed(userNum), 0)] ++ actions)) | |
314 | + | } | |
315 | + | ||
316 | + | ||
317 | + | @Callable(i) | |
318 | + | func refreshUserReward (userAddressBytes,userNum) = { | |
319 | + | let checkCaller = if ((i.caller == boostingContractOrFail())) | |
320 | + | then true | |
321 | + | else throwErr("permission denied") | |
322 | + | if ((checkCaller == checkCaller)) | |
323 | + | then { | |
324 | + | let $t01184511923 = _refreshUserReward(Address(userAddressBytes), userNum) | |
325 | + | let actions = $t01184511923._1 | |
326 | + | let reward = $t01184511923._2 | |
327 | + | $Tuple2(([IntegerEntry(keyUserUnclaimed(userNum), reward)] ++ actions), reward) | |
328 | + | } | |
329 | + | else throw("Strict value is not equal to itself.") | |
330 | + | } | |
331 | + | ||
350 | 332 | ||
351 | 333 | ||
352 | 334 | @Callable(i) | |
388 | 370 | ||
389 | 371 | ||
390 | 372 | @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) | |
412 | - | } | |
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 | - | } | |
373 | + | func processPendingPeriodsAndUsers () = $Tuple2(nil, throwErr("deprecated")) | |
450 | 374 | ||
451 | 375 | ||
452 | 376 | ||
453 | 377 | @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 | - | else throw("Strict value is not equal to itself.") | |
470 | - | } | |
471 | - | ||
472 | - | ||
473 | - | ||
474 | - | @Callable(i) | |
475 | - | func processPendingPeriodsAndUsers () = $Tuple2(nil, invoke(this, "finalizeWrapper", [maxDepth], nil)) | |
476 | - | ||
477 | - | ||
478 | - | ||
479 | - | @Callable(i) | |
480 | - | func deposit () = { | |
481 | - | let checkCaller = if ((i.caller == votingEmissionContract)) | |
378 | + | func claimReward () = { | |
379 | + | let cfgArray = readConfigArrayOrFail() | |
380 | + | let userAddress = i.caller | |
381 | + | let userAddressStr = toString(userAddress) | |
382 | + | let $t01365513712 = commonClaimReward(userAddressStr) | |
383 | + | let amount = $t01365513712._1 | |
384 | + | let actions = $t01365513712._2 | |
385 | + | let checkAmount = if ((amount > 0)) | |
482 | 386 | then true | |
483 | - | else | |
484 | - | if (( | |
387 | + | else throw("nothing to claim") | |
388 | + | if ((checkAmount == checkAmount)) | |
485 | 389 | 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)) | |
390 | + | let userGwxAmount = { | |
391 | + | let @ = invoke(boostingContractOrFail(), "getUserGwxAmount", [userAddressStr], nil) | |
392 | + | if ($isInstanceOf(@, "Int")) | |
393 | + | then @ | |
394 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
395 | + | } | |
396 | + | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddressStr)) | |
397 | + | let activeReferralInv = if ((referrer == unit)) | |
398 | + | then unit | |
399 | + | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (userGwxAmount >= referralMinGWxAmount)], nil) | |
400 | + | if ((activeReferralInv == activeReferralInv)) | |
491 | 401 | 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)) | |
402 | + | let referralInv = if (if ((referrer == unit)) | |
403 | + | then true | |
404 | + | else (referralMinGWxAmount > userGwxAmount)) | |
405 | + | then unit | |
406 | + | else { | |
407 | + | let referrerReward = fraction(amount, referrerRewardPermille, SCALE) | |
408 | + | let referralReward = fraction(amount, referralRewardPermille, SCALE) | |
409 | + | invoke(referralsContractAddressOrFail, "incUnclaimed", [referralProgramName, userAddress, referrerReward, referralReward], nil) | |
410 | + | } | |
411 | + | if ((referralInv == referralInv)) | |
497 | 412 | 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")) | |
413 | + | let claimedReferral = { | |
414 | + | let @ = invoke(referralsContractAddressOrFail, "claim", [referralProgramName], nil) | |
415 | + | if ($isInstanceOf(@, "Int")) | |
503 | 416 | then @ | |
504 | - | else throw(($getType(@) + " couldn't be cast to | |
417 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
505 | 418 | } | |
506 | - | if (( | |
419 | + | if ((claimedReferral == claimedReferral)) | |
507 | 420 | 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) | |
421 | + | let totalAmount = (amount + claimedReferral) | |
422 | + | $Tuple2(([ScriptTransfer(i.caller, amount, fromBase58String(cfgArray[IdxCfgAssetId])), HistoryEntry("claim", userAddressStr, totalAmount, i)] ++ actions), totalAmount) | |
515 | 423 | } | |
516 | 424 | else throw("Strict value is not equal to itself.") | |
517 | 425 | } | |
525 | 433 | ||
526 | 434 | ||
527 | 435 | @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 | 436 | func claimRewardREADONLY (address) = { | |
556 | - | let $ | |
557 | - | let amount = $ | |
558 | - | let actions = $ | |
437 | + | let $t01503915089 = commonClaimReward(address) | |
438 | + | let amount = $t01503915089._1 | |
439 | + | let actions = $t01503915089._2 | |
559 | 440 | let referralUnclaimed = valueOrElse(getInteger(referralsContractAddressOrFail, keyUnclaimedReferral(referralProgramName, address)), 0) | |
560 | 441 | let totalAmount = (amount + referralUnclaimed) | |
561 | 442 | $Tuple2(nil, totalAmount) | |
564 | 445 | ||
565 | 446 | ||
566 | 447 | @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 | 448 | func onEmissionForGwxStart () = if ((i.caller != factoryContract)) | |
597 | 449 | then throw("permissions denied") | |
598 | 450 | 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 | - | } | |
665 | - | } | |
666 | 451 | ||
667 | 452 | ||
668 | 453 |
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 | ||
141 | 147 | func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight" | |
142 | 148 | ||
143 | 149 | ||
144 | 150 | func keyUsersCount () = "%s__nextUserNum" | |
145 | 151 | ||
146 | 152 | ||
153 | + | func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", toString(userAddress)], SEP) | |
154 | + | ||
155 | + | ||
147 | 156 | func keyRatePerBlockCurrent () = "%s%s__ratePerBlock__current" | |
148 | 157 | ||
149 | 158 | ||
150 | 159 | func keyGwxHoldersRewardCurrent () = "%s%s__gwxHoldersReward__current" | |
151 | 160 | ||
152 | 161 | ||
153 | 162 | func keyGwxHoldersRewardNext () = "%s%s__gwxHoldersReward__next" | |
154 | 163 | ||
155 | 164 | ||
156 | 165 | func keyPoolWeightVirtual () = "%s%s__poolWeight__GWXvirtualPOOL" | |
157 | 166 | ||
158 | 167 | ||
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 | 168 | 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 | 169 | ||
212 | 170 | ||
213 | 171 | func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP) | |
214 | 172 | ||
215 | 173 | ||
216 | 174 | let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(keyReferralsContractAddress())) | |
217 | 175 | ||
218 | 176 | func keyTradingRewardHistory (user,i) = makeString(["%s%s%s%s", "tradingReward", "history", user, toBase58String(i.transactionId)], SEP) | |
219 | 177 | ||
220 | 178 | ||
221 | 179 | func keyTradingReward (userAddress) = makeString(["%s%s", "tradingReward", userAddress], SEP) | |
222 | 180 | ||
223 | 181 | ||
224 | 182 | func keyMaxRecipients () = makeString(["%s", "maxRecipients"], SEP) | |
225 | 183 | ||
226 | 184 | ||
227 | 185 | func HistoryEntry (type,user,amount,i) = { | |
228 | 186 | let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], SEP) | |
229 | 187 | let historyDATA = makeString(["%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount)], SEP) | |
230 | 188 | StringEntry(historyKEY, historyDATA) | |
231 | 189 | } | |
232 | 190 | ||
233 | 191 | ||
234 | 192 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
235 | 193 | ||
236 | 194 | ||
237 | 195 | func keyManagerVaultAddress () = "%s__managerVaultAddress" | |
238 | 196 | ||
239 | 197 | ||
240 | 198 | func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) { | |
241 | 199 | case s: String => | |
242 | 200 | addressFromStringValue(s) | |
243 | 201 | case _ => | |
244 | 202 | this | |
245 | 203 | } | |
246 | 204 | ||
247 | 205 | ||
248 | 206 | func managerPublicKeyOrUnit () = { | |
249 | 207 | let managerVaultAddress = getManagerVaultAddressOrThis() | |
250 | 208 | match getString(managerVaultAddress, keyManagerPublicKey()) { | |
251 | 209 | case s: String => | |
252 | 210 | fromBase58String(s) | |
253 | 211 | case _: Unit => | |
254 | 212 | unit | |
255 | 213 | case _ => | |
256 | 214 | throw("Match error") | |
257 | 215 | } | |
258 | 216 | } | |
259 | 217 | ||
260 | 218 | ||
261 | 219 | func mustManager (i) = { | |
262 | 220 | let pd = throw("Permission denied") | |
263 | 221 | match managerPublicKeyOrUnit() { | |
264 | 222 | case pk: ByteVector => | |
265 | 223 | if ((i.callerPublicKey == pk)) | |
266 | 224 | then true | |
267 | 225 | else pd | |
268 | 226 | case _: Unit => | |
269 | 227 | if ((i.caller == this)) | |
270 | 228 | then true | |
271 | 229 | else pd | |
272 | 230 | case _ => | |
273 | 231 | throw("Match error") | |
274 | 232 | } | |
275 | 233 | } | |
276 | 234 | ||
277 | 235 | ||
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 | 236 | func getUserIndexByAddress (boostingContractAddressStr,userAddress) = { | |
326 | 237 | let key = makeString(["%s%s%s", "mapping", "user2num", userAddress], SEP) | |
327 | 238 | parseIntValue(valueOrErrorMessage(getString(Address(fromBase58String(boostingContractAddressStr)), key), ((("User address " + userAddress) + " is not found in boosting contract data, key=") + key))) | |
328 | 239 | } | |
329 | 240 | ||
330 | 241 | ||
331 | - | func | |
242 | + | func getTradingReward (userAddress) = valueOrElse(getInteger(this, keyTradingReward(userAddress)), 0) | |
332 | 243 | ||
333 | 244 | ||
334 | - | func commonClaimReward (userAddress) = { | |
335 | - | let cfgArray = readConfigArrayOrFail() | |
336 | - | let userIdx = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddress) | |
337 | - | let userUnclaimedOption = getInteger(keyUserUnclaimed(userIdx)) | |
338 | - | match userUnclaimedOption { | |
245 | + | func keyRewardPerGwxIntegral () = makeString(["%s", "rewardPerGwxIntegral"], SEP) | |
246 | + | ||
247 | + | ||
248 | + | func getGwxAmountTotalOption () = { | |
249 | + | let keyGwxTotal = "%s%s__gwx__total" | |
250 | + | getInteger(boostingContractOrFail(), keyGwxTotal) | |
251 | + | } | |
252 | + | ||
253 | + | ||
254 | + | func getUserGwxAmountTotalOption (userAddress) = { | |
255 | + | func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP) | |
256 | + | ||
257 | + | getInteger(boostingContractOrFail(), keyUserGwxAmountTotal(userAddress)) | |
258 | + | } | |
259 | + | ||
260 | + | ||
261 | + | func _refreshRewardPerGwxIntegral () = { | |
262 | + | let rewardPerGwxIntegralPrevious = valueOrElse( match getString(this, keyRewardPerGwxIntegral()) { | |
263 | + | case s: String => | |
264 | + | parseBigInt(s) | |
339 | 265 | case _: Unit => | |
340 | - | $Tuple2(0, nil) | |
341 | - | case u: Int => | |
342 | - | $Tuple2(u, [IntegerEntry(keyUserUnclaimed(userIdx), 0)]) | |
266 | + | unit | |
267 | + | case _ => | |
268 | + | throw("Match error") | |
269 | + | }, zeroBigInt) | |
270 | + | let rewardPerGwxIntegralLastHeight = valueOrErrorMessage(getInteger(this, keyGwxRewardEmissionStartHeight()), wrapErr(("invalid " + keyGwxRewardEmissionStartHeight()))) | |
271 | + | let emissionRate = valueOrErrorMessage(getInteger(emissionContract, keyRatePerBlockCurrent()), wrapErr(("invalid " + keyRatePerBlockCurrent()))) | |
272 | + | let gwxHoldersRewardCurrent = valueOrElse(getInteger(emissionContract, keyGwxHoldersRewardCurrent()), 0) | |
273 | + | let gwxAmountTotal = valueOrElse(getGwxAmountTotalOption(), 0) | |
274 | + | let dh = toBigInt((height - rewardPerGwxIntegralLastHeight)) | |
275 | + | let gwxAmountTotalBI = toBigInt(gwxAmountTotal) | |
276 | + | let rewardPerGwxIntegral = (rewardPerGwxIntegralPrevious + (if ((gwxAmountTotalBI == zeroBigInt)) | |
277 | + | then zeroBigInt | |
278 | + | else fraction(dh, ((toBigInt(emissionRate) * toBigInt(gwxHoldersRewardCurrent)) * MULT18BI), (gwxAmountTotalBI * MULT8BI)))) | |
279 | + | $Tuple2([IntegerEntry(keyGwxRewardEmissionStartHeight(), height), StringEntry(keyRewardPerGwxIntegral(), toString(rewardPerGwxIntegral))], rewardPerGwxIntegral) | |
280 | + | } | |
281 | + | ||
282 | + | ||
283 | + | func keyRewardPerGwxIntegralUserLast (userAddress) = makeString(["%s%s", "rewardPerGwxIntegralUserLast", toString(userAddress)], SEP) | |
284 | + | ||
285 | + | ||
286 | + | func _refreshUserReward (userAddress,userNum) = { | |
287 | + | let $t01012210210 = _refreshRewardPerGwxIntegral() | |
288 | + | let rewardPerGwxIntegralActions = $t01012210210._1 | |
289 | + | let rewardPerGwxIntegral = $t01012210210._2 | |
290 | + | let rewardPerGwxIntegralUserLast = match getString(this, keyRewardPerGwxIntegralUserLast(userAddress)) { | |
291 | + | case s: String => | |
292 | + | valueOrErrorMessage(parseBigInt(s), wrapErr("invalid user last integral")) | |
293 | + | case _: Unit => | |
294 | + | rewardPerGwxIntegral | |
343 | 295 | case _ => | |
344 | 296 | throw("Match error") | |
345 | 297 | } | |
298 | + | let userIdxOption = getString(boostingContractOrFail(), keyUser2NumMapping(userAddress)) | |
299 | + | let userUnclaimed = valueOrElse(getInteger(keyUserUnclaimed(userNum)), 0) | |
300 | + | let userGwxAmount = valueOrElse(getUserGwxAmountTotalOption(userAddress), 0) | |
301 | + | let userReward = (toInt(fraction(toBigInt(userGwxAmount), (rewardPerGwxIntegral - rewardPerGwxIntegralUserLast), MULT18BI)) + userUnclaimed) | |
302 | + | $Tuple2(([StringEntry(keyRewardPerGwxIntegralUserLast(userAddress), toString(rewardPerGwxIntegral))] ++ rewardPerGwxIntegralActions), userReward) | |
346 | 303 | } | |
347 | 304 | ||
348 | 305 | ||
349 | - | func getTradingReward (userAddress) = valueOrElse(getInteger(this, keyTradingReward(userAddress)), 0) | |
306 | + | func commonClaimReward (userAddressStr) = { | |
307 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
308 | + | let cfgArray = readConfigArrayOrFail() | |
309 | + | let userNum = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddressStr) | |
310 | + | let $t01150111565 = _refreshUserReward(userAddress, userNum) | |
311 | + | let actions = $t01150111565._1 | |
312 | + | let reward = $t01150111565._2 | |
313 | + | $Tuple2(reward, ([IntegerEntry(keyUserUnclaimed(userNum), 0)] ++ actions)) | |
314 | + | } | |
315 | + | ||
316 | + | ||
317 | + | @Callable(i) | |
318 | + | func refreshUserReward (userAddressBytes,userNum) = { | |
319 | + | let checkCaller = if ((i.caller == boostingContractOrFail())) | |
320 | + | then true | |
321 | + | else throwErr("permission denied") | |
322 | + | if ((checkCaller == checkCaller)) | |
323 | + | then { | |
324 | + | let $t01184511923 = _refreshUserReward(Address(userAddressBytes), userNum) | |
325 | + | let actions = $t01184511923._1 | |
326 | + | let reward = $t01184511923._2 | |
327 | + | $Tuple2(([IntegerEntry(keyUserUnclaimed(userNum), reward)] ++ actions), reward) | |
328 | + | } | |
329 | + | else throw("Strict value is not equal to itself.") | |
330 | + | } | |
331 | + | ||
350 | 332 | ||
351 | 333 | ||
352 | 334 | @Callable(i) | |
353 | 335 | func tradeRewardInternal (paymentAmountLeftOver,userAddresses,rewards,currentIter) = if ((currentIter == size(userAddresses))) | |
354 | 336 | then nil | |
355 | 337 | else { | |
356 | 338 | let checks = [if ((i.caller == this)) | |
357 | 339 | then true | |
358 | 340 | else throwErr("Permission denied"), if ((paymentAmountLeftOver >= rewards[currentIter])) | |
359 | 341 | then true | |
360 | 342 | else throwErr("insufficient payment assetId")] | |
361 | 343 | if ((checks == checks)) | |
362 | 344 | then { | |
363 | 345 | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [(paymentAmountLeftOver - rewards[currentIter]), userAddresses, rewards, (currentIter + 1)], nil) | |
364 | 346 | if ((tradeRewardInternal == tradeRewardInternal)) | |
365 | 347 | then { | |
366 | 348 | let tradingRewardHistoryKey = keyTradingRewardHistory(userAddresses[currentIter], i) | |
367 | 349 | let userAddress = addressFromStringValue(userAddresses[currentIter]) | |
368 | 350 | $Tuple2([IntegerEntry(tradingRewardHistoryKey, rewards[currentIter]), IntegerEntry(keyTradingReward(userAddresses[currentIter]), rewards[currentIter])], tradeRewardInternal) | |
369 | 351 | } | |
370 | 352 | else throw("Strict value is not equal to itself.") | |
371 | 353 | } | |
372 | 354 | else throw("Strict value is not equal to itself.") | |
373 | 355 | } | |
374 | 356 | ||
375 | 357 | ||
376 | 358 | ||
377 | 359 | @Callable(i) | |
378 | 360 | func updateReferralActivity (userAddress,gWxAmountStart) = { | |
379 | 361 | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) | |
380 | 362 | let activeReferralInv = if ((referrer == unit)) | |
381 | 363 | then unit | |
382 | 364 | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (gWxAmountStart >= referralMinGWxAmount)], nil) | |
383 | 365 | if ((activeReferralInv == activeReferralInv)) | |
384 | 366 | then $Tuple2(nil, unit) | |
385 | 367 | else throw("Strict value is not equal to itself.") | |
386 | 368 | } | |
387 | 369 | ||
388 | 370 | ||
389 | 371 | ||
390 | 372 | @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) | |
412 | - | } | |
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 | - | } | |
373 | + | func processPendingPeriodsAndUsers () = $Tuple2(nil, throwErr("deprecated")) | |
450 | 374 | ||
451 | 375 | ||
452 | 376 | ||
453 | 377 | @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 | - | else throw("Strict value is not equal to itself.") | |
470 | - | } | |
471 | - | ||
472 | - | ||
473 | - | ||
474 | - | @Callable(i) | |
475 | - | func processPendingPeriodsAndUsers () = $Tuple2(nil, invoke(this, "finalizeWrapper", [maxDepth], nil)) | |
476 | - | ||
477 | - | ||
478 | - | ||
479 | - | @Callable(i) | |
480 | - | func deposit () = { | |
481 | - | let checkCaller = if ((i.caller == votingEmissionContract)) | |
378 | + | func claimReward () = { | |
379 | + | let cfgArray = readConfigArrayOrFail() | |
380 | + | let userAddress = i.caller | |
381 | + | let userAddressStr = toString(userAddress) | |
382 | + | let $t01365513712 = commonClaimReward(userAddressStr) | |
383 | + | let amount = $t01365513712._1 | |
384 | + | let actions = $t01365513712._2 | |
385 | + | let checkAmount = if ((amount > 0)) | |
482 | 386 | then true | |
483 | - | else | |
484 | - | if (( | |
387 | + | else throw("nothing to claim") | |
388 | + | if ((checkAmount == checkAmount)) | |
485 | 389 | 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)) | |
390 | + | let userGwxAmount = { | |
391 | + | let @ = invoke(boostingContractOrFail(), "getUserGwxAmount", [userAddressStr], nil) | |
392 | + | if ($isInstanceOf(@, "Int")) | |
393 | + | then @ | |
394 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
395 | + | } | |
396 | + | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddressStr)) | |
397 | + | let activeReferralInv = if ((referrer == unit)) | |
398 | + | then unit | |
399 | + | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (userGwxAmount >= referralMinGWxAmount)], nil) | |
400 | + | if ((activeReferralInv == activeReferralInv)) | |
491 | 401 | 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)) | |
402 | + | let referralInv = if (if ((referrer == unit)) | |
403 | + | then true | |
404 | + | else (referralMinGWxAmount > userGwxAmount)) | |
405 | + | then unit | |
406 | + | else { | |
407 | + | let referrerReward = fraction(amount, referrerRewardPermille, SCALE) | |
408 | + | let referralReward = fraction(amount, referralRewardPermille, SCALE) | |
409 | + | invoke(referralsContractAddressOrFail, "incUnclaimed", [referralProgramName, userAddress, referrerReward, referralReward], nil) | |
410 | + | } | |
411 | + | if ((referralInv == referralInv)) | |
497 | 412 | 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")) | |
413 | + | let claimedReferral = { | |
414 | + | let @ = invoke(referralsContractAddressOrFail, "claim", [referralProgramName], nil) | |
415 | + | if ($isInstanceOf(@, "Int")) | |
503 | 416 | then @ | |
504 | - | else throw(($getType(@) + " couldn't be cast to | |
417 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
505 | 418 | } | |
506 | - | if (( | |
419 | + | if ((claimedReferral == claimedReferral)) | |
507 | 420 | 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) | |
421 | + | let totalAmount = (amount + claimedReferral) | |
422 | + | $Tuple2(([ScriptTransfer(i.caller, amount, fromBase58String(cfgArray[IdxCfgAssetId])), HistoryEntry("claim", userAddressStr, totalAmount, i)] ++ actions), totalAmount) | |
515 | 423 | } | |
516 | 424 | else throw("Strict value is not equal to itself.") | |
517 | 425 | } | |
518 | 426 | else throw("Strict value is not equal to itself.") | |
519 | 427 | } | |
520 | 428 | else throw("Strict value is not equal to itself.") | |
521 | 429 | } | |
522 | 430 | else throw("Strict value is not equal to itself.") | |
523 | 431 | } | |
524 | 432 | ||
525 | 433 | ||
526 | 434 | ||
527 | 435 | @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 | 436 | func claimRewardREADONLY (address) = { | |
556 | - | let $ | |
557 | - | let amount = $ | |
558 | - | let actions = $ | |
437 | + | let $t01503915089 = commonClaimReward(address) | |
438 | + | let amount = $t01503915089._1 | |
439 | + | let actions = $t01503915089._2 | |
559 | 440 | let referralUnclaimed = valueOrElse(getInteger(referralsContractAddressOrFail, keyUnclaimedReferral(referralProgramName, address)), 0) | |
560 | 441 | let totalAmount = (amount + referralUnclaimed) | |
561 | 442 | $Tuple2(nil, totalAmount) | |
562 | 443 | } | |
563 | 444 | ||
564 | 445 | ||
565 | 446 | ||
566 | 447 | @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 | 448 | func onEmissionForGwxStart () = if ((i.caller != factoryContract)) | |
597 | 449 | then throw("permissions denied") | |
598 | 450 | 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 | - | } | |
665 | - | } | |
666 | 451 | ||
667 | 452 | ||
668 | 453 | ||
669 | 454 | @Callable(i) | |
670 | 455 | func tradeReward (userAddresses,rewards) = { | |
671 | 456 | let argsComparison = (size(userAddresses) == size(rewards)) | |
672 | 457 | let maxRecipients = valueOrElse(getInteger(keyMaxRecipients()), 0) | |
673 | 458 | let payment = i.payments[0] | |
674 | 459 | let paymentAssetId = payment.assetId | |
675 | 460 | let paymentAmount = payment.amount | |
676 | 461 | let checks = [if ((maxRecipients >= size(userAddresses))) | |
677 | 462 | then true | |
678 | 463 | else throwErr("Too many recipients"), if (argsComparison) | |
679 | 464 | then true | |
680 | 465 | else throwErr("Arguments size mismatch"), if ((paymentAssetId == wxAssetId)) | |
681 | 466 | then true | |
682 | 467 | else throwErr("Wrong asset payment")] | |
683 | 468 | if ((checks == checks)) | |
684 | 469 | then { | |
685 | 470 | let tradeRewardInternal = invoke(this, "tradeRewardInternal", [paymentAmount, userAddresses, rewards, 0], nil) | |
686 | 471 | if ((tradeRewardInternal == tradeRewardInternal)) | |
687 | 472 | then $Tuple2(nil, tradeRewardInternal) | |
688 | 473 | else throw("Strict value is not equal to itself.") | |
689 | 474 | } | |
690 | 475 | else throw("Strict value is not equal to itself.") | |
691 | 476 | } | |
692 | 477 | ||
693 | 478 | ||
694 | 479 | ||
695 | 480 | @Callable(i) | |
696 | 481 | func claimTradingReward () = { | |
697 | 482 | let userAddress = i.caller | |
698 | 483 | let userAddressString = toString(userAddress) | |
699 | 484 | let reward = getTradingReward(userAddressString) | |
700 | 485 | if ((reward > 0)) | |
701 | 486 | then $Tuple2([ScriptTransfer(userAddress, reward, wxAssetId), IntegerEntry(keyTradingReward(userAddressString), 0)], reward) | |
702 | 487 | else throwErr("nothing to claim") | |
703 | 488 | } | |
704 | 489 | ||
705 | 490 | ||
706 | 491 | ||
707 | 492 | @Callable(i) | |
708 | 493 | func claimTradingRewardREADONLY (userAddress) = $Tuple2(nil, getTradingReward(userAddress)) | |
709 | 494 | ||
710 | 495 | ||
711 | 496 | @Verifier(tx) | |
712 | 497 | func verify () = { | |
713 | 498 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
714 | 499 | case pk: ByteVector => | |
715 | 500 | pk | |
716 | 501 | case _: Unit => | |
717 | 502 | tx.senderPublicKey | |
718 | 503 | case _ => | |
719 | 504 | throw("Match error") | |
720 | 505 | } | |
721 | 506 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
722 | 507 | } | |
723 | 508 |
github/deemru/w8io/169f3d6 91.07 ms ◑