tx · 44fuU8CAFGwn9pdreeYxTFyZjNNnccaCtuD5AzgdAjR2 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h: -0.05000000 Waves 2023.03.28 10:14 [2509487] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves
{ "type": 13, "id": "44fuU8CAFGwn9pdreeYxTFyZjNNnccaCtuD5AzgdAjR2", "fee": 5000000, "feeAssetId": null, "timestamp": 1679987734069, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "5mHFchirJH29GUTaABP6bnMBeCZJFEL72fBjLxiBnJB3LF3jX4jakT29aeYvaASUcuj7uJHDMndayQDdSb9EwyLQ" ], "script": "base64:BgIWCAISABIAEgASBQoDAQEBEgASAwoBAQ4ADGNvbnRyYWN0RmlsZQIJcmViYWxhbmNlAA9rZXlzVGFyZ2V0UmF0aW8CDyVzX190YXJnZXRSYXRpbwAUa2V5QWRkaXRpb25hbEJhbGFuY2UCGiVzX19hZGRpdGlvbmFsV2F2ZXNCYWxhbmNlABprZXlTV2F2ZXNBZGRpdGlvbmFsQmFsYW5jZQIRJXNfX3NXYXZlc0JhbGFuY2UAEGtleVNXYXZlc0Fzc2V0SWQCESVzX19zV2F2ZXNBc3NldElkAA9rZXlQcm94eUFkZHJlc3MCECVzX19wcm94eUFkZHJlc3MBEGdldEludGVnZXJPclplcm8BCmludGVnZXJLZXkEByRtYXRjaDAJAJoIAgUEdGhpcwUKaW50ZWdlcktleQMJAAECBQckbWF0Y2gwAgNJbnQEA3ZhbAUHJG1hdGNoMAUDdmFsAAABEGdldFN0cmluZ09yVGhyb3cBCXN0cmluZ0tleQQHJG1hdGNoMAkAnQgCBQR0aGlzBQlzdHJpbmdLZXkDCQABAgUHJG1hdGNoMAIGU3RyaW5nBAFzBQckbWF0Y2gwBQFzC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BRd0YXJnZXRBZGRpdGlvbmFsQmFsYW5jZQQGbmV3UmVnCQBkAgUOcmVndWxhckJhbGFuY2UFBmNoYW5nZQMJAAACBQZjaGFuZ2UAAAUDbmlsAwkAZgIAAAUGY2hhbmdlBA9zZW5kV2F2ZXNBbW91bnQJAGgCBQZjaGFuZ2UA////////////AQkBB2RlcG9zaXQBBQ9zZW5kV2F2ZXNBbW91bnQEDmdldFdhdmVzQW1vdW50BQZjaGFuZ2UJAQh3aXRoZHJhdwEFDmdldFdhdmVzQW1vdW50CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAO96CGs=", "height": 2509487, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: AKW2SvCMFrc61Cfc2dUDqBrsNf3Jth3zn731ULCJrXSt Next: 8vn7jQm3xrr5emPUkFcVhBFSghRNd1VwaTFoh145uxMB Diff:
Old | New | Differences | |
---|---|---|---|
200 | 200 | } | |
201 | 201 | ||
202 | 202 | ||
203 | + | ||
204 | + | @Callable(i) | |
205 | + | func rebalanceRatio (targetRatio) = { | |
206 | + | let regularBalance = wavesBalance(this).regular | |
207 | + | if ((regularBalance == regularBalance)) | |
208 | + | then { | |
209 | + | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
210 | + | if ((additionalBalance == additionalBalance)) | |
211 | + | then { | |
212 | + | let wholeBlalance = (regularBalance + additionalBalance) | |
213 | + | let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100) | |
214 | + | let change = (additionalBalance - targetAdditionalBalance) | |
215 | + | let newReg = (regularBalance + change) | |
216 | + | if ((change == 0)) | |
217 | + | then nil | |
218 | + | else if ((0 > change)) | |
219 | + | then { | |
220 | + | let sendWavesAmount = (change * -1) | |
221 | + | deposit(sendWavesAmount) | |
222 | + | } | |
223 | + | else { | |
224 | + | let getWavesAmount = change | |
225 | + | withdraw(getWavesAmount) | |
226 | + | } | |
227 | + | } | |
228 | + | else throw("Strict value is not equal to itself.") | |
229 | + | } | |
230 | + | else throw("Strict value is not equal to itself.") | |
231 | + | } | |
232 | + | ||
233 | + |
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 | 73 | then { | |
74 | 74 | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)]) | |
75 | 75 | if ((depositInvoke == depositInvoke)) | |
76 | 76 | then match depositInvoke { | |
77 | 77 | case receivedSWaves: Int => | |
78 | 78 | let newAdditionalBalance = (currentAdditionalBalance + wavesAmount) | |
79 | 79 | let newSWavesBalance = (currentSWavesBalance + receivedSWaves) | |
80 | 80 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
81 | 81 | case _ => | |
82 | 82 | nil | |
83 | 83 | } | |
84 | 84 | else throw("Strict value is not equal to itself.") | |
85 | 85 | } | |
86 | 86 | else throw("Strict value is not equal to itself.") | |
87 | 87 | } | |
88 | 88 | else throw("Strict value is not equal to itself.") | |
89 | 89 | } | |
90 | 90 | ||
91 | 91 | ||
92 | 92 | func withdraw (wavesAmount) = { | |
93 | 93 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
94 | 94 | let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId)) | |
95 | 95 | if ((sWavesId == sWavesId)) | |
96 | 96 | then { | |
97 | 97 | let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
98 | 98 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
99 | 99 | then { | |
100 | 100 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
101 | 101 | if ((currentSWavesBalance == currentSWavesBalance)) | |
102 | 102 | then { | |
103 | 103 | let currentProxyRate = getRate() | |
104 | 104 | if ((currentProxyRate == currentProxyRate)) | |
105 | 105 | then { | |
106 | 106 | let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate) | |
107 | 107 | let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)]) | |
108 | 108 | if ((depositInvoke == depositInvoke)) | |
109 | 109 | then match depositInvoke { | |
110 | 110 | case receivedWaves: Int => | |
111 | 111 | let newAdditionalBalance = (currentAdditionalBalance - receivedWaves) | |
112 | 112 | let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount) | |
113 | 113 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
114 | 114 | case _ => | |
115 | 115 | nil | |
116 | 116 | } | |
117 | 117 | else throw("Strict value is not equal to itself.") | |
118 | 118 | } | |
119 | 119 | else throw("Strict value is not equal to itself.") | |
120 | 120 | } | |
121 | 121 | else throw("Strict value is not equal to itself.") | |
122 | 122 | } | |
123 | 123 | else throw("Strict value is not equal to itself.") | |
124 | 124 | } | |
125 | 125 | else throw("Strict value is not equal to itself.") | |
126 | 126 | } | |
127 | 127 | ||
128 | 128 | ||
129 | 129 | @Callable(i) | |
130 | 130 | func returnWavesBalance () = $Tuple2(nil, internalWavesBalance()) | |
131 | 131 | ||
132 | 132 | ||
133 | 133 | ||
134 | 134 | @Callable(i) | |
135 | 135 | func returnSWavesBalance () = $Tuple2(nil, getIntegerOrZero(keySWavesAdditionalBalance)) | |
136 | 136 | ||
137 | 137 | ||
138 | 138 | ||
139 | 139 | @Callable(i) | |
140 | 140 | func calcRatio () = { | |
141 | 141 | let regularWavesBalance = wavesBalance(this).regular | |
142 | 142 | let additional = getIntegerOrZero(keyAdditionalBalance) | |
143 | 143 | let ratio = fraction(100, additional, (additional + regularWavesBalance)) | |
144 | 144 | $Tuple2(nil, ratio) | |
145 | 145 | } | |
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | 149 | @Callable(i) | |
150 | 150 | func calcRatioTest (regularBalance,additional,targetRatio) = { | |
151 | 151 | let sum = (regularBalance + additional) | |
152 | 152 | let targetAdditionalBalance = fraction(targetRatio, sum, 100) | |
153 | 153 | let change = (additional - targetAdditionalBalance) | |
154 | 154 | let newReg = (regularBalance + change) | |
155 | 155 | if ((0 > change)) | |
156 | 156 | then { | |
157 | 157 | let sendAmount = (change * -1) | |
158 | 158 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("deposit: " + toString(sendAmount))]) | |
159 | 159 | } | |
160 | 160 | else { | |
161 | 161 | let sendAmount = change | |
162 | 162 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("withdraw: " + toString(sendAmount))]) | |
163 | 163 | } | |
164 | 164 | } | |
165 | 165 | ||
166 | 166 | ||
167 | 167 | ||
168 | 168 | @Callable(i) | |
169 | 169 | func rebalance () = { | |
170 | 170 | let regularBalance = wavesBalance(this).regular | |
171 | 171 | if ((regularBalance == regularBalance)) | |
172 | 172 | then { | |
173 | 173 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
174 | 174 | if ((additionalBalance == additionalBalance)) | |
175 | 175 | then { | |
176 | 176 | let targetRatio = getTargetRatio() | |
177 | 177 | if ((targetRatio == targetRatio)) | |
178 | 178 | then { | |
179 | 179 | let wholeBlalance = (regularBalance + additionalBalance) | |
180 | 180 | let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100) | |
181 | 181 | let change = (additionalBalance - targetAdditionalBalance) | |
182 | 182 | let newReg = (regularBalance + change) | |
183 | 183 | if ((change == 0)) | |
184 | 184 | then nil | |
185 | 185 | else if ((0 > change)) | |
186 | 186 | then { | |
187 | 187 | let sendWavesAmount = (change * -1) | |
188 | 188 | deposit(sendWavesAmount) | |
189 | 189 | } | |
190 | 190 | else { | |
191 | 191 | let getWavesAmount = change | |
192 | 192 | withdraw(getWavesAmount) | |
193 | 193 | } | |
194 | 194 | } | |
195 | 195 | else throw("Strict value is not equal to itself.") | |
196 | 196 | } | |
197 | 197 | else throw("Strict value is not equal to itself.") | |
198 | 198 | } | |
199 | 199 | else throw("Strict value is not equal to itself.") | |
200 | 200 | } | |
201 | 201 | ||
202 | 202 | ||
203 | + | ||
204 | + | @Callable(i) | |
205 | + | func rebalanceRatio (targetRatio) = { | |
206 | + | let regularBalance = wavesBalance(this).regular | |
207 | + | if ((regularBalance == regularBalance)) | |
208 | + | then { | |
209 | + | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
210 | + | if ((additionalBalance == additionalBalance)) | |
211 | + | then { | |
212 | + | let wholeBlalance = (regularBalance + additionalBalance) | |
213 | + | let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100) | |
214 | + | let change = (additionalBalance - targetAdditionalBalance) | |
215 | + | let newReg = (regularBalance + change) | |
216 | + | if ((change == 0)) | |
217 | + | then nil | |
218 | + | else if ((0 > change)) | |
219 | + | then { | |
220 | + | let sendWavesAmount = (change * -1) | |
221 | + | deposit(sendWavesAmount) | |
222 | + | } | |
223 | + | else { | |
224 | + | let getWavesAmount = change | |
225 | + | withdraw(getWavesAmount) | |
226 | + | } | |
227 | + | } | |
228 | + | else throw("Strict value is not equal to itself.") | |
229 | + | } | |
230 | + | else throw("Strict value is not equal to itself.") | |
231 | + | } | |
232 | + | ||
233 | + |
github/deemru/w8io/026f985 31.07 ms ◑