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:AAIFAAAAAAAAAA0IAhIDCgEIEgASABIAAAAAEAAAAAAJcHJlY2lzaW9uAA3gtrOnZAAAAQAAABNrZXlNYW5hZ2VyUHVibGljS2V5AAAAAAkABCIAAAABAgAAABBtYW5hZ2VyUHVibGljS2V5AQAAABZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAAAAAQAAAAHJG1hdGNoMAkBAAAAE2tleU1hbmFnZXJQdWJsaWNLZXkAAAAAAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAXMFAAAAByRtYXRjaDAJAAJZAAAAAQUAAAABcwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAUAAAAEdW5pdAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAALbXVzdE1hbmFnZXIAAAABAAAAAWkEAAAAAnBkCQAAAgAAAAECAAAAEXBlcm1pc3Npb24gZGVuaWVkBAAAAAckbWF0Y2gwCQEAAAAWbWFuYWdlclB1YmxpY0tleU9yVW5pdAAAAAADCQAAAQAAAAIFAAAAByRtYXRjaDACAAAACkJ5dGVW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YXZlcwAAAAEIBQAAAAdwYXltZW50AAAABmFtb3VudAkBAAAACXNlbmRXYXZlcwAAAAIIBQAAAAFpAAAABmNhbGxlcgUAAAAOdHJhbnNmZXJBbW91bnQJAAACAAAAAQIAAAAkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAAAAAWkBAAAACGNvbXBvdW5kAAAAAAQAAAAFcmF0aW8JAQAAAA5jYWxjdWxhdGVSYXRpbwAAAAAJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAICAAAABXJhdGlvBQAAAAVyYXRpbwUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXm9av7l", "height": 2305451, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: B1yz65pFKbqHwmNfrbj39XzMnYxXQ1hbjyKyuQACSks3 Next: BxV7wh1pPFKDP66uooy1C7ueFvgTqHBP8zEWn6Z6isHR Diff:
Old | New | Differences | |
---|---|---|---|
58 | 58 | func setLeasedAmount (amount) = IntegerEntry("leasedAmount", amount) | |
59 | 59 | ||
60 | 60 | ||
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) | |
69 | 71 | [newLease, BinaryEntry("leaseId", newLeaseId)] | |
70 | - | } | |
71 | - | else nil | |
72 | - | ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount)) | |
73 | - | } | |
72 | + | } | |
73 | + | else nil | |
74 | + | ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount)) | |
75 | + | } | |
74 | 76 | ||
75 | 77 | ||
76 | 78 | func issueSWaves (amount) = { | |
120 | 122 | } | |
121 | 123 | ||
122 | 124 | ||
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.") | |
127 | 131 | } | |
128 | - | ||
129 | 132 | ||
130 | 133 | ||
131 | 134 | @Callable(i) | |
159 | 162 | ||
160 | 163 | ||
161 | 164 | @Callable(i) | |
162 | - | func | |
165 | + | func unstake () = { | |
163 | 166 | let payment = i.payments[0] | |
164 | 167 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
165 | 168 | if ((payment.assetId != sWavesAssetId)) | |
168 | 171 | then throw("Wrong payments amount") | |
169 | 172 | else { | |
170 | 173 | 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.") | |
173 | 186 | } | |
187 | + | } | |
188 | + | ||
189 | + | ||
190 | + | ||
191 | + | @Callable(i) | |
192 | + | func compound () = { | |
193 | + | let ratio = calculateRatio() | |
194 | + | [IntegerEntry("ratio", ratio)] | |
174 | 195 | } | |
175 | 196 | ||
176 | 197 |
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 setLeasedAmount (amount) = IntegerEntry("leasedAmount", amount) | |
59 | 59 | ||
60 | 60 | ||
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) | |
69 | 71 | [newLease, BinaryEntry("leaseId", newLeaseId)] | |
70 | - | } | |
71 | - | else nil | |
72 | - | ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount)) | |
73 | - | } | |
72 | + | } | |
73 | + | else nil | |
74 | + | ((cancelLease() ++ leaseActions) :+ setLeasedAmount(newAmount)) | |
75 | + | } | |
74 | 76 | ||
75 | 77 | ||
76 | 78 | func issueSWaves (amount) = { | |
77 | 79 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
78 | 80 | Reissue(sWavesAssetId, amount, true) | |
79 | 81 | } | |
80 | 82 | ||
81 | 83 | ||
82 | 84 | func burnSWaves (amount) = { | |
83 | 85 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
84 | 86 | Burn(sWavesAssetId, amount) | |
85 | 87 | } | |
86 | 88 | ||
87 | 89 | ||
88 | 90 | func sendSWaves (recipient,amount) = { | |
89 | 91 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
90 | 92 | ScriptTransfer(recipient, amount, sWavesAssetId) | |
91 | 93 | } | |
92 | 94 | ||
93 | 95 | ||
94 | 96 | func sendWaves (recipient,amount) = ScriptTransfer(recipient, amount, unit) | |
95 | 97 | ||
96 | 98 | ||
97 | 99 | func sWavesQuantity () = { | |
98 | 100 | let assetId = fromBase58String(getStringValue("sWavesAssetId")) | |
99 | 101 | match assetInfo(assetId) { | |
100 | 102 | case asset: Asset => | |
101 | 103 | asset.quantity | |
102 | 104 | case _ => | |
103 | 105 | throw("Can't find asset") | |
104 | 106 | } | |
105 | 107 | } | |
106 | 108 | ||
107 | 109 | ||
108 | 110 | func getMinerBalance () = { | |
109 | 111 | let leaserAddress = Address(fromBase58String(getStringValue("leaserAddress"))) | |
110 | 112 | wavesBalance(leaserAddress).regular | |
111 | 113 | } | |
112 | 114 | ||
113 | 115 | ||
114 | 116 | func calculateRatio () = { | |
115 | 117 | let leasedAmount = getIntegerValue("leasedAmount") | |
116 | 118 | let sWavesTotal = sWavesQuantity() | |
117 | 119 | let minerBalance = getMinerBalance() | |
118 | 120 | let wavesTotal = (leasedAmount + minerBalance) | |
119 | 121 | fraction(wavesTotal, precision, sWavesTotal) | |
120 | 122 | } | |
121 | 123 | ||
122 | 124 | ||
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.") | |
127 | 131 | } | |
128 | - | ||
129 | 132 | ||
130 | 133 | ||
131 | 134 | @Callable(i) | |
132 | 135 | func init (leaserAddress) = { | |
133 | 136 | let checks = [mustManager(i), mustNotInited()] | |
134 | 137 | if ((checks == checks)) | |
135 | 138 | then { | |
136 | 139 | let sWaves = Issue("sWaves", "", 0, 8, true, unit, 0) | |
137 | 140 | let sWavesAssetId = calculateAssetId(sWaves) | |
138 | 141 | [BooleanEntry("inited", true), StringEntry("sWavesAssetId", toBase58String(sWavesAssetId)), StringEntry("leaserAddress", leaserAddress), IntegerEntry("ratio", precision), IntegerEntry("leasedAmount", 0), sWaves] | |
139 | 142 | } | |
140 | 143 | else throw("Strict value is not equal to itself.") | |
141 | 144 | } | |
142 | 145 | ||
143 | 146 | ||
144 | 147 | ||
145 | 148 | @Callable(i) | |
146 | 149 | func stake () = { | |
147 | 150 | let payment = i.payments[0] | |
148 | 151 | if ((payment.assetId != unit)) | |
149 | 152 | then throw("Only WAVES supported") | |
150 | 153 | else if ((size(i.payments) != 1)) | |
151 | 154 | then throw("Wrong payments amount") | |
152 | 155 | else { | |
153 | 156 | let ratio = getIntegerValue("ratio") | |
154 | 157 | let toReissue = fraction(payment.amount, precision, ratio) | |
155 | 158 | ((lease(payment.amount) :+ issueSWaves(toReissue)) :+ sendSWaves(i.caller, toReissue)) | |
156 | 159 | } | |
157 | 160 | } | |
158 | 161 | ||
159 | 162 | ||
160 | 163 | ||
161 | 164 | @Callable(i) | |
162 | - | func | |
165 | + | func unstake () = { | |
163 | 166 | let payment = i.payments[0] | |
164 | 167 | let sWavesAssetId = fromBase58String(getStringValue("sWavesAssetId")) | |
165 | 168 | if ((payment.assetId != sWavesAssetId)) | |
166 | 169 | then throw("Only sWAVES supported") | |
167 | 170 | else if ((size(i.payments) != 1)) | |
168 | 171 | then throw("Wrong payments amount") | |
169 | 172 | else { | |
170 | 173 | 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.") | |
173 | 186 | } | |
187 | + | } | |
188 | + | ||
189 | + | ||
190 | + | ||
191 | + | @Callable(i) | |
192 | + | func compound () = { | |
193 | + | let ratio = calculateRatio() | |
194 | + | [IntegerEntry("ratio", ratio)] | |
174 | 195 | } | |
175 | 196 | ||
176 | 197 | ||
177 | 198 | @Verifier(tx) | |
178 | 199 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
179 | 200 |
github/deemru/w8io/026f985 36.75 ms ◑