tx · 2AnQUPScjXu7B8u5ETtoD7VLeAFPRozVwoThe5HBHnr6

3Mzep1R5kHeC1ecKFkWjuhU3Gw4LAdCib9N:  -0.01000000 Waves

2023.11.14 09:01 [2842619] smart account 3Mzep1R5kHeC1ecKFkWjuhU3Gw4LAdCib9N > SELF 0.00000000 Waves

{ "type": 13, "id": "2AnQUPScjXu7B8u5ETtoD7VLeAFPRozVwoThe5HBHnr6", "fee": 1000000, "feeAssetId": null, "timestamp": 1699941664038, "version": 2, "chainId": 84, "sender": "3Mzep1R5kHeC1ecKFkWjuhU3Gw4LAdCib9N", "senderPublicKey": "41THq9VrFxHEvVGJyz2oMpJQErnSkkqJXpBypSDxa5Mv", "proofs": [ "bmqRy2qPvT769wGS9q8VAkGVZtFcrULs9ZmszGxN6mLAn2oPu7SsSjuX11caQM1Yh9tM4JRq3WfaPUZwh2nga4o" ], "script": "base64:BgIYCAISAwoBGBIDCgEYEgQKAgIYEgQKAgIYFQAJc2VwYXJhdG9yAgJfXwAHY2hhaW5JZAkAyQECCQDKAQIIBQR0aGlzBWJ5dGVzAAEAAQAIY2hhaW5JZFQBAVQACGNoYWluSWRXAQFXAQttdXN0QWRkcmVzcwIBaQdhZGRyZXNzAwkAAAIIBQFpBmNhbGxlcgUHYWRkcmVzcwYJAAIBAhFwZXJtaXNzaW9uIGRlbmllZAEIbXVzdFRoaXMBAWkJAQttdXN0QWRkcmVzcwIFAWkFBHRoaXMAA1NFUAICX18ABVdBVkVTAgVXQVZFUwAQY29udHJhY3RGaWxlbmFtZQIVd3hkYW9fY2FsY3VsYXRvci5yaWRlAQd3cmFwRXJyAQFzCQCsAgIJAKwCAgUQY29udHJhY3RGaWxlbmFtZQICOiAFAXMBCHRocm93RXJyAQFzCQACAQkBB3dyYXBFcnIBBQFzARVrZXlQb3dlckNvbmZpZ0FkZHJlc3MAAhYlc19fcG93ZXJDb25maWdBZGRyZXNzARJwb3dlckNvbmZpZ0FkZHJlc3MBDmZhY3RvcnlBZGRyZXNzC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"succeeded", "spentComplexity": 0 } View: original | compacted Prev: L5dEc1bUtmwWiQh1Ho2vr4FeSaASoWXhERhWsKD5y4T Next: CaqBX449oHEdueMRrQmTPCUVDrq7tY9fTmcGJZLAvXon Diff:
OldNewDifferences
2121
2222 let WAVES = "WAVES"
2323
24-let contractFilename = "wxdao_factory.ride"
24+let contractFilename = "wxdao_calculator.ride"
2525
2626 func wrapErr (s) = ((contractFilename + ": ") + s)
2727
2929 func throwErr (s) = throw(wrapErr(s))
3030
3131
32-func stringToAssetId (s) = if ((s == WAVES))
33- then unit
34- else fromBase58String(s)
32+func keyPowerConfigAddress () = "%s__powerConfigAddress"
3533
3634
37-let ADMIN_LIST_SIZE = 5
38-
39-let QUORUM = 3
40-
41-let TXID_BYTES_LENGTH = 32
42-
43-func keyAllowedTxIdVotePrefix (txId) = makeString(["%s%s%s", "allowTxId", txId], SEP)
44-
45-
46-func keyFullAdminVote (prefix,adminAddress) = makeString([prefix, adminAddress], SEP)
47-
48-
49-func keyAdminAddressList () = makeString(["%s", "adminAddressList"], SEP)
50-
51-
52-func keyAllowedTxId () = makeString(["%s", "txId"], SEP)
53-
54-
55-func getAdminVote (prefix,admin) = {
56- let voteKey = keyFullAdminVote(prefix, admin)
57- valueOrElse(getInteger(voteKey), 0)
58- }
59-
60-
61-func getAdminsList () = match getString(this, keyAdminAddressList()) {
62- case s: String =>
63- split(s, SEP)
64- case _ =>
65- nil
66-}
67-
68-
69-func isInAdminList (address) = containsElement(getAdminsList(), address)
70-
71-
72-func genVotesKeysHelper (a,adminAddress) = {
73- let $t014801504 = a
74- let result = $t014801504._1
75- let prefix = $t014801504._2
76- $Tuple2((result :+ keyFullAdminVote(prefix, adminAddress)), prefix)
77- }
78-
79-
80-func genVotesKeys (keyPrefix) = {
81- let adminList = keyAdminAddressList()
82- let $t016511735 = {
83- let $l = getAdminsList()
84- let $s = size($l)
85- let $acc0 = $Tuple2(nil, keyPrefix)
86- func $f0_1 ($a,$i) = if (($i >= $s))
87- then $a
88- else genVotesKeysHelper($a, $l[$i])
89-
90- func $f0_2 ($a,$i) = if (($i >= $s))
91- then $a
92- else throw("List size exceeds 5")
93-
94- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
95- }
96- let result = $t016511735._1
97- let prefix = $t016511735._2
98- result
99- }
100-
101-
102-func countVotesHelper (result,voteKey) = (result + valueOrElse(getInteger(voteKey), 0))
103-
104-
105-func countVotes (prefix) = {
106- let votes = genVotesKeys(prefix)
107- let $l = votes
108- let $s = size($l)
109- let $acc0 = 0
110- func $f0_1 ($a,$i) = if (($i >= $s))
111- then $a
112- else countVotesHelper($a, $l[$i])
113-
114- func $f0_2 ($a,$i) = if (($i >= $s))
115- then $a
116- else throw("List size exceeds 5")
117-
118- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
119- }
120-
121-
122-func clearVotesHelper (result,key) = (result :+ DeleteEntry(key))
123-
124-
125-func getClearVoteEntries (prefix) = {
126- let votes = genVotesKeys(prefix)
127- let $l = votes
128- let $s = size($l)
129- let $acc0 = nil
130- func $f0_1 ($a,$i) = if (($i >= $s))
131- then $a
132- else clearVotesHelper($a, $l[$i])
133-
134- func $f0_2 ($a,$i) = if (($i >= $s))
135- then $a
136- else throw("List size exceeds 5")
137-
138- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
139- }
140-
141-
142-func voteINTERNAL (callerAddressString,keyPrefix,minVotes,voteResult) = {
143- let voteKey = keyFullAdminVote(keyPrefix, callerAddressString)
144- let adminCurrentVote = getAdminVote(keyPrefix, callerAddressString)
145- let err = if (!(isInAdminList(callerAddressString)))
146- then throwErr((("Address: " + callerAddressString) + " not in Admin list"))
147- else if ((adminCurrentVote == 1))
148- then throwErr((voteKey + " you already voted"))
149- else unit
150- if ((err == err))
151- then {
152- let votes = countVotes(keyPrefix)
153- if (((votes + 1) >= minVotes))
154- then {
155- let clearVoteEntries = getClearVoteEntries(keyPrefix)
156- (clearVoteEntries ++ voteResult)
157- }
158- else [IntegerEntry(voteKey, 1)]
159- }
160- else throw("Strict value is not equal to itself.")
161- }
162-
163-
164-func keyCalculatorAddress () = "%s__calculatorAddress"
165-
166-
167-func keyLpAssetId () = "%s__lpAssetId"
168-
169-
170-func currentPeriod () = makeString(["%s", "currentPeriod"], SEP)
171-
172-
173-func startHeightByPeriod (period) = makeString(["%s%d", "startHeight", toString(period)], SEP)
174-
175-
176-func periodLength () = makeString(["%s", "periodLength"], SEP)
177-
178-
179-func treasuryValueByPeriod (period) = makeString(["%s%d", "treasuryValue", toString(period)], SEP)
180-
181-
182-func treasuryValue () = makeString(["%s", "treasuryValue"], SEP)
183-
184-
185-let calculatorAddressOption = match getString(this, keyCalculatorAddress()) {
35+func powerConfigAddress (factoryAddress) = valueOrErrorMessage(match getString(factoryAddress, keyPowerConfigAddress()) {
18636 case s: String =>
18737 addressFromString(s)
18838 case _: Unit =>
18939 unit
19040 case _ =>
19141 throw("Match error")
192-}
42+}, wrapErr("invalid power config address"))
19343
194-let calculatorAddressOrFail = valueOrErrorMessage(calculatorAddressOption, wrapErr("invalid calculator address"))
19544
196-func keyConfigAddress () = "%s__powerConfigAddress"
45+func keyPowerAssetId () = "powerAssetId"
46+
47+
48+func powerAssetId (factoryAddress) = fromBase58String(valueOrErrorMessage(getString(powerConfigAddress(factoryAddress), keyPowerAssetId()), wrapErr("invalid power asset id")))
19749
19850
19951 func keyPowerContractAddress () = "%s__powerContractAddress"
20052
20153
202-func keyVotingResultAddress () = "contract_voting_result"
203-
204-
205-func keyProposalAllowBroadcast (address,txId) = ((("proposal_allow_broadcast_" + toString(address)) + "_") + toBase58String(txId))
206-
207-
208-let configAddressOption = match getString(this, keyConfigAddress()) {
54+func powerContractAddress (factoryAddress) = valueOrErrorMessage(match getString(factoryAddress, keyPowerContractAddress()) {
20955 case s: String =>
21056 addressFromString(s)
21157 case _: Unit =>
21258 unit
21359 case _ =>
21460 throw("Match error")
215-}
216-
217-let votingResultAddressOption = match configAddressOption {
218- case a: Address =>
219- match getString(a, keyVotingResultAddress()) {
220- case s: String =>
221- addressFromString(s)
222- case _: Unit =>
223- unit
224- case _ =>
225- throw("Match error")
226- }
227- case _: Unit =>
228- unit
229- case _ =>
230- throw("Match error")
231-}
232-
233-let votingResultAddressOrFail = valueOrErrorMessage(votingResultAddressOption, wrapErr("invalid voting result address"))
234-
235-let lpAssetIdOption = match getString(this, keyLpAssetId()) {
236- case s: String =>
237- fromBase58String(s)
238- case _: Unit =>
239- unit
240- case _ =>
241- throw("Match error")
242-}
243-
244-let lpAssetIdOrFail = valueOrErrorMessage(lpAssetIdOption, wrapErr("invalid lpAssetId"))
245-
246-func onlyAddress (i,address) = if ((i.caller == address))
247- then true
248- else throwErr("permission denied")
61+}, wrapErr("invalid power contract address"))
24962
25063
251-func onlyThis (i) = onlyAddress(i, this)
64+func keyAssets () = "%s__assets"
25265
25366
254-func onlyCalculator (i) = onlyAddress(i, calculatorAddressOrFail)
67+func getAssetsStr (factoryAddress) = valueOrErrorMessage(getString(factoryAddress, keyAssets()), wrapErr("invalid assets"))
68+
69+
70+func keyLpAssetId () = "%s__lpAssetId"
71+
72+
73+func getLpAssetId (factoryAddress) = fromBase58String(valueOrErrorMessage(getString(factoryAddress, keyLpAssetId()), wrapErr("invalid lp asset id")))
25574
25675
25776 @Callable(i)
258-func stringEntry (key,val) = if (onlyCalculator(i))
259- then $Tuple2([StringEntry(key, val)], key)
260- else $Tuple2(nil, unit)
261-
262-
263-
264-@Callable(i)
265-func integerEntry (key,val) = if (onlyCalculator(i))
266- then $Tuple2([IntegerEntry(key, val)], key)
267- else $Tuple2(nil, unit)
268-
269-
270-
271-@Callable(i)
272-func booleanEntry (key,val) = if (onlyCalculator(i))
273- then $Tuple2([BooleanEntry(key, val)], key)
274- else $Tuple2(nil, unit)
275-
276-
277-
278-@Callable(i)
279-func binaryEntry (key,val) = if (onlyCalculator(i))
280- then $Tuple2([BinaryEntry(key, val)], key)
281- else $Tuple2(nil, unit)
282-
283-
284-
285-@Callable(i)
286-func deleteEntry (key) = if (onlyCalculator(i))
287- then $Tuple2([DeleteEntry(key)], key)
288- else $Tuple2(nil, unit)
289-
290-
291-
292-@Callable(i)
293-func reissue (amount) = if (onlyCalculator(i))
294- then $Tuple2([Reissue(lpAssetIdOrFail, amount, true)], amount)
295- else $Tuple2(nil, unit)
296-
297-
298-
299-@Callable(i)
300-func burn (amount) = if (onlyCalculator(i))
301- then $Tuple2([Burn(lpAssetIdOrFail, amount)], amount)
302- else $Tuple2(nil, unit)
303-
304-
305-
306-@Callable(i)
307-func transferAsset (recipientBytes,amount,assetId) = if (onlyCalculator(i))
308- then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, assetId)], amount)
309- else $Tuple2(nil, unit)
310-
311-
312-
313-@Callable(i)
314-func transferAssets (recipientBytes,assetsList,amountsList) = if (onlyCalculator(i))
315- then {
316- func addNewTransfer (acc,nextAssetId) = {
317- let $t063846408 = acc
318- let transfers = $t063846408._1
319- let j = $t063846408._2
320- let newTransfer = ScriptTransfer(Address(recipientBytes), parseIntValue(amountsList[j]), stringToAssetId(assetsList[j]))
321- let updatedTransfers = (transfers :+ newTransfer)
322- $Tuple2(updatedTransfers, (j + 1))
323- }
324-
325- let $t066686749 = {
326- let $l = assetsList
327- let $s = size($l)
328- let $acc0 = $Tuple2(nil, 0)
329- func $f0_1 ($a,$i) = if (($i >= $s))
330- then $a
331- else addNewTransfer($a, $l[$i])
332-
333- func $f0_2 ($a,$i) = if (($i >= $s))
334- then $a
335- else throw("List size exceeds 10")
336-
337- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
338- }
339- let assetsTransfers = $t066686749._1
340- let _lastIndex = $t066686749._2
341- $Tuple2(assetsTransfers, unit)
342- }
343- else $Tuple2(nil, unit)
344-
345-
346-
347-@Callable(i)
348-func transferWaves (recipientBytes,amount) = if (onlyCalculator(i))
349- then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, unit)], amount)
350- else $Tuple2(nil, unit)
351-
352-
353-
354-@Callable(i)
355-func commitAfterStartWithLockRoundFor (contract,child,address,additionalLockRounds,paymentAssetId,paymentAmount) = $Tuple2(nil, invoke(addressFromStringValue(contract), "commitAfterStartWithLockRoundFor", [child, address, additionalLockRounds], [AttachedPayment(paymentAssetId, paymentAmount)]))
356-
357-
358-
359-@Callable(i)
360-func call (function,args) = {
361- let result = reentrantInvoke(calculatorAddressOrFail, function, [i.callerPublicKey, args], i.payments)
77+func withdraw (args) = {
78+ let recipient = addressFromStringValue(args[0])
79+ let amount = parseIntValue(args[1])
80+ let result = invoke(i.caller, "transferWaves", [recipient.bytes, amount], nil)
36281 $Tuple2(nil, result)
36382 }
36483
36584
36685
36786 @Callable(i)
368-func voteForTxId (txId) = {
369- let callerAddressString = toBase58String(i.caller.bytes)
370- let keyPrefix = keyAllowedTxIdVotePrefix(txId)
371- let result = [StringEntry(keyAllowedTxId(), txId)]
372- let allowedTxIdOption = getString(this, keyAllowedTxId())
373- let err = [if ((size(fromBase58String(txId)) == TXID_BYTES_LENGTH))
374- then true
375- else throwErr((txId + " is not valid txId")), if (if ((allowedTxIdOption == unit))
376- then true
377- else (value(allowedTxIdOption) != txId))
378- then true
379- else throwErr((txId + " is already allowed"))]
380- if ((err == err))
381- then voteINTERNAL(callerAddressString, keyPrefix, QUORUM, result)
87+func setIntParam (args) = {
88+ let key = args[0]
89+ let val = parseIntValue(args[1])
90+ let result = invoke(i.caller, "integerEntry", [key, val], nil)
91+ $Tuple2(nil, result)
92+ }
93+
94+
95+
96+@Callable(i)
97+func swap (callerPublicKey,args) = {
98+ let factoryAddress = i.caller
99+ let userAddress = addressFromPublicKey(callerPublicKey)
100+ let payment = if ((size(i.payments) == 1))
101+ then i.payments[0]
102+ else throwErr("1 payment is required")
103+ let err = wrapErr("invalid payment asset id")
104+ let paymentAssetId = if ((valueOrErrorMessage(payment.assetId, err) == getLpAssetId(factoryAddress)))
105+ then value(payment.assetId)
106+ else throwErr(err)
107+ let pwrPrice = 100
108+ let pwrAmount = (payment.amount / pwrPrice)
109+ let assetsStr = split(getAssetsStr(factoryAddress), SEP)
110+ let pwrBalance = assetBalance(factoryAddress, powerAssetId(factoryAddress))
111+ if ((pwrBalance == pwrBalance))
112+ then {
113+ func map (acc,nextAssetId) = {
114+ let assetId = fromBase58String(nextAssetId)
115+ let balance = assetBalance(factoryAddress, assetId)
116+ if ((balance == balance))
117+ then {
118+ let amount = fraction(balance, pwrAmount, pwrBalance)
119+ if ((amount > 0))
120+ then $Tuple2((acc._1 :+ assetId), (acc._2 :+ amount))
121+ else acc
122+ }
123+ else throw("Strict value is not equal to itself.")
124+ }
125+
126+ let transfers = {
127+ let $l = assetsStr
128+ let $s = size($l)
129+ let $acc0 = $Tuple2(nil, nil)
130+ func $f0_1 ($a,$i) = if (($i >= $s))
131+ then $a
132+ else map($a, $l[$i])
133+
134+ func $f0_2 ($a,$i) = if (($i >= $s))
135+ then $a
136+ else throw("List size exceeds 6")
137+
138+ $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6)
139+ }
140+ if ((transfers == transfers))
141+ then {
142+ let additionalLockRounds = 0
143+ let factoryActions = ([invoke(factoryAddress, "commitAfterStartWithLockRoundFor", [toString(powerContractAddress(factoryAddress)), toString(factoryAddress), toString(userAddress), additionalLockRounds, powerAssetId(factoryAddress), pwrAmount], nil)] ++ (if ((size(transfers._1) == 0))
144+ then nil
145+ else [invoke(factoryAddress, "transferAssets", [userAddress.bytes, transfers._1, transfers._2], nil)]))
146+ $Tuple2([Burn(paymentAssetId, payment.amount)], factoryActions)
147+ }
148+ else throw("Strict value is not equal to itself.")
149+ }
382150 else throw("Strict value is not equal to itself.")
383151 }
384152
385153
154+
155+@Callable(i)
156+func price (callerPublicKey,args) = $Tuple2(nil, 0)
157+
158+
386159 @Verifier(tx)
387-func verify () = {
388- let byProposal = match votingResultAddressOption {
389- case proposalAddress: Address =>
390- valueOrElse(getBoolean(proposalAddress, keyProposalAllowBroadcast(this, tx.id)), false)
391- case _ =>
392- false
393- }
394- let byAdmins = (tx.id == fromBase58String(valueOrElse(getString(this, keyAllowedTxId()), "")))
395- let byOwner = if ((size(getAdminsList()) >= QUORUM))
396- then false
397- else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
398- if (if (byProposal)
399- then true
400- else byAdmins)
401- then true
402- else byOwner
403- }
160+func verify () = (chainId == chainIdT)
404161
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let separator = "__"
55
66 let chainId = take(drop(this.bytes, 1), 1)
77
88 let chainIdT = base58'2T'
99
1010 let chainIdW = base58'2W'
1111
1212 func mustAddress (i,address) = if ((i.caller == address))
1313 then true
1414 else throw("permission denied")
1515
1616
1717 func mustThis (i) = mustAddress(i, this)
1818
1919
2020 let SEP = "__"
2121
2222 let WAVES = "WAVES"
2323
24-let contractFilename = "wxdao_factory.ride"
24+let contractFilename = "wxdao_calculator.ride"
2525
2626 func wrapErr (s) = ((contractFilename + ": ") + s)
2727
2828
2929 func throwErr (s) = throw(wrapErr(s))
3030
3131
32-func stringToAssetId (s) = if ((s == WAVES))
33- then unit
34- else fromBase58String(s)
32+func keyPowerConfigAddress () = "%s__powerConfigAddress"
3533
3634
37-let ADMIN_LIST_SIZE = 5
38-
39-let QUORUM = 3
40-
41-let TXID_BYTES_LENGTH = 32
42-
43-func keyAllowedTxIdVotePrefix (txId) = makeString(["%s%s%s", "allowTxId", txId], SEP)
44-
45-
46-func keyFullAdminVote (prefix,adminAddress) = makeString([prefix, adminAddress], SEP)
47-
48-
49-func keyAdminAddressList () = makeString(["%s", "adminAddressList"], SEP)
50-
51-
52-func keyAllowedTxId () = makeString(["%s", "txId"], SEP)
53-
54-
55-func getAdminVote (prefix,admin) = {
56- let voteKey = keyFullAdminVote(prefix, admin)
57- valueOrElse(getInteger(voteKey), 0)
58- }
59-
60-
61-func getAdminsList () = match getString(this, keyAdminAddressList()) {
62- case s: String =>
63- split(s, SEP)
64- case _ =>
65- nil
66-}
67-
68-
69-func isInAdminList (address) = containsElement(getAdminsList(), address)
70-
71-
72-func genVotesKeysHelper (a,adminAddress) = {
73- let $t014801504 = a
74- let result = $t014801504._1
75- let prefix = $t014801504._2
76- $Tuple2((result :+ keyFullAdminVote(prefix, adminAddress)), prefix)
77- }
78-
79-
80-func genVotesKeys (keyPrefix) = {
81- let adminList = keyAdminAddressList()
82- let $t016511735 = {
83- let $l = getAdminsList()
84- let $s = size($l)
85- let $acc0 = $Tuple2(nil, keyPrefix)
86- func $f0_1 ($a,$i) = if (($i >= $s))
87- then $a
88- else genVotesKeysHelper($a, $l[$i])
89-
90- func $f0_2 ($a,$i) = if (($i >= $s))
91- then $a
92- else throw("List size exceeds 5")
93-
94- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
95- }
96- let result = $t016511735._1
97- let prefix = $t016511735._2
98- result
99- }
100-
101-
102-func countVotesHelper (result,voteKey) = (result + valueOrElse(getInteger(voteKey), 0))
103-
104-
105-func countVotes (prefix) = {
106- let votes = genVotesKeys(prefix)
107- let $l = votes
108- let $s = size($l)
109- let $acc0 = 0
110- func $f0_1 ($a,$i) = if (($i >= $s))
111- then $a
112- else countVotesHelper($a, $l[$i])
113-
114- func $f0_2 ($a,$i) = if (($i >= $s))
115- then $a
116- else throw("List size exceeds 5")
117-
118- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
119- }
120-
121-
122-func clearVotesHelper (result,key) = (result :+ DeleteEntry(key))
123-
124-
125-func getClearVoteEntries (prefix) = {
126- let votes = genVotesKeys(prefix)
127- let $l = votes
128- let $s = size($l)
129- let $acc0 = nil
130- func $f0_1 ($a,$i) = if (($i >= $s))
131- then $a
132- else clearVotesHelper($a, $l[$i])
133-
134- func $f0_2 ($a,$i) = if (($i >= $s))
135- then $a
136- else throw("List size exceeds 5")
137-
138- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
139- }
140-
141-
142-func voteINTERNAL (callerAddressString,keyPrefix,minVotes,voteResult) = {
143- let voteKey = keyFullAdminVote(keyPrefix, callerAddressString)
144- let adminCurrentVote = getAdminVote(keyPrefix, callerAddressString)
145- let err = if (!(isInAdminList(callerAddressString)))
146- then throwErr((("Address: " + callerAddressString) + " not in Admin list"))
147- else if ((adminCurrentVote == 1))
148- then throwErr((voteKey + " you already voted"))
149- else unit
150- if ((err == err))
151- then {
152- let votes = countVotes(keyPrefix)
153- if (((votes + 1) >= minVotes))
154- then {
155- let clearVoteEntries = getClearVoteEntries(keyPrefix)
156- (clearVoteEntries ++ voteResult)
157- }
158- else [IntegerEntry(voteKey, 1)]
159- }
160- else throw("Strict value is not equal to itself.")
161- }
162-
163-
164-func keyCalculatorAddress () = "%s__calculatorAddress"
165-
166-
167-func keyLpAssetId () = "%s__lpAssetId"
168-
169-
170-func currentPeriod () = makeString(["%s", "currentPeriod"], SEP)
171-
172-
173-func startHeightByPeriod (period) = makeString(["%s%d", "startHeight", toString(period)], SEP)
174-
175-
176-func periodLength () = makeString(["%s", "periodLength"], SEP)
177-
178-
179-func treasuryValueByPeriod (period) = makeString(["%s%d", "treasuryValue", toString(period)], SEP)
180-
181-
182-func treasuryValue () = makeString(["%s", "treasuryValue"], SEP)
183-
184-
185-let calculatorAddressOption = match getString(this, keyCalculatorAddress()) {
35+func powerConfigAddress (factoryAddress) = valueOrErrorMessage(match getString(factoryAddress, keyPowerConfigAddress()) {
18636 case s: String =>
18737 addressFromString(s)
18838 case _: Unit =>
18939 unit
19040 case _ =>
19141 throw("Match error")
192-}
42+}, wrapErr("invalid power config address"))
19343
194-let calculatorAddressOrFail = valueOrErrorMessage(calculatorAddressOption, wrapErr("invalid calculator address"))
19544
196-func keyConfigAddress () = "%s__powerConfigAddress"
45+func keyPowerAssetId () = "powerAssetId"
46+
47+
48+func powerAssetId (factoryAddress) = fromBase58String(valueOrErrorMessage(getString(powerConfigAddress(factoryAddress), keyPowerAssetId()), wrapErr("invalid power asset id")))
19749
19850
19951 func keyPowerContractAddress () = "%s__powerContractAddress"
20052
20153
202-func keyVotingResultAddress () = "contract_voting_result"
203-
204-
205-func keyProposalAllowBroadcast (address,txId) = ((("proposal_allow_broadcast_" + toString(address)) + "_") + toBase58String(txId))
206-
207-
208-let configAddressOption = match getString(this, keyConfigAddress()) {
54+func powerContractAddress (factoryAddress) = valueOrErrorMessage(match getString(factoryAddress, keyPowerContractAddress()) {
20955 case s: String =>
21056 addressFromString(s)
21157 case _: Unit =>
21258 unit
21359 case _ =>
21460 throw("Match error")
215-}
216-
217-let votingResultAddressOption = match configAddressOption {
218- case a: Address =>
219- match getString(a, keyVotingResultAddress()) {
220- case s: String =>
221- addressFromString(s)
222- case _: Unit =>
223- unit
224- case _ =>
225- throw("Match error")
226- }
227- case _: Unit =>
228- unit
229- case _ =>
230- throw("Match error")
231-}
232-
233-let votingResultAddressOrFail = valueOrErrorMessage(votingResultAddressOption, wrapErr("invalid voting result address"))
234-
235-let lpAssetIdOption = match getString(this, keyLpAssetId()) {
236- case s: String =>
237- fromBase58String(s)
238- case _: Unit =>
239- unit
240- case _ =>
241- throw("Match error")
242-}
243-
244-let lpAssetIdOrFail = valueOrErrorMessage(lpAssetIdOption, wrapErr("invalid lpAssetId"))
245-
246-func onlyAddress (i,address) = if ((i.caller == address))
247- then true
248- else throwErr("permission denied")
61+}, wrapErr("invalid power contract address"))
24962
25063
251-func onlyThis (i) = onlyAddress(i, this)
64+func keyAssets () = "%s__assets"
25265
25366
254-func onlyCalculator (i) = onlyAddress(i, calculatorAddressOrFail)
67+func getAssetsStr (factoryAddress) = valueOrErrorMessage(getString(factoryAddress, keyAssets()), wrapErr("invalid assets"))
68+
69+
70+func keyLpAssetId () = "%s__lpAssetId"
71+
72+
73+func getLpAssetId (factoryAddress) = fromBase58String(valueOrErrorMessage(getString(factoryAddress, keyLpAssetId()), wrapErr("invalid lp asset id")))
25574
25675
25776 @Callable(i)
258-func stringEntry (key,val) = if (onlyCalculator(i))
259- then $Tuple2([StringEntry(key, val)], key)
260- else $Tuple2(nil, unit)
261-
262-
263-
264-@Callable(i)
265-func integerEntry (key,val) = if (onlyCalculator(i))
266- then $Tuple2([IntegerEntry(key, val)], key)
267- else $Tuple2(nil, unit)
268-
269-
270-
271-@Callable(i)
272-func booleanEntry (key,val) = if (onlyCalculator(i))
273- then $Tuple2([BooleanEntry(key, val)], key)
274- else $Tuple2(nil, unit)
275-
276-
277-
278-@Callable(i)
279-func binaryEntry (key,val) = if (onlyCalculator(i))
280- then $Tuple2([BinaryEntry(key, val)], key)
281- else $Tuple2(nil, unit)
282-
283-
284-
285-@Callable(i)
286-func deleteEntry (key) = if (onlyCalculator(i))
287- then $Tuple2([DeleteEntry(key)], key)
288- else $Tuple2(nil, unit)
289-
290-
291-
292-@Callable(i)
293-func reissue (amount) = if (onlyCalculator(i))
294- then $Tuple2([Reissue(lpAssetIdOrFail, amount, true)], amount)
295- else $Tuple2(nil, unit)
296-
297-
298-
299-@Callable(i)
300-func burn (amount) = if (onlyCalculator(i))
301- then $Tuple2([Burn(lpAssetIdOrFail, amount)], amount)
302- else $Tuple2(nil, unit)
303-
304-
305-
306-@Callable(i)
307-func transferAsset (recipientBytes,amount,assetId) = if (onlyCalculator(i))
308- then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, assetId)], amount)
309- else $Tuple2(nil, unit)
310-
311-
312-
313-@Callable(i)
314-func transferAssets (recipientBytes,assetsList,amountsList) = if (onlyCalculator(i))
315- then {
316- func addNewTransfer (acc,nextAssetId) = {
317- let $t063846408 = acc
318- let transfers = $t063846408._1
319- let j = $t063846408._2
320- let newTransfer = ScriptTransfer(Address(recipientBytes), parseIntValue(amountsList[j]), stringToAssetId(assetsList[j]))
321- let updatedTransfers = (transfers :+ newTransfer)
322- $Tuple2(updatedTransfers, (j + 1))
323- }
324-
325- let $t066686749 = {
326- let $l = assetsList
327- let $s = size($l)
328- let $acc0 = $Tuple2(nil, 0)
329- func $f0_1 ($a,$i) = if (($i >= $s))
330- then $a
331- else addNewTransfer($a, $l[$i])
332-
333- func $f0_2 ($a,$i) = if (($i >= $s))
334- then $a
335- else throw("List size exceeds 10")
336-
337- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
338- }
339- let assetsTransfers = $t066686749._1
340- let _lastIndex = $t066686749._2
341- $Tuple2(assetsTransfers, unit)
342- }
343- else $Tuple2(nil, unit)
344-
345-
346-
347-@Callable(i)
348-func transferWaves (recipientBytes,amount) = if (onlyCalculator(i))
349- then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, unit)], amount)
350- else $Tuple2(nil, unit)
351-
352-
353-
354-@Callable(i)
355-func commitAfterStartWithLockRoundFor (contract,child,address,additionalLockRounds,paymentAssetId,paymentAmount) = $Tuple2(nil, invoke(addressFromStringValue(contract), "commitAfterStartWithLockRoundFor", [child, address, additionalLockRounds], [AttachedPayment(paymentAssetId, paymentAmount)]))
356-
357-
358-
359-@Callable(i)
360-func call (function,args) = {
361- let result = reentrantInvoke(calculatorAddressOrFail, function, [i.callerPublicKey, args], i.payments)
77+func withdraw (args) = {
78+ let recipient = addressFromStringValue(args[0])
79+ let amount = parseIntValue(args[1])
80+ let result = invoke(i.caller, "transferWaves", [recipient.bytes, amount], nil)
36281 $Tuple2(nil, result)
36382 }
36483
36584
36685
36786 @Callable(i)
368-func voteForTxId (txId) = {
369- let callerAddressString = toBase58String(i.caller.bytes)
370- let keyPrefix = keyAllowedTxIdVotePrefix(txId)
371- let result = [StringEntry(keyAllowedTxId(), txId)]
372- let allowedTxIdOption = getString(this, keyAllowedTxId())
373- let err = [if ((size(fromBase58String(txId)) == TXID_BYTES_LENGTH))
374- then true
375- else throwErr((txId + " is not valid txId")), if (if ((allowedTxIdOption == unit))
376- then true
377- else (value(allowedTxIdOption) != txId))
378- then true
379- else throwErr((txId + " is already allowed"))]
380- if ((err == err))
381- then voteINTERNAL(callerAddressString, keyPrefix, QUORUM, result)
87+func setIntParam (args) = {
88+ let key = args[0]
89+ let val = parseIntValue(args[1])
90+ let result = invoke(i.caller, "integerEntry", [key, val], nil)
91+ $Tuple2(nil, result)
92+ }
93+
94+
95+
96+@Callable(i)
97+func swap (callerPublicKey,args) = {
98+ let factoryAddress = i.caller
99+ let userAddress = addressFromPublicKey(callerPublicKey)
100+ let payment = if ((size(i.payments) == 1))
101+ then i.payments[0]
102+ else throwErr("1 payment is required")
103+ let err = wrapErr("invalid payment asset id")
104+ let paymentAssetId = if ((valueOrErrorMessage(payment.assetId, err) == getLpAssetId(factoryAddress)))
105+ then value(payment.assetId)
106+ else throwErr(err)
107+ let pwrPrice = 100
108+ let pwrAmount = (payment.amount / pwrPrice)
109+ let assetsStr = split(getAssetsStr(factoryAddress), SEP)
110+ let pwrBalance = assetBalance(factoryAddress, powerAssetId(factoryAddress))
111+ if ((pwrBalance == pwrBalance))
112+ then {
113+ func map (acc,nextAssetId) = {
114+ let assetId = fromBase58String(nextAssetId)
115+ let balance = assetBalance(factoryAddress, assetId)
116+ if ((balance == balance))
117+ then {
118+ let amount = fraction(balance, pwrAmount, pwrBalance)
119+ if ((amount > 0))
120+ then $Tuple2((acc._1 :+ assetId), (acc._2 :+ amount))
121+ else acc
122+ }
123+ else throw("Strict value is not equal to itself.")
124+ }
125+
126+ let transfers = {
127+ let $l = assetsStr
128+ let $s = size($l)
129+ let $acc0 = $Tuple2(nil, nil)
130+ func $f0_1 ($a,$i) = if (($i >= $s))
131+ then $a
132+ else map($a, $l[$i])
133+
134+ func $f0_2 ($a,$i) = if (($i >= $s))
135+ then $a
136+ else throw("List size exceeds 6")
137+
138+ $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6)
139+ }
140+ if ((transfers == transfers))
141+ then {
142+ let additionalLockRounds = 0
143+ let factoryActions = ([invoke(factoryAddress, "commitAfterStartWithLockRoundFor", [toString(powerContractAddress(factoryAddress)), toString(factoryAddress), toString(userAddress), additionalLockRounds, powerAssetId(factoryAddress), pwrAmount], nil)] ++ (if ((size(transfers._1) == 0))
144+ then nil
145+ else [invoke(factoryAddress, "transferAssets", [userAddress.bytes, transfers._1, transfers._2], nil)]))
146+ $Tuple2([Burn(paymentAssetId, payment.amount)], factoryActions)
147+ }
148+ else throw("Strict value is not equal to itself.")
149+ }
382150 else throw("Strict value is not equal to itself.")
383151 }
384152
385153
154+
155+@Callable(i)
156+func price (callerPublicKey,args) = $Tuple2(nil, 0)
157+
158+
386159 @Verifier(tx)
387-func verify () = {
388- let byProposal = match votingResultAddressOption {
389- case proposalAddress: Address =>
390- valueOrElse(getBoolean(proposalAddress, keyProposalAllowBroadcast(this, tx.id)), false)
391- case _ =>
392- false
393- }
394- let byAdmins = (tx.id == fromBase58String(valueOrElse(getString(this, keyAllowedTxId()), "")))
395- let byOwner = if ((size(getAdminsList()) >= QUORUM))
396- then false
397- else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
398- if (if (byProposal)
399- then true
400- else byAdmins)
401- then true
402- else byOwner
403- }
160+func verify () = (chainId == chainIdT)
404161

github/deemru/w8io/026f985 
44.12 ms