tx · AuGR23H1WV8mAjnRLoKH5dQnxjNH7SeF9ifWm75DfPFJ

3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy:  -0.02600000 Waves

2023.08.16 14:12 [2713052] smart account 3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy > SELF 0.00000000 Waves

{ "type": 13, "id": "AuGR23H1WV8mAjnRLoKH5dQnxjNH7SeF9ifWm75DfPFJ", "fee": 2600000, "feeAssetId": null, "timestamp": 1692184224408, "version": 2, "chainId": 84, "sender": "3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy", "senderPublicKey": "9W33iCCNfmFxUbiC6XZcH5x7f6xfwC7Jb3BoExT5q2PV", "proofs": [ "2Pyw3gijmHDb2siDxBzz5dAqSHDWSDcNfM52sRFifePsVG7GWZtVdtPfQug3yh3kWTTDkDbZ1qcNUZ8SGguJKuw" ], "script": "base64:BgLOLQgCEggKBggIAQEBCBIFCgMBCAISAwoBARIECgIICBIECgIICBIDCgEIEgMKAQgSAwoBCBIECgIIARIDCgEIEgASABIFCgMICAQSAwoBCBIDCgEIEgQKAggIEgQKAggIIgNTRVAiBlNDQUxFOCIFTVVMVDgiDlBPT0xXRUlHSFRNVUxUIhBjb250cmFjdEZpbGVuYW1lIgdTQ0FMRTE4IgZNVUxUMTgiCE1VTFQxOEJJIhVkdXJhdGlvbk1vbnRoc0FsbG93ZWQiC2Jsb2Nrc0luRGF5Ig1ibG9ja3NJbk1vbnRoIgd3cmFwRXJyIgNtc2ciCHRocm93RXJyIg9nZXRTdHJpbmdPckZhaWwiB2FkZHJlc3MiA2tleSIMZ2V0SW50T3JaZXJvIg9nZXRJbnRPckRlZmF1bHQiCmRlZmF1bHRWYWwiDGdldEludE9yRmFpbCIDYWJzIgN2YWwiDmVuc3VyZVBvc2l0aXZlIgF2IgFtIhtrZXlSZWZlcnJhbHNDb250cmFjdEFkZHJlc3MiHnJlZmVycmFsc0NvbnRyYWN0QWRkcmVzc09yRmFpbCIWa2V5Um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v1ym55HG Next: D69Z5DoJ8y2c7My6s56dB7LJoKKvSwqd1SW8kvjhttMP Diff:
OldNewDifferences
99
1010 let POOLWEIGHTMULT = MULT8
1111
12-func wrapErr (msg) = makeString(["boosting.ride:", msg], " ")
12+let contractFilename = "boosting.ride"
13+
14+let SCALE18 = 18
15+
16+let MULT18 = 1000000000000000000
17+
18+let MULT18BI = toBigInt(MULT18)
19+
20+let durationMonthsAllowed = [1, 3, 6, 12, 24, 48]
21+
22+let blocksInDay = 1440
23+
24+let blocksInMonth = 43800
25+
26+func wrapErr (msg) = makeString([contractFilename, ": ", msg], "")
1327
1428
1529 func throwErr (msg) = throw(wrapErr(msg))
1630
1731
18-func strf (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
32+func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
1933
2034
21-func ioz (address,key) = valueOrElse(getInteger(address, key), 0)
35+func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0)
2236
2337
24-func iod (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal)
38+func getIntOrDefault (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal)
2539
2640
27-func iof (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
41+func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
2842
2943
3044 func abs (val) = if ((0 > val))
3246 else val
3347
3448
35-func aal (val) = match val {
36- case valAnyLyst: List[Any] =>
37- valAnyLyst
38- case _ =>
39- throwErr("fail to cast into List[Any]")
40-}
41-
42-
43-func ai (val) = match val {
44- case valInt: Int =>
45- valInt
46- case _ =>
47- throwErr("fail to cast into Int")
48-}
49+func ensurePositive (v,m) = if ((v >= 0))
50+ then v
51+ else throwErr((valueOrElse(m, "value") + " should be positive"))
4952
5053
5154 func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP)
5255
5356
54-let referralsContractAddressOrFail = addressFromStringValue(strf(this, keyReferralsContractAddress()))
57+let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(this, keyReferralsContractAddress()))
5558
5659 let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP)
5760
8790 func keyFactoryCfg () = "%s__factoryConfig"
8891
8992
90-func keyFactoryLpList () = "%s__lpTokensList"
91-
92-
9393 func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP)
9494
9595
9999 func keyFactoryPoolWeightHistory (poolAddress,num) = ((("%s%s__poolWeight__" + poolAddress) + "__") + toString(num))
100100
101101
102-func readFactoryAddressOrFail () = addressFromStringValue(strf(this, keyFactoryAddress()))
102+func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(this, keyFactoryAddress()))
103103
104104
105-func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP)
106-
107-
108-func readFactoryCfgOrFail (factory) = split(strf(factory, keyFactoryCfg()), SEP)
105+func readFactoryCfgOrFail (factory) = split(getStringOrFail(factory, keyFactoryCfg()), SEP)
109106
110107
111108 func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp])
147144 func keyEmissionEndBlock () = "%s%s__emission__endBlock"
148145
149146
150-func keyNextPeriod () = "%s__nextPeriod"
151-
152-
153-func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight"
154-
155-
156147 let IdxCfgAssetId = 1
157148
158149 let IdxCfgMinLockAmount = 2
163154
164155 let IdxCfgMathContract = 5
165156
157+let IdxCfgBlocksInPeriod = 6
158+
166159 func keyConfig () = "%s__config"
167160
168161
169-func readConfigArrayOrFail () = split(strf(this, keyConfig()), SEP)
162+func readConfigArrayOrFail () = split(getStringOrFail(this, keyConfig()), SEP)
170163
171164
172-let mathContract = addressFromStringValue(readConfigArrayOrFail()[IdxCfgMathContract])
165+let cfgArray = readConfigArrayOrFail()
173166
174-func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP)
167+let assetId = fromBase58String(cfgArray[IdxCfgAssetId])
168+
169+let minLockAmount = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMinLockAmount]), wrapErr("invalid min lock amount"))
170+
171+let minLockDuration = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMinLockDuration]), wrapErr("invalid min lock duration"))
172+
173+let maxLockDuration = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMaxLockDuration]), wrapErr("invalid max lock duration"))
174+
175+let mathContract = valueOrErrorMessage(addressFromString(cfgArray[IdxCfgMathContract]), wrapErr("invalid math contract address"))
176+
177+let blocksInPeriod = valueOrErrorMessage(parseInt(cfgArray[IdxCfgBlocksInPeriod]), wrapErr("invalid blocks in period"))
178+
179+func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d%s", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP)
175180
176181
177182 func formatConfig (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = formatConfigS(assetId, toString(minLockAmount), toString(minLockDuration), toString(maxLockDuration), mathContract)
215220 }
216221
217222
218-let IdxLockUserNum = 1
223+let IdxLockAmount = 1
219224
220-let IdxLockAmount = 2
225+let IdxLockStart = 2
221226
222-let IdxLockStart = 3
227+let IdxLockDuration = 3
223228
224-let IdxLockDuration = 4
229+let IdxLockLastUpdateTimestamp = 4
225230
226-let IdxLockParamK = 5
231+let IdxLockGwxAmount = 5
227232
228-let IdxLockParamB = 6
233+let IdxLockWxClaimed = 6
229234
230-func keyLockParamsRecord (userAddress) = makeString(["%s%s__lock", userAddress], SEP)
235+func keyLockParamsRecord (userAddress,txId) = makeString(["%s%s%s__lock", toString(userAddress), match txId {
236+ case b: ByteVector =>
237+ toBase58String(b)
238+ case _: Unit =>
239+ "legacy"
240+ case _ =>
241+ throw("Match error")
242+}], SEP)
231243
232244
233-func readLockParamsRecordOrFail (userAddress) = split(strf(this, keyLockParamsRecord(userAddress)), SEP)
245+func readLockParamsRecordOrFail (userAddress,txId) = split(getStringOrFail(this, keyLockParamsRecord(userAddress, txId)), SEP)
234246
235247
236-func formatLockParamsRecordS (userNum,amount,start,duration,paramK,paramB,lastUpdTimestamp,gwxAmount) = makeString(["%d%d%d%d%d%d%d%d", userNum, amount, start, duration, paramK, paramB, lastUpdTimestamp, gwxAmount], SEP)
248+func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP)
237249
238250
239-func formatLockParamsRecord (userNum,amount,start,duration,paramK,paramB,gwxAmount) = formatLockParamsRecordS(userNum, toString(amount), toString(start), toString(duration), toString(paramK), toString(paramB), toString(lastBlock.timestamp), toString(gwxAmount))
251+func formatLockParamsRecord (amount,start,duration,gwxAmount,wxClaimed) = makeString(["%d%d%d%d%d%d", toString(amount), toString(start), toString(duration), toString(lastBlock.timestamp), toString(gwxAmount), toString(wxClaimed)], SEP)
240252
241253
242254 func keyNextUserNum () = "%s__nextUserNum"
246258
247259
248260 func keyNum2UserMapping (num) = makeString(["%s%s%s__mapping__num2user", num], SEP)
249-
250-
251-func keyLockParamUserAmount (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "amount"], SEP)
252-
253-
254-func keyLockParamStartBlock (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "start"], SEP)
255-
256-
257-func keyLockParamDuration (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "duration"], SEP)
258-
259-
260-func keyLockParamK (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "k"], SEP)
261-
262-
263-func keyLockParamB (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "b"], SEP)
264-
265-
266-func keyLockParamByPeriodK (userNum,period) = makeString(["%s%d%s%d__paramByPeriod", userNum, "k", period], SEP)
267-
268-
269-func keyLockParamByPeriodB (userNum,period) = makeString(["%s%d%s%d__paramByPeriod", userNum, "b", period], SEP)
270261
271262
272263 func keyLockParamTotalAmount () = "%s%s__stats__activeTotalLocked"
281272 func keyStatsUsersCount () = "%s%s__stats__activeUsersCount"
282273
283274
284-func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum], SEP)
275+func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum)], SEP)
285276
286277
287-func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum, lpAssetId], SEP)
278+func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum), lpAssetId], SEP)
288279
289280
290-func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", userNum], SEP)
281+func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", toString(userNum)], SEP)
291282
292283
293284 func keyTotalMaxBoostINTEGRAL () = "%s%s__maxBoostInt__total"
294285
295286
296-func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", userNum], SEP)
287+func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", toString(userNum)], SEP)
297288
298289
299-func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", userNum], SEP)
290+func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", toString(userNum)], SEP)
300291
301292
302-func keyTotalCachedGwx () = "%s%s__gwxCached__total"
303-
304-
305-func keyTotalCachedGwxCorrective () = "%s__gwxCachedTotalCorrective"
293+func keyGwxTotal () = "%s%s__gwx__total"
306294
307295
308296 func keyVote (amountAssetId,priceAssetId,address,epoch) = makeString(["%s%s%s%s%d", "vote", amountAssetId, priceAssetId, toString(address), toString(epoch)], SEP)
354342
355343 let votingEmissionContract = addressFromStringValue(getStringValue(factoryContract, keyVotingEmissionContract))
356344
345+let keyVotingEmissionRateContract = makeString(["%s", "votingEmissionRateContract"], SEP)
346+
357347 let boostCoeff = {
358348 let @ = invoke(emissionContract, "getBoostCoeffREADONLY", nil, nil)
359349 if ($isInstanceOf(@, "Int"))
361351 else throw(($getType(@) + " couldn't be cast to Int"))
362352 }
363353
364-func getTotalCachedGwx (correct) = {
365- let currentEpochUi = getIntegerValue(votingEmissionContract, keyCurrentEpochUi())
366- let keyTargetEpoch = makeString(["%s%s", "totalCachedGwxCorrection__activationEpoch"], SEP)
367- let targetEpochOption = getInteger(this, keyTargetEpoch)
368- let totalCachedGwxRaw = valueOrElse(getInteger(this, keyTotalCachedGwx()), 0)
369- let isCorrectionActivated = if (isDefined(targetEpochOption))
370- then (currentEpochUi >= value(targetEpochOption))
371- else false
372- let corrective = if (if (isCorrectionActivated)
373- then correct
374- else false)
375- then valueOrElse(getInteger(this, keyTotalCachedGwxCorrective()), 0)
376- else 0
377- max([0, (totalCachedGwxRaw + corrective)])
354+func userNumberByAddressOrFail (userAddress) = match getString(this, keyUser2NumMapping(toString(userAddress))) {
355+ case s: String =>
356+ valueOrErrorMessage(parseInt(s), wrapErr("invalid user number"))
357+ case _: Unit =>
358+ throwErr("invalid user")
359+ case _ =>
360+ throw("Match error")
361+}
362+
363+
364+func getGwxAmountTotal () = valueOrElse(getInteger(this, keyGwxTotal()), 0)
365+
366+
367+func getLockedGwxAmount (userAddress) = {
368+ let functionName = "getLockedGwxAmount"
369+ let votingEmissionRateContract = valueOrErrorMessage( match getString(votingEmissionContract, keyVotingEmissionRateContract) {
370+ case _: Unit =>
371+ unit
372+ case s: String =>
373+ addressFromString(s)
374+ case _ =>
375+ throw("Match error")
376+ }, wrapErr("invalid voting emission rate address"))
377+ let lockedVotingEmissionRate = {
378+ let @ = invoke(votingEmissionContract, functionName, [toString(userAddress)], nil)
379+ if ($isInstanceOf(@, "Int"))
380+ then @
381+ else throw(($getType(@) + " couldn't be cast to Int"))
382+ }
383+ let lockedVotingEmission = {
384+ let @ = invoke(votingEmissionRateContract, functionName, [toString(userAddress)], nil)
385+ if ($isInstanceOf(@, "Int"))
386+ then @
387+ else throw(($getType(@) + " couldn't be cast to Int"))
388+ }
389+ let locked = max([lockedVotingEmissionRate, lockedVotingEmission])
390+ locked
378391 }
379392
380393
381-func HistoryEntry (type,user,amount,lockStart,duration,k,b,i) = {
394+func HistoryEntry (type,user,amount,lockStart,duration,gwxAmount,i) = {
382395 let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], SEP)
383- let historyDATA = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount), toString(lockStart), toString(duration), toString(k), toString(b)], SEP)
396+ let historyDATA = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount), toString(lockStart), toString(duration), toString(gwxAmount)], SEP)
384397 StringEntry(historyKEY, historyDATA)
385398 }
386399
390403 let locksCountKEY = keyStatsLocksCount()
391404 let usersCountKEY = keyStatsUsersCount()
392405 let totalAmountKEY = keyLockParamTotalAmount()
393- let locksDurationSumInBlocks = ioz(this, locksDurationSumInBlocksKEY)
394- let locksCount = ioz(this, locksCountKEY)
395- let usersCount = ioz(this, usersCountKEY)
396- let totalAmount = ioz(this, totalAmountKEY)
406+ let locksDurationSumInBlocks = getIntOrZero(this, locksDurationSumInBlocksKEY)
407+ let locksCount = getIntOrZero(this, locksCountKEY)
408+ let usersCount = getIntOrZero(this, usersCountKEY)
409+ let totalAmount = getIntOrZero(this, totalAmountKEY)
397410 [IntegerEntry(locksDurationSumInBlocksKEY, (locksDurationSumInBlocks + durationInc)), IntegerEntry(locksCountKEY, (locksCount + lockCountInc)), IntegerEntry(usersCountKEY, (usersCount + usersCountInc)), IntegerEntry(totalAmountKEY, (totalAmount + totalLockedInc))]
398411 }
399412
400413
401-func calcGwxAmount (kRaw,bRaw,h) = {
402- let SCALE = 1000
403- (((kRaw * h) + bRaw) / SCALE)
404- }
405-
406-
407-func LockParamsEntry (userAddress,userNum,amount,start,duration,k,b,period) = {
408- let userAmountKEY = keyLockParamUserAmount(userNum)
409- let startBlockKEY = keyLockParamStartBlock(userNum)
410- let durationKEY = keyLockParamDuration(userNum)
411- let kKEY = keyLockParamK(userNum)
412- let bKEY = keyLockParamB(userNum)
413- let kByPeriodKEY = keyLockParamByPeriodK(userNum, period)
414- let bByPeriodKEY = keyLockParamByPeriodB(userNum, period)
415- let gwxAmount = calcGwxAmount(k, b, height)
416-[IntegerEntry(userAmountKEY, amount), IntegerEntry(startBlockKEY, start), IntegerEntry(durationKEY, duration), IntegerEntry(kKEY, k), IntegerEntry(bKEY, b), IntegerEntry(kByPeriodKEY, k), IntegerEntry(bByPeriodKEY, b), StringEntry(keyLockParamsRecord(userAddress), formatLockParamsRecord(userNum, amount, start, duration, k, b, gwxAmount))]
417- }
414+func LockParamsEntry (userAddress,txId,amount,start,duration,gwxAmount,wxClaimed) = [StringEntry(keyLockParamsRecord(userAddress, txId), formatLockParamsRecord(amount, start, duration, gwxAmount, wxClaimed))]
418415
419416
420417 func extractOptionalPaymentAmountOrFail (i,expectedAssetId) = if ((size(i.payments) > 1))
429426 }
430427
431428
432-func calcUserGwxAmountAtHeight (userAddress,targetHeight) = {
433- let EMPTY = "empty"
434- let user2NumMappingKEY = keyUser2NumMapping(userAddress)
435- let userNum = valueOrElse(getString(user2NumMappingKEY), EMPTY)
436- let k = valueOrElse(getInteger(keyLockParamK(userNum)), 0)
437- let b = valueOrElse(getInteger(keyLockParamB(userNum)), 0)
438- let gwxAmountCalc = calcGwxAmount(k, b, targetHeight)
439- let gwxAmount = if ((0 > gwxAmountCalc))
440- then 0
441- else gwxAmountCalc
442- gwxAmount
443- }
444-
445-
446-func calcCurrentGwxAmount (userAddress) = calcUserGwxAmountAtHeight(userAddress, height)
429+func getUserGwxAmountTotal (userAddress) = valueOrElse(getInteger(this, keyUserGwxAmountTotal(userAddress)), 0)
447430
448431
449432 func getVotingEmissionEpochInfo () = {
450- let $t01718617476 = {
433+ let $t01505115341 = {
451434 let currentEpochUi = value(getInteger(votingEmissionContract, keyCurrentEpochUi()))
452435 let lastFinalizedEpoch = (currentEpochUi - 1)
453436 if ((0 > lastFinalizedEpoch))
454437 then throwErr("invalid epoch")
455438 else $Tuple2(currentEpochUi, lastFinalizedEpoch)
456439 }
457- let currentEpochUi = $t01718617476._1
458- let lastFinalizedEpoch = $t01718617476._2
440+ let currentEpochUi = $t01505115341._1
441+ let lastFinalizedEpoch = $t01505115341._2
459442 let currentEpochStartHeight = value(getInteger(votingEmissionContract, keyStartHeightByEpoch(currentEpochUi)))
460443 $Tuple2(lastFinalizedEpoch, currentEpochStartHeight)
461444 }
488471
489472 func getUserVoteFinalized (lpAssetIdStr,userAddressStr) = {
490473 let userAddress = addressFromStringValue(userAddressStr)
491- let $t01816718247 = getVotingEmissionEpochInfo()
492- let lastFinalizedEpoch = $t01816718247._1
493- let currentEpochStartHeight = $t01816718247._2
494- let $t01825018325 = getPoolAssetsByLpAssetId(lpAssetIdStr)
495- let amountAssetId = $t01825018325._1
496- let priceAssetId = $t01825018325._2
474+ let $t01603216112 = getVotingEmissionEpochInfo()
475+ let lastFinalizedEpoch = $t01603216112._1
476+ let currentEpochStartHeight = $t01603216112._2
477+ let $t01611516190 = getPoolAssetsByLpAssetId(lpAssetIdStr)
478+ let amountAssetId = $t01611516190._1
479+ let priceAssetId = $t01611516190._2
497480 let userVoteKey = keyVote(amountAssetId, priceAssetId, userAddress, lastFinalizedEpoch)
498481 let userVote = valueOrElse(getInteger(votingEmissionContract, userVoteKey), 0)
499482 userVote
510493
511494
512495 func getVotingResultStaked (lpAssetIdStr) = {
513- let $t01886918949 = getVotingEmissionEpochInfo()
514- let lastFinalizedEpoch = $t01886918949._1
515- let currentEpochStartHeight = $t01886918949._2
496+ let $t01673416814 = getVotingEmissionEpochInfo()
497+ let lastFinalizedEpoch = $t01673416814._1
498+ let currentEpochStartHeight = $t01673416814._2
516499 let votingResultStakedStart = valueOrElse(getInteger(votingEmissionContract, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), 0)
517500 let votingResultStaked = valueOrElse(getInteger(this, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), votingResultStakedStart)
518501 votingResultStaked
520503
521504
522505 func getVotingResultStakedIntegral (lpAssetIdStr) = {
523- let $t01931119391 = getVotingEmissionEpochInfo()
524- let lastFinalizedEpoch = $t01931119391._1
525- let currentEpochStartHeight = $t01931119391._2
506+ let $t01717617256 = getVotingEmissionEpochInfo()
507+ let lastFinalizedEpoch = $t01717617256._1
508+ let currentEpochStartHeight = $t01717617256._2
526509 let votingResultStaked = getVotingResultStaked(lpAssetIdStr)
527510 let votingResultStakedIntegralPrev = valueOrElse(getInteger(this, keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch)), 0)
528511 let votingResultStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch)), currentEpochStartHeight)
533516
534517
535518 func refreshVotingResultStakedIntegral (lpAssetIdStr,stakedVoteDelta) = {
536- let $t02022820308 = getVotingEmissionEpochInfo()
537- let lastFinalizedEpoch = $t02022820308._1
538- let currentEpochStartHeight = $t02022820308._2
519+ let $t01809318173 = getVotingEmissionEpochInfo()
520+ let lastFinalizedEpoch = $t01809318173._1
521+ let currentEpochStartHeight = $t01809318173._2
539522 let votingResultStaked = getVotingResultStaked(lpAssetIdStr)
540523 let votingResultStakedNew = (votingResultStaked + stakedVoteDelta)
541524 let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr)
544527
545528
546529 func getUserVoteStakedIntegral (lpAssetIdStr,userAddressStr) = {
547- let $t02091920999 = getVotingEmissionEpochInfo()
548- let lastFinalizedEpoch = $t02091920999._1
549- let currentEpochStartHeight = $t02091920999._2
530+ let $t01878418864 = getVotingEmissionEpochInfo()
531+ let lastFinalizedEpoch = $t01878418864._1
532+ let currentEpochStartHeight = $t01878418864._2
550533 let userAddress = addressFromStringValue(userAddressStr)
551534 let userVoteStaked = getUserVoteStaked(lpAssetIdStr, userAddressStr)
552535 let userVoteStakedIntegralPrev = valueOrElse(getInteger(this, keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch)), 0)
558541
559542
560543 func refreshVoteStakedIntegral (lpAssetIdStr,userAddressStr,edge) = {
561- let $t02178721867 = getVotingEmissionEpochInfo()
562- let lastFinalizedEpoch = $t02178721867._1
563- let currentEpochStartHeight = $t02178721867._2
544+ let $t01965219732 = getVotingEmissionEpochInfo()
545+ let lastFinalizedEpoch = $t01965219732._1
546+ let currentEpochStartHeight = $t01965219732._2
564547 let userAddress = addressFromStringValue(userAddressStr)
565548 let userVoteFinalized = getUserVoteFinalized(lpAssetIdStr, userAddressStr)
566549 let actions = if ((userVoteFinalized == 0))
579562
580563
581564 func getStakedVotesIntegralsDiff (lpAssetIdStr,userAddressStr) = {
582- let $t02272122801 = getVotingEmissionEpochInfo()
583- let lastFinalizedEpoch = $t02272122801._1
584- let currentEpochStartHeight = $t02272122801._2
565+ let $t02058620666 = getVotingEmissionEpochInfo()
566+ let lastFinalizedEpoch = $t02058620666._1
567+ let currentEpochStartHeight = $t02058620666._2
585568 let userAddress = addressFromStringValue(userAddressStr)
586569 let userVoteStakedIntegralLastKey = keyVoteStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch)
587570 let userVoteStakedIntegralLast = valueOrElse(getInteger(this, userVoteStakedIntegralLastKey), 0)
596579
597580
598581 func refreshBoostEmissionIntegral () = {
599- let wxEmissionPerBlock = iof(emissionContract, keyEmissionRatePerBlockCurrent())
582+ let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent())
600583 let boostingV2LastUpdateHeightOption = getInteger(this, keyBoostingV2LastUpdateHeight())
601584 let boostingV2IngergalOption = getInteger(this, keyBoostingV2Integral())
602- let emissionEnd = iof(emissionContract, keyEmissionEndBlock())
585+ let emissionEnd = getIntOrFail(emissionContract, keyEmissionEndBlock())
603586 let h = if ((height > emissionEnd))
604587 then emissionEnd
605588 else height
619602
620603
621604 func internalClaimWxBoost (lpAssetIdStr,userAddressStr,readOnly) = {
622- let userRecordOption = getString(this, keyLockParamsRecord(userAddressStr))
623- if ((userRecordOption == unit))
624- then $Tuple3(0, nil, "userRecord::is::empty")
625- else {
626- let userRecordArray = split(value(userRecordOption), SEP)
627- let userNumStr = userRecordArray[IdxLockUserNum]
605+ let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
606+ let userNum = userNumberByAddressOrFail(userAddress)
607+ if ((userNum == userNum))
608+ then {
628609 let EMPTYSTR = "empty"
629610 let poolWeight = if ((lpAssetIdStr != EMPTYSTR))
630611 then {
634615 else if (readOnly)
635616 then 0
636617 else throwErr(("not readonly mode: unsupported lp asset " + lpAssetIdStr))
637- let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNumStr, lpAssetIdStr)
638- let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr)
639- let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), ioz(this, userBoostEmissionLastIntegralKEY))
618+ let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNum, lpAssetIdStr)
619+ let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum)
620+ let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), getIntOrZero(this, userBoostEmissionLastIntegralKEY))
640621 let boostEmissionIntegral = refreshBoostEmissionIntegral()._2
641622 let userBoostEmissionIntegral = (boostEmissionIntegral - userBoostEmissionLastIntegral)
642623 if ((0 > userBoostEmissionIntegral))
643624 then throwErr("wrong calculations")
644625 else {
645- let $t02642026559 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr)
646- let stakedVotesIntegralsActions = $t02642026559._1
647- let userVoteIntegralDiff = $t02642026559._2
648- let totalVotesIntegralDiff = $t02642026559._3
626+ let $t02420824347 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr)
627+ let stakedVotesIntegralsActions = $t02420824347._1
628+ let userVoteIntegralDiff = $t02420824347._2
629+ let totalVotesIntegralDiff = $t02420824347._3
649630 let poolUserBoostEmissionIntegral = fraction(userBoostEmissionIntegral, poolWeight, POOLWEIGHTMULT)
650631 let userBoostAvaliableToClaimTotalNew = if ((totalVotesIntegralDiff == 0))
651632 then 0
655636 $Tuple3(userBoostAvaliableToClaimTotalNew, dataState, debug)
656637 }
657638 }
639+ else throw("Strict value is not equal to itself.")
658640 }
659641
660642
661-func lockActions (i,duration) = {
662- let cfgArray = readConfigArrayOrFail()
663- let assetIdStr = cfgArray[IdxCfgAssetId]
664- let assetId = fromBase58String(assetIdStr)
665- let minLockAmount = parseIntValue(cfgArray[IdxCfgMinLockAmount])
666- let minLockDuration = parseIntValue(cfgArray[IdxCfgMinLockDuration])
667- let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration])
643+func lockActions (i,durationMonths) = {
644+ let duration = (durationMonths * blocksInMonth)
645+ let assetIdStr = toBase58String(assetId)
668646 if ((size(i.payments) != 1))
669647 then throwErr("invalid payment - exact one payment must be attached")
670648 else {
672650 let pmtAmount = pmt.amount
673651 if ((assetId != value(pmt.assetId)))
674652 then throwErr((("invalid asset is in payment - " + assetIdStr) + " is expected"))
675- else {
676- let nextUserNumKEY = keyNextUserNum()
677- let userAddressStr = toString(i.caller)
678- let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr)))
679- let userNumStr = if (userIsExisting)
680- then value(getString(keyUser2NumMapping(userAddressStr)))
681- else toString(iof(this, nextUserNumKEY))
682- let userNum = parseIntValue(userNumStr)
683- let lockStart = height
684- let startBlockKEY = keyLockParamStartBlock(userNumStr)
685- let durationKEY = keyLockParamDuration(userNumStr)
686- let userAmountKEY = keyLockParamUserAmount(userNumStr)
687- if (if ((minLockAmount > pmtAmount))
688- then (i.caller != lpStakingPoolsContract)
689- else false)
690- then throwErr(("amount is less then minLockAmount=" + toString(minLockAmount)))
691- else if ((minLockDuration > duration))
692- then throwErr(("passed duration is less then minLockDuration=" + toString(minLockDuration)))
693- else if ((duration > maxLockDuration))
694- then throwErr(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration)))
695- else if (if (userIsExisting)
696- then ((iof(this, startBlockKEY) + iof(this, durationKEY)) >= lockStart)
697- else false)
698- then throwErr("there is an active lock - consider to use increaseLock")
699- else if ((ioz(this, userAmountKEY) > 0))
700- then throwErr(("there are locked WXs - consider to use increaseLock " + userAmountKEY))
701- else {
702- let coeffX8 = fraction(duration, MULT8, maxLockDuration)
703- let gWxAmountStart = fraction(pmtAmount, coeffX8, MULT8)
704- let gWxParamsResultList = aal(invoke(mathContract, "calcGwxParamsREADONLY", [gWxAmountStart, lockStart, duration], nil))
705- let k = ai(gWxParamsResultList[0])
706- let b = ai(gWxParamsResultList[1])
707- let period = toString(ai(gWxParamsResultList[2]))
708- let totalCachedGwxRaw = getTotalCachedGwx(false)
709- let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr)
710- let boostEmissionIntegral = refreshBoostEmissionIntegral()._2
711- let arr = if (userIsExisting)
712- then nil
713- else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)]
714- $Tuple2(((((arr ++ LockParamsEntry(userAddressStr, userNumStr, pmtAmount, lockStart, duration, k, b, period)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting)
715- then 0
716- else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, k, b, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyTotalCachedGwx(), (totalCachedGwxRaw + gWxAmountStart))]), gWxAmountStart)
717- }
718- }
653+ else if (!(containsElement(durationMonthsAllowed, durationMonths)))
654+ then throwErr("invalid duration")
655+ else {
656+ let nextUserNumKEY = keyNextUserNum()
657+ let userAddress = i.caller
658+ let userAddressStr = toString(userAddress)
659+ let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr)))
660+ let userNumStr = if (userIsExisting)
661+ then value(getString(keyUser2NumMapping(userAddressStr)))
662+ else toString(getIntOrFail(this, nextUserNumKEY))
663+ let userNum = parseIntValue(userNumStr)
664+ let lockStart = height
665+ if (if ((minLockAmount > pmtAmount))
666+ then (userAddress != lpStakingPoolsContract)
667+ else false)
668+ then throwErr(("amount is less then minLockAmount=" + toString(minLockAmount)))
669+ else if ((minLockDuration > duration))
670+ then throwErr(("passed duration is less then minLockDuration=" + toString(minLockDuration)))
671+ else if ((duration > maxLockDuration))
672+ then throwErr(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration)))
673+ else {
674+ let gWxAmountStart = fraction(pmtAmount, duration, maxLockDuration)
675+ let gwxAmountTotal = getGwxAmountTotal()
676+ let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum)
677+ let boostEmissionIntegral = refreshBoostEmissionIntegral()._2
678+ let userGwxAmountTotal = getUserGwxAmountTotal(userAddress)
679+ let gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes, userNum], nil)
680+ if ((gwxRewardInv == gwxRewardInv))
681+ then {
682+ let arr = if (userIsExisting)
683+ then nil
684+ else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)]
685+ $Tuple2(((((arr ++ LockParamsEntry(userAddress, i.transactionId, pmtAmount, lockStart, duration, gWxAmountStart, 0)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting)
686+ then 0
687+ else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, gWxAmountStart, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyGwxTotal(), (gwxAmountTotal + gWxAmountStart)), IntegerEntry(keyUserGwxAmountTotal(userAddress), (userGwxAmountTotal + gWxAmountStart))]), gWxAmountStart)
688+ }
689+ else throw("Strict value is not equal to itself.")
690+ }
691+ }
719692 }
693+ }
694+
695+
696+func getWxWithdrawable (userAddress,txIdOption) = {
697+ let userRecordArray = readLockParamsRecordOrFail(userAddress, txIdOption)
698+ let userAmount = parseIntValue(userRecordArray[IdxLockAmount])
699+ let lockStart = parseIntValue(userRecordArray[IdxLockStart])
700+ let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
701+ let lockEnd = (lockStart + lockDuration)
702+ let wxClaimed = parseIntValue(userRecordArray[IdxLockWxClaimed])
703+ let t = ((height - lockStart) / blocksInPeriod)
704+ let exponent = fraction(toBigInt(t), (toBigInt((8 * blocksInPeriod)) * MULT18BI), toBigInt(lockDuration))
705+ let wxWithdrawable = if ((height > lockEnd))
706+ then userAmount
707+ else (toInt(fraction(toBigInt(userAmount), (MULT18BI - pow(toBigInt(5), 1, exponent, SCALE18, SCALE18, DOWN)), MULT18BI)) - wxClaimed)
708+ wxWithdrawable
720709 }
721710
722711
732721
733722 @Callable(i)
734723 func lockRef (duration,referrerAddress,signature) = {
735- let $t03117031235 = lockActions(i, duration)
736- let lockActionsResult = $t03117031235._1
737- let gWxAmountStart = $t03117031235._2
724+ let $t02915529220 = lockActions(i, duration)
725+ let lockActionsResult = $t02915529220._1
726+ let gWxAmountStart = $t02915529220._2
738727 let referralAddress = toString(i.caller)
739728 let refInv = if (if ((referrerAddress == ""))
740729 then true
755744
756745 @Callable(i)
757746 func lock (duration) = {
758- let $t03169331758 = lockActions(i, duration)
759- let lockActionsResult = $t03169331758._1
760- let gWxAmountStart = $t03169331758._2
747+ let $t02967829743 = lockActions(i, duration)
748+ let lockActionsResult = $t02967829743._1
749+ let gWxAmountStart = $t02967829743._2
761750 let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil)
762751 if ((updateRefActivity == updateRefActivity))
763752 then $Tuple2(lockActionsResult, unit)
767756
768757
769758 @Callable(i)
770-func increaseLock (deltaDuration) = {
771- let cfgArray = readConfigArrayOrFail()
772- let assetIdStr = cfgArray[IdxCfgAssetId]
773- let assetId = fromBase58String(assetIdStr)
774- let minLockDuration = parseIntValue(cfgArray[IdxCfgMinLockDuration])
775- let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration])
776- let pmtAmount = extractOptionalPaymentAmountOrFail(i, assetId)
777- let userAddressStr = toString(i.caller)
778- let userRecordArray = readLockParamsRecordOrFail(userAddressStr)
779- let userNumStr = userRecordArray[IdxLockUserNum]
780- let userAmount = parseIntValue(userRecordArray[IdxLockAmount])
781- let lockStart = parseIntValue(userRecordArray[IdxLockStart])
782- let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
783- let lockEnd = (lockStart + lockDuration)
784- let remainingDuration = max([(lockEnd - height), 0])
785- let userAmountNew = (userAmount + pmtAmount)
786- let lockDurationNew = (remainingDuration + deltaDuration)
787- if ((0 > deltaDuration))
788- then throwErr("duration is less then zero")
789- else if ((minLockDuration > lockDurationNew))
790- then throwErr(("lockDurationNew is less then minLockDuration=" + toString(minLockDuration)))
791- else if ((lockDurationNew > maxLockDuration))
792- then throwErr(("deltaDuration + existedLockDuration is greater then maxLockDuration=" + toString(maxLockDuration)))
793- else {
794- let coeffX8 = fraction(lockDurationNew, MULT8, maxLockDuration)
795- let gWxAmountStart = fraction(userAmountNew, coeffX8, MULT8)
796- let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil)
797- if ((updateRefActivity == updateRefActivity))
798- then {
799- let lockStartNew = height
800- let gWxParamsResultList = aal(invoke(mathContract, "calcGwxParamsREADONLY", [gWxAmountStart, lockStartNew, lockDurationNew], nil))
801- let k = ai(gWxParamsResultList[0])
802- let b = ai(gWxParamsResultList[1])
803- let period = toString(ai(gWxParamsResultList[2]))
804- let currUserGwx = calcCurrentGwxAmount(userAddressStr)
805- let gwxDiff = (gWxAmountStart - currUserGwx)
806- if ((0 > gwxDiff))
807- then throwErr(("gwxDiff is less then 0: " + toString(gwxDiff)))
808- else {
809- let totalCachedGwxRaw = getTotalCachedGwx(false)
810- let totalCachedGwxCorrected = getTotalCachedGwx(true)
811- (((LockParamsEntry(userAddressStr, userNumStr, userAmountNew, lockStartNew, lockDurationNew, k, b, period) ++ StatsEntry(pmtAmount, deltaDuration, 0, 0)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, lockDurationNew, k, b, i)) ++ [IntegerEntry(keyTotalCachedGwx(), (totalCachedGwxRaw + gwxDiff))])
812- }
813- }
814- else throw("Strict value is not equal to itself.")
815- }
816- }
817-
818-
819-
820-@Callable(i)
821759 func claimWxBoost (lpAssetIdStr,userAddressStr) = if ((stakingContract != i.caller))
822760 then throwErr("permissions denied")
823761 else {
824- let $t03486334965 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)
825- let userBoostAvailable = $t03486334965._1
826- let dataState = $t03486334965._2
827- let debug = $t03486334965._3
762+ let $t03005330155 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)
763+ let userBoostAvailable = $t03005330155._1
764+ let dataState = $t03005330155._2
765+ let debug = $t03005330155._3
828766 $Tuple2(dataState, [userBoostAvailable])
829767 }
830768
832770
833771 @Callable(i)
834772 func claimWxBoostREADONLY (lpAssetIdStr,userAddressStr) = {
835- let $t03509735198 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true)
836- let userBoostAvailable = $t03509735198._1
837- let dataState = $t03509735198._2
838- let debug = $t03509735198._3
773+ let $t03028730388 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true)
774+ let userBoostAvailable = $t03028730388._1
775+ let dataState = $t03028730388._2
776+ let debug = $t03028730388._3
839777 $Tuple2(nil, [userBoostAvailable, debug])
840778 }
841779
842780
843781
844782 @Callable(i)
845-func unlock (userAddress) = {
846- let userRecordArray = readLockParamsRecordOrFail(userAddress)
847- let userNumStr = userRecordArray[IdxLockUserNum]
783+func unlock (txIdStr) = {
784+ let userAddress = i.caller
785+ let userAddressStr = toString(userAddress)
786+ let txId = fromBase58String(txIdStr)
787+ let userRecordArray = readLockParamsRecordOrFail(userAddress, if ((txIdStr == ""))
788+ then unit
789+ else txId)
848790 let userAmount = parseIntValue(userRecordArray[IdxLockAmount])
849791 let lockStart = parseIntValue(userRecordArray[IdxLockStart])
850792 let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
851- let lockEnd = (lockStart + lockDuration)
852- let cfgArray = readConfigArrayOrFail()
853- let assetId = fromBase58String(cfgArray[IdxCfgAssetId])
854- if ((lockEnd >= height))
855- then throwErr((("wait " + toString(lockEnd)) + " to unlock"))
856- else if ((0 >= userAmount))
857- then throwErr("nothing to unlock")
858- else {
859- let period = valueOrElse(getInteger(mathContract, keyNextPeriod()), 0)
860- (((LockParamsEntry(userAddress, userNumStr, 0, lockStart, lockDuration, 0, 0, toString(period)) ++ StatsEntry(-(userAmount), 0, 0, -1)) :+ HistoryEntry("unlock", userAddress, userAmount, lockStart, lockDuration, 0, 0, i)) :+ ScriptTransfer(addressFromStringValue(userAddress), userAmount, assetId))
861- }
793+ let wxClaimed = parseIntValue(userRecordArray[IdxLockWxClaimed])
794+ let gwxAmount = parseIntValue(userRecordArray[IdxLockGwxAmount])
795+ let t = ((height - lockStart) / blocksInPeriod)
796+ let wxWithdrawable = getWxWithdrawable(userAddress, if ((txIdStr == ""))
797+ then unit
798+ else txId)
799+ let gWxAmountStart = fraction(userAmount, lockDuration, maxLockDuration)
800+ let gwxBurned = min([fraction((t * blocksInPeriod), gWxAmountStart, maxLockDuration), gwxAmount])
801+ let gwxRemaining = ensurePositive((gwxAmount - gwxBurned), "gwxRemaining")
802+ let lockedGwxAmount = getLockedGwxAmount(userAddress)
803+ if ((0 >= userAmount))
804+ then throwErr("nothing to unlock")
805+ else {
806+ let gwxAmountTotal = getGwxAmountTotal()
807+ let userGwxAmountTotal = getUserGwxAmountTotal(userAddress)
808+ let userGwxAmountTotalNew = ensurePositive((userGwxAmountTotal - gwxBurned), "userGwxAmountTotalNew")
809+ if ((lockedGwxAmount > userGwxAmountTotalNew))
810+ then throwErr(("locked gwx amount: " + toString(lockedGwxAmount)))
811+ else {
812+ let userNum = parseIntValue(valueOrErrorMessage(getString(keyUser2NumMapping(userAddressStr)), wrapErr("invalid user number")))
813+ let gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes, userNum], nil)
814+ if ((gwxRewardInv == gwxRewardInv))
815+ then ((((LockParamsEntry(userAddress, txId, userAmount, lockStart, lockDuration, gwxRemaining, (wxClaimed + wxWithdrawable)) ++ StatsEntry(-(wxWithdrawable), 0, 0, 0)) :+ HistoryEntry("unlock", userAddressStr, wxWithdrawable, lockStart, lockDuration, gwxBurned, i)) :+ ScriptTransfer(userAddress, wxWithdrawable, assetId)) ++ [IntegerEntry(keyGwxTotal(), ensurePositive((gwxAmountTotal - gwxBurned), "gwxTotal")), IntegerEntry(keyUserGwxAmountTotal(userAddress), userGwxAmountTotalNew)])
816+ else throw("Strict value is not equal to itself.")
817+ }
818+ }
862819 }
863820
864821
865822
866823 @Callable(i)
867-func gwxUserInfoREADONLY (userAddress) = {
868- let gwxAmount = calcCurrentGwxAmount(userAddress)
824+func gwxUserInfoREADONLY (userAddressStr) = {
825+ let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
826+ let gwxAmount = getUserGwxAmountTotal(userAddress)
869827 $Tuple2(nil, [gwxAmount])
870828 }
871829
872830
873831
874832 @Callable(i)
875-func userMaxDurationREADONLY (userAddressStr) = {
876- let cfgArray = readConfigArrayOrFail()
877- let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration])
878- let userRecordOption = getString(this, keyLockParamsRecord(userAddressStr))
879- if ((userRecordOption == unit))
880- then $Tuple2(nil, $Tuple2("lock", maxLockDuration))
881- else {
882- let userRecordArray = split(value(userRecordOption), SEP)
883- let lockStart = parseIntValue(userRecordArray[IdxLockStart])
884- let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
885- let lockEnd = (lockStart + lockDuration)
886- let remainingDuration = max([(lockEnd - height), 0])
887- let maxDeltaDuration = (maxLockDuration - remainingDuration)
888- $Tuple2(nil, $Tuple2("increaseLock", maxDeltaDuration))
889- }
890- }
833+func userMaxDurationREADONLY (userAddressStr) = $Tuple2(nil, $Tuple2("lock", maxLockDuration))
891834
892835
893836
894837 @Callable(i)
895-func getUserGwxAmountAtHeightREADONLY (userAddress,targetHeight) = {
896- let gwxAmount = calcUserGwxAmountAtHeight(userAddress, targetHeight)
838+func getUserGwxAmountAtHeightREADONLY (userAddressStr,targetHeight) = {
839+ let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
840+ let gwxAmount = getUserGwxAmountTotal(userAddress)
897841 $Tuple2(nil, gwxAmount)
898842 }
899843
900844
901845
902846 @Callable(i)
903-func getTotalCachedGwxREADONLY () = $Tuple2(nil, getTotalCachedGwx(true))
847+func getUserGwxAmount (userAddressStr) = {
848+ let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
849+ let gwxAmount = getUserGwxAmountTotal(userAddress)
850+ $Tuple2(nil, gwxAmount)
851+ }
852+
853+
854+
855+@Callable(i)
856+func getGwxTotalREADONLY () = $Tuple2(nil, getGwxAmountTotal())
904857
905858
906859
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let SEP = "__"
55
66 let SCALE8 = 8
77
88 let MULT8 = 100000000
99
1010 let POOLWEIGHTMULT = MULT8
1111
12-func wrapErr (msg) = makeString(["boosting.ride:", msg], " ")
12+let contractFilename = "boosting.ride"
13+
14+let SCALE18 = 18
15+
16+let MULT18 = 1000000000000000000
17+
18+let MULT18BI = toBigInt(MULT18)
19+
20+let durationMonthsAllowed = [1, 3, 6, 12, 24, 48]
21+
22+let blocksInDay = 1440
23+
24+let blocksInMonth = 43800
25+
26+func wrapErr (msg) = makeString([contractFilename, ": ", msg], "")
1327
1428
1529 func throwErr (msg) = throw(wrapErr(msg))
1630
1731
18-func strf (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
32+func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
1933
2034
21-func ioz (address,key) = valueOrElse(getInteger(address, key), 0)
35+func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0)
2236
2337
24-func iod (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal)
38+func getIntOrDefault (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal)
2539
2640
27-func iof (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
41+func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
2842
2943
3044 func abs (val) = if ((0 > val))
3145 then -(val)
3246 else val
3347
3448
35-func aal (val) = match val {
36- case valAnyLyst: List[Any] =>
37- valAnyLyst
38- case _ =>
39- throwErr("fail to cast into List[Any]")
40-}
41-
42-
43-func ai (val) = match val {
44- case valInt: Int =>
45- valInt
46- case _ =>
47- throwErr("fail to cast into Int")
48-}
49+func ensurePositive (v,m) = if ((v >= 0))
50+ then v
51+ else throwErr((valueOrElse(m, "value") + " should be positive"))
4952
5053
5154 func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP)
5255
5356
54-let referralsContractAddressOrFail = addressFromStringValue(strf(this, keyReferralsContractAddress()))
57+let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(this, keyReferralsContractAddress()))
5558
5659 let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP)
5760
5861 let referralProgramNameDefault = "wxlock"
5962
6063 let referralProgramName = valueOrElse(getString(this, keyReferralProgramName), referralProgramNameDefault)
6164
6265 func keyFactoryAddress () = "%s%s__config__factoryAddress"
6366
6467
6568 let IdxFactoryCfgStakingDapp = 1
6669
6770 let IdxFactoryCfgBoostingDapp = 2
6871
6972 let IdxFactoryCfgIdoDapp = 3
7073
7174 let IdxFactoryCfgTeamDapp = 4
7275
7376 let IdxFactoryCfgEmissionDapp = 5
7477
7578 let IdxFactoryCfgRestDapp = 6
7679
7780 let IdxFactoryCfgSlippageDapp = 7
7881
7982 let IdxFactoryCfgDaoDapp = 8
8083
8184 let IdxFactoryCfgMarketingDapp = 9
8285
8386 let IdxFactoryCfgGwxRewardDapp = 10
8487
8588 let IdxFactoryCfgBirdsDapp = 11
8689
8790 func keyFactoryCfg () = "%s__factoryConfig"
8891
8992
90-func keyFactoryLpList () = "%s__lpTokensList"
91-
92-
9393 func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP)
9494
9595
9696 func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP)
9797
9898
9999 func keyFactoryPoolWeightHistory (poolAddress,num) = ((("%s%s__poolWeight__" + poolAddress) + "__") + toString(num))
100100
101101
102-func readFactoryAddressOrFail () = addressFromStringValue(strf(this, keyFactoryAddress()))
102+func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(this, keyFactoryAddress()))
103103
104104
105-func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP)
106-
107-
108-func readFactoryCfgOrFail (factory) = split(strf(factory, keyFactoryCfg()), SEP)
105+func readFactoryCfgOrFail (factory) = split(getStringOrFail(factory, keyFactoryCfg()), SEP)
109106
110107
111108 func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp])
112109
113110
114111 func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp])
115112
116113
117114 func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp])
118115
119116
120117 func getGwxRewardAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgGwxRewardDapp])
121118
122119
123120 func keyManagerPublicKey () = "%s__managerPublicKey"
124121
125122
126123 func keyManagerVaultAddress () = "%s__managerVaultAddress"
127124
128125
129126 func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current"
130127
131128
132129 func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current"
133130
134131
135132 func keyEmissionStartBlock () = "%s%s__emission__startBlock"
136133
137134
138135 func keyBoostingV2LastUpdateHeight () = "%s%s__boostingV2__startBlock"
139136
140137
141138 func keyBoostingV2Integral () = "%s%s__boostingV2__integral"
142139
143140
144141 func keyEmissionDurationInBlocks () = "%s%s__emission__duration"
145142
146143
147144 func keyEmissionEndBlock () = "%s%s__emission__endBlock"
148145
149146
150-func keyNextPeriod () = "%s__nextPeriod"
151-
152-
153-func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight"
154-
155-
156147 let IdxCfgAssetId = 1
157148
158149 let IdxCfgMinLockAmount = 2
159150
160151 let IdxCfgMinLockDuration = 3
161152
162153 let IdxCfgMaxLockDuration = 4
163154
164155 let IdxCfgMathContract = 5
165156
157+let IdxCfgBlocksInPeriod = 6
158+
166159 func keyConfig () = "%s__config"
167160
168161
169-func readConfigArrayOrFail () = split(strf(this, keyConfig()), SEP)
162+func readConfigArrayOrFail () = split(getStringOrFail(this, keyConfig()), SEP)
170163
171164
172-let mathContract = addressFromStringValue(readConfigArrayOrFail()[IdxCfgMathContract])
165+let cfgArray = readConfigArrayOrFail()
173166
174-func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP)
167+let assetId = fromBase58String(cfgArray[IdxCfgAssetId])
168+
169+let minLockAmount = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMinLockAmount]), wrapErr("invalid min lock amount"))
170+
171+let minLockDuration = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMinLockDuration]), wrapErr("invalid min lock duration"))
172+
173+let maxLockDuration = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMaxLockDuration]), wrapErr("invalid max lock duration"))
174+
175+let mathContract = valueOrErrorMessage(addressFromString(cfgArray[IdxCfgMathContract]), wrapErr("invalid math contract address"))
176+
177+let blocksInPeriod = valueOrErrorMessage(parseInt(cfgArray[IdxCfgBlocksInPeriod]), wrapErr("invalid blocks in period"))
178+
179+func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d%s", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP)
175180
176181
177182 func formatConfig (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = formatConfigS(assetId, toString(minLockAmount), toString(minLockDuration), toString(maxLockDuration), mathContract)
178183
179184
180185 func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) {
181186 case s: String =>
182187 addressFromStringValue(s)
183188 case _ =>
184189 this
185190 }
186191
187192
188193 func managerPublicKeyOrUnit () = {
189194 let managerVaultAddress = getManagerVaultAddressOrThis()
190195 match getString(managerVaultAddress, keyManagerPublicKey()) {
191196 case s: String =>
192197 fromBase58String(s)
193198 case _: Unit =>
194199 unit
195200 case _ =>
196201 throw("Match error")
197202 }
198203 }
199204
200205
201206 func mustManager (i) = {
202207 let pd = throwErr("Permission denied")
203208 match managerPublicKeyOrUnit() {
204209 case pk: ByteVector =>
205210 if ((i.callerPublicKey == pk))
206211 then true
207212 else pd
208213 case _: Unit =>
209214 if ((i.caller == this))
210215 then true
211216 else pd
212217 case _ =>
213218 throw("Match error")
214219 }
215220 }
216221
217222
218-let IdxLockUserNum = 1
223+let IdxLockAmount = 1
219224
220-let IdxLockAmount = 2
225+let IdxLockStart = 2
221226
222-let IdxLockStart = 3
227+let IdxLockDuration = 3
223228
224-let IdxLockDuration = 4
229+let IdxLockLastUpdateTimestamp = 4
225230
226-let IdxLockParamK = 5
231+let IdxLockGwxAmount = 5
227232
228-let IdxLockParamB = 6
233+let IdxLockWxClaimed = 6
229234
230-func keyLockParamsRecord (userAddress) = makeString(["%s%s__lock", userAddress], SEP)
235+func keyLockParamsRecord (userAddress,txId) = makeString(["%s%s%s__lock", toString(userAddress), match txId {
236+ case b: ByteVector =>
237+ toBase58String(b)
238+ case _: Unit =>
239+ "legacy"
240+ case _ =>
241+ throw("Match error")
242+}], SEP)
231243
232244
233-func readLockParamsRecordOrFail (userAddress) = split(strf(this, keyLockParamsRecord(userAddress)), SEP)
245+func readLockParamsRecordOrFail (userAddress,txId) = split(getStringOrFail(this, keyLockParamsRecord(userAddress, txId)), SEP)
234246
235247
236-func formatLockParamsRecordS (userNum,amount,start,duration,paramK,paramB,lastUpdTimestamp,gwxAmount) = makeString(["%d%d%d%d%d%d%d%d", userNum, amount, start, duration, paramK, paramB, lastUpdTimestamp, gwxAmount], SEP)
248+func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP)
237249
238250
239-func formatLockParamsRecord (userNum,amount,start,duration,paramK,paramB,gwxAmount) = formatLockParamsRecordS(userNum, toString(amount), toString(start), toString(duration), toString(paramK), toString(paramB), toString(lastBlock.timestamp), toString(gwxAmount))
251+func formatLockParamsRecord (amount,start,duration,gwxAmount,wxClaimed) = makeString(["%d%d%d%d%d%d", toString(amount), toString(start), toString(duration), toString(lastBlock.timestamp), toString(gwxAmount), toString(wxClaimed)], SEP)
240252
241253
242254 func keyNextUserNum () = "%s__nextUserNum"
243255
244256
245257 func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", userAddress], SEP)
246258
247259
248260 func keyNum2UserMapping (num) = makeString(["%s%s%s__mapping__num2user", num], SEP)
249-
250-
251-func keyLockParamUserAmount (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "amount"], SEP)
252-
253-
254-func keyLockParamStartBlock (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "start"], SEP)
255-
256-
257-func keyLockParamDuration (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "duration"], SEP)
258-
259-
260-func keyLockParamK (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "k"], SEP)
261-
262-
263-func keyLockParamB (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "b"], SEP)
264-
265-
266-func keyLockParamByPeriodK (userNum,period) = makeString(["%s%d%s%d__paramByPeriod", userNum, "k", period], SEP)
267-
268-
269-func keyLockParamByPeriodB (userNum,period) = makeString(["%s%d%s%d__paramByPeriod", userNum, "b", period], SEP)
270261
271262
272263 func keyLockParamTotalAmount () = "%s%s__stats__activeTotalLocked"
273264
274265
275266 func keyStatsLocksDurationSumInBlocks () = "%s%s__stats__locksDurationSumInBlocks"
276267
277268
278269 func keyStatsLocksCount () = "%s%s__stats__locksCount"
279270
280271
281272 func keyStatsUsersCount () = "%s%s__stats__activeUsersCount"
282273
283274
284-func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum], SEP)
275+func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum)], SEP)
285276
286277
287-func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum, lpAssetId], SEP)
278+func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum), lpAssetId], SEP)
288279
289280
290-func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", userNum], SEP)
281+func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", toString(userNum)], SEP)
291282
292283
293284 func keyTotalMaxBoostINTEGRAL () = "%s%s__maxBoostInt__total"
294285
295286
296-func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", userNum], SEP)
287+func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", toString(userNum)], SEP)
297288
298289
299-func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", userNum], SEP)
290+func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", toString(userNum)], SEP)
300291
301292
302-func keyTotalCachedGwx () = "%s%s__gwxCached__total"
303-
304-
305-func keyTotalCachedGwxCorrective () = "%s__gwxCachedTotalCorrective"
293+func keyGwxTotal () = "%s%s__gwx__total"
306294
307295
308296 func keyVote (amountAssetId,priceAssetId,address,epoch) = makeString(["%s%s%s%s%d", "vote", amountAssetId, priceAssetId, toString(address), toString(epoch)], SEP)
309297
310298
311299 func keyStartHeightByEpoch (epoch) = makeString(["%s%d", "startHeight", toString(epoch)], SEP)
312300
313301
314302 func keyCurrentEpochUi () = makeString(["%s", "currentEpochUi"], SEP)
315303
316304
317305 func keyVotingResultStaked (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStaked", lpAssetIdStr, toString(epoch)], SEP)
318306
319307
320308 func keyVotingResultStakedIntegral (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStakedIntegral", lpAssetIdStr, toString(epoch)], SEP)
321309
322310
323311 func keyVotingResultStakedLastUpdateHeight (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStakedIntegralLastUpdateHeight", lpAssetIdStr, toString(epoch)], SEP)
324312
325313
326314 func keyVotingResultStakedIntegralLast (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "votingResultStakedIntegralLast", lpAssetIdStr, toString(address), toString(epoch)], SEP)
327315
328316
329317 func keyVoteStakedIntegral (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegral", lpAssetIdStr, toString(address), toString(epoch)], SEP)
330318
331319
332320 func keyVoteStakedLastUpdateHeight (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegralLastUpdateHeight", lpAssetIdStr, toString(address), toString(epoch)], SEP)
333321
334322
335323 func keyVoteStakedIntegralLast (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegralLast", lpAssetIdStr, toString(address), toString(epoch)], SEP)
336324
337325
338326 func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s", "staked", userAddressStr, lpAssetIdStr], SEP)
339327
340328
341329 let factoryContract = readFactoryAddressOrFail()
342330
343331 let factoryCfg = readFactoryCfgOrFail(factoryContract)
344332
345333 let emissionContract = getEmissionAddressOrFail(factoryCfg)
346334
347335 let stakingContract = getStakingAddressOrFail(factoryCfg)
348336
349337 let gwxRewardContract = getGwxRewardAddressOrFail(factoryCfg)
350338
351339 let lpStakingPoolsContract = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(makeString(["%s", "lpStakingPoolsContract"], SEP)), wrapErr("lp_staking_pools contract address is undefined"))), wrapErr("invalid lp_staking_pools contract address"))
352340
353341 let keyVotingEmissionContract = makeString(["%s", "votingEmissionContract"], SEP)
354342
355343 let votingEmissionContract = addressFromStringValue(getStringValue(factoryContract, keyVotingEmissionContract))
356344
345+let keyVotingEmissionRateContract = makeString(["%s", "votingEmissionRateContract"], SEP)
346+
357347 let boostCoeff = {
358348 let @ = invoke(emissionContract, "getBoostCoeffREADONLY", nil, nil)
359349 if ($isInstanceOf(@, "Int"))
360350 then @
361351 else throw(($getType(@) + " couldn't be cast to Int"))
362352 }
363353
364-func getTotalCachedGwx (correct) = {
365- let currentEpochUi = getIntegerValue(votingEmissionContract, keyCurrentEpochUi())
366- let keyTargetEpoch = makeString(["%s%s", "totalCachedGwxCorrection__activationEpoch"], SEP)
367- let targetEpochOption = getInteger(this, keyTargetEpoch)
368- let totalCachedGwxRaw = valueOrElse(getInteger(this, keyTotalCachedGwx()), 0)
369- let isCorrectionActivated = if (isDefined(targetEpochOption))
370- then (currentEpochUi >= value(targetEpochOption))
371- else false
372- let corrective = if (if (isCorrectionActivated)
373- then correct
374- else false)
375- then valueOrElse(getInteger(this, keyTotalCachedGwxCorrective()), 0)
376- else 0
377- max([0, (totalCachedGwxRaw + corrective)])
354+func userNumberByAddressOrFail (userAddress) = match getString(this, keyUser2NumMapping(toString(userAddress))) {
355+ case s: String =>
356+ valueOrErrorMessage(parseInt(s), wrapErr("invalid user number"))
357+ case _: Unit =>
358+ throwErr("invalid user")
359+ case _ =>
360+ throw("Match error")
361+}
362+
363+
364+func getGwxAmountTotal () = valueOrElse(getInteger(this, keyGwxTotal()), 0)
365+
366+
367+func getLockedGwxAmount (userAddress) = {
368+ let functionName = "getLockedGwxAmount"
369+ let votingEmissionRateContract = valueOrErrorMessage( match getString(votingEmissionContract, keyVotingEmissionRateContract) {
370+ case _: Unit =>
371+ unit
372+ case s: String =>
373+ addressFromString(s)
374+ case _ =>
375+ throw("Match error")
376+ }, wrapErr("invalid voting emission rate address"))
377+ let lockedVotingEmissionRate = {
378+ let @ = invoke(votingEmissionContract, functionName, [toString(userAddress)], nil)
379+ if ($isInstanceOf(@, "Int"))
380+ then @
381+ else throw(($getType(@) + " couldn't be cast to Int"))
382+ }
383+ let lockedVotingEmission = {
384+ let @ = invoke(votingEmissionRateContract, functionName, [toString(userAddress)], nil)
385+ if ($isInstanceOf(@, "Int"))
386+ then @
387+ else throw(($getType(@) + " couldn't be cast to Int"))
388+ }
389+ let locked = max([lockedVotingEmissionRate, lockedVotingEmission])
390+ locked
378391 }
379392
380393
381-func HistoryEntry (type,user,amount,lockStart,duration,k,b,i) = {
394+func HistoryEntry (type,user,amount,lockStart,duration,gwxAmount,i) = {
382395 let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], SEP)
383- let historyDATA = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount), toString(lockStart), toString(duration), toString(k), toString(b)], SEP)
396+ let historyDATA = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount), toString(lockStart), toString(duration), toString(gwxAmount)], SEP)
384397 StringEntry(historyKEY, historyDATA)
385398 }
386399
387400
388401 func StatsEntry (totalLockedInc,durationInc,lockCountInc,usersCountInc) = {
389402 let locksDurationSumInBlocksKEY = keyStatsLocksDurationSumInBlocks()
390403 let locksCountKEY = keyStatsLocksCount()
391404 let usersCountKEY = keyStatsUsersCount()
392405 let totalAmountKEY = keyLockParamTotalAmount()
393- let locksDurationSumInBlocks = ioz(this, locksDurationSumInBlocksKEY)
394- let locksCount = ioz(this, locksCountKEY)
395- let usersCount = ioz(this, usersCountKEY)
396- let totalAmount = ioz(this, totalAmountKEY)
406+ let locksDurationSumInBlocks = getIntOrZero(this, locksDurationSumInBlocksKEY)
407+ let locksCount = getIntOrZero(this, locksCountKEY)
408+ let usersCount = getIntOrZero(this, usersCountKEY)
409+ let totalAmount = getIntOrZero(this, totalAmountKEY)
397410 [IntegerEntry(locksDurationSumInBlocksKEY, (locksDurationSumInBlocks + durationInc)), IntegerEntry(locksCountKEY, (locksCount + lockCountInc)), IntegerEntry(usersCountKEY, (usersCount + usersCountInc)), IntegerEntry(totalAmountKEY, (totalAmount + totalLockedInc))]
398411 }
399412
400413
401-func calcGwxAmount (kRaw,bRaw,h) = {
402- let SCALE = 1000
403- (((kRaw * h) + bRaw) / SCALE)
404- }
405-
406-
407-func LockParamsEntry (userAddress,userNum,amount,start,duration,k,b,period) = {
408- let userAmountKEY = keyLockParamUserAmount(userNum)
409- let startBlockKEY = keyLockParamStartBlock(userNum)
410- let durationKEY = keyLockParamDuration(userNum)
411- let kKEY = keyLockParamK(userNum)
412- let bKEY = keyLockParamB(userNum)
413- let kByPeriodKEY = keyLockParamByPeriodK(userNum, period)
414- let bByPeriodKEY = keyLockParamByPeriodB(userNum, period)
415- let gwxAmount = calcGwxAmount(k, b, height)
416-[IntegerEntry(userAmountKEY, amount), IntegerEntry(startBlockKEY, start), IntegerEntry(durationKEY, duration), IntegerEntry(kKEY, k), IntegerEntry(bKEY, b), IntegerEntry(kByPeriodKEY, k), IntegerEntry(bByPeriodKEY, b), StringEntry(keyLockParamsRecord(userAddress), formatLockParamsRecord(userNum, amount, start, duration, k, b, gwxAmount))]
417- }
414+func LockParamsEntry (userAddress,txId,amount,start,duration,gwxAmount,wxClaimed) = [StringEntry(keyLockParamsRecord(userAddress, txId), formatLockParamsRecord(amount, start, duration, gwxAmount, wxClaimed))]
418415
419416
420417 func extractOptionalPaymentAmountOrFail (i,expectedAssetId) = if ((size(i.payments) > 1))
421418 then throwErr("only one payment is allowed")
422419 else if ((size(i.payments) == 0))
423420 then 0
424421 else {
425422 let pmt = i.payments[0]
426423 if ((value(pmt.assetId) != expectedAssetId))
427424 then throwErr("invalid asset id in payment")
428425 else pmt.amount
429426 }
430427
431428
432-func calcUserGwxAmountAtHeight (userAddress,targetHeight) = {
433- let EMPTY = "empty"
434- let user2NumMappingKEY = keyUser2NumMapping(userAddress)
435- let userNum = valueOrElse(getString(user2NumMappingKEY), EMPTY)
436- let k = valueOrElse(getInteger(keyLockParamK(userNum)), 0)
437- let b = valueOrElse(getInteger(keyLockParamB(userNum)), 0)
438- let gwxAmountCalc = calcGwxAmount(k, b, targetHeight)
439- let gwxAmount = if ((0 > gwxAmountCalc))
440- then 0
441- else gwxAmountCalc
442- gwxAmount
443- }
444-
445-
446-func calcCurrentGwxAmount (userAddress) = calcUserGwxAmountAtHeight(userAddress, height)
429+func getUserGwxAmountTotal (userAddress) = valueOrElse(getInteger(this, keyUserGwxAmountTotal(userAddress)), 0)
447430
448431
449432 func getVotingEmissionEpochInfo () = {
450- let $t01718617476 = {
433+ let $t01505115341 = {
451434 let currentEpochUi = value(getInteger(votingEmissionContract, keyCurrentEpochUi()))
452435 let lastFinalizedEpoch = (currentEpochUi - 1)
453436 if ((0 > lastFinalizedEpoch))
454437 then throwErr("invalid epoch")
455438 else $Tuple2(currentEpochUi, lastFinalizedEpoch)
456439 }
457- let currentEpochUi = $t01718617476._1
458- let lastFinalizedEpoch = $t01718617476._2
440+ let currentEpochUi = $t01505115341._1
441+ let lastFinalizedEpoch = $t01505115341._2
459442 let currentEpochStartHeight = value(getInteger(votingEmissionContract, keyStartHeightByEpoch(currentEpochUi)))
460443 $Tuple2(lastFinalizedEpoch, currentEpochStartHeight)
461444 }
462445
463446
464447 func getPoolAssetsByLpAssetId (lpAssetIdStr) = {
465448 let idxAmountAssetId = 4
466449 let idxPriceAssetId = 5
467450 let poolCfg = {
468451 let @ = invoke(factoryContract, "getPoolConfigByLpAssetIdREADONLY", [lpAssetIdStr], nil)
469452 if ($isInstanceOf(@, "List[Any]"))
470453 then @
471454 else throw(($getType(@) + " couldn't be cast to List[Any]"))
472455 }
473456 let amountAssetId = {
474457 let @ = poolCfg[idxAmountAssetId]
475458 if ($isInstanceOf(@, "String"))
476459 then @
477460 else throw(($getType(@) + " couldn't be cast to String"))
478461 }
479462 let priceAssetId = {
480463 let @ = poolCfg[idxPriceAssetId]
481464 if ($isInstanceOf(@, "String"))
482465 then @
483466 else throw(($getType(@) + " couldn't be cast to String"))
484467 }
485468 $Tuple2(amountAssetId, priceAssetId)
486469 }
487470
488471
489472 func getUserVoteFinalized (lpAssetIdStr,userAddressStr) = {
490473 let userAddress = addressFromStringValue(userAddressStr)
491- let $t01816718247 = getVotingEmissionEpochInfo()
492- let lastFinalizedEpoch = $t01816718247._1
493- let currentEpochStartHeight = $t01816718247._2
494- let $t01825018325 = getPoolAssetsByLpAssetId(lpAssetIdStr)
495- let amountAssetId = $t01825018325._1
496- let priceAssetId = $t01825018325._2
474+ let $t01603216112 = getVotingEmissionEpochInfo()
475+ let lastFinalizedEpoch = $t01603216112._1
476+ let currentEpochStartHeight = $t01603216112._2
477+ let $t01611516190 = getPoolAssetsByLpAssetId(lpAssetIdStr)
478+ let amountAssetId = $t01611516190._1
479+ let priceAssetId = $t01611516190._2
497480 let userVoteKey = keyVote(amountAssetId, priceAssetId, userAddress, lastFinalizedEpoch)
498481 let userVote = valueOrElse(getInteger(votingEmissionContract, userVoteKey), 0)
499482 userVote
500483 }
501484
502485
503486 func getUserVoteStaked (lpAssetIdStr,userAddressStr) = {
504487 let stakedByUser = valueOrElse(getInteger(stakingContract, keyStakedByUser(userAddressStr, lpAssetIdStr)), 0)
505488 let userVote = getUserVoteFinalized(lpAssetIdStr, userAddressStr)
506489 if ((stakedByUser == 0))
507490 then 0
508491 else userVote
509492 }
510493
511494
512495 func getVotingResultStaked (lpAssetIdStr) = {
513- let $t01886918949 = getVotingEmissionEpochInfo()
514- let lastFinalizedEpoch = $t01886918949._1
515- let currentEpochStartHeight = $t01886918949._2
496+ let $t01673416814 = getVotingEmissionEpochInfo()
497+ let lastFinalizedEpoch = $t01673416814._1
498+ let currentEpochStartHeight = $t01673416814._2
516499 let votingResultStakedStart = valueOrElse(getInteger(votingEmissionContract, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), 0)
517500 let votingResultStaked = valueOrElse(getInteger(this, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), votingResultStakedStart)
518501 votingResultStaked
519502 }
520503
521504
522505 func getVotingResultStakedIntegral (lpAssetIdStr) = {
523- let $t01931119391 = getVotingEmissionEpochInfo()
524- let lastFinalizedEpoch = $t01931119391._1
525- let currentEpochStartHeight = $t01931119391._2
506+ let $t01717617256 = getVotingEmissionEpochInfo()
507+ let lastFinalizedEpoch = $t01717617256._1
508+ let currentEpochStartHeight = $t01717617256._2
526509 let votingResultStaked = getVotingResultStaked(lpAssetIdStr)
527510 let votingResultStakedIntegralPrev = valueOrElse(getInteger(this, keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch)), 0)
528511 let votingResultStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch)), currentEpochStartHeight)
529512 let votingResultStakedIntegralDh = (height - votingResultStakedLastUpdateHeight)
530513 let votingResultStakedIntegral = ((votingResultStakedIntegralDh * votingResultStaked) + votingResultStakedIntegralPrev)
531514 votingResultStakedIntegral
532515 }
533516
534517
535518 func refreshVotingResultStakedIntegral (lpAssetIdStr,stakedVoteDelta) = {
536- let $t02022820308 = getVotingEmissionEpochInfo()
537- let lastFinalizedEpoch = $t02022820308._1
538- let currentEpochStartHeight = $t02022820308._2
519+ let $t01809318173 = getVotingEmissionEpochInfo()
520+ let lastFinalizedEpoch = $t01809318173._1
521+ let currentEpochStartHeight = $t01809318173._2
539522 let votingResultStaked = getVotingResultStaked(lpAssetIdStr)
540523 let votingResultStakedNew = (votingResultStaked + stakedVoteDelta)
541524 let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr)
542525 [IntegerEntry(keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch), votingResultStakedNew), IntegerEntry(keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch), height), IntegerEntry(keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch), votingResultStakedIntegral)]
543526 }
544527
545528
546529 func getUserVoteStakedIntegral (lpAssetIdStr,userAddressStr) = {
547- let $t02091920999 = getVotingEmissionEpochInfo()
548- let lastFinalizedEpoch = $t02091920999._1
549- let currentEpochStartHeight = $t02091920999._2
530+ let $t01878418864 = getVotingEmissionEpochInfo()
531+ let lastFinalizedEpoch = $t01878418864._1
532+ let currentEpochStartHeight = $t01878418864._2
550533 let userAddress = addressFromStringValue(userAddressStr)
551534 let userVoteStaked = getUserVoteStaked(lpAssetIdStr, userAddressStr)
552535 let userVoteStakedIntegralPrev = valueOrElse(getInteger(this, keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch)), 0)
553536 let userVoteStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVoteStakedLastUpdateHeight(lpAssetIdStr, userAddress, lastFinalizedEpoch)), currentEpochStartHeight)
554537 let userVoteStakedIntegralDh = (height - userVoteStakedLastUpdateHeight)
555538 let userVoteStakedIntegral = ((userVoteStakedIntegralDh * userVoteStaked) + userVoteStakedIntegralPrev)
556539 userVoteStakedIntegral
557540 }
558541
559542
560543 func refreshVoteStakedIntegral (lpAssetIdStr,userAddressStr,edge) = {
561- let $t02178721867 = getVotingEmissionEpochInfo()
562- let lastFinalizedEpoch = $t02178721867._1
563- let currentEpochStartHeight = $t02178721867._2
544+ let $t01965219732 = getVotingEmissionEpochInfo()
545+ let lastFinalizedEpoch = $t01965219732._1
546+ let currentEpochStartHeight = $t01965219732._2
564547 let userAddress = addressFromStringValue(userAddressStr)
565548 let userVoteFinalized = getUserVoteFinalized(lpAssetIdStr, userAddressStr)
566549 let actions = if ((userVoteFinalized == 0))
567550 then nil
568551 else {
569552 let stakedVoteDelta = if (edge)
570553 then userVoteFinalized
571554 else -(userVoteFinalized)
572555 let votingResultActions = refreshVotingResultStakedIntegral(lpAssetIdStr, stakedVoteDelta)
573556 let userVoteStakedIntegral = getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr)
574557 let voteActions = [IntegerEntry(keyVoteStakedLastUpdateHeight(lpAssetIdStr, userAddress, lastFinalizedEpoch), height), IntegerEntry(keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch), userVoteStakedIntegral)]
575558 (votingResultActions ++ voteActions)
576559 }
577560 actions
578561 }
579562
580563
581564 func getStakedVotesIntegralsDiff (lpAssetIdStr,userAddressStr) = {
582- let $t02272122801 = getVotingEmissionEpochInfo()
583- let lastFinalizedEpoch = $t02272122801._1
584- let currentEpochStartHeight = $t02272122801._2
565+ let $t02058620666 = getVotingEmissionEpochInfo()
566+ let lastFinalizedEpoch = $t02058620666._1
567+ let currentEpochStartHeight = $t02058620666._2
585568 let userAddress = addressFromStringValue(userAddressStr)
586569 let userVoteStakedIntegralLastKey = keyVoteStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch)
587570 let userVoteStakedIntegralLast = valueOrElse(getInteger(this, userVoteStakedIntegralLastKey), 0)
588571 let votingResultStakedIntegralLastKey = keyVotingResultStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch)
589572 let votingResultStakedIntegralLast = valueOrElse(getInteger(this, votingResultStakedIntegralLastKey), 0)
590573 let userVoteStakedIntegral = getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr)
591574 let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr)
592575 let userVoteStakedIntegralDiff = (userVoteStakedIntegral - userVoteStakedIntegralLast)
593576 let votingResultStakedIntegralDiff = (votingResultStakedIntegral - votingResultStakedIntegralLast)
594577 $Tuple3([IntegerEntry(userVoteStakedIntegralLastKey, userVoteStakedIntegral), IntegerEntry(votingResultStakedIntegralLastKey, votingResultStakedIntegral)], userVoteStakedIntegralDiff, votingResultStakedIntegralDiff)
595578 }
596579
597580
598581 func refreshBoostEmissionIntegral () = {
599- let wxEmissionPerBlock = iof(emissionContract, keyEmissionRatePerBlockCurrent())
582+ let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent())
600583 let boostingV2LastUpdateHeightOption = getInteger(this, keyBoostingV2LastUpdateHeight())
601584 let boostingV2IngergalOption = getInteger(this, keyBoostingV2Integral())
602- let emissionEnd = iof(emissionContract, keyEmissionEndBlock())
585+ let emissionEnd = getIntOrFail(emissionContract, keyEmissionEndBlock())
603586 let h = if ((height > emissionEnd))
604587 then emissionEnd
605588 else height
606589 let dh = match boostingV2LastUpdateHeightOption {
607590 case lastUpdateHeight: Int =>
608591 max([(h - lastUpdateHeight), 0])
609592 case _: Unit =>
610593 0
611594 case _ =>
612595 throw("Match error")
613596 }
614597 let boostEmissionPerBlock = ((wxEmissionPerBlock * (boostCoeff - 1)) / boostCoeff)
615598 let boostEmissionIntegralPrev = valueOrElse(boostingV2IngergalOption, 0)
616599 let boostEmissionIntegral = ((boostEmissionPerBlock * dh) + boostEmissionIntegralPrev)
617600 $Tuple2([IntegerEntry(keyBoostingV2Integral(), boostEmissionIntegral), IntegerEntry(keyBoostingV2LastUpdateHeight(), height)], boostEmissionIntegral)
618601 }
619602
620603
621604 func internalClaimWxBoost (lpAssetIdStr,userAddressStr,readOnly) = {
622- let userRecordOption = getString(this, keyLockParamsRecord(userAddressStr))
623- if ((userRecordOption == unit))
624- then $Tuple3(0, nil, "userRecord::is::empty")
625- else {
626- let userRecordArray = split(value(userRecordOption), SEP)
627- let userNumStr = userRecordArray[IdxLockUserNum]
605+ let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
606+ let userNum = userNumberByAddressOrFail(userAddress)
607+ if ((userNum == userNum))
608+ then {
628609 let EMPTYSTR = "empty"
629610 let poolWeight = if ((lpAssetIdStr != EMPTYSTR))
630611 then {
631612 let poolAddressStr = valueOrErrorMessage(getString(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr)), wrapErr(("unsupported lp asset " + lpAssetIdStr)))
632613 getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr))
633614 }
634615 else if (readOnly)
635616 then 0
636617 else throwErr(("not readonly mode: unsupported lp asset " + lpAssetIdStr))
637- let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNumStr, lpAssetIdStr)
638- let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr)
639- let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), ioz(this, userBoostEmissionLastIntegralKEY))
618+ let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNum, lpAssetIdStr)
619+ let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum)
620+ let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), getIntOrZero(this, userBoostEmissionLastIntegralKEY))
640621 let boostEmissionIntegral = refreshBoostEmissionIntegral()._2
641622 let userBoostEmissionIntegral = (boostEmissionIntegral - userBoostEmissionLastIntegral)
642623 if ((0 > userBoostEmissionIntegral))
643624 then throwErr("wrong calculations")
644625 else {
645- let $t02642026559 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr)
646- let stakedVotesIntegralsActions = $t02642026559._1
647- let userVoteIntegralDiff = $t02642026559._2
648- let totalVotesIntegralDiff = $t02642026559._3
626+ let $t02420824347 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr)
627+ let stakedVotesIntegralsActions = $t02420824347._1
628+ let userVoteIntegralDiff = $t02420824347._2
629+ let totalVotesIntegralDiff = $t02420824347._3
649630 let poolUserBoostEmissionIntegral = fraction(userBoostEmissionIntegral, poolWeight, POOLWEIGHTMULT)
650631 let userBoostAvaliableToClaimTotalNew = if ((totalVotesIntegralDiff == 0))
651632 then 0
652633 else fraction(poolUserBoostEmissionIntegral, userVoteIntegralDiff, totalVotesIntegralDiff)
653634 let dataState = ([IntegerEntry(userLpBoostEmissionLastIntegralKEY, boostEmissionIntegral)] ++ stakedVotesIntegralsActions)
654635 let debug = makeString([toString(userBoostEmissionLastIntegral), toString(userBoostEmissionIntegral), toString(poolWeight), toString(userVoteIntegralDiff), toString(totalVotesIntegralDiff)], ":")
655636 $Tuple3(userBoostAvaliableToClaimTotalNew, dataState, debug)
656637 }
657638 }
639+ else throw("Strict value is not equal to itself.")
658640 }
659641
660642
661-func lockActions (i,duration) = {
662- let cfgArray = readConfigArrayOrFail()
663- let assetIdStr = cfgArray[IdxCfgAssetId]
664- let assetId = fromBase58String(assetIdStr)
665- let minLockAmount = parseIntValue(cfgArray[IdxCfgMinLockAmount])
666- let minLockDuration = parseIntValue(cfgArray[IdxCfgMinLockDuration])
667- let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration])
643+func lockActions (i,durationMonths) = {
644+ let duration = (durationMonths * blocksInMonth)
645+ let assetIdStr = toBase58String(assetId)
668646 if ((size(i.payments) != 1))
669647 then throwErr("invalid payment - exact one payment must be attached")
670648 else {
671649 let pmt = i.payments[0]
672650 let pmtAmount = pmt.amount
673651 if ((assetId != value(pmt.assetId)))
674652 then throwErr((("invalid asset is in payment - " + assetIdStr) + " is expected"))
675- else {
676- let nextUserNumKEY = keyNextUserNum()
677- let userAddressStr = toString(i.caller)
678- let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr)))
679- let userNumStr = if (userIsExisting)
680- then value(getString(keyUser2NumMapping(userAddressStr)))
681- else toString(iof(this, nextUserNumKEY))
682- let userNum = parseIntValue(userNumStr)
683- let lockStart = height
684- let startBlockKEY = keyLockParamStartBlock(userNumStr)
685- let durationKEY = keyLockParamDuration(userNumStr)
686- let userAmountKEY = keyLockParamUserAmount(userNumStr)
687- if (if ((minLockAmount > pmtAmount))
688- then (i.caller != lpStakingPoolsContract)
689- else false)
690- then throwErr(("amount is less then minLockAmount=" + toString(minLockAmount)))
691- else if ((minLockDuration > duration))
692- then throwErr(("passed duration is less then minLockDuration=" + toString(minLockDuration)))
693- else if ((duration > maxLockDuration))
694- then throwErr(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration)))
695- else if (if (userIsExisting)
696- then ((iof(this, startBlockKEY) + iof(this, durationKEY)) >= lockStart)
697- else false)
698- then throwErr("there is an active lock - consider to use increaseLock")
699- else if ((ioz(this, userAmountKEY) > 0))
700- then throwErr(("there are locked WXs - consider to use increaseLock " + userAmountKEY))
701- else {
702- let coeffX8 = fraction(duration, MULT8, maxLockDuration)
703- let gWxAmountStart = fraction(pmtAmount, coeffX8, MULT8)
704- let gWxParamsResultList = aal(invoke(mathContract, "calcGwxParamsREADONLY", [gWxAmountStart, lockStart, duration], nil))
705- let k = ai(gWxParamsResultList[0])
706- let b = ai(gWxParamsResultList[1])
707- let period = toString(ai(gWxParamsResultList[2]))
708- let totalCachedGwxRaw = getTotalCachedGwx(false)
709- let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr)
710- let boostEmissionIntegral = refreshBoostEmissionIntegral()._2
711- let arr = if (userIsExisting)
712- then nil
713- else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)]
714- $Tuple2(((((arr ++ LockParamsEntry(userAddressStr, userNumStr, pmtAmount, lockStart, duration, k, b, period)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting)
715- then 0
716- else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, k, b, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyTotalCachedGwx(), (totalCachedGwxRaw + gWxAmountStart))]), gWxAmountStart)
717- }
718- }
653+ else if (!(containsElement(durationMonthsAllowed, durationMonths)))
654+ then throwErr("invalid duration")
655+ else {
656+ let nextUserNumKEY = keyNextUserNum()
657+ let userAddress = i.caller
658+ let userAddressStr = toString(userAddress)
659+ let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr)))
660+ let userNumStr = if (userIsExisting)
661+ then value(getString(keyUser2NumMapping(userAddressStr)))
662+ else toString(getIntOrFail(this, nextUserNumKEY))
663+ let userNum = parseIntValue(userNumStr)
664+ let lockStart = height
665+ if (if ((minLockAmount > pmtAmount))
666+ then (userAddress != lpStakingPoolsContract)
667+ else false)
668+ then throwErr(("amount is less then minLockAmount=" + toString(minLockAmount)))
669+ else if ((minLockDuration > duration))
670+ then throwErr(("passed duration is less then minLockDuration=" + toString(minLockDuration)))
671+ else if ((duration > maxLockDuration))
672+ then throwErr(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration)))
673+ else {
674+ let gWxAmountStart = fraction(pmtAmount, duration, maxLockDuration)
675+ let gwxAmountTotal = getGwxAmountTotal()
676+ let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum)
677+ let boostEmissionIntegral = refreshBoostEmissionIntegral()._2
678+ let userGwxAmountTotal = getUserGwxAmountTotal(userAddress)
679+ let gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes, userNum], nil)
680+ if ((gwxRewardInv == gwxRewardInv))
681+ then {
682+ let arr = if (userIsExisting)
683+ then nil
684+ else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)]
685+ $Tuple2(((((arr ++ LockParamsEntry(userAddress, i.transactionId, pmtAmount, lockStart, duration, gWxAmountStart, 0)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting)
686+ then 0
687+ else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, gWxAmountStart, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyGwxTotal(), (gwxAmountTotal + gWxAmountStart)), IntegerEntry(keyUserGwxAmountTotal(userAddress), (userGwxAmountTotal + gWxAmountStart))]), gWxAmountStart)
688+ }
689+ else throw("Strict value is not equal to itself.")
690+ }
691+ }
719692 }
693+ }
694+
695+
696+func getWxWithdrawable (userAddress,txIdOption) = {
697+ let userRecordArray = readLockParamsRecordOrFail(userAddress, txIdOption)
698+ let userAmount = parseIntValue(userRecordArray[IdxLockAmount])
699+ let lockStart = parseIntValue(userRecordArray[IdxLockStart])
700+ let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
701+ let lockEnd = (lockStart + lockDuration)
702+ let wxClaimed = parseIntValue(userRecordArray[IdxLockWxClaimed])
703+ let t = ((height - lockStart) / blocksInPeriod)
704+ let exponent = fraction(toBigInt(t), (toBigInt((8 * blocksInPeriod)) * MULT18BI), toBigInt(lockDuration))
705+ let wxWithdrawable = if ((height > lockEnd))
706+ then userAmount
707+ else (toInt(fraction(toBigInt(userAmount), (MULT18BI - pow(toBigInt(5), 1, exponent, SCALE18, SCALE18, DOWN)), MULT18BI)) - wxClaimed)
708+ wxWithdrawable
720709 }
721710
722711
723712 @Callable(i)
724713 func constructor (factoryAddressStr,lockAssetIdStr,minLockAmount,minDuration,maxDuration,mathContract) = {
725714 let checkCaller = mustManager(i)
726715 if ((checkCaller == checkCaller))
727716 then ([IntegerEntry(keyNextUserNum(), 0), StringEntry(keyConfig(), formatConfig(lockAssetIdStr, minLockAmount, minDuration, maxDuration, mathContract)), StringEntry(keyFactoryAddress(), factoryAddressStr)] ++ StatsEntry(0, 0, 0, 0))
728717 else throw("Strict value is not equal to itself.")
729718 }
730719
731720
732721
733722 @Callable(i)
734723 func lockRef (duration,referrerAddress,signature) = {
735- let $t03117031235 = lockActions(i, duration)
736- let lockActionsResult = $t03117031235._1
737- let gWxAmountStart = $t03117031235._2
724+ let $t02915529220 = lockActions(i, duration)
725+ let lockActionsResult = $t02915529220._1
726+ let gWxAmountStart = $t02915529220._2
738727 let referralAddress = toString(i.caller)
739728 let refInv = if (if ((referrerAddress == ""))
740729 then true
741730 else (signature == base58''))
742731 then unit
743732 else invoke(referralsContractAddressOrFail, "createPair", [referralProgramName, referrerAddress, referralAddress, signature], nil)
744733 if ((refInv == refInv))
745734 then {
746735 let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil)
747736 if ((updateRefActivity == updateRefActivity))
748737 then $Tuple2(lockActionsResult, unit)
749738 else throw("Strict value is not equal to itself.")
750739 }
751740 else throw("Strict value is not equal to itself.")
752741 }
753742
754743
755744
756745 @Callable(i)
757746 func lock (duration) = {
758- let $t03169331758 = lockActions(i, duration)
759- let lockActionsResult = $t03169331758._1
760- let gWxAmountStart = $t03169331758._2
747+ let $t02967829743 = lockActions(i, duration)
748+ let lockActionsResult = $t02967829743._1
749+ let gWxAmountStart = $t02967829743._2
761750 let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil)
762751 if ((updateRefActivity == updateRefActivity))
763752 then $Tuple2(lockActionsResult, unit)
764753 else throw("Strict value is not equal to itself.")
765754 }
766755
767756
768757
769758 @Callable(i)
770-func increaseLock (deltaDuration) = {
771- let cfgArray = readConfigArrayOrFail()
772- let assetIdStr = cfgArray[IdxCfgAssetId]
773- let assetId = fromBase58String(assetIdStr)
774- let minLockDuration = parseIntValue(cfgArray[IdxCfgMinLockDuration])
775- let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration])
776- let pmtAmount = extractOptionalPaymentAmountOrFail(i, assetId)
777- let userAddressStr = toString(i.caller)
778- let userRecordArray = readLockParamsRecordOrFail(userAddressStr)
779- let userNumStr = userRecordArray[IdxLockUserNum]
780- let userAmount = parseIntValue(userRecordArray[IdxLockAmount])
781- let lockStart = parseIntValue(userRecordArray[IdxLockStart])
782- let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
783- let lockEnd = (lockStart + lockDuration)
784- let remainingDuration = max([(lockEnd - height), 0])
785- let userAmountNew = (userAmount + pmtAmount)
786- let lockDurationNew = (remainingDuration + deltaDuration)
787- if ((0 > deltaDuration))
788- then throwErr("duration is less then zero")
789- else if ((minLockDuration > lockDurationNew))
790- then throwErr(("lockDurationNew is less then minLockDuration=" + toString(minLockDuration)))
791- else if ((lockDurationNew > maxLockDuration))
792- then throwErr(("deltaDuration + existedLockDuration is greater then maxLockDuration=" + toString(maxLockDuration)))
793- else {
794- let coeffX8 = fraction(lockDurationNew, MULT8, maxLockDuration)
795- let gWxAmountStart = fraction(userAmountNew, coeffX8, MULT8)
796- let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil)
797- if ((updateRefActivity == updateRefActivity))
798- then {
799- let lockStartNew = height
800- let gWxParamsResultList = aal(invoke(mathContract, "calcGwxParamsREADONLY", [gWxAmountStart, lockStartNew, lockDurationNew], nil))
801- let k = ai(gWxParamsResultList[0])
802- let b = ai(gWxParamsResultList[1])
803- let period = toString(ai(gWxParamsResultList[2]))
804- let currUserGwx = calcCurrentGwxAmount(userAddressStr)
805- let gwxDiff = (gWxAmountStart - currUserGwx)
806- if ((0 > gwxDiff))
807- then throwErr(("gwxDiff is less then 0: " + toString(gwxDiff)))
808- else {
809- let totalCachedGwxRaw = getTotalCachedGwx(false)
810- let totalCachedGwxCorrected = getTotalCachedGwx(true)
811- (((LockParamsEntry(userAddressStr, userNumStr, userAmountNew, lockStartNew, lockDurationNew, k, b, period) ++ StatsEntry(pmtAmount, deltaDuration, 0, 0)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, lockDurationNew, k, b, i)) ++ [IntegerEntry(keyTotalCachedGwx(), (totalCachedGwxRaw + gwxDiff))])
812- }
813- }
814- else throw("Strict value is not equal to itself.")
815- }
816- }
817-
818-
819-
820-@Callable(i)
821759 func claimWxBoost (lpAssetIdStr,userAddressStr) = if ((stakingContract != i.caller))
822760 then throwErr("permissions denied")
823761 else {
824- let $t03486334965 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)
825- let userBoostAvailable = $t03486334965._1
826- let dataState = $t03486334965._2
827- let debug = $t03486334965._3
762+ let $t03005330155 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)
763+ let userBoostAvailable = $t03005330155._1
764+ let dataState = $t03005330155._2
765+ let debug = $t03005330155._3
828766 $Tuple2(dataState, [userBoostAvailable])
829767 }
830768
831769
832770
833771 @Callable(i)
834772 func claimWxBoostREADONLY (lpAssetIdStr,userAddressStr) = {
835- let $t03509735198 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true)
836- let userBoostAvailable = $t03509735198._1
837- let dataState = $t03509735198._2
838- let debug = $t03509735198._3
773+ let $t03028730388 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true)
774+ let userBoostAvailable = $t03028730388._1
775+ let dataState = $t03028730388._2
776+ let debug = $t03028730388._3
839777 $Tuple2(nil, [userBoostAvailable, debug])
840778 }
841779
842780
843781
844782 @Callable(i)
845-func unlock (userAddress) = {
846- let userRecordArray = readLockParamsRecordOrFail(userAddress)
847- let userNumStr = userRecordArray[IdxLockUserNum]
783+func unlock (txIdStr) = {
784+ let userAddress = i.caller
785+ let userAddressStr = toString(userAddress)
786+ let txId = fromBase58String(txIdStr)
787+ let userRecordArray = readLockParamsRecordOrFail(userAddress, if ((txIdStr == ""))
788+ then unit
789+ else txId)
848790 let userAmount = parseIntValue(userRecordArray[IdxLockAmount])
849791 let lockStart = parseIntValue(userRecordArray[IdxLockStart])
850792 let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
851- let lockEnd = (lockStart + lockDuration)
852- let cfgArray = readConfigArrayOrFail()
853- let assetId = fromBase58String(cfgArray[IdxCfgAssetId])
854- if ((lockEnd >= height))
855- then throwErr((("wait " + toString(lockEnd)) + " to unlock"))
856- else if ((0 >= userAmount))
857- then throwErr("nothing to unlock")
858- else {
859- let period = valueOrElse(getInteger(mathContract, keyNextPeriod()), 0)
860- (((LockParamsEntry(userAddress, userNumStr, 0, lockStart, lockDuration, 0, 0, toString(period)) ++ StatsEntry(-(userAmount), 0, 0, -1)) :+ HistoryEntry("unlock", userAddress, userAmount, lockStart, lockDuration, 0, 0, i)) :+ ScriptTransfer(addressFromStringValue(userAddress), userAmount, assetId))
861- }
793+ let wxClaimed = parseIntValue(userRecordArray[IdxLockWxClaimed])
794+ let gwxAmount = parseIntValue(userRecordArray[IdxLockGwxAmount])
795+ let t = ((height - lockStart) / blocksInPeriod)
796+ let wxWithdrawable = getWxWithdrawable(userAddress, if ((txIdStr == ""))
797+ then unit
798+ else txId)
799+ let gWxAmountStart = fraction(userAmount, lockDuration, maxLockDuration)
800+ let gwxBurned = min([fraction((t * blocksInPeriod), gWxAmountStart, maxLockDuration), gwxAmount])
801+ let gwxRemaining = ensurePositive((gwxAmount - gwxBurned), "gwxRemaining")
802+ let lockedGwxAmount = getLockedGwxAmount(userAddress)
803+ if ((0 >= userAmount))
804+ then throwErr("nothing to unlock")
805+ else {
806+ let gwxAmountTotal = getGwxAmountTotal()
807+ let userGwxAmountTotal = getUserGwxAmountTotal(userAddress)
808+ let userGwxAmountTotalNew = ensurePositive((userGwxAmountTotal - gwxBurned), "userGwxAmountTotalNew")
809+ if ((lockedGwxAmount > userGwxAmountTotalNew))
810+ then throwErr(("locked gwx amount: " + toString(lockedGwxAmount)))
811+ else {
812+ let userNum = parseIntValue(valueOrErrorMessage(getString(keyUser2NumMapping(userAddressStr)), wrapErr("invalid user number")))
813+ let gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes, userNum], nil)
814+ if ((gwxRewardInv == gwxRewardInv))
815+ then ((((LockParamsEntry(userAddress, txId, userAmount, lockStart, lockDuration, gwxRemaining, (wxClaimed + wxWithdrawable)) ++ StatsEntry(-(wxWithdrawable), 0, 0, 0)) :+ HistoryEntry("unlock", userAddressStr, wxWithdrawable, lockStart, lockDuration, gwxBurned, i)) :+ ScriptTransfer(userAddress, wxWithdrawable, assetId)) ++ [IntegerEntry(keyGwxTotal(), ensurePositive((gwxAmountTotal - gwxBurned), "gwxTotal")), IntegerEntry(keyUserGwxAmountTotal(userAddress), userGwxAmountTotalNew)])
816+ else throw("Strict value is not equal to itself.")
817+ }
818+ }
862819 }
863820
864821
865822
866823 @Callable(i)
867-func gwxUserInfoREADONLY (userAddress) = {
868- let gwxAmount = calcCurrentGwxAmount(userAddress)
824+func gwxUserInfoREADONLY (userAddressStr) = {
825+ let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
826+ let gwxAmount = getUserGwxAmountTotal(userAddress)
869827 $Tuple2(nil, [gwxAmount])
870828 }
871829
872830
873831
874832 @Callable(i)
875-func userMaxDurationREADONLY (userAddressStr) = {
876- let cfgArray = readConfigArrayOrFail()
877- let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration])
878- let userRecordOption = getString(this, keyLockParamsRecord(userAddressStr))
879- if ((userRecordOption == unit))
880- then $Tuple2(nil, $Tuple2("lock", maxLockDuration))
881- else {
882- let userRecordArray = split(value(userRecordOption), SEP)
883- let lockStart = parseIntValue(userRecordArray[IdxLockStart])
884- let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
885- let lockEnd = (lockStart + lockDuration)
886- let remainingDuration = max([(lockEnd - height), 0])
887- let maxDeltaDuration = (maxLockDuration - remainingDuration)
888- $Tuple2(nil, $Tuple2("increaseLock", maxDeltaDuration))
889- }
890- }
833+func userMaxDurationREADONLY (userAddressStr) = $Tuple2(nil, $Tuple2("lock", maxLockDuration))
891834
892835
893836
894837 @Callable(i)
895-func getUserGwxAmountAtHeightREADONLY (userAddress,targetHeight) = {
896- let gwxAmount = calcUserGwxAmountAtHeight(userAddress, targetHeight)
838+func getUserGwxAmountAtHeightREADONLY (userAddressStr,targetHeight) = {
839+ let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
840+ let gwxAmount = getUserGwxAmountTotal(userAddress)
897841 $Tuple2(nil, gwxAmount)
898842 }
899843
900844
901845
902846 @Callable(i)
903-func getTotalCachedGwxREADONLY () = $Tuple2(nil, getTotalCachedGwx(true))
847+func getUserGwxAmount (userAddressStr) = {
848+ let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
849+ let gwxAmount = getUserGwxAmountTotal(userAddress)
850+ $Tuple2(nil, gwxAmount)
851+ }
852+
853+
854+
855+@Callable(i)
856+func getGwxTotalREADONLY () = $Tuple2(nil, getGwxAmountTotal())
904857
905858
906859
907860 @Callable(i)
908861 func onBoostEmissionUpdate () = {
909862 let checkCaller = if ((i.caller == emissionContract))
910863 then true
911864 else mustManager(i)
912865 if ((checkCaller == checkCaller))
913866 then refreshBoostEmissionIntegral()
914867 else throw("Strict value is not equal to itself.")
915868 }
916869
917870
918871
919872 @Callable(i)
920873 func onStakedVoteUpdate (lpAssetIdStr,userAddressStr,edge) = {
921874 let checkCaller = if ((i.caller == stakingContract))
922875 then true
923876 else mustManager(i)
924877 if ((checkCaller == checkCaller))
925878 then {
926879 let actions = refreshVoteStakedIntegral(lpAssetIdStr, userAddressStr, edge)
927880 $Tuple2(actions, unit)
928881 }
929882 else throw("Strict value is not equal to itself.")
930883 }
931884
932885
933886
934887 @Callable(i)
935888 func getVotingResultStakedREADONLY (lpAssetIdStr) = $Tuple2(nil, getVotingResultStaked(lpAssetIdStr))
936889
937890
938891
939892 @Callable(i)
940893 func getVotingResultStakedIntegralREADONLY (lpAssetIdStr) = $Tuple2(nil, getVotingResultStakedIntegral(lpAssetIdStr))
941894
942895
943896
944897 @Callable(i)
945898 func getUserVoteFinalizedREADONLY (lpAssetIdStr,userAddressStr) = $Tuple2(nil, getUserVoteFinalized(lpAssetIdStr, userAddressStr))
946899
947900
948901
949902 @Callable(i)
950903 func getUserVoteStakedIntegralREADONLY (lpAssetIdStr,userAddressStr) = $Tuple2(nil, getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr))
951904
952905
953906 @Verifier(tx)
954907 func verify () = {
955908 let targetPublicKey = match managerPublicKeyOrUnit() {
956909 case pk: ByteVector =>
957910 pk
958911 case _: Unit =>
959912 tx.senderPublicKey
960913 case _ =>
961914 throw("Match error")
962915 }
963916 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
964917 }
965918

github/deemru/w8io/026f985 
179.03 ms