tx · 8Fa8PH8xvgBTVuXa7AWViEpTjZ8rooSMzJf4SRfVELxi

3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq:  -0.01000000 Waves

2023.07.20 16:50 [2674259] smart account 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq > SELF 0.00000000 Waves

{ "type": 13, "id": "8Fa8PH8xvgBTVuXa7AWViEpTjZ8rooSMzJf4SRfVELxi", "fee": 1000000, "feeAssetId": null, "timestamp": 1689861044333, "version": 2, "chainId": 84, "sender": "3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq", "senderPublicKey": "57SkjQUEwC1ayCqLbXLuzBqifK6B6SR6rfxtGsbAo3zW", "proofs": [ "467TMh26gzZ9qf1VjPf3SfvFf5BZEBpQtd67qzG8kaMqi5RN2hXLTNicZZTuAgBhcPVQuGYDm4fk5cKbSxbGmuwt" ], "script": "base64:BgIaCAISAwoBARIAEgMKAQgSAwoBARIDCgEIEgAWAAxjb250cmFjdEZpbGUCEG1wdF9zdGFraW5nLnJpZGUAA1NFUAICX18ABnNjYWxlOACAwtcvABJBRERSRVNTX0JZVEVTX1NJWkUAGgEIdGhyb3dFcnIBA21zZwkAAgEJAKwCAgkArAICBQxjb250cmFjdEZpbGUCAjogBQNtc2cACmtleUFzc2V0SWQJALkJAgkAzAgCAgIlcwkAzAgCAgdhc3NldElkBQNuaWwFA1NFUAATa2V5RW1pc3Npb25QZXJCbG9jawkAuQkCCQDMCAICAiVzCQDMCAICEGVtaXNzaW9uUGVyQmxvY2sFA25pbAUDU0VQAA1rZXlTdGFydEJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIKc3RhcnRCbG9jawUDbmlsBQNTRVAAEGtleVRvdGFsTHBBbW91bnQJALkJAgkAzAgCAgIlcwkAzAgCAg10b3RhbExwQW1vdW50BQNuaWwFA1NFUAATa2V5VG90YWxBc3NldEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICEHRvdGFsQXNzZXRBbW91bnQFA25pbAU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VzcwAABBd1c2VyVG90YWxBc3NldFdpdGhkcmF3bgkBC3ZhbHVlT3JFbHNlAgkAmggCBQR0aGlzCQEaa2V5VXNlclRvdGFsQXNzZXRXaXRoZHJhd24BBQt1c2VyQWRkcmVzcwAACQCUCgIFA25pbAkAlwoFBQx1c2VyTHBBbW91bnQFHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcJAQ9nZXRDdXJyZW50UHJpY2UABRV1c2VyVG90YWxTdGFrZWRBbW91bnQFF3VzZXJUb3RhbEFzc2V0V2l0aGRyYXduAWkBFmdldFRvdGFsQXNzZXRzUkVBRE9OTFkACQCUCgIFA25pbAkAlQoDBQ10b3RhbExwQW1vdW50CQErZ2V0VG90YWxBc3NldEFtb3VudFdpdGhQcm9maXRPck1heEF2YWlsYWJsZQAJAQ9nZXRDdXJyZW50UHJpY2UAAJ8d3f0=", "height": 2674259, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9VSJDAE3AHniSi75bSKhCVmtHkc9WfD5jg2kNLKT1KBf Next: A7Ut3bNqxBuaJpCRbr2uewZT7odFPSLMT5xqfnroJTC1 Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let contractFile = "mrt_staking.ride"
4+let contractFile = "mpt_staking.ride"
55
66 let SEP = "__"
77
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let contractFile = "mrt_staking.ride"
4+let contractFile = "mpt_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())
5757 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 }
6565 if ((totalLpAmount == 0))
6666 then 0
6767 else totalAmount
6868 }
6969
7070
7171 func getCurrentPrice () = if ((totalLpAmount != 0))
7272 then fraction(getTotalAssetAmountWithProfitOrMaxAvailable(), scale8, totalLpAmount)
7373 else (1 * scale8)
7474
7575
7676 func getStakeActions (i,userAddress) = {
7777 let checks = [if ((size(i.payments) == 1))
7878 then true
7979 else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
8080 then true
8181 else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0))
8282 then true
8383 else "payment amount should be greater than 0"]
8484 if ((checks == checks))
8585 then {
8686 let paymentAmount = i.payments[0].amount
8787 let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
8888 let userLpAmount = getUserLpAmount(userAddress)
8989 let userTotalStakedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
9090 let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
9191 let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
9292 let newUserLpAmount = (userLpAmount + paymentLpAmount)
9393 let newUserTotalStakedAmount = (userTotalStakedAmount + paymentAmount)
9494 let updateStartHeightAction = if ((totalLpAmount == 0))
9595 then [IntegerEntry(keyStartBlock, height)]
9696 else nil
9797 ([IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalStakedAmount)] ++ updateStartHeightAction)
9898 }
9999 else throw("Strict value is not equal to itself.")
100100 }
101101
102102
103103 @Callable(i)
104104 func setEmissionPerBlock (emissionPerBlock) = {
105105 let check = [if ((i.caller == this))
106106 then true
107107 else throwErr("permission denied")]
108108 if ((check == check))
109109 then [IntegerEntry(keyTotalAssetAmount, getTotalAssetAmountWithProfitOrMaxAvailable()), IntegerEntry(keyStartBlock, height), IntegerEntry(keyEmissionPerBlock, max([0, emissionPerBlock]))]
110110 else throw("Strict value is not equal to itself.")
111111 }
112112
113113
114114
115115 @Callable(i)
116116 func stake () = getStakeActions(i, toString(i.caller))
117117
118118
119119
120120 @Callable(i)
121121 func stakeFor (userAddress) = {
122122 let check = [if ((size(fromBase58String(userAddress)) == ADDRESS_BYTES_SIZE))
123123 then true
124124 else throwErr("address is not valid")]
125125 if ((check == check))
126126 then getStakeActions(i, userAddress)
127127 else throw("Strict value is not equal to itself.")
128128 }
129129
130130
131131
132132 @Callable(i)
133133 func withdraw (lpAssetWithdrawAmount) = {
134134 let userAddress = toString(i.caller)
135135 let userLpAmount = getUserLpAmount(userAddress)
136136 let check = [if ((lpAssetWithdrawAmount > 0))
137137 then true
138138 else throwErr("amount should be more than 0"), if ((userLpAmount >= lpAssetWithdrawAmount))
139139 then true
140140 else throwErr((("cannot withdraw more than available (" + toString(userLpAmount)) + ")"))]
141141 if ((check == check))
142142 then {
143143 let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount)
144144 let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8)
145145 let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount)
146146 let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
147147 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
148148 let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount)
149149 [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), IntegerEntry(keyStartBlock, height), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)]
150150 }
151151 else throw("Strict value is not equal to itself.")
152152 }
153153
154154
155155
156156 @Callable(i)
157157 func getUserAssetsREADONLY (userAddress) = {
158158 let userLpAmount = getUserLpAmount(userAddress)
159159 let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
160160 let userTotalStakedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
161161 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
162162 $Tuple2(nil, $Tuple5(userLpAmount, userAvailableAssetToWithdraw, getCurrentPrice(), userTotalStakedAmount, userTotalAssetWithdrawn))
163163 }
164164
165165
166166
167167 @Callable(i)
168168 func getTotalAssetsREADONLY () = $Tuple2(nil, $Tuple3(totalLpAmount, getTotalAssetAmountWithProfitOrMaxAvailable(), getCurrentPrice()))
169169
170170

github/deemru/w8io/026f985 
47.69 ms