tx · 36UVQqSDA8X6FYQvznVGRyYbXPYZyp6AecqTJBzfp4u1

3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h:  -0.05000000 Waves

2023.03.29 09:15 [2510858] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves

{ "type": 13, "id": "36UVQqSDA8X6FYQvznVGRyYbXPYZyp6AecqTJBzfp4u1", "fee": 5000000, "feeAssetId": null, "timestamp": 1680070525118, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "5LpbuApt2WEanGtiP6MBA84ww6qHHrgi3Qj9bLqCFTQTuw35PmUfGcdpvyVPfEquwwAfcuYaxG8ZxA5soV4KveJj" ], "script": "base64:BgIHCAISAwoBAQ8ADGNvbnRyYWN0RmlsZQIJcmViYWxhbmNlAA9rZXlzVGFyZ2V0UmF0aW8CDyVzX190YXJnZXRSYXRpbwAUa2V5QWRkaXRpb25hbEJhbGFuY2UCGiVzX19hZGRpdGlvbmFsV2F2ZXNCYWxhbmNlABprZXlTV2F2ZXNBZGRpdGlvbmFsQmFsYW5jZQIRJXNfX3NXYXZlc0JhbGFuY2UAEGtleVNXYXZlc0Fzc2V0SWQCESVzX19zV2F2ZXNBc3NldElkAA9rZXlQcm94eUFkZHJlc3MCECVzX19wcm94eUFkZHJlc3MADWtleU1pbkJhbGFuY2UCEyVzX21pbldhdmVzQmFsYWxuY2UABk1VTFQxMgCAoJSljR0BEGdldEludGVnZXJPclplcm8BCmludGVnZXJLZXkEByRtYXRjaDAJAJoIAgUEdGhpcwUKaW50ZWdlcktleQMJAAECBQckbWF0Y2gwAgNJbnQEA3ZhbAUHJG1hdGNoMAUDdmFsAAABEGdldFN0cmluZ09yVGhyb3cBCXN0cmluZ0tleQQHJG1hdGNoMAkAnQgCBQR0aGlzBQlzdHJpbmdLZX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2V0QWRkaXRpb25hbEJhbGFuY2UDCQAAAgUGY2hhbmdlAAAFA25pbAMJAGYCAAAFBmNoYW5nZQQPc2VuZFdhdmVzQW1vdW50CQBoAgUGY2hhbmdlAP///////////wEJAQdkZXBvc2l0AQUPc2VuZFdhdmVzQW1vdW50BA5nZXRXYXZlc0Ftb3VudAUGY2hhbmdlCQEId2l0aGRyYXcBBQ5nZXRXYXZlc0Ftb3VudAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgBCZMAZ", "height": 2510858, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: A2saRMNi6Am5rvtqqKKFHBnS3rYLnNEtJS9CaAVKVhb2 Next: 9MZwQVHAHh1AvA8EFBRP3uYh6ZCx1UhD9yB7xCVDye2U Diff:
OldNewDifferences
1212 let keySWavesAssetId = "%s__sWavesAssetId"
1313
1414 let keyProxyAddress = "%s__proxyAddress"
15+
16+let keyMinBalance = "%s_minWavesBalalnce"
17+
18+let MULT12 = 1000000000000
1519
1620 func getIntegerOrZero (integerKey) = match getInteger(this, integerKey) {
1721 case val: Int =>
3034
3135
3236 func getTargetRatio () = match getInteger(keysTargetRatio) {
33- case s: Int =>
34- min([100, max([0, s])])
37+ case ratio: Int =>
38+ min([100, max([0, ratio])])
3539 case _ =>
3640 80
41+}
42+
43+
44+func getMinBalance () = match getInteger(keyMinBalance) {
45+ case i: Int =>
46+ max([0, i])
47+ case _ =>
48+ 0
3749 }
3850
3951
93105 let currentProxyRate = getRate()
94106 if ((currentProxyRate == currentProxyRate))
95107 then {
96- let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate)
108+ let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate)
97109 if ((sendSWavesAmount > 0))
98110 then {
99111 let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)])
122134
123135 @Callable(i)
124136 func rebalanceRatio (targetRatio) = {
125- let regularBalance = wavesBalance(this).regular
137+ let regularBalance = max([0, (wavesBalance(this).regular - getMinBalance())])
126138 if ((regularBalance == regularBalance))
127139 then {
128140 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
131143 let wholeBalance = (regularBalance + additionalBalance)
132144 let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100)
133145 let change = (additionalBalance - targetAdditionalBalance)
134- let newReg = (regularBalance + change)
135146 if ((change == 0))
136147 then nil
137148 else if ((0 > change))
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"
15+
16+let keyMinBalance = "%s_minWavesBalalnce"
17+
18+let MULT12 = 1000000000000
1519
1620 func getIntegerOrZero (integerKey) = match getInteger(this, integerKey) {
1721 case val: Int =>
1822 val
1923 case _ =>
2024 0
2125 }
2226
2327
2428 func getStringOrThrow (stringKey) = match getString(this, stringKey) {
2529 case s: String =>
2630 s
2731 case _ =>
2832 throw((("[" + stringKey) + "] is empty"))
2933 }
3034
3135
3236 func getTargetRatio () = match getInteger(keysTargetRatio) {
33- case s: Int =>
34- min([100, max([0, s])])
37+ case ratio: Int =>
38+ min([100, max([0, ratio])])
3539 case _ =>
3640 80
41+}
42+
43+
44+func getMinBalance () = match getInteger(keyMinBalance) {
45+ case i: Int =>
46+ max([0, i])
47+ case _ =>
48+ 0
3749 }
3850
3951
4052 func getRate () = {
4153 let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
4254 let inv = invoke(proxy, "getRate", nil, nil)
4355 if ((inv == inv))
4456 then match inv {
4557 case s: String =>
4658 parseIntValue(s)
4759 case _ =>
4860 throw("ZERO rate")
4961 }
5062 else throw("Strict value is not equal to itself.")
5163 }
5264
5365
5466 func deposit (wavesAmount) = {
5567 let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
5668 let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
5769 if ((currentAdditionalBalance == currentAdditionalBalance))
5870 then {
5971 let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
6072 if ((currentSWavesBalance == currentSWavesBalance))
6173 then if ((wavesAmount > 0))
6274 then {
6375 let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)])
6476 if ((depositInvoke == depositInvoke))
6577 then match depositInvoke {
6678 case receivedSWaves: Int =>
6779 let newAdditionalBalance = (currentAdditionalBalance + wavesAmount)
6880 let newSWavesBalance = (currentSWavesBalance + receivedSWaves)
6981 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
7082 case _ =>
7183 nil
7284 }
7385 else throw("Strict value is not equal to itself.")
7486 }
7587 else nil
7688 else throw("Strict value is not equal to itself.")
7789 }
7890 else throw("Strict value is not equal to itself.")
7991 }
8092
8193
8294 func withdraw (wavesAmount) = {
8395 let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
8496 let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId))
8597 if ((sWavesId == sWavesId))
8698 then {
8799 let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
88100 if ((currentAdditionalBalance == currentAdditionalBalance))
89101 then {
90102 let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
91103 if ((currentSWavesBalance == currentSWavesBalance))
92104 then {
93105 let currentProxyRate = getRate()
94106 if ((currentProxyRate == currentProxyRate))
95107 then {
96- let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate)
108+ let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate)
97109 if ((sendSWavesAmount > 0))
98110 then {
99111 let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)])
100112 if ((depositInvoke == depositInvoke))
101113 then match depositInvoke {
102114 case receivedWaves: Int =>
103115 let newAdditionalBalance = (currentAdditionalBalance - receivedWaves)
104116 let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount)
105117 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
106118 case _ =>
107119 nil
108120 }
109121 else throw("Strict value is not equal to itself.")
110122 }
111123 else nil
112124 }
113125 else throw("Strict value is not equal to itself.")
114126 }
115127 else throw("Strict value is not equal to itself.")
116128 }
117129 else throw("Strict value is not equal to itself.")
118130 }
119131 else throw("Strict value is not equal to itself.")
120132 }
121133
122134
123135 @Callable(i)
124136 func rebalanceRatio (targetRatio) = {
125- let regularBalance = wavesBalance(this).regular
137+ let regularBalance = max([0, (wavesBalance(this).regular - getMinBalance())])
126138 if ((regularBalance == regularBalance))
127139 then {
128140 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
129141 if ((additionalBalance == additionalBalance))
130142 then {
131143 let wholeBalance = (regularBalance + additionalBalance)
132144 let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100)
133145 let change = (additionalBalance - targetAdditionalBalance)
134- let newReg = (regularBalance + change)
135146 if ((change == 0))
136147 then nil
137148 else if ((0 > change))
138149 then {
139150 let sendWavesAmount = (change * -1)
140151 deposit(sendWavesAmount)
141152 }
142153 else {
143154 let getWavesAmount = change
144155 withdraw(getWavesAmount)
145156 }
146157 }
147158 else throw("Strict value is not equal to itself.")
148159 }
149160 else throw("Strict value is not equal to itself.")
150161 }
151162
152163

github/deemru/w8io/026f985 
41.38 ms