tx · VHjZXu1kroKpF87G9ZuZUEdR4BCVNVQe9HdFbYvLza5

3N2HGnBgfp7smNh1ok2kSwGigcsLcvb5pRU:  -0.00500000 Waves

2023.03.16 11:33 [2492338] smart account 3N2HGnBgfp7smNh1ok2kSwGigcsLcvb5pRU > SELF 0.00000000 Waves

{ "type": 13, "id": "VHjZXu1kroKpF87G9ZuZUEdR4BCVNVQe9HdFbYvLza5", "fee": 500000, "feeAssetId": null, "timestamp": 1678955602130, "version": 2, "chainId": 84, "sender": "3N2HGnBgfp7smNh1ok2kSwGigcsLcvb5pRU", "senderPublicKey": "HJWUBG6MGSbzNyQ7ypsGrtyBMEEihMcySK6RX9m5fwuj", "proofs": [ "2NAx93Moes1YgYXrH13hnVZokzgywkkJktdtMrS6ECGssyLeKPURGGu63Jmw4mYxkL3pVu9pgJSvCSHypMYegGhG" ], "script": null, "height": 2492338, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6Q8GricbhbJXbSq3ZzMFZrWS5dMS4MvHsZ48BDh7gq46 Next: 8MUWsiaJvGMNJfAiCZBnCCmiFi3PBNYVQFhtiWnvbi8n Full:
OldNewDifferences
1-{-# STDLIB_VERSION 5 #-}
2-{-# SCRIPT_TYPE ACCOUNT #-}
3-{-# CONTENT_TYPE DAPP #-}
4-let SEP = "__"
5-
6-let wavesAssetId = "WAVES"
7-
8-let invalidPriceAsset = "Invalid price asset"
9-
10-func throwErr (msg) = throw(makeString(["user_pools.ride:", msg], " "))
11-
12-
13-func throwPD () = throwErr("Permission denied")
14-
15-
16-func throwCreateNotCalled () = throwErr("Create is not called for assets pair")
17-
18-
19-func throwYouNotIssuer () = throwErr("You are not amountAsset issuer")
20-
21-
22-func throwPoolExists () = throwErr("Pool with such assets already exists")
23-
24-
25-func throwAssetNotVerified () = throwErr("Asset is not verified")
26-
27-
28-func throwInvalidPriceAsset () = throwErr(invalidPriceAsset)
29-
30-
31-func throwInvalidFeeAsset () = throwErr("Invalid fee asset")
32-
33-
34-func throwInvalidAmountAsset () = throwErr("Invalid amount asset attached")
35-
36-
37-func throwInvalidStatus () = throwErr("Invalid status")
38-
39-
40-func throwCanActivateOnlyPendingPool () = throwErr("Can activate pool only in 'pending' status")
41-
42-
43-func throwFactoryReturnedNotString () = throwErr("FactoryV2 returned not string")
44-
45-
46-func throwInvalidPriceAssetAmount () = throwErr("invalid price asset amount")
47-
48-
49-func throwInvalidFee () = throwErr("invalid fee")
50-
51-
52-func keyManagerPublicKey () = makeString(["%s", "managerPublicKey"], SEP)
53-
54-
55-func keyPendingManagerPublicKey () = makeString(["%s", "pendingManagerPublicKey"], SEP)
56-
57-
58-func keyAdminPubKeys () = makeString(["%s", "adminPubKeys"], SEP)
59-
60-
61-func keyStatus (amountAssetId,priceAssetId) = makeString(["%s%s%s", "status", amountAssetId, priceAssetId], SEP)
62-
63-
64-func keyFactoryContract () = makeString(["%s", "factoryContract"], SEP)
65-
66-
67-func keyAssetsStoreContract () = makeString(["%s", "assetsStoreContract"], SEP)
68-
69-
70-func keyEmissionContract () = makeString(["%s", "emissionContract"], SEP)
71-
72-
73-func keySuffix (amountAssetId,priceAssetId) = makeString(["%s%s%s", "suffix", amountAssetId, priceAssetId], SEP)
74-
75-
76-func keyLastIndex () = makeString(["%s", "lastIndex"], SEP)
77-
78-
79-let indexSuffix = "u"
80-
81-let statusPending = "pending"
82-
83-let statusDeclined = "declined"
84-
85-let statusActive = "active"
86-
87-let statuses = [statusPending, statusDeclined, statusActive]
88-
89-func keyCreateCalled (amountAssetId,priceAssetId) = makeString(["%s%s%s", "createCalled", amountAssetId, priceAssetId], SEP)
90-
91-
92-func keyCreateCaller (amountAssetId,priceAssetId) = makeString(["%s%s%s", "createCaller", amountAssetId, priceAssetId], SEP)
93-
94-
95-func keyAmountAssetAmount (amountAssetId,priceAssetId) = makeString(["%s%s%s", "amountAssetAmount", amountAssetId, priceAssetId], SEP)
96-
97-
98-func keyPriceAssetAmount (amountAssetId,priceAssetId) = makeString(["%s%s%s", "priceAssetAmount", amountAssetId, priceAssetId], SEP)
99-
100-
101-func keyHeight (amountAssetId,priceAssetId) = makeString(["%s%s%s", "height", amountAssetId, priceAssetId], SEP)
102-
103-
104-func keyFeeAssetId () = makeString(["%s", "feeAssetId"], SEP)
105-
106-
107-func keyFeeAmount () = makeString(["%s", "feeAmount"], SEP)
108-
109-
110-func keyAmountAssetMinAmount () = makeString(["%s", "amountAssetMinAmount"], SEP)
111-
112-
113-func keyPriceAssetsMinAmount () = makeString(["%s", "priceAssetsMinAmount"], SEP)
114-
115-
116-func keyPriceAssets () = makeString(["%s", "priceAssets"], SEP)
117-
118-
119-func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), (key + " is not defined"))
120-
121-
122-func stringOptionToList (stringOrUnit) = match stringOrUnit {
123- case s: String =>
124- if ((size(s) == 0))
125- then nil
126- else split(s, SEP)
127- case _: Unit =>
128- nil
129- case _ =>
130- throw("Match error")
131-}
132-
133-
134-let factoryContract = addressFromStringValue(getStringOrFail(keyFactoryContract()))
135-
136-func isCreateCalled (amountAssetId,priceAssetId) = valueOrElse(getBoolean(keyCreateCalled(amountAssetId, priceAssetId)), false)
137-
138-
139-func mustCreateCalled (amountAssetId,priceAssetId) = if (isCreateCalled(amountAssetId, priceAssetId))
140- then true
141- else throwCreateNotCalled()
142-
143-
144-func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
145- case s: String =>
146- fromBase58String(s)
147- case _: Unit =>
148- unit
149- case _ =>
150- throw("Match error")
151-}
152-
153-
154-func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
155- case s: String =>
156- fromBase58String(s)
157- case _: Unit =>
158- unit
159- case _ =>
160- throw("Match error")
161-}
162-
163-
164-func isManager (i) = match managerPublicKeyOrUnit() {
165- case pk: ByteVector =>
166- (i.callerPublicKey == pk)
167- case _: Unit =>
168- (i.caller == this)
169- case _ =>
170- throw("Match error")
171-}
172-
173-
174-func mustManager (i) = if (isManager(i))
175- then true
176- else throwPD()
177-
178-
179-func mustAdmin (i) = {
180- let adminPKs = stringOptionToList(getString(keyAdminPubKeys()))
181- if (containsElement(adminPKs, toBase58String(i.callerPublicKey)))
182- then true
183- else mustManager(i)
184- }
185-
186-
187-func isVerified (assetId) = (valueOrElse(getInteger(addressFromStringValue(getStringOrFail(keyAssetsStoreContract())), (("status_<" + assetId) + ">")), 0) == 2)
188-
189-
190-func getIdAndInfo (payment) = match payment.assetId {
191- case id: ByteVector =>
192- let info = value(assetInfo(id))
193- $Tuple2(toBase58String(id), info)
194- case _: Unit =>
195- $Tuple2(wavesAssetId, unit)
196- case _ =>
197- throw("Match error")
198-}
199-
200-
201-func validStatus (status) = containsElement(statuses, status)
202-
203-
204-@Callable(i)
205-func constructor (factoryV2Address,assetsStoreAddress,emissionAddress,priceAssetsMinAmount,amountAssetMinAmount,feeAssetId,feeAmount) = {
206- let checkCaller = mustManager(i)
207- if ((checkCaller == checkCaller))
208- then [StringEntry(keyFactoryContract(), factoryV2Address), StringEntry(keyAssetsStoreContract(), assetsStoreAddress), StringEntry(keyEmissionContract(), emissionAddress), StringEntry(keyPriceAssetsMinAmount(), makeString(priceAssetsMinAmount, SEP)), IntegerEntry(keyAmountAssetMinAmount(), amountAssetMinAmount), StringEntry(keyFeeAssetId(), feeAssetId), IntegerEntry(keyFeeAmount(), feeAmount)]
209- else throw("Strict value is not equal to itself.")
210- }
211-
212-
213-
214-@Callable(i)
215-func create () = {
216- let amountAssetPayment = value(i.payments[0])
217- let priceAssetPayment = value(i.payments[1])
218- let feeAssetPayment = value(i.payments[2])
219- let $t067946866 = getIdAndInfo(amountAssetPayment)
220- let amountAssetId = $t067946866._1
221- let amountAssetInfo = $t067946866._2
222- let $t068706939 = getIdAndInfo(priceAssetPayment)
223- let priceAssetId = $t068706939._1
224- let priceAssetInfo = $t068706939._2
225- let $t069437006 = getIdAndInfo(feeAssetPayment)
226- let feeAssetId = $t069437006._1
227- let feeAssetInfo = $t069437006._2
228- let priceAssetsList = stringOptionToList(getString(factoryContract, keyPriceAssets()))
229- let managerPriceAssetMinAmount = 1
230- let priceAssetMinAmount = if (isManager(i))
231- then managerPriceAssetMinAmount
232- else {
233- let priceAssetsIndex = valueOrErrorMessage(indexOf(priceAssetsList, priceAssetId), invalidPriceAsset)
234- value(parseInt(stringOptionToList(getString(keyPriceAssetsMinAmount()))[priceAssetsIndex]))
235- }
236- let lastIndex = valueOrElse(getInteger(keyLastIndex()), 0)
237- let curIndex = (lastIndex + 1)
238- let emissionContract = addressFromStringValue(getStringOrFail(keyEmissionContract()))
239- let poolExists = {
240- let @ = invoke(factoryContract, "poolExistsREADONLY", [amountAssetId, priceAssetId], nil)
241- if ($isInstanceOf(@, "Boolean"))
242- then @
243- else throw("Couldn't cast Any to Boolean")
244- }
245- let checks = [if (!(isCreateCalled(amountAssetId, priceAssetId)))
246- then true
247- else throwPoolExists(), if (!(poolExists))
248- then true
249- else throwPoolExists(), if (if (isManager(i))
250- then true
251- else isVerified(amountAssetId))
252- then true
253- else throwAssetNotVerified(), if ((getString(keyFeeAssetId()) == feeAssetId))
254- then true
255- else throwInvalidFeeAsset(), if (if (isManager(i))
256- then true
257- else (amountAssetPayment.amount >= getIntegerValue(keyAmountAssetMinAmount())))
258- then true
259- else throwInvalidAmountAsset(), if (if (isManager(i))
260- then true
261- else (priceAssetPayment.amount >= priceAssetMinAmount))
262- then true
263- else throwInvalidPriceAssetAmount(), if ((feeAssetPayment.amount == getInteger(keyFeeAmount())))
264- then true
265- else throwInvalidFee()]
266- if ((checks == checks))
267- then {
268- let burnEmissionInv = invoke(emissionContract, "burn", nil, [AttachedPayment(fromBase58String(feeAssetId), feeAssetPayment.amount)])
269- if ((burnEmissionInv == burnEmissionInv))
270- then [BooleanEntry(keyCreateCalled(amountAssetId, priceAssetId), true), StringEntry(keyCreateCaller(amountAssetId, priceAssetId), toString(i.caller)), IntegerEntry(keyLastIndex(), curIndex), StringEntry(keySuffix(amountAssetId, priceAssetId), (toString(curIndex) + indexSuffix)), IntegerEntry(keyHeight(amountAssetId, priceAssetId), height), StringEntry(keyStatus(amountAssetId, priceAssetId), statusPending), IntegerEntry(keyAmountAssetAmount(amountAssetId, priceAssetId), amountAssetPayment.amount), IntegerEntry(keyPriceAssetAmount(amountAssetId, priceAssetId), priceAssetPayment.amount)]
271- else throw("Strict value is not equal to itself.")
272- }
273- else throw("Strict value is not equal to itself.")
274- }
275-
276-
277-
278-@Callable(i)
279-func activate (poolAddress,amountAssetId,amountAssetTicker,priceAssetId,priceAssetTicker,logo) = {
280- let checks = [mustAdmin(i), if (isCreateCalled(amountAssetId, priceAssetId))
281- then true
282- else throwCreateNotCalled(), if ((value(getString(keyStatus(amountAssetId, priceAssetId))) == statusPending))
283- then true
284- else throwCanActivateOnlyPendingPool()]
285- if ((checks == checks))
286- then {
287- let activateNewPoolInv = invoke(factoryContract, "activateNewPool", [poolAddress, amountAssetId, priceAssetId, ((amountAssetTicker + priceAssetTicker) + "LP"), (((amountAssetTicker + "/") + priceAssetTicker) + " pool liquidity provider token"), 0, "VLTPOOL", logo], nil)
288- if ((activateNewPoolInv == activateNewPoolInv))
289- then {
290- let lpAssetId = match activateNewPoolInv {
291- case id: String =>
292- id
293- case _ =>
294- throwFactoryReturnedNotString()
295- }
296- if ((lpAssetId == lpAssetId))
297- then {
298- let beforePut = assetBalance(this, fromBase58String(lpAssetId))
299- if ((beforePut == beforePut))
300- then {
301- let put = invoke(addressFromStringValue(poolAddress), "put", [0, false], [AttachedPayment(if ((amountAssetId == "WAVES"))
302- then unit
303- else fromBase58String(amountAssetId), value(getInteger(keyAmountAssetAmount(amountAssetId, priceAssetId)))), AttachedPayment(if ((priceAssetId == "WAVES"))
304- then unit
305- else fromBase58String(priceAssetId), value(getInteger(keyPriceAssetAmount(amountAssetId, priceAssetId))))])
306- if ((put == put))
307- then {
308- let afterPut = assetBalance(this, fromBase58String(lpAssetId))
309- if ((afterPut == afterPut))
310- then {
311- let user = value(addressFromString(value(getString(keyCreateCaller(amountAssetId, priceAssetId)))))
312-[StringEntry(keyStatus(amountAssetId, priceAssetId), statusActive), ScriptTransfer(user, (afterPut - beforePut), fromBase58String(lpAssetId))]
313- }
314- else throw("Strict value is not equal to itself.")
315- }
316- else throw("Strict value is not equal to itself.")
317- }
318- else throw("Strict value is not equal to itself.")
319- }
320- else throw("Strict value is not equal to itself.")
321- }
322- else throw("Strict value is not equal to itself.")
323- }
324- else throw("Strict value is not equal to itself.")
325- }
326-
327-
328-
329-@Callable(i)
330-func setAdmins (adminPubKeys) = {
331- let checkCaller = mustManager(i)
332- if ((checkCaller == checkCaller))
333- then [StringEntry(keyAdminPubKeys(), makeString(adminPubKeys, SEP))]
334- else throw("Strict value is not equal to itself.")
335- }
336-
337-
338-
339-@Callable(i)
340-func setManager (pendingManagerPublicKey) = {
341- let checkCaller = mustManager(i)
342- if ((checkCaller == checkCaller))
343- then {
344- let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
345- if ((checkManagerPublicKey == checkManagerPublicKey))
346- then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
347- else throw("Strict value is not equal to itself.")
348- }
349- else throw("Strict value is not equal to itself.")
350- }
351-
352-
353-
354-@Callable(i)
355-func confirmManager () = {
356- let pm = pendingManagerPublicKeyOrUnit()
357- let hasPM = if (isDefined(pm))
358- then true
359- else throw("No pending manager")
360- if ((hasPM == hasPM))
361- then {
362- let checkPM = if ((i.callerPublicKey == value(pm)))
363- then true
364- else throw("You are not pending manager")
365- if ((checkPM == checkPM))
366- then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
367- else throw("Strict value is not equal to itself.")
368- }
369- else throw("Strict value is not equal to itself.")
370- }
371-
372-
373-
374-@Callable(i)
375-func priceAssetsREADONLY () = $Tuple2(nil, stringOptionToList(getString(keyPriceAssets())))
376-
377-
378-
379-@Callable(i)
380-func statusREADONLY (amountAssetId,priceAssetId) = {
381- let status = match getString(keyStatus(amountAssetId, priceAssetId)) {
382- case s: String =>
383- s
384- case _ =>
385- unit
386- }
387- $Tuple2(nil, status)
388- }
389-
390-
391-@Verifier(tx)
392-func verify () = {
393- let targetPublicKey = match managerPublicKeyOrUnit() {
394- case pk: ByteVector =>
395- pk
396- case _: Unit =>
397- tx.senderPublicKey
398- case _ =>
399- throw("Match error")
400- }
401- sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
402- }
403-
1+# no script

github/deemru/w8io/169f3d6 
47.94 ms