tx · HX2qcsRGvSQgnaxXsFFtksiF2352Mj4QzarSYFrTa4XA 3MsU428UzSefm85q7jvBsRV66Du7E72xEkL: -0.01000000 Waves 2022.06.10 10:59 [2090021] smart account 3MsU428UzSefm85q7jvBsRV66Du7E72xEkL > SELF 0.00000000 Waves
{ "type": 13, "id": "HX2qcsRGvSQgnaxXsFFtksiF2352Mj4QzarSYFrTa4XA", "fee": 1000000, "feeAssetId": null, "timestamp": 1654848021166, "version": 2, "chainId": 84, "sender": "3MsU428UzSefm85q7jvBsRV66Du7E72xEkL", "senderPublicKey": "58FFoU7LCj1DKboVntQXuE3KQDpf92NouXncN5b4vY8U", "proofs": [ "AsPqetPFPoDZ6g7NdZNzVXtCq6Bg8wneerZtG2xrGpaUNQDihAxDmUTw5gnyerrL4yXT4f4WuqTnYX7QXy74wPa" ], "script": "base64:AAIFAAAAAAAAAAsIAhIAEgMKAQESAAAAAAgAAAAACkRJU0NMQUlNRVICAAAAGnB1enpsZSBzdGFraW5nIHNjLiB0eXZtIDopAAAAAAVzY2FsZQAAAAAABfXhAAAAAAAIcHV6emxlSWQBAAAAIC03E4HTJDddn+FvdtPRD5PvLCz03YmtXEpW6HzJAXIbAAAAAAxlYXJuZWRBc3NldHMJAARMAAAAAgEAAAAgrZ1IFoWReWfvw0p6hpnR3VDpBUk85P5AREeM4YPEwvQFAAAAA25pbAAAAAASZWFybmVkQXNzZXRzQW1vdW50CQABkAAAAAEFAAAADGVhcm5lZEFzc2V0cwEAAAANdHJ5R2V0SW50ZWdlcgAAAAEAAAADa2V5BAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFiBQAAAAckbWF0Y2gwBQAAAAFiAAAAAAAAAAAAAQAAAB1jYWxjdWxhdGVDdXJyZW50QXNzZXRJbnRlcmVzdAAAAAIAAAAHYXNzZXRJZAAAAAphc3NldElkU3RyBAAAAAt0b3RhbFN0YWtl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JhbF9wdXp6bGVTdGFrZWQFAAAABmFtb3VudAUAAAADbmlsAAAAAWkBAAAABWNsYWltAAAAAAkBAAAAC2NsYWltUmVzdWx0AAAAAQgFAAAAAWkAAAAGY2FsbGVyAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXnmnFq1", "height": 2090021, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6eC7XpinLjD7ZWisd4M5TyHy41mSk9PgvHEUDHHc5UMq Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let DISCLAIMER = " | |
4 | + | let DISCLAIMER = "puzzle staking sc. tyvm :)" | |
5 | 5 | ||
6 | 6 | let scale = 100000000 | |
7 | 7 | ||
94 | 94 | ||
95 | 95 | ||
96 | 96 | @Callable(i) | |
97 | - | func unstake ( | |
97 | + | func unstake (amount) = { | |
98 | 98 | let addressStr = toString(i.caller) | |
99 | 99 | let puzzleAvailable = tryGetInteger((addressStr + "_puzzleStaked")) | |
100 | - | if (( | |
100 | + | if ((amount > puzzleAvailable)) | |
101 | 101 | then throw("you don't have PUZZLE available") | |
102 | - | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_puzzleStaked"), (puzzleAvailable - | |
102 | + | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_puzzleStaked"), (puzzleAvailable - amount)), IntegerEntry("global_puzzleStaked", (tryGetInteger("global_puzzleStaked") - amount))]) | |
103 | 103 | } | |
104 | 104 | ||
105 | 105 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let DISCLAIMER = " | |
4 | + | let DISCLAIMER = "puzzle staking sc. tyvm :)" | |
5 | 5 | ||
6 | 6 | let scale = 100000000 | |
7 | 7 | ||
8 | 8 | let puzzleId = base58'43W4FcqA1rEpSmUGHoGiXvpSLfhadws9LS5j3SJsKxxS' | |
9 | 9 | ||
10 | 10 | let earnedAssets = [base58'CgidgEMbCKXXErgJXVyZCFRaK8SBNA73Jg8mNXALtVKh'] | |
11 | 11 | ||
12 | 12 | let earnedAssetsAmount = size(earnedAssets) | |
13 | 13 | ||
14 | 14 | func tryGetInteger (key) = match getInteger(this, key) { | |
15 | 15 | case b: Int => | |
16 | 16 | b | |
17 | 17 | case _ => | |
18 | 18 | 0 | |
19 | 19 | } | |
20 | 20 | ||
21 | 21 | ||
22 | 22 | func calculateCurrentAssetInterest (assetId,assetIdStr) = { | |
23 | 23 | let totalStaked = tryGetInteger("global_puzzleStaked") | |
24 | 24 | let tokenBalanceLastCheck = tryGetInteger((("global_lastCheck_" + assetIdStr) + "_earnings")) | |
25 | 25 | let currentTokenEarnings = max([tokenBalanceLastCheck, assetBalance(this, assetId)]) | |
26 | 26 | let newEarnings = (currentTokenEarnings - tokenBalanceLastCheck) | |
27 | 27 | let newInterest = if ((totalStaked == 0)) | |
28 | 28 | then 0 | |
29 | 29 | else fraction(newEarnings, scale, totalStaked) | |
30 | 30 | let lastCheckInterest = tryGetInteger((("global_lastCheck_" + assetIdStr) + "_interest")) | |
31 | 31 | (lastCheckInterest + newInterest) | |
32 | 32 | } | |
33 | 33 | ||
34 | 34 | ||
35 | 35 | func claimResult (address) = { | |
36 | 36 | let addressStr = toString(address) | |
37 | 37 | let puzzleAmount = tryGetInteger((addressStr + "_puzzleStaked")) | |
38 | 38 | func handler (accum,assetId) = { | |
39 | 39 | let assetIdStr = toBase58String(assetId) | |
40 | 40 | let currentTokenInterest = calculateCurrentAssetInterest(assetId, assetIdStr) | |
41 | 41 | let currentTokenEarnings = max([tryGetInteger((("global_lastCheck_" + assetIdStr) + "_earnings")), assetBalance(this, assetId)]) | |
42 | 42 | let rewardAmount = fraction(puzzleAmount, (currentTokenInterest - tryGetInteger((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"))), scale) | |
43 | 43 | if ((rewardAmount == 0)) | |
44 | 44 | then accum | |
45 | 45 | else (accum ++ [IntegerEntry((("global_lastCheck_" + assetIdStr) + "_earnings"), (currentTokenEarnings - rewardAmount)), IntegerEntry((("global_lastCheck_" + assetIdStr) + "_interest"), currentTokenInterest), IntegerEntry((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"), currentTokenInterest), ScriptTransfer(address, rewardAmount, assetId)]) | |
46 | 46 | } | |
47 | 47 | ||
48 | 48 | let $l = earnedAssets | |
49 | 49 | let $s = size($l) | |
50 | 50 | let $acc0 = nil | |
51 | 51 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
52 | 52 | then $a | |
53 | 53 | else handler($a, $l[$i]) | |
54 | 54 | ||
55 | 55 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
56 | 56 | then $a | |
57 | 57 | else throw("List size exceeds 17") | |
58 | 58 | ||
59 | 59 | $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($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) | |
60 | 60 | } | |
61 | 61 | ||
62 | 62 | ||
63 | 63 | @Callable(i) | |
64 | 64 | func stake () = { | |
65 | 65 | let addressStr = toString(i.caller) | |
66 | 66 | let pmt = i.payments[0] | |
67 | 67 | if ((value(pmt.assetId) != puzzleId)) | |
68 | 68 | then throw("wrong asset attached") | |
69 | 69 | else { | |
70 | 70 | func handler (accum,assetId) = { | |
71 | 71 | let assetIdStr = toBase58String(assetId) | |
72 | 72 | let currentTokenInterest = calculateCurrentAssetInterest(assetId, assetIdStr) | |
73 | 73 | (accum ++ [IntegerEntry((("global_lastCheck_" + assetIdStr) + "_earnings"), assetBalance(this, assetId)), IntegerEntry((("global_lastCheck_" + assetIdStr) + "_interest"), currentTokenInterest), IntegerEntry((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"), currentTokenInterest)]) | |
74 | 74 | } | |
75 | 75 | ||
76 | 76 | let li = { | |
77 | 77 | let $l = earnedAssets | |
78 | 78 | let $s = size($l) | |
79 | 79 | let $acc0 = nil | |
80 | 80 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
81 | 81 | then $a | |
82 | 82 | else handler($a, $l[$i]) | |
83 | 83 | ||
84 | 84 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
85 | 85 | then $a | |
86 | 86 | else throw("List size exceeds 17") | |
87 | 87 | ||
88 | 88 | $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($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) | |
89 | 89 | } | |
90 | 90 | (li ++ [IntegerEntry((addressStr + "_puzzleStaked"), (tryGetInteger((addressStr + "_puzzleStaked")) + pmt.amount)), IntegerEntry("global_puzzleStaked", (tryGetInteger("global_puzzleStaked") + pmt.amount))]) | |
91 | 91 | } | |
92 | 92 | } | |
93 | 93 | ||
94 | 94 | ||
95 | 95 | ||
96 | 96 | @Callable(i) | |
97 | - | func unstake ( | |
97 | + | func unstake (amount) = { | |
98 | 98 | let addressStr = toString(i.caller) | |
99 | 99 | let puzzleAvailable = tryGetInteger((addressStr + "_puzzleStaked")) | |
100 | - | if (( | |
100 | + | if ((amount > puzzleAvailable)) | |
101 | 101 | then throw("you don't have PUZZLE available") | |
102 | - | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_puzzleStaked"), (puzzleAvailable - | |
102 | + | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_puzzleStaked"), (puzzleAvailable - amount)), IntegerEntry("global_puzzleStaked", (tryGetInteger("global_puzzleStaked") - amount))]) | |
103 | 103 | } | |
104 | 104 | ||
105 | 105 | ||
106 | 106 | ||
107 | 107 | @Callable(i) | |
108 | 108 | func claim () = claimResult(i.caller) | |
109 | 109 | ||
110 | 110 | ||
111 | 111 | @Verifier(tx) | |
112 | 112 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
113 | 113 |
github/deemru/w8io/169f3d6 58.68 ms ◑