tx · BxV7wh1pPFKDP66uooy1C7ueFvgTqHBP8zEWn6Z6isHR 3N1JYSyNP7mn7f1YTZ2aRdi6ThpKw23j9Sy: -0.01000000 Waves 2022.11.09 20:08 [2309878] smart account 3N1JYSyNP7mn7f1YTZ2aRdi6ThpKw23j9Sy > SELF 0.00000000 Waves
{ "type": 13, "id": "BxV7wh1pPFKDP66uooy1C7ueFvgTqHBP8zEWn6Z6isHR", "fee": 1000000, "feeAssetId": null, "timestamp": 1668013781623, "version": 2, "chainId": 84, "sender": "3N1JYSyNP7mn7f1YTZ2aRdi6ThpKw23j9Sy", "senderPublicKey": "65hdh3BQVcB4NhB1URp1RBWMK7AWDhrCSVjwbFjS64jo", "proofs": [ "51unTJBtiq55s7YiGh3zPAbcAz4KCWi5sqXNFsU5sPTgQyx48uEPWeqRVtW4ZzGXeHTmVdnFYSofWhZEZtGo1oVt" ], "script": "base64:AAIFAAAAAAAAAA0IAhIDCgEIEgASABIAAAAAEwAAAAAJcHJlY2lzaW9uAA3gtrOnZAAAAQAAABNrZXlNYW5hZ2VyUHVibGljS2V5AAAAAAkABCIAAAABAgAAABBtYW5hZ2VyUHVibGljS2V5AQAAABZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAAAAAQAAAAHJG1hdGNoMAkBAAAAE2tleU1hbmFnZXJQdWJsaWNLZXkAAAAAAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAXMFAAAAByRtYXRjaDAJAAJZAAAAAQUAAAABcwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAUAAAAEdW5pdAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAALbXVzdE1hbmFnZXIAAAABAAAAAWkEAAAAAnBkCQAAAgAAAAECAAAAEXBlcm1pc3Npb24gZGVuaWVkBAAAAAckbWF0Y2gwCQEAAAAWbWFuYWdlclB1YmxpY0tleU9yVW5pdAAAAAADCQAAAQAAAAIFAAAAByRtYXRjaDACAAAACkJ5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pAAAABmNhbGxlcgUAAAAOdHJhbnNmZXJBbW91bnQAAAABaQEAAAAIY29tcG91bmQAAAAABAAAAAJkdAkBAAAAGGdldENvbXBvdW5kVGltZXN0YW1wRGlmZgAAAAADCQAAAAAAAAIFAAAAAmR0AAAAAAAAAAAABQAAAANuaWwEAAAABHJhdGUJAQAAAAtjdXJyZW50UmF0ZQAAAAEFAAAAAmR0BAAAAAtleGNlc3NXYXZlcwkBAAAADmdldEV4Y2Vzc1dhdmVzAAAAAAQAAAALc1dhdmVzVG90YWwJAQAAAA5zV2F2ZXNRdWFudGl0eQAAAAAEAAAACmdyb3d0aFJhdGUJAABpAAAAAgkAAGsAAAADBQAAAAtleGNlc3NXYXZlcwUAAAAJcHJlY2lzaW9uBQAAAAtzV2F2ZXNUb3RhbAUAAAACZHQEAAAADndpdGhkcmF3UmVzdWx0CQEAAAAId2l0aGRyYXcAAAAAAwkAAAAAAAACBQAAAA53aXRoZHJhd1Jlc3VsdAUAAAAOd2l0aGRyYXdSZXN1bHQJAAROAAAAAgkBAAAABWxlYXNlAAAAAQUAAAALZXhjZXNzV2F2ZXMJAQAAAAdzZXRSYXRlAAAAAgUAAAAEcmF0ZQUAAAAKZ3Jvd3RoUmF0ZQkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4AAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAACQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tlefH2Mes=", "height": 2309878, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4Eouaqckyijs7VAZU4N7WupKPZvva2o4DNDD9DfLPkj2 Next: none Diff:
Old | New | Differences | |
---|---|---|---|
55 | 55 | } | |
56 | 56 | ||
57 | 57 | ||
58 | - | func setLeasedAmount (amount) = IntegerEntry("leasedAmount", amount) | |
58 | + | func getBalance () = valueOrElse(getInteger("balance"), 0) | |
59 | + | ||
60 | + | ||
61 | + | func setBalance (amount) = IntegerEntry("balance", amount) | |
59 | 62 | ||
60 | 63 | ||
61 | 64 | func lease (amount) = if ((amount == 0)) | |
62 | 65 | then nil | |
63 | 66 | else { | |
64 | 67 | let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
65 | - | let currentAmount = | |
68 | + | let currentAmount = getBalance() | |
66 | 69 | let newAmount = (currentAmount + amount) | |
67 | 70 | let leaseActions = if ((newAmount > 0)) | |
68 | 71 | then { | |
71 | 74 | [newLease, BinaryEntry("leaseId", newLeaseId)] | |
72 | 75 | } | |
73 | 76 | else nil | |
74 | - | ((cancelLease() ++ leaseActions) :+ | |
77 | + | ((cancelLease() ++ leaseActions) :+ setBalance(newAmount)) | |
75 | 78 | } | |
76 | 79 | ||
77 | 80 | ||
107 | 110 | } | |
108 | 111 | ||
109 | 112 | ||
110 | - | func | |
113 | + | func getExcessWaves () = { | |
111 | 114 | let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
112 | 115 | wavesBalance(leaserAddress).regular | |
113 | 116 | } | |
114 | 117 | ||
115 | 118 | ||
116 | - | func calculateRatio () = { | |
117 | - | let leasedAmount = getIntegerValue("leasedAmount") | |
118 | - | let sWavesTotal = sWavesQuantity() | |
119 | - | let minerBalance = getMinerBalance() | |
120 | - | let wavesTotal = (leasedAmount + minerBalance) | |
121 | - | fraction(wavesTotal, precision, sWavesTotal) | |
122 | - | } | |
119 | + | func setRate (rate,growthRate) = [IntegerEntry("lastRate", rate), IntegerEntry("lastTimestamp", lastBlock.timestamp)] | |
123 | 120 | ||
124 | 121 | ||
125 | - | func withdraw ( | |
122 | + | func withdraw () = { | |
126 | 123 | let minerAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
127 | - | let result = invoke(minerAddress, "withdraw", | |
124 | + | let result = invoke(minerAddress, "withdraw", nil, nil) | |
128 | 125 | if ((result == result)) | |
129 | 126 | then result | |
130 | 127 | else throw("Strict value is not equal to itself.") | |
131 | 128 | } | |
129 | + | ||
130 | + | ||
131 | + | func currentRate (dt) = (getIntegerValue("lastRate") + (getIntegerValue("growthRate") * dt)) | |
132 | + | ||
133 | + | ||
134 | + | func getCompoundTimestampDiff () = (lastBlock.timestamp - getIntegerValue("lastTimestamp")) | |
132 | 135 | ||
133 | 136 | ||
134 | 137 | @Callable(i) | |
138 | 141 | then { | |
139 | 142 | let sWaves = Issue("sWaves", "", 0, 8, true, unit, 0) | |
140 | 143 | let sWavesAssetId = calculateAssetId(sWaves) | |
141 | - | [BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry(" | |
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] | |
142 | 145 | } | |
143 | 146 | else throw("Strict value is not equal to itself.") | |
144 | 147 | } | |
153 | 156 | else if ((size(i.payments) != 1)) | |
154 | 157 | then throw("Wrong payments amount") | |
155 | 158 | else { | |
156 | - | let ratio = getIntegerValue("ratio") | |
157 | - | let toReissue = fraction(payment.amount, precision, ratio) | |
159 | + | let dt = getCompoundTimestampDiff() | |
160 | + | let rate = currentRate(dt) | |
161 | + | let toReissue = fraction(payment.amount, precision, rate) | |
158 | 162 | ((lease(payment.amount) :+ issueSWaves(toReissue)) :+ sendSWaves(i.caller, toReissue)) | |
159 | 163 | } | |
160 | 164 | } | |
170 | 174 | else if ((size(i.payments) != 1)) | |
171 | 175 | then throw("Wrong payments amount") | |
172 | 176 | else { | |
173 | - | let ratio = getIntegerValue("ratio") | |
174 | - | let transferAmount = fraction(payment.amount, ratio, precision) | |
175 | - | let minerBalance = getMinerBalance() | |
176 | - | let unleaseAmount = if ((transferAmount > minerBalance)) | |
177 | - | then (transferAmount - minerBalance) | |
178 | - | else 0 | |
179 | - | let withdrawAmount = if ((transferAmount > minerBalance)) | |
180 | - | then minerBalance | |
181 | - | else (minerBalance - transferAmount) | |
182 | - | let withdrawResult = withdraw(withdrawAmount) | |
183 | - | if ((withdrawResult == withdrawResult)) | |
184 | - | then ((lease(-(unleaseAmount)) :+ burnSWaves(payment.amount)) :+ sendWaves(i.caller, transferAmount)) | |
185 | - | else throw("Strict value is not equal to itself.") | |
177 | + | let dt = getCompoundTimestampDiff() | |
178 | + | let rate = currentRate(dt) | |
179 | + | let transferAmount = fraction(payment.amount, rate, precision) | |
180 | + | ((lease(-(transferAmount)) :+ burnSWaves(payment.amount)) :+ sendWaves(i.caller, transferAmount)) | |
186 | 181 | } | |
187 | 182 | } | |
188 | 183 | ||
190 | 185 | ||
191 | 186 | @Callable(i) | |
192 | 187 | func compound () = { | |
193 | - | let ratio = calculateRatio() | |
194 | - | [IntegerEntry("ratio", ratio)] | |
188 | + | let dt = getCompoundTimestampDiff() | |
189 | + | if ((dt == 0)) | |
190 | + | then nil | |
191 | + | else { | |
192 | + | let rate = currentRate(dt) | |
193 | + | let excessWaves = getExcessWaves() | |
194 | + | let sWavesTotal = sWavesQuantity() | |
195 | + | let growthRate = (fraction(excessWaves, precision, sWavesTotal) / dt) | |
196 | + | let withdrawResult = withdraw() | |
197 | + | if ((withdrawResult == withdrawResult)) | |
198 | + | then (lease(excessWaves) ++ setRate(rate, growthRate)) | |
199 | + | else throw("Strict value is not equal to itself.") | |
200 | + | } | |
195 | 201 | } | |
196 | 202 | ||
197 | 203 |
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 | - | func setLeasedAmount (amount) = IntegerEntry("leasedAmount", amount) | |
58 | + | func getBalance () = valueOrElse(getInteger("balance"), 0) | |
59 | + | ||
60 | + | ||
61 | + | func setBalance (amount) = IntegerEntry("balance", amount) | |
59 | 62 | ||
60 | 63 | ||
61 | 64 | func lease (amount) = if ((amount == 0)) | |
62 | 65 | then nil | |
63 | 66 | else { | |
64 | 67 | let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
65 | - | let currentAmount = | |
68 | + | let currentAmount = getBalance() | |
66 | 69 | let newAmount = (currentAmount + amount) | |
67 | 70 | let leaseActions = if ((newAmount > 0)) | |
68 | 71 | then { | |
69 | 72 | let newLease = Lease(leaserAddress, newAmount) | |
70 | 73 | let newLeaseId = calculateLeaseId(newLease) | |
71 | 74 | [newLease, BinaryEntry("leaseId", newLeaseId)] | |
72 | 75 | } | |
73 | 76 | else nil | |
74 | - | ((cancelLease() ++ leaseActions) :+ | |
77 | + | ((cancelLease() ++ leaseActions) :+ setBalance(newAmount)) | |
75 | 78 | } | |
76 | 79 | ||
77 | 80 | ||
78 | 81 | func issueSWaves (amount) = { | |
79 | 82 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
80 | 83 | Reissue(sWavesAssetId, amount, true) | |
81 | 84 | } | |
82 | 85 | ||
83 | 86 | ||
84 | 87 | func burnSWaves (amount) = { | |
85 | 88 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
86 | 89 | Burn(sWavesAssetId, amount) | |
87 | 90 | } | |
88 | 91 | ||
89 | 92 | ||
90 | 93 | func sendSWaves (recipient,amount) = { | |
91 | 94 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
92 | 95 | ScriptTransfer(recipient, amount, sWavesAssetId) | |
93 | 96 | } | |
94 | 97 | ||
95 | 98 | ||
96 | 99 | func sendWaves (recipient,amount) = ScriptTransfer(recipient, amount, unit) | |
97 | 100 | ||
98 | 101 | ||
99 | 102 | func sWavesQuantity () = { | |
100 | 103 | let assetId = fromBase58String(getStringValue("sWavesAssetId")) | |
101 | 104 | match assetInfo(assetId) { | |
102 | 105 | case asset: Asset => | |
103 | 106 | asset.quantity | |
104 | 107 | case _ => | |
105 | 108 | throw("Can't find asset") | |
106 | 109 | } | |
107 | 110 | } | |
108 | 111 | ||
109 | 112 | ||
110 | - | func | |
113 | + | func getExcessWaves () = { | |
111 | 114 | let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
112 | 115 | wavesBalance(leaserAddress).regular | |
113 | 116 | } | |
114 | 117 | ||
115 | 118 | ||
116 | - | func calculateRatio () = { | |
117 | - | let leasedAmount = getIntegerValue("leasedAmount") | |
118 | - | let sWavesTotal = sWavesQuantity() | |
119 | - | let minerBalance = getMinerBalance() | |
120 | - | let wavesTotal = (leasedAmount + minerBalance) | |
121 | - | fraction(wavesTotal, precision, sWavesTotal) | |
122 | - | } | |
119 | + | func setRate (rate,growthRate) = [IntegerEntry("lastRate", rate), IntegerEntry("lastTimestamp", lastBlock.timestamp)] | |
123 | 120 | ||
124 | 121 | ||
125 | - | func withdraw ( | |
122 | + | func withdraw () = { | |
126 | 123 | let minerAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
127 | - | let result = invoke(minerAddress, "withdraw", | |
124 | + | let result = invoke(minerAddress, "withdraw", nil, nil) | |
128 | 125 | if ((result == result)) | |
129 | 126 | then result | |
130 | 127 | else throw("Strict value is not equal to itself.") | |
131 | 128 | } | |
129 | + | ||
130 | + | ||
131 | + | func currentRate (dt) = (getIntegerValue("lastRate") + (getIntegerValue("growthRate") * dt)) | |
132 | + | ||
133 | + | ||
134 | + | func getCompoundTimestampDiff () = (lastBlock.timestamp - getIntegerValue("lastTimestamp")) | |
132 | 135 | ||
133 | 136 | ||
134 | 137 | @Callable(i) | |
135 | 138 | func init (leaserAddress) = { | |
136 | 139 | let checks = [mustManager(i), mustNotInited()] | |
137 | 140 | if ((checks == checks)) | |
138 | 141 | then { | |
139 | 142 | let sWaves = Issue("sWaves", "", 0, 8, true, unit, 0) | |
140 | 143 | let sWavesAssetId = calculateAssetId(sWaves) | |
141 | - | [BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry(" | |
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] | |
142 | 145 | } | |
143 | 146 | else throw("Strict value is not equal to itself.") | |
144 | 147 | } | |
145 | 148 | ||
146 | 149 | ||
147 | 150 | ||
148 | 151 | @Callable(i) | |
149 | 152 | func stake () = { | |
150 | 153 | let payment = i.payments[0] | |
151 | 154 | if ((payment.assetId != unit)) | |
152 | 155 | then throw("Only WAVES supported") | |
153 | 156 | else if ((size(i.payments) != 1)) | |
154 | 157 | then throw("Wrong payments amount") | |
155 | 158 | else { | |
156 | - | let ratio = getIntegerValue("ratio") | |
157 | - | let toReissue = fraction(payment.amount, precision, ratio) | |
159 | + | let dt = getCompoundTimestampDiff() | |
160 | + | let rate = currentRate(dt) | |
161 | + | let toReissue = fraction(payment.amount, precision, rate) | |
158 | 162 | ((lease(payment.amount) :+ issueSWaves(toReissue)) :+ sendSWaves(i.caller, toReissue)) | |
159 | 163 | } | |
160 | 164 | } | |
161 | 165 | ||
162 | 166 | ||
163 | 167 | ||
164 | 168 | @Callable(i) | |
165 | 169 | func unstake () = { | |
166 | 170 | let payment = i.payments[0] | |
167 | 171 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
168 | 172 | if ((payment.assetId != sWavesAssetId)) | |
169 | 173 | then throw("Only sWAVES supported") | |
170 | 174 | else if ((size(i.payments) != 1)) | |
171 | 175 | then throw("Wrong payments amount") | |
172 | 176 | else { | |
173 | - | let ratio = getIntegerValue("ratio") | |
174 | - | let transferAmount = fraction(payment.amount, ratio, precision) | |
175 | - | let minerBalance = getMinerBalance() | |
176 | - | let unleaseAmount = if ((transferAmount > minerBalance)) | |
177 | - | then (transferAmount - minerBalance) | |
178 | - | else 0 | |
179 | - | let withdrawAmount = if ((transferAmount > minerBalance)) | |
180 | - | then minerBalance | |
181 | - | else (minerBalance - transferAmount) | |
182 | - | let withdrawResult = withdraw(withdrawAmount) | |
183 | - | if ((withdrawResult == withdrawResult)) | |
184 | - | then ((lease(-(unleaseAmount)) :+ burnSWaves(payment.amount)) :+ sendWaves(i.caller, transferAmount)) | |
185 | - | else throw("Strict value is not equal to itself.") | |
177 | + | let dt = getCompoundTimestampDiff() | |
178 | + | let rate = currentRate(dt) | |
179 | + | let transferAmount = fraction(payment.amount, rate, precision) | |
180 | + | ((lease(-(transferAmount)) :+ burnSWaves(payment.amount)) :+ sendWaves(i.caller, transferAmount)) | |
186 | 181 | } | |
187 | 182 | } | |
188 | 183 | ||
189 | 184 | ||
190 | 185 | ||
191 | 186 | @Callable(i) | |
192 | 187 | func compound () = { | |
193 | - | let ratio = calculateRatio() | |
194 | - | [IntegerEntry("ratio", ratio)] | |
188 | + | let dt = getCompoundTimestampDiff() | |
189 | + | if ((dt == 0)) | |
190 | + | then nil | |
191 | + | else { | |
192 | + | let rate = currentRate(dt) | |
193 | + | let excessWaves = getExcessWaves() | |
194 | + | let sWavesTotal = sWavesQuantity() | |
195 | + | let growthRate = (fraction(excessWaves, precision, sWavesTotal) / dt) | |
196 | + | let withdrawResult = withdraw() | |
197 | + | if ((withdrawResult == withdrawResult)) | |
198 | + | then (lease(excessWaves) ++ setRate(rate, growthRate)) | |
199 | + | else throw("Strict value is not equal to itself.") | |
200 | + | } | |
195 | 201 | } | |
196 | 202 | ||
197 | 203 | ||
198 | 204 | @Verifier(tx) | |
199 | 205 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
200 | 206 |
github/deemru/w8io/169f3d6 49.30 ms ◑