tx · GTzu2PnjbnZRRh2y2PouaX8c58CzRgXEpXS4Q8Rrt3UP

3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq:  -0.01000000 Waves

2023.07.18 17:11 [2671419] smart account 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq > SELF 0.00000000 Waves

{ "type": 13, "id": "GTzu2PnjbnZRRh2y2PouaX8c58CzRgXEpXS4Q8Rrt3UP", "fee": 1000000, "feeAssetId": null, "timestamp": 1689689529787, "version": 2, "chainId": 84, "sender": "3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq", "senderPublicKey": "57SkjQUEwC1ayCqLbXLuzBqifK6B6SR6rfxtGsbAo3zW", "proofs": [ "4vFpRbB58G2utCgotiYudHHWAroNfTLWijHVFQY8rGLGqEGrrrWDb1tvu6jDVEa1mf3LfnoeSMK2rU8A5wyDsW9Q" ], "script": "base64:BgIVCAISAwoBARIAEgMKAQESAwoBCBIAEwAMY29udHJhY3RGaWxlAhBtcnRfc3Rha2luZy5yaWRlAANTRVACAl9fAAZzY2FsZTgAgMLXLwEIdGhyb3dFcnIBA21zZwkAAgEJAKwCAgkArAICBQxjb250cmFjdEZpbGUCAjogBQNtc2cACmtleUFzc2V0SWQJALkJAgkAzAgCAgIlcwkAzAgCAgdhc3NldElkBQNuaWwFA1NFUAATa2V5RW1pc3Npb25QZXJCbG9jawkAuQkCCQDMCAICAiVzCQDMCAICEGVtaXNzaW9uUGVyQmxvY2sFA25pbAUDU0VQAA1rZXlTdGFydEJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIKc3RhcnRCbG9jawUDbmlsBQNTRVAAEGtleVRvdGFsTHBBbW91bnQJALkJAgkAzAgCAgIlcwkAzAgCAg10b3RhbExwQW1vdW50BQNuaWwFA1NFUAATa2V5VG90YWxBc3NldEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICEHRvdGFsQXNzZXRBbW91bnQFA25pbAUDU0VQAQ9rZXlVc2VyTHBBbW91bnQBC3Vz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xMcEFtb3VudAkAzAgCCQEMSW50ZWdlckVudHJ5AgUTa2V5VG90YWxBc3NldEFtb3VudAUTbmV3VG90YWxBc3NldEFtb3VudAkAzAgCCQEMSW50ZWdlckVudHJ5AgkBD2tleVVzZXJMcEFtb3VudAEFC3VzZXJBZGRyZXNzBQ9uZXdVc2VyTHBBbW91bnQJAMwIAgkBDEludGVnZXJFbnRyeQIJARprZXlVc2VyVG90YWxBc3NldFdpdGhkcmF3bgEFC3VzZXJBZGRyZXNzBRpuZXdVc2VyVG90YWxBc3NldFdpdGhkcmF3bgkAzAgCCQEOU2NyaXB0VHJhbnNmZXIDCAUBaQZjYWxsZXIFE3dpdGhkcmF3QXNzZXRBbW91bnQFDGFzc2V0SWRCeXRlcwUDbmlsCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAWkBHmdldEF2YWlsYWJsZVRvV2l0aGRyYXdSRUFET05MWQELdXNlckFkZHJlc3MEDHVzZXJMcEFtb3VudAkBD2dldFVzZXJMcEFtb3VudAEFC3VzZXJBZGRyZXNzBBx1c2VyQXZhaWxhYmxlQXNzZXRUb1dpdGhkcmF3CQBrAwUMdXNlckxwQW1vdW50CQEPZ2V0Q3VycmVudFByaWNlAAUGc2NhbGU4CQCUCgIFA25pbAUcdXNlckF2YWlsYWJsZUFzc2V0VG9XaXRoZHJhdwFpARZnZXRUb3RhbEFzc2V0c1JFQURPTkxZAAQadG90YWxXaXRoUHJvZml0QXNzZXRBbW91bnQJAGQCBRB0b3RhbEFzc2V0QW1vdW50CQEPY2FsY1RvdGFsUHJvZml0AAkAlAoCBQNuaWwJAJQKAgUNdG90YWxMcEFtb3VudAUadG90YWxXaXRoUHJvZml0QXNzZXRBbW91bnQATzswow==", "height": 2671419, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8DtA7EiAcWtZLi6aqRfRowYse6MqYC8WpHisY1SRrVSA Next: 2Pa8hiUqrufveUKrha23ptc3P6dNKYA8DDyke6iHyViP 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].assetId != assetIdBytes))
72+ else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
7373 then true
74- else throwErr(makeString(["payment should be in ", assetIdString], " ")), if ((0 > i.payments[0].amount))
74+ else throwErr(makeString(["payment should be in ", assetIdString], " ")), if ((i.payments[0].amount > 0))
7575 then true
7676 else "payment amount should be greater than 0"]
7777 if ((checks == checks))
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].assetId != assetIdBytes))
72+ else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
7373 then true
74- else throwErr(makeString(["payment should be in ", assetIdString], " ")), if ((0 > i.payments[0].amount))
74+ else throwErr(makeString(["payment should be in ", assetIdString], " ")), if ((i.payments[0].amount > 0))
7575 then true
7676 else "payment amount should be greater than 0"]
7777 if ((checks == checks))
7878 then {
7979 let paymentAmount = i.payments[0].amount
8080 let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
8181 let userAddress = toString(i.caller)
8282 let userLpAmount = getUserLpAmount(userAddress)
8383 let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
8484 let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
8585 let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
8686 let newUserLpAmount = (userLpAmount + paymentLpAmount)
8787 let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
8888 [IntegerEntry(keyTotalLpAmount, newTotalAssetAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)]
8989 }
9090 else throw("Strict value is not equal to itself.")
9191 }
9292
9393
9494
9595 @Callable(i)
9696 func withdraw (lpAssetWithdrawAmount) = {
9797 let userAddress = toString(i.caller)
9898 let userLpAmount = getUserLpAmount(userAddress)
9999 let check = [if ((userLpAmount > lpAssetWithdrawAmount))
100100 then true
101101 else (("cannot withdraw more than available (" + toString(userLpAmount)) + throwErr(")"))]
102102 if ((check == check))
103103 then {
104104 let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount)
105105 let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8)
106106 let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount)
107107 let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
108108 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
109109 let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount)
110110 [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)]
111111 }
112112 else throw("Strict value is not equal to itself.")
113113 }
114114
115115
116116
117117 @Callable(i)
118118 func getAvailableToWithdrawREADONLY (userAddress) = {
119119 let userLpAmount = getUserLpAmount(userAddress)
120120 let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
121121 $Tuple2(nil, userAvailableAssetToWithdraw)
122122 }
123123
124124
125125
126126 @Callable(i)
127127 func getTotalAssetsREADONLY () = {
128128 let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
129129 $Tuple2(nil, $Tuple2(totalLpAmount, totalWithProfitAssetAmount))
130130 }
131131
132132

github/deemru/w8io/026f985 
27.56 ms