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