tx · 326DugJPSMm2YiAxGBmqf1CVDQRXSCMP6vdeQtw6FVVX

3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq:  -0.01000000 Waves

2023.07.19 09:13 [2672376] smart account 3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq > SELF 0.00000000 Waves

{ "type": 13, "id": "326DugJPSMm2YiAxGBmqf1CVDQRXSCMP6vdeQtw6FVVX", "fee": 1000000, "feeAssetId": null, "timestamp": 1689747210993, "version": 2, "chainId": 84, "sender": "3MpMuGN8rW9EpPwzETAQz88Pe9TQhSwiriq", "senderPublicKey": "57SkjQUEwC1ayCqLbXLuzBqifK6B6SR6rfxtGsbAo3zW", "proofs": [ "hY4EUo9DtdGUsUTKpkwQVxSifkERPh4KsFXUiVa7v4n4VLUkoc84JVUJRbfa225EURBkbtEpeB9h897xMh3ttwG" ], "script": "base64:BgIVCAISAwoBARIAEgMKAQESAwoBCBIAFAAMY29udHJhY3RGaWxlAhBtcnRfc3Rha2luZy5yaWRlAANTRVACAl9fAAZzY2FsZTgAgMLXLwEIdGhyb3dFcnIBA21zZwkAAgEJAKwCAgkArAICBQxjb250cmFjdEZpbGUCAjogBQNtc2cACmtleUFzc2V0SWQJALkJAgkAzAgCAgIlcwkAzAgCAgdhc3NldElkBQNuaWwFA1NFUAATa2V5RW1pc3Npb25QZXJCbG9jawkAuQkCCQDMCAICAiVzCQDMCAICEGVtaXNzaW9uUGVyQmxvY2sFA25pbAUDU0VQAA1rZXlTdGFydEJsb2NrCQC5CQIJAMwIAgICJXMJAMwIAgIKc3RhcnRCbG9jawUDbmlsBQNTRVAAEGtleVRvdGFsTHBBbW91bnQJALkJAgkAzAgCAgIlcwkAzAgCAg10b3RhbExwQW1vdW50BQNuaWwFA1NFUAATa2V5VG90YWxBc3NldEFtb3VudAkAuQkCCQDMCAICAiVzCQDMCAICEHRvdGFsQXNzZXRBbW91bnQFA25pbAUDU0VQAQ9rZXlVc2VyTHBBbW91bnQBC3VzZXJBZGRyZ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mF3CQBrAwUMdXNlckxwQW1vdW50CQEPZ2V0Q3VycmVudFByaWNlAAUGc2NhbGU4CQCUCgIFA25pbAkAlAoCBQx1c2VyTHBBbW91bnQFHHVzZXJBdmFpbGFibGVBc3NldFRvV2l0aGRyYXcBaQEWZ2V0VG90YWxBc3NldHNSRUFET05MWQAJAJQKAgUDbmlsCQCUCgIFDXRvdGFsTHBBbW91bnQJAStnZXRUb3RhbEFzc2V0QW1vdW50V2l0aFByb2ZpdE9yTWF4QXZhaWxhYmxlAADoPcAs", "height": 2672376, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: CfstKQdLaqwaxAsCWFeZurVu4Uo4vwGhRsvnZxcL4d6r Next: 8GEqyqv1MR2KCmXDZWivdm8NRPUBjmZiXaL8vXZTC2Kp 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 () = {
6767 let currentPrice = if ((totalLpAmount != 0))
6868 then fraction(getTotalAssetAmountWithProfitOrMaxAvailable(), scale8, totalLpAmount)
6969 else (1 * scale8)
7070 currentPrice
7171 }
7272
7373
7474 @Callable(i)
7575 func setEmissionPerBlock (emissionPerBlock) = [IntegerEntry(keyTotalAssetAmount, getTotalAssetAmountWithProfitOrMaxAvailable()), IntegerEntry(keyStartBlock, height), IntegerEntry(keyEmissionPerBlock, max([0, emissionPerBlock]))]
7676
7777
7878
7979 @Callable(i)
8080 func stake () = {
8181 let checks = [if ((size(i.payments) == 1))
8282 then true
8383 else throwErr("should include 1 payment"), if ((i.payments[0].assetId == assetIdBytes))
8484 then true
8585 else throwErr(("payment should be in " + assetIdString)), if ((i.payments[0].amount > 0))
8686 then true
8787 else "payment amount should be greater than 0"]
8888 if ((checks == checks))
8989 then {
9090 let paymentAmount = i.payments[0].amount
9191 let paymentLpAmount = fraction(paymentAmount, scale8, getCurrentPrice())
9292 let userAddress = toString(i.caller)
9393 let userLpAmount = getUserLpAmount(userAddress)
9494 let userTotalInvestedAmount = valueOrElse(getInteger(this, keyUserTotalAssetStaked(userAddress)), 0)
9595 let newTotalLpAmount = (totalLpAmount + paymentLpAmount)
9696 let newTotalAssetAmount = (totalAssetAmount + paymentAmount)
9797 let newUserLpAmount = (userLpAmount + paymentLpAmount)
9898 let newUserTotalInvestedAmount = (userTotalInvestedAmount + paymentAmount)
9999 [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetStaked(userAddress), newUserTotalInvestedAmount)]
100100 }
101101 else throw("Strict value is not equal to itself.")
102102 }
103103
104104
105105
106106 @Callable(i)
107107 func withdraw (lpAssetWithdrawAmount) = {
108108 let userAddress = toString(i.caller)
109109 let userLpAmount = getUserLpAmount(userAddress)
110110 let check = [if ((userLpAmount >= lpAssetWithdrawAmount))
111111 then true
112112 else throwErr((("cannot withdraw more than available (" + toString(userLpAmount)) + ")"))]
113113 if ((check == check))
114114 then {
115115 let newUserLpAmount = (userLpAmount - lpAssetWithdrawAmount)
116116 let withdrawAssetAmount = fraction(lpAssetWithdrawAmount, getCurrentPrice(), scale8)
117117 let newTotalLpAmount = (totalLpAmount - lpAssetWithdrawAmount)
118118 let newTotalAssetAmount = fraction(newTotalLpAmount, getCurrentPrice(), scale8)
119119 let userTotalAssetWithdrawn = valueOrElse(getInteger(this, keyUserTotalAssetWithdrawn(userAddress)), 0)
120120 let newUserTotalAssetWithdrawn = (userTotalAssetWithdrawn + withdrawAssetAmount)
121121 [IntegerEntry(keyTotalLpAmount, newTotalLpAmount), IntegerEntry(keyTotalAssetAmount, newTotalAssetAmount), IntegerEntry(keyUserLpAmount(userAddress), newUserLpAmount), IntegerEntry(keyUserTotalAssetWithdrawn(userAddress), newUserTotalAssetWithdrawn), IntegerEntry(keyStartBlock, height), ScriptTransfer(i.caller, withdrawAssetAmount, assetIdBytes)]
122122 }
123123 else throw("Strict value is not equal to itself.")
124124 }
125125
126126
127127
128128 @Callable(i)
129129 func getAvailableToWithdrawREADONLY (userAddress) = {
130130 let userLpAmount = getUserLpAmount(userAddress)
131131 let userAvailableAssetToWithdraw = fraction(userLpAmount, getCurrentPrice(), scale8)
132132 $Tuple2(nil, $Tuple2(userLpAmount, userAvailableAssetToWithdraw))
133133 }
134134
135135
136136
137137 @Callable(i)
138138 func getTotalAssetsREADONLY () = $Tuple2(nil, $Tuple2(totalLpAmount, getTotalAssetAmountWithProfitOrMaxAvailable()))
139139
140140

github/deemru/w8io/026f985 
26.87 ms