tx · 2dyj61ZeMCRoLBWuiThNkiWzgb3w3HMzZq7pMaXmkbeK

3NA6t3Dh9Zhv7sk86Sq99PNMeHynGr3947u:  -0.00500000 Waves

2023.03.20 10:03 [2498005] smart account 3NA6t3Dh9Zhv7sk86Sq99PNMeHynGr3947u > SELF 0.00000000 Waves

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

github/deemru/w8io/169f3d6 
51.68 ms