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