tx · 4Dqtd1ucyeBYQGnhd2rjxCgyLSiKGrYLdSKynpGHaN5A 3N1HdGqmcf4nVsUgmWiwB8p6p8ErWBmvQua: -0.01000000 Waves 2023.11.16 15:47 [2845957] smart account 3N1HdGqmcf4nVsUgmWiwB8p6p8ErWBmvQua > SELF 0.00000000 Waves
{ "type": 13, "id": "4Dqtd1ucyeBYQGnhd2rjxCgyLSiKGrYLdSKynpGHaN5A", "fee": 1000000, "feeAssetId": null, "timestamp": 1700138882110, "version": 2, "chainId": 84, "sender": "3N1HdGqmcf4nVsUgmWiwB8p6p8ErWBmvQua", "senderPublicKey": "JAEVvs5E9kGyXWx3YQaivUpUP3vb3pgr2eS6UrYr1A8P", "proofs": [ "2Rhe8J2yq87ymfzBbe2mobXioKhqgfzPjQjK7CUUw9Y9FUg5NhKSCo3mj9xYaFDonQTMLYKpGgixRxekLVkiYFWp", "4119BBjn5TVQPKgcpKykKK8X3q5psh2cSGEVRUXfKTujvPqHn7hQ3yN57McLUxDoP7ayGNn6d4jTq7m1LELZETw4" ], "script": "base64:AAIFAAAAAAAAAAgIAhIAEgASAAAAAA0AAAAAC1NUQUtFX0FTU0VUAQAAACD7LPnYlf1swEEEPtZwmjNnqQeXDdHWpLonOTtKfVOsIgAAAAAKRUFSTl9BU1NFVAEAAAAg+yz52JX9bMBBBD7WcJozZ6kHlw3R1qS6Jzk7Sn1TrCIAAAAADVRPS0VOU19QRVJfTVMAAAAAAAAAAAEAAAAAA1NFUAIAAAACX18AAAAAC0RFTk9NSU5BVE9SAA3gtrOnZAAAAQAAABB1c2VyRGVwb3NpdGVkS2V5AAAAAQAAAAR1c2VyCQAEuQAAAAIJAARMAAAAAgIAAAACdWQJAARMAAAAAgkAAlgAAAABCAUAAAAEdXNlcgAAAAVieXRlcwUAAAADbmlsBQAAAANTRVABAAAAEXRvdGFsRGVwb3NpdGVkS2V5AAAAAAIAAAACdGQBAAAADWxhc3RVcGRhdGVLZXkAAAAAAgAAAAJsdQEAAAAXcmV3Y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AAt1c2VyUmV3YXJkcwAAAAEIBQAAAAFpAAAABmNhbGxlcgAAAAAAAAAAAAUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXnKGAYQ", "height": 2845957, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Ga8ix3Wcaf4Hr4JJR7B1r4T3TtmjmwKU4yRqNorkHQGZ Next: G8PPjDoVTucoiTTZmikHFVkxRAmUtf9aKmTzp9uKSVJz Diff:
Old | New | Differences | |
---|---|---|---|
73 | 73 | ||
74 | 74 | ||
75 | 75 | @Callable(i) | |
76 | + | func update () = [IntegerEntry(lastUpdateKey(), lastBlock.timestamp), StringEntry(rewardPerTokenStoredKey(), toString(calcRewardPerTokenStored()))] | |
77 | + | ||
78 | + | ||
79 | + | ||
80 | + | @Callable(i) | |
76 | 81 | func deposit () = if (if ((size(i.payments) != 1)) | |
77 | 82 | then true | |
78 | 83 | else (i.payments[0].assetId != STAKE_ASSET)) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let STAKE_ASSET = base58'HuV7L2uJ4v2SDS5xqZLWPHhimTUgEMKstmxwfBY17SX3' | |
5 | 5 | ||
6 | 6 | let EARN_ASSET = base58'HuV7L2uJ4v2SDS5xqZLWPHhimTUgEMKstmxwfBY17SX3' | |
7 | 7 | ||
8 | 8 | let TOKENS_PER_MS = 1 | |
9 | 9 | ||
10 | 10 | let SEP = "__" | |
11 | 11 | ||
12 | 12 | let DENOMINATOR = 1000000000000000000 | |
13 | 13 | ||
14 | 14 | func userDepositedKey (user) = makeString(["ud", toBase58String(user.bytes)], SEP) | |
15 | 15 | ||
16 | 16 | ||
17 | 17 | func totalDepositedKey () = "td" | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func lastUpdateKey () = "lu" | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func rewardPerTokenStoredKey () = "rpts" | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func userRewardPerTokenPaidKey (user) = makeString(["urpd", toBase58String(user.bytes)], SEP) | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func userRewards (user) = makeString(["ur", toBase58String(user.bytes)], SEP) | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func calcRewardPerTokenStored () = { | |
33 | 33 | let totalDeposited = toBigInt( match getInteger(totalDepositedKey()) { | |
34 | 34 | case a: Int => | |
35 | 35 | a | |
36 | 36 | case _ => | |
37 | 37 | 0 | |
38 | 38 | }) | |
39 | 39 | let lastUpdate = toBigInt( match getInteger(lastUpdateKey()) { | |
40 | 40 | case a: Int => | |
41 | 41 | a | |
42 | 42 | case _ => | |
43 | 43 | lastBlock.timestamp | |
44 | 44 | }) | |
45 | 45 | let rewardPerTokenStored = parseBigIntValue( match getString(rewardPerTokenStoredKey()) { | |
46 | 46 | case a: String => | |
47 | 47 | a | |
48 | 48 | case _ => | |
49 | 49 | "0" | |
50 | 50 | }) | |
51 | 51 | if ((totalDeposited == toBigInt(0))) | |
52 | 52 | then rewardPerTokenStored | |
53 | 53 | else (rewardPerTokenStored + (((toBigInt(TOKENS_PER_MS) * (toBigInt(lastBlock.timestamp) - lastUpdate)) * toBigInt(DENOMINATOR)) / totalDeposited)) | |
54 | 54 | } | |
55 | 55 | ||
56 | 56 | ||
57 | 57 | func earned (user) = { | |
58 | 58 | let userDeposited = toBigInt( match getInteger(userDepositedKey(user)) { | |
59 | 59 | case a: Int => | |
60 | 60 | a | |
61 | 61 | case _ => | |
62 | 62 | 0 | |
63 | 63 | }) | |
64 | 64 | let userRewardPerTokenPaid = parseBigIntValue(getStringValue(userRewardPerTokenPaidKey(user))) | |
65 | 65 | let rewards = toBigInt( match getInteger(userRewards(user)) { | |
66 | 66 | case a: Int => | |
67 | 67 | a | |
68 | 68 | case _ => | |
69 | 69 | 0 | |
70 | 70 | }) | |
71 | 71 | (fraction(userDeposited, (calcRewardPerTokenStored() - userRewardPerTokenPaid), toBigInt(DENOMINATOR)) + rewards) | |
72 | 72 | } | |
73 | 73 | ||
74 | 74 | ||
75 | 75 | @Callable(i) | |
76 | + | func update () = [IntegerEntry(lastUpdateKey(), lastBlock.timestamp), StringEntry(rewardPerTokenStoredKey(), toString(calcRewardPerTokenStored()))] | |
77 | + | ||
78 | + | ||
79 | + | ||
80 | + | @Callable(i) | |
76 | 81 | func deposit () = if (if ((size(i.payments) != 1)) | |
77 | 82 | then true | |
78 | 83 | else (i.payments[0].assetId != STAKE_ASSET)) | |
79 | 84 | then throw("incorrect asset deposits") | |
80 | 85 | else { | |
81 | 86 | let userDeposited = match getInteger(userDepositedKey(i.caller)) { | |
82 | 87 | case a: Int => | |
83 | 88 | a | |
84 | 89 | case _ => | |
85 | 90 | 0 | |
86 | 91 | } | |
87 | 92 | let totalDeposited = match getInteger(totalDepositedKey()) { | |
88 | 93 | case a: Int => | |
89 | 94 | a | |
90 | 95 | case _ => | |
91 | 96 | 0 | |
92 | 97 | } | |
93 | 98 | [IntegerEntry(userDepositedKey(i.caller), (userDeposited + i.payments[0].amount)), IntegerEntry(totalDepositedKey(), (totalDeposited + i.payments[0].amount)), IntegerEntry(lastUpdateKey(), lastBlock.timestamp), StringEntry(rewardPerTokenStoredKey(), toString(calcRewardPerTokenStored())), StringEntry(userRewardPerTokenPaidKey(i.caller), toString(calcRewardPerTokenStored())), IntegerEntry(userRewards(i.caller), if ((userDeposited == 0)) | |
94 | 99 | then 0 | |
95 | 100 | else toInt(earned(i.caller)))] | |
96 | 101 | } | |
97 | 102 | ||
98 | 103 | ||
99 | 104 | ||
100 | 105 | @Callable(i) | |
101 | 106 | func withdraw () = { | |
102 | 107 | let userDeposited = match getInteger(userDepositedKey(i.caller)) { | |
103 | 108 | case a: Int => | |
104 | 109 | a | |
105 | 110 | case _ => | |
106 | 111 | 0 | |
107 | 112 | } | |
108 | 113 | let totalDeposited = match getInteger(totalDepositedKey()) { | |
109 | 114 | case a: Int => | |
110 | 115 | a | |
111 | 116 | case _ => | |
112 | 117 | 0 | |
113 | 118 | } | |
114 | 119 | let earnedTokens = toInt(earned(i.caller)) | |
115 | 120 | if ((userDeposited == 0)) | |
116 | 121 | then throw("empty deposit") | |
117 | 122 | else [IntegerEntry(userDepositedKey(i.caller), 0), IntegerEntry(totalDepositedKey(), (totalDeposited - userDeposited)), IntegerEntry(lastUpdateKey(), lastBlock.timestamp), ScriptTransfer(i.caller, userDeposited, STAKE_ASSET), ScriptTransfer(i.caller, earnedTokens, EARN_ASSET), StringEntry(rewardPerTokenStoredKey(), toString(calcRewardPerTokenStored())), StringEntry(userRewardPerTokenPaidKey(i.caller), toString(calcRewardPerTokenStored())), IntegerEntry(userRewards(i.caller), 0)] | |
118 | 123 | } | |
119 | 124 | ||
120 | 125 | ||
121 | 126 | @Verifier(tx) | |
122 | 127 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
123 | 128 |
github/deemru/w8io/026f985 28.22 ms ◑