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:AAIFAAAAAAAAAA0IAhIDCgEIEgASABIAAAAAEwAAAAAJcHJlY2lzaW9uAA3gtrOnZAAAAQAAABNrZXlNYW5hZ2VyUHVibGljS2V5AAAAAAkABCIAAAABAgAAABBtYW5hZ2VyUHVibGljS2V5AQAAABZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAAAAAQAAAAHJG1hdGNoMAkBAAAAE2tleU1hbmFnZXJQdWJsaWNLZXkAAAAAAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAXMFAAAAByRtYXRjaDAJAAJZAAAAAQUAAAABcwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAUAAAAEdW5pdAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAALbXVzdE1hbmFnZXIAAAABAAAAAWkEAAAAAnBkCQAAAgAAAAECAAAAEXBlcm1pc3Npb24gZGVuaWVkBAAAAAckbWF0Y2gwCQEAAAAWbWFuYWdlclB1YmxpY0tleU9yVW5pdAAAAAADCQAAAQAAAAIFAAAAByRtYXRjaDACAAAACkJ5dGVWZWN0b3IE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lckFtb3VudAkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4AAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAACQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tleT8OYPw=", "height": 2309910, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BvNMntVJ1wdcRMCMXYeMDGSjHA9eDpcwknEGqwrjMBBD Next: 6ZAaHhj1he28UkFKT3YcTsLXLfvhizgYniWba3Rkta6x Diff:
OldNewDifferences
135135
136136
137137 @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)
157138 func init (leaserAddress) = {
158139 let checks = [mustManager(i), mustNotInited()]
159140 if ((checks == checks))
163144 [BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry("lastRate", precision), IntegerEntry("lastTimestamp", lastBlock.timestamp), IntegerEntry("growthRate", 0), IntegerEntry("balance", 0), sWaves]
164145 }
165146 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+ }
166168 }
167169
168170
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let precision = 1000000000000000000
55
66 func keyManagerPublicKey () = getString("managerPublicKey")
77
88
99 func managerPublicKeyOrUnit () = match keyManagerPublicKey() {
1010 case s: String =>
1111 fromBase58String(s)
1212 case _: Unit =>
1313 unit
1414 case _ =>
1515 throw("Match error")
1616 }
1717
1818
1919 func mustManager (i) = {
2020 let pd = throw("permission denied")
2121 match managerPublicKeyOrUnit() {
2222 case pk: ByteVector =>
2323 if ((i.callerPublicKey == pk))
2424 then true
2525 else pd
2626 case _: Unit =>
2727 if ((i.caller == this))
2828 then true
2929 else pd
3030 case _ =>
3131 throw("Match error")
3232 }
3333 }
3434
3535
3636 func mustNotInited () = match getBoolean("inited") {
3737 case inited: Boolean =>
3838 if ((inited == false))
3939 then true
4040 else throw("Already inited")
4141 case _: Unit =>
4242 false
4343 case _ =>
4444 throw("Match error")
4545 }
4646
4747
4848 func cancelLease () = match getBinary("leaseId") {
4949 case id: ByteVector =>
5050 [LeaseCancel(id), DeleteEntry("leaseId")]
5151 case _: Unit =>
5252 nil
5353 case _ =>
5454 throw("Match error")
5555 }
5656
5757
5858 func getBalance () = valueOrElse(getInteger("balance"), 0)
5959
6060
6161 func setBalance (amount) = IntegerEntry("balance", amount)
6262
6363
6464 func lease (amount) = if ((amount == 0))
6565 then nil
6666 else {
6767 let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
6868 let currentAmount = getBalance()
6969 let newAmount = (currentAmount + amount)
7070 let leaseActions = if ((newAmount > 0))
7171 then {
7272 let newLease = Lease(leaserAddress, newAmount)
7373 let newLeaseId = calculateLeaseId(newLease)
7474 [newLease, BinaryEntry("leaseId", newLeaseId)]
7575 }
7676 else nil
7777 ((cancelLease() ++ leaseActions) :+ setBalance(newAmount))
7878 }
7979
8080
8181 func issueSWaves (amount) = {
8282 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
8383 Reissue(sWavesAssetId, amount, true)
8484 }
8585
8686
8787 func burnSWaves (amount) = {
8888 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
8989 Burn(sWavesAssetId, amount)
9090 }
9191
9292
9393 func sendSWaves (recipient,amount) = {
9494 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
9595 ScriptTransfer(recipient, amount, sWavesAssetId)
9696 }
9797
9898
9999 func sendWaves (recipient,amount) = ScriptTransfer(recipient, amount, unit)
100100
101101
102102 func sWavesQuantity () = {
103103 let assetId = fromBase58String(getStringValue("sWavesAssetId"))
104104 match assetInfo(assetId) {
105105 case asset: Asset =>
106106 asset.quantity
107107 case _ =>
108108 throw("Can't find asset")
109109 }
110110 }
111111
112112
113113 func getExcessWaves () = {
114114 let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
115115 wavesBalance(leaserAddress).regular
116116 }
117117
118118
119119 func setRate (rate,growthRate) = [IntegerEntry("lastRate", rate), IntegerEntry("lastTimestamp", lastBlock.timestamp)]
120120
121121
122122 func withdraw () = {
123123 let minerAddress = Address(fromBase58String(getStringValue("leaserAddress")))
124124 let result = invoke(minerAddress, "withdraw", nil, nil)
125125 if ((result == result))
126126 then result
127127 else throw("Strict value is not equal to itself.")
128128 }
129129
130130
131131 func currentRate (dt) = (getIntegerValue("lastRate") + (getIntegerValue("growthRate") * dt))
132132
133133
134134 func getCompoundTimestampDiff () = (lastBlock.timestamp - getIntegerValue("lastTimestamp"))
135135
136136
137137 @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)
157138 func init (leaserAddress) = {
158139 let checks = [mustManager(i), mustNotInited()]
159140 if ((checks == checks))
160141 then {
161142 let sWaves = Issue("sWaves", "", 0, 8, true, unit, 0)
162143 let sWavesAssetId = calculateAssetId(sWaves)
163144 [BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry("lastRate", precision), IntegerEntry("lastTimestamp", lastBlock.timestamp), IntegerEntry("growthRate", 0), IntegerEntry("balance", 0), sWaves]
164145 }
165146 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+ }
166168 }
167169
168170
169171
170172 @Callable(i)
171173 func stake () = {
172174 let payment = i.payments[0]
173175 if ((payment.assetId != unit))
174176 then throw("Only WAVES supported")
175177 else if ((size(i.payments) != 1))
176178 then throw("Wrong payments amount")
177179 else {
178180 let dt = getCompoundTimestampDiff()
179181 let rate = currentRate(dt)
180182 let toReissue = fraction(payment.amount, precision, rate)
181183 let result = invoke(this, "compound", nil, nil)
182184 if ((result == result))
183185 then ((lease(payment.amount) :+ issueSWaves(toReissue)) :+ sendSWaves(i.caller, toReissue))
184186 else throw("Strict value is not equal to itself.")
185187 }
186188 }
187189
188190
189191
190192 @Callable(i)
191193 func unstake () = {
192194 let payment = i.payments[0]
193195 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
194196 if ((payment.assetId != sWavesAssetId))
195197 then throw("Only sWAVES supported")
196198 else if ((size(i.payments) != 1))
197199 then throw("Wrong payments amount")
198200 else {
199201 let dt = getCompoundTimestampDiff()
200202 let rate = currentRate(dt)
201203 let transferAmount = fraction(payment.amount, rate, precision)
202204 let result = invoke(this, "compound", nil, nil)
203205 if ((result == result))
204206 then ((lease(-(transferAmount)) :+ burnSWaves(payment.amount)) :+ sendWaves(i.caller, transferAmount))
205207 else throw("Strict value is not equal to itself.")
206208 }
207209 }
208210
209211
210212 @Verifier(tx)
211213 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
212214

github/deemru/w8io/169f3d6 
26.43 ms