tx · 9MZwQVHAHh1AvA8EFBRP3uYh6ZCx1UhD9yB7xCVDye2U 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h: -0.05000000 Waves 2023.03.29 09:15 [2510858] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves
{ "type": 13, "id": "9MZwQVHAHh1AvA8EFBRP3uYh6ZCx1UhD9yB7xCVDye2U", "fee": 5000000, "feeAssetId": null, "timestamp": 1680070550220, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "LUCx3bDi6BUrfDBiqJvYpzgNQoXgM4NGZg1i4nPYLxjXMnM64y6HJsX1E3RFw2hwV3tBwHv43U8H89gFh9pgkBt" ], "script": "base64:BgIHCAISAwoBAQ8ADGNvbnRyYWN0RmlsZQIJcmViYWxhbmNlAA9rZXlzVGFyZ2V0UmF0aW8CDyVzX190YXJnZXRSYXRpbwAUa2V5QWRkaXRpb25hbEJhbGFuY2UCGiVzX19hZGRpdGlvbmFsV2F2ZXNCYWxhbmNlABprZXlTV2F2ZXNBZGRpdGlvbmFsQmFsYW5jZQIRJXNfX3NXYXZlc0JhbGFuY2UAEGtleVNXYXZlc0Fzc2V0SWQCESVzX19zV2F2ZXNBc3NldElkAA9rZXlQcm94eUFkZHJlc3MCECVzX19wcm94eUFkZHJlc3MADWtleU1pbkJhbGFuY2UCFCVzX19taW5XYXZlc0JhbGFsbmNlAAZNVUxUMTIAgKCUpY0dARBnZXRJbnRlZ2VyT3JaZXJvAQppbnRlZ2VyS2V5BAckbWF0Y2gwCQCaCAIFBHRoaXMFCmludGVnZXJLZXkDCQABAgUHJG1hdGNoMAIDSW50BAN2YWwFByRtYXRjaDAFA3ZhbAAAARBnZXRTdHJpbmdPclRocm93AQlzdHJpbmdLZXkEByRtYXRjaDAJAJ0IAgUEdGhp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Y2UFF3RhcmdldEFkZGl0aW9uYWxCYWxhbmNlAwkAAAIFBmNoYW5nZQAABQNuaWwDCQBmAgAABQZjaGFuZ2UED3NlbmRXYXZlc0Ftb3VudAkAaAIFBmNoYW5nZQD///////////8BCQEHZGVwb3NpdAEFD3NlbmRXYXZlc0Ftb3VudAQOZ2V0V2F2ZXNBbW91bnQFBmNoYW5nZQkBCHdpdGhkcmF3AQUOZ2V0V2F2ZXNBbW91bnQJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4JAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4AJxtsiQ==", "height": 2510858, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 36UVQqSDA8X6FYQvznVGRyYbXPYZyp6AecqTJBzfp4u1 Next: Hce4aPAvmT9eMwmJomxYJuuLHT6io955KnNVFzDv8tB Diff:
Old | New | Differences | |
---|---|---|---|
13 | 13 | ||
14 | 14 | let keyProxyAddress = "%s__proxyAddress" | |
15 | 15 | ||
16 | - | let keyMinBalance = "%s_minWavesBalalnce" | |
16 | + | let keyMinBalance = "%s__minWavesBalalnce" | |
17 | 17 | ||
18 | 18 | let MULT12 = 1000000000000 | |
19 | 19 |
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 | - | let keyMinBalance = "%s_minWavesBalalnce" | |
16 | + | let keyMinBalance = "%s__minWavesBalalnce" | |
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 | 80 | |
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("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 if ((wavesAmount > 0)) | |
74 | 74 | then { | |
75 | 75 | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(unit, wavesAmount)]) | |
76 | 76 | if ((depositInvoke == depositInvoke)) | |
77 | 77 | then match depositInvoke { | |
78 | 78 | case receivedSWaves: Int => | |
79 | 79 | let newAdditionalBalance = (currentAdditionalBalance + wavesAmount) | |
80 | 80 | let newSWavesBalance = (currentSWavesBalance + receivedSWaves) | |
81 | 81 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
82 | 82 | case _ => | |
83 | 83 | nil | |
84 | 84 | } | |
85 | 85 | else throw("Strict value is not equal to itself.") | |
86 | 86 | } | |
87 | 87 | else nil | |
88 | 88 | else throw("Strict value is not equal to itself.") | |
89 | 89 | } | |
90 | 90 | else throw("Strict value is not equal to itself.") | |
91 | 91 | } | |
92 | 92 | ||
93 | 93 | ||
94 | 94 | func withdraw (wavesAmount) = { | |
95 | 95 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
96 | 96 | let sWavesId = fromBase58String(getStringOrThrow(keySWavesAssetId)) | |
97 | 97 | if ((sWavesId == sWavesId)) | |
98 | 98 | then { | |
99 | 99 | let currentAdditionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
100 | 100 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
101 | 101 | then { | |
102 | 102 | let currentSWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
103 | 103 | if ((currentSWavesBalance == currentSWavesBalance)) | |
104 | 104 | then { | |
105 | 105 | let currentProxyRate = getRate() | |
106 | 106 | if ((currentProxyRate == currentProxyRate)) | |
107 | 107 | then { | |
108 | 108 | let sendSWavesAmount = fraction(MULT12, wavesAmount, currentProxyRate) | |
109 | 109 | if ((sendSWavesAmount > 0)) | |
110 | 110 | then { | |
111 | 111 | let depositInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(sWavesId, sendSWavesAmount)]) | |
112 | 112 | if ((depositInvoke == depositInvoke)) | |
113 | 113 | then match depositInvoke { | |
114 | 114 | case receivedWaves: Int => | |
115 | 115 | let newAdditionalBalance = (currentAdditionalBalance - receivedWaves) | |
116 | 116 | let newSWavesBalance = (currentSWavesBalance - sendSWavesAmount) | |
117 | 117 | [IntegerEntry(keyAdditionalBalance, newAdditionalBalance), IntegerEntry(keySWavesAdditionalBalance, newSWavesBalance)] | |
118 | 118 | case _ => | |
119 | 119 | nil | |
120 | 120 | } | |
121 | 121 | else throw("Strict value is not equal to itself.") | |
122 | 122 | } | |
123 | 123 | else nil | |
124 | 124 | } | |
125 | 125 | else throw("Strict value is not equal to itself.") | |
126 | 126 | } | |
127 | 127 | else throw("Strict value is not equal to itself.") | |
128 | 128 | } | |
129 | 129 | else throw("Strict value is not equal to itself.") | |
130 | 130 | } | |
131 | 131 | else throw("Strict value is not equal to itself.") | |
132 | 132 | } | |
133 | 133 | ||
134 | 134 | ||
135 | 135 | @Callable(i) | |
136 | 136 | func rebalanceRatio (targetRatio) = { | |
137 | 137 | let regularBalance = max([0, (wavesBalance(this).regular - getMinBalance())]) | |
138 | 138 | if ((regularBalance == regularBalance)) | |
139 | 139 | then { | |
140 | 140 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
141 | 141 | if ((additionalBalance == additionalBalance)) | |
142 | 142 | then { | |
143 | 143 | let wholeBalance = (regularBalance + additionalBalance) | |
144 | 144 | let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100) | |
145 | 145 | let change = (additionalBalance - targetAdditionalBalance) | |
146 | 146 | if ((change == 0)) | |
147 | 147 | then nil | |
148 | 148 | else if ((0 > change)) | |
149 | 149 | then { | |
150 | 150 | let sendWavesAmount = (change * -1) | |
151 | 151 | deposit(sendWavesAmount) | |
152 | 152 | } | |
153 | 153 | else { | |
154 | 154 | let getWavesAmount = change | |
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 |
github/deemru/w8io/026f985 32.40 ms ◑