1 | | - | {-# STDLIB_VERSION 6 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let SEP = "__" |
---|
5 | | - | |
---|
6 | | - | let SCALE = 1000 |
---|
7 | | - | |
---|
8 | | - | let MULT8 = 100000000 |
---|
9 | | - | |
---|
10 | | - | let zeroBigInt = toBigInt(0) |
---|
11 | | - | |
---|
12 | | - | let processingStageTotal = 0 |
---|
13 | | - | |
---|
14 | | - | let processingStageShares = 1 |
---|
15 | | - | |
---|
16 | | - | func getNumberByKey (key) = valueOrElse(getInteger(this, key), 0) |
---|
17 | | - | |
---|
18 | | - | |
---|
19 | | - | func getNumberOrFail (key) = valueOrErrorMessage(getInteger(this, key), (("mandatory this." + key) + " is not defined")) |
---|
20 | | - | |
---|
21 | | - | |
---|
22 | | - | func getStringByKey (key) = valueOrElse(getString(this, key), "") |
---|
23 | | - | |
---|
24 | | - | |
---|
25 | | - | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), (("mandatory this." + key) + " is not defined")) |
---|
26 | | - | |
---|
27 | | - | |
---|
28 | | - | func abs (val) = if ((0 > val)) |
---|
29 | | - | then -(val) |
---|
30 | | - | else val |
---|
31 | | - | |
---|
32 | | - | |
---|
33 | | - | func absBigInt (val) = if ((zeroBigInt > val)) |
---|
34 | | - | then -(val) |
---|
35 | | - | else val |
---|
36 | | - | |
---|
37 | | - | |
---|
38 | | - | let keyMaxDepth = "%s__maxDepth" |
---|
39 | | - | |
---|
40 | | - | let maxDepthDefault = 30 |
---|
41 | | - | |
---|
42 | | - | let maxDepth = valueOrElse(getInteger(this, keyMaxDepth), maxDepthDefault) |
---|
43 | | - | |
---|
44 | | - | func keyFactoryAddress () = "%s%s__config__factoryAddress" |
---|
45 | | - | |
---|
46 | | - | |
---|
47 | | - | let factoryAddressStr = getStringOrFail(keyFactoryAddress()) |
---|
48 | | - | |
---|
49 | | - | let factoryContract = addressFromStringValue(factoryAddressStr) |
---|
50 | | - | |
---|
51 | | - | func keyEmissionAddress () = "%s%s__config__emissionAddress" |
---|
52 | | - | |
---|
53 | | - | |
---|
54 | | - | func keyNumToUserMapping (num) = makeString(["%s%s%s", "mapping", "num2user", toString(num)], SEP) |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | let keyReferralProgramName = makeString(["%s%s", "referral", "programName"], SEP) |
---|
58 | | - | |
---|
59 | | - | let referralProgramNameDefault = "wxlock" |
---|
60 | | - | |
---|
61 | | - | let referralProgramName = valueOrElse(getString(this, keyReferralProgramName), referralProgramNameDefault) |
---|
62 | | - | |
---|
63 | | - | let keyReferralMinGWxAmount = makeString(["%s%s", "referral", "minGWxAmount"], SEP) |
---|
64 | | - | |
---|
65 | | - | let referralMinGWxAmountDefault = (500 * MULT8) |
---|
66 | | - | |
---|
67 | | - | let referralMinGWxAmount = valueOrElse(getInteger(this, keyReferralMinGWxAmount), referralMinGWxAmountDefault) |
---|
68 | | - | |
---|
69 | | - | let keyReferrerRewardPermille = makeString(["%s%s", "referral", "referrerRewardPermille"], SEP) |
---|
70 | | - | |
---|
71 | | - | let referrerRewardPermilleDefault = 50 |
---|
72 | | - | |
---|
73 | | - | let referrerRewardPermille = valueOrElse(getInteger(this, keyReferrerRewardPermille), referrerRewardPermilleDefault) |
---|
74 | | - | |
---|
75 | | - | let keyReferralRewardPermille = makeString(["%s%s", "referral", "referralRewardPermille"], SEP) |
---|
76 | | - | |
---|
77 | | - | let referralRewardPermilleDefault = 50 |
---|
78 | | - | |
---|
79 | | - | let referralRewardPermille = valueOrElse(getInteger(this, keyReferralRewardPermille), referralRewardPermilleDefault) |
---|
80 | | - | |
---|
81 | | - | func keyReferrer (referralAddress) = makeString(["%s%s%s", "referrer", referralProgramName, referralAddress], SEP) |
---|
82 | | - | |
---|
83 | | - | |
---|
84 | | - | func keyUnclaimedReferral (programName,claimerAddress) = makeString(["%s%s%s", "unclaimedReferral", programName, claimerAddress], SEP) |
---|
85 | | - | |
---|
86 | | - | |
---|
87 | | - | let emissionAddressStr = getStringOrFail(keyEmissionAddress()) |
---|
88 | | - | |
---|
89 | | - | let emissionContract = addressFromStringValue(emissionAddressStr) |
---|
90 | | - | |
---|
91 | | - | let IdxCfgAssetId = 1 |
---|
92 | | - | |
---|
93 | | - | let IdxCfgPacemakerAddress = 2 |
---|
94 | | - | |
---|
95 | | - | let IdxCfgBoostingContract = 3 |
---|
96 | | - | |
---|
97 | | - | let IdxCfgMaxDepth = 4 |
---|
98 | | - | |
---|
99 | | - | func keyConfig () = "%s__config" |
---|
100 | | - | |
---|
101 | | - | |
---|
102 | | - | func readConfigArrayOrFail () = split(getStringOrFail(keyConfig()), SEP) |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | func formatConfig (wxAssetIdStr,matcherPacemakerAddressStr,boostingContractAddressStr,maxDepth) = makeString(["%s%s%s%d", wxAssetIdStr, matcherPacemakerAddressStr, boostingContractAddressStr, toString(maxDepth)], SEP) |
---|
106 | | - | |
---|
107 | | - | |
---|
108 | | - | func boostingContractOrFail () = { |
---|
109 | | - | let cfgArray = readConfigArrayOrFail() |
---|
110 | | - | valueOrErrorMessage(addressFromString(cfgArray[IdxCfgBoostingContract]), "boosting contract address is not defined") |
---|
111 | | - | } |
---|
112 | | - | |
---|
113 | | - | |
---|
114 | | - | func keyGwxRewardEmissionStartHeight () = "%s%s__gwxRewardEmissionPart__startHeight" |
---|
115 | | - | |
---|
116 | | - | |
---|
117 | | - | func keyUsersCount () = "%s__nextUserNum" |
---|
118 | | - | |
---|
119 | | - | |
---|
120 | | - | func keyRatePerBlockCurrent () = "%s%s__ratePerBlock__current" |
---|
121 | | - | |
---|
122 | | - | |
---|
123 | | - | func keyPoolWeightVirtual () = "%s%s__poolWeight__GWXvirtualPOOL" |
---|
124 | | - | |
---|
125 | | - | |
---|
126 | | - | func keyNextProcessedUser () = "%s__nextProcessedUser" |
---|
127 | | - | |
---|
128 | | - | |
---|
129 | | - | func keyLatestPeriod () = "%s__latestPeriod" |
---|
130 | | - | |
---|
131 | | - | |
---|
132 | | - | func keyNextPeriod () = "%s__nextPeriod" |
---|
133 | | - | |
---|
134 | | - | |
---|
135 | | - | func keyProcessingStage () = "%s__processingStage" |
---|
136 | | - | |
---|
137 | | - | |
---|
138 | | - | func keyNextProcessedPeriod () = "%s__nextProcessedPeriod" |
---|
139 | | - | |
---|
140 | | - | |
---|
141 | | - | func keyUserUnclaimed (userIndex) = makeString(["%s%d", "userUnclaimed", toString(userIndex)], SEP) |
---|
142 | | - | |
---|
143 | | - | |
---|
144 | | - | func keyNextUnlaimedPeriodOfUser (userIndex) = makeString(["%s%d__nextClaimedPeriod", toString(userIndex)], SEP) |
---|
145 | | - | |
---|
146 | | - | |
---|
147 | | - | func keyLastProcessedPeriodOfUser (userIndex) = makeString(["%s%d__lastProcessedPeriod", toString(userIndex)], SEP) |
---|
148 | | - | |
---|
149 | | - | |
---|
150 | | - | func keyHeightForPeriod (period) = makeString(["%s%d__startHeightForPeriod", toString(period)], SEP) |
---|
151 | | - | |
---|
152 | | - | |
---|
153 | | - | func keyAuxEmissionRewardForPeriod (period) = makeString(["%s%d__auxEmissionReward", toString(period)], SEP) |
---|
154 | | - | |
---|
155 | | - | |
---|
156 | | - | func keyTotalAmountForPeriod (period) = makeString(["%s%d__totalAmountForPeriod", toString(period)], SEP) |
---|
157 | | - | |
---|
158 | | - | |
---|
159 | | - | func keyLastPayoutInfo () = "%s__lastPayoutInfo" |
---|
160 | | - | |
---|
161 | | - | |
---|
162 | | - | func PeriodPayoutInfo (period,matcherReward,emissionReward) = makeString(["%d%d%d", toString(period), toString(matcherReward), toString(emissionReward)], SEP) |
---|
163 | | - | |
---|
164 | | - | |
---|
165 | | - | func keyPayoutHistoryInfo (period) = makeString(["%s%s%d__payouts__history", toString(period)], SEP) |
---|
166 | | - | |
---|
167 | | - | |
---|
168 | | - | func keyTotalWeightForPeriod (period) = makeString(["%s%d__totalWeightForPeriod", toString(period)], SEP) |
---|
169 | | - | |
---|
170 | | - | |
---|
171 | | - | func keyUserKValueForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "k", toString(period)], SEP) |
---|
172 | | - | |
---|
173 | | - | |
---|
174 | | - | func keyUserBValueForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "b", toString(period)], SEP) |
---|
175 | | - | |
---|
176 | | - | |
---|
177 | | - | func keyUserWeightForPeriod (period,userIndex) = makeString(["%s%d%s%d__paramByPeriod", toString(userIndex), "weight", toString(period)], SEP) |
---|
178 | | - | |
---|
179 | | - | |
---|
180 | | - | func keyReferralsContractAddress () = makeString(["%s%s", "config", "referralsContractAddress"], SEP) |
---|
181 | | - | |
---|
182 | | - | |
---|
183 | | - | let referralsContractAddressOrFail = addressFromStringValue(getStringOrFail(keyReferralsContractAddress())) |
---|
184 | | - | |
---|
185 | | - | func HistoryEntry (type,user,amount,i) = { |
---|
186 | | - | let historyKEY = makeString(["%s%s%s%s__history", type, user, toBase58String(i.transactionId)], SEP) |
---|
187 | | - | let historyDATA = makeString(["%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(amount)], SEP) |
---|
188 | | - | StringEntry(historyKEY, historyDATA) |
---|
189 | | - | } |
---|
190 | | - | |
---|
191 | | - | |
---|
192 | | - | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
193 | | - | |
---|
194 | | - | |
---|
195 | | - | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" |
---|
196 | | - | |
---|
197 | | - | |
---|
198 | | - | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { |
---|
199 | | - | case s: String => |
---|
200 | | - | fromBase58String(s) |
---|
201 | | - | case _: Unit => |
---|
202 | | - | unit |
---|
203 | | - | case _ => |
---|
204 | | - | throw("Match error") |
---|
205 | | - | } |
---|
206 | | - | |
---|
207 | | - | |
---|
208 | | - | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { |
---|
209 | | - | case s: String => |
---|
210 | | - | fromBase58String(s) |
---|
211 | | - | case _: Unit => |
---|
212 | | - | unit |
---|
213 | | - | case _ => |
---|
214 | | - | throw("Match error") |
---|
215 | | - | } |
---|
216 | | - | |
---|
217 | | - | |
---|
218 | | - | func mustManager (i) = { |
---|
219 | | - | let pd = throw("Permission denied") |
---|
220 | | - | match managerPublicKeyOrUnit() { |
---|
221 | | - | case pk: ByteVector => |
---|
222 | | - | if ((i.callerPublicKey == pk)) |
---|
223 | | - | then true |
---|
224 | | - | else pd |
---|
225 | | - | case _: Unit => |
---|
226 | | - | if ((i.caller == this)) |
---|
227 | | - | then true |
---|
228 | | - | else pd |
---|
229 | | - | case _ => |
---|
230 | | - | throw("Match error") |
---|
231 | | - | } |
---|
232 | | - | } |
---|
233 | | - | |
---|
234 | | - | |
---|
235 | | - | func calcUserWeight (boostingContractAddress,heightForPeriod,period,userIndex) = { |
---|
236 | | - | let kLast = keyLastProcessedPeriodOfUser(userIndex) |
---|
237 | | - | let kKey = keyUserKValueForPeriod(period, userIndex) |
---|
238 | | - | let kRaw = getInteger(boostingContractAddress, kKey) |
---|
239 | | - | let kUserWeight = keyUserWeightForPeriod(period, userIndex) |
---|
240 | | - | if (isDefined(kRaw)) |
---|
241 | | - | then { |
---|
242 | | - | let k = value(kRaw) |
---|
243 | | - | let b = value(getInteger(boostingContractAddress, keyUserBValueForPeriod(period, userIndex))) |
---|
244 | | - | let w = ((k * heightForPeriod) + b) |
---|
245 | | - | if ((w > 0)) |
---|
246 | | - | then $Tuple2((w / SCALE), [IntegerEntry(kLast, period), IntegerEntry(kUserWeight, w)]) |
---|
247 | | - | else $Tuple2(0, nil) |
---|
248 | | - | } |
---|
249 | | - | else { |
---|
250 | | - | let p = getInteger(this, kLast) |
---|
251 | | - | if (if (isDefined(p)) |
---|
252 | | - | then (period >= value(p)) |
---|
253 | | - | else false) |
---|
254 | | - | then { |
---|
255 | | - | let pv = value(p) |
---|
256 | | - | let k = value(getInteger(boostingContractAddress, keyUserKValueForPeriod(pv, userIndex))) |
---|
257 | | - | let b = value(getInteger(boostingContractAddress, keyUserBValueForPeriod(pv, userIndex))) |
---|
258 | | - | let w = ((k * heightForPeriod) + b) |
---|
259 | | - | if ((w > 0)) |
---|
260 | | - | then $Tuple2((w / SCALE), [IntegerEntry(kUserWeight, w)]) |
---|
261 | | - | else $Tuple2(0, nil) |
---|
262 | | - | } |
---|
263 | | - | else $Tuple2(0, nil) |
---|
264 | | - | } |
---|
265 | | - | } |
---|
266 | | - | |
---|
267 | | - | |
---|
268 | | - | func calcUserWeightForClaim (boostingContractAddress,heightForPeriod,period,userIndex) = { |
---|
269 | | - | let kUserWeight = keyUserWeightForPeriod(period, userIndex) |
---|
270 | | - | let userWeightOrUnit = getInteger(kUserWeight) |
---|
271 | | - | match userWeightOrUnit { |
---|
272 | | - | case _: Unit => |
---|
273 | | - | 0 |
---|
274 | | - | case w: Int => |
---|
275 | | - | (w / SCALE) |
---|
276 | | - | case _ => |
---|
277 | | - | throw("Match error") |
---|
278 | | - | } |
---|
279 | | - | } |
---|
280 | | - | |
---|
281 | | - | |
---|
282 | | - | func getUserIndexByAddress (boostingContractAddressStr,userAddress) = { |
---|
283 | | - | let key = makeString(["%s%s%s", "mapping", "user2num", userAddress], SEP) |
---|
284 | | - | parseIntValue(valueOrErrorMessage(getString(Address(fromBase58String(boostingContractAddressStr)), key), ((("User address " + userAddress) + " is not found in boosting contract data, key=") + key))) |
---|
285 | | - | } |
---|
286 | | - | |
---|
287 | | - | |
---|
288 | | - | func nextPeriod () = getNumberByKey(keyNextPeriod()) |
---|
289 | | - | |
---|
290 | | - | |
---|
291 | | - | func commonClaimReward (userAddress) = { |
---|
292 | | - | let cfgArray = readConfigArrayOrFail() |
---|
293 | | - | let userIdx = getUserIndexByAddress(cfgArray[IdxCfgBoostingContract], userAddress) |
---|
294 | | - | let userUnclaimedOption = getInteger(keyUserUnclaimed(userIdx)) |
---|
295 | | - | match userUnclaimedOption { |
---|
296 | | - | case _: Unit => |
---|
297 | | - | $Tuple2(0, nil) |
---|
298 | | - | case u: Int => |
---|
299 | | - | $Tuple2(u, [IntegerEntry(keyUserUnclaimed(userIdx), 0)]) |
---|
300 | | - | case _ => |
---|
301 | | - | throw("Match error") |
---|
302 | | - | } |
---|
303 | | - | } |
---|
304 | | - | |
---|
305 | | - | |
---|
306 | | - | @Callable(i) |
---|
307 | | - | func updateReferralActivity (userAddress,gWxAmountStart) = { |
---|
308 | | - | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) |
---|
309 | | - | let activeReferralInv = if ((referrer == unit)) |
---|
310 | | - | then unit |
---|
311 | | - | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (gWxAmountStart >= referralMinGWxAmount)], nil) |
---|
312 | | - | if ((activeReferralInv == activeReferralInv)) |
---|
313 | | - | then $Tuple2(nil, unit) |
---|
314 | | - | else throw("Strict value is not equal to itself.") |
---|
315 | | - | } |
---|
316 | | - | |
---|
317 | | - | |
---|
318 | | - | |
---|
319 | | - | @Callable(i) |
---|
320 | | - | func finalizeHelper () = { |
---|
321 | | - | let processingStage = valueOrElse(getInteger(keyProcessingStage()), processingStageTotal) |
---|
322 | | - | let currentPeriod = getNumberByKey(keyNextProcessedPeriod()) |
---|
323 | | - | let currentUser = getNumberByKey(keyNextProcessedUser()) |
---|
324 | | - | let latestPeriod = getNumberByKey(keyLatestPeriod()) |
---|
325 | | - | let usersCount = valueOrElse(getInteger(boostingContractOrFail(), keyUsersCount()), 0) |
---|
326 | | - | let totalWeightKey = keyTotalWeightForPeriod(currentPeriod) |
---|
327 | | - | let totalWeight = getNumberByKey(keyTotalWeightForPeriod(currentPeriod)) |
---|
328 | | - | let heightForPeriod = getNumberByKey(keyHeightForPeriod(currentPeriod)) |
---|
329 | | - | if ((currentPeriod > latestPeriod)) |
---|
330 | | - | then $Tuple2(nil, false) |
---|
331 | | - | else if ((processingStage == processingStageTotal)) |
---|
332 | | - | then { |
---|
333 | | - | let $t01238212498 = calcUserWeight(boostingContractOrFail(), heightForPeriod, currentPeriod, currentUser) |
---|
334 | | - | let userWeight = $t01238212498._1 |
---|
335 | | - | let userActions = $t01238212498._2 |
---|
336 | | - | let totalWeightNew = (totalWeight + userWeight) |
---|
337 | | - | let processingActions = if (((usersCount - 1) > currentUser)) |
---|
338 | | - | then [IntegerEntry(keyNextProcessedUser(), (currentUser + 1))] |
---|
339 | | - | else [IntegerEntry(keyProcessingStage(), processingStageShares), IntegerEntry(keyNextProcessedUser(), 0)] |
---|
340 | | - | $Tuple2((([IntegerEntry(totalWeightKey, totalWeightNew)] ++ processingActions) ++ userActions), true) |
---|
341 | | - | } |
---|
342 | | - | else if ((processingStage == processingStageShares)) |
---|
343 | | - | then { |
---|
344 | | - | let userWeight = calcUserWeightForClaim(boostingContractOrFail(), heightForPeriod, currentPeriod, currentUser) |
---|
345 | | - | let userAmountMatcherForPeriod = fraction(getNumberByKey(keyTotalAmountForPeriod(currentPeriod)), userWeight, totalWeight) |
---|
346 | | - | let userAmountEmissionForPeriod = fraction(getNumberByKey(keyAuxEmissionRewardForPeriod(currentPeriod)), userWeight, totalWeight) |
---|
347 | | - | let userTotalAmount = (userAmountEmissionForPeriod + userAmountMatcherForPeriod) |
---|
348 | | - | let userUnclaimedOption = getInteger(keyUserUnclaimed(currentUser)) |
---|
349 | | - | let userAddress = getStringValue(boostingContractOrFail(), keyNumToUserMapping(currentUser)) |
---|
350 | | - | let referrer = getString(referralsContractAddressOrFail, keyReferrer(userAddress)) |
---|
351 | | - | let activeReferralInv = if ((referrer == unit)) |
---|
352 | | - | then unit |
---|
353 | | - | else invoke(referralsContractAddressOrFail, "updateReferralActivity", [referralProgramName, userAddress, (userWeight >= referralMinGWxAmount)], nil) |
---|
354 | | - | if ((activeReferralInv == activeReferralInv)) |
---|
355 | | - | then { |
---|
356 | | - | let referralInv = if (if ((referrer == unit)) |
---|
357 | | - | then true |
---|
358 | | - | else (referralMinGWxAmount > userWeight)) |
---|
359 | | - | then unit |
---|
360 | | - | else { |
---|
361 | | - | let referrerReward = fraction(userTotalAmount, referrerRewardPermille, SCALE) |
---|
362 | | - | let referralReward = fraction(userTotalAmount, referralRewardPermille, SCALE) |
---|
363 | | - | invoke(referralsContractAddressOrFail, "incUnclaimed", [referralProgramName, userAddress, referrerReward, referralReward], nil) |
---|
364 | | - | } |
---|
365 | | - | if ((referralInv == referralInv)) |
---|
366 | | - | then { |
---|
367 | | - | let unclaimedActions = [IntegerEntry(keyUserUnclaimed(currentUser), (valueOrElse(userUnclaimedOption, 0) + userTotalAmount))] |
---|
368 | | - | let processingActions = if (((usersCount - 1) > currentUser)) |
---|
369 | | - | then [IntegerEntry(keyNextProcessedUser(), (currentUser + 1))] |
---|
370 | | - | else [IntegerEntry(keyNextProcessedPeriod(), (currentPeriod + 1)), IntegerEntry(keyNextProcessedUser(), 0), DeleteEntry(keyProcessingStage())] |
---|
371 | | - | $Tuple2((unclaimedActions ++ processingActions), true) |
---|
372 | | - | } |
---|
373 | | - | else throw("Strict value is not equal to itself.") |
---|
374 | | - | } |
---|
375 | | - | else throw("Strict value is not equal to itself.") |
---|
376 | | - | } |
---|
377 | | - | else throw("invalid processing stage") |
---|
378 | | - | } |
---|
379 | | - | |
---|
380 | | - | |
---|
381 | | - | |
---|
382 | | - | @Callable(i) |
---|
383 | | - | func finalizeWrapper (counter) = { |
---|
384 | | - | let result = { |
---|
385 | | - | let @ = invoke(this, "finalizeHelper", nil, nil) |
---|
386 | | - | if ($isInstanceOf(@, "Boolean")) |
---|
387 | | - | then @ |
---|
388 | | - | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
389 | | - | } |
---|
390 | | - | if ((result == result)) |
---|
391 | | - | then if (!(result)) |
---|
392 | | - | then if ((counter == maxDepth)) |
---|
393 | | - | then throw("Nothing to process") |
---|
394 | | - | else $Tuple2(nil, unit) |
---|
395 | | - | else if ((counter > 0)) |
---|
396 | | - | then $Tuple2(nil, invoke(this, "finalizeWrapper", [(counter - 1)], nil)) |
---|
397 | | - | else $Tuple2(nil, unit) |
---|
398 | | - | else throw("Strict value is not equal to itself.") |
---|
399 | | - | } |
---|
400 | | - | |
---|
401 | | - | |
---|
402 | | - | |
---|
403 | | - | @Callable(i) |
---|
404 | | - | func processPendingPeriodsAndUsers () = $Tuple2(nil, invoke(this, "finalizeWrapper", [maxDepth], nil)) |
---|
405 | | - | |
---|
406 | | - | |
---|
407 | | - | |
---|
408 | | - | @Callable(i) |
---|
409 | | - | func deposit () = { |
---|
410 | | - | let cfgArray = readConfigArrayOrFail() |
---|
411 | | - | if ((i.caller != Address(fromBase58String(cfgArray[IdxCfgPacemakerAddress])))) |
---|
412 | | - | then throw("Wrong caller address") |
---|
413 | | - | else { |
---|
414 | | - | let assetId = value(value(i.payments[0]).assetId) |
---|
415 | | - | if ((assetId != fromBase58String(cfgArray[IdxCfgAssetId]))) |
---|
416 | | - | then throw("Wrong payment asset") |
---|
417 | | - | else { |
---|
418 | | - | let period = nextPeriod() |
---|
419 | | - | let deltaH = (height - getNumberOrFail(keyGwxRewardEmissionStartHeight())) |
---|
420 | | - | let emissionRate = valueOrErrorMessage(getInteger(emissionContract, keyRatePerBlockCurrent()), (("mandatory emission_contract." + keyRatePerBlockCurrent()) + " is not defined")) |
---|
421 | | - | let weight = valueOrErrorMessage(getInteger(factoryContract, keyPoolWeightVirtual()), (("mandatory factory_contract." + keyPoolWeightVirtual()) + " is not defined")) |
---|
422 | | - | let auxAmount = fraction((deltaH * weight), emissionRate, MULT8) |
---|
423 | | - | let em = invoke(emissionContract, "emit", [auxAmount], nil) |
---|
424 | | - | if ((em == em)) |
---|
425 | | - | then { |
---|
426 | | - | let matcherPart = value(i.payments[0]).amount |
---|
427 | | - | let payoutInfo = PeriodPayoutInfo(period, matcherPart, auxAmount) |
---|
428 | | - | [IntegerEntry(keyLatestPeriod(), period), IntegerEntry(keyHeightForPeriod(period), height), IntegerEntry(keyAuxEmissionRewardForPeriod(period), auxAmount), IntegerEntry(keyGwxRewardEmissionStartHeight(), height), IntegerEntry(keyTotalAmountForPeriod(period), matcherPart), IntegerEntry(keyNextPeriod(), (period + 1)), StringEntry(keyLastPayoutInfo(), payoutInfo), StringEntry(keyPayoutHistoryInfo(period), payoutInfo)] |
---|
429 | | - | } |
---|
430 | | - | else throw("Strict value is not equal to itself.") |
---|
431 | | - | } |
---|
432 | | - | } |
---|
433 | | - | } |
---|
434 | | - | |
---|
435 | | - | |
---|
436 | | - | |
---|
437 | | - | @Callable(i) |
---|
438 | | - | func claimReward () = { |
---|
439 | | - | let cfgArray = readConfigArrayOrFail() |
---|
440 | | - | let address = toString(i.caller) |
---|
441 | | - | let $t01795118001 = commonClaimReward(address) |
---|
442 | | - | let amount = $t01795118001._1 |
---|
443 | | - | let actions = $t01795118001._2 |
---|
444 | | - | let checkAmount = if ((amount > 0)) |
---|
445 | | - | then true |
---|
446 | | - | else throw("Nothing to claim") |
---|
447 | | - | if ((checkAmount == checkAmount)) |
---|
448 | | - | then { |
---|
449 | | - | let amountFromEmission = 0 |
---|
450 | | - | let claimedReferral = { |
---|
451 | | - | let @ = invoke(referralsContractAddressOrFail, "claim", [referralProgramName], nil) |
---|
452 | | - | if ($isInstanceOf(@, "Int")) |
---|
453 | | - | then @ |
---|
454 | | - | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
455 | | - | } |
---|
456 | | - | let totalAmount = (amount + claimedReferral) |
---|
457 | | - | $Tuple2(([ScriptTransfer(i.caller, totalAmount, fromBase58String(cfgArray[IdxCfgAssetId])), HistoryEntry("claim", address, amount, i)] ++ actions), [totalAmount, amountFromEmission]) |
---|
458 | | - | } |
---|
459 | | - | else throw("Strict value is not equal to itself.") |
---|
460 | | - | } |
---|
461 | | - | |
---|
462 | | - | |
---|
463 | | - | |
---|
464 | | - | @Callable(i) |
---|
465 | | - | func claimRewardREADONLY (address) = { |
---|
466 | | - | let $t01858918639 = commonClaimReward(address) |
---|
467 | | - | let amount = $t01858918639._1 |
---|
468 | | - | let actions = $t01858918639._2 |
---|
469 | | - | let referralUnclaimed = valueOrElse(getInteger(referralsContractAddressOrFail, keyUnclaimedReferral(referralProgramName, address)), 0) |
---|
470 | | - | let totalAmount = (amount + referralUnclaimed) |
---|
471 | | - | $Tuple2(nil, totalAmount) |
---|
472 | | - | } |
---|
473 | | - | |
---|
474 | | - | |
---|
475 | | - | |
---|
476 | | - | @Callable(i) |
---|
477 | | - | func latestFinalizedPeriodREADONLY (address) = $Tuple2(nil, valueOrElse(getInteger(this, keyLatestPeriod()), -1)) |
---|
478 | | - | |
---|
479 | | - | |
---|
480 | | - | |
---|
481 | | - | @Callable(i) |
---|
482 | | - | func latestFinalizedPeriodInfoREADONLY (address) = $Tuple2(nil, getStringByKey(keyLastPayoutInfo())) |
---|
483 | | - | |
---|
484 | | - | |
---|
485 | | - | |
---|
486 | | - | @Callable(i) |
---|
487 | | - | func calcGwxParamsREADONLY (gwxAmountStart,lockStartHeight,lockDurationBlocks) = { |
---|
488 | | - | let lockEndHeight = (lockStartHeight + lockDurationBlocks) |
---|
489 | | - | let scale8ParamK = -(fraction(gwxAmountStart, SCALE, lockDurationBlocks)) |
---|
490 | | - | let scale8ParamB = (fraction(gwxAmountStart, SCALE, lockDurationBlocks) * lockEndHeight) |
---|
491 | | - | $Tuple2(nil, [scale8ParamK, scale8ParamB, nextPeriod()]) |
---|
492 | | - | } |
---|
493 | | - | |
---|
494 | | - | |
---|
495 | | - | |
---|
496 | | - | @Callable(i) |
---|
497 | | - | func calcGwxAmountStartREADONLY (wxLockAmount,lockDuration,maxLockDuration) = { |
---|
498 | | - | let coeffX8 = fraction(lockDuration, MULT8, maxLockDuration) |
---|
499 | | - | let gWxAmountStart = fraction(wxLockAmount, coeffX8, MULT8) |
---|
500 | | - | $Tuple2(nil, [gWxAmountStart]) |
---|
501 | | - | } |
---|
502 | | - | |
---|
503 | | - | |
---|
504 | | - | |
---|
505 | | - | @Callable(i) |
---|
506 | | - | func onEmissionForGwxStart () = if ((i.caller != factoryContract)) |
---|
507 | | - | then throw("permissions denied") |
---|
508 | | - | else [IntegerEntry(keyGwxRewardEmissionStartHeight(), height)] |
---|
509 | | - | |
---|
510 | | - | |
---|
511 | | - | |
---|
512 | | - | @Callable(i) |
---|
513 | | - | func latestPeriodEmissionRewardsREADONLY (address) = { |
---|
514 | | - | let period = nextPeriod() |
---|
515 | | - | $Tuple2(nil, [getNumberByKey(keyAuxEmissionRewardForPeriod(period))]) |
---|
516 | | - | } |
---|
517 | | - | |
---|
518 | | - | |
---|
519 | | - | |
---|
520 | | - | @Callable(i) |
---|
521 | | - | func calcD (x1BigIntStr,x2BigIntStr,ampBigIntStr,aPrecisionBigIntStr,targetPrecisionBigIntStr) = { |
---|
522 | | - | let nCoins = toBigInt(2) |
---|
523 | | - | let aPrecision = parseBigIntValue(aPrecisionBigIntStr) |
---|
524 | | - | let targetPrecision = parseBigIntValue(targetPrecisionBigIntStr) |
---|
525 | | - | let x1 = parseBigIntValue(x1BigIntStr) |
---|
526 | | - | let x2 = parseBigIntValue(x2BigIntStr) |
---|
527 | | - | let amp = (parseBigIntValue(ampBigIntStr) * aPrecision) |
---|
528 | | - | let s = (x1 + x2) |
---|
529 | | - | if ((s == zeroBigInt)) |
---|
530 | | - | then $Tuple2(nil, toString(zeroBigInt)) |
---|
531 | | - | else { |
---|
532 | | - | let ann = (amp * nCoins) |
---|
533 | | - | let arr = [0, 1, 2, 3, 4, 5, 6] |
---|
534 | | - | func calc (acc,cur) = { |
---|
535 | | - | let $t02135121378 = acc |
---|
536 | | - | let d = $t02135121378._1 |
---|
537 | | - | let dPrev = $t02135121378._2 |
---|
538 | | - | let found = $t02135121378._3 |
---|
539 | | - | if ((found != unit)) |
---|
540 | | - | then acc |
---|
541 | | - | else { |
---|
542 | | - | let dp = (((d * d) * d) / (((x1 * x2) * nCoins) * nCoins)) |
---|
543 | | - | let dNext = (((((ann * s) / aPrecision) + (dp * nCoins)) * d) / ((((ann - aPrecision) * d) / aPrecision) + ((nCoins + toBigInt(1)) * dp))) |
---|
544 | | - | let dDiff = absBigInt((dNext - value(d))) |
---|
545 | | - | if ((targetPrecision >= dDiff)) |
---|
546 | | - | then $Tuple3(dNext, d, cur) |
---|
547 | | - | else $Tuple3(dNext, d, unit) |
---|
548 | | - | } |
---|
549 | | - | } |
---|
550 | | - | |
---|
551 | | - | let $t02199122054 = { |
---|
552 | | - | let $l = arr |
---|
553 | | - | let $s = size($l) |
---|
554 | | - | let $acc0 = $Tuple3(s, unit, unit) |
---|
555 | | - | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
556 | | - | then $a |
---|
557 | | - | else calc($a, $l[$i]) |
---|
558 | | - | |
---|
559 | | - | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
560 | | - | then $a |
---|
561 | | - | else throw("List size exceeds 7") |
---|
562 | | - | |
---|
563 | | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7) |
---|
564 | | - | } |
---|
565 | | - | let dNext = $t02199122054._1 |
---|
566 | | - | let dPrev = $t02199122054._2 |
---|
567 | | - | let found = $t02199122054._3 |
---|
568 | | - | if ((found != unit)) |
---|
569 | | - | then $Tuple2(nil, toString(dNext)) |
---|
570 | | - | else { |
---|
571 | | - | let dDiff = absBigInt((dNext - value(dPrev))) |
---|
572 | | - | throw(("D calculation error, dDiff = " + toString(dDiff))) |
---|
573 | | - | } |
---|
574 | | - | } |
---|
575 | | - | } |
---|
576 | | - | |
---|
577 | | - | |
---|
578 | | - | |
---|
579 | | - | @Callable(i) |
---|
580 | | - | func setManager (pendingManagerPublicKey) = { |
---|
581 | | - | let checkCaller = mustManager(i) |
---|
582 | | - | if ((checkCaller == checkCaller)) |
---|
583 | | - | then { |
---|
584 | | - | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) |
---|
585 | | - | if ((checkManagerPublicKey == checkManagerPublicKey)) |
---|
586 | | - | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] |
---|
587 | | - | else throw("Strict value is not equal to itself.") |
---|
588 | | - | } |
---|
589 | | - | else throw("Strict value is not equal to itself.") |
---|
590 | | - | } |
---|
591 | | - | |
---|
592 | | - | |
---|
593 | | - | |
---|
594 | | - | @Callable(i) |
---|
595 | | - | func confirmManager () = { |
---|
596 | | - | let pm = pendingManagerPublicKeyOrUnit() |
---|
597 | | - | let hasPM = if (isDefined(pm)) |
---|
598 | | - | then true |
---|
599 | | - | else throw("No pending manager") |
---|
600 | | - | if ((hasPM == hasPM)) |
---|
601 | | - | then { |
---|
602 | | - | let checkPM = if ((i.callerPublicKey == value(pm))) |
---|
603 | | - | then true |
---|
604 | | - | else throw("You are not pending manager") |
---|
605 | | - | if ((checkPM == checkPM)) |
---|
606 | | - | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] |
---|
607 | | - | else throw("Strict value is not equal to itself.") |
---|
608 | | - | } |
---|
609 | | - | else throw("Strict value is not equal to itself.") |
---|
610 | | - | } |
---|
611 | | - | |
---|
612 | | - | |
---|
613 | | - | @Verifier(tx) |
---|
614 | | - | func verify () = { |
---|
615 | | - | let targetPublicKey = match managerPublicKeyOrUnit() { |
---|
616 | | - | case pk: ByteVector => |
---|
617 | | - | pk |
---|
618 | | - | case _: Unit => |
---|
619 | | - | tx.senderPublicKey |
---|
620 | | - | case _ => |
---|
621 | | - | throw("Match error") |
---|
622 | | - | } |
---|
623 | | - | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
624 | | - | } |
---|
625 | | - | |
---|
| 1 | + | # no script |
---|