tx · PYNG8TMuBwimUwnB5ZYa9rph4C7Q8CoRj6sFmub1CKv

3Msj81YL4DxQdbQACtfXhMbpWmze1VVnctu:  -0.01000000 Waves

2022.10.17 08:56 [2275981] smart account 3Msj81YL4DxQdbQACtfXhMbpWmze1VVnctu > SELF 0.00000000 Waves

{ "type": 13, "id": "PYNG8TMuBwimUwnB5ZYa9rph4C7Q8CoRj6sFmub1CKv", "fee": 1000000, "feeAssetId": null, "timestamp": 1665986296621, "version": 2, "chainId": 84, "sender": "3Msj81YL4DxQdbQACtfXhMbpWmze1VVnctu", "senderPublicKey": "28hGQdonCy33HT27DAdzF7rwYRv24Nizp2yBBtwjRUia", "proofs": [ "52VXTX1hDF34WpdPNXz49rdGWrhNyR4rP758bgwSN1WxHxHUstCg4PBq66ASY6t7SSkaqRhe4HfejJj6JitaVxyE" ], "script": "base64:AAIFAAAAAAAAAA8IAhIGCgQIAQEBEgMKAQgAAAANAQAAAAxoZWlnaHRFbmRLRVkAAAAAAgAAAApoZWlnaHRfZW5kAQAAAA5oZWlnaHRTdGFydEtFWQAAAAACAAAADGhlaWdodF9zdGFydAEAAAASYXZhaWxhYmxlQXNzZXRzS0VZAAAAAAIAAAAQYXZhaWxhYmxlX2Fzc2V0cwAAAAAJaGVpZ2h0RW5kCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQaAAAAAgUAAAAEdGhpcwkBAAAADGhlaWdodEVuZEtFWQAAAAACAAAAJGhlaWdodF9lbmQgaXMgbm90IHNwZWNpZmllZCBpbiBzdGF0ZQAAAAAMYXNzZXRzU3RyaW5nCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQdAAAAAgUAAAAEdGhpcwkBAAAAEmF2YWlsYWJsZUFzc2V0c0tFWQAAAAACAAAAJUFzc2V0cyBsaXN0IGlzIG5vdCBzcGVjaWZpZWQgaW4gc3RhdGUBAAAACWFzQW55TGlzdAAAAAEAAAADdmFsBAAAAAckbWF0Y2gwBQAAAAN2Y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ZWRPcHRpb25zBQAAAANuaWwAAAAAtY7GoA==", "height": 2275981, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
OldNewDifferences
1-# no script
1+{-# STDLIB_VERSION 5 #-}
2+{-# SCRIPT_TYPE ACCOUNT #-}
3+{-# CONTENT_TYPE DAPP #-}
4+func heightEndKEY () = "height_end"
5+
6+
7+func heightStartKEY () = "height_start"
8+
9+
10+func availableAssetsKEY () = "available_assets"
11+
12+
13+let heightEnd = valueOrErrorMessage(getInteger(this, heightEndKEY()), "height_end is not specified in state")
14+
15+let assetsString = valueOrErrorMessage(getString(this, availableAssetsKEY()), "Assets list is not specified in state")
16+
17+func asAnyList (val) = match val {
18+ case valAnyLyst: List[Any] =>
19+ valAnyLyst
20+ case _ =>
21+ throw("fail to cast into List[Any]")
22+}
23+
24+
25+func asInt (val) = match val {
26+ case valInt: Int =>
27+ valInt
28+ case _ =>
29+ throw("fail to cast into Int")
30+}
31+
32+
33+let nsbtStakingContract = Address(base58'3MuGfNhF98CNBCfthhoJEo6SYUv7zTgkK4J')
34+
35+let surfStakingContract = Address(base58'3N5yarEiTQccnnuerogYT3BxM5Zc5bRgDZy')
36+
37+let availableVotes = split(assetsString, ",")
38+
39+func keyUserBalance (userAddr) = makeString(["balance", toString(userAddr)], "_")
40+
41+
42+func keyUserVotingPower (userAddr) = makeString(["votingPower", userAddr], "_")
43+
44+
45+func keyUserLastVote (userAddr) = makeString(["last_vote", userAddr], "_")
46+
47+
48+@Callable(contextObj)
49+func constructor (available_assets,heightStart,heightEnd,quorumPercent) = {
50+ let surfData = asAnyList(invoke(surfStakingContract, "surfStakingSYSREADONLY", ["", 0], nil))
51+ let gnsbtFromSurfTotal = asInt(surfData[3])
52+ let nsbtData = asAnyList(invoke(nsbtStakingContract, "nsbtStakingSYSREADONLY", ["", 0], nil))
53+ let gnsbtFromNsbtTotal = asInt(nsbtData[1])
54+ if ((contextObj.caller != this))
55+ then throw("permissions denied")
56+ else [IntegerEntry(heightStartKEY(), heightStart), IntegerEntry(heightEndKEY(), heightEnd), StringEntry(availableAssetsKEY(), available_assets), IntegerEntry("gnsbt_fromNsbt_total", gnsbtFromNsbtTotal), IntegerEntry("gnsbt_fromSurf_total", gnsbtFromSurfTotal), IntegerEntry("quorum", fraction((gnsbtFromNsbtTotal + gnsbtFromSurfTotal), quorumPercent, 100))]
57+ }
58+
59+
60+
61+@Callable(contextObj)
62+func castVote (newUserSelectedOptions) = {
63+ let userAddress = toString(contextObj.caller)
64+ if ((containsElement(availableVotes, newUserSelectedOptions) == false))
65+ then throw("Incorrect vote!")
66+ else if ((height >= heightEnd))
67+ then throw("vote finished")
68+ else {
69+ let surfData = asAnyList(invoke(surfStakingContract, "surfStakingSYSREADONLY", [userAddress, 0], nil))
70+ let gnsbtFromSurfEffectiveHeight = asInt(surfData[4])
71+ let gnsbtFromSurf = if ((gnsbtFromSurfEffectiveHeight > heightEnd))
72+ then 0
73+ else asInt(surfData[2])
74+ let nsbtData = asAnyList(invoke(nsbtStakingContract, "nsbtStakingSYSREADONLY", [userAddress, 0], nil))
75+ let newUserVotingPower = (asInt(nsbtData[0]) + gnsbtFromSurf)
76+ if ((0 >= newUserVotingPower))
77+ then throw("not enough gnsbt to vote")
78+ else {
79+ let selectedOptionsArr = split(newUserSelectedOptions, ":")
80+ let prevUserChoiceKEY = keyUserLastVote(userAddress)
81+ let prevUserSelectedOptions = valueOrElse(getString(this, prevUserChoiceKEY), newUserSelectedOptions)
82+ let prevUserSelectedOptionsArr = split(prevUserSelectedOptions, ":")
83+ let prevUserVotingPowerKEY = keyUserVotingPower(userAddress)
84+ let prevUserVotingPower = valueOrElse(getInteger(this, prevUserVotingPowerKEY), 0)
85+ func refreshVotes (data,idx) = {
86+ let newUserChoice = selectedOptionsArr[idx]
87+ let prevUserChoice = prevUserSelectedOptionsArr[idx]
88+ let newTotalByChoiceKEY = makeString(["vote", newUserChoice], "_")
89+ let newTotalByChoiceAmount = valueOrElse(getInteger(this, newTotalByChoiceKEY), 0)
90+ let prevTotalByChoiceKEY = makeString(["vote", prevUserChoice], "_")
91+ let prevTotalByChoiceAmount = valueOrElse(getInteger(this, prevTotalByChoiceKEY), 0)
92+ let refreshTotals = if ((newUserChoice != prevUserChoice))
93+ then [IntegerEntry(prevTotalByChoiceKEY, (prevTotalByChoiceAmount - prevUserVotingPower)), IntegerEntry(newTotalByChoiceKEY, (newTotalByChoiceAmount + newUserVotingPower))]
94+ else [IntegerEntry(newTotalByChoiceKEY, ((newTotalByChoiceAmount + newUserVotingPower) - prevUserVotingPower))]
95+ (data ++ refreshTotals)
96+ }
97+
98+ let idxes = [0]
99+ ({
100+ let $l = idxes
101+ let $s = size($l)
102+ let $acc0 = nil
103+ func $f0_1 ($a,$i) = if (($i >= $s))
104+ then $a
105+ else refreshVotes($a, $l[$i])
106+
107+ func $f0_2 ($a,$i) = if (($i >= $s))
108+ then $a
109+ else throw("List size exceeds 2")
110+
111+ $f0_2($f0_1($f0_1($acc0, 0), 1), 2)
112+ } ++ [IntegerEntry(prevUserVotingPowerKEY, newUserVotingPower), StringEntry(prevUserChoiceKEY, newUserSelectedOptions)])
113+ }
114+ }
115+ }
116+
117+

github/deemru/w8io/169f3d6 
24.71 ms