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:BgIJCAISAwoBARIAEgAMY29udHJhY3RGaWxlAglyZWJhbGFuY2UAD2tleXNUYXJnZXRSYXRpbwIPJXNfX3RhcmdldFJhdGlvABRrZXlBZGRpdGlvbmFsQmFsYW5jZQIaJXNfX2FkZGl0aW9uYWxXYXZlc0JhbGFuY2UAGmtleVNXYXZlc0FkZGl0aW9uYWxCYWxhbmNlAhElc19fc1dhdmVzQmFsYW5jZQAQa2V5U1dhdmVzQXNzZXRJZAIRJXNfX3NXYXZlc0Fzc2V0SWQAD2tleVByb3h5QWRkcmVzcwIQJXNfX3Byb3h5QWRkcmVzcwANa2V5TWluQmFsYW5jZQITJXNfX21pbldhdmVzQmFsYW5jZQAGTVVMVDEyAICglKWNHQEQZ2V0SW50ZWdlck9yWmVybwEKaW50ZWdlcktleQQHJG1hdGNoMAkAmggCBQR0aGlzBQppbnRlZ2VyS2V5AwkAAQIFByRtYXRjaDACA0ludAQDdmFsBQckbWF0Y2gwBQN2YWwAAAEQZ2V0U3RyaW5nT3JUaHJvdwEJc3RyaW5nS2V5BAckbWF0Y2gwCQCdCAIFBHRoaXMFCXN0cmluZ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mYED3NlbmRXYXZlc0Ftb3VudAkBAS0BBQRkaWZmCQEHZGVwb3NpdAEFD3NlbmRXYXZlc0Ftb3VudAQOZ2V0V2F2ZXNBbW91bnQFBGRpZmYJAQh3aXRoZHJhdwEFDmdldFdhdmVzQW1vdW50CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAgFpAQ5yZWJhbGFuY2VSYXRpbwELdGFyZ2V0UmF0aW8JARFyZWJhbGFuY2VJbnRlcm5hbAEFC3RhcmdldFJhdGlvAWkBCXJlYmFsYW5jZQAJARFyZWJhbGFuY2VJbnRlcm5hbAEJAQ5nZXRUYXJnZXRSYXRpbwAAu2iIKw==", "height": 2511119, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 95Qmh2UMcxgtRYrLNxj1Hhv9eJE4krhpttBxDFRi5SiR Next: GuWtKs3nYMdz2tUqzSF3Xmi9nZzLLUmXVtpq8jcdRpEn Diff:
Old | New | Differences | |
---|---|---|---|
134 | 134 | ||
135 | 135 | ||
136 | 136 | func rebalanceInternal (targetRatio) = { | |
137 | - | let regularBalance = | |
137 | + | let regularBalance = wavesBalance(this).regular | |
138 | 138 | if ((regularBalance == regularBalance)) | |
139 | 139 | then { | |
140 | 140 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
141 | 141 | if ((additionalBalance == additionalBalance)) | |
142 | 142 | then { | |
143 | - | let wholeBalance = (regularBalance + additionalBalance) | |
143 | + | let wholeBalance = max([0, ((regularBalance + additionalBalance) - getMinBalance())]) | |
144 | 144 | let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100) | |
145 | 145 | let diff = (additionalBalance - targetAdditionalBalance) | |
146 | 146 | if ((diff == 0)) |
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 | let keyMinBalance = "%s__minWavesBalance" | |
17 | 17 | ||
18 | 18 | let MULT12 = 1000000000000 | |
19 | 19 | ||
20 | 20 | func getIntegerOrZero (integerKey) = match getInteger(this, integerKey) { | |
21 | 21 | case val: Int => | |
22 | 22 | val | |
23 | 23 | case _ => | |
24 | 24 | 0 | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getStringOrThrow (stringKey) = match getString(this, stringKey) { | |
29 | 29 | case s: String => | |
30 | 30 | s | |
31 | 31 | case _ => | |
32 | 32 | throw((("[" + stringKey) + "] is empty")) | |
33 | 33 | } | |
34 | 34 | ||
35 | 35 | ||
36 | 36 | func getTargetRatio () = match getInteger(keysTargetRatio) { | |
37 | 37 | case ratio: Int => | |
38 | 38 | min([100, max([0, ratio])]) | |
39 | 39 | case _ => | |
40 | 40 | 0 | |
41 | 41 | } | |
42 | 42 | ||
43 | 43 | ||
44 | 44 | func getMinBalance () = match getInteger(keyMinBalance) { | |
45 | 45 | case i: Int => | |
46 | 46 | max([0, i]) | |
47 | 47 | case _ => | |
48 | 48 | 0 | |
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("Rate is zero (0)") | |
61 | 61 | } | |
62 | 62 | else throw("Strict value is not equal to itself.") | |
63 | 63 | } | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func getProxyAddress () = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
67 | 67 | ||
68 | 68 | ||
69 | 69 | func getSWavesId () = fromBase58String(getStringOrThrow(keySWavesAssetId)) | |
70 | 70 | ||
71 | 71 | ||
72 | 72 | func deposit (wavesAmount) = { | |
73 | 73 | let proxy = getProxyAddress() | |
74 | 74 | let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
75 | 75 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
76 | 76 | then { | |
77 | 77 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
78 | 78 | if ((currentSWavesBalance == currentSWavesBalance)) | |
79 | 79 | then if ((wavesAmount > 0)) | |
80 | 80 | then { | |
81 | 81 | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)]) | |
82 | 82 | if ((depositInvoke == depositInvoke)) | |
83 | 83 | then match depositInvoke { | |
84 | 84 | case receivedSWaves: Int => | |
85 | 85 | let newAdditionalBalance = (currentAdditionalBalance + wavesAmount) | |
86 | 86 | let newSWavesBalance = (currentSWavesBalance + receivedSWaves) | |
87 | 87 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
88 | 88 | case _ => | |
89 | 89 | nil | |
90 | 90 | } | |
91 | 91 | else throw("Strict value is not equal to itself.") | |
92 | 92 | } | |
93 | 93 | else nil | |
94 | 94 | else throw("Strict value is not equal to itself.") | |
95 | 95 | } | |
96 | 96 | else throw("Strict value is not equal to itself.") | |
97 | 97 | } | |
98 | 98 | ||
99 | 99 | ||
100 | 100 | func withdraw (wavesAmount) = { | |
101 | 101 | let proxy = getProxyAddress() | |
102 | 102 | let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
103 | 103 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
104 | 104 | then { | |
105 | 105 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
106 | 106 | if ((currentSWavesBalance == currentSWavesBalance)) | |
107 | 107 | then { | |
108 | 108 | let currentProxyRate = getRate() | |
109 | 109 | if ((currentProxyRate == currentProxyRate)) | |
110 | 110 | then { | |
111 | 111 | let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate) | |
112 | 112 | if ((sendSWavesAmount > 0)) | |
113 | 113 | then { | |
114 | 114 | let withdrawInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(getSWavesId(), sendSWavesAmount)]) | |
115 | 115 | if ((withdrawInvoke == withdrawInvoke)) | |
116 | 116 | then match withdrawInvoke { | |
117 | 117 | case receivedWaves: Int => | |
118 | 118 | let newAdditionalBalance = (currentAdditionalBalance - receivedWaves) | |
119 | 119 | let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount) | |
120 | 120 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
121 | 121 | case _ => | |
122 | 122 | nil | |
123 | 123 | } | |
124 | 124 | else throw("Strict value is not equal to itself.") | |
125 | 125 | } | |
126 | 126 | else nil | |
127 | 127 | } | |
128 | 128 | else throw("Strict value is not equal to itself.") | |
129 | 129 | } | |
130 | 130 | else throw("Strict value is not equal to itself.") | |
131 | 131 | } | |
132 | 132 | else throw("Strict value is not equal to itself.") | |
133 | 133 | } | |
134 | 134 | ||
135 | 135 | ||
136 | 136 | func rebalanceInternal (targetRatio) = { | |
137 | - | let regularBalance = | |
137 | + | let regularBalance = wavesBalance(this).regular | |
138 | 138 | if ((regularBalance == regularBalance)) | |
139 | 139 | then { | |
140 | 140 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
141 | 141 | if ((additionalBalance == additionalBalance)) | |
142 | 142 | then { | |
143 | - | let wholeBalance = (regularBalance + additionalBalance) | |
143 | + | let wholeBalance = max([0, ((regularBalance + additionalBalance) - getMinBalance())]) | |
144 | 144 | let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100) | |
145 | 145 | let diff = (additionalBalance - targetAdditionalBalance) | |
146 | 146 | if ((diff == 0)) | |
147 | 147 | then nil | |
148 | 148 | else if ((0 > diff)) | |
149 | 149 | then { | |
150 | 150 | let sendWavesAmount = -(diff) | |
151 | 151 | deposit(sendWavesAmount) | |
152 | 152 | } | |
153 | 153 | else { | |
154 | 154 | let getWavesAmount = diff | |
155 | 155 | withdraw(getWavesAmount) | |
156 | 156 | } | |
157 | 157 | } | |
158 | 158 | else throw("Strict value is not equal to itself.") | |
159 | 159 | } | |
160 | 160 | else throw("Strict value is not equal to itself.") | |
161 | 161 | } | |
162 | 162 | ||
163 | 163 | ||
164 | 164 | @Callable(i) | |
165 | 165 | func rebalanceRatio (targetRatio) = rebalanceInternal(targetRatio) | |
166 | 166 | ||
167 | 167 | ||
168 | 168 | ||
169 | 169 | @Callable(i) | |
170 | 170 | func rebalance () = rebalanceInternal(getTargetRatio()) | |
171 | 171 | ||
172 | 172 |
github/deemru/w8io/169f3d6 40.41 ms ◑