tx · 9KfYKRG3dzxJHQ5fRNycES6AMrv4WDrAYGV1ybFovkdA

3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq:  -0.01000000 Waves

2023.07.18 16:56 [2671402] smart account 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq > SELF 0.00000000 Waves

{ "type": 13, "id": "9KfYKRG3dzxJHQ5fRNycES6AMrv4WDrAYGV1ybFovkdA", "fee": 1000000, "feeAssetId": null, "timestamp": 1689688599298, "version": 2, "chainId": 84, "sender": "3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq", "senderPublicKey": "57SkjQUEwC1ayCqLbXLuzBqifK6B6SR6rfxtGsbAo3zW", "proofs": [ "4pseERZ2iaaYpkzy2xhABBzW4GSXXLK1R9j1c37CMLR4zCBnpRRbBHF4L4Eua39s7KrZD7mgNUxCoawPYoSrw1T9" ], "script": "base64:BgIVCAISAwoBARIAEgMKAQESAwoBCBIAEwAMY29udHJhY3RGaWxlAhBtcnRfc3Rha2luZy5yaWRlAANTRVACAl9fAAZzY2FsZTgAgMLXLwEIdGhyb3dFcnIBA21zZwkAAgEJAKwCAgkArAICBQxjb250cmFjdEZpbGUCAjogBQNtc2cACmtleUFzc2V0SWQJALkJAgkAzAgCAgIlcwkAzAgCAgdhc3NldElkBQNuaWwFA1NFUAATa2V5RW1pc3Npb25QZXJCbG9jawkAuQkCCQDMCAICAiVzCQDMCAICEGVtaXNzaW9uUGVyQmxvY2sFA25pbAUDU0VQAA1rZXlTdGFydEJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIKc3RhcnRCbG9jawUDbmlsBQNTRVAAEGtleVRvdGFsTHBBbW91bnQJALkJAgkAzAgCAgIlcwkAzAgCAg10b3RhbExwQW1vdW50BQNuaWwFA1NFUAATa2V5VG90YWxBc3NldEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICEHRvdGFsQXNzZXRBbW91bnQFA25pbAUDU0VQAQ9rZXlVc2VyTHBBbW91bnQBC3VzZXJ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clRvdGFsQXNzZXRXaXRoZHJhd24BBQt1c2VyQWRkcmVzcwUabmV3VXNlclRvdGFsQXNzZXRXaXRoZHJhd24JAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwgFAWkGY2FsbGVyBRN3aXRoZHJhd0Fzc2V0QW1vdW50BQxhc3NldElkQnl0ZXMFA25pbAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgFpAR5nZXRBdmFpbGFibGVUb1dpdGhkcmF3UkVBRE9OTFkBC3VzZXJBZGRyZXNzBAx1c2VyTHBBbW91bnQJAQ9nZXRVc2VyTHBBbW91bnQBBQt1c2VyQWRkcmVzcwQcdXNlckF2YWlsYWJsZUFzc2V0VG9XaXRoZHJhdwkAawMFDHVzZXJMcEFtb3VudAkBD2dldEN1cnJlbnRQcmljZQAFBnNjYWxlOAkAlAoCBQNuaWwFHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcBaQEWZ2V0VG90YWxBc3NldHNSRUFET05MWQAEGnRvdGFsV2l0aFByb2ZpdEFzc2V0QW1vdW50CQBkAgUQdG90YWxBc3NldEFtb3VudAkBD2NhbGNUb3RhbFByb2ZpdAAJAJQKAgUDbmlsCQCUCgIFDXRvdGFsTHBBbW91bnQFGnRvdGFsV2l0aFByb2ZpdEFzc2V0QW1vdW50AIgJZNI=", "height": 2671402, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9SucZkgRaeQN42bYCtauYD2TMv2mbjgek8XUwbKR43jH Next: 8DtA7EiAcWtZLi6aqRfRowYse6MqYC8WpHisY1SRrVSA Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-func getAddressBalance (addressString,assetIdString) = {
5- let address = addressFromStringValue(addressString)
6- if ((assetIdString == "WAVES"))
7- then wavesBalance(address).regular
8- else {
9- let assetId = fromBase58String(assetIdString)
10- assetBalance(address, assetId)
11- }
4+let contractFile = "mrt_staking.ride"
5+
6+let SEP = "__"
7+
8+let scale8 = 100000000
9+
10+func throwErr (msg) = throw(((contractFile + ": ") + msg))
11+
12+
13+let keyAssetId = makeString(["%s", "assetId"], SEP)
14+
15+let keyEmissionPerBlock = makeString(["%s", "emissionPerBlock"], SEP)
16+
17+let keyStartBlock = makeString(["%s", "startBlock"], SEP)
18+
19+let keyTotalLpAmount = makeString(["%s", "totalLpAmount"], SEP)
20+
21+let keyTotalAssetAmount = makeString(["%s", "totalAssetAmount"], SEP)
22+
23+func keyUserLpAmount (userAddress) = makeString(["%s%s", "userLpAmount", userAddress], SEP)
24+
25+
26+func keyUserTotalAssetWithdrawn (userAddress) = makeString(["%s%s", "totalAssetWithdrawn", userAddress], SEP)
27+
28+
29+func keyUserTotalAssetStaked (userAddress) = makeString(["%s%s", "totalAssetStaked", userAddress], SEP)
30+
31+
32+let totalLpAmount = valueOrElse(getInteger(this, keyTotalLpAmount), 0)
33+
34+let totalAssetAmount = valueOrElse(getInteger(this, keyTotalAssetAmount), 0)
35+
36+let assetIdString = getStringValue(this, keyAssetId)
37+
38+let assetIdBytes = unit
39+
40+func getUserLpAmount (userAddress) = valueOrElse(getInteger(this, keyUserLpAmount(userAddress)), 0)
41+
42+
43+func calcTotalProfit () = {
44+ let emissionPerBlock = valueOrElse(getInteger(this, keyEmissionPerBlock), 0)
45+ let startBlock = valueOrElse(getInteger(this, keyStartBlock), 0)
46+ let elapsedBlocks = (height - startBlock)
47+ max([0, (emissionPerBlock * elapsedBlocks)])
1248 }
1349
50+
51+func getCurrentPrice () = {
52+ let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
53+ let currentPrice = if ((totalLpAmount != 0))
54+ then fraction(totalWithProfitAssetAmount, scale8, totalLpAmount)
55+ else (1 * scale8)
56+ currentPrice
57+ }
58+
59+
60+@Callable(i)
61+func setEmissionPerBlock (emissionPerBlock) = {
62+ let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
63+[IntegerEntry(keyTotalAssetAmount, totalWithProfitAssetAmount), IntegerEntry(keyStartBlock, height), IntegerEntry(keyEmissionPerBlock, max([0, emissionPerBlock]))]
64+ }
65+
66+
67+
68+@Callable(i)
69+func stake () = {
70+ let checks = [if ((size(i.payments) == 1))
71+ then true
72+ else throwErr("should include 1 payment"), if ((i.payments[0].amount > 0))
73+ then true
74+ else "payment amount should be greater than 0"]
75+ if ((checks == checks))
76+ then {
77+ let paymentAmount = i.payments[0].amount
78+ let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
79+ let userAddress = toString(i.caller)
80+ let userLpAmount = getUserLpAmount(userAddress)
81+ let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
82+ let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
83+ let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
84+ let newUserLpAmount = (userLpAmount + paymentLpAmount)
85+ let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
86+[IntegerEntry(keyTotalLpAmount, newTotalAssetAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)]
87+ }
88+ else throw("Strict value is not equal to itself.")
89+ }
90+
91+
92+
93+@Callable(i)
94+func withdraw (lpAssetWithdrawAmount) = {
95+ let userAddress = toString(i.caller)
96+ let userLpAmount = getUserLpAmount(userAddress)
97+ let check = [if ((lpAssetWithdrawAmount > userLpAmount))
98+ then true
99+ else (("cannot withdraw more than available (" + toString(userLpAmount)) + throwErr(")"))]
100+ if ((check == check))
101+ then {
102+ let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount)
103+ let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8)
104+ let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount)
105+ let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
106+ let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
107+ let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount)
108+[IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)]
109+ }
110+ else throw("Strict value is not equal to itself.")
111+ }
112+
113+
114+
115+@Callable(i)
116+func getAvailableToWithdrawREADONLY (userAddress) = {
117+ let userLpAmount = getUserLpAmount(userAddress)
118+ let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
119+ $Tuple2(nil, userAvailableAssetToWithdraw)
120+ }
121+
122+
123+
124+@Callable(i)
125+func getTotalAssetsREADONLY () = {
126+ let totalWithProfitAssetAmount = (totalAssetAmount + calcTotalProfit())
127+ $Tuple2(nil, $Tuple2(totalLpAmount, totalWithProfitAssetAmount))
128+ }
14129
15130

github/deemru/w8io/026f985 
22.53 ms