tx · 6MqgmCdbvrGRDpGhqPsXLMXtpdFF6pEjrJrSbCVDvqxq

3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq:  -0.01000000 Waves

2023.07.19 12:22 [2672556] smart account 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq > SELF 0.00000000 Waves

{ "type": 13, "id": "6MqgmCdbvrGRDpGhqPsXLMXtpdFF6pEjrJrSbCVDvqxq", "fee": 1000000, "feeAssetId": null, "timestamp": 1689758639911, "version": 2, "chainId": 84, "sender": "3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq", "senderPublicKey": "57SkjQUEwC1ayCqLbXLuzBqifK6B6SR6rfxtGsbAo3zW", "proofs": [ "38Um71yDhcQPa6yzszeCn12Nh7jYpSTDD4y2TwYiGvb8BfTpxYwZ1pEM3QX8L2HyqM5GrSuJs21PXsDswkRVpFUS" ], "script": "base64:BgIaCAISAwoBARIAEgMKAQgSAwoBARIDCgEIEgAVAAxjb250cmFjdEZpbGUCEG1ydF9zdGFraW5nLnJpZGUAA1NFUAICX18ABnNjYWxlOACAwtcvAQh0aHJvd0VycgEDbXNnCQACAQkArAICCQCsAgIFDGNvbnRyYWN0RmlsZQICOiAFA21zZwAKa2V5QXNzZXRJZAkAuQkCCQDMCAICAiVzCQDMCAICB2Fzc2V0SWQFA25pbAUDU0VQABNrZXlFbWlzc2lvblBlckJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIQZW1pc3Npb25QZXJCbG9jawUDbmlsBQNTRVAADWtleVN0YXJ0QmxvY2sJALkJAgkAzAgCAgIlcwkAzAgCAgpzdGFydEJsb2NrBQNuaWwFA1NFUAAQa2V5VG90YWxMcEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICDXRvdGFsTHBBbW91bnQFA25pbAUDU0VQABNrZXlUb3RhbEFzc2V0QW1vdW50CQC5CQIJAMwIAgICJXMJAMwIAgIQdG90YWxBc3NldEFtb3VudAUDbmlsBQNTRVABD2tleVVzZXJMcEFt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VnZXJFbnRyeQIJARprZXlVc2VyVG90YWxBc3NldFdpdGhkcmF3bgEFC3VzZXJBZGRyZXNzBRpuZXdVc2VyVG90YWxBc3NldFdpdGhkcmF3bgkAzAgCCQEMSW50ZWdlckVudHJ5AgUNa2V5U3RhcnRCbG9jawUGaGVpZ2h0CQDMCAIJAQ5TY3JpcHRUcmFuc2ZlcgMIBQFpBmNhbGxlcgUTd2l0aGRyYXdBc3NldEFtb3VudAUMYXNzZXRJZEJ5dGVzBQNuaWwJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BaQEVZ2V0VXNlckFzc2V0c1JFQURPTkxZAQt1c2VyQWRkcmVzcwQMdXNlckxwQW1vdW50CQEPZ2V0VXNlckxwQW1vdW50AQULdXNlckFkZHJlc3MEHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcJAGsDBQx1c2VyTHBBbW91bnQJAQ9nZXRDdXJyZW50UHJpY2UABQZzY2FsZTgJAJQKAgUDbmlsCQCVCgMFDHVzZXJMcEFtb3VudAUcdXNlckF2YWlsYWJsZUFzc2V0VG9XaXRoZHJhdwkBD2dldEN1cnJlbnRQcmljZQABaQEWZ2V0VG90YWxBc3NldHNSRUFET05MWQAJAJQKAgUDbmlsCQCVCgMFDXRvdGFsTHBBbW91bnQJAStnZXRUb3RhbEFzc2V0QW1vdW50V2l0aFByb2ZpdE9yTWF4QXZhaWxhYmxlAAkBD2dldEN1cnJlbnRQcmljZQAAGhBbNA==", "height": 2672556, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: wk54hKdzC4LrbbUNE4p27qfYahCjU648PnUym1YVUXQ Next: 9afHXwHh2UxoJQFxqLuw6zqfYFiaKnxC7Q9DZj31CpK9 Diff:
OldNewDifferences
6868 else (1 * scale8)
6969
7070
71+func getStakeAction (i,userAddress) = {
72+ let checks = [if ((size(i.payments) == 1))
73+ then true
74+ else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
75+ then true
76+ else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0))
77+ then true
78+ else "payment amount should be greater than 0"]
79+ if ((checks == checks))
80+ then {
81+ let paymentAmount = i.payments[0].amount
82+ let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
83+ let userLpAmount = getUserLpAmount(userAddress)
84+ let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
85+ let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
86+ let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
87+ let newUserLpAmount = (userLpAmount + paymentLpAmount)
88+ let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
89+ let updateStartHeightAction = if ((totalLpAmount == 0))
90+ then [IntegerEntry(keyStartBlock, height)]
91+ else nil
92+ ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)] ++ updateStartHeightAction)
93+ }
94+ else throw("Strict value is not equal to itself.")
95+ }
96+
97+
7198 @Callable(i)
7299 func setEmissionPerBlock (emissionPerBlock) = {
73100 let check = [if ((i.caller == this))
81108
82109
83110 @Callable(i)
84-func stake () = {
85- let checks = [if ((size(i.payments) == 1))
86- then true
87- else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
88- then true
89- else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0))
90- then true
91- else "payment amount should be greater than 0"]
92- if ((checks == checks))
93- then {
94- let paymentAmount = i.payments[0].amount
95- let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
96- let userAddress = toString(i.caller)
97- let userLpAmount = getUserLpAmount(userAddress)
98- let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
99- let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
100- let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
101- let newUserLpAmount = (userLpAmount + paymentLpAmount)
102- let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
103- let updateStartHeightAction = if ((totalLpAmount == 0))
104- then [IntegerEntry(keyStartBlock, height)]
105- else nil
106- ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)] ++ updateStartHeightAction)
107- }
108- else throw("Strict value is not equal to itself.")
109- }
111+func stake () = getStakeAction(i, toString(i.caller))
112+
113+
114+
115+@Callable(i)
116+func stakeFor (userAddress) = getStakeAction(i, userAddress)
110117
111118
112119
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 = valueOrElse(getString(this, keyAssetId), "WAVES")
3737
3838 let assetIdBytes = if ((assetIdString == "WAVES"))
3939 then unit
4040 else fromBase58String(assetIdString)
4141
4242 func getUserLpAmount (userAddress) = valueOrElse(getInteger(this, keyUserLpAmount(userAddress)), 0)
4343
4444
4545 func calcTotalProfit () = {
4646 let emissionPerBlock = valueOrElse(getInteger(this, keyEmissionPerBlock), 0)
4747 let startBlock = valueOrElse(getInteger(this, keyStartBlock), 0)
4848 let elapsedBlocks = (height - startBlock)
4949 max([0, (emissionPerBlock * elapsedBlocks)])
5050 }
5151
5252
5353 func getTotalAssetAmountWithProfitOrMaxAvailable () = {
5454 let totalAssetAmountWithProfit = (totalAssetAmount + calcTotalProfit())
5555 match assetIdBytes {
5656 case u: Unit =>
5757 min([totalAssetAmountWithProfit, wavesBalance(this).available])
5858 case b: ByteVector =>
5959 min([totalAssetAmountWithProfit, assetBalance(this, b)])
6060 case _ =>
6161 throw("Match error")
6262 }
6363 }
6464
6565
6666 func getCurrentPrice () = if ((totalLpAmount != 0))
6767 then fraction(getTotalAssetAmountWithProfitOrMaxAvailable(), scale8, totalLpAmount)
6868 else (1 * scale8)
6969
7070
71+func getStakeAction (i,userAddress) = {
72+ let checks = [if ((size(i.payments) == 1))
73+ then true
74+ else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
75+ then true
76+ else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0))
77+ then true
78+ else "payment amount should be greater than 0"]
79+ if ((checks == checks))
80+ then {
81+ let paymentAmount = i.payments[0].amount
82+ let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
83+ let userLpAmount = getUserLpAmount(userAddress)
84+ let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
85+ let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
86+ let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
87+ let newUserLpAmount = (userLpAmount + paymentLpAmount)
88+ let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
89+ let updateStartHeightAction = if ((totalLpAmount == 0))
90+ then [IntegerEntry(keyStartBlock, height)]
91+ else nil
92+ ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)] ++ updateStartHeightAction)
93+ }
94+ else throw("Strict value is not equal to itself.")
95+ }
96+
97+
7198 @Callable(i)
7299 func setEmissionPerBlock (emissionPerBlock) = {
73100 let check = [if ((i.caller == this))
74101 then true
75102 else throwErr("permission denied")]
76103 if ((check == check))
77104 then [IntegerEntry(keyTotalAssetAmount, getTotalAssetAmountWithProfitOrMaxAvailable()), IntegerEntry(keyStartBlock, height), IntegerEntry(keyEmissionPerBlock, max([0, emissionPerBlock]))]
78105 else throw("Strict value is not equal to itself.")
79106 }
80107
81108
82109
83110 @Callable(i)
84-func stake () = {
85- let checks = [if ((size(i.payments) == 1))
86- then true
87- else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
88- then true
89- else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0))
90- then true
91- else "payment amount should be greater than 0"]
92- if ((checks == checks))
93- then {
94- let paymentAmount = i.payments[0].amount
95- let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
96- let userAddress = toString(i.caller)
97- let userLpAmount = getUserLpAmount(userAddress)
98- let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
99- let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
100- let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
101- let newUserLpAmount = (userLpAmount + paymentLpAmount)
102- let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
103- let updateStartHeightAction = if ((totalLpAmount == 0))
104- then [IntegerEntry(keyStartBlock, height)]
105- else nil
106- ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)] ++ updateStartHeightAction)
107- }
108- else throw("Strict value is not equal to itself.")
109- }
111+func stake () = getStakeAction(i, toString(i.caller))
112+
113+
114+
115+@Callable(i)
116+func stakeFor (userAddress) = getStakeAction(i, userAddress)
110117
111118
112119
113120 @Callable(i)
114121 func withdraw (lpAssetWithdrawAmount) = {
115122 let userAddress = toString(i.caller)
116123 let userLpAmount = getUserLpAmount(userAddress)
117124 let check = [if ((userLpAmount >= lpAssetWithdrawAmount))
118125 then true
119126 else throwErr((("cannot withdraw more than available (" + toString(userLpAmount)) + ")"))]
120127 if ((check == check))
121128 then {
122129 let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount)
123130 let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8)
124131 let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount)
125132 let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
126133 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
127134 let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount)
128135 [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), IntegerEntry(keyStartBlock, height), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)]
129136 }
130137 else throw("Strict value is not equal to itself.")
131138 }
132139
133140
134141
135142 @Callable(i)
136143 func getUserAssetsREADONLY (userAddress) = {
137144 let userLpAmount = getUserLpAmount(userAddress)
138145 let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
139146 $Tuple2(nil, $Tuple3(userLpAmount, userAvailableAssetToWithdraw, getCurrentPrice()))
140147 }
141148
142149
143150
144151 @Callable(i)
145152 func getTotalAssetsREADONLY () = $Tuple2(nil, $Tuple3(totalLpAmount, getTotalAssetAmountWithProfitOrMaxAvailable(), getCurrentPrice()))
146153
147154

github/deemru/w8io/026f985 
49.90 ms