tx · 9afHXwHh2UxoJQFxqLuw6zqfYFiaKnxC7Q9DZj31CpK9 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq: -0.01000000 Waves 2023.07.19 12:27 [2672562] smart account 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq > SELF 0.00000000 Waves
{ "type": 13, "id": "9afHXwHh2UxoJQFxqLuw6zqfYFiaKnxC7Q9DZj31CpK9", "fee": 1000000, "feeAssetId": null, "timestamp": 1689758900243, "version": 2, "chainId": 84, "sender": "3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq", "senderPublicKey": "57SkjQUEwC1ayCqLbXLuzBqifK6B6SR6rfxtGsbAo3zW", "proofs": [ "2Qx9FFi4xCi5Xbx2xFNGDiPUCr31f6RXTbCwDMPKYD3aayV7mKQYjsLmhDiMfYzBi7cSN7d9MNo8gEx2kVEnV6it" ], "script": "base64:BgIaCAISAwoBARIAEgMKAQgSAwoBARIDCgEIEgAVAAxjb250cmFjdEZpbGUCEG1ydF9zdGFraW5nLnJpZGUAA1NFUAICX18ABnNjYWxlOACAwtcvAQh0aHJvd0VycgEDbXNnCQACAQkArAICCQCsAgIFDGNvbnRyYWN0RmlsZQICOiAFA21zZwAKa2V5QXNzZXRJZAkAuQkCCQDMCAICAiVzCQDMCAICB2Fzc2V0SWQFA25pbAUDU0VQABNrZXlFbWlzc2lvblBlckJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIQZW1pc3Npb25QZXJCbG9jawUDbmlsBQNTRVAADWtleVN0YXJ0QmxvY2sJALkJAgkAzAgCAgIlcwkAzAgCAgpzdGFydEJsb2NrBQNuaWwFA1NFUAAQa2V5VG90YWxMcEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICDXRvdGFsTHBBbW91bnQFA25pbAUDU0VQABNrZXlUb3RhbEFzc2V0QW1vdW50CQC5CQIJAMwIAgICJXMJAMwIAgIQdG90YWxBc3NldEFtb3VudAUDbmlsBQNTRVABD2tleVVzZXJMcEFt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zAgCCQEMSW50ZWdlckVudHJ5AgkBD2tleVVzZXJMcEFtb3VudAEFC3VzZXJBZGRyZXNzBQ9uZXdVc2VyTHBBbW91bnQJAMwIAgkBDEludGVnZXJFbnRyeQIJARprZXlVc2VyVG90YWxBc3NldFdpdGhkcmF3bgEFC3VzZXJBZGRyZXNzBRpuZXdVc2VyVG90YWxBc3NldFdpdGhkcmF3bgkAzAgCCQEMSW50ZWdlckVudHJ5AgUNa2V5U3RhcnRCbG9jawUGaGVpZ2h0CQDMCAIJAQ5TY3JpcHRUcmFuc2ZlcgMIBQFpBmNhbGxlcgUTd2l0aGRyYXdBc3NldEFtb3VudAUMYXNzZXRJZEJ5dGVzBQNuaWwJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BaQEVZ2V0VXNlckFzc2V0c1JFQURPTkxZAQt1c2VyQWRkcmVzcwQMdXNlckxwQW1vdW50CQEPZ2V0VXNlckxwQW1vdW50AQULdXNlckFkZHJlc3MEHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcJAGsDBQx1c2VyTHBBbW91bnQJAQ9nZXRDdXJyZW50UHJpY2UABQZzY2FsZTgJAJQKAgUDbmlsCQCVCgMFDHVzZXJMcEFtb3VudAUcdXNlckF2YWlsYWJsZUFzc2V0VG9XaXRoZHJhdwkBD2dldEN1cnJlbnRQcmljZQABaQEWZ2V0VG90YWxBc3NldHNSRUFET05MWQAJAJQKAgUDbmlsCQCVCgMFDXRvdGFsTHBBbW91bnQJAStnZXRUb3RhbEFzc2V0QW1vdW50V2l0aFByb2ZpdE9yTWF4QXZhaWxhYmxlAAkBD2dldEN1cnJlbnRQcmljZQAABHKXbA==", "height": 2672562, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6MqgmCdbvrGRDpGhqPsXLMXtpdFF6pEjrJrSbCVDvqxq Next: BrkV6ZnB28fo3AMKbuDLP5GHPgzyrbBBVsRxAjqjnbJw Diff:
Old | New | Differences | |
---|---|---|---|
121 | 121 | func withdraw (lpAssetWithdrawAmount) = { | |
122 | 122 | let userAddress = toString(i.caller) | |
123 | 123 | let userLpAmount = getUserLpAmount(userAddress) | |
124 | - | let check = [if ((userLpAmount >= lpAssetWithdrawAmount)) | |
124 | + | let check = [if ((lpAssetWithdrawAmount > 0)) | |
125 | + | then true | |
126 | + | else throwErr("amount should be more than 0"), if ((userLpAmount >= lpAssetWithdrawAmount)) | |
125 | 127 | then true | |
126 | 128 | else throwErr((("cannot withdraw more than available (" + toString(userLpAmount)) + ")"))] | |
127 | 129 | if ((check == check)) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let contractFile = "mrt_staking.ride" | |
5 | 5 | ||
6 | 6 | let SEP = "__" | |
7 | 7 | ||
8 | 8 | let scale8 = 100000000 | |
9 | 9 | ||
10 | 10 | func throwErr (msg) = throw(((contractFile + ": ") + msg)) | |
11 | 11 | ||
12 | 12 | ||
13 | 13 | let keyAssetId = makeString(["%s", "assetId"], SEP) | |
14 | 14 | ||
15 | 15 | let keyEmissionPerBlock = makeString(["%s", "emissionPerBlock"], SEP) | |
16 | 16 | ||
17 | 17 | let keyStartBlock = makeString(["%s", "startBlock"], SEP) | |
18 | 18 | ||
19 | 19 | let keyTotalLpAmount = makeString(["%s", "totalLpAmount"], SEP) | |
20 | 20 | ||
21 | 21 | let keyTotalAssetAmount = makeString(["%s", "totalAssetAmount"], SEP) | |
22 | 22 | ||
23 | 23 | func keyUserLpAmount (userAddress) = makeString(["%s%s", "userLpAmount", userAddress], SEP) | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func keyUserTotalAssetWithdrawn (userAddress) = makeString(["%s%s", "totalAssetWithdrawn", userAddress], SEP) | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func keyUserTotalAssetStaked (userAddress) = makeString(["%s%s", "totalAssetStaked", userAddress], SEP) | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | let totalLpAmount = valueOrElse(getInteger(this, keyTotalLpAmount), 0) | |
33 | 33 | ||
34 | 34 | let totalAssetAmount = valueOrElse(getInteger(this, keyTotalAssetAmount), 0) | |
35 | 35 | ||
36 | 36 | let assetIdString = valueOrElse(getString(this, keyAssetId), "WAVES") | |
37 | 37 | ||
38 | 38 | let assetIdBytes = if ((assetIdString == "WAVES")) | |
39 | 39 | then unit | |
40 | 40 | else fromBase58String(assetIdString) | |
41 | 41 | ||
42 | 42 | func getUserLpAmount (userAddress) = valueOrElse(getInteger(this, keyUserLpAmount(userAddress)), 0) | |
43 | 43 | ||
44 | 44 | ||
45 | 45 | func calcTotalProfit () = { | |
46 | 46 | let emissionPerBlock = valueOrElse(getInteger(this, keyEmissionPerBlock), 0) | |
47 | 47 | let startBlock = valueOrElse(getInteger(this, keyStartBlock), 0) | |
48 | 48 | let elapsedBlocks = (height - startBlock) | |
49 | 49 | max([0, (emissionPerBlock * elapsedBlocks)]) | |
50 | 50 | } | |
51 | 51 | ||
52 | 52 | ||
53 | 53 | func getTotalAssetAmountWithProfitOrMaxAvailable () = { | |
54 | 54 | let totalAssetAmountWithProfit = (totalAssetAmount + calcTotalProfit()) | |
55 | 55 | match assetIdBytes { | |
56 | 56 | case u: Unit => | |
57 | 57 | min([totalAssetAmountWithProfit, wavesBalance(this).available]) | |
58 | 58 | case b: ByteVector => | |
59 | 59 | min([totalAssetAmountWithProfit, assetBalance(this, b)]) | |
60 | 60 | case _ => | |
61 | 61 | throw("Match error") | |
62 | 62 | } | |
63 | 63 | } | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func getCurrentPrice () = if ((totalLpAmount != 0)) | |
67 | 67 | then fraction(getTotalAssetAmountWithProfitOrMaxAvailable(), scale8, totalLpAmount) | |
68 | 68 | else (1 * scale8) | |
69 | 69 | ||
70 | 70 | ||
71 | 71 | func getStakeAction (i,userAddress) = { | |
72 | 72 | let checks = [if ((size(i.payments) == 1)) | |
73 | 73 | then true | |
74 | 74 | else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes)) | |
75 | 75 | then true | |
76 | 76 | else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0)) | |
77 | 77 | then true | |
78 | 78 | else "payment amount should be greater than 0"] | |
79 | 79 | if ((checks == checks)) | |
80 | 80 | then { | |
81 | 81 | let paymentAmount = i.payments[0].amount | |
82 | 82 | let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice()) | |
83 | 83 | let userLpAmount = getUserLpAmount(userAddress) | |
84 | 84 | let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0) | |
85 | 85 | let newTotalLpAmount = (totalLpAmount + paymentLpAmount) | |
86 | 86 | let newTotalAssetAmount = (totalAssetAmount + paymentAmount) | |
87 | 87 | let newUserLpAmount = (userLpAmount + paymentLpAmount) | |
88 | 88 | let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount) | |
89 | 89 | let updateStartHeightAction = if ((totalLpAmount == 0)) | |
90 | 90 | then [IntegerEntry(keyStartBlock, height)] | |
91 | 91 | else nil | |
92 | 92 | ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)] ++ updateStartHeightAction) | |
93 | 93 | } | |
94 | 94 | else throw("Strict value is not equal to itself.") | |
95 | 95 | } | |
96 | 96 | ||
97 | 97 | ||
98 | 98 | @Callable(i) | |
99 | 99 | func setEmissionPerBlock (emissionPerBlock) = { | |
100 | 100 | let check = [if ((i.caller == this)) | |
101 | 101 | then true | |
102 | 102 | else throwErr("permission denied")] | |
103 | 103 | if ((check == check)) | |
104 | 104 | then [IntegerEntry(keyTotalAssetAmount, getTotalAssetAmountWithProfitOrMaxAvailable()), IntegerEntry(keyStartBlock, height), IntegerEntry(keyEmissionPerBlock, max([0, emissionPerBlock]))] | |
105 | 105 | else throw("Strict value is not equal to itself.") | |
106 | 106 | } | |
107 | 107 | ||
108 | 108 | ||
109 | 109 | ||
110 | 110 | @Callable(i) | |
111 | 111 | func stake () = getStakeAction(i, toString(i.caller)) | |
112 | 112 | ||
113 | 113 | ||
114 | 114 | ||
115 | 115 | @Callable(i) | |
116 | 116 | func stakeFor (userAddress) = getStakeAction(i, userAddress) | |
117 | 117 | ||
118 | 118 | ||
119 | 119 | ||
120 | 120 | @Callable(i) | |
121 | 121 | func withdraw (lpAssetWithdrawAmount) = { | |
122 | 122 | let userAddress = toString(i.caller) | |
123 | 123 | let userLpAmount = getUserLpAmount(userAddress) | |
124 | - | let check = [if ((userLpAmount >= lpAssetWithdrawAmount)) | |
124 | + | let check = [if ((lpAssetWithdrawAmount > 0)) | |
125 | + | then true | |
126 | + | else throwErr("amount should be more than 0"), if ((userLpAmount >= lpAssetWithdrawAmount)) | |
125 | 127 | then true | |
126 | 128 | else throwErr((("cannot withdraw more than available (" + toString(userLpAmount)) + ")"))] | |
127 | 129 | if ((check == check)) | |
128 | 130 | then { | |
129 | 131 | let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount) | |
130 | 132 | let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8) | |
131 | 133 | let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount) | |
132 | 134 | let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8) | |
133 | 135 | let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0) | |
134 | 136 | let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount) | |
135 | 137 | [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), IntegerEntry(keyStartBlock, height), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)] | |
136 | 138 | } | |
137 | 139 | else throw("Strict value is not equal to itself.") | |
138 | 140 | } | |
139 | 141 | ||
140 | 142 | ||
141 | 143 | ||
142 | 144 | @Callable(i) | |
143 | 145 | func getUserAssetsREADONLY (userAddress) = { | |
144 | 146 | let userLpAmount = getUserLpAmount(userAddress) | |
145 | 147 | let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8) | |
146 | 148 | $Tuple2(nil, $Tuple3(userLpAmount, userAvailableAssetToWithdraw, getCurrentPrice())) | |
147 | 149 | } | |
148 | 150 | ||
149 | 151 | ||
150 | 152 | ||
151 | 153 | @Callable(i) | |
152 | 154 | func getTotalAssetsREADONLY () = $Tuple2(nil, $Tuple3(totalLpAmount, getTotalAssetAmountWithProfitOrMaxAvailable(), getCurrentPrice())) | |
153 | 155 | ||
154 | 156 |
github/deemru/w8io/026f985 46.93 ms ◑