tx · 3QdAbedjLjm8845Yn7uw5nKzf1orfQMgnw9ALzA14mg4

3MvVH33KASni1qXr1BJhmuwPnYKmgwZBGaR:  -0.00500000 Waves

2023.03.16 13:54 [2492487] smart account 3MvVH33KASni1qXr1BJhmuwPnYKmgwZBGaR > SELF 0.00000000 Waves

{ "type": 13, "id": "3QdAbedjLjm8845Yn7uw5nKzf1orfQMgnw9ALzA14mg4", "fee": 500000, "feeAssetId": null, "timestamp": 1678964105097, "version": 2, "chainId": 84, "sender": "3MvVH33KASni1qXr1BJhmuwPnYKmgwZBGaR", "senderPublicKey": "2uEfkKMnD8wQeJcHwphftPPzFcaujs486fDaMuUyNT9w", "proofs": [ "252MDEwsGEMNZLAuSPp6TbcNqSTPWQGwZ6LAoQkWchcNpSbbvrBdkts7yNxxUnLGuwfiPJCM1CzcQmdYaV1mReBL" ], "script": null, "height": 2492487, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6EaiH4bKxMKgKi4CRLqJWMo9Jk5Xdgmi7cwMhsTXxrL4 Next: CY9rCQNJKwo97tNJwE1JsGsgMMeXTR4dzWncCZ3ogWCf Full:
OldNewDifferences
1-{-# STDLIB_VERSION 6 #-}
2-{-# SCRIPT_TYPE ACCOUNT #-}
3-{-# CONTENT_TYPE DAPP #-}
4-let separator = "__"
5-
6-let shareAssetDecimals = 8
7-
8-let wavesString = "WAVES"
9-
10-let scale18 = 1000000000000000000
11-
12-let scale18BigInt = toBigInt(scale18)
13-
14-func wrapErr (msg) = makeString(["lp_staking_pools.ride:", msg], " ")
15-
16-
17-func throwErr (msg) = throw(wrapErr(msg))
18-
19-
20-func errKeyIsNotDefined (address,key) = wrapErr(makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
21-
22-
23-func getStrOrFail (address,key) = valueOrErrorMessage(getString(address, key), errKeyIsNotDefined(address, key))
24-
25-
26-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), errKeyIsNotDefined(address, key))
27-
28-
29-func parseAssetId (input) = if ((input == wavesString))
30- then unit
31- else fromBase58String(input)
32-
33-
34-func assetIdToString (input) = if ((input == unit))
35- then wavesString
36- else toBase58String(value(input))
37-
38-
39-func ensurePositive (v) = if ((v >= 0))
40- then v
41- else throwErr("value should be positive")
42-
43-
44-func keyFactoryContract () = makeString(["%s", "factoryContract"], separator)
45-
46-
47-func keyLpStakingContract () = makeString(["%s", "lpStakingContract"], separator)
48-
49-
50-func keyStakingContract () = makeString(["%s", "stakingContract"], separator)
51-
52-
53-func keyBoostingContract () = makeString(["%s", "boostingContract"], separator)
54-
55-
56-func keySwapContract () = makeString(["%s", "swapContract"], separator)
57-
58-
59-func keyAssetsStoreContract () = makeString(["%s", "assetsStoreContract"], separator)
60-
61-
62-func keyUsdtAssetId () = makeString(["%s", "usdtAssetId"], separator)
63-
64-
65-func keyWxAssetId () = makeString(["%s", "wxAssetId"], separator)
66-
67-
68-func keyShutdown () = makeString(["%s", "shutdown"], separator)
69-
70-
71-func keyMinDelay () = makeString(["%s", "minDelay"], separator)
72-
73-
74-func keyLockFraction () = makeString(["%s", "lockFraction"], separator)
75-
76-
77-func keyShareAssetId (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetId"], separator)
78-
79-
80-func keyBaseAssetId (shareAssetId) = makeString(["%s%s", assetIdToString(shareAssetId), "baseAssetId"], separator)
81-
82-
83-func keyPeriod (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "period"], separator)
84-
85-
86-func keyPeriodStartHeight (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "periodStartHeight", toString(period)], separator)
87-
88-
89-func keyBaseAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "baseAssetAmountToConvert"], separator)
90-
91-
92-func keyShareAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetAmountToConvert"], separator)
93-
94-
95-func keyUserBaseAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert"], separator)
96-
97-
98-func keyUserBaseAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert", "period"], separator)
99-
100-
101-func keyUserShareAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert"], separator)
102-
103-
104-func keyUserShareAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert", "period"], separator)
105-
106-
107-func keyPricePeriod (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "price", toString(period)], separator)
108-
109-
110-func keyPriceHistory (baseAssetId) = makeString(["%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
111-
112-
113-func keyPricePeriodPut (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "put"], separator)
114-
115-
116-func keyPricePutHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "put", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
117-
118-
119-func keyPricePeriodGet (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "get"], separator)
120-
121-
122-func keyPriceGetHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "get", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
123-
124-
125-func keyHistoryEntry (baseAssetId,operation,period,userAddress,txId) = makeString(["%s%s%s%s", "history", operation, toString(userAddress), toBase58String(txId), toString(height)], separator)
126-
127-
128-func keyManagerPublicKey () = "%s__managerPublicKey"
129-
130-
131-func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
132-
133-
134-func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
135- case s: String =>
136- fromBase58String(s)
137- case _: Unit =>
138- unit
139- case _ =>
140- throw("Match error")
141-}
142-
143-
144-func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
145- case s: String =>
146- fromBase58String(s)
147- case _: Unit =>
148- unit
149- case _ =>
150- throw("Match error")
151-}
152-
153-
154-let permissionDeniedError = throw("Permission denied")
155-
156-func mustThis (i) = if ((i.caller == this))
157- then true
158- else permissionDeniedError
159-
160-
161-func mustManager (i) = match managerPublicKeyOrUnit() {
162- case pk: ByteVector =>
163- if ((i.callerPublicKey == pk))
164- then true
165- else permissionDeniedError
166- case _: Unit =>
167- mustThis(i)
168- case _ =>
169- throw("Match error")
170-}
171-
172-
173-let shutdown = valueOrElse(getBoolean(keyShutdown()), false)
174-
175-func shutdownCheck (i) = if (if (!(shutdown))
176- then true
177- else mustManager(i))
178- then true
179- else throw("operation is disabled")
180-
181-
182-let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract()))
183-
184-let lpStakingContract = addressFromStringValue(getStrOrFail(this, keyLpStakingContract()))
185-
186-let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract()))
187-
188-let boostingContract = addressFromStringValue(getStrOrFail(this, keyBoostingContract()))
189-
190-let swapContract = addressFromStringValue(getStrOrFail(this, keySwapContract()))
191-
192-let assetsStoreContract = addressFromStringValue(getStrOrFail(this, keyAssetsStoreContract()))
193-
194-let usdtAssetId = parseAssetId(getStrOrFail(this, keyUsdtAssetId()))
195-
196-let wxAssetId = parseAssetId(getStrOrFail(this, keyWxAssetId()))
197-
198-let minDelayDefault = 1440
199-
200-let minDelay = valueOrElse(getInteger(this, keyMinDelay()), minDelayDefault)
201-
202-let lockFractionMultiplier = 100000000
203-
204-let lockFractionDefault = fraction(1, lockFractionMultiplier, 2)
205-
206-let lockFraction = valueOrElse(getInteger(this, keyLockFraction()), lockFractionDefault)
207-
208-func getPoolInfo (amountAssetId) = {
209- let amountAssetIdStr = assetIdToString(amountAssetId)
210- let priceAssetIdStr = assetIdToString(usdtAssetId)
211- let poolInfoOption = {
212- let @ = invoke(factoryContract, "poolInfoREADONLY", [amountAssetIdStr, priceAssetIdStr], nil)
213- if ($isInstanceOf(@, "(Address, ByteVector)"))
214- then @
215- else unit
216- }
217- poolInfoOption
218- }
219-
220-
221-func calcPrice (lpAssetId,shareAssetId) = {
222- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), "failed to get share asset info")
223- let shareAssetEmission = shareAssetInfo.quantity
224- let stakedAmount = ensurePositive(valueOrErrorMessage({
225- let @ = invoke(stakingContract, "stakedByUserREADONLY", [assetIdToString(lpAssetId), toString(this)], nil)
226- if ($isInstanceOf(@, "Int"))
227- then @
228- else unit
229- }, wrapErr("invalid stakedByUserREADONLY result")))
230- let price = if ((shareAssetEmission == 0))
231- then scale18BigInt
232- else fraction(toBigInt(stakedAmount), scale18BigInt, toBigInt(shareAssetEmission), FLOOR)
233- price
234- }
235-
236-
237-@Callable(i)
238-func setManager (pendingManagerPublicKey) = {
239- let checkCaller = mustManager(i)
240- if ((checkCaller == checkCaller))
241- then {
242- let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
243- if ((checkManagerPublicKey == checkManagerPublicKey))
244- then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
245- else throw("Strict value is not equal to itself.")
246- }
247- else throw("Strict value is not equal to itself.")
248- }
249-
250-
251-
252-@Callable(i)
253-func confirmManager () = {
254- let pm = pendingManagerPublicKeyOrUnit()
255- let hasPM = if (isDefined(pm))
256- then true
257- else throwErr("no pending manager")
258- if ((hasPM == hasPM))
259- then {
260- let checkPM = if ((i.callerPublicKey == value(pm)))
261- then true
262- else throwErr("you are not pending manager")
263- if ((checkPM == checkPM))
264- then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
265- else throw("Strict value is not equal to itself.")
266- }
267- else throw("Strict value is not equal to itself.")
268- }
269-
270-
271-
272-@Callable(i)
273-func emit (assetId,amount) = {
274- let checkCaller = mustThis(i)
275- if ((checkCaller == checkCaller))
276- then {
277- let isReissuable = true
278- $Tuple2([Reissue(assetId, amount, isReissuable)], amount)
279- }
280- else throw("Strict value is not equal to itself.")
281- }
282-
283-
284-
285-@Callable(i)
286-func burn (assetId,amount) = {
287- let checkCaller = mustThis(i)
288- if ((checkCaller == checkCaller))
289- then $Tuple2([Burn(assetId, amount)], amount)
290- else throw("Strict value is not equal to itself.")
291- }
292-
293-
294-
295-@Callable(i)
296-func create (baseAssetIdStr,shareAssetIdStr,shareAssetName,shareAssetDescription,shareAssetLogo) = {
297- let shareAssetLabel = "STAKING_LP"
298- let baseAssetId = parseAssetId(baseAssetIdStr)
299- let checks = [mustManager(i), if (isDefined(getPoolInfo(baseAssetId)))
300- then true
301- else throwErr("invalid base asset")]
302- if ((checks == checks))
303- then {
304- let commonState = [IntegerEntry(keyPeriod(baseAssetId), 0)]
305- if ((shareAssetIdStr == ""))
306- then {
307- let shareAssetIssueAmount = 1
308- let shareAssetIssueAction = Issue(shareAssetName, shareAssetDescription, shareAssetIssueAmount, shareAssetDecimals, true)
309- let calculatedShareAssetId = calculateAssetId(shareAssetIssueAction)
310- let shareAssetBurnAction = Burn(calculatedShareAssetId, shareAssetIssueAmount)
311- let calculatedShareAssetIdStr = toBase58String(calculatedShareAssetId)
312- let createOrUpdate = invoke(assetsStoreContract, "createOrUpdate", [calculatedShareAssetIdStr, shareAssetLogo, false], nil)
313- if ((createOrUpdate == createOrUpdate))
314- then {
315- let addLabel = invoke(assetsStoreContract, "addLabel", [calculatedShareAssetIdStr, shareAssetLabel], nil)
316- if ((addLabel == addLabel))
317- then $Tuple2((commonState ++ [shareAssetIssueAction, shareAssetBurnAction, StringEntry(keyShareAssetId(baseAssetId), calculatedShareAssetIdStr), StringEntry(keyBaseAssetId(calculatedShareAssetId), baseAssetIdStr)]), calculatedShareAssetIdStr)
318- else throw("Strict value is not equal to itself.")
319- }
320- else throw("Strict value is not equal to itself.")
321- }
322- else {
323- let shareAssetId = fromBase58String(shareAssetIdStr)
324- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id"))
325- let checkIssuer = if ((shareAssetInfo.issuer == lpStakingContract))
326- then true
327- else throwErr("invalid share asset id issuer")
328- if ((checkIssuer == checkIssuer))
329- then $Tuple2((commonState ++ [StringEntry(keyShareAssetId(baseAssetId), shareAssetIdStr), StringEntry(keyBaseAssetId(shareAssetId), baseAssetIdStr)]), shareAssetIdStr)
330- else throw("Strict value is not equal to itself.")
331- }
332- }
333- else throw("Strict value is not equal to itself.")
334- }
335-
336-
337-
338-@Callable(i)
339-func put () = {
340- let pmt = if ((size(i.payments) == 1))
341- then i.payments[0]
342- else throwErr("exactly 1 payment is expected")
343- let baseAssetId = pmt.assetId
344- let userAddress = i.caller
345- let checks = [shutdownCheck(i), if (isDefined(getString(keyShareAssetId(baseAssetId))))
346- then true
347- else throwErr("invalid asset")]
348- if ((checks == checks))
349- then {
350- let $t01192312026 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
351- let poolAddress = $t01192312026._1
352- let lpAssetId = $t01192312026._2
353- let period = value(getInteger(keyPeriod(baseAssetId)))
354- let userBaseAssetAmountToConvertPeriodOption = getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress))
355- let claimShareAssetInvocation = if ((userBaseAssetAmountToConvertPeriodOption == unit))
356- then unit
357- else {
358- let userBaseAssetAmountToConvertPeriod = value(userBaseAssetAmountToConvertPeriodOption)
359- if ((userBaseAssetAmountToConvertPeriod == period))
360- then unit
361- else invoke(this, "claimShareAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil)
362- }
363- if ((claimShareAssetInvocation == claimShareAssetInvocation))
364- then {
365- let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0)
366- let userBaseAssetAmountToConvert = valueOrElse(getInteger(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress)), 0)
367- $Tuple2([IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), (baseAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), (userBaseAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress), period), IntegerEntry(keyHistoryEntry(baseAssetId, "put", period, userAddress, i.transactionId), pmt.amount)], unit)
368- }
369- else throw("Strict value is not equal to itself.")
370- }
371- else throw("Strict value is not equal to itself.")
372- }
373-
374-
375-
376-@Callable(i)
377-func claimShareAsset (baseAssetIdStr,userAddressStr) = {
378- let checks = [shutdownCheck(i)]
379- if ((checks == checks))
380- then {
381- let userAddress = if ((userAddressStr == ""))
382- then i.caller
383- else {
384- let checkCaller = mustThis(i)
385- if ((checkCaller == checkCaller))
386- then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
387- else throw("Strict value is not equal to itself.")
388- }
389- if ((userAddress == userAddress))
390- then {
391- let baseAssetId = parseAssetId(baseAssetIdStr)
392- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
393- if ((shareAssetId == shareAssetId))
394- then {
395- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
396- if ((period == period))
397- then {
398- let userBaseAssetAmountToConvert = valueOrElse(getInteger(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress)), 0)
399- let checkAmountToConvert = if ((userBaseAssetAmountToConvert > 0))
400- then true
401- else throwErr("nothing to claim")
402- if ((checkAmountToConvert == checkAmountToConvert))
403- then {
404- let userBaseAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period"))
405- let checkPeriod = if ((period > userBaseAssetAmountToConvertPeriod))
406- then true
407- else throwErr("invalid period")
408- if ((checkPeriod == checkPeriod))
409- then {
410- let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodPut(baseAssetId, userBaseAssetAmountToConvertPeriod)), wrapErr("failed to get price")))
411- let shareAssetAmount = toInt(fraction(toBigInt(userBaseAssetAmountToConvert), scale18BigInt, price))
412- $Tuple2([IntegerEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), 0), DeleteEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, shareAssetAmount, shareAssetId), IntegerEntry(keyHistoryEntry(baseAssetId, "claimShareAsset", period, userAddress, i.transactionId), shareAssetAmount)], unit)
413- }
414- else throw("Strict value is not equal to itself.")
415- }
416- else throw("Strict value is not equal to itself.")
417- }
418- else throw("Strict value is not equal to itself.")
419- }
420- else throw("Strict value is not equal to itself.")
421- }
422- else throw("Strict value is not equal to itself.")
423- }
424- else throw("Strict value is not equal to itself.")
425- }
426-
427-
428-
429-@Callable(i)
430-func get () = {
431- let checks = [shutdownCheck(i)]
432- if ((checks == checks))
433- then {
434- let pmt = if ((size(i.payments) == 1))
435- then i.payments[0]
436- else throwErr("exactly 1 payment is expected")
437- let shareAssetId = pmt.assetId
438- let baseAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyBaseAssetId(shareAssetId)), wrapErr("invalid share asset id"))))
439- if ((baseAssetId == baseAssetId))
440- then {
441- let userAddress = i.caller
442- let $t01582915932 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
443- let poolAddress = $t01582915932._1
444- let lpAssetId = $t01582915932._2
445- let period = value(getInteger(keyPeriod(baseAssetId)))
446- let userShareAssetAmountToConvertPeriodOption = getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress))
447- let claimBaseAssetInvocation = if ((userShareAssetAmountToConvertPeriodOption == unit))
448- then unit
449- else {
450- let userShareAssetAmountToConvertPeriod = value(userShareAssetAmountToConvertPeriodOption)
451- if ((userShareAssetAmountToConvertPeriod == period))
452- then unit
453- else invoke(this, "claimBaseAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil)
454- }
455- if ((claimBaseAssetInvocation == claimBaseAssetInvocation))
456- then {
457- let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0)
458- let userShareAssetAmountToConvert = valueOrElse(getInteger(keyUserShareAssetAmountToConvert(baseAssetId, userAddress)), 0)
459- $Tuple2([IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), (shareAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), (userShareAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress), period), IntegerEntry(keyHistoryEntry(baseAssetId, "get", period, userAddress, i.transactionId), pmt.amount)], unit)
460- }
461- else throw("Strict value is not equal to itself.")
462- }
463- else throw("Strict value is not equal to itself.")
464- }
465- else throw("Strict value is not equal to itself.")
466- }
467-
468-
469-
470-@Callable(i)
471-func claimBaseAsset (baseAssetIdStr,userAddressStr) = {
472- let checks = [shutdownCheck(i)]
473- if ((checks == checks))
474- then {
475- let userAddress = if ((userAddressStr == ""))
476- then i.caller
477- else {
478- let checkCaller = mustThis(i)
479- if ((checkCaller == checkCaller))
480- then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
481- else throw("Strict value is not equal to itself.")
482- }
483- if ((userAddress == userAddress))
484- then {
485- let baseAssetId = parseAssetId(baseAssetIdStr)
486- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
487- if ((shareAssetId == shareAssetId))
488- then {
489- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
490- if ((period == period))
491- then {
492- let userShareAssetAmountToConvert = valueOrElse(getInteger(keyUserShareAssetAmountToConvert(baseAssetId, userAddress)), 0)
493- let checkAmountToConvert = if ((userShareAssetAmountToConvert > 0))
494- then true
495- else throwErr("nothing to claim")
496- if ((checkAmountToConvert == checkAmountToConvert))
497- then {
498- let userShareAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period"))
499- let checkPeriod = if ((period > userShareAssetAmountToConvertPeriod))
500- then true
501- else throwErr("invalid period")
502- if ((checkPeriod == checkPeriod))
503- then {
504- let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodGet(baseAssetId, userShareAssetAmountToConvertPeriod)), wrapErr("failed to get price")))
505- let baseAssetAmount = toInt(fraction(toBigInt(userShareAssetAmountToConvert), price, scale18BigInt))
506- $Tuple2([IntegerEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), 0), DeleteEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, baseAssetAmount, baseAssetId), IntegerEntry(keyHistoryEntry(baseAssetId, "claimBaseAsset", period, userAddress, i.transactionId), baseAssetAmount)], unit)
507- }
508- else throw("Strict value is not equal to itself.")
509- }
510- else throw("Strict value is not equal to itself.")
511- }
512- else throw("Strict value is not equal to itself.")
513- }
514- else throw("Strict value is not equal to itself.")
515- }
516- else throw("Strict value is not equal to itself.")
517- }
518- else throw("Strict value is not equal to itself.")
519- }
520-
521-
522-
523-@Callable(i)
524-func finalize (baseAssetIdStr) = {
525- let checks = [shutdownCheck(i)]
526- if ((checks == checks))
527- then {
528- let baseAssetId = parseAssetId(baseAssetIdStr)
529- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
530- if ((shareAssetId == shareAssetId))
531- then {
532- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id"))
533- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
534- if ((period == period))
535- then {
536- let periodStartHeightOption = getInteger(keyPeriodStartHeight(baseAssetId, period))
537- let checkDelay = if ((periodStartHeightOption == unit))
538- then unit
539- else {
540- let delay = (height - value(periodStartHeightOption))
541- let blocksToWait = max([0, (minDelay - delay)])
542- if ((blocksToWait == 0))
543- then unit
544- else throwErr(makeString(["finalization will be possible in ", toString(blocksToWait), " blocks"], ""))
545- }
546- if ((checkDelay == checkDelay))
547- then {
548- let $t02008920274 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
549- let poolAddress = $t02008920274._1
550- let lpAssetId = $t02008920274._2
551- let stakingReward = valueOrErrorMessage({
552- let @ = invoke(stakingContract, "claimWxDoNotThrow", [assetIdToString(lpAssetId)], nil)
553- if ($isInstanceOf(@, "Int"))
554- then @
555- else unit
556- }, wrapErr("invalid claimWx result"))
557- if ((stakingReward == stakingReward))
558- then {
559- let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0)
560- let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0)
561- let checkFinalizationIsRequired = {
562- let isFinalizationRequired = if (if ((stakingReward > 0))
563- then true
564- else (baseAssetAmountToConvert > 0))
565- then true
566- else (shareAssetAmountToConvert > 0)
567- if (isFinalizationRequired)
568- then true
569- else throwErr("nothing to finalize")
570- }
571- if ((checkFinalizationIsRequired == checkFinalizationIsRequired))
572- then {
573- let useStakingReward = if ((stakingReward > 0))
574- then {
575- let lockPart = fraction(stakingReward, lockFraction, lockFractionMultiplier)
576- let convertPart = (stakingReward - lockPart)
577- let r = invoke(boostingContract, "userMaxDurationREADONLY", [toString(this)], nil)
578- let lock = if ((lockPart > 0))
579- then match r {
580- case _ =>
581- if (if (if ($isInstanceOf($match0._1, "String"))
582- then $isInstanceOf($match0._2, "Int")
583- else false)
584- then $isInstanceOf($match0, "(String, Int)")
585- else false)
586- then {
587- let function = $match0._1
588- let duration = $match0._2
589- if ((lockPart > 0))
590- then invoke(boostingContract, function, [duration], [AttachedPayment(wxAssetId, lockPart)])
591- else unit
592- }
593- else throwErr("invalid lock params")
594- }
595- else unit
596- if ((lock == lock))
597- then {
598- let convertedAmount = if ((convertPart > 0))
599- then {
600- let inAssetId = wxAssetId
601- let minimumToReceive = 0
602- let outAssetIdStr = assetIdToString(usdtAssetId)
603- let targetAddress = toString(this)
604- valueOrErrorMessage({
605- let @ = invoke(swapContract, "swap", [minimumToReceive, outAssetIdStr, targetAddress], [AttachedPayment(inAssetId, convertPart)])
606- if ($isInstanceOf(@, "Int"))
607- then @
608- else unit
609- }, wrapErr("invalid swap result"))
610- }
611- else 0
612- if ((convertedAmount == convertedAmount))
613- then {
614- let lpAssetAmount = if ((convertedAmount > 0))
615- then {
616- let minOutAmount = 0
617- let autoStake = true
618- valueOrErrorMessage({
619- let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(usdtAssetId, convertedAmount)])
620- if ($isInstanceOf(@, "Int"))
621- then @
622- else unit
623- }, wrapErr("invalid putOneTknV2 result"))
624- }
625- else 0
626- if ((lpAssetAmount == lpAssetAmount))
627- then lpAssetAmount
628- else throw("Strict value is not equal to itself.")
629- }
630- else throw("Strict value is not equal to itself.")
631- }
632- else throw("Strict value is not equal to itself.")
633- }
634- else unit
635- if ((useStakingReward == useStakingReward))
636- then {
637- let getActions = if ((shareAssetAmountToConvert > 0))
638- then {
639- let price = calcPrice(lpAssetId, shareAssetId)
640- if ((price == price))
641- then {
642- let unstakeAmount = toInt(fraction(toBigInt(shareAssetAmountToConvert), price, scale18BigInt, FLOOR))
643- let baseAssetAmount = {
644- let outAssetId = baseAssetId
645- let minOutAmount = 0
646- valueOrErrorMessage({
647- let @ = invoke(poolAddress, "unstakeAndGetOneTknV2", [unstakeAmount, assetIdToString(outAssetId), minOutAmount], nil)
648- if ($isInstanceOf(@, "Int"))
649- then @
650- else unit
651- }, wrapErr("invalid unstakeAndGetOneTknV2 result"))
652- }
653- if ((baseAssetAmount == baseAssetAmount))
654- then {
655- let shareAssetBurn = if ((shareAssetInfo.issuer == this))
656- then invoke(this, "burn", [shareAssetId, shareAssetAmountToConvert], nil)
657- else throwErr("invalid share asset issuer")
658- if ((shareAssetBurn == shareAssetBurn))
659- then {
660- let priceGet = fraction(toBigInt(baseAssetAmount), scale18BigInt, toBigInt(shareAssetAmountToConvert), FLOOR)
661- let priceGetUpdateActions = [BinaryEntry(keyPricePeriodGet(baseAssetId, period), toBytes(priceGet)), StringEntry(keyPriceGetHistory(baseAssetId), toString(priceGet))]
662- priceGetUpdateActions
663- }
664- else throw("Strict value is not equal to itself.")
665- }
666- else throw("Strict value is not equal to itself.")
667- }
668- else throw("Strict value is not equal to itself.")
669- }
670- else nil
671- if ((getActions == getActions))
672- then {
673- let putActions = if ((baseAssetAmountToConvert > 0))
674- then {
675- let lpAssetAmount = {
676- let minOutAmount = 0
677- let autoStake = true
678- valueOrErrorMessage({
679- let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(baseAssetId, baseAssetAmountToConvert)])
680- if ($isInstanceOf(@, "Int"))
681- then @
682- else unit
683- }, wrapErr("invalid putOneTknV2 result"))
684- }
685- if ((lpAssetAmount == lpAssetAmount))
686- then {
687- let price = calcPrice(lpAssetId, shareAssetId)
688- if ((price == price))
689- then {
690- let shareAssetAmount = toInt(fraction(toBigInt(lpAssetAmount), scale18BigInt, price, FLOOR))
691- let shareAssetReissue = if ((shareAssetInfo.issuer == this))
692- then invoke(this, "emit", [shareAssetId, shareAssetAmount], nil)
693- else throwErr("invalid share asset issuer")
694- if ((shareAssetReissue == shareAssetReissue))
695- then {
696- let pricePut = fraction(toBigInt(baseAssetAmountToConvert), scale18BigInt, toBigInt(shareAssetAmount))
697- let pricePutUpdateActions = [BinaryEntry(keyPricePeriodPut(baseAssetId, period), toBytes(pricePut)), StringEntry(keyPricePutHistory(baseAssetId), toString(pricePut))]
698- pricePutUpdateActions
699- }
700- else throw("Strict value is not equal to itself.")
701- }
702- else throw("Strict value is not equal to itself.")
703- }
704- else throw("Strict value is not equal to itself.")
705- }
706- else nil
707- if ((putActions == putActions))
708- then {
709- let newPeriod = (period + 1)
710- let lastPrice = calcPrice(lpAssetId, shareAssetId)
711- let actions = (([IntegerEntry(keyPeriod(baseAssetId), newPeriod), IntegerEntry(keyPeriodStartHeight(baseAssetId, newPeriod), height), IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), 0), IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), 0), BinaryEntry(keyPricePeriod(baseAssetId, period), toBytes(lastPrice)), StringEntry(keyPriceHistory(baseAssetId), toString(lastPrice))] ++ putActions) ++ getActions)
712- $Tuple2(actions, toBytes(lastPrice))
713- }
714- else throw("Strict value is not equal to itself.")
715- }
716- else throw("Strict value is not equal to itself.")
717- }
718- else throw("Strict value is not equal to itself.")
719- }
720- else throw("Strict value is not equal to itself.")
721- }
722- else throw("Strict value is not equal to itself.")
723- }
724- else throw("Strict value is not equal to itself.")
725- }
726- else throw("Strict value is not equal to itself.")
727- }
728- else throw("Strict value is not equal to itself.")
729- }
730- else throw("Strict value is not equal to itself.")
731- }
732-
733-
734-@Verifier(tx)
735-func verify () = {
736- let targetPublicKey = match managerPublicKeyOrUnit() {
737- case pk: ByteVector =>
738- pk
739- case _: Unit =>
740- tx.senderPublicKey
741- case _ =>
742- throw("Match error")
743- }
744- sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
745- }
746-
1+# no script

github/deemru/w8io/026f985 
44.13 ms