tx · 319rJAAw9xqhiwHhkf2aoRxkpy2JsiWLU9sKv1ym55HG

3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy:  -0.02700000 Waves

2023.08.14 17:39 [2710362] smart account 3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy > SELF 0.00000000 Waves

{ "type": 13, "id": "319rJAAw9xqhiwHhkf2aoRxkpy2JsiWLU9sKv1ym55HG", "fee": 2700000, "feeAssetId": null, "timestamp": 1692024013968, "version": 2, "chainId": 84, "sender": "3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy", "senderPublicKey": "9W33iCCNfmFxUbiC6XZcH5x7f6xfwC7Jb3BoExT5q2PV", "proofs": [ "5TurZTvh4sezLLsSA11iYEwJ87tQps1BaiMacwUADhLiaw28wkMrvNeNJKNKs8T8WL9VvFnf43aHxEiCmkobo5Y" ], "script": "base64:BgKZLwgCEggKBggIAQEBCBIFCgMBCAISAwoBARIDCgEBEgQKAggIEgQKAggIEgMKAQgSAwoBCBIDCgEIEgQKAggBEgASABIFCgMICAQSAwoBCBIDCgEIEgQKAggIEgQKAggIIgNTRVAiBlNDQUxFOCIFTVVMVDgiDlBPT0xXRUlHSFRNVUxUIgd3cmFwRXJyIgNtc2ciCHRocm93RXJyIgRzdHJmIgdhZGRyZXNzIgNrZXkiA2lveiIDaW9kIgpkZWZhdWx0VmFsIgNpb2YiA2FicyIDdmFsIgNhYWwiByRtYXRjaDAiCnZhbEFueUx5c3QiAmFpIgZ2YWxJbnQiG2tleVJlZmVycmFsc0NvbnRyYWN0QWRkcmVzcyIecmVmZXJyYWxzQ29udHJhY3RBZGRyZXNzT3JGYWlsIhZrZXlSZWZlcnJhbFByb2dyYW1OYW1lIhpyZWZlcnJhbFByb2dyYW1OYW1lRGVmYXVsdCITcmVmZXJyYWxQcm9ncmFtTmFtZSIRa2V5RmFjdG9yeUFkZHJlc3MiGElkeEZhY3RvcnlDZmdTdGFraW5nRGFwcCIZSWR4RmFjdG9yeUNmZ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dldFVzZXJWb3RlRmluYWxpemVkUkVBRE9OTFkCAmJKAmJSCQCUCgIFA25pbAkBAmRpAgUCYkoFAmJSAmFJASFnZXRVc2VyVm90ZVN0YWtlZEludGVncmFsUkVBRE9OTFkCAmJKAmJSCQCUCgIFA25pbAkBAmREAgUCYkoFAmJSAQJmcAECZnEABAJmcgQBcgkBAmFGAAMJAAECBQFyAgpCeXRlVmVjdG9yBAJhSwUBcgUCYUsDCQABAgUBcgIEVW5pdAgFAmZwD3NlbmRlclB1YmxpY0tleQkAAgECC01hdGNoIGVycm9yCQD0AwMIBQJmcAlib2R5Qnl0ZXMJAJEDAggFAmZwBnByb29mcwAABQJmclpY1bA=", "height": 2710362, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: FisWfXcmP2HDisjzh8QUDSVtj5gya5bWqp5HuzvvbgSt Next: AuGR23H1WV8mAjnRLoKH5dQnxjNH7SeF9ifWm75DfPFJ Diff:
OldNewDifferences
99
1010 let POOLWEIGHTMULT = MULT8
1111
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], "")
12+func wrapErr (msg) = makeString(["boosting.ride:", msg], " ")
2713
2814
2915 func throwErr (msg) = throw(wrapErr(msg))
3016
3117
32-func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
18+func strf (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
3319
3420
35-func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0)
21+func ioz (address,key) = valueOrElse(getInteger(address, key), 0)
3622
3723
38-func getIntOrDefault (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal)
24+func iod (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal)
3925
4026
41-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
27+func iof (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
4228
4329
4430 func abs (val) = if ((0 > val))
4632 else val
4733
4834
49-func ensurePositive (v,m) = if ((v >= 0))
50- then v
51- else throwErr((valueOrElse(m, "value") + " should be positive"))
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+}
5249
5350
5451 func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP)
5552
5653
57-let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(this, keyReferralsContractAddress()))
54+let referralsContractAddressOrFail = addressFromStringValue(strf(this, keyReferralsContractAddress()))
5855
5956 let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP)
6057
9087 func keyFactoryCfg () = "%s__factoryConfig"
9188
9289
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(getStringOrFail(this, keyFactoryAddress()))
102+func readFactoryAddressOrFail () = addressFromStringValue(strf(this, keyFactoryAddress()))
103103
104104
105-func readFactoryCfgOrFail (factory) = split(getStringOrFail(factory, keyFactoryCfg()), SEP)
105+func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP)
106+
107+
108+func readFactoryCfgOrFail (factory) = split(strf(factory, keyFactoryCfg()), SEP)
106109
107110
108111 func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp])
144147 func keyEmissionEndBlock () = "%s%s__emission__endBlock"
145148
146149
150+func keyNextPeriod () = "%s__nextPeriod"
151+
152+
153+func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight"
154+
155+
147156 let IdxCfgAssetId = 1
148157
149158 let IdxCfgMinLockAmount = 2
154163
155164 let IdxCfgMathContract = 5
156165
157-let IdxCfgBlocksInPeriod = 6
158-
159166 func keyConfig () = "%s__config"
160167
161168
162-func readConfigArrayOrFail () = split(getStringOrFail(this, keyConfig()), SEP)
169+func readConfigArrayOrFail () = split(strf(this, keyConfig()), SEP)
163170
164171
165-let cfgArray = readConfigArrayOrFail()
172+let mathContract = addressFromStringValue(readConfigArrayOrFail()[IdxCfgMathContract])
166173
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)
174+func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP)
180175
181176
182177 func formatConfig (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = formatConfigS(assetId, toString(minLockAmount), toString(minLockDuration), toString(maxLockDuration), mathContract)
220215 }
221216
222217
223-let IdxLockAmount = 1
218+let IdxLockUserNum = 1
224219
225-let IdxLockStart = 2
220+let IdxLockAmount = 2
226221
227-let IdxLockDuration = 3
222+let IdxLockStart = 3
228223
229-let IdxLockLastUpdateTimestamp = 4
224+let IdxLockDuration = 4
230225
231-let IdxLockGwxAmount = 5
226+let IdxLockParamK = 5
232227
233-let IdxLockWxClaimed = 6
228+let IdxLockParamB = 6
234229
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)
230+func keyLockParamsRecord (userAddress) = makeString(["%s%s__lock", userAddress], SEP)
243231
244232
245-func readLockParamsRecordOrFail (userAddress,txId) = split(getStringOrFail(this, keyLockParamsRecord(userAddress, txId)), SEP)
233+func readLockParamsRecordOrFail (userAddress) = split(strf(this, keyLockParamsRecord(userAddress)), SEP)
246234
247235
248-func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP)
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)
249237
250238
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)
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))
252240
253241
254242 func keyNextUserNum () = "%s__nextUserNum"
258246
259247
260248 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)
261270
262271
263272 func keyLockParamTotalAmount () = "%s%s__stats__activeTotalLocked"
272281 func keyStatsUsersCount () = "%s%s__stats__activeUsersCount"
273282
274283
275-func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum)], SEP)
284+func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum], SEP)
276285
277286
278-func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum), lpAssetId], SEP)
287+func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum, lpAssetId], SEP)
279288
280289
281-func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", toString(userNum)], SEP)
290+func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", userNum], SEP)
282291
283292
284293 func keyTotalMaxBoostINTEGRAL () = "%s%s__maxBoostInt__total"
285294
286295
287-func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", toString(userNum)], SEP)
296+func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", userNum], SEP)
288297
289298
290-func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", toString(userNum)], SEP)
299+func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", userNum], SEP)
291300
292301
293-func keyGwxTotal () = "%s%s__gwx__total"
302+func keyTotalCachedGwx () = "%s%s__gwxCached__total"
303+
304+
305+func keyTotalCachedGwxCorrective () = "%s__gwxCachedTotalCorrective"
294306
295307
296308 func keyVote (amountAssetId,priceAssetId,address,epoch) = makeString(["%s%s%s%s%d", "vote", amountAssetId, priceAssetId, toString(address), toString(epoch)], SEP)
342354
343355 let votingEmissionContract = addressFromStringValue(getStringValue(factoryContract, keyVotingEmissionContract))
344356
345-let keyVotingEmissionRateContract = makeString(["%s", "votingEmissionRateContract"], SEP)
346-
347357 let boostCoeff = {
348358 let @ = invoke(emissionContract, "getBoostCoeffREADONLY", nil, nil)
349359 if ($isInstanceOf(@, "Int"))
351361 else throw(($getType(@) + " couldn't be cast to Int"))
352362 }
353363
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
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)])
391378 }
392379
393380
394-func HistoryEntry (type,user,amount,lockStart,duration,gwxAmount,i) = {
381+func HistoryEntry (type,user,amount,lockStart,duration,k,b,i) = {
395382 let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], 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)
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)
397384 StringEntry(historyKEY, historyDATA)
398385 }
399386
403390 let locksCountKEY = keyStatsLocksCount()
404391 let usersCountKEY = keyStatsUsersCount()
405392 let totalAmountKEY = keyLockParamTotalAmount()
406- let locksDurationSumInBlocks = getIntOrZero(this, locksDurationSumInBlocksKEY)
407- let locksCount = getIntOrZero(this, locksCountKEY)
408- let usersCount = getIntOrZero(this, usersCountKEY)
409- let totalAmount = getIntOrZero(this, totalAmountKEY)
393+ let locksDurationSumInBlocks = ioz(this, locksDurationSumInBlocksKEY)
394+ let locksCount = ioz(this, locksCountKEY)
395+ let usersCount = ioz(this, usersCountKEY)
396+ let totalAmount = ioz(this, totalAmountKEY)
410397 [IntegerEntry(locksDurationSumInBlocksKEY, (locksDurationSumInBlocks + durationInc)), IntegerEntry(locksCountKEY, (locksCount + lockCountInc)), IntegerEntry(usersCountKEY, (usersCount + usersCountInc)), IntegerEntry(totalAmountKEY, (totalAmount + totalLockedInc))]
411398 }
412399
413400
414-func LockParamsEntry (userAddress,txId,amount,start,duration,gwxAmount,wxClaimed) = [StringEntry(keyLockParamsRecord(userAddress, txId), formatLockParamsRecord(amount, start, duration, gwxAmount, wxClaimed))]
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+ }
415418
416419
417420 func extractOptionalPaymentAmountOrFail (i,expectedAssetId) = if ((size(i.payments) > 1))
426429 }
427430
428431
429-func getUserGwxAmountTotal (userAddress) = valueOrElse(getInteger(this, keyUserGwxAmountTotal(userAddress)), 0)
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)
430447
431448
432449 func getVotingEmissionEpochInfo () = {
433- let $t01505115341 = {
450+ let $t01718617476 = {
434451 let currentEpochUi = value(getInteger(votingEmissionContract, keyCurrentEpochUi()))
435452 let lastFinalizedEpoch = (currentEpochUi - 1)
436453 if ((0 > lastFinalizedEpoch))
437454 then throwErr("invalid epoch")
438455 else $Tuple2(currentEpochUi, lastFinalizedEpoch)
439456 }
440- let currentEpochUi = $t01505115341._1
441- let lastFinalizedEpoch = $t01505115341._2
457+ let currentEpochUi = $t01718617476._1
458+ let lastFinalizedEpoch = $t01718617476._2
442459 let currentEpochStartHeight = value(getInteger(votingEmissionContract, keyStartHeightByEpoch(currentEpochUi)))
443460 $Tuple2(lastFinalizedEpoch, currentEpochStartHeight)
444461 }
471488
472489 func getUserVoteFinalized (lpAssetIdStr,userAddressStr) = {
473490 let userAddress = addressFromStringValue(userAddressStr)
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
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
480497 let userVoteKey = keyVote(amountAssetId, priceAssetId, userAddress, lastFinalizedEpoch)
481498 let userVote = valueOrElse(getInteger(votingEmissionContract, userVoteKey), 0)
482499 userVote
493510
494511
495512 func getVotingResultStaked (lpAssetIdStr) = {
496- let $t01673416814 = getVotingEmissionEpochInfo()
497- let lastFinalizedEpoch = $t01673416814._1
498- let currentEpochStartHeight = $t01673416814._2
513+ let $t01886918949 = getVotingEmissionEpochInfo()
514+ let lastFinalizedEpoch = $t01886918949._1
515+ let currentEpochStartHeight = $t01886918949._2
499516 let votingResultStakedStart = valueOrElse(getInteger(votingEmissionContract, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), 0)
500517 let votingResultStaked = valueOrElse(getInteger(this, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), votingResultStakedStart)
501518 votingResultStaked
503520
504521
505522 func getVotingResultStakedIntegral (lpAssetIdStr) = {
506- let $t01717617256 = getVotingEmissionEpochInfo()
507- let lastFinalizedEpoch = $t01717617256._1
508- let currentEpochStartHeight = $t01717617256._2
523+ let $t01931119391 = getVotingEmissionEpochInfo()
524+ let lastFinalizedEpoch = $t01931119391._1
525+ let currentEpochStartHeight = $t01931119391._2
509526 let votingResultStaked = getVotingResultStaked(lpAssetIdStr)
510527 let votingResultStakedIntegralPrev = valueOrElse(getInteger(this, keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch)), 0)
511528 let votingResultStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch)), currentEpochStartHeight)
516533
517534
518535 func refreshVotingResultStakedIntegral (lpAssetIdStr,stakedVoteDelta) = {
519- let $t01809318173 = getVotingEmissionEpochInfo()
520- let lastFinalizedEpoch = $t01809318173._1
521- let currentEpochStartHeight = $t01809318173._2
536+ let $t02022820308 = getVotingEmissionEpochInfo()
537+ let lastFinalizedEpoch = $t02022820308._1
538+ let currentEpochStartHeight = $t02022820308._2
522539 let votingResultStaked = getVotingResultStaked(lpAssetIdStr)
523540 let votingResultStakedNew = (votingResultStaked + stakedVoteDelta)
524541 let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr)
527544
528545
529546 func getUserVoteStakedIntegral (lpAssetIdStr,userAddressStr) = {
530- let $t01878418864 = getVotingEmissionEpochInfo()
531- let lastFinalizedEpoch = $t01878418864._1
532- let currentEpochStartHeight = $t01878418864._2
547+ let $t02091920999 = getVotingEmissionEpochInfo()
548+ let lastFinalizedEpoch = $t02091920999._1
549+ let currentEpochStartHeight = $t02091920999._2
533550 let userAddress = addressFromStringValue(userAddressStr)
534551 let userVoteStaked = getUserVoteStaked(lpAssetIdStr, userAddressStr)
535552 let userVoteStakedIntegralPrev = valueOrElse(getInteger(this, keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch)), 0)
541558
542559
543560 func refreshVoteStakedIntegral (lpAssetIdStr,userAddressStr,edge) = {
544- let $t01965219732 = getVotingEmissionEpochInfo()
545- let lastFinalizedEpoch = $t01965219732._1
546- let currentEpochStartHeight = $t01965219732._2
561+ let $t02178721867 = getVotingEmissionEpochInfo()
562+ let lastFinalizedEpoch = $t02178721867._1
563+ let currentEpochStartHeight = $t02178721867._2
547564 let userAddress = addressFromStringValue(userAddressStr)
548565 let userVoteFinalized = getUserVoteFinalized(lpAssetIdStr, userAddressStr)
549566 let actions = if ((userVoteFinalized == 0))
562579
563580
564581 func getStakedVotesIntegralsDiff (lpAssetIdStr,userAddressStr) = {
565- let $t02058620666 = getVotingEmissionEpochInfo()
566- let lastFinalizedEpoch = $t02058620666._1
567- let currentEpochStartHeight = $t02058620666._2
582+ let $t02272122801 = getVotingEmissionEpochInfo()
583+ let lastFinalizedEpoch = $t02272122801._1
584+ let currentEpochStartHeight = $t02272122801._2
568585 let userAddress = addressFromStringValue(userAddressStr)
569586 let userVoteStakedIntegralLastKey = keyVoteStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch)
570587 let userVoteStakedIntegralLast = valueOrElse(getInteger(this, userVoteStakedIntegralLastKey), 0)
579596
580597
581598 func refreshBoostEmissionIntegral () = {
582- let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent())
599+ let wxEmissionPerBlock = iof(emissionContract, keyEmissionRatePerBlockCurrent())
583600 let boostingV2LastUpdateHeightOption = getInteger(this, keyBoostingV2LastUpdateHeight())
584601 let boostingV2IngergalOption = getInteger(this, keyBoostingV2Integral())
585- let emissionEnd = getIntOrFail(emissionContract, keyEmissionEndBlock())
602+ let emissionEnd = iof(emissionContract, keyEmissionEndBlock())
586603 let h = if ((height > emissionEnd))
587604 then emissionEnd
588605 else height
602619
603620
604621 func internalClaimWxBoost (lpAssetIdStr,userAddressStr,readOnly) = {
605- let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
606- let userNum = userNumberByAddressOrFail(userAddress)
607- if ((userNum == userNum))
608- then {
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]
609628 let EMPTYSTR = "empty"
610629 let poolWeight = if ((lpAssetIdStr != EMPTYSTR))
611630 then {
615634 else if (readOnly)
616635 then 0
617636 else throwErr(("not readonly mode: unsupported lp asset " + lpAssetIdStr))
618- let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNum, lpAssetIdStr)
619- let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum)
620- let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), getIntOrZero(this, userBoostEmissionLastIntegralKEY))
637+ let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNumStr, lpAssetIdStr)
638+ let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr)
639+ let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), ioz(this, userBoostEmissionLastIntegralKEY))
621640 let boostEmissionIntegral = refreshBoostEmissionIntegral()._2
622641 let userBoostEmissionIntegral = (boostEmissionIntegral - userBoostEmissionLastIntegral)
623642 if ((0 > userBoostEmissionIntegral))
624643 then throwErr("wrong calculations")
625644 else {
626- let $t02420824347 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr)
627- let stakedVotesIntegralsActions = $t02420824347._1
628- let userVoteIntegralDiff = $t02420824347._2
629- let totalVotesIntegralDiff = $t02420824347._3
645+ let $t02642026559 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr)
646+ let stakedVotesIntegralsActions = $t02642026559._1
647+ let userVoteIntegralDiff = $t02642026559._2
648+ let totalVotesIntegralDiff = $t02642026559._3
630649 let poolUserBoostEmissionIntegral = fraction(userBoostEmissionIntegral, poolWeight, POOLWEIGHTMULT)
631650 let userBoostAvaliableToClaimTotalNew = if ((totalVotesIntegralDiff == 0))
632651 then 0
636655 $Tuple3(userBoostAvaliableToClaimTotalNew, dataState, debug)
637656 }
638657 }
639- else throw("Strict value is not equal to itself.")
640658 }
641659
642660
643-func lockActions (i,durationMonths) = if (!(containsElement(durationMonthsAllowed, durationMonths)))
644- then throwErr("invalid duration")
645- else {
646- let duration = (durationMonths * blocksInMonth)
647- let assetIdStr = toBase58String(assetId)
648- if ((size(i.payments) != 1))
649- then throwErr("invalid payment - exact one payment must be attached")
650- else {
651- let pmt = i.payments[0]
652- let pmtAmount = pmt.amount
653- if ((assetId != value(pmt.assetId)))
654- then throwErr((("invalid asset is in payment - " + assetIdStr) + " is expected"))
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], 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- }
692- }
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
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])
668+ if ((size(i.payments) != 1))
669+ then throwErr("invalid payment - exact one payment must be attached")
670+ else {
671+ let pmt = i.payments[0]
672+ let pmtAmount = pmt.amount
673+ if ((assetId != value(pmt.assetId)))
674+ 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+ }
719+ }
709720 }
710721
711722
721732
722733 @Callable(i)
723734 func lockRef (duration,referrerAddress,signature) = {
724- let $t02914629211 = lockActions(i, duration)
725- let lockActionsResult = $t02914629211._1
726- let gWxAmountStart = $t02914629211._2
735+ let $t03117031235 = lockActions(i, duration)
736+ let lockActionsResult = $t03117031235._1
737+ let gWxAmountStart = $t03117031235._2
727738 let referralAddress = toString(i.caller)
728739 let refInv = if (if ((referrerAddress == ""))
729740 then true
744755
745756 @Callable(i)
746757 func lock (duration) = {
747- let $t02966929734 = lockActions(i, duration)
748- let lockActionsResult = $t02966929734._1
749- let gWxAmountStart = $t02966929734._2
758+ let $t03169331758 = lockActions(i, duration)
759+ let lockActionsResult = $t03169331758._1
760+ let gWxAmountStart = $t03169331758._2
750761 let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil)
751762 if ((updateRefActivity == updateRefActivity))
752763 then $Tuple2(lockActionsResult, unit)
756767
757768
758769 @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)
759821 func claimWxBoost (lpAssetIdStr,userAddressStr) = if ((stakingContract != i.caller))
760822 then throwErr("permissions denied")
761823 else {
762- let $t03004430146 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)
763- let userBoostAvailable = $t03004430146._1
764- let dataState = $t03004430146._2
765- let debug = $t03004430146._3
824+ let $t03486334965 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)
825+ let userBoostAvailable = $t03486334965._1
826+ let dataState = $t03486334965._2
827+ let debug = $t03486334965._3
766828 $Tuple2(dataState, [userBoostAvailable])
767829 }
768830
770832
771833 @Callable(i)
772834 func claimWxBoostREADONLY (lpAssetIdStr,userAddressStr) = {
773- let $t03027830379 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true)
774- let userBoostAvailable = $t03027830379._1
775- let dataState = $t03027830379._2
776- let debug = $t03027830379._3
835+ let $t03509735198 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true)
836+ let userBoostAvailable = $t03509735198._1
837+ let dataState = $t03509735198._2
838+ let debug = $t03509735198._3
777839 $Tuple2(nil, [userBoostAvailable, debug])
778840 }
779841
780842
781843
782844 @Callable(i)
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)
845+func unlock (userAddress) = {
846+ let userRecordArray = readLockParamsRecordOrFail(userAddress)
847+ let userNumStr = userRecordArray[IdxLockUserNum]
790848 let userAmount = parseIntValue(userRecordArray[IdxLockAmount])
791849 let lockStart = parseIntValue(userRecordArray[IdxLockStart])
792850 let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
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")
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+ }
862+ }
863+
864+
865+
866+@Callable(i)
867+func gwxUserInfoREADONLY (userAddress) = {
868+ let gwxAmount = calcCurrentGwxAmount(userAddress)
869+ $Tuple2(nil, [gwxAmount])
870+ }
871+
872+
873+
874+@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))
805881 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 gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes], nil)
813- if ((gwxRewardInv == gwxRewardInv))
814- 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)])
815- else throw("Strict value is not equal to itself.")
816- }
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))
817889 }
818890 }
819891
820892
821893
822894 @Callable(i)
823-func gwxUserInfoREADONLY (userAddressStr) = {
824- let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
825- let gwxAmount = getUserGwxAmountTotal(userAddress)
826- $Tuple2(nil, [gwxAmount])
827- }
828-
829-
830-
831-@Callable(i)
832-func userMaxDurationREADONLY (userAddressStr) = $Tuple2(nil, $Tuple2("increaseLock", maxLockDuration))
833-
834-
835-
836-@Callable(i)
837-func getUserGwxAmountAtHeightREADONLY (userAddressStr,targetHeight) = {
838- let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
839- let gwxAmount = getUserGwxAmountTotal(userAddress)
895+func getUserGwxAmountAtHeightREADONLY (userAddress,targetHeight) = {
896+ let gwxAmount = calcUserGwxAmountAtHeight(userAddress, targetHeight)
840897 $Tuple2(nil, gwxAmount)
841898 }
842899
843900
844901
845902 @Callable(i)
846-func getUserGwxAmount (userAddressStr) = {
847- let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
848- let gwxAmount = getUserGwxAmountTotal(userAddress)
849- $Tuple2(nil, gwxAmount)
850- }
851-
852-
853-
854-@Callable(i)
855-func getGwxTotalREADONLY () = $Tuple2(nil, getGwxAmountTotal())
903+func getTotalCachedGwxREADONLY () = $Tuple2(nil, getTotalCachedGwx(true))
856904
857905
858906
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-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], "")
12+func wrapErr (msg) = makeString(["boosting.ride:", msg], " ")
2713
2814
2915 func throwErr (msg) = throw(wrapErr(msg))
3016
3117
32-func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
18+func strf (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
3319
3420
35-func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0)
21+func ioz (address,key) = valueOrElse(getInteger(address, key), 0)
3622
3723
38-func getIntOrDefault (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal)
24+func iod (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal)
3925
4026
41-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
27+func iof (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined")))
4228
4329
4430 func abs (val) = if ((0 > val))
4531 then -(val)
4632 else val
4733
4834
49-func ensurePositive (v,m) = if ((v >= 0))
50- then v
51- else throwErr((valueOrElse(m, "value") + " should be positive"))
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+}
5249
5350
5451 func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP)
5552
5653
57-let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(this, keyReferralsContractAddress()))
54+let referralsContractAddressOrFail = addressFromStringValue(strf(this, keyReferralsContractAddress()))
5855
5956 let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP)
6057
6158 let referralProgramNameDefault = "wxlock"
6259
6360 let referralProgramName = valueOrElse(getString(this, keyReferralProgramName), referralProgramNameDefault)
6461
6562 func keyFactoryAddress () = "%s%s__config__factoryAddress"
6663
6764
6865 let IdxFactoryCfgStakingDapp = 1
6966
7067 let IdxFactoryCfgBoostingDapp = 2
7168
7269 let IdxFactoryCfgIdoDapp = 3
7370
7471 let IdxFactoryCfgTeamDapp = 4
7572
7673 let IdxFactoryCfgEmissionDapp = 5
7774
7875 let IdxFactoryCfgRestDapp = 6
7976
8077 let IdxFactoryCfgSlippageDapp = 7
8178
8279 let IdxFactoryCfgDaoDapp = 8
8380
8481 let IdxFactoryCfgMarketingDapp = 9
8582
8683 let IdxFactoryCfgGwxRewardDapp = 10
8784
8885 let IdxFactoryCfgBirdsDapp = 11
8986
9087 func keyFactoryCfg () = "%s__factoryConfig"
9188
9289
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(getStringOrFail(this, keyFactoryAddress()))
102+func readFactoryAddressOrFail () = addressFromStringValue(strf(this, keyFactoryAddress()))
103103
104104
105-func readFactoryCfgOrFail (factory) = split(getStringOrFail(factory, keyFactoryCfg()), SEP)
105+func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP)
106+
107+
108+func readFactoryCfgOrFail (factory) = split(strf(factory, keyFactoryCfg()), SEP)
106109
107110
108111 func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp])
109112
110113
111114 func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp])
112115
113116
114117 func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp])
115118
116119
117120 func getGwxRewardAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgGwxRewardDapp])
118121
119122
120123 func keyManagerPublicKey () = "%s__managerPublicKey"
121124
122125
123126 func keyManagerVaultAddress () = "%s__managerVaultAddress"
124127
125128
126129 func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current"
127130
128131
129132 func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current"
130133
131134
132135 func keyEmissionStartBlock () = "%s%s__emission__startBlock"
133136
134137
135138 func keyBoostingV2LastUpdateHeight () = "%s%s__boostingV2__startBlock"
136139
137140
138141 func keyBoostingV2Integral () = "%s%s__boostingV2__integral"
139142
140143
141144 func keyEmissionDurationInBlocks () = "%s%s__emission__duration"
142145
143146
144147 func keyEmissionEndBlock () = "%s%s__emission__endBlock"
145148
146149
150+func keyNextPeriod () = "%s__nextPeriod"
151+
152+
153+func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight"
154+
155+
147156 let IdxCfgAssetId = 1
148157
149158 let IdxCfgMinLockAmount = 2
150159
151160 let IdxCfgMinLockDuration = 3
152161
153162 let IdxCfgMaxLockDuration = 4
154163
155164 let IdxCfgMathContract = 5
156165
157-let IdxCfgBlocksInPeriod = 6
158-
159166 func keyConfig () = "%s__config"
160167
161168
162-func readConfigArrayOrFail () = split(getStringOrFail(this, keyConfig()), SEP)
169+func readConfigArrayOrFail () = split(strf(this, keyConfig()), SEP)
163170
164171
165-let cfgArray = readConfigArrayOrFail()
172+let mathContract = addressFromStringValue(readConfigArrayOrFail()[IdxCfgMathContract])
166173
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)
174+func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP)
180175
181176
182177 func formatConfig (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = formatConfigS(assetId, toString(minLockAmount), toString(minLockDuration), toString(maxLockDuration), mathContract)
183178
184179
185180 func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) {
186181 case s: String =>
187182 addressFromStringValue(s)
188183 case _ =>
189184 this
190185 }
191186
192187
193188 func managerPublicKeyOrUnit () = {
194189 let managerVaultAddress = getManagerVaultAddressOrThis()
195190 match getString(managerVaultAddress, keyManagerPublicKey()) {
196191 case s: String =>
197192 fromBase58String(s)
198193 case _: Unit =>
199194 unit
200195 case _ =>
201196 throw("Match error")
202197 }
203198 }
204199
205200
206201 func mustManager (i) = {
207202 let pd = throwErr("Permission denied")
208203 match managerPublicKeyOrUnit() {
209204 case pk: ByteVector =>
210205 if ((i.callerPublicKey == pk))
211206 then true
212207 else pd
213208 case _: Unit =>
214209 if ((i.caller == this))
215210 then true
216211 else pd
217212 case _ =>
218213 throw("Match error")
219214 }
220215 }
221216
222217
223-let IdxLockAmount = 1
218+let IdxLockUserNum = 1
224219
225-let IdxLockStart = 2
220+let IdxLockAmount = 2
226221
227-let IdxLockDuration = 3
222+let IdxLockStart = 3
228223
229-let IdxLockLastUpdateTimestamp = 4
224+let IdxLockDuration = 4
230225
231-let IdxLockGwxAmount = 5
226+let IdxLockParamK = 5
232227
233-let IdxLockWxClaimed = 6
228+let IdxLockParamB = 6
234229
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)
230+func keyLockParamsRecord (userAddress) = makeString(["%s%s__lock", userAddress], SEP)
243231
244232
245-func readLockParamsRecordOrFail (userAddress,txId) = split(getStringOrFail(this, keyLockParamsRecord(userAddress, txId)), SEP)
233+func readLockParamsRecordOrFail (userAddress) = split(strf(this, keyLockParamsRecord(userAddress)), SEP)
246234
247235
248-func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP)
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)
249237
250238
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)
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))
252240
253241
254242 func keyNextUserNum () = "%s__nextUserNum"
255243
256244
257245 func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", userAddress], SEP)
258246
259247
260248 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)
261270
262271
263272 func keyLockParamTotalAmount () = "%s%s__stats__activeTotalLocked"
264273
265274
266275 func keyStatsLocksDurationSumInBlocks () = "%s%s__stats__locksDurationSumInBlocks"
267276
268277
269278 func keyStatsLocksCount () = "%s%s__stats__locksCount"
270279
271280
272281 func keyStatsUsersCount () = "%s%s__stats__activeUsersCount"
273282
274283
275-func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum)], SEP)
284+func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum], SEP)
276285
277286
278-func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum), lpAssetId], SEP)
287+func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum, lpAssetId], SEP)
279288
280289
281-func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", toString(userNum)], SEP)
290+func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", userNum], SEP)
282291
283292
284293 func keyTotalMaxBoostINTEGRAL () = "%s%s__maxBoostInt__total"
285294
286295
287-func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", toString(userNum)], SEP)
296+func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", userNum], SEP)
288297
289298
290-func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", toString(userNum)], SEP)
299+func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", userNum], SEP)
291300
292301
293-func keyGwxTotal () = "%s%s__gwx__total"
302+func keyTotalCachedGwx () = "%s%s__gwxCached__total"
303+
304+
305+func keyTotalCachedGwxCorrective () = "%s__gwxCachedTotalCorrective"
294306
295307
296308 func keyVote (amountAssetId,priceAssetId,address,epoch) = makeString(["%s%s%s%s%d", "vote", amountAssetId, priceAssetId, toString(address), toString(epoch)], SEP)
297309
298310
299311 func keyStartHeightByEpoch (epoch) = makeString(["%s%d", "startHeight", toString(epoch)], SEP)
300312
301313
302314 func keyCurrentEpochUi () = makeString(["%s", "currentEpochUi"], SEP)
303315
304316
305317 func keyVotingResultStaked (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStaked", lpAssetIdStr, toString(epoch)], SEP)
306318
307319
308320 func keyVotingResultStakedIntegral (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStakedIntegral", lpAssetIdStr, toString(epoch)], SEP)
309321
310322
311323 func keyVotingResultStakedLastUpdateHeight (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStakedIntegralLastUpdateHeight", lpAssetIdStr, toString(epoch)], SEP)
312324
313325
314326 func keyVotingResultStakedIntegralLast (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "votingResultStakedIntegralLast", lpAssetIdStr, toString(address), toString(epoch)], SEP)
315327
316328
317329 func keyVoteStakedIntegral (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegral", lpAssetIdStr, toString(address), toString(epoch)], SEP)
318330
319331
320332 func keyVoteStakedLastUpdateHeight (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegralLastUpdateHeight", lpAssetIdStr, toString(address), toString(epoch)], SEP)
321333
322334
323335 func keyVoteStakedIntegralLast (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegralLast", lpAssetIdStr, toString(address), toString(epoch)], SEP)
324336
325337
326338 func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s", "staked", userAddressStr, lpAssetIdStr], SEP)
327339
328340
329341 let factoryContract = readFactoryAddressOrFail()
330342
331343 let factoryCfg = readFactoryCfgOrFail(factoryContract)
332344
333345 let emissionContract = getEmissionAddressOrFail(factoryCfg)
334346
335347 let stakingContract = getStakingAddressOrFail(factoryCfg)
336348
337349 let gwxRewardContract = getGwxRewardAddressOrFail(factoryCfg)
338350
339351 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"))
340352
341353 let keyVotingEmissionContract = makeString(["%s", "votingEmissionContract"], SEP)
342354
343355 let votingEmissionContract = addressFromStringValue(getStringValue(factoryContract, keyVotingEmissionContract))
344356
345-let keyVotingEmissionRateContract = makeString(["%s", "votingEmissionRateContract"], SEP)
346-
347357 let boostCoeff = {
348358 let @ = invoke(emissionContract, "getBoostCoeffREADONLY", nil, nil)
349359 if ($isInstanceOf(@, "Int"))
350360 then @
351361 else throw(($getType(@) + " couldn't be cast to Int"))
352362 }
353363
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
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)])
391378 }
392379
393380
394-func HistoryEntry (type,user,amount,lockStart,duration,gwxAmount,i) = {
381+func HistoryEntry (type,user,amount,lockStart,duration,k,b,i) = {
395382 let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], 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)
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)
397384 StringEntry(historyKEY, historyDATA)
398385 }
399386
400387
401388 func StatsEntry (totalLockedInc,durationInc,lockCountInc,usersCountInc) = {
402389 let locksDurationSumInBlocksKEY = keyStatsLocksDurationSumInBlocks()
403390 let locksCountKEY = keyStatsLocksCount()
404391 let usersCountKEY = keyStatsUsersCount()
405392 let totalAmountKEY = keyLockParamTotalAmount()
406- let locksDurationSumInBlocks = getIntOrZero(this, locksDurationSumInBlocksKEY)
407- let locksCount = getIntOrZero(this, locksCountKEY)
408- let usersCount = getIntOrZero(this, usersCountKEY)
409- let totalAmount = getIntOrZero(this, totalAmountKEY)
393+ let locksDurationSumInBlocks = ioz(this, locksDurationSumInBlocksKEY)
394+ let locksCount = ioz(this, locksCountKEY)
395+ let usersCount = ioz(this, usersCountKEY)
396+ let totalAmount = ioz(this, totalAmountKEY)
410397 [IntegerEntry(locksDurationSumInBlocksKEY, (locksDurationSumInBlocks + durationInc)), IntegerEntry(locksCountKEY, (locksCount + lockCountInc)), IntegerEntry(usersCountKEY, (usersCount + usersCountInc)), IntegerEntry(totalAmountKEY, (totalAmount + totalLockedInc))]
411398 }
412399
413400
414-func LockParamsEntry (userAddress,txId,amount,start,duration,gwxAmount,wxClaimed) = [StringEntry(keyLockParamsRecord(userAddress, txId), formatLockParamsRecord(amount, start, duration, gwxAmount, wxClaimed))]
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+ }
415418
416419
417420 func extractOptionalPaymentAmountOrFail (i,expectedAssetId) = if ((size(i.payments) > 1))
418421 then throwErr("only one payment is allowed")
419422 else if ((size(i.payments) == 0))
420423 then 0
421424 else {
422425 let pmt = i.payments[0]
423426 if ((value(pmt.assetId) != expectedAssetId))
424427 then throwErr("invalid asset id in payment")
425428 else pmt.amount
426429 }
427430
428431
429-func getUserGwxAmountTotal (userAddress) = valueOrElse(getInteger(this, keyUserGwxAmountTotal(userAddress)), 0)
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)
430447
431448
432449 func getVotingEmissionEpochInfo () = {
433- let $t01505115341 = {
450+ let $t01718617476 = {
434451 let currentEpochUi = value(getInteger(votingEmissionContract, keyCurrentEpochUi()))
435452 let lastFinalizedEpoch = (currentEpochUi - 1)
436453 if ((0 > lastFinalizedEpoch))
437454 then throwErr("invalid epoch")
438455 else $Tuple2(currentEpochUi, lastFinalizedEpoch)
439456 }
440- let currentEpochUi = $t01505115341._1
441- let lastFinalizedEpoch = $t01505115341._2
457+ let currentEpochUi = $t01718617476._1
458+ let lastFinalizedEpoch = $t01718617476._2
442459 let currentEpochStartHeight = value(getInteger(votingEmissionContract, keyStartHeightByEpoch(currentEpochUi)))
443460 $Tuple2(lastFinalizedEpoch, currentEpochStartHeight)
444461 }
445462
446463
447464 func getPoolAssetsByLpAssetId (lpAssetIdStr) = {
448465 let idxAmountAssetId = 4
449466 let idxPriceAssetId = 5
450467 let poolCfg = {
451468 let @ = invoke(factoryContract, "getPoolConfigByLpAssetIdREADONLY", [lpAssetIdStr], nil)
452469 if ($isInstanceOf(@, "List[Any]"))
453470 then @
454471 else throw(($getType(@) + " couldn't be cast to List[Any]"))
455472 }
456473 let amountAssetId = {
457474 let @ = poolCfg[idxAmountAssetId]
458475 if ($isInstanceOf(@, "String"))
459476 then @
460477 else throw(($getType(@) + " couldn't be cast to String"))
461478 }
462479 let priceAssetId = {
463480 let @ = poolCfg[idxPriceAssetId]
464481 if ($isInstanceOf(@, "String"))
465482 then @
466483 else throw(($getType(@) + " couldn't be cast to String"))
467484 }
468485 $Tuple2(amountAssetId, priceAssetId)
469486 }
470487
471488
472489 func getUserVoteFinalized (lpAssetIdStr,userAddressStr) = {
473490 let userAddress = addressFromStringValue(userAddressStr)
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
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
480497 let userVoteKey = keyVote(amountAssetId, priceAssetId, userAddress, lastFinalizedEpoch)
481498 let userVote = valueOrElse(getInteger(votingEmissionContract, userVoteKey), 0)
482499 userVote
483500 }
484501
485502
486503 func getUserVoteStaked (lpAssetIdStr,userAddressStr) = {
487504 let stakedByUser = valueOrElse(getInteger(stakingContract, keyStakedByUser(userAddressStr, lpAssetIdStr)), 0)
488505 let userVote = getUserVoteFinalized(lpAssetIdStr, userAddressStr)
489506 if ((stakedByUser == 0))
490507 then 0
491508 else userVote
492509 }
493510
494511
495512 func getVotingResultStaked (lpAssetIdStr) = {
496- let $t01673416814 = getVotingEmissionEpochInfo()
497- let lastFinalizedEpoch = $t01673416814._1
498- let currentEpochStartHeight = $t01673416814._2
513+ let $t01886918949 = getVotingEmissionEpochInfo()
514+ let lastFinalizedEpoch = $t01886918949._1
515+ let currentEpochStartHeight = $t01886918949._2
499516 let votingResultStakedStart = valueOrElse(getInteger(votingEmissionContract, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), 0)
500517 let votingResultStaked = valueOrElse(getInteger(this, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), votingResultStakedStart)
501518 votingResultStaked
502519 }
503520
504521
505522 func getVotingResultStakedIntegral (lpAssetIdStr) = {
506- let $t01717617256 = getVotingEmissionEpochInfo()
507- let lastFinalizedEpoch = $t01717617256._1
508- let currentEpochStartHeight = $t01717617256._2
523+ let $t01931119391 = getVotingEmissionEpochInfo()
524+ let lastFinalizedEpoch = $t01931119391._1
525+ let currentEpochStartHeight = $t01931119391._2
509526 let votingResultStaked = getVotingResultStaked(lpAssetIdStr)
510527 let votingResultStakedIntegralPrev = valueOrElse(getInteger(this, keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch)), 0)
511528 let votingResultStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch)), currentEpochStartHeight)
512529 let votingResultStakedIntegralDh = (height - votingResultStakedLastUpdateHeight)
513530 let votingResultStakedIntegral = ((votingResultStakedIntegralDh * votingResultStaked) + votingResultStakedIntegralPrev)
514531 votingResultStakedIntegral
515532 }
516533
517534
518535 func refreshVotingResultStakedIntegral (lpAssetIdStr,stakedVoteDelta) = {
519- let $t01809318173 = getVotingEmissionEpochInfo()
520- let lastFinalizedEpoch = $t01809318173._1
521- let currentEpochStartHeight = $t01809318173._2
536+ let $t02022820308 = getVotingEmissionEpochInfo()
537+ let lastFinalizedEpoch = $t02022820308._1
538+ let currentEpochStartHeight = $t02022820308._2
522539 let votingResultStaked = getVotingResultStaked(lpAssetIdStr)
523540 let votingResultStakedNew = (votingResultStaked + stakedVoteDelta)
524541 let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr)
525542 [IntegerEntry(keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch), votingResultStakedNew), IntegerEntry(keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch), height), IntegerEntry(keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch), votingResultStakedIntegral)]
526543 }
527544
528545
529546 func getUserVoteStakedIntegral (lpAssetIdStr,userAddressStr) = {
530- let $t01878418864 = getVotingEmissionEpochInfo()
531- let lastFinalizedEpoch = $t01878418864._1
532- let currentEpochStartHeight = $t01878418864._2
547+ let $t02091920999 = getVotingEmissionEpochInfo()
548+ let lastFinalizedEpoch = $t02091920999._1
549+ let currentEpochStartHeight = $t02091920999._2
533550 let userAddress = addressFromStringValue(userAddressStr)
534551 let userVoteStaked = getUserVoteStaked(lpAssetIdStr, userAddressStr)
535552 let userVoteStakedIntegralPrev = valueOrElse(getInteger(this, keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch)), 0)
536553 let userVoteStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVoteStakedLastUpdateHeight(lpAssetIdStr, userAddress, lastFinalizedEpoch)), currentEpochStartHeight)
537554 let userVoteStakedIntegralDh = (height - userVoteStakedLastUpdateHeight)
538555 let userVoteStakedIntegral = ((userVoteStakedIntegralDh * userVoteStaked) + userVoteStakedIntegralPrev)
539556 userVoteStakedIntegral
540557 }
541558
542559
543560 func refreshVoteStakedIntegral (lpAssetIdStr,userAddressStr,edge) = {
544- let $t01965219732 = getVotingEmissionEpochInfo()
545- let lastFinalizedEpoch = $t01965219732._1
546- let currentEpochStartHeight = $t01965219732._2
561+ let $t02178721867 = getVotingEmissionEpochInfo()
562+ let lastFinalizedEpoch = $t02178721867._1
563+ let currentEpochStartHeight = $t02178721867._2
547564 let userAddress = addressFromStringValue(userAddressStr)
548565 let userVoteFinalized = getUserVoteFinalized(lpAssetIdStr, userAddressStr)
549566 let actions = if ((userVoteFinalized == 0))
550567 then nil
551568 else {
552569 let stakedVoteDelta = if (edge)
553570 then userVoteFinalized
554571 else -(userVoteFinalized)
555572 let votingResultActions = refreshVotingResultStakedIntegral(lpAssetIdStr, stakedVoteDelta)
556573 let userVoteStakedIntegral = getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr)
557574 let voteActions = [IntegerEntry(keyVoteStakedLastUpdateHeight(lpAssetIdStr, userAddress, lastFinalizedEpoch), height), IntegerEntry(keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch), userVoteStakedIntegral)]
558575 (votingResultActions ++ voteActions)
559576 }
560577 actions
561578 }
562579
563580
564581 func getStakedVotesIntegralsDiff (lpAssetIdStr,userAddressStr) = {
565- let $t02058620666 = getVotingEmissionEpochInfo()
566- let lastFinalizedEpoch = $t02058620666._1
567- let currentEpochStartHeight = $t02058620666._2
582+ let $t02272122801 = getVotingEmissionEpochInfo()
583+ let lastFinalizedEpoch = $t02272122801._1
584+ let currentEpochStartHeight = $t02272122801._2
568585 let userAddress = addressFromStringValue(userAddressStr)
569586 let userVoteStakedIntegralLastKey = keyVoteStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch)
570587 let userVoteStakedIntegralLast = valueOrElse(getInteger(this, userVoteStakedIntegralLastKey), 0)
571588 let votingResultStakedIntegralLastKey = keyVotingResultStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch)
572589 let votingResultStakedIntegralLast = valueOrElse(getInteger(this, votingResultStakedIntegralLastKey), 0)
573590 let userVoteStakedIntegral = getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr)
574591 let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr)
575592 let userVoteStakedIntegralDiff = (userVoteStakedIntegral - userVoteStakedIntegralLast)
576593 let votingResultStakedIntegralDiff = (votingResultStakedIntegral - votingResultStakedIntegralLast)
577594 $Tuple3([IntegerEntry(userVoteStakedIntegralLastKey, userVoteStakedIntegral), IntegerEntry(votingResultStakedIntegralLastKey, votingResultStakedIntegral)], userVoteStakedIntegralDiff, votingResultStakedIntegralDiff)
578595 }
579596
580597
581598 func refreshBoostEmissionIntegral () = {
582- let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent())
599+ let wxEmissionPerBlock = iof(emissionContract, keyEmissionRatePerBlockCurrent())
583600 let boostingV2LastUpdateHeightOption = getInteger(this, keyBoostingV2LastUpdateHeight())
584601 let boostingV2IngergalOption = getInteger(this, keyBoostingV2Integral())
585- let emissionEnd = getIntOrFail(emissionContract, keyEmissionEndBlock())
602+ let emissionEnd = iof(emissionContract, keyEmissionEndBlock())
586603 let h = if ((height > emissionEnd))
587604 then emissionEnd
588605 else height
589606 let dh = match boostingV2LastUpdateHeightOption {
590607 case lastUpdateHeight: Int =>
591608 max([(h - lastUpdateHeight), 0])
592609 case _: Unit =>
593610 0
594611 case _ =>
595612 throw("Match error")
596613 }
597614 let boostEmissionPerBlock = ((wxEmissionPerBlock * (boostCoeff - 1)) / boostCoeff)
598615 let boostEmissionIntegralPrev = valueOrElse(boostingV2IngergalOption, 0)
599616 let boostEmissionIntegral = ((boostEmissionPerBlock * dh) + boostEmissionIntegralPrev)
600617 $Tuple2([IntegerEntry(keyBoostingV2Integral(), boostEmissionIntegral), IntegerEntry(keyBoostingV2LastUpdateHeight(), height)], boostEmissionIntegral)
601618 }
602619
603620
604621 func internalClaimWxBoost (lpAssetIdStr,userAddressStr,readOnly) = {
605- let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
606- let userNum = userNumberByAddressOrFail(userAddress)
607- if ((userNum == userNum))
608- then {
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]
609628 let EMPTYSTR = "empty"
610629 let poolWeight = if ((lpAssetIdStr != EMPTYSTR))
611630 then {
612631 let poolAddressStr = valueOrErrorMessage(getString(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr)), wrapErr(("unsupported lp asset " + lpAssetIdStr)))
613632 getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr))
614633 }
615634 else if (readOnly)
616635 then 0
617636 else throwErr(("not readonly mode: unsupported lp asset " + lpAssetIdStr))
618- let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNum, lpAssetIdStr)
619- let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum)
620- let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), getIntOrZero(this, userBoostEmissionLastIntegralKEY))
637+ let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNumStr, lpAssetIdStr)
638+ let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr)
639+ let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), ioz(this, userBoostEmissionLastIntegralKEY))
621640 let boostEmissionIntegral = refreshBoostEmissionIntegral()._2
622641 let userBoostEmissionIntegral = (boostEmissionIntegral - userBoostEmissionLastIntegral)
623642 if ((0 > userBoostEmissionIntegral))
624643 then throwErr("wrong calculations")
625644 else {
626- let $t02420824347 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr)
627- let stakedVotesIntegralsActions = $t02420824347._1
628- let userVoteIntegralDiff = $t02420824347._2
629- let totalVotesIntegralDiff = $t02420824347._3
645+ let $t02642026559 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr)
646+ let stakedVotesIntegralsActions = $t02642026559._1
647+ let userVoteIntegralDiff = $t02642026559._2
648+ let totalVotesIntegralDiff = $t02642026559._3
630649 let poolUserBoostEmissionIntegral = fraction(userBoostEmissionIntegral, poolWeight, POOLWEIGHTMULT)
631650 let userBoostAvaliableToClaimTotalNew = if ((totalVotesIntegralDiff == 0))
632651 then 0
633652 else fraction(poolUserBoostEmissionIntegral, userVoteIntegralDiff, totalVotesIntegralDiff)
634653 let dataState = ([IntegerEntry(userLpBoostEmissionLastIntegralKEY, boostEmissionIntegral)] ++ stakedVotesIntegralsActions)
635654 let debug = makeString([toString(userBoostEmissionLastIntegral), toString(userBoostEmissionIntegral), toString(poolWeight), toString(userVoteIntegralDiff), toString(totalVotesIntegralDiff)], ":")
636655 $Tuple3(userBoostAvaliableToClaimTotalNew, dataState, debug)
637656 }
638657 }
639- else throw("Strict value is not equal to itself.")
640658 }
641659
642660
643-func lockActions (i,durationMonths) = if (!(containsElement(durationMonthsAllowed, durationMonths)))
644- then throwErr("invalid duration")
645- else {
646- let duration = (durationMonths * blocksInMonth)
647- let assetIdStr = toBase58String(assetId)
648- if ((size(i.payments) != 1))
649- then throwErr("invalid payment - exact one payment must be attached")
650- else {
651- let pmt = i.payments[0]
652- let pmtAmount = pmt.amount
653- if ((assetId != value(pmt.assetId)))
654- then throwErr((("invalid asset is in payment - " + assetIdStr) + " is expected"))
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], 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- }
692- }
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
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])
668+ if ((size(i.payments) != 1))
669+ then throwErr("invalid payment - exact one payment must be attached")
670+ else {
671+ let pmt = i.payments[0]
672+ let pmtAmount = pmt.amount
673+ if ((assetId != value(pmt.assetId)))
674+ 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+ }
719+ }
709720 }
710721
711722
712723 @Callable(i)
713724 func constructor (factoryAddressStr,lockAssetIdStr,minLockAmount,minDuration,maxDuration,mathContract) = {
714725 let checkCaller = mustManager(i)
715726 if ((checkCaller == checkCaller))
716727 then ([IntegerEntry(keyNextUserNum(), 0), StringEntry(keyConfig(), formatConfig(lockAssetIdStr, minLockAmount, minDuration, maxDuration, mathContract)), StringEntry(keyFactoryAddress(), factoryAddressStr)] ++ StatsEntry(0, 0, 0, 0))
717728 else throw("Strict value is not equal to itself.")
718729 }
719730
720731
721732
722733 @Callable(i)
723734 func lockRef (duration,referrerAddress,signature) = {
724- let $t02914629211 = lockActions(i, duration)
725- let lockActionsResult = $t02914629211._1
726- let gWxAmountStart = $t02914629211._2
735+ let $t03117031235 = lockActions(i, duration)
736+ let lockActionsResult = $t03117031235._1
737+ let gWxAmountStart = $t03117031235._2
727738 let referralAddress = toString(i.caller)
728739 let refInv = if (if ((referrerAddress == ""))
729740 then true
730741 else (signature == base58''))
731742 then unit
732743 else invoke(referralsContractAddressOrFail, "createPair", [referralProgramName, referrerAddress, referralAddress, signature], nil)
733744 if ((refInv == refInv))
734745 then {
735746 let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil)
736747 if ((updateRefActivity == updateRefActivity))
737748 then $Tuple2(lockActionsResult, unit)
738749 else throw("Strict value is not equal to itself.")
739750 }
740751 else throw("Strict value is not equal to itself.")
741752 }
742753
743754
744755
745756 @Callable(i)
746757 func lock (duration) = {
747- let $t02966929734 = lockActions(i, duration)
748- let lockActionsResult = $t02966929734._1
749- let gWxAmountStart = $t02966929734._2
758+ let $t03169331758 = lockActions(i, duration)
759+ let lockActionsResult = $t03169331758._1
760+ let gWxAmountStart = $t03169331758._2
750761 let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil)
751762 if ((updateRefActivity == updateRefActivity))
752763 then $Tuple2(lockActionsResult, unit)
753764 else throw("Strict value is not equal to itself.")
754765 }
755766
756767
757768
758769 @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)
759821 func claimWxBoost (lpAssetIdStr,userAddressStr) = if ((stakingContract != i.caller))
760822 then throwErr("permissions denied")
761823 else {
762- let $t03004430146 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)
763- let userBoostAvailable = $t03004430146._1
764- let dataState = $t03004430146._2
765- let debug = $t03004430146._3
824+ let $t03486334965 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)
825+ let userBoostAvailable = $t03486334965._1
826+ let dataState = $t03486334965._2
827+ let debug = $t03486334965._3
766828 $Tuple2(dataState, [userBoostAvailable])
767829 }
768830
769831
770832
771833 @Callable(i)
772834 func claimWxBoostREADONLY (lpAssetIdStr,userAddressStr) = {
773- let $t03027830379 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true)
774- let userBoostAvailable = $t03027830379._1
775- let dataState = $t03027830379._2
776- let debug = $t03027830379._3
835+ let $t03509735198 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true)
836+ let userBoostAvailable = $t03509735198._1
837+ let dataState = $t03509735198._2
838+ let debug = $t03509735198._3
777839 $Tuple2(nil, [userBoostAvailable, debug])
778840 }
779841
780842
781843
782844 @Callable(i)
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)
845+func unlock (userAddress) = {
846+ let userRecordArray = readLockParamsRecordOrFail(userAddress)
847+ let userNumStr = userRecordArray[IdxLockUserNum]
790848 let userAmount = parseIntValue(userRecordArray[IdxLockAmount])
791849 let lockStart = parseIntValue(userRecordArray[IdxLockStart])
792850 let lockDuration = parseIntValue(userRecordArray[IdxLockDuration])
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")
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+ }
862+ }
863+
864+
865+
866+@Callable(i)
867+func gwxUserInfoREADONLY (userAddress) = {
868+ let gwxAmount = calcCurrentGwxAmount(userAddress)
869+ $Tuple2(nil, [gwxAmount])
870+ }
871+
872+
873+
874+@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))
805881 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 gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes], nil)
813- if ((gwxRewardInv == gwxRewardInv))
814- 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)])
815- else throw("Strict value is not equal to itself.")
816- }
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))
817889 }
818890 }
819891
820892
821893
822894 @Callable(i)
823-func gwxUserInfoREADONLY (userAddressStr) = {
824- let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
825- let gwxAmount = getUserGwxAmountTotal(userAddress)
826- $Tuple2(nil, [gwxAmount])
827- }
828-
829-
830-
831-@Callable(i)
832-func userMaxDurationREADONLY (userAddressStr) = $Tuple2(nil, $Tuple2("increaseLock", maxLockDuration))
833-
834-
835-
836-@Callable(i)
837-func getUserGwxAmountAtHeightREADONLY (userAddressStr,targetHeight) = {
838- let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
839- let gwxAmount = getUserGwxAmountTotal(userAddress)
895+func getUserGwxAmountAtHeightREADONLY (userAddress,targetHeight) = {
896+ let gwxAmount = calcUserGwxAmountAtHeight(userAddress, targetHeight)
840897 $Tuple2(nil, gwxAmount)
841898 }
842899
843900
844901
845902 @Callable(i)
846-func getUserGwxAmount (userAddressStr) = {
847- let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
848- let gwxAmount = getUserGwxAmountTotal(userAddress)
849- $Tuple2(nil, gwxAmount)
850- }
851-
852-
853-
854-@Callable(i)
855-func getGwxTotalREADONLY () = $Tuple2(nil, getGwxAmountTotal())
903+func getTotalCachedGwxREADONLY () = $Tuple2(nil, getTotalCachedGwx(true))
856904
857905
858906
859907 @Callable(i)
860908 func onBoostEmissionUpdate () = {
861909 let checkCaller = if ((i.caller == emissionContract))
862910 then true
863911 else mustManager(i)
864912 if ((checkCaller == checkCaller))
865913 then refreshBoostEmissionIntegral()
866914 else throw("Strict value is not equal to itself.")
867915 }
868916
869917
870918
871919 @Callable(i)
872920 func onStakedVoteUpdate (lpAssetIdStr,userAddressStr,edge) = {
873921 let checkCaller = if ((i.caller == stakingContract))
874922 then true
875923 else mustManager(i)
876924 if ((checkCaller == checkCaller))
877925 then {
878926 let actions = refreshVoteStakedIntegral(lpAssetIdStr, userAddressStr, edge)
879927 $Tuple2(actions, unit)
880928 }
881929 else throw("Strict value is not equal to itself.")
882930 }
883931
884932
885933
886934 @Callable(i)
887935 func getVotingResultStakedREADONLY (lpAssetIdStr) = $Tuple2(nil, getVotingResultStaked(lpAssetIdStr))
888936
889937
890938
891939 @Callable(i)
892940 func getVotingResultStakedIntegralREADONLY (lpAssetIdStr) = $Tuple2(nil, getVotingResultStakedIntegral(lpAssetIdStr))
893941
894942
895943
896944 @Callable(i)
897945 func getUserVoteFinalizedREADONLY (lpAssetIdStr,userAddressStr) = $Tuple2(nil, getUserVoteFinalized(lpAssetIdStr, userAddressStr))
898946
899947
900948
901949 @Callable(i)
902950 func getUserVoteStakedIntegralREADONLY (lpAssetIdStr,userAddressStr) = $Tuple2(nil, getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr))
903951
904952
905953 @Verifier(tx)
906954 func verify () = {
907955 let targetPublicKey = match managerPublicKeyOrUnit() {
908956 case pk: ByteVector =>
909957 pk
910958 case _: Unit =>
911959 tx.senderPublicKey
912960 case _ =>
913961 throw("Match error")
914962 }
915963 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
916964 }
917965

github/deemru/w8io/026f985 
183.66 ms