tx · mKTDV39acEKVnuZwHoV7AFvZpFVAPPNkaT1MTBidUGL 3MxovCV2pBS5Z6YEcj3Gap5ish6dX3YERfP: -0.05000000 Waves 2022.11.09 20:41 [2309910] smart account 3MxovCV2pBS5Z6YEcj3Gap5ish6dX3YERfP > SELF 0.00000000 Waves
{ "type": 13, "id": "mKTDV39acEKVnuZwHoV7AFvZpFVAPPNkaT1MTBidUGL", "fee": 5000000, "feeAssetId": null, "timestamp": 1668015678519, "version": 2, "chainId": 84, "sender": "3MxovCV2pBS5Z6YEcj3Gap5ish6dX3YERfP", "senderPublicKey": "6aZUzHaTgW7zPizjKqNFNAaKdYXVUaNwstd6E3NsD3YF", "proofs": [ "5DaoB5K8qLZe51asS6w4sBVdeQMs3yYwxxVe6Wn18VKM5Ny39ttVjLrBukYZG6F4yRgDebLTQh6v4SCysNrC1ud6" ], "script": "base64:AAIFAAAAAAAAAA0IAhIDCgEIEgASABIAAAAAEwAAAAAJcHJlY2lzaW9uAA3gtrOnZAAAAQAAABNrZXlNYW5hZ2VyUHVibGljS2V5AAAAAAkABCIAAAABAgAAABBtYW5hZ2VyUHVibGljS2V5AQAAABZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAAAAAQAAAAHJG1hdGNoMAkBAAAAE2tleU1hbmFnZXJQdWJsaWNLZXkAAAAAAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAXMFAAAAByRtYXRjaDAJAAJZAAAAAQUAAAABcwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAUAAAAEdW5pdAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAALbXVzdE1hbmFnZXIAAAABAAAAAWkEAAAAAnBkCQAAAgAAAAECAAAAEXBlcm1pc3Npb24gZGVuaWVkBAAAAAckbWF0Y2gwCQEAAAAWbWFuYWdlclB1YmxpY0tleU9yVW5pdAAAAAADCQAAAQAAAAIFAAAAByRtYXRjaDACAAAACkJ5dGVWZWN0b3IEA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ckFtb3VudAkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4AAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAACQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tleT8OYPw=", "height": 2309910, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BvNMntVJ1wdcRMCMXYeMDGSjHA9eDpcwknEGqwrjMBBD Next: 6ZAaHhj1he28UkFKT3YcTsLXLfvhizgYniWba3Rkta6x Diff:
Old | New | Differences | |
---|---|---|---|
135 | 135 | ||
136 | 136 | ||
137 | 137 | @Callable(i) | |
138 | - | func compound () = { | |
139 | - | let dt = getCompoundTimestampDiff() | |
140 | - | if ((dt == 0)) | |
141 | - | then nil | |
142 | - | else { | |
143 | - | let rate = currentRate(dt) | |
144 | - | let excessWaves = getExcessWaves() | |
145 | - | let sWavesTotal = sWavesQuantity() | |
146 | - | let growthRate = (fraction(excessWaves, precision, sWavesTotal) / dt) | |
147 | - | let withdrawResult = withdraw() | |
148 | - | if ((withdrawResult == withdrawResult)) | |
149 | - | then (lease(excessWaves) ++ setRate(rate, growthRate)) | |
150 | - | else throw("Strict value is not equal to itself.") | |
151 | - | } | |
152 | - | } | |
153 | - | ||
154 | - | ||
155 | - | ||
156 | - | @Callable(i) | |
157 | 138 | func init (leaserAddress) = { | |
158 | 139 | let checks = [mustManager(i), mustNotInited()] | |
159 | 140 | if ((checks == checks)) | |
163 | 144 | [BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry("lastRate", precision), IntegerEntry("lastTimestamp", lastBlock.timestamp), IntegerEntry("growthRate", 0), IntegerEntry("balance", 0), sWaves] | |
164 | 145 | } | |
165 | 146 | else throw("Strict value is not equal to itself.") | |
147 | + | } | |
148 | + | ||
149 | + | ||
150 | + | ||
151 | + | @Callable(i) | |
152 | + | func compound () = { | |
153 | + | let dt = getCompoundTimestampDiff() | |
154 | + | let sWavesTotal = sWavesQuantity() | |
155 | + | if (if ((dt == 0)) | |
156 | + | then true | |
157 | + | else (sWavesTotal == 0)) | |
158 | + | then nil | |
159 | + | else { | |
160 | + | let rate = currentRate(dt) | |
161 | + | let excessWaves = getExcessWaves() | |
162 | + | let growthRate = (fraction(excessWaves, precision, sWavesTotal) / dt) | |
163 | + | let withdrawResult = withdraw() | |
164 | + | if ((withdrawResult == withdrawResult)) | |
165 | + | then (lease(excessWaves) ++ setRate(rate, growthRate)) | |
166 | + | else throw("Strict value is not equal to itself.") | |
167 | + | } | |
166 | 168 | } | |
167 | 169 | ||
168 | 170 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let precision = 1000000000000000000 | |
5 | 5 | ||
6 | 6 | func keyManagerPublicKey () = getString("managerPublicKey") | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func managerPublicKeyOrUnit () = match keyManagerPublicKey() { | |
10 | 10 | case s: String => | |
11 | 11 | fromBase58String(s) | |
12 | 12 | case _: Unit => | |
13 | 13 | unit | |
14 | 14 | case _ => | |
15 | 15 | throw("Match error") | |
16 | 16 | } | |
17 | 17 | ||
18 | 18 | ||
19 | 19 | func mustManager (i) = { | |
20 | 20 | let pd = throw("permission denied") | |
21 | 21 | match managerPublicKeyOrUnit() { | |
22 | 22 | case pk: ByteVector => | |
23 | 23 | if ((i.callerPublicKey == pk)) | |
24 | 24 | then true | |
25 | 25 | else pd | |
26 | 26 | case _: Unit => | |
27 | 27 | if ((i.caller == this)) | |
28 | 28 | then true | |
29 | 29 | else pd | |
30 | 30 | case _ => | |
31 | 31 | throw("Match error") | |
32 | 32 | } | |
33 | 33 | } | |
34 | 34 | ||
35 | 35 | ||
36 | 36 | func mustNotInited () = match getBoolean("inited") { | |
37 | 37 | case inited: Boolean => | |
38 | 38 | if ((inited == false)) | |
39 | 39 | then true | |
40 | 40 | else throw("Already inited") | |
41 | 41 | case _: Unit => | |
42 | 42 | false | |
43 | 43 | case _ => | |
44 | 44 | throw("Match error") | |
45 | 45 | } | |
46 | 46 | ||
47 | 47 | ||
48 | 48 | func cancelLease () = match getBinary("leaseId") { | |
49 | 49 | case id: ByteVector => | |
50 | 50 | [LeaseCancel(id), DeleteEntry("leaseId")] | |
51 | 51 | case _: Unit => | |
52 | 52 | nil | |
53 | 53 | case _ => | |
54 | 54 | throw("Match error") | |
55 | 55 | } | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | func getBalance () = valueOrElse(getInteger("balance"), 0) | |
59 | 59 | ||
60 | 60 | ||
61 | 61 | func setBalance (amount) = IntegerEntry("balance", amount) | |
62 | 62 | ||
63 | 63 | ||
64 | 64 | func lease (amount) = if ((amount == 0)) | |
65 | 65 | then nil | |
66 | 66 | else { | |
67 | 67 | let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
68 | 68 | let currentAmount = getBalance() | |
69 | 69 | let newAmount = (currentAmount + amount) | |
70 | 70 | let leaseActions = if ((newAmount > 0)) | |
71 | 71 | then { | |
72 | 72 | let newLease = Lease(leaserAddress, newAmount) | |
73 | 73 | let newLeaseId = calculateLeaseId(newLease) | |
74 | 74 | [newLease, BinaryEntry("leaseId", newLeaseId)] | |
75 | 75 | } | |
76 | 76 | else nil | |
77 | 77 | ((cancelLease() ++ leaseActions) :+ setBalance(newAmount)) | |
78 | 78 | } | |
79 | 79 | ||
80 | 80 | ||
81 | 81 | func issueSWaves (amount) = { | |
82 | 82 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
83 | 83 | Reissue(sWavesAssetId, amount, true) | |
84 | 84 | } | |
85 | 85 | ||
86 | 86 | ||
87 | 87 | func burnSWaves (amount) = { | |
88 | 88 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
89 | 89 | Burn(sWavesAssetId, amount) | |
90 | 90 | } | |
91 | 91 | ||
92 | 92 | ||
93 | 93 | func sendSWaves (recipient,amount) = { | |
94 | 94 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
95 | 95 | ScriptTransfer(recipient, amount, sWavesAssetId) | |
96 | 96 | } | |
97 | 97 | ||
98 | 98 | ||
99 | 99 | func sendWaves (recipient,amount) = ScriptTransfer(recipient, amount, unit) | |
100 | 100 | ||
101 | 101 | ||
102 | 102 | func sWavesQuantity () = { | |
103 | 103 | let assetId = fromBase58String(getStringValue("sWavesAssetId")) | |
104 | 104 | match assetInfo(assetId) { | |
105 | 105 | case asset: Asset => | |
106 | 106 | asset.quantity | |
107 | 107 | case _ => | |
108 | 108 | throw("Can't find asset") | |
109 | 109 | } | |
110 | 110 | } | |
111 | 111 | ||
112 | 112 | ||
113 | 113 | func getExcessWaves () = { | |
114 | 114 | let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
115 | 115 | wavesBalance(leaserAddress).regular | |
116 | 116 | } | |
117 | 117 | ||
118 | 118 | ||
119 | 119 | func setRate (rate,growthRate) = [IntegerEntry("lastRate", rate), IntegerEntry("lastTimestamp", lastBlock.timestamp)] | |
120 | 120 | ||
121 | 121 | ||
122 | 122 | func withdraw () = { | |
123 | 123 | let minerAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
124 | 124 | let result = invoke(minerAddress, "withdraw", nil, nil) | |
125 | 125 | if ((result == result)) | |
126 | 126 | then result | |
127 | 127 | else throw("Strict value is not equal to itself.") | |
128 | 128 | } | |
129 | 129 | ||
130 | 130 | ||
131 | 131 | func currentRate (dt) = (getIntegerValue("lastRate") + (getIntegerValue("growthRate") * dt)) | |
132 | 132 | ||
133 | 133 | ||
134 | 134 | func getCompoundTimestampDiff () = (lastBlock.timestamp - getIntegerValue("lastTimestamp")) | |
135 | 135 | ||
136 | 136 | ||
137 | 137 | @Callable(i) | |
138 | - | func compound () = { | |
139 | - | let dt = getCompoundTimestampDiff() | |
140 | - | if ((dt == 0)) | |
141 | - | then nil | |
142 | - | else { | |
143 | - | let rate = currentRate(dt) | |
144 | - | let excessWaves = getExcessWaves() | |
145 | - | let sWavesTotal = sWavesQuantity() | |
146 | - | let growthRate = (fraction(excessWaves, precision, sWavesTotal) / dt) | |
147 | - | let withdrawResult = withdraw() | |
148 | - | if ((withdrawResult == withdrawResult)) | |
149 | - | then (lease(excessWaves) ++ setRate(rate, growthRate)) | |
150 | - | else throw("Strict value is not equal to itself.") | |
151 | - | } | |
152 | - | } | |
153 | - | ||
154 | - | ||
155 | - | ||
156 | - | @Callable(i) | |
157 | 138 | func init (leaserAddress) = { | |
158 | 139 | let checks = [mustManager(i), mustNotInited()] | |
159 | 140 | if ((checks == checks)) | |
160 | 141 | then { | |
161 | 142 | let sWaves = Issue("sWaves", "", 0, 8, true, unit, 0) | |
162 | 143 | let sWavesAssetId = calculateAssetId(sWaves) | |
163 | 144 | [BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry("lastRate", precision), IntegerEntry("lastTimestamp", lastBlock.timestamp), IntegerEntry("growthRate", 0), IntegerEntry("balance", 0), sWaves] | |
164 | 145 | } | |
165 | 146 | else throw("Strict value is not equal to itself.") | |
147 | + | } | |
148 | + | ||
149 | + | ||
150 | + | ||
151 | + | @Callable(i) | |
152 | + | func compound () = { | |
153 | + | let dt = getCompoundTimestampDiff() | |
154 | + | let sWavesTotal = sWavesQuantity() | |
155 | + | if (if ((dt == 0)) | |
156 | + | then true | |
157 | + | else (sWavesTotal == 0)) | |
158 | + | then nil | |
159 | + | else { | |
160 | + | let rate = currentRate(dt) | |
161 | + | let excessWaves = getExcessWaves() | |
162 | + | let growthRate = (fraction(excessWaves, precision, sWavesTotal) / dt) | |
163 | + | let withdrawResult = withdraw() | |
164 | + | if ((withdrawResult == withdrawResult)) | |
165 | + | then (lease(excessWaves) ++ setRate(rate, growthRate)) | |
166 | + | else throw("Strict value is not equal to itself.") | |
167 | + | } | |
166 | 168 | } | |
167 | 169 | ||
168 | 170 | ||
169 | 171 | ||
170 | 172 | @Callable(i) | |
171 | 173 | func stake () = { | |
172 | 174 | let payment = i.payments[0] | |
173 | 175 | if ((payment.assetId != unit)) | |
174 | 176 | then throw("Only WAVES supported") | |
175 | 177 | else if ((size(i.payments) != 1)) | |
176 | 178 | then throw("Wrong payments amount") | |
177 | 179 | else { | |
178 | 180 | let dt = getCompoundTimestampDiff() | |
179 | 181 | let rate = currentRate(dt) | |
180 | 182 | let toReissue = fraction(payment.amount, precision, rate) | |
181 | 183 | let result = invoke(this, "compound", nil, nil) | |
182 | 184 | if ((result == result)) | |
183 | 185 | then ((lease(payment.amount) :+ issueSWaves(toReissue)) :+ sendSWaves(i.caller, toReissue)) | |
184 | 186 | else throw("Strict value is not equal to itself.") | |
185 | 187 | } | |
186 | 188 | } | |
187 | 189 | ||
188 | 190 | ||
189 | 191 | ||
190 | 192 | @Callable(i) | |
191 | 193 | func unstake () = { | |
192 | 194 | let payment = i.payments[0] | |
193 | 195 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
194 | 196 | if ((payment.assetId != sWavesAssetId)) | |
195 | 197 | then throw("Only sWAVES supported") | |
196 | 198 | else if ((size(i.payments) != 1)) | |
197 | 199 | then throw("Wrong payments amount") | |
198 | 200 | else { | |
199 | 201 | let dt = getCompoundTimestampDiff() | |
200 | 202 | let rate = currentRate(dt) | |
201 | 203 | let transferAmount = fraction(payment.amount, rate, precision) | |
202 | 204 | let result = invoke(this, "compound", nil, nil) | |
203 | 205 | if ((result == result)) | |
204 | 206 | then ((lease(-(transferAmount)) :+ burnSWaves(payment.amount)) :+ sendWaves(i.caller, transferAmount)) | |
205 | 207 | else throw("Strict value is not equal to itself.") | |
206 | 208 | } | |
207 | 209 | } | |
208 | 210 | ||
209 | 211 | ||
210 | 212 | @Verifier(tx) | |
211 | 213 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
212 | 214 |
github/deemru/w8io/169f3d6 26.43 ms ◑