tx · Baaotz4McJhssGt25z1CFQP5Jr1jBRFAH5JaNJ547HEg

3NChGL86Z1gFcd6bgPxJyHSSEdPYdPkxmNv:  -0.00500000 Waves

2023.03.20 11:17 [2498081] smart account 3NChGL86Z1gFcd6bgPxJyHSSEdPYdPkxmNv > SELF 0.00000000 Waves

{ "type": 13, "id": "Baaotz4McJhssGt25z1CFQP5Jr1jBRFAH5JaNJ547HEg", "fee": 500000, "feeAssetId": null, "timestamp": 1679300236593, "version": 2, "chainId": 84, "sender": "3NChGL86Z1gFcd6bgPxJyHSSEdPYdPkxmNv", "senderPublicKey": "7WFp9MhGkKapUD5G1vwgWmy65Akv3eBnMThTsBDTcGgV", "proofs": [ "67LKYtjqGagXTdCfm15m1oGreHgHjbr2Nk31Jcot6CXSmFUXtppzkcUeJaXW4rz6maJsup4FfEvL54F8w4QqAJ7z" ], "script": null, "height": 2498081, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: DoZ6XRJkW323dmJbsJj2om9ZnhLhRmx7dFg7XF7tvUrv Next: none Full:
OldNewDifferences
1-{-# STDLIB_VERSION 5 #-}
2-{-# SCRIPT_TYPE ACCOUNT #-}
3-{-# CONTENT_TYPE DAPP #-}
4-let separator = "__"
5-
6-let keyFeeAmount = makeString(["%s", "fee"], separator)
7-
8-let keyUsdnAssetId = makeString(["%s", "usdnAssetId"], separator)
9-
10-let keyEpochLength = makeString(["%s", "epochLength"], separator)
11-
12-let keyFinalizeReward = makeString(["%s", "finalizeReward"], separator)
13-
14-let keyWxAssetId = makeString(["%s", "wxAssetId"], separator)
15-
16-let keyAssetsStoreContract = makeString(["%s", "assetsStoreContract"], separator)
17-
18-let keyUserPoolContract = makeString(["%s", "userPoolContract"], separator)
19-
20-let keyEmissionContract = makeString(["%s", "emissionContract"], separator)
21-
22-let keyBoostingContract = makeString(["%s", "boostingContract"], separator)
23-
24-let keyFactoryContract = makeString(["%s", "factoryContract"], separator)
25-
26-let keyVotingEmissionContract = makeString(["%s", "votingEmissionContract"], separator)
27-
28-let keyThreshold = makeString(["%s", "votingThreshold"], separator)
29-
30-func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), (key + " is not defined"))
31-
32-
33-func getIntOrFail (key) = valueOrErrorMessage(getInteger(this, key), (key + " is not defined"))
34-
35-
36-func keyInListAssetId (amountAssetId,priceAssetId) = makeString(["%s%s%s", "inList", amountAssetId, priceAssetId], separator)
37-
38-
39-func keySuggestIndex (amountAssetId,priceAssetId) = makeString(["%s%s%s", "suggestIndex", amountAssetId, priceAssetId], separator)
40-
41-
42-func keyStartHeight (amountAssetId,priceAssetId,suggestIndex) = makeString(["%s%s%s%d", "startHeight", amountAssetId, priceAssetId, toString(suggestIndex)], separator)
43-
44-
45-func keyVotingResult (amountAssetId,priceAssetId,suggestIndex) = makeString(["%s%s%s%d", "votingResult", amountAssetId, priceAssetId, toString(suggestIndex)], separator)
46-
47-
48-func totalVotes (totalYes,totalNo) = makeString(["%d%d", totalYes, totalNo], separator)
49-
50-
51-func keyVote (amountAssetId,priceAssetId,suggestIndex,voterAddress) = makeString(["%s%s%s%d%s", "vote", amountAssetId, priceAssetId, toString(suggestIndex), voterAddress], separator)
52-
53-
54-func keyVoteValue (gwxAmount,vote) = {
55- let key = if (vote)
56- then makeString(["%d%s", gwxAmount, "yes"], separator)
57- else makeString(["%d%s", gwxAmount, "no"], separator)
58- key
59- }
60-
61-
62-func keyInList (pool) = {
63- let $t025262566 = pool
64- let amountAssetId = $t025262566._1
65- let priceAssetId = $t025262566._2
66- makeString(["%s%s%s", "inList", amountAssetId, priceAssetId], separator)
67- }
68-
69-
70-func keyManagerPublicKey () = "%s__managerPublicKey"
71-
72-
73-func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
74-
75-
76-let assetsStoreContract = addressFromStringValue(getStringOrFail(keyAssetsStoreContract))
77-
78-let boostingContract = addressFromStringValue(getStringOrFail(keyBoostingContract))
79-
80-let emissionContract = addressFromStringValue(getStringOrFail(keyEmissionContract))
81-
82-let factoryContract = addressFromStringValue(getStringOrFail(keyFactoryContract))
83-
84-let userPoolContract = addressFromStringValue(getStringOrFail(keyUserPoolContract))
85-
86-let votingEmissionContract = addressFromStringValue(getStringOrFail(keyVotingEmissionContract))
87-
88-func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
89- case s: String =>
90- fromBase58String(s)
91- case _: Unit =>
92- unit
93- case _ =>
94- throw("Match error")
95-}
96-
97-
98-func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
99- case s: String =>
100- fromBase58String(s)
101- case _: Unit =>
102- unit
103- case _ =>
104- throw("Match error")
105-}
106-
107-
108-func isManager (i) = match managerPublicKeyOrUnit() {
109- case pk: ByteVector =>
110- (i.callerPublicKey == pk)
111- case _: Unit =>
112- (i.caller == this)
113- case _ =>
114- throw("Match error")
115-}
116-
117-
118-func mustManager (i) = if (isManager(i))
119- then true
120- else throw("permission denied")
121-
122-
123-func asInt (val) = match val {
124- case valInt: Int =>
125- valInt
126- case _ =>
127- throw("failed to cast into Integer")
128-}
129-
130-
131-@Callable(i)
132-func constructor (assetsStoreContractPrm,boostingContractPrm,emissionContractPrm,factoryContractPrm,userPoolContractPrm,votingEmissionContractPrm,feeAmountPrm,wxAssetIdPrm,votingDurationPrm,usdnAssetIdPrm,finalizeRewardPrm) = {
133- let checks = [mustManager(i), if (isDefined(addressFromString(assetsStoreContractPrm)))
134- then true
135- else throw("Invalid asset_store contract address"), if (isDefined(addressFromString(boostingContractPrm)))
136- then true
137- else throw("Invalid boosting contract address"), if (isDefined(addressFromString(userPoolContractPrm)))
138- then true
139- else throw("Invalid user_pools contract address"), if (isDefined(addressFromString(emissionContractPrm)))
140- then true
141- else throw("Invalid emission contract address"), if (isDefined(addressFromString(factoryContractPrm)))
142- then true
143- else throw("Invalid factory contract address"), if ((feeAmountPrm >= 0))
144- then true
145- else throw("Invalid fee amount"), if ((votingDurationPrm > 0))
146- then true
147- else throw("Invalid voting duration"), if ((finalizeRewardPrm >= 0))
148- then true
149- else throw("Invalid finalize reward"), if (isDefined(assetInfo(fromBase58String(wxAssetIdPrm))))
150- then true
151- else throw("Invalid WX asset ID"), if (isDefined(assetInfo(fromBase58String(usdnAssetIdPrm))))
152- then true
153- else throw("Invalid USDN asset ID")]
154- if ((checks == checks))
155- then $Tuple2([StringEntry(keyAssetsStoreContract, assetsStoreContractPrm), StringEntry(keyBoostingContract, boostingContractPrm), StringEntry(keyEmissionContract, emissionContractPrm), StringEntry(keyFactoryContract, factoryContractPrm), StringEntry(keyUserPoolContract, userPoolContractPrm), StringEntry(keyVotingEmissionContract, votingEmissionContractPrm), IntegerEntry(keyFeeAmount, feeAmountPrm), IntegerEntry(keyEpochLength, votingDurationPrm), IntegerEntry(keyFinalizeReward, finalizeRewardPrm), StringEntry(keyWxAssetId, wxAssetIdPrm), StringEntry(keyUsdnAssetId, usdnAssetIdPrm)], unit)
156- else throw("Strict value is not equal to itself.")
157- }
158-
159-
160-
161-@Callable(i)
162-func constructorV2 (threshold) = {
163- let checks = [mustManager(i), if ((threshold > 0))
164- then true
165- else throw("invalid threshold")]
166- if ((checks == checks))
167- then $Tuple2([IntegerEntry(keyThreshold, threshold)], unit)
168- else throw("Strict value is not equal to itself.")
169- }
170-
171-
172-
173-@Callable(i)
174-func suggest (amountAssetId,priceAssetId) = {
175- let pool = $Tuple2(amountAssetId, priceAssetId)
176- let payment = value(i.payments[0])
177- let checkAmountAsset = if ((amountAssetId == "WAVES"))
178- then unit
179- else {
180- let info = valueOrErrorMessage(assetInfo(fromBase58String(amountAssetId)), "invalid amountAssetId ID")
181- if ((info.scripted == false))
182- then true
183- else throw("asset is smart")
184- }
185- if ((checkAmountAsset == checkAmountAsset))
186- then {
187- let checks = [if ((toBase58String(value(payment.assetId)) == value(getString(keyWxAssetId))))
188- then true
189- else throw("invalid fee asset"), if ((payment.amount == value(getInteger(keyFeeAmount))))
190- then true
191- else throw("invalid fee amount"), if ((getInteger(keyInListAssetId(amountAssetId, priceAssetId)) == unit))
192- then true
193- else throw("already in voting list"), if (!(valueOrElse(getBoolean(votingEmissionContract, keyInList(pool)), false)))
194- then true
195- else throw("pool is in emission voting list")]
196- if ((checks == checks))
197- then {
198- let ensureActive = match invoke(userPoolContract, "statusREADONLY", [amountAssetId, priceAssetId], nil) {
199- case s: String =>
200- if ((s == "active"))
201- then true
202- else throw("user pool is not active")
203- case _ =>
204- throw("user pool is not active")
205- }
206- if ((ensureActive == ensureActive))
207- then {
208- let ensureAmountAssetVerified = if (isManager(i))
209- then unit
210- else {
211- let inv = match invoke(assetsStoreContract, "isVerifiedREADONLY", [amountAssetId], nil) {
212- case b: Boolean =>
213- if (b)
214- then true
215- else throw("asset is not verified")
216- case _ =>
217- throw("asset is not verified")
218- }
219- if ((inv == inv))
220- then unit
221- else throw("Strict value is not equal to itself.")
222- }
223- if ((ensureAmountAssetVerified == ensureAmountAssetVerified))
224- then {
225- let burnFeeInv = invoke(emissionContract, "burn", nil, [AttachedPayment(payment.assetId, payment.amount)])
226- if ((burnFeeInv == burnFeeInv))
227- then {
228- let newSuggestIndex = match getInteger(keySuggestIndex(amountAssetId, priceAssetId)) {
229- case int: Int =>
230- (int + 1)
231- case _ =>
232- 0
233- }
234- $Tuple2([IntegerEntry(keyInListAssetId(amountAssetId, priceAssetId), newSuggestIndex), IntegerEntry(keyStartHeight(amountAssetId, priceAssetId, newSuggestIndex), height), StringEntry(keyVotingResult(amountAssetId, priceAssetId, newSuggestIndex), totalVotes("0", "0")), IntegerEntry(keySuggestIndex(amountAssetId, priceAssetId), newSuggestIndex)], unit)
235- }
236- else throw("Strict value is not equal to itself.")
237- }
238- else throw("Strict value is not equal to itself.")
239- }
240- else throw("Strict value is not equal to itself.")
241- }
242- else throw("Strict value is not equal to itself.")
243- }
244- else throw("Strict value is not equal to itself.")
245- }
246-
247-
248-
249-@Callable(i)
250-func vote (amountAssetId,priceAssetId,inFavor) = {
251- let suggestIndex = value(getInteger(keyInListAssetId(amountAssetId, priceAssetId)))
252- let votingFinishHeight = (value(getInteger(keyStartHeight(amountAssetId, priceAssetId, suggestIndex))) + value(getInteger(keyEpochLength)))
253- let checks = [if (isDefined(getInteger(keyInListAssetId(amountAssetId, priceAssetId))))
254- then true
255- else throw("the token isn't on the voting list"), if ((votingFinishHeight > height))
256- then true
257- else throw("too late to vote")]
258- if ((checks == checks))
259- then {
260- let gwxAmount = invoke(boostingContract, "getUserGwxAmountAtHeightREADONLY", [toString(i.caller), votingFinishHeight], nil)
261- let notZero = if ((asInt(gwxAmount) > 0))
262- then true
263- else throw("you don't have gwx")
264- if ((notZero == notZero))
265- then {
266- let vote = match getString(keyVote(amountAssetId, priceAssetId, suggestIndex, toString(i.caller))) {
267- case s: String =>
268- let vote = split(s, separator)
269- let voteValue = vote[1]
270- let voteType = vote[2]
271- let isVoteTypeSimilar = if (if ((voteType == "yes"))
272- then (inFavor == true)
273- else false)
274- then true
275- else if ((voteType == "no"))
276- then (inFavor == false)
277- else false
278- let isVoteValueSimilar = if (isVoteTypeSimilar)
279- then (asInt(gwxAmount) == parseIntValue(voteValue))
280- else false
281- let isNewVoteSimilar = if (if (isVoteTypeSimilar)
282- then isVoteValueSimilar
283- else false)
284- then throw("you already voted")
285- else invoke(this, "cancelVote", [amountAssetId, priceAssetId], nil)
286- isNewVoteSimilar
287- case u: Unit =>
288- u
289- case _ =>
290- throw("Match error")
291- }
292- if ((vote == vote))
293- then {
294- let votingResult = split(value(getString(keyVotingResult(amountAssetId, priceAssetId, suggestIndex))), separator)
295- let positiveVotes = votingResult[1]
296- let negativeVotes = votingResult[2]
297- let newPositiveAndNegativeVotes = if (inFavor)
298- then {
299- let newPositiveVotes = (parseIntValue(positiveVotes) + asInt(gwxAmount))
300-[toString(newPositiveVotes), negativeVotes]
301- }
302- else {
303- let newNegativeVotes = (parseIntValue(negativeVotes) + asInt(gwxAmount))
304-[positiveVotes, toString(newNegativeVotes)]
305- }
306- let voteKey = keyVote(amountAssetId, priceAssetId, suggestIndex, toString(i.caller))
307- let voteValue = keyVoteValue(toString(asInt(gwxAmount)), inFavor)
308- $Tuple2([StringEntry(keyVotingResult(amountAssetId, priceAssetId, suggestIndex), totalVotes(newPositiveAndNegativeVotes[0], newPositiveAndNegativeVotes[1])), StringEntry(voteKey, voteValue)], unit)
309- }
310- else throw("Strict value is not equal to itself.")
311- }
312- else throw("Strict value is not equal to itself.")
313- }
314- else throw("Strict value is not equal to itself.")
315- }
316-
317-
318-
319-@Callable(i)
320-func cancelVote (amountAssetId,priceAssetId) = {
321- let userAddress = if ((i.caller == this))
322- then toString(i.originCaller)
323- else toString(i.caller)
324- let suggestIndex = value(getInteger(keyInListAssetId(amountAssetId, priceAssetId)))
325- let checks = [if (isDefined(getString(keyVotingResult(amountAssetId, priceAssetId, suggestIndex))))
326- then true
327- else throw("no vote for assets pair")]
328- if ((checks == checks))
329- then {
330- let vote = split(value(getString(keyVote(amountAssetId, priceAssetId, suggestIndex, userAddress))), separator)
331- let voteValue = vote[1]
332- let voteType = vote[2]
333- let votingResult = split(value(getString(keyVotingResult(amountAssetId, priceAssetId, suggestIndex))), separator)
334- let positiveVotes = votingResult[1]
335- let negativeVotes = votingResult[2]
336- let actions = if ((voteType == "yes"))
337- then {
338- let newPositiveVotes = (parseIntValue(positiveVotes) - parseIntValue(voteValue))
339- $Tuple2([StringEntry(keyVotingResult(amountAssetId, priceAssetId, suggestIndex), totalVotes(toString(newPositiveVotes), negativeVotes)), DeleteEntry(keyVote(amountAssetId, priceAssetId, suggestIndex, userAddress))], unit)
340- }
341- else {
342- let newNegativeVotes = (parseIntValue(negativeVotes) - parseIntValue(voteValue))
343- $Tuple2([StringEntry(keyVotingResult(amountAssetId, priceAssetId, suggestIndex), totalVotes(positiveVotes, toString(newNegativeVotes))), DeleteEntry(keyVote(amountAssetId, priceAssetId, suggestIndex, userAddress))], unit)
344- }
345- actions
346- }
347- else throw("Strict value is not equal to itself.")
348- }
349-
350-
351-
352-@Callable(i)
353-func setFee (newFee) = {
354- let checks = [mustManager(i)]
355- if ((checks == checks))
356- then [IntegerEntry(keyFeeAmount, newFee)]
357- else throw("Strict value is not equal to itself.")
358- }
359-
360-
361-
362-@Callable(i)
363-func setThreshold (newThreshold) = {
364- let checks = [mustManager(i), if ((newThreshold > 0))
365- then true
366- else throw("invalid threshold")]
367- if ((checks == checks))
368- then $Tuple2([IntegerEntry(keyThreshold, newThreshold)], unit)
369- else throw("Strict value is not equal to itself.")
370- }
371-
372-
373-
374-@Callable(i)
375-func finalize (amountAssetId,priceAssetId) = {
376- let suggestIndex = value(getInteger(keyInListAssetId(amountAssetId, priceAssetId)))
377- let votingFinishHeight = (value(getInteger(keyStartHeight(amountAssetId, priceAssetId, suggestIndex))) + value(getInteger(keyEpochLength)))
378- let checks = [if (isDefined(getInteger(keyInListAssetId(amountAssetId, priceAssetId))))
379- then true
380- else throw("no assets pair"), if ((height >= votingFinishHeight))
381- then true
382- else throw("insufficient height for completion")]
383- if ((checks == checks))
384- then {
385- let votingResult = split(value(getString(keyVotingResult(amountAssetId, priceAssetId, suggestIndex))), separator)
386- let positiveVotes = parseIntValue(votingResult[1])
387- let negativeVotes = parseIntValue(votingResult[2])
388- let allVotes = (positiveVotes + negativeVotes)
389- let threshold = getIntOrFail(keyThreshold)
390- let actions = if (if ((allVotes >= threshold))
391- then (positiveVotes > negativeVotes)
392- else false)
393- then {
394- let res = invoke(factoryContract, "setWxEmissionPoolLabel", [amountAssetId, priceAssetId], nil)
395- if ((res == res))
396- then {
397- let votingEmissionInv = invoke(votingEmissionContract, "create", [amountAssetId, priceAssetId], nil)
398- if ((votingEmissionInv == votingEmissionInv))
399- then $Tuple2([DeleteEntry(keyInListAssetId(amountAssetId, priceAssetId))], unit)
400- else throw("Strict value is not equal to itself.")
401- }
402- else throw("Strict value is not equal to itself.")
403- }
404- else $Tuple2([DeleteEntry(keyInListAssetId(amountAssetId, priceAssetId))], unit)
405- actions
406- }
407- else throw("Strict value is not equal to itself.")
408- }
409-
410-
411-
412-@Callable(i)
413-func setManager (pendingManagerPublicKey) = {
414- let checkCaller = mustManager(i)
415- if ((checkCaller == checkCaller))
416- then {
417- let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
418- if ((checkManagerPublicKey == checkManagerPublicKey))
419- then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
420- else throw("Strict value is not equal to itself.")
421- }
422- else throw("Strict value is not equal to itself.")
423- }
424-
425-
426-
427-@Callable(i)
428-func confirmManager () = {
429- let pm = pendingManagerPublicKeyOrUnit()
430- let hasPM = if (isDefined(pm))
431- then true
432- else throw("no pending manager")
433- if ((hasPM == hasPM))
434- then {
435- let checkPM = if ((i.callerPublicKey == value(pm)))
436- then true
437- else throw("you are not pending manager")
438- if ((checkPM == checkPM))
439- then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
440- else throw("Strict value is not equal to itself.")
441- }
442- else throw("Strict value is not equal to itself.")
443- }
444-
445-
446-@Verifier(tx)
447-func verify () = {
448- let targetPublicKey = match managerPublicKeyOrUnit() {
449- case pk: ByteVector =>
450- pk
451- case _: Unit =>
452- tx.senderPublicKey
453- case _ =>
454- throw("Match error")
455- }
456- sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
457- }
458-
1+# no script

github/deemru/w8io/873ac7e 
90.75 ms