tx · 9AS2V8cZDiHN884tuntATqWNhKirdzVVCYhK8eGCB85c

3PANnmCGrufT8SZY5u6BZUgZq4QTh5XdPMa:  -0.01300000 Waves

2024.02.20 11:43 [4050142] smart account 3PANnmCGrufT8SZY5u6BZUgZq4QTh5XdPMa > SELF 0.00000000 Waves

{ "type": 13, "id": "9AS2V8cZDiHN884tuntATqWNhKirdzVVCYhK8eGCB85c", "fee": 1300000, "feeAssetId": null, "timestamp": 1708418356646, "version": 2, "chainId": 87, "sender": "3PANnmCGrufT8SZY5u6BZUgZq4QTh5XdPMa", "senderPublicKey": "EfRKQWb1FWaWmo9fkorRwMA4BrSzUWNAVhXqB9vLmv7g", "proofs": [ "3XfLesVS8BmpHaovVERNpDjgRyuUnDCosMZWBKbovteXXTVZt5PVvenyveFX1PaA6kJ8Y8kR2hhAXXXnLmXEiDLC" ], "script": null, "height": 4050142, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4zUs3ZnRaQmcbkv1S677JPTMgxprceeqd6sTuTbgwarE Next: AWZ1s9C91zXx6iUqgtuPL2iKUyM4HeRG6emYFdc1hQnq Full:
OldNewDifferences
1-{-# STDLIB_VERSION 6 #-}
2-{-# SCRIPT_TYPE ACCOUNT #-}
3-{-# CONTENT_TYPE DAPP #-}
4-let contractFile = "l2mp_swap.ride"
5-
6-let SEP = "__"
7-
8-let scale8 = 100000000
9-
10-let scale18 = 1000000000000000000
11-
12-let ADDRESS_BYTES_SIZE = 26
13-
14-let BLOCKS_IN_DAY = 1440
15-
16-func wrapErr (msg) = ((contractFile + ": ") + msg)
17-
18-
19-func throwErr (msg) = throw(wrapErr(msg))
20-
21-
22-let keyAssetInId = makeString(["%s", "assetInId"], SEP)
23-
24-let keyAssetOutId = makeString(["%s", "assetOutId"], SEP)
25-
26-let keyAssetOutPrice = makeString(["%s", "assetOutPrice"], SEP)
27-
28-let keyStakingAddress = makeString(["%s", "stakingAddress"], SEP)
29-
30-let keyStatsTotalIn = makeString(["%s%s", "stats", "totalIn"], SEP)
31-
32-let keyStatsTotalOut = makeString(["%s%s", "stats", "totalOut"], SEP)
33-
34-let keyAllowedAddress = makeString(["%s", "allowedAddress"], SEP)
35-
36-func keyStatsTotalInByAddress (address) = makeString(["%s%s%s", "stats", "totalIn", toString(address)], SEP)
37-
38-
39-func keyStatsTotalOutByAddress (address) = makeString(["%s%s%s", "stats", "totalOut", toString(address)], SEP)
40-
41-
42-func keyHistory (address,txId) = makeString(["%s%s%s", "history", toString(address), toBase58String(txId)], SEP)
43-
44-
45-func formatHistory (amountIn,amountOut,stake) = makeString(["%d%d%d", toString(amountIn), toString(amountOut), toString(stake)], SEP)
46-
47-
48-let assetInId = fromBase58String(valueOrErrorMessage(getString(this, keyAssetInId), wrapErr("invalid assetInId")))
49-
50-let assetInInfo = valueOrErrorMessage(assetInfo(assetInId), wrapErr("invalid assetInInfo"))
51-
52-let assetOutId = fromBase58String(valueOrErrorMessage(getString(this, keyAssetOutId), wrapErr("invalid assetInId")))
53-
54-let assetOutInfo = valueOrErrorMessage(assetInfo(assetOutId), wrapErr("invalid assetOutInfo"))
55-
56-let assetOutPrice = valueOrErrorMessage(getInteger(this, keyAssetOutPrice), wrapErr("invalid assetOutPrice"))
57-
58-let stakingAddressOption = match getString(this, keyStakingAddress) {
59- case s: String =>
60- addressFromString(s)
61- case _: Unit =>
62- unit
63- case _ =>
64- throw("Match error")
65-}
66-
67-let stakingAddress = valueOrErrorMessage(stakingAddressOption, wrapErr("invalid stakingAddress"))
68-
69-let allowedAddressOption = match getString(this, keyAllowedAddress) {
70- case s: String =>
71- addressFromString(s)
72- case _: Unit =>
73- unit
74- case _ =>
75- throw("Match error")
76-}
77-
78-let allowedAddress = valueOrErrorMessage(allowedAddressOption, wrapErr("invalid allowedAddress"))
79-
80-let ADMIN_LIST_SIZE = 5
81-
82-let QUORUM = 3
83-
84-let TXID_BYTES_LENGTH = 32
85-
86-func keyAllowedTxIdVotePrefix (txId) = makeString(["%s%s%s", "allowTxId", txId], SEP)
87-
88-
89-func keyFullAdminVote (prefix,adminAddress) = makeString([prefix, adminAddress], SEP)
90-
91-
92-func keyAdminAddressList () = makeString(["%s", "adminAddressList"], SEP)
93-
94-
95-func keyAllowedTxId () = makeString(["%s", "txId"], SEP)
96-
97-
98-func getAdminVote (prefix,admin) = {
99- let voteKey = keyFullAdminVote(prefix, admin)
100- valueOrElse(getInteger(voteKey), 0)
101- }
102-
103-
104-func getAdminsList () = match getString(this, keyAdminAddressList()) {
105- case s: String =>
106- split(s, SEP)
107- case _ =>
108- nil
109-}
110-
111-
112-func isInAdminList (address) = containsElement(getAdminsList(), address)
113-
114-
115-func genVotesKeysHelper (a,adminAddress) = {
116- let $t033223346 = a
117- let result = $t033223346._1
118- let prefix = $t033223346._2
119- $Tuple2((result :+ keyFullAdminVote(prefix, adminAddress)), prefix)
120- }
121-
122-
123-func genVotesKeys (keyPrefix) = {
124- let adminList = keyAdminAddressList()
125- let $t034933577 = {
126- let $l = getAdminsList()
127- let $s = size($l)
128- let $acc0 = $Tuple2(nil, keyPrefix)
129- func $f0_1 ($a,$i) = if (($i >= $s))
130- then $a
131- else genVotesKeysHelper($a, $l[$i])
132-
133- func $f0_2 ($a,$i) = if (($i >= $s))
134- then $a
135- else throw("List size exceeds 5")
136-
137- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
138- }
139- let result = $t034933577._1
140- let prefix = $t034933577._2
141- result
142- }
143-
144-
145-func countVotesHelper (result,voteKey) = (result + valueOrElse(getInteger(voteKey), 0))
146-
147-
148-func countVotes (prefix) = {
149- let votes = genVotesKeys(prefix)
150- let $l = votes
151- let $s = size($l)
152- let $acc0 = 0
153- func $f0_1 ($a,$i) = if (($i >= $s))
154- then $a
155- else countVotesHelper($a, $l[$i])
156-
157- func $f0_2 ($a,$i) = if (($i >= $s))
158- then $a
159- else throw("List size exceeds 5")
160-
161- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
162- }
163-
164-
165-func clearVotesHelper (result,key) = (result :+ DeleteEntry(key))
166-
167-
168-func getClearVoteEntries (prefix) = {
169- let votes = genVotesKeys(prefix)
170- let $l = votes
171- let $s = size($l)
172- let $acc0 = nil
173- func $f0_1 ($a,$i) = if (($i >= $s))
174- then $a
175- else clearVotesHelper($a, $l[$i])
176-
177- func $f0_2 ($a,$i) = if (($i >= $s))
178- then $a
179- else throw("List size exceeds 5")
180-
181- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5)
182- }
183-
184-
185-func voteINTERNAL (callerAddressString,keyPrefix,minVotes,voteResult) = {
186- let voteKey = keyFullAdminVote(keyPrefix, callerAddressString)
187- let adminCurrentVote = getAdminVote(keyPrefix, callerAddressString)
188- let err = if (!(isInAdminList(callerAddressString)))
189- then throwErr((("Address: " + callerAddressString) + " not in Admin list"))
190- else if ((adminCurrentVote == 1))
191- then throwErr((voteKey + " you already voted"))
192- else unit
193- if ((err == err))
194- then {
195- let votes = countVotes(keyPrefix)
196- if (((votes + 1) >= minVotes))
197- then {
198- let clearVoteEntries = getClearVoteEntries(keyPrefix)
199- (clearVoteEntries ++ voteResult)
200- }
201- else [IntegerEntry(voteKey, 1)]
202- }
203- else throw("Strict value is not equal to itself.")
204- }
205-
206-
207-func getSwapActions (i,stakingNode) = {
208- let stake = true
209- let userAddress = i.caller
210- let paymentSizeExpected = 1
211- if ((size(i.payments) != paymentSizeExpected))
212- then throwErr("invalid payments")
213- else {
214- let payment = i.payments[0]
215- if ((payment.assetId != assetInId))
216- then throwErr("invalid payment assetId")
217- else if ((assetOutPrice == 0))
218- then throwErr("invalid assetOutPrice")
219- else {
220- let assetInAmount = payment.amount
221- let assetOutAmount = fraction(assetInAmount, scale8, assetOutPrice)
222- if ((assetOutAmount == 0))
223- then throwErr("invalid assetOutAmount")
224- else {
225- let stakeInv = if (stake)
226- then invoke(stakingAddress, "stakeForSwapHELPER", [toString(userAddress), stakingNode], [AttachedPayment(assetOutId, assetOutAmount)])
227- else unit
228- if ((stakeInv == stakeInv))
229- then $Tuple2(([IntegerEntry(keyStatsTotalIn, (valueOrElse(getInteger(this, keyStatsTotalIn), 0) + assetInAmount)), IntegerEntry(keyStatsTotalOut, (valueOrElse(getInteger(this, keyStatsTotalOut), 0) + assetOutAmount)), IntegerEntry(keyStatsTotalInByAddress(userAddress), (valueOrElse(getInteger(this, keyStatsTotalInByAddress(userAddress)), 0) + assetInAmount)), IntegerEntry(keyStatsTotalOutByAddress(userAddress), (valueOrElse(getInteger(this, keyStatsTotalOutByAddress(userAddress)), 0) + assetOutAmount)), StringEntry(keyHistory(userAddress, i.transactionId), formatHistory(assetInAmount, assetOutAmount, stake))] ++ (if (stake)
230- then nil
231- else [ScriptTransfer(userAddress, assetOutAmount, assetOutId)])), assetOutAmount)
232- else throw("Strict value is not equal to itself.")
233- }
234- }
235- }
236- }
237-
238-
239-@Callable(i)
240-func swapAndSetStakingNode (stakingNode) = getSwapActions(i, stakingNode)
241-
242-
243-
244-@Callable(i)
245-func claim () = {
246- let checkCaller = if ((i.caller == allowedAddress))
247- then true
248- else throwErr("permission denied")
249- if ((checkCaller == checkCaller))
250- then $Tuple2([ScriptTransfer(allowedAddress, assetBalance(this, assetInId), assetInId)], unit)
251- else throw("Strict value is not equal to itself.")
252- }
253-
254-
255-
256-@Callable(i)
257-func voteForTxId (txId) = {
258- let callerAddressString = toBase58String(i.caller.bytes)
259- let keyPrefix = keyAllowedTxIdVotePrefix(txId)
260- let result = [StringEntry(keyAllowedTxId(), txId)]
261- let allowedTxIdOption = getString(this, keyAllowedTxId())
262- let err = [if ((size(fromBase58String(txId)) == TXID_BYTES_LENGTH))
263- then true
264- else throwErr((txId + " is not valid txId")), if (if ((allowedTxIdOption == unit))
265- then true
266- else (value(allowedTxIdOption) != txId))
267- then true
268- else throwErr((txId + " is already allowed"))]
269- if ((err == err))
270- then voteINTERNAL(callerAddressString, keyPrefix, QUORUM, result)
271- else throw("Strict value is not equal to itself.")
272- }
273-
274-
275-@Verifier(tx)
276-func verify () = {
277- let byAdmins = (tx.id == fromBase58String(valueOrElse(getString(this, keyAllowedTxId()), "")))
278- let byOwner = if ((size(getAdminsList()) >= QUORUM))
279- then false
280- else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
281- if (byAdmins)
282- then true
283- else byOwner
284- }
285-
1+# no script

github/deemru/w8io/6500d08 
27.77 ms