24 | | - | |
---|
25 | | - | |
---|
26 | | - | func getAssetString (assetId) = match assetId { |
---|
27 | | - | case b: ByteVector => |
---|
28 | | - | toBase58String(b) |
---|
29 | | - | case _ => |
---|
30 | | - | "WAVES" |
---|
31 | | - | } |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | func getAssetBytes (assetIdStr) = if ((assetIdStr == "WAVES")) |
---|
35 | | - | then unit |
---|
36 | | - | else fromBase58String(assetIdStr) |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | func payBoostingResult (boostingId) = { |
---|
40 | | - | let lastHeight = tryGetInteger((("boosting_" + boostingId) + "_lastHeight")) |
---|
41 | | - | let finishHeight = tryGetInteger((("boosting_" + boostingId) + "_finishHeight")) |
---|
42 | | - | if (if ((lastHeight != 0)) |
---|
43 | | - | then (finishHeight > lastHeight) |
---|
44 | | - | else false) |
---|
45 | | - | then { |
---|
46 | | - | let blockReward = (tryGetInteger((("boosting_" + boostingId) + "_totalAmount")) / ((tryGetInteger((("boosting_" + boostingId) + "_days")) * hours) * minutes)) |
---|
47 | | - | let toPay = fraction((min([finishHeight, height]) - lastHeight), blockReward, 1) |
---|
48 | | - | let getFinishedPoolId = tryGetString((("boosting_" + boostingId) + "_poolId")) |
---|
49 | | - | let getPoolBoostings = tryGetString((("pool_" + getFinishedPoolId) + "_boostings")) |
---|
50 | | - | let sizeStr = size(getPoolBoostings) |
---|
51 | | - | let findIndex = value(indexOf(getPoolBoostings, boostingId)) |
---|
52 | | - | let modifierLeft = if ((findIndex == 0)) |
---|
53 | | - | then 0 |
---|
54 | | - | else 1 |
---|
55 | | - | let modifierRight = if ((findIndex == 0)) |
---|
56 | | - | then 2 |
---|
57 | | - | else 1 |
---|
58 | | - | let leftStr = take(getPoolBoostings, (sizeStr - ((sizeStr - findIndex) + modifierLeft))) |
---|
59 | | - | let rightStr = takeRight(getPoolBoostings, (sizeStr - (findIndex + modifierRight))) |
---|
60 | | - | let openBoostingsIds = (leftStr + rightStr) |
---|
61 | | - | [IntegerEntry((("boosting_" + boostingId) + "_lastHeight"), height), ScriptTransfer(addressFromStringValue(tryGetString((("boosting_" + boostingId) + "_poolId"))), toPay, getAssetBytes(tryGetString((("boosting_" + boostingId) + "_assetId")))), StringEntry((("pool_" + getFinishedPoolId) + "_boostings"), if ((finishHeight > height)) |
---|
62 | | - | then tryGetString((("pool_" + getFinishedPoolId) + "_boostings")) |
---|
63 | | - | else openBoostingsIds)] |
---|
64 | | - | } |
---|
65 | | - | else nil |
---|
66 | | - | } |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | func endedBoostingIds (boostingId) = { |
---|
70 | | - | let lastHeight = tryGetInteger((("boosting_" + boostingId) + "_lastHeight")) |
---|
71 | | - | let finishHeight = tryGetInteger((("boosting_" + boostingId) + "_finishHeight")) |
---|
72 | | - | if ((lastHeight >= finishHeight)) |
---|
73 | | - | then [StringEntry((("list ended " + toString(height)) + " boostingIds"), ((tryGetString((("list ended " + toString(height)) + " boostingIds")) + boostingId) + ","))] |
---|
74 | | - | else [StringEntry((("list ongoing boosts " + toString(height)) + " boostingIds"), ((tryGetString((("list ongoing boosts " + toString(height)) + " boostingIds")) + boostingId) + ","))] |
---|
75 | | - | } |
---|
76 | | - | |
---|
77 | | - | |
---|
78 | | - | @Callable(i) |
---|
79 | | - | func addBoosting (poolId,days) = if ((1 > days)) |
---|
80 | | - | then throw("amount of days has to be between 1 and 365") |
---|
81 | | - | else if ((days > 365)) |
---|
82 | | - | then throw("amount of days has to be between 1 and 365") |
---|
83 | | - | else if (false) |
---|
84 | | - | then throw("under maintenance until further notice") |
---|
85 | | - | else { |
---|
86 | | - | let fullAmount = i.payments[0].amount |
---|
87 | | - | if ((1440 > (fullAmount / days))) |
---|
88 | | - | then throw((("boosting amount too small, minimum is " + toString((1440 * days))) + " of the smallest unit of payment asset")) |
---|
89 | | - | else { |
---|
90 | | - | let assetId = getAssetString(i.payments[0].assetId) |
---|
91 | | - | if ((height == tryGetInteger("height"))) |
---|
92 | | - | then throw("wait 1 minute") |
---|
93 | | - | else { |
---|
94 | | - | let entry = if ((size(tryGetString((("pool_" + poolId) + "_boostings"))) > 11)) |
---|
95 | | - | then throw("max 5 boosts per pool") |
---|
96 | | - | else invoke(this, "entryEnded", nil, nil) |
---|
97 | | - | if ((entry == entry)) |
---|
98 | | - | then { |
---|
99 | | - | let boostingId = if ((size((("list ongoing boosts " + toString(height)) + " boostingIds")) > 112)) |
---|
100 | | - | then throw("wait till other boosts are finished") |
---|
101 | | - | else take(tryGetString((("list ended " + toString(height)) + " boostingIds")), 1) |
---|
102 | | - | if ((addressFromString(poolId) == unit)) |
---|
103 | | - | then throw("incorrect pool address") |
---|
104 | | - | else [IntegerEntry((("boosting_" + boostingId) + "_days"), days), IntegerEntry((("boosting_" + boostingId) + "_totalAmount"), fullAmount), IntegerEntry((("boosting_" + boostingId) + "_dailyAmount"), (fullAmount / days)), IntegerEntry((("boosting_" + boostingId) + "_startHeight"), height), IntegerEntry((("boosting_" + boostingId) + "_finishHeight"), (height + ((days * hours) * minutes))), IntegerEntry((("boosting_" + boostingId) + "_finishTimestamp"), (lastBlock.timestamp + ((((days * hours) * minutes) * 60) * 1000))), IntegerEntry((("boosting_" + boostingId) + "_lastHeight"), height), StringEntry((("boosting_" + boostingId) + "_assetId"), assetId), StringEntry((("boosting_" + boostingId) + "_owner"), toString(i.caller)), StringEntry((("boosting_" + boostingId) + "_poolId"), poolId), StringEntry((("pool_" + poolId) + "_boostings"), ((tryGetString((("pool_" + poolId) + "_boostings")) + boostingId) + ","))] |
---|
105 | | - | } |
---|
106 | | - | else throw("Strict value is not equal to itself.") |
---|
107 | | - | } |
---|
108 | | - | } |
---|
109 | | - | } |
---|
110 | | - | |
---|
111 | | - | |
---|
112 | | - | |
---|
113 | | - | @Callable(i) |
---|
114 | | - | func payBoosting (boostingId) = payBoostingResult(boostingId) |
---|
115 | | - | |
---|
116 | | - | |
---|
117 | | - | |
---|
118 | | - | @Callable(i) |
---|
119 | | - | func payBoostings () = { |
---|
120 | | - | func f (accum,next) = { |
---|
121 | | - | let in = invoke(this, "payBoosting", [next], nil) |
---|
122 | | - | if ((in == in)) |
---|
123 | | - | then in |
---|
124 | | - | else throw("Strict value is not equal to itself.") |
---|
125 | | - | } |
---|
126 | | - | |
---|
127 | | - | let payments = { |
---|
128 | | - | let $l = li |
---|
129 | | - | let $s = size($l) |
---|
130 | | - | let $acc0 = 0 |
---|
131 | | - | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
132 | | - | then $a |
---|
133 | | - | else f($a, $l[$i]) |
---|
134 | | - | |
---|
135 | | - | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
136 | | - | then $a |
---|
137 | | - | else throw("List size exceeds 56") |
---|
138 | | - | |
---|
139 | | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40), 41), 42), 43), 44), 45), 46), 47), 48), 49), 50), 51), 52), 53), 54), 55), 56) |
---|
140 | | - | } |
---|
141 | | - | if ((payments == payments)) |
---|
142 | | - | then nil |
---|
143 | | - | else throw("Strict value is not equal to itself.") |
---|
144 | | - | } |
---|
145 | | - | |
---|
146 | | - | |
---|
147 | | - | |
---|
148 | | - | @Callable(i) |
---|
149 | | - | func endedBoostings (boostingId) = endedBoostingIds(boostingId) |
---|
150 | | - | |
---|
151 | | - | |
---|
152 | | - | |
---|
153 | | - | @Callable(i) |
---|
154 | | - | func entryEnded () = { |
---|
155 | | - | func f (accum,next) = { |
---|
156 | | - | let in = invoke(this, "endedBoostings", [next], nil) |
---|
157 | | - | if ((in == in)) |
---|
158 | | - | then in |
---|
159 | | - | else throw("Strict value is not equal to itself.") |
---|
160 | | - | } |
---|
161 | | - | |
---|
162 | | - | let end = { |
---|
163 | | - | let $l = li |
---|
164 | | - | let $s = size($l) |
---|
165 | | - | let $acc0 = 0 |
---|
166 | | - | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
167 | | - | then $a |
---|
168 | | - | else f($a, $l[$i]) |
---|
169 | | - | |
---|
170 | | - | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
171 | | - | then $a |
---|
172 | | - | else throw("List size exceeds 56") |
---|
173 | | - | |
---|
174 | | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40), 41), 42), 43), 44), 45), 46), 47), 48), 49), 50), 51), 52), 53), 54), 55), 56) |
---|
175 | | - | } |
---|
176 | | - | if ((end == end)) |
---|
177 | | - | then [IntegerEntry("height", height)] |
---|
178 | | - | else throw("Strict value is not equal to itself.") |
---|
179 | | - | } |
---|
180 | | - | |
---|
181 | | - | |
---|
182 | | - | |
---|
183 | | - | @Callable(i) |
---|
184 | | - | func deleteEntr (poolId) = [DeleteEntry((("pool_" + poolId) + "_boostings"))] |
---|
185 | | - | |
---|
186 | | - | |
---|
187 | | - | |
---|
188 | | - | @Callable(i) |
---|
189 | | - | func checkStr (boostingId) = { |
---|
190 | | - | let getFinishedPoolId1 = tryGetString((("boosting_" + boostingId) + "_poolId")) |
---|
191 | | - | let getPoolBoostings = tryGetString((("pool_" + getFinishedPoolId1) + "_boostings")) |
---|
192 | | - | let sizeStr = size(getPoolBoostings) |
---|
193 | | - | if ((indexOf(getPoolBoostings, boostingId) == unit)) |
---|
194 | | - | then nil |
---|
195 | | - | else { |
---|
196 | | - | let findIndex = value(indexOf(getPoolBoostings, boostingId)) |
---|
197 | | - | let modifierRight = if ((findIndex == 0)) |
---|
198 | | - | then 2 |
---|
199 | | - | else 1 |
---|
200 | | - | let modifierLeft = if ((findIndex == 0)) |
---|
201 | | - | then 0 |
---|
202 | | - | else 1 |
---|
203 | | - | let removeEndedBoostingID = (take(getPoolBoostings, (sizeStr - ((sizeStr - findIndex) + modifierLeft))) + takeRight(getPoolBoostings, (sizeStr - (findIndex + modifierRight)))) |
---|
204 | | - | [StringEntry("getFinishedPoolId", getFinishedPoolId1), StringEntry("getPoolBoostings", getPoolBoostings), IntegerEntry("findIndex", findIndex), IntegerEntry("sizeStr", sizeStr), StringEntry("left string", take(getPoolBoostings, (sizeStr - (sizeStr - findIndex)))), StringEntry("right string", takeRight(getPoolBoostings, (sizeStr - (findIndex + modifierRight)))), StringEntry((("pool_" + getFinishedPoolId1) + "_boostings"), removeEndedBoostingID)] |
---|
205 | | - | } |
---|
206 | | - | } |
---|
207 | | - | |
---|
208 | | - | |
---|
209 | | - | |
---|
210 | | - | @Callable(i) |
---|
211 | | - | func remove (boostingId) = { |
---|
212 | | - | let getFinishedPoolId = tryGetString((("boosting_" + boostingId) + "_poolId")) |
---|
213 | | - | let getPoolBoostings = tryGetString((("pool_" + getFinishedPoolId) + "_boostings")) |
---|
214 | | - | let sizeStr = size(getPoolBoostings) |
---|
215 | | - | let findIndex = value(indexOf(getPoolBoostings, boostingId)) |
---|
216 | | - | let modifierLeft = if ((findIndex == 0)) |
---|
217 | | - | then 0 |
---|
218 | | - | else 1 |
---|
219 | | - | let modifierRight = if ((findIndex == 0)) |
---|
220 | | - | then 2 |
---|
221 | | - | else 1 |
---|
222 | | - | let leftStr = take(getPoolBoostings, (sizeStr - ((sizeStr - findIndex) + modifierLeft))) |
---|
223 | | - | let rightStr = takeRight(getPoolBoostings, (sizeStr - (findIndex + modifierRight))) |
---|
224 | | - | let openBoostingsIds = (leftStr + rightStr) |
---|
225 | | - | [StringEntry("getFinishedPoolId", getFinishedPoolId), StringEntry("getPoolBoostings", getPoolBoostings), IntegerEntry("findIndex", findIndex), IntegerEntry("sizeStr", sizeStr), StringEntry("left string", leftStr), StringEntry("right string", rightStr), StringEntry("openBoostingsIds", openBoostingsIds), StringEntry((("pool_" + getFinishedPoolId) + "_boostings"), openBoostingsIds)] |
---|
226 | | - | } |
---|
227 | | - | |
---|