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