tx · C6nJEhHC3gt1HYmX8YKGzcowMBD5bxC3E9FJhmPW4W6T

3N6HSS7Toat1RhyEsyqVGgVSRzH19W1FTbP:  -0.00500000 Waves

2023.08.18 10:22 [2715737] smart account 3N6HSS7Toat1RhyEsyqVGgVSRzH19W1FTbP > SELF 0.00000000 Waves

{ "type": 13, "id": "C6nJEhHC3gt1HYmX8YKGzcowMBD5bxC3E9FJhmPW4W6T", "fee": 500000, "feeAssetId": null, "timestamp": 1692343387791, "version": 1, "sender": "3N6HSS7Toat1RhyEsyqVGgVSRzH19W1FTbP", "senderPublicKey": "AoKo4segKHU4DeJnxXQYJj2u7J6XJeux6r8KLW52cd2Q", "proofs": [ "pWc9YFTqvpwDc1Ufyn8RG1BoagdQqYHmj31BEtAUBVrEM3CuENHCNBCawreDdnNi3iRraPVkgCto3BKdfqq1vVu" ], "script": "base64:BgIKCAISBAoCCAESAAEBBHRlc3QABARsaXN0CQDMCAIJAJQKAgIBYQAACQDMCAIJAJQKAgIBYgABCQDMCAIJAJQKAgIBYwACBQNuaWwKAQNiYXICA2FjYwRuZXh0BAkkdDAxOTEyMDgFBG5leHQEAWEIBQkkdDAxOTEyMDgCXzEEAWIIBQkkdDAxOTEyMDgCXzIEAWMJAPwHBAUEdGhpcwIDZm9vCQDMCAIFAWEJAMwIAgUBYgUDbmlsBQNuaWwDCQAAAgUBYwUBYwAACQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCgACJGwFBGxpc3QKAAIkcwkAkAMBBQIkbAoABSRhY2MwAAAKAQUkZjBfMQICJGECJGkDCQBnAgUCJGkFAiRzBQIkYQkBA2JhcgIFAiRhCQCRAwIFAiRsBQIkaQoBBSRmMF8yAgIkYQIkaQMJAGcCBQIkaQUCJHMFAiRhCQACAQIUTGlzdCBzaXplIGV4Y2VlZHMgMTAJAQUkZjBfMgIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIFBSRhY2MwAAAAAQACAAMABAAFAAYABwAIAAkACgIBaQEDZm9vAgFhAWIJAMwIAgkBDEludGVnZXJFbnRyeQIFAWEFAWIFA25pbAFpAQFhAAQBYQkBBHRlc3QAAwkAAAIFAWEFAWEFA25pbAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgARkt5a", "chainId": 84, "height": 2715737, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GEimRHwKJoyZKiLey5tfCVDAAY4FPbAPPUxrTsbRktnA Next: 6zMrSnh1QwfVD8rRMvm6MpzapTu8SPYuDjovuK4BKxq8 Full:
OldNewDifferences
1-{-# STDLIB_VERSION 7 #-}
1+{-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let SEP = "__"
4+func test () = {
5+ let list = [$Tuple2("a", 0), $Tuple2("b", 1), $Tuple2("c", 2)]
6+ func bar (acc,next) = {
7+ let $t0191208 = next
8+ let a = $t0191208._1
9+ let b = $t0191208._2
10+ let c = invoke(this, "foo", [a, b], nil)
11+ if ((c == c))
12+ then 0
13+ else throw("Strict value is not equal to itself.")
14+ }
515
6-let CONTRACT_NAME = "calculator.ride"
16+ let $l = list
17+ let $s = size($l)
18+ let $acc0 = 0
19+ func $f0_1 ($a,$i) = if (($i >= $s))
20+ then $a
21+ else bar($a, $l[$i])
722
8-let SCALE8 = 100000000
23+ func $f0_2 ($a,$i) = if (($i >= $s))
24+ then $a
25+ else throw("List size exceeds 10")
926
10-let PENDING = "PENDING"
11-
12-let WAVES = "WAVES"
13-
14-func wrapErr (s) = ((CONTRACT_NAME + ": ") + s)
15-
16-
17-func throwErr (s) = throw(wrapErr(s))
18-
19-
20-func assetIdToString (assetId) = match assetId {
21- case b: ByteVector =>
22- toBase58String(b)
23- case _: Unit =>
24- WAVES
25- case _ =>
26- throw("Match error")
27-}
28-
29-
30-func stringToAssetId (s) = if ((s == WAVES))
31- then unit
32- else fromBase58String(s)
33-
34-
35-func abs (n) = if ((0 > n))
36- then -(n)
37- else n
38-
39-
40-func keyFactoryAddress () = makeString(["%s", "factory"], SEP)
41-
42-
43-func keyManagerPublicKey () = makeString(["%s", "managerPublicKey"], SEP)
44-
45-
46-func keyLpAssetId () = makeString(["%s", "lpAssetId"], SEP)
47-
48-
49-func keyProxyTreasuryAddress () = makeString(["%s", "proxyTreasury"], SEP)
50-
51-
52-func keyMainTreasuryAddress () = makeString(["%s", "mainTreasury"], SEP)
53-
54-
55-func keyBusinessTreasuryAddress () = makeString(["%s", "businessTreasury"], SEP)
56-
57-
58-func keyBusinessTreasuryPart () = makeString(["%s", "businessTreasuryPart"], SEP)
59-
60-
61-func keyInvested (assetId) = makeString(["%s%s", "invested", assetIdToString(assetId)], SEP)
62-
63-
64-func keyDonated (assetId) = makeString(["%s%s", "donated", assetIdToString(assetId)], SEP)
65-
66-
67-func keyAvailable (userAddress) = makeString(["%s%s", "available", toString(userAddress)], SEP)
68-
69-
70-func keyClaimed (userAddress) = makeString(["%s%s", "claimed", toString(userAddress)], SEP)
71-
72-
73-func keyCurrentPeriod () = makeString(["%s", "currentPeriod"], SEP)
74-
75-
76-func keyPriceForPeriod (period) = makeString(["%s%d", "price", toString(period)], SEP)
77-
78-
79-func keyStartHeight (period) = makeString(["%s%d", "startHeight", toString(period)], SEP)
80-
81-
82-func keyPowerManagerBonus (period) = makeString(["%s%d", "powerManagerBonus", toString(period)], SEP)
83-
84-
85-func keyPeriodLength () = "%s__periodLength"
86-
87-
88-func keyInvestPeriodLength () = "%s__investPeriodLength"
89-
90-
91-func keyBlockProcessingReward () = "%s__blockProcessingReward"
92-
93-
94-func keyNextBlockToProcess () = "%s__nextBlockToProcess"
95-
96-
97-func keyBlockProcessed (height) = makeString(["%s%d", "blockProcessed", toString(height)], SEP)
98-
99-
100-func keyWithdrawal () = "%s__withdrawal"
101-
102-
103-func keyWithdrawalRequest (userAddress,txId) = makeString(["%s%s%s", "withdrawal", toString(userAddress), toBase58String(txId)], SEP)
104-
105-
106-func valueWithdrawalRequest (status,lpAssetAmount,targetPeriod,claimTxId) = {
107- let claimTxIdStr = match claimTxId {
108- case b: ByteVector =>
109- toBase58String(b)
110- case _: Unit =>
111- "SOON"
112- case _ =>
113- throw("Match error")
114- }
115- makeString(["%s%d%d%s", status, toString(lpAssetAmount), toString(targetPeriod), claimTxIdStr], SEP)
116- }
117-
118-
119-func keyWithdrawalHistory (userAddress,txId) = makeString(["%s%s%s", "withdrawalHistory", toString(userAddress), toBase58String(txId)], SEP)
120-
121-
122-func keyPeriodWithdrawalAssetIds (period) = makeString(["%s%d", "periodReward", toString(period)], SEP)
123-
124-
125-func keyPeriodWithdrawalAmounts (period) = makeString(["%s%d", "periodRewardAmount", toString(period)], SEP)
126-
127-
128-func parseWithdrawalRequestValueOrFail (s) = {
129- let parts = split(s, SEP)
130- if ((size(parts) == 5))
131- then {
132- let status = parts[1]
133- let lpAssetAmount = valueOrErrorMessage(parseInt(parts[2]), wrapErr("invalid lpAssetAmount"))
134- let targetPeriod = valueOrErrorMessage(parseInt(parts[3]), wrapErr("invalid targetPeriod"))
135- let claimTxId = parts[4]
136- $Tuple4(status, lpAssetAmount, targetPeriod, claimTxId)
137- }
138- else throwErr("invalid withdrawal request value")
139- }
140-
141-
142-let factoryAddressOption = match getString(this, keyFactoryAddress()) {
143- case s: String =>
144- addressFromString(s)
145- case _: Unit =>
146- unit
147- case _ =>
148- throw("Match error")
149-}
150-
151-let factoryAddressOrFail = valueOrErrorMessage(factoryAddressOption, wrapErr("invalid factory address"))
152-
153-let lpAssetIdOption = match factoryAddressOption {
154- case a: Address =>
155- match getString(a, keyLpAssetId()) {
156- case s: String =>
157- fromBase58String(s)
158- case _: Unit =>
159- unit
160- case _ =>
161- throw("Match error")
162- }
163- case _: Unit =>
164- unit
165- case _ =>
166- throw("Match error")
167-}
168-
169-let lpAssetIdOrFail = valueOrErrorMessage(lpAssetIdOption, wrapErr("invalid lpAssetId"))
170-
171-let proxyTreasuryAddressOption = match factoryAddressOption {
172- case a: Address =>
173- match getString(a, keyProxyTreasuryAddress()) {
174- case s: String =>
175- addressFromString(s)
176- case _: Unit =>
177- unit
178- case _ =>
179- throw("Match error")
180- }
181- case _: Unit =>
182- unit
183- case _ =>
184- throw("Match error")
185-}
186-
187-let proxyTreasuryAddressOrFail = valueOrErrorMessage(proxyTreasuryAddressOption, wrapErr("invalid proxy treasury address"))
188-
189-let mainTreasuryAddressOption = match factoryAddressOption {
190- case a: Address =>
191- match getString(a, keyMainTreasuryAddress()) {
192- case s: String =>
193- addressFromString(s)
194- case _: Unit =>
195- unit
196- case _ =>
197- throw("Match error")
198- }
199- case _: Unit =>
200- unit
201- case _ =>
202- throw("Match error")
203-}
204-
205-let businessTreasuryAddressOption = match factoryAddressOption {
206- case a: Address =>
207- match getString(a, keyBusinessTreasuryAddress()) {
208- case s: String =>
209- addressFromString(s)
210- case _: Unit =>
211- unit
212- case _ =>
213- throw("Match error")
214- }
215- case _: Unit =>
216- unit
217- case _ =>
218- throw("Match error")
219-}
220-
221-let mainTreasuryAddressOrFail = valueOrErrorMessage(mainTreasuryAddressOption, wrapErr("invalid main treasury address"))
222-
223-let businessTreasuryAddressOrFail = valueOrErrorMessage(businessTreasuryAddressOption, wrapErr("invalid business treasury address"))
224-
225-func getManagerPublicKeyOrUnit () = match factoryAddressOption {
226- case fa: Address =>
227- match getString(fa, keyManagerPublicKey()) {
228- case pub: String =>
229- fromBase58String(pub)
230- case _ =>
231- unit
232- }
233- case _ =>
234- unit
235-}
236-
237-
238-func onlyAddress (i,address) = if ((i.caller == address))
239- then true
240- else throwErr("permission denied")
241-
242-
243-func onlyFactory (i) = onlyAddress(i, factoryAddressOrFail)
244-
245-
246-func rewardForOption (rewards,target) = {
247- let s = size(rewards)
248- let $t057855810 = rewards[0]
249- let a0 = $t057855810._1
250- let r0 = $t057855810._2
251- let $t058135838 = rewards[1]
252- let a1 = $t058135838._1
253- let r1 = $t058135838._2
254- let $t058415866 = rewards[2]
255- let a2 = $t058415866._1
256- let r2 = $t058415866._2
257- if (if ((s > 0))
258- then (a0 == target)
259- else false)
260- then r0
261- else if (if ((s > 1))
262- then (a1 == target)
263- else false)
264- then r1
265- else if (if ((s > 2))
266- then (a2 == target)
267- else false)
268- then r2
269- else unit
270- }
271-
272-
273-func finalizeINTERNAL (newTreasuryVolumeInWaves,pwrManagersBonusInWaves,treasuryVolumeDiffAllocationCoef) = {
274- let donatedWavesAmount = valueOrElse(getInteger(factoryAddressOrFail, keyDonated(unit)), 0)
275- let investedWavesAmount = valueOrElse(getInteger(factoryAddressOrFail, keyInvested(unit)), 0)
276- let currentTreasuryVolumeInWaves = (donatedWavesAmount + investedWavesAmount)
277- let profitRaw = (newTreasuryVolumeInWaves - currentTreasuryVolumeInWaves)
278- let pwrManagersBonusAmount = if (if ((profitRaw >= pwrManagersBonusInWaves))
279- then true
280- else (pwrManagersBonusInWaves == 0))
281- then pwrManagersBonusInWaves
282- else throwErr("power bonus is more than profit")
283- let profit = (profitRaw - pwrManagersBonusAmount)
284- let donationPart = if ((currentTreasuryVolumeInWaves > 0))
285- then fraction(donatedWavesAmount, SCALE8, currentTreasuryVolumeInWaves)
286- else 0
287- let donationProfitPartRaw = fraction(profit, donationPart, SCALE8)
288- let investmentProfitPartRaw = (profit - donationProfitPartRaw)
289- let treasuryVolumeDiffAllocationCoefAbs = abs(treasuryVolumeDiffAllocationCoef)
290- let amountToDonation = fraction(investmentProfitPartRaw, if ((0 > treasuryVolumeDiffAllocationCoef))
291- then treasuryVolumeDiffAllocationCoefAbs
292- else 0, SCALE8)
293- let amountToInvestment = fraction(donationProfitPartRaw, if ((treasuryVolumeDiffAllocationCoef > 0))
294- then treasuryVolumeDiffAllocationCoefAbs
295- else 0, SCALE8)
296- let donationProfitPart = ((donationProfitPartRaw - amountToInvestment) + amountToDonation)
297- let investmentProfitPart = ((investmentProfitPartRaw - amountToDonation) + amountToInvestment)
298- let donatedWavesAmountNewRaw = (donatedWavesAmount + donationProfitPart)
299- let investedWavesAmountNewRaw = (investedWavesAmount + investmentProfitPart)
300- let donatedPartDebt = min([0, donatedWavesAmountNewRaw])
301- let investedPartDebt = min([0, investedWavesAmountNewRaw])
302- let donatedWavesAmountNew = (max([0, donatedWavesAmountNewRaw]) + investedPartDebt)
303- let investedWavesAmountNew = (max([0, investedWavesAmountNewRaw]) + donatedPartDebt)
304- let lpAssetQuantity = valueOrErrorMessage(assetInfo(lpAssetIdOrFail), wrapErr("invalid lpAsset info")).quantity
305- let newPrice = fraction(investedWavesAmountNew, SCALE8, lpAssetQuantity)
306- let checkIfPriceNotZero = if ((newPrice != 0))
307- then true
308- else throwErr("LP price cannot be 0")
309- if ((checkIfPriceNotZero == checkIfPriceNotZero))
310- then {
311- let lpAssetAmountToBurn = valueOrElse(getInteger(factoryAddressOrFail, keyWithdrawal()), 0)
312- let paymentAmountMin = max([0, fraction(lpAssetAmountToBurn, newPrice, SCALE8)])
313- let finalInvestedWavesAmount = (investedWavesAmountNew - paymentAmountMin)
314- let lpAssetFinalQuantity = (lpAssetQuantity - lpAssetAmountToBurn)
315- $Tuple6(paymentAmountMin, finalInvestedWavesAmount, donatedWavesAmountNew, newPrice, lpAssetAmountToBurn, lpAssetFinalQuantity)
316- }
317- else throw("Strict value is not equal to itself.")
318- }
319-
320-
321-func claimCollateralINTERNAL (userAddressBytes,txId) = {
322- let userAddress = Address(userAddressBytes)
323- let currentPeriodOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyCurrentPeriod()), wrapErr("invalid period"))
324- let withdrawalRequestOption = valueOrErrorMessage(getString(factoryAddressOrFail, keyWithdrawalRequest(userAddress, txId)), wrapErr("invalid withdrawal request"))
325- let $t092819394 = parseWithdrawalRequestValueOrFail(withdrawalRequestOption)
326- let status = $t092819394._1
327- let lpAssetAmount = $t092819394._2
328- let targetPeriod = $t092819394._3
329- let claimTxId = $t092819394._4
330- if ((targetPeriod > currentPeriodOrFail))
331- then throwErr("invalid withdrawal request period")
332- else {
333- let priceOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyPriceForPeriod(targetPeriod)), wrapErr("invalid price"))
334- let wavesAmount = if ((priceOrFail > 0))
335- then fraction(lpAssetAmount, priceOrFail, SCALE8)
336- else 0
337- let assetsString = getStringValue(factoryAddressOrFail, keyPeriodWithdrawalAssetIds(currentPeriodOrFail))
338- let amountsString = getStringValue(factoryAddressOrFail, keyPeriodWithdrawalAmounts(currentPeriodOrFail))
339- $Tuple6(userAddress, lpAssetAmount, targetPeriod, wavesAmount, assetsString, amountsString)
340- }
341- }
342-
343-
344-func claimCollateralREADONLYStringResponse (userAddressBytes,txId) = {
345- let $t01018110347 = claimCollateralINTERNAL(userAddressBytes, txId)
346- let userAddress = $t01018110347._1
347- let lpAssetAmount = $t01018110347._2
348- let targetPeriod = $t01018110347._3
349- let wavesAmount = $t01018110347._4
350- let assetsString = $t01018110347._5
351- let amountsString = $t01018110347._6
352- let assets = makeString(removeByIndex(split_51C(assetsString, SEP), 0), ":")
353- let amounts = makeString(removeByIndex(split_51C(amountsString, SEP), 0), ":")
354- makeString(["%d%s%s", toString(wavesAmount), assets, amounts], SEP)
27+ $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)
35528 }
35629
35730
35831 @Callable(i)
359-func claimLP (userAddressBytes) = {
360- let checkCaller = onlyFactory(i)
361- if ((checkCaller == checkCaller))
362- then {
363- let userAddress = Address(userAddressBytes)
364- let available = valueOrElse(getInteger(factoryAddressOrFail, keyAvailable(userAddress)), 0)
365- let claimed = valueOrElse(getInteger(factoryAddressOrFail, keyClaimed(userAddress)), 0)
366- let factoryActions = if ((available > 0))
367- then [invoke(factoryAddressOrFail, "transferAsset", [userAddressBytes, available, lpAssetIdOrFail], nil), invoke(factoryAddressOrFail, "integerEntry", [keyAvailable(userAddress), 0], nil), invoke(factoryAddressOrFail, "integerEntry", [keyClaimed(userAddress), (claimed + available)], nil)]
368- else throwErr("nothing to claim")
369- $Tuple2(nil, factoryActions)
370- }
371- else throw("Strict value is not equal to itself.")
372- }
32+func foo (a,b) = [IntegerEntry(a, b)]
37333
37434
37535
37636 @Callable(i)
377-func finalize (userAddressBytes,newTreasuryVolumeInWaves,pwrManagersBonusInWaves,treasuryVolumeDiffAllocationCoef) = {
378- let checkCaller = onlyFactory(i)
379- if ((checkCaller == checkCaller))
380- then {
381- let currentPeriodOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyCurrentPeriod()), wrapErr("invalid period"))
382- let periodLength = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyPeriodLength()), wrapErr("invalid period length"))
383- let currentStartHeight = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyStartHeight(currentPeriodOrFail)), wrapErr("invalid start height"))
384- let currentPriceOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyPriceForPeriod(currentPeriodOrFail)), wrapErr("invalid price"))
385- let nextBlockToProcess = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyNextBlockToProcess()), wrapErr("invalid next block to process"))
386- let periodEndHeight = ((currentStartHeight + periodLength) - 1)
387- let checks = [if ((i.originCaller == mainTreasuryAddressOrFail))
388- then true
389- else throwErr("permission denied"), if ((nextBlockToProcess > periodEndHeight))
390- then true
391- else throwErr("unprocessed blocks"), if ((newTreasuryVolumeInWaves >= 0))
392- then true
393- else throwErr("invalid new treasury volume"), if ((pwrManagersBonusInWaves >= 0))
394- then true
395- else throwErr("invalid PWR managers bonus"), if (if ((treasuryVolumeDiffAllocationCoef >= -(SCALE8)))
396- then (SCALE8 >= treasuryVolumeDiffAllocationCoef)
397- else false)
398- then true
399- else throwErr("invalid treasury volume diff allocation coefficient")]
400- if ((checks == checks))
401- then {
402- let $t01310913369 = finalizeINTERNAL(newTreasuryVolumeInWaves, pwrManagersBonusInWaves, treasuryVolumeDiffAllocationCoef)
403- let paymentAmountMin = $t01310913369._1
404- let finalInvestedWavesAmount = $t01310913369._2
405- let donatedWavesAmountNew = $t01310913369._3
406- let newPrice = $t01310913369._4
407- let lpAssetAmountToBurn = $t01310913369._5
408- let lpAssetFinalQuantity = $t01310913369._6
409- let newPeriod = (currentPeriodOrFail + 1)
410- func addNewAction (actions,payment) = {
411- let $t01351713579 = actions
412- let scriptTransfers = $t01351713579._1
413- let assetIdsString = $t01351713579._2
414- let amountsString = $t01351713579._3
415- let paymentAmount = payment.amount
416- let paymentAssetId = payment.assetId
417- let newAssetIdsString = ("%s" + makeString([assetIdsString, assetIdToString(paymentAssetId)], SEP))
418- let newAmountsString = ("%d" + makeString([amountsString, toString(paymentAmount)], SEP))
419- let newScriptTransfer = ScriptTransfer(factoryAddressOrFail, paymentAmount, paymentAssetId)
420- $Tuple3((scriptTransfers :+ newScriptTransfer), newAssetIdsString, newAmountsString)
421- }
422-
423- let $t01403914130 = {
424- let $l = i.payments
425- let $s = size($l)
426- let $acc0 = $Tuple3(nil, "", "")
427- func $f0_1 ($a,$i) = if (($i >= $s))
428- then $a
429- else addNewAction($a, $l[$i])
430-
431- func $f0_2 ($a,$i) = if (($i >= $s))
432- then $a
433- else throw("List size exceeds 10")
434-
435- $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)
436- }
437- let scriptTransfers = $t01403914130._1
438- let AssetIds = $t01403914130._2
439- let Amounts = $t01403914130._3
440- let factoryActions = [invoke(factoryAddressOrFail, "integerEntry", [keyPowerManagerBonus(currentPeriodOrFail), pwrManagersBonusInWaves], nil), invoke(factoryAddressOrFail, "integerEntry", [keyCurrentPeriod(), newPeriod], nil), invoke(factoryAddressOrFail, "integerEntry", [keyPriceForPeriod(newPeriod), newPrice], nil), invoke(factoryAddressOrFail, "integerEntry", [keyStartHeight(newPeriod), (periodEndHeight + 1)], nil), invoke(factoryAddressOrFail, "burn", [lpAssetAmountToBurn], nil), invoke(factoryAddressOrFail, "integerEntry", [keyWithdrawal(), 0], nil), invoke(factoryAddressOrFail, "integerEntry", [keyInvested(unit), finalInvestedWavesAmount], nil), invoke(factoryAddressOrFail, "integerEntry", [keyDonated(unit), donatedWavesAmountNew], nil), invoke(factoryAddressOrFail, "stringEntry", [keyPeriodWithdrawalAssetIds(newPeriod), AssetIds], nil), invoke(factoryAddressOrFail, "stringEntry", [keyPeriodWithdrawalAmounts(newPeriod), Amounts], nil)]
441- $Tuple2(scriptTransfers, factoryActions)
442- }
443- else throw("Strict value is not equal to itself.")
444- }
37+func a () = {
38+ let a = test()
39+ if ((a == a))
40+ then nil
44541 else throw("Strict value is not equal to itself.")
44642 }
44743
448-
449-
450-@Callable(i)
451-func finalizeREADONLY (newTreasuryVolumeInWaves,pwrManagersBonusInWaves,treasuryVolumeDiffAllocationCoef) = {
452- let currentPeriodOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyCurrentPeriod()), wrapErr("invalid period"))
453- let periodLength = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyPeriodLength()), wrapErr("invalid period length"))
454- let currentStartHeight = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyStartHeight(currentPeriodOrFail)), wrapErr("invalid start height"))
455- let currentPriceOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyPriceForPeriod(currentPeriodOrFail)), wrapErr("invalid price"))
456- let nextBlockToProcess = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyNextBlockToProcess()), wrapErr("invalid next block to process"))
457- let periodEndHeight = ((currentStartHeight + periodLength) - 1)
458- let checks = [if ((nextBlockToProcess > periodEndHeight))
459- then true
460- else throwErr("unprocessed blocks"), if ((newTreasuryVolumeInWaves >= 0))
461- then true
462- else throwErr("invalid new treasury volume"), if ((pwrManagersBonusInWaves >= 0))
463- then true
464- else throwErr("invalid PWR managers bonus"), if (if ((treasuryVolumeDiffAllocationCoef >= -(SCALE8)))
465- then (SCALE8 >= treasuryVolumeDiffAllocationCoef)
466- else false)
467- then true
468- else throwErr("invalid treasury volume diff allocation coefficient")]
469- if ((checks == checks))
470- then $Tuple2(nil, finalizeINTERNAL(newTreasuryVolumeInWaves, pwrManagersBonusInWaves, treasuryVolumeDiffAllocationCoef))
471- else throw("Strict value is not equal to itself.")
472- }
473-
474-
475-
476-@Callable(i)
477-func invest (userAddressBytes) = {
478- let checkCaller = onlyFactory(i)
479- if ((checkCaller == checkCaller))
480- then {
481- let userAddress = Address(userAddressBytes)
482- let currentPeriodOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyCurrentPeriod()), wrapErr("invalid period"))
483- let currentStartHeight = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyStartHeight(currentPeriodOrFail)), wrapErr("invalid start height"))
484- let investPeriodLength = getIntegerValue(factoryAddressOrFail, keyInvestPeriodLength())
485- let heightCheck = if (((currentStartHeight + investPeriodLength) > height))
486- then true
487- else throwErr("too late to invest in this period")
488- if ((heightCheck == heightCheck))
489- then {
490- let currentPriceOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyPriceForPeriod(currentPeriodOrFail)), wrapErr("invalid price"))
491- let payment = if ((size(i.payments) == 1))
492- then i.payments[0]
493- else throwErr("invalid payments")
494- let $t01798718164 = if (if ((payment.assetId == unit))
495- then (payment.amount > 0)
496- else false)
497- then $Tuple2(payment.amount, payment.assetId)
498- else throwErr("invalid payment amount")
499- let paymentAmount = $t01798718164._1
500- let paymentAssetId = $t01798718164._2
501- let treasuryPart = valueOrElse(getInteger(factoryAddressOrFail, keyBusinessTreasuryPart()), 0)
502- let paymentsWithoutTreasuryPart = fraction(paymentAmount, (SCALE8 - treasuryPart), SCALE8)
503- let lpAssetAmount = if ((currentPriceOrFail > 0))
504- then fraction(paymentsWithoutTreasuryPart, SCALE8, currentPriceOrFail)
505- else 0
506- let invested = valueOrElse(getInteger(factoryAddressOrFail, keyInvested(unit)), 0)
507- let actions = [ScriptTransfer(mainTreasuryAddressOrFail, paymentsWithoutTreasuryPart, paymentAssetId), ScriptTransfer(businessTreasuryAddressOrFail, treasuryPart, paymentAssetId)]
508- let factoryActions = [invoke(factoryAddressOrFail, "integerEntry", [keyInvested(unit), (invested + paymentsWithoutTreasuryPart)], nil), invoke(factoryAddressOrFail, "reissue", [lpAssetAmount], nil), invoke(factoryAddressOrFail, "transferAsset", [userAddressBytes, lpAssetAmount, lpAssetIdOrFail], nil)]
509- $Tuple2(actions, factoryActions)
510- }
511- else throw("Strict value is not equal to itself.")
512- }
513- else throw("Strict value is not equal to itself.")
514- }
515-
516-
517-
518-@Callable(i)
519-func withdraw (userAddressBytes) = {
520- let checkCaller = onlyFactory(i)
521- if ((checkCaller == checkCaller))
522- then {
523- let userAddress = Address(userAddressBytes)
524- let currentPeriodOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyCurrentPeriod()), wrapErr("invalid period"))
525- let payment = if ((size(i.payments) == 1))
526- then i.payments[0]
527- else throwErr(wrapErr("invalid payments"))
528- let paymentAssetId = if ((payment.assetId == lpAssetIdOrFail))
529- then lpAssetIdOrFail
530- else throwErr("invalid payment asset")
531- let paymentAmount = if ((payment.amount > 0))
532- then payment.amount
533- else throwErr("invalid payment amount")
534- let withdrawal = valueOrElse(getInteger(factoryAddressOrFail, keyWithdrawal()), 0)
535- let actions = [ScriptTransfer(factoryAddressOrFail, paymentAmount, paymentAssetId)]
536- let factoryActions = [invoke(factoryAddressOrFail, "integerEntry", [keyWithdrawal(), (withdrawal + paymentAmount)], nil), invoke(factoryAddressOrFail, "stringEntry", [keyWithdrawalRequest(userAddress, i.transactionId), valueWithdrawalRequest(PENDING, paymentAmount, (currentPeriodOrFail + 1), unit)], nil)]
537- if ((factoryActions == factoryActions))
538- then $Tuple2(actions, factoryActions)
539- else throw("Strict value is not equal to itself.")
540- }
541- else throw("Strict value is not equal to itself.")
542- }
543-
544-
545-
546-@Callable(i)
547-func cancelWithdraw (userAddressBytes,txId) = {
548- let checkCaller = onlyFactory(i)
549- if ((checkCaller == checkCaller))
550- then {
551- let userAddress = Address(userAddressBytes)
552- let withdrawalRequestOption = valueOrErrorMessage(getString(factoryAddressOrFail, keyWithdrawalRequest(userAddress, txId)), wrapErr("invalid withdrawal request"))
553- let currentPeriodOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyCurrentPeriod()), wrapErr("invalid period"))
554- let $t02089821011 = parseWithdrawalRequestValueOrFail(withdrawalRequestOption)
555- let status = $t02089821011._1
556- let lpAssetAmount = $t02089821011._2
557- let targetPeriod = $t02089821011._3
558- let claimTxId = $t02089821011._4
559- let checks = [if ((status == PENDING))
560- then true
561- else throwErr("invalid withdrawal request status"), if ((targetPeriod > currentPeriodOrFail))
562- then true
563- else throwErr("invalid withdrawal request period")]
564- if ((checks == checks))
565- then {
566- let withdrawal = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyWithdrawal()), wrapErr("invalid total withdrawal amount"))
567- let factoryActions = [invoke(factoryAddressOrFail, "integerEntry", [keyWithdrawal(), if ((withdrawal >= lpAssetAmount))
568- then (withdrawal - lpAssetAmount)
569- else throwErr("invalid withdrawal amount")], nil), invoke(factoryAddressOrFail, "deleteEntry", [keyWithdrawalRequest(userAddress, txId)], nil), invoke(factoryAddressOrFail, "transferAsset", [userAddressBytes, lpAssetAmount, lpAssetIdOrFail], nil)]
570- if ((factoryActions == factoryActions))
571- then $Tuple2(nil, factoryActions)
572- else throw("Strict value is not equal to itself.")
573- }
574- else throw("Strict value is not equal to itself.")
575- }
576- else throw("Strict value is not equal to itself.")
577- }
578-
579-
580-
581-@Callable(i)
582-func claimCollateral (userAddressBytes,txId) = {
583- let checkCaller = onlyFactory(i)
584- if ((checkCaller == checkCaller))
585- then {
586- let $t02199722182 = claimCollateralINTERNAL(userAddressBytes, fromBase58String(txId))
587- let userAddress = $t02199722182._1
588- let lpAssetAmount = $t02199722182._2
589- let targetPeriod = $t02199722182._3
590- let wavesAmount = $t02199722182._4
591- let assetsString = $t02199722182._5
592- let amountsString = $t02199722182._6
593- let assetsList = removeByIndex(split_51C(assetsString, SEP), 0)
594- let amountsList = removeByIndex(split_51C(amountsString, SEP), 0)
595- let factoryActions = [invoke(factoryAddressOrFail, "deleteEntry", [keyWithdrawalRequest(userAddress, fromBase58String(txId))], nil), invoke(factoryAddressOrFail, "integerEntry", [keyWithdrawalHistory(userAddress, fromBase58String(txId)), lpAssetAmount], nil), invoke(factoryAddressOrFail, "transferAssets", [userAddressBytes, assetsList, amountsList], nil)]
596- $Tuple2(nil, factoryActions)
597- }
598- else throw("Strict value is not equal to itself.")
599- }
600-
601-
602-
603-@Callable(i)
604-func claimCollateralBulk (userAddressBytes,txIds) = {
605- let checkCaller = onlyFactory(i)
606- if ((checkCaller == checkCaller))
607- then {
608- func addNewAction (state,txId) = {
609- let $t02294023139 = claimCollateralINTERNAL(userAddressBytes, fromBase58String(txId))
610- let userAddress = $t02294023139._1
611- let lpAssetAmount = $t02294023139._2
612- let targetPeriod = $t02294023139._3
613- let wavesAmount = $t02294023139._4
614- let assetsString = $t02294023139._5
615- let amountsString = $t02294023139._6
616- let assetsList = removeByIndex(split_51C(assetsString, SEP), 0)
617- let amountsList = removeByIndex(split_51C(amountsString, SEP), 0)
618- let newActions = [invoke(factoryAddressOrFail, "deleteEntry", [keyWithdrawalRequest(userAddress, fromBase58String(txId))], nil), invoke(factoryAddressOrFail, "integerEntry", [keyWithdrawalHistory(userAddress, fromBase58String(txId)), lpAssetAmount], nil), invoke(factoryAddressOrFail, "transferAssets", [userAddressBytes, assetsList, amountsList], nil)]
619- (state ++ newActions)
620- }
621-
622- let allFactoryActions = {
623- let $l = txIds
624- let $s = size($l)
625- let $acc0 = nil
626- func $f0_1 ($a,$i) = if (($i >= $s))
627- then $a
628- else addNewAction($a, $l[$i])
629-
630- func $f0_2 ($a,$i) = if (($i >= $s))
631- then $a
632- else throw("List size exceeds 10")
633-
634- $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)
635- }
636- $Tuple2(nil, allFactoryActions)
637- }
638- else throw("Strict value is not equal to itself.")
639- }
640-
641-
642-
643-@Callable(i)
644-func claimCollateralREADONLY (userAddressBytes,txId) = {
645- let response = claimCollateralREADONLYStringResponse(userAddressBytes, fromBase58String(txId))
646- $Tuple2(nil, response)
647- }
648-
649-
650-
651-@Callable(i)
652-func claimCollateralBulkREADONLY (userAddressBytes,txIds) = {
653- func processTxId (state,txId) = {
654- let response = claimCollateralREADONLYStringResponse(userAddressBytes, fromBase58String(txId))
655- (state :+ response)
656- }
657-
658- let allResponses = {
659- let $l = txIds
660- let $s = size($l)
661- let $acc0 = nil
662- func $f0_1 ($a,$i) = if (($i >= $s))
663- then $a
664- else processTxId($a, $l[$i])
665-
666- func $f0_2 ($a,$i) = if (($i >= $s))
667- then $a
668- else throw("List size exceeds 10")
669-
670- $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)
671- }
672- $Tuple2(nil, allResponses)
673- }
674-
675-
676-
677-@Callable(i)
678-func processBlocks (userAddressBytes) = {
679- let checkCaller = onlyFactory(i)
680- if ((checkCaller == checkCaller))
681- then {
682- let userAddress = Address(userAddressBytes)
683- let currentPeriodOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyCurrentPeriod()), wrapErr("invalid period"))
684- let periodLength = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyPeriodLength()), wrapErr("invalid period length"))
685- let currentStartHeight = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyStartHeight(currentPeriodOrFail)), wrapErr("invalid start height"))
686- let currentPriceOrFail = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyPriceForPeriod(currentPeriodOrFail)), wrapErr("invalid price"))
687- let nextBlockToProcess = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyNextBlockToProcess()), wrapErr("invalid next block to process"))
688- let periodEndHeight = ((currentStartHeight + periodLength) - 1)
689- let blocksProcessingBatchSizeMax = 40
690- let blocksProcessingBatchSize = if (if (if ((height >= nextBlockToProcess))
691- then if ((nextBlockToProcess >= currentStartHeight))
692- then true
693- else (currentPeriodOrFail == 0)
694- else false)
695- then (periodEndHeight >= nextBlockToProcess)
696- else false)
697- then min([((periodEndHeight - nextBlockToProcess) + 1), blocksProcessingBatchSizeMax])
698- else throwErr(wrapErr("invalid target block"))
699- let blockProcessingReward = valueOrErrorMessage(getInteger(factoryAddressOrFail, keyBlockProcessingReward()), wrapErr("invalid block processing reward"))
700- let blockProcessingRewardByGenerator = (blockProcessingReward / blocksProcessingBatchSize)
701- let blockProcessingRewardByGeneratorRemainder = (blockProcessingReward - (blockProcessingRewardByGenerator * blocksProcessingBatchSize))
702- func map (acc,inc) = if ((inc >= blocksProcessingBatchSize))
703- then acc
704- else {
705- let targetBlockHeight = (nextBlockToProcess + inc)
706- let targetBlockInfo = valueOrErrorMessage(blockInfoByHeight(targetBlockHeight), wrapErr("invalid block info"))
707- let treasuryRewardOrFail = valueOrErrorMessage(rewardForOption(targetBlockInfo.rewards, proxyTreasuryAddressOrFail), wrapErr(("invalid treasury reward for height " + toString(targetBlockHeight))))
708- let generator = targetBlockInfo.generator
709- let available = valueOrElse(getInteger(factoryAddressOrFail, keyAvailable(generator)), 0)
710- let callerReward = if ((inc == (blocksProcessingBatchSize - 1)))
711- then (blockProcessingRewardByGenerator + blockProcessingRewardByGeneratorRemainder)
712- else blockProcessingRewardByGenerator
713- let lpAssetAmount = if ((currentPriceOrFail > 0))
714- then fraction((treasuryRewardOrFail - callerReward), SCALE8, currentPriceOrFail)
715- else 0
716- let factoryActionsSingle = [invoke(factoryAddressOrFail, "stringEntry", [keyBlockProcessed(targetBlockHeight), makeString([toBase58String(i.transactionId), toString(currentPeriodOrFail), toString(generator), toBase58String(userAddressBytes), toString(treasuryRewardOrFail), toString(callerReward), toString(lpAssetAmount)], SEP)], nil), invoke(factoryAddressOrFail, "integerEntry", [keyAvailable(generator), (available + lpAssetAmount)], nil)]
717- if ((factoryActionsSingle == factoryActionsSingle))
718- then {
719- let $t02784327876 = acc
720- let lpAssetAcc = $t02784327876._1
721- let rewardAcc = $t02784327876._2
722- $Tuple2((lpAssetAcc + lpAssetAmount), (rewardAcc + treasuryRewardOrFail))
723- }
724- else throw("Strict value is not equal to itself.")
725- }
726-
727- let list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]
728- let $t02814328219 = {
729- let $l = list
730- let $s = size($l)
731- let $acc0 = $Tuple2(0, 0)
732- func $f0_1 ($a,$i) = if (($i >= $s))
733- then $a
734- else map($a, $l[$i])
735-
736- func $f0_2 ($a,$i) = if (($i >= $s))
737- then $a
738- else throw("List size exceeds 40")
739-
740- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($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), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40)
741- }
742- if (($t02814328219 == $t02814328219))
743- then {
744- let rewardAmountTotal = $t02814328219._2
745- let lpAssetAmountTotal = $t02814328219._1
746- let businessTreasuryPart = valueOrElse(getInteger(factoryAddressOrFail, keyBusinessTreasuryPart()), 0)
747- let rewardToBusinessTreasuryAmount = fraction(rewardAmountTotal, businessTreasuryPart, SCALE8)
748- let rewardToMainTreasuryAmount = ((rewardAmountTotal - rewardToBusinessTreasuryAmount) - blockProcessingReward)
749- let invested = valueOrElse(getInteger(factoryAddressOrFail, keyInvested(unit)), 0)
750- let actions = [invoke(factoryAddressOrFail, "reissue", [lpAssetAmountTotal], nil), invoke(factoryAddressOrFail, "integerEntry", [keyNextBlockToProcess(), (nextBlockToProcess + blocksProcessingBatchSize)], nil), invoke(factoryAddressOrFail, "transferFromProxyTreasury", [mainTreasuryAddressOrFail.bytes, rewardToMainTreasuryAmount], nil), invoke(factoryAddressOrFail, "transferFromProxyTreasury", [userAddressBytes, blockProcessingReward], nil), invoke(factoryAddressOrFail, "transferFromProxyTreasury", [businessTreasuryAddressOrFail.bytes, rewardToBusinessTreasuryAmount], nil), invoke(factoryAddressOrFail, "integerEntry", [keyInvested(unit), (invested + rewardToMainTreasuryAmount)], nil)]
751- if ((actions == actions))
752- then $Tuple2(nil, unit)
753- else throw("Strict value is not equal to itself.")
754- }
755- else throw("Strict value is not equal to itself.")
756- }
757- else throw("Strict value is not equal to itself.")
758- }
759-
760-
761-@Verifier(tx)
762-func verify () = {
763- let publicKey = match getManagerPublicKeyOrUnit() {
764- case pub: ByteVector =>
765- pub
766- case _ =>
767- tx.senderPublicKey
768- }
769- sigVerify(tx.bodyBytes, tx.proofs[0], publicKey)
770- }
77144

github/deemru/w8io/169f3d6 
46.91 ms