tx · HDP2ao8emwk1b6q1Z5VLnW3mwb9QZU2227sy6bGotwJe 3NBBWfzZtZtszaXbitTKnrB2xXwv26Bn7H9: -0.01600000 Waves 2022.09.14 18:34 [2228964] smart account 3NBBWfzZtZtszaXbitTKnrB2xXwv26Bn7H9 > SELF 0.00000000 Waves
{ "type": 13, "id": "HDP2ao8emwk1b6q1Z5VLnW3mwb9QZU2227sy6bGotwJe", "fee": 1600000, "feeAssetId": null, "timestamp": 1663169717878, "version": 2, "chainId": 84, "sender": "3NBBWfzZtZtszaXbitTKnrB2xXwv26Bn7H9", "senderPublicKey": "D1X9WatF6ARMCmm3jC4Ex5Wd5VQ3LY8i1xbHNqeHqeAa", "proofs": [ "3W2Btp3pS3cYGL3Ub9wKaWDY3LLC3oqvXAaKrD1K8H3PczApM4uzLBmWA5QycMjZ7NpNn3rm4St5DAbAt4rJpB95", "56axChogF273FLZ8EGsZ4xewuHe2JR4KaA389tqnNiXNsnoopHbZL9e1qid79jmRDTWYVd2aoZvqCoaG7Qs3P7xr" ], "script": "base64:BgIfCAISABIECgIICBIECgIICBIDCgEEEgMKAQgSAwoBCBEAD2tQcmVmaXhQb29sTmFtZQIFcG9vbF8ABWtQYWlyAgVwYWlyXwAJa0Fzc2V0SWRBAgpBX2Fzc2V0X2lkAAlrQXNzZXRJZEICCkJfYXNzZXRfaWQAH2tMYXVuY2hwYWREYXRhVHJhbnNhY3Rpb25TdGF0dXMCIWxhdW5jaHBhZF9kYXRhX3RyYW5zYWN0aW9uX3N0YXR1cwANa0FkbWluUHViS2V5MQILYWRtaW5fcHViXzEADWtBZG1pblB1YktleTICC2FkbWluX3B1Yl8yAA1rQWRtaW5QdWJLZXkzAgthZG1pbl9wdWJfMwASa0FkbWluSW52b2tlUHViS2V5AhBhZG1pbl9pbnZva2VfcHViABRrQWNoaWV2ZW1lbnRzV3JpdGVycwIUYWNoaWV2ZW1lbnRzX3dyaXRlcnMADGFkbWluUHViS2V5MQEg4qeMQDuGzRfmtEuH2+Wh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GlvbgYDCQABAgUHJG1hdGNoMAIZU2V0QXNzZXRTY3JpcHRUcmFuc2FjdGlvbgYDCQABAgUHJG1hdGNoMAITVHJhbnNmZXJUcmFuc2FjdGlvbgYDCQABAgUHJG1hdGNoMAITRXhjaGFuZ2VUcmFuc2FjdGlvbgYDCQABAgUHJG1hdGNoMAIXTWFzc1RyYW5zZmVyVHJhbnNhY3Rpb24GAwkAAQIFByRtYXRjaDACD0J1cm5UcmFuc2FjdGlvbgYJAAECBQckbWF0Y2gwAhJSZWlzc3VlVHJhbnNhY3Rpb24FDXNpZ25lZEJ5QWRtaW4JAAIBAgtNYXRjaCBlcnJvcnHIYdo=", "height": 2228964, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Fmm7rCSdDzrRFWPreEevEYf2k7ZnXjdnGvBteysP2i1J Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let kPrefixPoolName = "pool_" | |
5 | 5 | ||
6 | - | let | |
6 | + | let kPair = "pair_" | |
7 | 7 | ||
8 | - | let | |
8 | + | let kAssetIdA = "A_asset_id" | |
9 | 9 | ||
10 | - | let | |
10 | + | let kAssetIdB = "B_asset_id" | |
11 | 11 | ||
12 | - | let keyRewardPoolFractionCurrent = "_current_pool_fraction_reward" | |
13 | - | ||
14 | - | let keyRewardPoolFractionPrevious = "_previous_pool_fraction_reward" | |
15 | - | ||
16 | - | let keyHeightPoolFraction = "_pool_reward_update_height" | |
17 | - | ||
18 | - | let keyTotalRewardPerBlockCurrent = "total_reward_per_block_current" | |
19 | - | ||
20 | - | let keyTotalRewardPerBlockPrevious = "total_reward_per_block_previous" | |
21 | - | ||
22 | - | let keyRewardUpdateHeight = "reward_update_height" | |
23 | - | ||
24 | - | let keyLastInterest = "_last_interest" | |
25 | - | ||
26 | - | let keyLastInterestHeight = "_last_interest_height" | |
27 | - | ||
28 | - | let keyUserShareTokensLocked = "_share_tokens_locked" | |
29 | - | ||
30 | - | let keyUserLastInterest = "_last_interest" | |
31 | - | ||
32 | - | let keySWOPid = "SWOP_id" | |
33 | - | ||
34 | - | let keyUserSWOPClaimedAmount = "_SWOP_claimed_amount" | |
35 | - | ||
36 | - | let keyUserSWOPLastClaimedAmount = "_SWOP_last_claimed_amount" | |
37 | - | ||
38 | - | let keyAvailableSWOP = "_available_SWOP" | |
39 | - | ||
40 | - | let keyFarmingStartHeight = "farming_start_height" | |
41 | - | ||
42 | - | let keyAPY = "apy" | |
43 | - | ||
44 | - | let kPreviousTotalVoteSWOP = "previous_total_vote_SWOP" | |
45 | - | ||
46 | - | let keySwopYearEmission = "swop_year_emission" | |
47 | - | ||
48 | - | let keyBalancecpmmA = "A_asset_balance" | |
49 | - | ||
50 | - | let keyBalancecpmmB = "B_asset_balance" | |
51 | - | ||
52 | - | let kHarvestPoolActiveVoteStrucVoting = "_harvest_pool_activeVote_struc" | |
53 | - | ||
54 | - | let kHarvestUserPoolActiveVoteStrucVoting = "_harvest_user_pool_activeVote_struc" | |
55 | - | ||
56 | - | let keyLimitShareFirstHarvest = "share_limit_on_first_harvest" | |
57 | - | ||
58 | - | let keyAssetIdA = "A_asset_id" | |
59 | - | ||
60 | - | let keyAssetIdB = "B_asset_id" | |
61 | - | ||
62 | - | let keyFirstHarvestHeight = "first_harvest_height" | |
63 | - | ||
64 | - | let keyfirstHarvestCpmm = "first_harvest" | |
65 | - | ||
66 | - | let keyTempPrevSum = "sum_reward_previous" | |
67 | - | ||
68 | - | let keyTempCurSum = "sum_reward_current" | |
69 | - | ||
70 | - | let oneWeekInBlock = 10106 | |
71 | - | ||
72 | - | let totalVoteShare = 10000000000 | |
73 | - | ||
74 | - | let scaleValue1 = 10 | |
75 | - | ||
76 | - | let scaleValue3 = 1000 | |
77 | - | ||
78 | - | let scaleValue5 = 100000 | |
79 | - | ||
80 | - | let scaleValue6 = 1000000 | |
81 | - | ||
82 | - | let scaleValue8 = 100000000 | |
83 | - | ||
84 | - | let scaleValue11 = 100000000000 | |
12 | + | let kLaunchpadDataTransactionStatus = "launchpad_data_transaction_status" | |
85 | 13 | ||
86 | 14 | let kAdminPubKey1 = "admin_pub_1" | |
87 | 15 | ||
91 | 19 | ||
92 | 20 | let kAdminInvokePubKey = "admin_invoke_pub" | |
93 | 21 | ||
94 | - | let | |
22 | + | let kAchievementsWriters = "achievements_writers" | |
95 | 23 | ||
96 | - | let | |
24 | + | let adminPubKey1 = base58'GFmKZ2naZFRoCvNbwKAQVGmLb1uBeWGDgFabdGBuZiuy' | |
97 | 25 | ||
98 | - | let | |
26 | + | let adminPubKey2 = base58'GmJXRyhRA79g8yUGgKBAVdnFfQFDMjQG98b1MmLDh5kk' | |
99 | 27 | ||
100 | - | let | |
28 | + | let adminPubKey3 = base58'CFhbV6h41hVjbGHudGtS3fYUv7QAKRxFQzKNtx4B5PqP' | |
101 | 29 | ||
102 | - | let | |
30 | + | let adminPubKeyInvoke = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
103 | 31 | ||
104 | - | func getBase58FromOracle (key) = match getString(oracle, key) { | |
105 | - | case string: String => | |
106 | - | fromBase58String(string) | |
107 | - | case nothing => | |
108 | - | throw((key + "is empty")) | |
109 | - | } | |
32 | + | func isSelfCall (i) = if ((i.caller == this)) | |
33 | + | then unit | |
34 | + | else throw("Only the Oracle itself can invoke this function") | |
110 | 35 | ||
111 | 36 | ||
112 | - | let adminPubKey1 = getBase58FromOracle(kAdminPubKey1) | |
113 | - | ||
114 | - | let adminPubKey2 = getBase58FromOracle(kAdminPubKey2) | |
115 | - | ||
116 | - | let adminPubKey3 = getBase58FromOracle(kAdminPubKey3) | |
117 | - | ||
118 | - | let moneyBoxAddress = Address(getBase58FromOracle(kMoneyBoxAddress)) | |
119 | - | ||
120 | - | let votingAddress = Address(getBase58FromOracle(kVotingAddress)) | |
121 | - | ||
122 | - | let govAddress = Address(getBase58FromOracle(kGovAddress)) | |
123 | - | ||
124 | - | let adminInvokePubKey = getBase58FromOracle(kAdminInvokePubKey) | |
125 | - | ||
126 | - | let lpFarmingAddress = Address(getBase58FromOracle(kLPFarmingAddress)) | |
127 | - | ||
128 | - | func strAssetIdA (pool) = getStringValue(pool, keyAssetIdA) | |
129 | - | ||
130 | - | ||
131 | - | func strAssetIdB (pool) = getStringValue(pool, keyAssetIdB) | |
132 | - | ||
133 | - | ||
134 | - | func assetIdA (pool) = if ((strAssetIdA(pool) == "WAVES")) | |
135 | - | then unit | |
136 | - | else fromBase58String(strAssetIdA(pool)) | |
137 | - | ||
138 | - | ||
139 | - | func assetIdB (pool) = if ((strAssetIdB(pool) == "WAVES")) | |
140 | - | then unit | |
141 | - | else fromBase58String(strAssetIdB(pool)) | |
142 | - | ||
143 | - | ||
144 | - | let kBasePeriod = "base_period" | |
145 | - | ||
146 | - | let kPeriodLength = "period_length" | |
147 | - | ||
148 | - | let kStartHeight = "start_height" | |
149 | - | ||
150 | - | let kFirstHarvestHeight = "first_harvest_height" | |
151 | - | ||
152 | - | let kDurationFullVotePower = "duration_full_vote_power" | |
153 | - | ||
154 | - | let kMinVotePower = "min_vote_power" | |
155 | - | ||
156 | - | let basePeriod = valueOrErrorMessage(getInteger(votingAddress, kBasePeriod), "Empty kBasePeriod") | |
157 | - | ||
158 | - | let startHeight = valueOrErrorMessage(getInteger(votingAddress, kStartHeight), "Empty kStartHeight") | |
159 | - | ||
160 | - | let periodLength = valueOrErrorMessage(getInteger(votingAddress, kPeriodLength), "Empty kPeriodLength") | |
161 | - | ||
162 | - | let durationFullVotePower = valueOrErrorMessage(getInteger(votingAddress, kDurationFullVotePower), "Empty kDurationFullVotePower") | |
163 | - | ||
164 | - | let minVotePower = valueOrErrorMessage(getInteger(votingAddress, kMinVotePower), "Empty kMinVotePower") | |
165 | - | ||
166 | - | let isActive = getBooleanValue(this, keyActive) | |
167 | - | ||
168 | - | let currPeriod = (basePeriod + ((height - startHeight) / periodLength)) | |
169 | - | ||
170 | - | func getLimitToken (pool) = valueOrElse(getIntegerValue(pool, keyLimitShareFirstHarvest), 0) | |
171 | - | ||
172 | - | ||
173 | - | let APY = getIntegerValue(this, keyAPY) | |
174 | - | ||
175 | - | let SwopYearEmission = getIntegerValue(this, keySwopYearEmission) | |
176 | - | ||
177 | - | func assetNameA (pool) = match assetIdA(pool) { | |
178 | - | case id: ByteVector => | |
179 | - | value(assetInfo(id)).name | |
180 | - | case waves: Unit => | |
181 | - | "WAVES" | |
182 | - | case _ => | |
183 | - | throw("Match error") | |
184 | - | } | |
185 | - | ||
186 | - | ||
187 | - | func assetNameB (pool) = match assetIdB(pool) { | |
188 | - | case id: ByteVector => | |
189 | - | value(assetInfo(id)).name | |
190 | - | case waves: Unit => | |
191 | - | "WAVES" | |
192 | - | case _ => | |
193 | - | throw("Match error") | |
194 | - | } | |
195 | - | ||
196 | - | ||
197 | - | let SWOP = fromBase58String(getStringValue(this, keySWOPid)) | |
198 | - | ||
199 | - | func isFirstHarvest (pool) = valueOrElse(getBoolean(pool, keyfirstHarvestCpmm), false) | |
200 | - | ||
201 | - | ||
202 | - | func getHeightFirstHarvest (pool) = valueOrElse(getInteger(pool, keyFirstHarvestHeight), 0) | |
203 | - | ||
204 | - | ||
205 | - | func getBalanceA (pool) = valueOrErrorMessage(getInteger(pool, keyBalancecpmmA), ("No data on the key: " + keyBalancecpmmA)) | |
206 | - | ||
207 | - | ||
208 | - | func getBalanceB (pool) = valueOrErrorMessage(getInteger(pool, keyBalancecpmmB), ("No data on the key: " + keyBalancecpmmB)) | |
209 | - | ||
210 | - | ||
211 | - | func getShareLimitToken (pool) = valueOrErrorMessage(getInteger(pool, kShareLimit), ("No data on the key: " + kShareLimit)) | |
212 | - | ||
213 | - | ||
214 | - | func getTotalShareTokenLocked (pool) = valueOrErrorMessage(getInteger(this, (pool + keyShareTokensLocked)), (("No data on the key: " + pool) + keyShareTokensLocked)) | |
215 | - | ||
216 | - | ||
217 | - | func getShareAssetId (pool) = fromBase58String(getStringValue(value(addressFromString(pool)), "share_asset_id")) | |
218 | - | ||
219 | - | ||
220 | - | func accountBalance (assetId) = match assetId { | |
221 | - | case id: ByteVector => | |
222 | - | assetBalance(this, id) | |
223 | - | case waves: Unit => | |
224 | - | wavesBalance(this).available | |
225 | - | case _ => | |
226 | - | throw("Match error") | |
227 | - | } | |
228 | - | ||
229 | - | ||
230 | - | func getAssetInfo (assetId) = match assetId { | |
231 | - | case id: ByteVector => | |
232 | - | let stringId = toBase58String(id) | |
233 | - | let info = valueOrErrorMessage(assetInfo(id), (("Asset " + stringId) + " doesn't exist")) | |
234 | - | $Tuple3(stringId, info.name, info.decimals) | |
235 | - | case waves: Unit => | |
236 | - | $Tuple3("WAVES", "WAVES", 8) | |
237 | - | case _ => | |
238 | - | throw("Match error") | |
239 | - | } | |
240 | - | ||
241 | - | ||
242 | - | func calcScaleValue (assetId1,assetId2) = { | |
243 | - | let assetId1Decimals = value(assetInfo(assetId1)).decimals | |
244 | - | let assetId2Decimals = value(assetInfo(assetId2)).decimals | |
245 | - | let scaleDigits = ((assetId2Decimals - assetId1Decimals) + 8) | |
246 | - | pow(10, 0, scaleDigits, 0, 0, DOWN) | |
37 | + | func getPoolType (poolAddress) = { | |
38 | + | let version = valueOrErrorMessage(getString(poolAddress, "version"), "Pool is not initialized") | |
39 | + | if ((version == "1.0.0")) | |
40 | + | then "cpmm" | |
41 | + | else if ((version == "2.0.0")) | |
42 | + | then "flat" | |
43 | + | else if ((version == "3.0.0")) | |
44 | + | then "multycurve" | |
45 | + | else throw("Unknown version of pool") | |
247 | 46 | } | |
248 | 47 | ||
249 | 48 | ||
250 | - | func userAvailableSWOP (pool,user) = valueOrElse(getInteger(this, (((pool + "_") + toString(user)) + keyAvailableSWOP)), 0) | |
251 | - | ||
252 | - | ||
253 | - | func rewardInfo (pool) = { | |
254 | - | let totalRewardPerBlockCurrent = valueOrErrorMessage(getInteger(govAddress, keyTotalRewardPerBlockCurrent), ((("No data on the key: " + keyTotalRewardPerBlockCurrent) + " at address ") + toString(govAddress))) | |
255 | - | let totalRewardPerBlockPrevious = valueOrErrorMessage(getInteger(govAddress, keyTotalRewardPerBlockPrevious), ((("No data on the key: " + keyTotalRewardPerBlockPrevious) + " at address ") + toString(govAddress))) | |
256 | - | let rewardPoolFractionCurrent = valueOrErrorMessage(getInteger(govAddress, (pool + keyRewardPoolFractionCurrent)), (((("No data on the key: " + pool) + keyRewardPoolFractionCurrent) + " at address ") + toString(govAddress))) | |
257 | - | let rewardUpdateHeight = valueOrErrorMessage(getInteger(govAddress, keyRewardUpdateHeight), ((("No data on the key: " + keyRewardUpdateHeight) + " at address ") + toString(govAddress))) | |
258 | - | let poolRewardUpdateHeight = valueOrElse(getInteger(govAddress, (pool + keyHeightPoolFraction)), 0) | |
259 | - | let rewardPoolFractionPrevious = valueOrErrorMessage(getInteger(govAddress, (pool + keyRewardPoolFractionPrevious)), (((("No data on the key: " + pool) + keyRewardPoolFractionPrevious) + " at address ") + toString(govAddress))) | |
260 | - | let rewardPoolCurrent = fraction(totalRewardPerBlockCurrent, rewardPoolFractionCurrent, totalVoteShare) | |
261 | - | let rewardPoolPrevious = fraction(totalRewardPerBlockPrevious, rewardPoolFractionPrevious, totalVoteShare) | |
262 | - | if (if ((rewardPoolCurrent > totalRewardPerBlockCurrent)) | |
263 | - | then true | |
264 | - | else (rewardPoolPrevious > totalRewardPerBlockPrevious)) | |
265 | - | then throw("rewardPoolCurrent > totalRewardPerBlockCurrent or rewardPoolPrevious > totalRewardPerBlockPrevious") | |
266 | - | else $Tuple4(rewardPoolCurrent, rewardUpdateHeight, rewardPoolPrevious, poolRewardUpdateHeight) | |
267 | - | } | |
268 | - | ||
269 | - | ||
270 | - | func getLastInterestInfo (pool) = { | |
271 | - | let lastInterest = valueOrErrorMessage(getInteger(this, (pool + keyLastInterest)), (("No data on the key: " + pool) + keyLastInterest)) | |
272 | - | let lastInterestHeight = valueOrElse(getInteger(this, (pool + keyLastInterestHeight)), height) | |
273 | - | $Tuple2(lastInterestHeight, lastInterest) | |
274 | - | } | |
275 | - | ||
276 | - | ||
277 | - | func getUserInterestInfo (pool,userAddress) = { | |
278 | - | let userLastInterest = getInteger(this, (((pool + "_") + toString(userAddress)) + keyUserLastInterest)) | |
279 | - | let userShare = getInteger(this, (((pool + "_") + toString(userAddress)) + keyUserShareTokensLocked)) | |
280 | - | let lastInterest = valueOrErrorMessage(getInteger(this, (pool + keyLastInterest)), (("No data on the key: " + pool) + keyLastInterest)) | |
281 | - | let userLastInterestValue = match userLastInterest { | |
282 | - | case userLastInterest: Int => | |
283 | - | userLastInterest | |
284 | - | case _ => | |
285 | - | lastInterest | |
286 | - | } | |
287 | - | let userShareTokensAmount = match userShare { | |
288 | - | case userShare: Int => | |
289 | - | userShare | |
290 | - | case _ => | |
291 | - | 0 | |
292 | - | } | |
293 | - | $Tuple2(userLastInterestValue, userShareTokensAmount) | |
294 | - | } | |
295 | - | ||
296 | - | ||
297 | - | func calcInterest (lastInterestHeight,rewardUpdateHeight,poolRewardUpdateHeight,lastInterest,currentRewardPerBlock,shareTokenLocked,previousRewardPerBlock,shareAssetId,scaleValue,pmtAmount) = if ((shareTokenLocked == 0)) | |
298 | - | then 0 | |
299 | - | else if ((poolRewardUpdateHeight != 0)) | |
300 | - | then if (if ((rewardUpdateHeight > height)) | |
301 | - | then (rewardUpdateHeight == poolRewardUpdateHeight) | |
302 | - | else false) | |
303 | - | then { | |
304 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
305 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
306 | - | } | |
307 | - | else if (if ((height > rewardUpdateHeight)) | |
308 | - | then (rewardUpdateHeight != poolRewardUpdateHeight) | |
309 | - | else false) | |
310 | - | then { | |
311 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
312 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
313 | - | } | |
314 | - | else if (if (if ((height > rewardUpdateHeight)) | |
315 | - | then (rewardUpdateHeight == poolRewardUpdateHeight) | |
316 | - | else false) | |
317 | - | then (lastInterestHeight > rewardUpdateHeight) | |
318 | - | else false) | |
319 | - | then { | |
320 | - | let reward = (currentRewardPerBlock * (height - lastInterestHeight)) | |
321 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
322 | - | } | |
323 | - | else { | |
324 | - | let rewardAfterLastInterestBeforeReawardUpdate = (previousRewardPerBlock * (rewardUpdateHeight - lastInterestHeight)) | |
325 | - | let interestAfterUpdate = (lastInterest + fraction(rewardAfterLastInterestBeforeReawardUpdate, scaleValue, shareTokenLocked)) | |
326 | - | let reward = (currentRewardPerBlock * (height - rewardUpdateHeight)) | |
327 | - | (interestAfterUpdate + fraction(reward, scaleValue, shareTokenLocked)) | |
328 | - | } | |
329 | - | else if ((rewardUpdateHeight > height)) | |
330 | - | then { | |
331 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
332 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
333 | - | } | |
334 | - | else if ((lastInterestHeight > rewardUpdateHeight)) | |
335 | - | then { | |
336 | - | let reward = (currentRewardPerBlock * (height - lastInterestHeight)) | |
337 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
338 | - | } | |
339 | - | else { | |
340 | - | let rewardAfterLastInterestBeforeReawardUpdate = (previousRewardPerBlock * (rewardUpdateHeight - lastInterestHeight)) | |
341 | - | let interestAfterUpdate = (lastInterest + fraction(rewardAfterLastInterestBeforeReawardUpdate, scaleValue, shareTokenLocked)) | |
342 | - | let reward = (currentRewardPerBlock * (height - rewardUpdateHeight)) | |
343 | - | (interestAfterUpdate + fraction(reward, scaleValue, shareTokenLocked)) | |
344 | - | } | |
345 | - | ||
346 | - | ||
347 | - | func claimCalc (pool,caller,pmtAmount) = { | |
348 | - | let shareAssetId = getShareAssetId(pool) | |
349 | - | let scaleValue = calcScaleValue(SWOP, shareAssetId) | |
350 | - | let shareTokenLocked = getTotalShareTokenLocked(pool) | |
351 | - | let $t01352213587 = getLastInterestInfo(pool) | |
352 | - | let lastInterestHeight = $t01352213587._1 | |
353 | - | let lastInterest = $t01352213587._2 | |
354 | - | let $t01359213704 = rewardInfo(pool) | |
355 | - | let currentRewardPerBlock = $t01359213704._1 | |
356 | - | let rewardUpdateHeight = $t01359213704._2 | |
357 | - | let previousRewardPerBlock = $t01359213704._3 | |
358 | - | let poolRewardUpdateHeight = $t01359213704._4 | |
359 | - | let $t01370913788 = getUserInterestInfo(pool, caller) | |
360 | - | let userLastInterest = $t01370913788._1 | |
361 | - | let userShareTokensAmount = $t01370913788._2 | |
362 | - | let currentInterest = calcInterest(lastInterestHeight, rewardUpdateHeight, poolRewardUpdateHeight, lastInterest, currentRewardPerBlock, shareTokenLocked, previousRewardPerBlock, shareAssetId, scaleValue, pmtAmount) | |
363 | - | let claimAmount = fraction(userShareTokensAmount, (currentInterest - userLastInterest), scaleValue) | |
364 | - | let userNewInterest = currentInterest | |
365 | - | $Tuple4(userNewInterest, currentInterest, claimAmount, userShareTokensAmount) | |
366 | - | } | |
367 | - | ||
368 | - | ||
369 | - | func calculateProtocolReward (pool) = { | |
370 | - | let $t01430614371 = getLastInterestInfo(pool) | |
371 | - | let lastInterestHeight = $t01430614371._1 | |
372 | - | let lastInterest = $t01430614371._2 | |
373 | - | let $t01437614487 = rewardInfo(pool) | |
374 | - | let currentRewardPerBlock = $t01437614487._1 | |
375 | - | let rewardUpdateHeight = $t01437614487._2 | |
376 | - | let previousRewardPerBlock = $t01437614487._3 | |
377 | - | let poolRewardUpdateHeight = $t01437614487._4 | |
378 | - | let shareTokenLocked = getTotalShareTokenLocked(pool) | |
379 | - | if (if ((shareTokenLocked == 0)) | |
380 | - | then (poolRewardUpdateHeight == 0) | |
381 | - | else false) | |
382 | - | then if ((rewardUpdateHeight > height)) | |
383 | - | then { | |
384 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
385 | - | reward | |
386 | - | } | |
387 | - | else if ((lastInterestHeight > rewardUpdateHeight)) | |
388 | - | then { | |
389 | - | let reward = (currentRewardPerBlock * (height - lastInterestHeight)) | |
390 | - | reward | |
391 | - | } | |
392 | - | else { | |
393 | - | let rewardAfterLastInterestBeforeReawardUpdate = (previousRewardPerBlock * (rewardUpdateHeight - lastInterestHeight)) | |
394 | - | let reward = (currentRewardPerBlock * (height - rewardUpdateHeight)) | |
395 | - | (reward + rewardAfterLastInterestBeforeReawardUpdate) | |
396 | - | } | |
397 | - | else if (if ((shareTokenLocked == 0)) | |
398 | - | then (poolRewardUpdateHeight != 0) | |
399 | - | else false) | |
400 | - | then if (if ((rewardUpdateHeight > height)) | |
401 | - | then (rewardUpdateHeight == poolRewardUpdateHeight) | |
402 | - | else false) | |
403 | - | then { | |
404 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
405 | - | reward | |
406 | - | } | |
407 | - | else if (if ((height > rewardUpdateHeight)) | |
408 | - | then (rewardUpdateHeight != poolRewardUpdateHeight) | |
409 | - | else false) | |
410 | - | then { | |
411 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
412 | - | reward | |
413 | - | } | |
414 | - | else if (if (if ((height > rewardUpdateHeight)) | |
415 | - | then (rewardUpdateHeight == poolRewardUpdateHeight) | |
416 | - | else false) | |
417 | - | then (lastInterestHeight > rewardUpdateHeight) | |
418 | - | else false) | |
419 | - | then { | |
420 | - | let reward = (currentRewardPerBlock * (height - lastInterestHeight)) | |
421 | - | reward | |
422 | - | } | |
423 | - | else { | |
424 | - | let rewardAfterLastInterestBeforeReawardUpdate = (previousRewardPerBlock * (rewardUpdateHeight - lastInterestHeight)) | |
425 | - | let reward = (currentRewardPerBlock * (height - rewardUpdateHeight)) | |
426 | - | (reward + rewardAfterLastInterestBeforeReawardUpdate) | |
427 | - | } | |
428 | - | else 0 | |
429 | - | } | |
430 | - | ||
431 | - | ||
432 | - | func checkPmtAssetIdCorrect (pool,pmtAssetId) = { | |
433 | - | let poolShareAssetId = fromBase58String(getStringValue(value(addressFromString(pool)), "share_asset_id")) | |
434 | - | if ((pmtAssetId == poolShareAssetId)) | |
435 | - | then true | |
436 | - | else false | |
437 | - | } | |
438 | - | ||
439 | - | ||
440 | - | func getUserSWOPClaimedAmount (pool,user) = valueOrElse(getInteger(this, (((pool + "_") + toString(user)) + keyUserSWOPClaimedAmount)), 0) | |
441 | - | ||
442 | - | ||
443 | - | func suspend (cause) = [BooleanEntry(keyActive, false), StringEntry(keyCause, cause)] | |
49 | + | func getAddressIfValid (address) = toString(valueOrErrorMessage(addressFromString(address), (("Can't parse \"" + address) + "\" as address"))) | |
444 | 50 | ||
445 | 51 | ||
446 | 52 | @Callable(i) | |
447 | - | func init (earlyLP) = if (isDefined(getString(this, keySWOPid))) | |
448 | - | then throw("SWOP already initialized") | |
449 | - | else { | |
450 | - | let initAmount = 100000000000000 | |
451 | - | let SWOPissue = Issue("SWOP", "SWOP protocol token", initAmount, 8, true) | |
452 | - | let SWOPid = calculateAssetId(SWOPissue) | |
453 | - | [BooleanEntry(keyActive, true), Issue("SWOP", "SWOP protocol token", initAmount, 8, true), StringEntry(keySWOPid, toBase58String(SWOPid))] | |
454 | - | } | |
53 | + | func setAdmin () = valueOrElse(isSelfCall(i), [StringEntry(kAdminPubKey1, toBase58String(adminPubKey1)), StringEntry(kAdminPubKey2, toBase58String(adminPubKey2)), StringEntry(kAdminPubKey3, toBase58String(adminPubKey3)), StringEntry(kAdminInvokePubKey, toBase58String(adminPubKeyInvoke))]) | |
455 | 54 | ||
456 | 55 | ||
457 | 56 | ||
458 | 57 | @Callable(i) | |
459 | - | func initPoolShareFarming (pool) = if ((i.caller != this)) | |
460 | - | then throw("Only the DApp itself can call this function") | |
461 | - | else { | |
462 | - | let $t01746917572 = rewardInfo(pool) | |
463 | - | let currentReward = $t01746917572._1 | |
464 | - | let rewardUpdateHeight = $t01746917572._2 | |
465 | - | let previousRewardPerBlock = $t01746917572._3 | |
466 | - | let poolRewardUpdateHeight = $t01746917572._4 | |
467 | - | [IntegerEntry((pool + keyShareTokensLocked), 0), IntegerEntry((pool + keyLastInterest), 0), IntegerEntry((pool + keyLastInterestHeight), height)] | |
468 | - | } | |
58 | + | func addPool (poolAddress,poolName) = valueOrElse(isSelfCall(i), { | |
59 | + | let validatedAddress = getAddressIfValid(poolAddress) | |
60 | + | let keyName = (kPrefixPoolName + validatedAddress) | |
61 | + | let possiblyAlreadyAddedPool = getString(this, keyName) | |
62 | + | if (isDefined(possiblyAlreadyAddedPool)) | |
63 | + | then throw((((("Pool with address \"" + validatedAddress) + "\" is already defined with name \"") + value(possiblyAlreadyAddedPool)) + "\"")) | |
64 | + | else ([StringEntry(keyName, poolName)] ++ (if ((getPoolType(value(addressFromString(poolAddress))) == "multycurve")) | |
65 | + | then nil | |
66 | + | else { | |
67 | + | let assetIdA = valueOrErrorMessage(getString(value(addressFromString(poolAddress)), kAssetIdA), "Asset id A is incorrect") | |
68 | + | let assetIdB = valueOrErrorMessage(getString(value(addressFromString(poolAddress)), kAssetIdB), "Asset id B is incorrect") | |
69 | + | [StringEntry((((kPair + assetIdA) + "_") + assetIdB), poolAddress)] | |
70 | + | })) | |
71 | + | }) | |
469 | 72 | ||
470 | 73 | ||
471 | 74 | ||
472 | 75 | @Callable(i) | |
473 | - | func updatePoolInterest (pool) = if ((i.caller != moneyBoxAddress)) | |
474 | - | then throw("Only the Admin itself can call this function") | |
475 | - | else if (!(isActive)) | |
476 | - | then throw("DApp is inactive at this moment") | |
477 | - | else { | |
478 | - | let $t01799018123 = claimCalc(pool, addressFromPublicKey(adminInvokePubKey), 0) | |
479 | - | let userNewInterest = $t01799018123._1 | |
480 | - | let currentInterest = $t01799018123._2 | |
481 | - | let claimAmount = $t01799018123._3 | |
482 | - | let userShareTokensAmount = $t01799018123._4 | |
483 | - | let $t01812818231 = rewardInfo(pool) | |
484 | - | let currentReward = $t01812818231._1 | |
485 | - | let rewardUpdateHeight = $t01812818231._2 | |
486 | - | let previousRewardPerBlock = $t01812818231._3 | |
487 | - | let poolRewardUpdateHeight = $t01812818231._4 | |
488 | - | [IntegerEntry((pool + keyLastInterest), userNewInterest), IntegerEntry((pool + keyLastInterestHeight), height)] | |
489 | - | } | |
76 | + | func renamePool (poolAddress,newPoolName) = valueOrElse(isSelfCall(i), { | |
77 | + | let validatedAddress = getAddressIfValid(poolAddress) | |
78 | + | let keyName = (kPrefixPoolName + validatedAddress) | |
79 | + | let possiblyAlreadyAddedPool = getString(this, keyName) | |
80 | + | if (isDefined(possiblyAlreadyAddedPool)) | |
81 | + | then [StringEntry(keyName, newPoolName)] | |
82 | + | else throw((("Pool with address \"" + validatedAddress) + "\" has not yet been added")) | |
83 | + | }) | |
490 | 84 | ||
491 | 85 | ||
492 | 86 | ||
493 | 87 | @Callable(i) | |
494 | - | func lockShareTokens (pool) = { | |
495 | - | let $t01842318498 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
496 | - | let pmtAmount = $t01842318498._1 | |
497 | - | let pmtAssetId = $t01842318498._2 | |
498 | - | let $t01850318576 = getAssetInfo(pmtAssetId) | |
499 | - | let pmtStrAssetId = $t01850318576._1 | |
500 | - | let pmtAssetName = $t01850318576._2 | |
501 | - | let pmtDecimals = $t01850318576._3 | |
502 | - | let $t01858118698 = claimCalc(pool, i.originCaller, pmtAmount) | |
503 | - | let userNewInterest = $t01858118698._1 | |
504 | - | let currentInterest = $t01858118698._2 | |
505 | - | let claimAmount = $t01858118698._3 | |
506 | - | let userShareTokensAmount = $t01858118698._4 | |
507 | - | let userShareAmountNew = (userShareTokensAmount + pmtAmount) | |
508 | - | let availableFundsNew = (userAvailableSWOP(pool, i.originCaller) + claimAmount) | |
509 | - | let totalShareAmount = getTotalShareTokenLocked(pool) | |
510 | - | let totalShareAmountNew = (totalShareAmount + pmtAmount) | |
511 | - | let userClaimedAmount = getUserSWOPClaimedAmount(pool, i.originCaller) | |
512 | - | let userClaimedAmountNew = (userClaimedAmount + claimAmount) | |
513 | - | let baseEntry = [IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserLastInterest), userNewInterest), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserShareTokensLocked), userShareAmountNew), IntegerEntry((pool + keyShareTokensLocked), totalShareAmountNew), IntegerEntry((pool + keyLastInterest), currentInterest), IntegerEntry((pool + keyLastInterestHeight), height), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserSWOPClaimedAmount), userClaimedAmountNew), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserSWOPLastClaimedAmount), claimAmount), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyAvailableSWOP), availableFundsNew)] | |
514 | - | let uplp = if ((getString(Address(fromBase58String(pool)), "version") == "3.0.0")) | |
515 | - | then invoke(lpFarmingAddress, "updateUserInterest", [userShareAmountNew], nil) | |
516 | - | else 0 | |
517 | - | if ((uplp == uplp)) | |
518 | - | then if ((0 >= pmtAmount)) | |
519 | - | then throw("You can't lock token") | |
520 | - | else if (!(isActive)) | |
521 | - | then throw("DApp is inactive at this moment") | |
522 | - | else if (!(checkPmtAssetIdCorrect(pool, pmtAssetId))) | |
523 | - | then throw("Incorrect pmtAssetId") | |
524 | - | else if (if (isFirstHarvest(Address(fromBase58String(pool)))) | |
525 | - | then (getHeightFirstHarvest(Address(fromBase58String(pool))) > height) | |
526 | - | else false) | |
527 | - | then { | |
528 | - | let harvestPeriod = ((((getHeightFirstHarvest(Address(fromBase58String(pool))) - startHeight) + 1) / periodLength) - 1) | |
529 | - | let amountOfVoting = split(getStringValue(votingAddress, (((toString(i.originCaller) + "_") + pool) + "_user_pool_struc")), "_") | |
530 | - | let amountPoolStract = split(getStringValue(votingAddress, (pool + "_pool_struc")), "_") | |
531 | - | let amountActiveVoteUserPoolStract = split(valueOrElse(getString(votingAddress, (((toString(i.originCaller) + "_") + pool) + kHarvestUserPoolActiveVoteStrucVoting)), ""), "_") | |
532 | - | let amountPoolActiveVoteStract = split(valueOrElse(getString(votingAddress, (pool + kHarvestPoolActiveVoteStrucVoting)), ""), "_") | |
533 | - | let userShareTokenLocked = userShareTokensAmount | |
534 | - | let userPoolActiveVote = if ((toString(currPeriod) == amountOfVoting[2])) | |
535 | - | then valueOrElse(parseInt(amountActiveVoteUserPoolStract[0]), 0) | |
536 | - | else valueOrElse(parseInt(amountOfVoting[1]), 0) | |
537 | - | let poolActiveVote = if ((toString(currPeriod) == amountPoolStract[2])) | |
538 | - | then valueOrElse(parseInt(amountPoolActiveVoteStract[0]), 0) | |
539 | - | else valueOrElse(parseInt(amountPoolStract[1]), 0) | |
540 | - | let protocolReward = calculateProtocolReward(pool) | |
541 | - | if ((userPoolActiveVote != 0)) | |
542 | - | then { | |
543 | - | let limitShareToken = getShareLimitToken(addressFromStringValue(pool)) | |
544 | - | let shareToken = (fraction(limitShareToken, userPoolActiveVote, poolActiveVote) - userShareTokenLocked) | |
545 | - | if (if ((size(amountActiveVoteUserPoolStract) > 1)) | |
546 | - | then (valueOrElse(parseInt(amountActiveVoteUserPoolStract[1]), 0) >= harvestPeriod) | |
547 | - | else false) | |
548 | - | then throw("You can't share token") | |
549 | - | else if ((pmtAmount > limitShareToken)) | |
550 | - | then throw(("You can't share token more than " + toString(limitShareToken))) | |
551 | - | else if ((shareToken > 0)) | |
552 | - | then if ((fraction(99, (accountBalance(pmtAssetId) + pmtAmount), 100) > totalShareAmountNew)) | |
553 | - | then throw("Balance of share-token is greater than totalAmount") | |
554 | - | else if ((totalShareAmount == 0)) | |
555 | - | then (baseEntry ++ [Reissue(SWOP, protocolReward, true), ScriptTransfer(moneyBoxAddress, protocolReward, SWOP)]) | |
556 | - | else if ((shareToken >= pmtAmount)) | |
557 | - | then baseEntry | |
558 | - | else throw(("Your maximum share token is " + toString(shareToken))) | |
559 | - | else throw("You can't share token") | |
560 | - | } | |
561 | - | else throw("Your amount of token less than 0") | |
562 | - | } | |
563 | - | else baseEntry | |
564 | - | else throw("Strict value is not equal to itself.") | |
565 | - | } | |
88 | + | func launchpadDataTransactionStatus (status) = valueOrElse(isSelfCall(i), [BooleanEntry(kLaunchpadDataTransactionStatus, status)]) | |
566 | 89 | ||
567 | 90 | ||
568 | 91 | ||
569 | 92 | @Callable(i) | |
570 | - | func withdrawShareTokens (pool,shareTokensWithdrawAmount) = { | |
571 | - | let shareTokensId = fromBase58String(getStringValue(value(addressFromString(pool)), "share_asset_id")) | |
572 | - | let $t02331623427 = claimCalc(pool, i.originCaller, 1) | |
573 | - | let userNewInterest = $t02331623427._1 | |
574 | - | let currentInterest = $t02331623427._2 | |
575 | - | let claimAmount = $t02331623427._3 | |
576 | - | let userShareTokensAmount = $t02331623427._4 | |
577 | - | let userShareAmountNew = (userShareTokensAmount - shareTokensWithdrawAmount) | |
578 | - | let availableFundsNew = (userAvailableSWOP(pool, i.originCaller) + claimAmount) | |
579 | - | let totalShareAmount = getTotalShareTokenLocked(pool) | |
580 | - | let totalShareAmountNew = (totalShareAmount - shareTokensWithdrawAmount) | |
581 | - | let userClaimedAmount = getUserSWOPClaimedAmount(pool, i.originCaller) | |
582 | - | let userClaimedAmountNew = (userClaimedAmount + claimAmount) | |
583 | - | if ((shareTokensWithdrawAmount > userShareTokensAmount)) | |
584 | - | then throw("Withdraw amount more then user locked amount") | |
585 | - | else if (!(isActive)) | |
586 | - | then throw("DApp is inactive at this moment") | |
587 | - | else if ((shareTokensWithdrawAmount > userShareTokensAmount)) | |
588 | - | then throw("Withdraw amount more then user locked amount") | |
589 | - | else if ((fraction(99, (accountBalance(shareTokensId) - shareTokensWithdrawAmount), 100) > totalShareAmountNew)) | |
590 | - | then throw("Balance of share-token is greater than totalAmount") | |
591 | - | else { | |
592 | - | let uplp = if ((getString(Address(fromBase58String(pool)), "version") == "3.0.0")) | |
593 | - | then invoke(lpFarmingAddress, "updateUserInterest", [userShareAmountNew], nil) | |
594 | - | else 0 | |
595 | - | if ((uplp == uplp)) | |
596 | - | then [IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserLastInterest), userNewInterest), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserShareTokensLocked), userShareAmountNew), IntegerEntry((pool + keyLastInterest), currentInterest), IntegerEntry((pool + keyLastInterestHeight), height), IntegerEntry((pool + keyShareTokensLocked), totalShareAmountNew), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyAvailableSWOP), availableFundsNew), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserSWOPClaimedAmount), userClaimedAmountNew), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserSWOPLastClaimedAmount), claimAmount), ScriptTransfer(i.caller, shareTokensWithdrawAmount, shareTokensId)] | |
597 | - | else throw("Strict value is not equal to itself.") | |
598 | - | } | |
599 | - | } | |
93 | + | func addAchievementsWriter (address) = valueOrElse(isSelfCall(i), { | |
94 | + | let writers = valueOrElse(getString(this, kAchievementsWriters), "") | |
95 | + | let data = if ((writers == "")) | |
96 | + | then nil | |
97 | + | else split(writers, ",") | |
98 | + | [StringEntry(kAchievementsWriters, makeString((data :+ address), ","))] | |
99 | + | }) | |
600 | 100 | ||
601 | 101 | ||
602 | 102 | ||
603 | 103 | @Callable(i) | |
604 | - | func claim (pool) = { | |
605 | - | let shareTokensId = fromBase58String(getStringValue(value(addressFromString(pool)), "share_asset_id")) | |
606 | - | let shareTokenLocked = getTotalShareTokenLocked(pool) | |
607 | - | let $t02568925755 = getLastInterestInfo(pool) | |
608 | - | let lastInterestHeight = $t02568925755._1 | |
609 | - | let lastInterest = $t02568925755._2 | |
610 | - | let $t02576025874 = rewardInfo(pool) | |
611 | - | let currentRewardPerBlock = $t02576025874._1 | |
612 | - | let rewardUpdateHeight = $t02576025874._2 | |
613 | - | let previousRewardPerBlock = $t02576025874._3 | |
614 | - | let poolRewardUpdateHeight = $t02576025874._4 | |
615 | - | let $t02587925984 = claimCalc(pool, i.caller, 1) | |
616 | - | let userNewInterest = $t02587925984._1 | |
617 | - | let currentInterest = $t02587925984._2 | |
618 | - | let claimAmount = $t02587925984._3 | |
619 | - | let userShareTokensAmount = $t02587925984._4 | |
620 | - | let availableFund = (userAvailableSWOP(pool, i.caller) + claimAmount) | |
621 | - | let userClaimedAmount = getUserSWOPClaimedAmount(pool, i.caller) | |
622 | - | let userClaimedAmountNew = (userClaimedAmount + claimAmount) | |
623 | - | if ((availableFund == 0)) | |
624 | - | then throw("You have 0 available SWOP") | |
625 | - | else if (!(isActive)) | |
626 | - | then throw("DApp is inactive at this moment") | |
627 | - | else if ((availableFund == 0)) | |
628 | - | then throw("You have 0 available SWOP") | |
629 | - | else if ((fraction(99, accountBalance(shareTokensId), 100) > shareTokenLocked)) | |
630 | - | then throw("Balance of share-token is greater than totalAmount") | |
631 | - | else [IntegerEntry((((pool + "_") + toString(i.caller)) + keyUserLastInterest), userNewInterest), IntegerEntry((pool + keyLastInterest), currentInterest), IntegerEntry((pool + keyLastInterestHeight), height), IntegerEntry((((pool + "_") + toString(i.caller)) + keyAvailableSWOP), 0), Reissue(SWOP, availableFund, true), IntegerEntry((((pool + "_") + toString(i.caller)) + keyUserSWOPClaimedAmount), userClaimedAmountNew), IntegerEntry((((pool + "_") + toString(i.caller)) + keyUserSWOPLastClaimedAmount), claimAmount), ScriptTransfer(i.caller, availableFund, SWOP)] | |
632 | - | } | |
633 | - | ||
634 | - | ||
635 | - | ||
636 | - | @Callable(i) | |
637 | - | func shutdown () = if (!(isActive)) | |
638 | - | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, keyCause), "the cause wasn't specified"))) | |
639 | - | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
640 | - | then throw("Only admin can call this function") | |
641 | - | else suspend("Paused by admin") | |
642 | - | ||
643 | - | ||
644 | - | ||
645 | - | @Callable(i) | |
646 | - | func activate () = if (isActive) | |
647 | - | then throw("DApp is already active") | |
648 | - | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
649 | - | then throw("Only admin can call this function") | |
650 | - | else [BooleanEntry(keyActive, true), DeleteEntry(keyCause)] | |
104 | + | func removeAchievementsWriter (address) = valueOrElse(isSelfCall(i), { | |
105 | + | let writers = split(valueOrElse(getString(this, kAchievementsWriters), ""), ",") | |
106 | + | let index = valueOrErrorMessage(indexOf(writers, address), "Can't find address in the list") | |
107 | + | [StringEntry(kAchievementsWriters, makeString(removeByIndex(writers, index), ","))] | |
108 | + | }) | |
651 | 109 | ||
652 | 110 | ||
653 | 111 | @Verifier(tx) | |
654 | - | func verify () = match tx { | |
655 | - | case _ => | |
656 | - | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
657 | - | then 1 | |
658 | - | else 0 | |
659 | - | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
660 | - | then 1 | |
661 | - | else 0 | |
662 | - | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
663 | - | then 1 | |
664 | - | else 0 | |
665 | - | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
666 | - | } | |
112 | + | func verify () = { | |
113 | + | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
114 | + | then 1 | |
115 | + | else 0 | |
116 | + | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
117 | + | then 1 | |
118 | + | else 0 | |
119 | + | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
120 | + | then 1 | |
121 | + | else 0 | |
122 | + | let signedByAdmin = (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
123 | + | let signedByAdminToCallAddPool = (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 1) | |
124 | + | match tx { | |
125 | + | case inv: InvokeScriptTransaction => | |
126 | + | let isSelfInvokeRenamePool = if ((inv.dApp == this)) | |
127 | + | then containsElement(["renamePool"], inv.function) | |
128 | + | else false | |
129 | + | let isSelfInvokeSetAdmin = if ((inv.dApp == this)) | |
130 | + | then containsElement(["setAdmin"], inv.function) | |
131 | + | else false | |
132 | + | let isSelfInvokeAddPool = if ((inv.dApp == this)) | |
133 | + | then containsElement(["addPool"], inv.function) | |
134 | + | else false | |
135 | + | let isSelfInvokeLaunchpadDataTxStatus = if ((inv.dApp == this)) | |
136 | + | then containsElement(["launchpadDataTransactionStatus"], inv.function) | |
137 | + | else false | |
138 | + | let isSelfInvokeAddAchievementsWriter = if ((inv.dApp == this)) | |
139 | + | then containsElement(["addAchievementsWriter"], inv.function) | |
140 | + | else false | |
141 | + | let isSelfInvokeRemoveAchievementsWriter = if ((inv.dApp == this)) | |
142 | + | then containsElement(["removeAchievementsWriter"], inv.function) | |
143 | + | else false | |
144 | + | if (if (if (if (if (if (if (signedByAdmin) | |
145 | + | then (size(inv.payments) == 0) | |
146 | + | else false) | |
147 | + | then isSelfInvokeRenamePool | |
148 | + | else false) | |
149 | + | then true | |
150 | + | else if (if (signedByAdminToCallAddPool) | |
151 | + | then (size(inv.payments) == 0) | |
152 | + | else false) | |
153 | + | then isSelfInvokeAddPool | |
154 | + | else false) | |
155 | + | then true | |
156 | + | else if (if (signedByAdmin) | |
157 | + | then (size(inv.payments) == 0) | |
158 | + | else false) | |
159 | + | then isSelfInvokeSetAdmin | |
160 | + | else false) | |
161 | + | then true | |
162 | + | else if (if (signedByAdmin) | |
163 | + | then (size(inv.payments) == 0) | |
164 | + | else false) | |
165 | + | then isSelfInvokeLaunchpadDataTxStatus | |
166 | + | else false) | |
167 | + | then true | |
168 | + | else if (if (signedByAdmin) | |
169 | + | then (size(inv.payments) == 0) | |
170 | + | else false) | |
171 | + | then isSelfInvokeAddAchievementsWriter | |
172 | + | else false) | |
173 | + | then true | |
174 | + | else if (if (signedByAdmin) | |
175 | + | then (size(inv.payments) == 0) | |
176 | + | else false) | |
177 | + | then isSelfInvokeRemoveAchievementsWriter | |
178 | + | else false | |
179 | + | case _: Order|DataTransaction|SponsorFeeTransaction|SetScriptTransaction|CreateAliasTransaction|LeaseCancelTransaction|LeaseTransaction|IssueTransaction|InvokeExpressionTransaction|UpdateAssetInfoTransaction|InvokeScriptTransaction|SetAssetScriptTransaction|TransferTransaction|ExchangeTransaction|MassTransferTransaction|BurnTransaction|ReissueTransaction => | |
180 | + | signedByAdmin | |
181 | + | case _ => | |
182 | + | throw("Match error") | |
183 | + | } | |
184 | + | } | |
667 | 185 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let kPrefixPoolName = "pool_" | |
5 | 5 | ||
6 | - | let | |
6 | + | let kPair = "pair_" | |
7 | 7 | ||
8 | - | let | |
8 | + | let kAssetIdA = "A_asset_id" | |
9 | 9 | ||
10 | - | let | |
10 | + | let kAssetIdB = "B_asset_id" | |
11 | 11 | ||
12 | - | let keyRewardPoolFractionCurrent = "_current_pool_fraction_reward" | |
13 | - | ||
14 | - | let keyRewardPoolFractionPrevious = "_previous_pool_fraction_reward" | |
15 | - | ||
16 | - | let keyHeightPoolFraction = "_pool_reward_update_height" | |
17 | - | ||
18 | - | let keyTotalRewardPerBlockCurrent = "total_reward_per_block_current" | |
19 | - | ||
20 | - | let keyTotalRewardPerBlockPrevious = "total_reward_per_block_previous" | |
21 | - | ||
22 | - | let keyRewardUpdateHeight = "reward_update_height" | |
23 | - | ||
24 | - | let keyLastInterest = "_last_interest" | |
25 | - | ||
26 | - | let keyLastInterestHeight = "_last_interest_height" | |
27 | - | ||
28 | - | let keyUserShareTokensLocked = "_share_tokens_locked" | |
29 | - | ||
30 | - | let keyUserLastInterest = "_last_interest" | |
31 | - | ||
32 | - | let keySWOPid = "SWOP_id" | |
33 | - | ||
34 | - | let keyUserSWOPClaimedAmount = "_SWOP_claimed_amount" | |
35 | - | ||
36 | - | let keyUserSWOPLastClaimedAmount = "_SWOP_last_claimed_amount" | |
37 | - | ||
38 | - | let keyAvailableSWOP = "_available_SWOP" | |
39 | - | ||
40 | - | let keyFarmingStartHeight = "farming_start_height" | |
41 | - | ||
42 | - | let keyAPY = "apy" | |
43 | - | ||
44 | - | let kPreviousTotalVoteSWOP = "previous_total_vote_SWOP" | |
45 | - | ||
46 | - | let keySwopYearEmission = "swop_year_emission" | |
47 | - | ||
48 | - | let keyBalancecpmmA = "A_asset_balance" | |
49 | - | ||
50 | - | let keyBalancecpmmB = "B_asset_balance" | |
51 | - | ||
52 | - | let kHarvestPoolActiveVoteStrucVoting = "_harvest_pool_activeVote_struc" | |
53 | - | ||
54 | - | let kHarvestUserPoolActiveVoteStrucVoting = "_harvest_user_pool_activeVote_struc" | |
55 | - | ||
56 | - | let keyLimitShareFirstHarvest = "share_limit_on_first_harvest" | |
57 | - | ||
58 | - | let keyAssetIdA = "A_asset_id" | |
59 | - | ||
60 | - | let keyAssetIdB = "B_asset_id" | |
61 | - | ||
62 | - | let keyFirstHarvestHeight = "first_harvest_height" | |
63 | - | ||
64 | - | let keyfirstHarvestCpmm = "first_harvest" | |
65 | - | ||
66 | - | let keyTempPrevSum = "sum_reward_previous" | |
67 | - | ||
68 | - | let keyTempCurSum = "sum_reward_current" | |
69 | - | ||
70 | - | let oneWeekInBlock = 10106 | |
71 | - | ||
72 | - | let totalVoteShare = 10000000000 | |
73 | - | ||
74 | - | let scaleValue1 = 10 | |
75 | - | ||
76 | - | let scaleValue3 = 1000 | |
77 | - | ||
78 | - | let scaleValue5 = 100000 | |
79 | - | ||
80 | - | let scaleValue6 = 1000000 | |
81 | - | ||
82 | - | let scaleValue8 = 100000000 | |
83 | - | ||
84 | - | let scaleValue11 = 100000000000 | |
12 | + | let kLaunchpadDataTransactionStatus = "launchpad_data_transaction_status" | |
85 | 13 | ||
86 | 14 | let kAdminPubKey1 = "admin_pub_1" | |
87 | 15 | ||
88 | 16 | let kAdminPubKey2 = "admin_pub_2" | |
89 | 17 | ||
90 | 18 | let kAdminPubKey3 = "admin_pub_3" | |
91 | 19 | ||
92 | 20 | let kAdminInvokePubKey = "admin_invoke_pub" | |
93 | 21 | ||
94 | - | let | |
22 | + | let kAchievementsWriters = "achievements_writers" | |
95 | 23 | ||
96 | - | let | |
24 | + | let adminPubKey1 = base58'GFmKZ2naZFRoCvNbwKAQVGmLb1uBeWGDgFabdGBuZiuy' | |
97 | 25 | ||
98 | - | let | |
26 | + | let adminPubKey2 = base58'GmJXRyhRA79g8yUGgKBAVdnFfQFDMjQG98b1MmLDh5kk' | |
99 | 27 | ||
100 | - | let | |
28 | + | let adminPubKey3 = base58'CFhbV6h41hVjbGHudGtS3fYUv7QAKRxFQzKNtx4B5PqP' | |
101 | 29 | ||
102 | - | let | |
30 | + | let adminPubKeyInvoke = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
103 | 31 | ||
104 | - | func getBase58FromOracle (key) = match getString(oracle, key) { | |
105 | - | case string: String => | |
106 | - | fromBase58String(string) | |
107 | - | case nothing => | |
108 | - | throw((key + "is empty")) | |
109 | - | } | |
32 | + | func isSelfCall (i) = if ((i.caller == this)) | |
33 | + | then unit | |
34 | + | else throw("Only the Oracle itself can invoke this function") | |
110 | 35 | ||
111 | 36 | ||
112 | - | let adminPubKey1 = getBase58FromOracle(kAdminPubKey1) | |
113 | - | ||
114 | - | let adminPubKey2 = getBase58FromOracle(kAdminPubKey2) | |
115 | - | ||
116 | - | let adminPubKey3 = getBase58FromOracle(kAdminPubKey3) | |
117 | - | ||
118 | - | let moneyBoxAddress = Address(getBase58FromOracle(kMoneyBoxAddress)) | |
119 | - | ||
120 | - | let votingAddress = Address(getBase58FromOracle(kVotingAddress)) | |
121 | - | ||
122 | - | let govAddress = Address(getBase58FromOracle(kGovAddress)) | |
123 | - | ||
124 | - | let adminInvokePubKey = getBase58FromOracle(kAdminInvokePubKey) | |
125 | - | ||
126 | - | let lpFarmingAddress = Address(getBase58FromOracle(kLPFarmingAddress)) | |
127 | - | ||
128 | - | func strAssetIdA (pool) = getStringValue(pool, keyAssetIdA) | |
129 | - | ||
130 | - | ||
131 | - | func strAssetIdB (pool) = getStringValue(pool, keyAssetIdB) | |
132 | - | ||
133 | - | ||
134 | - | func assetIdA (pool) = if ((strAssetIdA(pool) == "WAVES")) | |
135 | - | then unit | |
136 | - | else fromBase58String(strAssetIdA(pool)) | |
137 | - | ||
138 | - | ||
139 | - | func assetIdB (pool) = if ((strAssetIdB(pool) == "WAVES")) | |
140 | - | then unit | |
141 | - | else fromBase58String(strAssetIdB(pool)) | |
142 | - | ||
143 | - | ||
144 | - | let kBasePeriod = "base_period" | |
145 | - | ||
146 | - | let kPeriodLength = "period_length" | |
147 | - | ||
148 | - | let kStartHeight = "start_height" | |
149 | - | ||
150 | - | let kFirstHarvestHeight = "first_harvest_height" | |
151 | - | ||
152 | - | let kDurationFullVotePower = "duration_full_vote_power" | |
153 | - | ||
154 | - | let kMinVotePower = "min_vote_power" | |
155 | - | ||
156 | - | let basePeriod = valueOrErrorMessage(getInteger(votingAddress, kBasePeriod), "Empty kBasePeriod") | |
157 | - | ||
158 | - | let startHeight = valueOrErrorMessage(getInteger(votingAddress, kStartHeight), "Empty kStartHeight") | |
159 | - | ||
160 | - | let periodLength = valueOrErrorMessage(getInteger(votingAddress, kPeriodLength), "Empty kPeriodLength") | |
161 | - | ||
162 | - | let durationFullVotePower = valueOrErrorMessage(getInteger(votingAddress, kDurationFullVotePower), "Empty kDurationFullVotePower") | |
163 | - | ||
164 | - | let minVotePower = valueOrErrorMessage(getInteger(votingAddress, kMinVotePower), "Empty kMinVotePower") | |
165 | - | ||
166 | - | let isActive = getBooleanValue(this, keyActive) | |
167 | - | ||
168 | - | let currPeriod = (basePeriod + ((height - startHeight) / periodLength)) | |
169 | - | ||
170 | - | func getLimitToken (pool) = valueOrElse(getIntegerValue(pool, keyLimitShareFirstHarvest), 0) | |
171 | - | ||
172 | - | ||
173 | - | let APY = getIntegerValue(this, keyAPY) | |
174 | - | ||
175 | - | let SwopYearEmission = getIntegerValue(this, keySwopYearEmission) | |
176 | - | ||
177 | - | func assetNameA (pool) = match assetIdA(pool) { | |
178 | - | case id: ByteVector => | |
179 | - | value(assetInfo(id)).name | |
180 | - | case waves: Unit => | |
181 | - | "WAVES" | |
182 | - | case _ => | |
183 | - | throw("Match error") | |
184 | - | } | |
185 | - | ||
186 | - | ||
187 | - | func assetNameB (pool) = match assetIdB(pool) { | |
188 | - | case id: ByteVector => | |
189 | - | value(assetInfo(id)).name | |
190 | - | case waves: Unit => | |
191 | - | "WAVES" | |
192 | - | case _ => | |
193 | - | throw("Match error") | |
194 | - | } | |
195 | - | ||
196 | - | ||
197 | - | let SWOP = fromBase58String(getStringValue(this, keySWOPid)) | |
198 | - | ||
199 | - | func isFirstHarvest (pool) = valueOrElse(getBoolean(pool, keyfirstHarvestCpmm), false) | |
200 | - | ||
201 | - | ||
202 | - | func getHeightFirstHarvest (pool) = valueOrElse(getInteger(pool, keyFirstHarvestHeight), 0) | |
203 | - | ||
204 | - | ||
205 | - | func getBalanceA (pool) = valueOrErrorMessage(getInteger(pool, keyBalancecpmmA), ("No data on the key: " + keyBalancecpmmA)) | |
206 | - | ||
207 | - | ||
208 | - | func getBalanceB (pool) = valueOrErrorMessage(getInteger(pool, keyBalancecpmmB), ("No data on the key: " + keyBalancecpmmB)) | |
209 | - | ||
210 | - | ||
211 | - | func getShareLimitToken (pool) = valueOrErrorMessage(getInteger(pool, kShareLimit), ("No data on the key: " + kShareLimit)) | |
212 | - | ||
213 | - | ||
214 | - | func getTotalShareTokenLocked (pool) = valueOrErrorMessage(getInteger(this, (pool + keyShareTokensLocked)), (("No data on the key: " + pool) + keyShareTokensLocked)) | |
215 | - | ||
216 | - | ||
217 | - | func getShareAssetId (pool) = fromBase58String(getStringValue(value(addressFromString(pool)), "share_asset_id")) | |
218 | - | ||
219 | - | ||
220 | - | func accountBalance (assetId) = match assetId { | |
221 | - | case id: ByteVector => | |
222 | - | assetBalance(this, id) | |
223 | - | case waves: Unit => | |
224 | - | wavesBalance(this).available | |
225 | - | case _ => | |
226 | - | throw("Match error") | |
227 | - | } | |
228 | - | ||
229 | - | ||
230 | - | func getAssetInfo (assetId) = match assetId { | |
231 | - | case id: ByteVector => | |
232 | - | let stringId = toBase58String(id) | |
233 | - | let info = valueOrErrorMessage(assetInfo(id), (("Asset " + stringId) + " doesn't exist")) | |
234 | - | $Tuple3(stringId, info.name, info.decimals) | |
235 | - | case waves: Unit => | |
236 | - | $Tuple3("WAVES", "WAVES", 8) | |
237 | - | case _ => | |
238 | - | throw("Match error") | |
239 | - | } | |
240 | - | ||
241 | - | ||
242 | - | func calcScaleValue (assetId1,assetId2) = { | |
243 | - | let assetId1Decimals = value(assetInfo(assetId1)).decimals | |
244 | - | let assetId2Decimals = value(assetInfo(assetId2)).decimals | |
245 | - | let scaleDigits = ((assetId2Decimals - assetId1Decimals) + 8) | |
246 | - | pow(10, 0, scaleDigits, 0, 0, DOWN) | |
37 | + | func getPoolType (poolAddress) = { | |
38 | + | let version = valueOrErrorMessage(getString(poolAddress, "version"), "Pool is not initialized") | |
39 | + | if ((version == "1.0.0")) | |
40 | + | then "cpmm" | |
41 | + | else if ((version == "2.0.0")) | |
42 | + | then "flat" | |
43 | + | else if ((version == "3.0.0")) | |
44 | + | then "multycurve" | |
45 | + | else throw("Unknown version of pool") | |
247 | 46 | } | |
248 | 47 | ||
249 | 48 | ||
250 | - | func userAvailableSWOP (pool,user) = valueOrElse(getInteger(this, (((pool + "_") + toString(user)) + keyAvailableSWOP)), 0) | |
251 | - | ||
252 | - | ||
253 | - | func rewardInfo (pool) = { | |
254 | - | let totalRewardPerBlockCurrent = valueOrErrorMessage(getInteger(govAddress, keyTotalRewardPerBlockCurrent), ((("No data on the key: " + keyTotalRewardPerBlockCurrent) + " at address ") + toString(govAddress))) | |
255 | - | let totalRewardPerBlockPrevious = valueOrErrorMessage(getInteger(govAddress, keyTotalRewardPerBlockPrevious), ((("No data on the key: " + keyTotalRewardPerBlockPrevious) + " at address ") + toString(govAddress))) | |
256 | - | let rewardPoolFractionCurrent = valueOrErrorMessage(getInteger(govAddress, (pool + keyRewardPoolFractionCurrent)), (((("No data on the key: " + pool) + keyRewardPoolFractionCurrent) + " at address ") + toString(govAddress))) | |
257 | - | let rewardUpdateHeight = valueOrErrorMessage(getInteger(govAddress, keyRewardUpdateHeight), ((("No data on the key: " + keyRewardUpdateHeight) + " at address ") + toString(govAddress))) | |
258 | - | let poolRewardUpdateHeight = valueOrElse(getInteger(govAddress, (pool + keyHeightPoolFraction)), 0) | |
259 | - | let rewardPoolFractionPrevious = valueOrErrorMessage(getInteger(govAddress, (pool + keyRewardPoolFractionPrevious)), (((("No data on the key: " + pool) + keyRewardPoolFractionPrevious) + " at address ") + toString(govAddress))) | |
260 | - | let rewardPoolCurrent = fraction(totalRewardPerBlockCurrent, rewardPoolFractionCurrent, totalVoteShare) | |
261 | - | let rewardPoolPrevious = fraction(totalRewardPerBlockPrevious, rewardPoolFractionPrevious, totalVoteShare) | |
262 | - | if (if ((rewardPoolCurrent > totalRewardPerBlockCurrent)) | |
263 | - | then true | |
264 | - | else (rewardPoolPrevious > totalRewardPerBlockPrevious)) | |
265 | - | then throw("rewardPoolCurrent > totalRewardPerBlockCurrent or rewardPoolPrevious > totalRewardPerBlockPrevious") | |
266 | - | else $Tuple4(rewardPoolCurrent, rewardUpdateHeight, rewardPoolPrevious, poolRewardUpdateHeight) | |
267 | - | } | |
268 | - | ||
269 | - | ||
270 | - | func getLastInterestInfo (pool) = { | |
271 | - | let lastInterest = valueOrErrorMessage(getInteger(this, (pool + keyLastInterest)), (("No data on the key: " + pool) + keyLastInterest)) | |
272 | - | let lastInterestHeight = valueOrElse(getInteger(this, (pool + keyLastInterestHeight)), height) | |
273 | - | $Tuple2(lastInterestHeight, lastInterest) | |
274 | - | } | |
275 | - | ||
276 | - | ||
277 | - | func getUserInterestInfo (pool,userAddress) = { | |
278 | - | let userLastInterest = getInteger(this, (((pool + "_") + toString(userAddress)) + keyUserLastInterest)) | |
279 | - | let userShare = getInteger(this, (((pool + "_") + toString(userAddress)) + keyUserShareTokensLocked)) | |
280 | - | let lastInterest = valueOrErrorMessage(getInteger(this, (pool + keyLastInterest)), (("No data on the key: " + pool) + keyLastInterest)) | |
281 | - | let userLastInterestValue = match userLastInterest { | |
282 | - | case userLastInterest: Int => | |
283 | - | userLastInterest | |
284 | - | case _ => | |
285 | - | lastInterest | |
286 | - | } | |
287 | - | let userShareTokensAmount = match userShare { | |
288 | - | case userShare: Int => | |
289 | - | userShare | |
290 | - | case _ => | |
291 | - | 0 | |
292 | - | } | |
293 | - | $Tuple2(userLastInterestValue, userShareTokensAmount) | |
294 | - | } | |
295 | - | ||
296 | - | ||
297 | - | func calcInterest (lastInterestHeight,rewardUpdateHeight,poolRewardUpdateHeight,lastInterest,currentRewardPerBlock,shareTokenLocked,previousRewardPerBlock,shareAssetId,scaleValue,pmtAmount) = if ((shareTokenLocked == 0)) | |
298 | - | then 0 | |
299 | - | else if ((poolRewardUpdateHeight != 0)) | |
300 | - | then if (if ((rewardUpdateHeight > height)) | |
301 | - | then (rewardUpdateHeight == poolRewardUpdateHeight) | |
302 | - | else false) | |
303 | - | then { | |
304 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
305 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
306 | - | } | |
307 | - | else if (if ((height > rewardUpdateHeight)) | |
308 | - | then (rewardUpdateHeight != poolRewardUpdateHeight) | |
309 | - | else false) | |
310 | - | then { | |
311 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
312 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
313 | - | } | |
314 | - | else if (if (if ((height > rewardUpdateHeight)) | |
315 | - | then (rewardUpdateHeight == poolRewardUpdateHeight) | |
316 | - | else false) | |
317 | - | then (lastInterestHeight > rewardUpdateHeight) | |
318 | - | else false) | |
319 | - | then { | |
320 | - | let reward = (currentRewardPerBlock * (height - lastInterestHeight)) | |
321 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
322 | - | } | |
323 | - | else { | |
324 | - | let rewardAfterLastInterestBeforeReawardUpdate = (previousRewardPerBlock * (rewardUpdateHeight - lastInterestHeight)) | |
325 | - | let interestAfterUpdate = (lastInterest + fraction(rewardAfterLastInterestBeforeReawardUpdate, scaleValue, shareTokenLocked)) | |
326 | - | let reward = (currentRewardPerBlock * (height - rewardUpdateHeight)) | |
327 | - | (interestAfterUpdate + fraction(reward, scaleValue, shareTokenLocked)) | |
328 | - | } | |
329 | - | else if ((rewardUpdateHeight > height)) | |
330 | - | then { | |
331 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
332 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
333 | - | } | |
334 | - | else if ((lastInterestHeight > rewardUpdateHeight)) | |
335 | - | then { | |
336 | - | let reward = (currentRewardPerBlock * (height - lastInterestHeight)) | |
337 | - | (lastInterest + fraction(reward, scaleValue, shareTokenLocked)) | |
338 | - | } | |
339 | - | else { | |
340 | - | let rewardAfterLastInterestBeforeReawardUpdate = (previousRewardPerBlock * (rewardUpdateHeight - lastInterestHeight)) | |
341 | - | let interestAfterUpdate = (lastInterest + fraction(rewardAfterLastInterestBeforeReawardUpdate, scaleValue, shareTokenLocked)) | |
342 | - | let reward = (currentRewardPerBlock * (height - rewardUpdateHeight)) | |
343 | - | (interestAfterUpdate + fraction(reward, scaleValue, shareTokenLocked)) | |
344 | - | } | |
345 | - | ||
346 | - | ||
347 | - | func claimCalc (pool,caller,pmtAmount) = { | |
348 | - | let shareAssetId = getShareAssetId(pool) | |
349 | - | let scaleValue = calcScaleValue(SWOP, shareAssetId) | |
350 | - | let shareTokenLocked = getTotalShareTokenLocked(pool) | |
351 | - | let $t01352213587 = getLastInterestInfo(pool) | |
352 | - | let lastInterestHeight = $t01352213587._1 | |
353 | - | let lastInterest = $t01352213587._2 | |
354 | - | let $t01359213704 = rewardInfo(pool) | |
355 | - | let currentRewardPerBlock = $t01359213704._1 | |
356 | - | let rewardUpdateHeight = $t01359213704._2 | |
357 | - | let previousRewardPerBlock = $t01359213704._3 | |
358 | - | let poolRewardUpdateHeight = $t01359213704._4 | |
359 | - | let $t01370913788 = getUserInterestInfo(pool, caller) | |
360 | - | let userLastInterest = $t01370913788._1 | |
361 | - | let userShareTokensAmount = $t01370913788._2 | |
362 | - | let currentInterest = calcInterest(lastInterestHeight, rewardUpdateHeight, poolRewardUpdateHeight, lastInterest, currentRewardPerBlock, shareTokenLocked, previousRewardPerBlock, shareAssetId, scaleValue, pmtAmount) | |
363 | - | let claimAmount = fraction(userShareTokensAmount, (currentInterest - userLastInterest), scaleValue) | |
364 | - | let userNewInterest = currentInterest | |
365 | - | $Tuple4(userNewInterest, currentInterest, claimAmount, userShareTokensAmount) | |
366 | - | } | |
367 | - | ||
368 | - | ||
369 | - | func calculateProtocolReward (pool) = { | |
370 | - | let $t01430614371 = getLastInterestInfo(pool) | |
371 | - | let lastInterestHeight = $t01430614371._1 | |
372 | - | let lastInterest = $t01430614371._2 | |
373 | - | let $t01437614487 = rewardInfo(pool) | |
374 | - | let currentRewardPerBlock = $t01437614487._1 | |
375 | - | let rewardUpdateHeight = $t01437614487._2 | |
376 | - | let previousRewardPerBlock = $t01437614487._3 | |
377 | - | let poolRewardUpdateHeight = $t01437614487._4 | |
378 | - | let shareTokenLocked = getTotalShareTokenLocked(pool) | |
379 | - | if (if ((shareTokenLocked == 0)) | |
380 | - | then (poolRewardUpdateHeight == 0) | |
381 | - | else false) | |
382 | - | then if ((rewardUpdateHeight > height)) | |
383 | - | then { | |
384 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
385 | - | reward | |
386 | - | } | |
387 | - | else if ((lastInterestHeight > rewardUpdateHeight)) | |
388 | - | then { | |
389 | - | let reward = (currentRewardPerBlock * (height - lastInterestHeight)) | |
390 | - | reward | |
391 | - | } | |
392 | - | else { | |
393 | - | let rewardAfterLastInterestBeforeReawardUpdate = (previousRewardPerBlock * (rewardUpdateHeight - lastInterestHeight)) | |
394 | - | let reward = (currentRewardPerBlock * (height - rewardUpdateHeight)) | |
395 | - | (reward + rewardAfterLastInterestBeforeReawardUpdate) | |
396 | - | } | |
397 | - | else if (if ((shareTokenLocked == 0)) | |
398 | - | then (poolRewardUpdateHeight != 0) | |
399 | - | else false) | |
400 | - | then if (if ((rewardUpdateHeight > height)) | |
401 | - | then (rewardUpdateHeight == poolRewardUpdateHeight) | |
402 | - | else false) | |
403 | - | then { | |
404 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
405 | - | reward | |
406 | - | } | |
407 | - | else if (if ((height > rewardUpdateHeight)) | |
408 | - | then (rewardUpdateHeight != poolRewardUpdateHeight) | |
409 | - | else false) | |
410 | - | then { | |
411 | - | let reward = (previousRewardPerBlock * (height - lastInterestHeight)) | |
412 | - | reward | |
413 | - | } | |
414 | - | else if (if (if ((height > rewardUpdateHeight)) | |
415 | - | then (rewardUpdateHeight == poolRewardUpdateHeight) | |
416 | - | else false) | |
417 | - | then (lastInterestHeight > rewardUpdateHeight) | |
418 | - | else false) | |
419 | - | then { | |
420 | - | let reward = (currentRewardPerBlock * (height - lastInterestHeight)) | |
421 | - | reward | |
422 | - | } | |
423 | - | else { | |
424 | - | let rewardAfterLastInterestBeforeReawardUpdate = (previousRewardPerBlock * (rewardUpdateHeight - lastInterestHeight)) | |
425 | - | let reward = (currentRewardPerBlock * (height - rewardUpdateHeight)) | |
426 | - | (reward + rewardAfterLastInterestBeforeReawardUpdate) | |
427 | - | } | |
428 | - | else 0 | |
429 | - | } | |
430 | - | ||
431 | - | ||
432 | - | func checkPmtAssetIdCorrect (pool,pmtAssetId) = { | |
433 | - | let poolShareAssetId = fromBase58String(getStringValue(value(addressFromString(pool)), "share_asset_id")) | |
434 | - | if ((pmtAssetId == poolShareAssetId)) | |
435 | - | then true | |
436 | - | else false | |
437 | - | } | |
438 | - | ||
439 | - | ||
440 | - | func getUserSWOPClaimedAmount (pool,user) = valueOrElse(getInteger(this, (((pool + "_") + toString(user)) + keyUserSWOPClaimedAmount)), 0) | |
441 | - | ||
442 | - | ||
443 | - | func suspend (cause) = [BooleanEntry(keyActive, false), StringEntry(keyCause, cause)] | |
49 | + | func getAddressIfValid (address) = toString(valueOrErrorMessage(addressFromString(address), (("Can't parse \"" + address) + "\" as address"))) | |
444 | 50 | ||
445 | 51 | ||
446 | 52 | @Callable(i) | |
447 | - | func init (earlyLP) = if (isDefined(getString(this, keySWOPid))) | |
448 | - | then throw("SWOP already initialized") | |
449 | - | else { | |
450 | - | let initAmount = 100000000000000 | |
451 | - | let SWOPissue = Issue("SWOP", "SWOP protocol token", initAmount, 8, true) | |
452 | - | let SWOPid = calculateAssetId(SWOPissue) | |
453 | - | [BooleanEntry(keyActive, true), Issue("SWOP", "SWOP protocol token", initAmount, 8, true), StringEntry(keySWOPid, toBase58String(SWOPid))] | |
454 | - | } | |
53 | + | func setAdmin () = valueOrElse(isSelfCall(i), [StringEntry(kAdminPubKey1, toBase58String(adminPubKey1)), StringEntry(kAdminPubKey2, toBase58String(adminPubKey2)), StringEntry(kAdminPubKey3, toBase58String(adminPubKey3)), StringEntry(kAdminInvokePubKey, toBase58String(adminPubKeyInvoke))]) | |
455 | 54 | ||
456 | 55 | ||
457 | 56 | ||
458 | 57 | @Callable(i) | |
459 | - | func initPoolShareFarming (pool) = if ((i.caller != this)) | |
460 | - | then throw("Only the DApp itself can call this function") | |
461 | - | else { | |
462 | - | let $t01746917572 = rewardInfo(pool) | |
463 | - | let currentReward = $t01746917572._1 | |
464 | - | let rewardUpdateHeight = $t01746917572._2 | |
465 | - | let previousRewardPerBlock = $t01746917572._3 | |
466 | - | let poolRewardUpdateHeight = $t01746917572._4 | |
467 | - | [IntegerEntry((pool + keyShareTokensLocked), 0), IntegerEntry((pool + keyLastInterest), 0), IntegerEntry((pool + keyLastInterestHeight), height)] | |
468 | - | } | |
58 | + | func addPool (poolAddress,poolName) = valueOrElse(isSelfCall(i), { | |
59 | + | let validatedAddress = getAddressIfValid(poolAddress) | |
60 | + | let keyName = (kPrefixPoolName + validatedAddress) | |
61 | + | let possiblyAlreadyAddedPool = getString(this, keyName) | |
62 | + | if (isDefined(possiblyAlreadyAddedPool)) | |
63 | + | then throw((((("Pool with address \"" + validatedAddress) + "\" is already defined with name \"") + value(possiblyAlreadyAddedPool)) + "\"")) | |
64 | + | else ([StringEntry(keyName, poolName)] ++ (if ((getPoolType(value(addressFromString(poolAddress))) == "multycurve")) | |
65 | + | then nil | |
66 | + | else { | |
67 | + | let assetIdA = valueOrErrorMessage(getString(value(addressFromString(poolAddress)), kAssetIdA), "Asset id A is incorrect") | |
68 | + | let assetIdB = valueOrErrorMessage(getString(value(addressFromString(poolAddress)), kAssetIdB), "Asset id B is incorrect") | |
69 | + | [StringEntry((((kPair + assetIdA) + "_") + assetIdB), poolAddress)] | |
70 | + | })) | |
71 | + | }) | |
469 | 72 | ||
470 | 73 | ||
471 | 74 | ||
472 | 75 | @Callable(i) | |
473 | - | func updatePoolInterest (pool) = if ((i.caller != moneyBoxAddress)) | |
474 | - | then throw("Only the Admin itself can call this function") | |
475 | - | else if (!(isActive)) | |
476 | - | then throw("DApp is inactive at this moment") | |
477 | - | else { | |
478 | - | let $t01799018123 = claimCalc(pool, addressFromPublicKey(adminInvokePubKey), 0) | |
479 | - | let userNewInterest = $t01799018123._1 | |
480 | - | let currentInterest = $t01799018123._2 | |
481 | - | let claimAmount = $t01799018123._3 | |
482 | - | let userShareTokensAmount = $t01799018123._4 | |
483 | - | let $t01812818231 = rewardInfo(pool) | |
484 | - | let currentReward = $t01812818231._1 | |
485 | - | let rewardUpdateHeight = $t01812818231._2 | |
486 | - | let previousRewardPerBlock = $t01812818231._3 | |
487 | - | let poolRewardUpdateHeight = $t01812818231._4 | |
488 | - | [IntegerEntry((pool + keyLastInterest), userNewInterest), IntegerEntry((pool + keyLastInterestHeight), height)] | |
489 | - | } | |
76 | + | func renamePool (poolAddress,newPoolName) = valueOrElse(isSelfCall(i), { | |
77 | + | let validatedAddress = getAddressIfValid(poolAddress) | |
78 | + | let keyName = (kPrefixPoolName + validatedAddress) | |
79 | + | let possiblyAlreadyAddedPool = getString(this, keyName) | |
80 | + | if (isDefined(possiblyAlreadyAddedPool)) | |
81 | + | then [StringEntry(keyName, newPoolName)] | |
82 | + | else throw((("Pool with address \"" + validatedAddress) + "\" has not yet been added")) | |
83 | + | }) | |
490 | 84 | ||
491 | 85 | ||
492 | 86 | ||
493 | 87 | @Callable(i) | |
494 | - | func lockShareTokens (pool) = { | |
495 | - | let $t01842318498 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
496 | - | let pmtAmount = $t01842318498._1 | |
497 | - | let pmtAssetId = $t01842318498._2 | |
498 | - | let $t01850318576 = getAssetInfo(pmtAssetId) | |
499 | - | let pmtStrAssetId = $t01850318576._1 | |
500 | - | let pmtAssetName = $t01850318576._2 | |
501 | - | let pmtDecimals = $t01850318576._3 | |
502 | - | let $t01858118698 = claimCalc(pool, i.originCaller, pmtAmount) | |
503 | - | let userNewInterest = $t01858118698._1 | |
504 | - | let currentInterest = $t01858118698._2 | |
505 | - | let claimAmount = $t01858118698._3 | |
506 | - | let userShareTokensAmount = $t01858118698._4 | |
507 | - | let userShareAmountNew = (userShareTokensAmount + pmtAmount) | |
508 | - | let availableFundsNew = (userAvailableSWOP(pool, i.originCaller) + claimAmount) | |
509 | - | let totalShareAmount = getTotalShareTokenLocked(pool) | |
510 | - | let totalShareAmountNew = (totalShareAmount + pmtAmount) | |
511 | - | let userClaimedAmount = getUserSWOPClaimedAmount(pool, i.originCaller) | |
512 | - | let userClaimedAmountNew = (userClaimedAmount + claimAmount) | |
513 | - | let baseEntry = [IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserLastInterest), userNewInterest), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserShareTokensLocked), userShareAmountNew), IntegerEntry((pool + keyShareTokensLocked), totalShareAmountNew), IntegerEntry((pool + keyLastInterest), currentInterest), IntegerEntry((pool + keyLastInterestHeight), height), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserSWOPClaimedAmount), userClaimedAmountNew), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserSWOPLastClaimedAmount), claimAmount), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyAvailableSWOP), availableFundsNew)] | |
514 | - | let uplp = if ((getString(Address(fromBase58String(pool)), "version") == "3.0.0")) | |
515 | - | then invoke(lpFarmingAddress, "updateUserInterest", [userShareAmountNew], nil) | |
516 | - | else 0 | |
517 | - | if ((uplp == uplp)) | |
518 | - | then if ((0 >= pmtAmount)) | |
519 | - | then throw("You can't lock token") | |
520 | - | else if (!(isActive)) | |
521 | - | then throw("DApp is inactive at this moment") | |
522 | - | else if (!(checkPmtAssetIdCorrect(pool, pmtAssetId))) | |
523 | - | then throw("Incorrect pmtAssetId") | |
524 | - | else if (if (isFirstHarvest(Address(fromBase58String(pool)))) | |
525 | - | then (getHeightFirstHarvest(Address(fromBase58String(pool))) > height) | |
526 | - | else false) | |
527 | - | then { | |
528 | - | let harvestPeriod = ((((getHeightFirstHarvest(Address(fromBase58String(pool))) - startHeight) + 1) / periodLength) - 1) | |
529 | - | let amountOfVoting = split(getStringValue(votingAddress, (((toString(i.originCaller) + "_") + pool) + "_user_pool_struc")), "_") | |
530 | - | let amountPoolStract = split(getStringValue(votingAddress, (pool + "_pool_struc")), "_") | |
531 | - | let amountActiveVoteUserPoolStract = split(valueOrElse(getString(votingAddress, (((toString(i.originCaller) + "_") + pool) + kHarvestUserPoolActiveVoteStrucVoting)), ""), "_") | |
532 | - | let amountPoolActiveVoteStract = split(valueOrElse(getString(votingAddress, (pool + kHarvestPoolActiveVoteStrucVoting)), ""), "_") | |
533 | - | let userShareTokenLocked = userShareTokensAmount | |
534 | - | let userPoolActiveVote = if ((toString(currPeriod) == amountOfVoting[2])) | |
535 | - | then valueOrElse(parseInt(amountActiveVoteUserPoolStract[0]), 0) | |
536 | - | else valueOrElse(parseInt(amountOfVoting[1]), 0) | |
537 | - | let poolActiveVote = if ((toString(currPeriod) == amountPoolStract[2])) | |
538 | - | then valueOrElse(parseInt(amountPoolActiveVoteStract[0]), 0) | |
539 | - | else valueOrElse(parseInt(amountPoolStract[1]), 0) | |
540 | - | let protocolReward = calculateProtocolReward(pool) | |
541 | - | if ((userPoolActiveVote != 0)) | |
542 | - | then { | |
543 | - | let limitShareToken = getShareLimitToken(addressFromStringValue(pool)) | |
544 | - | let shareToken = (fraction(limitShareToken, userPoolActiveVote, poolActiveVote) - userShareTokenLocked) | |
545 | - | if (if ((size(amountActiveVoteUserPoolStract) > 1)) | |
546 | - | then (valueOrElse(parseInt(amountActiveVoteUserPoolStract[1]), 0) >= harvestPeriod) | |
547 | - | else false) | |
548 | - | then throw("You can't share token") | |
549 | - | else if ((pmtAmount > limitShareToken)) | |
550 | - | then throw(("You can't share token more than " + toString(limitShareToken))) | |
551 | - | else if ((shareToken > 0)) | |
552 | - | then if ((fraction(99, (accountBalance(pmtAssetId) + pmtAmount), 100) > totalShareAmountNew)) | |
553 | - | then throw("Balance of share-token is greater than totalAmount") | |
554 | - | else if ((totalShareAmount == 0)) | |
555 | - | then (baseEntry ++ [Reissue(SWOP, protocolReward, true), ScriptTransfer(moneyBoxAddress, protocolReward, SWOP)]) | |
556 | - | else if ((shareToken >= pmtAmount)) | |
557 | - | then baseEntry | |
558 | - | else throw(("Your maximum share token is " + toString(shareToken))) | |
559 | - | else throw("You can't share token") | |
560 | - | } | |
561 | - | else throw("Your amount of token less than 0") | |
562 | - | } | |
563 | - | else baseEntry | |
564 | - | else throw("Strict value is not equal to itself.") | |
565 | - | } | |
88 | + | func launchpadDataTransactionStatus (status) = valueOrElse(isSelfCall(i), [BooleanEntry(kLaunchpadDataTransactionStatus, status)]) | |
566 | 89 | ||
567 | 90 | ||
568 | 91 | ||
569 | 92 | @Callable(i) | |
570 | - | func withdrawShareTokens (pool,shareTokensWithdrawAmount) = { | |
571 | - | let shareTokensId = fromBase58String(getStringValue(value(addressFromString(pool)), "share_asset_id")) | |
572 | - | let $t02331623427 = claimCalc(pool, i.originCaller, 1) | |
573 | - | let userNewInterest = $t02331623427._1 | |
574 | - | let currentInterest = $t02331623427._2 | |
575 | - | let claimAmount = $t02331623427._3 | |
576 | - | let userShareTokensAmount = $t02331623427._4 | |
577 | - | let userShareAmountNew = (userShareTokensAmount - shareTokensWithdrawAmount) | |
578 | - | let availableFundsNew = (userAvailableSWOP(pool, i.originCaller) + claimAmount) | |
579 | - | let totalShareAmount = getTotalShareTokenLocked(pool) | |
580 | - | let totalShareAmountNew = (totalShareAmount - shareTokensWithdrawAmount) | |
581 | - | let userClaimedAmount = getUserSWOPClaimedAmount(pool, i.originCaller) | |
582 | - | let userClaimedAmountNew = (userClaimedAmount + claimAmount) | |
583 | - | if ((shareTokensWithdrawAmount > userShareTokensAmount)) | |
584 | - | then throw("Withdraw amount more then user locked amount") | |
585 | - | else if (!(isActive)) | |
586 | - | then throw("DApp is inactive at this moment") | |
587 | - | else if ((shareTokensWithdrawAmount > userShareTokensAmount)) | |
588 | - | then throw("Withdraw amount more then user locked amount") | |
589 | - | else if ((fraction(99, (accountBalance(shareTokensId) - shareTokensWithdrawAmount), 100) > totalShareAmountNew)) | |
590 | - | then throw("Balance of share-token is greater than totalAmount") | |
591 | - | else { | |
592 | - | let uplp = if ((getString(Address(fromBase58String(pool)), "version") == "3.0.0")) | |
593 | - | then invoke(lpFarmingAddress, "updateUserInterest", [userShareAmountNew], nil) | |
594 | - | else 0 | |
595 | - | if ((uplp == uplp)) | |
596 | - | then [IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserLastInterest), userNewInterest), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserShareTokensLocked), userShareAmountNew), IntegerEntry((pool + keyLastInterest), currentInterest), IntegerEntry((pool + keyLastInterestHeight), height), IntegerEntry((pool + keyShareTokensLocked), totalShareAmountNew), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyAvailableSWOP), availableFundsNew), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserSWOPClaimedAmount), userClaimedAmountNew), IntegerEntry((((pool + "_") + toString(i.originCaller)) + keyUserSWOPLastClaimedAmount), claimAmount), ScriptTransfer(i.caller, shareTokensWithdrawAmount, shareTokensId)] | |
597 | - | else throw("Strict value is not equal to itself.") | |
598 | - | } | |
599 | - | } | |
93 | + | func addAchievementsWriter (address) = valueOrElse(isSelfCall(i), { | |
94 | + | let writers = valueOrElse(getString(this, kAchievementsWriters), "") | |
95 | + | let data = if ((writers == "")) | |
96 | + | then nil | |
97 | + | else split(writers, ",") | |
98 | + | [StringEntry(kAchievementsWriters, makeString((data :+ address), ","))] | |
99 | + | }) | |
600 | 100 | ||
601 | 101 | ||
602 | 102 | ||
603 | 103 | @Callable(i) | |
604 | - | func claim (pool) = { | |
605 | - | let shareTokensId = fromBase58String(getStringValue(value(addressFromString(pool)), "share_asset_id")) | |
606 | - | let shareTokenLocked = getTotalShareTokenLocked(pool) | |
607 | - | let $t02568925755 = getLastInterestInfo(pool) | |
608 | - | let lastInterestHeight = $t02568925755._1 | |
609 | - | let lastInterest = $t02568925755._2 | |
610 | - | let $t02576025874 = rewardInfo(pool) | |
611 | - | let currentRewardPerBlock = $t02576025874._1 | |
612 | - | let rewardUpdateHeight = $t02576025874._2 | |
613 | - | let previousRewardPerBlock = $t02576025874._3 | |
614 | - | let poolRewardUpdateHeight = $t02576025874._4 | |
615 | - | let $t02587925984 = claimCalc(pool, i.caller, 1) | |
616 | - | let userNewInterest = $t02587925984._1 | |
617 | - | let currentInterest = $t02587925984._2 | |
618 | - | let claimAmount = $t02587925984._3 | |
619 | - | let userShareTokensAmount = $t02587925984._4 | |
620 | - | let availableFund = (userAvailableSWOP(pool, i.caller) + claimAmount) | |
621 | - | let userClaimedAmount = getUserSWOPClaimedAmount(pool, i.caller) | |
622 | - | let userClaimedAmountNew = (userClaimedAmount + claimAmount) | |
623 | - | if ((availableFund == 0)) | |
624 | - | then throw("You have 0 available SWOP") | |
625 | - | else if (!(isActive)) | |
626 | - | then throw("DApp is inactive at this moment") | |
627 | - | else if ((availableFund == 0)) | |
628 | - | then throw("You have 0 available SWOP") | |
629 | - | else if ((fraction(99, accountBalance(shareTokensId), 100) > shareTokenLocked)) | |
630 | - | then throw("Balance of share-token is greater than totalAmount") | |
631 | - | else [IntegerEntry((((pool + "_") + toString(i.caller)) + keyUserLastInterest), userNewInterest), IntegerEntry((pool + keyLastInterest), currentInterest), IntegerEntry((pool + keyLastInterestHeight), height), IntegerEntry((((pool + "_") + toString(i.caller)) + keyAvailableSWOP), 0), Reissue(SWOP, availableFund, true), IntegerEntry((((pool + "_") + toString(i.caller)) + keyUserSWOPClaimedAmount), userClaimedAmountNew), IntegerEntry((((pool + "_") + toString(i.caller)) + keyUserSWOPLastClaimedAmount), claimAmount), ScriptTransfer(i.caller, availableFund, SWOP)] | |
632 | - | } | |
633 | - | ||
634 | - | ||
635 | - | ||
636 | - | @Callable(i) | |
637 | - | func shutdown () = if (!(isActive)) | |
638 | - | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, keyCause), "the cause wasn't specified"))) | |
639 | - | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
640 | - | then throw("Only admin can call this function") | |
641 | - | else suspend("Paused by admin") | |
642 | - | ||
643 | - | ||
644 | - | ||
645 | - | @Callable(i) | |
646 | - | func activate () = if (isActive) | |
647 | - | then throw("DApp is already active") | |
648 | - | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
649 | - | then throw("Only admin can call this function") | |
650 | - | else [BooleanEntry(keyActive, true), DeleteEntry(keyCause)] | |
104 | + | func removeAchievementsWriter (address) = valueOrElse(isSelfCall(i), { | |
105 | + | let writers = split(valueOrElse(getString(this, kAchievementsWriters), ""), ",") | |
106 | + | let index = valueOrErrorMessage(indexOf(writers, address), "Can't find address in the list") | |
107 | + | [StringEntry(kAchievementsWriters, makeString(removeByIndex(writers, index), ","))] | |
108 | + | }) | |
651 | 109 | ||
652 | 110 | ||
653 | 111 | @Verifier(tx) | |
654 | - | func verify () = match tx { | |
655 | - | case _ => | |
656 | - | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
657 | - | then 1 | |
658 | - | else 0 | |
659 | - | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
660 | - | then 1 | |
661 | - | else 0 | |
662 | - | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
663 | - | then 1 | |
664 | - | else 0 | |
665 | - | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
666 | - | } | |
112 | + | func verify () = { | |
113 | + | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
114 | + | then 1 | |
115 | + | else 0 | |
116 | + | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
117 | + | then 1 | |
118 | + | else 0 | |
119 | + | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
120 | + | then 1 | |
121 | + | else 0 | |
122 | + | let signedByAdmin = (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
123 | + | let signedByAdminToCallAddPool = (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 1) | |
124 | + | match tx { | |
125 | + | case inv: InvokeScriptTransaction => | |
126 | + | let isSelfInvokeRenamePool = if ((inv.dApp == this)) | |
127 | + | then containsElement(["renamePool"], inv.function) | |
128 | + | else false | |
129 | + | let isSelfInvokeSetAdmin = if ((inv.dApp == this)) | |
130 | + | then containsElement(["setAdmin"], inv.function) | |
131 | + | else false | |
132 | + | let isSelfInvokeAddPool = if ((inv.dApp == this)) | |
133 | + | then containsElement(["addPool"], inv.function) | |
134 | + | else false | |
135 | + | let isSelfInvokeLaunchpadDataTxStatus = if ((inv.dApp == this)) | |
136 | + | then containsElement(["launchpadDataTransactionStatus"], inv.function) | |
137 | + | else false | |
138 | + | let isSelfInvokeAddAchievementsWriter = if ((inv.dApp == this)) | |
139 | + | then containsElement(["addAchievementsWriter"], inv.function) | |
140 | + | else false | |
141 | + | let isSelfInvokeRemoveAchievementsWriter = if ((inv.dApp == this)) | |
142 | + | then containsElement(["removeAchievementsWriter"], inv.function) | |
143 | + | else false | |
144 | + | if (if (if (if (if (if (if (signedByAdmin) | |
145 | + | then (size(inv.payments) == 0) | |
146 | + | else false) | |
147 | + | then isSelfInvokeRenamePool | |
148 | + | else false) | |
149 | + | then true | |
150 | + | else if (if (signedByAdminToCallAddPool) | |
151 | + | then (size(inv.payments) == 0) | |
152 | + | else false) | |
153 | + | then isSelfInvokeAddPool | |
154 | + | else false) | |
155 | + | then true | |
156 | + | else if (if (signedByAdmin) | |
157 | + | then (size(inv.payments) == 0) | |
158 | + | else false) | |
159 | + | then isSelfInvokeSetAdmin | |
160 | + | else false) | |
161 | + | then true | |
162 | + | else if (if (signedByAdmin) | |
163 | + | then (size(inv.payments) == 0) | |
164 | + | else false) | |
165 | + | then isSelfInvokeLaunchpadDataTxStatus | |
166 | + | else false) | |
167 | + | then true | |
168 | + | else if (if (signedByAdmin) | |
169 | + | then (size(inv.payments) == 0) | |
170 | + | else false) | |
171 | + | then isSelfInvokeAddAchievementsWriter | |
172 | + | else false) | |
173 | + | then true | |
174 | + | else if (if (signedByAdmin) | |
175 | + | then (size(inv.payments) == 0) | |
176 | + | else false) | |
177 | + | then isSelfInvokeRemoveAchievementsWriter | |
178 | + | else false | |
179 | + | case _: Order|DataTransaction|SponsorFeeTransaction|SetScriptTransaction|CreateAliasTransaction|LeaseCancelTransaction|LeaseTransaction|IssueTransaction|InvokeExpressionTransaction|UpdateAssetInfoTransaction|InvokeScriptTransaction|SetAssetScriptTransaction|TransferTransaction|ExchangeTransaction|MassTransferTransaction|BurnTransaction|ReissueTransaction => | |
180 | + | signedByAdmin | |
181 | + | case _ => | |
182 | + | throw("Match error") | |
183 | + | } | |
184 | + | } | |
667 | 185 |
github/deemru/w8io/169f3d6 70.10 ms ◑