tx · 95Qmh2UMcxgtRYrLNxj1Hhv9eJE4krhpttBxDFRi5SiR

3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h:  -0.05000000 Waves

2023.03.29 10:12 [2510917] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves

{ "type": 13, "id": "95Qmh2UMcxgtRYrLNxj1Hhv9eJE4krhpttBxDFRi5SiR", "fee": 5000000, "feeAssetId": null, "timestamp": 1680074003694, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "3XgS9TubgTJHZ3Zcyj8KHMDeEHyoobyc3A8wMN3NE361rBszHtrPVTRverHXdT1gsGr7ataWBsKyQDJXBng6NHK3" ], "script": "base64:BgIJCAISAwoBARIAEgAMY29udHJhY3RGaWxlAglyZWJhbGFuY2UAD2tleXNUYXJnZXRSYXRpbwIPJXNfX3RhcmdldFJhdGlvABRrZXlBZGRpdGlvbmFsQmFsYW5jZQIaJXNfX2FkZGl0aW9uYWxXYXZlc0JhbGFuY2UAGmtleVNXYXZlc0FkZGl0aW9uYWxCYWxhbmNlAhElc19fc1dhdmVzQmFsYW5jZQAQa2V5U1dhdmVzQXNzZXRJZAIRJXNfX3NXYXZlc0Fzc2V0SWQAD2tleVByb3h5QWRkcmVzcwIQJXNfX3Byb3h5QWRkcmVzcwANa2V5TWluQmFsYW5jZQITJXNfX21pbldhdmVzQmFsYW5jZQAGTVVMVDEyAICglKWNHQEQZ2V0SW50ZWdlck9yWmVybwEKaW50ZWdlcktleQQHJG1hdGNoMAkAmggCBQR0aGlzBQppbnRlZ2VyS2V5AwkAAQIFByRtYXRjaDACA0ludAQDdmFsBQckbWF0Y2gwBQN2YWwAAAEQZ2V0U3RyaW5nT3JUaHJvdwEJc3RyaW5nS2V5BAckbWF0Y2gwCQCdCAIFBHRoaXMFCX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YED3NlbmRXYXZlc0Ftb3VudAkBAS0BBQRkaWZmCQEHZGVwb3NpdAEFD3NlbmRXYXZlc0Ftb3VudAQOZ2V0V2F2ZXNBbW91bnQFBGRpZmYJAQh3aXRoZHJhdwEFDmdldFdhdmVzQW1vdW50CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAgFpAQ5yZWJhbGFuY2VSYXRpbwELdGFyZ2V0UmF0aW8JARFyZWJhbGFuY2VJbnRlcm5hbAEFC3RhcmdldFJhdGlvAWkBCXJlYmFsYW5jZQAJARFyZWJhbGFuY2VJbnRlcm5hbAEJAQ5nZXRUYXJnZXRSYXRpbwAA712fTQ==", "height": 2510917, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Hce4aPAvmT9eMwmJomxYJuuLHT6io955KnNVFzDv8tB Next: 9B5o6xrQxZesRAhzUguYrZiAsQDiEBE8rwd8j9ahfLaN Diff:
OldNewDifferences
3737 case ratio: Int =>
3838 min([100, max([0, ratio])])
3939 case _ =>
40- 80
40+ 0
4141 }
4242
4343
5757 case s: String =>
5858 parseIntValue(s)
5959 case _ =>
60- throw("ZERO rate")
60+ throw("Rate is zero (0)")
6161 }
6262 else throw("Strict value is not equal to itself.")
6363 }
6464
6565
66+func getProxyAddress () = addressFromStringValue(getStringOrThrow(keyProxyAddress))
67+
68+
69+func getSWavesId () = fromBase58String(getStringOrThrow(keySWavesAssetId))
70+
71+
6672 func deposit (wavesAmount) = {
67- let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
73+ let proxy = getProxyAddress()
6874 let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
6975 if ((currentAdditionalBalance == currentAdditionalBalance))
7076 then {
9298
9399
94100 func withdraw (wavesAmount) = {
95- let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
96- let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId))
97- if ((sWavesId == sWavesId))
101+ let proxy = getProxyAddress()
102+ let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
103+ if ((currentAdditionalBalance == currentAdditionalBalance))
98104 then {
99- let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
100- if ((currentAdditionalBalance == currentAdditionalBalance))
105+ let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
106+ if ((currentSWavesBalance == currentSWavesBalance))
101107 then {
102- let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
103- if ((currentSWavesBalance == currentSWavesBalance))
108+ let currentProxyRate = getRate()
109+ if ((currentProxyRate == currentProxyRate))
104110 then {
105- let currentProxyRate = getRate()
106- if ((currentProxyRate == currentProxyRate))
111+ let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate)
112+ if ((sendSWavesAmount > 0))
107113 then {
108- let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate)
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)
114+ let withdrawInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(getSWavesId(), sendSWavesAmount)])
115+ if ((withdrawInvoke == withdrawInvoke))
116+ then match withdrawInvoke {
117+ case receivedWaves: Int =>
118+ let newAdditionalBalance = (currentAdditionalBalance - receivedWaves)
119+ let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount)
117120 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
118- case _ =>
119- nil
120- }
121- else throw("Strict value is not equal to itself.")
122- }
123- else nil
121+ case _ =>
122+ nil
123+ }
124+ else throw("Strict value is not equal to itself.")
124125 }
125- else throw("Strict value is not equal to itself.")
126+ else nil
126127 }
127128 else throw("Strict value is not equal to itself.")
128129 }
132133 }
133134
134135
135-@Callable(i)
136-func rebalanceRatio (targetRatio) = {
136+func rebalanceInternal (targetRatio) = {
137137 let regularBalance = max([0, (wavesBalance(this).regular - getMinBalance())])
138138 if ((regularBalance == regularBalance))
139139 then {
142142 then {
143143 let wholeBalance = (regularBalance + additionalBalance)
144144 let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100)
145- let change = (additionalBalance - targetAdditionalBalance)
146- if ((change == 0))
145+ let diff = (additionalBalance - targetAdditionalBalance)
146+ if ((diff == 0))
147147 then nil
148- else if ((0 > change))
148+ else if ((0 > diff))
149149 then {
150- let sendWavesAmount = (change * -1)
150+ let sendWavesAmount = -(diff)
151151 deposit(sendWavesAmount)
152152 }
153153 else {
154- let getWavesAmount = change
154+ let getWavesAmount = diff
155155 withdraw(getWavesAmount)
156156 }
157157 }
161161 }
162162
163163
164+@Callable(i)
165+func rebalanceRatio (targetRatio) = rebalanceInternal(targetRatio)
166+
167+
168+
169+@Callable(i)
170+func rebalance () = rebalanceInternal(getTargetRatio())
171+
172+
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 _ =>
40- 80
40+ 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 _ =>
60- throw("ZERO rate")
60+ throw("Rate is zero (0)")
6161 }
6262 else throw("Strict value is not equal to itself.")
6363 }
6464
6565
66+func getProxyAddress () = addressFromStringValue(getStringOrThrow(keyProxyAddress))
67+
68+
69+func getSWavesId () = fromBase58String(getStringOrThrow(keySWavesAssetId))
70+
71+
6672 func deposit (wavesAmount) = {
67- let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
73+ let proxy = getProxyAddress()
6874 let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
6975 if ((currentAdditionalBalance == currentAdditionalBalance))
7076 then {
7177 let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
7278 if ((currentSWavesBalance == currentSWavesBalance))
7379 then if ((wavesAmount > 0))
7480 then {
7581 let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)])
7682 if ((depositInvoke == depositInvoke))
7783 then match depositInvoke {
7884 case receivedSWaves: Int =>
7985 let newAdditionalBalance = (currentAdditionalBalance + wavesAmount)
8086 let newSWavesBalance = (currentSWavesBalance + receivedSWaves)
8187 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
8288 case _ =>
8389 nil
8490 }
8591 else throw("Strict value is not equal to itself.")
8692 }
8793 else nil
8894 else throw("Strict value is not equal to itself.")
8995 }
9096 else throw("Strict value is not equal to itself.")
9197 }
9298
9399
94100 func withdraw (wavesAmount) = {
95- let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
96- let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId))
97- if ((sWavesId == sWavesId))
101+ let proxy = getProxyAddress()
102+ let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
103+ if ((currentAdditionalBalance == currentAdditionalBalance))
98104 then {
99- let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
100- if ((currentAdditionalBalance == currentAdditionalBalance))
105+ let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
106+ if ((currentSWavesBalance == currentSWavesBalance))
101107 then {
102- let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
103- if ((currentSWavesBalance == currentSWavesBalance))
108+ let currentProxyRate = getRate()
109+ if ((currentProxyRate == currentProxyRate))
104110 then {
105- let currentProxyRate = getRate()
106- if ((currentProxyRate == currentProxyRate))
111+ let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate)
112+ if ((sendSWavesAmount > 0))
107113 then {
108- let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate)
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)
114+ let withdrawInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(getSWavesId(), sendSWavesAmount)])
115+ if ((withdrawInvoke == withdrawInvoke))
116+ then match withdrawInvoke {
117+ case receivedWaves: Int =>
118+ let newAdditionalBalance = (currentAdditionalBalance - receivedWaves)
119+ let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount)
117120 [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
118- case _ =>
119- nil
120- }
121- else throw("Strict value is not equal to itself.")
122- }
123- else nil
121+ case _ =>
122+ nil
123+ }
124+ else throw("Strict value is not equal to itself.")
124125 }
125- else throw("Strict value is not equal to itself.")
126+ else nil
126127 }
127128 else throw("Strict value is not equal to itself.")
128129 }
129130 else throw("Strict value is not equal to itself.")
130131 }
131132 else throw("Strict value is not equal to itself.")
132133 }
133134
134135
135-@Callable(i)
136-func rebalanceRatio (targetRatio) = {
136+func rebalanceInternal (targetRatio) = {
137137 let regularBalance = max([0, (wavesBalance(this).regular - getMinBalance())])
138138 if ((regularBalance == regularBalance))
139139 then {
140140 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
141141 if ((additionalBalance == additionalBalance))
142142 then {
143143 let wholeBalance = (regularBalance + additionalBalance)
144144 let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100)
145- let change = (additionalBalance - targetAdditionalBalance)
146- if ((change == 0))
145+ let diff = (additionalBalance - targetAdditionalBalance)
146+ if ((diff == 0))
147147 then nil
148- else if ((0 > change))
148+ else if ((0 > diff))
149149 then {
150- let sendWavesAmount = (change * -1)
150+ let sendWavesAmount = -(diff)
151151 deposit(sendWavesAmount)
152152 }
153153 else {
154- let getWavesAmount = change
154+ 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
164+@Callable(i)
165+func rebalanceRatio (targetRatio) = rebalanceInternal(targetRatio)
166+
167+
168+
169+@Callable(i)
170+func rebalance () = rebalanceInternal(getTargetRatio())
171+
172+

github/deemru/w8io/169f3d6 
55.39 ms