tx · hah8iB6uvj4swZWNkirWF9SkAwovKTnrUK474VyKF2s 3N1HdGqmcf4nVsUgmWiwB8p6p8ErWBmvQua: -0.01000000 Waves 2023.11.16 02:45 [2845148] smart account 3N1HdGqmcf4nVsUgmWiwB8p6p8ErWBmvQua > SELF 0.00000000 Waves
{ "type": 13, "id": "hah8iB6uvj4swZWNkirWF9SkAwovKTnrUK474VyKF2s", "fee": 1000000, "feeAssetId": null, "timestamp": 1700091975352, "version": 2, "chainId": 84, "sender": "3N1HdGqmcf4nVsUgmWiwB8p6p8ErWBmvQua", "senderPublicKey": "JAEVvs5E9kGyXWx3YQaivUpUP3vb3pgr2eS6UrYr1A8P", "proofs": [ "5jG4aL8mcbpJGBxTdeNfji1P1cxbEHVgrqiMD9nTGJRsguquN7J5SdMHGdBfk7G6CXkiUSYoEueVysrvqbWXZqQD" ], "script": "base64:AAIFAAAAAAAAAAYIAhIAEgAAAAAOAAAAAAtTVEFLRV9BU1NFVAEAAAAg+yz52JX9bMBBBD7WcJozZ6kHlw3R1qS6Jzk7Sn1TrCIAAAAACkVBUk5fQVNTRVQBAAAAIPss+diV/WzAQQQ+1nCaM2epB5cN0dakuic5O0p9U6wiAAAAAA1UT0tFTlNfUEVSX01TAAAAAAAAAAABAAAAAANTRVACAAAAAl9fAAAAAAtERU5PTUlOQVRPUgAN4Lazp2QAAAEAAAAQdXNlckRlcG9zaXRlZEtleQAAAAEAAAAEdXNlcgkABLkAAAACCQAETAAAAAICAAAAAnVkCQAETAAAAAIJAAJYAAAAAQgFAAAABHVzZXIAAAAFYnl0ZXMFAAAAA25pbAUAAAADU0VQAQAAAA11c2VyVXBkYXRlS2V5AAAAAQAAAAR1c2VyCQAEuQAAAAIJAARMAAAAAgIAAAACdXUJAARMAAAAAgkAAlgAAAABCAUAAAAEdXNlcgAAAAVieXRlcwUAAAADbmlsBQAAAANTRVABAAAAEXRvdGFsRGVwb3NpdGVkS2V5AAAAAAIAAAACdGQBAAAADWxhc3RVcGRhdGVLZX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AAAMZWFybmVkVG9rZW5zBQAAAApFQVJOX0FTU0VUCQAETAAAAAIJAQAAAAtTdHJpbmdFbnRyeQAAAAIJAQAAABdyZXdhcmRQZXJUb2tlblN0b3JlZEtleQAAAAAJAAGmAAAAAQkBAAAAGGNhbGNSZXdhcmRQZXJUb2tlblN0b3JlZAAAAAAJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkBAAAAGXVzZXJSZXdhcmRQZXJUb2tlblBhaWRLZXkAAAABCAUAAAABaQAAAAZjYWxsZXIJAAGmAAAAAQkBAAAAGGNhbGNSZXdhcmRQZXJUb2tlblN0b3JlZAAAAAAJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAt1c2VyUmV3YXJkcwAAAAEIBQAAAAFpAAAABmNhbGxlcgAAAAAAAAAAAAUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXk/SLWU", "height": 2845148, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: EYsuSB85qVP5CHACifn15JWJqT4bv6SwciDkamS7PD1R Next: BS2Kj2aJ7qKMCqBgpk31hUX8YUitXf1eQKcb1MNa9tmA Diff:
Old | New | Differences | |
---|---|---|---|
76 | 76 | else (i.payments[0].assetId != STAKE_ASSET)) | |
77 | 77 | then throw("incorrect asset deposits") | |
78 | 78 | else { | |
79 | - | let userDeposited = getIntegerValue(userDepositedKey(i.caller)) | |
80 | - | let totalDeposited = getIntegerValue(totalDepositedKey()) | |
79 | + | let userDeposited = match getInteger(userDepositedKey(i.caller)) { | |
80 | + | case a: Int => | |
81 | + | a | |
82 | + | case _ => | |
83 | + | 0 | |
84 | + | } | |
85 | + | let totalDeposited = match getInteger(totalDepositedKey()) { | |
86 | + | case a: Int => | |
87 | + | a | |
88 | + | case _ => | |
89 | + | 0 | |
90 | + | } | |
81 | 91 | [IntegerEntry(userDepositedKey(i.caller), (userDeposited + i.payments[0].amount)), IntegerEntry(totalDepositedKey(), (totalDeposited + i.payments[0].amount)), StringEntry(rewardPerTokenStoredKey(), toString(calcRewardPerTokenStored())), StringEntry(userRewardPerTokenPaidKey(i.caller), toString(calcRewardPerTokenStored())), IntegerEntry(userRewards(i.caller), toInt(earned(i.caller)))] | |
82 | 92 | } | |
83 | 93 | ||
85 | 95 | ||
86 | 96 | @Callable(i) | |
87 | 97 | func withdraw () = { | |
88 | - | let userDeposited = getIntegerValue(userDepositedKey(i.caller)) | |
89 | - | let totalDeposited = getIntegerValue(totalDepositedKey()) | |
98 | + | let userDeposited = match getInteger(userDepositedKey(i.caller)) { | |
99 | + | case a: Int => | |
100 | + | a | |
101 | + | case _ => | |
102 | + | 0 | |
103 | + | } | |
104 | + | let totalDeposited = match getInteger(totalDepositedKey()) { | |
105 | + | case a: Int => | |
106 | + | a | |
107 | + | case _ => | |
108 | + | 0 | |
109 | + | } | |
90 | 110 | let earnedTokens = toInt(earned(i.caller)) | |
91 | 111 | [IntegerEntry(userDepositedKey(i.caller), 0), IntegerEntry(totalDepositedKey(), (totalDeposited - userDeposited)), 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)] | |
92 | 112 | } |
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 userUpdateKey (user) = makeString(["uu", toBase58String(user.bytes)], SEP) | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func totalDepositedKey () = "td" | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func lastUpdateKey () = "lu" | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func rewardPerTokenStoredKey () = "rpts" | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func userRewardPerTokenPaidKey (user) = makeString(["urpd", toBase58String(user.bytes)], SEP) | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func userRewards (user) = makeString(["ur", toBase58String(user.bytes)], SEP) | |
33 | 33 | ||
34 | 34 | ||
35 | 35 | func calcRewardPerTokenStored () = { | |
36 | 36 | let totalDeposited = toBigInt( match getInteger(totalDepositedKey()) { | |
37 | 37 | case a: Int => | |
38 | 38 | a | |
39 | 39 | case _ => | |
40 | 40 | 0 | |
41 | 41 | }) | |
42 | 42 | let lastUpdate = toBigInt( match getInteger(lastUpdateKey()) { | |
43 | 43 | case a: Int => | |
44 | 44 | a | |
45 | 45 | case _ => | |
46 | 46 | lastBlock.timestamp | |
47 | 47 | }) | |
48 | 48 | let rewardPerTokenStored = parseBigIntValue( match getString(rewardPerTokenStoredKey()) { | |
49 | 49 | case a: String => | |
50 | 50 | a | |
51 | 51 | case _ => | |
52 | 52 | "0" | |
53 | 53 | }) | |
54 | 54 | if ((totalDeposited == toBigInt(0))) | |
55 | 55 | then rewardPerTokenStored | |
56 | 56 | else (rewardPerTokenStored + (((toBigInt(TOKENS_PER_MS) * (toBigInt(lastBlock.timestamp) - lastUpdate)) * toBigInt(DENOMINATOR)) / totalDeposited)) | |
57 | 57 | } | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | func earned (user) = { | |
61 | 61 | let userDeposited = toBigInt(getIntegerValue(userDepositedKey(user))) | |
62 | 62 | let userRewardPerTokenPaid = toBigInt(getIntegerValue(userRewardPerTokenPaidKey(user))) | |
63 | 63 | let rewards = toBigInt( match getInteger(userRewards(user)) { | |
64 | 64 | case a: Int => | |
65 | 65 | a | |
66 | 66 | case _ => | |
67 | 67 | 0 | |
68 | 68 | }) | |
69 | 69 | (fraction(userDeposited, (calcRewardPerTokenStored() - userRewardPerTokenPaid), toBigInt(DENOMINATOR)) + rewards) | |
70 | 70 | } | |
71 | 71 | ||
72 | 72 | ||
73 | 73 | @Callable(i) | |
74 | 74 | func deposit () = if (if ((size(i.payments) != 1)) | |
75 | 75 | then true | |
76 | 76 | else (i.payments[0].assetId != STAKE_ASSET)) | |
77 | 77 | then throw("incorrect asset deposits") | |
78 | 78 | else { | |
79 | - | let userDeposited = getIntegerValue(userDepositedKey(i.caller)) | |
80 | - | let totalDeposited = getIntegerValue(totalDepositedKey()) | |
79 | + | let userDeposited = match getInteger(userDepositedKey(i.caller)) { | |
80 | + | case a: Int => | |
81 | + | a | |
82 | + | case _ => | |
83 | + | 0 | |
84 | + | } | |
85 | + | let totalDeposited = match getInteger(totalDepositedKey()) { | |
86 | + | case a: Int => | |
87 | + | a | |
88 | + | case _ => | |
89 | + | 0 | |
90 | + | } | |
81 | 91 | [IntegerEntry(userDepositedKey(i.caller), (userDeposited + i.payments[0].amount)), IntegerEntry(totalDepositedKey(), (totalDeposited + i.payments[0].amount)), StringEntry(rewardPerTokenStoredKey(), toString(calcRewardPerTokenStored())), StringEntry(userRewardPerTokenPaidKey(i.caller), toString(calcRewardPerTokenStored())), IntegerEntry(userRewards(i.caller), toInt(earned(i.caller)))] | |
82 | 92 | } | |
83 | 93 | ||
84 | 94 | ||
85 | 95 | ||
86 | 96 | @Callable(i) | |
87 | 97 | func withdraw () = { | |
88 | - | let userDeposited = getIntegerValue(userDepositedKey(i.caller)) | |
89 | - | let totalDeposited = getIntegerValue(totalDepositedKey()) | |
98 | + | let userDeposited = match getInteger(userDepositedKey(i.caller)) { | |
99 | + | case a: Int => | |
100 | + | a | |
101 | + | case _ => | |
102 | + | 0 | |
103 | + | } | |
104 | + | let totalDeposited = match getInteger(totalDepositedKey()) { | |
105 | + | case a: Int => | |
106 | + | a | |
107 | + | case _ => | |
108 | + | 0 | |
109 | + | } | |
90 | 110 | let earnedTokens = toInt(earned(i.caller)) | |
91 | 111 | [IntegerEntry(userDepositedKey(i.caller), 0), IntegerEntry(totalDepositedKey(), (totalDeposited - userDeposited)), 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)] | |
92 | 112 | } | |
93 | 113 | ||
94 | 114 | ||
95 | 115 | @Verifier(tx) | |
96 | 116 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
97 | 117 |
github/deemru/w8io/026f985 28.05 ms ◑