1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let SCALE8 = 8 |
---|
5 | 5 | | |
---|
6 | 6 | | let MULT8 = 100000000 |
---|
7 | 7 | | |
---|
8 | 8 | | let SCALE18 = 18 |
---|
9 | 9 | | |
---|
10 | 10 | | let MULT18 = toBigInt(1000000000000000000) |
---|
11 | 11 | | |
---|
12 | 12 | | let SEP = "__" |
---|
13 | 13 | | |
---|
14 | 14 | | let POOLWEIGHTMULT = MULT8 |
---|
15 | 15 | | |
---|
16 | 16 | | let zeroBigInt = toBigInt(0) |
---|
17 | 17 | | |
---|
18 | 18 | | let oneBigInt = toBigInt(1) |
---|
19 | 19 | | |
---|
20 | 20 | | func asAnyList (val) = match val { |
---|
21 | 21 | | case valAnyLyst: List[Any] => |
---|
22 | 22 | | valAnyLyst |
---|
23 | 23 | | case _ => |
---|
24 | 24 | | throw("fail to cast into List[Any]") |
---|
25 | 25 | | } |
---|
26 | 26 | | |
---|
27 | 27 | | |
---|
28 | 28 | | func asInt (val) = match val { |
---|
29 | 29 | | case valInt: Int => |
---|
30 | 30 | | valInt |
---|
31 | 31 | | case _ => |
---|
32 | 32 | | throw("fail to cast into Int") |
---|
33 | 33 | | } |
---|
34 | 34 | | |
---|
35 | 35 | | |
---|
36 | 36 | | func asString (val) = match val { |
---|
37 | 37 | | case valStr: String => |
---|
38 | 38 | | valStr |
---|
39 | 39 | | case _ => |
---|
40 | 40 | | throw("fail to cast into Int") |
---|
41 | 41 | | } |
---|
42 | 42 | | |
---|
43 | 43 | | |
---|
44 | 44 | | func asByteVector (val) = match val { |
---|
45 | 45 | | case valBin: ByteVector => |
---|
46 | 46 | | valBin |
---|
47 | 47 | | case _ => |
---|
48 | 48 | | throw("fail to cast into Int") |
---|
49 | 49 | | } |
---|
50 | 50 | | |
---|
51 | 51 | | |
---|
52 | 52 | | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), (("mandatory this." + key) + " is not defined")) |
---|
53 | 53 | | |
---|
54 | 54 | | |
---|
55 | 55 | | func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined")) |
---|
56 | 56 | | |
---|
57 | 57 | | |
---|
58 | 58 | | func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0) |
---|
59 | 59 | | |
---|
60 | 60 | | |
---|
61 | 61 | | func getIntOrDefault (address,key,defaultVal) = valueOrElse(getInteger(address, key), defaultVal) |
---|
62 | 62 | | |
---|
63 | 63 | | |
---|
64 | 64 | | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined")) |
---|
65 | 65 | | |
---|
66 | 66 | | |
---|
67 | 67 | | func getBigIntFromStringOrZero (address,key) = value(parseBigInt(valueOrElse(getString(address, key), "0"))) |
---|
68 | 68 | | |
---|
69 | 69 | | |
---|
70 | 70 | | func getBigIntFromStringOrDefault (address,key,defaultVal) = match getString(address, key) { |
---|
71 | 71 | | case s: String => |
---|
72 | 72 | | value(parseBigInt(s)) |
---|
73 | 73 | | case _: Unit => |
---|
74 | 74 | | defaultVal |
---|
75 | 75 | | case _ => |
---|
76 | 76 | | throw("Match error") |
---|
77 | 77 | | } |
---|
78 | 78 | | |
---|
79 | 79 | | |
---|
80 | 80 | | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), MULT18, toBigInt(origScaleMult)) |
---|
81 | 81 | | |
---|
82 | 82 | | |
---|
83 | 83 | | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), MULT18)) |
---|
84 | 84 | | |
---|
85 | 85 | | |
---|
86 | 86 | | func keyFactoryAddress () = "%s%s__config__factoryAddress" |
---|
87 | 87 | | |
---|
88 | 88 | | |
---|
89 | 89 | | func keyVotingEmissionContract () = "%s__votingEmissionContract" |
---|
90 | 90 | | |
---|
91 | 91 | | |
---|
92 | 92 | | let IdxFactoryCfgStakingDapp = 1 |
---|
93 | 93 | | |
---|
94 | 94 | | let IdxFactoryCfgBoostingDapp = 2 |
---|
95 | 95 | | |
---|
96 | 96 | | let IdxFactoryCfgIdoDapp = 3 |
---|
97 | 97 | | |
---|
98 | 98 | | let IdxFactoryCfgTeamDapp = 4 |
---|
99 | 99 | | |
---|
100 | 100 | | let IdxFactoryCfgEmissionDapp = 5 |
---|
101 | 101 | | |
---|
102 | 102 | | let IdxFactoryCfgRestDapp = 6 |
---|
103 | 103 | | |
---|
104 | 104 | | let IdxFactoryCfgSlippageDapp = 7 |
---|
105 | 105 | | |
---|
106 | 106 | | func keyFactoryCfg () = "%s__factoryConfig" |
---|
107 | 107 | | |
---|
108 | 108 | | |
---|
109 | 109 | | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
110 | 110 | | |
---|
111 | 111 | | |
---|
112 | 112 | | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" |
---|
113 | 113 | | |
---|
114 | 114 | | |
---|
115 | 115 | | func keyStablePoolAddonAddr () = "%s__stablePoolAddonAddr" |
---|
116 | 116 | | |
---|
117 | 117 | | |
---|
118 | 118 | | func keyAddonAddr () = "%s__addonAddr" |
---|
119 | 119 | | |
---|
120 | 120 | | |
---|
121 | 121 | | func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) |
---|
122 | 122 | | |
---|
123 | 123 | | |
---|
124 | 124 | | func keyFactoryLpList () = "%s__lpTokensList" |
---|
125 | 125 | | |
---|
126 | 126 | | |
---|
127 | 127 | | func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) |
---|
128 | 128 | | |
---|
129 | 129 | | |
---|
130 | 130 | | func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP) |
---|
131 | 131 | | |
---|
132 | 132 | | |
---|
133 | 133 | | func readLpList (factory) = split(valueOrElse(getString(factory, keyFactoryLpList()), ""), SEP) |
---|
134 | 134 | | |
---|
135 | 135 | | |
---|
136 | 136 | | func readFactoryCfgOrFail (factory) = split(getStringByAddressOrFail(factory, keyFactoryCfg()), SEP) |
---|
137 | 137 | | |
---|
138 | 138 | | |
---|
139 | 139 | | func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp]) |
---|
140 | 140 | | |
---|
141 | 141 | | |
---|
142 | 142 | | func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp]) |
---|
143 | 143 | | |
---|
144 | 144 | | |
---|
145 | 145 | | func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp]) |
---|
146 | 146 | | |
---|
147 | 147 | | |
---|
148 | 148 | | func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current" |
---|
149 | 149 | | |
---|
150 | 150 | | |
---|
151 | 151 | | func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current" |
---|
152 | 152 | | |
---|
153 | 153 | | |
---|
154 | 154 | | func keyEmissionStartBlock () = "%s%s__emission__startBlock" |
---|
155 | 155 | | |
---|
156 | 156 | | |
---|
157 | 157 | | func keyEmissionDurationInBlocks () = "%s%s__emission__duration" |
---|
158 | 158 | | |
---|
159 | 159 | | |
---|
160 | 160 | | func keyEmissionEndBlock () = "%s%s__emission__endBlock" |
---|
161 | 161 | | |
---|
162 | 162 | | |
---|
163 | 163 | | func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP) |
---|
164 | 164 | | |
---|
165 | 165 | | |
---|
166 | 166 | | func keyStakedTotal (lpAssetIdStr) = ("%s%s%s__staked__total__" + lpAssetIdStr) |
---|
167 | 167 | | |
---|
168 | 168 | | |
---|
169 | 169 | | func keyClaimedByUser (lpAssetIdStr,userAddressStr) = makeString(["%s%s%s__claimed", userAddressStr, lpAssetIdStr], SEP) |
---|
170 | 170 | | |
---|
171 | 171 | | |
---|
172 | 172 | | func keyClaimedByUserMinReward (lpAssetIdStr,userAddressStr) = makeString(["%s%s%s__claimedMinReward", userAddressStr, lpAssetIdStr], SEP) |
---|
173 | 173 | | |
---|
174 | 174 | | |
---|
175 | 175 | | func keyClaimedByUserBoostReward (lpAssetIdStr,userAddressStr) = makeString(["%s%s%s__claimedBoostReward", userAddressStr, lpAssetIdStr], SEP) |
---|
176 | 176 | | |
---|
177 | 177 | | |
---|
178 | 178 | | func keyClaimedTotal (lpAssetIdStr) = makeString(["%s%s%s__claimed__total", lpAssetIdStr], SEP) |
---|
179 | 179 | | |
---|
180 | 180 | | |
---|
181 | 181 | | func readStaked (key) = valueOrElse(getInteger(this, key), 0) |
---|
182 | 182 | | |
---|
183 | 183 | | |
---|
184 | 184 | | func keyLastTotalLpBalance (lpAssetId) = makeString(["%s%s%s", lpAssetId, "total", "bal"], SEP) |
---|
185 | 185 | | |
---|
186 | 186 | | |
---|
187 | 187 | | func keyLastUserLpBalance (lpAssetId,userAddress) = makeString(["%s%s%s", lpAssetId, userAddress, "bal"], SEP) |
---|
188 | 188 | | |
---|
189 | 189 | | |
---|
190 | 190 | | func keyTotalLpBalanceIntegral (lpAssetId) = makeString(["%s%s%s", lpAssetId, "total", "balINT"], SEP) |
---|
191 | 191 | | |
---|
192 | 192 | | |
---|
193 | 193 | | func keyUserLpBalanceIntegral (lpAssetId,userAddress) = makeString(["%s%s%s", lpAssetId, userAddress, "balINT"], SEP) |
---|
194 | 194 | | |
---|
195 | 195 | | |
---|
196 | 196 | | func keyTotalLpBalanceIntegralLastUpdHeight (lpAssetId) = makeString(["%s%s%s", lpAssetId, "total", "lastUpd"], SEP) |
---|
197 | 197 | | |
---|
198 | 198 | | |
---|
199 | 199 | | func keyUserLpBalanceIntegralLastUpdHeight (lpAssetId,userAddress) = makeString(["%s%s%s", lpAssetId, userAddress, "lastUpd"], SEP) |
---|
200 | 200 | | |
---|
201 | 201 | | |
---|
202 | 202 | | func keyWxPerLpIntegral (lpAssetId) = makeString(["%s%s%s%s", lpAssetId, "common", "lpInt"], SEP) |
---|
203 | 203 | | |
---|
204 | 204 | | |
---|
205 | 205 | | func keyWxPerLpIntegralLastUpdHeight (lpAssetId) = makeString(["%s%s%s%s", lpAssetId, "common", "lpIntH"], SEP) |
---|
206 | 206 | | |
---|
207 | 207 | | |
---|
208 | 208 | | func keyWxToClaimUser (lpAssetId,userAddress) = makeString(["%s%s%s%s", lpAssetId, userAddress, "lpInt"], SEP) |
---|
209 | 209 | | |
---|
210 | 210 | | |
---|
211 | 211 | | func keyWxPerLpIntegralUserLastUpdHeight (lpAssetId,userAddress) = makeString(["%s%s%s%s", lpAssetId, userAddress, "lpIntH"], SEP) |
---|
212 | 212 | | |
---|
213 | 213 | | |
---|
214 | 214 | | func keyWxPerLp (lpAssetId) = makeString(["%s", lpAssetId, "wxPerLp"], SEP) |
---|
215 | 215 | | |
---|
216 | 216 | | |
---|
217 | 217 | | func keyWxPerLpX18 (lpAssetId) = makeString(["%s", lpAssetId, "wxPerLpX18"], SEP) |
---|
218 | 218 | | |
---|
219 | 219 | | |
---|
220 | 220 | | func keyWxPerLpIntegralUserLast (lpAssetId,userAddress) = makeString(["%s%s%s%s", lpAssetId, userAddress, "uIntL"], SEP) |
---|
221 | 221 | | |
---|
222 | 222 | | |
---|
223 | 223 | | func keyOperationHistoryRecord (type,userAddress,txId58) = makeString(["%s%s%s%s__history", type, userAddress, txId58], SEP) |
---|
224 | 224 | | |
---|
225 | 225 | | |
---|
226 | 226 | | func formatHistoryRecord (userAddress,lpAssetId,type,amount) = makeString(["%s%s%s%d%d%d", userAddress, lpAssetId, type, toString(height), toString(lastBlock.timestamp), toString(amount)], SEP) |
---|
227 | 227 | | |
---|
228 | 228 | | |
---|
229 | 229 | | func OperationHistoryEntry (type,userAddress,lpAssetId,amount,txId) = StringEntry(keyOperationHistoryRecord(type, userAddress, toBase58String(txId)), formatHistoryRecord(userAddress, lpAssetId, type, amount)) |
---|
230 | 230 | | |
---|
231 | 231 | | |
---|
232 | 232 | | let factoryAddress = getStringOrFail(this, keyFactoryAddress()) |
---|
233 | 233 | | |
---|
234 | 234 | | let factoryContract = addressFromStringValue(factoryAddress) |
---|
235 | 235 | | |
---|
236 | 236 | | let factoryCfg = readFactoryCfgOrFail(factoryContract) |
---|
237 | 237 | | |
---|
238 | 238 | | let emissionContract = getEmissionAddressOrFail(factoryCfg) |
---|
239 | 239 | | |
---|
240 | 240 | | let boostingContract = getBoostingAddressOrFail(factoryCfg) |
---|
241 | 241 | | |
---|
242 | 242 | | func keyNextUser (lpAssetId) = makeString(["%s%s", lpAssetId, "nextUser"], SEP) |
---|
243 | 243 | | |
---|
244 | 244 | | |
---|
245 | 245 | | func getUsersListName (lpAssetId) = makeString(["users", lpAssetId], SEP) |
---|
246 | 246 | | |
---|
247 | 247 | | |
---|
248 | 248 | | func keyListHead (listName) = makeString(["%s%s%s", listName, "head"], SEP) |
---|
249 | 249 | | |
---|
250 | 250 | | |
---|
251 | 251 | | func keyListSize (listName) = makeString(["%s%s%s", listName, "size"], SEP) |
---|
252 | 252 | | |
---|
253 | 253 | | |
---|
254 | 254 | | func keyListPrev (listName,id) = makeString(["%s%s%s%s", listName, id, "prev"], SEP) |
---|
255 | 255 | | |
---|
256 | 256 | | |
---|
257 | 257 | | func keyListNext (listName,id) = makeString(["%s%s%s%s", listName, id, "next"], SEP) |
---|
258 | 258 | | |
---|
259 | 259 | | |
---|
260 | 260 | | func containsNode (listName,id) = { |
---|
261 | 261 | | let headOrUnit = getString(this, keyListHead(listName)) |
---|
262 | 262 | | let prevOrUnit = getString(this, keyListPrev(listName, id)) |
---|
263 | 263 | | let nextOrUnit = getString(this, keyListNext(listName, id)) |
---|
264 | 264 | | if (if ((id == valueOrElse(headOrUnit, ""))) |
---|
265 | 265 | | then true |
---|
266 | 266 | | else (prevOrUnit != unit)) |
---|
267 | 267 | | then true |
---|
268 | 268 | | else (nextOrUnit != unit) |
---|
269 | 269 | | } |
---|
270 | 270 | | |
---|
271 | 271 | | |
---|
272 | 272 | | func insertNodeActions (listName,id) = { |
---|
273 | 273 | | let headOrUnit = getString(this, keyListHead(listName)) |
---|
274 | 274 | | let listSize = valueOrElse(getInteger(this, keyListSize(listName)), 0) |
---|
275 | 275 | | let checkNode = if (!(containsNode(listName, id))) |
---|
276 | 276 | | then true |
---|
277 | 277 | | else throw("Node exists") |
---|
278 | 278 | | if ((checkNode == checkNode)) |
---|
279 | 279 | | then (([IntegerEntry(keyListSize(listName), (listSize + 1))] ++ (if ((headOrUnit != unit)) |
---|
280 | 280 | | then [StringEntry(keyListNext(listName, id), value(headOrUnit)), StringEntry(keyListPrev(listName, value(headOrUnit)), id)] |
---|
281 | 281 | | else nil)) ++ [StringEntry(keyListHead(listName), id)]) |
---|
282 | 282 | | else throw("Strict value is not equal to itself.") |
---|
283 | 283 | | } |
---|
284 | 284 | | |
---|
285 | 285 | | |
---|
286 | 286 | | func deleteNodeActions (listName,id) = { |
---|
287 | 287 | | let headOrUnit = getString(this, keyListHead(listName)) |
---|
288 | 288 | | let listSize = valueOrElse(getInteger(this, keyListSize(listName)), 0) |
---|
289 | 289 | | let prevOrUnit = getString(this, keyListPrev(listName, id)) |
---|
290 | 290 | | let nextOrUnit = getString(this, keyListNext(listName, id)) |
---|
291 | 291 | | ([IntegerEntry(keyListSize(listName), (listSize - 1))] ++ (if (if ((prevOrUnit != unit)) |
---|
292 | 292 | | then (nextOrUnit != unit) |
---|
293 | 293 | | else false) |
---|
294 | 294 | | then [StringEntry(keyListNext(listName, value(prevOrUnit)), value(nextOrUnit)), StringEntry(keyListPrev(listName, value(nextOrUnit)), value(prevOrUnit)), DeleteEntry(keyListPrev(listName, id)), DeleteEntry(keyListNext(listName, id))] |
---|
295 | 295 | | else if ((nextOrUnit != unit)) |
---|
296 | 296 | | then [StringEntry(keyListHead(listName), value(nextOrUnit)), DeleteEntry(keyListNext(listName, id)), DeleteEntry(keyListPrev(listName, value(nextOrUnit)))] |
---|
297 | 297 | | else if ((prevOrUnit != unit)) |
---|
298 | 298 | | then [DeleteEntry(keyListPrev(listName, id)), DeleteEntry(keyListNext(listName, value(prevOrUnit)))] |
---|
299 | 299 | | else if ((id == valueOrElse(headOrUnit, ""))) |
---|
300 | 300 | | then [DeleteEntry(keyListHead(listName))] |
---|
301 | 301 | | else throw(((("invalid node: " + listName) + ".") + id)))) |
---|
302 | 302 | | } |
---|
303 | 303 | | |
---|
304 | 304 | | |
---|
305 | 305 | | func calcWxPerLpIntegralUserLast (stakedByUser,wxPerLpIntegralUserLastUpdHeightOrZero,wxPerLpIntegralNew,wxPerLpIntegralUserLastKEY) = if (if ((wxPerLpIntegralUserLastUpdHeightOrZero == zeroBigInt)) |
---|
306 | 306 | | then (stakedByUser > zeroBigInt) |
---|
307 | 307 | | else false) |
---|
308 | 308 | | then zeroBigInt |
---|
309 | 309 | | else if ((stakedByUser == zeroBigInt)) |
---|
310 | 310 | | then wxPerLpIntegralNew |
---|
311 | 311 | | else if (if ((wxPerLpIntegralUserLastUpdHeightOrZero > zeroBigInt)) |
---|
312 | 312 | | then (stakedByUser > zeroBigInt) |
---|
313 | 313 | | else false) |
---|
314 | 314 | | then value(parseBigInt(getStringOrFail(this, wxPerLpIntegralUserLastKEY))) |
---|
315 | 315 | | else throw("calcWxPerLpIntegralUserLast: unexpected state") |
---|
316 | 316 | | |
---|
317 | 317 | | |
---|
318 | 318 | | func refreshPoolINTEGRALS (lpAssetIdStr,poolAddressStr,lpDeltaAmount) = { |
---|
319 | 319 | | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) |
---|
320 | 320 | | let stakedTotal = toBigInt(readStaked(stakedTotalKEY)) |
---|
321 | 321 | | let nonZeroStakedTotal = if ((stakedTotal == zeroBigInt)) |
---|
322 | 322 | | then oneBigInt |
---|
323 | 323 | | else stakedTotal |
---|
324 | 324 | | let poolWeight = getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr)) |
---|
325 | 325 | | let emissionStartBlock = getIntOrFail(emissionContract, keyEmissionStartBlock()) |
---|
326 | 326 | | let MULT3 = 1000 |
---|
327 | 327 | | let wxEmissionPerBlockX3 = (getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent()) * MULT3) |
---|
328 | 328 | | let poolWxEmissionPerBlockX3 = fraction(wxEmissionPerBlockX3, poolWeight, (POOLWEIGHTMULT * 3)) |
---|
329 | 329 | | let wxPerLpIntegralKEY = keyWxPerLpIntegral(lpAssetIdStr) |
---|
330 | 330 | | let wxPerLpIntegralLastUpdHeightKEY = keyWxPerLpIntegralLastUpdHeight(lpAssetIdStr) |
---|
331 | 331 | | let wxPerLpKEY = keyWxPerLp(lpAssetIdStr) |
---|
332 | 332 | | let wxPerLpIntegralLastUpdHeight = getIntOrDefault(this, wxPerLpIntegralLastUpdHeightKEY, emissionStartBlock) |
---|
333 | 333 | | let wxPerLpIntegral = getBigIntFromStringOrZero(this, wxPerLpIntegralKEY) |
---|
334 | 334 | | let wxPerLpOrZeroX3 = 0 |
---|
335 | 335 | | let dh = max([(height - wxPerLpIntegralLastUpdHeight), 0]) |
---|
336 | 336 | | let wxPerLpX3 = if ((wxPerLpOrZeroX3 != 0)) |
---|
337 | 337 | | then toBigInt(wxPerLpOrZeroX3) |
---|
338 | 338 | | else fraction(toBigInt(poolWxEmissionPerBlockX3), toBigInt(MULT8), nonZeroStakedTotal) |
---|
339 | 339 | | let stakedTotalNew = (stakedTotal + toBigInt(lpDeltaAmount)) |
---|
340 | 340 | | let nonZeroStakedTotalNew = if ((stakedTotalNew == zeroBigInt)) |
---|
341 | 341 | | then oneBigInt |
---|
342 | 342 | | else stakedTotalNew |
---|
343 | 343 | | let wxPerLpIntegralNew = (wxPerLpIntegral + (wxPerLpX3 * toBigInt(dh))) |
---|
344 | 344 | | let wxPerLpX3New = (toBigInt(poolWxEmissionPerBlockX3) / nonZeroStakedTotalNew) |
---|
345 | 345 | | let wxPerLpIntegralLastUpdHeightNew = height |
---|
346 | 346 | | let debug = makeString([toString(wxPerLpIntegralNew), toString(dh), toString(wxPerLpX3), toString(stakedTotal), toString(poolWxEmissionPerBlockX3), toString(wxEmissionPerBlockX3), toString(poolWeight)], "::") |
---|
347 | 347 | | $Tuple3(wxPerLpIntegralNew, [StringEntry(wxPerLpIntegralKEY, toString(wxPerLpIntegralNew)), IntegerEntry(wxPerLpIntegralLastUpdHeightKEY, wxPerLpIntegralLastUpdHeightNew), StringEntry(wxPerLpKEY, toString(wxPerLpX3New))], debug) |
---|
348 | 348 | | } |
---|
349 | 349 | | |
---|
350 | 350 | | |
---|
351 | 351 | | func refreshINTEGRALS (lpAssetIdStr,userAddressStr,poolAddressStr,lpDeltaAmount) = { |
---|
352 | 352 | | let $t01427414396 = refreshPoolINTEGRALS(lpAssetIdStr, poolAddressStr, lpDeltaAmount) |
---|
353 | 353 | | let wxPerLpIntegralNew = $t01427414396._1 |
---|
354 | 354 | | let poolIntegralSTATE = $t01427414396._2 |
---|
355 | 355 | | let poolDEBUG = $t01427414396._3 |
---|
356 | 356 | | let MULT3 = 1000 |
---|
357 | 357 | | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) |
---|
358 | 358 | | let stakedByUser = readStaked(stakedByUserKEY) |
---|
359 | 359 | | let wxToClaimUserKEY = keyWxToClaimUser(lpAssetIdStr, userAddressStr) |
---|
360 | 360 | | let wxPerLpIntegralUserLastUpdHeightKEY = keyWxPerLpIntegralUserLastUpdHeight(lpAssetIdStr, userAddressStr) |
---|
361 | 361 | | let wxPerLpIntegralUserLastKEY = keyWxPerLpIntegralUserLast(lpAssetIdStr, userAddressStr) |
---|
362 | 362 | | let wxToClaimUser = getBigIntFromStringOrZero(this, wxToClaimUserKEY) |
---|
363 | 363 | | let wxPerLpIntegralUserLastUpdHeightOrZero = getIntOrZero(this, wxPerLpIntegralUserLastUpdHeightKEY) |
---|
364 | 364 | | let wxPerLpIntegralUserLast = calcWxPerLpIntegralUserLast(toBigInt(stakedByUser), toBigInt(wxPerLpIntegralUserLastUpdHeightOrZero), wxPerLpIntegralNew, wxPerLpIntegralUserLastKEY) |
---|
365 | 365 | | let MULT11 = (MULT8 * MULT3) |
---|
366 | 366 | | let wxToClaimUserNew = max([(wxToClaimUser + fraction((wxPerLpIntegralNew - wxPerLpIntegralUserLast), toBigInt(stakedByUser), toBigInt(MULT11))), zeroBigInt]) |
---|
367 | 367 | | let wxPerLpIntegralUserLastNew = wxPerLpIntegralNew |
---|
368 | 368 | | let wxPerLpIntegralUserLastUpdHeightNew = height |
---|
369 | 369 | | let debug = makeString([toString(wxToClaimUser), toString(wxPerLpIntegralUserLast), toString(stakedByUser), poolDEBUG, toString(height)], "::") |
---|
370 | 370 | | $Tuple3(wxToClaimUserNew, (poolIntegralSTATE ++ [StringEntry(wxToClaimUserKEY, toString(wxToClaimUserNew)), IntegerEntry(wxPerLpIntegralUserLastUpdHeightKEY, wxPerLpIntegralUserLastUpdHeightNew), StringEntry(wxPerLpIntegralUserLastKEY, toString(wxPerLpIntegralUserLastNew))]), debug) |
---|
371 | 371 | | } |
---|
372 | 372 | | |
---|
373 | 373 | | |
---|
374 | 374 | | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { |
---|
375 | 375 | | case s: String => |
---|
376 | 376 | | fromBase58String(s) |
---|
377 | 377 | | case _: Unit => |
---|
378 | 378 | | unit |
---|
379 | 379 | | case _ => |
---|
380 | 380 | | throw("Match error") |
---|
381 | 381 | | } |
---|
382 | 382 | | |
---|
383 | 383 | | |
---|
384 | 384 | | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { |
---|
385 | 385 | | case s: String => |
---|
386 | 386 | | fromBase58String(s) |
---|
387 | 387 | | case _: Unit => |
---|
388 | 388 | | unit |
---|
389 | 389 | | case _ => |
---|
390 | 390 | | throw("Match error") |
---|
391 | 391 | | } |
---|
392 | 392 | | |
---|
393 | 393 | | |
---|
394 | 394 | | let permissionDeniedError = throw("Permission denied") |
---|
395 | 395 | | |
---|
396 | 396 | | func mustThis (i) = if ((i.caller == this)) |
---|
397 | 397 | | then true |
---|
398 | 398 | | else permissionDeniedError |
---|
399 | 399 | | |
---|
400 | 400 | | |
---|
401 | 401 | | func mustManager (i) = match managerPublicKeyOrUnit() { |
---|
402 | 402 | | case pk: ByteVector => |
---|
403 | 403 | | if ((i.callerPublicKey == pk)) |
---|
404 | 404 | | then true |
---|
405 | 405 | | else permissionDeniedError |
---|
406 | 406 | | case _: Unit => |
---|
407 | 407 | | if ((i.caller == this)) |
---|
408 | 408 | | then true |
---|
409 | 409 | | else permissionDeniedError |
---|
410 | 410 | | case _ => |
---|
411 | 411 | | throw("Match error") |
---|
412 | 412 | | } |
---|
413 | 413 | | |
---|
414 | 414 | | |
---|
415 | 415 | | @Callable(i) |
---|
416 | 416 | | func constructor (factoryAddressStr) = { |
---|
417 | 417 | | let checkCaller = mustManager(i) |
---|
418 | 418 | | if ((checkCaller == checkCaller)) |
---|
419 | 419 | | then [StringEntry(keyFactoryAddress(), factoryAddressStr)] |
---|
420 | 420 | | else throw("Strict value is not equal to itself.") |
---|
421 | 421 | | } |
---|
422 | 422 | | |
---|
423 | 423 | | |
---|
424 | 424 | | |
---|
425 | 425 | | @Callable(i) |
---|
426 | 426 | | func constructorV2 (votingEmissionContract) = { |
---|
427 | 427 | | let cheks = [mustManager(i), if ((addressFromString(votingEmissionContract) != unit)) |
---|
428 | 428 | | then true |
---|
429 | 429 | | else "invalid voting emission contract address"] |
---|
430 | 430 | | if ((cheks == cheks)) |
---|
431 | 431 | | then [StringEntry(keyVotingEmissionContract(), votingEmissionContract)] |
---|
432 | 432 | | else throw("Strict value is not equal to itself.") |
---|
433 | 433 | | } |
---|
434 | 434 | | |
---|
435 | 435 | | |
---|
436 | 436 | | |
---|
437 | 437 | | @Callable(i) |
---|
438 | 438 | | func setManager (pendingManagerPublicKey) = { |
---|
439 | 439 | | let checkCaller = mustManager(i) |
---|
440 | 440 | | if ((checkCaller == checkCaller)) |
---|
441 | 441 | | then { |
---|
442 | 442 | | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) |
---|
443 | 443 | | if ((checkManagerPublicKey == checkManagerPublicKey)) |
---|
444 | 444 | | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] |
---|
445 | 445 | | else throw("Strict value is not equal to itself.") |
---|
446 | 446 | | } |
---|
447 | 447 | | else throw("Strict value is not equal to itself.") |
---|
448 | 448 | | } |
---|
449 | 449 | | |
---|
450 | 450 | | |
---|
451 | 451 | | |
---|
452 | 452 | | @Callable(i) |
---|
453 | 453 | | func confirmManager () = { |
---|
454 | 454 | | let pm = pendingManagerPublicKeyOrUnit() |
---|
455 | 455 | | let hasPM = if (isDefined(pm)) |
---|
456 | 456 | | then true |
---|
457 | 457 | | else throw("No pending manager") |
---|
458 | 458 | | if ((hasPM == hasPM)) |
---|
459 | 459 | | then { |
---|
460 | 460 | | let checkPM = if ((i.callerPublicKey == value(pm))) |
---|
461 | 461 | | then true |
---|
462 | 462 | | else throw("You are not pending manager") |
---|
463 | 463 | | if ((checkPM == checkPM)) |
---|
464 | 464 | | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] |
---|
465 | 465 | | else throw("Strict value is not equal to itself.") |
---|
466 | 466 | | } |
---|
467 | 467 | | else throw("Strict value is not equal to itself.") |
---|
468 | 468 | | } |
---|
469 | 469 | | |
---|
470 | 470 | | |
---|
471 | 471 | | |
---|
472 | 472 | | @Callable(i) |
---|
473 | 473 | | func stake () = if ((size(i.payments) != 1)) |
---|
474 | 474 | | then throw("invalid payment - exact one payment must be attached") |
---|
475 | 475 | | else { |
---|
476 | 476 | | let pmt = i.payments[0] |
---|
477 | 477 | | let lpAssetId = value(pmt.assetId) |
---|
478 | 478 | | let lpAssetIdStr = toBase58String(lpAssetId) |
---|
479 | 479 | | let amount = pmt.amount |
---|
480 | 480 | | let poolAddressStr = valueOrErrorMessage(getString(factoryContract, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr)) |
---|
481 | 481 | | let callerStr = toString(i.caller) |
---|
482 | 482 | | let userAddressStr = if ((callerStr == poolAddressStr)) |
---|
483 | 483 | | then toString(i.originCaller) |
---|
484 | 484 | | else callerStr |
---|
485 | 485 | | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) |
---|
486 | 486 | | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) |
---|
487 | 487 | | let stakedByUser = readStaked(stakedByUserKEY) |
---|
488 | 488 | | let stakedTotal = readStaked(stakedTotalKEY) |
---|
489 | 489 | | let $t01883218949 = refreshINTEGRALS(lpAssetIdStr, userAddressStr, poolAddressStr, amount) |
---|
490 | 490 | | let wxToClaimUserNew = $t01883218949._1 |
---|
491 | 491 | | let integralSTATE = $t01883218949._2 |
---|
492 | 492 | | let debug = $t01883218949._3 |
---|
493 | 493 | | let listName = getUsersListName(lpAssetIdStr) |
---|
494 | 494 | | let listActions = if (containsNode(listName, userAddressStr)) |
---|
495 | 495 | | then nil |
---|
496 | 496 | | else insertNodeActions(listName, userAddressStr) |
---|
497 | 497 | | (([IntegerEntry(stakedByUserKEY, (stakedByUser + amount)), IntegerEntry(stakedTotalKEY, (stakedTotal + amount)), OperationHistoryEntry("stake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] ++ integralSTATE) ++ listActions) |
---|
498 | 498 | | } |
---|
499 | 499 | | |
---|
500 | 500 | | |
---|
501 | 501 | | |
---|
502 | 502 | | @Callable(i) |
---|
503 | 503 | | func unstake (lpAssetIdStr,amount) = { |
---|
504 | 504 | | let lpAssetId = fromBase58String(lpAssetIdStr) |
---|
505 | 505 | | let poolAddressStr = valueOrErrorMessage(getString(factoryContract, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr)) |
---|
506 | 506 | | let poolAddon = valueOrElse(getString(addressFromStringValue(poolAddressStr), keyAddonAddr()), poolAddressStr) |
---|
507 | 507 | | let callerStr = toString(i.caller) |
---|
508 | 508 | | let userAddressStr = if (if ((callerStr == poolAddressStr)) |
---|
509 | 509 | | then true |
---|
510 | 510 | | else (callerStr == poolAddon)) |
---|
511 | 511 | | then toString(i.originCaller) |
---|
512 | 512 | | else callerStr |
---|
513 | 513 | | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) |
---|
514 | 514 | | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) |
---|
515 | 515 | | let stakedByUser = readStaked(stakedByUserKEY) |
---|
516 | 516 | | let stakedTotal = readStaked(stakedTotalKEY) |
---|
517 | 517 | | let integralSTATE = refreshINTEGRALS(lpAssetIdStr, userAddressStr, poolAddressStr, -(amount))._2 |
---|
518 | 518 | | let listName = getUsersListName(lpAssetIdStr) |
---|
519 | 519 | | let listActions = if (if (containsNode(listName, userAddressStr)) |
---|
520 | 520 | | then (amount == stakedByUser) |
---|
521 | 521 | | else false) |
---|
522 | 522 | | then deleteNodeActions(listName, userAddressStr) |
---|
523 | 523 | | else nil |
---|
524 | 524 | | let claimedByUser = getBigIntFromStringOrZero(this, keyClaimedByUser(lpAssetIdStr, userAddressStr)) |
---|
525 | 525 | | let poolAddress = getStringByAddressOrFail(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr)) |
---|
526 | 526 | | let wxToClaimUserNew = refreshINTEGRALS(lpAssetIdStr, userAddressStr, poolAddress, 0)._1 |
---|
527 | 527 | | let availableToClaim = (wxToClaimUserNew - claimedByUser) |
---|
528 | 528 | | let r = if ((availableToClaim > zeroBigInt)) |
---|
529 | 529 | | then invoke(this, "claimWxINTERNAL", [lpAssetIdStr, userAddressStr], nil) |
---|
530 | 530 | | else unit |
---|
531 | 531 | | if ((r == r)) |
---|
532 | 532 | | then if ((amount > stakedByUser)) |
---|
533 | 533 | | then throw(((((((("passed amount=" + toString(amount)) + " is greater than available=") + toString(stakedByUser)) + ". lpAssetId=") + lpAssetIdStr) + ". stakedByUserKEY=") + stakedByUserKEY)) |
---|
534 | 534 | | else (([IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] ++ integralSTATE) ++ listActions) |
---|
535 | 535 | | else throw("Strict value is not equal to itself.") |
---|
536 | 536 | | } |
---|
537 | 537 | | |
---|
538 | 538 | | |
---|
539 | 539 | | |
---|
540 | 540 | | @Callable(i) |
---|
541 | 541 | | func claimWx (lpAssetIdStr) = { |
---|
542 | 542 | | let userAddressStr = toString(i.caller) |
---|
543 | 543 | | let result = invoke(this, "claimWxINTERNAL", [lpAssetIdStr, userAddressStr], nil) |
---|
544 | 544 | | $Tuple2(nil, result) |
---|
545 | 545 | | } |
---|
546 | 546 | | |
---|
547 | 547 | | |
---|
548 | 548 | | |
---|
549 | 549 | | @Callable(i) |
---|
550 | 550 | | func claimWxINTERNAL (lpAssetIdStr,userAddressStr) = { |
---|
551 | 551 | | let checkCaller = mustThis(i) |
---|
552 | 552 | | if ((checkCaller == checkCaller)) |
---|
553 | 553 | | then { |
---|
554 | 554 | | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), "claimWxINTERNAL: invalid user address") |
---|
555 | 555 | | let poolAddressStr = getStringByAddressOrFail(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr)) |
---|
556 | 556 | | let claimedByUserKEY = keyClaimedByUser(lpAssetIdStr, userAddressStr) |
---|
557 | 557 | | let claimedTotalKEY = keyClaimedTotal(lpAssetIdStr) |
---|
558 | 558 | | let claimedByUserMinRewardKEY = keyClaimedByUserMinReward(lpAssetIdStr, userAddressStr) |
---|
559 | 559 | | let claimedByUserBoostRewardKEY = keyClaimedByUserBoostReward(lpAssetIdStr, userAddressStr) |
---|
560 | 560 | | let claimedByUser = getBigIntFromStringOrZero(this, claimedByUserKEY) |
---|
561 | 561 | | let claimedByUserMinReward = getBigIntFromStringOrZero(this, claimedByUserMinRewardKEY) |
---|
562 | 562 | | let claimedByUserBoostReward = getBigIntFromStringOrZero(this, claimedByUserBoostRewardKEY) |
---|
563 | 563 | | let claimedTotal = getBigIntFromStringOrZero(this, claimedTotalKEY) |
---|
564 | 564 | | let $t02278722899 = refreshINTEGRALS(lpAssetIdStr, userAddressStr, poolAddressStr, 0) |
---|
565 | 565 | | let wxToClaimUserNew = $t02278722899._1 |
---|
566 | 566 | | let integralSTATE = $t02278722899._2 |
---|
567 | 567 | | let debug = $t02278722899._3 |
---|
568 | 568 | | let availableToClaim = max([(wxToClaimUserNew - claimedByUser), zeroBigInt]) |
---|
569 | 569 | | if ((zeroBigInt >= availableToClaim)) |
---|
570 | 570 | | then throw("nothing to claim") |
---|
571 | 571 | | else { |
---|
572 | 572 | | let wxAmountBoostTotal = max([asInt(asAnyList(invoke(boostingContract, "claimWxBoost", [lpAssetIdStr, userAddressStr], nil))[0]), 0]) |
---|
573 | 573 | | let minRewardPart = availableToClaim |
---|
574 | 574 | | let boostRewardPart = min([(minRewardPart * toBigInt(2)), toBigInt(wxAmountBoostTotal)]) |
---|
575 | 575 | | let wxAssetId = asByteVector(asAnyList(invoke(emissionContract, "emit", [toInt(minRewardPart)], nil))[0]) |
---|
576 | 576 | | let emitBoost = asAnyList(invoke(emissionContract, "emit", [toInt(boostRewardPart)], nil)) |
---|
577 | 577 | | if ((emitBoost == emitBoost)) |
---|
578 | 578 | | then { |
---|
579 | 579 | | let claimedByUserValue = (claimedByUser + availableToClaim) |
---|
580 | 580 | | let claimedByUserMinRewardPlusPart = (claimedByUserMinReward + minRewardPart) |
---|
581 | 581 | | let claimedByUserBoostRewardPlusBoostRewardPart = (claimedByUserMinReward + minRewardPart) |
---|
582 | 582 | | let claimedTotalPlusAvailableToClaim = (claimedByUserMinReward + minRewardPart) |
---|
583 | 583 | | [StringEntry(claimedByUserKEY, toString(claimedByUserValue)), StringEntry(claimedByUserMinRewardKEY, toString(claimedByUserMinRewardPlusPart)), StringEntry(claimedByUserBoostRewardKEY, toString(claimedByUserBoostRewardPlusBoostRewardPart)), StringEntry(claimedTotalKEY, toString(claimedTotalPlusAvailableToClaim)), ScriptTransfer(userAddress, toInt(minRewardPart), wxAssetId), ScriptTransfer(userAddress, toInt(boostRewardPart), wxAssetId), OperationHistoryEntry("claim", userAddressStr, lpAssetIdStr, toInt(availableToClaim), i.transactionId)] |
---|
584 | 584 | | } |
---|
585 | 585 | | else throw("Strict value is not equal to itself.") |
---|
586 | 586 | | } |
---|
587 | 587 | | } |
---|
588 | 588 | | else throw("Strict value is not equal to itself.") |
---|
589 | 589 | | } |
---|
590 | 590 | | |
---|
591 | 591 | | |
---|
592 | 592 | | |
---|
593 | 593 | | @Callable(i) |
---|
594 | 594 | | func claimWxBulkInternalREADONLY (currentIter,lpAssetIds,userAddressStr,resAcc) = if ((currentIter == size(lpAssetIds))) |
---|
595 | 595 | | then $Tuple2(nil, resAcc) |
---|
596 | 596 | | else { |
---|
597 | 597 | | let lpAssetId = lpAssetIds[currentIter] |
---|
598 | 598 | | let info = split({ |
---|
599 | 599 | | let @ = invoke(this, "claimWxREADONLY", [lpAssetId, userAddressStr], nil) |
---|
600 | 600 | | if ($isInstanceOf(@, "String")) |
---|
601 | 601 | | then @ |
---|
602 | 602 | | else throw(($getType(@) + " couldn't be cast to String")) |
---|
603 | 603 | | }, SEP) |
---|
604 | 604 | | let unclaimed = info[3] |
---|
605 | 605 | | let claimed = info[4] |
---|
606 | 606 | | let res = (resAcc :+ makeString(["%d%d", unclaimed, claimed], SEP)) |
---|
607 | 607 | | let inv = { |
---|
608 | 608 | | let @ = invoke(this, "claimWxBulkInternalREADONLY", [(currentIter + 1), lpAssetIds, userAddressStr, res], nil) |
---|
609 | 609 | | if ($isInstanceOf(@, "List[Any]")) |
---|
610 | 610 | | then @ |
---|
611 | 611 | | else throw(($getType(@) + " couldn't be cast to List[Any]")) |
---|
612 | 612 | | } |
---|
613 | 613 | | if ((inv == inv)) |
---|
614 | 614 | | then $Tuple2(nil, inv) |
---|
615 | 615 | | else throw("Strict value is not equal to itself.") |
---|
616 | 616 | | } |
---|
617 | 617 | | |
---|
618 | 618 | | |
---|
619 | 619 | | |
---|
620 | 620 | | @Callable(i) |
---|
621 | 621 | | func claimWxBulkREADONLY (lpAssetIds,userAddressStr) = { |
---|
622 | 622 | | let res = invoke(this, "claimWxBulkInternalREADONLY", [0, lpAssetIds, userAddressStr, nil], nil) |
---|
623 | 623 | | $Tuple2(nil, res) |
---|
624 | 624 | | } |
---|
625 | 625 | | |
---|
626 | 626 | | |
---|
627 | 627 | | |
---|
628 | 628 | | @Callable(i) |
---|
629 | 629 | | func claimWxREADONLY (lpAssetIdStr,userAddressStr) = { |
---|
630 | 630 | | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) |
---|
631 | 631 | | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) |
---|
632 | 632 | | let claimedByUserKEY = keyClaimedByUser(lpAssetIdStr, userAddressStr) |
---|
633 | 633 | | let stakedByUser = readStaked(stakedByUserKEY) |
---|
634 | 634 | | let stakedTotal = readStaked(stakedTotalKEY) |
---|
635 | 635 | | let claimedByUser = getBigIntFromStringOrZero(this, claimedByUserKEY) |
---|
636 | 636 | | let poolAddressStr = getStringByAddressOrFail(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr)) |
---|
637 | 637 | | let poolWeight = getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr)) |
---|
638 | 638 | | let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent()) |
---|
639 | 639 | | let emissionStartBlock = getIntOrFail(emissionContract, keyEmissionStartBlock()) |
---|
640 | 640 | | let passedBlocks = if ((emissionStartBlock > height)) |
---|
641 | 641 | | then 0 |
---|
642 | 642 | | else (height - emissionStartBlock) |
---|
643 | 643 | | let poolWxEmission = fraction((wxEmissionPerBlock * passedBlocks), poolWeight, POOLWEIGHTMULT) |
---|
644 | 644 | | let userWxReward = fraction(poolWxEmission, stakedByUser, stakedTotal) |
---|
645 | 645 | | let $t02635726469 = refreshINTEGRALS(lpAssetIdStr, userAddressStr, poolAddressStr, 0) |
---|
646 | 646 | | let wxToClaimUserNew = $t02635726469._1 |
---|
647 | 647 | | let integralSTATE = $t02635726469._2 |
---|
648 | 648 | | let debug = $t02635726469._3 |
---|
649 | 649 | | let availableToClaim = max([(wxToClaimUserNew - claimedByUser), zeroBigInt]) |
---|
650 | 650 | | let boostInvResult = asAnyList(invoke(boostingContract, "claimWxBoostREADONLY", [lpAssetIdStr, userAddressStr], nil)) |
---|
651 | 651 | | let wxAmountBoostTotal = max([asInt(boostInvResult[0]), 0]) |
---|
652 | 652 | | let boostDebug = asString(boostInvResult[1]) |
---|
653 | 653 | | let minRewardPart = availableToClaim |
---|
654 | 654 | | let boostRewardPart = min([(minRewardPart * toBigInt(2)), toBigInt(wxAmountBoostTotal)]) |
---|
655 | 655 | | let totalReward = (minRewardPart + boostRewardPart) |
---|
656 | 656 | | $Tuple2(nil, makeString(["%s%s%d%d%d%d%s", lpAssetIdStr, userAddressStr, toString(totalReward), toString(claimedByUser), toString(minRewardPart), toString(boostRewardPart), "soon"], SEP)) |
---|
657 | 657 | | } |
---|
658 | 658 | | |
---|
659 | 659 | | |
---|
660 | 660 | | |
---|
661 | 661 | | @Callable(i) |
---|
662 | 662 | | func usersListTraversal (lpAssetId) = { |
---|
663 | 663 | | let checkCaller = if ((toBase58String(i.caller.bytes) == valueOrElse(getString(this, keyVotingEmissionContract()), ""))) |
---|
664 | 664 | | then true |
---|
665 | 665 | | else mustManager(i) |
---|
666 | 666 | | if ((checkCaller == checkCaller)) |
---|
667 | 667 | | then { |
---|
668 | 668 | | let listName = getUsersListName(lpAssetId) |
---|
669 | 669 | | let userOrUnit = getString(keyNextUser(lpAssetId)) |
---|
670 | 670 | | let headOrUnit = getString(keyListHead(listName)) |
---|
671 | 671 | | match userOrUnit { |
---|
672 | 672 | | case _: Unit => |
---|
673 | 673 | | match headOrUnit { |
---|
674 | 674 | | case _: Unit => |
---|
675 | 675 | | $Tuple2(nil, false) |
---|
676 | 676 | | case head: String => |
---|
677 | 677 | | $Tuple2([StringEntry(keyNextUser(lpAssetId), head)], true) |
---|
678 | 678 | | case _ => |
---|
679 | 679 | | throw("Match error") |
---|
680 | 680 | | } |
---|
681 | 681 | | case userAddress: String => |
---|
682 | 682 | | let claimedByUser = getBigIntFromStringOrZero(this, keyClaimedByUser(lpAssetId, userAddress)) |
---|
683 | 683 | | let poolAddress = getStringByAddressOrFail(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetId)) |
---|
684 | 684 | | let wxToClaimUserNew = refreshINTEGRALS(lpAssetId, userAddress, poolAddress, 0)._1 |
---|
685 | 685 | | let availableToClaim = (wxToClaimUserNew - claimedByUser) |
---|
686 | 686 | | let r = if ((availableToClaim > zeroBigInt)) |
---|
687 | 687 | | then invoke(this, "claimWxINTERNAL", [lpAssetId, userAddress], nil) |
---|
688 | 688 | | else unit |
---|
689 | 689 | | if ((r == r)) |
---|
690 | 690 | | then { |
---|
691 | 691 | | let nextUserOrUnit = getString(keyListNext(listName, userAddress)) |
---|
692 | 692 | | match nextUserOrUnit { |
---|
693 | 693 | | case _: Unit => |
---|
694 | 694 | | $Tuple2([DeleteEntry(keyNextUser(lpAssetId))], false) |
---|
695 | 695 | | case nextUser: String => |
---|
696 | 696 | | $Tuple2([StringEntry(keyNextUser(lpAssetId), nextUser)], true) |
---|
697 | 697 | | case _ => |
---|
698 | 698 | | throw("Match error") |
---|
699 | 699 | | } |
---|
700 | 700 | | } |
---|
701 | 701 | | else throw("Strict value is not equal to itself.") |
---|
702 | 702 | | case _ => |
---|
703 | 703 | | throw("Match error") |
---|
704 | 704 | | } |
---|
705 | 705 | | } |
---|
706 | 706 | | else throw("Strict value is not equal to itself.") |
---|
707 | 707 | | } |
---|
708 | 708 | | |
---|
709 | 709 | | |
---|
710 | 710 | | |
---|
711 | 711 | | @Callable(i) |
---|
712 | 712 | | func onModifyWeight (lpAssetIdStr,poolAddressStr) = if ((i.caller != factoryContract)) |
---|
713 | 713 | | then throw("permissions denied") |
---|
714 | 714 | | else { |
---|
715 | 715 | | let $t02876928879 = refreshPoolINTEGRALS(lpAssetIdStr, poolAddressStr, 0) |
---|
716 | 716 | | let wxPerLpIntegralNew = $t02876928879._1 |
---|
717 | 717 | | let poolIntegralSTATE = $t02876928879._2 |
---|
718 | 718 | | let poolDEBUG = $t02876928879._3 |
---|
719 | 719 | | poolIntegralSTATE |
---|
720 | 720 | | } |
---|
721 | 721 | | |
---|
722 | 722 | | |
---|
723 | 723 | | @Verifier(tx) |
---|
724 | 724 | | func verify () = { |
---|
725 | 725 | | let targetPublicKey = match managerPublicKeyOrUnit() { |
---|
726 | 726 | | case pk: ByteVector => |
---|
727 | 727 | | pk |
---|
728 | 728 | | case _: Unit => |
---|
729 | 729 | | tx.senderPublicKey |
---|
730 | 730 | | case _ => |
---|
731 | 731 | | throw("Match error") |
---|
732 | 732 | | } |
---|
733 | 733 | | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
734 | 734 | | } |
---|
735 | 735 | | |
---|