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 | 12 | | func strf (address,key) = valueOrErrorMessage(getString(address, key), (("mandatory this." + key) + " is not defined")) |
---|
13 | 13 | | |
---|
14 | 14 | | |
---|
15 | 15 | | func ioz (address,key) = valueOrElse(getInteger(address, key), 0) |
---|
16 | 16 | | |
---|
17 | 17 | | |
---|
18 | 18 | | func iod (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal) |
---|
19 | 19 | | |
---|
20 | 20 | | |
---|
21 | 21 | | func iof (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined")) |
---|
22 | 22 | | |
---|
23 | 23 | | |
---|
24 | 24 | | func abs (val) = if ((0 > val)) |
---|
25 | 25 | | then -(val) |
---|
26 | 26 | | else val |
---|
27 | 27 | | |
---|
28 | 28 | | |
---|
29 | 29 | | func aal (val) = match val { |
---|
30 | 30 | | case valAnyLyst: List[Any] => |
---|
31 | 31 | | valAnyLyst |
---|
32 | 32 | | case _ => |
---|
33 | 33 | | throw("fail to cast into List[Any]") |
---|
34 | 34 | | } |
---|
35 | 35 | | |
---|
36 | 36 | | |
---|
37 | 37 | | func ai (val) = match val { |
---|
38 | 38 | | case valInt: Int => |
---|
39 | 39 | | valInt |
---|
40 | 40 | | case _ => |
---|
41 | 41 | | throw("fail to cast into Int") |
---|
42 | 42 | | } |
---|
43 | 43 | | |
---|
44 | 44 | | |
---|
45 | 45 | | func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP) |
---|
46 | 46 | | |
---|
47 | 47 | | |
---|
48 | 48 | | let referralsContractAddressOrFail = addressFromStringValue(strf(this, keyReferralsContractAddress())) |
---|
49 | 49 | | |
---|
50 | 50 | | let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP) |
---|
51 | 51 | | |
---|
52 | 52 | | let referralProgramNameDefault = "wxlock" |
---|
53 | 53 | | |
---|
54 | 54 | | let referralProgramName = valueOrElse(getString(this, keyReferralProgramName), referralProgramNameDefault) |
---|
55 | 55 | | |
---|
56 | 56 | | func keyFactoryAddress () = "%s%s__config__factoryAddress" |
---|
57 | 57 | | |
---|
58 | 58 | | |
---|
59 | 59 | | let IdxFactoryCfgStakingDapp = 1 |
---|
60 | 60 | | |
---|
61 | 61 | | let IdxFactoryCfgBoostingDapp = 2 |
---|
62 | 62 | | |
---|
63 | 63 | | let IdxFactoryCfgIdoDapp = 3 |
---|
64 | 64 | | |
---|
65 | 65 | | let IdxFactoryCfgTeamDapp = 4 |
---|
66 | 66 | | |
---|
67 | 67 | | let IdxFactoryCfgEmissionDapp = 5 |
---|
68 | 68 | | |
---|
69 | 69 | | let IdxFactoryCfgRestDapp = 6 |
---|
70 | 70 | | |
---|
71 | 71 | | let IdxFactoryCfgSlippageDapp = 7 |
---|
72 | 72 | | |
---|
73 | 73 | | let IdxFactoryCfgDaoDapp = 8 |
---|
74 | 74 | | |
---|
75 | 75 | | let IdxFactoryCfgMarketingDapp = 9 |
---|
76 | 76 | | |
---|
77 | 77 | | let IdxFactoryCfgGwxRewardDapp = 10 |
---|
78 | 78 | | |
---|
79 | 79 | | let IdxFactoryCfgBirdsDapp = 11 |
---|
80 | 80 | | |
---|
81 | 81 | | func keyFactoryCfg () = "%s__factoryConfig" |
---|
82 | 82 | | |
---|
83 | 83 | | |
---|
84 | 84 | | func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) |
---|
85 | 85 | | |
---|
86 | 86 | | |
---|
87 | 87 | | func keyFactoryLpList () = "%s__lpTokensList" |
---|
88 | 88 | | |
---|
89 | 89 | | |
---|
90 | 90 | | func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) |
---|
91 | 91 | | |
---|
92 | 92 | | |
---|
93 | 93 | | func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP) |
---|
94 | 94 | | |
---|
95 | 95 | | |
---|
96 | 96 | | func keyFactoryPoolWeightHistory (poolAddress,num) = ((("%s%s__poolWeight__" + poolAddress) + "__") + toString(num)) |
---|
97 | 97 | | |
---|
98 | 98 | | |
---|
99 | 99 | | func readFactoryAddressOrFail () = addressFromStringValue(strf(this, keyFactoryAddress())) |
---|
100 | 100 | | |
---|
101 | 101 | | |
---|
102 | 102 | | func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP) |
---|
103 | 103 | | |
---|
104 | 104 | | |
---|
105 | 105 | | func readFactoryCfgOrFail (factory) = split(strf(factory, keyFactoryCfg()), SEP) |
---|
106 | 106 | | |
---|
107 | 107 | | |
---|
108 | 108 | | func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp]) |
---|
109 | 109 | | |
---|
110 | 110 | | |
---|
111 | 111 | | func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp]) |
---|
112 | 112 | | |
---|
113 | 113 | | |
---|
114 | 114 | | func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp]) |
---|
115 | 115 | | |
---|
116 | 116 | | |
---|
117 | 117 | | func getGwxRewardAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgGwxRewardDapp]) |
---|
118 | 118 | | |
---|
119 | 119 | | |
---|
120 | 120 | | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
121 | 121 | | |
---|
122 | 122 | | |
---|
123 | 123 | | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" |
---|
124 | 124 | | |
---|
125 | 125 | | |
---|
126 | 126 | | func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current" |
---|
127 | 127 | | |
---|
128 | 128 | | |
---|
129 | 129 | | func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current" |
---|
130 | 130 | | |
---|
131 | 131 | | |
---|
132 | 132 | | func keyEmissionStartBlock () = "%s%s__emission__startBlock" |
---|
133 | 133 | | |
---|
134 | 134 | | |
---|
135 | 135 | | func keyEmissionDurationInBlocks () = "%s%s__emission__duration" |
---|
136 | 136 | | |
---|
137 | 137 | | |
---|
138 | 138 | | func keyEmissionEndBlock () = "%s%s__emission__endBlock" |
---|
139 | 139 | | |
---|
140 | 140 | | |
---|
141 | 141 | | func keyNextPeriod () = "%s__nextPeriod" |
---|
142 | 142 | | |
---|
143 | 143 | | |
---|
144 | 144 | | func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight" |
---|
145 | 145 | | |
---|
146 | 146 | | |
---|
147 | 147 | | let IdxCfgAssetId = 1 |
---|
148 | 148 | | |
---|
149 | 149 | | let IdxCfgMinLockAmount = 2 |
---|
150 | 150 | | |
---|
151 | 151 | | let IdxCfgMinLockDuration = 3 |
---|
152 | 152 | | |
---|
153 | 153 | | let IdxCfgMaxLockDuration = 4 |
---|
154 | 154 | | |
---|
155 | 155 | | let IdxCfgMathContract = 5 |
---|
156 | 156 | | |
---|
157 | 157 | | func keyConfig () = "%s__config" |
---|
158 | 158 | | |
---|
159 | 159 | | |
---|
160 | 160 | | func readConfigArrayOrFail () = split(strf(this, keyConfig()), SEP) |
---|
161 | 161 | | |
---|
162 | 162 | | |
---|
163 | 163 | | let mathContract = addressFromStringValue(readConfigArrayOrFail()[IdxCfgMathContract]) |
---|
164 | 164 | | |
---|
165 | 165 | | func formatConfigS (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = makeString(["%s%d%d%d", assetId, minLockAmount, minLockDuration, maxLockDuration, mathContract], SEP) |
---|
166 | 166 | | |
---|
167 | 167 | | |
---|
168 | 168 | | func formatConfig (assetId,minLockAmount,minLockDuration,maxLockDuration,mathContract) = formatConfigS(assetId, toString(minLockAmount), toString(minLockDuration), toString(maxLockDuration), mathContract) |
---|
169 | 169 | | |
---|
170 | 170 | | |
---|
171 | 171 | | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { |
---|
172 | 172 | | case s: String => |
---|
173 | 173 | | fromBase58String(s) |
---|
174 | 174 | | case _: Unit => |
---|
175 | 175 | | unit |
---|
176 | 176 | | case _ => |
---|
177 | 177 | | throw("Match error") |
---|
178 | 178 | | } |
---|
179 | 179 | | |
---|
180 | 180 | | |
---|
181 | 181 | | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { |
---|
182 | 182 | | case s: String => |
---|
183 | 183 | | fromBase58String(s) |
---|
184 | 184 | | case _: Unit => |
---|
185 | 185 | | unit |
---|
186 | 186 | | case _ => |
---|
187 | 187 | | throw("Match error") |
---|
188 | 188 | | } |
---|
189 | 189 | | |
---|
190 | 190 | | |
---|
191 | 191 | | func mustManager (i) = { |
---|
192 | 192 | | let pd = throw("Permission denied") |
---|
193 | 193 | | match managerPublicKeyOrUnit() { |
---|
194 | 194 | | case pk: ByteVector => |
---|
195 | 195 | | if ((i.callerPublicKey == pk)) |
---|
196 | 196 | | then true |
---|
197 | 197 | | else pd |
---|
198 | 198 | | case _: Unit => |
---|
199 | 199 | | if ((i.caller == this)) |
---|
200 | 200 | | then true |
---|
201 | 201 | | else pd |
---|
202 | 202 | | case _ => |
---|
203 | 203 | | throw("Match error") |
---|
204 | 204 | | } |
---|
205 | 205 | | } |
---|
206 | 206 | | |
---|
207 | 207 | | |
---|
208 | 208 | | let IdxLockUserNum = 1 |
---|
209 | 209 | | |
---|
210 | 210 | | let IdxLockAmount = 2 |
---|
211 | 211 | | |
---|
212 | 212 | | let IdxLockStart = 3 |
---|
213 | 213 | | |
---|
214 | 214 | | let IdxLockDuration = 4 |
---|
215 | 215 | | |
---|
216 | 216 | | let IdxLockParamK = 5 |
---|
217 | 217 | | |
---|
218 | 218 | | let IdxLockParamB = 6 |
---|
219 | 219 | | |
---|
220 | 220 | | func keyLockParamsRecord (userAddress) = makeString(["%s%s__lock", userAddress], SEP) |
---|
221 | 221 | | |
---|
222 | 222 | | |
---|
223 | 223 | | func readLockParamsRecordOrFail (userAddress) = split(strf(this, keyLockParamsRecord(userAddress)), SEP) |
---|
224 | 224 | | |
---|
225 | 225 | | |
---|
226 | 226 | | 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) |
---|
227 | 227 | | |
---|
228 | 228 | | |
---|
229 | 229 | | 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)) |
---|
230 | 230 | | |
---|
231 | 231 | | |
---|
232 | 232 | | func keyNextUserNum () = "%s__nextUserNum" |
---|
233 | 233 | | |
---|
234 | 234 | | |
---|
235 | 235 | | func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", userAddress], SEP) |
---|
236 | 236 | | |
---|
237 | 237 | | |
---|
238 | 238 | | func keyNum2UserMapping (num) = makeString(["%s%s%s__mapping__num2user", num], SEP) |
---|
239 | 239 | | |
---|
240 | 240 | | |
---|
241 | 241 | | func keyLockParamUserAmount (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "amount"], SEP) |
---|
242 | 242 | | |
---|
243 | 243 | | |
---|
244 | 244 | | func keyLockParamStartBlock (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "start"], SEP) |
---|
245 | 245 | | |
---|
246 | 246 | | |
---|
247 | 247 | | func keyLockParamDuration (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "duration"], SEP) |
---|
248 | 248 | | |
---|
249 | 249 | | |
---|
250 | 250 | | func keyLockParamK (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "k"], SEP) |
---|
251 | 251 | | |
---|
252 | 252 | | |
---|
253 | 253 | | func keyLockParamB (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "b"], SEP) |
---|
254 | 254 | | |
---|
255 | 255 | | |
---|
256 | 256 | | func keyLockParamByPeriodK (userNum,period) = makeString(["%s%d%s%d__paramByPeriod", userNum, "k", period], SEP) |
---|
257 | 257 | | |
---|
258 | 258 | | |
---|
259 | 259 | | func keyLockParamByPeriodB (userNum,period) = makeString(["%s%d%s%d__paramByPeriod", userNum, "b", period], SEP) |
---|
260 | 260 | | |
---|
261 | 261 | | |
---|
262 | 262 | | func keyLockParamTotalAmount () = "%s%s__stats__activeTotalLocked" |
---|
263 | 263 | | |
---|
264 | 264 | | |
---|
265 | 265 | | func keyStatsLocksDurationSumInBlocks () = "%s%s__stats__locksDurationSumInBlocks" |
---|
266 | 266 | | |
---|
267 | 267 | | |
---|
268 | 268 | | func keyStatsLocksCount () = "%s%s__stats__locksCount" |
---|
269 | 269 | | |
---|
270 | 270 | | |
---|
271 | 271 | | func keyStatsUsersCount () = "%s%s__stats__activeUsersCount" |
---|
272 | 272 | | |
---|
273 | 273 | | |
---|
274 | 274 | | func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastInt", userNum], SEP) |
---|
275 | 275 | | |
---|
276 | 276 | | |
---|
277 | 277 | | func keyUserLpBoostEmissionLastINTEGRAL (userNum,lpAssetId) = makeString(["%s%d__userBoostEmissionLastInt", userNum, lpAssetId], SEP) |
---|
278 | 278 | | |
---|
279 | 279 | | |
---|
280 | 280 | | func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", userNum], SEP) |
---|
281 | 281 | | |
---|
282 | 282 | | |
---|
283 | 283 | | func keyTotalMaxBoostINTEGRAL () = "%s%s__maxBoostInt__total" |
---|
284 | 284 | | |
---|
285 | 285 | | |
---|
286 | 286 | | func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", userNum], SEP) |
---|
287 | 287 | | |
---|
288 | 288 | | |
---|
289 | 289 | | func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", userNum], SEP) |
---|
290 | 290 | | |
---|
291 | 291 | | |
---|
292 | 292 | | func keyTotalCachedGwx () = "%s%s__gwxCached__total" |
---|
293 | 293 | | |
---|
294 | 294 | | |
---|
295 | 295 | | func keyTotalCachedGwxCorrective () = "%s__gwxCachedTotalCorrective" |
---|
296 | 296 | | |
---|
297 | 297 | | |
---|
298 | 298 | | let factoryContract = readFactoryAddressOrFail() |
---|
299 | 299 | | |
---|
300 | 300 | | let factoryCfg = readFactoryCfgOrFail(factoryContract) |
---|
301 | 301 | | |
---|
302 | 302 | | let emissionContract = getEmissionAddressOrFail(factoryCfg) |
---|
303 | 303 | | |
---|
304 | 304 | | let stakingContract = getStakingAddressOrFail(factoryCfg) |
---|
305 | 305 | | |
---|
306 | 306 | | let gwxRewardContract = getGwxRewardAddressOrFail(factoryCfg) |
---|
307 | 307 | | |
---|
308 | 308 | | func getTotalCachedGwx (correct) = { |
---|
309 | 309 | | let keyVotingEmissionContract = makeString(["%s", "votingEmissionContract"], SEP) |
---|
310 | 310 | | let votingEmissionContract = addressFromStringValue(getStringValue(factoryContract, keyVotingEmissionContract)) |
---|
311 | 311 | | let keyCurrentEpochUi = makeString(["%s", "currentEpochUi"], SEP) |
---|
312 | 312 | | let currentEpochUi = getIntegerValue(votingEmissionContract, keyCurrentEpochUi) |
---|
313 | 313 | | let keyTargetEpoch = makeString(["%s%s", "totalCachedGwxCorrection__activationEpoch"], SEP) |
---|
314 | 314 | | let targetEpochOption = getInteger(this, keyTargetEpoch) |
---|
315 | 315 | | let totalCachedGwxRaw = valueOrElse(getInteger(this, keyTotalCachedGwx()), 0) |
---|
316 | 316 | | let isCorrectionActivated = if (isDefined(targetEpochOption)) |
---|
317 | 317 | | then (currentEpochUi >= value(targetEpochOption)) |
---|
318 | 318 | | else false |
---|
319 | 319 | | let corrective = if (if (isCorrectionActivated) |
---|
320 | 320 | | then correct |
---|
321 | 321 | | else false) |
---|
322 | 322 | | then valueOrElse(getInteger(this, keyTotalCachedGwxCorrective()), 0) |
---|
323 | 323 | | else 0 |
---|
324 | 324 | | max([0, (totalCachedGwxRaw + corrective)]) |
---|
325 | 325 | | } |
---|
326 | 326 | | |
---|
327 | 327 | | |
---|
328 | 328 | | func HistoryEntry (type,user,amount,lockStart,duration,k,b,i) = { |
---|
329 | 329 | | let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], SEP) |
---|
330 | 330 | | 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) |
---|
331 | 331 | | StringEntry(historyKEY, historyDATA) |
---|
332 | 332 | | } |
---|
333 | 333 | | |
---|
334 | 334 | | |
---|
335 | 335 | | func StatsEntry (totalLockedInc,durationInc,lockCountInc,usersCountInc) = { |
---|
336 | 336 | | let locksDurationSumInBlocksKEY = keyStatsLocksDurationSumInBlocks() |
---|
337 | 337 | | let locksCountKEY = keyStatsLocksCount() |
---|
338 | 338 | | let usersCountKEY = keyStatsUsersCount() |
---|
339 | 339 | | let totalAmountKEY = keyLockParamTotalAmount() |
---|
340 | 340 | | let locksDurationSumInBlocks = ioz(this, locksDurationSumInBlocksKEY) |
---|
341 | 341 | | let locksCount = ioz(this, locksCountKEY) |
---|
342 | 342 | | let usersCount = ioz(this, usersCountKEY) |
---|
343 | 343 | | let totalAmount = ioz(this, totalAmountKEY) |
---|
344 | 344 | | [IntegerEntry(locksDurationSumInBlocksKEY, (locksDurationSumInBlocks + durationInc)), IntegerEntry(locksCountKEY, (locksCount + lockCountInc)), IntegerEntry(usersCountKEY, (usersCount + usersCountInc)), IntegerEntry(totalAmountKEY, (totalAmount + totalLockedInc))] |
---|
345 | 345 | | } |
---|
346 | 346 | | |
---|
347 | 347 | | |
---|
348 | 348 | | func calcGwxAmount (kRaw,bRaw,h) = { |
---|
349 | 349 | | let SCALE = 1000 |
---|
350 | 350 | | (((kRaw * h) + bRaw) / SCALE) |
---|
351 | 351 | | } |
---|
352 | 352 | | |
---|
353 | 353 | | |
---|
354 | 354 | | func LockParamsEntry (userAddress,userNum,amount,start,duration,k,b,period) = { |
---|
355 | 355 | | let userAmountKEY = keyLockParamUserAmount(userNum) |
---|
356 | 356 | | let startBlockKEY = keyLockParamStartBlock(userNum) |
---|
357 | 357 | | let durationKEY = keyLockParamDuration(userNum) |
---|
358 | 358 | | let kKEY = keyLockParamK(userNum) |
---|
359 | 359 | | let bKEY = keyLockParamB(userNum) |
---|
360 | 360 | | let kByPeriodKEY = keyLockParamByPeriodK(userNum, period) |
---|
361 | 361 | | let bByPeriodKEY = keyLockParamByPeriodB(userNum, period) |
---|
362 | 362 | | let gwxAmount = calcGwxAmount(k, b, height) |
---|
363 | 363 | | [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))] |
---|
364 | 364 | | } |
---|
365 | 365 | | |
---|
366 | 366 | | |
---|
367 | 367 | | func extractOptionalPaymentAmountOrFail (i,expectedAssetId) = if ((size(i.payments) > 1)) |
---|
368 | 368 | | then throw("only one payment is allowed") |
---|
369 | 369 | | else if ((size(i.payments) == 0)) |
---|
370 | 370 | | then 0 |
---|
371 | 371 | | else { |
---|
372 | 372 | | let pmt = i.payments[0] |
---|
373 | 373 | | if ((value(pmt.assetId) != expectedAssetId)) |
---|
374 | 374 | | then throw("invalid asset id in payment") |
---|
375 | 375 | | else pmt.amount |
---|
376 | 376 | | } |
---|
377 | 377 | | |
---|
378 | 378 | | |
---|
379 | 379 | | func calcUserGwxAmountAtHeight (userAddress,targetHeight) = { |
---|
380 | 380 | | let EMPTY = "empty" |
---|
381 | 381 | | let user2NumMappingKEY = keyUser2NumMapping(userAddress) |
---|
382 | 382 | | let userNum = valueOrElse(getString(user2NumMappingKEY), EMPTY) |
---|
383 | 383 | | let k = valueOrElse(getInteger(keyLockParamK(userNum)), 0) |
---|
384 | 384 | | let b = valueOrElse(getInteger(keyLockParamB(userNum)), 0) |
---|
385 | 385 | | let gwxAmountCalc = calcGwxAmount(k, b, targetHeight) |
---|
386 | 386 | | let gwxAmount = if ((0 > gwxAmountCalc)) |
---|
387 | 387 | | then 0 |
---|
388 | 388 | | else gwxAmountCalc |
---|
389 | 389 | | gwxAmount |
---|
390 | 390 | | } |
---|
391 | 391 | | |
---|
392 | 392 | | |
---|
393 | 393 | | func calcCurrentGwxAmount (userAddress) = calcUserGwxAmountAtHeight(userAddress, height) |
---|
394 | 394 | | |
---|
395 | 395 | | |
---|
396 | 396 | | func internalClaimWxBoost (lpAssetIdStr,userAddressStr,readOnly) = { |
---|
397 | 397 | | let EMPTY = "EMPTY" |
---|
398 | 398 | | let userRecordOrEmpty = valueOrElse(getString(this, keyLockParamsRecord(userAddressStr)), EMPTY) |
---|
399 | 399 | | if ((userRecordOrEmpty == EMPTY)) |
---|
400 | 400 | | then $Tuple3(0, nil, "userRecord::is::empty") |
---|
401 | 401 | | else { |
---|
402 | 402 | | let userRecordArray = split(userRecordOrEmpty, SEP) |
---|
403 | 403 | | let userNumStr = userRecordArray[IdxLockUserNum] |
---|
404 | 404 | | let gwxRewardEmissionStartHeight = valueOrElse(getInteger(gwxRewardContract, keyGwxRewardEmissionStartHeight()), 0) |
---|
405 | 405 | | let EMPTYSTR = "empty" |
---|
406 | 406 | | let $t01496515533 = if ((lpAssetIdStr != EMPTYSTR)) |
---|
407 | 407 | | then { |
---|
408 | 408 | | let poolAddressStr = valueOrErrorMessage(getString(factoryContract, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr)) |
---|
409 | 409 | | let pw1 = getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr)) |
---|
410 | 410 | | let pw0 = valueOrElse(getInteger(factoryContract, keyFactoryPoolWeightHistory(poolAddressStr, 0)), pw1) |
---|
411 | 411 | | $Tuple2(pw0, pw1) |
---|
412 | 412 | | } |
---|
413 | 413 | | else if (readOnly) |
---|
414 | 414 | | then $Tuple2(0, 0) |
---|
415 | 415 | | else throw(("not readonly mode: unsupported lp asset " + lpAssetIdStr)) |
---|
416 | 416 | | let poolWeight0 = $t01496515533._1 |
---|
417 | 417 | | let poolWeight1 = $t01496515533._2 |
---|
418 | 418 | | let wxEmissionPerBlock = iof(emissionContract, keyEmissionRatePerBlockCurrent()) |
---|
419 | 419 | | let emissionStart = iof(emissionContract, keyEmissionStartBlock()) |
---|
420 | 420 | | let emissionEnd = iof(emissionContract, keyEmissionEndBlock()) |
---|
421 | 421 | | let h = if ((height > emissionEnd)) |
---|
422 | 422 | | then emissionEnd |
---|
423 | 423 | | else height |
---|
424 | 424 | | let dh = max([(h - emissionStart), 0]) |
---|
425 | 425 | | let userLpBoostEmissionLastIntegralKEY = keyUserLpBoostEmissionLastINTEGRAL(userNumStr, lpAssetIdStr) |
---|
426 | 426 | | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr) |
---|
427 | 427 | | let userBoostEmissionLastIntegral = valueOrElse(getInteger(this, userLpBoostEmissionLastIntegralKEY), ioz(this, userBoostEmissionLastIntegralKEY)) |
---|
428 | 428 | | let boostEmissionIntegral = (((wxEmissionPerBlock * dh) * 2) / 3) |
---|
429 | 429 | | let userBoostEmissionIntegral = (boostEmissionIntegral - userBoostEmissionLastIntegral) |
---|
430 | 430 | | let udh = fraction(userBoostEmissionIntegral, 3, (2 * wxEmissionPerBlock)) |
---|
431 | 431 | | let uLastH = (h - udh) |
---|
432 | 432 | | let udh0 = max([(gwxRewardEmissionStartHeight - uLastH), 0]) |
---|
433 | 433 | | let udh1 = ((h - uLastH) - udh0) |
---|
434 | 434 | | if (if (if ((0 > uLastH)) |
---|
435 | 435 | | then true |
---|
436 | 436 | | else (0 > udh1)) |
---|
437 | 437 | | then true |
---|
438 | 438 | | else (abs(((udh0 + udh1) - udh)) >= 1)) |
---|
439 | 439 | | then throw(((((((("invalid udh calc: udh=" + toString(udh)) + " uLastH=") + toString(uLastH)) + " udh0=") + toString(udh0)) + " udh1=") + toString(udh1))) |
---|
440 | 440 | | else if ((0 > userBoostEmissionIntegral)) |
---|
441 | 441 | | then throw("wrong calculations") |
---|
442 | 442 | | else { |
---|
443 | 443 | | let userMaxBoostIntegralKEY = keyUserMaxBoostINTEGRAL(userNumStr) |
---|
444 | 444 | | let totalMaxBoostIntegralKEY = keyTotalMaxBoostINTEGRAL() |
---|
445 | 445 | | let userMaxBoostInt = ioz(this, userMaxBoostIntegralKEY) |
---|
446 | 446 | | let totalMaxBoostInt = ioz(this, totalMaxBoostIntegralKEY) |
---|
447 | 447 | | let totalCachedGwxCorrected = getTotalCachedGwx(true) |
---|
448 | 448 | | let userCurrGwx = calcCurrentGwxAmount(userAddressStr) |
---|
449 | 449 | | let userBoostAvalaibleToClaimTotalKEY = keyUserBoostAvalaibleToClaimTotal(userNumStr) |
---|
450 | 450 | | let userBoostAvaliableToClaimTotal = ioz(this, userBoostAvalaibleToClaimTotalKEY) |
---|
451 | 451 | | let userBoostEmissionIntegral0 = if ((udh == 0)) |
---|
452 | 452 | | then 0 |
---|
453 | 453 | | else fraction(userBoostEmissionIntegral, udh0, udh) |
---|
454 | 454 | | let userBoostEmissionIntegral1 = if ((udh == 0)) |
---|
455 | 455 | | then 0 |
---|
456 | 456 | | else fraction(userBoostEmissionIntegral, udh1, udh) |
---|
457 | 457 | | let poolUserBoostEmissionIntegral0 = fraction(userBoostEmissionIntegral0, poolWeight0, POOLWEIGHTMULT) |
---|
458 | 458 | | let poolUserBoostEmissionIntegral1 = fraction(userBoostEmissionIntegral1, poolWeight1, POOLWEIGHTMULT) |
---|
459 | 459 | | let userBoostAvaliableToClaimTotalNew0 = if ((totalCachedGwxCorrected == 0)) |
---|
460 | 460 | | then 0 |
---|
461 | 461 | | else fraction(poolUserBoostEmissionIntegral0, userCurrGwx, totalCachedGwxCorrected) |
---|
462 | 462 | | let userBoostAvaliableToClaimTotalNew1 = if ((totalCachedGwxCorrected == 0)) |
---|
463 | 463 | | then 0 |
---|
464 | 464 | | else fraction(poolUserBoostEmissionIntegral1, userCurrGwx, totalCachedGwxCorrected) |
---|
465 | 465 | | let userBoostAvaliableToClaimTotalNew = (userBoostAvaliableToClaimTotalNew0 + userBoostAvaliableToClaimTotalNew1) |
---|
466 | 466 | | let userBoostClaimedKEY = keyUserBoostClaimed(userNumStr) |
---|
467 | 467 | | let userBoostClaimed = ioz(this, userBoostClaimedKEY) |
---|
468 | 468 | | let userBoostAvailable = (userBoostAvaliableToClaimTotalNew - userBoostClaimed) |
---|
469 | 469 | | let dataState = [IntegerEntry(userLpBoostEmissionLastIntegralKEY, boostEmissionIntegral)] |
---|
470 | 470 | | let debug = makeString([toString(userBoostEmissionLastIntegral), toString(userBoostEmissionIntegral), toString(userBoostClaimed), toString(userBoostAvailable), toString(poolWeight0), toString(poolWeight1), toString(h), toString(udh), toString(uLastH), toString(udh0), toString(udh1), toString(userCurrGwx), toString(totalCachedGwxCorrected)], ":") |
---|
471 | 471 | | $Tuple3(userBoostAvaliableToClaimTotalNew, dataState, debug) |
---|
472 | 472 | | } |
---|
473 | 473 | | } |
---|
474 | 474 | | } |
---|
475 | 475 | | |
---|
476 | 476 | | |
---|
477 | 477 | | func lockActions (i,duration) = { |
---|
478 | 478 | | let cfgArray = readConfigArrayOrFail() |
---|
479 | 479 | | let assetIdStr = cfgArray[IdxCfgAssetId] |
---|
480 | 480 | | let assetId = fromBase58String(assetIdStr) |
---|
481 | 481 | | let minLockAmount = parseIntValue(cfgArray[IdxCfgMinLockAmount]) |
---|
482 | 482 | | let minLockDuration = parseIntValue(cfgArray[IdxCfgMinLockDuration]) |
---|
483 | 483 | | let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration]) |
---|
484 | 484 | | if ((size(i.payments) != 1)) |
---|
485 | 485 | | then throw("invalid payment - exact one payment must be attached") |
---|
486 | 486 | | else { |
---|
487 | 487 | | let pmt = i.payments[0] |
---|
488 | 488 | | let pmtAmount = pmt.amount |
---|
489 | 489 | | if ((assetId != value(pmt.assetId))) |
---|
490 | 490 | | then throw((("invalid asset is in payment - " + assetIdStr) + " is expected")) |
---|
491 | 491 | | else { |
---|
492 | 492 | | let nextUserNumKEY = keyNextUserNum() |
---|
493 | 493 | | let userAddressStr = toString(i.caller) |
---|
494 | 494 | | let userIsExisting = isDefined(getString(keyUser2NumMapping(userAddressStr))) |
---|
495 | 495 | | let userNumStr = if (userIsExisting) |
---|
496 | 496 | | then value(getString(keyUser2NumMapping(userAddressStr))) |
---|
497 | 497 | | else toString(iof(this, nextUserNumKEY)) |
---|
498 | 498 | | let userNum = parseIntValue(userNumStr) |
---|
499 | 499 | | let lockStart = height |
---|
500 | 500 | | let startBlockKEY = keyLockParamStartBlock(userNumStr) |
---|
501 | 501 | | let durationKEY = keyLockParamDuration(userNumStr) |
---|
502 | 502 | | let userAmountKEY = keyLockParamUserAmount(userNumStr) |
---|
503 | 503 | | if ((minLockAmount > pmtAmount)) |
---|
504 | 504 | | then throw(("amount is less then minLockAmount=" + toString(minLockAmount))) |
---|
505 | 505 | | else if ((minLockDuration > duration)) |
---|
506 | 506 | | then throw(("passed duration is less then minLockDuration=" + toString(minLockDuration))) |
---|
507 | 507 | | else if ((duration > maxLockDuration)) |
---|
508 | 508 | | then throw(("passed duration is greater then maxLockDuration=" + toString(maxLockDuration))) |
---|
509 | 509 | | else if (if (userIsExisting) |
---|
510 | 510 | | then ((iof(this, startBlockKEY) + iof(this, durationKEY)) >= lockStart) |
---|
511 | 511 | | else false) |
---|
512 | 512 | | then throw("there is an active lock - consider to use increaseLock") |
---|
513 | 513 | | else if ((ioz(this, userAmountKEY) > 0)) |
---|
514 | 514 | | then throw(("there are locked WXs - consider to use increaseLock " + userAmountKEY)) |
---|
515 | 515 | | else { |
---|
516 | 516 | | let coeffX8 = fraction(duration, MULT8, maxLockDuration) |
---|
517 | 517 | | let gWxAmountStart = fraction(pmtAmount, coeffX8, MULT8) |
---|
518 | 518 | | let gWxParamsResultList = aal(invoke(mathContract, "calcGwxParamsREADONLY", [gWxAmountStart, lockStart, duration], nil)) |
---|
519 | 519 | | let k = ai(gWxParamsResultList[0]) |
---|
520 | 520 | | let b = ai(gWxParamsResultList[1]) |
---|
521 | 521 | | let period = toString(ai(gWxParamsResultList[2])) |
---|
522 | 522 | | let wxEmissionPerBlock = iof(emissionContract, keyEmissionRatePerBlockCurrent()) |
---|
523 | 523 | | let emissionStart = iof(emissionContract, keyEmissionStartBlock()) |
---|
524 | 524 | | let emissionEnd = iof(emissionContract, keyEmissionEndBlock()) |
---|
525 | 525 | | let h = if ((height > emissionEnd)) |
---|
526 | 526 | | then emissionEnd |
---|
527 | 527 | | else height |
---|
528 | 528 | | let dh = max([(h - emissionStart), 0]) |
---|
529 | 529 | | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr) |
---|
530 | 530 | | let boostEmissionIntegral = (((wxEmissionPerBlock * dh) * 2) / 3) |
---|
531 | 531 | | let userMaxBoostIntegralKEY = keyUserMaxBoostINTEGRAL(userNumStr) |
---|
532 | 532 | | let totalMaxBoostIntegralKEY = keyTotalMaxBoostINTEGRAL() |
---|
533 | 533 | | let userMaxBoostInt = ((gWxAmountStart * duration) / 2) |
---|
534 | 534 | | let totalMaxBoostInt = ioz(this, totalMaxBoostIntegralKEY) |
---|
535 | 535 | | let totalCachedGwxRaw = getTotalCachedGwx(false) |
---|
536 | 536 | | let arr = if (userIsExisting) |
---|
537 | 537 | | then nil |
---|
538 | 538 | | else [IntegerEntry(nextUserNumKEY, (userNum + 1)), StringEntry(keyUser2NumMapping(userAddressStr), userNumStr), StringEntry(keyNum2UserMapping(userNumStr), userAddressStr)] |
---|
539 | 539 | | $Tuple2(((((arr ++ LockParamsEntry(userAddressStr, userNumStr, pmtAmount, lockStart, duration, k, b, period)) ++ StatsEntry(pmtAmount, duration, 1, if (userIsExisting) |
---|
540 | 540 | | then 0 |
---|
541 | 541 | | else 1)) :+ HistoryEntry("lock", userAddressStr, pmtAmount, lockStart, duration, k, b, i)) ++ [IntegerEntry(userBoostEmissionLastIntegralKEY, boostEmissionIntegral), IntegerEntry(keyTotalCachedGwx(), (totalCachedGwxRaw + gWxAmountStart))]), gWxAmountStart) |
---|
542 | 542 | | } |
---|
543 | 543 | | } |
---|
544 | 544 | | } |
---|
545 | 545 | | } |
---|
546 | 546 | | |
---|
547 | 547 | | |
---|
548 | 548 | | @Callable(i) |
---|
549 | 549 | | func constructor (factoryAddressStr,lockAssetIdStr,minLockAmount,minDuration,maxDuration,mathContract) = { |
---|
550 | 550 | | let checkCaller = mustManager(i) |
---|
551 | 551 | | if ((checkCaller == checkCaller)) |
---|
552 | 552 | | then ([IntegerEntry(keyNextUserNum(), 0), StringEntry(keyConfig(), formatConfig(lockAssetIdStr, minLockAmount, minDuration, maxDuration, mathContract)), StringEntry(keyFactoryAddress(), factoryAddressStr)] ++ StatsEntry(0, 0, 0, 0)) |
---|
553 | 553 | | else throw("Strict value is not equal to itself.") |
---|
554 | 554 | | } |
---|
555 | 555 | | |
---|
556 | 556 | | |
---|
557 | 557 | | |
---|
558 | 558 | | @Callable(i) |
---|
559 | 559 | | func lockRef (duration,referrerAddress,signature) = { |
---|
560 | 560 | | let $t02389223957 = lockActions(i, duration) |
---|
561 | 561 | | let lockActionsResult = $t02389223957._1 |
---|
562 | 562 | | let gWxAmountStart = $t02389223957._2 |
---|
563 | 563 | | let referralAddress = toString(i.caller) |
---|
564 | 564 | | let refInv = if (if ((referrerAddress == "")) |
---|
565 | 565 | | then true |
---|
566 | 566 | | else (signature == base58'')) |
---|
567 | 567 | | then unit |
---|
568 | 568 | | else invoke(referralsContractAddressOrFail, "createPair", [referralProgramName, referrerAddress, referralAddress, signature], nil) |
---|
569 | 569 | | if ((refInv == refInv)) |
---|
570 | 570 | | then { |
---|
571 | 571 | | let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil) |
---|
572 | 572 | | if ((updateRefActivity == updateRefActivity)) |
---|
573 | 573 | | then $Tuple2(lockActionsResult, unit) |
---|
574 | 574 | | else throw("Strict value is not equal to itself.") |
---|
575 | 575 | | } |
---|
576 | 576 | | else throw("Strict value is not equal to itself.") |
---|
577 | 577 | | } |
---|
578 | 578 | | |
---|
579 | 579 | | |
---|
580 | 580 | | |
---|
581 | 581 | | @Callable(i) |
---|
582 | 582 | | func lock (duration) = { |
---|
583 | 583 | | let $t02441524480 = lockActions(i, duration) |
---|
584 | 584 | | let lockActionsResult = $t02441524480._1 |
---|
585 | 585 | | let gWxAmountStart = $t02441524480._2 |
---|
586 | 586 | | let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil) |
---|
587 | 587 | | if ((updateRefActivity == updateRefActivity)) |
---|
588 | 588 | | then $Tuple2(lockActionsResult, unit) |
---|
589 | 589 | | else throw("Strict value is not equal to itself.") |
---|
590 | 590 | | } |
---|
591 | 591 | | |
---|
592 | 592 | | |
---|
593 | 593 | | |
---|
594 | 594 | | @Callable(i) |
---|
595 | 595 | | func increaseLock (deltaDuration) = { |
---|
596 | 596 | | let cfgArray = readConfigArrayOrFail() |
---|
597 | 597 | | let assetIdStr = cfgArray[IdxCfgAssetId] |
---|
598 | 598 | | let assetId = fromBase58String(assetIdStr) |
---|
599 | 599 | | let minLockDuration = parseIntValue(cfgArray[IdxCfgMinLockDuration]) |
---|
600 | 600 | | let maxLockDuration = parseIntValue(cfgArray[IdxCfgMaxLockDuration]) |
---|
601 | 601 | | let pmtAmount = extractOptionalPaymentAmountOrFail(i, assetId) |
---|
602 | 602 | | let userAddressStr = toString(i.caller) |
---|
603 | 603 | | let userRecordArray = readLockParamsRecordOrFail(userAddressStr) |
---|
604 | 604 | | let userNumStr = userRecordArray[IdxLockUserNum] |
---|
605 | 605 | | let userAmount = parseIntValue(userRecordArray[IdxLockAmount]) |
---|
606 | 606 | | let lockStart = parseIntValue(userRecordArray[IdxLockStart]) |
---|
607 | 607 | | let lockDuration = parseIntValue(userRecordArray[IdxLockDuration]) |
---|
608 | 608 | | let lockEnd = (lockStart + lockDuration) |
---|
609 | 609 | | let remainingDuration = max([(lockEnd - height), 0]) |
---|
610 | 610 | | let userAmountNew = (userAmount + pmtAmount) |
---|
611 | 611 | | let lockDurationNew = (remainingDuration + deltaDuration) |
---|
612 | 612 | | if ((0 > deltaDuration)) |
---|
613 | 613 | | then throw("duration is less then zero") |
---|
614 | 614 | | else if ((minLockDuration > lockDurationNew)) |
---|
615 | 615 | | then throw(("lockDurationNew is less then minLockDuration=" + toString(minLockDuration))) |
---|
616 | 616 | | else if ((lockDurationNew > maxLockDuration)) |
---|
617 | 617 | | then throw(("deltaDuration + existedLockDuration is greater then maxLockDuration=" + toString(maxLockDuration))) |
---|
618 | 618 | | else { |
---|
619 | 619 | | let coeffX8 = fraction(lockDurationNew, MULT8, maxLockDuration) |
---|
620 | 620 | | let gWxAmountStart = fraction(userAmountNew, coeffX8, MULT8) |
---|
621 | 621 | | let updateRefActivity = invoke(mathContract, "updateReferralActivity", [toString(i.caller), gWxAmountStart], nil) |
---|
622 | 622 | | if ((updateRefActivity == updateRefActivity)) |
---|
623 | 623 | | then { |
---|
624 | 624 | | let lockStartNew = height |
---|
625 | 625 | | let gWxParamsResultList = aal(invoke(mathContract, "calcGwxParamsREADONLY", [gWxAmountStart, lockStartNew, lockDurationNew], nil)) |
---|
626 | 626 | | let k = ai(gWxParamsResultList[0]) |
---|
627 | 627 | | let b = ai(gWxParamsResultList[1]) |
---|
628 | 628 | | let period = toString(ai(gWxParamsResultList[2])) |
---|
629 | 629 | | let wxEmissionPerBlock = iof(emissionContract, keyEmissionRatePerBlockCurrent()) |
---|
630 | 630 | | let emissionStart = iof(emissionContract, keyEmissionStartBlock()) |
---|
631 | 631 | | let emissionEnd = iof(emissionContract, keyEmissionEndBlock()) |
---|
632 | 632 | | let h = if ((height > emissionEnd)) |
---|
633 | 633 | | then emissionEnd |
---|
634 | 634 | | else height |
---|
635 | 635 | | let dh = max([(h - emissionStart), 0]) |
---|
636 | 636 | | let userBoostEmissionLastIntegralKEY = keyUserBoostEmissionLastINTEGRAL(userNumStr) |
---|
637 | 637 | | let userBoostEmissionLastIntegral = ioz(this, userBoostEmissionLastIntegralKEY) |
---|
638 | 638 | | let boostEmissionIntegral = (((wxEmissionPerBlock * dh) * 2) / 3) |
---|
639 | 639 | | let userBoostEmissionIntegral = (boostEmissionIntegral - userBoostEmissionLastIntegral) |
---|
640 | 640 | | if ((0 > userBoostEmissionIntegral)) |
---|
641 | 641 | | then throw("wrong calculations") |
---|
642 | 642 | | else { |
---|
643 | 643 | | let userMaxBoostIntegralKEY = keyUserMaxBoostINTEGRAL(userNumStr) |
---|
644 | 644 | | let totalMaxBoostIntegralKEY = keyTotalMaxBoostINTEGRAL() |
---|
645 | 645 | | let userMaxBoostInt = ioz(this, userMaxBoostIntegralKEY) |
---|
646 | 646 | | let totalMaxBoostInt = ioz(this, totalMaxBoostIntegralKEY) |
---|
647 | 647 | | let currUserGwx = calcCurrentGwxAmount(userAddressStr) |
---|
648 | 648 | | let gwxDiff = (gWxAmountStart - currUserGwx) |
---|
649 | 649 | | if ((0 > gwxDiff)) |
---|
650 | 650 | | then throw(("gwxDiff is less then 0: " + toString(gwxDiff))) |
---|
651 | 651 | | else { |
---|
652 | 652 | | let totalCachedGwxRaw = getTotalCachedGwx(false) |
---|
653 | 653 | | let totalCachedGwxCorrected = getTotalCachedGwx(true) |
---|
654 | 654 | | let userBoostAvalaibleToClaimTotalKEY = keyUserBoostAvalaibleToClaimTotal(userNumStr) |
---|
655 | 655 | | let userBoostAvaliableToClaimTotal = ioz(this, userBoostAvalaibleToClaimTotalKEY) |
---|
656 | 656 | | let userBoostAvaliableToClaimTotalNew = fraction(userBoostEmissionIntegral, currUserGwx, totalCachedGwxCorrected) |
---|
657 | 657 | | let userMaxBoostIntNew = ((gWxAmountStart * lockDurationNew) / 2) |
---|
658 | 658 | | let remainingUserMaxBoostInt = ((currUserGwx * remainingDuration) / 2) |
---|
659 | 659 | | let userMaxBoostIntDiff = (userMaxBoostIntNew - remainingUserMaxBoostInt) |
---|
660 | 660 | | (((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))]) |
---|
661 | 661 | | } |
---|
662 | 662 | | } |
---|
663 | 663 | | } |
---|
664 | 664 | | else throw("Strict value is not equal to itself.") |
---|
665 | 665 | | } |
---|
666 | 666 | | } |
---|
667 | 667 | | |
---|
668 | 668 | | |
---|
669 | 669 | | |
---|
670 | 670 | | @Callable(i) |
---|
671 | 671 | | func claimWxBoost (lpAssetIdStr,userAddressStr) = if ((stakingContract != i.caller)) |
---|
672 | 672 | | then throw("permissions denied") |
---|
673 | 673 | | else { |
---|
674 | 674 | | let $t02946129563 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false) |
---|
675 | 675 | | let userBoostAvailable = $t02946129563._1 |
---|
676 | 676 | | let dataState = $t02946129563._2 |
---|
677 | 677 | | let debug = $t02946129563._3 |
---|
678 | 678 | | $Tuple2(dataState, [userBoostAvailable]) |
---|
679 | 679 | | } |
---|
680 | 680 | | |
---|
681 | 681 | | |
---|
682 | 682 | | |
---|
683 | 683 | | @Callable(i) |
---|
684 | 684 | | func claimWxBoostREADONLY (lpAssetIdStr,userAddressStr) = { |
---|
685 | 685 | | let $t02969529796 = internalClaimWxBoost(lpAssetIdStr, userAddressStr, true) |
---|
686 | 686 | | let userBoostAvailable = $t02969529796._1 |
---|
687 | 687 | | let dataState = $t02969529796._2 |
---|
688 | 688 | | let debug = $t02969529796._3 |
---|
689 | 689 | | $Tuple2(nil, [userBoostAvailable, debug]) |
---|
690 | 690 | | } |
---|
691 | 691 | | |
---|
692 | 692 | | |
---|
693 | 693 | | |
---|
694 | 694 | | @Callable(i) |
---|
695 | 695 | | func unlock (userAddress) = { |
---|
696 | 696 | | let userRecordArray = readLockParamsRecordOrFail(userAddress) |
---|
697 | 697 | | let userNumStr = userRecordArray[IdxLockUserNum] |
---|
698 | 698 | | let userAmount = parseIntValue(userRecordArray[IdxLockAmount]) |
---|
699 | 699 | | let lockStart = parseIntValue(userRecordArray[IdxLockStart]) |
---|
700 | 700 | | let lockDuration = parseIntValue(userRecordArray[IdxLockDuration]) |
---|
701 | 701 | | let lockEnd = (lockStart + lockDuration) |
---|
702 | 702 | | let cfgArray = readConfigArrayOrFail() |
---|
703 | 703 | | let assetId = fromBase58String(cfgArray[IdxCfgAssetId]) |
---|
704 | 704 | | if ((lockEnd >= height)) |
---|
705 | 705 | | then throw((("wait " + toString(lockEnd)) + " to unlock")) |
---|
706 | 706 | | else if ((0 >= userAmount)) |
---|
707 | 707 | | then throw("nothing to unlock") |
---|
708 | 708 | | else { |
---|
709 | 709 | | let period = valueOrElse(getInteger(mathContract, keyNextPeriod()), 0) |
---|
710 | 710 | | (((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)) |
---|
711 | 711 | | } |
---|
712 | 712 | | } |
---|
713 | 713 | | |
---|
714 | 714 | | |
---|
715 | 715 | | |
---|
716 | 716 | | @Callable(i) |
---|
717 | 717 | | func gwxUserInfoREADONLY (userAddress) = { |
---|
718 | 718 | | let gwxAmount = calcCurrentGwxAmount(userAddress) |
---|
719 | 719 | | $Tuple2(nil, [gwxAmount]) |
---|
720 | 720 | | } |
---|
721 | 721 | | |
---|
722 | 722 | | |
---|
723 | 723 | | |
---|
724 | 724 | | @Callable(i) |
---|