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 idxPoolAddress = 1 |
---|
19 | 19 | | |
---|
20 | 20 | | let idxPoolStatus = 2 |
---|
21 | 21 | | |
---|
22 | 22 | | let idxPoolLPAssetId = 3 |
---|
23 | 23 | | |
---|
24 | 24 | | let idxAmtAssetId = 4 |
---|
25 | 25 | | |
---|
26 | 26 | | let idxPriceAssetId = 5 |
---|
27 | 27 | | |
---|
28 | 28 | | let idxAmtAssetDcm = 6 |
---|
29 | 29 | | |
---|
30 | 30 | | let idxPriceAssetDcm = 7 |
---|
31 | 31 | | |
---|
32 | 32 | | let idxIAmtAssetId = 8 |
---|
33 | 33 | | |
---|
34 | 34 | | let idxIPriceAssetId = 9 |
---|
35 | 35 | | |
---|
36 | 36 | | let idxLPAssetDcm = 10 |
---|
37 | 37 | | |
---|
38 | 38 | | func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined")) |
---|
39 | 39 | | |
---|
40 | 40 | | |
---|
41 | 41 | | func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined")) |
---|
42 | 42 | | |
---|
43 | 43 | | |
---|
44 | 44 | | func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0) |
---|
45 | 45 | | |
---|
46 | 46 | | |
---|
47 | 47 | | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined")) |
---|
48 | 48 | | |
---|
49 | 49 | | |
---|
50 | 50 | | func asAnyList (val) = match val { |
---|
51 | 51 | | case valAnyLyst: List[Any] => |
---|
52 | 52 | | valAnyLyst |
---|
53 | 53 | | case _ => |
---|
54 | 54 | | throw("fail to cast into List[Any]") |
---|
55 | 55 | | } |
---|
56 | 56 | | |
---|
57 | 57 | | |
---|
58 | 58 | | func asInt (val) = match val { |
---|
59 | 59 | | case valInt: Int => |
---|
60 | 60 | | valInt |
---|
61 | 61 | | case _ => |
---|
62 | 62 | | throw("fail to cast into Int") |
---|
63 | 63 | | } |
---|
64 | 64 | | |
---|
65 | 65 | | |
---|
66 | 66 | | func asString (val) = match val { |
---|
67 | 67 | | case valStr: String => |
---|
68 | 68 | | valStr |
---|
69 | 69 | | case _ => |
---|
70 | 70 | | throw("fail to cast into String") |
---|
71 | 71 | | } |
---|
72 | 72 | | |
---|
73 | 73 | | |
---|
74 | 74 | | func keyFactoryAddress () = "%s%s__config__factoryAddress" |
---|
75 | 75 | | |
---|
76 | 76 | | |
---|
77 | 77 | | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
78 | 78 | | |
---|
79 | 79 | | |
---|
80 | 80 | | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" |
---|
81 | 81 | | |
---|
82 | 82 | | |
---|
83 | 83 | | let IdxFactoryCfgStakingDapp = 1 |
---|
84 | 84 | | |
---|
85 | 85 | | let IdxFactoryCfgBoostingDapp = 2 |
---|
86 | 86 | | |
---|
87 | 87 | | let IdxFactoryCfgIdoDapp = 3 |
---|
88 | 88 | | |
---|
89 | 89 | | let IdxFactoryCfgTeamDapp = 4 |
---|
90 | 90 | | |
---|
91 | 91 | | let IdxFactoryCfgEmissionDapp = 5 |
---|
92 | 92 | | |
---|
93 | 93 | | let IdxFactoryCfgRestDapp = 6 |
---|
94 | 94 | | |
---|
95 | 95 | | let IdxFactoryCfgSlippageDapp = 7 |
---|
96 | 96 | | |
---|
97 | 97 | | let IdxFactoryCfgGwxRewardDapp = 8 |
---|
98 | 98 | | |
---|
99 | 99 | | func keyFactoryCfg () = "%s__factoryConfig" |
---|
100 | 100 | | |
---|
101 | 101 | | |
---|
102 | 102 | | func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) |
---|
103 | 103 | | |
---|
104 | 104 | | |
---|
105 | 105 | | func keyFactoryLpList () = "%s__lpTokensList" |
---|
106 | 106 | | |
---|
107 | 107 | | |
---|
108 | 108 | | func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) |
---|
109 | 109 | | |
---|
110 | 110 | | |
---|
111 | 111 | | func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP) |
---|
112 | 112 | | |
---|
113 | 113 | | |
---|
114 | 114 | | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(keyFactoryAddress())) |
---|
115 | 115 | | |
---|
116 | 116 | | |
---|
117 | 117 | | func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP) |
---|
118 | 118 | | |
---|
119 | 119 | | |
---|
120 | 120 | | func readFactoryCfgOrFail (factory) = split(getStringByAddressOrFail(factory, keyFactoryCfg()), SEP) |
---|
121 | 121 | | |
---|
122 | 122 | | |
---|
123 | 123 | | func getBoostingAddressOrFail (fCfg) = addressFromStringValue(fCfg[IdxFactoryCfgBoostingDapp]) |
---|
124 | 124 | | |
---|
125 | 125 | | |
---|
126 | 126 | | func getEmissionAddressOrFail (fCfg) = addressFromStringValue(fCfg[IdxFactoryCfgEmissionDapp]) |
---|
127 | 127 | | |
---|
128 | 128 | | |
---|
129 | 129 | | func getStakingAddressOrFail (fCfg) = addressFromStringValue(fCfg[IdxFactoryCfgStakingDapp]) |
---|
130 | 130 | | |
---|
131 | 131 | | |
---|
132 | 132 | | func getGwxRewardAddressOrFail (fCfg) = addressFromStringValue(fCfg[IdxFactoryCfgGwxRewardDapp]) |
---|
133 | 133 | | |
---|
134 | 134 | | |
---|
135 | 135 | | func keyBoostCfg () = "%s__config" |
---|
136 | 136 | | |
---|
137 | 137 | | |
---|
138 | 138 | | func keyBoostingLockParamTotalAmount () = "%s%s__stats__activeTotalLocked" |
---|
139 | 139 | | |
---|
140 | 140 | | |
---|
141 | 141 | | func keyBoostingStatsLocksDurationSumInBlocks () = "%s%s__stats__locksDurationSumInBlocks" |
---|
142 | 142 | | |
---|
143 | 143 | | |
---|
144 | 144 | | func keyBoostingStatsLocksCount () = "%s%s__stats__locksCount" |
---|
145 | 145 | | |
---|
146 | 146 | | |
---|
147 | 147 | | func keyBoostingStatsUsersCount () = "%s%s__stats__activeUsersCount" |
---|
148 | 148 | | |
---|
149 | 149 | | |
---|
150 | 150 | | func keyUser2NumMapping (userAddress) = makeString(["%s%s%s__mapping__user2num", userAddress], SEP) |
---|
151 | 151 | | |
---|
152 | 152 | | |
---|
153 | 153 | | func keyNum2UserMapping (num) = makeString(["%s%s%s__mapping__num2user", num], SEP) |
---|
154 | 154 | | |
---|
155 | 155 | | |
---|
156 | 156 | | func keyLockParamUserAmount (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "amount"], SEP) |
---|
157 | 157 | | |
---|
158 | 158 | | |
---|
159 | 159 | | func keyLockParamStartBlock (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "start"], SEP) |
---|
160 | 160 | | |
---|
161 | 161 | | |
---|
162 | 162 | | func keyLockParamDuration (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "duration"], SEP) |
---|
163 | 163 | | |
---|
164 | 164 | | |
---|
165 | 165 | | func keyLockParamK (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "k"], SEP) |
---|
166 | 166 | | |
---|
167 | 167 | | |
---|
168 | 168 | | func keyLockParamB (userNum) = makeString(["%s%d%s__paramByUserNum", userNum, "b"], SEP) |
---|
169 | 169 | | |
---|
170 | 170 | | |
---|
171 | 171 | | func keyLockParamByPeriodK (userNum,period) = makeString(["%s%d%s%d__paramByPeriod", userNum, "k", period], SEP) |
---|
172 | 172 | | |
---|
173 | 173 | | |
---|
174 | 174 | | func keyLockParamByPeriodB (userNum,period) = makeString(["%s%d%s%d__paramByPeriod", userNum, "b", period], SEP) |
---|
175 | 175 | | |
---|
176 | 176 | | |
---|
177 | 177 | | func keyUserBoostEmissionLastINTEGRAL (userNum) = makeString(["%s%d__userBoostEmissionLastInt", userNum], SEP) |
---|
178 | 178 | | |
---|
179 | 179 | | |
---|
180 | 180 | | func keyUserMaxBoostINTEGRAL (userNum) = makeString(["%s%d__maxBoostInt", userNum], SEP) |
---|
181 | 181 | | |
---|
182 | 182 | | |
---|
183 | 183 | | func keyTotalMaxBoostINTEGRAL () = "%s%s__maxBoostInt__total" |
---|
184 | 184 | | |
---|
185 | 185 | | |
---|
186 | 186 | | func keyUserBoostAvalaibleToClaimTotal (userNum) = makeString(["%s%d__userBoostAvaliableToClaimTotal", userNum], SEP) |
---|
187 | 187 | | |
---|
188 | 188 | | |
---|
189 | 189 | | func keyUserBoostClaimed (userNum) = makeString(["%s%d__userBoostClaimed", userNum], SEP) |
---|
190 | 190 | | |
---|
191 | 191 | | |
---|
192 | 192 | | func keyTotalCachedGwx () = "%s%s__gwxCached__total" |
---|
193 | 193 | | |
---|
194 | 194 | | |
---|
195 | 195 | | func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP) |
---|
196 | 196 | | |
---|
197 | 197 | | |
---|
198 | 198 | | func keyStakedTotal (lpAssetIdStr) = ("%s%s%s__staked__total__" + lpAssetIdStr) |
---|
199 | 199 | | |
---|
200 | 200 | | |
---|
201 | 201 | | func keyClaimedByUser (lpAssetIdStr,userAddressStr) = makeString(["%s%s%s__claimed", userAddressStr, lpAssetIdStr], SEP) |
---|
202 | 202 | | |
---|
203 | 203 | | |
---|
204 | 204 | | func keyClaimedByUserMinReward (lpAssetIdStr,userAddressStr) = makeString(["%s%s%s__claimedMinReward", userAddressStr, lpAssetIdStr], SEP) |
---|
205 | 205 | | |
---|
206 | 206 | | |
---|
207 | 207 | | func keyClaimedByUserBoostReward (lpAssetIdStr,userAddressStr) = makeString(["%s%s%s__claimedBoostReward", userAddressStr, lpAssetIdStr], SEP) |
---|
208 | 208 | | |
---|
209 | 209 | | |
---|
210 | 210 | | func readStaked (stakingDapp,key) = valueOrElse(getInteger(stakingDapp, key), 0) |
---|
211 | 211 | | |
---|
212 | 212 | | |
---|
213 | 213 | | func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current" |
---|
214 | 214 | | |
---|
215 | 215 | | |
---|
216 | 216 | | func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current" |
---|
217 | 217 | | |
---|
218 | 218 | | |
---|
219 | 219 | | func keyEmissionStartBlock () = "%s%s__emission__startBlock" |
---|
220 | 220 | | |
---|
221 | 221 | | |
---|
222 | 222 | | func keyEmissionDurationInBlocks () = "%s%s__emission__duration" |
---|
223 | 223 | | |
---|
224 | 224 | | |
---|
225 | 225 | | func keyEmissionEndBlock () = "%s%s__emission__endBlock" |
---|
226 | 226 | | |
---|
227 | 227 | | |
---|
228 | 228 | | func keyAddonAddr () = "%s__addonAddr" |
---|
229 | 229 | | |
---|
230 | 230 | | |
---|
231 | 231 | | let factoryDapp = readFactoryAddressOrFail() |
---|
232 | 232 | | |
---|
233 | 233 | | let factoryCfg = readFactoryCfgOrFail(factoryDapp) |
---|
234 | 234 | | |
---|
235 | 235 | | let emissionDapp = getEmissionAddressOrFail(factoryCfg) |
---|
236 | 236 | | |
---|
237 | 237 | | let stakingDapp = getStakingAddressOrFail(factoryCfg) |
---|
238 | 238 | | |
---|
239 | 239 | | let gwxRewardDapp = getGwxRewardAddressOrFail(factoryCfg) |
---|
240 | 240 | | |
---|
241 | 241 | | let boostingDapp = getBoostingAddressOrFail(factoryCfg) |
---|
242 | 242 | | |
---|
243 | 243 | | func getPoolInFee (poolAddress) = { |
---|
244 | 244 | | let @ = invoke(factoryDapp, "getInFeeREADONLY", [toString(poolAddress)], nil) |
---|
245 | 245 | | if ($isInstanceOf(@, "Int")) |
---|
246 | 246 | | then @ |
---|
247 | 247 | | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
248 | 248 | | } |
---|
249 | 249 | | |
---|
250 | 250 | | |
---|
251 | 251 | | func getPoolOutFee (poolAddress) = { |
---|
252 | 252 | | let @ = invoke(factoryDapp, "getOutFeeREADONLY", [toString(poolAddress)], nil) |
---|
253 | 253 | | if ($isInstanceOf(@, "Int")) |
---|
254 | 254 | | then @ |
---|
255 | 255 | | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
256 | 256 | | } |
---|
257 | 257 | | |
---|
258 | 258 | | |
---|
259 | 259 | | func internalCurrentRewardRate (lpAssetId) = { |
---|
260 | 260 | | let poolAddressStr = getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAssetId)) |
---|
261 | 261 | | let poolWeightMult = MULT8 |
---|
262 | 262 | | let poolWeight = getIntegerValue(factoryDapp, keyFactoryPoolWeight(poolAddressStr)) |
---|
263 | 263 | | let wxEmissionPerBlock = getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent()) |
---|
264 | 264 | | let wxEmissionPerBlockMax = getIntOrFail(emissionDapp, keyEmissionRatePerBlockMaxCurrent()) |
---|
265 | 265 | | let boostMaxCoeff = 3 |
---|
266 | 266 | | let poolWxEmissionPerBlock = (fraction(wxEmissionPerBlock, poolWeight, poolWeightMult) / boostMaxCoeff) |
---|
267 | 267 | | let poolWxEmissionPerBlockMax = fraction(wxEmissionPerBlockMax, poolWeight, poolWeightMult) |
---|
268 | 268 | | let maxFactor = (boostMaxCoeff * MULT8) |
---|
269 | 269 | | let totalLpStaked = getIntOrZero(stakingDapp, keyStakedTotal(lpAssetId)) |
---|
270 | 270 | | [poolWxEmissionPerBlock, maxFactor, totalLpStaked] |
---|
271 | 271 | | } |
---|
272 | 272 | | |
---|
273 | 273 | | |
---|
274 | 274 | | func calcGwxAmountStartREADONLY (lockAmount,lockDuration,maxLockDuration) = { |
---|
275 | 275 | | let coeffX8 = fraction(lockDuration, MULT8, maxLockDuration) |
---|
276 | 276 | | let gWxAmountStart = fraction(lockAmount, coeffX8, MULT8) |
---|
277 | 277 | | [gWxAmountStart] |
---|
278 | 278 | | } |
---|
279 | 279 | | |
---|
280 | 280 | | |
---|
281 | 281 | | func getKey (addr,key,type) = if ((type == "string")) |
---|
282 | 282 | | then getStringValue(addr, key) |
---|
283 | 283 | | else if ((type == "integer")) |
---|
284 | 284 | | then toString(getIntegerValue(addr, key)) |
---|
285 | 285 | | else if ((type == "boolean")) |
---|
286 | 286 | | then toString(getBooleanValue(addr, key)) |
---|
287 | 287 | | else throw("unknown type. expected string/integer/boolean") |
---|
288 | 288 | | |
---|
289 | 289 | | |
---|
290 | 290 | | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { |
---|
291 | 291 | | case s: String => |
---|
292 | 292 | | fromBase58String(s) |
---|
293 | 293 | | case _: Unit => |
---|
294 | 294 | | unit |
---|
295 | 295 | | case _ => |
---|
296 | 296 | | throw("Match error") |
---|
297 | 297 | | } |
---|
298 | 298 | | |
---|
299 | 299 | | |
---|
300 | 300 | | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { |
---|
301 | 301 | | case s: String => |
---|
302 | 302 | | fromBase58String(s) |
---|
303 | 303 | | case _: Unit => |
---|
304 | 304 | | unit |
---|
305 | 305 | | case _ => |
---|
306 | 306 | | throw("Match error") |
---|
307 | 307 | | } |
---|
308 | 308 | | |
---|
309 | 309 | | |
---|
310 | 310 | | func mustManager (i) = { |
---|
311 | 311 | | let pd = throw("Permission denied") |
---|
312 | 312 | | match managerPublicKeyOrUnit() { |
---|
313 | 313 | | case pk: ByteVector => |
---|
314 | 314 | | if ((i.callerPublicKey == pk)) |
---|
315 | 315 | | then true |
---|
316 | 316 | | else pd |
---|
317 | 317 | | case _: Unit => |
---|
318 | 318 | | if ((i.caller == this)) |
---|
319 | 319 | | then true |
---|
320 | 320 | | else pd |
---|
321 | 321 | | case _ => |
---|
322 | 322 | | throw("Match error") |
---|
323 | 323 | | } |
---|
324 | 324 | | } |
---|
325 | 325 | | |
---|
326 | 326 | | |
---|
327 | 327 | | @Callable(i) |
---|
328 | 328 | | func constructor (factoryAddress) = { |
---|
329 | 329 | | let checkCaller = mustManager(i) |
---|
330 | 330 | | if ((checkCaller == checkCaller)) |
---|
331 | 331 | | then [StringEntry(keyFactoryAddress(), factoryAddress)] |
---|
332 | 332 | | else throw("Strict value is not equal to itself.") |
---|
333 | 333 | | } |
---|
334 | 334 | | |
---|
335 | 335 | | |
---|
336 | 336 | | |
---|
337 | 337 | | @Callable(i) |
---|
338 | 338 | | func currentRewardRateREADONLY (lpAssetId) = { |
---|
339 | 339 | | let rewardData = internalCurrentRewardRate(lpAssetId) |
---|
340 | 340 | | let wxEmissionPerBlock = rewardData[0] |
---|
341 | 341 | | let maxFactor = rewardData[1] |
---|
342 | 342 | | let totalLpStaked = rewardData[2] |
---|
343 | 343 | | $Tuple2(nil, makeString(["%d%d%d", toString(wxEmissionPerBlock), toString(maxFactor), toString(totalLpStaked)], SEP)) |
---|
344 | 344 | | } |
---|
345 | 345 | | |
---|
346 | 346 | | |
---|
347 | 347 | | |
---|
348 | 348 | | @Callable(i) |
---|
349 | 349 | | func currentUserRewardRateREADONLY (lpAssetId,userAddress) = { |
---|
350 | 350 | | let rewardData = internalCurrentRewardRate(lpAssetId) |
---|
351 | 351 | | let wxEmissionPerBlock = rewardData[0] |
---|
352 | 352 | | let maxFactor = rewardData[1] |
---|
353 | 353 | | let totalLpStaked = rewardData[2] |
---|
354 | 354 | | let lpStakedByUser = getIntOrZero(stakingDapp, keyStakedByUser(userAddress, lpAssetId)) |
---|
355 | 355 | | let userClaimInfo = split(asString(invoke(stakingDapp, "claimWxREADONLY", [lpAssetId, userAddress], nil)), SEP) |
---|
356 | 356 | | let minRewardPart = valueOrErrorMessage(parseInt(userClaimInfo[5]), "couldn't parse minRewardPart") |
---|
357 | 357 | | let boostRewardPart = valueOrErrorMessage(parseInt(userClaimInfo[6]), "couldn't parse boostRewardPart") |
---|
358 | 358 | | let debug = userClaimInfo[7] |
---|
359 | 359 | | let boostingPower = if ((boostRewardPart == 0)) |
---|
360 | 360 | | then (1 * MULT8) |
---|
361 | 361 | | else fraction((minRewardPart + boostRewardPart), MULT8, minRewardPart) |
---|
362 | 362 | | $Tuple2(nil, makeString(["%d%d%d%d%d%s", toString(wxEmissionPerBlock), toString(maxFactor), toString(totalLpStaked), toString(lpStakedByUser), toString(boostingPower), debug], SEP)) |
---|
363 | 363 | | } |
---|
364 | 364 | | |
---|
365 | 365 | | |
---|
366 | 366 | | |
---|
367 | 367 | | @Callable(i) |
---|
368 | 368 | | func calcBoostBulkInternalREADONLY (currentIter,deltaWxAmountBulk,deltaLockPeriodInBlocksBulk,deltaLpAmountBulk,lpAssetIdOptBulk,userAddressOpt,resAcc) = if ((currentIter == size(deltaWxAmountBulk))) |
---|
369 | 369 | | then $Tuple2(nil, resAcc) |
---|
370 | 370 | | else { |
---|
371 | 371 | | let deltaWxAmount = deltaWxAmountBulk[currentIter] |
---|
372 | 372 | | let deltaLockPeriodInBlocks = deltaLockPeriodInBlocksBulk[currentIter] |
---|
373 | 373 | | let deltaLpAmount = deltaLpAmountBulk[currentIter] |
---|
374 | 374 | | let lpAssetIdOpt = lpAssetIdOptBulk[currentIter] |
---|
375 | 375 | | let info = { |
---|
376 | 376 | | let @ = invoke(this, "calcBoostREADONLY", [deltaWxAmount, deltaLockPeriodInBlocks, deltaLpAmount, lpAssetIdOpt, userAddressOpt], nil) |
---|
377 | 377 | | if ($isInstanceOf(@, "String")) |
---|
378 | 378 | | then @ |
---|
379 | 379 | | else throw(($getType(@) + " couldn't be cast to String")) |
---|
380 | 380 | | } |
---|
381 | 381 | | let res = (resAcc :+ info) |
---|
382 | 382 | | let inv = { |
---|
383 | 383 | | let @ = invoke(this, "calcBoostBulkInternalREADONLY", [(currentIter + 1), deltaWxAmountBulk, deltaLockPeriodInBlocksBulk, deltaLpAmountBulk, lpAssetIdOptBulk, userAddressOpt, res], nil) |
---|
384 | 384 | | if ($isInstanceOf(@, "List[Any]")) |
---|
385 | 385 | | then @ |
---|
386 | 386 | | else throw(($getType(@) + " couldn't be cast to List[Any]")) |
---|
387 | 387 | | } |
---|
388 | 388 | | if ((inv == inv)) |
---|
389 | 389 | | then $Tuple2(nil, inv) |
---|
390 | 390 | | else throw("Strict value is not equal to itself.") |
---|
391 | 391 | | } |
---|
392 | 392 | | |
---|
393 | 393 | | |
---|
394 | 394 | | |
---|
395 | 395 | | @Callable(i) |
---|
396 | 396 | | func calcBoostBulkREADONLY (deltaWxAmount,deltaLockPeriodInBlocks,deltaLpAmount,lpAssetIdOpt,userAddressOpt) = { |
---|
397 | 397 | | let res = invoke(this, "calcBoostBulkInternalREADONLY", [0, deltaWxAmount, deltaLockPeriodInBlocks, deltaLpAmount, lpAssetIdOpt, userAddressOpt, nil], nil) |
---|
398 | 398 | | $Tuple2(nil, res) |
---|
399 | 399 | | } |
---|
400 | 400 | | |
---|
401 | 401 | | |
---|
402 | 402 | | |
---|
403 | 403 | | @Callable(i) |
---|
404 | 404 | | func calcBoostREADONLY (deltaWxAmount,deltaLockPeriodInBlocks,deltaLpAmount,lpAssetIdOpt,userAddressOpt) = { |
---|
405 | 405 | | let mathDapp = gwxRewardDapp |
---|
406 | 406 | | let EMPTYSTR = "empty" |
---|
407 | 407 | | let maxLockDurationInBlocks = parseIntValue(split(getStringByAddressOrFail(boostingDapp, keyBoostCfg()), SEP)[4]) |
---|
408 | 408 | | let lpAssetIdStr = if ((lpAssetIdOpt == "")) |
---|
409 | 409 | | then EMPTYSTR |
---|
410 | 410 | | else lpAssetIdOpt |
---|
411 | 411 | | let userAddressStr = if ((userAddressOpt == "")) |
---|
412 | 412 | | then EMPTYSTR |
---|
413 | 413 | | else userAddressOpt |
---|
414 | 414 | | let userNumStr = valueOrElse(getString(boostingDapp, keyUser2NumMapping(userAddressOpt)), EMPTYSTR) |
---|
415 | 415 | | let userAmount = valueOrElse(getInteger(boostingDapp, keyLockParamUserAmount(userNumStr)), 0) |
---|
416 | 416 | | let lockStart = valueOrElse(getInteger(boostingDapp, keyLockParamStartBlock(userNumStr)), height) |
---|
417 | 417 | | let lockDuration = valueOrElse(getInteger(boostingDapp, keyLockParamDuration(userNumStr)), 0) |
---|
418 | 418 | | let lockEnd = (lockStart + lockDuration) |
---|
419 | 419 | | let remainingDuration = max([(lockEnd - height), 0]) |
---|
420 | 420 | | let userAmountNew = (userAmount + deltaWxAmount) |
---|
421 | 421 | | let lockDurationNew = min([(remainingDuration + deltaLockPeriodInBlocks), maxLockDurationInBlocks]) |
---|
422 | 422 | | let userCurrgWxAmount = asInt(asAnyList(invoke(boostingDapp, "gwxUserInfoREADONLY", [userAddressStr], nil))[0]) |
---|
423 | 423 | | let gWxAmountStartNew = calcGwxAmountStartREADONLY(userAmountNew, lockDurationNew, maxLockDurationInBlocks)[0] |
---|
424 | 424 | | let gWxParamsResultList = asAnyList(invoke(mathDapp, "calcGwxParamsREADONLY", [gWxAmountStartNew, height, lockDurationNew], nil)) |
---|
425 | 425 | | let gWxAmountDiff = (gWxAmountStartNew - userCurrgWxAmount) |
---|
426 | 426 | | let k = asInt(gWxParamsResultList[0]) |
---|
427 | 427 | | let b = asInt(gWxParamsResultList[1]) |
---|
428 | 428 | | let period = toString(asInt(gWxParamsResultList[2])) |
---|
429 | 429 | | let totalMaxBoostIntegralKEY = keyTotalMaxBoostINTEGRAL() |
---|
430 | 430 | | let userMaxBoostIntNew = ((gWxAmountStartNew * lockDurationNew) / 2) |
---|
431 | 431 | | let totalMaxBoostInt = getIntOrZero(boostingDapp, totalMaxBoostIntegralKEY) |
---|
432 | 432 | | let totalCachedGwx = { |
---|
433 | 433 | | let @ = invoke(boostingDapp, "getTotalCachedGwxREADONLY", nil, nil) |
---|
434 | 434 | | if ($isInstanceOf(@, "Int")) |
---|
435 | 435 | | then @ |
---|
436 | 436 | | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
437 | 437 | | } |
---|
438 | 438 | | let MULT3 = 1000 |
---|
439 | 439 | | let wxEmissionPerBlockX3 = (getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent()) * MULT3) |
---|
440 | 440 | | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) |
---|
441 | 441 | | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) |
---|
442 | 442 | | let stakedByUser = readStaked(stakingDapp, stakedByUserKEY) |
---|
443 | 443 | | let stakedTotal = readStaked(stakingDapp, stakedTotalKEY) |
---|
444 | 444 | | let stakedByUserNew = (stakedByUser + deltaLpAmount) |
---|
445 | 445 | | let stakedTotalNew = (stakedTotal + deltaLpAmount) |
---|
446 | 446 | | let poolWeight = if ((lpAssetIdStr != EMPTYSTR)) |
---|
447 | 447 | | then { |
---|
448 | 448 | | let poolAddressStr = valueOrErrorMessage(getString(factoryDapp, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr)) |
---|
449 | 449 | | getIntegerValue(factoryDapp, keyFactoryPoolWeight(poolAddressStr)) |
---|
450 | 450 | | } |
---|
451 | 451 | | else 0 |
---|
452 | 452 | | let poolWxEmissionPerBlockX3 = fraction(wxEmissionPerBlockX3, poolWeight, (POOLWEIGHTMULT * 3)) |
---|
453 | 453 | | let wxPerLpX3 = if ((stakedTotalNew != 0)) |
---|
454 | 454 | | then fraction(poolWxEmissionPerBlockX3, MULT8, stakedTotalNew) |
---|
455 | 455 | | else 0 |
---|
456 | 456 | | let userWxPerBlockX3 = fraction(wxPerLpX3, stakedByUserNew, MULT8) |
---|
457 | 457 | | let boostEmissionPerBlockX3 = (poolWxEmissionPerBlockX3 * 2) |
---|
458 | 458 | | let tmpUserBoostPerBlockX3 = fraction(gWxAmountStartNew, boostEmissionPerBlockX3, (totalCachedGwx + gWxAmountDiff)) |
---|
459 | 459 | | let userBoostPerBlockX3 = min([tmpUserBoostPerBlockX3, (userWxPerBlockX3 * 2)]) |
---|
460 | 460 | | let boostCoeff = if ((userWxPerBlockX3 == 0)) |
---|
461 | 461 | | then (1 * MULT8) |
---|
462 | 462 | | else fraction((userBoostPerBlockX3 + userWxPerBlockX3), MULT8, userWxPerBlockX3) |
---|
463 | 463 | | $Tuple2(nil, makeString(["%d%d%s", toString(gWxAmountStartNew), toString(boostCoeff), "d"], SEP)) |
---|
464 | 464 | | } |
---|
465 | 465 | | |
---|
466 | 466 | | |
---|
467 | 467 | | |
---|
468 | 468 | | @Callable(i) |
---|
469 | 469 | | func wxEmissionStatsREADONLY () = { |
---|
470 | 470 | | let ONEMULT = toString(MULT8) |
---|
471 | 471 | | let ONE = "1" |
---|
472 | 472 | | let wxEmissionPerBlock = getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent()) |
---|
473 | 473 | | let emissionStartBlock = getIntOrFail(emissionDapp, keyEmissionStartBlock()) |
---|
474 | 474 | | let passedBlocks = if ((emissionStartBlock > height)) |
---|
475 | 475 | | then 0 |
---|
476 | 476 | | else (height - emissionStartBlock) |
---|
477 | 477 | | let teamEmDuration = (1440 * 365) |
---|
478 | 478 | | let teamEmMax = (201000000 * MULT8) |
---|
479 | 479 | | let teamEm = if ((passedBlocks > teamEmDuration)) |
---|
480 | 480 | | then teamEmMax |
---|
481 | 481 | | else fraction(teamEmMax, passedBlocks, teamEmDuration) |
---|
482 | 482 | | let totalWxReleased = ((wxEmissionPerBlock * passedBlocks) + teamEm) |
---|
483 | 483 | | let totalWxLocked = getIntOrZero(boostingDapp, keyBoostingLockParamTotalAmount()) |
---|
484 | 484 | | let locksDurationSumInBlocks = getIntOrZero(boostingDapp, keyBoostingStatsLocksDurationSumInBlocks()) |
---|
485 | 485 | | let locksCount = getIntOrZero(boostingDapp, keyBoostingStatsLocksCount()) |
---|
486 | 486 | | $Tuple2(nil, makeString(["%d%d%d%d", toString(totalWxReleased), toString(totalWxLocked), toString(locksDurationSumInBlocks), toString(locksCount)], SEP)) |
---|
487 | 487 | | } |
---|
488 | 488 | | |
---|
489 | 489 | | |
---|
490 | 490 | | |
---|
491 | 491 | | @Callable(i) |
---|
492 | 492 | | func poolStatsREADONLY (lpAsset) = { |
---|
493 | 493 | | let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset))) |
---|
494 | 494 | | let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil)) |
---|
495 | 495 | | let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId])) |
---|
496 | 496 | | let amtAssetId = asString(cfg[idxAmtAssetId]) |
---|
497 | 497 | | let priceAssetId = asString(cfg[idxPriceAssetId]) |
---|
498 | 498 | | let iAmtAssetId = asString(cfg[idxIAmtAssetId]) |
---|
499 | 499 | | let iPriceAssetId = asString(cfg[idxIPriceAssetId]) |
---|
500 | 500 | | let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm])) |
---|
501 | 501 | | let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm])) |
---|
502 | 502 | | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity |
---|
503 | 503 | | let accAmtAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amtAssetId], nil)) |
---|
504 | 504 | | let accPriceAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [priceAssetId], nil)) |
---|
505 | 505 | | let pricesList = if ((poolLPBalance == 0)) |
---|
506 | 506 | | then [toString(zeroBigInt), toString(zeroBigInt), toString(zeroBigInt)] |
---|
507 | 507 | | else asAnyList(invoke(poolAddress, "calcPricesWrapperREADONLY", [accAmtAssetBalance, accPriceAssetBalance, poolLPBalance], nil)) |
---|
508 | 508 | | let curPrice = 0 |
---|
509 | 509 | | let lpAmtAssetShare = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [pricesList[1], MULT8], nil)) |
---|
510 | 510 | | let lpPriceAssetShare = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [pricesList[2], MULT8], nil)) |
---|
511 | 511 | | let poolWeight = getIntegerValue(factoryDapp, keyFactoryPoolWeight(toString(poolAddress))) |
---|
512 | 512 | | let inFee = getPoolInFee(poolAddress) |
---|
513 | 513 | | let outFee = getPoolOutFee(poolAddress) |
---|
514 | 514 | | let poolOneTokenOperationsDisabled = { |
---|
515 | 515 | | let @ = invoke(factoryDapp, "isPoolOneTokenOperationsDisabledREADONLY", [toString(poolAddress)], nil) |
---|
516 | 516 | | if ($isInstanceOf(@, "Boolean")) |
---|
517 | 517 | | then @ |
---|
518 | 518 | | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
519 | 519 | | } |
---|
520 | 520 | | let poolOneTokenOperationsEnabled = !(poolOneTokenOperationsDisabled) |
---|
521 | 521 | | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d%d%s", toString(accAmtAssetBalance), toString(accPriceAssetBalance), toString(poolLPBalance), toString(curPrice), toString(lpAmtAssetShare), toString(lpPriceAssetShare), toString(poolWeight), toString(inFee), toString(outFee), toString(poolOneTokenOperationsEnabled)], SEP)) |
---|
522 | 522 | | } |
---|
523 | 523 | | |
---|
524 | 524 | | |
---|
525 | 525 | | |
---|
526 | 526 | | @Callable(i) |
---|
527 | 527 | | func poolEvaluatePutByAmountAssetREADONLY (lpAsset,inAmAssetAmt) = { |
---|
528 | 528 | | let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset))) |
---|
529 | 529 | | let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil)) |
---|
530 | 530 | | let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId])) |
---|
531 | 531 | | let amAssetIdStr = asString(cfg[idxAmtAssetId]) |
---|
532 | 532 | | let amAssetId = fromBase58String(amAssetIdStr) |
---|
533 | 533 | | let prAssetIdStr = asString(cfg[idxPriceAssetId]) |
---|
534 | 534 | | let prAssetId = fromBase58String(prAssetIdStr) |
---|
535 | 535 | | let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm])) |
---|
536 | 536 | | let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm])) |
---|
537 | 537 | | let poolStatus = asString(cfg[idxPoolStatus]) |
---|
538 | 538 | | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity |
---|
539 | 539 | | let accAmtAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amAssetIdStr], nil)) |
---|
540 | 540 | | let accPriceAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [prAssetIdStr], nil)) |
---|
541 | 541 | | let amtAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [accAmtAssetBalance, amtAssetDcm], nil))) |
---|
542 | 542 | | let priceAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [accPriceAssetBalance, priceAssetDcm], nil))) |
---|
543 | 543 | | let curPriceX18 = if ((poolLPBalance == 0)) |
---|
544 | 544 | | then zeroBigInt |
---|
545 | 545 | | else parseBigIntValue(asString(invoke(poolAddress, "calcPriceBigIntWrapperREADONLY", [toString(priceAssetAmtX18), toString(amtAssetAmtX18)], nil))) |
---|
546 | 546 | | let curPrice = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(curPriceX18), MULT8], nil)) |
---|
547 | 547 | | let inAmAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [inAmAssetAmt, amtAssetDcm], nil))) |
---|
548 | 548 | | let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, MULT18) |
---|
549 | 549 | | let inPrAssetAmt = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(inPrAssetAmtX18), priceAssetDcm], nil)) |
---|
550 | 550 | | let res = invoke(poolAddress, "estimatePutOperationWrapperREADONLY", ["", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false], nil) |
---|
551 | 551 | | let $t02283223185 = match res { |
---|
552 | 552 | | case _ => |
---|
553 | 553 | | if (if (if ($isInstanceOf($match0._1, "Int")) |
---|
554 | 554 | | then if ($isInstanceOf($match0._3, "Int")) |
---|
555 | 555 | | then if ($isInstanceOf($match0._4, "Int")) |
---|
556 | 556 | | then if ($isInstanceOf($match0._5, "Int")) |
---|
557 | 557 | | then $isInstanceOf($match0._6, "Int") |
---|
558 | 558 | | else false |
---|
559 | 559 | | else false |
---|
560 | 560 | | else false |
---|
561 | 561 | | else false) |
---|
562 | 562 | | then (size($match0) == 13) |
---|
563 | 563 | | else false) |
---|
564 | 564 | | then { |
---|
565 | 565 | | let calcLpAmt = $match0._1 |
---|
566 | 566 | | let curPriceCalc = $match0._3 |
---|
567 | 567 | | let amBalance = $match0._4 |
---|
568 | 568 | | let prBalance = $match0._5 |
---|
569 | 569 | | let lpEmission = $match0._6 |
---|
570 | 570 | | $Tuple5(calcLpAmt, curPriceCalc, amBalance, prBalance, lpEmission) |
---|
571 | 571 | | } |
---|
572 | 572 | | else throw("Couldn't cast types") |
---|
573 | 573 | | } |
---|
574 | 574 | | let calcLpAmt = $t02283223185._1 |
---|
575 | 575 | | let curPriceCalc = $t02283223185._2 |
---|
576 | 576 | | let amBalance = $t02283223185._3 |
---|
577 | 577 | | let prBalance = $t02283223185._4 |
---|
578 | 578 | | let lpEmission = $t02283223185._5 |
---|
579 | 579 | | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d", toString(calcLpAmt), toString(curPrice), toString(amBalance), toString(prBalance), toString(lpEmission), poolStatus, toString(inAmAssetAmt), toString(inPrAssetAmt)], SEP)) |
---|
580 | 580 | | } |
---|
581 | 581 | | |
---|
582 | 582 | | |
---|
583 | 583 | | |
---|
584 | 584 | | @Callable(i) |
---|
585 | 585 | | func poolEvaluatePutByPriceAssetREADONLY (lpAsset,inPrAssetAmt) = { |
---|
586 | 586 | | let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset))) |
---|
587 | 587 | | let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil)) |
---|
588 | 588 | | let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId])) |
---|
589 | 589 | | let amAssetIdStr = asString(cfg[idxAmtAssetId]) |
---|
590 | 590 | | let amAssetId = fromBase58String(amAssetIdStr) |
---|
591 | 591 | | let prAssetIdStr = asString(cfg[idxPriceAssetId]) |
---|
592 | 592 | | let prAssetId = fromBase58String(prAssetIdStr) |
---|
593 | 593 | | let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm])) |
---|
594 | 594 | | let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm])) |
---|
595 | 595 | | let poolStatus = asString(cfg[idxPoolStatus]) |
---|
596 | 596 | | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity |
---|
597 | 597 | | let amBalanceRaw = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amAssetIdStr], nil)) |
---|
598 | 598 | | let prBalanceRaw = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [prAssetIdStr], nil)) |
---|
599 | 599 | | let amBalanceRawX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [amBalanceRaw, amtAssetDcm], nil))) |
---|
600 | 600 | | let prBalanceRawX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [prBalanceRaw, priceAssetDcm], nil))) |
---|
601 | 601 | | let curPriceX18 = if ((poolLPBalance == 0)) |
---|
602 | 602 | | then zeroBigInt |
---|
603 | 603 | | else parseBigIntValue(asString(invoke(poolAddress, "calcPriceBigIntWrapperREADONLY", [toString(prBalanceRawX18), toString(amBalanceRawX18)], nil))) |
---|
604 | 604 | | let curPrice = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(curPriceX18), MULT8], nil)) |
---|
605 | 605 | | let inPrAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [inPrAssetAmt, priceAssetDcm], nil))) |
---|
606 | 606 | | let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, MULT18, curPriceX18) |
---|
607 | 607 | | let inAmAssetAmt = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(inAmAssetAmtX18), amtAssetDcm], nil)) |
---|
608 | 608 | | let res = invoke(poolAddress, "estimatePutOperationWrapperREADONLY", ["", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false], nil) |
---|
609 | 609 | | let $t02575826111 = match res { |
---|
610 | 610 | | case _ => |
---|
611 | 611 | | if (if (if ($isInstanceOf($match0._1, "Int")) |
---|
612 | 612 | | then if ($isInstanceOf($match0._3, "Int")) |
---|
613 | 613 | | then if ($isInstanceOf($match0._4, "Int")) |
---|
614 | 614 | | then if ($isInstanceOf($match0._5, "Int")) |
---|
615 | 615 | | then $isInstanceOf($match0._6, "Int") |
---|
616 | 616 | | else false |
---|
617 | 617 | | else false |
---|
618 | 618 | | else false |
---|
619 | 619 | | else false) |
---|
620 | 620 | | then (size($match0) == 13) |
---|
621 | 621 | | else false) |
---|
622 | 622 | | then { |
---|
623 | 623 | | let calcLpAmt = $match0._1 |
---|
624 | 624 | | let curPriceCalc = $match0._3 |
---|
625 | 625 | | let amBalance = $match0._4 |
---|
626 | 626 | | let prBalance = $match0._5 |
---|
627 | 627 | | let lpEmission = $match0._6 |
---|
628 | 628 | | $Tuple5(calcLpAmt, curPriceCalc, amBalance, prBalance, lpEmission) |
---|
629 | 629 | | } |
---|
630 | 630 | | else throw("Couldn't cast types") |
---|
631 | 631 | | } |
---|
632 | 632 | | let calcLpAmt = $t02575826111._1 |
---|
633 | 633 | | let curPriceCalc = $t02575826111._2 |
---|
634 | 634 | | let amBalance = $t02575826111._3 |
---|
635 | 635 | | let prBalance = $t02575826111._4 |
---|
636 | 636 | | let lpEmission = $t02575826111._5 |
---|
637 | 637 | | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d", toString(calcLpAmt), toString(curPrice), toString(amBalance), toString(prBalance), toString(lpEmission), poolStatus, toString(inAmAssetAmt), toString(inPrAssetAmt)], SEP)) |
---|
638 | 638 | | } |
---|
639 | 639 | | |
---|
640 | 640 | | |
---|
641 | 641 | | |
---|
642 | 642 | | @Callable(i) |
---|
643 | 643 | | func poolEvaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = { |
---|
644 | 644 | | let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(paymentLpAssetId))) |
---|
645 | 645 | | let res = invoke(poolAddress, "estimateGetOperationWrapperREADONLY", ["", paymentLpAssetId, paymentLpAmt, toString(poolAddress)], nil) |
---|
646 | 646 | | let $t02680627223 = match res { |
---|
647 | 647 | | case _ => |
---|
648 | 648 | | if (if (if ($isInstanceOf($match0._1, "Int")) |
---|
649 | 649 | | then if ($isInstanceOf($match0._2, "Int")) |
---|
650 | 650 | | then if ($isInstanceOf($match0._5, "Int")) |
---|
651 | 651 | | then if ($isInstanceOf($match0._6, "Int")) |
---|
652 | 652 | | then if ($isInstanceOf($match0._7, "Int")) |
---|
653 | 653 | | then if ($isInstanceOf($match0._8, "String")) |
---|
654 | 654 | | then $isInstanceOf($match0._9, "String") |
---|
655 | 655 | | else false |
---|
656 | 656 | | else false |
---|
657 | 657 | | else false |
---|
658 | 658 | | else false |
---|
659 | 659 | | else false |
---|
660 | 660 | | else false) |
---|
661 | 661 | | then (size($match0) == 10) |
---|
662 | 662 | | else false) |
---|
663 | 663 | | then { |
---|
664 | 664 | | let outAmAmt = $match0._1 |
---|
665 | 665 | | let outPrAmt = $match0._2 |
---|
666 | 666 | | let amBalance = $match0._5 |
---|
667 | 667 | | let prBalance = $match0._6 |
---|
668 | 668 | | let lpEmission = $match0._7 |
---|
669 | 669 | | let curPrice = $match0._8 |
---|
670 | 670 | | let poolStatus = $match0._9 |
---|
671 | 671 | | $Tuple7(outAmAmt, outPrAmt, amBalance, prBalance, lpEmission, curPrice, poolStatus) |
---|
672 | 672 | | } |
---|
673 | 673 | | else throw("Couldn't cast types") |
---|
674 | 674 | | } |
---|
675 | 675 | | let outAmAmt = $t02680627223._1 |
---|
676 | 676 | | let outPrAmt = $t02680627223._2 |
---|
677 | 677 | | let amBalance = $t02680627223._3 |
---|
678 | 678 | | let prBalance = $t02680627223._4 |
---|
679 | 679 | | let lpEmission = $t02680627223._5 |
---|
680 | 680 | | let curPrice = $t02680627223._6 |
---|
681 | 681 | | let poolStatus = $t02680627223._7 |
---|
682 | 682 | | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(outAmAmt), toString(outPrAmt), toString(amBalance), toString(prBalance), toString(lpEmission), curPrice, poolStatus], SEP)) |
---|
683 | 683 | | } |
---|
684 | 684 | | |
---|
685 | 685 | | |
---|
686 | 686 | | |
---|
687 | 687 | | @Callable(i) |
---|
688 | 688 | | func gwxUserInfoREADONLY (userAddress) = { |
---|
689 | 689 | | let gwxUserInfoLIST = asAnyList(invoke(boostingDapp, "gwxUserInfoREADONLY", [userAddress], nil)) |
---|
690 | 690 | | let gwxAmount = asInt(gwxUserInfoLIST[0]) |
---|
691 | 691 | | $Tuple2(nil, makeString(["%d", toString(gwxAmount)], SEP)) |
---|
692 | 692 | | } |
---|
693 | 693 | | |
---|
694 | 694 | | |
---|
695 | 695 | | |
---|
696 | 696 | | @Callable(i) |
---|
697 | 697 | | func unstakeAndGetOneTknV2 (poolAddress,unstakeAmount,outAssetId,minOutAmount) = { |
---|
698 | 698 | | let inv = invoke(addressFromStringValue(poolAddress), "unstakeAndGetOneTknV2", [unstakeAmount, outAssetId, minOutAmount], nil) |
---|
699 | 699 | | if ((inv == inv)) |
---|
700 | 700 | | then $Tuple2(nil, unit) |
---|
701 | 701 | | else throw("Strict value is not equal to itself.") |
---|
702 | 702 | | } |
---|
703 | 703 | | |
---|
704 | 704 | | |
---|
705 | 705 | | |
---|
706 | 706 | | @Callable(i) |
---|
707 | 707 | | func getKeysBulkInternal (currentIter,keys,resAcc) = if ((currentIter == size(keys))) |
---|
708 | 708 | | then $Tuple2(nil, resAcc) |
---|
709 | 709 | | else { |
---|
710 | 710 | | let k = split(keys[currentIter], "++") |
---|
711 | 711 | | let addr = addressFromStringValue(k[0]) |
---|
712 | 712 | | let key = k[1] |
---|
713 | 713 | | let type = k[2] |
---|
714 | 714 | | let val = getKey(addr, key, type) |
---|
715 | 715 | | let res = (resAcc :+ val) |
---|
716 | 716 | | let inv = invoke(this, "getKeysBulkInternal", [(currentIter + 1), keys, res], nil) |
---|
717 | 717 | | if ((inv == inv)) |
---|
718 | 718 | | then $Tuple2(nil, inv) |
---|
719 | 719 | | else throw("Strict value is not equal to itself.") |
---|
720 | 720 | | } |
---|
721 | 721 | | |
---|
722 | 722 | | |
---|
723 | 723 | | |
---|
724 | 724 | | @Callable(i) |
---|
725 | 725 | | func getKeysBulk (keys) = { |
---|
726 | 726 | | let res = invoke(this, "getKeysBulkInternal", [0, keys, nil], nil) |
---|
727 | 727 | | $Tuple2(nil, res) |
---|
728 | 728 | | } |
---|
729 | 729 | | |
---|
730 | 730 | | |
---|
731 | 731 | | |
---|
732 | 732 | | @Callable(i) |
---|
733 | 733 | | func setManager (pendingManagerPublicKey) = { |
---|
734 | 734 | | let checkCaller = mustManager(i) |
---|
735 | 735 | | if ((checkCaller == checkCaller)) |
---|
736 | 736 | | then { |
---|
737 | 737 | | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) |
---|
738 | 738 | | if ((checkManagerPublicKey == checkManagerPublicKey)) |
---|
739 | 739 | | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] |
---|
740 | 740 | | else throw("Strict value is not equal to itself.") |
---|
741 | 741 | | } |
---|
742 | 742 | | else throw("Strict value is not equal to itself.") |
---|
743 | 743 | | } |
---|
744 | 744 | | |
---|
745 | 745 | | |
---|
746 | 746 | | |
---|
747 | 747 | | @Callable(i) |
---|
748 | 748 | | func confirmManager () = { |
---|
749 | 749 | | let pm = pendingManagerPublicKeyOrUnit() |
---|
750 | 750 | | let hasPM = if (isDefined(pm)) |
---|
751 | 751 | | then true |
---|
752 | 752 | | else throw("No pending manager") |
---|
753 | 753 | | if ((hasPM == hasPM)) |
---|
754 | 754 | | then { |
---|
755 | 755 | | let checkPM = if ((i.callerPublicKey == value(pm))) |
---|
756 | 756 | | then true |
---|
757 | 757 | | else throw("You are not pending manager") |
---|
758 | 758 | | if ((checkPM == checkPM)) |
---|
759 | 759 | | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] |
---|
760 | 760 | | else throw("Strict value is not equal to itself.") |
---|
761 | 761 | | } |
---|
762 | 762 | | else throw("Strict value is not equal to itself.") |
---|
763 | 763 | | } |
---|
764 | 764 | | |
---|
765 | 765 | | |
---|
766 | 766 | | @Verifier(tx) |
---|
767 | 767 | | func verify () = { |
---|
768 | 768 | | let targetPublicKey = match managerPublicKeyOrUnit() { |
---|
769 | 769 | | case pk: ByteVector => |
---|
770 | 770 | | pk |
---|
771 | 771 | | case _: Unit => |
---|
772 | 772 | | tx.senderPublicKey |
---|
773 | 773 | | case _ => |
---|
774 | 774 | | throw("Match error") |
---|
775 | 775 | | } |
---|
776 | 776 | | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
777 | 777 | | } |
---|
778 | 778 | | |
---|