tx · 8vn7jQm3xrr5emPUkFcVhBFSghRNd1VwaTFoh145uxMB 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h: -0.05000000 Waves 2023.03.28 14:00 [2509724] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves
{ "type": 13, "id": "8vn7jQm3xrr5emPUkFcVhBFSghRNd1VwaTFoh145uxMB", "fee": 5000000, "feeAssetId": null, "timestamp": 1680001278221, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "35RdgFnvDh4jkR2DDXywVf9b6jDhcvJwADjSzu9Eevx4xJpQvj73t5XeP9rD9XJB6H3a7KLkcfNAHiKsk9EQcTBT" ], "script": "base64:BgIQCAISABIFCgMBAQESAwoBAQ4ADGNvbnRyYWN0RmlsZQIJcmViYWxhbmNlAA9rZXlzVGFyZ2V0UmF0aW8CDyVzX190YXJnZXRSYXRpbwAUa2V5QWRkaXRpb25hbEJhbGFuY2UCGiVzX19hZGRpdGlvbmFsV2F2ZXNCYWxhbmNlABprZXlTV2F2ZXNBZGRpdGlvbmFsQmFsYW5jZQIRJXNfX3NXYXZlc0JhbGFuY2UAEGtleVNXYXZlc0Fzc2V0SWQCESVzX19zV2F2ZXNBc3NldElkAA9rZXlQcm94eUFkZHJlc3MCECVzX19wcm94eUFkZHJlc3MBEGdldEludGVnZXJPclplcm8BCmludGVnZXJLZXkEByRtYXRjaDAJAJoIAgUEdGhpcwUKaW50ZWdlcktleQMJAAECBQckbWF0Y2gwAgNJbnQEA3ZhbAUHJG1hdGNoMAUDdmFsAAABEGdldFN0cmluZ09yVGhyb3cBCXN0cmluZ0tleQQHJG1hdGNoMAkAnQgCBQR0aGlzBQlzdHJpbmdLZXkDCQABAgUHJG1hdGNoMAIGU3RyaW5nBAFzBQckbWF0Y2gwBQFzCQACAQ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Y2hhbmdlAwkAAAIFBmNoYW5nZQAABQNuaWwDCQBmAgAABQZjaGFuZ2UED3NlbmRXYXZlc0Ftb3VudAkAaAIFBmNoYW5nZQD///////////8BCQEHZGVwb3NpdAEFD3NlbmRXYXZlc0Ftb3VudAQOZ2V0V2F2ZXNBbW91bnQFBmNoYW5nZQkBCHdpdGhkcmF3AQUOZ2V0V2F2ZXNBbW91bnQJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4JAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4Am9325A==", "height": 2509724, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 44fuU8CAFGwn9pdreeYxTFyZjNNnccaCtuD5AzgdAjR2 Next: A2saRMNi6Am5rvtqqKKFHBnS3rYLnNEtJS9CaAVKVhb2 Diff:
Old | New | Differences | |
---|---|---|---|
70 | 70 | then { | |
71 | 71 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
72 | 72 | if ((currentSWavesBalance == currentSWavesBalance)) | |
73 | - | then { | |
74 | - | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)]) | |
75 | - | if ((depositInvoke == depositInvoke)) | |
76 | - | then match depositInvoke { | |
77 | - | case receivedSWaves: Int => | |
78 | - | let newAdditionalBalance = (currentAdditionalBalance + wavesAmount) | |
79 | - | let newSWavesBalance = (currentSWavesBalance + receivedSWaves) | |
73 | + | then if ((wavesAmount > 0)) | |
74 | + | then { | |
75 | + | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)]) | |
76 | + | if ((depositInvoke == depositInvoke)) | |
77 | + | then match depositInvoke { | |
78 | + | case receivedSWaves: Int => | |
79 | + | let newAdditionalBalance = (currentAdditionalBalance + wavesAmount) | |
80 | + | let newSWavesBalance = (currentSWavesBalance + receivedSWaves) | |
80 | 81 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
81 | - | case _ => | |
82 | - | nil | |
82 | + | case _ => | |
83 | + | nil | |
84 | + | } | |
85 | + | else throw("Strict value is not equal to itself.") | |
83 | 86 | } | |
84 | - | else throw("Strict value is not equal to itself.") | |
85 | - | } | |
87 | + | else nil | |
86 | 88 | else throw("Strict value is not equal to itself.") | |
87 | 89 | } | |
88 | 90 | else throw("Strict value is not equal to itself.") | |
104 | 106 | if ((currentProxyRate == currentProxyRate)) | |
105 | 107 | then { | |
106 | 108 | let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate) | |
107 | - | let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)]) | |
108 | - | if ((depositInvoke == depositInvoke)) | |
109 | - | then match depositInvoke { | |
110 | - | case receivedWaves: Int => | |
111 | - | let newAdditionalBalance = (currentAdditionalBalance - receivedWaves) | |
112 | - | let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount) | |
109 | + | if ((sendSWavesAmount > 0)) | |
110 | + | then { | |
111 | + | let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)]) | |
112 | + | if ((depositInvoke == depositInvoke)) | |
113 | + | then match depositInvoke { | |
114 | + | case receivedWaves: Int => | |
115 | + | let newAdditionalBalance = (currentAdditionalBalance - receivedWaves) | |
116 | + | let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount) | |
113 | 117 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
114 | - | case _ => | |
115 | - | nil | |
116 | - | } | |
117 | - | else throw("Strict value is not equal to itself.") | |
118 | + | case _ => | |
119 | + | nil | |
120 | + | } | |
121 | + | else throw("Strict value is not equal to itself.") | |
122 | + | } | |
123 | + | else nil | |
118 | 124 | } | |
119 | 125 | else throw("Strict value is not equal to itself.") | |
120 | 126 | } | |
124 | 130 | } | |
125 | 131 | else throw("Strict value is not equal to itself.") | |
126 | 132 | } | |
127 | - | ||
128 | - | ||
129 | - | @Callable(i) | |
130 | - | func returnWavesBalance () = $Tuple2(nil, internalWavesBalance()) | |
131 | - | ||
132 | - | ||
133 | - | ||
134 | - | @Callable(i) | |
135 | - | func returnSWavesBalance () = $Tuple2(nil, getIntegerOrZero(keySWavesAdditionalBalance)) | |
136 | - | ||
137 | 133 | ||
138 | 134 | ||
139 | 135 | @Callable(i) | |
161 | 157 | let sendAmount = change | |
162 | 158 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("withdraw: " + toString(sendAmount))]) | |
163 | 159 | } | |
164 | - | } | |
165 | - | ||
166 | - | ||
167 | - | ||
168 | - | @Callable(i) | |
169 | - | func rebalance () = { | |
170 | - | let regularBalance = wavesBalance(this).regular | |
171 | - | if ((regularBalance == regularBalance)) | |
172 | - | then { | |
173 | - | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
174 | - | if ((additionalBalance == additionalBalance)) | |
175 | - | then { | |
176 | - | let targetRatio = getTargetRatio() | |
177 | - | if ((targetRatio == targetRatio)) | |
178 | - | then { | |
179 | - | let wholeBlalance = (regularBalance + additionalBalance) | |
180 | - | let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100) | |
181 | - | let change = (additionalBalance - targetAdditionalBalance) | |
182 | - | let newReg = (regularBalance + change) | |
183 | - | if ((change == 0)) | |
184 | - | then nil | |
185 | - | else if ((0 > change)) | |
186 | - | then { | |
187 | - | let sendWavesAmount = (change * -1) | |
188 | - | deposit(sendWavesAmount) | |
189 | - | } | |
190 | - | else { | |
191 | - | let getWavesAmount = change | |
192 | - | withdraw(getWavesAmount) | |
193 | - | } | |
194 | - | } | |
195 | - | else throw("Strict value is not equal to itself.") | |
196 | - | } | |
197 | - | else throw("Strict value is not equal to itself.") | |
198 | - | } | |
199 | - | else throw("Strict value is not equal to itself.") | |
200 | 160 | } | |
201 | 161 | ||
202 | 162 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let contractFile = "rebalance" | |
5 | 5 | ||
6 | 6 | let keysTargetRatio = "%s__targetRatio" | |
7 | 7 | ||
8 | 8 | let keyAdditionalBalance = "%s__additionalWavesBalance" | |
9 | 9 | ||
10 | 10 | let keySWavesAdditionalBalance = "%s__sWavesBalance" | |
11 | 11 | ||
12 | 12 | let keySWavesAssetId = "%s__sWavesAssetId" | |
13 | 13 | ||
14 | 14 | let keyProxyAddress = "%s__proxyAddress" | |
15 | 15 | ||
16 | 16 | func getIntegerOrZero (integerKey) = match getInteger(this, integerKey) { | |
17 | 17 | case val: Int => | |
18 | 18 | val | |
19 | 19 | case _ => | |
20 | 20 | 0 | |
21 | 21 | } | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | func getStringOrThrow (stringKey) = match getString(this, stringKey) { | |
25 | 25 | case s: String => | |
26 | 26 | s | |
27 | 27 | case _ => | |
28 | 28 | throw((("[" + stringKey) + "] is empty")) | |
29 | 29 | } | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func getTargetRatio () = match getInteger(keysTargetRatio) { | |
33 | 33 | case s: Int => | |
34 | 34 | s | |
35 | 35 | case _ => | |
36 | 36 | 80 | |
37 | 37 | } | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func internalWavesBalance () = (wavesBalance(this).regular + getIntegerOrZero(keyAdditionalBalance)) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func internalRate () = { | |
44 | 44 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
45 | 45 | let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
46 | 46 | if ((additionalBalance == 0)) | |
47 | 47 | then 0 | |
48 | 48 | else fraction(100000000000, additionalBalance, sWavesBalance) | |
49 | 49 | } | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getRate () = { | |
53 | 53 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
54 | 54 | let inv = invoke(proxy, "getRate", nil, nil) | |
55 | 55 | if ((inv == inv)) | |
56 | 56 | then match inv { | |
57 | 57 | case s: String => | |
58 | 58 | parseIntValue(s) | |
59 | 59 | case _ => | |
60 | 60 | throw("ZERO rate") | |
61 | 61 | } | |
62 | 62 | else throw("Strict value is not equal to itself.") | |
63 | 63 | } | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func deposit (wavesAmount) = { | |
67 | 67 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
68 | 68 | let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
69 | 69 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
70 | 70 | then { | |
71 | 71 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
72 | 72 | if ((currentSWavesBalance == currentSWavesBalance)) | |
73 | - | then { | |
74 | - | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)]) | |
75 | - | if ((depositInvoke == depositInvoke)) | |
76 | - | then match depositInvoke { | |
77 | - | case receivedSWaves: Int => | |
78 | - | let newAdditionalBalance = (currentAdditionalBalance + wavesAmount) | |
79 | - | let newSWavesBalance = (currentSWavesBalance + receivedSWaves) | |
73 | + | then if ((wavesAmount > 0)) | |
74 | + | then { | |
75 | + | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)]) | |
76 | + | if ((depositInvoke == depositInvoke)) | |
77 | + | then match depositInvoke { | |
78 | + | case receivedSWaves: Int => | |
79 | + | let newAdditionalBalance = (currentAdditionalBalance + wavesAmount) | |
80 | + | let newSWavesBalance = (currentSWavesBalance + receivedSWaves) | |
80 | 81 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
81 | - | case _ => | |
82 | - | nil | |
82 | + | case _ => | |
83 | + | nil | |
84 | + | } | |
85 | + | else throw("Strict value is not equal to itself.") | |
83 | 86 | } | |
84 | - | else throw("Strict value is not equal to itself.") | |
85 | - | } | |
87 | + | else nil | |
86 | 88 | else throw("Strict value is not equal to itself.") | |
87 | 89 | } | |
88 | 90 | else throw("Strict value is not equal to itself.") | |
89 | 91 | } | |
90 | 92 | ||
91 | 93 | ||
92 | 94 | func withdraw (wavesAmount) = { | |
93 | 95 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
94 | 96 | let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId)) | |
95 | 97 | if ((sWavesId == sWavesId)) | |
96 | 98 | then { | |
97 | 99 | let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
98 | 100 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
99 | 101 | then { | |
100 | 102 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
101 | 103 | if ((currentSWavesBalance == currentSWavesBalance)) | |
102 | 104 | then { | |
103 | 105 | let currentProxyRate = getRate() | |
104 | 106 | if ((currentProxyRate == currentProxyRate)) | |
105 | 107 | then { | |
106 | 108 | let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate) | |
107 | - | let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)]) | |
108 | - | if ((depositInvoke == depositInvoke)) | |
109 | - | then match depositInvoke { | |
110 | - | case receivedWaves: Int => | |
111 | - | let newAdditionalBalance = (currentAdditionalBalance - receivedWaves) | |
112 | - | let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount) | |
109 | + | if ((sendSWavesAmount > 0)) | |
110 | + | then { | |
111 | + | let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)]) | |
112 | + | if ((depositInvoke == depositInvoke)) | |
113 | + | then match depositInvoke { | |
114 | + | case receivedWaves: Int => | |
115 | + | let newAdditionalBalance = (currentAdditionalBalance - receivedWaves) | |
116 | + | let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount) | |
113 | 117 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
114 | - | case _ => | |
115 | - | nil | |
116 | - | } | |
117 | - | else throw("Strict value is not equal to itself.") | |
118 | + | case _ => | |
119 | + | nil | |
120 | + | } | |
121 | + | else throw("Strict value is not equal to itself.") | |
122 | + | } | |
123 | + | else nil | |
118 | 124 | } | |
119 | 125 | else throw("Strict value is not equal to itself.") | |
120 | 126 | } | |
121 | 127 | else throw("Strict value is not equal to itself.") | |
122 | 128 | } | |
123 | 129 | else throw("Strict value is not equal to itself.") | |
124 | 130 | } | |
125 | 131 | else throw("Strict value is not equal to itself.") | |
126 | 132 | } | |
127 | - | ||
128 | - | ||
129 | - | @Callable(i) | |
130 | - | func returnWavesBalance () = $Tuple2(nil, internalWavesBalance()) | |
131 | - | ||
132 | - | ||
133 | - | ||
134 | - | @Callable(i) | |
135 | - | func returnSWavesBalance () = $Tuple2(nil, getIntegerOrZero(keySWavesAdditionalBalance)) | |
136 | - | ||
137 | 133 | ||
138 | 134 | ||
139 | 135 | @Callable(i) | |
140 | 136 | func calcRatio () = { | |
141 | 137 | let regularWavesBalance = wavesBalance(this).regular | |
142 | 138 | let additional = getIntegerOrZero(keyAdditionalBalance) | |
143 | 139 | let ratio = fraction(100, additional, (additional + regularWavesBalance)) | |
144 | 140 | $Tuple2(nil, ratio) | |
145 | 141 | } | |
146 | 142 | ||
147 | 143 | ||
148 | 144 | ||
149 | 145 | @Callable(i) | |
150 | 146 | func calcRatioTest (regularBalance,additional,targetRatio) = { | |
151 | 147 | let sum = (regularBalance + additional) | |
152 | 148 | let targetAdditionalBalance = fraction(targetRatio, sum, 100) | |
153 | 149 | let change = (additional - targetAdditionalBalance) | |
154 | 150 | let newReg = (regularBalance + change) | |
155 | 151 | if ((0 > change)) | |
156 | 152 | then { | |
157 | 153 | let sendAmount = (change * -1) | |
158 | 154 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("deposit: " + toString(sendAmount))]) | |
159 | 155 | } | |
160 | 156 | else { | |
161 | 157 | let sendAmount = change | |
162 | 158 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("withdraw: " + toString(sendAmount))]) | |
163 | 159 | } | |
164 | - | } | |
165 | - | ||
166 | - | ||
167 | - | ||
168 | - | @Callable(i) | |
169 | - | func rebalance () = { | |
170 | - | let regularBalance = wavesBalance(this).regular | |
171 | - | if ((regularBalance == regularBalance)) | |
172 | - | then { | |
173 | - | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
174 | - | if ((additionalBalance == additionalBalance)) | |
175 | - | then { | |
176 | - | let targetRatio = getTargetRatio() | |
177 | - | if ((targetRatio == targetRatio)) | |
178 | - | then { | |
179 | - | let wholeBlalance = (regularBalance + additionalBalance) | |
180 | - | let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100) | |
181 | - | let change = (additionalBalance - targetAdditionalBalance) | |
182 | - | let newReg = (regularBalance + change) | |
183 | - | if ((change == 0)) | |
184 | - | then nil | |
185 | - | else if ((0 > change)) | |
186 | - | then { | |
187 | - | let sendWavesAmount = (change * -1) | |
188 | - | deposit(sendWavesAmount) | |
189 | - | } | |
190 | - | else { | |
191 | - | let getWavesAmount = change | |
192 | - | withdraw(getWavesAmount) | |
193 | - | } | |
194 | - | } | |
195 | - | else throw("Strict value is not equal to itself.") | |
196 | - | } | |
197 | - | else throw("Strict value is not equal to itself.") | |
198 | - | } | |
199 | - | else throw("Strict value is not equal to itself.") | |
200 | 160 | } | |
201 | 161 | ||
202 | 162 | ||
203 | 163 | ||
204 | 164 | @Callable(i) | |
205 | 165 | func rebalanceRatio (targetRatio) = { | |
206 | 166 | let regularBalance = wavesBalance(this).regular | |
207 | 167 | if ((regularBalance == regularBalance)) | |
208 | 168 | then { | |
209 | 169 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
210 | 170 | if ((additionalBalance == additionalBalance)) | |
211 | 171 | then { | |
212 | 172 | let wholeBlalance = (regularBalance + additionalBalance) | |
213 | 173 | let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100) | |
214 | 174 | let change = (additionalBalance - targetAdditionalBalance) | |
215 | 175 | let newReg = (regularBalance + change) | |
216 | 176 | if ((change == 0)) | |
217 | 177 | then nil | |
218 | 178 | else if ((0 > change)) | |
219 | 179 | then { | |
220 | 180 | let sendWavesAmount = (change * -1) | |
221 | 181 | deposit(sendWavesAmount) | |
222 | 182 | } | |
223 | 183 | else { | |
224 | 184 | let getWavesAmount = change | |
225 | 185 | withdraw(getWavesAmount) | |
226 | 186 | } | |
227 | 187 | } | |
228 | 188 | else throw("Strict value is not equal to itself.") | |
229 | 189 | } | |
230 | 190 | else throw("Strict value is not equal to itself.") | |
231 | 191 | } | |
232 | 192 | ||
233 | 193 |
github/deemru/w8io/169f3d6 35.91 ms ◑