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:BgIWCAISABIAEgASBQoDAQEBEgASAwoBAQ4ADGNvbnRyYWN0RmlsZQIJcmViYWxhbmNlAA9rZXlzVGFyZ2V0UmF0aW8CDyVzX190YXJnZXRSYXRpbwAUa2V5QWRkaXRpb25hbEJhbGFuY2UCGiVzX19hZGRpdGlvbmFsV2F2ZXNCYWxhbmNlABprZXlTV2F2ZXNBZGRpdGlvbmFsQmFsYW5jZQIRJXNfX3NXYXZlc0JhbGFuY2UAEGtleVNXYXZlc0Fzc2V0SWQCESVzX19zV2F2ZXNBc3NldElkAA9rZXlQcm94eUFkZHJlc3MCECVzX19wcm94eUFkZHJlc3MBEGdldEludGVnZXJPclplcm8BCmludGVnZXJLZXkEByRtYXRjaDAJAJoIAgUEdGhpcwUKaW50ZWdlcktleQMJAAECBQckbWF0Y2gwAgNJbnQEA3ZhbAUHJG1hdGNoMAUDdmFsAAABEGdldFN0cmluZ09yVGhyb3cBCXN0cmluZ0tleQQHJG1hdGNoMAkAnQgCBQR0aGlzBQlzdHJpbmdLZXkDCQABAgUHJG1hdGNoMAIGU3RyaW5nBAFzBQckbWF0Y2gwBQFz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lBRd0YXJnZXRBZGRpdGlvbmFsQmFsYW5jZQQGbmV3UmVnCQBkAgUOcmVndWxhckJhbGFuY2UFBmNoYW5nZQMJAAACBQZjaGFuZ2UAAAUDbmlsAwkAZgIAAAUGY2hhbmdlBA9zZW5kV2F2ZXNBbW91bnQJAGgCBQZjaGFuZ2UA////////////AQkBB2RlcG9zaXQBBQ9zZW5kV2F2ZXNBbW91bnQEDmdldFdhdmVzQW1vdW50BQZjaGFuZ2UJAQh3aXRoZHJhdwEFDmdldFdhdmVzQW1vdW50CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAO96CGs=", "height": 2509487, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: AKW2SvCMFrc61Cfc2dUDqBrsNf3Jth3zn731ULCJrXSt Next: 8vn7jQm3xrr5emPUkFcVhBFSghRNd1VwaTFoh145uxMB Diff:
OldNewDifferences
200200 }
201201
202202
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+
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let contractFile = "rebalance"
55
66 let keysTargetRatio = "%s__targetRatio"
77
88 let keyAdditionalBalance = "%s__additionalWavesBalance"
99
1010 let keySWavesAdditionalBalance = "%s__sWavesBalance"
1111
1212 let keySWavesAssetId = "%s__sWavesAssetId"
1313
1414 let keyProxyAddress = "%s__proxyAddress"
1515
1616 func getIntegerOrZero (integerKey) = match getInteger(this, integerKey) {
1717 case val: Int =>
1818 val
1919 case _ =>
2020 0
2121 }
2222
2323
2424 func getStringOrThrow (stringKey) = match getString(this, stringKey) {
2525 case s: String =>
2626 s
2727 case _ =>
2828 throw((("[" + stringKey) + "] is empty"))
2929 }
3030
3131
3232 func getTargetRatio () = match getInteger(keysTargetRatio) {
3333 case s: Int =>
3434 s
3535 case _ =>
3636 80
3737 }
3838
3939
4040 func internalWavesBalance () = (wavesBalance(this).regular + getIntegerOrZero(keyAdditionalBalance))
4141
4242
4343 func internalRate () = {
4444 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
4545 let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
4646 if ((additionalBalance == 0))
4747 then 0
4848 else fraction(100000000000, additionalBalance, sWavesBalance)
4949 }
5050
5151
5252 func getRate () = {
5353 let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
5454 let inv = invoke(proxy, "getRate", nil, nil)
5555 if ((inv == inv))
5656 then match inv {
5757 case s: String =>
5858 parseIntValue(s)
5959 case _ =>
6060 throw("ZERO rate")
6161 }
6262 else throw("Strict value is not equal to itself.")
6363 }
6464
6565
6666 func deposit (wavesAmount) = {
6767 let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
6868 let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
6969 if ((currentAdditionalBalance == currentAdditionalBalance))
7070 then {
7171 let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
7272 if ((currentSWavesBalance == currentSWavesBalance))
7373 then {
7474 let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)])
7575 if ((depositInvoke == depositInvoke))
7676 then match depositInvoke {
7777 case receivedSWaves: Int =>
7878 let newAdditionalBalance = (currentAdditionalBalance + wavesAmount)
7979 let newSWavesBalance = (currentSWavesBalance + receivedSWaves)
8080 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
8181 case _ =>
8282 nil
8383 }
8484 else throw("Strict value is not equal to itself.")
8585 }
8686 else throw("Strict value is not equal to itself.")
8787 }
8888 else throw("Strict value is not equal to itself.")
8989 }
9090
9191
9292 func withdraw (wavesAmount) = {
9393 let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
9494 let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId))
9595 if ((sWavesId == sWavesId))
9696 then {
9797 let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
9898 if ((currentAdditionalBalance == currentAdditionalBalance))
9999 then {
100100 let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
101101 if ((currentSWavesBalance == currentSWavesBalance))
102102 then {
103103 let currentProxyRate = getRate()
104104 if ((currentProxyRate == currentProxyRate))
105105 then {
106106 let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate)
107107 let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)])
108108 if ((depositInvoke == depositInvoke))
109109 then match depositInvoke {
110110 case receivedWaves: Int =>
111111 let newAdditionalBalance = (currentAdditionalBalance - receivedWaves)
112112 let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount)
113113 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
114114 case _ =>
115115 nil
116116 }
117117 else throw("Strict value is not equal to itself.")
118118 }
119119 else throw("Strict value is not equal to itself.")
120120 }
121121 else throw("Strict value is not equal to itself.")
122122 }
123123 else throw("Strict value is not equal to itself.")
124124 }
125125 else throw("Strict value is not equal to itself.")
126126 }
127127
128128
129129 @Callable(i)
130130 func returnWavesBalance () = $Tuple2(nil, internalWavesBalance())
131131
132132
133133
134134 @Callable(i)
135135 func returnSWavesBalance () = $Tuple2(nil, getIntegerOrZero(keySWavesAdditionalBalance))
136136
137137
138138
139139 @Callable(i)
140140 func calcRatio () = {
141141 let regularWavesBalance = wavesBalance(this).regular
142142 let additional = getIntegerOrZero(keyAdditionalBalance)
143143 let ratio = fraction(100, additional, (additional + regularWavesBalance))
144144 $Tuple2(nil, ratio)
145145 }
146146
147147
148148
149149 @Callable(i)
150150 func calcRatioTest (regularBalance,additional,targetRatio) = {
151151 let sum = (regularBalance + additional)
152152 let targetAdditionalBalance = fraction(targetRatio, sum, 100)
153153 let change = (additional - targetAdditionalBalance)
154154 let newReg = (regularBalance + change)
155155 if ((0 > change))
156156 then {
157157 let sendAmount = (change * -1)
158158 $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("deposit: " + toString(sendAmount))])
159159 }
160160 else {
161161 let sendAmount = change
162162 $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("withdraw: " + toString(sendAmount))])
163163 }
164164 }
165165
166166
167167
168168 @Callable(i)
169169 func rebalance () = {
170170 let regularBalance = wavesBalance(this).regular
171171 if ((regularBalance == regularBalance))
172172 then {
173173 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
174174 if ((additionalBalance == additionalBalance))
175175 then {
176176 let targetRatio = getTargetRatio()
177177 if ((targetRatio == targetRatio))
178178 then {
179179 let wholeBlalance = (regularBalance + additionalBalance)
180180 let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100)
181181 let change = (additionalBalance - targetAdditionalBalance)
182182 let newReg = (regularBalance + change)
183183 if ((change == 0))
184184 then nil
185185 else if ((0 > change))
186186 then {
187187 let sendWavesAmount = (change * -1)
188188 deposit(sendWavesAmount)
189189 }
190190 else {
191191 let getWavesAmount = change
192192 withdraw(getWavesAmount)
193193 }
194194 }
195195 else throw("Strict value is not equal to itself.")
196196 }
197197 else throw("Strict value is not equal to itself.")
198198 }
199199 else throw("Strict value is not equal to itself.")
200200 }
201201
202202
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