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