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:BgIRCAISABIAEgASBQoDAQEBEgAOAAxjb250cmFjdEZpbGUCCXJlYmFsYW5jZQAPa2V5c1RhcmdldFJhdGlvAg8lc19fdGFyZ2V0UmF0aW8AFGtleUFkZGl0aW9uYWxCYWxhbmNlAholc19fYWRkaXRpb25hbFdhdmVzQmFsYW5jZQAaa2V5U1dhdmVzQWRkaXRpb25hbEJhbGFuY2UCESVzX19zV2F2ZXNCYWxhbmNlABBrZXlTV2F2ZXNBc3NldElkAhElc19fc1dhdmVzQXNzZXRJZAAPa2V5UHJveHlBZGRyZXNzAhAlc19fcHJveHlBZGRyZXNzARBnZXRJbnRlZ2VyT3JaZXJvAQppbnRlZ2VyS2V5BAckbWF0Y2gwCQCaCAIFBHRoaXMFCmludGVnZXJLZXkDCQABAgUHJG1hdGNoMAIDSW50BAN2YWwFByRtYXRjaDAFA3ZhbAAAARBnZXRTdHJpbmdPclRocm93AQlzdHJpbmdLZXkEByRtYXRjaDAJAJ0IAgUEdGhpcwUJc3RyaW5nS2V5AwkAAQIFByRtYXRjaDACBlN0cmluZwQBcwUHJG1hdGNoMAUBcwkAAgEJAKwC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sQmFsYW5jZQkAawMFC3RhcmdldFJhdGlvBQ13aG9sZUJsYWxhbmNlAGQEBmNoYW5nZQkAZQIFEWFkZGl0aW9uYWxCYWxhbmNlBRd0YXJnZXRBZGRpdGlvbmFsQmFsYW5jZQQGbmV3UmVnCQBkAgUOcmVndWxhckJhbGFuY2UFBmNoYW5nZQMJAGYCAAAFBmNoYW5nZQQPc2VuZFdhdmVzQW1vdW50CQBoAgUGY2hhbmdlAP///////////wEJAQdkZXBvc2l0AQUPc2VuZFdhdmVzQW1vdW50BA5nZXRXYXZlc0Ftb3VudAUGY2hhbmdlCQEId2l0aGRyYXcBBQ5nZXRXYXZlc0Ftb3VudAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgAxfZFj", "height": 2509468, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BN14Vfd9aoDBtQospVDznCoZboQsFZ5bmmSTPvtknHZD Next: ZYfmLsTeAxZk97CX7PPMQG7g1478dGJrXATh9cfAWYD Diff:
Old | New | Differences | |
---|---|---|---|
29 | 29 | } | |
30 | 30 | ||
31 | 31 | ||
32 | + | func getTargetRatio () = match getInteger(keysTargetRatio) { | |
33 | + | case s: Int => | |
34 | + | s | |
35 | + | case _ => | |
36 | + | 80 | |
37 | + | } | |
38 | + | ||
39 | + | ||
32 | 40 | func internalWavesBalance () = (wavesBalance(this).regular + getIntegerOrZero(keyAdditionalBalance)) | |
33 | 41 | ||
34 | 42 | ||
35 | - | func | |
43 | + | func internalRate () = { | |
36 | 44 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
37 | 45 | let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
38 | 46 | if ((additionalBalance == 0)) | |
49 | 57 | case s: String => | |
50 | 58 | parseIntValue(s) | |
51 | 59 | case _ => | |
52 | - | | |
60 | + | throw("ZERO rate") | |
53 | 61 | } | |
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 | + | } | |
54 | 125 | else throw("Strict value is not equal to itself.") | |
55 | 126 | } | |
56 | 127 | ||
93 | 164 | } | |
94 | 165 | ||
95 | 166 | ||
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 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let contractFile = "rebalance" | |
5 | 5 | ||
6 | 6 | let keysTargetRatio = "%s__targetRatio" | |
7 | 7 | ||
8 | 8 | let keyAdditionalBalance = "%s__additionalWavesBalance" | |
9 | 9 | ||
10 | 10 | let keySWavesAdditionalBalance = "%s__sWavesBalance" | |
11 | 11 | ||
12 | 12 | let keySWavesAssetId = "%s__sWavesAssetId" | |
13 | 13 | ||
14 | 14 | let keyProxyAddress = "%s__proxyAddress" | |
15 | 15 | ||
16 | 16 | func getIntegerOrZero (integerKey) = match getInteger(this, integerKey) { | |
17 | 17 | case val: Int => | |
18 | 18 | val | |
19 | 19 | case _ => | |
20 | 20 | 0 | |
21 | 21 | } | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | func getStringOrThrow (stringKey) = match getString(this, stringKey) { | |
25 | 25 | case s: String => | |
26 | 26 | s | |
27 | 27 | case _ => | |
28 | 28 | throw((("[" + stringKey) + "] is empty")) | |
29 | 29 | } | |
30 | 30 | ||
31 | 31 | ||
32 | + | func getTargetRatio () = match getInteger(keysTargetRatio) { | |
33 | + | case s: Int => | |
34 | + | s | |
35 | + | case _ => | |
36 | + | 80 | |
37 | + | } | |
38 | + | ||
39 | + | ||
32 | 40 | func internalWavesBalance () = (wavesBalance(this).regular + getIntegerOrZero(keyAdditionalBalance)) | |
33 | 41 | ||
34 | 42 | ||
35 | - | func | |
43 | + | func internalRate () = { | |
36 | 44 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
37 | 45 | let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
38 | 46 | if ((additionalBalance == 0)) | |
39 | 47 | then 0 | |
40 | 48 | else fraction(100000000000, additionalBalance, sWavesBalance) | |
41 | 49 | } | |
42 | 50 | ||
43 | 51 | ||
44 | 52 | func getRate () = { | |
45 | 53 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
46 | 54 | let inv = invoke(proxy, "getRate", nil, nil) | |
47 | 55 | if ((inv == inv)) | |
48 | 56 | then match inv { | |
49 | 57 | case s: String => | |
50 | 58 | parseIntValue(s) | |
51 | 59 | case _ => | |
52 | - | | |
60 | + | throw("ZERO rate") | |
53 | 61 | } | |
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 | + | } | |
54 | 125 | else throw("Strict value is not equal to itself.") | |
55 | 126 | } | |
56 | 127 | ||
57 | 128 | ||
58 | 129 | @Callable(i) | |
59 | 130 | func returnWavesBalance () = $Tuple2(nil, internalWavesBalance()) | |
60 | 131 | ||
61 | 132 | ||
62 | 133 | ||
63 | 134 | @Callable(i) | |
64 | 135 | func returnSWavesBalance () = $Tuple2(nil, getIntegerOrZero(keySWavesAdditionalBalance)) | |
65 | 136 | ||
66 | 137 | ||
67 | 138 | ||
68 | 139 | @Callable(i) | |
69 | 140 | func calcRatio () = { | |
70 | 141 | let regularWavesBalance = wavesBalance(this).regular | |
71 | 142 | let additional = getIntegerOrZero(keyAdditionalBalance) | |
72 | 143 | let ratio = fraction(100, additional, (additional + regularWavesBalance)) | |
73 | 144 | $Tuple2(nil, ratio) | |
74 | 145 | } | |
75 | 146 | ||
76 | 147 | ||
77 | 148 | ||
78 | 149 | @Callable(i) | |
79 | 150 | func calcRatioTest (regularBalance,additional,targetRatio) = { | |
80 | 151 | let sum = (regularBalance + additional) | |
81 | 152 | let targetAdditionalBalance = fraction(targetRatio, sum, 100) | |
82 | 153 | let change = (additional - targetAdditionalBalance) | |
83 | 154 | let newReg = (regularBalance + change) | |
84 | 155 | if ((0 > change)) | |
85 | 156 | then { | |
86 | 157 | let sendAmount = (change * -1) | |
87 | 158 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("deposit: " + toString(sendAmount))]) | |
88 | 159 | } | |
89 | 160 | else { | |
90 | 161 | let sendAmount = change | |
91 | 162 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("withdraw: " + toString(sendAmount))]) | |
92 | 163 | } | |
93 | 164 | } | |
94 | 165 | ||
95 | 166 | ||
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 ◑