tx · FQR71EwWYET2D37rV9cyPQy9c57AsVrLSPBFetrAPMsk

3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h:  -0.05000000 Waves

2023.03.28 09:53 [2509468] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves

{ "type": 13, "id": "FQR71EwWYET2D37rV9cyPQy9c57AsVrLSPBFetrAPMsk", "fee": 5000000, "feeAssetId": null, "timestamp": 1679986407647, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "4Hf2zM5FTDj64zR1dnYNtjKb11pjMh6yt1uDxvu673rLvPzK6wJiwKhM2493Nhjf9vnUkgYUoL1kQ9txttwgrnPY" ], "script": "base64:BgIRCAISABIAEgASBQoDAQEBEgAOAAxjb250cmFjdEZpbGUCCXJlYmFsYW5jZQAPa2V5c1RhcmdldFJhdGlvAg8lc19fdGFyZ2V0UmF0aW8AFGtleUFkZGl0aW9uYWxCYWxhbmNlAholc19fYWRkaXRpb25hbFdhdmVzQmFsYW5jZQAaa2V5U1dhdmVzQWRkaXRpb25hbEJhbGFuY2UCESVzX19zV2F2ZXNCYWxhbmNlABBrZXlTV2F2ZXNBc3NldElkAhElc19fc1dhdmVzQXNzZXRJZAAPa2V5UHJveHlBZGRyZXNzAhAlc19fcHJveHlBZGRyZXNzARBnZXRJbnRlZ2VyT3JaZXJvAQppbnRlZ2VyS2V5BAckbWF0Y2gwCQCaCAIFBHRoaXMFCmludGVnZXJLZXkDCQABAgUHJG1hdGNoMAIDSW50BAN2YWwFByRtYXRjaDAFA3ZhbAAAARBnZXRTdHJpbmdPclRocm93AQlzdHJpbmdLZXkEByRtYXRjaDAJAJ0IAgUEdGhpcwUJc3RyaW5nS2V5AwkAAQIFByRtYXRjaDACBlN0cmluZwQBcwUHJG1hdGNoMAUBcwkAAgEJAKw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FsQmFsYW5jZQkAawMFC3RhcmdldFJhdGlvBQ13aG9sZUJsYWxhbmNlAGQEBmNoYW5nZQkAZQIFEWFkZGl0aW9uYWxCYWxhbmNlBRd0YXJnZXRBZGRpdGlvbmFsQmFsYW5jZQQGbmV3UmVnCQBkAgUOcmVndWxhckJhbGFuY2UFBmNoYW5nZQMJAGYCAAAFBmNoYW5nZQQPc2VuZFdhdmVzQW1vdW50CQBoAgUGY2hhbmdlAP///////////wEJAQdkZXBvc2l0AQUPc2VuZFdhdmVzQW1vdW50BA5nZXRXYXZlc0Ftb3VudAUGY2hhbmdlCQEId2l0aGRyYXcBBQ5nZXRXYXZlc0Ftb3VudAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgAxfZFj", "height": 2509468, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BN14Vfd9aoDBtQospVDznCoZboQsFZ5bmmSTPvtknHZD Next: ZYfmLsTeAxZk97CX7PPMQG7g1478dGJrXATh9cfAWYD Diff:
OldNewDifferences
2929 }
3030
3131
32+func getTargetRatio () = match getInteger(keysTargetRatio) {
33+ case s: Int =>
34+ s
35+ case _ =>
36+ 80
37+}
38+
39+
3240 func internalWavesBalance () = (wavesBalance(this).regular + getIntegerOrZero(keyAdditionalBalance))
3341
3442
35-func currentRate () = {
43+func internalRate () = {
3644 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
3745 let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
3846 if ((additionalBalance == 0))
4957 case s: String =>
5058 parseIntValue(s)
5159 case _ =>
52- 0
60+ throw("ZERO rate")
5361 }
62+ else throw("Strict value is not equal to itself.")
63+ }
64+
65+
66+func deposit (wavesAmount) = {
67+ let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
68+ let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
69+ if ((currentAdditionalBalance == currentAdditionalBalance))
70+ then {
71+ let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
72+ if ((currentSWavesBalance == currentSWavesBalance))
73+ then {
74+ let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)])
75+ if ((depositInvoke == depositInvoke))
76+ then match depositInvoke {
77+ case receivedSWaves: Int =>
78+ let newAdditionalBalance = (currentAdditionalBalance - wavesAmount)
79+ let newSWavesBalance = (currentSWavesBalance + receivedSWaves)
80+[IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
81+ case _ =>
82+ nil
83+ }
84+ else throw("Strict value is not equal to itself.")
85+ }
86+ else throw("Strict value is not equal to itself.")
87+ }
88+ else throw("Strict value is not equal to itself.")
89+ }
90+
91+
92+func withdraw (wavesAmount) = {
93+ let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
94+ let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId))
95+ if ((sWavesId == sWavesId))
96+ then {
97+ let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
98+ if ((currentAdditionalBalance == currentAdditionalBalance))
99+ then {
100+ let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
101+ if ((currentSWavesBalance == currentSWavesBalance))
102+ then {
103+ let currentProxyRate = getRate()
104+ if ((currentProxyRate == currentProxyRate))
105+ then {
106+ let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate)
107+ let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)])
108+ if ((depositInvoke == depositInvoke))
109+ then match depositInvoke {
110+ case receivedWaves: Int =>
111+ let newAdditionalBalance = (currentAdditionalBalance + receivedWaves)
112+ let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount)
113+[IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
114+ case _ =>
115+ nil
116+ }
117+ else throw("Strict value is not equal to itself.")
118+ }
119+ else throw("Strict value is not equal to itself.")
120+ }
121+ else throw("Strict value is not equal to itself.")
122+ }
123+ else throw("Strict value is not equal to itself.")
124+ }
54125 else throw("Strict value is not equal to itself.")
55126 }
56127
93164 }
94165
95166
167+
168+@Callable(i)
169+func rebalance () = {
170+ let regularBalance = wavesBalance(this).regular
171+ if ((regularBalance == regularBalance))
172+ then {
173+ let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
174+ if ((additionalBalance == additionalBalance))
175+ then {
176+ let targetRatio = getTargetRatio()
177+ if ((targetRatio == targetRatio))
178+ then {
179+ let wholeBlalance = (regularBalance + additionalBalance)
180+ let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100)
181+ let change = (additionalBalance - targetAdditionalBalance)
182+ let newReg = (regularBalance + change)
183+ if ((0 > change))
184+ then {
185+ let sendWavesAmount = (change * -1)
186+ deposit(sendWavesAmount)
187+ }
188+ else {
189+ let getWavesAmount = change
190+ withdraw(getWavesAmount)
191+ }
192+ }
193+ else throw("Strict value is not equal to itself.")
194+ }
195+ else throw("Strict value is not equal to itself.")
196+ }
197+ else throw("Strict value is not equal to itself.")
198+ }
199+
200+
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
32+func getTargetRatio () = match getInteger(keysTargetRatio) {
33+ case s: Int =>
34+ s
35+ case _ =>
36+ 80
37+}
38+
39+
3240 func internalWavesBalance () = (wavesBalance(this).regular + getIntegerOrZero(keyAdditionalBalance))
3341
3442
35-func currentRate () = {
43+func internalRate () = {
3644 let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
3745 let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
3846 if ((additionalBalance == 0))
3947 then 0
4048 else fraction(100000000000, additionalBalance, sWavesBalance)
4149 }
4250
4351
4452 func getRate () = {
4553 let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
4654 let inv = invoke(proxy, "getRate", nil, nil)
4755 if ((inv == inv))
4856 then match inv {
4957 case s: String =>
5058 parseIntValue(s)
5159 case _ =>
52- 0
60+ throw("ZERO rate")
5361 }
62+ else throw("Strict value is not equal to itself.")
63+ }
64+
65+
66+func deposit (wavesAmount) = {
67+ let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
68+ let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
69+ if ((currentAdditionalBalance == currentAdditionalBalance))
70+ then {
71+ let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
72+ if ((currentSWavesBalance == currentSWavesBalance))
73+ then {
74+ let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)])
75+ if ((depositInvoke == depositInvoke))
76+ then match depositInvoke {
77+ case receivedSWaves: Int =>
78+ let newAdditionalBalance = (currentAdditionalBalance - wavesAmount)
79+ let newSWavesBalance = (currentSWavesBalance + receivedSWaves)
80+[IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
81+ case _ =>
82+ nil
83+ }
84+ else throw("Strict value is not equal to itself.")
85+ }
86+ else throw("Strict value is not equal to itself.")
87+ }
88+ else throw("Strict value is not equal to itself.")
89+ }
90+
91+
92+func withdraw (wavesAmount) = {
93+ let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress))
94+ let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId))
95+ if ((sWavesId == sWavesId))
96+ then {
97+ let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance)
98+ if ((currentAdditionalBalance == currentAdditionalBalance))
99+ then {
100+ let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance)
101+ if ((currentSWavesBalance == currentSWavesBalance))
102+ then {
103+ let currentProxyRate = getRate()
104+ if ((currentProxyRate == currentProxyRate))
105+ then {
106+ let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate)
107+ let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)])
108+ if ((depositInvoke == depositInvoke))
109+ then match depositInvoke {
110+ case receivedWaves: Int =>
111+ let newAdditionalBalance = (currentAdditionalBalance + receivedWaves)
112+ let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount)
113+[IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)]
114+ case _ =>
115+ nil
116+ }
117+ else throw("Strict value is not equal to itself.")
118+ }
119+ else throw("Strict value is not equal to itself.")
120+ }
121+ else throw("Strict value is not equal to itself.")
122+ }
123+ else throw("Strict value is not equal to itself.")
124+ }
54125 else throw("Strict value is not equal to itself.")
55126 }
56127
57128
58129 @Callable(i)
59130 func returnWavesBalance () = $Tuple2(nil, internalWavesBalance())
60131
61132
62133
63134 @Callable(i)
64135 func returnSWavesBalance () = $Tuple2(nil, getIntegerOrZero(keySWavesAdditionalBalance))
65136
66137
67138
68139 @Callable(i)
69140 func calcRatio () = {
70141 let regularWavesBalance = wavesBalance(this).regular
71142 let additional = getIntegerOrZero(keyAdditionalBalance)
72143 let ratio = fraction(100, additional, (additional + regularWavesBalance))
73144 $Tuple2(nil, ratio)
74145 }
75146
76147
77148
78149 @Callable(i)
79150 func calcRatioTest (regularBalance,additional,targetRatio) = {
80151 let sum = (regularBalance + additional)
81152 let targetAdditionalBalance = fraction(targetRatio, sum, 100)
82153 let change = (additional - targetAdditionalBalance)
83154 let newReg = (regularBalance + change)
84155 if ((0 > change))
85156 then {
86157 let sendAmount = (change * -1)
87158 $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("deposit: " + toString(sendAmount))])
88159 }
89160 else {
90161 let sendAmount = change
91162 $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("withdraw: " + toString(sendAmount))])
92163 }
93164 }
94165
95166
167+
168+@Callable(i)
169+func rebalance () = {
170+ let regularBalance = wavesBalance(this).regular
171+ if ((regularBalance == regularBalance))
172+ then {
173+ let additionalBalance = getIntegerOrZero(keyAdditionalBalance)
174+ if ((additionalBalance == additionalBalance))
175+ then {
176+ let targetRatio = getTargetRatio()
177+ if ((targetRatio == targetRatio))
178+ then {
179+ let wholeBlalance = (regularBalance + additionalBalance)
180+ let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100)
181+ let change = (additionalBalance - targetAdditionalBalance)
182+ let newReg = (regularBalance + change)
183+ if ((0 > change))
184+ then {
185+ let sendWavesAmount = (change * -1)
186+ deposit(sendWavesAmount)
187+ }
188+ else {
189+ let getWavesAmount = change
190+ withdraw(getWavesAmount)
191+ }
192+ }
193+ else throw("Strict value is not equal to itself.")
194+ }
195+ else throw("Strict value is not equal to itself.")
196+ }
197+ else throw("Strict value is not equal to itself.")
198+ }
199+
200+

github/deemru/w8io/026f985 
27.81 ms