tx · 65remLvToC36SH7VaK6p9MCsrzbBAgEb247SjKueYXQg

3Mzt645zA6u2QG6jRPoo6H6CK89kVggFgNi:  -0.01400000 Waves

2022.06.07 15:34 [2085952] smart account 3Mzt645zA6u2QG6jRPoo6H6CK89kVggFgNi > SELF 0.00000000 Waves

{ "type": 13, "id": "65remLvToC36SH7VaK6p9MCsrzbBAgEb247SjKueYXQg", "fee": 1400000, "feeAssetId": null, "timestamp": 1654605293674, "version": 1, "sender": "3Mzt645zA6u2QG6jRPoo6H6CK89kVggFgNi", "senderPublicKey": "7uejFa4bRSfBcedNiZpvC7nH9dnudVtejqqd8Rq4o8Ay", "proofs": [ "4tZrQHNw7yHiLLsu1kNiizg7BbauvKMjMSqRXQSMbMXDvWVFzC5SxQKQHAYeX1f8QWRdfQGFzSTVCjLRoWTviUqY", "JhzRzdZhN6hKKju5ooLSyQD9UMpKFk3UgV47v7QQHPsEZEeGLfUh2PJjzTxoNcmsnZUjtBfgm5HrEsXxzugaRDJ" ], "script": null, "chainId": 84, "height": 2085952, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8RSunht1hDBARnU5YhJRHQ22krRU6YhuCdKyRjVpzet2 Next: DKxyAgX2ubtyYE6nAwvpw2t3JdQmVy9x36YuCS9W2mWy Full:
OldNewDifferences
1-{-# STDLIB_VERSION 4 #-}
2-{-# SCRIPT_TYPE ACCOUNT #-}
3-{-# CONTENT_TYPE DAPP #-}
4-let SEP = "__"
5-
6-func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), ("No data for this.key=" + key))
7-
8-
9-func getBooleanOrFail (key) = valueOrErrorMessage(getBoolean(this, key), ("No data for this.key=" + key))
10-
11-
12-func failExecuteGet (msg,baseAssetStr,userAddressStr,getTxIdStr) = throw(((((((msg + ": baseAssetStr=") + baseAssetStr) + " userAddressStr=") + userAddressStr) + " getTxIdStr=") + getTxIdStr))
13-
14-
15-func keyAssetCfg (baseAssetStr) = ("%s%s%s__config__asset__" + baseAssetStr)
16-
17-
18-func keyNextInternalAssetId () = "%s__nextInternalAssetId"
19-
20-
21-func keyPriceLast (internalBasetAssetStr) = ("%s%s%d__price__last__" + internalBasetAssetStr)
22-
23-
24-func keyPriceHistory (internalBasetAssetStr,h,timestamp) = makeString(["%s%s%d%d%d__price__history", internalBasetAssetStr, toString(h), toString(timestamp)], SEP)
25-
26-
27-func keyTotalLocked (internalBasetAssetStr) = ("%s%s%d__total__locked__" + internalBasetAssetStr)
28-
29-
30-func keyTotalLockedByUser (internalBaseAssetStr,userAddressStr) = makeString(["%s%s%d%s__total__locked", internalBaseAssetStr, userAddressStr], SEP)
31-
32-
33-func keyMappingsInternal2baseAssetId (internalBaseAsset) = ("%s%s%d__mappings__internal2baseAssetId__" + toString(internalBaseAsset))
34-
35-
36-func keyMappingsBaseAsset2internalId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr)
37-
38-
39-func keyMappingsShare2baseAssetId (shareAssetStr) = ("%s%s%s__mappings__share2baseAssetId__" + shareAssetStr)
40-
41-
42-func keyMappingsBaseAsset2shareId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2shareId__" + baseAssetStr)
43-
44-
45-func keyShutdownPutOperation (internalBaseAssetStr) = ("%s%s%d__shutdown__put__" + internalBaseAssetStr)
46-
47-
48-func keyShutdownManager (internalBaseAssetStr) = ("%s%s%d__shutdown__manager__" + internalBaseAssetStr)
49-
50-
51-let IdxCfgShareAssetId = 1
52-
53-let IdxCfgInternalBaseAsset = 2
54-
55-let IdxCfgDecimalsMultBothAssets = 3
56-
57-let IdxCfgDecimalsMultPrice = 4
58-
59-let IdxCfgGetDelayBlocks = 5
60-
61-func dataAssetCfg (shareAssetStr,internalBaseAssetStr,decimalsMultBothAssets,decimalsMultPrice,getDelayInBlocks) = makeString(["%s%d%d%d%d", shareAssetStr, internalBaseAssetStr, toString(decimalsMultBothAssets), toString(decimalsMultPrice), toString(getDelayInBlocks)], SEP)
62-
63-
64-let IdxTotalLockedShare = 1
65-
66-let IdxTotalLockedBase = 2
67-
68-func dataTotalLocked (shareAssetAmount,baseAssetAmount) = makeString(["%d%d", toString(shareAssetAmount), toString(baseAssetAmount)], SEP)
69-
70-
71-func readTotalLocked (key) = {
72- let totalLockedArray = split(valueOrElse(getString(this, key), dataTotalLocked(0, 0)), SEP)
73-[-1, parseIntValue(totalLockedArray[IdxTotalLockedShare]), parseIntValue(totalLockedArray[IdxTotalLockedBase])]
74- }
75-
76-
77-func keyOperation (operationType,internalBaseAssetStr,userAddress,txId) = makeString(["%s%d%s%s", operationType, internalBaseAssetStr, userAddress, txId], SEP)
78-
79-
80-let IdxOperStatus = 1
81-
82-let IdxOperInAmount = 2
83-
84-let IdxOperPrice = 3
85-
86-let IdxOperOutAmount = 4
87-
88-let IdxOperStartHeight = 5
89-
90-let IdxOperStartTimestamp = 6
91-
92-let IdxOperEndHeight = 7
93-
94-let IdxOperEndTimestamp = 8
95-
96-func privateDataOperationAllStrings (status,inAssetAmount,price,outAssetAmount,startHeight,startTimestamp,endHeight,endTimestamp) = makeString(["%s%d%d%d%d%d%d%d", status, inAssetAmount, price, outAssetAmount, startHeight, startTimestamp, endHeight, endTimestamp], SEP)
97-
98-
99-func dataOperation (status,inAssetAmount,price,outAssetAmount,startHeight,startTimestamp,endHeight,endTimestamp) = privateDataOperationAllStrings(status, toString(inAssetAmount), toString(price), toString(outAssetAmount), toString(startHeight), toString(startTimestamp), toString(endHeight), toString(endTimestamp))
100-
101-
102-func dataOperationExecutionUpdate (currOperArray,newStatus,newEndTimestamp) = privateDataOperationAllStrings(newStatus, currOperArray[IdxOperInAmount], currOperArray[IdxOperPrice], currOperArray[IdxOperOutAmount], currOperArray[IdxOperStartHeight], currOperArray[IdxOperStartTimestamp], currOperArray[IdxOperEndHeight], toString(newEndTimestamp))
103-
104-
105-func readAssetCfgOrFail (baseAssetStr) = {
106- let key = keyAssetCfg(baseAssetStr)
107- split(getStringOrFail(key), SEP)
108- }
109-
110-
111-func incrementTotalLocked (key,shareAssetAmount,baseAssetAmount) = {
112- let dataArray = readTotalLocked(key)
113- StringEntry(key, dataTotalLocked((dataArray[IdxTotalLockedShare] + shareAssetAmount), (dataArray[IdxTotalLockedBase] + baseAssetAmount)))
114- }
115-
116-
117-func decrementTotalLocked (key,shareAssetAmount,baseAssetAmount) = {
118- let dataArray = readTotalLocked(key)
119- StringEntry(key, dataTotalLocked((dataArray[IdxTotalLockedShare] - shareAssetAmount), (dataArray[IdxTotalLockedBase] - baseAssetAmount)))
120- }
121-
122-
123-func genericCalcPrice (internalBaseAssetStr,baseAssetId,topUpBaseAmount,shareAssetId,decimalsMultBothAssets,decimalsMultPrice) = {
124- let totalLockedArray = readTotalLocked(keyTotalLocked(internalBaseAssetStr))
125- let totalLockedBaseAmount = totalLockedArray[IdxTotalLockedBase]
126- let baseAssetBalance = assetBalance(this, baseAssetId)
127- let baseAssetBalanceConsideringLock = ((baseAssetBalance - totalLockedBaseAmount) + topUpBaseAmount)
128- if ((0 > baseAssetBalanceConsideringLock))
129- then throw(((("baseAssetBalanceConsideringLock < 0: baseAssetBalance=" + toString(baseAssetBalance)) + " baseAssetBalanceConsideringLock=") + toString(baseAssetBalanceConsideringLock)))
130- else {
131- let shareEmission = value(assetInfo(shareAssetId)).quantity
132- let price = if ((shareEmission == 0))
133- then (1 * decimalsMultPrice)
134- else fraction(baseAssetBalanceConsideringLock, decimalsMultPrice, shareEmission)
135- $Tuple5(price, baseAssetBalance, totalLockedBaseAmount, baseAssetBalanceConsideringLock, shareEmission)
136- }
137- }
138-
139-
140-func calcPrice (internalBaseAssetStr,baseAssetId,shareAssetId,decimalsMultBothAssets,decimalsMultPrice) = genericCalcPrice(internalBaseAssetStr, baseAssetId, 0, shareAssetId, decimalsMultBothAssets, decimalsMultPrice)
141-
142-
143-func privateCurrentSysParamsREST (baseAssetStr) = {
144- let baseAssetId = fromBase58String(baseAssetStr)
145- let cfgArray = readAssetCfgOrFail(baseAssetStr)
146- let shareAssetStr = cfgArray[IdxCfgShareAssetId]
147- let shareAssetId = fromBase58String(shareAssetStr)
148- let decimalsMultBothAssets = parseIntValue(cfgArray[IdxCfgDecimalsMultBothAssets])
149- let decimalsMultPrice = parseIntValue(cfgArray[IdxCfgDecimalsMultPrice])
150- let internalBaseAssetStr = cfgArray[IdxCfgInternalBaseAsset]
151- let sysState = calcPrice(internalBaseAssetStr, baseAssetId, shareAssetId, decimalsMultBothAssets, decimalsMultPrice)
152- $Tuple6(IntegerEntry("price", sysState._1), IntegerEntry("decimalsMultPrice", decimalsMultPrice), IntegerEntry("baseAssetBalance", sysState._2), IntegerEntry("totalLockedBaseAmount", sysState._3), IntegerEntry("baseAssetBalanceConsideringLock", sysState._4), IntegerEntry("shareEmission", sysState._5))
153- }
154-
155-
156-@Callable(i)
157-func adminRegisterAsset (baseAssetStr,shareAssetName,shareAssetDescr,getDelayinBlocks,shutdownManagerAddress) = {
158- let baseAssetId = fromBase58String(baseAssetStr)
159- let decimals = value(assetInfo(baseAssetId)).decimals
160- if ((i.caller != this))
161- then throw("permissions denied")
162- else if ((toString(addressFromStringValue(shutdownManagerAddress)) != shutdownManagerAddress))
163- then throw("invalid shutdownManagerAddress")
164- else if ((0 > getDelayinBlocks))
165- then throw(("invalid getDelayinBlocks=" + toString(getDelayinBlocks)))
166- else {
167- let shareAssetIssueAction = Issue(shareAssetName, shareAssetDescr, 1, decimals, true)
168- let shareAssetId = calculateAssetId(shareAssetIssueAction)
169- let shareAssetStr = toBase58String(shareAssetId)
170- let decimalsMultPrice = ((100 * 1000) * 1000)
171- let decimalsMultBothAssets = pow(10, 0, decimals, 0, 0, DOWN)
172- let startPrice = (1 * decimalsMultPrice)
173- let internalBaseAssettId = valueOrElse(getInteger(this, keyNextInternalAssetId()), 0)
174- let internalBaseAssetStr = toString(internalBaseAssettId)
175-[StringEntry(keyAssetCfg(baseAssetStr), dataAssetCfg(shareAssetStr, internalBaseAssetStr, decimalsMultBothAssets, decimalsMultPrice, getDelayinBlocks)), StringEntry(keyMappingsInternal2baseAssetId(internalBaseAssettId), baseAssetStr), StringEntry(keyMappingsBaseAsset2internalId(baseAssetStr), internalBaseAssetStr), StringEntry(keyMappingsShare2baseAssetId(shareAssetStr), baseAssetStr), StringEntry(keyMappingsBaseAsset2shareId(baseAssetStr), shareAssetStr), BooleanEntry(keyShutdownPutOperation(internalBaseAssetStr), false), StringEntry(keyShutdownManager(internalBaseAssetStr), shutdownManagerAddress), IntegerEntry(keyNextInternalAssetId(), (internalBaseAssettId + 1)), IntegerEntry(keyPriceLast(internalBaseAssetStr), startPrice), IntegerEntry(keyPriceHistory(internalBaseAssetStr, height, lastBlock.timestamp), startPrice), shareAssetIssueAction, Burn(shareAssetId, 1)]
176- }
177- }
178-
179-
180-
181-@Callable(i)
182-func shutdownPut (internalBaseAssetId) = {
183- let internalBaseAssetIdStr = toString(internalBaseAssetId)
184- let baseAssetIdStr = getStringOrFail(keyMappingsInternal2baseAssetId(internalBaseAssetId))
185- let shutdownManagerAddress = getStringOrFail(keyShutdownManager(internalBaseAssetIdStr))
186- if ((1 > size(baseAssetIdStr)))
187- then throw("invalid internalBaseAssetId")
188- else if ((toString(i.caller) != shutdownManagerAddress))
189- then throw("access denied")
190- else [BooleanEntry(keyShutdownPutOperation(toString(internalBaseAssetId)), true)]
191- }
192-
193-
194-
195-@Callable(i)
196-func put () = {
197- let pmt = value(i.payments[0])
198- let baseAssetId = value(pmt.assetId)
199- let baseAssetStr = toBase58String(baseAssetId)
200- let userAddressStr = toString(i.caller)
201- let cfgArray = readAssetCfgOrFail(baseAssetStr)
202- let shareAssetStr = cfgArray[IdxCfgShareAssetId]
203- let shareAssetId = fromBase58String(shareAssetStr)
204- let decimalsMultBothAssets = parseIntValue(cfgArray[IdxCfgDecimalsMultBothAssets])
205- let decimalsMultPrice = parseIntValue(cfgArray[IdxCfgDecimalsMultPrice])
206- let internalBaseAssetStr = cfgArray[IdxCfgInternalBaseAsset]
207- let isPutBlocked = getBooleanOrFail(keyShutdownPutOperation(internalBaseAssetStr))
208- if (isPutBlocked)
209- then throw("put operation is blocked")
210- else {
211- let price = calcPrice(internalBaseAssetStr, baseAssetId, shareAssetId, decimalsMultBothAssets, decimalsMultPrice)._1
212- let shareAssetAmount = fraction(pmt.amount, decimalsMultPrice, price)
213-[Reissue(shareAssetId, shareAssetAmount, true), ScriptTransfer(i.caller, shareAssetAmount, shareAssetId), StringEntry(keyOperation("P", internalBaseAssetStr, userAddressStr, toBase58String(i.transactionId)), dataOperation("FINISHED", pmt.amount, price, shareAssetAmount, height, lastBlock.timestamp, height, lastBlock.timestamp))]
214- }
215- }
216-
217-
218-
219-@Callable(i)
220-func submitGetRequest () = {
221- let pmt = value(i.payments[0])
222- let shareAssetId = value(pmt.assetId)
223- let shareAssetStr = toBase58String(shareAssetId)
224- let callerPubStr = toBase58String(i.callerPublicKey)
225- let userAddress = i.caller
226- let userAddressStr = toString(userAddress)
227- let shareAssetAmount = pmt.amount
228- let baseAssetStr = getStringOrFail(keyMappingsShare2baseAssetId(shareAssetStr))
229- let baseAssetId = fromBase58String(baseAssetStr)
230- let cfgArray = readAssetCfgOrFail(baseAssetStr)
231- let decimalsMultBothAssets = parseIntValue(cfgArray[IdxCfgDecimalsMultBothAssets])
232- let decimalsMultPrice = parseIntValue(cfgArray[IdxCfgDecimalsMultPrice])
233- let getDelayBlocks = parseIntValue(cfgArray[IdxCfgGetDelayBlocks])
234- let internalBaseAssetStr = cfgArray[IdxCfgInternalBaseAsset]
235- let price = calcPrice(internalBaseAssetStr, baseAssetId, shareAssetId, decimalsMultBothAssets, decimalsMultPrice)._1
236- let baseAssetAmount = fraction(shareAssetAmount, price, decimalsMultPrice)
237- let operationKey = keyOperation("G", internalBaseAssetStr, userAddressStr, toBase58String(i.transactionId))
238- let operationData = dataOperation("PENDING", shareAssetAmount, price, baseAssetAmount, height, lastBlock.timestamp, (height + getDelayBlocks), 0)
239-[Burn(shareAssetId, shareAssetAmount), StringEntry(operationKey, operationData), incrementTotalLocked(keyTotalLocked(internalBaseAssetStr), shareAssetAmount, baseAssetAmount), incrementTotalLocked(keyTotalLockedByUser(internalBaseAssetStr, userAddressStr), shareAssetAmount, baseAssetAmount)]
240- }
241-
242-
243-
244-@Callable(i)
245-func executeGetRequest (baseAssetStr,userAddressStr,getTxIdStr) = {
246- let userAddress = addressFromStringValue(userAddressStr)
247- let assetCfgArray = readAssetCfgOrFail(baseAssetStr)
248- let shareAssetId = fromBase58String(assetCfgArray[IdxCfgShareAssetId])
249- let baseAssetId = fromBase58String(baseAssetStr)
250- let internalBaseAssetStr = assetCfgArray[IdxCfgInternalBaseAsset]
251- let operationKey = keyOperation("G", internalBaseAssetStr, userAddressStr, getTxIdStr)
252- let operationArray = split(getStringOrFail(operationKey), SEP)
253- let status = operationArray[IdxOperStatus]
254- let endHeight = parseIntValue(operationArray[IdxOperEndHeight])
255- let inShareAmount = parseIntValue(operationArray[IdxOperInAmount])
256- let outBaseAmount = parseIntValue(operationArray[IdxOperOutAmount])
257- if ((status != "PENDING"))
258- then failExecuteGet("Status is not PENDING", baseAssetStr, userAddressStr, getTxIdStr)
259- else if ((endHeight > height))
260- then failExecuteGet(((("EndHeight[" + toString(endHeight)) + "] > ") + toString(height)), baseAssetStr, userAddressStr, getTxIdStr)
261- else [ScriptTransfer(userAddress, outBaseAmount, baseAssetId), StringEntry(operationKey, dataOperationExecutionUpdate(operationArray, "FINISHED", lastBlock.timestamp)), decrementTotalLocked(keyTotalLocked(internalBaseAssetStr), inShareAmount, outBaseAmount), decrementTotalLocked(keyTotalLockedByUser(internalBaseAssetStr, userAddressStr), inShareAmount, outBaseAmount)]
262- }
263-
264-
265-
266-@Callable(i)
267-func topUpBalance (baseAssetStr) = {
268- let assetCfgArray = readAssetCfgOrFail(baseAssetStr)
269- let pmt = value(i.payments[0])
270- let pmtAssetId = value(pmt.assetId)
271- let pmtAssetStr = toBase58String(pmtAssetId)
272- let shareAssetId = fromBase58String(assetCfgArray[IdxCfgShareAssetId])
273- let decimalsMultBothAssets = parseIntValue(assetCfgArray[IdxCfgDecimalsMultBothAssets])
274- let decimalsMultPrice = parseIntValue(assetCfgArray[IdxCfgDecimalsMultPrice])
275- let internalBaseAssetStr = assetCfgArray[IdxCfgInternalBaseAsset]
276- if ((baseAssetStr != pmtAssetStr))
277- then throw("attached payment's asset id is NOT matched passed baseAssetStr")
278- else if ((size(i.payments) > 1))
279- then throw("only one payment can be attached")
280- else {
281- let price = genericCalcPrice(internalBaseAssetStr, pmtAssetId, pmt.amount, shareAssetId, decimalsMultBothAssets, decimalsMultPrice)._1
282-[IntegerEntry(keyPriceLast(internalBaseAssetStr), price), IntegerEntry(keyPriceHistory(internalBaseAssetStr, height, lastBlock.timestamp), price)]
283- }
284- }
285-
286-
287-
288-@Callable(i)
289-func currentSysParamsREST (baseAssetStr) = {
290- let sysStateTuple = privateCurrentSysParamsREST(baseAssetStr)
291- let price = sysStateTuple._1.value
292- let decimalsMultPrice = sysStateTuple._2.value
293- let baseAssetBalance = sysStateTuple._3.value
294- let totalLockedBaseAmount = sysStateTuple._4.value
295- let baseAssetBalanceConsideringLock = sysStateTuple._5.value
296- let shareEmission = sysStateTuple._6.value
297- let restData = makeString(["startCurrentSysParamsREST", toString(price), toString(decimalsMultPrice), toString(baseAssetBalance), toString(totalLockedBaseAmount), toString(baseAssetBalanceConsideringLock), toString(shareEmission), "endCurrentSysParamsREST"], SEP)
298- throw(restData)
299- }
300-
301-
302-@Verifier(tx)
303-func verify () = {
304- let pubKeyAdminsList = ["kMVLGCwXnETBo7cjirdUTSrrWXCDYFUNY56FyHEvpj1", "GidQ61btQCXZBYeuYqpJphw5hP1o9zyduRTwrEvUzPZ", "DTz4eaCd7UfVtfodw4GrVJ2bE4HQFYW6T94mpGsHMhXz"]
305- let s0 = if (sigVerify(tx.bodyBytes, tx.proofs[0], fromBase58String(pubKeyAdminsList[0])))
306- then 1
307- else 0
308- let s1 = if (sigVerify(tx.bodyBytes, tx.proofs[1], fromBase58String(pubKeyAdminsList[1])))
309- then 1
310- else 0
311- let s2 = if (sigVerify(tx.bodyBytes, tx.proofs[2], fromBase58String(pubKeyAdminsList[2])))
312- then 1
313- else 0
314- let count = ((s0 + s1) + s2)
315- if ((2 > count))
316- then throw(((((("invalid multisig: s0=" + toString(s0)) + " s1=") + toString(s1)) + " s2=") + toString(s2)))
317- else true
318- }
319-
1+# no script

github/deemru/w8io/026f985 
48.56 ms