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