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:BgIVCAISAwoBARIAEgMKAQESAwoBCBIAEwAMY29udHJhY3RGaWxlAhBtcnRfc3Rha2luZy5yaWRlAANTRVACAl9fAAZzY2FsZTgAgMLXLwEIdGhyb3dFcnIBA21zZwkAAgEJAKwCAgkArAICBQxjb250cmFjdEZpbGUCAjogBQNtc2cACmtleUFzc2V0SWQJALkJAgkAzAgCAgIlcwkAzAgCAgdhc3NldElkBQNuaWwFA1NFUAATa2V5RW1pc3Npb25QZXJCbG9jawkAuQkCCQDMCAICAiVzCQDMCAICEGVtaXNzaW9uUGVyQmxvY2sFA25pbAUDU0VQAA1rZXlTdGFydEJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIKc3RhcnRCbG9jawUDbmlsBQNTRVAAEGtleVRvdGFsTHBBbW91bnQJALkJAgkAzAgCAgIlcwkAzAgCAg10b3RhbExwQW1vdW50BQNuaWwFA1NFUAATa2V5VG90YWxBc3NldEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICEHRvdGFsQXNzZXRBbW91bnQFA25pbAUDU0VQAQ9rZXlVc2VyTHBBbW91bnQBC3VzZXJBZGR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sTHBBbW91bnQFEG5ld1RvdGFsTHBBbW91bnQJAMwIAgkBDEludGVnZXJFbnRyeQIFE2tleVRvdGFsQXNzZXRBbW91bnQFE25ld1RvdGFsQXNzZXRBbW91bnQJAMwIAgkBDEludGVnZXJFbnRyeQIJAQ9rZXlVc2VyTHBBbW91bnQBBQt1c2VyQWRkcmVzcwUPbmV3VXNlckxwQW1vdW50CQDMCAIJAQxJbnRlZ2VyRW50cnkCCQEaa2V5VXNlclRvdGFsQXNzZXRXaXRoZHJhd24BBQt1c2VyQWRkcmVzcwUabmV3VXNlclRvdGFsQXNzZXRXaXRoZHJhd24JAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwgFAWkGY2FsbGVyBRN3aXRoZHJhd0Fzc2V0QW1vdW50BQxhc3NldElkQnl0ZXMFA25pbAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgFpAR5nZXRBdmFpbGFibGVUb1dpdGhkcmF3UkVBRE9OTFkBC3VzZXJBZGRyZXNzBAx1c2VyTHBBbW91bnQJAQ9nZXRVc2VyTHBBbW91bnQBBQt1c2VyQWRkcmVzcwQcdXNlckF2YWlsYWJsZUFzc2V0VG9XaXRoZHJhdwkAawMFDHVzZXJMcEFtb3VudAkBD2dldEN1cnJlbnRQcmljZQAFBnNjYWxlOAkAlAoCBQNuaWwFHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcBaQEWZ2V0VG90YWxBc3NldHNSRUFET05MWQAEGnRvdGFsV2l0aFByb2ZpdEFzc2V0QW1vdW50CQBkAgUQdG90YWxBc3NldEFtb3VudAkBD2NhbGNUb3RhbFByb2ZpdAAJAJQKAgUDbmlsCQCUCgIFDXRvdGFsTHBBbW91bnQFGnRvdGFsV2l0aFByb2ZpdEFzc2V0QW1vdW50AB1MwjY=", "height": 2671415, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9KfYKRG3dzxJHQ5fRNycES6AMrv4WDrAYGV1ybFovkdA Next: GTzu2PnjbnZRRh2y2PouaX8c58CzRgXEpXS4Q8Rrt3UP Diff:
OldNewDifferences
6767
6868 @Callable(i)
6969 func stake () = {
70- let checks = [if ((size(i.payments) == 1))
70+ let checks = [if ((size(i.payments) != 1))
7171 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))
7375 then true
7476 else "payment amount should be greater than 0"]
7577 if ((checks == checks))
9496 func withdraw (lpAssetWithdrawAmount) = {
9597 let userAddress = toString(i.caller)
9698 let userLpAmount = getUserLpAmount(userAddress)
97- let check = [if ((lpAssetWithdrawAmount > userLpAmount))
99+ let check = [if ((userLpAmount > lpAssetWithdrawAmount))
98100 then true
99101 else (("cannot withdraw more than available (" + toString(userLpAmount)) + throwErr(")"))]
100102 if ((check == check))
105107 let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
106108 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
107109 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)]
109111 }
110112 else throw("Strict value is not equal to itself.")
111113 }
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
3636 let assetIdString = getStringValue(this, keyAssetId)
3737
3838 let assetIdBytes = unit
3939
4040 func getUserLpAmount (userAddress) = valueOrElse(getInteger(this, keyUserLpAmount(userAddress)), 0)
4141
4242
4343 func calcTotalProfit () = {
4444 let emissionPerBlock = valueOrElse(getInteger(this, keyEmissionPerBlock), 0)
4545 let startBlock = valueOrElse(getInteger(this, keyStartBlock), 0)
4646 let elapsedBlocks = (height - startBlock)
4747 max([0, (emissionPerBlock * elapsedBlocks)])
4848 }
4949
5050
5151 func getCurrentPrice () = {
5252 let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
5353 let currentPrice = if ((totalLpAmount != 0))
5454 then fraction(totalWithProfitAssetAmount, scale8, totalLpAmount)
5555 else (1 * scale8)
5656 currentPrice
5757 }
5858
5959
6060 @Callable(i)
6161 func setEmissionPerBlock (emissionPerBlock) = {
6262 let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
6363 [IntegerEntry(keyTotalAssetAmount, totalWithProfitAssetAmount), IntegerEntry(keyStartBlock, height), IntegerEntry(keyEmissionPerBlock, max([0, emissionPerBlock]))]
6464 }
6565
6666
6767
6868 @Callable(i)
6969 func stake () = {
70- let checks = [if ((size(i.payments) == 1))
70+ let checks = [if ((size(i.payments) != 1))
7171 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))
7375 then true
7476 else "payment amount should be greater than 0"]
7577 if ((checks == checks))
7678 then {
7779 let paymentAmount = i.payments[0].amount
7880 let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
7981 let userAddress = toString(i.caller)
8082 let userLpAmount = getUserLpAmount(userAddress)
8183 let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
8284 let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
8385 let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
8486 let newUserLpAmount = (userLpAmount + paymentLpAmount)
8587 let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
8688 [IntegerEntry(keyTotalLpAmount, newTotalAssetAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)]
8789 }
8890 else throw("Strict value is not equal to itself.")
8991 }
9092
9193
9294
9395 @Callable(i)
9496 func withdraw (lpAssetWithdrawAmount) = {
9597 let userAddress = toString(i.caller)
9698 let userLpAmount = getUserLpAmount(userAddress)
97- let check = [if ((lpAssetWithdrawAmount > userLpAmount))
99+ let check = [if ((userLpAmount > lpAssetWithdrawAmount))
98100 then true
99101 else (("cannot withdraw more than available (" + toString(userLpAmount)) + throwErr(")"))]
100102 if ((check == check))
101103 then {
102104 let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount)
103105 let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8)
104106 let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount)
105107 let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
106108 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
107109 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)]
109111 }
110112 else throw("Strict value is not equal to itself.")
111113 }
112114
113115
114116
115117 @Callable(i)
116118 func getAvailableToWithdrawREADONLY (userAddress) = {
117119 let userLpAmount = getUserLpAmount(userAddress)
118120 let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
119121 $Tuple2(nil, userAvailableAssetToWithdraw)
120122 }
121123
122124
123125
124126 @Callable(i)
125127 func getTotalAssetsREADONLY () = {
126128 let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
127129 $Tuple2(nil, $Tuple2(totalLpAmount, totalWithProfitAssetAmount))
128130 }
129131
130132

github/deemru/w8io/026f985 
28.11 ms