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