tx · Dw5HPqqhBvepzspaCV3PuvhK4BHpbVxt84H7oiRYqVi8

3N3PoX8z2Mvu5YbaqZmtyF3dRFjqvhRkB3M:  -0.01400000 Waves

2022.03.10 17:50 [1957993] smart account 3N3PoX8z2Mvu5YbaqZmtyF3dRFjqvhRkB3M > SELF 0.00000000 Waves

{ "type": 13, "id": "Dw5HPqqhBvepzspaCV3PuvhK4BHpbVxt84H7oiRYqVi8", "fee": 1400000, "feeAssetId": null, "timestamp": 1646923828876, "version": 2, "chainId": 84, "sender": "3N3PoX8z2Mvu5YbaqZmtyF3dRFjqvhRkB3M", "senderPublicKey": "FWZMxrtn6KRrWMPXmQPqDg5eRzwB2YvHhMjMJpwnLmBi", "proofs": [ "2iSL6zsw2HtdmcpW2gx4UErtsfSh3b5uqw42adJt1Dnh7GVDLX9hYLoQAQvmYkDKicb4whnTLUCGdHYdFeBoaa95" ], "script": "base64:AAIFAAAAAAAAB4oIAhIDCgEIEgASAwoBCBIDCgEIEgAaFgoBQRIRaW50ZXJuYWxCYXNlQXNzZXQaEgoBQhINa2V5UG9vbENvbmZpZxoOCgFDEglpQW10QXNzZXQaEAoBRBILaVByaWNlQXNzZXQaGAoBRRITa2V5QWxsUG9vbHNTaHV0ZG93bhoSCgFGEg1rZXlQb29sV2VpZ2h0GhQKAUcSD2NvbnRyYWN0QWRkcmVzcxoYCgFIEhNrZXlNYW5hZ2VyUHVibGljS2V5Gh8KAUkSGmtleVBlbmRpbmdNYW5hZ2VyUHVibGljS2V5GhQKAUoSD2ZhY3RvcnlDb250cmFjdBoTCgFLEg5jb252ZXJ0QXNzZXRJZBoWCgFMEhFkYXRhUHV0QWN0aW9uSW5mbxoOCgFNEglpbkFzc2V0SWQaDwoBThIKaW5Bc3NldEFtdBoNCgFPEgh0eEhlaWdodBoQCgFQEgt0eFRpbWVzdGFtcBoZCgFREhRkYXRhSW52ZXN0QWN0aW9uSW5mbxoWCgFSEhFvdXRBbW91bnRBc3NldEFtdBoVCgFTEhBvdXRQ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G8gaXRzZWxmLgAAAAJhZgEAAAAOY29uZmlybU1hbmFnZXIAAAAABAAAAAJhTgkBAAAAAmFkAAAAAAQAAAACYU8DCQEAAAAJaXNEZWZpbmVkAAAAAQUAAAACYU4GCQAAAgAAAAECAAAAEk5vIHBlbmRpbmcgbWFuYWdlcgMJAAAAAAAAAgUAAAACYU8FAAAAAmFPBAAAAAJhUAMJAAAAAAAAAggFAAAAAmFmAAAAD2NhbGxlclB1YmxpY0tleQkBAAAABXZhbHVlAAAAAQUAAAACYU4GCQAAAgAAAAECAAAAG1lvdSBhcmUgbm90IHBlbmRpbmcgbWFuYWdlcgMJAAAAAAAAAgUAAAACYVAFAAAAAmFQCQAETAAAAAIJAQAAAAtTdHJpbmdFbnRyeQAAAAIJAQAAAAFIAAAAAAkAAlgAAAABCQEAAAAFdmFsdWUAAAABBQAAAAJhTgkABEwAAAACCQEAAAALRGVsZXRlRW50cnkAAAABCQEAAAABSQAAAAAFAAAAA25pbAkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4JAAACAAAAAQIAAAAkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAAAAAQAAAAJhUQEAAAACYVIAAAAABAAAAAJhUwQAAAABVgkBAAAAAmFiAAAAAAMJAAABAAAAAgUAAAABVgIAAAAKQnl0ZVZlY3RvcgQAAAACYWgFAAAAAVYFAAAAAmFoAwkAAAEAAAACBQAAAAFWAgAAAARVbml0CAUAAAACYVEAAAAPc2VuZGVyUHVibGljS2V5CQAAAgAAAAECAAAAC01hdGNoIGVycm9yCQAB9AAAAAMIBQAAAAJhUQAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAmFRAAAABnByb29mcwAAAAAAAAAAAAUAAAACYVP9P6oS", "height": 1957993, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6yAo28f4tA5JpJof7PCMZ2ipYSe24GhZLhVwkZnvPN9k Next: 12fwpVRbQWHR5SK2n69N2w7uASeGUsMqxMHAUhRGWKZA Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let SCALE8 = 8
5-
6-let MULT8 = 100000000
7-
8-let SCALE18 = 18
9-
10-let MULT18 = toBigInt(1000000000000000000)
11-
124 let SEP = "__"
135
14-let POOLWEIGHTMULT = MULT8
6+let scale8 = 100000000
157
16-let zeroBigInt = toBigInt(0)
8+let poolStatsPriceKey = 4
179
1810 let idxPoolAddress = 1
1911
3527
3628 let idxLPAssetDcm = 10
3729
38-func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined"))
30+let idxMatcherPublicKey = 11
31+
32+func keyRegisterPut (poolAddress,txId) = ((("%s%s%s__P__" + poolAddress) + "__") + txId)
3933
4034
41-func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined"))
35+func keyRegisterInvest (poolAddress,txId) = ((("%s%s%s__invest__" + poolAddress) + "__") + txId)
4236
4337
44-func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0)
38+func keyPoolTotalAmtByAsset (poolAddress,assetId) = ((("%s%s%s__total__" + poolAddress) + "__") + assetId)
4539
4640
47-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined"))
41+func keyFactoryContract () = "%s__factoryContract"
4842
4943
50-func asAnyList (val) = match val {
51- case valAnyLyst: List[Any] =>
52- valAnyLyst
53- case _ =>
54- throw("fail to cast into List[Any]")
55-}
44+func keySlippageAmtPerAssetCumulative (poolAddress,assetId) = (((("%s%s%s__" + poolAddress) + "__") + assetId) + "__slippageCumulative")
5645
5746
58-func asInt (val) = match val {
59- case valInt: Int =>
60- valInt
61- case _ =>
62- throw("fail to cast into Int")
63-}
47+func keyFactoryConfig () = "%s__factoryConfig"
48+
49+
50+func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2PoolAssets")
51+
52+
53+func keyMappingsInternal2baseAssetId (internalBaseAsset) = ("%s%s%d__mappings__internal2baseAssetId__" + toString(internalBaseAsset))
54+
55+
56+func keyPoolConfig (iAmtAsset,iPriceAsset) = (((("%d%d%s__" + iAmtAsset) + "__") + iPriceAsset) + "__config")
57+
58+
59+func keyAllPoolsShutdown () = "%s__shutdown"
60+
61+
62+func keyPoolWeight (contractAddress) = ("%s%s__poolWeight__" + contractAddress)
63+
64+
65+func keyManagerPublicKey () = "%s__managerPublicKey"
66+
67+
68+func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
69+
70+
71+let factoryContract = addressFromStringValue(valueOrErrorMessage(getString(this, keyFactoryContract()), "No Factory Acc found."))
72+
73+func convertAssetId (assetId) = if (!(isDefined(assetId)))
74+ then "WAVES"
75+ else assetId
76+
77+
78+func dataPutActionInfo (inAssetId,inAssetAmt,txHeight,txTimestamp) = makeString(["%s%d%d%d", inAssetId, toString(inAssetAmt), toString(txHeight), toString(txTimestamp)], SEP)
79+
80+
81+func dataInvestActionInfo (outAmountAssetAmt,outPriceAssetAmt,txHeight,txTimestamp) = makeString(["%d%d%d%d", toString(outAmountAssetAmt), toString(outPriceAssetAmt), toString(txHeight), toString(txTimestamp)], SEP)
6482
6583
6684 func asString (val) = match val {
7189 }
7290
7391
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-let factoryDapp = readFactoryAddressOrFail()
229-
230-let factoryCfg = readFactoryCfgOrFail(factoryDapp)
231-
232-let emissionDapp = getEmissionAddressOrFail(factoryCfg)
233-
234-let stakingDapp = getStakingAddressOrFail(factoryCfg)
235-
236-let gwxRewardDapp = getGwxRewardAddressOrFail(factoryCfg)
237-
238-let boostingDapp = getBoostingAddressOrFail(factoryCfg)
239-
240-func internalCurrentRewardRate (lpAssetId) = {
241- let poolAddressStr = getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAssetId))
242- let poolWeightMult = MULT8
243- let poolWeight = getIntegerValue(factoryDapp, keyFactoryPoolWeight(poolAddressStr))
244- let wxEmissionPerBlock = getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent())
245- let wxEmissionPerBlockMax = getIntOrFail(emissionDapp, keyEmissionRatePerBlockMaxCurrent())
246- let boostMaxCoeff = 3
247- let poolWxEmissionPerBlock = (fraction(wxEmissionPerBlock, poolWeight, poolWeightMult) / boostMaxCoeff)
248- let poolWxEmissionPerBlockMax = fraction(wxEmissionPerBlockMax, poolWeight, poolWeightMult)
249- let maxFactor = (boostMaxCoeff * MULT8)
250- let totalLpStaked = getIntOrZero(stakingDapp, keyStakedTotal(lpAssetId))
251-[poolWxEmissionPerBlock, maxFactor, totalLpStaked]
252- }
253-
254-
255-func calcGwxAmountStartREADONLY (lockAmount,lockDuration,maxLockDuration) = {
256- let coeffX8 = fraction(lockDuration, MULT8, maxLockDuration)
257- let gWxAmountStart = fraction(lockAmount, coeffX8, MULT8)
258-[gWxAmountStart]
259- }
92+func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale)
26093
26194
26295 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
297130
298131
299132 @Callable(i)
300-func constructor (factoryAddress) = if ((i.caller != this))
301- then throw("not authorized")
302- else [StringEntry(keyFactoryAddress(), factoryAddress)]
303-
304-
305-
306-@Callable(i)
307-func currentRewardRateREADONLY (lpAssetId) = {
308- let rewardData = internalCurrentRewardRate(lpAssetId)
309- let wxEmissionPerBlock = rewardData[0]
310- let maxFactor = rewardData[1]
311- let totalLpStaked = rewardData[2]
312- $Tuple2(nil, makeString(["%d%d%d", toString(wxEmissionPerBlock), toString(maxFactor), toString(totalLpStaked)], SEP))
133+func constructor (factoryContract) = {
134+ let checkCaller = mustManager(i)
135+ if ((checkCaller == checkCaller))
136+ then [StringEntry(keyFactoryContract(), factoryContract)]
137+ else throw("Strict value is not equal to itself.")
313138 }
314139
315140
316141
317142 @Callable(i)
318-func currentUserRewardRateREADONLY (lpAssetId,userAddress) = {
319- let rewardData = internalCurrentRewardRate(lpAssetId)
320- let wxEmissionPerBlock = rewardData[0]
321- let maxFactor = rewardData[1]
322- let totalLpStaked = rewardData[2]
323- let lpStakedByUser = getIntOrZero(stakingDapp, keyStakedByUser(userAddress, lpAssetId))
324- let userClaimInfo = split(asString(invoke(stakingDapp, "claimWxREADONLY", [lpAssetId, userAddress], nil)), SEP)
325- let minRewardPart = valueOrErrorMessage(parseInt(userClaimInfo[5]), "couldn't parse minRewardPart")
326- let boostRewardPart = valueOrErrorMessage(parseInt(userClaimInfo[6]), "couldn't parse boostRewardPart")
327- let debug = userClaimInfo[7]
328- let boostingPower = if ((boostRewardPart == 0))
329- then (1 * MULT8)
330- else fraction((minRewardPart + boostRewardPart), MULT8, minRewardPart)
331- $Tuple2(nil, makeString(["%d%d%d%d%d%s", toString(wxEmissionPerBlock), toString(maxFactor), toString(totalLpStaked), toString(lpStakedByUser), toString(boostingPower), debug], SEP))
143+func put () = {
144+ let pool = toString(i.caller)
145+ let pmtAmtAsset = value(i.payments[0])
146+ let pmtAssetId = if (!(isDefined(pmtAmtAsset.assetId)))
147+ then "WAVES"
148+ else toBase58String(value(pmtAmtAsset.assetId))
149+ let pmtAssetAmt = pmtAmtAsset.amount
150+ let poolAssets = split(valueOrErrorMessage(getString(factoryContract, keyMappingPoolContractAddressToPoolAssets(pool)), "Invalid caller"), SEP)
151+ let amountAssetId = parseIntValue(poolAssets[1])
152+ let priceAssetId = parseIntValue(poolAssets[2])
153+ let amountAsset = valueOrErrorMessage(getString(factoryContract, keyMappingsInternal2baseAssetId(amountAssetId)), "Cannot find asset")
154+ let priceAsset = valueOrErrorMessage(getString(factoryContract, keyMappingsInternal2baseAssetId(priceAssetId)), "Cannot find asset")
155+ let totalAmt = valueOrElse(getInteger(this, keyPoolTotalAmtByAsset(pool, pmtAssetId)), 0)
156+ let cumulativeSlippageAmt = valueOrElse(getInteger(this, keySlippageAmtPerAssetCumulative(pool, pmtAssetId)), 0)
157+[StringEntry(keyRegisterPut(pool, toBase58String(i.transactionId)), dataPutActionInfo(pmtAssetId, pmtAssetAmt, height, lastBlock.timestamp)), IntegerEntry(keyPoolTotalAmtByAsset(pool, pmtAssetId), (totalAmt + pmtAssetAmt)), IntegerEntry(keySlippageAmtPerAssetCumulative(pool, pmtAssetId), (cumulativeSlippageAmt + pmtAssetAmt))]
332158 }
333159
334160
335161
336162 @Callable(i)
337-func claimedRewardREADONLY (userAddress) = {
338- let lpList = readLpList()
339- let prefix = "%s%d%d%d%s"
340- func claimedRewardByLpAggregator (resultStr,nextLp) = {
341- let claimedByUserMinRewardKEY = keyClaimedByUserMinReward(nextLp, userAddress)
342- let claimedByUserBoostRewardKEY = keyClaimedByUserBoostReward(nextLp, userAddress)
343- let minRewardClaimed = valueOrElse(getInteger(stakingDapp, claimedByUserMinRewardKEY), 0)
344- let boostRewardClaimed = valueOrElse(getInteger(stakingDapp, claimedByUserBoostRewardKEY), 0)
345- let gFeeClaimed = 0
346- makeString([(prefix + resultStr), nextLp, toString(minRewardClaimed), toString(boostRewardClaimed), toString(gFeeClaimed), "end"], SEP)
347- }
348-
349- let result = {
350- let $l = lpList
351- let $s = size($l)
352- let $acc0 = "%s"
353- func $f0_1 ($a,$i) = if (($i >= $s))
354- then $a
355- else claimedRewardByLpAggregator($a, $l[$i])
356-
357- func $f0_2 ($a,$i) = if (($i >= $s))
358- then $a
359- else throw("List size exceeds 10")
360-
361- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
362- }
363- $Tuple2(nil, ((result + SEP) + userAddress))
364- }
365-
366-
367-
368-@Callable(i)
369-func calcBoostREADONLY (deltaWxAmount,deltaLockPeriodInBlocks,deltaLpAmount,lpAssetIdOpt,userAddressOpt) = {
370- let mathDapp = gwxRewardDapp
371- let EMPTYSTR = "empty"
372- let maxLockDurationInBlocks = parseIntValue(split(getStringByAddressOrFail(boostingDapp, keyBoostCfg()), SEP)[4])
373- let lpAssetIdStr = if ((lpAssetIdOpt == ""))
374- then EMPTYSTR
375- else lpAssetIdOpt
376- let userAddressStr = if ((userAddressOpt == ""))
377- then EMPTYSTR
378- else userAddressOpt
379- let userNumStr = valueOrElse(getString(boostingDapp, keyUser2NumMapping(userAddressOpt)), EMPTYSTR)
380- let userAmount = valueOrElse(getInteger(boostingDapp, keyLockParamUserAmount(userNumStr)), 0)
381- let lockStart = valueOrElse(getInteger(boostingDapp, keyLockParamStartBlock(userNumStr)), height)
382- let lockDuration = valueOrElse(getInteger(boostingDapp, keyLockParamDuration(userNumStr)), 0)
383- let lockEnd = (lockStart + lockDuration)
384- let remainingDuration = max([(lockEnd - height), 0])
385- let userAmountNew = (userAmount + deltaWxAmount)
386- let lockDurationNew = min([(remainingDuration + deltaLockPeriodInBlocks), maxLockDurationInBlocks])
387- let userCurrgWxAmount = asInt(asAnyList(invoke(boostingDapp, "gwxUserInfoREADONLY", [userAddressStr], nil))[0])
388- let gWxAmountStartNew = calcGwxAmountStartREADONLY(userAmountNew, lockDurationNew, maxLockDurationInBlocks)[0]
389- let gWxParamsResultList = asAnyList(invoke(mathDapp, "calcGwxParamsREADONLY", [gWxAmountStartNew, height, lockDurationNew], nil))
390- let gWxAmountDiff = (gWxAmountStartNew - userCurrgWxAmount)
391- let k = asInt(gWxParamsResultList[0])
392- let b = asInt(gWxParamsResultList[1])
393- let period = toString(asInt(gWxParamsResultList[2]))
394- let totalMaxBoostIntegralKEY = keyTotalMaxBoostINTEGRAL()
395- let totalCachedGwxKEY = keyTotalCachedGwx()
396- let userMaxBoostIntNew = ((gWxAmountStartNew * lockDurationNew) / 2)
397- let totalMaxBoostInt = getIntOrZero(boostingDapp, totalMaxBoostIntegralKEY)
398- let totalCachedGwx = valueOrElse(getInteger(boostingDapp, totalCachedGwxKEY), 0)
399- let MULT3 = 1000
400- let wxEmissionPerBlockX3 = (getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent()) * MULT3)
401- let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr)
402- let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
403- let stakedByUser = readStaked(stakingDapp, stakedByUserKEY)
404- let stakedTotal = readStaked(stakingDapp, stakedTotalKEY)
405- let stakedByUserNew = (stakedByUser + deltaLpAmount)
406- let stakedTotalNew = (stakedTotal + deltaLpAmount)
407- let poolWeight = if ((lpAssetIdStr != EMPTYSTR))
408- then {
409- let poolAddressStr = valueOrErrorMessage(getString(factoryDapp, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr))
410- getIntegerValue(factoryDapp, keyFactoryPoolWeight(poolAddressStr))
411- }
412- else 0
413- let poolWxEmissionPerBlockX3 = fraction(wxEmissionPerBlockX3, poolWeight, (POOLWEIGHTMULT * 3))
414- let wxPerLpX3 = if ((stakedTotalNew != 0))
415- then fraction(poolWxEmissionPerBlockX3, MULT8, stakedTotalNew)
416- else 0
417- let userWxPerBlockX3 = fraction(wxPerLpX3, stakedByUserNew, MULT8)
418- let boostEmissionPerBlockX3 = (poolWxEmissionPerBlockX3 * 2)
419- let tmpUserBoostPerBlockX3 = fraction(gWxAmountStartNew, boostEmissionPerBlockX3, (totalCachedGwx + gWxAmountDiff))
420- let userBoostPerBlockX3 = min([tmpUserBoostPerBlockX3, (userWxPerBlockX3 * 2)])
421- let boostCoeff = if ((userWxPerBlockX3 == 0))
422- then (1 * MULT8)
423- else fraction((userBoostPerBlockX3 + userWxPerBlockX3), MULT8, userWxPerBlockX3)
424- let debug = makeString([("lpAssetIdStr=" + lpAssetIdStr), ("userAddressStr=" + userAddressStr), ("userNumStr=" + userNumStr), ("userAmount=" + toString(userAmount)), ("userAmountNew=" + toString(userAmountNew)), ("lockDurationNew=" + toString(lockDurationNew)), ("gWxAmountStart=" + toString(gWxAmountStartNew)), ("tmpUserBoostPerBlockX3=" + toString(tmpUserBoostPerBlockX3)), ("stakedByUserNew=" + toString(stakedByUserNew)), ("stakedTotalNew=" + toString(stakedTotalNew)), ("poolWeight=" + toString(poolWeight)), ("wxPerLpX3=" + toString(wxPerLpX3)), ("poolWxEmissionPerBlockX3=" + toString(poolWxEmissionPerBlockX3)), ("userWxPerBlockX3=" + toString(userWxPerBlockX3)), ("gWxAmountDiff=" + toString(gWxAmountDiff)), ("totalCachedGwx=" + toString(totalCachedGwx)), ("userCurrgWxAmount=" + toString(userCurrgWxAmount))], "::")
425- $Tuple2(nil, makeString(["%d%d%s", toString(gWxAmountStartNew), toString(boostCoeff), debug], SEP))
426- }
427-
428-
429-
430-@Callable(i)
431-func wxEmissionStatsREADONLY () = {
432- let ONEMULT = toString(MULT8)
433- let ONE = "1"
434- let wxEmissionPerBlock = getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent())
435- let emissionStartBlock = getIntOrFail(emissionDapp, keyEmissionStartBlock())
436- let passedBlocks = if ((emissionStartBlock > height))
437- then 0
438- else (height - emissionStartBlock)
439- let teamEmDuration = (1440 * 365)
440- let teamEmMax = (201000000 * MULT8)
441- let teamEm = if ((passedBlocks > teamEmDuration))
442- then teamEmMax
443- else fraction(teamEmMax, passedBlocks, teamEmDuration)
444- let totalWxReleased = ((wxEmissionPerBlock * passedBlocks) + teamEm)
445- let totalWxLocked = getIntOrZero(boostingDapp, keyBoostingLockParamTotalAmount())
446- let locksDurationSumInBlocks = getIntOrZero(boostingDapp, keyBoostingStatsLocksDurationSumInBlocks())
447- let locksCount = getIntOrZero(boostingDapp, keyBoostingStatsLocksCount())
448- $Tuple2(nil, makeString(["%d%d%d%d", toString(totalWxReleased), toString(totalWxLocked), toString(locksDurationSumInBlocks), toString(locksCount)], SEP))
449- }
450-
451-
452-
453-@Callable(i)
454-func poolStatsREADONLY (lpAsset) = {
455- let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset)))
456- let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil))
457- let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId]))
458- let amtAssetId = asString(cfg[idxAmtAssetId])
459- let priceAssetId = asString(cfg[idxPriceAssetId])
460- let iAmtAssetId = asString(cfg[idxIAmtAssetId])
461- let iPriceAssetId = asString(cfg[idxIPriceAssetId])
462- let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm]))
463- let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm]))
464- let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
465- let accAmtAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amtAssetId], nil))
466- let accPriceAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [priceAssetId], nil))
467- let pricesList = if ((poolLPBalance == 0))
468- then [toString(zeroBigInt), toString(zeroBigInt), toString(zeroBigInt)]
469- else asAnyList(invoke(poolAddress, "calcPricesWrapperREADONLY", [accAmtAssetBalance, accPriceAssetBalance, poolLPBalance], nil))
470- let curPrice = 0
471- let lpAmtAssetShare = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [pricesList[1], MULT8], nil))
472- let lpPriceAssetShare = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [pricesList[2], MULT8], nil))
473- let poolWeight = getIntegerValue(factoryDapp, keyFactoryPoolWeight(toString(poolAddress)))
474- $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(accAmtAssetBalance), toString(accPriceAssetBalance), toString(poolLPBalance), toString(curPrice), toString(lpAmtAssetShare), toString(lpPriceAssetShare), toString(poolWeight)], SEP))
475- }
476-
477-
478-
479-@Callable(i)
480-func poolEvaluatePutByAmountAssetREADONLY (lpAsset,inAmAssetAmt) = {
481- let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset)))
482- let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil))
483- let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId]))
484- let amAssetIdStr = asString(cfg[idxAmtAssetId])
485- let amAssetId = fromBase58String(amAssetIdStr)
486- let prAssetIdStr = asString(cfg[idxPriceAssetId])
487- let prAssetId = fromBase58String(prAssetIdStr)
488- let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm]))
489- let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm]))
490- let poolStatus = asString(cfg[idxPoolStatus])
491- let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
492- let accAmtAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amAssetIdStr], nil))
493- let accPriceAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [prAssetIdStr], nil))
494- let amtAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [accAmtAssetBalance, amtAssetDcm], nil)))
495- let priceAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [accPriceAssetBalance, priceAssetDcm], nil)))
496- let curPriceX18 = if ((poolLPBalance == 0))
497- then zeroBigInt
498- else parseBigIntValue(asString(invoke(poolAddress, "calcPriceBigIntWrapperREADONLY", [toString(priceAssetAmtX18), toString(amtAssetAmtX18)], nil)))
499- let curPrice = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(curPriceX18), MULT8], nil))
500- let inAmAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [inAmAssetAmt, amtAssetDcm], nil)))
501- let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, MULT18)
502- let inPrAssetAmt = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(inPrAssetAmtX18), priceAssetDcm], nil))
503- let res = invoke(poolAddress, "estimatePutOperationWrapperREADONLY", ["", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false], nil)
504- let $t02282123174 = match res {
505- case _ =>
506- if (if ($isInstanceOf($match0._1, "Int"))
507- then if ($isInstanceOf($match0._3, "Int"))
508- then if ($isInstanceOf($match0._4, "Int"))
509- then if ($isInstanceOf($match0._5, "Int"))
510- then $isInstanceOf($match0._6, "Int")
511- else false
512- else false
513- else false
514- else false)
515- then {
516- let calcLpAmt = $match0._1
517- let curPriceCalc = $match0._3
518- let amBalance = $match0._4
519- let prBalance = $match0._5
520- let lpEmission = $match0._6
521- $Tuple5(calcLpAmt, curPriceCalc, amBalance, prBalance, lpEmission)
522- }
523- else throw("Couldn't cast types")
524- }
525- let calcLpAmt = $t02282123174._1
526- let curPriceCalc = $t02282123174._2
527- let amBalance = $t02282123174._3
528- let prBalance = $t02282123174._4
529- let lpEmission = $t02282123174._5
530- $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))
531- }
532-
533-
534-
535-@Callable(i)
536-func poolEvaluatePutByPriceAssetREADONLY (lpAsset,inPrAssetAmt) = {
537- let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset)))
538- let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil))
539- let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId]))
540- let amAssetIdStr = asString(cfg[idxAmtAssetId])
541- let amAssetId = fromBase58String(amAssetIdStr)
542- let prAssetIdStr = asString(cfg[idxPriceAssetId])
543- let prAssetId = fromBase58String(prAssetIdStr)
544- let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm]))
545- let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm]))
546- let poolStatus = asString(cfg[idxPoolStatus])
547- let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
548- let amBalanceRaw = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amAssetIdStr], nil))
549- let prBalanceRaw = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [prAssetIdStr], nil))
550- let amBalanceRawX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [amBalanceRaw, amtAssetDcm], nil)))
551- let prBalanceRawX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [prBalanceRaw, priceAssetDcm], nil)))
552- let curPriceX18 = if ((poolLPBalance == 0))
553- then zeroBigInt
554- else parseBigIntValue(asString(invoke(poolAddress, "calcPriceBigIntWrapperREADONLY", [toString(prBalanceRawX18), toString(amBalanceRawX18)], nil)))
555- let curPrice = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(curPriceX18), MULT8], nil))
556- let inPrAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [inPrAssetAmt, priceAssetDcm], nil)))
557- let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, MULT18, curPriceX18)
558- let inAmAssetAmt = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(inAmAssetAmtX18), amtAssetDcm], nil))
559- let res = invoke(poolAddress, "estimatePutOperationWrapperREADONLY", ["", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false], nil)
560- let $t02574726100 = match res {
561- case _ =>
562- if (if ($isInstanceOf($match0._1, "Int"))
563- then if ($isInstanceOf($match0._3, "Int"))
564- then if ($isInstanceOf($match0._4, "Int"))
565- then if ($isInstanceOf($match0._5, "Int"))
566- then $isInstanceOf($match0._6, "Int")
567- else false
568- else false
569- else false
570- else false)
571- then {
572- let calcLpAmt = $match0._1
573- let curPriceCalc = $match0._3
574- let amBalance = $match0._4
575- let prBalance = $match0._5
576- let lpEmission = $match0._6
577- $Tuple5(calcLpAmt, curPriceCalc, amBalance, prBalance, lpEmission)
578- }
579- else throw("Couldn't cast types")
580- }
581- let calcLpAmt = $t02574726100._1
582- let curPriceCalc = $t02574726100._2
583- let amBalance = $t02574726100._3
584- let prBalance = $t02574726100._4
585- let lpEmission = $t02574726100._5
586- $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))
587- }
588-
589-
590-
591-@Callable(i)
592-func poolEvaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = {
593- let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(paymentLpAssetId)))
594- let res = invoke(poolAddress, "estimateGetOperationWrapperREADONLY", ["", paymentLpAssetId, paymentLpAmt, toString(poolAddress)], nil)
595- let $t02679527212 = match res {
596- case _ =>
597- if (if ($isInstanceOf($match0._1, "Int"))
598- then if ($isInstanceOf($match0._2, "Int"))
599- then if ($isInstanceOf($match0._5, "Int"))
600- then if ($isInstanceOf($match0._6, "Int"))
601- then if ($isInstanceOf($match0._7, "Int"))
602- then if ($isInstanceOf($match0._8, "String"))
603- then $isInstanceOf($match0._9, "String")
604- else false
605- else false
606- else false
607- else false
608- else false
609- else false)
610- then {
611- let outAmAmt = $match0._1
612- let outPrAmt = $match0._2
613- let amBalance = $match0._5
614- let prBalance = $match0._6
615- let lpEmission = $match0._7
616- let curPrice = $match0._8
617- let poolStatus = $match0._9
618- $Tuple7(outAmAmt, outPrAmt, amBalance, prBalance, lpEmission, curPrice, poolStatus)
619- }
620- else throw("Couldn't cast types")
621- }
622- let outAmAmt = $t02679527212._1
623- let outPrAmt = $t02679527212._2
624- let amBalance = $t02679527212._3
625- let prBalance = $t02679527212._4
626- let lpEmission = $t02679527212._5
627- let curPrice = $t02679527212._6
628- let poolStatus = $t02679527212._7
629- $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(outAmAmt), toString(outPrAmt), toString(amBalance), toString(prBalance), toString(lpEmission), curPrice, poolStatus], SEP))
630- }
631-
632-
633-
634-@Callable(i)
635-func gwxUserInfoREADONLY (userAddress) = {
636- let gwxUserInfoLIST = asAnyList(invoke(boostingDapp, "gwxUserInfoREADONLY", [userAddress], nil))
637- let gwxAmount = asInt(gwxUserInfoLIST[0])
638- $Tuple2(nil, makeString(["%d", toString(gwxAmount)], SEP))
163+func invest (poolAddressStr) = {
164+ let poolAddress = valueOrErrorMessage(addressFromString(poolAddressStr), "invalid pool address")
165+ let poolAssets = split(valueOrErrorMessage(getString(factoryContract, keyMappingPoolContractAddressToPoolAssets(poolAddressStr)), "Invalid pool passed."), SEP)
166+ let amId = valueOrErrorMessage(getString(factoryContract, keyMappingsInternal2baseAssetId(parseIntValue(poolAssets[1]))), "No asset mapping found")
167+ let prId = valueOrErrorMessage(getString(factoryContract, keyMappingsInternal2baseAssetId(parseIntValue(poolAssets[2]))), "No asset mapping found")
168+ let amBalance = valueOrElse(getInteger(this, keyPoolTotalAmtByAsset(poolAddressStr, amId)), 0)
169+ let prBalance = valueOrElse(getInteger(this, keyPoolTotalAmtByAsset(poolAddressStr, prId)), 0)
170+ let estByPrResult = invoke(poolAddress, "evaluatePutByPriceAssetREADONLY", [prBalance], nil)
171+ let estByAmResult = invoke(poolAddress, "evaluatePutByAmountAssetREADONLY", [amBalance], nil)
172+ let IdxEstAmAmount = 7
173+ let IdxEstPrAmount = 8
174+ let estAmAmt = valueOrErrorMessage(parseIntValue(split(asString(estByPrResult), SEP)[IdxEstAmAmount]), "fail to parse estimated amAsset amount")
175+ let estPrAmt = valueOrErrorMessage(parseIntValue(split(asString(estByAmResult), SEP)[IdxEstPrAmount]), "fail to parse estimated prAsset amount")
176+ let $t066436744 = if ((amBalance >= estAmAmt))
177+ then $Tuple2(estAmAmt, prBalance)
178+ else $Tuple2(amBalance, estPrAmt)
179+ let amAmt = $t066436744._1
180+ let prAmt = $t066436744._2
181+ let amAssetId = if ((amId == "WAVES"))
182+ then unit
183+ else fromBase58String(amId)
184+ let prAssetId = if ((prId == "WAVES"))
185+ then unit
186+ else fromBase58String(prId)
187+ let lpPut = invoke(poolAddress, "putForFree", [1000], [AttachedPayment(amAssetId, amAmt), AttachedPayment(prAssetId, prAmt)])
188+ if ((lpPut == lpPut))
189+ then [StringEntry(keyRegisterInvest(poolAddressStr, toBase58String(i.transactionId)), dataInvestActionInfo(amAmt, prAmt, height, lastBlock.timestamp)), IntegerEntry(keyPoolTotalAmtByAsset(poolAddressStr, amId), (amBalance - amAmt)), IntegerEntry(keyPoolTotalAmtByAsset(poolAddressStr, prId), (prBalance - prAmt))]
190+ else throw("Strict value is not equal to itself.")
639191 }
640192
641193
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let SCALE8 = 8
5-
6-let MULT8 = 100000000
7-
8-let SCALE18 = 18
9-
10-let MULT18 = toBigInt(1000000000000000000)
11-
124 let SEP = "__"
135
14-let POOLWEIGHTMULT = MULT8
6+let scale8 = 100000000
157
16-let zeroBigInt = toBigInt(0)
8+let poolStatsPriceKey = 4
179
1810 let idxPoolAddress = 1
1911
2012 let idxPoolStatus = 2
2113
2214 let idxPoolLPAssetId = 3
2315
2416 let idxAmtAssetId = 4
2517
2618 let idxPriceAssetId = 5
2719
2820 let idxAmtAssetDcm = 6
2921
3022 let idxPriceAssetDcm = 7
3123
3224 let idxIAmtAssetId = 8
3325
3426 let idxIPriceAssetId = 9
3527
3628 let idxLPAssetDcm = 10
3729
38-func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined"))
30+let idxMatcherPublicKey = 11
31+
32+func keyRegisterPut (poolAddress,txId) = ((("%s%s%s__P__" + poolAddress) + "__") + txId)
3933
4034
41-func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined"))
35+func keyRegisterInvest (poolAddress,txId) = ((("%s%s%s__invest__" + poolAddress) + "__") + txId)
4236
4337
44-func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0)
38+func keyPoolTotalAmtByAsset (poolAddress,assetId) = ((("%s%s%s__total__" + poolAddress) + "__") + assetId)
4539
4640
47-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined"))
41+func keyFactoryContract () = "%s__factoryContract"
4842
4943
50-func asAnyList (val) = match val {
51- case valAnyLyst: List[Any] =>
52- valAnyLyst
53- case _ =>
54- throw("fail to cast into List[Any]")
55-}
44+func keySlippageAmtPerAssetCumulative (poolAddress,assetId) = (((("%s%s%s__" + poolAddress) + "__") + assetId) + "__slippageCumulative")
5645
5746
58-func asInt (val) = match val {
59- case valInt: Int =>
60- valInt
61- case _ =>
62- throw("fail to cast into Int")
63-}
47+func keyFactoryConfig () = "%s__factoryConfig"
48+
49+
50+func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2PoolAssets")
51+
52+
53+func keyMappingsInternal2baseAssetId (internalBaseAsset) = ("%s%s%d__mappings__internal2baseAssetId__" + toString(internalBaseAsset))
54+
55+
56+func keyPoolConfig (iAmtAsset,iPriceAsset) = (((("%d%d%s__" + iAmtAsset) + "__") + iPriceAsset) + "__config")
57+
58+
59+func keyAllPoolsShutdown () = "%s__shutdown"
60+
61+
62+func keyPoolWeight (contractAddress) = ("%s%s__poolWeight__" + contractAddress)
63+
64+
65+func keyManagerPublicKey () = "%s__managerPublicKey"
66+
67+
68+func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
69+
70+
71+let factoryContract = addressFromStringValue(valueOrErrorMessage(getString(this, keyFactoryContract()), "No Factory Acc found."))
72+
73+func convertAssetId (assetId) = if (!(isDefined(assetId)))
74+ then "WAVES"
75+ else assetId
76+
77+
78+func dataPutActionInfo (inAssetId,inAssetAmt,txHeight,txTimestamp) = makeString(["%s%d%d%d", inAssetId, toString(inAssetAmt), toString(txHeight), toString(txTimestamp)], SEP)
79+
80+
81+func dataInvestActionInfo (outAmountAssetAmt,outPriceAssetAmt,txHeight,txTimestamp) = makeString(["%d%d%d%d", toString(outAmountAssetAmt), toString(outPriceAssetAmt), toString(txHeight), toString(txTimestamp)], SEP)
6482
6583
6684 func asString (val) = match val {
6785 case valStr: String =>
6886 valStr
6987 case _ =>
7088 throw("fail to cast into String")
7189 }
7290
7391
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-let factoryDapp = readFactoryAddressOrFail()
229-
230-let factoryCfg = readFactoryCfgOrFail(factoryDapp)
231-
232-let emissionDapp = getEmissionAddressOrFail(factoryCfg)
233-
234-let stakingDapp = getStakingAddressOrFail(factoryCfg)
235-
236-let gwxRewardDapp = getGwxRewardAddressOrFail(factoryCfg)
237-
238-let boostingDapp = getBoostingAddressOrFail(factoryCfg)
239-
240-func internalCurrentRewardRate (lpAssetId) = {
241- let poolAddressStr = getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAssetId))
242- let poolWeightMult = MULT8
243- let poolWeight = getIntegerValue(factoryDapp, keyFactoryPoolWeight(poolAddressStr))
244- let wxEmissionPerBlock = getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent())
245- let wxEmissionPerBlockMax = getIntOrFail(emissionDapp, keyEmissionRatePerBlockMaxCurrent())
246- let boostMaxCoeff = 3
247- let poolWxEmissionPerBlock = (fraction(wxEmissionPerBlock, poolWeight, poolWeightMult) / boostMaxCoeff)
248- let poolWxEmissionPerBlockMax = fraction(wxEmissionPerBlockMax, poolWeight, poolWeightMult)
249- let maxFactor = (boostMaxCoeff * MULT8)
250- let totalLpStaked = getIntOrZero(stakingDapp, keyStakedTotal(lpAssetId))
251-[poolWxEmissionPerBlock, maxFactor, totalLpStaked]
252- }
253-
254-
255-func calcGwxAmountStartREADONLY (lockAmount,lockDuration,maxLockDuration) = {
256- let coeffX8 = fraction(lockDuration, MULT8, maxLockDuration)
257- let gWxAmountStart = fraction(lockAmount, coeffX8, MULT8)
258-[gWxAmountStart]
259- }
92+func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale)
26093
26194
26295 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
26396 case s: String =>
26497 fromBase58String(s)
26598 case _: Unit =>
26699 unit
267100 case _ =>
268101 throw("Match error")
269102 }
270103
271104
272105 func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
273106 case s: String =>
274107 fromBase58String(s)
275108 case _: Unit =>
276109 unit
277110 case _ =>
278111 throw("Match error")
279112 }
280113
281114
282115 func mustManager (i) = {
283116 let pd = throw("Permission denied")
284117 match managerPublicKeyOrUnit() {
285118 case pk: ByteVector =>
286119 if ((i.callerPublicKey == pk))
287120 then true
288121 else pd
289122 case _: Unit =>
290123 if ((i.caller == this))
291124 then true
292125 else pd
293126 case _ =>
294127 throw("Match error")
295128 }
296129 }
297130
298131
299132 @Callable(i)
300-func constructor (factoryAddress) = if ((i.caller != this))
301- then throw("not authorized")
302- else [StringEntry(keyFactoryAddress(), factoryAddress)]
303-
304-
305-
306-@Callable(i)
307-func currentRewardRateREADONLY (lpAssetId) = {
308- let rewardData = internalCurrentRewardRate(lpAssetId)
309- let wxEmissionPerBlock = rewardData[0]
310- let maxFactor = rewardData[1]
311- let totalLpStaked = rewardData[2]
312- $Tuple2(nil, makeString(["%d%d%d", toString(wxEmissionPerBlock), toString(maxFactor), toString(totalLpStaked)], SEP))
133+func constructor (factoryContract) = {
134+ let checkCaller = mustManager(i)
135+ if ((checkCaller == checkCaller))
136+ then [StringEntry(keyFactoryContract(), factoryContract)]
137+ else throw("Strict value is not equal to itself.")
313138 }
314139
315140
316141
317142 @Callable(i)
318-func currentUserRewardRateREADONLY (lpAssetId,userAddress) = {
319- let rewardData = internalCurrentRewardRate(lpAssetId)
320- let wxEmissionPerBlock = rewardData[0]
321- let maxFactor = rewardData[1]
322- let totalLpStaked = rewardData[2]
323- let lpStakedByUser = getIntOrZero(stakingDapp, keyStakedByUser(userAddress, lpAssetId))
324- let userClaimInfo = split(asString(invoke(stakingDapp, "claimWxREADONLY", [lpAssetId, userAddress], nil)), SEP)
325- let minRewardPart = valueOrErrorMessage(parseInt(userClaimInfo[5]), "couldn't parse minRewardPart")
326- let boostRewardPart = valueOrErrorMessage(parseInt(userClaimInfo[6]), "couldn't parse boostRewardPart")
327- let debug = userClaimInfo[7]
328- let boostingPower = if ((boostRewardPart == 0))
329- then (1 * MULT8)
330- else fraction((minRewardPart + boostRewardPart), MULT8, minRewardPart)
331- $Tuple2(nil, makeString(["%d%d%d%d%d%s", toString(wxEmissionPerBlock), toString(maxFactor), toString(totalLpStaked), toString(lpStakedByUser), toString(boostingPower), debug], SEP))
143+func put () = {
144+ let pool = toString(i.caller)
145+ let pmtAmtAsset = value(i.payments[0])
146+ let pmtAssetId = if (!(isDefined(pmtAmtAsset.assetId)))
147+ then "WAVES"
148+ else toBase58String(value(pmtAmtAsset.assetId))
149+ let pmtAssetAmt = pmtAmtAsset.amount
150+ let poolAssets = split(valueOrErrorMessage(getString(factoryContract, keyMappingPoolContractAddressToPoolAssets(pool)), "Invalid caller"), SEP)
151+ let amountAssetId = parseIntValue(poolAssets[1])
152+ let priceAssetId = parseIntValue(poolAssets[2])
153+ let amountAsset = valueOrErrorMessage(getString(factoryContract, keyMappingsInternal2baseAssetId(amountAssetId)), "Cannot find asset")
154+ let priceAsset = valueOrErrorMessage(getString(factoryContract, keyMappingsInternal2baseAssetId(priceAssetId)), "Cannot find asset")
155+ let totalAmt = valueOrElse(getInteger(this, keyPoolTotalAmtByAsset(pool, pmtAssetId)), 0)
156+ let cumulativeSlippageAmt = valueOrElse(getInteger(this, keySlippageAmtPerAssetCumulative(pool, pmtAssetId)), 0)
157+[StringEntry(keyRegisterPut(pool, toBase58String(i.transactionId)), dataPutActionInfo(pmtAssetId, pmtAssetAmt, height, lastBlock.timestamp)), IntegerEntry(keyPoolTotalAmtByAsset(pool, pmtAssetId), (totalAmt + pmtAssetAmt)), IntegerEntry(keySlippageAmtPerAssetCumulative(pool, pmtAssetId), (cumulativeSlippageAmt + pmtAssetAmt))]
332158 }
333159
334160
335161
336162 @Callable(i)
337-func claimedRewardREADONLY (userAddress) = {
338- let lpList = readLpList()
339- let prefix = "%s%d%d%d%s"
340- func claimedRewardByLpAggregator (resultStr,nextLp) = {
341- let claimedByUserMinRewardKEY = keyClaimedByUserMinReward(nextLp, userAddress)
342- let claimedByUserBoostRewardKEY = keyClaimedByUserBoostReward(nextLp, userAddress)
343- let minRewardClaimed = valueOrElse(getInteger(stakingDapp, claimedByUserMinRewardKEY), 0)
344- let boostRewardClaimed = valueOrElse(getInteger(stakingDapp, claimedByUserBoostRewardKEY), 0)
345- let gFeeClaimed = 0
346- makeString([(prefix + resultStr), nextLp, toString(minRewardClaimed), toString(boostRewardClaimed), toString(gFeeClaimed), "end"], SEP)
347- }
348-
349- let result = {
350- let $l = lpList
351- let $s = size($l)
352- let $acc0 = "%s"
353- func $f0_1 ($a,$i) = if (($i >= $s))
354- then $a
355- else claimedRewardByLpAggregator($a, $l[$i])
356-
357- func $f0_2 ($a,$i) = if (($i >= $s))
358- then $a
359- else throw("List size exceeds 10")
360-
361- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
362- }
363- $Tuple2(nil, ((result + SEP) + userAddress))
364- }
365-
366-
367-
368-@Callable(i)
369-func calcBoostREADONLY (deltaWxAmount,deltaLockPeriodInBlocks,deltaLpAmount,lpAssetIdOpt,userAddressOpt) = {
370- let mathDapp = gwxRewardDapp
371- let EMPTYSTR = "empty"
372- let maxLockDurationInBlocks = parseIntValue(split(getStringByAddressOrFail(boostingDapp, keyBoostCfg()), SEP)[4])
373- let lpAssetIdStr = if ((lpAssetIdOpt == ""))
374- then EMPTYSTR
375- else lpAssetIdOpt
376- let userAddressStr = if ((userAddressOpt == ""))
377- then EMPTYSTR
378- else userAddressOpt
379- let userNumStr = valueOrElse(getString(boostingDapp, keyUser2NumMapping(userAddressOpt)), EMPTYSTR)
380- let userAmount = valueOrElse(getInteger(boostingDapp, keyLockParamUserAmount(userNumStr)), 0)
381- let lockStart = valueOrElse(getInteger(boostingDapp, keyLockParamStartBlock(userNumStr)), height)
382- let lockDuration = valueOrElse(getInteger(boostingDapp, keyLockParamDuration(userNumStr)), 0)
383- let lockEnd = (lockStart + lockDuration)
384- let remainingDuration = max([(lockEnd - height), 0])
385- let userAmountNew = (userAmount + deltaWxAmount)
386- let lockDurationNew = min([(remainingDuration + deltaLockPeriodInBlocks), maxLockDurationInBlocks])
387- let userCurrgWxAmount = asInt(asAnyList(invoke(boostingDapp, "gwxUserInfoREADONLY", [userAddressStr], nil))[0])
388- let gWxAmountStartNew = calcGwxAmountStartREADONLY(userAmountNew, lockDurationNew, maxLockDurationInBlocks)[0]
389- let gWxParamsResultList = asAnyList(invoke(mathDapp, "calcGwxParamsREADONLY", [gWxAmountStartNew, height, lockDurationNew], nil))
390- let gWxAmountDiff = (gWxAmountStartNew - userCurrgWxAmount)
391- let k = asInt(gWxParamsResultList[0])
392- let b = asInt(gWxParamsResultList[1])
393- let period = toString(asInt(gWxParamsResultList[2]))
394- let totalMaxBoostIntegralKEY = keyTotalMaxBoostINTEGRAL()
395- let totalCachedGwxKEY = keyTotalCachedGwx()
396- let userMaxBoostIntNew = ((gWxAmountStartNew * lockDurationNew) / 2)
397- let totalMaxBoostInt = getIntOrZero(boostingDapp, totalMaxBoostIntegralKEY)
398- let totalCachedGwx = valueOrElse(getInteger(boostingDapp, totalCachedGwxKEY), 0)
399- let MULT3 = 1000
400- let wxEmissionPerBlockX3 = (getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent()) * MULT3)
401- let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr)
402- let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
403- let stakedByUser = readStaked(stakingDapp, stakedByUserKEY)
404- let stakedTotal = readStaked(stakingDapp, stakedTotalKEY)
405- let stakedByUserNew = (stakedByUser + deltaLpAmount)
406- let stakedTotalNew = (stakedTotal + deltaLpAmount)
407- let poolWeight = if ((lpAssetIdStr != EMPTYSTR))
408- then {
409- let poolAddressStr = valueOrErrorMessage(getString(factoryDapp, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr))
410- getIntegerValue(factoryDapp, keyFactoryPoolWeight(poolAddressStr))
411- }
412- else 0
413- let poolWxEmissionPerBlockX3 = fraction(wxEmissionPerBlockX3, poolWeight, (POOLWEIGHTMULT * 3))
414- let wxPerLpX3 = if ((stakedTotalNew != 0))
415- then fraction(poolWxEmissionPerBlockX3, MULT8, stakedTotalNew)
416- else 0
417- let userWxPerBlockX3 = fraction(wxPerLpX3, stakedByUserNew, MULT8)
418- let boostEmissionPerBlockX3 = (poolWxEmissionPerBlockX3 * 2)
419- let tmpUserBoostPerBlockX3 = fraction(gWxAmountStartNew, boostEmissionPerBlockX3, (totalCachedGwx + gWxAmountDiff))
420- let userBoostPerBlockX3 = min([tmpUserBoostPerBlockX3, (userWxPerBlockX3 * 2)])
421- let boostCoeff = if ((userWxPerBlockX3 == 0))
422- then (1 * MULT8)
423- else fraction((userBoostPerBlockX3 + userWxPerBlockX3), MULT8, userWxPerBlockX3)
424- let debug = makeString([("lpAssetIdStr=" + lpAssetIdStr), ("userAddressStr=" + userAddressStr), ("userNumStr=" + userNumStr), ("userAmount=" + toString(userAmount)), ("userAmountNew=" + toString(userAmountNew)), ("lockDurationNew=" + toString(lockDurationNew)), ("gWxAmountStart=" + toString(gWxAmountStartNew)), ("tmpUserBoostPerBlockX3=" + toString(tmpUserBoostPerBlockX3)), ("stakedByUserNew=" + toString(stakedByUserNew)), ("stakedTotalNew=" + toString(stakedTotalNew)), ("poolWeight=" + toString(poolWeight)), ("wxPerLpX3=" + toString(wxPerLpX3)), ("poolWxEmissionPerBlockX3=" + toString(poolWxEmissionPerBlockX3)), ("userWxPerBlockX3=" + toString(userWxPerBlockX3)), ("gWxAmountDiff=" + toString(gWxAmountDiff)), ("totalCachedGwx=" + toString(totalCachedGwx)), ("userCurrgWxAmount=" + toString(userCurrgWxAmount))], "::")
425- $Tuple2(nil, makeString(["%d%d%s", toString(gWxAmountStartNew), toString(boostCoeff), debug], SEP))
426- }
427-
428-
429-
430-@Callable(i)
431-func wxEmissionStatsREADONLY () = {
432- let ONEMULT = toString(MULT8)
433- let ONE = "1"
434- let wxEmissionPerBlock = getIntOrFail(emissionDapp, keyEmissionRatePerBlockCurrent())
435- let emissionStartBlock = getIntOrFail(emissionDapp, keyEmissionStartBlock())
436- let passedBlocks = if ((emissionStartBlock > height))
437- then 0
438- else (height - emissionStartBlock)
439- let teamEmDuration = (1440 * 365)
440- let teamEmMax = (201000000 * MULT8)
441- let teamEm = if ((passedBlocks > teamEmDuration))
442- then teamEmMax
443- else fraction(teamEmMax, passedBlocks, teamEmDuration)
444- let totalWxReleased = ((wxEmissionPerBlock * passedBlocks) + teamEm)
445- let totalWxLocked = getIntOrZero(boostingDapp, keyBoostingLockParamTotalAmount())
446- let locksDurationSumInBlocks = getIntOrZero(boostingDapp, keyBoostingStatsLocksDurationSumInBlocks())
447- let locksCount = getIntOrZero(boostingDapp, keyBoostingStatsLocksCount())
448- $Tuple2(nil, makeString(["%d%d%d%d", toString(totalWxReleased), toString(totalWxLocked), toString(locksDurationSumInBlocks), toString(locksCount)], SEP))
449- }
450-
451-
452-
453-@Callable(i)
454-func poolStatsREADONLY (lpAsset) = {
455- let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset)))
456- let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil))
457- let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId]))
458- let amtAssetId = asString(cfg[idxAmtAssetId])
459- let priceAssetId = asString(cfg[idxPriceAssetId])
460- let iAmtAssetId = asString(cfg[idxIAmtAssetId])
461- let iPriceAssetId = asString(cfg[idxIPriceAssetId])
462- let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm]))
463- let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm]))
464- let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
465- let accAmtAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amtAssetId], nil))
466- let accPriceAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [priceAssetId], nil))
467- let pricesList = if ((poolLPBalance == 0))
468- then [toString(zeroBigInt), toString(zeroBigInt), toString(zeroBigInt)]
469- else asAnyList(invoke(poolAddress, "calcPricesWrapperREADONLY", [accAmtAssetBalance, accPriceAssetBalance, poolLPBalance], nil))
470- let curPrice = 0
471- let lpAmtAssetShare = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [pricesList[1], MULT8], nil))
472- let lpPriceAssetShare = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [pricesList[2], MULT8], nil))
473- let poolWeight = getIntegerValue(factoryDapp, keyFactoryPoolWeight(toString(poolAddress)))
474- $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(accAmtAssetBalance), toString(accPriceAssetBalance), toString(poolLPBalance), toString(curPrice), toString(lpAmtAssetShare), toString(lpPriceAssetShare), toString(poolWeight)], SEP))
475- }
476-
477-
478-
479-@Callable(i)
480-func poolEvaluatePutByAmountAssetREADONLY (lpAsset,inAmAssetAmt) = {
481- let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset)))
482- let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil))
483- let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId]))
484- let amAssetIdStr = asString(cfg[idxAmtAssetId])
485- let amAssetId = fromBase58String(amAssetIdStr)
486- let prAssetIdStr = asString(cfg[idxPriceAssetId])
487- let prAssetId = fromBase58String(prAssetIdStr)
488- let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm]))
489- let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm]))
490- let poolStatus = asString(cfg[idxPoolStatus])
491- let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
492- let accAmtAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amAssetIdStr], nil))
493- let accPriceAssetBalance = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [prAssetIdStr], nil))
494- let amtAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [accAmtAssetBalance, amtAssetDcm], nil)))
495- let priceAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [accPriceAssetBalance, priceAssetDcm], nil)))
496- let curPriceX18 = if ((poolLPBalance == 0))
497- then zeroBigInt
498- else parseBigIntValue(asString(invoke(poolAddress, "calcPriceBigIntWrapperREADONLY", [toString(priceAssetAmtX18), toString(amtAssetAmtX18)], nil)))
499- let curPrice = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(curPriceX18), MULT8], nil))
500- let inAmAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [inAmAssetAmt, amtAssetDcm], nil)))
501- let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, MULT18)
502- let inPrAssetAmt = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(inPrAssetAmtX18), priceAssetDcm], nil))
503- let res = invoke(poolAddress, "estimatePutOperationWrapperREADONLY", ["", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false], nil)
504- let $t02282123174 = match res {
505- case _ =>
506- if (if ($isInstanceOf($match0._1, "Int"))
507- then if ($isInstanceOf($match0._3, "Int"))
508- then if ($isInstanceOf($match0._4, "Int"))
509- then if ($isInstanceOf($match0._5, "Int"))
510- then $isInstanceOf($match0._6, "Int")
511- else false
512- else false
513- else false
514- else false)
515- then {
516- let calcLpAmt = $match0._1
517- let curPriceCalc = $match0._3
518- let amBalance = $match0._4
519- let prBalance = $match0._5
520- let lpEmission = $match0._6
521- $Tuple5(calcLpAmt, curPriceCalc, amBalance, prBalance, lpEmission)
522- }
523- else throw("Couldn't cast types")
524- }
525- let calcLpAmt = $t02282123174._1
526- let curPriceCalc = $t02282123174._2
527- let amBalance = $t02282123174._3
528- let prBalance = $t02282123174._4
529- let lpEmission = $t02282123174._5
530- $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))
531- }
532-
533-
534-
535-@Callable(i)
536-func poolEvaluatePutByPriceAssetREADONLY (lpAsset,inPrAssetAmt) = {
537- let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(lpAsset)))
538- let cfg = asAnyList(invoke(poolAddress, "getPoolConfigWrapperREADONLY", nil, nil))
539- let lpAssetId = fromBase58String(asString(cfg[idxPoolLPAssetId]))
540- let amAssetIdStr = asString(cfg[idxAmtAssetId])
541- let amAssetId = fromBase58String(amAssetIdStr)
542- let prAssetIdStr = asString(cfg[idxPriceAssetId])
543- let prAssetId = fromBase58String(prAssetIdStr)
544- let amtAssetDcm = parseIntValue(asString(cfg[idxAmtAssetDcm]))
545- let priceAssetDcm = parseIntValue(asString(cfg[idxPriceAssetDcm]))
546- let poolStatus = asString(cfg[idxPoolStatus])
547- let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
548- let amBalanceRaw = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [amAssetIdStr], nil))
549- let prBalanceRaw = asInt(invoke(poolAddress, "getAccBalanceWrapperREADONLY", [prAssetIdStr], nil))
550- let amBalanceRawX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [amBalanceRaw, amtAssetDcm], nil)))
551- let prBalanceRawX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [prBalanceRaw, priceAssetDcm], nil)))
552- let curPriceX18 = if ((poolLPBalance == 0))
553- then zeroBigInt
554- else parseBigIntValue(asString(invoke(poolAddress, "calcPriceBigIntWrapperREADONLY", [toString(prBalanceRawX18), toString(amBalanceRawX18)], nil)))
555- let curPrice = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(curPriceX18), MULT8], nil))
556- let inPrAssetAmtX18 = parseBigIntValue(asString(invoke(poolAddress, "toX18WrapperREADONLY", [inPrAssetAmt, priceAssetDcm], nil)))
557- let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, MULT18, curPriceX18)
558- let inAmAssetAmt = asInt(invoke(poolAddress, "fromX18WrapperREADONLY", [toString(inAmAssetAmtX18), amtAssetDcm], nil))
559- let res = invoke(poolAddress, "estimatePutOperationWrapperREADONLY", ["", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false], nil)
560- let $t02574726100 = match res {
561- case _ =>
562- if (if ($isInstanceOf($match0._1, "Int"))
563- then if ($isInstanceOf($match0._3, "Int"))
564- then if ($isInstanceOf($match0._4, "Int"))
565- then if ($isInstanceOf($match0._5, "Int"))
566- then $isInstanceOf($match0._6, "Int")
567- else false
568- else false
569- else false
570- else false)
571- then {
572- let calcLpAmt = $match0._1
573- let curPriceCalc = $match0._3
574- let amBalance = $match0._4
575- let prBalance = $match0._5
576- let lpEmission = $match0._6
577- $Tuple5(calcLpAmt, curPriceCalc, amBalance, prBalance, lpEmission)
578- }
579- else throw("Couldn't cast types")
580- }
581- let calcLpAmt = $t02574726100._1
582- let curPriceCalc = $t02574726100._2
583- let amBalance = $t02574726100._3
584- let prBalance = $t02574726100._4
585- let lpEmission = $t02574726100._5
586- $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))
587- }
588-
589-
590-
591-@Callable(i)
592-func poolEvaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = {
593- let poolAddress = addressFromStringValue(getStringByAddressOrFail(factoryDapp, keyFactoryLpAssetToPoolContractAddress(paymentLpAssetId)))
594- let res = invoke(poolAddress, "estimateGetOperationWrapperREADONLY", ["", paymentLpAssetId, paymentLpAmt, toString(poolAddress)], nil)
595- let $t02679527212 = match res {
596- case _ =>
597- if (if ($isInstanceOf($match0._1, "Int"))
598- then if ($isInstanceOf($match0._2, "Int"))
599- then if ($isInstanceOf($match0._5, "Int"))
600- then if ($isInstanceOf($match0._6, "Int"))
601- then if ($isInstanceOf($match0._7, "Int"))
602- then if ($isInstanceOf($match0._8, "String"))
603- then $isInstanceOf($match0._9, "String")
604- else false
605- else false
606- else false
607- else false
608- else false
609- else false)
610- then {
611- let outAmAmt = $match0._1
612- let outPrAmt = $match0._2
613- let amBalance = $match0._5
614- let prBalance = $match0._6
615- let lpEmission = $match0._7
616- let curPrice = $match0._8
617- let poolStatus = $match0._9
618- $Tuple7(outAmAmt, outPrAmt, amBalance, prBalance, lpEmission, curPrice, poolStatus)
619- }
620- else throw("Couldn't cast types")
621- }
622- let outAmAmt = $t02679527212._1
623- let outPrAmt = $t02679527212._2
624- let amBalance = $t02679527212._3
625- let prBalance = $t02679527212._4
626- let lpEmission = $t02679527212._5
627- let curPrice = $t02679527212._6
628- let poolStatus = $t02679527212._7
629- $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(outAmAmt), toString(outPrAmt), toString(amBalance), toString(prBalance), toString(lpEmission), curPrice, poolStatus], SEP))
630- }
631-
632-
633-
634-@Callable(i)
635-func gwxUserInfoREADONLY (userAddress) = {
636- let gwxUserInfoLIST = asAnyList(invoke(boostingDapp, "gwxUserInfoREADONLY", [userAddress], nil))
637- let gwxAmount = asInt(gwxUserInfoLIST[0])
638- $Tuple2(nil, makeString(["%d", toString(gwxAmount)], SEP))
163+func invest (poolAddressStr) = {
164+ let poolAddress = valueOrErrorMessage(addressFromString(poolAddressStr), "invalid pool address")
165+ let poolAssets = split(valueOrErrorMessage(getString(factoryContract, keyMappingPoolContractAddressToPoolAssets(poolAddressStr)), "Invalid pool passed."), SEP)
166+ let amId = valueOrErrorMessage(getString(factoryContract, keyMappingsInternal2baseAssetId(parseIntValue(poolAssets[1]))), "No asset mapping found")
167+ let prId = valueOrErrorMessage(getString(factoryContract, keyMappingsInternal2baseAssetId(parseIntValue(poolAssets[2]))), "No asset mapping found")
168+ let amBalance = valueOrElse(getInteger(this, keyPoolTotalAmtByAsset(poolAddressStr, amId)), 0)
169+ let prBalance = valueOrElse(getInteger(this, keyPoolTotalAmtByAsset(poolAddressStr, prId)), 0)
170+ let estByPrResult = invoke(poolAddress, "evaluatePutByPriceAssetREADONLY", [prBalance], nil)
171+ let estByAmResult = invoke(poolAddress, "evaluatePutByAmountAssetREADONLY", [amBalance], nil)
172+ let IdxEstAmAmount = 7
173+ let IdxEstPrAmount = 8
174+ let estAmAmt = valueOrErrorMessage(parseIntValue(split(asString(estByPrResult), SEP)[IdxEstAmAmount]), "fail to parse estimated amAsset amount")
175+ let estPrAmt = valueOrErrorMessage(parseIntValue(split(asString(estByAmResult), SEP)[IdxEstPrAmount]), "fail to parse estimated prAsset amount")
176+ let $t066436744 = if ((amBalance >= estAmAmt))
177+ then $Tuple2(estAmAmt, prBalance)
178+ else $Tuple2(amBalance, estPrAmt)
179+ let amAmt = $t066436744._1
180+ let prAmt = $t066436744._2
181+ let amAssetId = if ((amId == "WAVES"))
182+ then unit
183+ else fromBase58String(amId)
184+ let prAssetId = if ((prId == "WAVES"))
185+ then unit
186+ else fromBase58String(prId)
187+ let lpPut = invoke(poolAddress, "putForFree", [1000], [AttachedPayment(amAssetId, amAmt), AttachedPayment(prAssetId, prAmt)])
188+ if ((lpPut == lpPut))
189+ then [StringEntry(keyRegisterInvest(poolAddressStr, toBase58String(i.transactionId)), dataInvestActionInfo(amAmt, prAmt, height, lastBlock.timestamp)), IntegerEntry(keyPoolTotalAmtByAsset(poolAddressStr, amId), (amBalance - amAmt)), IntegerEntry(keyPoolTotalAmtByAsset(poolAddressStr, prId), (prBalance - prAmt))]
190+ else throw("Strict value is not equal to itself.")
639191 }
640192
641193
642194
643195 @Callable(i)
644196 func setManager (pendingManagerPublicKey) = {
645197 let checkCaller = mustManager(i)
646198 if ((checkCaller == checkCaller))
647199 then {
648200 let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
649201 if ((checkManagerPublicKey == checkManagerPublicKey))
650202 then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
651203 else throw("Strict value is not equal to itself.")
652204 }
653205 else throw("Strict value is not equal to itself.")
654206 }
655207
656208
657209
658210 @Callable(i)
659211 func confirmManager () = {
660212 let pm = pendingManagerPublicKeyOrUnit()
661213 let hasPM = if (isDefined(pm))
662214 then true
663215 else throw("No pending manager")
664216 if ((hasPM == hasPM))
665217 then {
666218 let checkPM = if ((i.callerPublicKey == value(pm)))
667219 then true
668220 else throw("You are not pending manager")
669221 if ((checkPM == checkPM))
670222 then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
671223 else throw("Strict value is not equal to itself.")
672224 }
673225 else throw("Strict value is not equal to itself.")
674226 }
675227
676228
677229 @Verifier(tx)
678230 func verify () = {
679231 let targetPublicKey = match managerPublicKeyOrUnit() {
680232 case pk: ByteVector =>
681233 pk
682234 case _: Unit =>
683235 tx.senderPublicKey
684236 case _ =>
685237 throw("Match error")
686238 }
687239 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
688240 }
689241

github/deemru/w8io/026f985 
73.17 ms