tx · 8DtA7EiAcWtZLi6aqRfRowYse6MqYC8WpHisY1SRrVSA 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq: -0.01000000 Waves 2023.07.18 17:05 [2671415] smart account 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq > SELF 0.00000000 Waves
{ "type": 13, "id": "8DtA7EiAcWtZLi6aqRfRowYse6MqYC8WpHisY1SRrVSA", "fee": 1000000, "feeAssetId": null, "timestamp": 1689689167534, "version": 2, "chainId": 84, "sender": "3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq", "senderPublicKey": "57SkjQUEwC1ayCqLbXLuzBqifK6B6SR6rfxtGsbAo3zW", "proofs": [ "pHxBsUTdBqoXTR6woNb9zdhd3iEbrMwArHZkBvUKcuqj9BmSYGXETVTfvmB6LEJzhQWfs6reCdW9He8Qa5ie133" ], "script": "base64:BgIVCAISAwoBARIAEgMKAQESAwoBCBIAEwAMY29udHJhY3RGaWxlAhBtcnRfc3Rha2luZy5yaWRlAANTRVACAl9fAAZzY2FsZTgAgMLXLwEIdGhyb3dFcnIBA21zZwkAAgEJAKwCAgkArAICBQxjb250cmFjdEZpbGUCAjogBQNtc2cACmtleUFzc2V0SWQJALkJAgkAzAgCAgIlcwkAzAgCAgdhc3NldElkBQNuaWwFA1NFUAATa2V5RW1pc3Npb25QZXJCbG9jawkAuQkCCQDMCAICAiVzCQDMCAICEGVtaXNzaW9uUGVyQmxvY2sFA25pbAUDU0VQAA1rZXlTdGFydEJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIKc3RhcnRCbG9jawUDbmlsBQNTRVAAEGtleVRvdGFsTHBBbW91bnQJALkJAgkAzAgCAgIlcwkAzAgCAg10b3RhbExwQW1vdW50BQNuaWwFA1NFUAATa2V5VG90YWxBc3NldEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICEHRvdGFsQXNzZXRBbW91bnQFA25pbAUDU0VQAQ9rZXlVc2VyTHBBbW91bnQBC3VzZXJBZGRy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THBBbW91bnQFEG5ld1RvdGFsTHBBbW91bnQJAMwIAgkBDEludGVnZXJFbnRyeQIFE2tleVRvdGFsQXNzZXRBbW91bnQFE25ld1RvdGFsQXNzZXRBbW91bnQJAMwIAgkBDEludGVnZXJFbnRyeQIJAQ9rZXlVc2VyTHBBbW91bnQBBQt1c2VyQWRkcmVzcwUPbmV3VXNlckxwQW1vdW50CQDMCAIJAQxJbnRlZ2VyRW50cnkCCQEaa2V5VXNlclRvdGFsQXNzZXRXaXRoZHJhd24BBQt1c2VyQWRkcmVzcwUabmV3VXNlclRvdGFsQXNzZXRXaXRoZHJhd24JAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwgFAWkGY2FsbGVyBRN3aXRoZHJhd0Fzc2V0QW1vdW50BQxhc3NldElkQnl0ZXMFA25pbAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgFpAR5nZXRBdmFpbGFibGVUb1dpdGhkcmF3UkVBRE9OTFkBC3VzZXJBZGRyZXNzBAx1c2VyTHBBbW91bnQJAQ9nZXRVc2VyTHBBbW91bnQBBQt1c2VyQWRkcmVzcwQcdXNlckF2YWlsYWJsZUFzc2V0VG9XaXRoZHJhdwkAawMFDHVzZXJMcEFtb3VudAkBD2dldEN1cnJlbnRQcmljZQAFBnNjYWxlOAkAlAoCBQNuaWwFHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcBaQEWZ2V0VG90YWxBc3NldHNSRUFET05MWQAEGnRvdGFsV2l0aFByb2ZpdEFzc2V0QW1vdW50CQBkAgUQdG90YWxBc3NldEFtb3VudAkBD2NhbGNUb3RhbFByb2ZpdAAJAJQKAgUDbmlsCQCUCgIFDXRvdGFsTHBBbW91bnQFGnRvdGFsV2l0aFByb2ZpdEFzc2V0QW1vdW50AB1MwjY=", "height": 2671415, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9KfYKRG3dzxJHQ5fRNycES6AMrv4WDrAYGV1ybFovkdA Next: GTzu2PnjbnZRRh2y2PouaX8c58CzRgXEpXS4Q8Rrt3UP Diff:
Old | New | Differences | |
---|---|---|---|
67 | 67 | ||
68 | 68 | @Callable(i) | |
69 | 69 | func stake () = { | |
70 | - | let checks = [if ((size(i.payments) | |
70 | + | let checks = [if ((size(i.payments) != 1)) | |
71 | 71 | then true | |
72 | - | else throwErr("should include 1 payment"), if ((i.payments[0].amount > 0)) | |
72 | + | else throwErr("should include 1 payment"), if ((i.payments[0].assetId != assetIdBytes)) | |
73 | + | then true | |
74 | + | else throwErr(makeString(["payment should be in ", assetIdString], " ")), if ((0 > i.payments[0].amount)) | |
73 | 75 | then true | |
74 | 76 | else "payment amount should be greater than 0"] | |
75 | 77 | if ((checks == checks)) | |
94 | 96 | func withdraw (lpAssetWithdrawAmount) = { | |
95 | 97 | let userAddress = toString(i.caller) | |
96 | 98 | let userLpAmount = getUserLpAmount(userAddress) | |
97 | - | let check = [if (( | |
99 | + | let check = [if ((userLpAmount > lpAssetWithdrawAmount)) | |
98 | 100 | then true | |
99 | 101 | else (("cannot withdraw more than available (" + toString(userLpAmount)) + throwErr(")"))] | |
100 | 102 | if ((check == check)) | |
105 | 107 | let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8) | |
106 | 108 | let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0) | |
107 | 109 | let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount) | |
108 | - | [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)] | |
110 | + | [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)] | |
109 | 111 | } | |
110 | 112 | else throw("Strict value is not equal to itself.") | |
111 | 113 | } |
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 = getStringValue(this, keyAssetId) | |
37 | 37 | ||
38 | 38 | let assetIdBytes = unit | |
39 | 39 | ||
40 | 40 | func getUserLpAmount (userAddress) = valueOrElse(getInteger(this, keyUserLpAmount(userAddress)), 0) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func calcTotalProfit () = { | |
44 | 44 | let emissionPerBlock = valueOrElse(getInteger(this, keyEmissionPerBlock), 0) | |
45 | 45 | let startBlock = valueOrElse(getInteger(this, keyStartBlock), 0) | |
46 | 46 | let elapsedBlocks = (height - startBlock) | |
47 | 47 | max([0, (emissionPerBlock * elapsedBlocks)]) | |
48 | 48 | } | |
49 | 49 | ||
50 | 50 | ||
51 | 51 | func getCurrentPrice () = { | |
52 | 52 | let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit()) | |
53 | 53 | let currentPrice = if ((totalLpAmount != 0)) | |
54 | 54 | then fraction(totalWithProfitAssetAmount, scale8, totalLpAmount) | |
55 | 55 | else (1 * scale8) | |
56 | 56 | currentPrice | |
57 | 57 | } | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | @Callable(i) | |
61 | 61 | func setEmissionPerBlock (emissionPerBlock) = { | |
62 | 62 | let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit()) | |
63 | 63 | [IntegerEntry(keyTotalAssetAmount, totalWithProfitAssetAmount), IntegerEntry(keyStartBlock, height), IntegerEntry(keyEmissionPerBlock, max([0, emissionPerBlock]))] | |
64 | 64 | } | |
65 | 65 | ||
66 | 66 | ||
67 | 67 | ||
68 | 68 | @Callable(i) | |
69 | 69 | func stake () = { | |
70 | - | let checks = [if ((size(i.payments) | |
70 | + | let checks = [if ((size(i.payments) != 1)) | |
71 | 71 | then true | |
72 | - | else throwErr("should include 1 payment"), if ((i.payments[0].amount > 0)) | |
72 | + | else throwErr("should include 1 payment"), if ((i.payments[0].assetId != assetIdBytes)) | |
73 | + | then true | |
74 | + | else throwErr(makeString(["payment should be in ", assetIdString], " ")), if ((0 > i.payments[0].amount)) | |
73 | 75 | then true | |
74 | 76 | else "payment amount should be greater than 0"] | |
75 | 77 | if ((checks == checks)) | |
76 | 78 | then { | |
77 | 79 | let paymentAmount = i.payments[0].amount | |
78 | 80 | let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice()) | |
79 | 81 | let userAddress = toString(i.caller) | |
80 | 82 | let userLpAmount = getUserLpAmount(userAddress) | |
81 | 83 | let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0) | |
82 | 84 | let newTotalLpAmount = (totalLpAmount + paymentLpAmount) | |
83 | 85 | let newTotalAssetAmount = (totalAssetAmount + paymentAmount) | |
84 | 86 | let newUserLpAmount = (userLpAmount + paymentLpAmount) | |
85 | 87 | let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount) | |
86 | 88 | [IntegerEntry(keyTotalLpAmount, newTotalAssetAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)] | |
87 | 89 | } | |
88 | 90 | else throw("Strict value is not equal to itself.") | |
89 | 91 | } | |
90 | 92 | ||
91 | 93 | ||
92 | 94 | ||
93 | 95 | @Callable(i) | |
94 | 96 | func withdraw (lpAssetWithdrawAmount) = { | |
95 | 97 | let userAddress = toString(i.caller) | |
96 | 98 | let userLpAmount = getUserLpAmount(userAddress) | |
97 | - | let check = [if (( | |
99 | + | let check = [if ((userLpAmount > lpAssetWithdrawAmount)) | |
98 | 100 | then true | |
99 | 101 | else (("cannot withdraw more than available (" + toString(userLpAmount)) + throwErr(")"))] | |
100 | 102 | if ((check == check)) | |
101 | 103 | then { | |
102 | 104 | let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount) | |
103 | 105 | let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8) | |
104 | 106 | let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount) | |
105 | 107 | let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8) | |
106 | 108 | let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0) | |
107 | 109 | let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount) | |
108 | - | [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)] | |
110 | + | [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)] | |
109 | 111 | } | |
110 | 112 | else throw("Strict value is not equal to itself.") | |
111 | 113 | } | |
112 | 114 | ||
113 | 115 | ||
114 | 116 | ||
115 | 117 | @Callable(i) | |
116 | 118 | func getAvailableToWithdrawREADONLY (userAddress) = { | |
117 | 119 | let userLpAmount = getUserLpAmount(userAddress) | |
118 | 120 | let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8) | |
119 | 121 | $Tuple2(nil, userAvailableAssetToWithdraw) | |
120 | 122 | } | |
121 | 123 | ||
122 | 124 | ||
123 | 125 | ||
124 | 126 | @Callable(i) | |
125 | 127 | func getTotalAssetsREADONLY () = { | |
126 | 128 | let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit()) | |
127 | 129 | $Tuple2(nil, $Tuple2(totalLpAmount, totalWithProfitAssetAmount)) | |
128 | 130 | } | |
129 | 131 | ||
130 | 132 |
github/deemru/w8io/026f985 28.11 ms ◑