tx · 4Eouaqckyijs7VAZU4N7WupKPZvva2o4DNDD9DfLPkj2

3N1JYSyNP7mn7f1YTZ2aRdi6ThpKw23j9Sy:  -0.01000000 Waves

2022.11.06 18:36 [2305451] smart account 3N1JYSyNP7mn7f1YTZ2aRdi6ThpKw23j9Sy > SELF 0.00000000 Waves

{ "type": 13, "id": "4Eouaqckyijs7VAZU4N7WupKPZvva2o4DNDD9DfLPkj2", "fee": 1000000, "feeAssetId": null, "timestamp": 1667749056407, "version": 2, "chainId": 84, "sender": "3N1JYSyNP7mn7f1YTZ2aRdi6ThpKw23j9Sy", "senderPublicKey": "65hdh3BQVcB4NhB1URp1RBWMK7AWDhrCSVjwbFjS64jo", "proofs": [ "K7AMWy5X1S4mb5cLhoFDx5FFyPzntrT7a2k3hEsJ11YB81Xuj7oNuDwwuho1nKuveAvzmVJaXj5qgNDHD2tCewL" ], "script": "base64:AAIFAAAAAAAAAA0IAhIDCgEIEgASABIAAAAAEAAAAAAJcHJlY2lzaW9uAA3gtrOnZAAAAQAAABNrZXlNYW5hZ2VyUHVibGljS2V5AAAAAAkABCIAAAABAgAAABBtYW5hZ2VyUHVibGljS2V5AQAAABZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAAAAAQAAAAHJG1hdGNoMAkBAAAAE2tleU1hbmFnZXJQdWJsaWNLZXkAAAAAAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAXMFAAAAByRtYXRjaDAJAAJZAAAAAQUAAAABcwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAUAAAAEdW5pdAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAALbXVzdE1hbmFnZXIAAAABAAAAAWkEAAAAAnBkCQAAAgAAAAECAAAAEXBlcm1pc3Npb24gZGVuaWVkBAAAAAckbWF0Y2gwCQEAAAAWbWFuYWdlclB1YmxpY0tleU9yVW5pdAAAAAADCQAAAQAAAAIFAAAAByRtYXRjaDACAAAACkJ5dGV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XYXZlcwAAAAEIBQAAAAdwYXltZW50AAAABmFtb3VudAkBAAAACXNlbmRXYXZlcwAAAAIIBQAAAAFpAAAABmNhbGxlcgUAAAAOdHJhbnNmZXJBbW91bnQJAAACAAAAAQIAAAAkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAAAAAWkBAAAACGNvbXBvdW5kAAAAAAQAAAAFcmF0aW8JAQAAAA5jYWxjdWxhdGVSYXRpbwAAAAAJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAICAAAABXJhdGlvBQAAAAVyYXRpbwUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXm9av7l", "height": 2305451, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: B1yz65pFKbqHwmNfrbj39XzMnYxXQ1hbjyKyuQACSks3 Next: BxV7wh1pPFKDP66uooy1C7ueFvgTqHBP8zEWn6Z6isHR Diff:
OldNewDifferences
5858 func setLeasedAmount (amount) = IntegerEntry("leasedAmount", amount)
5959
6060
61-func lease (amount) = {
62- let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
63- let currentAmount = getIntegerValue("leasedAmount")
64- let newAmount = (currentAmount + amount)
65- let leaseActions = if ((newAmount > 0))
66- then {
67- let newLease = Lease(leaserAddress, newAmount)
68- let newLeaseId = calculateLeaseId(newLease)
61+func lease (amount) = if ((amount == 0))
62+ then nil
63+ else {
64+ let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
65+ let currentAmount = getIntegerValue("leasedAmount")
66+ let newAmount = (currentAmount + amount)
67+ let leaseActions = if ((newAmount > 0))
68+ then {
69+ let newLease = Lease(leaserAddress, newAmount)
70+ let newLeaseId = calculateLeaseId(newLease)
6971 [newLease, BinaryEntry("leaseId", newLeaseId)]
70- }
71- else nil
72- ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount))
73- }
72+ }
73+ else nil
74+ ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount))
75+ }
7476
7577
7678 func issueSWaves (amount) = {
120122 }
121123
122124
123-@Callable(i)
124-func compound () = {
125- let ratio = calculateRatio()
126-[IntegerEntry("ratio", ratio)]
125+func withdraw (amount) = {
126+ let minerAddress = Address(fromBase58String(getStringValue("leaserAddress")))
127+ let result = invoke(minerAddress, "withdraw", [amount], nil)
128+ if ((result == result))
129+ then result
130+ else throw("Strict value is not equal to itself.")
127131 }
128-
129132
130133
131134 @Callable(i)
159162
160163
161164 @Callable(i)
162-func withdraw () = {
165+func unstake () = {
163166 let payment = i.payments[0]
164167 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
165168 if ((payment.assetId != sWavesAssetId))
168171 then throw("Wrong payments amount")
169172 else {
170173 let ratio = getIntegerValue("ratio")
171- let toTransfer = fraction(payment.amount, ratio, precision)
172- ((lease(-(toTransfer)) :+ burnSWaves(payment.amount)) :+ sendWaves(i.caller, toTransfer))
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.")
173186 }
187+ }
188+
189+
190+
191+@Callable(i)
192+func compound () = {
193+ let ratio = calculateRatio()
194+[IntegerEntry("ratio", ratio)]
174195 }
175196
176197
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 setLeasedAmount (amount) = IntegerEntry("leasedAmount", amount)
5959
6060
61-func lease (amount) = {
62- let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
63- let currentAmount = getIntegerValue("leasedAmount")
64- let newAmount = (currentAmount + amount)
65- let leaseActions = if ((newAmount > 0))
66- then {
67- let newLease = Lease(leaserAddress, newAmount)
68- let newLeaseId = calculateLeaseId(newLease)
61+func lease (amount) = if ((amount == 0))
62+ then nil
63+ else {
64+ let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
65+ let currentAmount = getIntegerValue("leasedAmount")
66+ let newAmount = (currentAmount + amount)
67+ let leaseActions = if ((newAmount > 0))
68+ then {
69+ let newLease = Lease(leaserAddress, newAmount)
70+ let newLeaseId = calculateLeaseId(newLease)
6971 [newLease, BinaryEntry("leaseId", newLeaseId)]
70- }
71- else nil
72- ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount))
73- }
72+ }
73+ else nil
74+ ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount))
75+ }
7476
7577
7678 func issueSWaves (amount) = {
7779 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
7880 Reissue(sWavesAssetId, amount, true)
7981 }
8082
8183
8284 func burnSWaves (amount) = {
8385 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
8486 Burn(sWavesAssetId, amount)
8587 }
8688
8789
8890 func sendSWaves (recipient,amount) = {
8991 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
9092 ScriptTransfer(recipient, amount, sWavesAssetId)
9193 }
9294
9395
9496 func sendWaves (recipient,amount) = ScriptTransfer(recipient, amount, unit)
9597
9698
9799 func sWavesQuantity () = {
98100 let assetId = fromBase58String(getStringValue("sWavesAssetId"))
99101 match assetInfo(assetId) {
100102 case asset: Asset =>
101103 asset.quantity
102104 case _ =>
103105 throw("Can't find asset")
104106 }
105107 }
106108
107109
108110 func getMinerBalance () = {
109111 let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress")))
110112 wavesBalance(leaserAddress).regular
111113 }
112114
113115
114116 func calculateRatio () = {
115117 let leasedAmount = getIntegerValue("leasedAmount")
116118 let sWavesTotal = sWavesQuantity()
117119 let minerBalance = getMinerBalance()
118120 let wavesTotal = (leasedAmount + minerBalance)
119121 fraction(wavesTotal, precision, sWavesTotal)
120122 }
121123
122124
123-@Callable(i)
124-func compound () = {
125- let ratio = calculateRatio()
126-[IntegerEntry("ratio", ratio)]
125+func withdraw (amount) = {
126+ let minerAddress = Address(fromBase58String(getStringValue("leaserAddress")))
127+ let result = invoke(minerAddress, "withdraw", [amount], nil)
128+ if ((result == result))
129+ then result
130+ else throw("Strict value is not equal to itself.")
127131 }
128-
129132
130133
131134 @Callable(i)
132135 func init (leaserAddress) = {
133136 let checks = [mustManager(i), mustNotInited()]
134137 if ((checks == checks))
135138 then {
136139 let sWaves = Issue("sWaves", "", 0, 8, true, unit, 0)
137140 let sWavesAssetId = calculateAssetId(sWaves)
138141 [BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry("ratio", precision), IntegerEntry("leasedAmount", 0), sWaves]
139142 }
140143 else throw("Strict value is not equal to itself.")
141144 }
142145
143146
144147
145148 @Callable(i)
146149 func stake () = {
147150 let payment = i.payments[0]
148151 if ((payment.assetId != unit))
149152 then throw("Only WAVES supported")
150153 else if ((size(i.payments) != 1))
151154 then throw("Wrong payments amount")
152155 else {
153156 let ratio = getIntegerValue("ratio")
154157 let toReissue = fraction(payment.amount, precision, ratio)
155158 ((lease(payment.amount) :+ issueSWaves(toReissue)) :+ sendSWaves(i.caller, toReissue))
156159 }
157160 }
158161
159162
160163
161164 @Callable(i)
162-func withdraw () = {
165+func unstake () = {
163166 let payment = i.payments[0]
164167 let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId"))
165168 if ((payment.assetId != sWavesAssetId))
166169 then throw("Only sWAVES supported")
167170 else if ((size(i.payments) != 1))
168171 then throw("Wrong payments amount")
169172 else {
170173 let ratio = getIntegerValue("ratio")
171- let toTransfer = fraction(payment.amount, ratio, precision)
172- ((lease(-(toTransfer)) :+ burnSWaves(payment.amount)) :+ sendWaves(i.caller, toTransfer))
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.")
173186 }
187+ }
188+
189+
190+
191+@Callable(i)
192+func compound () = {
193+ let ratio = calculateRatio()
194+[IntegerEntry("ratio", ratio)]
174195 }
175196
176197
177198 @Verifier(tx)
178199 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
179200

github/deemru/w8io/026f985 
36.75 ms