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:AAIFAAAAAAAAAA0IAhIDCgEIEgASABIAAAAAEwAAAAAJcHJlY2lzaW9uAA3gtrOnZAAAAQAAABNrZXlNYW5hZ2VyUHVibGljS2V5AAAAAAkABCIAAAABAgAAABBtYW5hZ2VyUHVibGljS2V5AQAAABZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAAAAAQAAAAHJG1hdGNoMAkBAAAAE2tleU1hbmFnZXJQdWJsaWNLZXkAAAAAAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAXMFAAAAByRtYXRjaDAJAAJZAAAAAQUAAAABcwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAUAAAAEdW5pdAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAALbXVzdE1hbmFnZXIAAAABAAAAAWkEAAAAAnBkCQAAAgAAAAECAAAAEXBlcm1pc3Npb24gZGVuaWVkBAAAAAckbWF0Y2gwCQEAAAAWbWFuYWdlclB1YmxpY0tleU9yVW5pdAAAAAADCQAAAQAAAAIFAAAAByRtYXRjaDACAAAACkJ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FpAAAABmNhbGxlcgUAAAAOdHJhbnNmZXJBbW91bnQAAAABaQEAAAAIY29tcG91bmQAAAAABAAAAAJkdAkBAAAAGGdldENvbXBvdW5kVGltZXN0YW1wRGlmZgAAAAADCQAAAAAAAAIFAAAAAmR0AAAAAAAAAAAABQAAAANuaWwEAAAABHJhdGUJAQAAAAtjdXJyZW50UmF0ZQAAAAEFAAAAAmR0BAAAAAtleGNlc3NXYXZlcwkBAAAADmdldEV4Y2Vzc1dhdmVzAAAAAAQAAAALc1dhdmVzVG90YWwJAQAAAA5zV2F2ZXNRdWFudGl0eQAAAAAEAAAACmdyb3d0aFJhdGUJAABpAAAAAgkAAGsAAAADBQAAAAtleGNlc3NXYXZlcwUAAAAJcHJlY2lzaW9uBQAAAAtzV2F2ZXNUb3RhbAUAAAACZHQEAAAADndpdGhkcmF3UmVzdWx0CQEAAAAId2l0aGRyYXcAAAAAAwkAAAAAAAACBQAAAA53aXRoZHJhd1Jlc3VsdAUAAAAOd2l0aGRyYXdSZXN1bHQJAAROAAAAAgkBAAAABWxlYXNlAAAAAQUAAAALZXhjZXNzV2F2ZXMJAQAAAAdzZXRSYXRlAAAAAgUAAAAEcmF0ZQUAAAAKZ3Jvd3RoUmF0ZQkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4AAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAACQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tlefH2Mes=", "height": 2309878, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4Eouaqckyijs7VAZU4N7WupKPZvva2o4DNDD9DfLPkj2 Next: none Diff:
OldNewDifferences
5555 }
5656
5757
58-func setLeasedAmount (amount) = IntegerEntry("leasedAmount", amount)
58+func getBalance () = valueOrElse(getInteger("balance"), 0)
59+
60+
61+func setBalance (amount) = IntegerEntry("balance", amount)
5962
6063
6164 func lease (amount) = if ((amount == 0))
6265 then nil
6366 else {
6467 let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
65- let currentAmount = getIntegerValue("leasedAmount")
68+ let currentAmount = getBalance()
6669 let newAmount = (currentAmount + amount)
6770 let leaseActions = if ((newAmount > 0))
6871 then {
7174 [newLease, BinaryEntry("leaseId", newLeaseId)]
7275 }
7376 else nil
74- ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount))
77+ ((cancelLease() ++ leaseActions) :+ setBalance(newAmount))
7578 }
7679
7780
107110 }
108111
109112
110-func getMinerBalance () = {
113+func getExcessWaves () = {
111114 let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
112115 wavesBalance(leaserAddress).regular
113116 }
114117
115118
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)]
123120
124121
125-func withdraw (amount) = {
122+func withdraw () = {
126123 let minerAddress = Address(fromBase58String(getStringValue("leaserAddress")))
127- let result = invoke(minerAddress, "withdraw", [amount], nil)
124+ let result = invoke(minerAddress, "withdraw", nil, nil)
128125 if ((result == result))
129126 then result
130127 else throw("Strict value is not equal to itself.")
131128 }
129+
130+
131+func currentRate (dt) = (getIntegerValue("lastRate") + (getIntegerValue("growthRate") * dt))
132+
133+
134+func getCompoundTimestampDiff () = (lastBlock.timestamp - getIntegerValue("lastTimestamp"))
132135
133136
134137 @Callable(i)
138141 then {
139142 let sWaves = Issue("sWaves", "", 0, 8, true, unit, 0)
140143 let sWavesAssetId = calculateAssetId(sWaves)
141-[BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry("ratio", precision), IntegerEntry("leasedAmount", 0), sWaves]
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]
142145 }
143146 else throw("Strict value is not equal to itself.")
144147 }
153156 else if ((size(i.payments) != 1))
154157 then throw("Wrong payments amount")
155158 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)
158162 ((lease(payment.amount) :+ issueSWaves(toReissue)) :+ sendSWaves(i.caller, toReissue))
159163 }
160164 }
170174 else if ((size(i.payments) != 1))
171175 then throw("Wrong payments amount")
172176 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))
186181 }
187182 }
188183
190185
191186 @Callable(i)
192187 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+ }
195201 }
196202
197203
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
58-func setLeasedAmount (amount) = IntegerEntry("leasedAmount", amount)
58+func getBalance () = valueOrElse(getInteger("balance"), 0)
59+
60+
61+func setBalance (amount) = IntegerEntry("balance", amount)
5962
6063
6164 func lease (amount) = if ((amount == 0))
6265 then nil
6366 else {
6467 let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
65- let currentAmount = getIntegerValue("leasedAmount")
68+ let currentAmount = getBalance()
6669 let newAmount = (currentAmount + amount)
6770 let leaseActions = if ((newAmount > 0))
6871 then {
6972 let newLease = Lease(leaserAddress, newAmount)
7073 let newLeaseId = calculateLeaseId(newLease)
7174 [newLease, BinaryEntry("leaseId", newLeaseId)]
7275 }
7376 else nil
74- ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount))
77+ ((cancelLease() ++ leaseActions) :+ setBalance(newAmount))
7578 }
7679
7780
7881 func issueSWaves (amount) = {
7982 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
8083 Reissue(sWavesAssetId, amount, true)
8184 }
8285
8386
8487 func burnSWaves (amount) = {
8588 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
8689 Burn(sWavesAssetId, amount)
8790 }
8891
8992
9093 func sendSWaves (recipient,amount) = {
9194 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
9295 ScriptTransfer(recipient, amount, sWavesAssetId)
9396 }
9497
9598
9699 func sendWaves (recipient,amount) = ScriptTransfer(recipient, amount, unit)
97100
98101
99102 func sWavesQuantity () = {
100103 let assetId = fromBase58String(getStringValue("sWavesAssetId"))
101104 match assetInfo(assetId) {
102105 case asset: Asset =>
103106 asset.quantity
104107 case _ =>
105108 throw("Can't find asset")
106109 }
107110 }
108111
109112
110-func getMinerBalance () = {
113+func getExcessWaves () = {
111114 let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
112115 wavesBalance(leaserAddress).regular
113116 }
114117
115118
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)]
123120
124121
125-func withdraw (amount) = {
122+func withdraw () = {
126123 let minerAddress = Address(fromBase58String(getStringValue("leaserAddress")))
127- let result = invoke(minerAddress, "withdraw", [amount], nil)
124+ let result = invoke(minerAddress, "withdraw", nil, nil)
128125 if ((result == result))
129126 then result
130127 else throw("Strict value is not equal to itself.")
131128 }
129+
130+
131+func currentRate (dt) = (getIntegerValue("lastRate") + (getIntegerValue("growthRate") * dt))
132+
133+
134+func getCompoundTimestampDiff () = (lastBlock.timestamp - getIntegerValue("lastTimestamp"))
132135
133136
134137 @Callable(i)
135138 func init (leaserAddress) = {
136139 let checks = [mustManager(i), mustNotInited()]
137140 if ((checks == checks))
138141 then {
139142 let sWaves = Issue("sWaves", "", 0, 8, true, unit, 0)
140143 let sWavesAssetId = calculateAssetId(sWaves)
141-[BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry("ratio", precision), IntegerEntry("leasedAmount", 0), sWaves]
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]
142145 }
143146 else throw("Strict value is not equal to itself.")
144147 }
145148
146149
147150
148151 @Callable(i)
149152 func stake () = {
150153 let payment = i.payments[0]
151154 if ((payment.assetId != unit))
152155 then throw("Only WAVES supported")
153156 else if ((size(i.payments) != 1))
154157 then throw("Wrong payments amount")
155158 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)
158162 ((lease(payment.amount) :+ issueSWaves(toReissue)) :+ sendSWaves(i.caller, toReissue))
159163 }
160164 }
161165
162166
163167
164168 @Callable(i)
165169 func unstake () = {
166170 let payment = i.payments[0]
167171 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
168172 if ((payment.assetId != sWavesAssetId))
169173 then throw("Only sWAVES supported")
170174 else if ((size(i.payments) != 1))
171175 then throw("Wrong payments amount")
172176 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))
186181 }
187182 }
188183
189184
190185
191186 @Callable(i)
192187 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+ }
195201 }
196202
197203
198204 @Verifier(tx)
199205 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
200206

github/deemru/w8io/169f3d6 
49.30 ms