tx · AKW2SvCMFrc61Cfc2dUDqBrsNf3Jth3zn731ULCJrXSt 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h: -0.05000000 Waves 2023.03.28 10:05 [2509479] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves
{ "type": 13, "id": "AKW2SvCMFrc61Cfc2dUDqBrsNf3Jth3zn731ULCJrXSt", "fee": 5000000, "feeAssetId": null, "timestamp": 1679987135876, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "2AKGJwXT3MT8PsaB8g6YwoJ2reMbVkyK68rkiMvZTWLCzPn61dcLV4RwN1rqNRN4wSpY4XVSEYPX5PaioDUjopFJ" ], "script": "base64:BgIRCAISABIAEgASBQoDAQEBEgAOAAxjb250cmFjdEZpbGUCCXJlYmFsYW5jZQAPa2V5c1RhcmdldFJhdGlvAg8lc19fdGFyZ2V0UmF0aW8AFGtleUFkZGl0aW9uYWxCYWxhbmNlAholc19fYWRkaXRpb25hbFdhdmVzQmFsYW5jZQAaa2V5U1dhdmVzQWRkaXRpb25hbEJhbGFuY2UCESVzX19zV2F2ZXNCYWxhbmNlABBrZXlTV2F2ZXNBc3NldElkAhElc19fc1dhdmVzQXNzZXRJZAAPa2V5UHJveHlBZGRyZXNzAhAlc19fcHJveHlBZGRyZXNzARBnZXRJbnRlZ2VyT3JaZXJvAQppbnRlZ2VyS2V5BAckbWF0Y2gwCQCaCAIFBHRoaXMFCmludGVnZXJLZXkDCQABAgUHJG1hdGNoMAIDSW50BAN2YWwFByRtYXRjaDAFA3ZhbAAAARBnZXRTdHJpbmdPclRocm93AQlzdHJpbmdLZXkEByRtYXRjaDAJAJ0IAgUEdGhpcwUJc3RyaW5nS2V5AwkAAQIFByRtYXRjaDACBlN0cmluZwQBcwUHJG1hdGNoMAUBcwkA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pdGlvbmFsQmFsYW5jZQkAawMFC3RhcmdldFJhdGlvBQ13aG9sZUJsYWxhbmNlAGQEBmNoYW5nZQkAZQIFEWFkZGl0aW9uYWxCYWxhbmNlBRd0YXJnZXRBZGRpdGlvbmFsQmFsYW5jZQQGbmV3UmVnCQBkAgUOcmVndWxhckJhbGFuY2UFBmNoYW5nZQMJAAACBQZjaGFuZ2UAAAUDbmlsAwkAZgIAAAUGY2hhbmdlBA9zZW5kV2F2ZXNBbW91bnQJAGgCBQZjaGFuZ2UA////////////AQkBB2RlcG9zaXQBBQ9zZW5kV2F2ZXNBbW91bnQEDmdldFdhdmVzQW1vdW50BQZjaGFuZ2UJAQh3aXRoZHJhdwEFDmdldFdhdmVzQW1vdW50CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAJuTpWE=", "height": 2509479, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: ZYfmLsTeAxZk97CX7PPMQG7g1478dGJrXATh9cfAWYD Next: 44fuU8CAFGwn9pdreeYxTFyZjNNnccaCtuD5AzgdAjR2 Diff:
Old | New | Differences | |
---|---|---|---|
180 | 180 | let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100) | |
181 | 181 | let change = (additionalBalance - targetAdditionalBalance) | |
182 | 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 | - | } | |
183 | + | if ((change == 0)) | |
184 | + | then nil | |
185 | + | else if ((0 > change)) | |
186 | + | then { | |
187 | + | let sendWavesAmount = (change * -1) | |
188 | + | deposit(sendWavesAmount) | |
189 | + | } | |
190 | + | else { | |
191 | + | let getWavesAmount = change | |
192 | + | withdraw(getWavesAmount) | |
193 | + | } | |
192 | 194 | } | |
193 | 195 | else throw("Strict value is not equal to itself.") | |
194 | 196 | } |
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 | 32 | func getTargetRatio () = match getInteger(keysTargetRatio) { | |
33 | 33 | case s: Int => | |
34 | 34 | s | |
35 | 35 | case _ => | |
36 | 36 | 80 | |
37 | 37 | } | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func internalWavesBalance () = (wavesBalance(this).regular + getIntegerOrZero(keyAdditionalBalance)) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func internalRate () = { | |
44 | 44 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
45 | 45 | let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
46 | 46 | if ((additionalBalance == 0)) | |
47 | 47 | then 0 | |
48 | 48 | else fraction(100000000000, additionalBalance, sWavesBalance) | |
49 | 49 | } | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getRate () = { | |
53 | 53 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
54 | 54 | let inv = invoke(proxy, "getRate", nil, nil) | |
55 | 55 | if ((inv == inv)) | |
56 | 56 | then match inv { | |
57 | 57 | case s: String => | |
58 | 58 | parseIntValue(s) | |
59 | 59 | case _ => | |
60 | 60 | throw("ZERO rate") | |
61 | 61 | } | |
62 | 62 | else throw("Strict value is not equal to itself.") | |
63 | 63 | } | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func deposit (wavesAmount) = { | |
67 | 67 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
68 | 68 | let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
69 | 69 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
70 | 70 | then { | |
71 | 71 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
72 | 72 | if ((currentSWavesBalance == currentSWavesBalance)) | |
73 | 73 | then { | |
74 | 74 | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)]) | |
75 | 75 | if ((depositInvoke == depositInvoke)) | |
76 | 76 | then match depositInvoke { | |
77 | 77 | case receivedSWaves: Int => | |
78 | 78 | let newAdditionalBalance = (currentAdditionalBalance + wavesAmount) | |
79 | 79 | let newSWavesBalance = (currentSWavesBalance + receivedSWaves) | |
80 | 80 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
81 | 81 | case _ => | |
82 | 82 | nil | |
83 | 83 | } | |
84 | 84 | else throw("Strict value is not equal to itself.") | |
85 | 85 | } | |
86 | 86 | else throw("Strict value is not equal to itself.") | |
87 | 87 | } | |
88 | 88 | else throw("Strict value is not equal to itself.") | |
89 | 89 | } | |
90 | 90 | ||
91 | 91 | ||
92 | 92 | func withdraw (wavesAmount) = { | |
93 | 93 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
94 | 94 | let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId)) | |
95 | 95 | if ((sWavesId == sWavesId)) | |
96 | 96 | then { | |
97 | 97 | let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
98 | 98 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
99 | 99 | then { | |
100 | 100 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
101 | 101 | if ((currentSWavesBalance == currentSWavesBalance)) | |
102 | 102 | then { | |
103 | 103 | let currentProxyRate = getRate() | |
104 | 104 | if ((currentProxyRate == currentProxyRate)) | |
105 | 105 | then { | |
106 | 106 | let sendSWavesAmount = fraction(1000000000000, wavesAmount, currentProxyRate) | |
107 | 107 | let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)]) | |
108 | 108 | if ((depositInvoke == depositInvoke)) | |
109 | 109 | then match depositInvoke { | |
110 | 110 | case receivedWaves: Int => | |
111 | 111 | let newAdditionalBalance = (currentAdditionalBalance - receivedWaves) | |
112 | 112 | let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount) | |
113 | 113 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
114 | 114 | case _ => | |
115 | 115 | nil | |
116 | 116 | } | |
117 | 117 | else throw("Strict value is not equal to itself.") | |
118 | 118 | } | |
119 | 119 | else throw("Strict value is not equal to itself.") | |
120 | 120 | } | |
121 | 121 | else throw("Strict value is not equal to itself.") | |
122 | 122 | } | |
123 | 123 | else throw("Strict value is not equal to itself.") | |
124 | 124 | } | |
125 | 125 | else throw("Strict value is not equal to itself.") | |
126 | 126 | } | |
127 | 127 | ||
128 | 128 | ||
129 | 129 | @Callable(i) | |
130 | 130 | func returnWavesBalance () = $Tuple2(nil, internalWavesBalance()) | |
131 | 131 | ||
132 | 132 | ||
133 | 133 | ||
134 | 134 | @Callable(i) | |
135 | 135 | func returnSWavesBalance () = $Tuple2(nil, getIntegerOrZero(keySWavesAdditionalBalance)) | |
136 | 136 | ||
137 | 137 | ||
138 | 138 | ||
139 | 139 | @Callable(i) | |
140 | 140 | func calcRatio () = { | |
141 | 141 | let regularWavesBalance = wavesBalance(this).regular | |
142 | 142 | let additional = getIntegerOrZero(keyAdditionalBalance) | |
143 | 143 | let ratio = fraction(100, additional, (additional + regularWavesBalance)) | |
144 | 144 | $Tuple2(nil, ratio) | |
145 | 145 | } | |
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | 149 | @Callable(i) | |
150 | 150 | func calcRatioTest (regularBalance,additional,targetRatio) = { | |
151 | 151 | let sum = (regularBalance + additional) | |
152 | 152 | let targetAdditionalBalance = fraction(targetRatio, sum, 100) | |
153 | 153 | let change = (additional - targetAdditionalBalance) | |
154 | 154 | let newReg = (regularBalance + change) | |
155 | 155 | if ((0 > change)) | |
156 | 156 | then { | |
157 | 157 | let sendAmount = (change * -1) | |
158 | 158 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("deposit: " + toString(sendAmount))]) | |
159 | 159 | } | |
160 | 160 | else { | |
161 | 161 | let sendAmount = change | |
162 | 162 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("withdraw: " + toString(sendAmount))]) | |
163 | 163 | } | |
164 | 164 | } | |
165 | 165 | ||
166 | 166 | ||
167 | 167 | ||
168 | 168 | @Callable(i) | |
169 | 169 | func rebalance () = { | |
170 | 170 | let regularBalance = wavesBalance(this).regular | |
171 | 171 | if ((regularBalance == regularBalance)) | |
172 | 172 | then { | |
173 | 173 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
174 | 174 | if ((additionalBalance == additionalBalance)) | |
175 | 175 | then { | |
176 | 176 | let targetRatio = getTargetRatio() | |
177 | 177 | if ((targetRatio == targetRatio)) | |
178 | 178 | then { | |
179 | 179 | let wholeBlalance = (regularBalance + additionalBalance) | |
180 | 180 | let targetAdditionalBalance = fraction(targetRatio, wholeBlalance, 100) | |
181 | 181 | let change = (additionalBalance - targetAdditionalBalance) | |
182 | 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 | - | } | |
183 | + | if ((change == 0)) | |
184 | + | then nil | |
185 | + | else if ((0 > change)) | |
186 | + | then { | |
187 | + | let sendWavesAmount = (change * -1) | |
188 | + | deposit(sendWavesAmount) | |
189 | + | } | |
190 | + | else { | |
191 | + | let getWavesAmount = change | |
192 | + | withdraw(getWavesAmount) | |
193 | + | } | |
192 | 194 | } | |
193 | 195 | else throw("Strict value is not equal to itself.") | |
194 | 196 | } | |
195 | 197 | else throw("Strict value is not equal to itself.") | |
196 | 198 | } | |
197 | 199 | else throw("Strict value is not equal to itself.") | |
198 | 200 | } | |
199 | 201 | ||
200 | 202 |
github/deemru/w8io/169f3d6 27.98 ms ◑