tx · 9VSJDAE3AHniSi75bSKhCVmtHkc9WfD5jg2kNLKT1KBf

3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq:  -0.01000000 Waves

2023.07.19 17:16 [2672850] smart account 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq > SELF 0.00000000 Waves

{ "type": 13, "id": "9VSJDAE3AHniSi75bSKhCVmtHkc9WfD5jg2kNLKT1KBf", "fee": 1000000, "feeAssetId": null, "timestamp": 1689776256967, "version": 2, "chainId": 84, "sender": "3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq", "senderPublicKey": "57SkjQUEwC1ayCqLbXLuzBqifK6B6SR6rfxtGsbAo3zW", "proofs": [ "3dKGXXkJyYpt42MLsSvpKZgDuYHWagsiNkpda3M3j6ATJgCKrcyj3CLRmT3tq4zqdiVZN45NbG98T4eMdFurK6sa" ], "script": "base64:BgIaCAISAwoBARIAEgMKAQgSAwoBARIDCgEIEgAWAAxjb250cmFjdEZpbGUCEG1ydF9zdGFraW5nLnJpZGUAA1NFUAICX18ABnNjYWxlOACAwtcvABJBRERSRVNTX0JZVEVTX1NJWkUAGgEIdGhyb3dFcnIBA21zZwkAAgEJAKwCAgkArAICBQxjb250cmFjdEZpbGUCAjogBQNtc2cACmtleUFzc2V0SWQJALkJAgkAzAgCAgIlcwkAzAgCAgdhc3NldElkBQNuaWwFA1NFUAATa2V5RW1pc3Npb25QZXJCbG9jawkAuQkCCQDMCAICAiVzCQDMCAICEGVtaXNzaW9uUGVyQmxvY2sFA25pbAUDU0VQAA1rZXlTdGFydEJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIKc3RhcnRCbG9jawUDbmlsBQNTRVAAEGtleVRvdGFsTHBBbW91bnQJALkJAgkAzAgCAgIlcwkAzAgCAg10b3RhbExwQW1vdW50BQNuaWwFA1NFUAATa2V5VG90YWxBc3NldEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICEHRvdGFsQXNzZXRBbW91bnQFA25pbAUDU0V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AABBd1c2VyVG90YWxBc3NldFdpdGhkcmF3bgkBC3ZhbHVlT3JFbHNlAgkAmggCBQR0aGlzCQEaa2V5VXNlclRvdGFsQXNzZXRXaXRoZHJhd24BBQt1c2VyQWRkcmVzcwAACQCUCgIFA25pbAkAlwoFBQx1c2VyTHBBbW91bnQFHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcJAQ9nZXRDdXJyZW50UHJpY2UABRV1c2VyVG90YWxTdGFrZWRBbW91bnQFF3VzZXJUb3RhbEFzc2V0V2l0aGRyYXduAWkBFmdldFRvdGFsQXNzZXRzUkVBRE9OTFkACQCUCgIFA25pbAkAlQoDBQ10b3RhbExwQW1vdW50CQErZ2V0VG90YWxBc3NldEFtb3VudFdpdGhQcm9maXRPck1heEF2YWlsYWJsZQAJAQ9nZXRDdXJyZW50UHJpY2UAAHZVUSA=", "height": 2672850, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BrkV6ZnB28fo3AMKbuDLP5GHPgzyrbBBVsRxAjqjnbJw Next: 8Fa8PH8xvgBTVuXa7AWViEpTjZ8rooSMzJf4SRfVELxi Diff:
OldNewDifferences
5454
5555 func getTotalAssetAmountWithProfitOrMaxAvailable () = {
5656 let totalAssetAmountWithProfit = (totalAssetAmount + calcTotalProfit())
57- match assetIdBytes {
57+ let totalAmount = match assetIdBytes {
5858 case u: Unit =>
5959 min([totalAssetAmountWithProfit, wavesBalance(this).available])
6060 case b: ByteVector =>
6262 case _ =>
6363 throw("Match error")
6464 }
65+ if ((totalLpAmount == 0))
66+ then 0
67+ else totalAmount
6568 }
6669
6770
7073 else (1 * scale8)
7174
7275
73-func getStakeAction (i,userAddress) = {
76+func getStakeActions (i,userAddress) = {
7477 let checks = [if ((size(i.payments) == 1))
7578 then true
7679 else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
8386 let paymentAmount = i.payments[0].amount
8487 let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
8588 let userLpAmount = getUserLpAmount(userAddress)
86- let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
89+ let userTotalStakedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
8790 let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
8891 let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
8992 let newUserLpAmount = (userLpAmount + paymentLpAmount)
90- let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
93+ let newUserTotalStakedAmount = (userTotalStakedAmount + paymentAmount)
9194 let updateStartHeightAction = if ((totalLpAmount == 0))
9295 then [IntegerEntry(keyStartBlock, height)]
9396 else nil
94- ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)] ++ updateStartHeightAction)
97+ ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalStakedAmount)] ++ updateStartHeightAction)
9598 }
9699 else throw("Strict value is not equal to itself.")
97100 }
110113
111114
112115 @Callable(i)
113-func stake () = getStakeAction(i, toString(i.caller))
116+func stake () = getStakeActions(i, toString(i.caller))
114117
115118
116119
120123 then true
121124 else throwErr("address is not valid")]
122125 if ((check == check))
123- then getStakeAction(i, userAddress)
126+ then getStakeActions(i, userAddress)
124127 else throw("Strict value is not equal to itself.")
125128 }
126129
154157 func getUserAssetsREADONLY (userAddress) = {
155158 let userLpAmount = getUserLpAmount(userAddress)
156159 let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
157- $Tuple2(nil, $Tuple3(userLpAmount, userAvailableAssetToWithdraw, getCurrentPrice()))
160+ let userTotalStakedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
161+ let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
162+ $Tuple2(nil, $Tuple5(userLpAmount, userAvailableAssetToWithdraw, getCurrentPrice(), userTotalStakedAmount, userTotalAssetWithdrawn))
158163 }
159164
160165
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 let ADDRESS_BYTES_SIZE = 26
1111
1212 func throwErr (msg) = throw(((contractFile + ": ") + msg))
1313
1414
1515 let keyAssetId = makeString(["%s", "assetId"], SEP)
1616
1717 let keyEmissionPerBlock = makeString(["%s", "emissionPerBlock"], SEP)
1818
1919 let keyStartBlock = makeString(["%s", "startBlock"], SEP)
2020
2121 let keyTotalLpAmount = makeString(["%s", "totalLpAmount"], SEP)
2222
2323 let keyTotalAssetAmount = makeString(["%s", "totalAssetAmount"], SEP)
2424
2525 func keyUserLpAmount (userAddress) = makeString(["%s%s", "userLpAmount", userAddress], SEP)
2626
2727
2828 func keyUserTotalAssetWithdrawn (userAddress) = makeString(["%s%s", "totalAssetWithdrawn", userAddress], SEP)
2929
3030
3131 func keyUserTotalAssetStaked (userAddress) = makeString(["%s%s", "totalAssetStaked", userAddress], SEP)
3232
3333
3434 let totalLpAmount = valueOrElse(getInteger(this, keyTotalLpAmount), 0)
3535
3636 let totalAssetAmount = valueOrElse(getInteger(this, keyTotalAssetAmount), 0)
3737
3838 let assetIdString = valueOrElse(getString(this, keyAssetId), "WAVES")
3939
4040 let assetIdBytes = if ((assetIdString == "WAVES"))
4141 then unit
4242 else fromBase58String(assetIdString)
4343
4444 func getUserLpAmount (userAddress) = valueOrElse(getInteger(this, keyUserLpAmount(userAddress)), 0)
4545
4646
4747 func calcTotalProfit () = {
4848 let emissionPerBlock = valueOrElse(getInteger(this, keyEmissionPerBlock), 0)
4949 let startBlock = valueOrElse(getInteger(this, keyStartBlock), 0)
5050 let elapsedBlocks = (height - startBlock)
5151 max([0, (emissionPerBlock * elapsedBlocks)])
5252 }
5353
5454
5555 func getTotalAssetAmountWithProfitOrMaxAvailable () = {
5656 let totalAssetAmountWithProfit = (totalAssetAmount + calcTotalProfit())
57- match assetIdBytes {
57+ let totalAmount = match assetIdBytes {
5858 case u: Unit =>
5959 min([totalAssetAmountWithProfit, wavesBalance(this).available])
6060 case b: ByteVector =>
6161 min([totalAssetAmountWithProfit, assetBalance(this, b)])
6262 case _ =>
6363 throw("Match error")
6464 }
65+ if ((totalLpAmount == 0))
66+ then 0
67+ else totalAmount
6568 }
6669
6770
6871 func getCurrentPrice () = if ((totalLpAmount != 0))
6972 then fraction(getTotalAssetAmountWithProfitOrMaxAvailable(), scale8, totalLpAmount)
7073 else (1 * scale8)
7174
7275
73-func getStakeAction (i,userAddress) = {
76+func getStakeActions (i,userAddress) = {
7477 let checks = [if ((size(i.payments) == 1))
7578 then true
7679 else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
7780 then true
7881 else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0))
7982 then true
8083 else "payment amount should be greater than 0"]
8184 if ((checks == checks))
8285 then {
8386 let paymentAmount = i.payments[0].amount
8487 let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
8588 let userLpAmount = getUserLpAmount(userAddress)
86- let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
89+ let userTotalStakedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
8790 let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
8891 let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
8992 let newUserLpAmount = (userLpAmount + paymentLpAmount)
90- let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
93+ let newUserTotalStakedAmount = (userTotalStakedAmount + paymentAmount)
9194 let updateStartHeightAction = if ((totalLpAmount == 0))
9295 then [IntegerEntry(keyStartBlock, height)]
9396 else nil
94- ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)] ++ updateStartHeightAction)
97+ ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalStakedAmount)] ++ updateStartHeightAction)
9598 }
9699 else throw("Strict value is not equal to itself.")
97100 }
98101
99102
100103 @Callable(i)
101104 func setEmissionPerBlock (emissionPerBlock) = {
102105 let check = [if ((i.caller == this))
103106 then true
104107 else throwErr("permission denied")]
105108 if ((check == check))
106109 then [IntegerEntry(keyTotalAssetAmount, getTotalAssetAmountWithProfitOrMaxAvailable()), IntegerEntry(keyStartBlock, height), IntegerEntry(keyEmissionPerBlock, max([0, emissionPerBlock]))]
107110 else throw("Strict value is not equal to itself.")
108111 }
109112
110113
111114
112115 @Callable(i)
113-func stake () = getStakeAction(i, toString(i.caller))
116+func stake () = getStakeActions(i, toString(i.caller))
114117
115118
116119
117120 @Callable(i)
118121 func stakeFor (userAddress) = {
119122 let check = [if ((size(fromBase58String(userAddress)) == ADDRESS_BYTES_SIZE))
120123 then true
121124 else throwErr("address is not valid")]
122125 if ((check == check))
123- then getStakeAction(i, userAddress)
126+ then getStakeActions(i, userAddress)
124127 else throw("Strict value is not equal to itself.")
125128 }
126129
127130
128131
129132 @Callable(i)
130133 func withdraw (lpAssetWithdrawAmount) = {
131134 let userAddress = toString(i.caller)
132135 let userLpAmount = getUserLpAmount(userAddress)
133136 let check = [if ((lpAssetWithdrawAmount > 0))
134137 then true
135138 else throwErr("amount should be more than 0"), if ((userLpAmount >= lpAssetWithdrawAmount))
136139 then true
137140 else throwErr((("cannot withdraw more than available (" + toString(userLpAmount)) + ")"))]
138141 if ((check == check))
139142 then {
140143 let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount)
141144 let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8)
142145 let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount)
143146 let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
144147 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
145148 let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount)
146149 [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), IntegerEntry(keyStartBlock, height), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)]
147150 }
148151 else throw("Strict value is not equal to itself.")
149152 }
150153
151154
152155
153156 @Callable(i)
154157 func getUserAssetsREADONLY (userAddress) = {
155158 let userLpAmount = getUserLpAmount(userAddress)
156159 let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
157- $Tuple2(nil, $Tuple3(userLpAmount, userAvailableAssetToWithdraw, getCurrentPrice()))
160+ let userTotalStakedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
161+ let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
162+ $Tuple2(nil, $Tuple5(userLpAmount, userAvailableAssetToWithdraw, getCurrentPrice(), userTotalStakedAmount, userTotalAssetWithdrawn))
158163 }
159164
160165
161166
162167 @Callable(i)
163168 func getTotalAssetsREADONLY () = $Tuple2(nil, $Tuple3(totalLpAmount, getTotalAssetAmountWithProfitOrMaxAvailable(), getCurrentPrice()))
164169
165170

github/deemru/w8io/026f985 
35.22 ms