tx · 9B5o6xrQxZesRAhzUguYrZiAsQDiEBE8rwd8j9ahfLaN

3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h:  -0.05000000 Waves

2023.03.29 13:43 [2511119] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves

{ "type": 13, "id": "9B5o6xrQxZesRAhzUguYrZiAsQDiEBE8rwd8j9ahfLaN", "fee": 5000000, "feeAssetId": null, "timestamp": 1680086699856, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "pR666GCz44wuAbysBvzcw89QhYQTtHDEVa6osSfxdMFrec45oDwNqCxTjCsTVmeMMNKCeqWmawCKoGdbHs3DAXr" ], "script": "base64:BgIJCAISAwoBARIAEgAMY29udHJhY3RGaWxlAglyZWJhbGFuY2UAD2tleXNUYXJnZXRSYXRpbwIPJXNfX3RhcmdldFJhdGlvABRrZXlBZGRpdGlvbmFsQmFsYW5jZQIaJXNfX2FkZGl0aW9uYWxXYXZlc0JhbGFuY2UAGmtleVNXYXZlc0FkZGl0aW9uYWxCYWxhbmNlAhElc19fc1dhdmVzQmFsYW5jZQAQa2V5U1dhdmVzQXNzZXRJZAIRJXNfX3NXYXZlc0Fzc2V0SWQAD2tleVByb3h5QWRkcmVzcwIQJXNfX3Byb3h5QWRkcmVzcwANa2V5TWluQmFsYW5jZQITJXNfX21pbldhdmVzQmFsYW5jZQAGTVVMVDEyAICglKWNHQEQZ2V0SW50ZWdlck9yWmVybwEKaW50ZWdlcktleQQHJG1hdGNoMAkAmggCBQR0aGlzBQppbnRlZ2VyS2V5AwkAAQIFByRtYXRjaDACA0ludAQDdmFsBQckbWF0Y2gwBQN2YWwAAAEQZ2V0U3RyaW5nT3JUaHJvdwEJc3RyaW5nS2V5BAckbWF0Y2gwCQCdCAIFBHRoaXMFCXN0cmlu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ZmYED3NlbmRXYXZlc0Ftb3VudAkBAS0BBQRkaWZmCQEHZGVwb3NpdAEFD3NlbmRXYXZlc0Ftb3VudAQOZ2V0V2F2ZXNBbW91bnQFBGRpZmYJAQh3aXRoZHJhdwEFDmdldFdhdmVzQW1vdW50CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAgFpAQ5yZWJhbGFuY2VSYXRpbwELdGFyZ2V0UmF0aW8JARFyZWJhbGFuY2VJbnRlcm5hbAEFC3RhcmdldFJhdGlvAWkBCXJlYmFsYW5jZQAJARFyZWJhbGFuY2VJbnRlcm5hbAEJAQ5nZXRUYXJnZXRSYXRpbwAAu2iIKw==", "height": 2511119, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 95Qmh2UMcxgtRYrLNxj1Hhv9eJE4krhpttBxDFRi5SiR Next: GuWtKs3nYMdz2tUqzSF3Xmi9nZzLLUmXVtpq8jcdRpEn Diff:
OldNewDifferences
134134
135135
136136 func rebalanceInternal (targetRatio) = {
137- let regularBalance = max([0, (wavesBalance(this).regular - getMinBalance())])
137+ let regularBalance = wavesBalance(this).regular
138138 if ((regularBalance == regularBalance))
139139 then {
140140 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
141141 if ((additionalBalance == additionalBalance))
142142 then {
143- let wholeBalance = (regularBalance + additionalBalance)
143+ let wholeBalance = max([0, ((regularBalance + additionalBalance) - getMinBalance())])
144144 let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100)
145145 let diff = (additionalBalance - targetAdditionalBalance)
146146 if ((diff == 0))
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 let keyMinBalance = "%s__minWavesBalance"
1717
1818 let MULT12 = 1000000000000
1919
2020 func getIntegerOrZero (integerKey) = match getInteger(this, integerKey) {
2121 case val: Int =>
2222 val
2323 case _ =>
2424 0
2525 }
2626
2727
2828 func getStringOrThrow (stringKey) = match getString(this, stringKey) {
2929 case s: String =>
3030 s
3131 case _ =>
3232 throw((("[" + stringKey) + "] is empty"))
3333 }
3434
3535
3636 func getTargetRatio () = match getInteger(keysTargetRatio) {
3737 case ratio: Int =>
3838 min([100, max([0, ratio])])
3939 case _ =>
4040 0
4141 }
4242
4343
4444 func getMinBalance () = match getInteger(keyMinBalance) {
4545 case i: Int =>
4646 max([0, i])
4747 case _ =>
4848 0
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("Rate is zero (0)")
6161 }
6262 else throw("Strict value is not equal to itself.")
6363 }
6464
6565
6666 func getProxyAddress () = addressFromStringValue(getStringOrThrow(keyProxyAddress))
6767
6868
6969 func getSWavesId () = fromBase58String(getStringOrThrow(keySWavesAssetId))
7070
7171
7272 func deposit (wavesAmount) = {
7373 let proxy = getProxyAddress()
7474 let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
7575 if ((currentAdditionalBalance == currentAdditionalBalance))
7676 then {
7777 let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
7878 if ((currentSWavesBalance == currentSWavesBalance))
7979 then if ((wavesAmount > 0))
8080 then {
8181 let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)])
8282 if ((depositInvoke == depositInvoke))
8383 then match depositInvoke {
8484 case receivedSWaves: Int =>
8585 let newAdditionalBalance = (currentAdditionalBalance + wavesAmount)
8686 let newSWavesBalance = (currentSWavesBalance + receivedSWaves)
8787 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
8888 case _ =>
8989 nil
9090 }
9191 else throw("Strict value is not equal to itself.")
9292 }
9393 else nil
9494 else throw("Strict value is not equal to itself.")
9595 }
9696 else throw("Strict value is not equal to itself.")
9797 }
9898
9999
100100 func withdraw (wavesAmount) = {
101101 let proxy = getProxyAddress()
102102 let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
103103 if ((currentAdditionalBalance == currentAdditionalBalance))
104104 then {
105105 let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
106106 if ((currentSWavesBalance == currentSWavesBalance))
107107 then {
108108 let currentProxyRate = getRate()
109109 if ((currentProxyRate == currentProxyRate))
110110 then {
111111 let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate)
112112 if ((sendSWavesAmount > 0))
113113 then {
114114 let withdrawInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(getSWavesId(), sendSWavesAmount)])
115115 if ((withdrawInvoke == withdrawInvoke))
116116 then match withdrawInvoke {
117117 case receivedWaves: Int =>
118118 let newAdditionalBalance = (currentAdditionalBalance - receivedWaves)
119119 let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount)
120120 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
121121 case _ =>
122122 nil
123123 }
124124 else throw("Strict value is not equal to itself.")
125125 }
126126 else nil
127127 }
128128 else throw("Strict value is not equal to itself.")
129129 }
130130 else throw("Strict value is not equal to itself.")
131131 }
132132 else throw("Strict value is not equal to itself.")
133133 }
134134
135135
136136 func rebalanceInternal (targetRatio) = {
137- let regularBalance = max([0, (wavesBalance(this).regular - getMinBalance())])
137+ let regularBalance = wavesBalance(this).regular
138138 if ((regularBalance == regularBalance))
139139 then {
140140 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
141141 if ((additionalBalance == additionalBalance))
142142 then {
143- let wholeBalance = (regularBalance + additionalBalance)
143+ let wholeBalance = max([0, ((regularBalance + additionalBalance) - getMinBalance())])
144144 let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100)
145145 let diff = (additionalBalance - targetAdditionalBalance)
146146 if ((diff == 0))
147147 then nil
148148 else if ((0 > diff))
149149 then {
150150 let sendWavesAmount = -(diff)
151151 deposit(sendWavesAmount)
152152 }
153153 else {
154154 let getWavesAmount = diff
155155 withdraw(getWavesAmount)
156156 }
157157 }
158158 else throw("Strict value is not equal to itself.")
159159 }
160160 else throw("Strict value is not equal to itself.")
161161 }
162162
163163
164164 @Callable(i)
165165 func rebalanceRatio (targetRatio) = rebalanceInternal(targetRatio)
166166
167167
168168
169169 @Callable(i)
170170 func rebalance () = rebalanceInternal(getTargetRatio())
171171
172172

github/deemru/w8io/026f985 
45.65 ms