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