tx · knBNmNSMARodkYfFjWEEPH3Px1dxcQbBKFDn4Q7nbdZ 3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy: -0.02600000 Waves 2023.08.17 16:29 [2714656] smart account 3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy > SELF 0.00000000 Waves
{ "type": 13, "id": "knBNmNSMARodkYfFjWEEPH3Px1dxcQbBKFDn4Q7nbdZ", "fee": 2600000, "feeAssetId": null, "timestamp": 1692279013163, "version": 2, "chainId": 84, "sender": "3Myn55vLkduxbX3ZXfiDCZhaQsLxYp1kmCy", "senderPublicKey": "9W33iCCNfmFxUbiC6XZcH5x7f6xfwC7Jb3BoExT5q2PV", "proofs": [ "3kicBaxS5xfM55fiNEp7bWt2Fp8Ekewyk8FK5Hy9ngajZrTinjkgTWVANEwubc2dJJS8bDDAx1cwb87QdCbpc88D" ], "script": "base64:BgLOLQgCEggKBggIAQEBCBIFCgMBCAISAwoBARIECgIICBIECgIICBIDCgEIEgMKAQgSAwoBCBIECgIIARIDCgEIEgASABIFCgMICAQSAwoBCBIDCgEIEgQKAggIEgQKAggIIgNTRVAiBlNDQUxFOCIFTVVMVDgiDlBPT0xXRUlHSFRNVUxUIhBjb250cmFjdEZpbGVuYW1lIgdTQ0FMRTE4IgZNVUxUMTgiCE1VTFQxOEJJIhVkdXJhdGlvbk1vbnRoc0FsbG93ZWQiC2Jsb2Nrc0luRGF5Ig1ibG9ja3NJbk1vbnRoIgd3cmFwRXJyIgNtc2ciCHRocm93RXJyIg9nZXRTdHJpbmdPckZhaWwiB2FkZHJlc3MiA2tleSIMZ2V0SW50T3JaZXJvIg9nZXRJbnRPckRlZmF1bHQiCmRlZmF1bHRWYWwiDGdldEludE9yRmFpbCIDYWJzIgN2YWwiDmVuc3VyZVBvc2l0aXZlIgF2IgFtIhtrZXlSZWZlcnJhbHNDb250cmFjdEFkZHJlc3MiHnJlZmVycmFsc0NvbnRyYWN0QWRkcmVzc09yRmFpbCIWa2V5UmVmZX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 Next: 9DQJJgWJFS9psM54dnDAvcEjMfZfgwwbHeRL2GnLgSEo Diff:
Old | New | Differences | |
---|---|---|---|
9 | 9 | ||
10 | 10 | let POOLWEIGHTMULT = MULT8 | |
11 | 11 | ||
12 | - | func wrapErr (msg) = makeString(["boosting.ride:", msg], " ") | |
12 | + | let contractFilename = "boosting.ride" | |
13 | + | ||
14 | + | let SCALE18 = 18 | |
15 | + | ||
16 | + | let MULT18 = 1000000000000000000 | |
17 | + | ||
18 | + | let MULT18BI = toBigInt(MULT18) | |
19 | + | ||
20 | + | let durationMonthsAllowed = [1, 3, 6, 12, 24, 48] | |
21 | + | ||
22 | + | let blocksInDay = 1440 | |
23 | + | ||
24 | + | let blocksInMonth = 43800 | |
25 | + | ||
26 | + | func wrapErr (msg) = makeString([contractFilename, ": ", msg], "") | |
13 | 27 | ||
14 | 28 | ||
15 | 29 | func throwErr (msg) = throw(wrapErr(msg)) | |
16 | 30 | ||
17 | 31 | ||
18 | - | func | |
32 | + | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined"))) | |
19 | 33 | ||
20 | 34 | ||
21 | - | func | |
35 | + | func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0) | |
22 | 36 | ||
23 | 37 | ||
24 | - | func | |
38 | + | func getIntOrDefault (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal) | |
25 | 39 | ||
26 | 40 | ||
27 | - | func | |
41 | + | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined"))) | |
28 | 42 | ||
29 | 43 | ||
30 | 44 | func abs (val) = if ((0 > val)) | |
32 | 46 | else val | |
33 | 47 | ||
34 | 48 | ||
35 | - | func aal (val) = match val { | |
36 | - | case valAnyLyst: List[Any] => | |
37 | - | valAnyLyst | |
38 | - | case _ => | |
39 | - | throwErr("fail to cast into List[Any]") | |
40 | - | } | |
41 | - | ||
42 | - | ||
43 | - | func ai (val) = match val { | |
44 | - | case valInt: Int => | |
45 | - | valInt | |
46 | - | case _ => | |
47 | - | throwErr("fail to cast into Int") | |
48 | - | } | |
49 | + | func ensurePositive (v,m) = if ((v >= 0)) | |
50 | + | then v | |
51 | + | else throwErr((valueOrElse(m, "value") + " should be positive")) | |
49 | 52 | ||
50 | 53 | ||
51 | 54 | func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP) | |
52 | 55 | ||
53 | 56 | ||
54 | - | let referralsContractAddressOrFail = addressFromStringValue( | |
57 | + | let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(this, keyReferralsContractAddress())) | |
55 | 58 | ||
56 | 59 | let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP) | |
57 | 60 | ||
87 | 90 | func keyFactoryCfg () = "%s__factoryConfig" | |
88 | 91 | ||
89 | 92 | ||
90 | - | func keyFactoryLpList () = "%s__lpTokensList" | |
91 | - | ||
92 | - | ||
93 | 93 | func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) | |
94 | 94 | ||
95 | 95 | ||
99 | 99 | func keyFactoryPoolWeightHistory (poolAddress,num) = ((("%s%s__poolWeight__" + poolAddress) + "__") + toString(num)) | |
100 | 100 | ||
101 | 101 | ||
102 | - | func readFactoryAddressOrFail () = addressFromStringValue( | |
102 | + | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(this, keyFactoryAddress())) | |
103 | 103 | ||
104 | 104 | ||
105 | - | func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP) | |
106 | - | ||
107 | - | ||
108 | - | func readFactoryCfgOrFail (factory) = split(strf(factory, keyFactoryCfg()), SEP) | |
105 | + | func readFactoryCfgOrFail (factory) = split(getStringOrFail(factory, keyFactoryCfg()), SEP) | |
109 | 106 | ||
110 | 107 | ||
111 | 108 | func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp]) | |
147 | 144 | func keyEmissionEndBlock () = "%s%s__emission__endBlock" | |
148 | 145 | ||
149 | 146 | ||
150 | - | func keyNextPeriod () = "%s__nextPeriod" | |
151 | - | ||
152 | - | ||
153 | - | func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight" | |
154 | - | ||
155 | - | ||
156 | 147 | let IdxCfgAssetId = 1 | |
157 | 148 | ||
158 | 149 | let IdxCfgMinLockAmount = 2 | |
163 | 154 | ||
164 | 155 | let IdxCfgMathContract = 5 | |
165 | 156 | ||
157 | + | let IdxCfgBlocksInPeriod = 6 | |
158 | + | ||
166 | 159 | func keyConfig () = "%s__config" | |
167 | 160 | ||
168 | 161 | ||
169 | - | func readConfigArrayOrFail () = split( | |
162 | + | func readConfigArrayOrFail () = split(getStringOrFail(this, keyConfig()), SEP) | |
170 | 163 | ||
171 | 164 | ||
172 | - | let | |
165 | + | let cfgArray = readConfigArrayOrFail() | |
173 | 166 | ||
174 | - | func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP) | |
167 | + | let assetId = fromBase58String(cfgArray[IdxCfgAssetId]) | |
168 | + | ||
169 | + | let minLockAmount = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMinLockAmount]), wrapErr("invalid min lock amount")) | |
170 | + | ||
171 | + | let minLockDuration = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMinLockDuration]), wrapErr("invalid min lock duration")) | |
172 | + | ||
173 | + | let maxLockDuration = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMaxLockDuration]), wrapErr("invalid max lock duration")) | |
174 | + | ||
175 | + | let mathContract = valueOrErrorMessage(addressFromString(cfgArray[IdxCfgMathContract]), wrapErr("invalid math contract address")) | |
176 | + | ||
177 | + | let blocksInPeriod = valueOrErrorMessage(parseInt(cfgArray[IdxCfgBlocksInPeriod]), wrapErr("invalid blocks in period")) | |
178 | + | ||
179 | + | func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d%s", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP) | |
175 | 180 | ||
176 | 181 | ||
177 | 182 | func formatConfig (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = formatConfigS(assetId, toString(minLockAmount), toString(minLockDuration), toString(maxLockDuration), mathContract) | |
215 | 220 | } | |
216 | 221 | ||
217 | 222 | ||
218 | - | let | |
223 | + | let IdxLockAmount = 1 | |
219 | 224 | ||
220 | - | let | |
225 | + | let IdxLockStart = 2 | |
221 | 226 | ||
222 | - | let | |
227 | + | let IdxLockDuration = 3 | |
223 | 228 | ||
224 | - | let | |
229 | + | let IdxLockLastUpdateTimestamp = 4 | |
225 | 230 | ||
226 | - | let | |
231 | + | let IdxLockGwxAmount = 5 | |
227 | 232 | ||
228 | - | let | |
233 | + | let IdxLockWxClaimed = 6 | |
229 | 234 | ||
230 | - | func keyLockParamsRecord (userAddress) = makeString(["%s%s__lock", userAddress], SEP) | |
235 | + | func keyLockParamsRecord (userAddress,txId) = makeString(["%s%s%s__lock", toString(userAddress), match txId { | |
236 | + | case b: ByteVector => | |
237 | + | toBase58String(b) | |
238 | + | case _: Unit => | |
239 | + | "legacy" | |
240 | + | case _ => | |
241 | + | throw("Match error") | |
242 | + | }], SEP) | |
231 | 243 | ||
232 | 244 | ||
233 | - | func readLockParamsRecordOrFail (userAddress) = split( | |
245 | + | func readLockParamsRecordOrFail (userAddress,txId) = split(getStringOrFail(this, keyLockParamsRecord(userAddress, txId)), SEP) | |
234 | 246 | ||
235 | 247 | ||
236 | - | func | |
248 | + | func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP) | |
237 | 249 | ||
238 | 250 | ||
239 | - | func formatLockParamsRecord ( | |
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) | |
240 | 252 | ||
241 | 253 | ||
242 | 254 | func keyNextUserNum () = "%s__nextUserNum" | |
246 | 258 | ||
247 | 259 | ||
248 | 260 | 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) | |
270 | 261 | ||
271 | 262 | ||
272 | 263 | func keyLockParamTotalAmount () = "%s%s__stats__activeTotalLocked" | |
281 | 272 | func keyStatsUsersCount () = "%s%s__stats__activeUsersCount" | |
282 | 273 | ||
283 | 274 | ||
284 | - | func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum], SEP) | |
275 | + | func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum)], SEP) | |
285 | 276 | ||
286 | 277 | ||
287 | - | func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum, lpAssetId], SEP) | |
278 | + | func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum), lpAssetId], SEP) | |
288 | 279 | ||
289 | 280 | ||
290 | - | func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", userNum], SEP) | |
281 | + | func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", toString(userNum)], SEP) | |
291 | 282 | ||
292 | 283 | ||
293 | 284 | func keyTotalMaxBoostINTEGRAL () = "%s%s__maxBoostInt__total" | |
294 | 285 | ||
295 | 286 | ||
296 | - | func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", userNum], SEP) | |
287 | + | func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", toString(userNum)], SEP) | |
297 | 288 | ||
298 | 289 | ||
299 | - | func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", userNum], SEP) | |
290 | + | func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", toString(userNum)], SEP) | |
300 | 291 | ||
301 | 292 | ||
302 | - | func keyTotalCachedGwx () = "%s%s__gwxCached__total" | |
303 | - | ||
304 | - | ||
305 | - | func keyTotalCachedGwxCorrective () = "%s__gwxCachedTotalCorrective" | |
293 | + | func keyGwxTotal () = "%s%s__gwx__total" | |
306 | 294 | ||
307 | 295 | ||
308 | 296 | func keyVote (amountAssetId,priceAssetId,address,epoch) = makeString(["%s%s%s%s%d", "vote", amountAssetId, priceAssetId, toString(address), toString(epoch)], SEP) | |
354 | 342 | ||
355 | 343 | let votingEmissionContract = addressFromStringValue(getStringValue(factoryContract, keyVotingEmissionContract)) | |
356 | 344 | ||
345 | + | let keyVotingEmissionRateContract = makeString(["%s", "votingEmissionRateContract"], SEP) | |
346 | + | ||
357 | 347 | let boostCoeff = { | |
358 | 348 | let @ = invoke(emissionContract, "getBoostCoeffREADONLY", nil, nil) | |
359 | 349 | if ($isInstanceOf(@, "Int")) | |
361 | 351 | else throw(($getType(@) + " couldn't be cast to Int")) | |
362 | 352 | } | |
363 | 353 | ||
364 | - | func getTotalCachedGwx (correct) = { | |
365 | - | let currentEpochUi = getIntegerValue(votingEmissionContract, keyCurrentEpochUi()) | |
366 | - | let keyTargetEpoch = makeString(["%s%s", "totalCachedGwxCorrection__activationEpoch"], SEP) | |
367 | - | let targetEpochOption = getInteger(this, keyTargetEpoch) | |
368 | - | let totalCachedGwxRaw = valueOrElse(getInteger(this, keyTotalCachedGwx()), 0) | |
369 | - | let isCorrectionActivated = if (isDefined(targetEpochOption)) | |
370 | - | then (currentEpochUi >= value(targetEpochOption)) | |
371 | - | else false | |
372 | - | let corrective = if (if (isCorrectionActivated) | |
373 | - | then correct | |
374 | - | else false) | |
375 | - | then valueOrElse(getInteger(this, keyTotalCachedGwxCorrective()), 0) | |
376 | - | else 0 | |
377 | - | max([0, (totalCachedGwxRaw + corrective)]) | |
354 | + | func userNumberByAddressOrFail (userAddress) = match getString(this, keyUser2NumMapping(toString(userAddress))) { | |
355 | + | case s: String => | |
356 | + | valueOrErrorMessage(parseInt(s), wrapErr("invalid user number")) | |
357 | + | case _: Unit => | |
358 | + | throwErr("invalid user") | |
359 | + | case _ => | |
360 | + | throw("Match error") | |
361 | + | } | |
362 | + | ||
363 | + | ||
364 | + | func getGwxAmountTotal () = valueOrElse(getInteger(this, keyGwxTotal()), 0) | |
365 | + | ||
366 | + | ||
367 | + | func getLockedGwxAmount (userAddress) = { | |
368 | + | let functionName = "getLockedGwxAmount" | |
369 | + | let votingEmissionRateContract = valueOrErrorMessage( match getString(votingEmissionContract, keyVotingEmissionRateContract) { | |
370 | + | case _: Unit => | |
371 | + | unit | |
372 | + | case s: String => | |
373 | + | addressFromString(s) | |
374 | + | case _ => | |
375 | + | throw("Match error") | |
376 | + | }, wrapErr("invalid voting emission rate address")) | |
377 | + | let lockedVotingEmissionRate = { | |
378 | + | let @ = invoke(votingEmissionContract, functionName, [toString(userAddress)], nil) | |
379 | + | if ($isInstanceOf(@, "Int")) | |
380 | + | then @ | |
381 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
382 | + | } | |
383 | + | let lockedVotingEmission = { | |
384 | + | let @ = invoke(votingEmissionRateContract, functionName, [toString(userAddress)], nil) | |
385 | + | if ($isInstanceOf(@, "Int")) | |
386 | + | then @ | |
387 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
388 | + | } | |
389 | + | let locked = max([lockedVotingEmissionRate, lockedVotingEmission]) | |
390 | + | locked | |
378 | 391 | } | |
379 | 392 | ||
380 | 393 | ||
381 | - | func HistoryEntry (type,user,amount,lockStart,duration, | |
394 | + | func HistoryEntry (type,user,amount,lockStart,duration,gwxAmount,i) = { | |
382 | 395 | let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], SEP) | |
383 | - | let historyDATA = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount), toString(lockStart), toString(duration), toString( | |
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) | |
384 | 397 | StringEntry(historyKEY, historyDATA) | |
385 | 398 | } | |
386 | 399 | ||
390 | 403 | let locksCountKEY = keyStatsLocksCount() | |
391 | 404 | let usersCountKEY = keyStatsUsersCount() | |
392 | 405 | let totalAmountKEY = keyLockParamTotalAmount() | |
393 | - | let locksDurationSumInBlocks = | |
394 | - | let locksCount = | |
395 | - | let usersCount = | |
396 | - | let totalAmount = | |
406 | + | let locksDurationSumInBlocks = getIntOrZero(this, locksDurationSumInBlocksKEY) | |
407 | + | let locksCount = getIntOrZero(this, locksCountKEY) | |
408 | + | let usersCount = getIntOrZero(this, usersCountKEY) | |
409 | + | let totalAmount = getIntOrZero(this, totalAmountKEY) | |
397 | 410 | [IntegerEntry(locksDurationSumInBlocksKEY, (locksDurationSumInBlocks + durationInc)), IntegerEntry(locksCountKEY, (locksCount + lockCountInc)), IntegerEntry(usersCountKEY, (usersCount + usersCountInc)), IntegerEntry(totalAmountKEY, (totalAmount + totalLockedInc))] | |
398 | 411 | } | |
399 | 412 | ||
400 | 413 | ||
401 | - | func calcGwxAmount (kRaw,bRaw,h) = { | |
402 | - | let SCALE = 1000 | |
403 | - | (((kRaw * h) + bRaw) / SCALE) | |
404 | - | } | |
405 | - | ||
406 | - | ||
407 | - | func LockParamsEntry (userAddress,userNum,amount,start,duration,k,b,period) = { | |
408 | - | let userAmountKEY = keyLockParamUserAmount(userNum) | |
409 | - | let startBlockKEY = keyLockParamStartBlock(userNum) | |
410 | - | let durationKEY = keyLockParamDuration(userNum) | |
411 | - | let kKEY = keyLockParamK(userNum) | |
412 | - | let bKEY = keyLockParamB(userNum) | |
413 | - | let kByPeriodKEY = keyLockParamByPeriodK(userNum, period) | |
414 | - | let bByPeriodKEY = keyLockParamByPeriodB(userNum, period) | |
415 | - | let gwxAmount = calcGwxAmount(k, b, height) | |
416 | - | [IntegerEntry(userAmountKEY, amount), IntegerEntry(startBlockKEY, start), IntegerEntry(durationKEY, duration), IntegerEntry(kKEY, k), IntegerEntry(bKEY, b), IntegerEntry(kByPeriodKEY, k), IntegerEntry(bByPeriodKEY, b), StringEntry(keyLockParamsRecord(userAddress), formatLockParamsRecord(userNum, amount, start, duration, k, b, gwxAmount))] | |
417 | - | } | |
414 | + | func LockParamsEntry (userAddress,txId,amount,start,duration,gwxAmount,wxClaimed) = [StringEntry(keyLockParamsRecord(userAddress, txId), formatLockParamsRecord(amount, start, duration, gwxAmount, wxClaimed))] | |
418 | 415 | ||
419 | 416 | ||
420 | 417 | func extractOptionalPaymentAmountOrFail (i,expectedAssetId) = if ((size(i.payments) > 1)) | |
429 | 426 | } | |
430 | 427 | ||
431 | 428 | ||
432 | - | func calcUserGwxAmountAtHeight (userAddress,targetHeight) = { | |
433 | - | let EMPTY = "empty" | |
434 | - | let user2NumMappingKEY = keyUser2NumMapping(userAddress) | |
435 | - | let userNum = valueOrElse(getString(user2NumMappingKEY), EMPTY) | |
436 | - | let k = valueOrElse(getInteger(keyLockParamK(userNum)), 0) | |
437 | - | let b = valueOrElse(getInteger(keyLockParamB(userNum)), 0) | |
438 | - | let gwxAmountCalc = calcGwxAmount(k, b, targetHeight) | |
439 | - | let gwxAmount = if ((0 > gwxAmountCalc)) | |
440 | - | then 0 | |
441 | - | else gwxAmountCalc | |
442 | - | gwxAmount | |
443 | - | } | |
444 | - | ||
445 | - | ||
446 | - | func calcCurrentGwxAmount (userAddress) = calcUserGwxAmountAtHeight(userAddress, height) | |
429 | + | func getUserGwxAmountTotal (userAddress) = valueOrElse(getInteger(this, keyUserGwxAmountTotal(userAddress)), 0) | |
447 | 430 | ||
448 | 431 | ||
449 | 432 | func getVotingEmissionEpochInfo () = { | |
450 | - | let $ | |
433 | + | let $t01505615346 = { | |
451 | 434 | let currentEpochUi = value(getInteger(votingEmissionContract, keyCurrentEpochUi())) | |
452 | 435 | let lastFinalizedEpoch = (currentEpochUi - 1) | |
453 | 436 | if ((0 > lastFinalizedEpoch)) | |
454 | 437 | then throwErr("invalid epoch") | |
455 | 438 | else $Tuple2(currentEpochUi, lastFinalizedEpoch) | |
456 | 439 | } | |
457 | - | let currentEpochUi = $ | |
458 | - | let lastFinalizedEpoch = $ | |
440 | + | let currentEpochUi = $t01505615346._1 | |
441 | + | let lastFinalizedEpoch = $t01505615346._2 | |
459 | 442 | let currentEpochStartHeight = value(getInteger(votingEmissionContract, keyStartHeightByEpoch(currentEpochUi))) | |
460 | 443 | $Tuple2(lastFinalizedEpoch, currentEpochStartHeight) | |
461 | 444 | } | |
488 | 471 | ||
489 | 472 | func getUserVoteFinalized (lpAssetIdStr,userAddressStr) = { | |
490 | 473 | let userAddress = addressFromStringValue(userAddressStr) | |
491 | - | let $ | |
492 | - | let lastFinalizedEpoch = $ | |
493 | - | let currentEpochStartHeight = $ | |
494 | - | let $ | |
495 | - | let amountAssetId = $ | |
496 | - | let priceAssetId = $ | |
474 | + | let $t01603716117 = getVotingEmissionEpochInfo() | |
475 | + | let lastFinalizedEpoch = $t01603716117._1 | |
476 | + | let currentEpochStartHeight = $t01603716117._2 | |
477 | + | let $t01612016195 = getPoolAssetsByLpAssetId(lpAssetIdStr) | |
478 | + | let amountAssetId = $t01612016195._1 | |
479 | + | let priceAssetId = $t01612016195._2 | |
497 | 480 | let userVoteKey = keyVote(amountAssetId, priceAssetId, userAddress, lastFinalizedEpoch) | |
498 | 481 | let userVote = valueOrElse(getInteger(votingEmissionContract, userVoteKey), 0) | |
499 | 482 | userVote | |
510 | 493 | ||
511 | 494 | ||
512 | 495 | func getVotingResultStaked (lpAssetIdStr) = { | |
513 | - | let $ | |
514 | - | let lastFinalizedEpoch = $ | |
515 | - | let currentEpochStartHeight = $ | |
496 | + | let $t01673916819 = getVotingEmissionEpochInfo() | |
497 | + | let lastFinalizedEpoch = $t01673916819._1 | |
498 | + | let currentEpochStartHeight = $t01673916819._2 | |
516 | 499 | let votingResultStakedStart = valueOrElse(getInteger(votingEmissionContract, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), 0) | |
517 | 500 | let votingResultStaked = valueOrElse(getInteger(this, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), votingResultStakedStart) | |
518 | 501 | votingResultStaked | |
520 | 503 | ||
521 | 504 | ||
522 | 505 | func getVotingResultStakedIntegral (lpAssetIdStr) = { | |
523 | - | let $ | |
524 | - | let lastFinalizedEpoch = $ | |
525 | - | let currentEpochStartHeight = $ | |
506 | + | let $t01718117261 = getVotingEmissionEpochInfo() | |
507 | + | let lastFinalizedEpoch = $t01718117261._1 | |
508 | + | let currentEpochStartHeight = $t01718117261._2 | |
526 | 509 | let votingResultStaked = getVotingResultStaked(lpAssetIdStr) | |
527 | 510 | let votingResultStakedIntegralPrev = valueOrElse(getInteger(this, keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch)), 0) | |
528 | 511 | let votingResultStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch)), currentEpochStartHeight) | |
533 | 516 | ||
534 | 517 | ||
535 | 518 | func refreshVotingResultStakedIntegral (lpAssetIdStr,stakedVoteDelta) = { | |
536 | - | let $ | |
537 | - | let lastFinalizedEpoch = $ | |
538 | - | let currentEpochStartHeight = $ | |
519 | + | let $t01809818178 = getVotingEmissionEpochInfo() | |
520 | + | let lastFinalizedEpoch = $t01809818178._1 | |
521 | + | let currentEpochStartHeight = $t01809818178._2 | |
539 | 522 | let votingResultStaked = getVotingResultStaked(lpAssetIdStr) | |
540 | 523 | let votingResultStakedNew = (votingResultStaked + stakedVoteDelta) | |
541 | 524 | let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr) | |
544 | 527 | ||
545 | 528 | ||
546 | 529 | func getUserVoteStakedIntegral (lpAssetIdStr,userAddressStr) = { | |
547 | - | let $ | |
548 | - | let lastFinalizedEpoch = $ | |
549 | - | let currentEpochStartHeight = $ | |
530 | + | let $t01878918869 = getVotingEmissionEpochInfo() | |
531 | + | let lastFinalizedEpoch = $t01878918869._1 | |
532 | + | let currentEpochStartHeight = $t01878918869._2 | |
550 | 533 | let userAddress = addressFromStringValue(userAddressStr) | |
551 | 534 | let userVoteStaked = getUserVoteStaked(lpAssetIdStr, userAddressStr) | |
552 | 535 | let userVoteStakedIntegralPrev = valueOrElse(getInteger(this, keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch)), 0) | |
558 | 541 | ||
559 | 542 | ||
560 | 543 | func refreshVoteStakedIntegral (lpAssetIdStr,userAddressStr,edge) = { | |
561 | - | let $ | |
562 | - | let lastFinalizedEpoch = $ | |
563 | - | let currentEpochStartHeight = $ | |
544 | + | let $t01965719737 = getVotingEmissionEpochInfo() | |
545 | + | let lastFinalizedEpoch = $t01965719737._1 | |
546 | + | let currentEpochStartHeight = $t01965719737._2 | |
564 | 547 | let userAddress = addressFromStringValue(userAddressStr) | |
565 | 548 | let userVoteFinalized = getUserVoteFinalized(lpAssetIdStr, userAddressStr) | |
566 | 549 | let actions = if ((userVoteFinalized == 0)) | |
579 | 562 | ||
580 | 563 | ||
581 | 564 | func getStakedVotesIntegralsDiff (lpAssetIdStr,userAddressStr) = { | |
582 | - | let $ | |
583 | - | let lastFinalizedEpoch = $ | |
584 | - | let currentEpochStartHeight = $ | |
565 | + | let $t02059120671 = getVotingEmissionEpochInfo() | |
566 | + | let lastFinalizedEpoch = $t02059120671._1 | |
567 | + | let currentEpochStartHeight = $t02059120671._2 | |
585 | 568 | let userAddress = addressFromStringValue(userAddressStr) | |
586 | 569 | let userVoteStakedIntegralLastKey = keyVoteStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch) | |
587 | 570 | let userVoteStakedIntegralLast = valueOrElse(getInteger(this, userVoteStakedIntegralLastKey), 0) | |
596 | 579 | ||
597 | 580 | ||
598 | 581 | func refreshBoostEmissionIntegral () = { | |
599 | - | let wxEmissionPerBlock = | |
582 | + | let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent()) | |
600 | 583 | let boostingV2LastUpdateHeightOption = getInteger(this, keyBoostingV2LastUpdateHeight()) | |
601 | 584 | let boostingV2IngergalOption = getInteger(this, keyBoostingV2Integral()) | |
602 | - | let emissionEnd = | |
585 | + | let emissionEnd = getIntOrFail(emissionContract, keyEmissionEndBlock()) | |
603 | 586 | let h = if ((height > emissionEnd)) | |
604 | 587 | then emissionEnd | |
605 | 588 | else height | |
619 | 602 | ||
620 | 603 | ||
621 | 604 | func internalClaimWxBoost (lpAssetIdStr,userAddressStr,readOnly) = { | |
622 | - | let userRecordOption = getString(this, keyLockParamsRecord(userAddressStr)) | |
623 | - | if ((userRecordOption == unit)) | |
624 | - | then $Tuple3(0, nil, "userRecord::is::empty") | |
625 | - | else { | |
626 | - | let userRecordArray = split(value(userRecordOption), SEP) | |
627 | - | let userNumStr = userRecordArray[IdxLockUserNum] | |
605 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
606 | + | let userNum = userNumberByAddressOrFail(userAddress) | |
607 | + | if ((userNum == userNum)) | |
608 | + | then { | |
628 | 609 | let EMPTYSTR = "empty" | |
629 | 610 | let poolWeight = if ((lpAssetIdStr != EMPTYSTR)) | |
630 | 611 | then { | |
634 | 615 | else if (readOnly) | |
635 | 616 | then 0 | |
636 | 617 | else throwErr(("not readonly mode: unsupported lp asset " + lpAssetIdStr)) | |
637 | - | let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL( | |
638 | - | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL( | |
639 | - | let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), | |
618 | + | let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNum, lpAssetIdStr) | |
619 | + | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum) | |
620 | + | let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), getIntOrZero(this, userBoostEmissionLastIntegralKEY)) | |
640 | 621 | let boostEmissionIntegral = refreshBoostEmissionIntegral()._2 | |
641 | 622 | let userBoostEmissionIntegral = (boostEmissionIntegral - userBoostEmissionLastIntegral) | |
642 | 623 | if ((0 > userBoostEmissionIntegral)) | |
643 | 624 | then throwErr("wrong calculations") | |
644 | 625 | else { | |
645 | - | let $ | |
646 | - | let stakedVotesIntegralsActions = $ | |
647 | - | let userVoteIntegralDiff = $ | |
648 | - | let totalVotesIntegralDiff = $ | |
626 | + | let $t02421324352 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr) | |
627 | + | let stakedVotesIntegralsActions = $t02421324352._1 | |
628 | + | let userVoteIntegralDiff = $t02421324352._2 | |
629 | + | let totalVotesIntegralDiff = $t02421324352._3 | |
649 | 630 | let poolUserBoostEmissionIntegral = fraction(userBoostEmissionIntegral, poolWeight, POOLWEIGHTMULT) | |
650 | 631 | let userBoostAvaliableToClaimTotalNew = if ((totalVotesIntegralDiff == 0)) | |
651 | 632 | then 0 | |
655 | 636 | $Tuple3(userBoostAvaliableToClaimTotalNew, dataState, debug) | |
656 | 637 | } | |
657 | 638 | } | |
639 | + | else throw("Strict value is not equal to itself.") | |
658 | 640 | } | |
659 | 641 | ||
660 | 642 | ||
661 | - | func lockActions (i,duration) = { | |
662 | - | let cfgArray = readConfigArrayOrFail() | |
663 | - | let assetIdStr = cfgArray[IdxCfgAssetId] | |
664 | - | let assetId = fromBase58String(assetIdStr) | |
665 | - | let minLockAmount = parseIntValue(cfgArray[IdxCfgMinLockAmount]) | |
666 | - | let minLockDuration = parseIntValue(cfgArray[IdxCfgMinLockDuration]) | |
667 | - | let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration]) | |
643 | + | func lockActions (i,durationMonths) = { | |
644 | + | let duration = (durationMonths * blocksInMonth) | |
645 | + | let assetIdStr = toBase58String(assetId) | |
668 | 646 | if ((size(i.payments) != 1)) | |
669 | 647 | then throwErr("invalid payment - exact one payment must be attached") | |
670 | 648 | else { | |
672 | 650 | let pmtAmount = pmt.amount | |
673 | 651 | if ((assetId != value(pmt.assetId))) | |
674 | 652 | then throwErr((("invalid asset is in payment - " + assetIdStr) + " is expected")) | |
675 | - | else { | |
676 | - | let nextUserNumKEY = keyNextUserNum() | |
677 | - | let userAddressStr = toString(i.caller) | |
678 | - | let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr))) | |
679 | - | let userNumStr = if (userIsExisting) | |
680 | - | then value(getString(keyUser2NumMapping(userAddressStr))) | |
681 | - | else toString(iof(this, nextUserNumKEY)) | |
682 | - | let userNum = parseIntValue(userNumStr) | |
683 | - | let lockStart = height | |
684 | - | let startBlockKEY = keyLockParamStartBlock(userNumStr) | |
685 | - | let durationKEY = keyLockParamDuration(userNumStr) | |
686 | - | let userAmountKEY = keyLockParamUserAmount(userNumStr) | |
687 | - | if (if ((minLockAmount > pmtAmount)) | |
688 | - | then (i.caller != lpStakingPoolsContract) | |
689 | - | else false) | |
690 | - | then throwErr(("amount is less then minLockAmount=" + toString(minLockAmount))) | |
691 | - | else if ((minLockDuration > duration)) | |
692 | - | then throwErr(("passed duration is less then minLockDuration=" + toString(minLockDuration))) | |
693 | - | else if ((duration > maxLockDuration)) | |
694 | - | then throwErr(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration))) | |
695 | - | else if (if (userIsExisting) | |
696 | - | then ((iof(this, startBlockKEY) + iof(this, durationKEY)) >= lockStart) | |
697 | - | else false) | |
698 | - | then throwErr("there is an active lock - consider to use increaseLock") | |
699 | - | else if ((ioz(this, userAmountKEY) > 0)) | |
700 | - | then throwErr(("there are locked WXs - consider to use increaseLock " + userAmountKEY)) | |
701 | - | else { | |
702 | - | let coeffX8 = fraction(duration, MULT8, maxLockDuration) | |
703 | - | let gWxAmountStart = fraction(pmtAmount, coeffX8, MULT8) | |
704 | - | let gWxParamsResultList = aal(invoke(mathContract, "calcGwxParamsREADONLY", [gWxAmountStart, lockStart, duration], nil)) | |
705 | - | let k = ai(gWxParamsResultList[0]) | |
706 | - | let b = ai(gWxParamsResultList[1]) | |
707 | - | let period = toString(ai(gWxParamsResultList[2])) | |
708 | - | let totalCachedGwxRaw = getTotalCachedGwx(false) | |
709 | - | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr) | |
710 | - | let boostEmissionIntegral = refreshBoostEmissionIntegral()._2 | |
711 | - | let arr = if (userIsExisting) | |
712 | - | then nil | |
713 | - | else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)] | |
714 | - | $Tuple2(((((arr ++ LockParamsEntry(userAddressStr, userNumStr, pmtAmount, lockStart, duration, k, b, period)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting) | |
715 | - | then 0 | |
716 | - | else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, k, b, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyTotalCachedGwx(), (totalCachedGwxRaw + gWxAmountStart))]), gWxAmountStart) | |
717 | - | } | |
718 | - | } | |
653 | + | else if (!(containsElement(durationMonthsAllowed, durationMonths))) | |
654 | + | then throwErr("invalid duration") | |
655 | + | else { | |
656 | + | let nextUserNumKEY = keyNextUserNum() | |
657 | + | let userAddress = i.caller | |
658 | + | let userAddressStr = toString(userAddress) | |
659 | + | let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr))) | |
660 | + | let userNumStr = if (userIsExisting) | |
661 | + | then value(getString(keyUser2NumMapping(userAddressStr))) | |
662 | + | else toString(getIntOrFail(this, nextUserNumKEY)) | |
663 | + | let userNum = parseIntValue(userNumStr) | |
664 | + | let lockStart = height | |
665 | + | if (if ((minLockAmount > pmtAmount)) | |
666 | + | then (userAddress != lpStakingPoolsContract) | |
667 | + | else false) | |
668 | + | then throwErr(("amount is less then minLockAmount=" + toString(minLockAmount))) | |
669 | + | else if ((minLockDuration > duration)) | |
670 | + | then throwErr(("passed duration is less then minLockDuration=" + toString(minLockDuration))) | |
671 | + | else if ((duration > maxLockDuration)) | |
672 | + | then throwErr(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration))) | |
673 | + | else { | |
674 | + | let gWxAmountStart = fraction(pmtAmount, duration, maxLockDuration) | |
675 | + | let gwxAmountTotal = getGwxAmountTotal() | |
676 | + | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum) | |
677 | + | let boostEmissionIntegral = refreshBoostEmissionIntegral()._2 | |
678 | + | let userGwxAmountTotal = getUserGwxAmountTotal(userAddress) | |
679 | + | let gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes, userNum], nil) | |
680 | + | if ((gwxRewardInv == gwxRewardInv)) | |
681 | + | then { | |
682 | + | let arr = if (userIsExisting) | |
683 | + | then nil | |
684 | + | else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)] | |
685 | + | $Tuple2(((((arr ++ LockParamsEntry(userAddress, i.transactionId, pmtAmount, lockStart, duration, gWxAmountStart, 0)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting) | |
686 | + | then 0 | |
687 | + | else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, gWxAmountStart, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyGwxTotal(), (gwxAmountTotal + gWxAmountStart)), IntegerEntry(keyUserGwxAmountTotal(userAddress), (userGwxAmountTotal + gWxAmountStart))]), gWxAmountStart) | |
688 | + | } | |
689 | + | else throw("Strict value is not equal to itself.") | |
690 | + | } | |
691 | + | } | |
719 | 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 | |
720 | 709 | } | |
721 | 710 | ||
722 | 711 | ||
732 | 721 | ||
733 | 722 | @Callable(i) | |
734 | 723 | func lockRef (duration,referrerAddress,signature) = { | |
735 | - | let $ | |
736 | - | let lockActionsResult = $ | |
737 | - | let gWxAmountStart = $ | |
724 | + | let $t02916029225 = lockActions(i, duration) | |
725 | + | let lockActionsResult = $t02916029225._1 | |
726 | + | let gWxAmountStart = $t02916029225._2 | |
738 | 727 | let referralAddress = toString(i.caller) | |
739 | 728 | let refInv = if (if ((referrerAddress == "")) | |
740 | 729 | then true | |
755 | 744 | ||
756 | 745 | @Callable(i) | |
757 | 746 | func lock (duration) = { | |
758 | - | let $ | |
759 | - | let lockActionsResult = $ | |
760 | - | let gWxAmountStart = $ | |
747 | + | let $t02968329748 = lockActions(i, duration) | |
748 | + | let lockActionsResult = $t02968329748._1 | |
749 | + | let gWxAmountStart = $t02968329748._2 | |
761 | 750 | let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil) | |
762 | 751 | if ((updateRefActivity == updateRefActivity)) | |
763 | 752 | then $Tuple2(lockActionsResult, unit) | |
767 | 756 | ||
768 | 757 | ||
769 | 758 | @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) | |
821 | 759 | func claimWxBoost (lpAssetIdStr,userAddressStr) = if ((stakingContract != i.caller)) | |
822 | 760 | then throwErr("permissions denied") | |
823 | 761 | else { | |
824 | - | let $ | |
825 | - | let userBoostAvailable = $ | |
826 | - | let dataState = $ | |
827 | - | let debug = $ | |
762 | + | let $t03005830160 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false) | |
763 | + | let userBoostAvailable = $t03005830160._1 | |
764 | + | let dataState = $t03005830160._2 | |
765 | + | let debug = $t03005830160._3 | |
828 | 766 | $Tuple2(dataState, [userBoostAvailable]) | |
829 | 767 | } | |
830 | 768 | ||
832 | 770 | ||
833 | 771 | @Callable(i) | |
834 | 772 | func claimWxBoostREADONLY (lpAssetIdStr,userAddressStr) = { | |
835 | - | let $ | |
836 | - | let userBoostAvailable = $ | |
837 | - | let dataState = $ | |
838 | - | let debug = $ | |
773 | + | let $t03029230393 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true) | |
774 | + | let userBoostAvailable = $t03029230393._1 | |
775 | + | let dataState = $t03029230393._2 | |
776 | + | let debug = $t03029230393._3 | |
839 | 777 | $Tuple2(nil, [userBoostAvailable, debug]) | |
840 | 778 | } | |
841 | 779 | ||
842 | 780 | ||
843 | 781 | ||
844 | 782 | @Callable(i) | |
845 | - | func unlock (userAddress) = { | |
846 | - | let userRecordArray = readLockParamsRecordOrFail(userAddress) | |
847 | - | let userNumStr = userRecordArray[IdxLockUserNum] | |
783 | + | func unlock (txIdStr) = { | |
784 | + | let userAddress = i.caller | |
785 | + | let userAddressStr = toString(userAddress) | |
786 | + | let txIdOption = if ((txIdStr == "")) | |
787 | + | then unit | |
788 | + | else fromBase58String(txIdStr) | |
789 | + | let userRecordArray = readLockParamsRecordOrFail(userAddress, txIdOption) | |
848 | 790 | let userAmount = parseIntValue(userRecordArray[IdxLockAmount]) | |
849 | 791 | let lockStart = parseIntValue(userRecordArray[IdxLockStart]) | |
850 | 792 | let lockDuration = parseIntValue(userRecordArray[IdxLockDuration]) | |
851 | - | let lockEnd = (lockStart + lockDuration) | |
852 | - | let cfgArray = readConfigArrayOrFail() | |
853 | - | let assetId = fromBase58String(cfgArray[IdxCfgAssetId]) | |
854 | - | if ((lockEnd >= height)) | |
855 | - | then throwErr((("wait " + toString(lockEnd)) + " to unlock")) | |
856 | - | else if ((0 >= userAmount)) | |
857 | - | then throwErr("nothing to unlock") | |
858 | - | else { | |
859 | - | let period = valueOrElse(getInteger(mathContract, keyNextPeriod()), 0) | |
860 | - | (((LockParamsEntry(userAddress, userNumStr, 0, lockStart, lockDuration, 0, 0, toString(period)) ++ StatsEntry(-(userAmount), 0, 0, -1)) :+ HistoryEntry("unlock", userAddress, userAmount, lockStart, lockDuration, 0, 0, i)) :+ ScriptTransfer(addressFromStringValue(userAddress), userAmount, assetId)) | |
861 | - | } | |
793 | + | let wxClaimed = parseIntValue(userRecordArray[IdxLockWxClaimed]) | |
794 | + | let gwxAmount = parseIntValue(userRecordArray[IdxLockGwxAmount]) | |
795 | + | let t = ((height - lockStart) / blocksInPeriod) | |
796 | + | let wxWithdrawable = getWxWithdrawable(userAddress, txIdOption) | |
797 | + | let gWxAmountStart = fraction(userAmount, lockDuration, maxLockDuration) | |
798 | + | let gwxBurned = min([fraction((t * blocksInPeriod), gWxAmountStart, maxLockDuration), gwxAmount]) | |
799 | + | let gwxRemaining = ensurePositive((gwxAmount - gwxBurned), "gwxRemaining") | |
800 | + | let lockedGwxAmount = getLockedGwxAmount(userAddress) | |
801 | + | if ((0 >= userAmount)) | |
802 | + | then throwErr("nothing to unlock") | |
803 | + | else { | |
804 | + | let gwxAmountTotal = getGwxAmountTotal() | |
805 | + | let userGwxAmountTotal = getUserGwxAmountTotal(userAddress) | |
806 | + | let userGwxAmountTotalNew = ensurePositive((userGwxAmountTotal - gwxBurned), "userGwxAmountTotalNew") | |
807 | + | if ((lockedGwxAmount > userGwxAmountTotalNew)) | |
808 | + | then throwErr(("locked gwx amount: " + toString(lockedGwxAmount))) | |
809 | + | else { | |
810 | + | let userNum = parseIntValue(valueOrErrorMessage(getString(keyUser2NumMapping(userAddressStr)), wrapErr("invalid user number"))) | |
811 | + | let gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes, userNum], nil) | |
812 | + | if ((gwxRewardInv == gwxRewardInv)) | |
813 | + | then ((((LockParamsEntry(userAddress, txIdOption, 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)]) | |
814 | + | else throw("Strict value is not equal to itself.") | |
815 | + | } | |
816 | + | } | |
862 | 817 | } | |
863 | 818 | ||
864 | 819 | ||
865 | 820 | ||
866 | 821 | @Callable(i) | |
867 | - | func gwxUserInfoREADONLY (userAddress) = { | |
868 | - | let gwxAmount = calcCurrentGwxAmount(userAddress) | |
822 | + | func gwxUserInfoREADONLY (userAddressStr) = { | |
823 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
824 | + | let gwxAmount = getUserGwxAmountTotal(userAddress) | |
869 | 825 | $Tuple2(nil, [gwxAmount]) | |
870 | 826 | } | |
871 | 827 | ||
872 | 828 | ||
873 | 829 | ||
874 | 830 | @Callable(i) | |
875 | - | func userMaxDurationREADONLY (userAddressStr) = { | |
876 | - | let cfgArray = readConfigArrayOrFail() | |
877 | - | let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration]) | |
878 | - | let userRecordOption = getString(this, keyLockParamsRecord(userAddressStr)) | |
879 | - | if ((userRecordOption == unit)) | |
880 | - | then $Tuple2(nil, $Tuple2("lock", maxLockDuration)) | |
881 | - | else { | |
882 | - | let userRecordArray = split(value(userRecordOption), SEP) | |
883 | - | let lockStart = parseIntValue(userRecordArray[IdxLockStart]) | |
884 | - | let lockDuration = parseIntValue(userRecordArray[IdxLockDuration]) | |
885 | - | let lockEnd = (lockStart + lockDuration) | |
886 | - | let remainingDuration = max([(lockEnd - height), 0]) | |
887 | - | let maxDeltaDuration = (maxLockDuration - remainingDuration) | |
888 | - | $Tuple2(nil, $Tuple2("increaseLock", maxDeltaDuration)) | |
889 | - | } | |
890 | - | } | |
831 | + | func userMaxDurationREADONLY (userAddressStr) = $Tuple2(nil, $Tuple2("lock", maxLockDuration)) | |
891 | 832 | ||
892 | 833 | ||
893 | 834 | ||
894 | 835 | @Callable(i) | |
895 | - | func getUserGwxAmountAtHeightREADONLY (userAddress,targetHeight) = { | |
896 | - | let gwxAmount = calcUserGwxAmountAtHeight(userAddress, targetHeight) | |
836 | + | func getUserGwxAmountAtHeightREADONLY (userAddressStr,targetHeight) = { | |
837 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
838 | + | let gwxAmount = getUserGwxAmountTotal(userAddress) | |
897 | 839 | $Tuple2(nil, gwxAmount) | |
898 | 840 | } | |
899 | 841 | ||
900 | 842 | ||
901 | 843 | ||
902 | 844 | @Callable(i) | |
903 | - | func getTotalCachedGwxREADONLY () = $Tuple2(nil, getTotalCachedGwx(true)) | |
845 | + | func getUserGwxAmount (userAddressStr) = { | |
846 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
847 | + | let gwxAmount = getUserGwxAmountTotal(userAddress) | |
848 | + | $Tuple2(nil, gwxAmount) | |
849 | + | } | |
850 | + | ||
851 | + | ||
852 | + | ||
853 | + | @Callable(i) | |
854 | + | func getGwxTotalREADONLY () = $Tuple2(nil, getGwxAmountTotal()) | |
904 | 855 | ||
905 | 856 | ||
906 | 857 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | 6 | let SCALE8 = 8 | |
7 | 7 | ||
8 | 8 | let MULT8 = 100000000 | |
9 | 9 | ||
10 | 10 | let POOLWEIGHTMULT = MULT8 | |
11 | 11 | ||
12 | - | func wrapErr (msg) = makeString(["boosting.ride:", msg], " ") | |
12 | + | let contractFilename = "boosting.ride" | |
13 | + | ||
14 | + | let SCALE18 = 18 | |
15 | + | ||
16 | + | let MULT18 = 1000000000000000000 | |
17 | + | ||
18 | + | let MULT18BI = toBigInt(MULT18) | |
19 | + | ||
20 | + | let durationMonthsAllowed = [1, 3, 6, 12, 24, 48] | |
21 | + | ||
22 | + | let blocksInDay = 1440 | |
23 | + | ||
24 | + | let blocksInMonth = 43800 | |
25 | + | ||
26 | + | func wrapErr (msg) = makeString([contractFilename, ": ", msg], "") | |
13 | 27 | ||
14 | 28 | ||
15 | 29 | func throwErr (msg) = throw(wrapErr(msg)) | |
16 | 30 | ||
17 | 31 | ||
18 | - | func | |
32 | + | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined"))) | |
19 | 33 | ||
20 | 34 | ||
21 | - | func | |
35 | + | func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0) | |
22 | 36 | ||
23 | 37 | ||
24 | - | func | |
38 | + | func getIntOrDefault (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal) | |
25 | 39 | ||
26 | 40 | ||
27 | - | func | |
41 | + | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), wrapErr((("mandatory this." + key) + " is not defined"))) | |
28 | 42 | ||
29 | 43 | ||
30 | 44 | func abs (val) = if ((0 > val)) | |
31 | 45 | then -(val) | |
32 | 46 | else val | |
33 | 47 | ||
34 | 48 | ||
35 | - | func aal (val) = match val { | |
36 | - | case valAnyLyst: List[Any] => | |
37 | - | valAnyLyst | |
38 | - | case _ => | |
39 | - | throwErr("fail to cast into List[Any]") | |
40 | - | } | |
41 | - | ||
42 | - | ||
43 | - | func ai (val) = match val { | |
44 | - | case valInt: Int => | |
45 | - | valInt | |
46 | - | case _ => | |
47 | - | throwErr("fail to cast into Int") | |
48 | - | } | |
49 | + | func ensurePositive (v,m) = if ((v >= 0)) | |
50 | + | then v | |
51 | + | else throwErr((valueOrElse(m, "value") + " should be positive")) | |
49 | 52 | ||
50 | 53 | ||
51 | 54 | func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP) | |
52 | 55 | ||
53 | 56 | ||
54 | - | let referralsContractAddressOrFail = addressFromStringValue( | |
57 | + | let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(this, keyReferralsContractAddress())) | |
55 | 58 | ||
56 | 59 | let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP) | |
57 | 60 | ||
58 | 61 | let referralProgramNameDefault = "wxlock" | |
59 | 62 | ||
60 | 63 | let referralProgramName = valueOrElse(getString(this, keyReferralProgramName), referralProgramNameDefault) | |
61 | 64 | ||
62 | 65 | func keyFactoryAddress () = "%s%s__config__factoryAddress" | |
63 | 66 | ||
64 | 67 | ||
65 | 68 | let IdxFactoryCfgStakingDapp = 1 | |
66 | 69 | ||
67 | 70 | let IdxFactoryCfgBoostingDapp = 2 | |
68 | 71 | ||
69 | 72 | let IdxFactoryCfgIdoDapp = 3 | |
70 | 73 | ||
71 | 74 | let IdxFactoryCfgTeamDapp = 4 | |
72 | 75 | ||
73 | 76 | let IdxFactoryCfgEmissionDapp = 5 | |
74 | 77 | ||
75 | 78 | let IdxFactoryCfgRestDapp = 6 | |
76 | 79 | ||
77 | 80 | let IdxFactoryCfgSlippageDapp = 7 | |
78 | 81 | ||
79 | 82 | let IdxFactoryCfgDaoDapp = 8 | |
80 | 83 | ||
81 | 84 | let IdxFactoryCfgMarketingDapp = 9 | |
82 | 85 | ||
83 | 86 | let IdxFactoryCfgGwxRewardDapp = 10 | |
84 | 87 | ||
85 | 88 | let IdxFactoryCfgBirdsDapp = 11 | |
86 | 89 | ||
87 | 90 | func keyFactoryCfg () = "%s__factoryConfig" | |
88 | 91 | ||
89 | 92 | ||
90 | - | func keyFactoryLpList () = "%s__lpTokensList" | |
91 | - | ||
92 | - | ||
93 | 93 | func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) | |
94 | 94 | ||
95 | 95 | ||
96 | 96 | func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP) | |
97 | 97 | ||
98 | 98 | ||
99 | 99 | func keyFactoryPoolWeightHistory (poolAddress,num) = ((("%s%s__poolWeight__" + poolAddress) + "__") + toString(num)) | |
100 | 100 | ||
101 | 101 | ||
102 | - | func readFactoryAddressOrFail () = addressFromStringValue( | |
102 | + | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(this, keyFactoryAddress())) | |
103 | 103 | ||
104 | 104 | ||
105 | - | func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP) | |
106 | - | ||
107 | - | ||
108 | - | func readFactoryCfgOrFail (factory) = split(strf(factory, keyFactoryCfg()), SEP) | |
105 | + | func readFactoryCfgOrFail (factory) = split(getStringOrFail(factory, keyFactoryCfg()), SEP) | |
109 | 106 | ||
110 | 107 | ||
111 | 108 | func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp]) | |
112 | 109 | ||
113 | 110 | ||
114 | 111 | func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp]) | |
115 | 112 | ||
116 | 113 | ||
117 | 114 | func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp]) | |
118 | 115 | ||
119 | 116 | ||
120 | 117 | func getGwxRewardAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgGwxRewardDapp]) | |
121 | 118 | ||
122 | 119 | ||
123 | 120 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
124 | 121 | ||
125 | 122 | ||
126 | 123 | func keyManagerVaultAddress () = "%s__managerVaultAddress" | |
127 | 124 | ||
128 | 125 | ||
129 | 126 | func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current" | |
130 | 127 | ||
131 | 128 | ||
132 | 129 | func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current" | |
133 | 130 | ||
134 | 131 | ||
135 | 132 | func keyEmissionStartBlock () = "%s%s__emission__startBlock" | |
136 | 133 | ||
137 | 134 | ||
138 | 135 | func keyBoostingV2LastUpdateHeight () = "%s%s__boostingV2__startBlock" | |
139 | 136 | ||
140 | 137 | ||
141 | 138 | func keyBoostingV2Integral () = "%s%s__boostingV2__integral" | |
142 | 139 | ||
143 | 140 | ||
144 | 141 | func keyEmissionDurationInBlocks () = "%s%s__emission__duration" | |
145 | 142 | ||
146 | 143 | ||
147 | 144 | func keyEmissionEndBlock () = "%s%s__emission__endBlock" | |
148 | 145 | ||
149 | 146 | ||
150 | - | func keyNextPeriod () = "%s__nextPeriod" | |
151 | - | ||
152 | - | ||
153 | - | func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight" | |
154 | - | ||
155 | - | ||
156 | 147 | let IdxCfgAssetId = 1 | |
157 | 148 | ||
158 | 149 | let IdxCfgMinLockAmount = 2 | |
159 | 150 | ||
160 | 151 | let IdxCfgMinLockDuration = 3 | |
161 | 152 | ||
162 | 153 | let IdxCfgMaxLockDuration = 4 | |
163 | 154 | ||
164 | 155 | let IdxCfgMathContract = 5 | |
165 | 156 | ||
157 | + | let IdxCfgBlocksInPeriod = 6 | |
158 | + | ||
166 | 159 | func keyConfig () = "%s__config" | |
167 | 160 | ||
168 | 161 | ||
169 | - | func readConfigArrayOrFail () = split( | |
162 | + | func readConfigArrayOrFail () = split(getStringOrFail(this, keyConfig()), SEP) | |
170 | 163 | ||
171 | 164 | ||
172 | - | let | |
165 | + | let cfgArray = readConfigArrayOrFail() | |
173 | 166 | ||
174 | - | func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP) | |
167 | + | let assetId = fromBase58String(cfgArray[IdxCfgAssetId]) | |
168 | + | ||
169 | + | let minLockAmount = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMinLockAmount]), wrapErr("invalid min lock amount")) | |
170 | + | ||
171 | + | let minLockDuration = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMinLockDuration]), wrapErr("invalid min lock duration")) | |
172 | + | ||
173 | + | let maxLockDuration = valueOrErrorMessage(parseInt(cfgArray[IdxCfgMaxLockDuration]), wrapErr("invalid max lock duration")) | |
174 | + | ||
175 | + | let mathContract = valueOrErrorMessage(addressFromString(cfgArray[IdxCfgMathContract]), wrapErr("invalid math contract address")) | |
176 | + | ||
177 | + | let blocksInPeriod = valueOrErrorMessage(parseInt(cfgArray[IdxCfgBlocksInPeriod]), wrapErr("invalid blocks in period")) | |
178 | + | ||
179 | + | func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d%s", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP) | |
175 | 180 | ||
176 | 181 | ||
177 | 182 | func formatConfig (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = formatConfigS(assetId, toString(minLockAmount), toString(minLockDuration), toString(maxLockDuration), mathContract) | |
178 | 183 | ||
179 | 184 | ||
180 | 185 | func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) { | |
181 | 186 | case s: String => | |
182 | 187 | addressFromStringValue(s) | |
183 | 188 | case _ => | |
184 | 189 | this | |
185 | 190 | } | |
186 | 191 | ||
187 | 192 | ||
188 | 193 | func managerPublicKeyOrUnit () = { | |
189 | 194 | let managerVaultAddress = getManagerVaultAddressOrThis() | |
190 | 195 | match getString(managerVaultAddress, keyManagerPublicKey()) { | |
191 | 196 | case s: String => | |
192 | 197 | fromBase58String(s) | |
193 | 198 | case _: Unit => | |
194 | 199 | unit | |
195 | 200 | case _ => | |
196 | 201 | throw("Match error") | |
197 | 202 | } | |
198 | 203 | } | |
199 | 204 | ||
200 | 205 | ||
201 | 206 | func mustManager (i) = { | |
202 | 207 | let pd = throwErr("Permission denied") | |
203 | 208 | match managerPublicKeyOrUnit() { | |
204 | 209 | case pk: ByteVector => | |
205 | 210 | if ((i.callerPublicKey == pk)) | |
206 | 211 | then true | |
207 | 212 | else pd | |
208 | 213 | case _: Unit => | |
209 | 214 | if ((i.caller == this)) | |
210 | 215 | then true | |
211 | 216 | else pd | |
212 | 217 | case _ => | |
213 | 218 | throw("Match error") | |
214 | 219 | } | |
215 | 220 | } | |
216 | 221 | ||
217 | 222 | ||
218 | - | let | |
223 | + | let IdxLockAmount = 1 | |
219 | 224 | ||
220 | - | let | |
225 | + | let IdxLockStart = 2 | |
221 | 226 | ||
222 | - | let | |
227 | + | let IdxLockDuration = 3 | |
223 | 228 | ||
224 | - | let | |
229 | + | let IdxLockLastUpdateTimestamp = 4 | |
225 | 230 | ||
226 | - | let | |
231 | + | let IdxLockGwxAmount = 5 | |
227 | 232 | ||
228 | - | let | |
233 | + | let IdxLockWxClaimed = 6 | |
229 | 234 | ||
230 | - | func keyLockParamsRecord (userAddress) = makeString(["%s%s__lock", userAddress], SEP) | |
235 | + | func keyLockParamsRecord (userAddress,txId) = makeString(["%s%s%s__lock", toString(userAddress), match txId { | |
236 | + | case b: ByteVector => | |
237 | + | toBase58String(b) | |
238 | + | case _: Unit => | |
239 | + | "legacy" | |
240 | + | case _ => | |
241 | + | throw("Match error") | |
242 | + | }], SEP) | |
231 | 243 | ||
232 | 244 | ||
233 | - | func readLockParamsRecordOrFail (userAddress) = split( | |
245 | + | func readLockParamsRecordOrFail (userAddress,txId) = split(getStringOrFail(this, keyLockParamsRecord(userAddress, txId)), SEP) | |
234 | 246 | ||
235 | 247 | ||
236 | - | func | |
248 | + | func keyUserGwxAmountTotal (userAddress) = makeString(["%s%s__gwxAmountTotal", toString(userAddress)], SEP) | |
237 | 249 | ||
238 | 250 | ||
239 | - | func formatLockParamsRecord ( | |
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) | |
240 | 252 | ||
241 | 253 | ||
242 | 254 | func keyNextUserNum () = "%s__nextUserNum" | |
243 | 255 | ||
244 | 256 | ||
245 | 257 | func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", userAddress], SEP) | |
246 | 258 | ||
247 | 259 | ||
248 | 260 | 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) | |
270 | 261 | ||
271 | 262 | ||
272 | 263 | func keyLockParamTotalAmount () = "%s%s__stats__activeTotalLocked" | |
273 | 264 | ||
274 | 265 | ||
275 | 266 | func keyStatsLocksDurationSumInBlocks () = "%s%s__stats__locksDurationSumInBlocks" | |
276 | 267 | ||
277 | 268 | ||
278 | 269 | func keyStatsLocksCount () = "%s%s__stats__locksCount" | |
279 | 270 | ||
280 | 271 | ||
281 | 272 | func keyStatsUsersCount () = "%s%s__stats__activeUsersCount" | |
282 | 273 | ||
283 | 274 | ||
284 | - | func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum], SEP) | |
275 | + | func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum)], SEP) | |
285 | 276 | ||
286 | 277 | ||
287 | - | func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", userNum, lpAssetId], SEP) | |
278 | + | func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastIntV2", toString(userNum), lpAssetId], SEP) | |
288 | 279 | ||
289 | 280 | ||
290 | - | func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", userNum], SEP) | |
281 | + | func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", toString(userNum)], SEP) | |
291 | 282 | ||
292 | 283 | ||
293 | 284 | func keyTotalMaxBoostINTEGRAL () = "%s%s__maxBoostInt__total" | |
294 | 285 | ||
295 | 286 | ||
296 | - | func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", userNum], SEP) | |
287 | + | func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", toString(userNum)], SEP) | |
297 | 288 | ||
298 | 289 | ||
299 | - | func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", userNum], SEP) | |
290 | + | func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", toString(userNum)], SEP) | |
300 | 291 | ||
301 | 292 | ||
302 | - | func keyTotalCachedGwx () = "%s%s__gwxCached__total" | |
303 | - | ||
304 | - | ||
305 | - | func keyTotalCachedGwxCorrective () = "%s__gwxCachedTotalCorrective" | |
293 | + | func keyGwxTotal () = "%s%s__gwx__total" | |
306 | 294 | ||
307 | 295 | ||
308 | 296 | func keyVote (amountAssetId,priceAssetId,address,epoch) = makeString(["%s%s%s%s%d", "vote", amountAssetId, priceAssetId, toString(address), toString(epoch)], SEP) | |
309 | 297 | ||
310 | 298 | ||
311 | 299 | func keyStartHeightByEpoch (epoch) = makeString(["%s%d", "startHeight", toString(epoch)], SEP) | |
312 | 300 | ||
313 | 301 | ||
314 | 302 | func keyCurrentEpochUi () = makeString(["%s", "currentEpochUi"], SEP) | |
315 | 303 | ||
316 | 304 | ||
317 | 305 | func keyVotingResultStaked (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStaked", lpAssetIdStr, toString(epoch)], SEP) | |
318 | 306 | ||
319 | 307 | ||
320 | 308 | func keyVotingResultStakedIntegral (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStakedIntegral", lpAssetIdStr, toString(epoch)], SEP) | |
321 | 309 | ||
322 | 310 | ||
323 | 311 | func keyVotingResultStakedLastUpdateHeight (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStakedIntegralLastUpdateHeight", lpAssetIdStr, toString(epoch)], SEP) | |
324 | 312 | ||
325 | 313 | ||
326 | 314 | func keyVotingResultStakedIntegralLast (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "votingResultStakedIntegralLast", lpAssetIdStr, toString(address), toString(epoch)], SEP) | |
327 | 315 | ||
328 | 316 | ||
329 | 317 | func keyVoteStakedIntegral (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegral", lpAssetIdStr, toString(address), toString(epoch)], SEP) | |
330 | 318 | ||
331 | 319 | ||
332 | 320 | func keyVoteStakedLastUpdateHeight (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegralLastUpdateHeight", lpAssetIdStr, toString(address), toString(epoch)], SEP) | |
333 | 321 | ||
334 | 322 | ||
335 | 323 | func keyVoteStakedIntegralLast (lpAssetIdStr,address,epoch) = makeString(["%s%s%s%d", "voteStakedIntegralLast", lpAssetIdStr, toString(address), toString(epoch)], SEP) | |
336 | 324 | ||
337 | 325 | ||
338 | 326 | func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s", "staked", userAddressStr, lpAssetIdStr], SEP) | |
339 | 327 | ||
340 | 328 | ||
341 | 329 | let factoryContract = readFactoryAddressOrFail() | |
342 | 330 | ||
343 | 331 | let factoryCfg = readFactoryCfgOrFail(factoryContract) | |
344 | 332 | ||
345 | 333 | let emissionContract = getEmissionAddressOrFail(factoryCfg) | |
346 | 334 | ||
347 | 335 | let stakingContract = getStakingAddressOrFail(factoryCfg) | |
348 | 336 | ||
349 | 337 | let gwxRewardContract = getGwxRewardAddressOrFail(factoryCfg) | |
350 | 338 | ||
351 | 339 | 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")) | |
352 | 340 | ||
353 | 341 | let keyVotingEmissionContract = makeString(["%s", "votingEmissionContract"], SEP) | |
354 | 342 | ||
355 | 343 | let votingEmissionContract = addressFromStringValue(getStringValue(factoryContract, keyVotingEmissionContract)) | |
356 | 344 | ||
345 | + | let keyVotingEmissionRateContract = makeString(["%s", "votingEmissionRateContract"], SEP) | |
346 | + | ||
357 | 347 | let boostCoeff = { | |
358 | 348 | let @ = invoke(emissionContract, "getBoostCoeffREADONLY", nil, nil) | |
359 | 349 | if ($isInstanceOf(@, "Int")) | |
360 | 350 | then @ | |
361 | 351 | else throw(($getType(@) + " couldn't be cast to Int")) | |
362 | 352 | } | |
363 | 353 | ||
364 | - | func getTotalCachedGwx (correct) = { | |
365 | - | let currentEpochUi = getIntegerValue(votingEmissionContract, keyCurrentEpochUi()) | |
366 | - | let keyTargetEpoch = makeString(["%s%s", "totalCachedGwxCorrection__activationEpoch"], SEP) | |
367 | - | let targetEpochOption = getInteger(this, keyTargetEpoch) | |
368 | - | let totalCachedGwxRaw = valueOrElse(getInteger(this, keyTotalCachedGwx()), 0) | |
369 | - | let isCorrectionActivated = if (isDefined(targetEpochOption)) | |
370 | - | then (currentEpochUi >= value(targetEpochOption)) | |
371 | - | else false | |
372 | - | let corrective = if (if (isCorrectionActivated) | |
373 | - | then correct | |
374 | - | else false) | |
375 | - | then valueOrElse(getInteger(this, keyTotalCachedGwxCorrective()), 0) | |
376 | - | else 0 | |
377 | - | max([0, (totalCachedGwxRaw + corrective)]) | |
354 | + | func userNumberByAddressOrFail (userAddress) = match getString(this, keyUser2NumMapping(toString(userAddress))) { | |
355 | + | case s: String => | |
356 | + | valueOrErrorMessage(parseInt(s), wrapErr("invalid user number")) | |
357 | + | case _: Unit => | |
358 | + | throwErr("invalid user") | |
359 | + | case _ => | |
360 | + | throw("Match error") | |
361 | + | } | |
362 | + | ||
363 | + | ||
364 | + | func getGwxAmountTotal () = valueOrElse(getInteger(this, keyGwxTotal()), 0) | |
365 | + | ||
366 | + | ||
367 | + | func getLockedGwxAmount (userAddress) = { | |
368 | + | let functionName = "getLockedGwxAmount" | |
369 | + | let votingEmissionRateContract = valueOrErrorMessage( match getString(votingEmissionContract, keyVotingEmissionRateContract) { | |
370 | + | case _: Unit => | |
371 | + | unit | |
372 | + | case s: String => | |
373 | + | addressFromString(s) | |
374 | + | case _ => | |
375 | + | throw("Match error") | |
376 | + | }, wrapErr("invalid voting emission rate address")) | |
377 | + | let lockedVotingEmissionRate = { | |
378 | + | let @ = invoke(votingEmissionContract, functionName, [toString(userAddress)], nil) | |
379 | + | if ($isInstanceOf(@, "Int")) | |
380 | + | then @ | |
381 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
382 | + | } | |
383 | + | let lockedVotingEmission = { | |
384 | + | let @ = invoke(votingEmissionRateContract, functionName, [toString(userAddress)], nil) | |
385 | + | if ($isInstanceOf(@, "Int")) | |
386 | + | then @ | |
387 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
388 | + | } | |
389 | + | let locked = max([lockedVotingEmissionRate, lockedVotingEmission]) | |
390 | + | locked | |
378 | 391 | } | |
379 | 392 | ||
380 | 393 | ||
381 | - | func HistoryEntry (type,user,amount,lockStart,duration, | |
394 | + | func HistoryEntry (type,user,amount,lockStart,duration,gwxAmount,i) = { | |
382 | 395 | let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], SEP) | |
383 | - | let historyDATA = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount), toString(lockStart), toString(duration), toString( | |
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) | |
384 | 397 | StringEntry(historyKEY, historyDATA) | |
385 | 398 | } | |
386 | 399 | ||
387 | 400 | ||
388 | 401 | func StatsEntry (totalLockedInc,durationInc,lockCountInc,usersCountInc) = { | |
389 | 402 | let locksDurationSumInBlocksKEY = keyStatsLocksDurationSumInBlocks() | |
390 | 403 | let locksCountKEY = keyStatsLocksCount() | |
391 | 404 | let usersCountKEY = keyStatsUsersCount() | |
392 | 405 | let totalAmountKEY = keyLockParamTotalAmount() | |
393 | - | let locksDurationSumInBlocks = | |
394 | - | let locksCount = | |
395 | - | let usersCount = | |
396 | - | let totalAmount = | |
406 | + | let locksDurationSumInBlocks = getIntOrZero(this, locksDurationSumInBlocksKEY) | |
407 | + | let locksCount = getIntOrZero(this, locksCountKEY) | |
408 | + | let usersCount = getIntOrZero(this, usersCountKEY) | |
409 | + | let totalAmount = getIntOrZero(this, totalAmountKEY) | |
397 | 410 | [IntegerEntry(locksDurationSumInBlocksKEY, (locksDurationSumInBlocks + durationInc)), IntegerEntry(locksCountKEY, (locksCount + lockCountInc)), IntegerEntry(usersCountKEY, (usersCount + usersCountInc)), IntegerEntry(totalAmountKEY, (totalAmount + totalLockedInc))] | |
398 | 411 | } | |
399 | 412 | ||
400 | 413 | ||
401 | - | func calcGwxAmount (kRaw,bRaw,h) = { | |
402 | - | let SCALE = 1000 | |
403 | - | (((kRaw * h) + bRaw) / SCALE) | |
404 | - | } | |
405 | - | ||
406 | - | ||
407 | - | func LockParamsEntry (userAddress,userNum,amount,start,duration,k,b,period) = { | |
408 | - | let userAmountKEY = keyLockParamUserAmount(userNum) | |
409 | - | let startBlockKEY = keyLockParamStartBlock(userNum) | |
410 | - | let durationKEY = keyLockParamDuration(userNum) | |
411 | - | let kKEY = keyLockParamK(userNum) | |
412 | - | let bKEY = keyLockParamB(userNum) | |
413 | - | let kByPeriodKEY = keyLockParamByPeriodK(userNum, period) | |
414 | - | let bByPeriodKEY = keyLockParamByPeriodB(userNum, period) | |
415 | - | let gwxAmount = calcGwxAmount(k, b, height) | |
416 | - | [IntegerEntry(userAmountKEY, amount), IntegerEntry(startBlockKEY, start), IntegerEntry(durationKEY, duration), IntegerEntry(kKEY, k), IntegerEntry(bKEY, b), IntegerEntry(kByPeriodKEY, k), IntegerEntry(bByPeriodKEY, b), StringEntry(keyLockParamsRecord(userAddress), formatLockParamsRecord(userNum, amount, start, duration, k, b, gwxAmount))] | |
417 | - | } | |
414 | + | func LockParamsEntry (userAddress,txId,amount,start,duration,gwxAmount,wxClaimed) = [StringEntry(keyLockParamsRecord(userAddress, txId), formatLockParamsRecord(amount, start, duration, gwxAmount, wxClaimed))] | |
418 | 415 | ||
419 | 416 | ||
420 | 417 | func extractOptionalPaymentAmountOrFail (i,expectedAssetId) = if ((size(i.payments) > 1)) | |
421 | 418 | then throwErr("only one payment is allowed") | |
422 | 419 | else if ((size(i.payments) == 0)) | |
423 | 420 | then 0 | |
424 | 421 | else { | |
425 | 422 | let pmt = i.payments[0] | |
426 | 423 | if ((value(pmt.assetId) != expectedAssetId)) | |
427 | 424 | then throwErr("invalid asset id in payment") | |
428 | 425 | else pmt.amount | |
429 | 426 | } | |
430 | 427 | ||
431 | 428 | ||
432 | - | func calcUserGwxAmountAtHeight (userAddress,targetHeight) = { | |
433 | - | let EMPTY = "empty" | |
434 | - | let user2NumMappingKEY = keyUser2NumMapping(userAddress) | |
435 | - | let userNum = valueOrElse(getString(user2NumMappingKEY), EMPTY) | |
436 | - | let k = valueOrElse(getInteger(keyLockParamK(userNum)), 0) | |
437 | - | let b = valueOrElse(getInteger(keyLockParamB(userNum)), 0) | |
438 | - | let gwxAmountCalc = calcGwxAmount(k, b, targetHeight) | |
439 | - | let gwxAmount = if ((0 > gwxAmountCalc)) | |
440 | - | then 0 | |
441 | - | else gwxAmountCalc | |
442 | - | gwxAmount | |
443 | - | } | |
444 | - | ||
445 | - | ||
446 | - | func calcCurrentGwxAmount (userAddress) = calcUserGwxAmountAtHeight(userAddress, height) | |
429 | + | func getUserGwxAmountTotal (userAddress) = valueOrElse(getInteger(this, keyUserGwxAmountTotal(userAddress)), 0) | |
447 | 430 | ||
448 | 431 | ||
449 | 432 | func getVotingEmissionEpochInfo () = { | |
450 | - | let $ | |
433 | + | let $t01505615346 = { | |
451 | 434 | let currentEpochUi = value(getInteger(votingEmissionContract, keyCurrentEpochUi())) | |
452 | 435 | let lastFinalizedEpoch = (currentEpochUi - 1) | |
453 | 436 | if ((0 > lastFinalizedEpoch)) | |
454 | 437 | then throwErr("invalid epoch") | |
455 | 438 | else $Tuple2(currentEpochUi, lastFinalizedEpoch) | |
456 | 439 | } | |
457 | - | let currentEpochUi = $ | |
458 | - | let lastFinalizedEpoch = $ | |
440 | + | let currentEpochUi = $t01505615346._1 | |
441 | + | let lastFinalizedEpoch = $t01505615346._2 | |
459 | 442 | let currentEpochStartHeight = value(getInteger(votingEmissionContract, keyStartHeightByEpoch(currentEpochUi))) | |
460 | 443 | $Tuple2(lastFinalizedEpoch, currentEpochStartHeight) | |
461 | 444 | } | |
462 | 445 | ||
463 | 446 | ||
464 | 447 | func getPoolAssetsByLpAssetId (lpAssetIdStr) = { | |
465 | 448 | let idxAmountAssetId = 4 | |
466 | 449 | let idxPriceAssetId = 5 | |
467 | 450 | let poolCfg = { | |
468 | 451 | let @ = invoke(factoryContract, "getPoolConfigByLpAssetIdREADONLY", [lpAssetIdStr], nil) | |
469 | 452 | if ($isInstanceOf(@, "List[Any]")) | |
470 | 453 | then @ | |
471 | 454 | else throw(($getType(@) + " couldn't be cast to List[Any]")) | |
472 | 455 | } | |
473 | 456 | let amountAssetId = { | |
474 | 457 | let @ = poolCfg[idxAmountAssetId] | |
475 | 458 | if ($isInstanceOf(@, "String")) | |
476 | 459 | then @ | |
477 | 460 | else throw(($getType(@) + " couldn't be cast to String")) | |
478 | 461 | } | |
479 | 462 | let priceAssetId = { | |
480 | 463 | let @ = poolCfg[idxPriceAssetId] | |
481 | 464 | if ($isInstanceOf(@, "String")) | |
482 | 465 | then @ | |
483 | 466 | else throw(($getType(@) + " couldn't be cast to String")) | |
484 | 467 | } | |
485 | 468 | $Tuple2(amountAssetId, priceAssetId) | |
486 | 469 | } | |
487 | 470 | ||
488 | 471 | ||
489 | 472 | func getUserVoteFinalized (lpAssetIdStr,userAddressStr) = { | |
490 | 473 | let userAddress = addressFromStringValue(userAddressStr) | |
491 | - | let $ | |
492 | - | let lastFinalizedEpoch = $ | |
493 | - | let currentEpochStartHeight = $ | |
494 | - | let $ | |
495 | - | let amountAssetId = $ | |
496 | - | let priceAssetId = $ | |
474 | + | let $t01603716117 = getVotingEmissionEpochInfo() | |
475 | + | let lastFinalizedEpoch = $t01603716117._1 | |
476 | + | let currentEpochStartHeight = $t01603716117._2 | |
477 | + | let $t01612016195 = getPoolAssetsByLpAssetId(lpAssetIdStr) | |
478 | + | let amountAssetId = $t01612016195._1 | |
479 | + | let priceAssetId = $t01612016195._2 | |
497 | 480 | let userVoteKey = keyVote(amountAssetId, priceAssetId, userAddress, lastFinalizedEpoch) | |
498 | 481 | let userVote = valueOrElse(getInteger(votingEmissionContract, userVoteKey), 0) | |
499 | 482 | userVote | |
500 | 483 | } | |
501 | 484 | ||
502 | 485 | ||
503 | 486 | func getUserVoteStaked (lpAssetIdStr,userAddressStr) = { | |
504 | 487 | let stakedByUser = valueOrElse(getInteger(stakingContract, keyStakedByUser(userAddressStr, lpAssetIdStr)), 0) | |
505 | 488 | let userVote = getUserVoteFinalized(lpAssetIdStr, userAddressStr) | |
506 | 489 | if ((stakedByUser == 0)) | |
507 | 490 | then 0 | |
508 | 491 | else userVote | |
509 | 492 | } | |
510 | 493 | ||
511 | 494 | ||
512 | 495 | func getVotingResultStaked (lpAssetIdStr) = { | |
513 | - | let $ | |
514 | - | let lastFinalizedEpoch = $ | |
515 | - | let currentEpochStartHeight = $ | |
496 | + | let $t01673916819 = getVotingEmissionEpochInfo() | |
497 | + | let lastFinalizedEpoch = $t01673916819._1 | |
498 | + | let currentEpochStartHeight = $t01673916819._2 | |
516 | 499 | let votingResultStakedStart = valueOrElse(getInteger(votingEmissionContract, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), 0) | |
517 | 500 | let votingResultStaked = valueOrElse(getInteger(this, keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch)), votingResultStakedStart) | |
518 | 501 | votingResultStaked | |
519 | 502 | } | |
520 | 503 | ||
521 | 504 | ||
522 | 505 | func getVotingResultStakedIntegral (lpAssetIdStr) = { | |
523 | - | let $ | |
524 | - | let lastFinalizedEpoch = $ | |
525 | - | let currentEpochStartHeight = $ | |
506 | + | let $t01718117261 = getVotingEmissionEpochInfo() | |
507 | + | let lastFinalizedEpoch = $t01718117261._1 | |
508 | + | let currentEpochStartHeight = $t01718117261._2 | |
526 | 509 | let votingResultStaked = getVotingResultStaked(lpAssetIdStr) | |
527 | 510 | let votingResultStakedIntegralPrev = valueOrElse(getInteger(this, keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch)), 0) | |
528 | 511 | let votingResultStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch)), currentEpochStartHeight) | |
529 | 512 | let votingResultStakedIntegralDh = (height - votingResultStakedLastUpdateHeight) | |
530 | 513 | let votingResultStakedIntegral = ((votingResultStakedIntegralDh * votingResultStaked) + votingResultStakedIntegralPrev) | |
531 | 514 | votingResultStakedIntegral | |
532 | 515 | } | |
533 | 516 | ||
534 | 517 | ||
535 | 518 | func refreshVotingResultStakedIntegral (lpAssetIdStr,stakedVoteDelta) = { | |
536 | - | let $ | |
537 | - | let lastFinalizedEpoch = $ | |
538 | - | let currentEpochStartHeight = $ | |
519 | + | let $t01809818178 = getVotingEmissionEpochInfo() | |
520 | + | let lastFinalizedEpoch = $t01809818178._1 | |
521 | + | let currentEpochStartHeight = $t01809818178._2 | |
539 | 522 | let votingResultStaked = getVotingResultStaked(lpAssetIdStr) | |
540 | 523 | let votingResultStakedNew = (votingResultStaked + stakedVoteDelta) | |
541 | 524 | let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr) | |
542 | 525 | [IntegerEntry(keyVotingResultStaked(lpAssetIdStr, lastFinalizedEpoch), votingResultStakedNew), IntegerEntry(keyVotingResultStakedLastUpdateHeight(lpAssetIdStr, lastFinalizedEpoch), height), IntegerEntry(keyVotingResultStakedIntegral(lpAssetIdStr, lastFinalizedEpoch), votingResultStakedIntegral)] | |
543 | 526 | } | |
544 | 527 | ||
545 | 528 | ||
546 | 529 | func getUserVoteStakedIntegral (lpAssetIdStr,userAddressStr) = { | |
547 | - | let $ | |
548 | - | let lastFinalizedEpoch = $ | |
549 | - | let currentEpochStartHeight = $ | |
530 | + | let $t01878918869 = getVotingEmissionEpochInfo() | |
531 | + | let lastFinalizedEpoch = $t01878918869._1 | |
532 | + | let currentEpochStartHeight = $t01878918869._2 | |
550 | 533 | let userAddress = addressFromStringValue(userAddressStr) | |
551 | 534 | let userVoteStaked = getUserVoteStaked(lpAssetIdStr, userAddressStr) | |
552 | 535 | let userVoteStakedIntegralPrev = valueOrElse(getInteger(this, keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch)), 0) | |
553 | 536 | let userVoteStakedLastUpdateHeight = valueOrElse(getInteger(this, keyVoteStakedLastUpdateHeight(lpAssetIdStr, userAddress, lastFinalizedEpoch)), currentEpochStartHeight) | |
554 | 537 | let userVoteStakedIntegralDh = (height - userVoteStakedLastUpdateHeight) | |
555 | 538 | let userVoteStakedIntegral = ((userVoteStakedIntegralDh * userVoteStaked) + userVoteStakedIntegralPrev) | |
556 | 539 | userVoteStakedIntegral | |
557 | 540 | } | |
558 | 541 | ||
559 | 542 | ||
560 | 543 | func refreshVoteStakedIntegral (lpAssetIdStr,userAddressStr,edge) = { | |
561 | - | let $ | |
562 | - | let lastFinalizedEpoch = $ | |
563 | - | let currentEpochStartHeight = $ | |
544 | + | let $t01965719737 = getVotingEmissionEpochInfo() | |
545 | + | let lastFinalizedEpoch = $t01965719737._1 | |
546 | + | let currentEpochStartHeight = $t01965719737._2 | |
564 | 547 | let userAddress = addressFromStringValue(userAddressStr) | |
565 | 548 | let userVoteFinalized = getUserVoteFinalized(lpAssetIdStr, userAddressStr) | |
566 | 549 | let actions = if ((userVoteFinalized == 0)) | |
567 | 550 | then nil | |
568 | 551 | else { | |
569 | 552 | let stakedVoteDelta = if (edge) | |
570 | 553 | then userVoteFinalized | |
571 | 554 | else -(userVoteFinalized) | |
572 | 555 | let votingResultActions = refreshVotingResultStakedIntegral(lpAssetIdStr, stakedVoteDelta) | |
573 | 556 | let userVoteStakedIntegral = getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr) | |
574 | 557 | let voteActions = [IntegerEntry(keyVoteStakedLastUpdateHeight(lpAssetIdStr, userAddress, lastFinalizedEpoch), height), IntegerEntry(keyVoteStakedIntegral(lpAssetIdStr, userAddress, lastFinalizedEpoch), userVoteStakedIntegral)] | |
575 | 558 | (votingResultActions ++ voteActions) | |
576 | 559 | } | |
577 | 560 | actions | |
578 | 561 | } | |
579 | 562 | ||
580 | 563 | ||
581 | 564 | func getStakedVotesIntegralsDiff (lpAssetIdStr,userAddressStr) = { | |
582 | - | let $ | |
583 | - | let lastFinalizedEpoch = $ | |
584 | - | let currentEpochStartHeight = $ | |
565 | + | let $t02059120671 = getVotingEmissionEpochInfo() | |
566 | + | let lastFinalizedEpoch = $t02059120671._1 | |
567 | + | let currentEpochStartHeight = $t02059120671._2 | |
585 | 568 | let userAddress = addressFromStringValue(userAddressStr) | |
586 | 569 | let userVoteStakedIntegralLastKey = keyVoteStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch) | |
587 | 570 | let userVoteStakedIntegralLast = valueOrElse(getInteger(this, userVoteStakedIntegralLastKey), 0) | |
588 | 571 | let votingResultStakedIntegralLastKey = keyVotingResultStakedIntegralLast(lpAssetIdStr, userAddress, lastFinalizedEpoch) | |
589 | 572 | let votingResultStakedIntegralLast = valueOrElse(getInteger(this, votingResultStakedIntegralLastKey), 0) | |
590 | 573 | let userVoteStakedIntegral = getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr) | |
591 | 574 | let votingResultStakedIntegral = getVotingResultStakedIntegral(lpAssetIdStr) | |
592 | 575 | let userVoteStakedIntegralDiff = (userVoteStakedIntegral - userVoteStakedIntegralLast) | |
593 | 576 | let votingResultStakedIntegralDiff = (votingResultStakedIntegral - votingResultStakedIntegralLast) | |
594 | 577 | $Tuple3([IntegerEntry(userVoteStakedIntegralLastKey, userVoteStakedIntegral), IntegerEntry(votingResultStakedIntegralLastKey, votingResultStakedIntegral)], userVoteStakedIntegralDiff, votingResultStakedIntegralDiff) | |
595 | 578 | } | |
596 | 579 | ||
597 | 580 | ||
598 | 581 | func refreshBoostEmissionIntegral () = { | |
599 | - | let wxEmissionPerBlock = | |
582 | + | let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent()) | |
600 | 583 | let boostingV2LastUpdateHeightOption = getInteger(this, keyBoostingV2LastUpdateHeight()) | |
601 | 584 | let boostingV2IngergalOption = getInteger(this, keyBoostingV2Integral()) | |
602 | - | let emissionEnd = | |
585 | + | let emissionEnd = getIntOrFail(emissionContract, keyEmissionEndBlock()) | |
603 | 586 | let h = if ((height > emissionEnd)) | |
604 | 587 | then emissionEnd | |
605 | 588 | else height | |
606 | 589 | let dh = match boostingV2LastUpdateHeightOption { | |
607 | 590 | case lastUpdateHeight: Int => | |
608 | 591 | max([(h - lastUpdateHeight), 0]) | |
609 | 592 | case _: Unit => | |
610 | 593 | 0 | |
611 | 594 | case _ => | |
612 | 595 | throw("Match error") | |
613 | 596 | } | |
614 | 597 | let boostEmissionPerBlock = ((wxEmissionPerBlock * (boostCoeff - 1)) / boostCoeff) | |
615 | 598 | let boostEmissionIntegralPrev = valueOrElse(boostingV2IngergalOption, 0) | |
616 | 599 | let boostEmissionIntegral = ((boostEmissionPerBlock * dh) + boostEmissionIntegralPrev) | |
617 | 600 | $Tuple2([IntegerEntry(keyBoostingV2Integral(), boostEmissionIntegral), IntegerEntry(keyBoostingV2LastUpdateHeight(), height)], boostEmissionIntegral) | |
618 | 601 | } | |
619 | 602 | ||
620 | 603 | ||
621 | 604 | func internalClaimWxBoost (lpAssetIdStr,userAddressStr,readOnly) = { | |
622 | - | let userRecordOption = getString(this, keyLockParamsRecord(userAddressStr)) | |
623 | - | if ((userRecordOption == unit)) | |
624 | - | then $Tuple3(0, nil, "userRecord::is::empty") | |
625 | - | else { | |
626 | - | let userRecordArray = split(value(userRecordOption), SEP) | |
627 | - | let userNumStr = userRecordArray[IdxLockUserNum] | |
605 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
606 | + | let userNum = userNumberByAddressOrFail(userAddress) | |
607 | + | if ((userNum == userNum)) | |
608 | + | then { | |
628 | 609 | let EMPTYSTR = "empty" | |
629 | 610 | let poolWeight = if ((lpAssetIdStr != EMPTYSTR)) | |
630 | 611 | then { | |
631 | 612 | let poolAddressStr = valueOrErrorMessage(getString(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr)), wrapErr(("unsupported lp asset " + lpAssetIdStr))) | |
632 | 613 | getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr)) | |
633 | 614 | } | |
634 | 615 | else if (readOnly) | |
635 | 616 | then 0 | |
636 | 617 | else throwErr(("not readonly mode: unsupported lp asset " + lpAssetIdStr)) | |
637 | - | let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL( | |
638 | - | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL( | |
639 | - | let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), | |
618 | + | let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNum, lpAssetIdStr) | |
619 | + | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum) | |
620 | + | let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), getIntOrZero(this, userBoostEmissionLastIntegralKEY)) | |
640 | 621 | let boostEmissionIntegral = refreshBoostEmissionIntegral()._2 | |
641 | 622 | let userBoostEmissionIntegral = (boostEmissionIntegral - userBoostEmissionLastIntegral) | |
642 | 623 | if ((0 > userBoostEmissionIntegral)) | |
643 | 624 | then throwErr("wrong calculations") | |
644 | 625 | else { | |
645 | - | let $ | |
646 | - | let stakedVotesIntegralsActions = $ | |
647 | - | let userVoteIntegralDiff = $ | |
648 | - | let totalVotesIntegralDiff = $ | |
626 | + | let $t02421324352 = getStakedVotesIntegralsDiff(lpAssetIdStr, userAddressStr) | |
627 | + | let stakedVotesIntegralsActions = $t02421324352._1 | |
628 | + | let userVoteIntegralDiff = $t02421324352._2 | |
629 | + | let totalVotesIntegralDiff = $t02421324352._3 | |
649 | 630 | let poolUserBoostEmissionIntegral = fraction(userBoostEmissionIntegral, poolWeight, POOLWEIGHTMULT) | |
650 | 631 | let userBoostAvaliableToClaimTotalNew = if ((totalVotesIntegralDiff == 0)) | |
651 | 632 | then 0 | |
652 | 633 | else fraction(poolUserBoostEmissionIntegral, userVoteIntegralDiff, totalVotesIntegralDiff) | |
653 | 634 | let dataState = ([IntegerEntry(userLpBoostEmissionLastIntegralKEY, boostEmissionIntegral)] ++ stakedVotesIntegralsActions) | |
654 | 635 | let debug = makeString([toString(userBoostEmissionLastIntegral), toString(userBoostEmissionIntegral), toString(poolWeight), toString(userVoteIntegralDiff), toString(totalVotesIntegralDiff)], ":") | |
655 | 636 | $Tuple3(userBoostAvaliableToClaimTotalNew, dataState, debug) | |
656 | 637 | } | |
657 | 638 | } | |
639 | + | else throw("Strict value is not equal to itself.") | |
658 | 640 | } | |
659 | 641 | ||
660 | 642 | ||
661 | - | func lockActions (i,duration) = { | |
662 | - | let cfgArray = readConfigArrayOrFail() | |
663 | - | let assetIdStr = cfgArray[IdxCfgAssetId] | |
664 | - | let assetId = fromBase58String(assetIdStr) | |
665 | - | let minLockAmount = parseIntValue(cfgArray[IdxCfgMinLockAmount]) | |
666 | - | let minLockDuration = parseIntValue(cfgArray[IdxCfgMinLockDuration]) | |
667 | - | let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration]) | |
643 | + | func lockActions (i,durationMonths) = { | |
644 | + | let duration = (durationMonths * blocksInMonth) | |
645 | + | let assetIdStr = toBase58String(assetId) | |
668 | 646 | if ((size(i.payments) != 1)) | |
669 | 647 | then throwErr("invalid payment - exact one payment must be attached") | |
670 | 648 | else { | |
671 | 649 | let pmt = i.payments[0] | |
672 | 650 | let pmtAmount = pmt.amount | |
673 | 651 | if ((assetId != value(pmt.assetId))) | |
674 | 652 | then throwErr((("invalid asset is in payment - " + assetIdStr) + " is expected")) | |
675 | - | else { | |
676 | - | let nextUserNumKEY = keyNextUserNum() | |
677 | - | let userAddressStr = toString(i.caller) | |
678 | - | let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr))) | |
679 | - | let userNumStr = if (userIsExisting) | |
680 | - | then value(getString(keyUser2NumMapping(userAddressStr))) | |
681 | - | else toString(iof(this, nextUserNumKEY)) | |
682 | - | let userNum = parseIntValue(userNumStr) | |
683 | - | let lockStart = height | |
684 | - | let startBlockKEY = keyLockParamStartBlock(userNumStr) | |
685 | - | let durationKEY = keyLockParamDuration(userNumStr) | |
686 | - | let userAmountKEY = keyLockParamUserAmount(userNumStr) | |
687 | - | if (if ((minLockAmount > pmtAmount)) | |
688 | - | then (i.caller != lpStakingPoolsContract) | |
689 | - | else false) | |
690 | - | then throwErr(("amount is less then minLockAmount=" + toString(minLockAmount))) | |
691 | - | else if ((minLockDuration > duration)) | |
692 | - | then throwErr(("passed duration is less then minLockDuration=" + toString(minLockDuration))) | |
693 | - | else if ((duration > maxLockDuration)) | |
694 | - | then throwErr(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration))) | |
695 | - | else if (if (userIsExisting) | |
696 | - | then ((iof(this, startBlockKEY) + iof(this, durationKEY)) >= lockStart) | |
697 | - | else false) | |
698 | - | then throwErr("there is an active lock - consider to use increaseLock") | |
699 | - | else if ((ioz(this, userAmountKEY) > 0)) | |
700 | - | then throwErr(("there are locked WXs - consider to use increaseLock " + userAmountKEY)) | |
701 | - | else { | |
702 | - | let coeffX8 = fraction(duration, MULT8, maxLockDuration) | |
703 | - | let gWxAmountStart = fraction(pmtAmount, coeffX8, MULT8) | |
704 | - | let gWxParamsResultList = aal(invoke(mathContract, "calcGwxParamsREADONLY", [gWxAmountStart, lockStart, duration], nil)) | |
705 | - | let k = ai(gWxParamsResultList[0]) | |
706 | - | let b = ai(gWxParamsResultList[1]) | |
707 | - | let period = toString(ai(gWxParamsResultList[2])) | |
708 | - | let totalCachedGwxRaw = getTotalCachedGwx(false) | |
709 | - | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr) | |
710 | - | let boostEmissionIntegral = refreshBoostEmissionIntegral()._2 | |
711 | - | let arr = if (userIsExisting) | |
712 | - | then nil | |
713 | - | else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)] | |
714 | - | $Tuple2(((((arr ++ LockParamsEntry(userAddressStr, userNumStr, pmtAmount, lockStart, duration, k, b, period)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting) | |
715 | - | then 0 | |
716 | - | else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, k, b, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyTotalCachedGwx(), (totalCachedGwxRaw + gWxAmountStart))]), gWxAmountStart) | |
717 | - | } | |
718 | - | } | |
653 | + | else if (!(containsElement(durationMonthsAllowed, durationMonths))) | |
654 | + | then throwErr("invalid duration") | |
655 | + | else { | |
656 | + | let nextUserNumKEY = keyNextUserNum() | |
657 | + | let userAddress = i.caller | |
658 | + | let userAddressStr = toString(userAddress) | |
659 | + | let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr))) | |
660 | + | let userNumStr = if (userIsExisting) | |
661 | + | then value(getString(keyUser2NumMapping(userAddressStr))) | |
662 | + | else toString(getIntOrFail(this, nextUserNumKEY)) | |
663 | + | let userNum = parseIntValue(userNumStr) | |
664 | + | let lockStart = height | |
665 | + | if (if ((minLockAmount > pmtAmount)) | |
666 | + | then (userAddress != lpStakingPoolsContract) | |
667 | + | else false) | |
668 | + | then throwErr(("amount is less then minLockAmount=" + toString(minLockAmount))) | |
669 | + | else if ((minLockDuration > duration)) | |
670 | + | then throwErr(("passed duration is less then minLockDuration=" + toString(minLockDuration))) | |
671 | + | else if ((duration > maxLockDuration)) | |
672 | + | then throwErr(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration))) | |
673 | + | else { | |
674 | + | let gWxAmountStart = fraction(pmtAmount, duration, maxLockDuration) | |
675 | + | let gwxAmountTotal = getGwxAmountTotal() | |
676 | + | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNum) | |
677 | + | let boostEmissionIntegral = refreshBoostEmissionIntegral()._2 | |
678 | + | let userGwxAmountTotal = getUserGwxAmountTotal(userAddress) | |
679 | + | let gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes, userNum], nil) | |
680 | + | if ((gwxRewardInv == gwxRewardInv)) | |
681 | + | then { | |
682 | + | let arr = if (userIsExisting) | |
683 | + | then nil | |
684 | + | else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)] | |
685 | + | $Tuple2(((((arr ++ LockParamsEntry(userAddress, i.transactionId, pmtAmount, lockStart, duration, gWxAmountStart, 0)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting) | |
686 | + | then 0 | |
687 | + | else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, gWxAmountStart, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyGwxTotal(), (gwxAmountTotal + gWxAmountStart)), IntegerEntry(keyUserGwxAmountTotal(userAddress), (userGwxAmountTotal + gWxAmountStart))]), gWxAmountStart) | |
688 | + | } | |
689 | + | else throw("Strict value is not equal to itself.") | |
690 | + | } | |
691 | + | } | |
719 | 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 | |
720 | 709 | } | |
721 | 710 | ||
722 | 711 | ||
723 | 712 | @Callable(i) | |
724 | 713 | func constructor (factoryAddressStr,lockAssetIdStr,minLockAmount,minDuration,maxDuration,mathContract) = { | |
725 | 714 | let checkCaller = mustManager(i) | |
726 | 715 | if ((checkCaller == checkCaller)) | |
727 | 716 | then ([IntegerEntry(keyNextUserNum(), 0), StringEntry(keyConfig(), formatConfig(lockAssetIdStr, minLockAmount, minDuration, maxDuration, mathContract)), StringEntry(keyFactoryAddress(), factoryAddressStr)] ++ StatsEntry(0, 0, 0, 0)) | |
728 | 717 | else throw("Strict value is not equal to itself.") | |
729 | 718 | } | |
730 | 719 | ||
731 | 720 | ||
732 | 721 | ||
733 | 722 | @Callable(i) | |
734 | 723 | func lockRef (duration,referrerAddress,signature) = { | |
735 | - | let $ | |
736 | - | let lockActionsResult = $ | |
737 | - | let gWxAmountStart = $ | |
724 | + | let $t02916029225 = lockActions(i, duration) | |
725 | + | let lockActionsResult = $t02916029225._1 | |
726 | + | let gWxAmountStart = $t02916029225._2 | |
738 | 727 | let referralAddress = toString(i.caller) | |
739 | 728 | let refInv = if (if ((referrerAddress == "")) | |
740 | 729 | then true | |
741 | 730 | else (signature == base58'')) | |
742 | 731 | then unit | |
743 | 732 | else invoke(referralsContractAddressOrFail, "createPair", [referralProgramName, referrerAddress, referralAddress, signature], nil) | |
744 | 733 | if ((refInv == refInv)) | |
745 | 734 | then { | |
746 | 735 | let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil) | |
747 | 736 | if ((updateRefActivity == updateRefActivity)) | |
748 | 737 | then $Tuple2(lockActionsResult, unit) | |
749 | 738 | else throw("Strict value is not equal to itself.") | |
750 | 739 | } | |
751 | 740 | else throw("Strict value is not equal to itself.") | |
752 | 741 | } | |
753 | 742 | ||
754 | 743 | ||
755 | 744 | ||
756 | 745 | @Callable(i) | |
757 | 746 | func lock (duration) = { | |
758 | - | let $ | |
759 | - | let lockActionsResult = $ | |
760 | - | let gWxAmountStart = $ | |
747 | + | let $t02968329748 = lockActions(i, duration) | |
748 | + | let lockActionsResult = $t02968329748._1 | |
749 | + | let gWxAmountStart = $t02968329748._2 | |
761 | 750 | let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil) | |
762 | 751 | if ((updateRefActivity == updateRefActivity)) | |
763 | 752 | then $Tuple2(lockActionsResult, unit) | |
764 | 753 | else throw("Strict value is not equal to itself.") | |
765 | 754 | } | |
766 | 755 | ||
767 | 756 | ||
768 | 757 | ||
769 | 758 | @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) | |
821 | 759 | func claimWxBoost (lpAssetIdStr,userAddressStr) = if ((stakingContract != i.caller)) | |
822 | 760 | then throwErr("permissions denied") | |
823 | 761 | else { | |
824 | - | let $ | |
825 | - | let userBoostAvailable = $ | |
826 | - | let dataState = $ | |
827 | - | let debug = $ | |
762 | + | let $t03005830160 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false) | |
763 | + | let userBoostAvailable = $t03005830160._1 | |
764 | + | let dataState = $t03005830160._2 | |
765 | + | let debug = $t03005830160._3 | |
828 | 766 | $Tuple2(dataState, [userBoostAvailable]) | |
829 | 767 | } | |
830 | 768 | ||
831 | 769 | ||
832 | 770 | ||
833 | 771 | @Callable(i) | |
834 | 772 | func claimWxBoostREADONLY (lpAssetIdStr,userAddressStr) = { | |
835 | - | let $ | |
836 | - | let userBoostAvailable = $ | |
837 | - | let dataState = $ | |
838 | - | let debug = $ | |
773 | + | let $t03029230393 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true) | |
774 | + | let userBoostAvailable = $t03029230393._1 | |
775 | + | let dataState = $t03029230393._2 | |
776 | + | let debug = $t03029230393._3 | |
839 | 777 | $Tuple2(nil, [userBoostAvailable, debug]) | |
840 | 778 | } | |
841 | 779 | ||
842 | 780 | ||
843 | 781 | ||
844 | 782 | @Callable(i) | |
845 | - | func unlock (userAddress) = { | |
846 | - | let userRecordArray = readLockParamsRecordOrFail(userAddress) | |
847 | - | let userNumStr = userRecordArray[IdxLockUserNum] | |
783 | + | func unlock (txIdStr) = { | |
784 | + | let userAddress = i.caller | |
785 | + | let userAddressStr = toString(userAddress) | |
786 | + | let txIdOption = if ((txIdStr == "")) | |
787 | + | then unit | |
788 | + | else fromBase58String(txIdStr) | |
789 | + | let userRecordArray = readLockParamsRecordOrFail(userAddress, txIdOption) | |
848 | 790 | let userAmount = parseIntValue(userRecordArray[IdxLockAmount]) | |
849 | 791 | let lockStart = parseIntValue(userRecordArray[IdxLockStart]) | |
850 | 792 | let lockDuration = parseIntValue(userRecordArray[IdxLockDuration]) | |
851 | - | let lockEnd = (lockStart + lockDuration) | |
852 | - | let cfgArray = readConfigArrayOrFail() | |
853 | - | let assetId = fromBase58String(cfgArray[IdxCfgAssetId]) | |
854 | - | if ((lockEnd >= height)) | |
855 | - | then throwErr((("wait " + toString(lockEnd)) + " to unlock")) | |
856 | - | else if ((0 >= userAmount)) | |
857 | - | then throwErr("nothing to unlock") | |
858 | - | else { | |
859 | - | let period = valueOrElse(getInteger(mathContract, keyNextPeriod()), 0) | |
860 | - | (((LockParamsEntry(userAddress, userNumStr, 0, lockStart, lockDuration, 0, 0, toString(period)) ++ StatsEntry(-(userAmount), 0, 0, -1)) :+ HistoryEntry("unlock", userAddress, userAmount, lockStart, lockDuration, 0, 0, i)) :+ ScriptTransfer(addressFromStringValue(userAddress), userAmount, assetId)) | |
861 | - | } | |
793 | + | let wxClaimed = parseIntValue(userRecordArray[IdxLockWxClaimed]) | |
794 | + | let gwxAmount = parseIntValue(userRecordArray[IdxLockGwxAmount]) | |
795 | + | let t = ((height - lockStart) / blocksInPeriod) | |
796 | + | let wxWithdrawable = getWxWithdrawable(userAddress, txIdOption) | |
797 | + | let gWxAmountStart = fraction(userAmount, lockDuration, maxLockDuration) | |
798 | + | let gwxBurned = min([fraction((t * blocksInPeriod), gWxAmountStart, maxLockDuration), gwxAmount]) | |
799 | + | let gwxRemaining = ensurePositive((gwxAmount - gwxBurned), "gwxRemaining") | |
800 | + | let lockedGwxAmount = getLockedGwxAmount(userAddress) | |
801 | + | if ((0 >= userAmount)) | |
802 | + | then throwErr("nothing to unlock") | |
803 | + | else { | |
804 | + | let gwxAmountTotal = getGwxAmountTotal() | |
805 | + | let userGwxAmountTotal = getUserGwxAmountTotal(userAddress) | |
806 | + | let userGwxAmountTotalNew = ensurePositive((userGwxAmountTotal - gwxBurned), "userGwxAmountTotalNew") | |
807 | + | if ((lockedGwxAmount > userGwxAmountTotalNew)) | |
808 | + | then throwErr(("locked gwx amount: " + toString(lockedGwxAmount))) | |
809 | + | else { | |
810 | + | let userNum = parseIntValue(valueOrErrorMessage(getString(keyUser2NumMapping(userAddressStr)), wrapErr("invalid user number"))) | |
811 | + | let gwxRewardInv = reentrantInvoke(gwxRewardContract, "refreshUserReward", [userAddress.bytes, userNum], nil) | |
812 | + | if ((gwxRewardInv == gwxRewardInv)) | |
813 | + | then ((((LockParamsEntry(userAddress, txIdOption, 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)]) | |
814 | + | else throw("Strict value is not equal to itself.") | |
815 | + | } | |
816 | + | } | |
862 | 817 | } | |
863 | 818 | ||
864 | 819 | ||
865 | 820 | ||
866 | 821 | @Callable(i) | |
867 | - | func gwxUserInfoREADONLY (userAddress) = { | |
868 | - | let gwxAmount = calcCurrentGwxAmount(userAddress) | |
822 | + | func gwxUserInfoREADONLY (userAddressStr) = { | |
823 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
824 | + | let gwxAmount = getUserGwxAmountTotal(userAddress) | |
869 | 825 | $Tuple2(nil, [gwxAmount]) | |
870 | 826 | } | |
871 | 827 | ||
872 | 828 | ||
873 | 829 | ||
874 | 830 | @Callable(i) | |
875 | - | func userMaxDurationREADONLY (userAddressStr) = { | |
876 | - | let cfgArray = readConfigArrayOrFail() | |
877 | - | let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration]) | |
878 | - | let userRecordOption = getString(this, keyLockParamsRecord(userAddressStr)) | |
879 | - | if ((userRecordOption == unit)) | |
880 | - | then $Tuple2(nil, $Tuple2("lock", maxLockDuration)) | |
881 | - | else { | |
882 | - | let userRecordArray = split(value(userRecordOption), SEP) | |
883 | - | let lockStart = parseIntValue(userRecordArray[IdxLockStart]) | |
884 | - | let lockDuration = parseIntValue(userRecordArray[IdxLockDuration]) | |
885 | - | let lockEnd = (lockStart + lockDuration) | |
886 | - | let remainingDuration = max([(lockEnd - height), 0]) | |
887 | - | let maxDeltaDuration = (maxLockDuration - remainingDuration) | |
888 | - | $Tuple2(nil, $Tuple2("increaseLock", maxDeltaDuration)) | |
889 | - | } | |
890 | - | } | |
831 | + | func userMaxDurationREADONLY (userAddressStr) = $Tuple2(nil, $Tuple2("lock", maxLockDuration)) | |
891 | 832 | ||
892 | 833 | ||
893 | 834 | ||
894 | 835 | @Callable(i) | |
895 | - | func getUserGwxAmountAtHeightREADONLY (userAddress,targetHeight) = { | |
896 | - | let gwxAmount = calcUserGwxAmountAtHeight(userAddress, targetHeight) | |
836 | + | func getUserGwxAmountAtHeightREADONLY (userAddressStr,targetHeight) = { | |
837 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
838 | + | let gwxAmount = getUserGwxAmountTotal(userAddress) | |
897 | 839 | $Tuple2(nil, gwxAmount) | |
898 | 840 | } | |
899 | 841 | ||
900 | 842 | ||
901 | 843 | ||
902 | 844 | @Callable(i) | |
903 | - | func getTotalCachedGwxREADONLY () = $Tuple2(nil, getTotalCachedGwx(true)) | |
845 | + | func getUserGwxAmount (userAddressStr) = { | |
846 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
847 | + | let gwxAmount = getUserGwxAmountTotal(userAddress) | |
848 | + | $Tuple2(nil, gwxAmount) | |
849 | + | } | |
850 | + | ||
851 | + | ||
852 | + | ||
853 | + | @Callable(i) | |
854 | + | func getGwxTotalREADONLY () = $Tuple2(nil, getGwxAmountTotal()) | |
904 | 855 | ||
905 | 856 | ||
906 | 857 | ||
907 | 858 | @Callable(i) | |
908 | 859 | func onBoostEmissionUpdate () = { | |
909 | 860 | let checkCaller = if ((i.caller == emissionContract)) | |
910 | 861 | then true | |
911 | 862 | else mustManager(i) | |
912 | 863 | if ((checkCaller == checkCaller)) | |
913 | 864 | then refreshBoostEmissionIntegral() | |
914 | 865 | else throw("Strict value is not equal to itself.") | |
915 | 866 | } | |
916 | 867 | ||
917 | 868 | ||
918 | 869 | ||
919 | 870 | @Callable(i) | |
920 | 871 | func onStakedVoteUpdate (lpAssetIdStr,userAddressStr,edge) = { | |
921 | 872 | let checkCaller = if ((i.caller == stakingContract)) | |
922 | 873 | then true | |
923 | 874 | else mustManager(i) | |
924 | 875 | if ((checkCaller == checkCaller)) | |
925 | 876 | then { | |
926 | 877 | let actions = refreshVoteStakedIntegral(lpAssetIdStr, userAddressStr, edge) | |
927 | 878 | $Tuple2(actions, unit) | |
928 | 879 | } | |
929 | 880 | else throw("Strict value is not equal to itself.") | |
930 | 881 | } | |
931 | 882 | ||
932 | 883 | ||
933 | 884 | ||
934 | 885 | @Callable(i) | |
935 | 886 | func getVotingResultStakedREADONLY (lpAssetIdStr) = $Tuple2(nil, getVotingResultStaked(lpAssetIdStr)) | |
936 | 887 | ||
937 | 888 | ||
938 | 889 | ||
939 | 890 | @Callable(i) | |
940 | 891 | func getVotingResultStakedIntegralREADONLY (lpAssetIdStr) = $Tuple2(nil, getVotingResultStakedIntegral(lpAssetIdStr)) | |
941 | 892 | ||
942 | 893 | ||
943 | 894 | ||
944 | 895 | @Callable(i) | |
945 | 896 | func getUserVoteFinalizedREADONLY (lpAssetIdStr,userAddressStr) = $Tuple2(nil, getUserVoteFinalized(lpAssetIdStr, userAddressStr)) | |
946 | 897 | ||
947 | 898 | ||
948 | 899 | ||
949 | 900 | @Callable(i) | |
950 | 901 | func getUserVoteStakedIntegralREADONLY (lpAssetIdStr,userAddressStr) = $Tuple2(nil, getUserVoteStakedIntegral(lpAssetIdStr, userAddressStr)) | |
951 | 902 | ||
952 | 903 | ||
953 | 904 | @Verifier(tx) | |
954 | 905 | func verify () = { | |
955 | 906 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
956 | 907 | case pk: ByteVector => | |
957 | 908 | pk | |
958 | 909 | case _: Unit => | |
959 | 910 | tx.senderPublicKey | |
960 | 911 | case _ => | |
961 | 912 | throw("Match error") | |
962 | 913 | } | |
963 | 914 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
964 | 915 | } | |
965 | 916 |
github/deemru/w8io/026f985 160.57 ms ◑