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:BgIVCAISAwoBARIAEgMKAQESAwoBCBIAFAAMY29udHJhY3RGaWxlAhBtcnRfc3Rha2luZy5yaWRlAANTRVACAl9fAAZzY2FsZTgAgMLXLwEIdGhyb3dFcnIBA21zZwkAAgEJAKwCAgkArAICBQxjb250cmFjdEZpbGUCAjogBQNtc2cACmtleUFzc2V0SWQJALkJAgkAzAgCAgIlcwkAzAgCAgdhc3NldElkBQNuaWwFA1NFUAATa2V5RW1pc3Npb25QZXJCbG9jawkAuQkCCQDMCAICAiVzCQDMCAICEGVtaXNzaW9uUGVyQmxvY2sFA25pbAUDU0VQAA1rZXlTdGFydEJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIKc3RhcnRCbG9jawUDbmlsBQNTRVAAEGtleVRvdGFsTHBBbW91bnQJALkJAgkAzAgCAgIlcwkAzAgCAg10b3RhbExwQW1vdW50BQNuaWwFA1NFUAATa2V5VG90YWxBc3NldEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICEHRvdGFsQXNzZXRBbW91bnQFA25pbAUDU0VQAQ9rZXlVc2VyTHBBbW91bnQBC3VzZXJ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pdGhkcmF3CQBrAwUMdXNlckxwQW1vdW50CQEPZ2V0Q3VycmVudFByaWNlAAUGc2NhbGU4CQCUCgIFA25pbAkAlAoCBQx1c2VyTHBBbW91bnQFHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcBaQEWZ2V0VG90YWxBc3NldHNSRUFET05MWQAJAJQKAgUDbmlsCQCUCgIFDXRvdGFsTHBBbW91bnQJAStnZXRUb3RhbEFzc2V0QW1vdW50V2l0aFByb2ZpdE9yTWF4QXZhaWxhYmxlAADoPcAs", "height": 2671593, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: C3UAN8Qo1F7VkU4SguA2XEy8UqRGMeWoLjiG44cxEbmo Next: 326DugJPSMm2YiAxGBmqf1CVDQRXSCMP6vdeQtw6FVVX Diff:
OldNewDifferences
3333
3434 let totalAssetAmount = valueOrElse(getInteger(this, keyTotalAssetAmount), 0)
3535
36-let assetIdString = getStringValue(this, keyAssetId)
36+let assetIdString = valueOrElse(getString(this, keyAssetId), "WAVES")
3737
38-let assetIdBytes = unit
38+let assetIdBytes = if ((assetIdString == "WAVES"))
39+ then unit
40+ else fromBase58String(assetIdString)
3941
4042 func getUserLpAmount (userAddress) = valueOrElse(getInteger(this, keyUserLpAmount(userAddress)), 0)
4143
4850 }
4951
5052
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+
5166 func getCurrentPrice () = {
52- let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
5367 let currentPrice = if ((totalLpAmount != 0))
54- then fraction(totalWithProfitAssetAmount, scale8, totalLpAmount)
68+ then fraction(getTotalAssetAmountWithProfitOrMaxAvailable(), scale8, totalLpAmount)
5569 else (1 * scale8)
5670 currentPrice
5771 }
5872
5973
6074 @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]))]
6576
6677
6778
124135
125136
126137 @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()))
131139
132140
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let contractFile = "mrt_staking.ride"
55
66 let SEP = "__"
77
88 let scale8 = 100000000
99
1010 func throwErr (msg) = throw(((contractFile + ": ") + msg))
1111
1212
1313 let keyAssetId = makeString(["%s", "assetId"], SEP)
1414
1515 let keyEmissionPerBlock = makeString(["%s", "emissionPerBlock"], SEP)
1616
1717 let keyStartBlock = makeString(["%s", "startBlock"], SEP)
1818
1919 let keyTotalLpAmount = makeString(["%s", "totalLpAmount"], SEP)
2020
2121 let keyTotalAssetAmount = makeString(["%s", "totalAssetAmount"], SEP)
2222
2323 func keyUserLpAmount (userAddress) = makeString(["%s%s", "userLpAmount", userAddress], SEP)
2424
2525
2626 func keyUserTotalAssetWithdrawn (userAddress) = makeString(["%s%s", "totalAssetWithdrawn", userAddress], SEP)
2727
2828
2929 func keyUserTotalAssetStaked (userAddress) = makeString(["%s%s", "totalAssetStaked", userAddress], SEP)
3030
3131
3232 let totalLpAmount = valueOrElse(getInteger(this, keyTotalLpAmount), 0)
3333
3434 let totalAssetAmount = valueOrElse(getInteger(this, keyTotalAssetAmount), 0)
3535
36-let assetIdString = getStringValue(this, keyAssetId)
36+let assetIdString = valueOrElse(getString(this, keyAssetId), "WAVES")
3737
38-let assetIdBytes = unit
38+let assetIdBytes = if ((assetIdString == "WAVES"))
39+ then unit
40+ else fromBase58String(assetIdString)
3941
4042 func getUserLpAmount (userAddress) = valueOrElse(getInteger(this, keyUserLpAmount(userAddress)), 0)
4143
4244
4345 func calcTotalProfit () = {
4446 let emissionPerBlock = valueOrElse(getInteger(this, keyEmissionPerBlock), 0)
4547 let startBlock = valueOrElse(getInteger(this, keyStartBlock), 0)
4648 let elapsedBlocks = (height - startBlock)
4749 max([0, (emissionPerBlock * elapsedBlocks)])
4850 }
4951
5052
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+
5166 func getCurrentPrice () = {
52- let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
5367 let currentPrice = if ((totalLpAmount != 0))
54- then fraction(totalWithProfitAssetAmount, scale8, totalLpAmount)
68+ then fraction(getTotalAssetAmountWithProfitOrMaxAvailable(), scale8, totalLpAmount)
5569 else (1 * scale8)
5670 currentPrice
5771 }
5872
5973
6074 @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]))]
6576
6677
6778
6879 @Callable(i)
6980 func stake () = {
7081 let checks = [if ((size(i.payments) == 1))
7182 then true
7283 else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
7384 then true
7485 else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0))
7586 then true
7687 else "payment amount should be greater than 0"]
7788 if ((checks == checks))
7889 then {
7990 let paymentAmount = i.payments[0].amount
8091 let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
8192 let userAddress = toString(i.caller)
8293 let userLpAmount = getUserLpAmount(userAddress)
8394 let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
8495 let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
8596 let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
8697 let newUserLpAmount = (userLpAmount + paymentLpAmount)
8798 let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
8899 [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)]
89100 }
90101 else throw("Strict value is not equal to itself.")
91102 }
92103
93104
94105
95106 @Callable(i)
96107 func withdraw (lpAssetWithdrawAmount) = {
97108 let userAddress = toString(i.caller)
98109 let userLpAmount = getUserLpAmount(userAddress)
99110 let check = [if ((userLpAmount >= lpAssetWithdrawAmount))
100111 then true
101112 else throwErr((("cannot withdraw more than available (" + toString(userLpAmount)) + ")"))]
102113 if ((check == check))
103114 then {
104115 let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount)
105116 let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8)
106117 let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount)
107118 let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
108119 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
109120 let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount)
110121 [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), IntegerEntry(keyStartBlock, height), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)]
111122 }
112123 else throw("Strict value is not equal to itself.")
113124 }
114125
115126
116127
117128 @Callable(i)
118129 func getAvailableToWithdrawREADONLY (userAddress) = {
119130 let userLpAmount = getUserLpAmount(userAddress)
120131 let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
121132 $Tuple2(nil, $Tuple2(userLpAmount, userAvailableAssetToWithdraw))
122133 }
123134
124135
125136
126137 @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()))
131139
132140

github/deemru/w8io/169f3d6 
30.58 ms