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