tx · Crb2Sx4M1dQ6zLiZNsVjeEvBJaCZcCkCSWrLNxpKzwZL 3MsRQhp2cbXJQxHETzdZQdj2QfP4b3Mp6UL: -0.01000000 Waves 2022.04.25 04:57 [2023389] smart account 3MsRQhp2cbXJQxHETzdZQdj2QfP4b3Mp6UL > SELF 0.00000000 Waves
{ "type": 13, "id": "Crb2Sx4M1dQ6zLiZNsVjeEvBJaCZcCkCSWrLNxpKzwZL", "fee": 1000000, "feeAssetId": null, "timestamp": 1650851891459, "version": 2, "chainId": 84, "sender": "3MsRQhp2cbXJQxHETzdZQdj2QfP4b3Mp6UL", "senderPublicKey": "FuM9F3sAdx6ZQfJfJMCdjC9w4wzTDx6F1KgWCbAM1KRy", "proofs": [ "38aSpd11GXjh12iaSt6sUw1MR54DHBPzNJq8yAGvUgevwmd5qyHk1jLFSu8WQqhjQihoNKjjKFxhvuFaTf2j4pb5" ], "script": "base64:AAIFAAAAAAAAAA4IAhIDCgEIEgUKAwgIAQAAAAgBAAAAEHdyaXRlQ29uc3RTdHJpbmcAAAACAAAAA2tleQAAAAV2YWx1ZQMJAQAAAAEhAAAAAQkBAAAACWlzRGVmaW5lZAAAAAEJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5CQEAAAALU3RyaW5nRW50cnkAAAACBQAAAANrZXkFAAAABXZhbHVlCQAAAgAAAAEJAAEsAAAAAgIAAAAVYWxyZWFkeSBpbml0aWFsaXplZDogBQAAAANrZXkAAAAAC2NvbmZpZ1N0b3JlAgAAAAZjb25maWcAAAAADWNvbmZpZ0FkZHJlc3MJAQAAABFAZXh0ck5hdGl2ZSgxMDYyKQAAAAECAAAAIzNNc1JRaHAyY2JYSlF4SEVUemRaUWRqMlFmUDRiM01wNlVMAAAAABJtYXliZU9yYWNsZUFkZHJlc3MEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAANY29uZmlnQWRkcmVzcwIAAAAOb3JhY2xlX2FkZHJlc3MDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN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ABXN0b3JlCQABLAAAAAIJAAEsAAAAAgkAAaQAAAABBQAAABFjdXJyZW50RXBvY2hTdGFydAIAAAABfAkAAaQAAAABCQAAZAAAAAIFAAAAH3VzZXJXaXRoZHJhd25XaXRoaW5DdXJyZW50RXBvY2gFAAAABmFtb3VudAUAAAADbmlsCQAAZQAAAAIJAABlAAAAAgUAAAADbG10BQAAAB91c2VyV2l0aGRyYXduV2l0aGluQ3VycmVudEVwb2NoBQAAAAZhbW91bnQJAAUUAAAAAgUAAAADbmlsAP//////////AAAAAPhpTiM=", "height": 2023389, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6PpWxbCb128BUze9VbxDAvspGNrFnxBhA61bn4v2mWPp Next: 4uY7uNg682mijftWrXTcGkFmEr7crcMbESXSNoywPLUY Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | func asInt (value) = match value { | |
5 | - | case int: Int => | |
6 | - | int | |
4 | + | func writeConstString (key,value) = if (!(isDefined(getString(this, key)))) | |
5 | + | then StringEntry(key, value) | |
6 | + | else throw(("already initialized: " + key)) | |
7 | + | ||
8 | + | ||
9 | + | let configStore = "config" | |
10 | + | ||
11 | + | let configAddress = addressFromStringValue("3MsRQhp2cbXJQxHETzdZQdj2QfP4b3Mp6UL") | |
12 | + | ||
13 | + | let maybeOracleAddress = match getString(configAddress, "oracle_address") { | |
14 | + | case s: String => | |
15 | + | addressFromString(s) | |
7 | 16 | case _ => | |
8 | - | | |
17 | + | unit | |
9 | 18 | } | |
10 | 19 | ||
20 | + | let HEIGHT = height | |
11 | 21 | ||
12 | - | func getI (key) = getInteger(this, key) | |
22 | + | let timeframe = 1440 | |
23 | + | ||
24 | + | func limit (assetId) = 1000000000 | |
13 | 25 | ||
14 | 26 | ||
15 | - | func writeInt (key,value) = if ((0 > value)) | |
16 | - | then throw(((("writing negative value " + toString(value)) + " for key ") + key)) | |
17 | - | else IntegerEntry(key, value) | |
27 | + | func userWithdrawnWithinEpochStore (user,assetId) = ((("withdrawn_" + user) + "_") + assetId) | |
18 | 28 | ||
19 | 29 | ||
20 | - | let main = addressFromStringValue("3PAZv9tgK1PX7dKR7b4kchq5qdpUS3G5sYT") | |
21 | - | ||
22 | - | let assetStringUsdc = "6XtHjpXbs9RRJP2Sr9GUyVqzACcby9TkThHXnjVC5CDJ" | |
23 | - | ||
24 | - | let reserveUsdc = addressFromStringValue("3PGCkrHBxFMi7tz1xqnxgBpeNvn5E4M4g8S") | |
25 | - | ||
26 | - | let assetId = fromBase58String(assetStringUsdc) | |
27 | - | ||
28 | - | let sender = addressFromStringValue("3MsRQhp2cbXJQxHETzdZQdj2QfP4b3Mp6UL") | |
29 | - | ||
30 | 30 | @Callable(i) | |
31 | - | func initbal (bal,key) = if ((i.caller != sender)) | |
32 | - | then throw("1") | |
33 | - | else $Tuple2([writeInt("MyBal", bal), writeInt(key, 0)], unit) | |
31 | + | func initialize (ca) = [writeConstString(configStore, ca)] | |
34 | 32 | ||
35 | 33 | ||
36 | 34 | ||
37 | 35 | @Callable(i) | |
38 | - | func byebye (lowm) = { | |
39 | - | let available = assetBalance(reserveUsdc, assetId) | |
40 | - | if ((lowm > available)) | |
41 | - | then throw("1") | |
42 | - | else { | |
43 | - | let uc = asInt(invoke(reserveUsdc, "userDepositUSD", [toString(this)], nil)) | |
44 | - | let v = if ((available > uc)) | |
45 | - | then uc | |
46 | - | else available | |
47 | - | if ((v == 0)) | |
48 | - | then throw("2") | |
49 | - | else $Tuple2(nil, asInt(invoke(main, "withdraw", [assetStringUsdc, v], nil))) | |
50 | - | } | |
51 | - | } | |
52 | - | ||
53 | - | ||
54 | - | ||
55 | - | @Callable(i) | |
56 | - | func goodbye (lowm) = { | |
57 | - | let available = assetBalance(reserveUsdc, assetId) | |
58 | - | if ((lowm > available)) | |
59 | - | then throw("1") | |
60 | - | else { | |
61 | - | let uc = valueOrElse(getI("MyBal"), 0) | |
62 | - | let v = if ((available > uc)) | |
63 | - | then uc | |
64 | - | else available | |
65 | - | if ((v == 0)) | |
66 | - | then throw("2") | |
67 | - | else $Tuple2([writeInt("MyBal", (uc - v))], asInt(invoke(main, "withdraw", [assetStringUsdc, v], nil))) | |
68 | - | } | |
69 | - | } | |
70 | - | ||
71 | - | ||
72 | - | ||
73 | - | @Callable(i) | |
74 | - | func kissmegoodbye (limitd,key) = { | |
75 | - | let available = assetBalance(reserveUsdc, assetId) | |
76 | - | if ((limitd > available)) | |
77 | - | then throw("1") | |
78 | - | else { | |
79 | - | let flag = valueOrElse(getI(key), 0) | |
80 | - | if ((flag == 1)) | |
81 | - | then throw("2") | |
82 | - | else $Tuple2([writeInt(key, 1)], asInt(invoke(main, "withdraw", [assetStringUsdc, limitd], nil))) | |
83 | - | } | |
84 | - | } | |
85 | - | ||
86 | - | ||
87 | - | ||
88 | - | @Callable(i) | |
89 | - | func testkiss (limitd,key) = { | |
90 | - | let available = 1000000000 | |
91 | - | if ((limitd > available)) | |
92 | - | then throw("1") | |
93 | - | else { | |
94 | - | let flag = valueOrElse(getI(key), 0) | |
95 | - | if ((flag == 1)) | |
96 | - | then throw("2") | |
97 | - | else $Tuple2([writeInt(key, 1), writeInt("MyBal", (flag + 1))], limitd) | |
98 | - | } | |
99 | - | } | |
100 | - | ||
101 | - | ||
102 | - | ||
103 | - | @Callable(i) | |
104 | - | func bb1 (lowm) = { | |
105 | - | let available = assetBalance(reserveUsdc, assetId) | |
106 | - | let uc = asInt(invoke(reserveUsdc, "userDepositUSD", [toString(this)], nil)) | |
107 | - | let v = if ((available > uc)) | |
108 | - | then uc | |
109 | - | else available | |
110 | - | if ((1 > v)) | |
111 | - | then throw("1") | |
112 | - | else $Tuple2(nil, asInt(invoke(main, "withdraw", [assetStringUsdc, v], nil))) | |
113 | - | } | |
36 | + | func validateWithdrawLimit (assetId,user,amount) = match limit(assetId) { | |
37 | + | case lmt: Int => | |
38 | + | let currentEpochStart = ((HEIGHT / timeframe) * timeframe) | |
39 | + | let currentEpochEnd = ((1 + (HEIGHT / timeframe)) * timeframe) | |
40 | + | let store = userWithdrawnWithinEpochStore(user, assetId) | |
41 | + | let tt = match getString(store) { | |
42 | + | case s: String => | |
43 | + | let data = split(s, "|") | |
44 | + | $Tuple2(parseIntValue(data[0]), parseIntValue(data[1])) | |
45 | + | case _ => | |
46 | + | $Tuple2(0, 0) | |
47 | + | } | |
48 | + | let epoch = tt._1 | |
49 | + | let withdrawn = tt._2 | |
50 | + | let userWithdrawnWithinCurrentEpoch = if ((epoch == currentEpochStart)) | |
51 | + | then withdrawn | |
52 | + | else 0 | |
53 | + | if (((userWithdrawnWithinCurrentEpoch + amount) > lmt)) | |
54 | + | then throw(((((((((((("breaching withdraw limit per " + toString(lmt)) + " ") + assetId) + " over ") + toString(timeframe)) + " blocks. Available: ") + toString((lmt - userWithdrawnWithinCurrentEpoch))) + " current epoch: ") + toString(currentEpochStart)) + "-") + toString(currentEpochEnd))) | |
55 | + | else $Tuple2([StringEntry(store, ((toString(currentEpochStart) + "|") + toString((userWithdrawnWithinCurrentEpoch + amount))))], ((lmt - userWithdrawnWithinCurrentEpoch) - amount)) | |
56 | + | case _ => | |
57 | + | $Tuple2(nil, -1) | |
58 | + | } | |
114 | 59 | ||
115 | 60 |
github/deemru/w8io/026f985 23.31 ms ◑