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