tx · 4uDHRyaYN55YQ2Cohjd94REj9PTdUmk4gzdGBVxd9be2 3NBGYJLwHsU6eJXLi74dB8cBbMfiTS2cTtu: -0.01400000 Waves 2022.05.15 18:31 [2052974] smart account 3NBGYJLwHsU6eJXLi74dB8cBbMfiTS2cTtu > SELF 0.00000000 Waves
{ "type": 13, "id": "4uDHRyaYN55YQ2Cohjd94REj9PTdUmk4gzdGBVxd9be2", "fee": 1400000, "feeAssetId": null, "timestamp": 1652628752208, "version": 2, "chainId": 84, "sender": "3NBGYJLwHsU6eJXLi74dB8cBbMfiTS2cTtu", "senderPublicKey": "DqoxVw7QE15hy21jZuVxZXM9E7WXmheH1up4dwp57Yb8", "proofs": [ "osZ5CwBVPDUoGe8itR9rikAgn6K8XXBM4nABShpcdiVq3cbACy3iUH35W5RBfXhM9bJdh1YcKY7NdNE79mPQ4Er" ], "script": "base64:AAIFAAAAAAAAABQIAhIAEgMKAQgSABIDCgEBEgASAAAAAA0AAAAACW9yYWNsZUtleQIAAAAJb3JhY2xlS2V5AAAAAAVTY2FsZQAAAAAAAA9CQAEAAAANdHJ5R2V0SW50ZWdlcgAAAAEAAAADa2V5BAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFiBQAAAAckbWF0Y2gwBQAAAAFiAAAAAAAAAAAAAQAAAAx0cnlHZXRTdHJpbmcAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQIAAAAAAAAAAAZvcmFjbGUJAQAAAAx0cnlHZXRTdHJpbmcAAAABBQAAAAlvcmFjbGVLZXkAAAAACW9yYWNsZUZlZQkBAAAABXZhbHVlAAAAAQkABCYAAAABBQAAAAZvcmFjbGUBAAAAGWdldEludGVnZXJCeUtleUZy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vYmFsX2xhc3RDaGVja19TQ09ORVhfaW50ZXJlc3QJAABkAAAAAgUAAAAPY3VycmVudEludGVyZXN0BQAAAA1pbnRlcmVzdERlbHRhBQAAAANuaWwAAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAACQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tleeC3920=", "height": 2052974, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5cN8KwRFrNKWV9PJax3f99SbTiDCUqmtGEobBiGBr6A1 Next: 5FQdBKvun9QA7cYwSGdEHKyT814iY5NaHsqaXx8SQ2NG Diff:
Old | New | Differences | |
---|---|---|---|
25 | 25 | ||
26 | 26 | let oracleFee = value(addressFromString(oracle)) | |
27 | 27 | ||
28 | + | func getIntegerByKeyFromOracle (key) = valueOrErrorMessage(getInteger(oracleFee, key), "Integer undefine or 0 in oracle") | |
29 | + | ||
30 | + | ||
28 | 31 | let SconexAssetId = fromBase58String(getStringValue(oracleFee, "SconexAssetId")) | |
32 | + | ||
33 | + | let currentFeeSconex = getIntegerByKeyFromOracle(("fee_" + toBase58String(SconexAssetId))) | |
34 | + | ||
35 | + | let stakeDapp = addressFromString(valueOrErrorMessage(getString(oracleFee, "stakeDapp"), "sconexDapp not found")) | |
29 | 36 | ||
30 | 37 | func claimResult (address) = { | |
31 | 38 | let addressStr = toString(address) | |
39 | 46 | } | |
40 | 47 | ||
41 | 48 | ||
49 | + | func isPayment (i) = if ((size(i.payments) != 1)) | |
50 | + | then throw("Wrong payments attached") | |
51 | + | else { | |
52 | + | let payment = value(i.payments[0]) | |
53 | + | let amount = value(payment.amount) | |
54 | + | $Tuple2(payment, amount) | |
55 | + | } | |
56 | + | ||
57 | + | ||
58 | + | func validatePayment (i) = { | |
59 | + | let t089829018 = isPayment(i) | |
60 | + | let payment = t089829018._1 | |
61 | + | let amount = t089829018._2 | |
62 | + | let assetId = if (if (isDefined(payment.assetId)) | |
63 | + | then (payment.assetId == SconexAssetId) | |
64 | + | else false) | |
65 | + | then payment.assetId | |
66 | + | else throw((("Only " + toBase58String(SconexAssetId)) + " token accepted as transaction fee")) | |
67 | + | if ((amount != currentFeeSconex)) | |
68 | + | then throw(((("Payment amount should be " + toString(currentFeeSconex)) + " but is: ") + toString(amount))) | |
69 | + | else $Tuple2(amount, assetId) | |
70 | + | } | |
71 | + | ||
72 | + | ||
73 | + | @Callable(i) | |
74 | + | func validateAndProcessPayment () = { | |
75 | + | let validP = validatePayment(i) | |
76 | + | let amountP = validP._1 | |
77 | + | let assetIdP = validP._2 | |
78 | + | if (!(isDefined(amountP))) | |
79 | + | then throw("Something went wrong") | |
80 | + | else { | |
81 | + | let invokeTeamFeeSplit = invoke(valueOrErrorMessage(stakeDapp, "stakeDapp not found"), "topUpReward", nil, [AttachedPayment(assetIdP, amountP)]) | |
82 | + | if ((invokeTeamFeeSplit == invokeTeamFeeSplit)) | |
83 | + | then nil | |
84 | + | else throw("Strict value is not equal to itself.") | |
85 | + | } | |
86 | + | } | |
87 | + | ||
88 | + | ||
89 | + | ||
42 | 90 | @Callable(i) | |
43 | 91 | func initDapp (dappKey) = if ((i.caller != this)) | |
44 | 92 | then throw("You cannot do this action") | |
50 | 98 | ||
51 | 99 | @Callable(i) | |
52 | 100 | func stake () = { | |
53 | - | let amount = i.payments[0].amount | |
54 | - | let addressStr = toString(i.caller) | |
55 | - | let totalStakedAmount = tryGetInteger("global_staked") | |
56 | - | if ((i.payments[0].assetId != SconexAssetId)) | |
57 | - | then throw("wrong asset attached") | |
58 | - | else (claimResult(i.caller) ++ [IntegerEntry("global_staked", (totalStakedAmount + amount)), IntegerEntry((addressStr + "_SCONEX_staked"), (tryGetInteger((addressStr + "_SCONEX_staked")) + amount))]) | |
101 | + | let validateAndProcessPaymentInvoke = invoke(valueOrErrorMessage(this, "this not found"), "validateAndProcessPayment", nil, [i.payments[0]]) | |
102 | + | if ((validateAndProcessPaymentInvoke == validateAndProcessPaymentInvoke)) | |
103 | + | then { | |
104 | + | let amount = i.payments[1].amount | |
105 | + | let addressStr = toString(i.caller) | |
106 | + | let totalStakedAmount = tryGetInteger("global_staked") | |
107 | + | if ((i.payments[1].assetId != SconexAssetId)) | |
108 | + | then throw("wrong asset attached") | |
109 | + | else (claimResult(i.caller) ++ [IntegerEntry("global_staked", (totalStakedAmount + amount)), IntegerEntry((addressStr + "_SCONEX_staked"), (tryGetInteger((addressStr + "_SCONEX_staked")) + amount))]) | |
110 | + | } | |
111 | + | else throw("Strict value is not equal to itself.") | |
59 | 112 | } | |
60 | 113 | ||
61 | 114 | ||
62 | 115 | ||
63 | 116 | @Callable(i) | |
64 | 117 | func unStake (amount) = { | |
65 | - | let addressStr = toString(i.caller) | |
66 | - | let stakedAmount = tryGetInteger((addressStr + "_SCONEX_staked")) | |
67 | - | if ((amount > stakedAmount)) | |
68 | - | then throw("you don't have tokens available") | |
69 | - | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_SCONEX_staked"), (stakedAmount - amount)), IntegerEntry("global_staked", (tryGetInteger("global_staked") - amount)), ScriptTransfer(i.caller, amount, SconexAssetId)]) | |
118 | + | let validateAndProcessPaymentInvoke = invoke(valueOrErrorMessage(this, "this not found"), "validateAndProcessPayment", nil, [i.payments[0]]) | |
119 | + | if ((validateAndProcessPaymentInvoke == validateAndProcessPaymentInvoke)) | |
120 | + | then { | |
121 | + | let addressStr = toString(i.caller) | |
122 | + | let stakedAmount = tryGetInteger((addressStr + "_SCONEX_staked")) | |
123 | + | if ((amount > stakedAmount)) | |
124 | + | then throw("you don't have tokens available") | |
125 | + | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_SCONEX_staked"), (stakedAmount - amount)), IntegerEntry("global_staked", (tryGetInteger("global_staked") - amount)), ScriptTransfer(i.caller, amount, SconexAssetId)]) | |
126 | + | } | |
127 | + | else throw("Strict value is not equal to itself.") | |
70 | 128 | } | |
71 | 129 | ||
72 | 130 | ||
73 | 131 | ||
74 | 132 | @Callable(i) | |
75 | - | func claimReward () = claimResult(i.caller) | |
133 | + | func claimReward () = { | |
134 | + | let validateAndProcessPaymentInvoke = invoke(valueOrErrorMessage(this, "this not found"), "validateAndProcessPayment", nil, [i.payments[0]]) | |
135 | + | if ((validateAndProcessPaymentInvoke == validateAndProcessPaymentInvoke)) | |
136 | + | then claimResult(i.caller) | |
137 | + | else throw("Strict value is not equal to itself.") | |
138 | + | } | |
76 | 139 | ||
77 | 140 | ||
78 | 141 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let oracleKey = "oracleKey" | |
5 | 5 | ||
6 | 6 | let Scale = 1000000 | |
7 | 7 | ||
8 | 8 | func tryGetInteger (key) = match getInteger(this, key) { | |
9 | 9 | case b: Int => | |
10 | 10 | b | |
11 | 11 | case _ => | |
12 | 12 | 0 | |
13 | 13 | } | |
14 | 14 | ||
15 | 15 | ||
16 | 16 | func tryGetString (key) = match getString(this, key) { | |
17 | 17 | case a: String => | |
18 | 18 | a | |
19 | 19 | case _ => | |
20 | 20 | "" | |
21 | 21 | } | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | let oracle = tryGetString(oracleKey) | |
25 | 25 | ||
26 | 26 | let oracleFee = value(addressFromString(oracle)) | |
27 | 27 | ||
28 | + | func getIntegerByKeyFromOracle (key) = valueOrErrorMessage(getInteger(oracleFee, key), "Integer undefine or 0 in oracle") | |
29 | + | ||
30 | + | ||
28 | 31 | let SconexAssetId = fromBase58String(getStringValue(oracleFee, "SconexAssetId")) | |
32 | + | ||
33 | + | let currentFeeSconex = getIntegerByKeyFromOracle(("fee_" + toBase58String(SconexAssetId))) | |
34 | + | ||
35 | + | let stakeDapp = addressFromString(valueOrErrorMessage(getString(oracleFee, "stakeDapp"), "sconexDapp not found")) | |
29 | 36 | ||
30 | 37 | func claimResult (address) = { | |
31 | 38 | let addressStr = toString(address) | |
32 | 39 | let currentInterest = tryGetInteger("global_lastCheck_SCONEX_interest") | |
33 | 40 | let lastCheckInterest = tryGetInteger((addressStr + "_lastCheck_SCONEX_interest")) | |
34 | 41 | let stakedAmount = tryGetInteger((addressStr + "_SCONEX_staked")) | |
35 | 42 | let reward = if ((lastCheckInterest > 0)) | |
36 | 43 | then fraction((currentInterest - lastCheckInterest), stakedAmount, Scale) | |
37 | 44 | else 0 | |
38 | 45 | [IntegerEntry((addressStr + "_lastCheck_SCONEX_interest"), currentInterest), IntegerEntry((addressStr + "_SCONEX_claimed"), (tryGetInteger((addressStr + "_SCONEX_claimed")) + reward)), ScriptTransfer(address, reward, SconexAssetId)] | |
39 | 46 | } | |
40 | 47 | ||
41 | 48 | ||
49 | + | func isPayment (i) = if ((size(i.payments) != 1)) | |
50 | + | then throw("Wrong payments attached") | |
51 | + | else { | |
52 | + | let payment = value(i.payments[0]) | |
53 | + | let amount = value(payment.amount) | |
54 | + | $Tuple2(payment, amount) | |
55 | + | } | |
56 | + | ||
57 | + | ||
58 | + | func validatePayment (i) = { | |
59 | + | let t089829018 = isPayment(i) | |
60 | + | let payment = t089829018._1 | |
61 | + | let amount = t089829018._2 | |
62 | + | let assetId = if (if (isDefined(payment.assetId)) | |
63 | + | then (payment.assetId == SconexAssetId) | |
64 | + | else false) | |
65 | + | then payment.assetId | |
66 | + | else throw((("Only " + toBase58String(SconexAssetId)) + " token accepted as transaction fee")) | |
67 | + | if ((amount != currentFeeSconex)) | |
68 | + | then throw(((("Payment amount should be " + toString(currentFeeSconex)) + " but is: ") + toString(amount))) | |
69 | + | else $Tuple2(amount, assetId) | |
70 | + | } | |
71 | + | ||
72 | + | ||
73 | + | @Callable(i) | |
74 | + | func validateAndProcessPayment () = { | |
75 | + | let validP = validatePayment(i) | |
76 | + | let amountP = validP._1 | |
77 | + | let assetIdP = validP._2 | |
78 | + | if (!(isDefined(amountP))) | |
79 | + | then throw("Something went wrong") | |
80 | + | else { | |
81 | + | let invokeTeamFeeSplit = invoke(valueOrErrorMessage(stakeDapp, "stakeDapp not found"), "topUpReward", nil, [AttachedPayment(assetIdP, amountP)]) | |
82 | + | if ((invokeTeamFeeSplit == invokeTeamFeeSplit)) | |
83 | + | then nil | |
84 | + | else throw("Strict value is not equal to itself.") | |
85 | + | } | |
86 | + | } | |
87 | + | ||
88 | + | ||
89 | + | ||
42 | 90 | @Callable(i) | |
43 | 91 | func initDapp (dappKey) = if ((i.caller != this)) | |
44 | 92 | then throw("You cannot do this action") | |
45 | 93 | else if ((oracle != "")) | |
46 | 94 | then throw("oracle already set, you can't override!") | |
47 | 95 | else [StringEntry(oracleKey, dappKey)] | |
48 | 96 | ||
49 | 97 | ||
50 | 98 | ||
51 | 99 | @Callable(i) | |
52 | 100 | func stake () = { | |
53 | - | let amount = i.payments[0].amount | |
54 | - | let addressStr = toString(i.caller) | |
55 | - | let totalStakedAmount = tryGetInteger("global_staked") | |
56 | - | if ((i.payments[0].assetId != SconexAssetId)) | |
57 | - | then throw("wrong asset attached") | |
58 | - | else (claimResult(i.caller) ++ [IntegerEntry("global_staked", (totalStakedAmount + amount)), IntegerEntry((addressStr + "_SCONEX_staked"), (tryGetInteger((addressStr + "_SCONEX_staked")) + amount))]) | |
101 | + | let validateAndProcessPaymentInvoke = invoke(valueOrErrorMessage(this, "this not found"), "validateAndProcessPayment", nil, [i.payments[0]]) | |
102 | + | if ((validateAndProcessPaymentInvoke == validateAndProcessPaymentInvoke)) | |
103 | + | then { | |
104 | + | let amount = i.payments[1].amount | |
105 | + | let addressStr = toString(i.caller) | |
106 | + | let totalStakedAmount = tryGetInteger("global_staked") | |
107 | + | if ((i.payments[1].assetId != SconexAssetId)) | |
108 | + | then throw("wrong asset attached") | |
109 | + | else (claimResult(i.caller) ++ [IntegerEntry("global_staked", (totalStakedAmount + amount)), IntegerEntry((addressStr + "_SCONEX_staked"), (tryGetInteger((addressStr + "_SCONEX_staked")) + amount))]) | |
110 | + | } | |
111 | + | else throw("Strict value is not equal to itself.") | |
59 | 112 | } | |
60 | 113 | ||
61 | 114 | ||
62 | 115 | ||
63 | 116 | @Callable(i) | |
64 | 117 | func unStake (amount) = { | |
65 | - | let addressStr = toString(i.caller) | |
66 | - | let stakedAmount = tryGetInteger((addressStr + "_SCONEX_staked")) | |
67 | - | if ((amount > stakedAmount)) | |
68 | - | then throw("you don't have tokens available") | |
69 | - | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_SCONEX_staked"), (stakedAmount - amount)), IntegerEntry("global_staked", (tryGetInteger("global_staked") - amount)), ScriptTransfer(i.caller, amount, SconexAssetId)]) | |
118 | + | let validateAndProcessPaymentInvoke = invoke(valueOrErrorMessage(this, "this not found"), "validateAndProcessPayment", nil, [i.payments[0]]) | |
119 | + | if ((validateAndProcessPaymentInvoke == validateAndProcessPaymentInvoke)) | |
120 | + | then { | |
121 | + | let addressStr = toString(i.caller) | |
122 | + | let stakedAmount = tryGetInteger((addressStr + "_SCONEX_staked")) | |
123 | + | if ((amount > stakedAmount)) | |
124 | + | then throw("you don't have tokens available") | |
125 | + | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_SCONEX_staked"), (stakedAmount - amount)), IntegerEntry("global_staked", (tryGetInteger("global_staked") - amount)), ScriptTransfer(i.caller, amount, SconexAssetId)]) | |
126 | + | } | |
127 | + | else throw("Strict value is not equal to itself.") | |
70 | 128 | } | |
71 | 129 | ||
72 | 130 | ||
73 | 131 | ||
74 | 132 | @Callable(i) | |
75 | - | func claimReward () = claimResult(i.caller) | |
133 | + | func claimReward () = { | |
134 | + | let validateAndProcessPaymentInvoke = invoke(valueOrErrorMessage(this, "this not found"), "validateAndProcessPayment", nil, [i.payments[0]]) | |
135 | + | if ((validateAndProcessPaymentInvoke == validateAndProcessPaymentInvoke)) | |
136 | + | then claimResult(i.caller) | |
137 | + | else throw("Strict value is not equal to itself.") | |
138 | + | } | |
76 | 139 | ||
77 | 140 | ||
78 | 141 | ||
79 | 142 | @Callable(i) | |
80 | 143 | func topUpReward () = { | |
81 | 144 | let amount = fraction(i.payments[0].amount, 9, 10) | |
82 | 145 | let currentInterest = tryGetInteger("global_lastCheck_SCONEX_interest") | |
83 | 146 | let totalStakedAmount = tryGetInteger("global_staked") | |
84 | 147 | let interestDelta = if ((totalStakedAmount > 0)) | |
85 | 148 | then fraction(amount, Scale, totalStakedAmount) | |
86 | 149 | else 0 | |
87 | 150 | if ((i.payments[0].assetId != SconexAssetId)) | |
88 | 151 | then throw("wrong asset attached") | |
89 | 152 | else [IntegerEntry("global_SCONEX_earnings", (tryGetInteger("global_SCONEX_earnings") + amount)), IntegerEntry("global_lastCheck_SCONEX_interest", (currentInterest + interestDelta))] | |
90 | 153 | } | |
91 | 154 | ||
92 | 155 | ||
93 | 156 | @Verifier(tx) | |
94 | 157 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
95 | 158 |
github/deemru/w8io/026f985 31.51 ms ◑